app/testpmd: convert to new Rx offloads API
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set xstats-hide-zero on|off\n"
530                         "    Set the option to hide the zero values"
531                         " for xstats display.\n"
532
533                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
534                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
535
536                         "set port (port_id) vf (vf_id) (mac_addr)"
537                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
538                         "   Add/Remove unicast or multicast MAC addr filter"
539                         " for a VF.\n\n"
540
541                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
542                         "|MPE) (on|off)\n"
543                         "    AUPE:accepts untagged VLAN;"
544                         "ROPE:accept unicast hash\n\n"
545                         "    BAM:accepts broadcast packets;"
546                         "MPE:accepts all multicast packets\n\n"
547                         "    Enable/Disable a VF receive mode of a port\n\n"
548
549                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
550                         "    Set rate limit for a queue of a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rate (rate_num) "
553                         "queue_mask (queue_mask_value)\n"
554                         "    Set rate limit for queues in VF of a port\n\n"
555
556                         "set port (port_id) mirror-rule (rule_id)"
557                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
558                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
559                         "   Set pool or vlan type mirror rule on a port.\n"
560                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
561                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
562                         " to pool 0.\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (uplink-mirror|downlink-mirror) dst-pool"
566                         " (pool_id) (on|off)\n"
567                         "   Set uplink or downlink type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
569                         " 0 on' enable mirror income traffic to pool 0.\n\n"
570
571                         "reset port (port_id) mirror-rule (rule_id)\n"
572                         "   Reset a mirror rule.\n\n"
573
574                         "set flush_rx (on|off)\n"
575                         "   Flush (default) or don't flush RX streams before"
576                         " forwarding. Mainly used with PCAP drivers.\n\n"
577
578                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the bypass mode for the lowest port on bypass enabled"
580                         " NIC.\n\n"
581
582                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
583                         "mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the event required to initiate specified bypass mode for"
585                         " the lowest port on a bypass enabled NIC where:\n"
586                         "       timeout   = enable bypass after watchdog timeout.\n"
587                         "       os_on     = enable bypass when OS/board is powered on.\n"
588                         "       os_off    = enable bypass when OS/board is powered off.\n"
589                         "       power_on  = enable bypass when power supply is turned on.\n"
590                         "       power_off = enable bypass when power supply is turned off."
591                         "\n\n"
592
593                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
594                         "   Set the bypass watchdog timeout to 'n' seconds"
595                         " where 0 = instant.\n\n"
596
597                         "show bypass config (port_id)\n"
598                         "   Show the bypass configuration for a bypass enabled NIC"
599                         " using the lowest port on the NIC.\n\n"
600
601 #ifdef RTE_LIBRTE_PMD_BOND
602                         "create bonded device (mode) (socket)\n"
603                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
604
605                         "add bonding slave (slave_id) (port_id)\n"
606                         "       Add a slave device to a bonded device.\n\n"
607
608                         "remove bonding slave (slave_id) (port_id)\n"
609                         "       Remove a slave device from a bonded device.\n\n"
610
611                         "set bonding mode (value) (port_id)\n"
612                         "       Set the bonding mode on a bonded device.\n\n"
613
614                         "set bonding primary (slave_id) (port_id)\n"
615                         "       Set the primary slave for a bonded device.\n\n"
616
617                         "show bonding config (port_id)\n"
618                         "       Show the bonding config for port_id.\n\n"
619
620                         "set bonding mac_addr (port_id) (address)\n"
621                         "       Set the MAC address of a bonded device.\n\n"
622
623                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
624                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
625
626                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
627                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
628
629                         "set bonding mon_period (port_id) (value)\n"
630                         "       Set the bonding link status monitoring polling period in ms.\n\n"
631
632                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
633                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
634
635 #endif
636                         "set link-up port (port_id)\n"
637                         "       Set link up for a port.\n\n"
638
639                         "set link-down port (port_id)\n"
640                         "       Set link down for a port.\n\n"
641
642                         "E-tag set insertion on port-tag-id (value)"
643                         " port (port_id) vf (vf_id)\n"
644                         "    Enable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
647                         "    Disable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set stripping (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag stripping on a port\n\n"
651
652                         "E-tag set forwarding (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag based forwarding"
654                         " on a port\n\n"
655
656                         "E-tag set filter add e-tag-id (value) dst-pool"
657                         " (pool_id) port (port_id)\n"
658                         "    Add an E-tag forwarding filter on a port\n\n"
659
660                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
661                         "    Delete an E-tag forwarding filter on a port\n\n"
662
663 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
664                         "set port tm hierarchy default (port_id)\n"
665                         "       Set default traffic Management hierarchy on a port\n\n"
666
667 #endif
668                         "ddp add (port_id) (profile_path[,output_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "queue_start_index (value) queue_num (value)\n"
688                         "    Set a queue region on a port\n\n"
689
690                         "set port (port_id) queue-region region_id (value) "
691                         "flowtype (value)\n"
692                         "    Set a flowtype region index on a port\n\n"
693
694                         "set port (port_id) queue-region UP (value) region_id (value)\n"
695                         "    Set the mapping of User Priority to "
696                         "queue region on a port\n\n"
697
698                         "set port (port_id) queue-region flush (on|off)\n"
699                         "    flush all queue region related configuration\n\n"
700
701                         "show port meter cap (port_id)\n"
702                         "    Show port meter capability information\n\n"
703
704                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
705                         "    meter profile add - srtcm rfc 2697\n\n"
706
707                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
708                         "    meter profile add - trtcm rfc 2698\n\n"
709
710                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
711                         "    meter profile add - trtcm rfc 4115\n\n"
712
713                         "del port meter profile (port_id) (profile_id)\n"
714                         "    meter profile delete\n\n"
715
716                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
717                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
718                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
719                         "(dscp_tbl_entry63)]\n"
720                         "    meter create\n\n"
721
722                         "enable port meter (port_id) (mtr_id)\n"
723                         "    meter enable\n\n"
724
725                         "disable port meter (port_id) (mtr_id)\n"
726                         "    meter disable\n\n"
727
728                         "del port meter (port_id) (mtr_id)\n"
729                         "    meter delete\n\n"
730
731                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
732                         "    meter update meter profile\n\n"
733
734                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
735                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
736                         "    update meter dscp table entries\n\n"
737
738                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
739                         "(action0) [(action1) (action2)]\n"
740                         "    meter update policer action\n\n"
741
742                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
743                         "    meter update stats\n\n"
744
745                         "show port (port_id) queue-region\n"
746                         "    show all queue region related configuration info\n\n"
747
748                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
749                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
750                         "       Add port tm node private shaper profile.\n\n"
751
752                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
753                         "       Delete port tm node private shaper profile.\n\n"
754
755                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
756                         " (shaper_profile_id)\n"
757                         "       Add/update port tm node shared shaper.\n\n"
758
759                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
760                         "       Delete port tm node shared shaper.\n\n"
761
762                         "set port tm node shaper profile (port_id) (node_id)"
763                         " (shaper_profile_id)\n"
764                         "       Set port tm node shaper profile.\n\n"
765
766                         "add port tm node wred profile (port_id) (wred_profile_id)"
767                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
768                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
769                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
770                         "       Add port tm node wred profile.\n\n"
771
772                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
773                         "       Delete port tm node wred profile.\n\n"
774
775                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
776                         " (priority) (weight) (level_id) (shaper_profile_id)"
777                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
778                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
779                         "       Add port tm nonleaf node.\n\n"
780
781                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm leaf node.\n\n"
786
787                         "del port tm node (port_id) (node_id)\n"
788                         "       Delete port tm node.\n\n"
789
790                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
791                         " (priority) (weight)\n"
792                         "       Set port tm node parent.\n\n"
793
794                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
795                         "       Commit tm hierarchy.\n\n"
796
797                         , list_pkt_forwarding_modes()
798                 );
799         }
800
801         if (show_all || !strcmp(res->section, "ports")) {
802
803                 cmdline_printf(
804                         cl,
805                         "\n"
806                         "Port Operations:\n"
807                         "----------------\n\n"
808
809                         "port start (port_id|all)\n"
810                         "    Start all ports or port_id.\n\n"
811
812                         "port stop (port_id|all)\n"
813                         "    Stop all ports or port_id.\n\n"
814
815                         "port close (port_id|all)\n"
816                         "    Close all ports or port_id.\n\n"
817
818                         "port attach (ident)\n"
819                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
820
821                         "port detach (port_id)\n"
822                         "    Detach physical or virtual dev by port_id\n\n"
823
824                         "port config (port_id|all)"
825                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
826                         " duplex (half|full|auto)\n"
827                         "    Set speed and duplex for all ports or port_id\n\n"
828
829                         "port config all (rxq|txq|rxd|txd) (value)\n"
830                         "    Set number for rxq/txq/rxd/txd.\n\n"
831
832                         "port config all max-pkt-len (value)\n"
833                         "    Set the max packet length.\n\n"
834
835                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
836                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
837                         " (on|off)\n"
838                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
839                         " for ports.\n\n"
840
841                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
842                         "geneve|nvgre|none|<flowtype_id>)\n"
843                         "    Set the RSS mode.\n\n"
844
845                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
846                         "    Set the RSS redirection table.\n\n"
847
848                         "port config (port_id) dcb vt (on|off) (traffic_class)"
849                         " pfc (on|off)\n"
850                         "    Set the DCB mode.\n\n"
851
852                         "port config all burst (value)\n"
853                         "    Set the number of packets per burst.\n\n"
854
855                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
856                         " (value)\n"
857                         "    Set the ring prefetch/host/writeback threshold"
858                         " for tx/rx queue.\n\n"
859
860                         "port config all (txfreet|txrst|rxfreet) (value)\n"
861                         "    Set free threshold for rx/tx, or set"
862                         " tx rs bit threshold.\n\n"
863                         "port config mtu X value\n"
864                         "    Set the MTU of port X to a given value\n\n"
865
866                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
867                         "    Start/stop a rx/tx queue of port X. Only take effect"
868                         " when port X is started\n\n"
869
870                         "port config (port_id|all) l2-tunnel E-tag ether-type"
871                         " (value)\n"
872                         "    Set the value of E-tag ether-type.\n\n"
873
874                         "port config (port_id|all) l2-tunnel E-tag"
875                         " (enable|disable)\n"
876                         "    Enable/disable the E-tag support.\n\n"
877
878                         "port config (port_id) pctype mapping reset\n"
879                         "    Reset flow type to pctype mapping on a port\n\n"
880
881                         "port config (port_id) pctype mapping update"
882                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
883                         "    Update a flow type to pctype mapping item on a port\n\n"
884                 );
885         }
886
887         if (show_all || !strcmp(res->section, "registers")) {
888
889                 cmdline_printf(
890                         cl,
891                         "\n"
892                         "Registers:\n"
893                         "----------\n\n"
894
895                         "read reg (port_id) (address)\n"
896                         "    Display value of a port register.\n\n"
897
898                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
899                         "    Display a port register bit field.\n\n"
900
901                         "read regbit (port_id) (address) (bit_x)\n"
902                         "    Display a single port register bit.\n\n"
903
904                         "write reg (port_id) (address) (value)\n"
905                         "    Set value of a port register.\n\n"
906
907                         "write regfield (port_id) (address) (bit_x) (bit_y)"
908                         " (value)\n"
909                         "    Set bit field of a port register.\n\n"
910
911                         "write regbit (port_id) (address) (bit_x) (value)\n"
912                         "    Set single bit value of a port register.\n\n"
913                 );
914         }
915         if (show_all || !strcmp(res->section, "filters")) {
916
917                 cmdline_printf(
918                         cl,
919                         "\n"
920                         "filters:\n"
921                         "--------\n\n"
922
923                         "ethertype_filter (port_id) (add|del)"
924                         " (mac_addr|mac_ignr) (mac_address) ethertype"
925                         " (ether_type) (drop|fwd) queue (queue_id)\n"
926                         "    Add/Del an ethertype filter.\n\n"
927
928                         "2tuple_filter (port_id) (add|del)"
929                         " dst_port (dst_port_value) protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 2tuple filter.\n\n"
933
934                         "5tuple_filter (port_id) (add|del)"
935                         " dst_ip (dst_address) src_ip (src_address)"
936                         " dst_port (dst_port_value) src_port (src_port_value)"
937                         " protocol (protocol_value)"
938                         " mask (mask_value) tcp_flags (tcp_flags_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a 5tuple filter.\n\n"
941
942                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
943                         "    Add/Del syn filter.\n\n"
944
945                         "flex_filter (port_id) (add|del) len (len_value)"
946                         " bytes (bytes_value) mask (mask_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a flex filter.\n\n"
949
950                         "flow_director_filter (port_id) mode IP (add|del|update)"
951                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
952                         " src (src_ip_address) dst (dst_ip_address)"
953                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
954                         " vlan (vlan_value) flexbytes (flexbytes_value)"
955                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
956                         " fd_id (fd_id_value)\n"
957                         "    Add/Del an IP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
961                         " src (src_ip_address) (src_port)"
962                         " dst (dst_ip_address) (dst_port)"
963                         " tos (tos_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-sctp|ipv6-sctp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tag (verification_tag) "
974                         " tos (tos_value) ttl (ttl_value)"
975                         " vlan (vlan_value)"
976                         " flexbytes (flexbytes_value) (drop|fwd)"
977                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
978                         "    Add/Del a SCTP type flow director filter.\n\n"
979
980                         "flow_director_filter (port_id) mode IP (add|del|update)"
981                         " flow l2_payload ether (ethertype)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a l2 payload type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
987                         " mac (mac_address) vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a Tunnel flow director filter.\n\n"
998
999                         "flush_flow_director (port_id)\n"
1000                         "    Flush all flow director entries of a device.\n\n"
1001
1002                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1003                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1004                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1005                         "    Set flow director IP mask.\n\n"
1006
1007                         "flow_director_mask (port_id) mode MAC-VLAN"
1008                         " vlan (vlan_value)\n"
1009                         "    Set flow director MAC-VLAN mask.\n\n"
1010
1011                         "flow_director_mask (port_id) mode Tunnel"
1012                         " vlan (vlan_value) mac (mac_value)"
1013                         " tunnel-type (tunnel_type_value)"
1014                         " tunnel-id (tunnel_id_value)\n"
1015                         "    Set flow director Tunnel mask.\n\n"
1016
1017                         "flow_director_flex_mask (port_id)"
1018                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1019                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1020                         " (mask)\n"
1021                         "    Configure mask of flex payload.\n\n"
1022
1023                         "flow_director_flex_payload (port_id)"
1024                         " (raw|l2|l3|l4) (config)\n"
1025                         "    Configure flex payload selection.\n\n"
1026
1027                         "get_sym_hash_ena_per_port (port_id)\n"
1028                         "    get symmetric hash enable configuration per port.\n\n"
1029
1030                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1031                         "    set symmetric hash enable configuration per port"
1032                         " to enable or disable.\n\n"
1033
1034                         "get_hash_global_config (port_id)\n"
1035                         "    Get the global configurations of hash filters.\n\n"
1036
1037                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1038                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1039                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1040                         " (enable|disable)\n"
1041                         "    Set the global configurations of hash filters.\n\n"
1042
1043                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1044                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1045                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1046                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1047                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1048                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1049                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1050                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1051                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1052                         "fld-8th|none) (select|add)\n"
1053                         "    Set the input set for hash.\n\n"
1054
1055                         "set_fdir_input_set (port_id) "
1056                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1058                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1059                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1060                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1061                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1062                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1063                         " (select|add)\n"
1064                         "    Set the input set for FDir.\n\n"
1065
1066                         "flow validate {port_id}"
1067                         " [group {group_id}] [priority {level}]"
1068                         " [ingress] [egress]"
1069                         " pattern {item} [/ {item} [...]] / end"
1070                         " actions {action} [/ {action} [...]] / end\n"
1071                         "    Check whether a flow rule can be created.\n\n"
1072
1073                         "flow create {port_id}"
1074                         " [group {group_id}] [priority {level}]"
1075                         " [ingress] [egress]"
1076                         " pattern {item} [/ {item} [...]] / end"
1077                         " actions {action} [/ {action} [...]] / end\n"
1078                         "    Create a flow rule.\n\n"
1079
1080                         "flow destroy {port_id} rule {rule_id} [...]\n"
1081                         "    Destroy specific flow rules.\n\n"
1082
1083                         "flow flush {port_id}\n"
1084                         "    Destroy all flow rules.\n\n"
1085
1086                         "flow query {port_id} {rule_id} {action}\n"
1087                         "    Query an existing flow rule.\n\n"
1088
1089                         "flow list {port_id} [group {group_id}] [...]\n"
1090                         "    List existing flow rules sorted by priority,"
1091                         " filtered by group identifiers.\n\n"
1092
1093                         "flow isolate {port_id} {boolean}\n"
1094                         "    Restrict ingress traffic to the defined"
1095                         " flow rules\n\n"
1096                 );
1097         }
1098 }
1099
1100 cmdline_parse_token_string_t cmd_help_long_help =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1102
1103 cmdline_parse_token_string_t cmd_help_long_section =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1105                         "all#control#display#config#"
1106                         "ports#registers#filters");
1107
1108 cmdline_parse_inst_t cmd_help_long = {
1109         .f = cmd_help_long_parsed,
1110         .data = NULL,
1111         .help_str = "help all|control|display|config|ports|register|filters: "
1112                 "Show help",
1113         .tokens = {
1114                 (void *)&cmd_help_long_help,
1115                 (void *)&cmd_help_long_section,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 /* *** start/stop/close all ports *** */
1122 struct cmd_operate_port_result {
1123         cmdline_fixed_string_t keyword;
1124         cmdline_fixed_string_t name;
1125         cmdline_fixed_string_t value;
1126 };
1127
1128 static void cmd_operate_port_parsed(void *parsed_result,
1129                                 __attribute__((unused)) struct cmdline *cl,
1130                                 __attribute__((unused)) void *data)
1131 {
1132         struct cmd_operate_port_result *res = parsed_result;
1133
1134         if (!strcmp(res->name, "start"))
1135                 start_port(RTE_PORT_ALL);
1136         else if (!strcmp(res->name, "stop"))
1137                 stop_port(RTE_PORT_ALL);
1138         else if (!strcmp(res->name, "close"))
1139                 close_port(RTE_PORT_ALL);
1140         else if (!strcmp(res->name, "reset"))
1141                 reset_port(RTE_PORT_ALL);
1142         else
1143                 printf("Unknown parameter\n");
1144 }
1145
1146 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1148                                                                 "port");
1149 cmdline_parse_token_string_t cmd_operate_port_all_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1151                                                 "start#stop#close#reset");
1152 cmdline_parse_token_string_t cmd_operate_port_all_all =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1154
1155 cmdline_parse_inst_t cmd_operate_port = {
1156         .f = cmd_operate_port_parsed,
1157         .data = NULL,
1158         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1159         .tokens = {
1160                 (void *)&cmd_operate_port_all_cmd,
1161                 (void *)&cmd_operate_port_all_port,
1162                 (void *)&cmd_operate_port_all_all,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** start/stop/close specific port *** */
1168 struct cmd_operate_specific_port_result {
1169         cmdline_fixed_string_t keyword;
1170         cmdline_fixed_string_t name;
1171         uint8_t value;
1172 };
1173
1174 static void cmd_operate_specific_port_parsed(void *parsed_result,
1175                         __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_operate_specific_port_result *res = parsed_result;
1179
1180         if (!strcmp(res->name, "start"))
1181                 start_port(res->value);
1182         else if (!strcmp(res->name, "stop"))
1183                 stop_port(res->value);
1184         else if (!strcmp(res->name, "close"))
1185                 close_port(res->value);
1186         else if (!strcmp(res->name, "reset"))
1187                 reset_port(res->value);
1188         else
1189                 printf("Unknown parameter\n");
1190 }
1191
1192 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                         keyword, "port");
1195 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                 name, "start#stop#close#reset");
1198 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1199         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                         value, UINT8);
1201
1202 cmdline_parse_inst_t cmd_operate_specific_port = {
1203         .f = cmd_operate_specific_port_parsed,
1204         .data = NULL,
1205         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1206         .tokens = {
1207                 (void *)&cmd_operate_specific_port_cmd,
1208                 (void *)&cmd_operate_specific_port_port,
1209                 (void *)&cmd_operate_specific_port_id,
1210                 NULL,
1211         },
1212 };
1213
1214 /* *** attach a specified port *** */
1215 struct cmd_operate_attach_port_result {
1216         cmdline_fixed_string_t port;
1217         cmdline_fixed_string_t keyword;
1218         cmdline_fixed_string_t identifier;
1219 };
1220
1221 static void cmd_operate_attach_port_parsed(void *parsed_result,
1222                                 __attribute__((unused)) struct cmdline *cl,
1223                                 __attribute__((unused)) void *data)
1224 {
1225         struct cmd_operate_attach_port_result *res = parsed_result;
1226
1227         if (!strcmp(res->keyword, "attach"))
1228                 attach_port(res->identifier);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         port, "port");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         keyword, "attach");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         identifier, NULL);
1242
1243 cmdline_parse_inst_t cmd_operate_attach_port = {
1244         .f = cmd_operate_attach_port_parsed,
1245         .data = NULL,
1246         .help_str = "port attach <identifier>: "
1247                 "(identifier: pci address or virtual dev name)",
1248         .tokens = {
1249                 (void *)&cmd_operate_attach_port_port,
1250                 (void *)&cmd_operate_attach_port_keyword,
1251                 (void *)&cmd_operate_attach_port_identifier,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** detach a specified port *** */
1257 struct cmd_operate_detach_port_result {
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t keyword;
1260         portid_t port_id;
1261 };
1262
1263 static void cmd_operate_detach_port_parsed(void *parsed_result,
1264                                 __attribute__((unused)) struct cmdline *cl,
1265                                 __attribute__((unused)) void *data)
1266 {
1267         struct cmd_operate_detach_port_result *res = parsed_result;
1268
1269         if (!strcmp(res->keyword, "detach"))
1270                 detach_port(res->port_id);
1271         else
1272                 printf("Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         port, "port");
1278 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         keyword, "detach");
1281 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         port_id, UINT16);
1284
1285 cmdline_parse_inst_t cmd_operate_detach_port = {
1286         .f = cmd_operate_detach_port_parsed,
1287         .data = NULL,
1288         .help_str = "port detach <port_id>",
1289         .tokens = {
1290                 (void *)&cmd_operate_detach_port_port,
1291                 (void *)&cmd_operate_detach_port_keyword,
1292                 (void *)&cmd_operate_detach_port_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** configure speed for all ports *** */
1298 struct cmd_config_speed_all {
1299         cmdline_fixed_string_t port;
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t all;
1302         cmdline_fixed_string_t item1;
1303         cmdline_fixed_string_t item2;
1304         cmdline_fixed_string_t value1;
1305         cmdline_fixed_string_t value2;
1306 };
1307
1308 static int
1309 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1310 {
1311
1312         int duplex;
1313
1314         if (!strcmp(duplexstr, "half")) {
1315                 duplex = ETH_LINK_HALF_DUPLEX;
1316         } else if (!strcmp(duplexstr, "full")) {
1317                 duplex = ETH_LINK_FULL_DUPLEX;
1318         } else if (!strcmp(duplexstr, "auto")) {
1319                 duplex = ETH_LINK_FULL_DUPLEX;
1320         } else {
1321                 printf("Unknown duplex parameter\n");
1322                 return -1;
1323         }
1324
1325         if (!strcmp(speedstr, "10")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1328         } else if (!strcmp(speedstr, "100")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1331         } else {
1332                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1333                         printf("Invalid speed/duplex parameters\n");
1334                         return -1;
1335                 }
1336                 if (!strcmp(speedstr, "1000")) {
1337                         *speed = ETH_LINK_SPEED_1G;
1338                 } else if (!strcmp(speedstr, "10000")) {
1339                         *speed = ETH_LINK_SPEED_10G;
1340                 } else if (!strcmp(speedstr, "25000")) {
1341                         *speed = ETH_LINK_SPEED_25G;
1342                 } else if (!strcmp(speedstr, "40000")) {
1343                         *speed = ETH_LINK_SPEED_40G;
1344                 } else if (!strcmp(speedstr, "50000")) {
1345                         *speed = ETH_LINK_SPEED_50G;
1346                 } else if (!strcmp(speedstr, "100000")) {
1347                         *speed = ETH_LINK_SPEED_100G;
1348                 } else if (!strcmp(speedstr, "auto")) {
1349                         *speed = ETH_LINK_SPEED_AUTONEG;
1350                 } else {
1351                         printf("Unknown speed parameter\n");
1352                         return -1;
1353                 }
1354         }
1355
1356         return 0;
1357 }
1358
1359 static void
1360 cmd_config_speed_all_parsed(void *parsed_result,
1361                         __attribute__((unused)) struct cmdline *cl,
1362                         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_config_speed_all *res = parsed_result;
1365         uint32_t link_speed;
1366         portid_t pid;
1367
1368         if (!all_ports_stopped()) {
1369                 printf("Please stop all ports first\n");
1370                 return;
1371         }
1372
1373         if (parse_and_check_speed_duplex(res->value1, res->value2,
1374                         &link_speed) < 0)
1375                 return;
1376
1377         RTE_ETH_FOREACH_DEV(pid) {
1378                 ports[pid].dev_conf.link_speeds = link_speed;
1379         }
1380
1381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1382 }
1383
1384 cmdline_parse_token_string_t cmd_config_speed_all_port =
1385         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1386 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1388                                                         "config");
1389 cmdline_parse_token_string_t cmd_config_speed_all_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1391 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1393 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1395                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1400                                                 "half#full#auto");
1401
1402 cmdline_parse_inst_t cmd_config_speed_all = {
1403         .f = cmd_config_speed_all_parsed,
1404         .data = NULL,
1405         .help_str = "port config all speed "
1406                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1407                                                         "half|full|auto",
1408         .tokens = {
1409                 (void *)&cmd_config_speed_all_port,
1410                 (void *)&cmd_config_speed_all_keyword,
1411                 (void *)&cmd_config_speed_all_all,
1412                 (void *)&cmd_config_speed_all_item1,
1413                 (void *)&cmd_config_speed_all_value1,
1414                 (void *)&cmd_config_speed_all_item2,
1415                 (void *)&cmd_config_speed_all_value2,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** configure speed for specific port *** */
1421 struct cmd_config_speed_specific {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         uint8_t id;
1425         cmdline_fixed_string_t item1;
1426         cmdline_fixed_string_t item2;
1427         cmdline_fixed_string_t value1;
1428         cmdline_fixed_string_t value2;
1429 };
1430
1431 static void
1432 cmd_config_speed_specific_parsed(void *parsed_result,
1433                                 __attribute__((unused)) struct cmdline *cl,
1434                                 __attribute__((unused)) void *data)
1435 {
1436         struct cmd_config_speed_specific *res = parsed_result;
1437         uint32_t link_speed;
1438
1439         if (!all_ports_stopped()) {
1440                 printf("Please stop all ports first\n");
1441                 return;
1442         }
1443
1444         if (port_id_is_invalid(res->id, ENABLED_WARN))
1445                 return;
1446
1447         if (parse_and_check_speed_duplex(res->value1, res->value2,
1448                         &link_speed) < 0)
1449                 return;
1450
1451         ports[res->id].dev_conf.link_speeds = link_speed;
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456
1457 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1459                                                                 "port");
1460 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1462                                                                 "config");
1463 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1464         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1465 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1467                                                                 "speed");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1470                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1473                                                                 "duplex");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1476                                                         "half#full#auto");
1477
1478 cmdline_parse_inst_t cmd_config_speed_specific = {
1479         .f = cmd_config_speed_specific_parsed,
1480         .data = NULL,
1481         .help_str = "port config <port_id> speed "
1482                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1483                                                         "half|full|auto",
1484         .tokens = {
1485                 (void *)&cmd_config_speed_specific_port,
1486                 (void *)&cmd_config_speed_specific_keyword,
1487                 (void *)&cmd_config_speed_specific_id,
1488                 (void *)&cmd_config_speed_specific_item1,
1489                 (void *)&cmd_config_speed_specific_value1,
1490                 (void *)&cmd_config_speed_specific_item2,
1491                 (void *)&cmd_config_speed_specific_value2,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure txq/rxq, txd/rxd *** */
1497 struct cmd_config_rx_tx {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t name;
1502         uint16_t value;
1503 };
1504
1505 static void
1506 cmd_config_rx_tx_parsed(void *parsed_result,
1507                         __attribute__((unused)) struct cmdline *cl,
1508                         __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_rx_tx *res = parsed_result;
1511
1512         if (!all_ports_stopped()) {
1513                 printf("Please stop all ports first\n");
1514                 return;
1515         }
1516         if (!strcmp(res->name, "rxq")) {
1517                 if (!res->value && !nb_txq) {
1518                         printf("Warning: Either rx or tx queues should be non zero\n");
1519                         return;
1520                 }
1521                 nb_rxq = res->value;
1522         }
1523         else if (!strcmp(res->name, "txq")) {
1524                 if (!res->value && !nb_rxq) {
1525                         printf("Warning: Either rx or tx queues should be non zero\n");
1526                         return;
1527                 }
1528                 nb_txq = res->value;
1529         }
1530         else if (!strcmp(res->name, "rxd")) {
1531                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1532                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1533                                         res->value, RTE_TEST_RX_DESC_MAX);
1534                         return;
1535                 }
1536                 nb_rxd = res->value;
1537         } else if (!strcmp(res->name, "txd")) {
1538                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1539                         printf("txd %d invalid - must be > 0 && <= %d\n",
1540                                         res->value, RTE_TEST_TX_DESC_MAX);
1541                         return;
1542                 }
1543                 nb_txd = res->value;
1544         } else {
1545                 printf("Unknown parameter\n");
1546                 return;
1547         }
1548
1549         fwd_config_setup();
1550
1551         init_port_config();
1552
1553         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1558 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1560 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1562 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1564                                                 "rxq#txq#rxd#txd");
1565 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1566         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1567
1568 cmdline_parse_inst_t cmd_config_rx_tx = {
1569         .f = cmd_config_rx_tx_parsed,
1570         .data = NULL,
1571         .help_str = "port config all rxq|txq|rxd|txd <value>",
1572         .tokens = {
1573                 (void *)&cmd_config_rx_tx_port,
1574                 (void *)&cmd_config_rx_tx_keyword,
1575                 (void *)&cmd_config_rx_tx_all,
1576                 (void *)&cmd_config_rx_tx_name,
1577                 (void *)&cmd_config_rx_tx_value,
1578                 NULL,
1579         },
1580 };
1581
1582 /* *** config max packet length *** */
1583 struct cmd_config_max_pkt_len_result {
1584         cmdline_fixed_string_t port;
1585         cmdline_fixed_string_t keyword;
1586         cmdline_fixed_string_t all;
1587         cmdline_fixed_string_t name;
1588         uint32_t value;
1589 };
1590
1591 static void
1592 cmd_config_max_pkt_len_parsed(void *parsed_result,
1593                                 __attribute__((unused)) struct cmdline *cl,
1594                                 __attribute__((unused)) void *data)
1595 {
1596         struct cmd_config_max_pkt_len_result *res = parsed_result;
1597         uint64_t rx_offloads = rx_mode.offloads;
1598
1599         if (!all_ports_stopped()) {
1600                 printf("Please stop all ports first\n");
1601                 return;
1602         }
1603
1604         if (!strcmp(res->name, "max-pkt-len")) {
1605                 if (res->value < ETHER_MIN_LEN) {
1606                         printf("max-pkt-len can not be less than %d\n",
1607                                                         ETHER_MIN_LEN);
1608                         return;
1609                 }
1610                 if (res->value == rx_mode.max_rx_pkt_len)
1611                         return;
1612
1613                 rx_mode.max_rx_pkt_len = res->value;
1614                 if (res->value > ETHER_MAX_LEN)
1615                         rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1616                 else
1617                         rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1618         } else {
1619                 printf("Unknown parameter\n");
1620                 return;
1621         }
1622
1623         rx_mode.offloads = rx_offloads;
1624
1625         init_port_config();
1626
1627         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1628 }
1629
1630 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1632                                                                 "port");
1633 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1635                                                                 "config");
1636 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1638                                                                 "all");
1639 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1641                                                                 "max-pkt-len");
1642 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1643         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1644                                                                 UINT32);
1645
1646 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1647         .f = cmd_config_max_pkt_len_parsed,
1648         .data = NULL,
1649         .help_str = "port config all max-pkt-len <value>",
1650         .tokens = {
1651                 (void *)&cmd_config_max_pkt_len_port,
1652                 (void *)&cmd_config_max_pkt_len_keyword,
1653                 (void *)&cmd_config_max_pkt_len_all,
1654                 (void *)&cmd_config_max_pkt_len_name,
1655                 (void *)&cmd_config_max_pkt_len_value,
1656                 NULL,
1657         },
1658 };
1659
1660 /* *** configure port MTU *** */
1661 struct cmd_config_mtu_result {
1662         cmdline_fixed_string_t port;
1663         cmdline_fixed_string_t keyword;
1664         cmdline_fixed_string_t mtu;
1665         portid_t port_id;
1666         uint16_t value;
1667 };
1668
1669 static void
1670 cmd_config_mtu_parsed(void *parsed_result,
1671                       __attribute__((unused)) struct cmdline *cl,
1672                       __attribute__((unused)) void *data)
1673 {
1674         struct cmd_config_mtu_result *res = parsed_result;
1675
1676         if (res->value < ETHER_MIN_LEN) {
1677                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1678                 return;
1679         }
1680         port_mtu_set(res->port_id, res->value);
1681 }
1682
1683 cmdline_parse_token_string_t cmd_config_mtu_port =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1685                                  "port");
1686 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1688                                  "config");
1689 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1690         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1691                                  "mtu");
1692 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1693         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1694 cmdline_parse_token_num_t cmd_config_mtu_value =
1695         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1696
1697 cmdline_parse_inst_t cmd_config_mtu = {
1698         .f = cmd_config_mtu_parsed,
1699         .data = NULL,
1700         .help_str = "port config mtu <port_id> <value>",
1701         .tokens = {
1702                 (void *)&cmd_config_mtu_port,
1703                 (void *)&cmd_config_mtu_keyword,
1704                 (void *)&cmd_config_mtu_mtu,
1705                 (void *)&cmd_config_mtu_port_id,
1706                 (void *)&cmd_config_mtu_value,
1707                 NULL,
1708         },
1709 };
1710
1711 /* *** configure rx mode *** */
1712 struct cmd_config_rx_mode_flag {
1713         cmdline_fixed_string_t port;
1714         cmdline_fixed_string_t keyword;
1715         cmdline_fixed_string_t all;
1716         cmdline_fixed_string_t name;
1717         cmdline_fixed_string_t value;
1718 };
1719
1720 static void
1721 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1722                                 __attribute__((unused)) struct cmdline *cl,
1723                                 __attribute__((unused)) void *data)
1724 {
1725         struct cmd_config_rx_mode_flag *res = parsed_result;
1726         uint64_t rx_offloads = rx_mode.offloads;
1727
1728         if (!all_ports_stopped()) {
1729                 printf("Please stop all ports first\n");
1730                 return;
1731         }
1732
1733         if (!strcmp(res->name, "crc-strip")) {
1734                 if (!strcmp(res->value, "on"))
1735                         rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1736                 else if (!strcmp(res->value, "off"))
1737                         rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1738                 else {
1739                         printf("Unknown parameter\n");
1740                         return;
1741                 }
1742         } else if (!strcmp(res->name, "scatter")) {
1743                 if (!strcmp(res->value, "on")) {
1744                         rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1745                 } else if (!strcmp(res->value, "off")) {
1746                         rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1747                 } else {
1748                         printf("Unknown parameter\n");
1749                         return;
1750                 }
1751         } else if (!strcmp(res->name, "rx-cksum")) {
1752                 if (!strcmp(res->value, "on"))
1753                         rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1754                 else if (!strcmp(res->value, "off"))
1755                         rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1756                 else {
1757                         printf("Unknown parameter\n");
1758                         return;
1759                 }
1760         } else if (!strcmp(res->name, "rx-timestamp")) {
1761                 if (!strcmp(res->value, "on"))
1762                         rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1763                 else if (!strcmp(res->value, "off"))
1764                         rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1765                 else {
1766                         printf("Unknown parameter\n");
1767                         return;
1768                 }
1769         } else if (!strcmp(res->name, "hw-vlan")) {
1770                 if (!strcmp(res->value, "on")) {
1771                         rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1772                                         DEV_RX_OFFLOAD_VLAN_STRIP);
1773                 }
1774                 else if (!strcmp(res->value, "off")) {
1775                         rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1776                                         DEV_RX_OFFLOAD_VLAN_STRIP);
1777                 }
1778                 else {
1779                         printf("Unknown parameter\n");
1780                         return;
1781                 }
1782         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1783                 if (!strcmp(res->value, "on"))
1784                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1785                 else if (!strcmp(res->value, "off"))
1786                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1787                 else {
1788                         printf("Unknown parameter\n");
1789                         return;
1790                 }
1791         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1792                 if (!strcmp(res->value, "on"))
1793                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1794                 else if (!strcmp(res->value, "off"))
1795                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1796                 else {
1797                         printf("Unknown parameter\n");
1798                         return;
1799                 }
1800         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1801                 if (!strcmp(res->value, "on"))
1802                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1803                 else if (!strcmp(res->value, "off"))
1804                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1805                 else {
1806                         printf("Unknown parameter\n");
1807                         return;
1808                 }
1809         } else if (!strcmp(res->name, "drop-en")) {
1810                 if (!strcmp(res->value, "on"))
1811                         rx_drop_en = 1;
1812                 else if (!strcmp(res->value, "off"))
1813                         rx_drop_en = 0;
1814                 else {
1815                         printf("Unknown parameter\n");
1816                         return;
1817                 }
1818         } else {
1819                 printf("Unknown parameter\n");
1820                 return;
1821         }
1822         rx_mode.offloads = rx_offloads;
1823
1824         init_port_config();
1825
1826         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1827 }
1828
1829 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1830         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1831 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1832         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1833                                                                 "config");
1834 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1835         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1836 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1837         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1838                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1839                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1840 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1841         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1842                                                         "on#off");
1843
1844 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1845         .f = cmd_config_rx_mode_flag_parsed,
1846         .data = NULL,
1847         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1848                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1849         .tokens = {
1850                 (void *)&cmd_config_rx_mode_flag_port,
1851                 (void *)&cmd_config_rx_mode_flag_keyword,
1852                 (void *)&cmd_config_rx_mode_flag_all,
1853                 (void *)&cmd_config_rx_mode_flag_name,
1854                 (void *)&cmd_config_rx_mode_flag_value,
1855                 NULL,
1856         },
1857 };
1858
1859 /* *** configure rss *** */
1860 struct cmd_config_rss {
1861         cmdline_fixed_string_t port;
1862         cmdline_fixed_string_t keyword;
1863         cmdline_fixed_string_t all;
1864         cmdline_fixed_string_t name;
1865         cmdline_fixed_string_t value;
1866 };
1867
1868 static void
1869 cmd_config_rss_parsed(void *parsed_result,
1870                         __attribute__((unused)) struct cmdline *cl,
1871                         __attribute__((unused)) void *data)
1872 {
1873         struct cmd_config_rss *res = parsed_result;
1874         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1875         int diag;
1876         uint8_t i;
1877
1878         if (!strcmp(res->value, "all"))
1879                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1880                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1881                                         ETH_RSS_L2_PAYLOAD;
1882         else if (!strcmp(res->value, "ip"))
1883                 rss_conf.rss_hf = ETH_RSS_IP;
1884         else if (!strcmp(res->value, "udp"))
1885                 rss_conf.rss_hf = ETH_RSS_UDP;
1886         else if (!strcmp(res->value, "tcp"))
1887                 rss_conf.rss_hf = ETH_RSS_TCP;
1888         else if (!strcmp(res->value, "sctp"))
1889                 rss_conf.rss_hf = ETH_RSS_SCTP;
1890         else if (!strcmp(res->value, "ether"))
1891                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1892         else if (!strcmp(res->value, "port"))
1893                 rss_conf.rss_hf = ETH_RSS_PORT;
1894         else if (!strcmp(res->value, "vxlan"))
1895                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1896         else if (!strcmp(res->value, "geneve"))
1897                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1898         else if (!strcmp(res->value, "nvgre"))
1899                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1900         else if (!strcmp(res->value, "none"))
1901                 rss_conf.rss_hf = 0;
1902         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1903                                                 atoi(res->value) < 64)
1904                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1905         else {
1906                 printf("Unknown parameter\n");
1907                 return;
1908         }
1909         rss_conf.rss_key = NULL;
1910         for (i = 0; i < rte_eth_dev_count(); i++) {
1911                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1912                 if (diag < 0)
1913                         printf("Configuration of RSS hash at ethernet port %d "
1914                                 "failed with error (%d): %s.\n",
1915                                 i, -diag, strerror(-diag));
1916         }
1917 }
1918
1919 cmdline_parse_token_string_t cmd_config_rss_port =
1920         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1921 cmdline_parse_token_string_t cmd_config_rss_keyword =
1922         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1923 cmdline_parse_token_string_t cmd_config_rss_all =
1924         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1925 cmdline_parse_token_string_t cmd_config_rss_name =
1926         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1927 cmdline_parse_token_string_t cmd_config_rss_value =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1929
1930 cmdline_parse_inst_t cmd_config_rss = {
1931         .f = cmd_config_rss_parsed,
1932         .data = NULL,
1933         .help_str = "port config all rss "
1934                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1935         .tokens = {
1936                 (void *)&cmd_config_rss_port,
1937                 (void *)&cmd_config_rss_keyword,
1938                 (void *)&cmd_config_rss_all,
1939                 (void *)&cmd_config_rss_name,
1940                 (void *)&cmd_config_rss_value,
1941                 NULL,
1942         },
1943 };
1944
1945 /* *** configure rss hash key *** */
1946 struct cmd_config_rss_hash_key {
1947         cmdline_fixed_string_t port;
1948         cmdline_fixed_string_t config;
1949         portid_t port_id;
1950         cmdline_fixed_string_t rss_hash_key;
1951         cmdline_fixed_string_t rss_type;
1952         cmdline_fixed_string_t key;
1953 };
1954
1955 static uint8_t
1956 hexa_digit_to_value(char hexa_digit)
1957 {
1958         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1959                 return (uint8_t) (hexa_digit - '0');
1960         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1961                 return (uint8_t) ((hexa_digit - 'a') + 10);
1962         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1963                 return (uint8_t) ((hexa_digit - 'A') + 10);
1964         /* Invalid hexa digit */
1965         return 0xFF;
1966 }
1967
1968 static uint8_t
1969 parse_and_check_key_hexa_digit(char *key, int idx)
1970 {
1971         uint8_t hexa_v;
1972
1973         hexa_v = hexa_digit_to_value(key[idx]);
1974         if (hexa_v == 0xFF)
1975                 printf("invalid key: character %c at position %d is not a "
1976                        "valid hexa digit\n", key[idx], idx);
1977         return hexa_v;
1978 }
1979
1980 static void
1981 cmd_config_rss_hash_key_parsed(void *parsed_result,
1982                                __attribute__((unused)) struct cmdline *cl,
1983                                __attribute__((unused)) void *data)
1984 {
1985         struct cmd_config_rss_hash_key *res = parsed_result;
1986         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1987         uint8_t xdgt0;
1988         uint8_t xdgt1;
1989         int i;
1990         struct rte_eth_dev_info dev_info;
1991         uint8_t hash_key_size;
1992         uint32_t key_len;
1993
1994         memset(&dev_info, 0, sizeof(dev_info));
1995         rte_eth_dev_info_get(res->port_id, &dev_info);
1996         if (dev_info.hash_key_size > 0 &&
1997                         dev_info.hash_key_size <= sizeof(hash_key))
1998                 hash_key_size = dev_info.hash_key_size;
1999         else {
2000                 printf("dev_info did not provide a valid hash key size\n");
2001                 return;
2002         }
2003         /* Check the length of the RSS hash key */
2004         key_len = strlen(res->key);
2005         if (key_len != (hash_key_size * 2)) {
2006                 printf("key length: %d invalid - key must be a string of %d"
2007                            " hexa-decimal numbers\n",
2008                            (int) key_len, hash_key_size * 2);
2009                 return;
2010         }
2011         /* Translate RSS hash key into binary representation */
2012         for (i = 0; i < hash_key_size; i++) {
2013                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2014                 if (xdgt0 == 0xFF)
2015                         return;
2016                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2017                 if (xdgt1 == 0xFF)
2018                         return;
2019                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2020         }
2021         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2022                         hash_key_size);
2023 }
2024
2025 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2026         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2027 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2028         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2029                                  "config");
2030 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2031         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2032 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2034                                  rss_hash_key, "rss-hash-key");
2035 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2037                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2038                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2039                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2040                                  "ipv6-tcp-ex#ipv6-udp-ex");
2041 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2042         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2043
2044 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2045         .f = cmd_config_rss_hash_key_parsed,
2046         .data = NULL,
2047         .help_str = "port config <port_id> rss-hash-key "
2048                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2049                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2050                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2051                 "<string of hex digits (variable length, NIC dependent)>",
2052         .tokens = {
2053                 (void *)&cmd_config_rss_hash_key_port,
2054                 (void *)&cmd_config_rss_hash_key_config,
2055                 (void *)&cmd_config_rss_hash_key_port_id,
2056                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2057                 (void *)&cmd_config_rss_hash_key_rss_type,
2058                 (void *)&cmd_config_rss_hash_key_value,
2059                 NULL,
2060         },
2061 };
2062
2063 /* *** configure port rxq/txq start/stop *** */
2064 struct cmd_config_rxtx_queue {
2065         cmdline_fixed_string_t port;
2066         portid_t portid;
2067         cmdline_fixed_string_t rxtxq;
2068         uint16_t qid;
2069         cmdline_fixed_string_t opname;
2070 };
2071
2072 static void
2073 cmd_config_rxtx_queue_parsed(void *parsed_result,
2074                         __attribute__((unused)) struct cmdline *cl,
2075                         __attribute__((unused)) void *data)
2076 {
2077         struct cmd_config_rxtx_queue *res = parsed_result;
2078         uint8_t isrx;
2079         uint8_t isstart;
2080         int ret = 0;
2081
2082         if (test_done == 0) {
2083                 printf("Please stop forwarding first\n");
2084                 return;
2085         }
2086
2087         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2088                 return;
2089
2090         if (port_is_started(res->portid) != 1) {
2091                 printf("Please start port %u first\n", res->portid);
2092                 return;
2093         }
2094
2095         if (!strcmp(res->rxtxq, "rxq"))
2096                 isrx = 1;
2097         else if (!strcmp(res->rxtxq, "txq"))
2098                 isrx = 0;
2099         else {
2100                 printf("Unknown parameter\n");
2101                 return;
2102         }
2103
2104         if (isrx && rx_queue_id_is_invalid(res->qid))
2105                 return;
2106         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2107                 return;
2108
2109         if (!strcmp(res->opname, "start"))
2110                 isstart = 1;
2111         else if (!strcmp(res->opname, "stop"))
2112                 isstart = 0;
2113         else {
2114                 printf("Unknown parameter\n");
2115                 return;
2116         }
2117
2118         if (isstart && isrx)
2119                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2120         else if (!isstart && isrx)
2121                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2122         else if (isstart && !isrx)
2123                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2124         else
2125                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2126
2127         if (ret == -ENOTSUP)
2128                 printf("Function not supported in PMD driver\n");
2129 }
2130
2131 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2133 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2134         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2135 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2137 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2138         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2139 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2141                                                 "start#stop");
2142
2143 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2144         .f = cmd_config_rxtx_queue_parsed,
2145         .data = NULL,
2146         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2147         .tokens = {
2148                 (void *)&cmd_config_speed_all_port,
2149                 (void *)&cmd_config_rxtx_queue_portid,
2150                 (void *)&cmd_config_rxtx_queue_rxtxq,
2151                 (void *)&cmd_config_rxtx_queue_qid,
2152                 (void *)&cmd_config_rxtx_queue_opname,
2153                 NULL,
2154         },
2155 };
2156
2157 /* *** Configure RSS RETA *** */
2158 struct cmd_config_rss_reta {
2159         cmdline_fixed_string_t port;
2160         cmdline_fixed_string_t keyword;
2161         portid_t port_id;
2162         cmdline_fixed_string_t name;
2163         cmdline_fixed_string_t list_name;
2164         cmdline_fixed_string_t list_of_items;
2165 };
2166
2167 static int
2168 parse_reta_config(const char *str,
2169                   struct rte_eth_rss_reta_entry64 *reta_conf,
2170                   uint16_t nb_entries)
2171 {
2172         int i;
2173         unsigned size;
2174         uint16_t hash_index, idx, shift;
2175         uint16_t nb_queue;
2176         char s[256];
2177         const char *p, *p0 = str;
2178         char *end;
2179         enum fieldnames {
2180                 FLD_HASH_INDEX = 0,
2181                 FLD_QUEUE,
2182                 _NUM_FLD
2183         };
2184         unsigned long int_fld[_NUM_FLD];
2185         char *str_fld[_NUM_FLD];
2186
2187         while ((p = strchr(p0,'(')) != NULL) {
2188                 ++p;
2189                 if((p0 = strchr(p,')')) == NULL)
2190                         return -1;
2191
2192                 size = p0 - p;
2193                 if(size >= sizeof(s))
2194                         return -1;
2195
2196                 snprintf(s, sizeof(s), "%.*s", size, p);
2197                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2198                         return -1;
2199                 for (i = 0; i < _NUM_FLD; i++) {
2200                         errno = 0;
2201                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2202                         if (errno != 0 || end == str_fld[i] ||
2203                                         int_fld[i] > 65535)
2204                                 return -1;
2205                 }
2206
2207                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2208                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2209
2210                 if (hash_index >= nb_entries) {
2211                         printf("Invalid RETA hash index=%d\n", hash_index);
2212                         return -1;
2213                 }
2214
2215                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2216                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2217                 reta_conf[idx].mask |= (1ULL << shift);
2218                 reta_conf[idx].reta[shift] = nb_queue;
2219         }
2220
2221         return 0;
2222 }
2223
2224 static void
2225 cmd_set_rss_reta_parsed(void *parsed_result,
2226                         __attribute__((unused)) struct cmdline *cl,
2227                         __attribute__((unused)) void *data)
2228 {
2229         int ret;
2230         struct rte_eth_dev_info dev_info;
2231         struct rte_eth_rss_reta_entry64 reta_conf[8];
2232         struct cmd_config_rss_reta *res = parsed_result;
2233
2234         memset(&dev_info, 0, sizeof(dev_info));
2235         rte_eth_dev_info_get(res->port_id, &dev_info);
2236         if (dev_info.reta_size == 0) {
2237                 printf("Redirection table size is 0 which is "
2238                                         "invalid for RSS\n");
2239                 return;
2240         } else
2241                 printf("The reta size of port %d is %u\n",
2242                         res->port_id, dev_info.reta_size);
2243         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2244                 printf("Currently do not support more than %u entries of "
2245                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2246                 return;
2247         }
2248
2249         memset(reta_conf, 0, sizeof(reta_conf));
2250         if (!strcmp(res->list_name, "reta")) {
2251                 if (parse_reta_config(res->list_of_items, reta_conf,
2252                                                 dev_info.reta_size)) {
2253                         printf("Invalid RSS Redirection Table "
2254                                         "config entered\n");
2255                         return;
2256                 }
2257                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2258                                 reta_conf, dev_info.reta_size);
2259                 if (ret != 0)
2260                         printf("Bad redirection table parameter, "
2261                                         "return code = %d \n", ret);
2262         }
2263 }
2264
2265 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2267 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2268         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2269 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2270         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2271 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2273 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2275 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2277                                  NULL);
2278 cmdline_parse_inst_t cmd_config_rss_reta = {
2279         .f = cmd_set_rss_reta_parsed,
2280         .data = NULL,
2281         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2282         .tokens = {
2283                 (void *)&cmd_config_rss_reta_port,
2284                 (void *)&cmd_config_rss_reta_keyword,
2285                 (void *)&cmd_config_rss_reta_port_id,
2286                 (void *)&cmd_config_rss_reta_name,
2287                 (void *)&cmd_config_rss_reta_list_name,
2288                 (void *)&cmd_config_rss_reta_list_of_items,
2289                 NULL,
2290         },
2291 };
2292
2293 /* *** SHOW PORT RETA INFO *** */
2294 struct cmd_showport_reta {
2295         cmdline_fixed_string_t show;
2296         cmdline_fixed_string_t port;
2297         portid_t port_id;
2298         cmdline_fixed_string_t rss;
2299         cmdline_fixed_string_t reta;
2300         uint16_t size;
2301         cmdline_fixed_string_t list_of_items;
2302 };
2303
2304 static int
2305 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2306                            uint16_t nb_entries,
2307                            char *str)
2308 {
2309         uint32_t size;
2310         const char *p, *p0 = str;
2311         char s[256];
2312         char *end;
2313         char *str_fld[8];
2314         uint16_t i;
2315         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2316                         RTE_RETA_GROUP_SIZE;
2317         int ret;
2318
2319         p = strchr(p0, '(');
2320         if (p == NULL)
2321                 return -1;
2322         p++;
2323         p0 = strchr(p, ')');
2324         if (p0 == NULL)
2325                 return -1;
2326         size = p0 - p;
2327         if (size >= sizeof(s)) {
2328                 printf("The string size exceeds the internal buffer size\n");
2329                 return -1;
2330         }
2331         snprintf(s, sizeof(s), "%.*s", size, p);
2332         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2333         if (ret <= 0 || ret != num) {
2334                 printf("The bits of masks do not match the number of "
2335                                         "reta entries: %u\n", num);
2336                 return -1;
2337         }
2338         for (i = 0; i < ret; i++)
2339                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2340
2341         return 0;
2342 }
2343
2344 static void
2345 cmd_showport_reta_parsed(void *parsed_result,
2346                          __attribute__((unused)) struct cmdline *cl,
2347                          __attribute__((unused)) void *data)
2348 {
2349         struct cmd_showport_reta *res = parsed_result;
2350         struct rte_eth_rss_reta_entry64 reta_conf[8];
2351         struct rte_eth_dev_info dev_info;
2352         uint16_t max_reta_size;
2353
2354         memset(&dev_info, 0, sizeof(dev_info));
2355         rte_eth_dev_info_get(res->port_id, &dev_info);
2356         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2357         if (res->size == 0 || res->size > max_reta_size) {
2358                 printf("Invalid redirection table size: %u (1-%u)\n",
2359                         res->size, max_reta_size);
2360                 return;
2361         }
2362
2363         memset(reta_conf, 0, sizeof(reta_conf));
2364         if (showport_parse_reta_config(reta_conf, res->size,
2365                                 res->list_of_items) < 0) {
2366                 printf("Invalid string: %s for reta masks\n",
2367                                         res->list_of_items);
2368                 return;
2369         }
2370         port_rss_reta_info(res->port_id, reta_conf, res->size);
2371 }
2372
2373 cmdline_parse_token_string_t cmd_showport_reta_show =
2374         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2375 cmdline_parse_token_string_t cmd_showport_reta_port =
2376         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2377 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2378         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2379 cmdline_parse_token_string_t cmd_showport_reta_rss =
2380         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2381 cmdline_parse_token_string_t cmd_showport_reta_reta =
2382         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2383 cmdline_parse_token_num_t cmd_showport_reta_size =
2384         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2385 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2386         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2387                                         list_of_items, NULL);
2388
2389 cmdline_parse_inst_t cmd_showport_reta = {
2390         .f = cmd_showport_reta_parsed,
2391         .data = NULL,
2392         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2393         .tokens = {
2394                 (void *)&cmd_showport_reta_show,
2395                 (void *)&cmd_showport_reta_port,
2396                 (void *)&cmd_showport_reta_port_id,
2397                 (void *)&cmd_showport_reta_rss,
2398                 (void *)&cmd_showport_reta_reta,
2399                 (void *)&cmd_showport_reta_size,
2400                 (void *)&cmd_showport_reta_list_of_items,
2401                 NULL,
2402         },
2403 };
2404
2405 /* *** Show RSS hash configuration *** */
2406 struct cmd_showport_rss_hash {
2407         cmdline_fixed_string_t show;
2408         cmdline_fixed_string_t port;
2409         portid_t port_id;
2410         cmdline_fixed_string_t rss_hash;
2411         cmdline_fixed_string_t rss_type;
2412         cmdline_fixed_string_t key; /* optional argument */
2413 };
2414
2415 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2416                                 __attribute__((unused)) struct cmdline *cl,
2417                                 void *show_rss_key)
2418 {
2419         struct cmd_showport_rss_hash *res = parsed_result;
2420
2421         port_rss_hash_conf_show(res->port_id, res->rss_type,
2422                                 show_rss_key != NULL);
2423 }
2424
2425 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2426         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2427 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2428         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2429 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2430         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2431 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2432         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2433                                  "rss-hash");
2434 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2435         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2436                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2437                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2438                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2439                                  "ipv6-tcp-ex#ipv6-udp-ex");
2440 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2441         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2442
2443 cmdline_parse_inst_t cmd_showport_rss_hash = {
2444         .f = cmd_showport_rss_hash_parsed,
2445         .data = NULL,
2446         .help_str = "show port <port_id> rss-hash "
2447                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2448                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2449                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2450         .tokens = {
2451                 (void *)&cmd_showport_rss_hash_show,
2452                 (void *)&cmd_showport_rss_hash_port,
2453                 (void *)&cmd_showport_rss_hash_port_id,
2454                 (void *)&cmd_showport_rss_hash_rss_hash,
2455                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2456                 NULL,
2457         },
2458 };
2459
2460 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2461         .f = cmd_showport_rss_hash_parsed,
2462         .data = (void *)1,
2463         .help_str = "show port <port_id> rss-hash "
2464                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2465                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2466                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2467         .tokens = {
2468                 (void *)&cmd_showport_rss_hash_show,
2469                 (void *)&cmd_showport_rss_hash_port,
2470                 (void *)&cmd_showport_rss_hash_port_id,
2471                 (void *)&cmd_showport_rss_hash_rss_hash,
2472                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2473                 (void *)&cmd_showport_rss_hash_rss_key,
2474                 NULL,
2475         },
2476 };
2477
2478 /* *** Configure DCB *** */
2479 struct cmd_config_dcb {
2480         cmdline_fixed_string_t port;
2481         cmdline_fixed_string_t config;
2482         portid_t port_id;
2483         cmdline_fixed_string_t dcb;
2484         cmdline_fixed_string_t vt;
2485         cmdline_fixed_string_t vt_en;
2486         uint8_t num_tcs;
2487         cmdline_fixed_string_t pfc;
2488         cmdline_fixed_string_t pfc_en;
2489 };
2490
2491 static void
2492 cmd_config_dcb_parsed(void *parsed_result,
2493                         __attribute__((unused)) struct cmdline *cl,
2494                         __attribute__((unused)) void *data)
2495 {
2496         struct cmd_config_dcb *res = parsed_result;
2497         portid_t port_id = res->port_id;
2498         struct rte_port *port;
2499         uint8_t pfc_en;
2500         int ret;
2501
2502         port = &ports[port_id];
2503         /** Check if the port is not started **/
2504         if (port->port_status != RTE_PORT_STOPPED) {
2505                 printf("Please stop port %d first\n", port_id);
2506                 return;
2507         }
2508
2509         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2510                 printf("The invalid number of traffic class,"
2511                         " only 4 or 8 allowed.\n");
2512                 return;
2513         }
2514
2515         if (nb_fwd_lcores < res->num_tcs) {
2516                 printf("nb_cores shouldn't be less than number of TCs.\n");
2517                 return;
2518         }
2519         if (!strncmp(res->pfc_en, "on", 2))
2520                 pfc_en = 1;
2521         else
2522                 pfc_en = 0;
2523
2524         /* DCB in VT mode */
2525         if (!strncmp(res->vt_en, "on", 2))
2526                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2527                                 (enum rte_eth_nb_tcs)res->num_tcs,
2528                                 pfc_en);
2529         else
2530                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2531                                 (enum rte_eth_nb_tcs)res->num_tcs,
2532                                 pfc_en);
2533
2534
2535         if (ret != 0) {
2536                 printf("Cannot initialize network ports.\n");
2537                 return;
2538         }
2539
2540         cmd_reconfig_device_queue(port_id, 1, 1);
2541 }
2542
2543 cmdline_parse_token_string_t cmd_config_dcb_port =
2544         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2545 cmdline_parse_token_string_t cmd_config_dcb_config =
2546         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2547 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2548         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2549 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2550         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2551 cmdline_parse_token_string_t cmd_config_dcb_vt =
2552         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2553 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2555 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2556         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2557 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2559 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2561
2562 cmdline_parse_inst_t cmd_config_dcb = {
2563         .f = cmd_config_dcb_parsed,
2564         .data = NULL,
2565         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2566         .tokens = {
2567                 (void *)&cmd_config_dcb_port,
2568                 (void *)&cmd_config_dcb_config,
2569                 (void *)&cmd_config_dcb_port_id,
2570                 (void *)&cmd_config_dcb_dcb,
2571                 (void *)&cmd_config_dcb_vt,
2572                 (void *)&cmd_config_dcb_vt_en,
2573                 (void *)&cmd_config_dcb_num_tcs,
2574                 (void *)&cmd_config_dcb_pfc,
2575                 (void *)&cmd_config_dcb_pfc_en,
2576                 NULL,
2577         },
2578 };
2579
2580 /* *** configure number of packets per burst *** */
2581 struct cmd_config_burst {
2582         cmdline_fixed_string_t port;
2583         cmdline_fixed_string_t keyword;
2584         cmdline_fixed_string_t all;
2585         cmdline_fixed_string_t name;
2586         uint16_t value;
2587 };
2588
2589 static void
2590 cmd_config_burst_parsed(void *parsed_result,
2591                         __attribute__((unused)) struct cmdline *cl,
2592                         __attribute__((unused)) void *data)
2593 {
2594         struct cmd_config_burst *res = parsed_result;
2595
2596         if (!all_ports_stopped()) {
2597                 printf("Please stop all ports first\n");
2598                 return;
2599         }
2600
2601         if (!strcmp(res->name, "burst")) {
2602                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2603                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2604                         return;
2605                 }
2606                 nb_pkt_per_burst = res->value;
2607         } else {
2608                 printf("Unknown parameter\n");
2609                 return;
2610         }
2611
2612         init_port_config();
2613
2614         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2615 }
2616
2617 cmdline_parse_token_string_t cmd_config_burst_port =
2618         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2619 cmdline_parse_token_string_t cmd_config_burst_keyword =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2621 cmdline_parse_token_string_t cmd_config_burst_all =
2622         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2623 cmdline_parse_token_string_t cmd_config_burst_name =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2625 cmdline_parse_token_num_t cmd_config_burst_value =
2626         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2627
2628 cmdline_parse_inst_t cmd_config_burst = {
2629         .f = cmd_config_burst_parsed,
2630         .data = NULL,
2631         .help_str = "port config all burst <value>",
2632         .tokens = {
2633                 (void *)&cmd_config_burst_port,
2634                 (void *)&cmd_config_burst_keyword,
2635                 (void *)&cmd_config_burst_all,
2636                 (void *)&cmd_config_burst_name,
2637                 (void *)&cmd_config_burst_value,
2638                 NULL,
2639         },
2640 };
2641
2642 /* *** configure rx/tx queues *** */
2643 struct cmd_config_thresh {
2644         cmdline_fixed_string_t port;
2645         cmdline_fixed_string_t keyword;
2646         cmdline_fixed_string_t all;
2647         cmdline_fixed_string_t name;
2648         uint8_t value;
2649 };
2650
2651 static void
2652 cmd_config_thresh_parsed(void *parsed_result,
2653                         __attribute__((unused)) struct cmdline *cl,
2654                         __attribute__((unused)) void *data)
2655 {
2656         struct cmd_config_thresh *res = parsed_result;
2657
2658         if (!all_ports_stopped()) {
2659                 printf("Please stop all ports first\n");
2660                 return;
2661         }
2662
2663         if (!strcmp(res->name, "txpt"))
2664                 tx_pthresh = res->value;
2665         else if(!strcmp(res->name, "txht"))
2666                 tx_hthresh = res->value;
2667         else if(!strcmp(res->name, "txwt"))
2668                 tx_wthresh = res->value;
2669         else if(!strcmp(res->name, "rxpt"))
2670                 rx_pthresh = res->value;
2671         else if(!strcmp(res->name, "rxht"))
2672                 rx_hthresh = res->value;
2673         else if(!strcmp(res->name, "rxwt"))
2674                 rx_wthresh = res->value;
2675         else {
2676                 printf("Unknown parameter\n");
2677                 return;
2678         }
2679
2680         init_port_config();
2681
2682         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2683 }
2684
2685 cmdline_parse_token_string_t cmd_config_thresh_port =
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2687 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2689 cmdline_parse_token_string_t cmd_config_thresh_all =
2690         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2691 cmdline_parse_token_string_t cmd_config_thresh_name =
2692         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2693                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2694 cmdline_parse_token_num_t cmd_config_thresh_value =
2695         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2696
2697 cmdline_parse_inst_t cmd_config_thresh = {
2698         .f = cmd_config_thresh_parsed,
2699         .data = NULL,
2700         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2701         .tokens = {
2702                 (void *)&cmd_config_thresh_port,
2703                 (void *)&cmd_config_thresh_keyword,
2704                 (void *)&cmd_config_thresh_all,
2705                 (void *)&cmd_config_thresh_name,
2706                 (void *)&cmd_config_thresh_value,
2707                 NULL,
2708         },
2709 };
2710
2711 /* *** configure free/rs threshold *** */
2712 struct cmd_config_threshold {
2713         cmdline_fixed_string_t port;
2714         cmdline_fixed_string_t keyword;
2715         cmdline_fixed_string_t all;
2716         cmdline_fixed_string_t name;
2717         uint16_t value;
2718 };
2719
2720 static void
2721 cmd_config_threshold_parsed(void *parsed_result,
2722                         __attribute__((unused)) struct cmdline *cl,
2723                         __attribute__((unused)) void *data)
2724 {
2725         struct cmd_config_threshold *res = parsed_result;
2726
2727         if (!all_ports_stopped()) {
2728                 printf("Please stop all ports first\n");
2729                 return;
2730         }
2731
2732         if (!strcmp(res->name, "txfreet"))
2733                 tx_free_thresh = res->value;
2734         else if (!strcmp(res->name, "txrst"))
2735                 tx_rs_thresh = res->value;
2736         else if (!strcmp(res->name, "rxfreet"))
2737                 rx_free_thresh = res->value;
2738         else {
2739                 printf("Unknown parameter\n");
2740                 return;
2741         }
2742
2743         init_port_config();
2744
2745         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2746 }
2747
2748 cmdline_parse_token_string_t cmd_config_threshold_port =
2749         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2750 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2751         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2752                                                                 "config");
2753 cmdline_parse_token_string_t cmd_config_threshold_all =
2754         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2755 cmdline_parse_token_string_t cmd_config_threshold_name =
2756         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2757                                                 "txfreet#txrst#rxfreet");
2758 cmdline_parse_token_num_t cmd_config_threshold_value =
2759         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2760
2761 cmdline_parse_inst_t cmd_config_threshold = {
2762         .f = cmd_config_threshold_parsed,
2763         .data = NULL,
2764         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2765         .tokens = {
2766                 (void *)&cmd_config_threshold_port,
2767                 (void *)&cmd_config_threshold_keyword,
2768                 (void *)&cmd_config_threshold_all,
2769                 (void *)&cmd_config_threshold_name,
2770                 (void *)&cmd_config_threshold_value,
2771                 NULL,
2772         },
2773 };
2774
2775 /* *** stop *** */
2776 struct cmd_stop_result {
2777         cmdline_fixed_string_t stop;
2778 };
2779
2780 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2781                             __attribute__((unused)) struct cmdline *cl,
2782                             __attribute__((unused)) void *data)
2783 {
2784         stop_packet_forwarding();
2785 }
2786
2787 cmdline_parse_token_string_t cmd_stop_stop =
2788         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2789
2790 cmdline_parse_inst_t cmd_stop = {
2791         .f = cmd_stop_parsed,
2792         .data = NULL,
2793         .help_str = "stop: Stop packet forwarding",
2794         .tokens = {
2795                 (void *)&cmd_stop_stop,
2796                 NULL,
2797         },
2798 };
2799
2800 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2801
2802 unsigned int
2803 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2804                 unsigned int *parsed_items, int check_unique_values)
2805 {
2806         unsigned int nb_item;
2807         unsigned int value;
2808         unsigned int i;
2809         unsigned int j;
2810         int value_ok;
2811         char c;
2812
2813         /*
2814          * First parse all items in the list and store their value.
2815          */
2816         value = 0;
2817         nb_item = 0;
2818         value_ok = 0;
2819         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2820                 c = str[i];
2821                 if ((c >= '0') && (c <= '9')) {
2822                         value = (unsigned int) (value * 10 + (c - '0'));
2823                         value_ok = 1;
2824                         continue;
2825                 }
2826                 if (c != ',') {
2827                         printf("character %c is not a decimal digit\n", c);
2828                         return 0;
2829                 }
2830                 if (! value_ok) {
2831                         printf("No valid value before comma\n");
2832                         return 0;
2833                 }
2834                 if (nb_item < max_items) {
2835                         parsed_items[nb_item] = value;
2836                         value_ok = 0;
2837                         value = 0;
2838                 }
2839                 nb_item++;
2840         }
2841         if (nb_item >= max_items) {
2842                 printf("Number of %s = %u > %u (maximum items)\n",
2843                        item_name, nb_item + 1, max_items);
2844                 return 0;
2845         }
2846         parsed_items[nb_item++] = value;
2847         if (! check_unique_values)
2848                 return nb_item;
2849
2850         /*
2851          * Then, check that all values in the list are differents.
2852          * No optimization here...
2853          */
2854         for (i = 0; i < nb_item; i++) {
2855                 for (j = i + 1; j < nb_item; j++) {
2856                         if (parsed_items[j] == parsed_items[i]) {
2857                                 printf("duplicated %s %u at index %u and %u\n",
2858                                        item_name, parsed_items[i], i, j);
2859                                 return 0;
2860                         }
2861                 }
2862         }
2863         return nb_item;
2864 }
2865
2866 struct cmd_set_list_result {
2867         cmdline_fixed_string_t cmd_keyword;
2868         cmdline_fixed_string_t list_name;
2869         cmdline_fixed_string_t list_of_items;
2870 };
2871
2872 static void cmd_set_list_parsed(void *parsed_result,
2873                                 __attribute__((unused)) struct cmdline *cl,
2874                                 __attribute__((unused)) void *data)
2875 {
2876         struct cmd_set_list_result *res;
2877         union {
2878                 unsigned int lcorelist[RTE_MAX_LCORE];
2879                 unsigned int portlist[RTE_MAX_ETHPORTS];
2880         } parsed_items;
2881         unsigned int nb_item;
2882
2883         if (test_done == 0) {
2884                 printf("Please stop forwarding first\n");
2885                 return;
2886         }
2887
2888         res = parsed_result;
2889         if (!strcmp(res->list_name, "corelist")) {
2890                 nb_item = parse_item_list(res->list_of_items, "core",
2891                                           RTE_MAX_LCORE,
2892                                           parsed_items.lcorelist, 1);
2893                 if (nb_item > 0) {
2894                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2895                         fwd_config_setup();
2896                 }
2897                 return;
2898         }
2899         if (!strcmp(res->list_name, "portlist")) {
2900                 nb_item = parse_item_list(res->list_of_items, "port",
2901                                           RTE_MAX_ETHPORTS,
2902                                           parsed_items.portlist, 1);
2903                 if (nb_item > 0) {
2904                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2905                         fwd_config_setup();
2906                 }
2907         }
2908 }
2909
2910 cmdline_parse_token_string_t cmd_set_list_keyword =
2911         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2912                                  "set");
2913 cmdline_parse_token_string_t cmd_set_list_name =
2914         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2915                                  "corelist#portlist");
2916 cmdline_parse_token_string_t cmd_set_list_of_items =
2917         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2918                                  NULL);
2919
2920 cmdline_parse_inst_t cmd_set_fwd_list = {
2921         .f = cmd_set_list_parsed,
2922         .data = NULL,
2923         .help_str = "set corelist|portlist <list0[,list1]*>",
2924         .tokens = {
2925                 (void *)&cmd_set_list_keyword,
2926                 (void *)&cmd_set_list_name,
2927                 (void *)&cmd_set_list_of_items,
2928                 NULL,
2929         },
2930 };
2931
2932 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2933
2934 struct cmd_setmask_result {
2935         cmdline_fixed_string_t set;
2936         cmdline_fixed_string_t mask;
2937         uint64_t hexavalue;
2938 };
2939
2940 static void cmd_set_mask_parsed(void *parsed_result,
2941                                 __attribute__((unused)) struct cmdline *cl,
2942                                 __attribute__((unused)) void *data)
2943 {
2944         struct cmd_setmask_result *res = parsed_result;
2945
2946         if (test_done == 0) {
2947                 printf("Please stop forwarding first\n");
2948                 return;
2949         }
2950         if (!strcmp(res->mask, "coremask")) {
2951                 set_fwd_lcores_mask(res->hexavalue);
2952                 fwd_config_setup();
2953         } else if (!strcmp(res->mask, "portmask")) {
2954                 set_fwd_ports_mask(res->hexavalue);
2955                 fwd_config_setup();
2956         }
2957 }
2958
2959 cmdline_parse_token_string_t cmd_setmask_set =
2960         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2961 cmdline_parse_token_string_t cmd_setmask_mask =
2962         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2963                                  "coremask#portmask");
2964 cmdline_parse_token_num_t cmd_setmask_value =
2965         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2966
2967 cmdline_parse_inst_t cmd_set_fwd_mask = {
2968         .f = cmd_set_mask_parsed,
2969         .data = NULL,
2970         .help_str = "set coremask|portmask <hexadecimal value>",
2971         .tokens = {
2972                 (void *)&cmd_setmask_set,
2973                 (void *)&cmd_setmask_mask,
2974                 (void *)&cmd_setmask_value,
2975                 NULL,
2976         },
2977 };
2978
2979 /*
2980  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2981  */
2982 struct cmd_set_result {
2983         cmdline_fixed_string_t set;
2984         cmdline_fixed_string_t what;
2985         uint16_t value;
2986 };
2987
2988 static void cmd_set_parsed(void *parsed_result,
2989                            __attribute__((unused)) struct cmdline *cl,
2990                            __attribute__((unused)) void *data)
2991 {
2992         struct cmd_set_result *res = parsed_result;
2993         if (!strcmp(res->what, "nbport")) {
2994                 set_fwd_ports_number(res->value);
2995                 fwd_config_setup();
2996         } else if (!strcmp(res->what, "nbcore")) {
2997                 set_fwd_lcores_number(res->value);
2998                 fwd_config_setup();
2999         } else if (!strcmp(res->what, "burst"))
3000                 set_nb_pkt_per_burst(res->value);
3001         else if (!strcmp(res->what, "verbose"))
3002                 set_verbose_level(res->value);
3003 }
3004
3005 cmdline_parse_token_string_t cmd_set_set =
3006         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3007 cmdline_parse_token_string_t cmd_set_what =
3008         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3009                                  "nbport#nbcore#burst#verbose");
3010 cmdline_parse_token_num_t cmd_set_value =
3011         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3012
3013 cmdline_parse_inst_t cmd_set_numbers = {
3014         .f = cmd_set_parsed,
3015         .data = NULL,
3016         .help_str = "set nbport|nbcore|burst|verbose <value>",
3017         .tokens = {
3018                 (void *)&cmd_set_set,
3019                 (void *)&cmd_set_what,
3020                 (void *)&cmd_set_value,
3021                 NULL,
3022         },
3023 };
3024
3025 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3026
3027 struct cmd_set_txpkts_result {
3028         cmdline_fixed_string_t cmd_keyword;
3029         cmdline_fixed_string_t txpkts;
3030         cmdline_fixed_string_t seg_lengths;
3031 };
3032
3033 static void
3034 cmd_set_txpkts_parsed(void *parsed_result,
3035                       __attribute__((unused)) struct cmdline *cl,
3036                       __attribute__((unused)) void *data)
3037 {
3038         struct cmd_set_txpkts_result *res;
3039         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3040         unsigned int nb_segs;
3041
3042         res = parsed_result;
3043         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3044                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3045         if (nb_segs > 0)
3046                 set_tx_pkt_segments(seg_lengths, nb_segs);
3047 }
3048
3049 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3050         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3051                                  cmd_keyword, "set");
3052 cmdline_parse_token_string_t cmd_set_txpkts_name =
3053         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3054                                  txpkts, "txpkts");
3055 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3056         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3057                                  seg_lengths, NULL);
3058
3059 cmdline_parse_inst_t cmd_set_txpkts = {
3060         .f = cmd_set_txpkts_parsed,
3061         .data = NULL,
3062         .help_str = "set txpkts <len0[,len1]*>",
3063         .tokens = {
3064                 (void *)&cmd_set_txpkts_keyword,
3065                 (void *)&cmd_set_txpkts_name,
3066                 (void *)&cmd_set_txpkts_lengths,
3067                 NULL,
3068         },
3069 };
3070
3071 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3072
3073 struct cmd_set_txsplit_result {
3074         cmdline_fixed_string_t cmd_keyword;
3075         cmdline_fixed_string_t txsplit;
3076         cmdline_fixed_string_t mode;
3077 };
3078
3079 static void
3080 cmd_set_txsplit_parsed(void *parsed_result,
3081                       __attribute__((unused)) struct cmdline *cl,
3082                       __attribute__((unused)) void *data)
3083 {
3084         struct cmd_set_txsplit_result *res;
3085
3086         res = parsed_result;
3087         set_tx_pkt_split(res->mode);
3088 }
3089
3090 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3091         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3092                                  cmd_keyword, "set");
3093 cmdline_parse_token_string_t cmd_set_txsplit_name =
3094         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3095                                  txsplit, "txsplit");
3096 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3097         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3098                                  mode, NULL);
3099
3100 cmdline_parse_inst_t cmd_set_txsplit = {
3101         .f = cmd_set_txsplit_parsed,
3102         .data = NULL,
3103         .help_str = "set txsplit on|off|rand",
3104         .tokens = {
3105                 (void *)&cmd_set_txsplit_keyword,
3106                 (void *)&cmd_set_txsplit_name,
3107                 (void *)&cmd_set_txsplit_mode,
3108                 NULL,
3109         },
3110 };
3111
3112 /* *** CONFIG TX QUEUE FLAGS *** */
3113
3114 struct cmd_config_txqflags_result {
3115         cmdline_fixed_string_t port;
3116         cmdline_fixed_string_t config;
3117         cmdline_fixed_string_t all;
3118         cmdline_fixed_string_t what;
3119         int32_t hexvalue;
3120 };
3121
3122 static void cmd_config_txqflags_parsed(void *parsed_result,
3123                                 __attribute__((unused)) struct cmdline *cl,
3124                                 __attribute__((unused)) void *data)
3125 {
3126         struct cmd_config_txqflags_result *res = parsed_result;
3127
3128         if (!all_ports_stopped()) {
3129                 printf("Please stop all ports first\n");
3130                 return;
3131         }
3132
3133         if (strcmp(res->what, "txqflags")) {
3134                 printf("Unknown parameter\n");
3135                 return;
3136         }
3137
3138         if (res->hexvalue >= 0) {
3139                 txq_flags = res->hexvalue;
3140         } else {
3141                 printf("txqflags must be >= 0\n");
3142                 return;
3143         }
3144
3145         init_port_config();
3146
3147         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3148 }
3149
3150 cmdline_parse_token_string_t cmd_config_txqflags_port =
3151         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3152                                  "port");
3153 cmdline_parse_token_string_t cmd_config_txqflags_config =
3154         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3155                                  "config");
3156 cmdline_parse_token_string_t cmd_config_txqflags_all =
3157         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3158                                  "all");
3159 cmdline_parse_token_string_t cmd_config_txqflags_what =
3160         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3161                                  "txqflags");
3162 cmdline_parse_token_num_t cmd_config_txqflags_value =
3163         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3164                                 hexvalue, INT32);
3165
3166 cmdline_parse_inst_t cmd_config_txqflags = {
3167         .f = cmd_config_txqflags_parsed,
3168         .data = NULL,
3169         .help_str = "port config all txqflags <value>",
3170         .tokens = {
3171                 (void *)&cmd_config_txqflags_port,
3172                 (void *)&cmd_config_txqflags_config,
3173                 (void *)&cmd_config_txqflags_all,
3174                 (void *)&cmd_config_txqflags_what,
3175                 (void *)&cmd_config_txqflags_value,
3176                 NULL,
3177         },
3178 };
3179
3180 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3181 struct cmd_rx_vlan_filter_all_result {
3182         cmdline_fixed_string_t rx_vlan;
3183         cmdline_fixed_string_t what;
3184         cmdline_fixed_string_t all;
3185         portid_t port_id;
3186 };
3187
3188 static void
3189 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3190                               __attribute__((unused)) struct cmdline *cl,
3191                               __attribute__((unused)) void *data)
3192 {
3193         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3194
3195         if (!strcmp(res->what, "add"))
3196                 rx_vlan_all_filter_set(res->port_id, 1);
3197         else
3198                 rx_vlan_all_filter_set(res->port_id, 0);
3199 }
3200
3201 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3202         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3203                                  rx_vlan, "rx_vlan");
3204 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3205         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3206                                  what, "add#rm");
3207 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3208         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3209                                  all, "all");
3210 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3211         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3212                               port_id, UINT16);
3213
3214 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3215         .f = cmd_rx_vlan_filter_all_parsed,
3216         .data = NULL,
3217         .help_str = "rx_vlan add|rm all <port_id>: "
3218                 "Add/Remove all identifiers to/from the set of VLAN "
3219                 "identifiers filtered by a port",
3220         .tokens = {
3221                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3222                 (void *)&cmd_rx_vlan_filter_all_what,
3223                 (void *)&cmd_rx_vlan_filter_all_all,
3224                 (void *)&cmd_rx_vlan_filter_all_portid,
3225                 NULL,
3226         },
3227 };
3228
3229 /* *** VLAN OFFLOAD SET ON A PORT *** */
3230 struct cmd_vlan_offload_result {
3231         cmdline_fixed_string_t vlan;
3232         cmdline_fixed_string_t set;
3233         cmdline_fixed_string_t vlan_type;
3234         cmdline_fixed_string_t what;
3235         cmdline_fixed_string_t on;
3236         cmdline_fixed_string_t port_id;
3237 };
3238
3239 static void
3240 cmd_vlan_offload_parsed(void *parsed_result,
3241                           __attribute__((unused)) struct cmdline *cl,
3242                           __attribute__((unused)) void *data)
3243 {
3244         int on;
3245         struct cmd_vlan_offload_result *res = parsed_result;
3246         char *str;
3247         int i, len = 0;
3248         portid_t port_id = 0;
3249         unsigned int tmp;
3250
3251         str = res->port_id;
3252         len = strnlen(str, STR_TOKEN_SIZE);
3253         i = 0;
3254         /* Get port_id first */
3255         while(i < len){
3256                 if(str[i] == ',')
3257                         break;
3258
3259                 i++;
3260         }
3261         str[i]='\0';
3262         tmp = strtoul(str, NULL, 0);
3263         /* If port_id greater that what portid_t can represent, return */
3264         if(tmp >= RTE_MAX_ETHPORTS)
3265                 return;
3266         port_id = (portid_t)tmp;
3267
3268         if (!strcmp(res->on, "on"))
3269                 on = 1;
3270         else
3271                 on = 0;
3272
3273         if (!strcmp(res->what, "strip"))
3274                 rx_vlan_strip_set(port_id,  on);
3275         else if(!strcmp(res->what, "stripq")){
3276                 uint16_t queue_id = 0;
3277
3278                 /* No queue_id, return */
3279                 if(i + 1 >= len) {
3280                         printf("must specify (port,queue_id)\n");
3281                         return;
3282                 }
3283                 tmp = strtoul(str + i + 1, NULL, 0);
3284                 /* If queue_id greater that what 16-bits can represent, return */
3285                 if(tmp > 0xffff)
3286                         return;
3287
3288                 queue_id = (uint16_t)tmp;
3289                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3290         }
3291         else if (!strcmp(res->what, "filter"))
3292                 rx_vlan_filter_set(port_id, on);
3293         else
3294                 vlan_extend_set(port_id, on);
3295
3296         return;
3297 }
3298
3299 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3300         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3301                                  vlan, "vlan");
3302 cmdline_parse_token_string_t cmd_vlan_offload_set =
3303         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3304                                  set, "set");
3305 cmdline_parse_token_string_t cmd_vlan_offload_what =
3306         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3307                                  what, "strip#filter#qinq#stripq");
3308 cmdline_parse_token_string_t cmd_vlan_offload_on =
3309         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3310                               on, "on#off");
3311 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3312         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3313                               port_id, NULL);
3314
3315 cmdline_parse_inst_t cmd_vlan_offload = {
3316         .f = cmd_vlan_offload_parsed,
3317         .data = NULL,
3318         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3319                 "<port_id[,queue_id]>: "
3320                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3321         .tokens = {
3322                 (void *)&cmd_vlan_offload_vlan,
3323                 (void *)&cmd_vlan_offload_set,
3324                 (void *)&cmd_vlan_offload_what,
3325                 (void *)&cmd_vlan_offload_on,
3326                 (void *)&cmd_vlan_offload_portid,
3327                 NULL,
3328         },
3329 };
3330
3331 /* *** VLAN TPID SET ON A PORT *** */
3332 struct cmd_vlan_tpid_result {
3333         cmdline_fixed_string_t vlan;
3334         cmdline_fixed_string_t set;
3335         cmdline_fixed_string_t vlan_type;
3336         cmdline_fixed_string_t what;
3337         uint16_t tp_id;
3338         portid_t port_id;
3339 };
3340
3341 static void
3342 cmd_vlan_tpid_parsed(void *parsed_result,
3343                           __attribute__((unused)) struct cmdline *cl,
3344                           __attribute__((unused)) void *data)
3345 {
3346         struct cmd_vlan_tpid_result *res = parsed_result;
3347         enum rte_vlan_type vlan_type;
3348
3349         if (!strcmp(res->vlan_type, "inner"))
3350                 vlan_type = ETH_VLAN_TYPE_INNER;
3351         else if (!strcmp(res->vlan_type, "outer"))
3352                 vlan_type = ETH_VLAN_TYPE_OUTER;
3353         else {
3354                 printf("Unknown vlan type\n");
3355                 return;
3356         }
3357         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3358 }
3359
3360 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3361         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3362                                  vlan, "vlan");
3363 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3364         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3365                                  set, "set");
3366 cmdline_parse_token_string_t cmd_vlan_type =
3367         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3368                                  vlan_type, "inner#outer");
3369 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3370         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3371                                  what, "tpid");
3372 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3373         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3374                               tp_id, UINT16);
3375 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3376         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3377                               port_id, UINT16);
3378
3379 cmdline_parse_inst_t cmd_vlan_tpid = {
3380         .f = cmd_vlan_tpid_parsed,
3381         .data = NULL,
3382         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3383                 "Set the VLAN Ether type",
3384         .tokens = {
3385                 (void *)&cmd_vlan_tpid_vlan,
3386                 (void *)&cmd_vlan_tpid_set,
3387                 (void *)&cmd_vlan_type,
3388                 (void *)&cmd_vlan_tpid_what,
3389                 (void *)&cmd_vlan_tpid_tpid,
3390                 (void *)&cmd_vlan_tpid_portid,
3391                 NULL,
3392         },
3393 };
3394
3395 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3396 struct cmd_rx_vlan_filter_result {
3397         cmdline_fixed_string_t rx_vlan;
3398         cmdline_fixed_string_t what;
3399         uint16_t vlan_id;
3400         portid_t port_id;
3401 };
3402
3403 static void
3404 cmd_rx_vlan_filter_parsed(void *parsed_result,
3405                           __attribute__((unused)) struct cmdline *cl,
3406                           __attribute__((unused)) void *data)
3407 {
3408         struct cmd_rx_vlan_filter_result *res = parsed_result;
3409
3410         if (!strcmp(res->what, "add"))
3411                 rx_vft_set(res->port_id, res->vlan_id, 1);
3412         else
3413                 rx_vft_set(res->port_id, res->vlan_id, 0);
3414 }
3415
3416 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3417         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3418                                  rx_vlan, "rx_vlan");
3419 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3420         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3421                                  what, "add#rm");
3422 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3423         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3424                               vlan_id, UINT16);
3425 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3426         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3427                               port_id, UINT16);
3428
3429 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3430         .f = cmd_rx_vlan_filter_parsed,
3431         .data = NULL,
3432         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3433                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3434                 "identifiers filtered by a port",
3435         .tokens = {
3436                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3437                 (void *)&cmd_rx_vlan_filter_what,
3438                 (void *)&cmd_rx_vlan_filter_vlanid,
3439                 (void *)&cmd_rx_vlan_filter_portid,
3440                 NULL,
3441         },
3442 };
3443
3444 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3445 struct cmd_tx_vlan_set_result {
3446         cmdline_fixed_string_t tx_vlan;
3447         cmdline_fixed_string_t set;
3448         portid_t port_id;
3449         uint16_t vlan_id;
3450 };
3451
3452 static void
3453 cmd_tx_vlan_set_parsed(void *parsed_result,
3454                        __attribute__((unused)) struct cmdline *cl,
3455                        __attribute__((unused)) void *data)
3456 {
3457         struct cmd_tx_vlan_set_result *res = parsed_result;
3458
3459         tx_vlan_set(res->port_id, res->vlan_id);
3460 }
3461
3462 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3463         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3464                                  tx_vlan, "tx_vlan");
3465 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3466         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3467                                  set, "set");
3468 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3469         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3470                               port_id, UINT16);
3471 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3472         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3473                               vlan_id, UINT16);
3474
3475 cmdline_parse_inst_t cmd_tx_vlan_set = {
3476         .f = cmd_tx_vlan_set_parsed,
3477         .data = NULL,
3478         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3479                 "Enable hardware insertion of a single VLAN header "
3480                 "with a given TAG Identifier in packets sent on a port",
3481         .tokens = {
3482                 (void *)&cmd_tx_vlan_set_tx_vlan,
3483                 (void *)&cmd_tx_vlan_set_set,
3484                 (void *)&cmd_tx_vlan_set_portid,
3485                 (void *)&cmd_tx_vlan_set_vlanid,
3486                 NULL,
3487         },
3488 };
3489
3490 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3491 struct cmd_tx_vlan_set_qinq_result {
3492         cmdline_fixed_string_t tx_vlan;
3493         cmdline_fixed_string_t set;
3494         portid_t port_id;
3495         uint16_t vlan_id;
3496         uint16_t vlan_id_outer;
3497 };
3498
3499 static void
3500 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3501                             __attribute__((unused)) struct cmdline *cl,
3502                             __attribute__((unused)) void *data)
3503 {
3504         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3505
3506         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3507 }
3508
3509 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3510         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3511                 tx_vlan, "tx_vlan");
3512 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3513         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3514                 set, "set");
3515 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3516         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3517                 port_id, UINT16);
3518 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3519         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3520                 vlan_id, UINT16);
3521 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3522         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3523                 vlan_id_outer, UINT16);
3524
3525 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3526         .f = cmd_tx_vlan_set_qinq_parsed,
3527         .data = NULL,
3528         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3529                 "Enable hardware insertion of double VLAN header "
3530                 "with given TAG Identifiers in packets sent on a port",
3531         .tokens = {
3532                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3533                 (void *)&cmd_tx_vlan_set_qinq_set,
3534                 (void *)&cmd_tx_vlan_set_qinq_portid,
3535                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3536                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3537                 NULL,
3538         },
3539 };
3540
3541 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3542 struct cmd_tx_vlan_set_pvid_result {
3543         cmdline_fixed_string_t tx_vlan;
3544         cmdline_fixed_string_t set;
3545         cmdline_fixed_string_t pvid;
3546         portid_t port_id;
3547         uint16_t vlan_id;
3548         cmdline_fixed_string_t mode;
3549 };
3550
3551 static void
3552 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3553                             __attribute__((unused)) struct cmdline *cl,
3554                             __attribute__((unused)) void *data)
3555 {
3556         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3557
3558         if (strcmp(res->mode, "on") == 0)
3559                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3560         else
3561                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3562 }
3563
3564 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3565         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3566                                  tx_vlan, "tx_vlan");
3567 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3568         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3569                                  set, "set");
3570 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3571         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3572                                  pvid, "pvid");
3573 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3574         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3575                              port_id, UINT16);
3576 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3577         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3578                               vlan_id, UINT16);
3579 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3580         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3581                                  mode, "on#off");
3582
3583 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3584         .f = cmd_tx_vlan_set_pvid_parsed,
3585         .data = NULL,
3586         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3587         .tokens = {
3588                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3589                 (void *)&cmd_tx_vlan_set_pvid_set,
3590                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3591                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3592                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3593                 (void *)&cmd_tx_vlan_set_pvid_mode,
3594                 NULL,
3595         },
3596 };
3597
3598 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3599 struct cmd_tx_vlan_reset_result {
3600         cmdline_fixed_string_t tx_vlan;
3601         cmdline_fixed_string_t reset;
3602         portid_t port_id;
3603 };
3604
3605 static void
3606 cmd_tx_vlan_reset_parsed(void *parsed_result,
3607                          __attribute__((unused)) struct cmdline *cl,
3608                          __attribute__((unused)) void *data)
3609 {
3610         struct cmd_tx_vlan_reset_result *res = parsed_result;
3611
3612         tx_vlan_reset(res->port_id);
3613 }
3614
3615 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3616         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3617                                  tx_vlan, "tx_vlan");
3618 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3619         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3620                                  reset, "reset");
3621 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3622         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3623                               port_id, UINT16);
3624
3625 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3626         .f = cmd_tx_vlan_reset_parsed,
3627         .data = NULL,
3628         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3629                 "VLAN header in packets sent on a port",
3630         .tokens = {
3631                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3632                 (void *)&cmd_tx_vlan_reset_reset,
3633                 (void *)&cmd_tx_vlan_reset_portid,
3634                 NULL,
3635         },
3636 };
3637
3638
3639 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3640 struct cmd_csum_result {
3641         cmdline_fixed_string_t csum;
3642         cmdline_fixed_string_t mode;
3643         cmdline_fixed_string_t proto;
3644         cmdline_fixed_string_t hwsw;
3645         portid_t port_id;
3646 };
3647
3648 static void
3649 csum_show(int port_id)
3650 {
3651         struct rte_eth_dev_info dev_info;
3652         uint16_t ol_flags;
3653
3654         ol_flags = ports[port_id].tx_ol_flags;
3655         printf("Parse tunnel is %s\n",
3656                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3657         printf("IP checksum offload is %s\n",
3658                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3659         printf("UDP checksum offload is %s\n",
3660                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3661         printf("TCP checksum offload is %s\n",
3662                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3663         printf("SCTP checksum offload is %s\n",
3664                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3665         printf("Outer-Ip checksum offload is %s\n",
3666                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3667
3668         /* display warnings if configuration is not supported by the NIC */
3669         rte_eth_dev_info_get(port_id, &dev_info);
3670         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3671                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3672                 printf("Warning: hardware IP checksum enabled but not "
3673                         "supported by port %d\n", port_id);
3674         }
3675         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3676                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3677                 printf("Warning: hardware UDP checksum enabled but not "
3678                         "supported by port %d\n", port_id);
3679         }
3680         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3682                 printf("Warning: hardware TCP checksum enabled but not "
3683                         "supported by port %d\n", port_id);
3684         }
3685         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3686                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3687                 printf("Warning: hardware SCTP checksum enabled but not "
3688                         "supported by port %d\n", port_id);
3689         }
3690         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3691                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3692                 printf("Warning: hardware outer IP checksum enabled but not "
3693                         "supported by port %d\n", port_id);
3694         }
3695 }
3696
3697 static void
3698 cmd_csum_parsed(void *parsed_result,
3699                        __attribute__((unused)) struct cmdline *cl,
3700                        __attribute__((unused)) void *data)
3701 {
3702         struct cmd_csum_result *res = parsed_result;
3703         int hw = 0;
3704         uint16_t mask = 0;
3705
3706         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3707                 printf("invalid port %d\n", res->port_id);
3708                 return;
3709         }
3710
3711         if (!strcmp(res->mode, "set")) {
3712
3713                 if (!strcmp(res->hwsw, "hw"))
3714                         hw = 1;
3715
3716                 if (!strcmp(res->proto, "ip")) {
3717                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3718                 } else if (!strcmp(res->proto, "udp")) {
3719                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3720                 } else if (!strcmp(res->proto, "tcp")) {
3721                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3722                 } else if (!strcmp(res->proto, "sctp")) {
3723                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3724                 } else if (!strcmp(res->proto, "outer-ip")) {
3725                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3726                 }
3727
3728                 if (hw)
3729                         ports[res->port_id].tx_ol_flags |= mask;
3730                 else
3731                         ports[res->port_id].tx_ol_flags &= (~mask);
3732         }
3733         csum_show(res->port_id);
3734 }
3735
3736 cmdline_parse_token_string_t cmd_csum_csum =
3737         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3738                                 csum, "csum");
3739 cmdline_parse_token_string_t cmd_csum_mode =
3740         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3741                                 mode, "set");
3742 cmdline_parse_token_string_t cmd_csum_proto =
3743         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3744                                 proto, "ip#tcp#udp#sctp#outer-ip");
3745 cmdline_parse_token_string_t cmd_csum_hwsw =
3746         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3747                                 hwsw, "hw#sw");
3748 cmdline_parse_token_num_t cmd_csum_portid =
3749         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3750                                 port_id, UINT16);
3751
3752 cmdline_parse_inst_t cmd_csum_set = {
3753         .f = cmd_csum_parsed,
3754         .data = NULL,
3755         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3756                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3757                 "using csum forward engine",
3758         .tokens = {
3759                 (void *)&cmd_csum_csum,
3760                 (void *)&cmd_csum_mode,
3761                 (void *)&cmd_csum_proto,
3762                 (void *)&cmd_csum_hwsw,
3763                 (void *)&cmd_csum_portid,
3764                 NULL,
3765         },
3766 };
3767
3768 cmdline_parse_token_string_t cmd_csum_mode_show =
3769         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3770                                 mode, "show");
3771
3772 cmdline_parse_inst_t cmd_csum_show = {
3773         .f = cmd_csum_parsed,
3774         .data = NULL,
3775         .help_str = "csum show <port_id>: Show checksum offload configuration",
3776         .tokens = {
3777                 (void *)&cmd_csum_csum,
3778                 (void *)&cmd_csum_mode_show,
3779                 (void *)&cmd_csum_portid,
3780                 NULL,
3781         },
3782 };
3783
3784 /* Enable/disable tunnel parsing */
3785 struct cmd_csum_tunnel_result {
3786         cmdline_fixed_string_t csum;
3787         cmdline_fixed_string_t parse;
3788         cmdline_fixed_string_t onoff;
3789         portid_t port_id;
3790 };
3791
3792 static void
3793 cmd_csum_tunnel_parsed(void *parsed_result,
3794                        __attribute__((unused)) struct cmdline *cl,
3795                        __attribute__((unused)) void *data)
3796 {
3797         struct cmd_csum_tunnel_result *res = parsed_result;
3798
3799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3800                 return;
3801
3802         if (!strcmp(res->onoff, "on"))
3803                 ports[res->port_id].tx_ol_flags |=
3804                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3805         else
3806                 ports[res->port_id].tx_ol_flags &=
3807                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3808
3809         csum_show(res->port_id);
3810 }
3811
3812 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3813         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3814                                 csum, "csum");
3815 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3816         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3817                                 parse, "parse_tunnel");
3818 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3819         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3820                                 onoff, "on#off");
3821 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3822         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3823                                 port_id, UINT16);
3824
3825 cmdline_parse_inst_t cmd_csum_tunnel = {
3826         .f = cmd_csum_tunnel_parsed,
3827         .data = NULL,
3828         .help_str = "csum parse_tunnel on|off <port_id>: "
3829                 "Enable/Disable parsing of tunnels for csum engine",
3830         .tokens = {
3831                 (void *)&cmd_csum_tunnel_csum,
3832                 (void *)&cmd_csum_tunnel_parse,
3833                 (void *)&cmd_csum_tunnel_onoff,
3834                 (void *)&cmd_csum_tunnel_portid,
3835                 NULL,
3836         },
3837 };
3838
3839 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3840 struct cmd_tso_set_result {
3841         cmdline_fixed_string_t tso;
3842         cmdline_fixed_string_t mode;
3843         uint16_t tso_segsz;
3844         portid_t port_id;
3845 };
3846
3847 static void
3848 cmd_tso_set_parsed(void *parsed_result,
3849                        __attribute__((unused)) struct cmdline *cl,
3850                        __attribute__((unused)) void *data)
3851 {
3852         struct cmd_tso_set_result *res = parsed_result;
3853         struct rte_eth_dev_info dev_info;
3854
3855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3856                 return;
3857
3858         if (!strcmp(res->mode, "set"))
3859                 ports[res->port_id].tso_segsz = res->tso_segsz;
3860
3861         if (ports[res->port_id].tso_segsz == 0)
3862                 printf("TSO for non-tunneled packets is disabled\n");
3863         else
3864                 printf("TSO segment size for non-tunneled packets is %d\n",
3865                         ports[res->port_id].tso_segsz);
3866
3867         /* display warnings if configuration is not supported by the NIC */
3868         rte_eth_dev_info_get(res->port_id, &dev_info);
3869         if ((ports[res->port_id].tso_segsz != 0) &&
3870                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3871                 printf("Warning: TSO enabled but not "
3872                         "supported by port %d\n", res->port_id);
3873         }
3874 }
3875
3876 cmdline_parse_token_string_t cmd_tso_set_tso =
3877         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3878                                 tso, "tso");
3879 cmdline_parse_token_string_t cmd_tso_set_mode =
3880         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3881                                 mode, "set");
3882 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3883         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3884                                 tso_segsz, UINT16);
3885 cmdline_parse_token_num_t cmd_tso_set_portid =
3886         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3887                                 port_id, UINT16);
3888
3889 cmdline_parse_inst_t cmd_tso_set = {
3890         .f = cmd_tso_set_parsed,
3891         .data = NULL,
3892         .help_str = "tso set <tso_segsz> <port_id>: "
3893                 "Set TSO segment size of non-tunneled packets for csum engine "
3894                 "(0 to disable)",
3895         .tokens = {
3896                 (void *)&cmd_tso_set_tso,
3897                 (void *)&cmd_tso_set_mode,
3898                 (void *)&cmd_tso_set_tso_segsz,
3899                 (void *)&cmd_tso_set_portid,
3900                 NULL,
3901         },
3902 };
3903
3904 cmdline_parse_token_string_t cmd_tso_show_mode =
3905         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3906                                 mode, "show");
3907
3908
3909 cmdline_parse_inst_t cmd_tso_show = {
3910         .f = cmd_tso_set_parsed,
3911         .data = NULL,
3912         .help_str = "tso show <port_id>: "
3913                 "Show TSO segment size of non-tunneled packets for csum engine",
3914         .tokens = {
3915                 (void *)&cmd_tso_set_tso,
3916                 (void *)&cmd_tso_show_mode,
3917                 (void *)&cmd_tso_set_portid,
3918                 NULL,
3919         },
3920 };
3921
3922 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3923 struct cmd_tunnel_tso_set_result {
3924         cmdline_fixed_string_t tso;
3925         cmdline_fixed_string_t mode;
3926         uint16_t tso_segsz;
3927         portid_t port_id;
3928 };
3929
3930 static void
3931 check_tunnel_tso_nic_support(portid_t port_id)
3932 {
3933         struct rte_eth_dev_info dev_info;
3934
3935         rte_eth_dev_info_get(port_id, &dev_info);
3936         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3937                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3938                        "supported by port %d\n", port_id);
3939         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3940                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3941                         "supported by port %d\n", port_id);
3942         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3943                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3944                        "supported by port %d\n", port_id);
3945         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3946                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3947                        "supported by port %d\n", port_id);
3948 }
3949
3950 static void
3951 cmd_tunnel_tso_set_parsed(void *parsed_result,
3952                           __attribute__((unused)) struct cmdline *cl,
3953                           __attribute__((unused)) void *data)
3954 {
3955         struct cmd_tunnel_tso_set_result *res = parsed_result;
3956
3957         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3958                 return;
3959
3960         if (!strcmp(res->mode, "set"))
3961                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3962
3963         if (ports[res->port_id].tunnel_tso_segsz == 0)
3964                 printf("TSO for tunneled packets is disabled\n");
3965         else {
3966                 printf("TSO segment size for tunneled packets is %d\n",
3967                         ports[res->port_id].tunnel_tso_segsz);
3968
3969                 /* Below conditions are needed to make it work:
3970                  * (1) tunnel TSO is supported by the NIC;
3971                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3972                  * are recognized;
3973                  * (3) for tunneled pkts with outer L3 of IPv4,
3974                  * "csum set outer-ip" must be set to hw, because after tso,
3975                  * total_len of outer IP header is changed, and the checksum
3976                  * of outer IP header calculated by sw should be wrong; that
3977                  * is not necessary for IPv6 tunneled pkts because there's no
3978                  * checksum in IP header anymore.
3979                  */
3980                 check_tunnel_tso_nic_support(res->port_id);
3981
3982                 if (!(ports[res->port_id].tx_ol_flags &
3983                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3984                         printf("Warning: csum parse_tunnel must be set "
3985                                 "so that tunneled packets are recognized\n");
3986                 if (!(ports[res->port_id].tx_ol_flags &
3987                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3988                         printf("Warning: csum set outer-ip must be set to hw "
3989                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3990         }
3991 }
3992
3993 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3994         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3995                                 tso, "tunnel_tso");
3996 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3997         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3998                                 mode, "set");
3999 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4000         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4001                                 tso_segsz, UINT16);
4002 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4003         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4004                                 port_id, UINT16);
4005
4006 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4007         .f = cmd_tunnel_tso_set_parsed,
4008         .data = NULL,
4009         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4010                 "Set TSO segment size of tunneled packets for csum engine "
4011                 "(0 to disable)",
4012         .tokens = {
4013                 (void *)&cmd_tunnel_tso_set_tso,
4014                 (void *)&cmd_tunnel_tso_set_mode,
4015                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4016                 (void *)&cmd_tunnel_tso_set_portid,
4017                 NULL,
4018         },
4019 };
4020
4021 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4022         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4023                                 mode, "show");
4024
4025
4026 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4027         .f = cmd_tunnel_tso_set_parsed,
4028         .data = NULL,
4029         .help_str = "tunnel_tso show <port_id> "
4030                 "Show TSO segment size of tunneled packets for csum engine",
4031         .tokens = {
4032                 (void *)&cmd_tunnel_tso_set_tso,
4033                 (void *)&cmd_tunnel_tso_show_mode,
4034                 (void *)&cmd_tunnel_tso_set_portid,
4035                 NULL,
4036         },
4037 };
4038
4039 /* *** SET GRO FOR A PORT *** */
4040 struct cmd_gro_enable_result {
4041         cmdline_fixed_string_t cmd_set;
4042         cmdline_fixed_string_t cmd_port;
4043         cmdline_fixed_string_t cmd_keyword;
4044         cmdline_fixed_string_t cmd_onoff;
4045         portid_t cmd_pid;
4046 };
4047
4048 static void
4049 cmd_gro_enable_parsed(void *parsed_result,
4050                 __attribute__((unused)) struct cmdline *cl,
4051                 __attribute__((unused)) void *data)
4052 {
4053         struct cmd_gro_enable_result *res;
4054
4055         res = parsed_result;
4056         if (!strcmp(res->cmd_keyword, "gro"))
4057                 setup_gro(res->cmd_onoff, res->cmd_pid);
4058 }
4059
4060 cmdline_parse_token_string_t cmd_gro_enable_set =
4061         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4062                         cmd_set, "set");
4063 cmdline_parse_token_string_t cmd_gro_enable_port =
4064         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4065                         cmd_keyword, "port");
4066 cmdline_parse_token_num_t cmd_gro_enable_pid =
4067         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4068                         cmd_pid, UINT16);
4069 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4070         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4071                         cmd_keyword, "gro");
4072 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4073         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4074                         cmd_onoff, "on#off");
4075
4076 cmdline_parse_inst_t cmd_gro_enable = {
4077         .f = cmd_gro_enable_parsed,
4078         .data = NULL,
4079         .help_str = "set port <port_id> gro on|off",
4080         .tokens = {
4081                 (void *)&cmd_gro_enable_set,
4082                 (void *)&cmd_gro_enable_port,
4083                 (void *)&cmd_gro_enable_pid,
4084                 (void *)&cmd_gro_enable_keyword,
4085                 (void *)&cmd_gro_enable_onoff,
4086                 NULL,
4087         },
4088 };
4089
4090 /* *** DISPLAY GRO CONFIGURATION *** */
4091 struct cmd_gro_show_result {
4092         cmdline_fixed_string_t cmd_show;
4093         cmdline_fixed_string_t cmd_port;
4094         cmdline_fixed_string_t cmd_keyword;
4095         portid_t cmd_pid;
4096 };
4097
4098 static void
4099 cmd_gro_show_parsed(void *parsed_result,
4100                 __attribute__((unused)) struct cmdline *cl,
4101                 __attribute__((unused)) void *data)
4102 {
4103         struct cmd_gro_show_result *res;
4104
4105         res = parsed_result;
4106         if (!strcmp(res->cmd_keyword, "gro"))
4107                 show_gro(res->cmd_pid);
4108 }
4109
4110 cmdline_parse_token_string_t cmd_gro_show_show =
4111         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4112                         cmd_show, "show");
4113 cmdline_parse_token_string_t cmd_gro_show_port =
4114         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4115                         cmd_port, "port");
4116 cmdline_parse_token_num_t cmd_gro_show_pid =
4117         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4118                         cmd_pid, UINT16);
4119 cmdline_parse_token_string_t cmd_gro_show_keyword =
4120         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4121                         cmd_keyword, "gro");
4122
4123 cmdline_parse_inst_t cmd_gro_show = {
4124         .f = cmd_gro_show_parsed,
4125         .data = NULL,
4126         .help_str = "show port <port_id> gro",
4127         .tokens = {
4128                 (void *)&cmd_gro_show_show,
4129                 (void *)&cmd_gro_show_port,
4130                 (void *)&cmd_gro_show_pid,
4131                 (void *)&cmd_gro_show_keyword,
4132                 NULL,
4133         },
4134 };
4135
4136 /* *** SET FLUSH CYCLES FOR GRO *** */
4137 struct cmd_gro_flush_result {
4138         cmdline_fixed_string_t cmd_set;
4139         cmdline_fixed_string_t cmd_keyword;
4140         cmdline_fixed_string_t cmd_flush;
4141         uint8_t cmd_cycles;
4142 };
4143
4144 static void
4145 cmd_gro_flush_parsed(void *parsed_result,
4146                 __attribute__((unused)) struct cmdline *cl,
4147                 __attribute__((unused)) void *data)
4148 {
4149         struct cmd_gro_flush_result *res;
4150
4151         res = parsed_result;
4152         if ((!strcmp(res->cmd_keyword, "gro")) &&
4153                         (!strcmp(res->cmd_flush, "flush")))
4154                 setup_gro_flush_cycles(res->cmd_cycles);
4155 }
4156
4157 cmdline_parse_token_string_t cmd_gro_flush_set =
4158         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4159                         cmd_set, "set");
4160 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4161         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4162                         cmd_keyword, "gro");
4163 cmdline_parse_token_string_t cmd_gro_flush_flush =
4164         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4165                         cmd_flush, "flush");
4166 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4167         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4168                         cmd_cycles, UINT8);
4169
4170 cmdline_parse_inst_t cmd_gro_flush = {
4171         .f = cmd_gro_flush_parsed,
4172         .data = NULL,
4173         .help_str = "set gro flush <cycles>",
4174         .tokens = {
4175                 (void *)&cmd_gro_flush_set,
4176                 (void *)&cmd_gro_flush_keyword,
4177                 (void *)&cmd_gro_flush_flush,
4178                 (void *)&cmd_gro_flush_cycles,
4179                 NULL,
4180         },
4181 };
4182
4183 /* *** ENABLE/DISABLE GSO *** */
4184 struct cmd_gso_enable_result {
4185         cmdline_fixed_string_t cmd_set;
4186         cmdline_fixed_string_t cmd_port;
4187         cmdline_fixed_string_t cmd_keyword;
4188         cmdline_fixed_string_t cmd_mode;
4189         portid_t cmd_pid;
4190 };
4191
4192 static void
4193 cmd_gso_enable_parsed(void *parsed_result,
4194                 __attribute__((unused)) struct cmdline *cl,
4195                 __attribute__((unused)) void *data)
4196 {
4197         struct cmd_gso_enable_result *res;
4198
4199         res = parsed_result;
4200         if (!strcmp(res->cmd_keyword, "gso"))
4201                 setup_gso(res->cmd_mode, res->cmd_pid);
4202 }
4203
4204 cmdline_parse_token_string_t cmd_gso_enable_set =
4205         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4206                         cmd_set, "set");
4207 cmdline_parse_token_string_t cmd_gso_enable_port =
4208         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4209                         cmd_port, "port");
4210 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4211         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4212                         cmd_keyword, "gso");
4213 cmdline_parse_token_string_t cmd_gso_enable_mode =
4214         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4215                         cmd_mode, "on#off");
4216 cmdline_parse_token_num_t cmd_gso_enable_pid =
4217         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4218                         cmd_pid, UINT16);
4219
4220 cmdline_parse_inst_t cmd_gso_enable = {
4221         .f = cmd_gso_enable_parsed,
4222         .data = NULL,
4223         .help_str = "set port <port_id> gso on|off",
4224         .tokens = {
4225                 (void *)&cmd_gso_enable_set,
4226                 (void *)&cmd_gso_enable_port,
4227                 (void *)&cmd_gso_enable_pid,
4228                 (void *)&cmd_gso_enable_keyword,
4229                 (void *)&cmd_gso_enable_mode,
4230                 NULL,
4231         },
4232 };
4233
4234 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4235 struct cmd_gso_size_result {
4236         cmdline_fixed_string_t cmd_set;
4237         cmdline_fixed_string_t cmd_keyword;
4238         cmdline_fixed_string_t cmd_segsz;
4239         uint16_t cmd_size;
4240 };
4241
4242 static void
4243 cmd_gso_size_parsed(void *parsed_result,
4244                        __attribute__((unused)) struct cmdline *cl,
4245                        __attribute__((unused)) void *data)
4246 {
4247         struct cmd_gso_size_result *res = parsed_result;
4248
4249         if (test_done == 0) {
4250                 printf("Before setting GSO segsz, please first"
4251                                 " stop fowarding\n");
4252                 return;
4253         }
4254
4255         if (!strcmp(res->cmd_keyword, "gso") &&
4256                         !strcmp(res->cmd_segsz, "segsz")) {
4257                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4258                         printf("gso_size should be larger than %zu."
4259                                         " Please input a legal value\n",
4260                                         RTE_GSO_SEG_SIZE_MIN);
4261                 else
4262                         gso_max_segment_size = res->cmd_size;
4263         }
4264 }
4265
4266 cmdline_parse_token_string_t cmd_gso_size_set =
4267         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4268                                 cmd_set, "set");
4269 cmdline_parse_token_string_t cmd_gso_size_keyword =
4270         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4271                                 cmd_keyword, "gso");
4272 cmdline_parse_token_string_t cmd_gso_size_segsz =
4273         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4274                                 cmd_segsz, "segsz");
4275 cmdline_parse_token_num_t cmd_gso_size_size =
4276         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4277                                 cmd_size, UINT16);
4278
4279 cmdline_parse_inst_t cmd_gso_size = {
4280         .f = cmd_gso_size_parsed,
4281         .data = NULL,
4282         .help_str = "set gso segsz <length>",
4283         .tokens = {
4284                 (void *)&cmd_gso_size_set,
4285                 (void *)&cmd_gso_size_keyword,
4286                 (void *)&cmd_gso_size_segsz,
4287                 (void *)&cmd_gso_size_size,
4288                 NULL,
4289         },
4290 };
4291
4292 /* *** SHOW GSO CONFIGURATION *** */
4293 struct cmd_gso_show_result {
4294         cmdline_fixed_string_t cmd_show;
4295         cmdline_fixed_string_t cmd_port;
4296         cmdline_fixed_string_t cmd_keyword;
4297         portid_t cmd_pid;
4298 };
4299
4300 static void
4301 cmd_gso_show_parsed(void *parsed_result,
4302                        __attribute__((unused)) struct cmdline *cl,
4303                        __attribute__((unused)) void *data)
4304 {
4305         struct cmd_gso_show_result *res = parsed_result;
4306
4307         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4308                 printf("invalid port id %u\n", res->cmd_pid);
4309                 return;
4310         }
4311         if (!strcmp(res->cmd_keyword, "gso")) {
4312                 if (gso_ports[res->cmd_pid].enable) {
4313                         printf("Max GSO'd packet size: %uB\n"
4314                                         "Supported GSO types: TCP/IPv4, "
4315                                         "VxLAN with inner TCP/IPv4 packet, "
4316                                         "GRE with inner TCP/IPv4  packet\n",
4317                                         gso_max_segment_size);
4318                 } else
4319                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4320         }
4321 }
4322
4323 cmdline_parse_token_string_t cmd_gso_show_show =
4324 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4325                 cmd_show, "show");
4326 cmdline_parse_token_string_t cmd_gso_show_port =
4327 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4328                 cmd_port, "port");
4329 cmdline_parse_token_string_t cmd_gso_show_keyword =
4330         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4331                                 cmd_keyword, "gso");
4332 cmdline_parse_token_num_t cmd_gso_show_pid =
4333         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4334                                 cmd_pid, UINT16);
4335
4336 cmdline_parse_inst_t cmd_gso_show = {
4337         .f = cmd_gso_show_parsed,
4338         .data = NULL,
4339         .help_str = "show port <port_id> gso",
4340         .tokens = {
4341                 (void *)&cmd_gso_show_show,
4342                 (void *)&cmd_gso_show_port,
4343                 (void *)&cmd_gso_show_pid,
4344                 (void *)&cmd_gso_show_keyword,
4345                 NULL,
4346         },
4347 };
4348
4349 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4350 struct cmd_set_flush_rx {
4351         cmdline_fixed_string_t set;
4352         cmdline_fixed_string_t flush_rx;
4353         cmdline_fixed_string_t mode;
4354 };
4355
4356 static void
4357 cmd_set_flush_rx_parsed(void *parsed_result,
4358                 __attribute__((unused)) struct cmdline *cl,
4359                 __attribute__((unused)) void *data)
4360 {
4361         struct cmd_set_flush_rx *res = parsed_result;
4362         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4363 }
4364
4365 cmdline_parse_token_string_t cmd_setflushrx_set =
4366         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4367                         set, "set");
4368 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4369         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4370                         flush_rx, "flush_rx");
4371 cmdline_parse_token_string_t cmd_setflushrx_mode =
4372         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4373                         mode, "on#off");
4374
4375
4376 cmdline_parse_inst_t cmd_set_flush_rx = {
4377         .f = cmd_set_flush_rx_parsed,
4378         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4379         .data = NULL,
4380         .tokens = {
4381                 (void *)&cmd_setflushrx_set,
4382                 (void *)&cmd_setflushrx_flush_rx,
4383                 (void *)&cmd_setflushrx_mode,
4384                 NULL,
4385         },
4386 };
4387
4388 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4389 struct cmd_set_link_check {
4390         cmdline_fixed_string_t set;
4391         cmdline_fixed_string_t link_check;
4392         cmdline_fixed_string_t mode;
4393 };
4394
4395 static void
4396 cmd_set_link_check_parsed(void *parsed_result,
4397                 __attribute__((unused)) struct cmdline *cl,
4398                 __attribute__((unused)) void *data)
4399 {
4400         struct cmd_set_link_check *res = parsed_result;
4401         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4402 }
4403
4404 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4405         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4406                         set, "set");
4407 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4408         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4409                         link_check, "link_check");
4410 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4411         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4412                         mode, "on#off");
4413
4414
4415 cmdline_parse_inst_t cmd_set_link_check = {
4416         .f = cmd_set_link_check_parsed,
4417         .help_str = "set link_check on|off: Enable/Disable link status check "
4418                     "when starting/stopping a port",
4419         .data = NULL,
4420         .tokens = {
4421                 (void *)&cmd_setlinkcheck_set,
4422                 (void *)&cmd_setlinkcheck_link_check,
4423                 (void *)&cmd_setlinkcheck_mode,
4424                 NULL,
4425         },
4426 };
4427
4428 /* *** SET NIC BYPASS MODE *** */
4429 struct cmd_set_bypass_mode_result {
4430         cmdline_fixed_string_t set;
4431         cmdline_fixed_string_t bypass;
4432         cmdline_fixed_string_t mode;
4433         cmdline_fixed_string_t value;
4434         portid_t port_id;
4435 };
4436
4437 static void
4438 cmd_set_bypass_mode_parsed(void *parsed_result,
4439                 __attribute__((unused)) struct cmdline *cl,
4440                 __attribute__((unused)) void *data)
4441 {
4442         struct cmd_set_bypass_mode_result *res = parsed_result;
4443         portid_t port_id = res->port_id;
4444         int32_t rc = -EINVAL;
4445
4446 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4447         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4448
4449         if (!strcmp(res->value, "bypass"))
4450                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4451         else if (!strcmp(res->value, "isolate"))
4452                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4453         else
4454                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4455
4456         /* Set the bypass mode for the relevant port. */
4457         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4458 #endif
4459         if (rc != 0)
4460                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4461 }
4462
4463 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4464         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4465                         set, "set");
4466 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4467         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4468                         bypass, "bypass");
4469 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4470         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4471                         mode, "mode");
4472 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4473         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4474                         value, "normal#bypass#isolate");
4475 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4476         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4477                                 port_id, UINT16);
4478
4479 cmdline_parse_inst_t cmd_set_bypass_mode = {
4480         .f = cmd_set_bypass_mode_parsed,
4481         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4482                     "Set the NIC bypass mode for port_id",
4483         .data = NULL,
4484         .tokens = {
4485                 (void *)&cmd_setbypass_mode_set,
4486                 (void *)&cmd_setbypass_mode_bypass,
4487                 (void *)&cmd_setbypass_mode_mode,
4488                 (void *)&cmd_setbypass_mode_value,
4489                 (void *)&cmd_setbypass_mode_port,
4490                 NULL,
4491         },
4492 };
4493
4494 /* *** SET NIC BYPASS EVENT *** */
4495 struct cmd_set_bypass_event_result {
4496         cmdline_fixed_string_t set;
4497         cmdline_fixed_string_t bypass;
4498         cmdline_fixed_string_t event;
4499         cmdline_fixed_string_t event_value;
4500         cmdline_fixed_string_t mode;
4501         cmdline_fixed_string_t mode_value;
4502         portid_t port_id;
4503 };
4504
4505 static void
4506 cmd_set_bypass_event_parsed(void *parsed_result,
4507                 __attribute__((unused)) struct cmdline *cl,
4508                 __attribute__((unused)) void *data)
4509 {
4510         int32_t rc = -EINVAL;
4511         struct cmd_set_bypass_event_result *res = parsed_result;
4512         portid_t port_id = res->port_id;
4513
4514 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4515         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4516         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4517
4518         if (!strcmp(res->event_value, "timeout"))
4519                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4520         else if (!strcmp(res->event_value, "os_on"))
4521                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4522         else if (!strcmp(res->event_value, "os_off"))
4523                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4524         else if (!strcmp(res->event_value, "power_on"))
4525                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4526         else if (!strcmp(res->event_value, "power_off"))
4527                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4528         else
4529                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4530
4531         if (!strcmp(res->mode_value, "bypass"))
4532                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4533         else if (!strcmp(res->mode_value, "isolate"))
4534                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4535         else
4536                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4537
4538         /* Set the watchdog timeout. */
4539         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4540
4541                 rc = -EINVAL;
4542                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4543                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4544                                                            bypass_timeout);
4545                 }
4546                 if (rc != 0) {
4547                         printf("Failed to set timeout value %u "
4548                         "for port %d, errto code: %d.\n",
4549                         bypass_timeout, port_id, rc);
4550                 }
4551         }
4552
4553         /* Set the bypass event to transition to bypass mode. */
4554         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4555                                               bypass_mode);
4556 #endif
4557
4558         if (rc != 0)
4559                 printf("\t Failed to set bypass event for port = %d.\n",
4560                        port_id);
4561 }
4562
4563 cmdline_parse_token_string_t cmd_setbypass_event_set =
4564         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4565                         set, "set");
4566 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4567         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4568                         bypass, "bypass");
4569 cmdline_parse_token_string_t cmd_setbypass_event_event =
4570         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4571                         event, "event");
4572 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4573         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4574                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4575 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4576         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4577                         mode, "mode");
4578 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4579         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4580                         mode_value, "normal#bypass#isolate");
4581 cmdline_parse_token_num_t cmd_setbypass_event_port =
4582         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4583                                 port_id, UINT16);
4584
4585 cmdline_parse_inst_t cmd_set_bypass_event = {
4586         .f = cmd_set_bypass_event_parsed,
4587         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4588                 "power_off mode normal|bypass|isolate <port_id>: "
4589                 "Set the NIC bypass event mode for port_id",
4590         .data = NULL,
4591         .tokens = {
4592                 (void *)&cmd_setbypass_event_set,
4593                 (void *)&cmd_setbypass_event_bypass,
4594                 (void *)&cmd_setbypass_event_event,
4595                 (void *)&cmd_setbypass_event_event_value,
4596                 (void *)&cmd_setbypass_event_mode,
4597                 (void *)&cmd_setbypass_event_mode_value,
4598                 (void *)&cmd_setbypass_event_port,
4599                 NULL,
4600         },
4601 };
4602
4603
4604 /* *** SET NIC BYPASS TIMEOUT *** */
4605 struct cmd_set_bypass_timeout_result {
4606         cmdline_fixed_string_t set;
4607         cmdline_fixed_string_t bypass;
4608         cmdline_fixed_string_t timeout;
4609         cmdline_fixed_string_t value;
4610 };
4611
4612 static void
4613 cmd_set_bypass_timeout_parsed(void *parsed_result,
4614                 __attribute__((unused)) struct cmdline *cl,
4615                 __attribute__((unused)) void *data)
4616 {
4617         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4618
4619 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4620         if (!strcmp(res->value, "1.5"))
4621                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4622         else if (!strcmp(res->value, "2"))
4623                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4624         else if (!strcmp(res->value, "3"))
4625                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4626         else if (!strcmp(res->value, "4"))
4627                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4628         else if (!strcmp(res->value, "8"))
4629                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4630         else if (!strcmp(res->value, "16"))
4631                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4632         else if (!strcmp(res->value, "32"))
4633                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4634         else
4635                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4636 #endif
4637 }
4638
4639 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4640         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4641                         set, "set");
4642 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4643         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4644                         bypass, "bypass");
4645 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4646         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4647                         timeout, "timeout");
4648 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4649         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4650                         value, "0#1.5#2#3#4#8#16#32");
4651
4652 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4653         .f = cmd_set_bypass_timeout_parsed,
4654         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4655                 "Set the NIC bypass watchdog timeout in seconds",
4656         .data = NULL,
4657         .tokens = {
4658                 (void *)&cmd_setbypass_timeout_set,
4659                 (void *)&cmd_setbypass_timeout_bypass,
4660                 (void *)&cmd_setbypass_timeout_timeout,
4661                 (void *)&cmd_setbypass_timeout_value,
4662                 NULL,
4663         },
4664 };
4665
4666 /* *** SHOW NIC BYPASS MODE *** */
4667 struct cmd_show_bypass_config_result {
4668         cmdline_fixed_string_t show;
4669         cmdline_fixed_string_t bypass;
4670         cmdline_fixed_string_t config;
4671         portid_t port_id;
4672 };
4673
4674 static void
4675 cmd_show_bypass_config_parsed(void *parsed_result,
4676                 __attribute__((unused)) struct cmdline *cl,
4677                 __attribute__((unused)) void *data)
4678 {
4679         struct cmd_show_bypass_config_result *res = parsed_result;
4680         portid_t port_id = res->port_id;
4681         int rc = -EINVAL;
4682 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4683         uint32_t event_mode;
4684         uint32_t bypass_mode;
4685         uint32_t timeout = bypass_timeout;
4686         int i;
4687
4688         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4689                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4690         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4691                 {"UNKNOWN", "normal", "bypass", "isolate"};
4692         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4693                 "NONE",
4694                 "OS/board on",
4695                 "power supply on",
4696                 "OS/board off",
4697                 "power supply off",
4698                 "timeout"};
4699         int num_events = (sizeof events) / (sizeof events[0]);
4700
4701         /* Display the bypass mode.*/
4702         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4703                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4704                 return;
4705         }
4706         else {
4707                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4708                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4709
4710                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4711         }
4712
4713         /* Display the bypass timeout.*/
4714         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4715                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4716
4717         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4718
4719         /* Display the bypass events and associated modes. */
4720         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4721
4722                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4723                         printf("\tFailed to get bypass mode for event = %s\n",
4724                                 events[i]);
4725                 } else {
4726                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4727                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4728
4729                         printf("\tbypass event: %-16s = %s\n", events[i],
4730                                 modes[event_mode]);
4731                 }
4732         }
4733 #endif
4734         if (rc != 0)
4735                 printf("\tFailed to get bypass configuration for port = %d\n",
4736                        port_id);
4737 }
4738
4739 cmdline_parse_token_string_t cmd_showbypass_config_show =
4740         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4741                         show, "show");
4742 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4743         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4744                         bypass, "bypass");
4745 cmdline_parse_token_string_t cmd_showbypass_config_config =
4746         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4747                         config, "config");
4748 cmdline_parse_token_num_t cmd_showbypass_config_port =
4749         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4750                                 port_id, UINT16);
4751
4752 cmdline_parse_inst_t cmd_show_bypass_config = {
4753         .f = cmd_show_bypass_config_parsed,
4754         .help_str = "show bypass config <port_id>: "
4755                     "Show the NIC bypass config for port_id",
4756         .data = NULL,
4757         .tokens = {
4758                 (void *)&cmd_showbypass_config_show,
4759                 (void *)&cmd_showbypass_config_bypass,
4760                 (void *)&cmd_showbypass_config_config,
4761                 (void *)&cmd_showbypass_config_port,
4762                 NULL,
4763         },
4764 };
4765
4766 #ifdef RTE_LIBRTE_PMD_BOND
4767 /* *** SET BONDING MODE *** */
4768 struct cmd_set_bonding_mode_result {
4769         cmdline_fixed_string_t set;
4770         cmdline_fixed_string_t bonding;
4771         cmdline_fixed_string_t mode;
4772         uint8_t value;
4773         portid_t port_id;
4774 };
4775
4776 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4777                 __attribute__((unused))  struct cmdline *cl,
4778                 __attribute__((unused)) void *data)
4779 {
4780         struct cmd_set_bonding_mode_result *res = parsed_result;
4781         portid_t port_id = res->port_id;
4782
4783         /* Set the bonding mode for the relevant port. */
4784         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4785                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4786 }
4787
4788 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4789 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4790                 set, "set");
4791 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4792 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4793                 bonding, "bonding");
4794 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4795 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4796                 mode, "mode");
4797 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4798 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4799                 value, UINT8);
4800 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4801 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4802                 port_id, UINT16);
4803
4804 cmdline_parse_inst_t cmd_set_bonding_mode = {
4805                 .f = cmd_set_bonding_mode_parsed,
4806                 .help_str = "set bonding mode <mode_value> <port_id>: "
4807                         "Set the bonding mode for port_id",
4808                 .data = NULL,
4809                 .tokens = {
4810                                 (void *) &cmd_setbonding_mode_set,
4811                                 (void *) &cmd_setbonding_mode_bonding,
4812                                 (void *) &cmd_setbonding_mode_mode,
4813                                 (void *) &cmd_setbonding_mode_value,
4814                                 (void *) &cmd_setbonding_mode_port,
4815                                 NULL
4816                 }
4817 };
4818
4819 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4820 struct cmd_set_bonding_lacp_dedicated_queues_result {
4821         cmdline_fixed_string_t set;
4822         cmdline_fixed_string_t bonding;
4823         cmdline_fixed_string_t lacp;
4824         cmdline_fixed_string_t dedicated_queues;
4825         portid_t port_id;
4826         cmdline_fixed_string_t mode;
4827 };
4828
4829 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4830                 __attribute__((unused))  struct cmdline *cl,
4831                 __attribute__((unused)) void *data)
4832 {
4833         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4834         portid_t port_id = res->port_id;
4835         struct rte_port *port;
4836
4837         port = &ports[port_id];
4838
4839         /** Check if the port is not started **/
4840         if (port->port_status != RTE_PORT_STOPPED) {
4841                 printf("Please stop port %d first\n", port_id);
4842                 return;
4843         }
4844
4845         if (!strcmp(res->mode, "enable")) {
4846                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4847                         printf("Dedicate queues for LACP control packets"
4848                                         " enabled\n");
4849                 else
4850                         printf("Enabling dedicate queues for LACP control "
4851                                         "packets on port %d failed\n", port_id);
4852         } else if (!strcmp(res->mode, "disable")) {
4853                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4854                         printf("Dedicated queues for LACP control packets "
4855                                         "disabled\n");
4856                 else
4857                         printf("Disabling dedicated queues for LACP control "
4858                                         "traffic on port %d failed\n", port_id);
4859         }
4860 }
4861
4862 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4863 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4864                 set, "set");
4865 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4866 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4867                 bonding, "bonding");
4868 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4869 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4870                 lacp, "lacp");
4871 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4872 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4873                 dedicated_queues, "dedicated_queues");
4874 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4875 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4876                 port_id, UINT16);
4877 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4878 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4879                 mode, "enable#disable");
4880
4881 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4882                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4883                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4884                         "enable|disable: "
4885                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4886                 .data = NULL,
4887                 .tokens = {
4888                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4889                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4890                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4891                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4892                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4893                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4894                         NULL
4895                 }
4896 };
4897
4898 /* *** SET BALANCE XMIT POLICY *** */
4899 struct cmd_set_bonding_balance_xmit_policy_result {
4900         cmdline_fixed_string_t set;
4901         cmdline_fixed_string_t bonding;
4902         cmdline_fixed_string_t balance_xmit_policy;
4903         portid_t port_id;
4904         cmdline_fixed_string_t policy;
4905 };
4906
4907 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4908                 __attribute__((unused))  struct cmdline *cl,
4909                 __attribute__((unused)) void *data)
4910 {
4911         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4912         portid_t port_id = res->port_id;
4913         uint8_t policy;
4914
4915         if (!strcmp(res->policy, "l2")) {
4916                 policy = BALANCE_XMIT_POLICY_LAYER2;
4917         } else if (!strcmp(res->policy, "l23")) {
4918                 policy = BALANCE_XMIT_POLICY_LAYER23;
4919         } else if (!strcmp(res->policy, "l34")) {
4920                 policy = BALANCE_XMIT_POLICY_LAYER34;
4921         } else {
4922                 printf("\t Invalid xmit policy selection");
4923                 return;
4924         }
4925
4926         /* Set the bonding mode for the relevant port. */
4927         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4928                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4929                                 port_id);
4930         }
4931 }
4932
4933 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4934 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4935                 set, "set");
4936 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4937 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4938                 bonding, "bonding");
4939 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4940 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4941                 balance_xmit_policy, "balance_xmit_policy");
4942 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4943 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4944                 port_id, UINT16);
4945 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4946 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4947                 policy, "l2#l23#l34");
4948
4949 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4950                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4951                 .help_str = "set bonding balance_xmit_policy <port_id> "
4952                         "l2|l23|l34: "
4953                         "Set the bonding balance_xmit_policy for port_id",
4954                 .data = NULL,
4955                 .tokens = {
4956                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4957                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4958                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4959                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4960                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4961                                 NULL
4962                 }
4963 };
4964
4965 /* *** SHOW NIC BONDING CONFIGURATION *** */
4966 struct cmd_show_bonding_config_result {
4967         cmdline_fixed_string_t show;
4968         cmdline_fixed_string_t bonding;
4969         cmdline_fixed_string_t config;
4970         portid_t port_id;
4971 };
4972
4973 static void cmd_show_bonding_config_parsed(void *parsed_result,
4974                 __attribute__((unused))  struct cmdline *cl,
4975                 __attribute__((unused)) void *data)
4976 {
4977         struct cmd_show_bonding_config_result *res = parsed_result;
4978         int bonding_mode, agg_mode;
4979         portid_t slaves[RTE_MAX_ETHPORTS];
4980         int num_slaves, num_active_slaves;
4981         int primary_id;
4982         int i;
4983         portid_t port_id = res->port_id;
4984
4985         /* Display the bonding mode.*/
4986         bonding_mode = rte_eth_bond_mode_get(port_id);
4987         if (bonding_mode < 0) {
4988                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4989                 return;
4990         } else
4991                 printf("\tBonding mode: %d\n", bonding_mode);
4992
4993         if (bonding_mode == BONDING_MODE_BALANCE) {
4994                 int balance_xmit_policy;
4995
4996                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4997                 if (balance_xmit_policy < 0) {
4998                         printf("\tFailed to get balance xmit policy for port = %d\n",
4999                                         port_id);
5000                         return;
5001                 } else {
5002                         printf("\tBalance Xmit Policy: ");
5003
5004                         switch (balance_xmit_policy) {
5005                         case BALANCE_XMIT_POLICY_LAYER2:
5006                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5007                                 break;
5008                         case BALANCE_XMIT_POLICY_LAYER23:
5009                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5010                                 break;
5011                         case BALANCE_XMIT_POLICY_LAYER34:
5012                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5013                                 break;
5014                         }
5015                         printf("\n");
5016                 }
5017         }
5018
5019         if (bonding_mode == BONDING_MODE_8023AD) {
5020                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5021                 printf("\tIEEE802.3AD Aggregator Mode: ");
5022                 switch (agg_mode) {
5023                 case AGG_BANDWIDTH:
5024                         printf("bandwidth");
5025                         break;
5026                 case AGG_STABLE:
5027                         printf("stable");
5028                         break;
5029                 case AGG_COUNT:
5030                         printf("count");
5031                         break;
5032                 }
5033                 printf("\n");
5034         }
5035
5036         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5037
5038         if (num_slaves < 0) {
5039                 printf("\tFailed to get slave list for port = %d\n", port_id);
5040                 return;
5041         }
5042         if (num_slaves > 0) {
5043                 printf("\tSlaves (%d): [", num_slaves);
5044                 for (i = 0; i < num_slaves - 1; i++)
5045                         printf("%d ", slaves[i]);
5046
5047                 printf("%d]\n", slaves[num_slaves - 1]);
5048         } else {
5049                 printf("\tSlaves: []\n");
5050
5051         }
5052
5053         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5054                         RTE_MAX_ETHPORTS);
5055
5056         if (num_active_slaves < 0) {
5057                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5058                 return;
5059         }
5060         if (num_active_slaves > 0) {
5061                 printf("\tActive Slaves (%d): [", num_active_slaves);
5062                 for (i = 0; i < num_active_slaves - 1; i++)
5063                         printf("%d ", slaves[i]);
5064
5065                 printf("%d]\n", slaves[num_active_slaves - 1]);
5066
5067         } else {
5068                 printf("\tActive Slaves: []\n");
5069
5070         }
5071
5072         primary_id = rte_eth_bond_primary_get(port_id);
5073         if (primary_id < 0) {
5074                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5075                 return;
5076         } else
5077                 printf("\tPrimary: [%d]\n", primary_id);
5078
5079 }
5080
5081 cmdline_parse_token_string_t cmd_showbonding_config_show =
5082 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5083                 show, "show");
5084 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5085 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5086                 bonding, "bonding");
5087 cmdline_parse_token_string_t cmd_showbonding_config_config =
5088 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5089                 config, "config");
5090 cmdline_parse_token_num_t cmd_showbonding_config_port =
5091 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5092                 port_id, UINT16);
5093
5094 cmdline_parse_inst_t cmd_show_bonding_config = {
5095                 .f = cmd_show_bonding_config_parsed,
5096                 .help_str = "show bonding config <port_id>: "
5097                         "Show the bonding config for port_id",
5098                 .data = NULL,
5099                 .tokens = {
5100                                 (void *)&cmd_showbonding_config_show,
5101                                 (void *)&cmd_showbonding_config_bonding,
5102                                 (void *)&cmd_showbonding_config_config,
5103                                 (void *)&cmd_showbonding_config_port,
5104                                 NULL
5105                 }
5106 };
5107
5108 /* *** SET BONDING PRIMARY *** */
5109 struct cmd_set_bonding_primary_result {
5110         cmdline_fixed_string_t set;
5111         cmdline_fixed_string_t bonding;
5112         cmdline_fixed_string_t primary;
5113         portid_t slave_id;
5114         portid_t port_id;
5115 };
5116
5117 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5118                 __attribute__((unused))  struct cmdline *cl,
5119                 __attribute__((unused)) void *data)
5120 {
5121         struct cmd_set_bonding_primary_result *res = parsed_result;
5122         portid_t master_port_id = res->port_id;
5123         portid_t slave_port_id = res->slave_id;
5124
5125         /* Set the primary slave for a bonded device. */
5126         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5127                 printf("\t Failed to set primary slave for port = %d.\n",
5128                                 master_port_id);
5129                 return;
5130         }
5131         init_port_config();
5132 }
5133
5134 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5135 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5136                 set, "set");
5137 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5138 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5139                 bonding, "bonding");
5140 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5141 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5142                 primary, "primary");
5143 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5144 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5145                 slave_id, UINT16);
5146 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5147 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5148                 port_id, UINT16);
5149
5150 cmdline_parse_inst_t cmd_set_bonding_primary = {
5151                 .f = cmd_set_bonding_primary_parsed,
5152                 .help_str = "set bonding primary <slave_id> <port_id>: "
5153                         "Set the primary slave for port_id",
5154                 .data = NULL,
5155                 .tokens = {
5156                                 (void *)&cmd_setbonding_primary_set,
5157                                 (void *)&cmd_setbonding_primary_bonding,
5158                                 (void *)&cmd_setbonding_primary_primary,
5159                                 (void *)&cmd_setbonding_primary_slave,
5160                                 (void *)&cmd_setbonding_primary_port,
5161                                 NULL
5162                 }
5163 };
5164
5165 /* *** ADD SLAVE *** */
5166 struct cmd_add_bonding_slave_result {
5167         cmdline_fixed_string_t add;
5168         cmdline_fixed_string_t bonding;
5169         cmdline_fixed_string_t slave;
5170         portid_t slave_id;
5171         portid_t port_id;
5172 };
5173
5174 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5175                 __attribute__((unused))  struct cmdline *cl,
5176                 __attribute__((unused)) void *data)
5177 {
5178         struct cmd_add_bonding_slave_result *res = parsed_result;
5179         portid_t master_port_id = res->port_id;
5180         portid_t slave_port_id = res->slave_id;
5181
5182         /* add the slave for a bonded device. */
5183         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5184                 printf("\t Failed to add slave %d to master port = %d.\n",
5185                                 slave_port_id, master_port_id);
5186                 return;
5187         }
5188         init_port_config();
5189         set_port_slave_flag(slave_port_id);
5190 }
5191
5192 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5193 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5194                 add, "add");
5195 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5196 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5197                 bonding, "bonding");
5198 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5199 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5200                 slave, "slave");
5201 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5202 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5203                 slave_id, UINT16);
5204 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5205 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5206                 port_id, UINT16);
5207
5208 cmdline_parse_inst_t cmd_add_bonding_slave = {
5209                 .f = cmd_add_bonding_slave_parsed,
5210                 .help_str = "add bonding slave <slave_id> <port_id>: "
5211                         "Add a slave device to a bonded device",
5212                 .data = NULL,
5213                 .tokens = {
5214                                 (void *)&cmd_addbonding_slave_add,
5215                                 (void *)&cmd_addbonding_slave_bonding,
5216                                 (void *)&cmd_addbonding_slave_slave,
5217                                 (void *)&cmd_addbonding_slave_slaveid,
5218                                 (void *)&cmd_addbonding_slave_port,
5219                                 NULL
5220                 }
5221 };
5222
5223 /* *** REMOVE SLAVE *** */
5224 struct cmd_remove_bonding_slave_result {
5225         cmdline_fixed_string_t remove;
5226         cmdline_fixed_string_t bonding;
5227         cmdline_fixed_string_t slave;
5228         portid_t slave_id;
5229         portid_t port_id;
5230 };
5231
5232 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5233                 __attribute__((unused))  struct cmdline *cl,
5234                 __attribute__((unused)) void *data)
5235 {
5236         struct cmd_remove_bonding_slave_result *res = parsed_result;
5237         portid_t master_port_id = res->port_id;
5238         portid_t slave_port_id = res->slave_id;
5239
5240         /* remove the slave from a bonded device. */
5241         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5242                 printf("\t Failed to remove slave %d from master port = %d.\n",
5243                                 slave_port_id, master_port_id);
5244                 return;
5245         }
5246         init_port_config();
5247         clear_port_slave_flag(slave_port_id);
5248 }
5249
5250 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5251                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5252                                 remove, "remove");
5253 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5254                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5255                                 bonding, "bonding");
5256 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5257                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5258                                 slave, "slave");
5259 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5260                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5261                                 slave_id, UINT16);
5262 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5263                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5264                                 port_id, UINT16);
5265
5266 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5267                 .f = cmd_remove_bonding_slave_parsed,
5268                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5269                         "Remove a slave device from a bonded device",
5270                 .data = NULL,
5271                 .tokens = {
5272                                 (void *)&cmd_removebonding_slave_remove,
5273                                 (void *)&cmd_removebonding_slave_bonding,
5274                                 (void *)&cmd_removebonding_slave_slave,
5275                                 (void *)&cmd_removebonding_slave_slaveid,
5276                                 (void *)&cmd_removebonding_slave_port,
5277                                 NULL
5278                 }
5279 };
5280
5281 /* *** CREATE BONDED DEVICE *** */
5282 struct cmd_create_bonded_device_result {
5283         cmdline_fixed_string_t create;
5284         cmdline_fixed_string_t bonded;
5285         cmdline_fixed_string_t device;
5286         uint8_t mode;
5287         uint8_t socket;
5288 };
5289
5290 static int bond_dev_num = 0;
5291
5292 static void cmd_create_bonded_device_parsed(void *parsed_result,
5293                 __attribute__((unused))  struct cmdline *cl,
5294                 __attribute__((unused)) void *data)
5295 {
5296         struct cmd_create_bonded_device_result *res = parsed_result;
5297         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5298         int port_id;
5299
5300         if (test_done == 0) {
5301                 printf("Please stop forwarding first\n");
5302                 return;
5303         }
5304
5305         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5306                         bond_dev_num++);
5307
5308         /* Create a new bonded device. */
5309         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5310         if (port_id < 0) {
5311                 printf("\t Failed to create bonded device.\n");
5312                 return;
5313         } else {
5314                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5315                                 port_id);
5316
5317                 /* Update number of ports */
5318                 nb_ports = rte_eth_dev_count();
5319                 reconfig(port_id, res->socket);
5320                 rte_eth_promiscuous_enable(port_id);
5321         }
5322
5323 }
5324
5325 cmdline_parse_token_string_t cmd_createbonded_device_create =
5326                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5327                                 create, "create");
5328 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5329                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5330                                 bonded, "bonded");
5331 cmdline_parse_token_string_t cmd_createbonded_device_device =
5332                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5333                                 device, "device");
5334 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5335                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5336                                 mode, UINT8);
5337 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5338                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5339                                 socket, UINT8);
5340
5341 cmdline_parse_inst_t cmd_create_bonded_device = {
5342                 .f = cmd_create_bonded_device_parsed,
5343                 .help_str = "create bonded device <mode> <socket>: "
5344                         "Create a new bonded device with specific bonding mode and socket",
5345                 .data = NULL,
5346                 .tokens = {
5347                                 (void *)&cmd_createbonded_device_create,
5348                                 (void *)&cmd_createbonded_device_bonded,
5349                                 (void *)&cmd_createbonded_device_device,
5350                                 (void *)&cmd_createbonded_device_mode,
5351                                 (void *)&cmd_createbonded_device_socket,
5352                                 NULL
5353                 }
5354 };
5355
5356 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5357 struct cmd_set_bond_mac_addr_result {
5358         cmdline_fixed_string_t set;
5359         cmdline_fixed_string_t bonding;
5360         cmdline_fixed_string_t mac_addr;
5361         uint16_t port_num;
5362         struct ether_addr address;
5363 };
5364
5365 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5366                 __attribute__((unused))  struct cmdline *cl,
5367                 __attribute__((unused)) void *data)
5368 {
5369         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5370         int ret;
5371
5372         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5373                 return;
5374
5375         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5376
5377         /* check the return value and print it if is < 0 */
5378         if (ret < 0)
5379                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5380 }
5381
5382 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5383                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5384 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5385                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5386                                 "bonding");
5387 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5388                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5389                                 "mac_addr");
5390 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5391                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5392                                 port_num, UINT16);
5393 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5394                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5395
5396 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5397                 .f = cmd_set_bond_mac_addr_parsed,
5398                 .data = (void *) 0,
5399                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5400                 .tokens = {
5401                                 (void *)&cmd_set_bond_mac_addr_set,
5402                                 (void *)&cmd_set_bond_mac_addr_bonding,
5403                                 (void *)&cmd_set_bond_mac_addr_mac,
5404                                 (void *)&cmd_set_bond_mac_addr_portnum,
5405                                 (void *)&cmd_set_bond_mac_addr_addr,
5406                                 NULL
5407                 }
5408 };
5409
5410
5411 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5412 struct cmd_set_bond_mon_period_result {
5413         cmdline_fixed_string_t set;
5414         cmdline_fixed_string_t bonding;
5415         cmdline_fixed_string_t mon_period;
5416         uint16_t port_num;
5417         uint32_t period_ms;
5418 };
5419
5420 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5421                 __attribute__((unused))  struct cmdline *cl,
5422                 __attribute__((unused)) void *data)
5423 {
5424         struct cmd_set_bond_mon_period_result *res = parsed_result;
5425         int ret;
5426
5427         if (res->port_num >= nb_ports) {
5428                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5429                 return;
5430         }
5431
5432         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5433
5434         /* check the return value and print it if is < 0 */
5435         if (ret < 0)
5436                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5437 }
5438
5439 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5440                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5441                                 set, "set");
5442 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5443                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5444                                 bonding, "bonding");
5445 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5446                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5447                                 mon_period,     "mon_period");
5448 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5449                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5450                                 port_num, UINT16);
5451 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5452                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5453                                 period_ms, UINT32);
5454
5455 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5456                 .f = cmd_set_bond_mon_period_parsed,
5457                 .data = (void *) 0,
5458                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5459                 .tokens = {
5460                                 (void *)&cmd_set_bond_mon_period_set,
5461                                 (void *)&cmd_set_bond_mon_period_bonding,
5462                                 (void *)&cmd_set_bond_mon_period_mon_period,
5463                                 (void *)&cmd_set_bond_mon_period_portnum,
5464                                 (void *)&cmd_set_bond_mon_period_period_ms,
5465                                 NULL
5466                 }
5467 };
5468
5469
5470
5471 struct cmd_set_bonding_agg_mode_policy_result {
5472         cmdline_fixed_string_t set;
5473         cmdline_fixed_string_t bonding;
5474         cmdline_fixed_string_t agg_mode;
5475         uint16_t port_num;
5476         cmdline_fixed_string_t policy;
5477 };
5478
5479
5480 static void
5481 cmd_set_bonding_agg_mode(void *parsed_result,
5482                 __attribute__((unused)) struct cmdline *cl,
5483                 __attribute__((unused)) void *data)
5484 {
5485         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5486         uint8_t policy = AGG_BANDWIDTH;
5487
5488         if (res->port_num >= nb_ports) {
5489                 printf("Port id %d must be less than %d\n",
5490                                 res->port_num, nb_ports);
5491                 return;
5492         }
5493
5494         if (!strcmp(res->policy, "bandwidth"))
5495                 policy = AGG_BANDWIDTH;
5496         else if (!strcmp(res->policy, "stable"))
5497                 policy = AGG_STABLE;
5498         else if (!strcmp(res->policy, "count"))
5499                 policy = AGG_COUNT;
5500
5501         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5502 }
5503
5504
5505 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5506         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5507                                 set, "set");
5508 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5509         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5510                                 bonding, "bonding");
5511
5512 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5513         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5514                                 agg_mode, "agg_mode");
5515
5516 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5517         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5518                                 port_num, UINT16);
5519
5520 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5521         TOKEN_STRING_INITIALIZER(
5522                         struct cmd_set_bonding_balance_xmit_policy_result,
5523                 policy, "stable#bandwidth#count");
5524
5525 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5526         .f = cmd_set_bonding_agg_mode,
5527         .data = (void *) 0,
5528         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5529         .tokens = {
5530                         (void *)&cmd_set_bonding_agg_mode_set,
5531                         (void *)&cmd_set_bonding_agg_mode_bonding,
5532                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5533                         (void *)&cmd_set_bonding_agg_mode_portnum,
5534                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5535                         NULL
5536                 }
5537 };
5538
5539
5540 #endif /* RTE_LIBRTE_PMD_BOND */
5541
5542 /* *** SET FORWARDING MODE *** */
5543 struct cmd_set_fwd_mode_result {
5544         cmdline_fixed_string_t set;
5545         cmdline_fixed_string_t fwd;
5546         cmdline_fixed_string_t mode;
5547 };
5548
5549 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5550                                     __attribute__((unused)) struct cmdline *cl,
5551                                     __attribute__((unused)) void *data)
5552 {
5553         struct cmd_set_fwd_mode_result *res = parsed_result;
5554
5555         retry_enabled = 0;
5556         set_pkt_forwarding_mode(res->mode);
5557 }
5558
5559 cmdline_parse_token_string_t cmd_setfwd_set =
5560         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5561 cmdline_parse_token_string_t cmd_setfwd_fwd =
5562         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5563 cmdline_parse_token_string_t cmd_setfwd_mode =
5564         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5565                 "" /* defined at init */);
5566
5567 cmdline_parse_inst_t cmd_set_fwd_mode = {
5568         .f = cmd_set_fwd_mode_parsed,
5569         .data = NULL,
5570         .help_str = NULL, /* defined at init */
5571         .tokens = {
5572                 (void *)&cmd_setfwd_set,
5573                 (void *)&cmd_setfwd_fwd,
5574                 (void *)&cmd_setfwd_mode,
5575                 NULL,
5576         },
5577 };
5578
5579 static void cmd_set_fwd_mode_init(void)
5580 {
5581         char *modes, *c;
5582         static char token[128];
5583         static char help[256];
5584         cmdline_parse_token_string_t *token_struct;
5585
5586         modes = list_pkt_forwarding_modes();
5587         snprintf(help, sizeof(help), "set fwd %s: "
5588                 "Set packet forwarding mode", modes);
5589         cmd_set_fwd_mode.help_str = help;
5590
5591         /* string token separator is # */
5592         for (c = token; *modes != '\0'; modes++)
5593                 if (*modes == '|')
5594                         *c++ = '#';
5595                 else
5596                         *c++ = *modes;
5597         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5598         token_struct->string_data.str = token;
5599 }
5600
5601 /* *** SET RETRY FORWARDING MODE *** */
5602 struct cmd_set_fwd_retry_mode_result {
5603         cmdline_fixed_string_t set;
5604         cmdline_fixed_string_t fwd;
5605         cmdline_fixed_string_t mode;
5606         cmdline_fixed_string_t retry;
5607 };
5608
5609 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5610                             __attribute__((unused)) struct cmdline *cl,
5611                             __attribute__((unused)) void *data)
5612 {
5613         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5614
5615         retry_enabled = 1;
5616         set_pkt_forwarding_mode(res->mode);
5617 }
5618
5619 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5620         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5621                         set, "set");
5622 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5623         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5624                         fwd, "fwd");
5625 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5627                         mode,
5628                 "" /* defined at init */);
5629 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5630         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5631                         retry, "retry");
5632
5633 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5634         .f = cmd_set_fwd_retry_mode_parsed,
5635         .data = NULL,
5636         .help_str = NULL, /* defined at init */
5637         .tokens = {
5638                 (void *)&cmd_setfwd_retry_set,
5639                 (void *)&cmd_setfwd_retry_fwd,
5640                 (void *)&cmd_setfwd_retry_mode,
5641                 (void *)&cmd_setfwd_retry_retry,
5642                 NULL,
5643         },
5644 };
5645
5646 static void cmd_set_fwd_retry_mode_init(void)
5647 {
5648         char *modes, *c;
5649         static char token[128];
5650         static char help[256];
5651         cmdline_parse_token_string_t *token_struct;
5652
5653         modes = list_pkt_forwarding_retry_modes();
5654         snprintf(help, sizeof(help), "set fwd %s retry: "
5655                 "Set packet forwarding mode with retry", modes);
5656         cmd_set_fwd_retry_mode.help_str = help;
5657
5658         /* string token separator is # */
5659         for (c = token; *modes != '\0'; modes++)
5660                 if (*modes == '|')
5661                         *c++ = '#';
5662                 else
5663                         *c++ = *modes;
5664         token_struct = (cmdline_parse_token_string_t *)
5665                 cmd_set_fwd_retry_mode.tokens[2];
5666         token_struct->string_data.str = token;
5667 }
5668
5669 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5670 struct cmd_set_burst_tx_retry_result {
5671         cmdline_fixed_string_t set;
5672         cmdline_fixed_string_t burst;
5673         cmdline_fixed_string_t tx;
5674         cmdline_fixed_string_t delay;
5675         uint32_t time;
5676         cmdline_fixed_string_t retry;
5677         uint32_t retry_num;
5678 };
5679
5680 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5681                                         __attribute__((unused)) struct cmdline *cl,
5682                                         __attribute__((unused)) void *data)
5683 {
5684         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5685
5686         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5687                 && !strcmp(res->tx, "tx")) {
5688                 if (!strcmp(res->delay, "delay"))
5689                         burst_tx_delay_time = res->time;
5690                 if (!strcmp(res->retry, "retry"))
5691                         burst_tx_retry_num = res->retry_num;
5692         }
5693
5694 }
5695
5696 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5697         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5698 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5699         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5700                                  "burst");
5701 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5702         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5703 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5704         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5705 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5706         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5707 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5708         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5709 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5710         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5711
5712 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5713         .f = cmd_set_burst_tx_retry_parsed,
5714         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5715         .tokens = {
5716                 (void *)&cmd_set_burst_tx_retry_set,
5717                 (void *)&cmd_set_burst_tx_retry_burst,
5718                 (void *)&cmd_set_burst_tx_retry_tx,
5719                 (void *)&cmd_set_burst_tx_retry_delay,
5720                 (void *)&cmd_set_burst_tx_retry_time,
5721                 (void *)&cmd_set_burst_tx_retry_retry,
5722                 (void *)&cmd_set_burst_tx_retry_retry_num,
5723                 NULL,
5724         },
5725 };
5726
5727 /* *** SET PROMISC MODE *** */
5728 struct cmd_set_promisc_mode_result {
5729         cmdline_fixed_string_t set;
5730         cmdline_fixed_string_t promisc;
5731         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5732         uint16_t port_num;               /* valid if "allports" argument == 0 */
5733         cmdline_fixed_string_t mode;
5734 };
5735
5736 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5737                                         __attribute__((unused)) struct cmdline *cl,
5738                                         void *allports)
5739 {
5740         struct cmd_set_promisc_mode_result *res = parsed_result;
5741         int enable;
5742         portid_t i;
5743
5744         if (!strcmp(res->mode, "on"))
5745                 enable = 1;
5746         else
5747                 enable = 0;
5748
5749         /* all ports */
5750         if (allports) {
5751                 RTE_ETH_FOREACH_DEV(i) {
5752                         if (enable)
5753                                 rte_eth_promiscuous_enable(i);
5754                         else
5755                                 rte_eth_promiscuous_disable(i);
5756                 }
5757         }
5758         else {
5759                 if (enable)
5760                         rte_eth_promiscuous_enable(res->port_num);
5761                 else
5762                         rte_eth_promiscuous_disable(res->port_num);
5763         }
5764 }
5765
5766 cmdline_parse_token_string_t cmd_setpromisc_set =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5768 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5769         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5770                                  "promisc");
5771 cmdline_parse_token_string_t cmd_setpromisc_portall =
5772         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5773                                  "all");
5774 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5775         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5776                               UINT8);
5777 cmdline_parse_token_string_t cmd_setpromisc_mode =
5778         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5779                                  "on#off");
5780
5781 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5782         .f = cmd_set_promisc_mode_parsed,
5783         .data = (void *)1,
5784         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5785         .tokens = {
5786                 (void *)&cmd_setpromisc_set,
5787                 (void *)&cmd_setpromisc_promisc,
5788                 (void *)&cmd_setpromisc_portall,
5789                 (void *)&cmd_setpromisc_mode,
5790                 NULL,
5791         },
5792 };
5793
5794 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5795         .f = cmd_set_promisc_mode_parsed,
5796         .data = (void *)0,
5797         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5798         .tokens = {
5799                 (void *)&cmd_setpromisc_set,
5800                 (void *)&cmd_setpromisc_promisc,
5801                 (void *)&cmd_setpromisc_portnum,
5802                 (void *)&cmd_setpromisc_mode,
5803                 NULL,
5804         },
5805 };
5806
5807 /* *** SET ALLMULTI MODE *** */
5808 struct cmd_set_allmulti_mode_result {
5809         cmdline_fixed_string_t set;
5810         cmdline_fixed_string_t allmulti;
5811         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5812         uint16_t port_num;               /* valid if "allports" argument == 0 */
5813         cmdline_fixed_string_t mode;
5814 };
5815
5816 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5817                                         __attribute__((unused)) struct cmdline *cl,
5818                                         void *allports)
5819 {
5820         struct cmd_set_allmulti_mode_result *res = parsed_result;
5821         int enable;
5822         portid_t i;
5823
5824         if (!strcmp(res->mode, "on"))
5825                 enable = 1;
5826         else
5827                 enable = 0;
5828
5829         /* all ports */
5830         if (allports) {
5831                 RTE_ETH_FOREACH_DEV(i) {
5832                         if (enable)
5833                                 rte_eth_allmulticast_enable(i);
5834                         else
5835                                 rte_eth_allmulticast_disable(i);
5836                 }
5837         }
5838         else {
5839                 if (enable)
5840                         rte_eth_allmulticast_enable(res->port_num);
5841                 else
5842                         rte_eth_allmulticast_disable(res->port_num);
5843         }
5844 }
5845
5846 cmdline_parse_token_string_t cmd_setallmulti_set =
5847         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5848 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5849         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5850                                  "allmulti");
5851 cmdline_parse_token_string_t cmd_setallmulti_portall =
5852         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5853                                  "all");
5854 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5855         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5856                               UINT16);
5857 cmdline_parse_token_string_t cmd_setallmulti_mode =
5858         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5859                                  "on#off");
5860
5861 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5862         .f = cmd_set_allmulti_mode_parsed,
5863         .data = (void *)1,
5864         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5865         .tokens = {
5866                 (void *)&cmd_setallmulti_set,
5867                 (void *)&cmd_setallmulti_allmulti,
5868                 (void *)&cmd_setallmulti_portall,
5869                 (void *)&cmd_setallmulti_mode,
5870                 NULL,
5871         },
5872 };
5873
5874 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5875         .f = cmd_set_allmulti_mode_parsed,
5876         .data = (void *)0,
5877         .help_str = "set allmulti <port_id> on|off: "
5878                 "Set allmulti mode on port_id",
5879         .tokens = {
5880                 (void *)&cmd_setallmulti_set,
5881                 (void *)&cmd_setallmulti_allmulti,
5882                 (void *)&cmd_setallmulti_portnum,
5883                 (void *)&cmd_setallmulti_mode,
5884                 NULL,
5885         },
5886 };
5887
5888 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5889 struct cmd_link_flow_ctrl_set_result {
5890         cmdline_fixed_string_t set;
5891         cmdline_fixed_string_t flow_ctrl;
5892         cmdline_fixed_string_t rx;
5893         cmdline_fixed_string_t rx_lfc_mode;
5894         cmdline_fixed_string_t tx;
5895         cmdline_fixed_string_t tx_lfc_mode;
5896         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5897         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5898         cmdline_fixed_string_t autoneg_str;
5899         cmdline_fixed_string_t autoneg;
5900         cmdline_fixed_string_t hw_str;
5901         uint32_t high_water;
5902         cmdline_fixed_string_t lw_str;
5903         uint32_t low_water;
5904         cmdline_fixed_string_t pt_str;
5905         uint16_t pause_time;
5906         cmdline_fixed_string_t xon_str;
5907         uint16_t send_xon;
5908         portid_t port_id;
5909 };
5910
5911 cmdline_parse_token_string_t cmd_lfc_set_set =
5912         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5913                                 set, "set");
5914 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5915         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5916                                 flow_ctrl, "flow_ctrl");
5917 cmdline_parse_token_string_t cmd_lfc_set_rx =
5918         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5919                                 rx, "rx");
5920 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5921         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5922                                 rx_lfc_mode, "on#off");
5923 cmdline_parse_token_string_t cmd_lfc_set_tx =
5924         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5925                                 tx, "tx");
5926 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5927         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5928                                 tx_lfc_mode, "on#off");
5929 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5930         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5931                                 hw_str, "high_water");
5932 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5933         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5934                                 high_water, UINT32);
5935 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5936         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5937                                 lw_str, "low_water");
5938 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5939         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5940                                 low_water, UINT32);
5941 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5942         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5943                                 pt_str, "pause_time");
5944 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5945         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5946                                 pause_time, UINT16);
5947 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5948         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5949                                 xon_str, "send_xon");
5950 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5951         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5952                                 send_xon, UINT16);
5953 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5954         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5955                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5956 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5957         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5958                                 mac_ctrl_frame_fwd_mode, "on#off");
5959 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5960         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5961                                 autoneg_str, "autoneg");
5962 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5963         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5964                                 autoneg, "on#off");
5965 cmdline_parse_token_num_t cmd_lfc_set_portid =
5966         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5967                                 port_id, UINT16);
5968
5969 /* forward declaration */
5970 static void
5971 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5972                               void *data);
5973
5974 cmdline_parse_inst_t cmd_link_flow_control_set = {
5975         .f = cmd_link_flow_ctrl_set_parsed,
5976         .data = NULL,
5977         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5978                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5979                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5980         .tokens = {
5981                 (void *)&cmd_lfc_set_set,
5982                 (void *)&cmd_lfc_set_flow_ctrl,
5983                 (void *)&cmd_lfc_set_rx,
5984                 (void *)&cmd_lfc_set_rx_mode,
5985                 (void *)&cmd_lfc_set_tx,
5986                 (void *)&cmd_lfc_set_tx_mode,
5987                 (void *)&cmd_lfc_set_high_water,
5988                 (void *)&cmd_lfc_set_low_water,
5989                 (void *)&cmd_lfc_set_pause_time,
5990                 (void *)&cmd_lfc_set_send_xon,
5991                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5992                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5993                 (void *)&cmd_lfc_set_autoneg_str,
5994                 (void *)&cmd_lfc_set_autoneg,
5995                 (void *)&cmd_lfc_set_portid,
5996                 NULL,
5997         },
5998 };
5999
6000 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6001         .f = cmd_link_flow_ctrl_set_parsed,
6002         .data = (void *)&cmd_link_flow_control_set_rx,
6003         .help_str = "set flow_ctrl rx on|off <port_id>: "
6004                 "Change rx flow control parameter",
6005         .tokens = {
6006                 (void *)&cmd_lfc_set_set,
6007                 (void *)&cmd_lfc_set_flow_ctrl,
6008                 (void *)&cmd_lfc_set_rx,
6009                 (void *)&cmd_lfc_set_rx_mode,
6010                 (void *)&cmd_lfc_set_portid,
6011                 NULL,
6012         },
6013 };
6014
6015 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6016         .f = cmd_link_flow_ctrl_set_parsed,
6017         .data = (void *)&cmd_link_flow_control_set_tx,
6018         .help_str = "set flow_ctrl tx on|off <port_id>: "
6019                 "Change tx flow control parameter",
6020         .tokens = {
6021                 (void *)&cmd_lfc_set_set,
6022                 (void *)&cmd_lfc_set_flow_ctrl,
6023                 (void *)&cmd_lfc_set_tx,
6024                 (void *)&cmd_lfc_set_tx_mode,
6025                 (void *)&cmd_lfc_set_portid,
6026                 NULL,
6027         },
6028 };
6029
6030 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6031         .f = cmd_link_flow_ctrl_set_parsed,
6032         .data = (void *)&cmd_link_flow_control_set_hw,
6033         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6034                 "Change high water flow control parameter",
6035         .tokens = {
6036                 (void *)&cmd_lfc_set_set,
6037                 (void *)&cmd_lfc_set_flow_ctrl,
6038                 (void *)&cmd_lfc_set_high_water_str,
6039                 (void *)&cmd_lfc_set_high_water,
6040                 (void *)&cmd_lfc_set_portid,
6041                 NULL,
6042         },
6043 };
6044
6045 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6046         .f = cmd_link_flow_ctrl_set_parsed,
6047         .data = (void *)&cmd_link_flow_control_set_lw,
6048         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6049                 "Change low water flow control parameter",
6050         .tokens = {
6051                 (void *)&cmd_lfc_set_set,
6052                 (void *)&cmd_lfc_set_flow_ctrl,
6053                 (void *)&cmd_lfc_set_low_water_str,
6054                 (void *)&cmd_lfc_set_low_water,
6055                 (void *)&cmd_lfc_set_portid,
6056                 NULL,
6057         },
6058 };
6059
6060 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6061         .f = cmd_link_flow_ctrl_set_parsed,
6062         .data = (void *)&cmd_link_flow_control_set_pt,
6063         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6064                 "Change pause time flow control parameter",
6065         .tokens = {
6066                 (void *)&cmd_lfc_set_set,
6067                 (void *)&cmd_lfc_set_flow_ctrl,
6068                 (void *)&cmd_lfc_set_pause_time_str,
6069                 (void *)&cmd_lfc_set_pause_time,
6070                 (void *)&cmd_lfc_set_portid,
6071                 NULL,
6072         },
6073 };
6074
6075 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6076         .f = cmd_link_flow_ctrl_set_parsed,
6077         .data = (void *)&cmd_link_flow_control_set_xon,
6078         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6079                 "Change send_xon flow control parameter",
6080         .tokens = {
6081                 (void *)&cmd_lfc_set_set,
6082                 (void *)&cmd_lfc_set_flow_ctrl,
6083                 (void *)&cmd_lfc_set_send_xon_str,
6084                 (void *)&cmd_lfc_set_send_xon,
6085                 (void *)&cmd_lfc_set_portid,
6086                 NULL,
6087         },
6088 };
6089
6090 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6091         .f = cmd_link_flow_ctrl_set_parsed,
6092         .data = (void *)&cmd_link_flow_control_set_macfwd,
6093         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6094                 "Change mac ctrl fwd flow control parameter",
6095         .tokens = {
6096                 (void *)&cmd_lfc_set_set,
6097                 (void *)&cmd_lfc_set_flow_ctrl,
6098                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6099                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6100                 (void *)&cmd_lfc_set_portid,
6101                 NULL,
6102         },
6103 };
6104
6105 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6106         .f = cmd_link_flow_ctrl_set_parsed,
6107         .data = (void *)&cmd_link_flow_control_set_autoneg,
6108         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6109                 "Change autoneg flow control parameter",
6110         .tokens = {
6111                 (void *)&cmd_lfc_set_set,
6112                 (void *)&cmd_lfc_set_flow_ctrl,
6113                 (void *)&cmd_lfc_set_autoneg_str,
6114                 (void *)&cmd_lfc_set_autoneg,
6115                 (void *)&cmd_lfc_set_portid,
6116                 NULL,
6117         },
6118 };
6119
6120 static void
6121 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6122                               __attribute__((unused)) struct cmdline *cl,
6123                               void *data)
6124 {
6125         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6126         cmdline_parse_inst_t *cmd = data;
6127         struct rte_eth_fc_conf fc_conf;
6128         int rx_fc_en = 0;
6129         int tx_fc_en = 0;
6130         int ret;
6131
6132         /*
6133          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6134          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6135          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6136          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6137          */
6138         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6139                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6140         };
6141
6142         /* Partial command line, retrieve current configuration */
6143         if (cmd) {
6144                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6145                 if (ret != 0) {
6146                         printf("cannot get current flow ctrl parameters, return"
6147                                "code = %d\n", ret);
6148                         return;
6149                 }
6150
6151                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6152                     (fc_conf.mode == RTE_FC_FULL))
6153                         rx_fc_en = 1;
6154                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6155                     (fc_conf.mode == RTE_FC_FULL))
6156                         tx_fc_en = 1;
6157         }
6158
6159         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6160                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6161
6162         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6163                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6164
6165         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6166
6167         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6168                 fc_conf.high_water = res->high_water;
6169
6170         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6171                 fc_conf.low_water = res->low_water;
6172
6173         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6174                 fc_conf.pause_time = res->pause_time;
6175
6176         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6177                 fc_conf.send_xon = res->send_xon;
6178
6179         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6180                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6181                         fc_conf.mac_ctrl_frame_fwd = 1;
6182                 else
6183                         fc_conf.mac_ctrl_frame_fwd = 0;
6184         }
6185
6186         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6187                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6188
6189         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6190         if (ret != 0)
6191                 printf("bad flow contrl parameter, return code = %d \n", ret);
6192 }
6193
6194 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6195 struct cmd_priority_flow_ctrl_set_result {
6196         cmdline_fixed_string_t set;
6197         cmdline_fixed_string_t pfc_ctrl;
6198         cmdline_fixed_string_t rx;
6199         cmdline_fixed_string_t rx_pfc_mode;
6200         cmdline_fixed_string_t tx;
6201         cmdline_fixed_string_t tx_pfc_mode;
6202         uint32_t high_water;
6203         uint32_t low_water;
6204         uint16_t pause_time;
6205         uint8_t  priority;
6206         portid_t port_id;
6207 };
6208
6209 static void
6210 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6211                        __attribute__((unused)) struct cmdline *cl,
6212                        __attribute__((unused)) void *data)
6213 {
6214         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6215         struct rte_eth_pfc_conf pfc_conf;
6216         int rx_fc_enable, tx_fc_enable;
6217         int ret;
6218
6219         /*
6220          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6221          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6222          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6223          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6224          */
6225         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6226                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6227         };
6228
6229         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6230         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6231         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6232         pfc_conf.fc.high_water = res->high_water;
6233         pfc_conf.fc.low_water  = res->low_water;
6234         pfc_conf.fc.pause_time = res->pause_time;
6235         pfc_conf.priority      = res->priority;
6236
6237         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6238         if (ret != 0)
6239                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6240 }
6241
6242 cmdline_parse_token_string_t cmd_pfc_set_set =
6243         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6244                                 set, "set");
6245 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6246         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6247                                 pfc_ctrl, "pfc_ctrl");
6248 cmdline_parse_token_string_t cmd_pfc_set_rx =
6249         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6250                                 rx, "rx");
6251 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6252         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6253                                 rx_pfc_mode, "on#off");
6254 cmdline_parse_token_string_t cmd_pfc_set_tx =
6255         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6256                                 tx, "tx");
6257 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6258         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6259                                 tx_pfc_mode, "on#off");
6260 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6261         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6262                                 high_water, UINT32);
6263 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6264         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6265                                 low_water, UINT32);
6266 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6267         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6268                                 pause_time, UINT16);
6269 cmdline_parse_token_num_t cmd_pfc_set_priority =
6270         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6271                                 priority, UINT8);
6272 cmdline_parse_token_num_t cmd_pfc_set_portid =
6273         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6274                                 port_id, UINT16);
6275
6276 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6277         .f = cmd_priority_flow_ctrl_set_parsed,
6278         .data = NULL,
6279         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6280                 "<pause_time> <priority> <port_id>: "
6281                 "Configure the Ethernet priority flow control",
6282         .tokens = {
6283                 (void *)&cmd_pfc_set_set,
6284                 (void *)&cmd_pfc_set_flow_ctrl,
6285                 (void *)&cmd_pfc_set_rx,
6286                 (void *)&cmd_pfc_set_rx_mode,
6287                 (void *)&cmd_pfc_set_tx,
6288                 (void *)&cmd_pfc_set_tx_mode,
6289                 (void *)&cmd_pfc_set_high_water,
6290                 (void *)&cmd_pfc_set_low_water,
6291                 (void *)&cmd_pfc_set_pause_time,
6292                 (void *)&cmd_pfc_set_priority,
6293                 (void *)&cmd_pfc_set_portid,
6294                 NULL,
6295         },
6296 };
6297
6298 /* *** RESET CONFIGURATION *** */
6299 struct cmd_reset_result {
6300         cmdline_fixed_string_t reset;
6301         cmdline_fixed_string_t def;
6302 };
6303
6304 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6305                              struct cmdline *cl,
6306                              __attribute__((unused)) void *data)
6307 {
6308         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6309         set_def_fwd_config();
6310 }
6311
6312 cmdline_parse_token_string_t cmd_reset_set =
6313         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6314 cmdline_parse_token_string_t cmd_reset_def =
6315         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6316                                  "default");
6317
6318 cmdline_parse_inst_t cmd_reset = {
6319         .f = cmd_reset_parsed,
6320         .data = NULL,
6321         .help_str = "set default: Reset default forwarding configuration",
6322         .tokens = {
6323                 (void *)&cmd_reset_set,
6324                 (void *)&cmd_reset_def,
6325                 NULL,
6326         },
6327 };
6328
6329 /* *** START FORWARDING *** */
6330 struct cmd_start_result {
6331         cmdline_fixed_string_t start;
6332 };
6333
6334 cmdline_parse_token_string_t cmd_start_start =
6335         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6336
6337 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6338                              __attribute__((unused)) struct cmdline *cl,
6339                              __attribute__((unused)) void *data)
6340 {
6341         start_packet_forwarding(0);
6342 }
6343
6344 cmdline_parse_inst_t cmd_start = {
6345         .f = cmd_start_parsed,
6346         .data = NULL,
6347         .help_str = "start: Start packet forwarding",
6348         .tokens = {
6349                 (void *)&cmd_start_start,
6350                 NULL,
6351         },
6352 };
6353
6354 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6355 struct cmd_start_tx_first_result {
6356         cmdline_fixed_string_t start;
6357         cmdline_fixed_string_t tx_first;
6358 };
6359
6360 static void
6361 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6362                           __attribute__((unused)) struct cmdline *cl,
6363                           __attribute__((unused)) void *data)
6364 {
6365         start_packet_forwarding(1);
6366 }
6367
6368 cmdline_parse_token_string_t cmd_start_tx_first_start =
6369         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6370                                  "start");
6371 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6372         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6373                                  tx_first, "tx_first");
6374
6375 cmdline_parse_inst_t cmd_start_tx_first = {
6376         .f = cmd_start_tx_first_parsed,
6377         .data = NULL,
6378         .help_str = "start tx_first: Start packet forwarding, "
6379                 "after sending 1 burst of packets",
6380         .tokens = {
6381                 (void *)&cmd_start_tx_first_start,
6382                 (void *)&cmd_start_tx_first_tx_first,
6383                 NULL,
6384         },
6385 };
6386
6387 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6388 struct cmd_start_tx_first_n_result {
6389         cmdline_fixed_string_t start;
6390         cmdline_fixed_string_t tx_first;
6391         uint32_t tx_num;
6392 };
6393
6394 static void
6395 cmd_start_tx_first_n_parsed(void *parsed_result,
6396                           __attribute__((unused)) struct cmdline *cl,
6397                           __attribute__((unused)) void *data)
6398 {
6399         struct cmd_start_tx_first_n_result *res = parsed_result;
6400
6401         start_packet_forwarding(res->tx_num);
6402 }
6403
6404 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6405         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6406                         start, "start");
6407 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6408         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6409                         tx_first, "tx_first");
6410 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6411         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6412                         tx_num, UINT32);
6413
6414 cmdline_parse_inst_t cmd_start_tx_first_n = {
6415         .f = cmd_start_tx_first_n_parsed,
6416         .data = NULL,
6417         .help_str = "start tx_first <num>: "
6418                 "packet forwarding, after sending <num> bursts of packets",
6419         .tokens = {
6420                 (void *)&cmd_start_tx_first_n_start,
6421                 (void *)&cmd_start_tx_first_n_tx_first,
6422                 (void *)&cmd_start_tx_first_n_tx_num,
6423                 NULL,
6424         },
6425 };
6426
6427 /* *** SET LINK UP *** */
6428 struct cmd_set_link_up_result {
6429         cmdline_fixed_string_t set;
6430         cmdline_fixed_string_t link_up;
6431         cmdline_fixed_string_t port;
6432         portid_t port_id;
6433 };
6434
6435 cmdline_parse_token_string_t cmd_set_link_up_set =
6436         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6437 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6438         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6439                                 "link-up");
6440 cmdline_parse_token_string_t cmd_set_link_up_port =
6441         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6442 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6443         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6444
6445 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6446                              __attribute__((unused)) struct cmdline *cl,
6447                              __attribute__((unused)) void *data)
6448 {
6449         struct cmd_set_link_up_result *res = parsed_result;
6450         dev_set_link_up(res->port_id);
6451 }
6452
6453 cmdline_parse_inst_t cmd_set_link_up = {
6454         .f = cmd_set_link_up_parsed,
6455         .data = NULL,
6456         .help_str = "set link-up port <port id>",
6457         .tokens = {
6458                 (void *)&cmd_set_link_up_set,
6459                 (void *)&cmd_set_link_up_link_up,
6460                 (void *)&cmd_set_link_up_port,
6461                 (void *)&cmd_set_link_up_port_id,
6462                 NULL,
6463         },
6464 };
6465
6466 /* *** SET LINK DOWN *** */
6467 struct cmd_set_link_down_result {
6468         cmdline_fixed_string_t set;
6469         cmdline_fixed_string_t link_down;
6470         cmdline_fixed_string_t port;
6471         portid_t port_id;
6472 };
6473
6474 cmdline_parse_token_string_t cmd_set_link_down_set =
6475         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6476 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6477         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6478                                 "link-down");
6479 cmdline_parse_token_string_t cmd_set_link_down_port =
6480         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6481 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6482         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6483
6484 static void cmd_set_link_down_parsed(
6485                                 __attribute__((unused)) void *parsed_result,
6486                                 __attribute__((unused)) struct cmdline *cl,
6487                                 __attribute__((unused)) void *data)
6488 {
6489         struct cmd_set_link_down_result *res = parsed_result;
6490         dev_set_link_down(res->port_id);
6491 }
6492
6493 cmdline_parse_inst_t cmd_set_link_down = {
6494         .f = cmd_set_link_down_parsed,
6495         .data = NULL,
6496         .help_str = "set link-down port <port id>",
6497         .tokens = {
6498                 (void *)&cmd_set_link_down_set,
6499                 (void *)&cmd_set_link_down_link_down,
6500                 (void *)&cmd_set_link_down_port,
6501                 (void *)&cmd_set_link_down_port_id,
6502                 NULL,
6503         },
6504 };
6505
6506 /* *** SHOW CFG *** */
6507 struct cmd_showcfg_result {
6508         cmdline_fixed_string_t show;
6509         cmdline_fixed_string_t cfg;
6510         cmdline_fixed_string_t what;
6511 };
6512
6513 static void cmd_showcfg_parsed(void *parsed_result,
6514                                __attribute__((unused)) struct cmdline *cl,
6515                                __attribute__((unused)) void *data)
6516 {
6517         struct cmd_showcfg_result *res = parsed_result;
6518         if (!strcmp(res->what, "rxtx"))
6519                 rxtx_config_display();
6520         else if (!strcmp(res->what, "cores"))
6521                 fwd_lcores_config_display();
6522         else if (!strcmp(res->what, "fwd"))
6523                 pkt_fwd_config_display(&cur_fwd_config);
6524         else if (!strcmp(res->what, "txpkts"))
6525                 show_tx_pkt_segments();
6526 }
6527
6528 cmdline_parse_token_string_t cmd_showcfg_show =
6529         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6530 cmdline_parse_token_string_t cmd_showcfg_port =
6531         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6532 cmdline_parse_token_string_t cmd_showcfg_what =
6533         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6534                                  "rxtx#cores#fwd#txpkts");
6535
6536 cmdline_parse_inst_t cmd_showcfg = {
6537         .f = cmd_showcfg_parsed,
6538         .data = NULL,
6539         .help_str = "show config rxtx|cores|fwd|txpkts",
6540         .tokens = {
6541                 (void *)&cmd_showcfg_show,
6542                 (void *)&cmd_showcfg_port,
6543                 (void *)&cmd_showcfg_what,
6544                 NULL,
6545         },
6546 };
6547
6548 /* *** SHOW ALL PORT INFO *** */
6549 struct cmd_showportall_result {
6550         cmdline_fixed_string_t show;
6551         cmdline_fixed_string_t port;
6552         cmdline_fixed_string_t what;
6553         cmdline_fixed_string_t all;
6554 };
6555
6556 static void cmd_showportall_parsed(void *parsed_result,
6557                                 __attribute__((unused)) struct cmdline *cl,
6558                                 __attribute__((unused)) void *data)
6559 {
6560         portid_t i;
6561
6562         struct cmd_showportall_result *res = parsed_result;
6563         if (!strcmp(res->show, "clear")) {
6564                 if (!strcmp(res->what, "stats"))
6565                         RTE_ETH_FOREACH_DEV(i)
6566                                 nic_stats_clear(i);
6567                 else if (!strcmp(res->what, "xstats"))
6568                         RTE_ETH_FOREACH_DEV(i)
6569                                 nic_xstats_clear(i);
6570         } else if (!strcmp(res->what, "info"))
6571                 RTE_ETH_FOREACH_DEV(i)
6572                         port_infos_display(i);
6573         else if (!strcmp(res->what, "stats"))
6574                 RTE_ETH_FOREACH_DEV(i)
6575                         nic_stats_display(i);
6576         else if (!strcmp(res->what, "xstats"))
6577                 RTE_ETH_FOREACH_DEV(i)
6578                         nic_xstats_display(i);
6579         else if (!strcmp(res->what, "fdir"))
6580                 RTE_ETH_FOREACH_DEV(i)
6581                         fdir_get_infos(i);
6582         else if (!strcmp(res->what, "stat_qmap"))
6583                 RTE_ETH_FOREACH_DEV(i)
6584                         nic_stats_mapping_display(i);
6585         else if (!strcmp(res->what, "dcb_tc"))
6586                 RTE_ETH_FOREACH_DEV(i)
6587                         port_dcb_info_display(i);
6588         else if (!strcmp(res->what, "cap"))
6589                 RTE_ETH_FOREACH_DEV(i)
6590                         port_offload_cap_display(i);
6591 }
6592
6593 cmdline_parse_token_string_t cmd_showportall_show =
6594         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6595                                  "show#clear");
6596 cmdline_parse_token_string_t cmd_showportall_port =
6597         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6598 cmdline_parse_token_string_t cmd_showportall_what =
6599         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6600                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6601 cmdline_parse_token_string_t cmd_showportall_all =
6602         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6603 cmdline_parse_inst_t cmd_showportall = {
6604         .f = cmd_showportall_parsed,
6605         .data = NULL,
6606         .help_str = "show|clear port "
6607                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6608         .tokens = {
6609                 (void *)&cmd_showportall_show,
6610                 (void *)&cmd_showportall_port,
6611                 (void *)&cmd_showportall_what,
6612                 (void *)&cmd_showportall_all,
6613                 NULL,
6614         },
6615 };
6616
6617 /* *** SHOW PORT INFO *** */
6618 struct cmd_showport_result {
6619         cmdline_fixed_string_t show;
6620         cmdline_fixed_string_t port;
6621         cmdline_fixed_string_t what;
6622         uint16_t portnum;
6623 };
6624
6625 static void cmd_showport_parsed(void *parsed_result,
6626                                 __attribute__((unused)) struct cmdline *cl,
6627                                 __attribute__((unused)) void *data)
6628 {
6629         struct cmd_showport_result *res = parsed_result;
6630         if (!strcmp(res->show, "clear")) {
6631                 if (!strcmp(res->what, "stats"))
6632                         nic_stats_clear(res->portnum);
6633                 else if (!strcmp(res->what, "xstats"))
6634                         nic_xstats_clear(res->portnum);
6635         } else if (!strcmp(res->what, "info"))
6636                 port_infos_display(res->portnum);
6637         else if (!strcmp(res->what, "stats"))
6638                 nic_stats_display(res->portnum);
6639         else if (!strcmp(res->what, "xstats"))
6640                 nic_xstats_display(res->portnum);
6641         else if (!strcmp(res->what, "fdir"))
6642                  fdir_get_infos(res->portnum);
6643         else if (!strcmp(res->what, "stat_qmap"))
6644                 nic_stats_mapping_display(res->portnum);
6645         else if (!strcmp(res->what, "dcb_tc"))
6646                 port_dcb_info_display(res->portnum);
6647         else if (!strcmp(res->what, "cap"))
6648                 port_offload_cap_display(res->portnum);
6649 }
6650
6651 cmdline_parse_token_string_t cmd_showport_show =
6652         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6653                                  "show#clear");
6654 cmdline_parse_token_string_t cmd_showport_port =
6655         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6656 cmdline_parse_token_string_t cmd_showport_what =
6657         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6658                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6659 cmdline_parse_token_num_t cmd_showport_portnum =
6660         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6661
6662 cmdline_parse_inst_t cmd_showport = {
6663         .f = cmd_showport_parsed,
6664         .data = NULL,
6665         .help_str = "show|clear port "
6666                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6667                 "<port_id>",
6668         .tokens = {
6669                 (void *)&cmd_showport_show,
6670                 (void *)&cmd_showport_port,
6671                 (void *)&cmd_showport_what,
6672                 (void *)&cmd_showport_portnum,
6673                 NULL,
6674         },
6675 };
6676
6677 /* *** SHOW QUEUE INFO *** */
6678 struct cmd_showqueue_result {
6679         cmdline_fixed_string_t show;
6680         cmdline_fixed_string_t type;
6681         cmdline_fixed_string_t what;
6682         uint16_t portnum;
6683         uint16_t queuenum;
6684 };
6685
6686 static void
6687 cmd_showqueue_parsed(void *parsed_result,
6688         __attribute__((unused)) struct cmdline *cl,
6689         __attribute__((unused)) void *data)
6690 {
6691         struct cmd_showqueue_result *res = parsed_result;
6692
6693         if (!strcmp(res->type, "rxq"))
6694                 rx_queue_infos_display(res->portnum, res->queuenum);
6695         else if (!strcmp(res->type, "txq"))
6696                 tx_queue_infos_display(res->portnum, res->queuenum);
6697 }
6698
6699 cmdline_parse_token_string_t cmd_showqueue_show =
6700         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6701 cmdline_parse_token_string_t cmd_showqueue_type =
6702         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6703 cmdline_parse_token_string_t cmd_showqueue_what =
6704         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6705 cmdline_parse_token_num_t cmd_showqueue_portnum =
6706         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6707 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6708         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6709
6710 cmdline_parse_inst_t cmd_showqueue = {
6711         .f = cmd_showqueue_parsed,
6712         .data = NULL,
6713         .help_str = "show rxq|txq info <port_id> <queue_id>",
6714         .tokens = {
6715                 (void *)&cmd_showqueue_show,
6716                 (void *)&cmd_showqueue_type,
6717                 (void *)&cmd_showqueue_what,
6718                 (void *)&cmd_showqueue_portnum,
6719                 (void *)&cmd_showqueue_queuenum,
6720                 NULL,
6721         },
6722 };
6723
6724 /* *** READ PORT REGISTER *** */
6725 struct cmd_read_reg_result {
6726         cmdline_fixed_string_t read;
6727         cmdline_fixed_string_t reg;
6728         portid_t port_id;
6729         uint32_t reg_off;
6730 };
6731
6732 static void
6733 cmd_read_reg_parsed(void *parsed_result,
6734                     __attribute__((unused)) struct cmdline *cl,
6735                     __attribute__((unused)) void *data)
6736 {
6737         struct cmd_read_reg_result *res = parsed_result;
6738         port_reg_display(res->port_id, res->reg_off);
6739 }
6740
6741 cmdline_parse_token_string_t cmd_read_reg_read =
6742         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6743 cmdline_parse_token_string_t cmd_read_reg_reg =
6744         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6745 cmdline_parse_token_num_t cmd_read_reg_port_id =
6746         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6747 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6748         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6749
6750 cmdline_parse_inst_t cmd_read_reg = {
6751         .f = cmd_read_reg_parsed,
6752         .data = NULL,
6753         .help_str = "read reg <port_id> <reg_off>",
6754         .tokens = {
6755                 (void *)&cmd_read_reg_read,
6756                 (void *)&cmd_read_reg_reg,
6757                 (void *)&cmd_read_reg_port_id,
6758                 (void *)&cmd_read_reg_reg_off,
6759                 NULL,
6760         },
6761 };
6762
6763 /* *** READ PORT REGISTER BIT FIELD *** */
6764 struct cmd_read_reg_bit_field_result {
6765         cmdline_fixed_string_t read;
6766         cmdline_fixed_string_t regfield;
6767         portid_t port_id;
6768         uint32_t reg_off;
6769         uint8_t bit1_pos;
6770         uint8_t bit2_pos;
6771 };
6772
6773 static void
6774 cmd_read_reg_bit_field_parsed(void *parsed_result,
6775                               __attribute__((unused)) struct cmdline *cl,
6776                               __attribute__((unused)) void *data)
6777 {
6778         struct cmd_read_reg_bit_field_result *res = parsed_result;
6779         port_reg_bit_field_display(res->port_id, res->reg_off,
6780                                    res->bit1_pos, res->bit2_pos);
6781 }
6782
6783 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6784         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6785                                  "read");
6786 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6787         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6788                                  regfield, "regfield");
6789 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6790         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6791                               UINT16);
6792 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6793         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6794                               UINT32);
6795 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6796         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6797                               UINT8);
6798 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6799         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6800                               UINT8);
6801
6802 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6803         .f = cmd_read_reg_bit_field_parsed,
6804         .data = NULL,
6805         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6806         "Read register bit field between bit_x and bit_y included",
6807         .tokens = {
6808                 (void *)&cmd_read_reg_bit_field_read,
6809                 (void *)&cmd_read_reg_bit_field_regfield,
6810                 (void *)&cmd_read_reg_bit_field_port_id,
6811                 (void *)&cmd_read_reg_bit_field_reg_off,
6812                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6813                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6814                 NULL,
6815         },
6816 };
6817
6818 /* *** READ PORT REGISTER BIT *** */
6819 struct cmd_read_reg_bit_result {
6820         cmdline_fixed_string_t read;
6821         cmdline_fixed_string_t regbit;
6822         portid_t port_id;
6823         uint32_t reg_off;
6824         uint8_t bit_pos;
6825 };
6826
6827 static void
6828 cmd_read_reg_bit_parsed(void *parsed_result,
6829                         __attribute__((unused)) struct cmdline *cl,
6830                         __attribute__((unused)) void *data)
6831 {
6832         struct cmd_read_reg_bit_result *res = parsed_result;
6833         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6834 }
6835
6836 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6837         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6838 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6839         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6840                                  regbit, "regbit");
6841 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6842         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6843 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6844         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6845 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6846         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6847
6848 cmdline_parse_inst_t cmd_read_reg_bit = {
6849         .f = cmd_read_reg_bit_parsed,
6850         .data = NULL,
6851         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6852         .tokens = {
6853                 (void *)&cmd_read_reg_bit_read,
6854                 (void *)&cmd_read_reg_bit_regbit,
6855                 (void *)&cmd_read_reg_bit_port_id,
6856                 (void *)&cmd_read_reg_bit_reg_off,
6857                 (void *)&cmd_read_reg_bit_bit_pos,
6858                 NULL,
6859         },
6860 };
6861
6862 /* *** WRITE PORT REGISTER *** */
6863 struct cmd_write_reg_result {
6864         cmdline_fixed_string_t write;
6865         cmdline_fixed_string_t reg;
6866         portid_t port_id;
6867         uint32_t reg_off;
6868         uint32_t value;
6869 };
6870
6871 static void
6872 cmd_write_reg_parsed(void *parsed_result,
6873                      __attribute__((unused)) struct cmdline *cl,
6874                      __attribute__((unused)) void *data)
6875 {
6876         struct cmd_write_reg_result *res = parsed_result;
6877         port_reg_set(res->port_id, res->reg_off, res->value);
6878 }
6879
6880 cmdline_parse_token_string_t cmd_write_reg_write =
6881         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6882 cmdline_parse_token_string_t cmd_write_reg_reg =
6883         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6884 cmdline_parse_token_num_t cmd_write_reg_port_id =
6885         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6886 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6887         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6888 cmdline_parse_token_num_t cmd_write_reg_value =
6889         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6890
6891 cmdline_parse_inst_t cmd_write_reg = {
6892         .f = cmd_write_reg_parsed,
6893         .data = NULL,
6894         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6895         .tokens = {
6896                 (void *)&cmd_write_reg_write,
6897                 (void *)&cmd_write_reg_reg,
6898                 (void *)&cmd_write_reg_port_id,
6899                 (void *)&cmd_write_reg_reg_off,
6900                 (void *)&cmd_write_reg_value,
6901                 NULL,
6902         },
6903 };
6904
6905 /* *** WRITE PORT REGISTER BIT FIELD *** */
6906 struct cmd_write_reg_bit_field_result {
6907         cmdline_fixed_string_t write;
6908         cmdline_fixed_string_t regfield;
6909         portid_t port_id;
6910         uint32_t reg_off;
6911         uint8_t bit1_pos;
6912         uint8_t bit2_pos;
6913         uint32_t value;
6914 };
6915
6916 static void
6917 cmd_write_reg_bit_field_parsed(void *parsed_result,
6918                                __attribute__((unused)) struct cmdline *cl,
6919                                __attribute__((unused)) void *data)
6920 {
6921         struct cmd_write_reg_bit_field_result *res = parsed_result;
6922         port_reg_bit_field_set(res->port_id, res->reg_off,
6923                           res->bit1_pos, res->bit2_pos, res->value);
6924 }
6925
6926 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6927         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6928                                  "write");
6929 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6930         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6931                                  regfield, "regfield");
6932 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6933         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6934                               UINT16);
6935 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6936         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6937                               UINT32);
6938 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6939         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6940                               UINT8);
6941 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6942         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6943                               UINT8);
6944 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6945         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6946                               UINT32);
6947
6948 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6949         .f = cmd_write_reg_bit_field_parsed,
6950         .data = NULL,
6951         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6952                 "<reg_value>: "
6953                 "Set register bit field between bit_x and bit_y included",
6954         .tokens = {
6955                 (void *)&cmd_write_reg_bit_field_write,
6956                 (void *)&cmd_write_reg_bit_field_regfield,
6957                 (void *)&cmd_write_reg_bit_field_port_id,
6958                 (void *)&cmd_write_reg_bit_field_reg_off,
6959                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6960                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6961                 (void *)&cmd_write_reg_bit_field_value,
6962                 NULL,
6963         },
6964 };
6965
6966 /* *** WRITE PORT REGISTER BIT *** */
6967 struct cmd_write_reg_bit_result {
6968         cmdline_fixed_string_t write;
6969         cmdline_fixed_string_t regbit;
6970         portid_t port_id;
6971         uint32_t reg_off;
6972         uint8_t bit_pos;
6973         uint8_t value;
6974 };
6975
6976 static void
6977 cmd_write_reg_bit_parsed(void *parsed_result,
6978                          __attribute__((unused)) struct cmdline *cl,
6979                          __attribute__((unused)) void *data)
6980 {
6981         struct cmd_write_reg_bit_result *res = parsed_result;
6982         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6983 }
6984
6985 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6986         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6987                                  "write");
6988 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6989         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6990                                  regbit, "regbit");
6991 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6992         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6993 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6994         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6995 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6996         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6997 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6998         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6999
7000 cmdline_parse_inst_t cmd_write_reg_bit = {
7001         .f = cmd_write_reg_bit_parsed,
7002         .data = NULL,
7003         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7004                 "0 <= bit_x <= 31",
7005         .tokens = {
7006                 (void *)&cmd_write_reg_bit_write,
7007                 (void *)&cmd_write_reg_bit_regbit,
7008                 (void *)&cmd_write_reg_bit_port_id,
7009                 (void *)&cmd_write_reg_bit_reg_off,
7010                 (void *)&cmd_write_reg_bit_bit_pos,
7011                 (void *)&cmd_write_reg_bit_value,
7012                 NULL,
7013         },
7014 };
7015
7016 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7017 struct cmd_read_rxd_txd_result {
7018         cmdline_fixed_string_t read;
7019         cmdline_fixed_string_t rxd_txd;
7020         portid_t port_id;
7021         uint16_t queue_id;
7022         uint16_t desc_id;
7023 };
7024
7025 static void
7026 cmd_read_rxd_txd_parsed(void *parsed_result,
7027                         __attribute__((unused)) struct cmdline *cl,
7028                         __attribute__((unused)) void *data)
7029 {
7030         struct cmd_read_rxd_txd_result *res = parsed_result;
7031
7032         if (!strcmp(res->rxd_txd, "rxd"))
7033                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7034         else if (!strcmp(res->rxd_txd, "txd"))
7035                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7036 }
7037
7038 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7039         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7040 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7041         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7042                                  "rxd#txd");
7043 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7044         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7045 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7046         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7047 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7048         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7049
7050 cmdline_parse_inst_t cmd_read_rxd_txd = {
7051         .f = cmd_read_rxd_txd_parsed,
7052         .data = NULL,
7053         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7054         .tokens = {
7055                 (void *)&cmd_read_rxd_txd_read,
7056                 (void *)&cmd_read_rxd_txd_rxd_txd,
7057                 (void *)&cmd_read_rxd_txd_port_id,
7058                 (void *)&cmd_read_rxd_txd_queue_id,
7059                 (void *)&cmd_read_rxd_txd_desc_id,
7060                 NULL,
7061         },
7062 };
7063
7064 /* *** QUIT *** */
7065 struct cmd_quit_result {
7066         cmdline_fixed_string_t quit;
7067 };
7068
7069 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7070                             struct cmdline *cl,
7071                             __attribute__((unused)) void *data)
7072 {
7073         pmd_test_exit();
7074         cmdline_quit(cl);
7075 }
7076
7077 cmdline_parse_token_string_t cmd_quit_quit =
7078         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7079
7080 cmdline_parse_inst_t cmd_quit = {
7081         .f = cmd_quit_parsed,
7082         .data = NULL,
7083         .help_str = "quit: Exit application",
7084         .tokens = {
7085                 (void *)&cmd_quit_quit,
7086                 NULL,
7087         },
7088 };
7089
7090 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7091 struct cmd_mac_addr_result {
7092         cmdline_fixed_string_t mac_addr_cmd;
7093         cmdline_fixed_string_t what;
7094         uint16_t port_num;
7095         struct ether_addr address;
7096 };
7097
7098 static void cmd_mac_addr_parsed(void *parsed_result,
7099                 __attribute__((unused)) struct cmdline *cl,
7100                 __attribute__((unused)) void *data)
7101 {
7102         struct cmd_mac_addr_result *res = parsed_result;
7103         int ret;
7104
7105         if (strcmp(res->what, "add") == 0)
7106                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7107         else if (strcmp(res->what, "set") == 0)
7108                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7109                                                        &res->address);
7110         else
7111                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7112
7113         /* check the return value and print it if is < 0 */
7114         if(ret < 0)
7115                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7116
7117 }
7118
7119 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7120         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7121                                 "mac_addr");
7122 cmdline_parse_token_string_t cmd_mac_addr_what =
7123         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7124                                 "add#remove#set");
7125 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7126                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7127                                         UINT16);
7128 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7129                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7130
7131 cmdline_parse_inst_t cmd_mac_addr = {
7132         .f = cmd_mac_addr_parsed,
7133         .data = (void *)0,
7134         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7135                         "Add/Remove/Set MAC address on port_id",
7136         .tokens = {
7137                 (void *)&cmd_mac_addr_cmd,
7138                 (void *)&cmd_mac_addr_what,
7139                 (void *)&cmd_mac_addr_portnum,
7140                 (void *)&cmd_mac_addr_addr,
7141                 NULL,
7142         },
7143 };
7144
7145
7146 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7147 struct cmd_set_qmap_result {
7148         cmdline_fixed_string_t set;
7149         cmdline_fixed_string_t qmap;
7150         cmdline_fixed_string_t what;
7151         portid_t port_id;
7152         uint16_t queue_id;
7153         uint8_t map_value;
7154 };
7155
7156 static void
7157 cmd_set_qmap_parsed(void *parsed_result,
7158                        __attribute__((unused)) struct cmdline *cl,
7159                        __attribute__((unused)) void *data)
7160 {
7161         struct cmd_set_qmap_result *res = parsed_result;
7162         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7163
7164         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7165 }
7166
7167 cmdline_parse_token_string_t cmd_setqmap_set =
7168         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7169                                  set, "set");
7170 cmdline_parse_token_string_t cmd_setqmap_qmap =
7171         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7172                                  qmap, "stat_qmap");
7173 cmdline_parse_token_string_t cmd_setqmap_what =
7174         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7175                                  what, "tx#rx");
7176 cmdline_parse_token_num_t cmd_setqmap_portid =
7177         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7178                               port_id, UINT16);
7179 cmdline_parse_token_num_t cmd_setqmap_queueid =
7180         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7181                               queue_id, UINT16);
7182 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7183         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7184                               map_value, UINT8);
7185
7186 cmdline_parse_inst_t cmd_set_qmap = {
7187         .f = cmd_set_qmap_parsed,
7188         .data = NULL,
7189         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7190                 "Set statistics mapping value on tx|rx queue_id of port_id",
7191         .tokens = {
7192                 (void *)&cmd_setqmap_set,
7193                 (void *)&cmd_setqmap_qmap,
7194                 (void *)&cmd_setqmap_what,
7195                 (void *)&cmd_setqmap_portid,
7196                 (void *)&cmd_setqmap_queueid,
7197                 (void *)&cmd_setqmap_mapvalue,
7198                 NULL,
7199         },
7200 };
7201
7202 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7203 struct cmd_set_xstats_hide_zero_result {
7204         cmdline_fixed_string_t keyword;
7205         cmdline_fixed_string_t name;
7206         cmdline_fixed_string_t on_off;
7207 };
7208
7209 static void
7210 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7211                         __attribute__((unused)) struct cmdline *cl,
7212                         __attribute__((unused)) void *data)
7213 {
7214         struct cmd_set_xstats_hide_zero_result *res;
7215         uint16_t on_off = 0;
7216
7217         res = parsed_result;
7218         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7219         set_xstats_hide_zero(on_off);
7220 }
7221
7222 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7223         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7224                                  keyword, "set");
7225 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7226         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7227                                  name, "xstats-hide-zero");
7228 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7229         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7230                                  on_off, "on#off");
7231
7232 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7233         .f = cmd_set_xstats_hide_zero_parsed,
7234         .data = NULL,
7235         .help_str = "set xstats-hide-zero on|off",
7236         .tokens = {
7237                 (void *)&cmd_set_xstats_hide_zero_keyword,
7238                 (void *)&cmd_set_xstats_hide_zero_name,
7239                 (void *)&cmd_set_xstats_hide_zero_on_off,
7240                 NULL,
7241         },
7242 };
7243
7244 /* *** CONFIGURE UNICAST HASH TABLE *** */
7245 struct cmd_set_uc_hash_table {
7246         cmdline_fixed_string_t set;
7247         cmdline_fixed_string_t port;
7248         portid_t port_id;
7249         cmdline_fixed_string_t what;
7250         struct ether_addr address;
7251         cmdline_fixed_string_t mode;
7252 };
7253
7254 static void
7255 cmd_set_uc_hash_parsed(void *parsed_result,
7256                        __attribute__((unused)) struct cmdline *cl,
7257                        __attribute__((unused)) void *data)
7258 {
7259         int ret=0;
7260         struct cmd_set_uc_hash_table *res = parsed_result;
7261
7262         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7263
7264         if (strcmp(res->what, "uta") == 0)
7265                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7266                                                 &res->address,(uint8_t)is_on);
7267         if (ret < 0)
7268                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7269
7270 }
7271
7272 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7273         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7274                                  set, "set");
7275 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7276         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7277                                  port, "port");
7278 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7279         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7280                               port_id, UINT16);
7281 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7282         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7283                                  what, "uta");
7284 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7285         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7286                                 address);
7287 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7288         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7289                                  mode, "on#off");
7290
7291 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7292         .f = cmd_set_uc_hash_parsed,
7293         .data = NULL,
7294         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7295         .tokens = {
7296                 (void *)&cmd_set_uc_hash_set,
7297                 (void *)&cmd_set_uc_hash_port,
7298                 (void *)&cmd_set_uc_hash_portid,
7299                 (void *)&cmd_set_uc_hash_what,
7300                 (void *)&cmd_set_uc_hash_mac,
7301                 (void *)&cmd_set_uc_hash_mode,
7302                 NULL,
7303         },
7304 };
7305
7306 struct cmd_set_uc_all_hash_table {
7307         cmdline_fixed_string_t set;
7308         cmdline_fixed_string_t port;
7309         portid_t port_id;
7310         cmdline_fixed_string_t what;
7311         cmdline_fixed_string_t value;
7312         cmdline_fixed_string_t mode;
7313 };
7314
7315 static void
7316 cmd_set_uc_all_hash_parsed(void *parsed_result,
7317                        __attribute__((unused)) struct cmdline *cl,
7318                        __attribute__((unused)) void *data)
7319 {
7320         int ret=0;
7321         struct cmd_set_uc_all_hash_table *res = parsed_result;
7322
7323         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7324
7325         if ((strcmp(res->what, "uta") == 0) &&
7326                 (strcmp(res->value, "all") == 0))
7327                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7328         if (ret < 0)
7329                 printf("bad unicast hash table parameter,"
7330                         "return code = %d \n", ret);
7331 }
7332
7333 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7334         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7335                                  set, "set");
7336 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7337         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7338                                  port, "port");
7339 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7340         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7341                               port_id, UINT16);
7342 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7343         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7344                                  what, "uta");
7345 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7346         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7347                                 value,"all");
7348 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7349         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7350                                  mode, "on#off");
7351
7352 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7353         .f = cmd_set_uc_all_hash_parsed,
7354         .data = NULL,
7355         .help_str = "set port <port_id> uta all on|off",
7356         .tokens = {
7357                 (void *)&cmd_set_uc_all_hash_set,
7358                 (void *)&cmd_set_uc_all_hash_port,
7359                 (void *)&cmd_set_uc_all_hash_portid,
7360                 (void *)&cmd_set_uc_all_hash_what,
7361                 (void *)&cmd_set_uc_all_hash_value,
7362                 (void *)&cmd_set_uc_all_hash_mode,
7363                 NULL,
7364         },
7365 };
7366
7367 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7368 struct cmd_set_vf_macvlan_filter {
7369         cmdline_fixed_string_t set;
7370         cmdline_fixed_string_t port;
7371         portid_t port_id;
7372         cmdline_fixed_string_t vf;
7373         uint8_t vf_id;
7374         struct ether_addr address;
7375         cmdline_fixed_string_t filter_type;
7376         cmdline_fixed_string_t mode;
7377 };
7378
7379 static void
7380 cmd_set_vf_macvlan_parsed(void *parsed_result,
7381                        __attribute__((unused)) struct cmdline *cl,
7382                        __attribute__((unused)) void *data)
7383 {
7384         int is_on, ret = 0;
7385         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7386         struct rte_eth_mac_filter filter;
7387
7388         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7389
7390         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7391
7392         /* set VF MAC filter */
7393         filter.is_vf = 1;
7394
7395         /* set VF ID */
7396         filter.dst_id = res->vf_id;
7397
7398         if (!strcmp(res->filter_type, "exact-mac"))
7399                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7400         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7401                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7402         else if (!strcmp(res->filter_type, "hashmac"))
7403                 filter.filter_type = RTE_MAC_HASH_MATCH;
7404         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7405                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7406
7407         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7408
7409         if (is_on)
7410                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7411                                         RTE_ETH_FILTER_MACVLAN,
7412                                         RTE_ETH_FILTER_ADD,
7413                                          &filter);
7414         else
7415                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7416                                         RTE_ETH_FILTER_MACVLAN,
7417                                         RTE_ETH_FILTER_DELETE,
7418                                         &filter);
7419
7420         if (ret < 0)
7421                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7422
7423 }
7424
7425 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7426         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7427                                  set, "set");
7428 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7429         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7430                                  port, "port");
7431 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7432         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7433                               port_id, UINT16);
7434 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7435         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7436                                  vf, "vf");
7437 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7438         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7439                                 vf_id, UINT8);
7440 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7441         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7442                                 address);
7443 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7444         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7445                                 filter_type, "exact-mac#exact-mac-vlan"
7446                                 "#hashmac#hashmac-vlan");
7447 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7448         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7449                                  mode, "on#off");
7450
7451 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7452         .f = cmd_set_vf_macvlan_parsed,
7453         .data = NULL,
7454         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7455                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7456                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7457                 "hash match rule: hash match of MAC and exact match of VLAN",
7458         .tokens = {
7459                 (void *)&cmd_set_vf_macvlan_set,
7460                 (void *)&cmd_set_vf_macvlan_port,
7461                 (void *)&cmd_set_vf_macvlan_portid,
7462                 (void *)&cmd_set_vf_macvlan_vf,
7463                 (void *)&cmd_set_vf_macvlan_vf_id,
7464                 (void *)&cmd_set_vf_macvlan_mac,
7465                 (void *)&cmd_set_vf_macvlan_filter_type,
7466                 (void *)&cmd_set_vf_macvlan_mode,
7467                 NULL,
7468         },
7469 };
7470
7471 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7472 struct cmd_set_vf_traffic {
7473         cmdline_fixed_string_t set;
7474         cmdline_fixed_string_t port;
7475         portid_t port_id;
7476         cmdline_fixed_string_t vf;
7477         uint8_t vf_id;
7478         cmdline_fixed_string_t what;
7479         cmdline_fixed_string_t mode;
7480 };
7481
7482 static void
7483 cmd_set_vf_traffic_parsed(void *parsed_result,
7484                        __attribute__((unused)) struct cmdline *cl,
7485                        __attribute__((unused)) void *data)
7486 {
7487         struct cmd_set_vf_traffic *res = parsed_result;
7488         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7489         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7490
7491         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7492 }
7493
7494 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7495         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7496                                  set, "set");
7497 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7498         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7499                                  port, "port");
7500 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7501         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7502                               port_id, UINT16);
7503 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7504         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7505                                  vf, "vf");
7506 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7507         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7508                               vf_id, UINT8);
7509 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7510         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7511                                  what, "tx#rx");
7512 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7513         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7514                                  mode, "on#off");
7515
7516 cmdline_parse_inst_t cmd_set_vf_traffic = {
7517         .f = cmd_set_vf_traffic_parsed,
7518         .data = NULL,
7519         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7520         .tokens = {
7521                 (void *)&cmd_setvf_traffic_set,
7522                 (void *)&cmd_setvf_traffic_port,
7523                 (void *)&cmd_setvf_traffic_portid,
7524                 (void *)&cmd_setvf_traffic_vf,
7525                 (void *)&cmd_setvf_traffic_vfid,
7526                 (void *)&cmd_setvf_traffic_what,
7527                 (void *)&cmd_setvf_traffic_mode,
7528                 NULL,
7529         },
7530 };
7531
7532 /* *** CONFIGURE VF RECEIVE MODE *** */
7533 struct cmd_set_vf_rxmode {
7534         cmdline_fixed_string_t set;
7535         cmdline_fixed_string_t port;
7536         portid_t port_id;
7537         cmdline_fixed_string_t vf;
7538         uint8_t vf_id;
7539         cmdline_fixed_string_t what;
7540         cmdline_fixed_string_t mode;
7541         cmdline_fixed_string_t on;
7542 };
7543
7544 static void
7545 cmd_set_vf_rxmode_parsed(void *parsed_result,
7546                        __attribute__((unused)) struct cmdline *cl,
7547                        __attribute__((unused)) void *data)
7548 {
7549         int ret = -ENOTSUP;
7550         uint16_t rx_mode = 0;
7551         struct cmd_set_vf_rxmode *res = parsed_result;
7552
7553         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7554         if (!strcmp(res->what,"rxmode")) {
7555                 if (!strcmp(res->mode, "AUPE"))
7556                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7557                 else if (!strcmp(res->mode, "ROPE"))
7558                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7559                 else if (!strcmp(res->mode, "BAM"))
7560                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7561                 else if (!strncmp(res->mode, "MPE",3))
7562                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7563         }
7564
7565         RTE_SET_USED(is_on);
7566
7567 #ifdef RTE_LIBRTE_IXGBE_PMD
7568         if (ret == -ENOTSUP)
7569                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7570                                                   rx_mode, (uint8_t)is_on);
7571 #endif
7572 #ifdef RTE_LIBRTE_BNXT_PMD
7573         if (ret == -ENOTSUP)
7574                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7575                                                  rx_mode, (uint8_t)is_on);
7576 #endif
7577         if (ret < 0)
7578                 printf("bad VF receive mode parameter, return code = %d \n",
7579                 ret);
7580 }
7581
7582 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7583         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7584                                  set, "set");
7585 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7586         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7587                                  port, "port");
7588 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7589         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7590                               port_id, UINT16);
7591 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7592         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7593                                  vf, "vf");
7594 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7595         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7596                               vf_id, UINT8);
7597 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7598         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7599                                  what, "rxmode");
7600 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7601         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7602                                  mode, "AUPE#ROPE#BAM#MPE");
7603 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7604         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7605                                  on, "on#off");
7606
7607 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7608         .f = cmd_set_vf_rxmode_parsed,
7609         .data = NULL,
7610         .help_str = "set port <port_id> vf <vf_id> rxmode "
7611                 "AUPE|ROPE|BAM|MPE on|off",
7612         .tokens = {
7613                 (void *)&cmd_set_vf_rxmode_set,
7614                 (void *)&cmd_set_vf_rxmode_port,
7615                 (void *)&cmd_set_vf_rxmode_portid,
7616                 (void *)&cmd_set_vf_rxmode_vf,
7617                 (void *)&cmd_set_vf_rxmode_vfid,
7618                 (void *)&cmd_set_vf_rxmode_what,
7619                 (void *)&cmd_set_vf_rxmode_mode,
7620                 (void *)&cmd_set_vf_rxmode_on,
7621                 NULL,
7622         },
7623 };
7624
7625 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7626 struct cmd_vf_mac_addr_result {
7627         cmdline_fixed_string_t mac_addr_cmd;
7628         cmdline_fixed_string_t what;
7629         cmdline_fixed_string_t port;
7630         uint16_t port_num;
7631         cmdline_fixed_string_t vf;
7632         uint8_t vf_num;
7633         struct ether_addr address;
7634 };
7635
7636 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7637                 __attribute__((unused)) struct cmdline *cl,
7638                 __attribute__((unused)) void *data)
7639 {
7640         struct cmd_vf_mac_addr_result *res = parsed_result;
7641         int ret = -ENOTSUP;
7642
7643         if (strcmp(res->what, "add") != 0)
7644                 return;
7645
7646 #ifdef RTE_LIBRTE_I40E_PMD
7647         if (ret == -ENOTSUP)
7648                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7649                                                    &res->address);
7650 #endif
7651 #ifdef RTE_LIBRTE_BNXT_PMD
7652         if (ret == -ENOTSUP)
7653                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7654                                                 res->vf_num);
7655 #endif
7656
7657         if(ret < 0)
7658                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7659
7660 }
7661
7662 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7663         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7664                                 mac_addr_cmd,"mac_addr");
7665 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7666         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7667                                 what,"add");
7668 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7669         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7670                                 port,"port");
7671 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7672         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7673                                 port_num, UINT16);
7674 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7675         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7676                                 vf,"vf");
7677 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7678         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7679                                 vf_num, UINT8);
7680 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7681         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7682                                 address);
7683
7684 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7685         .f = cmd_vf_mac_addr_parsed,
7686         .data = (void *)0,
7687         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7688                 "Add MAC address filtering for a VF on port_id",
7689         .tokens = {
7690                 (void *)&cmd_vf_mac_addr_cmd,
7691                 (void *)&cmd_vf_mac_addr_what,
7692                 (void *)&cmd_vf_mac_addr_port,
7693                 (void *)&cmd_vf_mac_addr_portnum,
7694                 (void *)&cmd_vf_mac_addr_vf,
7695                 (void *)&cmd_vf_mac_addr_vfnum,
7696                 (void *)&cmd_vf_mac_addr_addr,
7697                 NULL,
7698         },
7699 };
7700
7701 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7702 struct cmd_vf_rx_vlan_filter {
7703         cmdline_fixed_string_t rx_vlan;
7704         cmdline_fixed_string_t what;
7705         uint16_t vlan_id;
7706         cmdline_fixed_string_t port;
7707         portid_t port_id;
7708         cmdline_fixed_string_t vf;
7709         uint64_t vf_mask;
7710 };
7711
7712 static void
7713 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7714                           __attribute__((unused)) struct cmdline *cl,
7715                           __attribute__((unused)) void *data)
7716 {
7717         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7718         int ret = -ENOTSUP;
7719
7720         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7721
7722 #ifdef RTE_LIBRTE_IXGBE_PMD
7723         if (ret == -ENOTSUP)
7724                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7725                                 res->vlan_id, res->vf_mask, is_add);
7726 #endif
7727 #ifdef RTE_LIBRTE_I40E_PMD
7728         if (ret == -ENOTSUP)
7729                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7730                                 res->vlan_id, res->vf_mask, is_add);
7731 #endif
7732 #ifdef RTE_LIBRTE_BNXT_PMD
7733         if (ret == -ENOTSUP)
7734                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7735                                 res->vlan_id, res->vf_mask, is_add);
7736 #endif
7737
7738         switch (ret) {
7739         case 0:
7740                 break;
7741         case -EINVAL:
7742                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7743                                 res->vlan_id, res->vf_mask);
7744                 break;
7745         case -ENODEV:
7746                 printf("invalid port_id %d\n", res->port_id);
7747                 break;
7748         case -ENOTSUP:
7749                 printf("function not implemented or supported\n");
7750                 break;
7751         default:
7752                 printf("programming error: (%s)\n", strerror(-ret));
7753         }
7754 }
7755
7756 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7757         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7758                                  rx_vlan, "rx_vlan");
7759 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7760         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7761                                  what, "add#rm");
7762 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7763         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7764                               vlan_id, UINT16);
7765 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7766         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7767                                  port, "port");
7768 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7769         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7770                               port_id, UINT16);
7771 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7772         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7773                                  vf, "vf");
7774 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7775         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7776                               vf_mask, UINT64);
7777
7778 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7779         .f = cmd_vf_rx_vlan_filter_parsed,
7780         .data = NULL,
7781         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7782                 "(vf_mask = hexadecimal VF mask)",
7783         .tokens = {
7784                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7785                 (void *)&cmd_vf_rx_vlan_filter_what,
7786                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7787                 (void *)&cmd_vf_rx_vlan_filter_port,
7788                 (void *)&cmd_vf_rx_vlan_filter_portid,
7789                 (void *)&cmd_vf_rx_vlan_filter_vf,
7790                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7791                 NULL,
7792         },
7793 };
7794
7795 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7796 struct cmd_queue_rate_limit_result {
7797         cmdline_fixed_string_t set;
7798         cmdline_fixed_string_t port;
7799         uint16_t port_num;
7800         cmdline_fixed_string_t queue;
7801         uint8_t queue_num;
7802         cmdline_fixed_string_t rate;
7803         uint16_t rate_num;
7804 };
7805
7806 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7807                 __attribute__((unused)) struct cmdline *cl,
7808                 __attribute__((unused)) void *data)
7809 {
7810         struct cmd_queue_rate_limit_result *res = parsed_result;
7811         int ret = 0;
7812
7813         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7814                 && (strcmp(res->queue, "queue") == 0)
7815                 && (strcmp(res->rate, "rate") == 0))
7816                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7817                                         res->rate_num);
7818         if (ret < 0)
7819                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7820
7821 }
7822
7823 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7824         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7825                                 set, "set");
7826 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7827         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7828                                 port, "port");
7829 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7830         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7831                                 port_num, UINT16);
7832 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7833         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7834                                 queue, "queue");
7835 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7836         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7837                                 queue_num, UINT8);
7838 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7839         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7840                                 rate, "rate");
7841 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7842         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7843                                 rate_num, UINT16);
7844
7845 cmdline_parse_inst_t cmd_queue_rate_limit = {
7846         .f = cmd_queue_rate_limit_parsed,
7847         .data = (void *)0,
7848         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7849                 "Set rate limit for a queue on port_id",
7850         .tokens = {
7851                 (void *)&cmd_queue_rate_limit_set,
7852                 (void *)&cmd_queue_rate_limit_port,
7853                 (void *)&cmd_queue_rate_limit_portnum,
7854                 (void *)&cmd_queue_rate_limit_queue,
7855                 (void *)&cmd_queue_rate_limit_queuenum,
7856                 (void *)&cmd_queue_rate_limit_rate,
7857                 (void *)&cmd_queue_rate_limit_ratenum,
7858                 NULL,
7859         },
7860 };
7861
7862 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7863 struct cmd_vf_rate_limit_result {
7864         cmdline_fixed_string_t set;
7865         cmdline_fixed_string_t port;
7866         uint16_t port_num;
7867         cmdline_fixed_string_t vf;
7868         uint8_t vf_num;
7869         cmdline_fixed_string_t rate;
7870         uint16_t rate_num;
7871         cmdline_fixed_string_t q_msk;
7872         uint64_t q_msk_val;
7873 };
7874
7875 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7876                 __attribute__((unused)) struct cmdline *cl,
7877                 __attribute__((unused)) void *data)
7878 {
7879         struct cmd_vf_rate_limit_result *res = parsed_result;
7880         int ret = 0;
7881
7882         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7883                 && (strcmp(res->vf, "vf") == 0)
7884                 && (strcmp(res->rate, "rate") == 0)
7885                 && (strcmp(res->q_msk, "queue_mask") == 0))
7886                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7887                                         res->rate_num, res->q_msk_val);
7888         if (ret < 0)
7889                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7890
7891 }
7892
7893 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7894         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7895                                 set, "set");
7896 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7897         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7898                                 port, "port");
7899 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7900         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7901                                 port_num, UINT16);
7902 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7903         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7904                                 vf, "vf");
7905 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7906         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7907                                 vf_num, UINT8);
7908 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7909         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7910                                 rate, "rate");
7911 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7912         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7913                                 rate_num, UINT16);
7914 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7915         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7916                                 q_msk, "queue_mask");
7917 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7918         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7919                                 q_msk_val, UINT64);
7920
7921 cmdline_parse_inst_t cmd_vf_rate_limit = {
7922         .f = cmd_vf_rate_limit_parsed,
7923         .data = (void *)0,
7924         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7925                 "queue_mask <queue_mask_value>: "
7926                 "Set rate limit for queues of VF on port_id",
7927         .tokens = {
7928                 (void *)&cmd_vf_rate_limit_set,
7929                 (void *)&cmd_vf_rate_limit_port,
7930                 (void *)&cmd_vf_rate_limit_portnum,
7931                 (void *)&cmd_vf_rate_limit_vf,
7932                 (void *)&cmd_vf_rate_limit_vfnum,
7933                 (void *)&cmd_vf_rate_limit_rate,
7934                 (void *)&cmd_vf_rate_limit_ratenum,
7935                 (void *)&cmd_vf_rate_limit_q_msk,
7936                 (void *)&cmd_vf_rate_limit_q_msk_val,
7937                 NULL,
7938         },
7939 };
7940
7941 /* *** ADD TUNNEL FILTER OF A PORT *** */
7942 struct cmd_tunnel_filter_result {
7943         cmdline_fixed_string_t cmd;
7944         cmdline_fixed_string_t what;
7945         portid_t port_id;
7946         struct ether_addr outer_mac;
7947         struct ether_addr inner_mac;
7948         cmdline_ipaddr_t ip_value;
7949         uint16_t inner_vlan;
7950         cmdline_fixed_string_t tunnel_type;
7951         cmdline_fixed_string_t filter_type;
7952         uint32_t tenant_id;
7953         uint16_t queue_num;
7954 };
7955
7956 static void
7957 cmd_tunnel_filter_parsed(void *parsed_result,
7958                           __attribute__((unused)) struct cmdline *cl,
7959                           __attribute__((unused)) void *data)
7960 {
7961         struct cmd_tunnel_filter_result *res = parsed_result;
7962         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7963         int ret = 0;
7964
7965         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7966
7967         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7968         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7969         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7970
7971         if (res->ip_value.family == AF_INET) {
7972                 tunnel_filter_conf.ip_addr.ipv4_addr =
7973                         res->ip_value.addr.ipv4.s_addr;
7974                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7975         } else {
7976                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7977                         &(res->ip_value.addr.ipv6),
7978                         sizeof(struct in6_addr));
7979                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7980         }
7981
7982         if (!strcmp(res->filter_type, "imac-ivlan"))
7983                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7984         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7985                 tunnel_filter_conf.filter_type =
7986                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7987         else if (!strcmp(res->filter_type, "imac-tenid"))
7988                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7989         else if (!strcmp(res->filter_type, "imac"))
7990                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7991         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7992                 tunnel_filter_conf.filter_type =
7993                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7994         else if (!strcmp(res->filter_type, "oip"))
7995                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7996         else if (!strcmp(res->filter_type, "iip"))
7997                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7998         else {
7999                 printf("The filter type is not supported");
8000                 return;
8001         }
8002
8003         if (!strcmp(res->tunnel_type, "vxlan"))
8004                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8005         else if (!strcmp(res->tunnel_type, "nvgre"))
8006                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8007         else if (!strcmp(res->tunnel_type, "ipingre"))
8008                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8009         else {
8010                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8011                 return;
8012         }
8013
8014         tunnel_filter_conf.tenant_id = res->tenant_id;
8015         tunnel_filter_conf.queue_id = res->queue_num;
8016         if (!strcmp(res->what, "add"))
8017                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8018                                         RTE_ETH_FILTER_TUNNEL,
8019                                         RTE_ETH_FILTER_ADD,
8020                                         &tunnel_filter_conf);
8021         else
8022                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8023                                         RTE_ETH_FILTER_TUNNEL,
8024                                         RTE_ETH_FILTER_DELETE,
8025                                         &tunnel_filter_conf);
8026         if (ret < 0)
8027                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8028                                 strerror(-ret));
8029
8030 }
8031 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8032         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8033         cmd, "tunnel_filter");
8034 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8035         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8036         what, "add#rm");
8037 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8038         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8039         port_id, UINT16);
8040 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8041         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8042         outer_mac);
8043 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8044         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8045         inner_mac);
8046 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8047         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8048         inner_vlan, UINT16);
8049 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8050         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8051         ip_value);
8052 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8053         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8054         tunnel_type, "vxlan#nvgre#ipingre");
8055
8056 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8057         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8058         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8059                 "imac#omac-imac-tenid");
8060 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8061         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8062         tenant_id, UINT32);
8063 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8064         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8065         queue_num, UINT16);
8066
8067 cmdline_parse_inst_t cmd_tunnel_filter = {
8068         .f = cmd_tunnel_filter_parsed,
8069         .data = (void *)0,
8070         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8071                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8072                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8073                 "<queue_id>: Add/Rm tunnel filter of a port",
8074         .tokens = {
8075                 (void *)&cmd_tunnel_filter_cmd,
8076                 (void *)&cmd_tunnel_filter_what,
8077                 (void *)&cmd_tunnel_filter_port_id,
8078                 (void *)&cmd_tunnel_filter_outer_mac,
8079                 (void *)&cmd_tunnel_filter_inner_mac,
8080                 (void *)&cmd_tunnel_filter_ip_value,
8081                 (void *)&cmd_tunnel_filter_innner_vlan,
8082                 (void *)&cmd_tunnel_filter_tunnel_type,
8083                 (void *)&cmd_tunnel_filter_filter_type,
8084                 (void *)&cmd_tunnel_filter_tenant_id,
8085                 (void *)&cmd_tunnel_filter_queue_num,
8086                 NULL,
8087         },
8088 };
8089
8090 /* *** CONFIGURE TUNNEL UDP PORT *** */
8091 struct cmd_tunnel_udp_config {
8092         cmdline_fixed_string_t cmd;
8093         cmdline_fixed_string_t what;
8094         uint16_t udp_port;
8095         portid_t port_id;
8096 };
8097
8098 static void
8099 cmd_tunnel_udp_config_parsed(void *parsed_result,
8100                           __attribute__((unused)) struct cmdline *cl,
8101                           __attribute__((unused)) void *data)
8102 {
8103         struct cmd_tunnel_udp_config *res = parsed_result;
8104         struct rte_eth_udp_tunnel tunnel_udp;
8105         int ret;
8106
8107         tunnel_udp.udp_port = res->udp_port;
8108
8109         if (!strcmp(res->cmd, "rx_vxlan_port"))
8110                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8111
8112         if (!strcmp(res->what, "add"))
8113                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8114                                                       &tunnel_udp);
8115         else
8116                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8117                                                          &tunnel_udp);
8118
8119         if (ret < 0)
8120                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8121 }
8122
8123 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8124         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8125                                 cmd, "rx_vxlan_port");
8126 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8128                                 what, "add#rm");
8129 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8130         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8131                                 udp_port, UINT16);
8132 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8134                                 port_id, UINT16);
8135
8136 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8137         .f = cmd_tunnel_udp_config_parsed,
8138         .data = (void *)0,
8139         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8140                 "Add/Remove a tunneling UDP port filter",
8141         .tokens = {
8142                 (void *)&cmd_tunnel_udp_config_cmd,
8143                 (void *)&cmd_tunnel_udp_config_what,
8144                 (void *)&cmd_tunnel_udp_config_udp_port,
8145                 (void *)&cmd_tunnel_udp_config_port_id,
8146                 NULL,
8147         },
8148 };
8149
8150 /* *** GLOBAL CONFIG *** */
8151 struct cmd_global_config_result {
8152         cmdline_fixed_string_t cmd;
8153         portid_t port_id;
8154         cmdline_fixed_string_t cfg_type;
8155         uint8_t len;
8156 };
8157
8158 static void
8159 cmd_global_config_parsed(void *parsed_result,
8160                          __attribute__((unused)) struct cmdline *cl,
8161                          __attribute__((unused)) void *data)
8162 {
8163         struct cmd_global_config_result *res = parsed_result;
8164         struct rte_eth_global_cfg conf;
8165         int ret;
8166
8167         memset(&conf, 0, sizeof(conf));
8168         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8169         conf.cfg.gre_key_len = res->len;
8170         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8171                                       RTE_ETH_FILTER_SET, &conf);
8172         if (ret != 0)
8173                 printf("Global config error\n");
8174 }
8175
8176 cmdline_parse_token_string_t cmd_global_config_cmd =
8177         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8178                 "global_config");
8179 cmdline_parse_token_num_t cmd_global_config_port_id =
8180         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8181                                UINT16);
8182 cmdline_parse_token_string_t cmd_global_config_type =
8183         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8184                 cfg_type, "gre-key-len");
8185 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8186         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8187                 len, UINT8);
8188
8189 cmdline_parse_inst_t cmd_global_config = {
8190         .f = cmd_global_config_parsed,
8191         .data = (void *)NULL,
8192         .help_str = "global_config <port_id> gre-key-len <key_len>",
8193         .tokens = {
8194                 (void *)&cmd_global_config_cmd,
8195                 (void *)&cmd_global_config_port_id,
8196                 (void *)&cmd_global_config_type,
8197                 (void *)&cmd_global_config_gre_key_len,
8198                 NULL,
8199         },
8200 };
8201
8202 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8203 struct cmd_set_mirror_mask_result {
8204         cmdline_fixed_string_t set;
8205         cmdline_fixed_string_t port;
8206         portid_t port_id;
8207         cmdline_fixed_string_t mirror;
8208         uint8_t rule_id;
8209         cmdline_fixed_string_t what;
8210         cmdline_fixed_string_t value;
8211         cmdline_fixed_string_t dstpool;
8212         uint8_t dstpool_id;
8213         cmdline_fixed_string_t on;
8214 };
8215
8216 cmdline_parse_token_string_t cmd_mirror_mask_set =
8217         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8218                                 set, "set");
8219 cmdline_parse_token_string_t cmd_mirror_mask_port =
8220         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8221                                 port, "port");
8222 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8223         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8224                                 port_id, UINT16);
8225 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8226         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8227                                 mirror, "mirror-rule");
8228 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8229         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8230                                 rule_id, UINT8);
8231 cmdline_parse_token_string_t cmd_mirror_mask_what =
8232         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8233                                 what, "pool-mirror-up#pool-mirror-down"
8234                                       "#vlan-mirror");
8235 cmdline_parse_token_string_t cmd_mirror_mask_value =
8236         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8237                                 value, NULL);
8238 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8239         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8240                                 dstpool, "dst-pool");
8241 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8242         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8243                                 dstpool_id, UINT8);
8244 cmdline_parse_token_string_t cmd_mirror_mask_on =
8245         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8246                                 on, "on#off");
8247
8248 static void
8249 cmd_set_mirror_mask_parsed(void *parsed_result,
8250                        __attribute__((unused)) struct cmdline *cl,
8251                        __attribute__((unused)) void *data)
8252 {
8253         int ret,nb_item,i;
8254         struct cmd_set_mirror_mask_result *res = parsed_result;
8255         struct rte_eth_mirror_conf mr_conf;
8256
8257         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8258
8259         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8260
8261         mr_conf.dst_pool = res->dstpool_id;
8262
8263         if (!strcmp(res->what, "pool-mirror-up")) {
8264                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8265                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8266         } else if (!strcmp(res->what, "pool-mirror-down")) {
8267                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8268                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8269         } else if (!strcmp(res->what, "vlan-mirror")) {
8270                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8271                 nb_item = parse_item_list(res->value, "vlan",
8272                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8273                 if (nb_item <= 0)
8274                         return;
8275
8276                 for (i = 0; i < nb_item; i++) {
8277                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8278                                 printf("Invalid vlan_id: must be < 4096\n");
8279                                 return;
8280                         }
8281
8282                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8283                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8284                 }
8285         }
8286
8287         if (!strcmp(res->on, "on"))
8288                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8289                                                 res->rule_id, 1);
8290         else
8291                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8292                                                 res->rule_id, 0);
8293         if (ret < 0)
8294                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8295 }
8296
8297 cmdline_parse_inst_t cmd_set_mirror_mask = {
8298                 .f = cmd_set_mirror_mask_parsed,
8299                 .data = NULL,
8300                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8301                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8302                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8303                 .tokens = {
8304                         (void *)&cmd_mirror_mask_set,
8305                         (void *)&cmd_mirror_mask_port,
8306                         (void *)&cmd_mirror_mask_portid,
8307                         (void *)&cmd_mirror_mask_mirror,
8308                         (void *)&cmd_mirror_mask_ruleid,
8309                         (void *)&cmd_mirror_mask_what,
8310                         (void *)&cmd_mirror_mask_value,
8311                         (void *)&cmd_mirror_mask_dstpool,
8312                         (void *)&cmd_mirror_mask_poolid,
8313                         (void *)&cmd_mirror_mask_on,
8314                         NULL,
8315                 },
8316 };
8317
8318 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8319 struct cmd_set_mirror_link_result {
8320         cmdline_fixed_string_t set;
8321         cmdline_fixed_string_t port;
8322         portid_t port_id;
8323         cmdline_fixed_string_t mirror;
8324         uint8_t rule_id;
8325         cmdline_fixed_string_t what;
8326         cmdline_fixed_string_t dstpool;
8327         uint8_t dstpool_id;
8328         cmdline_fixed_string_t on;
8329 };
8330
8331 cmdline_parse_token_string_t cmd_mirror_link_set =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8333                                  set, "set");
8334 cmdline_parse_token_string_t cmd_mirror_link_port =
8335         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8336                                 port, "port");
8337 cmdline_parse_token_num_t cmd_mirror_link_portid =
8338         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8339                                 port_id, UINT16);
8340 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8341         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8342                                 mirror, "mirror-rule");
8343 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8344         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8345                             rule_id, UINT8);
8346 cmdline_parse_token_string_t cmd_mirror_link_what =
8347         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8348                                 what, "uplink-mirror#downlink-mirror");
8349 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8350         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8351                                 dstpool, "dst-pool");
8352 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8353         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8354                                 dstpool_id, UINT8);
8355 cmdline_parse_token_string_t cmd_mirror_link_on =
8356         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8357                                 on, "on#off");
8358
8359 static void
8360 cmd_set_mirror_link_parsed(void *parsed_result,
8361                        __attribute__((unused)) struct cmdline *cl,
8362                        __attribute__((unused)) void *data)
8363 {
8364         int ret;
8365         struct cmd_set_mirror_link_result *res = parsed_result;
8366         struct rte_eth_mirror_conf mr_conf;
8367
8368         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8369         if (!strcmp(res->what, "uplink-mirror"))
8370                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8371         else
8372                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8373
8374         mr_conf.dst_pool = res->dstpool_id;
8375
8376         if (!strcmp(res->on, "on"))
8377                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8378                                                 res->rule_id, 1);
8379         else
8380                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8381                                                 res->rule_id, 0);
8382
8383         /* check the return value and print it if is < 0 */
8384         if (ret < 0)
8385                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8386
8387 }
8388
8389 cmdline_parse_inst_t cmd_set_mirror_link = {
8390                 .f = cmd_set_mirror_link_parsed,
8391                 .data = NULL,
8392                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8393                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8394                 .tokens = {
8395                         (void *)&cmd_mirror_link_set,
8396                         (void *)&cmd_mirror_link_port,
8397                         (void *)&cmd_mirror_link_portid,
8398                         (void *)&cmd_mirror_link_mirror,
8399                         (void *)&cmd_mirror_link_ruleid,
8400                         (void *)&cmd_mirror_link_what,
8401                         (void *)&cmd_mirror_link_dstpool,
8402                         (void *)&cmd_mirror_link_poolid,
8403                         (void *)&cmd_mirror_link_on,
8404                         NULL,
8405                 },
8406 };
8407
8408 /* *** RESET VM MIRROR RULE *** */
8409 struct cmd_rm_mirror_rule_result {
8410         cmdline_fixed_string_t reset;
8411         cmdline_fixed_string_t port;
8412         portid_t port_id;
8413         cmdline_fixed_string_t mirror;
8414         uint8_t rule_id;
8415 };
8416
8417 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8418         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8419                                  reset, "reset");
8420 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8421         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8422                                 port, "port");
8423 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8424         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8425                                 port_id, UINT16);
8426 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8427         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8428                                 mirror, "mirror-rule");
8429 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8430         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8431                                 rule_id, UINT8);
8432
8433 static void
8434 cmd_reset_mirror_rule_parsed(void *parsed_result,
8435                        __attribute__((unused)) struct cmdline *cl,
8436                        __attribute__((unused)) void *data)
8437 {
8438         int ret;
8439         struct cmd_set_mirror_link_result *res = parsed_result;
8440         /* check rule_id */
8441         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8442         if(ret < 0)
8443                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8444 }
8445
8446 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8447                 .f = cmd_reset_mirror_rule_parsed,
8448                 .data = NULL,
8449                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8450                 .tokens = {
8451                         (void *)&cmd_rm_mirror_rule_reset,
8452                         (void *)&cmd_rm_mirror_rule_port,
8453                         (void *)&cmd_rm_mirror_rule_portid,
8454                         (void *)&cmd_rm_mirror_rule_mirror,
8455                         (void *)&cmd_rm_mirror_rule_ruleid,
8456                         NULL,
8457                 },
8458 };
8459
8460 /* ******************************************************************************** */
8461
8462 struct cmd_dump_result {
8463         cmdline_fixed_string_t dump;
8464 };
8465
8466 static void
8467 dump_struct_sizes(void)
8468 {
8469 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8470         DUMP_SIZE(struct rte_mbuf);
8471         DUMP_SIZE(struct rte_mempool);
8472         DUMP_SIZE(struct rte_ring);
8473 #undef DUMP_SIZE
8474 }
8475
8476 static void cmd_dump_parsed(void *parsed_result,
8477                             __attribute__((unused)) struct cmdline *cl,
8478                             __attribute__((unused)) void *data)
8479 {
8480         struct cmd_dump_result *res = parsed_result;
8481
8482         if (!strcmp(res->dump, "dump_physmem"))
8483                 rte_dump_physmem_layout(stdout);
8484         else if (!strcmp(res->dump, "dump_memzone"))
8485                 rte_memzone_dump(stdout);
8486         else if (!strcmp(res->dump, "dump_struct_sizes"))
8487                 dump_struct_sizes();
8488         else if (!strcmp(res->dump, "dump_ring"))
8489                 rte_ring_list_dump(stdout);
8490         else if (!strcmp(res->dump, "dump_mempool"))
8491                 rte_mempool_list_dump(stdout);
8492         else if (!strcmp(res->dump, "dump_devargs"))
8493                 rte_eal_devargs_dump(stdout);
8494         else if (!strcmp(res->dump, "dump_log_types"))
8495                 rte_log_dump(stdout);
8496 }
8497
8498 cmdline_parse_token_string_t cmd_dump_dump =
8499         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8500                 "dump_physmem#"
8501                 "dump_memzone#"
8502                 "dump_struct_sizes#"
8503                 "dump_ring#"
8504                 "dump_mempool#"
8505                 "dump_devargs#"
8506                 "dump_log_types");
8507
8508 cmdline_parse_inst_t cmd_dump = {
8509         .f = cmd_dump_parsed,  /* function to call */
8510         .data = NULL,      /* 2nd arg of func */
8511         .help_str = "Dump status",
8512         .tokens = {        /* token list, NULL terminated */
8513                 (void *)&cmd_dump_dump,
8514                 NULL,
8515         },
8516 };
8517
8518 /* ******************************************************************************** */
8519
8520 struct cmd_dump_one_result {
8521         cmdline_fixed_string_t dump;
8522         cmdline_fixed_string_t name;
8523 };
8524
8525 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8526                                 __attribute__((unused)) void *data)
8527 {
8528         struct cmd_dump_one_result *res = parsed_result;
8529
8530         if (!strcmp(res->dump, "dump_ring")) {
8531                 struct rte_ring *r;
8532                 r = rte_ring_lookup(res->name);
8533                 if (r == NULL) {
8534                         cmdline_printf(cl, "Cannot find ring\n");
8535                         return;
8536                 }
8537                 rte_ring_dump(stdout, r);
8538         } else if (!strcmp(res->dump, "dump_mempool")) {
8539                 struct rte_mempool *mp;
8540                 mp = rte_mempool_lookup(res->name);
8541                 if (mp == NULL) {
8542                         cmdline_printf(cl, "Cannot find mempool\n");
8543                         return;
8544                 }
8545                 rte_mempool_dump(stdout, mp);
8546         }
8547 }
8548
8549 cmdline_parse_token_string_t cmd_dump_one_dump =
8550         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8551                                  "dump_ring#dump_mempool");
8552
8553 cmdline_parse_token_string_t cmd_dump_one_name =
8554         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8555
8556 cmdline_parse_inst_t cmd_dump_one = {
8557         .f = cmd_dump_one_parsed,  /* function to call */
8558         .data = NULL,      /* 2nd arg of func */
8559         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8560         .tokens = {        /* token list, NULL terminated */
8561                 (void *)&cmd_dump_one_dump,
8562                 (void *)&cmd_dump_one_name,
8563                 NULL,
8564         },
8565 };
8566
8567 /* *** Add/Del syn filter *** */
8568 struct cmd_syn_filter_result {
8569         cmdline_fixed_string_t filter;
8570         portid_t port_id;
8571         cmdline_fixed_string_t ops;
8572         cmdline_fixed_string_t priority;
8573         cmdline_fixed_string_t high;
8574         cmdline_fixed_string_t queue;
8575         uint16_t queue_id;
8576 };
8577
8578 static void
8579 cmd_syn_filter_parsed(void *parsed_result,
8580                         __attribute__((unused)) struct cmdline *cl,
8581                         __attribute__((unused)) void *data)
8582 {
8583         struct cmd_syn_filter_result *res = parsed_result;
8584         struct rte_eth_syn_filter syn_filter;
8585         int ret = 0;
8586
8587         ret = rte_eth_dev_filter_supported(res->port_id,
8588                                         RTE_ETH_FILTER_SYN);
8589         if (ret < 0) {
8590                 printf("syn filter is not supported on port %u.\n",
8591                                 res->port_id);
8592                 return;
8593         }
8594
8595         memset(&syn_filter, 0, sizeof(syn_filter));
8596
8597         if (!strcmp(res->ops, "add")) {
8598                 if (!strcmp(res->high, "high"))
8599                         syn_filter.hig_pri = 1;
8600                 else
8601                         syn_filter.hig_pri = 0;
8602
8603                 syn_filter.queue = res->queue_id;
8604                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8605                                                 RTE_ETH_FILTER_SYN,
8606                                                 RTE_ETH_FILTER_ADD,
8607                                                 &syn_filter);
8608         } else
8609                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8610                                                 RTE_ETH_FILTER_SYN,
8611                                                 RTE_ETH_FILTER_DELETE,
8612                                                 &syn_filter);
8613
8614         if (ret < 0)
8615                 printf("syn filter programming error: (%s)\n",
8616                                 strerror(-ret));
8617 }
8618
8619 cmdline_parse_token_string_t cmd_syn_filter_filter =
8620         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8621         filter, "syn_filter");
8622 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8623         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8624         port_id, UINT16);
8625 cmdline_parse_token_string_t cmd_syn_filter_ops =
8626         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8627         ops, "add#del");
8628 cmdline_parse_token_string_t cmd_syn_filter_priority =
8629         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8630                                 priority, "priority");
8631 cmdline_parse_token_string_t cmd_syn_filter_high =
8632         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8633                                 high, "high#low");
8634 cmdline_parse_token_string_t cmd_syn_filter_queue =
8635         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8636                                 queue, "queue");
8637 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8638         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8639                                 queue_id, UINT16);
8640
8641 cmdline_parse_inst_t cmd_syn_filter = {
8642         .f = cmd_syn_filter_parsed,
8643         .data = NULL,
8644         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8645                 "<queue_id>: Add/Delete syn filter",
8646         .tokens = {
8647                 (void *)&cmd_syn_filter_filter,
8648                 (void *)&cmd_syn_filter_port_id,
8649                 (void *)&cmd_syn_filter_ops,
8650                 (void *)&cmd_syn_filter_priority,
8651                 (void *)&cmd_syn_filter_high,
8652                 (void *)&cmd_syn_filter_queue,
8653                 (void *)&cmd_syn_filter_queue_id,
8654                 NULL,
8655         },
8656 };
8657
8658 /* *** queue region set *** */
8659 struct cmd_queue_region_result {
8660         cmdline_fixed_string_t set;
8661         cmdline_fixed_string_t port;
8662         portid_t port_id;
8663         cmdline_fixed_string_t cmd;
8664         cmdline_fixed_string_t region;
8665         uint8_t  region_id;
8666         cmdline_fixed_string_t queue_start_index;
8667         uint8_t  queue_id;
8668         cmdline_fixed_string_t queue_num;
8669         uint8_t  queue_num_value;
8670 };
8671
8672 static void
8673 cmd_queue_region_parsed(void *parsed_result,
8674                         __attribute__((unused)) struct cmdline *cl,
8675                         __attribute__((unused)) void *data)
8676 {
8677         struct cmd_queue_region_result *res = parsed_result;
8678         int ret = -ENOTSUP;
8679 #ifdef RTE_LIBRTE_I40E_PMD
8680         struct rte_pmd_i40e_queue_region_conf region_conf;
8681         enum rte_pmd_i40e_queue_region_op op_type;
8682 #endif
8683
8684         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8685                 return;
8686
8687 #ifdef RTE_LIBRTE_I40E_PMD
8688         memset(&region_conf, 0, sizeof(region_conf));
8689         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8690         region_conf.region_id = res->region_id;
8691         region_conf.queue_num = res->queue_num_value;
8692         region_conf.queue_start_index = res->queue_id;
8693
8694         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8695                                 op_type, &region_conf);
8696 #endif
8697
8698         switch (ret) {
8699         case 0:
8700                 break;
8701         case -ENOTSUP:
8702                 printf("function not implemented or supported\n");
8703                 break;
8704         default:
8705                 printf("queue region config error: (%s)\n", strerror(-ret));
8706         }
8707 }
8708
8709 cmdline_parse_token_string_t cmd_queue_region_set =
8710 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8711                 set, "set");
8712 cmdline_parse_token_string_t cmd_queue_region_port =
8713         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8714 cmdline_parse_token_num_t cmd_queue_region_port_id =
8715         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8716                                 port_id, UINT16);
8717 cmdline_parse_token_string_t cmd_queue_region_cmd =
8718         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8719                                  cmd, "queue-region");
8720 cmdline_parse_token_string_t cmd_queue_region_id =
8721         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8722                                 region, "region_id");
8723 cmdline_parse_token_num_t cmd_queue_region_index =
8724         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8725                                 region_id, UINT8);
8726 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8727         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8728                                 queue_start_index, "queue_start_index");
8729 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8730         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8731                                 queue_id, UINT8);
8732 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8733         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8734                                 queue_num, "queue_num");
8735 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8736         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8737                                 queue_num_value, UINT8);
8738
8739 cmdline_parse_inst_t cmd_queue_region = {
8740         .f = cmd_queue_region_parsed,
8741         .data = NULL,
8742         .help_str = "set port <port_id> queue-region region_id <value> "
8743                 "queue_start_index <value> queue_num <value>: Set a queue region",
8744         .tokens = {
8745                 (void *)&cmd_queue_region_set,
8746                 (void *)&cmd_queue_region_port,
8747                 (void *)&cmd_queue_region_port_id,
8748                 (void *)&cmd_queue_region_cmd,
8749                 (void *)&cmd_queue_region_id,
8750                 (void *)&cmd_queue_region_index,
8751                 (void *)&cmd_queue_region_queue_start_index,
8752                 (void *)&cmd_queue_region_queue_id,
8753                 (void *)&cmd_queue_region_queue_num,
8754                 (void *)&cmd_queue_region_queue_num_value,
8755                 NULL,
8756         },
8757 };
8758
8759 /* *** queue region and flowtype set *** */
8760 struct cmd_region_flowtype_result {
8761         cmdline_fixed_string_t set;
8762         cmdline_fixed_string_t port;
8763         portid_t port_id;
8764         cmdline_fixed_string_t cmd;
8765         cmdline_fixed_string_t region;
8766         uint8_t  region_id;
8767         cmdline_fixed_string_t flowtype;
8768         uint8_t  flowtype_id;
8769 };
8770
8771 static void
8772 cmd_region_flowtype_parsed(void *parsed_result,
8773                         __attribute__((unused)) struct cmdline *cl,
8774                         __attribute__((unused)) void *data)
8775 {
8776         struct cmd_region_flowtype_result *res = parsed_result;
8777         int ret = -ENOTSUP;
8778 #ifdef RTE_LIBRTE_I40E_PMD
8779         struct rte_pmd_i40e_queue_region_conf region_conf;
8780         enum rte_pmd_i40e_queue_region_op op_type;
8781 #endif
8782
8783         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8784                 return;
8785
8786 #ifdef RTE_LIBRTE_I40E_PMD
8787         memset(&region_conf, 0, sizeof(region_conf));
8788
8789         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8790         region_conf.region_id = res->region_id;
8791         region_conf.hw_flowtype = res->flowtype_id;
8792
8793         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8794                         op_type, &region_conf);
8795 #endif
8796
8797         switch (ret) {
8798         case 0:
8799                 break;
8800         case -ENOTSUP:
8801                 printf("function not implemented or supported\n");
8802                 break;
8803         default:
8804                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8805         }
8806 }
8807
8808 cmdline_parse_token_string_t cmd_region_flowtype_set =
8809 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8810                                 set, "set");
8811 cmdline_parse_token_string_t cmd_region_flowtype_port =
8812         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8813                                 port, "port");
8814 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8815         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8816                                 port_id, UINT16);
8817 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8818         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8819                                 cmd, "queue-region");
8820 cmdline_parse_token_string_t cmd_region_flowtype_index =
8821         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8822                                 region, "region_id");
8823 cmdline_parse_token_num_t cmd_region_flowtype_id =
8824         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8825                                 region_id, UINT8);
8826 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8827         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8828                                 flowtype, "flowtype");
8829 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8830         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8831                                 flowtype_id, UINT8);
8832 cmdline_parse_inst_t cmd_region_flowtype = {
8833         .f = cmd_region_flowtype_parsed,
8834         .data = NULL,
8835         .help_str = "set port <port_id> queue-region region_id <value> "
8836                 "flowtype <value>: Set a flowtype region index",
8837         .tokens = {
8838                 (void *)&cmd_region_flowtype_set,
8839                 (void *)&cmd_region_flowtype_port,
8840                 (void *)&cmd_region_flowtype_port_index,
8841                 (void *)&cmd_region_flowtype_cmd,
8842                 (void *)&cmd_region_flowtype_index,
8843                 (void *)&cmd_region_flowtype_id,
8844                 (void *)&cmd_region_flowtype_flow_index,
8845                 (void *)&cmd_region_flowtype_flow_id,
8846                 NULL,
8847         },
8848 };
8849
8850 /* *** User Priority (UP) to queue region (region_id) set *** */
8851 struct cmd_user_priority_region_result {
8852         cmdline_fixed_string_t set;
8853         cmdline_fixed_string_t port;
8854         portid_t port_id;
8855         cmdline_fixed_string_t cmd;
8856         cmdline_fixed_string_t user_priority;
8857         uint8_t  user_priority_id;
8858         cmdline_fixed_string_t region;
8859         uint8_t  region_id;
8860 };
8861
8862 static void
8863 cmd_user_priority_region_parsed(void *parsed_result,
8864                         __attribute__((unused)) struct cmdline *cl,
8865                         __attribute__((unused)) void *data)
8866 {
8867         struct cmd_user_priority_region_result *res = parsed_result;
8868         int ret = -ENOTSUP;
8869 #ifdef RTE_LIBRTE_I40E_PMD
8870         struct rte_pmd_i40e_queue_region_conf region_conf;
8871         enum rte_pmd_i40e_queue_region_op op_type;
8872 #endif
8873
8874         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8875                 return;
8876
8877 #ifdef RTE_LIBRTE_I40E_PMD
8878         memset(&region_conf, 0, sizeof(region_conf));
8879         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8880         region_conf.user_priority = res->user_priority_id;
8881         region_conf.region_id = res->region_id;
8882
8883         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8884                                 op_type, &region_conf);
8885 #endif
8886
8887         switch (ret) {
8888         case 0:
8889                 break;
8890         case -ENOTSUP:
8891                 printf("function not implemented or supported\n");
8892                 break;
8893         default:
8894                 printf("user_priority region config error: (%s)\n",
8895                                 strerror(-ret));
8896         }
8897 }
8898
8899 cmdline_parse_token_string_t cmd_user_priority_region_set =
8900         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8901                                 set, "set");
8902 cmdline_parse_token_string_t cmd_user_priority_region_port =
8903         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8904                                 port, "port");
8905 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8906         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8907                                 port_id, UINT16);
8908 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8909         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8910                                 cmd, "queue-region");
8911 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8912         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8913                                 user_priority, "UP");
8914 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8915         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8916                                 user_priority_id, UINT8);
8917 cmdline_parse_token_string_t cmd_user_priority_region_region =
8918         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8919                                 region, "region_id");
8920 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8921         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8922                                 region_id, UINT8);
8923
8924 cmdline_parse_inst_t cmd_user_priority_region = {
8925         .f = cmd_user_priority_region_parsed,
8926         .data = NULL,
8927         .help_str = "set port <port_id> queue-region UP <value> "
8928                 "region_id <value>: Set the mapping of User Priority (UP) "
8929                 "to queue region (region_id) ",
8930         .tokens = {
8931                 (void *)&cmd_user_priority_region_set,
8932                 (void *)&cmd_user_priority_region_port,
8933                 (void *)&cmd_user_priority_region_port_index,
8934                 (void *)&cmd_user_priority_region_cmd,
8935                 (void *)&cmd_user_priority_region_UP,
8936                 (void *)&cmd_user_priority_region_UP_id,
8937                 (void *)&cmd_user_priority_region_region,
8938                 (void *)&cmd_user_priority_region_region_id,
8939                 NULL,
8940         },
8941 };
8942
8943 /* *** flush all queue region related configuration *** */
8944 struct cmd_flush_queue_region_result {
8945         cmdline_fixed_string_t set;
8946         cmdline_fixed_string_t port;
8947         portid_t port_id;
8948         cmdline_fixed_string_t cmd;
8949         cmdline_fixed_string_t flush;
8950         cmdline_fixed_string_t what;
8951 };
8952
8953 static void
8954 cmd_flush_queue_region_parsed(void *parsed_result,
8955                         __attribute__((unused)) struct cmdline *cl,
8956                         __attribute__((unused)) void *data)
8957 {
8958         struct cmd_flush_queue_region_result *res = parsed_result;
8959         int ret = -ENOTSUP;
8960 #ifdef RTE_LIBRTE_I40E_PMD
8961         struct rte_pmd_i40e_queue_region_conf region_conf;
8962         enum rte_pmd_i40e_queue_region_op op_type;
8963 #endif
8964
8965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8966                 return;
8967
8968 #ifdef RTE_LIBRTE_I40E_PMD
8969         memset(&region_conf, 0, sizeof(region_conf));
8970
8971         if (strcmp(res->what, "on") == 0)
8972                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8973         else
8974                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8975
8976         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8977                                 op_type, &region_conf);
8978 #endif
8979
8980         switch (ret) {
8981         case 0:
8982                 break;
8983         case -ENOTSUP:
8984                 printf("function not implemented or supported\n");
8985                 break;
8986         default:
8987                 printf("queue region config flush error: (%s)\n",
8988                                 strerror(-ret));
8989         }
8990 }
8991
8992 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8993         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8994                                 set, "set");
8995 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8996         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8997                                 port, "port");
8998 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8999         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9000                                 port_id, UINT16);
9001 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9002         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9003                                 cmd, "queue-region");
9004 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9005         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9006                                 flush, "flush");
9007 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9008         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9009                                 what, "on#off");
9010
9011 cmdline_parse_inst_t cmd_flush_queue_region = {
9012         .f = cmd_flush_queue_region_parsed,
9013         .data = NULL,
9014         .help_str = "set port <port_id> queue-region flush on|off"
9015                 ": flush all queue region related configuration",
9016         .tokens = {
9017                 (void *)&cmd_flush_queue_region_set,
9018                 (void *)&cmd_flush_queue_region_port,
9019                 (void *)&cmd_flush_queue_region_port_index,
9020                 (void *)&cmd_flush_queue_region_cmd,
9021                 (void *)&cmd_flush_queue_region_flush,
9022                 (void *)&cmd_flush_queue_region_what,
9023                 NULL,
9024         },
9025 };
9026
9027 /* *** get all queue region related configuration info *** */
9028 struct cmd_show_queue_region_info {
9029         cmdline_fixed_string_t show;
9030         cmdline_fixed_string_t port;
9031         portid_t port_id;
9032         cmdline_fixed_string_t cmd;
9033 };
9034
9035 static void
9036 cmd_show_queue_region_info_parsed(void *parsed_result,
9037                         __attribute__((unused)) struct cmdline *cl,
9038                         __attribute__((unused)) void *data)
9039 {
9040         struct cmd_show_queue_region_info *res = parsed_result;
9041         int ret = -ENOTSUP;
9042 #ifdef RTE_LIBRTE_I40E_PMD
9043         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9044         enum rte_pmd_i40e_queue_region_op op_type;
9045 #endif
9046
9047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9048                 return;
9049
9050 #ifdef RTE_LIBRTE_I40E_PMD
9051         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9052
9053         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9054
9055         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9056                                         op_type, &rte_pmd_regions);
9057
9058         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9059 #endif
9060
9061         switch (ret) {
9062         case 0:
9063                 break;
9064         case -ENOTSUP:
9065                 printf("function not implemented or supported\n");
9066                 break;
9067         default:
9068                 printf("queue region config info show error: (%s)\n",
9069                                 strerror(-ret));
9070         }
9071 }
9072
9073 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9074 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9075                                 show, "show");
9076 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9077         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9078                                 port, "port");
9079 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9080         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9081                                 port_id, UINT16);
9082 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9083         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9084                                 cmd, "queue-region");
9085
9086 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9087         .f = cmd_show_queue_region_info_parsed,
9088         .data = NULL,
9089         .help_str = "show port <port_id> queue-region"
9090                 ": show all queue region related configuration info",
9091         .tokens = {
9092                 (void *)&cmd_show_queue_region_info_get,
9093                 (void *)&cmd_show_queue_region_info_port,
9094                 (void *)&cmd_show_queue_region_info_port_index,
9095                 (void *)&cmd_show_queue_region_info_cmd,
9096                 NULL,
9097         },
9098 };
9099
9100 /* *** ADD/REMOVE A 2tuple FILTER *** */
9101 struct cmd_2tuple_filter_result {
9102         cmdline_fixed_string_t filter;
9103         portid_t port_id;
9104         cmdline_fixed_string_t ops;
9105         cmdline_fixed_string_t dst_port;
9106         uint16_t dst_port_value;
9107         cmdline_fixed_string_t protocol;
9108         uint8_t protocol_value;
9109         cmdline_fixed_string_t mask;
9110         uint8_t  mask_value;
9111         cmdline_fixed_string_t tcp_flags;
9112         uint8_t tcp_flags_value;
9113         cmdline_fixed_string_t priority;
9114         uint8_t  priority_value;
9115         cmdline_fixed_string_t queue;
9116         uint16_t  queue_id;
9117 };
9118
9119 static void
9120 cmd_2tuple_filter_parsed(void *parsed_result,
9121                         __attribute__((unused)) struct cmdline *cl,
9122                         __attribute__((unused)) void *data)
9123 {
9124         struct rte_eth_ntuple_filter filter;
9125         struct cmd_2tuple_filter_result *res = parsed_result;
9126         int ret = 0;
9127
9128         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9129         if (ret < 0) {
9130                 printf("ntuple filter is not supported on port %u.\n",
9131                         res->port_id);
9132                 return;
9133         }
9134
9135         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9136
9137         filter.flags = RTE_2TUPLE_FLAGS;
9138         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9139         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9140         filter.proto = res->protocol_value;
9141         filter.priority = res->priority_value;
9142         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9143                 printf("nonzero tcp_flags is only meaningful"
9144                         " when protocol is TCP.\n");
9145                 return;
9146         }
9147         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9148                 printf("invalid TCP flags.\n");
9149                 return;
9150         }
9151
9152         if (res->tcp_flags_value != 0) {
9153                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9154                 filter.tcp_flags = res->tcp_flags_value;
9155         }
9156
9157         /* need convert to big endian. */
9158         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9159         filter.queue = res->queue_id;
9160
9161         if (!strcmp(res->ops, "add"))
9162                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9163                                 RTE_ETH_FILTER_NTUPLE,
9164                                 RTE_ETH_FILTER_ADD,
9165                                 &filter);
9166         else
9167                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9168                                 RTE_ETH_FILTER_NTUPLE,
9169                                 RTE_ETH_FILTER_DELETE,
9170                                 &filter);
9171         if (ret < 0)
9172                 printf("2tuple filter programming error: (%s)\n",
9173                         strerror(-ret));
9174
9175 }
9176
9177 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9178         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9179                                  filter, "2tuple_filter");
9180 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9181         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9182                                 port_id, UINT16);
9183 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9184         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9185                                  ops, "add#del");
9186 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9187         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9188                                 dst_port, "dst_port");
9189 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9190         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9191                                 dst_port_value, UINT16);
9192 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9193         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9194                                 protocol, "protocol");
9195 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9196         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9197                                 protocol_value, UINT8);
9198 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9199         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9200                                 mask, "mask");
9201 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9202         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9203                                 mask_value, INT8);
9204 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9205         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9206                                 tcp_flags, "tcp_flags");
9207 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9208         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9209                                 tcp_flags_value, UINT8);
9210 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9211         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9212                                 priority, "priority");
9213 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9214         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9215                                 priority_value, UINT8);
9216 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9217         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9218                                 queue, "queue");
9219 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9220         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9221                                 queue_id, UINT16);
9222
9223 cmdline_parse_inst_t cmd_2tuple_filter = {
9224         .f = cmd_2tuple_filter_parsed,
9225         .data = NULL,
9226         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9227                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9228                 "<queue_id>: Add a 2tuple filter",
9229         .tokens = {
9230                 (void *)&cmd_2tuple_filter_filter,
9231                 (void *)&cmd_2tuple_filter_port_id,
9232                 (void *)&cmd_2tuple_filter_ops,
9233                 (void *)&cmd_2tuple_filter_dst_port,
9234                 (void *)&cmd_2tuple_filter_dst_port_value,
9235                 (void *)&cmd_2tuple_filter_protocol,
9236                 (void *)&cmd_2tuple_filter_protocol_value,
9237                 (void *)&cmd_2tuple_filter_mask,
9238                 (void *)&cmd_2tuple_filter_mask_value,
9239                 (void *)&cmd_2tuple_filter_tcp_flags,
9240                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9241                 (void *)&cmd_2tuple_filter_priority,
9242                 (void *)&cmd_2tuple_filter_priority_value,
9243                 (void *)&cmd_2tuple_filter_queue,
9244                 (void *)&cmd_2tuple_filter_queue_id,
9245                 NULL,
9246         },
9247 };
9248
9249 /* *** ADD/REMOVE A 5tuple FILTER *** */
9250 struct cmd_5tuple_filter_result {
9251         cmdline_fixed_string_t filter;
9252         portid_t port_id;
9253         cmdline_fixed_string_t ops;
9254         cmdline_fixed_string_t dst_ip;
9255         cmdline_ipaddr_t dst_ip_value;
9256         cmdline_fixed_string_t src_ip;
9257         cmdline_ipaddr_t src_ip_value;
9258         cmdline_fixed_string_t dst_port;
9259         uint16_t dst_port_value;
9260         cmdline_fixed_string_t src_port;
9261         uint16_t src_port_value;
9262         cmdline_fixed_string_t protocol;
9263         uint8_t protocol_value;
9264         cmdline_fixed_string_t mask;
9265         uint8_t  mask_value;
9266         cmdline_fixed_string_t tcp_flags;
9267         uint8_t tcp_flags_value;
9268         cmdline_fixed_string_t priority;
9269         uint8_t  priority_value;
9270         cmdline_fixed_string_t queue;
9271         uint16_t  queue_id;
9272 };
9273
9274 static void
9275 cmd_5tuple_filter_parsed(void *parsed_result,
9276                         __attribute__((unused)) struct cmdline *cl,
9277                         __attribute__((unused)) void *data)
9278 {
9279         struct rte_eth_ntuple_filter filter;
9280         struct cmd_5tuple_filter_result *res = parsed_result;
9281         int ret = 0;
9282
9283         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9284         if (ret < 0) {
9285                 printf("ntuple filter is not supported on port %u.\n",
9286                         res->port_id);
9287                 return;
9288         }
9289
9290         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9291
9292         filter.flags = RTE_5TUPLE_FLAGS;
9293         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9294         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9295         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9296         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9297         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9298         filter.proto = res->protocol_value;
9299         filter.priority = res->priority_value;
9300         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9301                 printf("nonzero tcp_flags is only meaningful"
9302                         " when protocol is TCP.\n");
9303                 return;
9304         }
9305         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9306                 printf("invalid TCP flags.\n");
9307                 return;
9308         }
9309
9310         if (res->tcp_flags_value != 0) {
9311                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9312                 filter.tcp_flags = res->tcp_flags_value;
9313         }
9314
9315         if (res->dst_ip_value.family == AF_INET)
9316                 /* no need to convert, already big endian. */
9317                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9318         else {
9319                 if (filter.dst_ip_mask == 0) {
9320                         printf("can not support ipv6 involved compare.\n");
9321                         return;
9322                 }
9323                 filter.dst_ip = 0;
9324         }
9325
9326         if (res->src_ip_value.family == AF_INET)
9327                 /* no need to convert, already big endian. */
9328                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9329         else {
9330                 if (filter.src_ip_mask == 0) {
9331                         printf("can not support ipv6 involved compare.\n");
9332                         return;
9333                 }
9334                 filter.src_ip = 0;
9335         }
9336         /* need convert to big endian. */
9337         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9338         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9339         filter.queue = res->queue_id;
9340
9341         if (!strcmp(res->ops, "add"))
9342                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9343                                 RTE_ETH_FILTER_NTUPLE,
9344                                 RTE_ETH_FILTER_ADD,
9345                                 &filter);
9346         else
9347                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9348                                 RTE_ETH_FILTER_NTUPLE,
9349                                 RTE_ETH_FILTER_DELETE,
9350                                 &filter);
9351         if (ret < 0)
9352                 printf("5tuple filter programming error: (%s)\n",
9353                         strerror(-ret));
9354 }
9355
9356 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9357         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9358                                  filter, "5tuple_filter");
9359 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9360         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9361                                 port_id, UINT16);
9362 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9363         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9364                                  ops, "add#del");
9365 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9366         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9367                                 dst_ip, "dst_ip");
9368 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9369         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9370                                 dst_ip_value);
9371 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9372         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9373                                 src_ip, "src_ip");
9374 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9375         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9376                                 src_ip_value);
9377 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9378         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9379                                 dst_port, "dst_port");
9380 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9381         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9382                                 dst_port_value, UINT16);
9383 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9384         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9385                                 src_port, "src_port");
9386 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9387         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9388                                 src_port_value, UINT16);
9389 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9390         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9391                                 protocol, "protocol");
9392 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9393         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9394                                 protocol_value, UINT8);
9395 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9396         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9397                                 mask, "mask");
9398 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9399         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9400                                 mask_value, INT8);
9401 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9402         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9403                                 tcp_flags, "tcp_flags");
9404 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9405         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9406                                 tcp_flags_value, UINT8);
9407 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9408         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9409                                 priority, "priority");
9410 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9411         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9412                                 priority_value, UINT8);
9413 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9414         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9415                                 queue, "queue");
9416 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9417         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9418                                 queue_id, UINT16);
9419
9420 cmdline_parse_inst_t cmd_5tuple_filter = {
9421         .f = cmd_5tuple_filter_parsed,
9422         .data = NULL,
9423         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9424                 "src_ip <value> dst_port <value> src_port <value> "
9425                 "protocol <value>  mask <value> tcp_flags <value> "
9426                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9427         .tokens = {
9428                 (void *)&cmd_5tuple_filter_filter,
9429                 (void *)&cmd_5tuple_filter_port_id,
9430                 (void *)&cmd_5tuple_filter_ops,
9431                 (void *)&cmd_5tuple_filter_dst_ip,
9432                 (void *)&cmd_5tuple_filter_dst_ip_value,
9433                 (void *)&cmd_5tuple_filter_src_ip,
9434                 (void *)&cmd_5tuple_filter_src_ip_value,
9435                 (void *)&cmd_5tuple_filter_dst_port,
9436                 (void *)&cmd_5tuple_filter_dst_port_value,
9437                 (void *)&cmd_5tuple_filter_src_port,
9438                 (void *)&cmd_5tuple_filter_src_port_value,
9439                 (void *)&cmd_5tuple_filter_protocol,
9440                 (void *)&cmd_5tuple_filter_protocol_value,
9441                 (void *)&cmd_5tuple_filter_mask,
9442                 (void *)&cmd_5tuple_filter_mask_value,
9443                 (void *)&cmd_5tuple_filter_tcp_flags,
9444                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9445                 (void *)&cmd_5tuple_filter_priority,
9446                 (void *)&cmd_5tuple_filter_priority_value,
9447                 (void *)&cmd_5tuple_filter_queue,
9448                 (void *)&cmd_5tuple_filter_queue_id,
9449                 NULL,
9450         },
9451 };
9452
9453 /* *** ADD/REMOVE A flex FILTER *** */
9454 struct cmd_flex_filter_result {
9455         cmdline_fixed_string_t filter;
9456         cmdline_fixed_string_t ops;
9457         portid_t port_id;
9458         cmdline_fixed_string_t len;
9459         uint8_t len_value;
9460         cmdline_fixed_string_t bytes;
9461         cmdline_fixed_string_t bytes_value;
9462         cmdline_fixed_string_t mask;
9463         cmdline_fixed_string_t mask_value;
9464         cmdline_fixed_string_t priority;
9465         uint8_t priority_value;
9466         cmdline_fixed_string_t queue;
9467         uint16_t queue_id;
9468 };
9469
9470 static int xdigit2val(unsigned char c)
9471 {
9472         int val;
9473         if (isdigit(c))
9474                 val = c - '0';
9475         else if (isupper(c))
9476                 val = c - 'A' + 10;
9477         else
9478                 val = c - 'a' + 10;
9479         return val;
9480 }
9481
9482 static void
9483 cmd_flex_filter_parsed(void *parsed_result,
9484                           __attribute__((unused)) struct cmdline *cl,
9485                           __attribute__((unused)) void *data)
9486 {
9487         int ret = 0;
9488         struct rte_eth_flex_filter filter;
9489         struct cmd_flex_filter_result *res = parsed_result;
9490         char *bytes_ptr, *mask_ptr;
9491         uint16_t len, i, j = 0;
9492         char c;
9493         int val;
9494         uint8_t byte = 0;
9495
9496         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9497                 printf("the len exceed the max length 128\n");
9498                 return;
9499         }
9500         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9501         filter.len = res->len_value;
9502         filter.priority = res->priority_value;
9503         filter.queue = res->queue_id;
9504         bytes_ptr = res->bytes_value;
9505         mask_ptr = res->mask_value;
9506
9507          /* translate bytes string to array. */
9508         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9509                 (bytes_ptr[1] == 'X')))
9510                 bytes_ptr += 2;
9511         len = strnlen(bytes_ptr, res->len_value * 2);
9512         if (len == 0 || (len % 8 != 0)) {
9513                 printf("please check len and bytes input\n");
9514                 return;
9515         }
9516         for (i = 0; i < len; i++) {
9517                 c = bytes_ptr[i];
9518                 if (isxdigit(c) == 0) {
9519                         /* invalid characters. */
9520                         printf("invalid input\n");
9521                         return;
9522                 }
9523                 val = xdigit2val(c);
9524                 if (i % 2) {
9525                         byte |= val;
9526                         filter.bytes[j] = byte;
9527                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9528                         j++;
9529                         byte = 0;
9530                 } else
9531                         byte |= val << 4;
9532         }
9533         printf("\n");
9534          /* translate mask string to uint8_t array. */
9535         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9536                 (mask_ptr[1] == 'X')))
9537                 mask_ptr += 2;
9538         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9539         if (len == 0) {
9540                 printf("invalid input\n");
9541                 return;
9542         }
9543         j = 0;
9544         byte = 0;
9545         for (i = 0; i < len; i++) {
9546                 c = mask_ptr[i];
9547                 if (isxdigit(c) == 0) {
9548                         /* invalid characters. */
9549                         printf("invalid input\n");
9550                         return;
9551                 }
9552                 val = xdigit2val(c);
9553                 if (i % 2) {
9554                         byte |= val;
9555                         filter.mask[j] = byte;
9556                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9557                         j++;
9558                         byte = 0;
9559                 } else
9560                         byte |= val << 4;
9561         }
9562         printf("\n");
9563
9564         if (!strcmp(res->ops, "add"))
9565                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9566                                 RTE_ETH_FILTER_FLEXIBLE,
9567                                 RTE_ETH_FILTER_ADD,
9568                                 &filter);
9569         else
9570                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9571                                 RTE_ETH_FILTER_FLEXIBLE,
9572                                 RTE_ETH_FILTER_DELETE,
9573                                 &filter);
9574
9575         if (ret < 0)
9576                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9577 }
9578
9579 cmdline_parse_token_string_t cmd_flex_filter_filter =
9580         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9581                                 filter, "flex_filter");
9582 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9583         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9584                                 port_id, UINT16);
9585 cmdline_parse_token_string_t cmd_flex_filter_ops =
9586         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9587                                 ops, "add#del");
9588 cmdline_parse_token_string_t cmd_flex_filter_len =
9589         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9590                                 len, "len");
9591 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9592         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9593                                 len_value, UINT8);
9594 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9595         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9596                                 bytes, "bytes");
9597 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9598         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9599                                 bytes_value, NULL);
9600 cmdline_parse_token_string_t cmd_flex_filter_mask =
9601         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9602                                 mask, "mask");
9603 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9604         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9605                                 mask_value, NULL);
9606 cmdline_parse_token_string_t cmd_flex_filter_priority =
9607         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9608                                 priority, "priority");
9609 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9610         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9611                                 priority_value, UINT8);
9612 cmdline_parse_token_string_t cmd_flex_filter_queue =
9613         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9614                                 queue, "queue");
9615 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9616         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9617                                 queue_id, UINT16);
9618 cmdline_parse_inst_t cmd_flex_filter = {
9619         .f = cmd_flex_filter_parsed,
9620         .data = NULL,
9621         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9622                 "<value> mask <value> priority <value> queue <queue_id>: "
9623                 "Add/Del a flex filter",
9624         .tokens = {
9625                 (void *)&cmd_flex_filter_filter,
9626                 (void *)&cmd_flex_filter_port_id,
9627                 (void *)&cmd_flex_filter_ops,
9628                 (void *)&cmd_flex_filter_len,
9629                 (void *)&cmd_flex_filter_len_value,
9630                 (void *)&cmd_flex_filter_bytes,
9631                 (void *)&cmd_flex_filter_bytes_value,
9632                 (void *)&cmd_flex_filter_mask,
9633                 (void *)&cmd_flex_filter_mask_value,
9634                 (void *)&cmd_flex_filter_priority,
9635                 (void *)&cmd_flex_filter_priority_value,
9636                 (void *)&cmd_flex_filter_queue,
9637                 (void *)&cmd_flex_filter_queue_id,
9638                 NULL,
9639         },
9640 };
9641
9642 /* *** Filters Control *** */
9643
9644 /* *** deal with ethertype filter *** */
9645 struct cmd_ethertype_filter_result {
9646         cmdline_fixed_string_t filter;
9647         portid_t port_id;
9648         cmdline_fixed_string_t ops;
9649         cmdline_fixed_string_t mac;
9650         struct ether_addr mac_addr;
9651         cmdline_fixed_string_t ethertype;
9652         uint16_t ethertype_value;
9653         cmdline_fixed_string_t drop;
9654         cmdline_fixed_string_t queue;
9655         uint16_t  queue_id;
9656 };
9657
9658 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9659         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9660                                  filter, "ethertype_filter");
9661 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9662         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9663                               port_id, UINT16);
9664 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9665         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9666                                  ops, "add#del");
9667 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9668         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9669                                  mac, "mac_addr#mac_ignr");
9670 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9671         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9672                                      mac_addr);
9673 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9674         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9675                                  ethertype, "ethertype");
9676 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9677         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9678                               ethertype_value, UINT16);
9679 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9680         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9681                                  drop, "drop#fwd");
9682 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9683         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9684                                  queue, "queue");
9685 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9686         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9687                               queue_id, UINT16);
9688
9689 static void
9690 cmd_ethertype_filter_parsed(void *parsed_result,
9691                           __attribute__((unused)) struct cmdline *cl,
9692                           __attribute__((unused)) void *data)
9693 {
9694         struct cmd_ethertype_filter_result *res = parsed_result;
9695         struct rte_eth_ethertype_filter filter;
9696         int ret = 0;
9697
9698         ret = rte_eth_dev_filter_supported(res->port_id,
9699                         RTE_ETH_FILTER_ETHERTYPE);
9700         if (ret < 0) {
9701                 printf("ethertype filter is not supported on port %u.\n",
9702                         res->port_id);
9703                 return;
9704         }
9705
9706         memset(&filter, 0, sizeof(filter));
9707         if (!strcmp(res->mac, "mac_addr")) {
9708                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9709                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9710                         sizeof(struct ether_addr));
9711         }
9712         if (!strcmp(res->drop, "drop"))
9713                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9714         filter.ether_type = res->ethertype_value;
9715         filter.queue = res->queue_id;
9716
9717         if (!strcmp(res->ops, "add"))
9718                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9719                                 RTE_ETH_FILTER_ETHERTYPE,
9720                                 RTE_ETH_FILTER_ADD,
9721                                 &filter);
9722         else
9723                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9724                                 RTE_ETH_FILTER_ETHERTYPE,
9725                                 RTE_ETH_FILTER_DELETE,
9726                                 &filter);
9727         if (ret < 0)
9728                 printf("ethertype filter programming error: (%s)\n",
9729                         strerror(-ret));
9730 }
9731
9732 cmdline_parse_inst_t cmd_ethertype_filter = {
9733         .f = cmd_ethertype_filter_parsed,
9734         .data = NULL,
9735         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9736                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9737                 "Add or delete an ethertype filter entry",
9738         .tokens = {
9739                 (void *)&cmd_ethertype_filter_filter,
9740                 (void *)&cmd_ethertype_filter_port_id,
9741                 (void *)&cmd_ethertype_filter_ops,
9742                 (void *)&cmd_ethertype_filter_mac,
9743                 (void *)&cmd_ethertype_filter_mac_addr,
9744                 (void *)&cmd_ethertype_filter_ethertype,
9745                 (void *)&cmd_ethertype_filter_ethertype_value,
9746                 (void *)&cmd_ethertype_filter_drop,
9747                 (void *)&cmd_ethertype_filter_queue,
9748                 (void *)&cmd_ethertype_filter_queue_id,
9749                 NULL,
9750         },
9751 };
9752
9753 /* *** deal with flow director filter *** */
9754 struct cmd_flow_director_result {
9755         cmdline_fixed_string_t flow_director_filter;
9756         portid_t port_id;
9757         cmdline_fixed_string_t mode;
9758         cmdline_fixed_string_t mode_value;
9759         cmdline_fixed_string_t ops;
9760         cmdline_fixed_string_t flow;
9761         cmdline_fixed_string_t flow_type;
9762         cmdline_fixed_string_t ether;
9763         uint16_t ether_type;
9764         cmdline_fixed_string_t src;
9765         cmdline_ipaddr_t ip_src;
9766         uint16_t port_src;
9767         cmdline_fixed_string_t dst;
9768         cmdline_ipaddr_t ip_dst;
9769         uint16_t port_dst;
9770         cmdline_fixed_string_t verify_tag;
9771         uint32_t verify_tag_value;
9772         cmdline_ipaddr_t tos;
9773         uint8_t tos_value;
9774         cmdline_ipaddr_t proto;
9775         uint8_t proto_value;
9776         cmdline_ipaddr_t ttl;
9777         uint8_t ttl_value;
9778         cmdline_fixed_string_t vlan;
9779         uint16_t vlan_value;
9780         cmdline_fixed_string_t flexbytes;
9781         cmdline_fixed_string_t flexbytes_value;
9782         cmdline_fixed_string_t pf_vf;
9783         cmdline_fixed_string_t drop;
9784         cmdline_fixed_string_t queue;
9785         uint16_t  queue_id;
9786         cmdline_fixed_string_t fd_id;
9787         uint32_t  fd_id_value;
9788         cmdline_fixed_string_t mac;
9789         struct ether_addr mac_addr;
9790         cmdline_fixed_string_t tunnel;
9791         cmdline_fixed_string_t tunnel_type;
9792         cmdline_fixed_string_t tunnel_id;
9793         uint32_t tunnel_id_value;
9794 };
9795
9796 static inline int
9797 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9798 {
9799         char s[256];
9800         const char *p, *p0 = q_arg;
9801         char *end;
9802         unsigned long int_fld;
9803         char *str_fld[max_num];
9804         int i;
9805         unsigned size;
9806         int ret = -1;
9807
9808         p = strchr(p0, '(');
9809         if (p == NULL)
9810                 return -1;
9811         ++p;
9812         p0 = strchr(p, ')');
9813         if (p0 == NULL)
9814                 return -1;
9815
9816         size = p0 - p;
9817         if (size >= sizeof(s))
9818                 return -1;
9819
9820         snprintf(s, sizeof(s), "%.*s", size, p);
9821         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9822         if (ret < 0 || ret > max_num)
9823                 return -1;
9824         for (i = 0; i < ret; i++) {
9825                 errno = 0;
9826                 int_fld = strtoul(str_fld[i], &end, 0);
9827                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9828                         return -1;
9829                 flexbytes[i] = (uint8_t)int_fld;
9830         }
9831         return ret;
9832 }
9833
9834 static uint16_t
9835 str2flowtype(char *string)
9836 {
9837         uint8_t i = 0;
9838         static const struct {
9839                 char str[32];
9840                 uint16_t type;
9841         } flowtype_str[] = {
9842                 {"raw", RTE_ETH_FLOW_RAW},
9843                 {"ipv4", RTE_ETH_FLOW_IPV4},
9844                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9845                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9846                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9847                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9848                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9849                 {"ipv6", RTE_ETH_FLOW_IPV6},
9850                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9851                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9852                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9853                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9854                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9855                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9856         };
9857
9858         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9859                 if (!strcmp(flowtype_str[i].str, string))
9860                         return flowtype_str[i].type;
9861         }
9862
9863         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9864                 return (uint16_t)atoi(string);
9865
9866         return RTE_ETH_FLOW_UNKNOWN;
9867 }
9868
9869 static enum rte_eth_fdir_tunnel_type
9870 str2fdir_tunneltype(char *string)
9871 {
9872         uint8_t i = 0;
9873
9874         static const struct {
9875                 char str[32];
9876                 enum rte_eth_fdir_tunnel_type type;
9877         } tunneltype_str[] = {
9878                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9879                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9880         };
9881
9882         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9883                 if (!strcmp(tunneltype_str[i].str, string))
9884                         return tunneltype_str[i].type;
9885         }
9886         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9887 }
9888
9889 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9890 do { \
9891         if ((ip_addr).family == AF_INET) \
9892                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9893         else { \
9894                 printf("invalid parameter.\n"); \
9895                 return; \
9896         } \
9897 } while (0)
9898
9899 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9900 do { \
9901         if ((ip_addr).family == AF_INET6) \
9902                 rte_memcpy(&(ip), \
9903                                  &((ip_addr).addr.ipv6), \
9904                                  sizeof(struct in6_addr)); \
9905         else { \
9906                 printf("invalid parameter.\n"); \
9907                 return; \
9908         } \
9909 } while (0)
9910
9911 static void
9912 cmd_flow_director_filter_parsed(void *parsed_result,
9913                           __attribute__((unused)) struct cmdline *cl,
9914                           __attribute__((unused)) void *data)
9915 {
9916         struct cmd_flow_director_result *res = parsed_result;
9917         struct rte_eth_fdir_filter entry;
9918         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9919         char *end;
9920         unsigned long vf_id;
9921         int ret = 0;
9922
9923         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9924         if (ret < 0) {
9925                 printf("flow director is not supported on port %u.\n",
9926                         res->port_id);
9927                 return;
9928         }
9929         memset(flexbytes, 0, sizeof(flexbytes));
9930         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9931
9932         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9933                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9934                         printf("Please set mode to MAC-VLAN.\n");
9935                         return;
9936                 }
9937         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9938                 if (strcmp(res->mode_value, "Tunnel")) {
9939                         printf("Please set mode to Tunnel.\n");
9940                         return;
9941                 }
9942         } else {
9943                 if (strcmp(res->mode_value, "IP")) {
9944                         printf("Please set mode to IP.\n");
9945                         return;
9946                 }
9947                 entry.input.flow_type = str2flowtype(res->flow_type);
9948         }
9949
9950         ret = parse_flexbytes(res->flexbytes_value,
9951                                         flexbytes,
9952                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9953         if (ret < 0) {
9954                 printf("error: Cannot parse flexbytes input.\n");
9955                 return;
9956         }
9957
9958         switch (entry.input.flow_type) {
9959         case RTE_ETH_FLOW_FRAG_IPV4:
9960         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9961                 entry.input.flow.ip4_flow.proto = res->proto_value;
9962                 /* fall-through */
9963         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9964         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9965                 IPV4_ADDR_TO_UINT(res->ip_dst,
9966                         entry.input.flow.ip4_flow.dst_ip);
9967                 IPV4_ADDR_TO_UINT(res->ip_src,
9968                         entry.input.flow.ip4_flow.src_ip);
9969                 entry.input.flow.ip4_flow.tos = res->tos_value;
9970                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9971                 /* need convert to big endian. */
9972                 entry.input.flow.udp4_flow.dst_port =
9973                                 rte_cpu_to_be_16(res->port_dst);
9974                 entry.input.flow.udp4_flow.src_port =
9975                                 rte_cpu_to_be_16(res->port_src);
9976                 break;
9977         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9978                 IPV4_ADDR_TO_UINT(res->ip_dst,
9979                         entry.input.flow.sctp4_flow.ip.dst_ip);
9980                 IPV4_ADDR_TO_UINT(res->ip_src,
9981                         entry.input.flow.sctp4_flow.ip.src_ip);
9982                 entry.input.flow.ip4_flow.tos = res->tos_value;
9983                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9984                 /* need convert to big endian. */
9985                 entry.input.flow.sctp4_flow.dst_port =
9986                                 rte_cpu_to_be_16(res->port_dst);
9987                 entry.input.flow.sctp4_flow.src_port =
9988                                 rte_cpu_to_be_16(res->port_src);
9989                 entry.input.flow.sctp4_flow.verify_tag =
9990                                 rte_cpu_to_be_32(res->verify_tag_value);
9991                 break;
9992         case RTE_ETH_FLOW_FRAG_IPV6:
9993         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9994                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9995                 /* fall-through */
9996         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9997         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9998                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9999                         entry.input.flow.ipv6_flow.dst_ip);
10000                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10001                         entry.input.flow.ipv6_flow.src_ip);
10002                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10003                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10004                 /* need convert to big endian. */
10005                 entry.input.flow.udp6_flow.dst_port =
10006                                 rte_cpu_to_be_16(res->port_dst);
10007                 entry.input.flow.udp6_flow.src_port =
10008                                 rte_cpu_to_be_16(res->port_src);
10009                 break;
10010         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10011                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10012                         entry.input.flow.sctp6_flow.ip.dst_ip);
10013                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10014                         entry.input.flow.sctp6_flow.ip.src_ip);
10015                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10016                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10017                 /* need convert to big endian. */
10018                 entry.input.flow.sctp6_flow.dst_port =
10019                                 rte_cpu_to_be_16(res->port_dst);
10020                 entry.input.flow.sctp6_flow.src_port =
10021                                 rte_cpu_to_be_16(res->port_src);
10022                 entry.input.flow.sctp6_flow.verify_tag =
10023                                 rte_cpu_to_be_32(res->verify_tag_value);
10024                 break;
10025         case RTE_ETH_FLOW_L2_PAYLOAD:
10026                 entry.input.flow.l2_flow.ether_type =
10027                         rte_cpu_to_be_16(res->ether_type);
10028                 break;
10029         default:
10030                 break;
10031         }
10032
10033         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10034                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10035                                  &res->mac_addr,
10036                                  sizeof(struct ether_addr));
10037
10038         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10039                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10040                                  &res->mac_addr,
10041                                  sizeof(struct ether_addr));
10042                 entry.input.flow.tunnel_flow.tunnel_type =
10043                         str2fdir_tunneltype(res->tunnel_type);
10044                 entry.input.flow.tunnel_flow.tunnel_id =
10045                         rte_cpu_to_be_32(res->tunnel_id_value);
10046         }
10047
10048         rte_memcpy(entry.input.flow_ext.flexbytes,
10049                    flexbytes,
10050                    RTE_ETH_FDIR_MAX_FLEXLEN);
10051
10052         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10053
10054         entry.action.flex_off = 0;  /*use 0 by default */
10055         if (!strcmp(res->drop, "drop"))
10056                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10057         else
10058                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10059
10060         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10061             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10062                 if (!strcmp(res->pf_vf, "pf"))
10063                         entry.input.flow_ext.is_vf = 0;
10064                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10065                         struct rte_eth_dev_info dev_info;
10066
10067                         memset(&dev_info, 0, sizeof(dev_info));
10068                         rte_eth_dev_info_get(res->port_id, &dev_info);
10069                         errno = 0;
10070                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10071                         if (errno != 0 || *end != '\0' ||
10072                             vf_id >= dev_info.max_vfs) {
10073                                 printf("invalid parameter %s.\n", res->pf_vf);
10074                                 return;
10075                         }
10076                         entry.input.flow_ext.is_vf = 1;
10077                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10078                 } else {
10079                         printf("invalid parameter %s.\n", res->pf_vf);
10080                         return;
10081                 }
10082         }
10083
10084         /* set to report FD ID by default */
10085         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10086         entry.action.rx_queue = res->queue_id;
10087         entry.soft_id = res->fd_id_value;
10088         if (!strcmp(res->ops, "add"))
10089                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10090                                              RTE_ETH_FILTER_ADD, &entry);
10091         else if (!strcmp(res->ops, "del"))
10092                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10093                                              RTE_ETH_FILTER_DELETE, &entry);
10094         else
10095                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10096                                              RTE_ETH_FILTER_UPDATE, &entry);
10097         if (ret < 0)
10098                 printf("flow director programming error: (%s)\n",
10099                         strerror(-ret));
10100 }
10101
10102 cmdline_parse_token_string_t cmd_flow_director_filter =
10103         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10104                                  flow_director_filter, "flow_director_filter");
10105 cmdline_parse_token_num_t cmd_flow_director_port_id =
10106         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10107                               port_id, UINT16);
10108 cmdline_parse_token_string_t cmd_flow_director_ops =
10109         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10110                                  ops, "add#del#update");
10111 cmdline_parse_token_string_t cmd_flow_director_flow =
10112         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10113                                  flow, "flow");
10114 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10115         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10116                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10117                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10118 cmdline_parse_token_string_t cmd_flow_director_ether =
10119         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10120                                  ether, "ether");
10121 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10122         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10123                               ether_type, UINT16);
10124 cmdline_parse_token_string_t cmd_flow_director_src =
10125         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10126                                  src, "src");
10127 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10128         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10129                                  ip_src);
10130 cmdline_parse_token_num_t cmd_flow_director_port_src =
10131         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10132                               port_src, UINT16);
10133 cmdline_parse_token_string_t cmd_flow_director_dst =
10134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10135                                  dst, "dst");
10136 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10137         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10138                                  ip_dst);
10139 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10140         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10141                               port_dst, UINT16);
10142 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10143         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10144                                   verify_tag, "verify_tag");
10145 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10146         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10147                               verify_tag_value, UINT32);
10148 cmdline_parse_token_string_t cmd_flow_director_tos =
10149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10150                                  tos, "tos");
10151 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10152         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10153                               tos_value, UINT8);
10154 cmdline_parse_token_string_t cmd_flow_director_proto =
10155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10156                                  proto, "proto");
10157 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10158         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10159                               proto_value, UINT8);
10160 cmdline_parse_token_string_t cmd_flow_director_ttl =
10161         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10162                                  ttl, "ttl");
10163 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10164         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10165                               ttl_value, UINT8);
10166 cmdline_parse_token_string_t cmd_flow_director_vlan =
10167         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10168                                  vlan, "vlan");
10169 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10170         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10171                               vlan_value, UINT16);
10172 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10173         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10174                                  flexbytes, "flexbytes");
10175 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10176         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10177                               flexbytes_value, NULL);
10178 cmdline_parse_token_string_t cmd_flow_director_drop =
10179         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10180                                  drop, "drop#fwd");
10181 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10182         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10183                               pf_vf, NULL);
10184 cmdline_parse_token_string_t cmd_flow_director_queue =
10185         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10186                                  queue, "queue");
10187 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10188         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10189                               queue_id, UINT16);
10190 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10191         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10192                                  fd_id, "fd_id");
10193 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10194         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10195                               fd_id_value, UINT32);
10196
10197 cmdline_parse_token_string_t cmd_flow_director_mode =
10198         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10199                                  mode, "mode");
10200 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10202                                  mode_value, "IP");
10203 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10204         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10205                                  mode_value, "MAC-VLAN");
10206 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10207         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10208                                  mode_value, "Tunnel");
10209 cmdline_parse_token_string_t cmd_flow_director_mac =
10210         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10211                                  mac, "mac");
10212 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10213         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10214                                     mac_addr);
10215 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10216         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10217                                  tunnel, "tunnel");
10218 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10219         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10220                                  tunnel_type, "NVGRE#VxLAN");
10221 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10223                                  tunnel_id, "tunnel-id");
10224 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10225         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10226                               tunnel_id_value, UINT32);
10227
10228 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10229         .f = cmd_flow_director_filter_parsed,
10230         .data = NULL,
10231         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10232                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10233                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10234                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10235                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10236                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10237                 "fd_id <fd_id_value>: "
10238                 "Add or delete an ip flow director entry on NIC",
10239         .tokens = {
10240                 (void *)&cmd_flow_director_filter,
10241                 (void *)&cmd_flow_director_port_id,
10242                 (void *)&cmd_flow_director_mode,
10243                 (void *)&cmd_flow_director_mode_ip,
10244                 (void *)&cmd_flow_director_ops,
10245                 (void *)&cmd_flow_director_flow,
10246                 (void *)&cmd_flow_director_flow_type,
10247                 (void *)&cmd_flow_director_src,
10248                 (void *)&cmd_flow_director_ip_src,
10249                 (void *)&cmd_flow_director_dst,
10250                 (void *)&cmd_flow_director_ip_dst,
10251                 (void *)&cmd_flow_director_tos,
10252                 (void *)&cmd_flow_director_tos_value,
10253                 (void *)&cmd_flow_director_proto,
10254                 (void *)&cmd_flow_director_proto_value,
10255                 (void *)&cmd_flow_director_ttl,
10256                 (void *)&cmd_flow_director_ttl_value,
10257                 (void *)&cmd_flow_director_vlan,
10258                 (void *)&cmd_flow_director_vlan_value,
10259                 (void *)&cmd_flow_director_flexbytes,
10260                 (void *)&cmd_flow_director_flexbytes_value,
10261                 (void *)&cmd_flow_director_drop,
10262                 (void *)&cmd_flow_director_pf_vf,
10263                 (void *)&cmd_flow_director_queue,
10264                 (void *)&cmd_flow_director_queue_id,
10265                 (void *)&cmd_flow_director_fd_id,
10266                 (void *)&cmd_flow_director_fd_id_value,
10267                 NULL,
10268         },
10269 };
10270
10271 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10272         .f = cmd_flow_director_filter_parsed,
10273         .data = NULL,
10274         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10275                 "director entry on NIC",
10276         .tokens = {
10277                 (void *)&cmd_flow_director_filter,
10278                 (void *)&cmd_flow_director_port_id,
10279                 (void *)&cmd_flow_director_mode,
10280                 (void *)&cmd_flow_director_mode_ip,
10281                 (void *)&cmd_flow_director_ops,
10282                 (void *)&cmd_flow_director_flow,
10283                 (void *)&cmd_flow_director_flow_type,
10284                 (void *)&cmd_flow_director_src,
10285                 (void *)&cmd_flow_director_ip_src,
10286                 (void *)&cmd_flow_director_port_src,
10287                 (void *)&cmd_flow_director_dst,
10288                 (void *)&cmd_flow_director_ip_dst,
10289                 (void *)&cmd_flow_director_port_dst,
10290                 (void *)&cmd_flow_director_tos,
10291                 (void *)&cmd_flow_director_tos_value,
10292                 (void *)&cmd_flow_director_ttl,
10293                 (void *)&cmd_flow_director_ttl_value,
10294                 (void *)&cmd_flow_director_vlan,
10295                 (void *)&cmd_flow_director_vlan_value,
10296                 (void *)&cmd_flow_director_flexbytes,
10297                 (void *)&cmd_flow_director_flexbytes_value,
10298                 (void *)&cmd_flow_director_drop,
10299                 (void *)&cmd_flow_director_pf_vf,
10300                 (void *)&cmd_flow_director_queue,
10301                 (void *)&cmd_flow_director_queue_id,
10302                 (void *)&cmd_flow_director_fd_id,
10303                 (void *)&cmd_flow_director_fd_id_value,
10304                 NULL,
10305         },
10306 };
10307
10308 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10309         .f = cmd_flow_director_filter_parsed,
10310         .data = NULL,
10311         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10312                 "director entry on NIC",
10313         .tokens = {
10314                 (void *)&cmd_flow_director_filter,
10315                 (void *)&cmd_flow_director_port_id,
10316                 (void *)&cmd_flow_director_mode,
10317                 (void *)&cmd_flow_director_mode_ip,
10318                 (void *)&cmd_flow_director_ops,
10319                 (void *)&cmd_flow_director_flow,
10320                 (void *)&cmd_flow_director_flow_type,
10321                 (void *)&cmd_flow_director_src,
10322                 (void *)&cmd_flow_director_ip_src,
10323                 (void *)&cmd_flow_director_port_dst,
10324                 (void *)&cmd_flow_director_dst,
10325                 (void *)&cmd_flow_director_ip_dst,
10326                 (void *)&cmd_flow_director_port_dst,
10327                 (void *)&cmd_flow_director_verify_tag,
10328                 (void *)&cmd_flow_director_verify_tag_value,
10329                 (void *)&cmd_flow_director_tos,
10330                 (void *)&cmd_flow_director_tos_value,
10331                 (void *)&cmd_flow_director_ttl,
10332                 (void *)&cmd_flow_director_ttl_value,
10333                 (void *)&cmd_flow_director_vlan,
10334                 (void *)&cmd_flow_director_vlan_value,
10335                 (void *)&cmd_flow_director_flexbytes,
10336                 (void *)&cmd_flow_director_flexbytes_value,
10337                 (void *)&cmd_flow_director_drop,
10338                 (void *)&cmd_flow_director_pf_vf,
10339                 (void *)&cmd_flow_director_queue,
10340                 (void *)&cmd_flow_director_queue_id,
10341                 (void *)&cmd_flow_director_fd_id,
10342                 (void *)&cmd_flow_director_fd_id_value,
10343                 NULL,
10344         },
10345 };
10346
10347 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10348         .f = cmd_flow_director_filter_parsed,
10349         .data = NULL,
10350         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10351                 "director entry on NIC",
10352         .tokens = {
10353                 (void *)&cmd_flow_director_filter,
10354                 (void *)&cmd_flow_director_port_id,
10355                 (void *)&cmd_flow_director_mode,
10356                 (void *)&cmd_flow_director_mode_ip,
10357                 (void *)&cmd_flow_director_ops,
10358                 (void *)&cmd_flow_director_flow,
10359                 (void *)&cmd_flow_director_flow_type,
10360                 (void *)&cmd_flow_director_ether,
10361                 (void *)&cmd_flow_director_ether_type,
10362                 (void *)&cmd_flow_director_flexbytes,
10363                 (void *)&cmd_flow_director_flexbytes_value,
10364                 (void *)&cmd_flow_director_drop,
10365                 (void *)&cmd_flow_director_pf_vf,
10366                 (void *)&cmd_flow_director_queue,
10367                 (void *)&cmd_flow_director_queue_id,
10368                 (void *)&cmd_flow_director_fd_id,
10369                 (void *)&cmd_flow_director_fd_id_value,
10370                 NULL,
10371         },
10372 };
10373
10374 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10375         .f = cmd_flow_director_filter_parsed,
10376         .data = NULL,
10377         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10378                 "director entry on NIC",
10379         .tokens = {
10380                 (void *)&cmd_flow_director_filter,
10381                 (void *)&cmd_flow_director_port_id,
10382                 (void *)&cmd_flow_director_mode,
10383                 (void *)&cmd_flow_director_mode_mac_vlan,
10384                 (void *)&cmd_flow_director_ops,
10385                 (void *)&cmd_flow_director_mac,
10386                 (void *)&cmd_flow_director_mac_addr,
10387                 (void *)&cmd_flow_director_vlan,
10388                 (void *)&cmd_flow_director_vlan_value,
10389                 (void *)&cmd_flow_director_flexbytes,
10390                 (void *)&cmd_flow_director_flexbytes_value,
10391                 (void *)&cmd_flow_director_drop,
10392                 (void *)&cmd_flow_director_queue,
10393                 (void *)&cmd_flow_director_queue_id,
10394                 (void *)&cmd_flow_director_fd_id,
10395                 (void *)&cmd_flow_director_fd_id_value,
10396                 NULL,
10397         },
10398 };
10399
10400 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10401         .f = cmd_flow_director_filter_parsed,
10402         .data = NULL,
10403         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10404                 "director entry on NIC",
10405         .tokens = {
10406                 (void *)&cmd_flow_director_filter,
10407                 (void *)&cmd_flow_director_port_id,
10408                 (void *)&cmd_flow_director_mode,
10409                 (void *)&cmd_flow_director_mode_tunnel,
10410                 (void *)&cmd_flow_director_ops,
10411                 (void *)&cmd_flow_director_mac,
10412                 (void *)&cmd_flow_director_mac_addr,
10413                 (void *)&cmd_flow_director_vlan,
10414                 (void *)&cmd_flow_director_vlan_value,
10415                 (void *)&cmd_flow_director_tunnel,
10416                 (void *)&cmd_flow_director_tunnel_type,
10417                 (void *)&cmd_flow_director_tunnel_id,
10418                 (void *)&cmd_flow_director_tunnel_id_value,
10419                 (void *)&cmd_flow_director_flexbytes,
10420                 (void *)&cmd_flow_director_flexbytes_value,
10421                 (void *)&cmd_flow_director_drop,
10422                 (void *)&cmd_flow_director_queue,
10423                 (void *)&cmd_flow_director_queue_id,
10424                 (void *)&cmd_flow_director_fd_id,
10425                 (void *)&cmd_flow_director_fd_id_value,
10426                 NULL,
10427         },
10428 };
10429
10430 struct cmd_flush_flow_director_result {
10431         cmdline_fixed_string_t flush_flow_director;
10432         portid_t port_id;
10433 };
10434
10435 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10437                                  flush_flow_director, "flush_flow_director");
10438 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10439         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10440                               port_id, UINT16);
10441
10442 static void
10443 cmd_flush_flow_director_parsed(void *parsed_result,
10444                           __attribute__((unused)) struct cmdline *cl,
10445                           __attribute__((unused)) void *data)
10446 {
10447         struct cmd_flow_director_result *res = parsed_result;
10448         int ret = 0;
10449
10450         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10451         if (ret < 0) {
10452                 printf("flow director is not supported on port %u.\n",
10453                         res->port_id);
10454                 return;
10455         }
10456
10457         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10458                         RTE_ETH_FILTER_FLUSH, NULL);
10459         if (ret < 0)
10460                 printf("flow director table flushing error: (%s)\n",
10461                         strerror(-ret));
10462 }
10463
10464 cmdline_parse_inst_t cmd_flush_flow_director = {
10465         .f = cmd_flush_flow_director_parsed,
10466         .data = NULL,
10467         .help_str = "flush_flow_director <port_id>: "
10468                 "Flush all flow director entries of a device on NIC",
10469         .tokens = {
10470                 (void *)&cmd_flush_flow_director_flush,
10471                 (void *)&cmd_flush_flow_director_port_id,
10472                 NULL,
10473         },
10474 };
10475
10476 /* *** deal with flow director mask *** */
10477 struct cmd_flow_director_mask_result {
10478         cmdline_fixed_string_t flow_director_mask;
10479         portid_t port_id;
10480         cmdline_fixed_string_t mode;
10481         cmdline_fixed_string_t mode_value;
10482         cmdline_fixed_string_t vlan;
10483         uint16_t vlan_mask;
10484         cmdline_fixed_string_t src_mask;
10485         cmdline_ipaddr_t ipv4_src;
10486         cmdline_ipaddr_t ipv6_src;
10487         uint16_t port_src;
10488         cmdline_fixed_string_t dst_mask;
10489         cmdline_ipaddr_t ipv4_dst;
10490         cmdline_ipaddr_t ipv6_dst;
10491         uint16_t port_dst;
10492         cmdline_fixed_string_t mac;
10493         uint8_t mac_addr_byte_mask;
10494         cmdline_fixed_string_t tunnel_id;
10495         uint32_t tunnel_id_mask;
10496         cmdline_fixed_string_t tunnel_type;
10497         uint8_t tunnel_type_mask;
10498 };
10499
10500 static void
10501 cmd_flow_director_mask_parsed(void *parsed_result,
10502                           __attribute__((unused)) struct cmdline *cl,
10503                           __attribute__((unused)) void *data)
10504 {
10505         struct cmd_flow_director_mask_result *res = parsed_result;
10506         struct rte_eth_fdir_masks *mask;
10507         struct rte_port *port;
10508
10509         if (res->port_id > nb_ports) {
10510                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10511                 return;
10512         }
10513
10514         port = &ports[res->port_id];
10515         /** Check if the port is not started **/
10516         if (port->port_status != RTE_PORT_STOPPED) {
10517                 printf("Please stop port %d first\n", res->port_id);
10518                 return;
10519         }
10520
10521         mask = &port->dev_conf.fdir_conf.mask;
10522
10523         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10524                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10525                         printf("Please set mode to MAC-VLAN.\n");
10526                         return;
10527                 }
10528
10529                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10530         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10531                 if (strcmp(res->mode_value, "Tunnel")) {
10532                         printf("Please set mode to Tunnel.\n");
10533                         return;
10534                 }
10535
10536                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10537                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10538                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10539                 mask->tunnel_type_mask = res->tunnel_type_mask;
10540         } else {
10541                 if (strcmp(res->mode_value, "IP")) {
10542                         printf("Please set mode to IP.\n");
10543                         return;
10544                 }
10545
10546                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10547                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10548                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10549                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10550                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10551                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10552                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10553         }
10554
10555         cmd_reconfig_device_queue(res->port_id, 1, 1);
10556 }
10557
10558 cmdline_parse_token_string_t cmd_flow_director_mask =
10559         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10560                                  flow_director_mask, "flow_director_mask");
10561 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10562         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10563                               port_id, UINT16);
10564 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10565         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10566                                  vlan, "vlan");
10567 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10568         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10569                               vlan_mask, UINT16);
10570 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10571         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10572                                  src_mask, "src_mask");
10573 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10574         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10575                                  ipv4_src);
10576 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10577         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10578                                  ipv6_src);
10579 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10580         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10581                               port_src, UINT16);
10582 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10583         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10584                                  dst_mask, "dst_mask");
10585 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10586         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10587                                  ipv4_dst);
10588 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10589         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10590                                  ipv6_dst);
10591 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10592         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10593                               port_dst, UINT16);
10594
10595 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10597                                  mode, "mode");
10598 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10600                                  mode_value, "IP");
10601 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10603                                  mode_value, "MAC-VLAN");
10604 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10606                                  mode_value, "Tunnel");
10607 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10608         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10609                                  mac, "mac");
10610 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10611         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10612                               mac_addr_byte_mask, UINT8);
10613 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10614         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10615                                  tunnel_type, "tunnel-type");
10616 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10617         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10618                               tunnel_type_mask, UINT8);
10619 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10620         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10621                                  tunnel_id, "tunnel-id");
10622 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10623         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10624                               tunnel_id_mask, UINT32);
10625
10626 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10627         .f = cmd_flow_director_mask_parsed,
10628         .data = NULL,
10629         .help_str = "flow_director_mask ... : "
10630                 "Set IP mode flow director's mask on NIC",
10631         .tokens = {
10632                 (void *)&cmd_flow_director_mask,
10633                 (void *)&cmd_flow_director_mask_port_id,
10634                 (void *)&cmd_flow_director_mask_mode,
10635                 (void *)&cmd_flow_director_mask_mode_ip,
10636                 (void *)&cmd_flow_director_mask_vlan,
10637                 (void *)&cmd_flow_director_mask_vlan_value,
10638                 (void *)&cmd_flow_director_mask_src,
10639                 (void *)&cmd_flow_director_mask_ipv4_src,
10640                 (void *)&cmd_flow_director_mask_ipv6_src,
10641                 (void *)&cmd_flow_director_mask_port_src,
10642                 (void *)&cmd_flow_director_mask_dst,
10643                 (void *)&cmd_flow_director_mask_ipv4_dst,
10644                 (void *)&cmd_flow_director_mask_ipv6_dst,
10645                 (void *)&cmd_flow_director_mask_port_dst,
10646                 NULL,
10647         },
10648 };
10649
10650 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10651         .f = cmd_flow_director_mask_parsed,
10652         .data = NULL,
10653         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10654                 "flow director's mask on NIC",
10655         .tokens = {
10656                 (void *)&cmd_flow_director_mask,
10657                 (void *)&cmd_flow_director_mask_port_id,
10658                 (void *)&cmd_flow_director_mask_mode,
10659                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10660                 (void *)&cmd_flow_director_mask_vlan,
10661                 (void *)&cmd_flow_director_mask_vlan_value,
10662                 NULL,
10663         },
10664 };
10665
10666 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10667         .f = cmd_flow_director_mask_parsed,
10668         .data = NULL,
10669         .help_str = "flow_director_mask ... : Set tunnel mode "
10670                 "flow director's mask on NIC",
10671         .tokens = {
10672                 (void *)&cmd_flow_director_mask,
10673                 (void *)&cmd_flow_director_mask_port_id,
10674                 (void *)&cmd_flow_director_mask_mode,
10675                 (void *)&cmd_flow_director_mask_mode_tunnel,
10676                 (void *)&cmd_flow_director_mask_vlan,
10677                 (void *)&cmd_flow_director_mask_vlan_value,
10678                 (void *)&cmd_flow_director_mask_mac,
10679                 (void *)&cmd_flow_director_mask_mac_value,
10680                 (void *)&cmd_flow_director_mask_tunnel_type,
10681                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10682                 (void *)&cmd_flow_director_mask_tunnel_id,
10683                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10684                 NULL,
10685         },
10686 };
10687
10688 /* *** deal with flow director mask on flexible payload *** */
10689 struct cmd_flow_director_flex_mask_result {
10690         cmdline_fixed_string_t flow_director_flexmask;
10691         portid_t port_id;
10692         cmdline_fixed_string_t flow;
10693         cmdline_fixed_string_t flow_type;
10694         cmdline_fixed_string_t mask;
10695 };
10696
10697 static void
10698 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10699                           __attribute__((unused)) struct cmdline *cl,
10700                           __attribute__((unused)) void *data)
10701 {
10702         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10703         struct rte_eth_fdir_info fdir_info;
10704         struct rte_eth_fdir_flex_mask flex_mask;
10705         struct rte_port *port;
10706         uint32_t flow_type_mask;
10707         uint16_t i;
10708         int ret;
10709
10710         if (res->port_id > nb_ports) {
10711                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10712                 return;
10713         }
10714
10715         port = &ports[res->port_id];
10716         /** Check if the port is not started **/
10717         if (port->port_status != RTE_PORT_STOPPED) {
10718                 printf("Please stop port %d first\n", res->port_id);
10719                 return;
10720         }
10721
10722         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10723         ret = parse_flexbytes(res->mask,
10724                         flex_mask.mask,
10725                         RTE_ETH_FDIR_MAX_FLEXLEN);
10726         if (ret < 0) {
10727                 printf("error: Cannot parse mask input.\n");
10728                 return;
10729         }
10730
10731         memset(&fdir_info, 0, sizeof(fdir_info));
10732         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10733                                 RTE_ETH_FILTER_INFO, &fdir_info);
10734         if (ret < 0) {
10735                 printf("Cannot get FDir filter info\n");
10736                 return;
10737         }
10738
10739         if (!strcmp(res->flow_type, "none")) {
10740                 /* means don't specify the flow type */
10741                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10742                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10743                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10744                                0, sizeof(struct rte_eth_fdir_flex_mask));
10745                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10746                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10747                                  &flex_mask,
10748                                  sizeof(struct rte_eth_fdir_flex_mask));
10749                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10750                 return;
10751         }
10752         flow_type_mask = fdir_info.flow_types_mask[0];
10753         if (!strcmp(res->flow_type, "all")) {
10754                 if (!flow_type_mask) {
10755                         printf("No flow type supported\n");
10756                         return;
10757                 }
10758                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10759                         if (flow_type_mask & (1 << i)) {
10760                                 flex_mask.flow_type = i;
10761                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10762                         }
10763                 }
10764                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10765                 return;
10766         }
10767         flex_mask.flow_type = str2flowtype(res->flow_type);
10768         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10769                 printf("Flow type %s not supported on port %d\n",
10770                                 res->flow_type, res->port_id);
10771                 return;
10772         }
10773         fdir_set_flex_mask(res->port_id, &flex_mask);
10774         cmd_reconfig_device_queue(res->port_id, 1, 1);
10775 }
10776
10777 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10779                                  flow_director_flexmask,
10780                                  "flow_director_flex_mask");
10781 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10782         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10783                               port_id, UINT16);
10784 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10785         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10786                                  flow, "flow");
10787 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10788         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10789                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10790                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10791 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10793                                  mask, NULL);
10794
10795 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10796         .f = cmd_flow_director_flex_mask_parsed,
10797         .data = NULL,
10798         .help_str = "flow_director_flex_mask ... : "
10799                 "Set flow director's flex mask on NIC",
10800         .tokens = {
10801                 (void *)&cmd_flow_director_flexmask,
10802                 (void *)&cmd_flow_director_flexmask_port_id,
10803                 (void *)&cmd_flow_director_flexmask_flow,
10804                 (void *)&cmd_flow_director_flexmask_flow_type,
10805                 (void *)&cmd_flow_director_flexmask_mask,
10806                 NULL,
10807         },
10808 };
10809
10810 /* *** deal with flow director flexible payload configuration *** */
10811 struct cmd_flow_director_flexpayload_result {
10812         cmdline_fixed_string_t flow_director_flexpayload;
10813         portid_t port_id;
10814         cmdline_fixed_string_t payload_layer;
10815         cmdline_fixed_string_t payload_cfg;
10816 };
10817
10818 static inline int
10819 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10820 {
10821         char s[256];
10822         const char *p, *p0 = q_arg;
10823         char *end;
10824         unsigned long int_fld;
10825         char *str_fld[max_num];
10826         int i;
10827         unsigned size;
10828         int ret = -1;
10829
10830         p = strchr(p0, '(');
10831         if (p == NULL)
10832                 return -1;
10833         ++p;
10834         p0 = strchr(p, ')');
10835         if (p0 == NULL)
10836                 return -1;
10837
10838         size = p0 - p;
10839         if (size >= sizeof(s))
10840                 return -1;
10841
10842         snprintf(s, sizeof(s), "%.*s", size, p);
10843         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10844         if (ret < 0 || ret > max_num)
10845                 return -1;
10846         for (i = 0; i < ret; i++) {
10847                 errno = 0;
10848                 int_fld = strtoul(str_fld[i], &end, 0);
10849                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10850                         return -1;
10851                 offsets[i] = (uint16_t)int_fld;
10852         }
10853         return ret;
10854 }
10855
10856 static void
10857 cmd_flow_director_flxpld_parsed(void *parsed_result,
10858                           __attribute__((unused)) struct cmdline *cl,
10859                           __attribute__((unused)) void *data)
10860 {
10861         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10862         struct rte_eth_flex_payload_cfg flex_cfg;
10863         struct rte_port *port;
10864         int ret = 0;
10865
10866         if (res->port_id > nb_ports) {
10867                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10868                 return;
10869         }
10870
10871         port = &ports[res->port_id];
10872         /** Check if the port is not started **/
10873         if (port->port_status != RTE_PORT_STOPPED) {
10874                 printf("Please stop port %d first\n", res->port_id);
10875                 return;
10876         }
10877
10878         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10879
10880         if (!strcmp(res->payload_layer, "raw"))
10881                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10882         else if (!strcmp(res->payload_layer, "l2"))
10883                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10884         else if (!strcmp(res->payload_layer, "l3"))
10885                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10886         else if (!strcmp(res->payload_layer, "l4"))
10887                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10888
10889         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10890                             RTE_ETH_FDIR_MAX_FLEXLEN);
10891         if (ret < 0) {
10892                 printf("error: Cannot parse flex payload input.\n");
10893                 return;
10894         }
10895
10896         fdir_set_flex_payload(res->port_id, &flex_cfg);
10897         cmd_reconfig_device_queue(res->port_id, 1, 1);
10898 }
10899
10900 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10902                                  flow_director_flexpayload,
10903                                  "flow_director_flex_payload");
10904 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10905         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10906                               port_id, UINT16);
10907 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10909                                  payload_layer, "raw#l2#l3#l4");
10910 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10911         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10912                                  payload_cfg, NULL);
10913
10914 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10915         .f = cmd_flow_director_flxpld_parsed,
10916         .data = NULL,
10917         .help_str = "flow_director_flexpayload ... : "
10918                 "Set flow director's flex payload on NIC",
10919         .tokens = {
10920                 (void *)&cmd_flow_director_flexpayload,
10921                 (void *)&cmd_flow_director_flexpayload_port_id,
10922                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10923                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10924                 NULL,
10925         },
10926 };
10927
10928 /* Generic flow interface command. */
10929 extern cmdline_parse_inst_t cmd_flow;
10930
10931 /* *** Classification Filters Control *** */
10932 /* *** Get symmetric hash enable per port *** */
10933 struct cmd_get_sym_hash_ena_per_port_result {
10934         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10935         portid_t port_id;
10936 };
10937
10938 static void
10939 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10940                                  __rte_unused struct cmdline *cl,
10941                                  __rte_unused void *data)
10942 {
10943         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10944         struct rte_eth_hash_filter_info info;
10945         int ret;
10946
10947         if (rte_eth_dev_filter_supported(res->port_id,
10948                                 RTE_ETH_FILTER_HASH) < 0) {
10949                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10950                                                         res->port_id);
10951                 return;
10952         }
10953
10954         memset(&info, 0, sizeof(info));
10955         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10956         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10957                                                 RTE_ETH_FILTER_GET, &info);
10958
10959         if (ret < 0) {
10960                 printf("Cannot get symmetric hash enable per port "
10961                                         "on port %u\n", res->port_id);
10962                 return;
10963         }
10964
10965         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10966                                 "enabled" : "disabled", res->port_id);
10967 }
10968
10969 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10970         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10971                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10972 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10973         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10974                 port_id, UINT16);
10975
10976 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10977         .f = cmd_get_sym_hash_per_port_parsed,
10978         .data = NULL,
10979         .help_str = "get_sym_hash_ena_per_port <port_id>",
10980         .tokens = {
10981                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10982                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10983                 NULL,
10984         },
10985 };
10986
10987 /* *** Set symmetric hash enable per port *** */
10988 struct cmd_set_sym_hash_ena_per_port_result {
10989         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10990         cmdline_fixed_string_t enable;
10991         portid_t port_id;
10992 };
10993
10994 static void
10995 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10996                                  __rte_unused struct cmdline *cl,
10997                                  __rte_unused void *data)
10998 {
10999         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11000         struct rte_eth_hash_filter_info info;
11001         int ret;
11002
11003         if (rte_eth_dev_filter_supported(res->port_id,
11004                                 RTE_ETH_FILTER_HASH) < 0) {
11005                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11006                                                         res->port_id);
11007                 return;
11008         }
11009
11010         memset(&info, 0, sizeof(info));
11011         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11012         if (!strcmp(res->enable, "enable"))
11013                 info.info.enable = 1;
11014         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11015                                         RTE_ETH_FILTER_SET, &info);
11016         if (ret < 0) {
11017                 printf("Cannot set symmetric hash enable per port on "
11018                                         "port %u\n", res->port_id);
11019                 return;
11020         }
11021         printf("Symmetric hash has been set to %s on port %u\n",
11022                                         res->enable, res->port_id);
11023 }
11024
11025 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11026         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11027                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11028 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11029         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11030                 port_id, UINT16);
11031 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11032         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11033                 enable, "enable#disable");
11034
11035 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11036         .f = cmd_set_sym_hash_per_port_parsed,
11037         .data = NULL,
11038         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11039         .tokens = {
11040                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11041                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11042                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11043                 NULL,
11044         },
11045 };
11046
11047 /* Get global config of hash function */
11048 struct cmd_get_hash_global_config_result {
11049         cmdline_fixed_string_t get_hash_global_config;
11050         portid_t port_id;
11051 };
11052
11053 static char *
11054 flowtype_to_str(uint16_t ftype)
11055 {
11056         uint16_t i;
11057         static struct {
11058                 char str[16];
11059                 uint16_t ftype;
11060         } ftype_table[] = {
11061                 {"ipv4", RTE_ETH_FLOW_IPV4},
11062                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11063                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11064                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11065                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11066                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11067                 {"ipv6", RTE_ETH_FLOW_IPV6},
11068                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11069                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11070                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11071                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11072                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11073                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11074                 {"port", RTE_ETH_FLOW_PORT},
11075                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11076                 {"geneve", RTE_ETH_FLOW_GENEVE},
11077                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11078         };
11079
11080         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11081                 if (ftype_table[i].ftype == ftype)
11082                         return ftype_table[i].str;
11083         }
11084
11085         return NULL;
11086 }
11087
11088 static void
11089 cmd_get_hash_global_config_parsed(void *parsed_result,
11090                                   __rte_unused struct cmdline *cl,
11091                                   __rte_unused void *data)
11092 {
11093         struct cmd_get_hash_global_config_result *res = parsed_result;
11094         struct rte_eth_hash_filter_info info;
11095         uint32_t idx, offset;
11096         uint16_t i;
11097         char *str;
11098         int ret;
11099
11100         if (rte_eth_dev_filter_supported(res->port_id,
11101                         RTE_ETH_FILTER_HASH) < 0) {
11102                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11103                                                         res->port_id);
11104                 return;
11105         }
11106
11107         memset(&info, 0, sizeof(info));
11108         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11109         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11110                                         RTE_ETH_FILTER_GET, &info);
11111         if (ret < 0) {
11112                 printf("Cannot get hash global configurations by port %d\n",
11113                                                         res->port_id);
11114                 return;
11115         }
11116
11117         switch (info.info.global_conf.hash_func) {
11118         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11119                 printf("Hash function is Toeplitz\n");
11120                 break;
11121         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11122                 printf("Hash function is Simple XOR\n");
11123                 break;
11124         default:
11125                 printf("Unknown hash function\n");
11126                 break;
11127         }
11128
11129         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11130                 idx = i / UINT32_BIT;
11131                 offset = i % UINT32_BIT;
11132                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11133                                                 (1UL << offset)))
11134                         continue;
11135                 str = flowtype_to_str(i);
11136                 if (!str)
11137                         continue;
11138                 printf("Symmetric hash is %s globally for flow type %s "
11139                                                         "by port %d\n",
11140                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11141                         (1UL << offset)) ? "enabled" : "disabled"), str,
11142                                                         res->port_id);
11143         }
11144 }
11145
11146 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11147         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11148                 get_hash_global_config, "get_hash_global_config");
11149 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11150         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11151                 port_id, UINT16);
11152
11153 cmdline_parse_inst_t cmd_get_hash_global_config = {
11154         .f = cmd_get_hash_global_config_parsed,
11155         .data = NULL,
11156         .help_str = "get_hash_global_config <port_id>",
11157         .tokens = {
11158                 (void *)&cmd_get_hash_global_config_all,
11159                 (void *)&cmd_get_hash_global_config_port_id,
11160                 NULL,
11161         },
11162 };
11163
11164 /* Set global config of hash function */
11165 struct cmd_set_hash_global_config_result {
11166         cmdline_fixed_string_t set_hash_global_config;
11167         portid_t port_id;
11168         cmdline_fixed_string_t hash_func;
11169         cmdline_fixed_string_t flow_type;
11170         cmdline_fixed_string_t enable;
11171 };
11172
11173 static void
11174 cmd_set_hash_global_config_parsed(void *parsed_result,
11175                                   __rte_unused struct cmdline *cl,
11176                                   __rte_unused void *data)
11177 {
11178         struct cmd_set_hash_global_config_result *res = parsed_result;
11179         struct rte_eth_hash_filter_info info;
11180         uint32_t ftype, idx, offset;
11181         int ret;
11182
11183         if (rte_eth_dev_filter_supported(res->port_id,
11184                                 RTE_ETH_FILTER_HASH) < 0) {
11185                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11186                                                         res->port_id);
11187                 return;
11188         }
11189         memset(&info, 0, sizeof(info));
11190         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11191         if (!strcmp(res->hash_func, "toeplitz"))
11192                 info.info.global_conf.hash_func =
11193                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11194         else if (!strcmp(res->hash_func, "simple_xor"))
11195                 info.info.global_conf.hash_func =
11196                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11197         else if (!strcmp(res->hash_func, "default"))
11198                 info.info.global_conf.hash_func =
11199                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11200
11201         ftype = str2flowtype(res->flow_type);
11202         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11203         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11204         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11205         if (!strcmp(res->enable, "enable"))
11206                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11207                                                 (1UL << offset);
11208         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11209                                         RTE_ETH_FILTER_SET, &info);
11210         if (ret < 0)
11211                 printf("Cannot set global hash configurations by port %d\n",
11212                                                         res->port_id);
11213         else
11214                 printf("Global hash configurations have been set "
11215                         "succcessfully by port %d\n", res->port_id);
11216 }
11217
11218 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11219         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11220                 set_hash_global_config, "set_hash_global_config");
11221 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11222         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11223                 port_id, UINT16);
11224 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11225         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11226                 hash_func, "toeplitz#simple_xor#default");
11227 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11228         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11229                 flow_type,
11230                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11231                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11232 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11233         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11234                 enable, "enable#disable");
11235
11236 cmdline_parse_inst_t cmd_set_hash_global_config = {
11237         .f = cmd_set_hash_global_config_parsed,
11238         .data = NULL,
11239         .help_str = "set_hash_global_config <port_id> "
11240                 "toeplitz|simple_xor|default "
11241                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11242                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11243                 "l2_payload enable|disable",
11244         .tokens = {
11245                 (void *)&cmd_set_hash_global_config_all,
11246                 (void *)&cmd_set_hash_global_config_port_id,
11247                 (void *)&cmd_set_hash_global_config_hash_func,
11248                 (void *)&cmd_set_hash_global_config_flow_type,
11249                 (void *)&cmd_set_hash_global_config_enable,
11250                 NULL,
11251         },
11252 };
11253
11254 /* Set hash input set */
11255 struct cmd_set_hash_input_set_result {
11256         cmdline_fixed_string_t set_hash_input_set;
11257         portid_t port_id;
11258         cmdline_fixed_string_t flow_type;
11259         cmdline_fixed_string_t inset_field;
11260         cmdline_fixed_string_t select;
11261 };
11262
11263 static enum rte_eth_input_set_field
11264 str2inset(char *string)
11265 {
11266         uint16_t i;
11267
11268         static const struct {
11269                 char str[32];
11270                 enum rte_eth_input_set_field inset;
11271         } inset_table[] = {
11272                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11273                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11274                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11275                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11276                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11277                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11278                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11279                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11280                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11281                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11282                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11283                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11284                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11285                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11286                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11287                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11288                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11289                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11290                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11291                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11292                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11293                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11294                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11295                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11296                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11297                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11298                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11299                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11300                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11301                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11302                 {"none", RTE_ETH_INPUT_SET_NONE},
11303         };
11304
11305         for (i = 0; i < RTE_DIM(inset_table); i++) {
11306                 if (!strcmp(string, inset_table[i].str))
11307                         return inset_table[i].inset;
11308         }
11309
11310         return RTE_ETH_INPUT_SET_UNKNOWN;
11311 }
11312
11313 static void
11314 cmd_set_hash_input_set_parsed(void *parsed_result,
11315                               __rte_unused struct cmdline *cl,
11316                               __rte_unused void *data)
11317 {
11318         struct cmd_set_hash_input_set_result *res = parsed_result;
11319         struct rte_eth_hash_filter_info info;
11320
11321         memset(&info, 0, sizeof(info));
11322         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11323         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11324         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11325         info.info.input_set_conf.inset_size = 1;
11326         if (!strcmp(res->select, "select"))
11327                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11328         else if (!strcmp(res->select, "add"))
11329                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11330         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11331                                 RTE_ETH_FILTER_SET, &info);
11332 }
11333
11334 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11335         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11336                 set_hash_input_set, "set_hash_input_set");
11337 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11338         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11339                 port_id, UINT16);
11340 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11341         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11342                 flow_type, NULL);
11343 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11344         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11345                 inset_field,
11346                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11347                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11348                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11349                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11350                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11351                 "fld-8th#none");
11352 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11353         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11354                 select, "select#add");
11355
11356 cmdline_parse_inst_t cmd_set_hash_input_set = {
11357         .f = cmd_set_hash_input_set_parsed,
11358         .data = NULL,
11359         .help_str = "set_hash_input_set <port_id> "
11360         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11361         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11362         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11363         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11364         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11365         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11366         "fld-7th|fld-8th|none select|add",
11367         .tokens = {
11368                 (void *)&cmd_set_hash_input_set_cmd,
11369                 (void *)&cmd_set_hash_input_set_port_id,
11370                 (void *)&cmd_set_hash_input_set_flow_type,
11371                 (void *)&cmd_set_hash_input_set_field,
11372                 (void *)&cmd_set_hash_input_set_select,
11373                 NULL,
11374         },
11375 };
11376
11377 /* Set flow director input set */
11378 struct cmd_set_fdir_input_set_result {
11379         cmdline_fixed_string_t set_fdir_input_set;
11380         portid_t port_id;
11381         cmdline_fixed_string_t flow_type;
11382         cmdline_fixed_string_t inset_field;
11383         cmdline_fixed_string_t select;
11384 };
11385
11386 static void
11387 cmd_set_fdir_input_set_parsed(void *parsed_result,
11388         __rte_unused struct cmdline *cl,
11389         __rte_unused void *data)
11390 {
11391         struct cmd_set_fdir_input_set_result *res = parsed_result;
11392         struct rte_eth_fdir_filter_info info;
11393
11394         memset(&info, 0, sizeof(info));
11395         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11396         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11397         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11398         info.info.input_set_conf.inset_size = 1;
11399         if (!strcmp(res->select, "select"))
11400                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11401         else if (!strcmp(res->select, "add"))
11402                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11403         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11404                 RTE_ETH_FILTER_SET, &info);
11405 }
11406
11407 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11408         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11409         set_fdir_input_set, "set_fdir_input_set");
11410 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11411         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11412         port_id, UINT16);
11413 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11414         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11415         flow_type,
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 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11419         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11420         inset_field,
11421         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11422         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11423         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11424         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11425         "sctp-veri-tag#none");
11426 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11427         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11428         select, "select#add");
11429
11430 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11431         .f = cmd_set_fdir_input_set_parsed,
11432         .data = NULL,
11433         .help_str = "set_fdir_input_set <port_id> "
11434         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11435         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11436         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11437         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11438         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11439         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11440         "sctp-veri-tag|none select|add",
11441         .tokens = {
11442                 (void *)&cmd_set_fdir_input_set_cmd,
11443                 (void *)&cmd_set_fdir_input_set_port_id,
11444                 (void *)&cmd_set_fdir_input_set_flow_type,
11445                 (void *)&cmd_set_fdir_input_set_field,
11446                 (void *)&cmd_set_fdir_input_set_select,
11447                 NULL,
11448         },
11449 };
11450
11451 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11452 struct cmd_mcast_addr_result {
11453         cmdline_fixed_string_t mcast_addr_cmd;
11454         cmdline_fixed_string_t what;
11455         uint16_t port_num;
11456         struct ether_addr mc_addr;
11457 };
11458
11459 static void cmd_mcast_addr_parsed(void *parsed_result,
11460                 __attribute__((unused)) struct cmdline *cl,
11461                 __attribute__((unused)) void *data)
11462 {
11463         struct cmd_mcast_addr_result *res = parsed_result;
11464
11465         if (!is_multicast_ether_addr(&res->mc_addr)) {
11466                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11467                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11468                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11469                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11470                 return;
11471         }
11472         if (strcmp(res->what, "add") == 0)
11473                 mcast_addr_add(res->port_num, &res->mc_addr);
11474         else
11475                 mcast_addr_remove(res->port_num, &res->mc_addr);
11476 }
11477
11478 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11479         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11480                                  mcast_addr_cmd, "mcast_addr");
11481 cmdline_parse_token_string_t cmd_mcast_addr_what =
11482         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11483                                  "add#remove");
11484 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11485         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11486 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11487         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11488
11489 cmdline_parse_inst_t cmd_mcast_addr = {
11490         .f = cmd_mcast_addr_parsed,
11491         .data = (void *)0,
11492         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11493                 "Add/Remove multicast MAC address on port_id",
11494         .tokens = {
11495                 (void *)&cmd_mcast_addr_cmd,
11496                 (void *)&cmd_mcast_addr_what,
11497                 (void *)&cmd_mcast_addr_portnum,
11498                 (void *)&cmd_mcast_addr_addr,
11499                 NULL,
11500         },
11501 };
11502
11503 /* l2 tunnel config
11504  * only support E-tag now.
11505  */
11506
11507 /* Ether type config */
11508 struct cmd_config_l2_tunnel_eth_type_result {
11509         cmdline_fixed_string_t port;
11510         cmdline_fixed_string_t config;
11511         cmdline_fixed_string_t all;
11512         uint8_t id;
11513         cmdline_fixed_string_t l2_tunnel;
11514         cmdline_fixed_string_t l2_tunnel_type;
11515         cmdline_fixed_string_t eth_type;
11516         uint16_t eth_type_val;
11517 };
11518
11519 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11520         TOKEN_STRING_INITIALIZER
11521                 (struct cmd_config_l2_tunnel_eth_type_result,
11522                  port, "port");
11523 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11524         TOKEN_STRING_INITIALIZER
11525                 (struct cmd_config_l2_tunnel_eth_type_result,
11526                  config, "config");
11527 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11528         TOKEN_STRING_INITIALIZER
11529                 (struct cmd_config_l2_tunnel_eth_type_result,
11530                  all, "all");
11531 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11532         TOKEN_NUM_INITIALIZER
11533                 (struct cmd_config_l2_tunnel_eth_type_result,
11534                  id, UINT8);
11535 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11536         TOKEN_STRING_INITIALIZER
11537                 (struct cmd_config_l2_tunnel_eth_type_result,
11538                  l2_tunnel, "l2-tunnel");
11539 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11540         TOKEN_STRING_INITIALIZER
11541                 (struct cmd_config_l2_tunnel_eth_type_result,
11542                  l2_tunnel_type, "E-tag");
11543 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11544         TOKEN_STRING_INITIALIZER
11545                 (struct cmd_config_l2_tunnel_eth_type_result,
11546                  eth_type, "ether-type");
11547 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11548         TOKEN_NUM_INITIALIZER
11549                 (struct cmd_config_l2_tunnel_eth_type_result,
11550                  eth_type_val, UINT16);
11551
11552 static enum rte_eth_tunnel_type
11553 str2fdir_l2_tunnel_type(char *string)
11554 {
11555         uint32_t i = 0;
11556
11557         static const struct {
11558                 char str[32];
11559                 enum rte_eth_tunnel_type type;
11560         } l2_tunnel_type_str[] = {
11561                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11562         };
11563
11564         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11565                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11566                         return l2_tunnel_type_str[i].type;
11567         }
11568         return RTE_TUNNEL_TYPE_NONE;
11569 }
11570
11571 /* ether type config for all ports */
11572 static void
11573 cmd_config_l2_tunnel_eth_type_all_parsed
11574         (void *parsed_result,
11575          __attribute__((unused)) struct cmdline *cl,
11576          __attribute__((unused)) void *data)
11577 {
11578         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11579         struct rte_eth_l2_tunnel_conf entry;
11580         portid_t pid;
11581
11582         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11583         entry.ether_type = res->eth_type_val;
11584
11585         RTE_ETH_FOREACH_DEV(pid) {
11586                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11587         }
11588 }
11589
11590 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11591         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11592         .data = NULL,
11593         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11594         .tokens = {
11595                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11596                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11597                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11598                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11599                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11600                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11601                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11602                 NULL,
11603         },
11604 };
11605
11606 /* ether type config for a specific port */
11607 static void
11608 cmd_config_l2_tunnel_eth_type_specific_parsed(
11609         void *parsed_result,
11610         __attribute__((unused)) struct cmdline *cl,
11611         __attribute__((unused)) void *data)
11612 {
11613         struct cmd_config_l2_tunnel_eth_type_result *res =
11614                  parsed_result;
11615         struct rte_eth_l2_tunnel_conf entry;
11616
11617         if (port_id_is_invalid(res->id, ENABLED_WARN))
11618                 return;
11619
11620         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11621         entry.ether_type = res->eth_type_val;
11622
11623         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11624 }
11625
11626 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11627         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11628         .data = NULL,
11629         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11630         .tokens = {
11631                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11632                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11633                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11634                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11635                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11636                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11637                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11638                 NULL,
11639         },
11640 };
11641
11642 /* Enable/disable l2 tunnel */
11643 struct cmd_config_l2_tunnel_en_dis_result {
11644         cmdline_fixed_string_t port;
11645         cmdline_fixed_string_t config;
11646         cmdline_fixed_string_t all;
11647         uint8_t id;
11648         cmdline_fixed_string_t l2_tunnel;
11649         cmdline_fixed_string_t l2_tunnel_type;
11650         cmdline_fixed_string_t en_dis;
11651 };
11652
11653 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11654         TOKEN_STRING_INITIALIZER
11655                 (struct cmd_config_l2_tunnel_en_dis_result,
11656                  port, "port");
11657 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11658         TOKEN_STRING_INITIALIZER
11659                 (struct cmd_config_l2_tunnel_en_dis_result,
11660                  config, "config");
11661 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11662         TOKEN_STRING_INITIALIZER
11663                 (struct cmd_config_l2_tunnel_en_dis_result,
11664                  all, "all");
11665 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11666         TOKEN_NUM_INITIALIZER
11667                 (struct cmd_config_l2_tunnel_en_dis_result,
11668                  id, UINT8);
11669 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11670         TOKEN_STRING_INITIALIZER
11671                 (struct cmd_config_l2_tunnel_en_dis_result,
11672                  l2_tunnel, "l2-tunnel");
11673 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11674         TOKEN_STRING_INITIALIZER
11675                 (struct cmd_config_l2_tunnel_en_dis_result,
11676                  l2_tunnel_type, "E-tag");
11677 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11678         TOKEN_STRING_INITIALIZER
11679                 (struct cmd_config_l2_tunnel_en_dis_result,
11680                  en_dis, "enable#disable");
11681
11682 /* enable/disable l2 tunnel for all ports */
11683 static void
11684 cmd_config_l2_tunnel_en_dis_all_parsed(
11685         void *parsed_result,
11686         __attribute__((unused)) struct cmdline *cl,
11687         __attribute__((unused)) void *data)
11688 {
11689         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11690         struct rte_eth_l2_tunnel_conf entry;
11691         portid_t pid;
11692         uint8_t en;
11693
11694         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11695
11696         if (!strcmp("enable", res->en_dis))
11697                 en = 1;
11698         else
11699                 en = 0;
11700
11701         RTE_ETH_FOREACH_DEV(pid) {
11702                 rte_eth_dev_l2_tunnel_offload_set(pid,
11703                                                   &entry,
11704                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11705                                                   en);
11706         }
11707 }
11708
11709 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11710         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11711         .data = NULL,
11712         .help_str = "port config all l2-tunnel E-tag enable|disable",
11713         .tokens = {
11714                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11715                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11716                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11717                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11718                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11719                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11720                 NULL,
11721         },
11722 };
11723
11724 /* enable/disable l2 tunnel for a port */
11725 static void
11726 cmd_config_l2_tunnel_en_dis_specific_parsed(
11727         void *parsed_result,
11728         __attribute__((unused)) struct cmdline *cl,
11729         __attribute__((unused)) void *data)
11730 {
11731         struct cmd_config_l2_tunnel_en_dis_result *res =
11732                 parsed_result;
11733         struct rte_eth_l2_tunnel_conf entry;
11734
11735         if (port_id_is_invalid(res->id, ENABLED_WARN))
11736                 return;
11737
11738         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11739
11740         if (!strcmp("enable", res->en_dis))
11741                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11742                                                   &entry,
11743                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11744                                                   1);
11745         else
11746                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11747                                                   &entry,
11748                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11749                                                   0);
11750 }
11751
11752 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11753         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11754         .data = NULL,
11755         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11756         .tokens = {
11757                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11758                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11759                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11760                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11761                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11762                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11763                 NULL,
11764         },
11765 };
11766
11767 /* E-tag configuration */
11768
11769 /* Common result structure for all E-tag configuration */
11770 struct cmd_config_e_tag_result {
11771         cmdline_fixed_string_t e_tag;
11772         cmdline_fixed_string_t set;
11773         cmdline_fixed_string_t insertion;
11774         cmdline_fixed_string_t stripping;
11775         cmdline_fixed_string_t forwarding;
11776         cmdline_fixed_string_t filter;
11777         cmdline_fixed_string_t add;
11778         cmdline_fixed_string_t del;
11779         cmdline_fixed_string_t on;
11780         cmdline_fixed_string_t off;
11781         cmdline_fixed_string_t on_off;
11782         cmdline_fixed_string_t port_tag_id;
11783         uint32_t port_tag_id_val;
11784         cmdline_fixed_string_t e_tag_id;
11785         uint16_t e_tag_id_val;
11786         cmdline_fixed_string_t dst_pool;
11787         uint8_t dst_pool_val;
11788         cmdline_fixed_string_t port;
11789         portid_t port_id;
11790         cmdline_fixed_string_t vf;
11791         uint8_t vf_id;
11792 };
11793
11794 /* Common CLI fields for all E-tag configuration */
11795 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11796         TOKEN_STRING_INITIALIZER
11797                 (struct cmd_config_e_tag_result,
11798                  e_tag, "E-tag");
11799 cmdline_parse_token_string_t cmd_config_e_tag_set =
11800         TOKEN_STRING_INITIALIZER
11801                 (struct cmd_config_e_tag_result,
11802                  set, "set");
11803 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11804         TOKEN_STRING_INITIALIZER
11805                 (struct cmd_config_e_tag_result,
11806                  insertion, "insertion");
11807 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11808         TOKEN_STRING_INITIALIZER
11809                 (struct cmd_config_e_tag_result,
11810                  stripping, "stripping");
11811 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11812         TOKEN_STRING_INITIALIZER
11813                 (struct cmd_config_e_tag_result,
11814                  forwarding, "forwarding");
11815 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11816         TOKEN_STRING_INITIALIZER
11817                 (struct cmd_config_e_tag_result,
11818                  filter, "filter");
11819 cmdline_parse_token_string_t cmd_config_e_tag_add =
11820         TOKEN_STRING_INITIALIZER
11821                 (struct cmd_config_e_tag_result,
11822                  add, "add");
11823 cmdline_parse_token_string_t cmd_config_e_tag_del =
11824         TOKEN_STRING_INITIALIZER
11825                 (struct cmd_config_e_tag_result,
11826                  del, "del");
11827 cmdline_parse_token_string_t cmd_config_e_tag_on =
11828         TOKEN_STRING_INITIALIZER
11829                 (struct cmd_config_e_tag_result,
11830                  on, "on");
11831 cmdline_parse_token_string_t cmd_config_e_tag_off =
11832         TOKEN_STRING_INITIALIZER
11833                 (struct cmd_config_e_tag_result,
11834                  off, "off");
11835 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11836         TOKEN_STRING_INITIALIZER
11837                 (struct cmd_config_e_tag_result,
11838                  on_off, "on#off");
11839 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11840         TOKEN_STRING_INITIALIZER
11841                 (struct cmd_config_e_tag_result,
11842                  port_tag_id, "port-tag-id");
11843 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11844         TOKEN_NUM_INITIALIZER
11845                 (struct cmd_config_e_tag_result,
11846                  port_tag_id_val, UINT32);
11847 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11848         TOKEN_STRING_INITIALIZER
11849                 (struct cmd_config_e_tag_result,
11850                  e_tag_id, "e-tag-id");
11851 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11852         TOKEN_NUM_INITIALIZER
11853                 (struct cmd_config_e_tag_result,
11854                  e_tag_id_val, UINT16);
11855 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11856         TOKEN_STRING_INITIALIZER
11857                 (struct cmd_config_e_tag_result,
11858                  dst_pool, "dst-pool");
11859 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11860         TOKEN_NUM_INITIALIZER
11861                 (struct cmd_config_e_tag_result,
11862                  dst_pool_val, UINT8);
11863 cmdline_parse_token_string_t cmd_config_e_tag_port =
11864         TOKEN_STRING_INITIALIZER
11865                 (struct cmd_config_e_tag_result,
11866                  port, "port");
11867 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11868         TOKEN_NUM_INITIALIZER
11869                 (struct cmd_config_e_tag_result,
11870                  port_id, UINT16);
11871 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11872         TOKEN_STRING_INITIALIZER
11873                 (struct cmd_config_e_tag_result,
11874                  vf, "vf");
11875 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11876         TOKEN_NUM_INITIALIZER
11877                 (struct cmd_config_e_tag_result,
11878                  vf_id, UINT8);
11879
11880 /* E-tag insertion configuration */
11881 static void
11882 cmd_config_e_tag_insertion_en_parsed(
11883         void *parsed_result,
11884         __attribute__((unused)) struct cmdline *cl,
11885         __attribute__((unused)) void *data)
11886 {
11887         struct cmd_config_e_tag_result *res =
11888                 parsed_result;
11889         struct rte_eth_l2_tunnel_conf entry;
11890
11891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11892                 return;
11893
11894         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11895         entry.tunnel_id = res->port_tag_id_val;
11896         entry.vf_id = res->vf_id;
11897         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11898                                           &entry,
11899                                           ETH_L2_TUNNEL_INSERTION_MASK,
11900                                           1);
11901 }
11902
11903 static void
11904 cmd_config_e_tag_insertion_dis_parsed(
11905         void *parsed_result,
11906         __attribute__((unused)) struct cmdline *cl,
11907         __attribute__((unused)) void *data)
11908 {
11909         struct cmd_config_e_tag_result *res =
11910                 parsed_result;
11911         struct rte_eth_l2_tunnel_conf entry;
11912
11913         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11914                 return;
11915
11916         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11917         entry.vf_id = res->vf_id;
11918
11919         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11920                                           &entry,
11921                                           ETH_L2_TUNNEL_INSERTION_MASK,
11922                                           0);
11923 }
11924
11925 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11926         .f = cmd_config_e_tag_insertion_en_parsed,
11927         .data = NULL,
11928         .help_str = "E-tag ... : E-tag insertion enable",
11929         .tokens = {
11930                 (void *)&cmd_config_e_tag_e_tag,
11931                 (void *)&cmd_config_e_tag_set,
11932                 (void *)&cmd_config_e_tag_insertion,
11933                 (void *)&cmd_config_e_tag_on,
11934                 (void *)&cmd_config_e_tag_port_tag_id,
11935                 (void *)&cmd_config_e_tag_port_tag_id_val,
11936                 (void *)&cmd_config_e_tag_port,
11937                 (void *)&cmd_config_e_tag_port_id,
11938                 (void *)&cmd_config_e_tag_vf,
11939                 (void *)&cmd_config_e_tag_vf_id,
11940                 NULL,
11941         },
11942 };
11943
11944 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11945         .f = cmd_config_e_tag_insertion_dis_parsed,
11946         .data = NULL,
11947         .help_str = "E-tag ... : E-tag insertion disable",
11948         .tokens = {
11949                 (void *)&cmd_config_e_tag_e_tag,
11950                 (void *)&cmd_config_e_tag_set,
11951                 (void *)&cmd_config_e_tag_insertion,
11952                 (void *)&cmd_config_e_tag_off,
11953                 (void *)&cmd_config_e_tag_port,
11954                 (void *)&cmd_config_e_tag_port_id,
11955                 (void *)&cmd_config_e_tag_vf,
11956                 (void *)&cmd_config_e_tag_vf_id,
11957                 NULL,
11958         },
11959 };
11960
11961 /* E-tag stripping configuration */
11962 static void
11963 cmd_config_e_tag_stripping_parsed(
11964         void *parsed_result,
11965         __attribute__((unused)) struct cmdline *cl,
11966         __attribute__((unused)) void *data)
11967 {
11968         struct cmd_config_e_tag_result *res =
11969                 parsed_result;
11970         struct rte_eth_l2_tunnel_conf entry;
11971
11972         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11973                 return;
11974
11975         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11976
11977         if (!strcmp(res->on_off, "on"))
11978                 rte_eth_dev_l2_tunnel_offload_set
11979                         (res->port_id,
11980                          &entry,
11981                          ETH_L2_TUNNEL_STRIPPING_MASK,
11982                          1);
11983         else
11984                 rte_eth_dev_l2_tunnel_offload_set
11985                         (res->port_id,
11986                          &entry,
11987                          ETH_L2_TUNNEL_STRIPPING_MASK,
11988                          0);
11989 }
11990
11991 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11992         .f = cmd_config_e_tag_stripping_parsed,
11993         .data = NULL,
11994         .help_str = "E-tag ... : E-tag stripping enable/disable",
11995         .tokens = {
11996                 (void *)&cmd_config_e_tag_e_tag,
11997                 (void *)&cmd_config_e_tag_set,
11998                 (void *)&cmd_config_e_tag_stripping,
11999                 (void *)&cmd_config_e_tag_on_off,
12000                 (void *)&cmd_config_e_tag_port,
12001                 (void *)&cmd_config_e_tag_port_id,
12002                 NULL,
12003         },
12004 };
12005
12006 /* E-tag forwarding configuration */
12007 static void
12008 cmd_config_e_tag_forwarding_parsed(
12009         void *parsed_result,
12010         __attribute__((unused)) struct cmdline *cl,
12011         __attribute__((unused)) void *data)
12012 {
12013         struct cmd_config_e_tag_result *res = parsed_result;
12014         struct rte_eth_l2_tunnel_conf entry;
12015
12016         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12017                 return;
12018
12019         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12020
12021         if (!strcmp(res->on_off, "on"))
12022                 rte_eth_dev_l2_tunnel_offload_set
12023                         (res->port_id,
12024                          &entry,
12025                          ETH_L2_TUNNEL_FORWARDING_MASK,
12026                          1);
12027         else
12028                 rte_eth_dev_l2_tunnel_offload_set
12029                         (res->port_id,
12030                          &entry,
12031                          ETH_L2_TUNNEL_FORWARDING_MASK,
12032                          0);
12033 }
12034
12035 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12036         .f = cmd_config_e_tag_forwarding_parsed,
12037         .data = NULL,
12038         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12039         .tokens = {
12040                 (void *)&cmd_config_e_tag_e_tag,
12041                 (void *)&cmd_config_e_tag_set,
12042                 (void *)&cmd_config_e_tag_forwarding,
12043                 (void *)&cmd_config_e_tag_on_off,
12044                 (void *)&cmd_config_e_tag_port,
12045                 (void *)&cmd_config_e_tag_port_id,
12046                 NULL,
12047         },
12048 };
12049
12050 /* E-tag filter configuration */
12051 static void
12052 cmd_config_e_tag_filter_add_parsed(
12053         void *parsed_result,
12054         __attribute__((unused)) struct cmdline *cl,
12055         __attribute__((unused)) void *data)
12056 {
12057         struct cmd_config_e_tag_result *res = parsed_result;
12058         struct rte_eth_l2_tunnel_conf entry;
12059         int ret = 0;
12060
12061         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12062                 return;
12063
12064         if (res->e_tag_id_val > 0x3fff) {
12065                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12066                 return;
12067         }
12068
12069         ret = rte_eth_dev_filter_supported(res->port_id,
12070                                            RTE_ETH_FILTER_L2_TUNNEL);
12071         if (ret < 0) {
12072                 printf("E-tag filter is not supported on port %u.\n",
12073                        res->port_id);
12074                 return;
12075         }
12076
12077         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12078         entry.tunnel_id = res->e_tag_id_val;
12079         entry.pool = res->dst_pool_val;
12080
12081         ret = rte_eth_dev_filter_ctrl(res->port_id,
12082                                       RTE_ETH_FILTER_L2_TUNNEL,
12083                                       RTE_ETH_FILTER_ADD,
12084                                       &entry);
12085         if (ret < 0)
12086                 printf("E-tag filter programming error: (%s)\n",
12087                        strerror(-ret));
12088 }
12089
12090 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12091         .f = cmd_config_e_tag_filter_add_parsed,
12092         .data = NULL,
12093         .help_str = "E-tag ... : E-tag filter add",
12094         .tokens = {
12095                 (void *)&cmd_config_e_tag_e_tag,
12096                 (void *)&cmd_config_e_tag_set,
12097                 (void *)&cmd_config_e_tag_filter,
12098                 (void *)&cmd_config_e_tag_add,
12099                 (void *)&cmd_config_e_tag_e_tag_id,
12100                 (void *)&cmd_config_e_tag_e_tag_id_val,
12101                 (void *)&cmd_config_e_tag_dst_pool,
12102                 (void *)&cmd_config_e_tag_dst_pool_val,
12103                 (void *)&cmd_config_e_tag_port,
12104                 (void *)&cmd_config_e_tag_port_id,
12105                 NULL,
12106         },
12107 };
12108
12109 static void
12110 cmd_config_e_tag_filter_del_parsed(
12111         void *parsed_result,
12112         __attribute__((unused)) struct cmdline *cl,
12113         __attribute__((unused)) void *data)
12114 {
12115         struct cmd_config_e_tag_result *res = parsed_result;
12116         struct rte_eth_l2_tunnel_conf entry;
12117         int ret = 0;
12118
12119         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12120                 return;
12121
12122         if (res->e_tag_id_val > 0x3fff) {
12123                 printf("e-tag-id must be less than 0x3fff.\n");
12124                 return;
12125         }
12126
12127         ret = rte_eth_dev_filter_supported(res->port_id,
12128                                            RTE_ETH_FILTER_L2_TUNNEL);
12129         if (ret < 0) {
12130                 printf("E-tag filter is not supported on port %u.\n",
12131                        res->port_id);
12132                 return;
12133         }
12134
12135         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12136         entry.tunnel_id = res->e_tag_id_val;
12137
12138         ret = rte_eth_dev_filter_ctrl(res->port_id,
12139                                       RTE_ETH_FILTER_L2_TUNNEL,
12140                                       RTE_ETH_FILTER_DELETE,
12141                                       &entry);
12142         if (ret < 0)
12143                 printf("E-tag filter programming error: (%s)\n",
12144                        strerror(-ret));
12145 }
12146
12147 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12148         .f = cmd_config_e_tag_filter_del_parsed,
12149         .data = NULL,
12150         .help_str = "E-tag ... : E-tag filter delete",
12151         .tokens = {
12152                 (void *)&cmd_config_e_tag_e_tag,
12153                 (void *)&cmd_config_e_tag_set,
12154                 (void *)&cmd_config_e_tag_filter,
12155                 (void *)&cmd_config_e_tag_del,
12156                 (void *)&cmd_config_e_tag_e_tag_id,
12157                 (void *)&cmd_config_e_tag_e_tag_id_val,
12158                 (void *)&cmd_config_e_tag_port,
12159                 (void *)&cmd_config_e_tag_port_id,
12160                 NULL,
12161         },
12162 };
12163
12164 /* vf vlan anti spoof configuration */
12165
12166 /* Common result structure for vf vlan anti spoof */
12167 struct cmd_vf_vlan_anti_spoof_result {
12168         cmdline_fixed_string_t set;
12169         cmdline_fixed_string_t vf;
12170         cmdline_fixed_string_t vlan;
12171         cmdline_fixed_string_t antispoof;
12172         portid_t port_id;
12173         uint32_t vf_id;
12174         cmdline_fixed_string_t on_off;
12175 };
12176
12177 /* Common CLI fields for vf vlan anti spoof enable disable */
12178 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12179         TOKEN_STRING_INITIALIZER
12180                 (struct cmd_vf_vlan_anti_spoof_result,
12181                  set, "set");
12182 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12183         TOKEN_STRING_INITIALIZER
12184                 (struct cmd_vf_vlan_anti_spoof_result,
12185                  vf, "vf");
12186 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12187         TOKEN_STRING_INITIALIZER
12188                 (struct cmd_vf_vlan_anti_spoof_result,
12189                  vlan, "vlan");
12190 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12191         TOKEN_STRING_INITIALIZER
12192                 (struct cmd_vf_vlan_anti_spoof_result,
12193                  antispoof, "antispoof");
12194 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12195         TOKEN_NUM_INITIALIZER
12196                 (struct cmd_vf_vlan_anti_spoof_result,
12197                  port_id, UINT16);
12198 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12199         TOKEN_NUM_INITIALIZER
12200                 (struct cmd_vf_vlan_anti_spoof_result,
12201                  vf_id, UINT32);
12202 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_vf_vlan_anti_spoof_result,
12205                  on_off, "on#off");
12206
12207 static void
12208 cmd_set_vf_vlan_anti_spoof_parsed(
12209         void *parsed_result,
12210         __attribute__((unused)) struct cmdline *cl,
12211         __attribute__((unused)) void *data)
12212 {
12213         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12214         int ret = -ENOTSUP;
12215
12216         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12217
12218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12219                 return;
12220
12221 #ifdef RTE_LIBRTE_IXGBE_PMD
12222         if (ret == -ENOTSUP)
12223                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12224                                 res->vf_id, is_on);
12225 #endif
12226 #ifdef RTE_LIBRTE_I40E_PMD
12227         if (ret == -ENOTSUP)
12228                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12229                                 res->vf_id, is_on);
12230 #endif
12231 #ifdef RTE_LIBRTE_BNXT_PMD
12232         if (ret == -ENOTSUP)
12233                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12234                                 res->vf_id, is_on);
12235 #endif
12236
12237         switch (ret) {
12238         case 0:
12239                 break;
12240         case -EINVAL:
12241                 printf("invalid vf_id %d\n", res->vf_id);
12242                 break;
12243         case -ENODEV:
12244                 printf("invalid port_id %d\n", res->port_id);
12245                 break;
12246         case -ENOTSUP:
12247                 printf("function not implemented\n");
12248                 break;
12249         default:
12250                 printf("programming error: (%s)\n", strerror(-ret));
12251         }
12252 }
12253
12254 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12255         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12256         .data = NULL,
12257         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12258         .tokens = {
12259                 (void *)&cmd_vf_vlan_anti_spoof_set,
12260                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12261                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12262                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12263                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12264                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12265                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12266                 NULL,
12267         },
12268 };
12269
12270 /* vf mac anti spoof configuration */
12271
12272 /* Common result structure for vf mac anti spoof */
12273 struct cmd_vf_mac_anti_spoof_result {
12274         cmdline_fixed_string_t set;
12275         cmdline_fixed_string_t vf;
12276         cmdline_fixed_string_t mac;
12277         cmdline_fixed_string_t antispoof;
12278         portid_t port_id;
12279         uint32_t vf_id;
12280         cmdline_fixed_string_t on_off;
12281 };
12282
12283 /* Common CLI fields for vf mac anti spoof enable disable */
12284 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12285         TOKEN_STRING_INITIALIZER
12286                 (struct cmd_vf_mac_anti_spoof_result,
12287                  set, "set");
12288 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12289         TOKEN_STRING_INITIALIZER
12290                 (struct cmd_vf_mac_anti_spoof_result,
12291                  vf, "vf");
12292 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12293         TOKEN_STRING_INITIALIZER
12294                 (struct cmd_vf_mac_anti_spoof_result,
12295                  mac, "mac");
12296 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12297         TOKEN_STRING_INITIALIZER
12298                 (struct cmd_vf_mac_anti_spoof_result,
12299                  antispoof, "antispoof");
12300 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12301         TOKEN_NUM_INITIALIZER
12302                 (struct cmd_vf_mac_anti_spoof_result,
12303                  port_id, UINT16);
12304 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12305         TOKEN_NUM_INITIALIZER
12306                 (struct cmd_vf_mac_anti_spoof_result,
12307                  vf_id, UINT32);
12308 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12309         TOKEN_STRING_INITIALIZER
12310                 (struct cmd_vf_mac_anti_spoof_result,
12311                  on_off, "on#off");
12312
12313 static void
12314 cmd_set_vf_mac_anti_spoof_parsed(
12315         void *parsed_result,
12316         __attribute__((unused)) struct cmdline *cl,
12317         __attribute__((unused)) void *data)
12318 {
12319         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12320         int ret = -ENOTSUP;
12321
12322         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12323
12324         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12325                 return;
12326
12327 #ifdef RTE_LIBRTE_IXGBE_PMD
12328         if (ret == -ENOTSUP)
12329                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12330                         res->vf_id, is_on);
12331 #endif
12332 #ifdef RTE_LIBRTE_I40E_PMD
12333         if (ret == -ENOTSUP)
12334                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12335                         res->vf_id, is_on);
12336 #endif
12337 #ifdef RTE_LIBRTE_BNXT_PMD
12338         if (ret == -ENOTSUP)
12339                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12340                         res->vf_id, is_on);
12341 #endif
12342
12343         switch (ret) {
12344         case 0:
12345                 break;
12346         case -EINVAL:
12347                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12348                 break;
12349         case -ENODEV:
12350                 printf("invalid port_id %d\n", res->port_id);
12351                 break;
12352         case -ENOTSUP:
12353                 printf("function not implemented\n");
12354                 break;
12355         default:
12356                 printf("programming error: (%s)\n", strerror(-ret));
12357         }
12358 }
12359
12360 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12361         .f = cmd_set_vf_mac_anti_spoof_parsed,
12362         .data = NULL,
12363         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12364         .tokens = {
12365                 (void *)&cmd_vf_mac_anti_spoof_set,
12366                 (void *)&cmd_vf_mac_anti_spoof_vf,
12367                 (void *)&cmd_vf_mac_anti_spoof_mac,
12368                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12369                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12370                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12371                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12372                 NULL,
12373         },
12374 };
12375
12376 /* vf vlan strip queue configuration */
12377
12378 /* Common result structure for vf mac anti spoof */
12379 struct cmd_vf_vlan_stripq_result {
12380         cmdline_fixed_string_t set;
12381         cmdline_fixed_string_t vf;
12382         cmdline_fixed_string_t vlan;
12383         cmdline_fixed_string_t stripq;
12384         portid_t port_id;
12385         uint16_t vf_id;
12386         cmdline_fixed_string_t on_off;
12387 };
12388
12389 /* Common CLI fields for vf vlan strip enable disable */
12390 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12391         TOKEN_STRING_INITIALIZER
12392                 (struct cmd_vf_vlan_stripq_result,
12393                  set, "set");
12394 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12395         TOKEN_STRING_INITIALIZER
12396                 (struct cmd_vf_vlan_stripq_result,
12397                  vf, "vf");
12398 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12399         TOKEN_STRING_INITIALIZER
12400                 (struct cmd_vf_vlan_stripq_result,
12401                  vlan, "vlan");
12402 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12403         TOKEN_STRING_INITIALIZER
12404                 (struct cmd_vf_vlan_stripq_result,
12405                  stripq, "stripq");
12406 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12407         TOKEN_NUM_INITIALIZER
12408                 (struct cmd_vf_vlan_stripq_result,
12409                  port_id, UINT16);
12410 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12411         TOKEN_NUM_INITIALIZER
12412                 (struct cmd_vf_vlan_stripq_result,
12413                  vf_id, UINT16);
12414 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12415         TOKEN_STRING_INITIALIZER
12416                 (struct cmd_vf_vlan_stripq_result,
12417                  on_off, "on#off");
12418
12419 static void
12420 cmd_set_vf_vlan_stripq_parsed(
12421         void *parsed_result,
12422         __attribute__((unused)) struct cmdline *cl,
12423         __attribute__((unused)) void *data)
12424 {
12425         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12426         int ret = -ENOTSUP;
12427
12428         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12429
12430         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12431                 return;
12432
12433 #ifdef RTE_LIBRTE_IXGBE_PMD
12434         if (ret == -ENOTSUP)
12435                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12436                         res->vf_id, is_on);
12437 #endif
12438 #ifdef RTE_LIBRTE_I40E_PMD
12439         if (ret == -ENOTSUP)
12440                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12441                         res->vf_id, is_on);
12442 #endif
12443 #ifdef RTE_LIBRTE_BNXT_PMD
12444         if (ret == -ENOTSUP)
12445                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12446                         res->vf_id, is_on);
12447 #endif
12448
12449         switch (ret) {
12450         case 0:
12451                 break;
12452         case -EINVAL:
12453                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12454                 break;
12455         case -ENODEV:
12456                 printf("invalid port_id %d\n", res->port_id);
12457                 break;
12458         case -ENOTSUP:
12459                 printf("function not implemented\n");
12460                 break;
12461         default:
12462                 printf("programming error: (%s)\n", strerror(-ret));
12463         }
12464 }
12465
12466 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12467         .f = cmd_set_vf_vlan_stripq_parsed,
12468         .data = NULL,
12469         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12470         .tokens = {
12471                 (void *)&cmd_vf_vlan_stripq_set,
12472                 (void *)&cmd_vf_vlan_stripq_vf,
12473                 (void *)&cmd_vf_vlan_stripq_vlan,
12474                 (void *)&cmd_vf_vlan_stripq_stripq,
12475                 (void *)&cmd_vf_vlan_stripq_port_id,
12476                 (void *)&cmd_vf_vlan_stripq_vf_id,
12477                 (void *)&cmd_vf_vlan_stripq_on_off,
12478                 NULL,
12479         },
12480 };
12481
12482 /* vf vlan insert configuration */
12483
12484 /* Common result structure for vf vlan insert */
12485 struct cmd_vf_vlan_insert_result {
12486         cmdline_fixed_string_t set;
12487         cmdline_fixed_string_t vf;
12488         cmdline_fixed_string_t vlan;
12489         cmdline_fixed_string_t insert;
12490         portid_t port_id;
12491         uint16_t vf_id;
12492         uint16_t vlan_id;
12493 };
12494
12495 /* Common CLI fields for vf vlan insert enable disable */
12496 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_vf_vlan_insert_result,
12499                  set, "set");
12500 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_vf_vlan_insert_result,
12503                  vf, "vf");
12504 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12505         TOKEN_STRING_INITIALIZER
12506                 (struct cmd_vf_vlan_insert_result,
12507                  vlan, "vlan");
12508 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12509         TOKEN_STRING_INITIALIZER
12510                 (struct cmd_vf_vlan_insert_result,
12511                  insert, "insert");
12512 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12513         TOKEN_NUM_INITIALIZER
12514                 (struct cmd_vf_vlan_insert_result,
12515                  port_id, UINT16);
12516 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12517         TOKEN_NUM_INITIALIZER
12518                 (struct cmd_vf_vlan_insert_result,
12519                  vf_id, UINT16);
12520 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12521         TOKEN_NUM_INITIALIZER
12522                 (struct cmd_vf_vlan_insert_result,
12523                  vlan_id, UINT16);
12524
12525 static void
12526 cmd_set_vf_vlan_insert_parsed(
12527         void *parsed_result,
12528         __attribute__((unused)) struct cmdline *cl,
12529         __attribute__((unused)) void *data)
12530 {
12531         struct cmd_vf_vlan_insert_result *res = parsed_result;
12532         int ret = -ENOTSUP;
12533
12534         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12535                 return;
12536
12537 #ifdef RTE_LIBRTE_IXGBE_PMD
12538         if (ret == -ENOTSUP)
12539                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12540                         res->vlan_id);
12541 #endif
12542 #ifdef RTE_LIBRTE_I40E_PMD
12543         if (ret == -ENOTSUP)
12544                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12545                         res->vlan_id);
12546 #endif
12547 #ifdef RTE_LIBRTE_BNXT_PMD
12548         if (ret == -ENOTSUP)
12549                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12550                         res->vlan_id);
12551 #endif
12552
12553         switch (ret) {
12554         case 0:
12555                 break;
12556         case -EINVAL:
12557                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12558                 break;
12559         case -ENODEV:
12560                 printf("invalid port_id %d\n", res->port_id);
12561                 break;
12562         case -ENOTSUP:
12563                 printf("function not implemented\n");
12564                 break;
12565         default:
12566                 printf("programming error: (%s)\n", strerror(-ret));
12567         }
12568 }
12569
12570 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12571         .f = cmd_set_vf_vlan_insert_parsed,
12572         .data = NULL,
12573         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12574         .tokens = {
12575                 (void *)&cmd_vf_vlan_insert_set,
12576                 (void *)&cmd_vf_vlan_insert_vf,
12577                 (void *)&cmd_vf_vlan_insert_vlan,
12578                 (void *)&cmd_vf_vlan_insert_insert,
12579                 (void *)&cmd_vf_vlan_insert_port_id,
12580                 (void *)&cmd_vf_vlan_insert_vf_id,
12581                 (void *)&cmd_vf_vlan_insert_vlan_id,
12582                 NULL,
12583         },
12584 };
12585
12586 /* tx loopback configuration */
12587
12588 /* Common result structure for tx loopback */
12589 struct cmd_tx_loopback_result {
12590         cmdline_fixed_string_t set;
12591         cmdline_fixed_string_t tx;
12592         cmdline_fixed_string_t loopback;
12593         portid_t port_id;
12594         cmdline_fixed_string_t on_off;
12595 };
12596
12597 /* Common CLI fields for tx loopback enable disable */
12598 cmdline_parse_token_string_t cmd_tx_loopback_set =
12599         TOKEN_STRING_INITIALIZER
12600                 (struct cmd_tx_loopback_result,
12601                  set, "set");
12602 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12603         TOKEN_STRING_INITIALIZER
12604                 (struct cmd_tx_loopback_result,
12605                  tx, "tx");
12606 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12607         TOKEN_STRING_INITIALIZER
12608                 (struct cmd_tx_loopback_result,
12609                  loopback, "loopback");
12610 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12611         TOKEN_NUM_INITIALIZER
12612                 (struct cmd_tx_loopback_result,
12613                  port_id, UINT16);
12614 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12615         TOKEN_STRING_INITIALIZER
12616                 (struct cmd_tx_loopback_result,
12617                  on_off, "on#off");
12618
12619 static void
12620 cmd_set_tx_loopback_parsed(
12621         void *parsed_result,
12622         __attribute__((unused)) struct cmdline *cl,
12623         __attribute__((unused)) void *data)
12624 {
12625         struct cmd_tx_loopback_result *res = parsed_result;
12626         int ret = -ENOTSUP;
12627
12628         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12629
12630         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12631                 return;
12632
12633 #ifdef RTE_LIBRTE_IXGBE_PMD
12634         if (ret == -ENOTSUP)
12635                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12636 #endif
12637 #ifdef RTE_LIBRTE_I40E_PMD
12638         if (ret == -ENOTSUP)
12639                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12640 #endif
12641 #ifdef RTE_LIBRTE_BNXT_PMD
12642         if (ret == -ENOTSUP)
12643                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12644 #endif
12645
12646         switch (ret) {
12647         case 0:
12648                 break;
12649         case -EINVAL:
12650                 printf("invalid is_on %d\n", is_on);
12651                 break;
12652         case -ENODEV:
12653                 printf("invalid port_id %d\n", res->port_id);
12654                 break;
12655         case -ENOTSUP:
12656                 printf("function not implemented\n");
12657                 break;
12658         default:
12659                 printf("programming error: (%s)\n", strerror(-ret));
12660         }
12661 }
12662
12663 cmdline_parse_inst_t cmd_set_tx_loopback = {
12664         .f = cmd_set_tx_loopback_parsed,
12665         .data = NULL,
12666         .help_str = "set tx loopback <port_id> on|off",
12667         .tokens = {
12668                 (void *)&cmd_tx_loopback_set,
12669                 (void *)&cmd_tx_loopback_tx,
12670                 (void *)&cmd_tx_loopback_loopback,
12671                 (void *)&cmd_tx_loopback_port_id,
12672                 (void *)&cmd_tx_loopback_on_off,
12673                 NULL,
12674         },
12675 };
12676
12677 /* all queues drop enable configuration */
12678
12679 /* Common result structure for all queues drop enable */
12680 struct cmd_all_queues_drop_en_result {
12681         cmdline_fixed_string_t set;
12682         cmdline_fixed_string_t all;
12683         cmdline_fixed_string_t queues;
12684         cmdline_fixed_string_t drop;
12685         portid_t port_id;
12686         cmdline_fixed_string_t on_off;
12687 };
12688
12689 /* Common CLI fields for tx loopback enable disable */
12690 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12691         TOKEN_STRING_INITIALIZER
12692                 (struct cmd_all_queues_drop_en_result,
12693                  set, "set");
12694 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12695         TOKEN_STRING_INITIALIZER
12696                 (struct cmd_all_queues_drop_en_result,
12697                  all, "all");
12698 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12699         TOKEN_STRING_INITIALIZER
12700                 (struct cmd_all_queues_drop_en_result,
12701                  queues, "queues");
12702 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12703         TOKEN_STRING_INITIALIZER
12704                 (struct cmd_all_queues_drop_en_result,
12705                  drop, "drop");
12706 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12707         TOKEN_NUM_INITIALIZER
12708                 (struct cmd_all_queues_drop_en_result,
12709                  port_id, UINT16);
12710 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12711         TOKEN_STRING_INITIALIZER
12712                 (struct cmd_all_queues_drop_en_result,
12713                  on_off, "on#off");
12714
12715 static void
12716 cmd_set_all_queues_drop_en_parsed(
12717         void *parsed_result,
12718         __attribute__((unused)) struct cmdline *cl,
12719         __attribute__((unused)) void *data)
12720 {
12721         struct cmd_all_queues_drop_en_result *res = parsed_result;
12722         int ret = -ENOTSUP;
12723         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12724
12725         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12726                 return;
12727
12728 #ifdef RTE_LIBRTE_IXGBE_PMD
12729         if (ret == -ENOTSUP)
12730                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12731 #endif
12732 #ifdef RTE_LIBRTE_BNXT_PMD
12733         if (ret == -ENOTSUP)
12734                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12735 #endif
12736         switch (ret) {
12737         case 0:
12738                 break;
12739         case -EINVAL:
12740                 printf("invalid is_on %d\n", is_on);
12741                 break;
12742         case -ENODEV:
12743                 printf("invalid port_id %d\n", res->port_id);
12744                 break;
12745         case -ENOTSUP:
12746                 printf("function not implemented\n");
12747                 break;
12748         default:
12749                 printf("programming error: (%s)\n", strerror(-ret));
12750         }
12751 }
12752
12753 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12754         .f = cmd_set_all_queues_drop_en_parsed,
12755         .data = NULL,
12756         .help_str = "set all queues drop <port_id> on|off",
12757         .tokens = {
12758                 (void *)&cmd_all_queues_drop_en_set,
12759                 (void *)&cmd_all_queues_drop_en_all,
12760                 (void *)&cmd_all_queues_drop_en_queues,
12761                 (void *)&cmd_all_queues_drop_en_drop,
12762                 (void *)&cmd_all_queues_drop_en_port_id,
12763                 (void *)&cmd_all_queues_drop_en_on_off,
12764                 NULL,
12765         },
12766 };
12767
12768 /* vf split drop enable configuration */
12769
12770 /* Common result structure for vf split drop enable */
12771 struct cmd_vf_split_drop_en_result {
12772         cmdline_fixed_string_t set;
12773         cmdline_fixed_string_t vf;
12774         cmdline_fixed_string_t split;
12775         cmdline_fixed_string_t drop;
12776         portid_t port_id;
12777         uint16_t vf_id;
12778         cmdline_fixed_string_t on_off;
12779 };
12780
12781 /* Common CLI fields for vf split drop enable disable */
12782 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12783         TOKEN_STRING_INITIALIZER
12784                 (struct cmd_vf_split_drop_en_result,
12785                  set, "set");
12786 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12787         TOKEN_STRING_INITIALIZER
12788                 (struct cmd_vf_split_drop_en_result,
12789                  vf, "vf");
12790 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12791         TOKEN_STRING_INITIALIZER
12792                 (struct cmd_vf_split_drop_en_result,
12793                  split, "split");
12794 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12795         TOKEN_STRING_INITIALIZER
12796                 (struct cmd_vf_split_drop_en_result,
12797                  drop, "drop");
12798 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12799         TOKEN_NUM_INITIALIZER
12800                 (struct cmd_vf_split_drop_en_result,
12801                  port_id, UINT16);
12802 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12803         TOKEN_NUM_INITIALIZER
12804                 (struct cmd_vf_split_drop_en_result,
12805                  vf_id, UINT16);
12806 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12807         TOKEN_STRING_INITIALIZER
12808                 (struct cmd_vf_split_drop_en_result,
12809                  on_off, "on#off");
12810
12811 static void
12812 cmd_set_vf_split_drop_en_parsed(
12813         void *parsed_result,
12814         __attribute__((unused)) struct cmdline *cl,
12815         __attribute__((unused)) void *data)
12816 {
12817         struct cmd_vf_split_drop_en_result *res = parsed_result;
12818         int ret = -ENOTSUP;
12819         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12820
12821         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12822                 return;
12823
12824 #ifdef RTE_LIBRTE_IXGBE_PMD
12825         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12826                         is_on);
12827 #endif
12828         switch (ret) {
12829         case 0:
12830                 break;
12831         case -EINVAL:
12832                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12833                 break;
12834         case -ENODEV:
12835                 printf("invalid port_id %d\n", res->port_id);
12836                 break;
12837         case -ENOTSUP:
12838                 printf("not supported on port %d\n", res->port_id);
12839                 break;
12840         default:
12841                 printf("programming error: (%s)\n", strerror(-ret));
12842         }
12843 }
12844
12845 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12846         .f = cmd_set_vf_split_drop_en_parsed,
12847         .data = NULL,
12848         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12849         .tokens = {
12850                 (void *)&cmd_vf_split_drop_en_set,
12851                 (void *)&cmd_vf_split_drop_en_vf,
12852                 (void *)&cmd_vf_split_drop_en_split,
12853                 (void *)&cmd_vf_split_drop_en_drop,
12854                 (void *)&cmd_vf_split_drop_en_port_id,
12855                 (void *)&cmd_vf_split_drop_en_vf_id,
12856                 (void *)&cmd_vf_split_drop_en_on_off,
12857                 NULL,
12858         },
12859 };
12860
12861 /* vf mac address configuration */
12862
12863 /* Common result structure for vf mac address */
12864 struct cmd_set_vf_mac_addr_result {
12865         cmdline_fixed_string_t set;
12866         cmdline_fixed_string_t vf;
12867         cmdline_fixed_string_t mac;
12868         cmdline_fixed_string_t addr;
12869         portid_t port_id;
12870         uint16_t vf_id;
12871         struct ether_addr mac_addr;
12872
12873 };
12874
12875 /* Common CLI fields for vf split drop enable disable */
12876 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12877         TOKEN_STRING_INITIALIZER
12878                 (struct cmd_set_vf_mac_addr_result,
12879                  set, "set");
12880 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12881         TOKEN_STRING_INITIALIZER
12882                 (struct cmd_set_vf_mac_addr_result,
12883                  vf, "vf");
12884 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12885         TOKEN_STRING_INITIALIZER
12886                 (struct cmd_set_vf_mac_addr_result,
12887                  mac, "mac");
12888 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12889         TOKEN_STRING_INITIALIZER
12890                 (struct cmd_set_vf_mac_addr_result,
12891                  addr, "addr");
12892 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12893         TOKEN_NUM_INITIALIZER
12894                 (struct cmd_set_vf_mac_addr_result,
12895                  port_id, UINT16);
12896 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12897         TOKEN_NUM_INITIALIZER
12898                 (struct cmd_set_vf_mac_addr_result,
12899                  vf_id, UINT16);
12900 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12901         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12902                  mac_addr);
12903
12904 static void
12905 cmd_set_vf_mac_addr_parsed(
12906         void *parsed_result,
12907         __attribute__((unused)) struct cmdline *cl,
12908         __attribute__((unused)) void *data)
12909 {
12910         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12911         int ret = -ENOTSUP;
12912
12913         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12914                 return;
12915
12916 #ifdef RTE_LIBRTE_IXGBE_PMD
12917         if (ret == -ENOTSUP)
12918                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12919                                 &res->mac_addr);
12920 #endif
12921 #ifdef RTE_LIBRTE_I40E_PMD
12922         if (ret == -ENOTSUP)
12923                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12924                                 &res->mac_addr);
12925 #endif
12926 #ifdef RTE_LIBRTE_BNXT_PMD
12927         if (ret == -ENOTSUP)
12928                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12929                                 &res->mac_addr);
12930 #endif
12931
12932         switch (ret) {
12933         case 0:
12934                 break;
12935         case -EINVAL:
12936                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12937                 break;
12938         case -ENODEV:
12939                 printf("invalid port_id %d\n", res->port_id);
12940                 break;
12941         case -ENOTSUP:
12942                 printf("function not implemented\n");
12943                 break;
12944         default:
12945                 printf("programming error: (%s)\n", strerror(-ret));
12946         }
12947 }
12948
12949 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12950         .f = cmd_set_vf_mac_addr_parsed,
12951         .data = NULL,
12952         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12953         .tokens = {
12954                 (void *)&cmd_set_vf_mac_addr_set,
12955                 (void *)&cmd_set_vf_mac_addr_vf,
12956                 (void *)&cmd_set_vf_mac_addr_mac,
12957                 (void *)&cmd_set_vf_mac_addr_addr,
12958                 (void *)&cmd_set_vf_mac_addr_port_id,
12959                 (void *)&cmd_set_vf_mac_addr_vf_id,
12960                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12961                 NULL,
12962         },
12963 };
12964
12965 /* MACsec configuration */
12966
12967 /* Common result structure for MACsec offload enable */
12968 struct cmd_macsec_offload_on_result {
12969         cmdline_fixed_string_t set;
12970         cmdline_fixed_string_t macsec;
12971         cmdline_fixed_string_t offload;
12972         portid_t port_id;
12973         cmdline_fixed_string_t on;
12974         cmdline_fixed_string_t encrypt;
12975         cmdline_fixed_string_t en_on_off;
12976         cmdline_fixed_string_t replay_protect;
12977         cmdline_fixed_string_t rp_on_off;
12978 };
12979
12980 /* Common CLI fields for MACsec offload disable */
12981 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12982         TOKEN_STRING_INITIALIZER
12983                 (struct cmd_macsec_offload_on_result,
12984                  set, "set");
12985 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12986         TOKEN_STRING_INITIALIZER
12987                 (struct cmd_macsec_offload_on_result,
12988                  macsec, "macsec");
12989 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12990         TOKEN_STRING_INITIALIZER
12991                 (struct cmd_macsec_offload_on_result,
12992                  offload, "offload");
12993 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12994         TOKEN_NUM_INITIALIZER
12995                 (struct cmd_macsec_offload_on_result,
12996                  port_id, UINT16);
12997 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12998         TOKEN_STRING_INITIALIZER
12999                 (struct cmd_macsec_offload_on_result,
13000                  on, "on");
13001 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13002         TOKEN_STRING_INITIALIZER
13003                 (struct cmd_macsec_offload_on_result,
13004                  encrypt, "encrypt");
13005 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13006         TOKEN_STRING_INITIALIZER
13007                 (struct cmd_macsec_offload_on_result,
13008                  en_on_off, "on#off");
13009 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13010         TOKEN_STRING_INITIALIZER
13011                 (struct cmd_macsec_offload_on_result,
13012                  replay_protect, "replay-protect");
13013 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13014         TOKEN_STRING_INITIALIZER
13015                 (struct cmd_macsec_offload_on_result,
13016                  rp_on_off, "on#off");
13017
13018 static void
13019 cmd_set_macsec_offload_on_parsed(
13020         void *parsed_result,
13021         __attribute__((unused)) struct cmdline *cl,
13022         __attribute__((unused)) void *data)
13023 {
13024         struct cmd_macsec_offload_on_result *res = parsed_result;
13025         int ret = -ENOTSUP;
13026         portid_t port_id = res->port_id;
13027         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13028         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13029
13030         if (port_id_is_invalid(port_id, ENABLED_WARN))
13031                 return;
13032
13033         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
13034 #ifdef RTE_LIBRTE_IXGBE_PMD
13035         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13036 #endif
13037         RTE_SET_USED(en);
13038         RTE_SET_USED(rp);
13039
13040         switch (ret) {
13041         case 0:
13042                 break;
13043         case -ENODEV:
13044                 printf("invalid port_id %d\n", port_id);
13045                 break;
13046         case -ENOTSUP:
13047                 printf("not supported on port %d\n", port_id);
13048                 break;
13049         default:
13050                 printf("programming error: (%s)\n", strerror(-ret));
13051         }
13052 }
13053
13054 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13055         .f = cmd_set_macsec_offload_on_parsed,
13056         .data = NULL,
13057         .help_str = "set macsec offload <port_id> on "
13058                 "encrypt on|off replay-protect on|off",
13059         .tokens = {
13060                 (void *)&cmd_macsec_offload_on_set,
13061                 (void *)&cmd_macsec_offload_on_macsec,
13062                 (void *)&cmd_macsec_offload_on_offload,
13063                 (void *)&cmd_macsec_offload_on_port_id,
13064                 (void *)&cmd_macsec_offload_on_on,
13065                 (void *)&cmd_macsec_offload_on_encrypt,
13066                 (void *)&cmd_macsec_offload_on_en_on_off,
13067                 (void *)&cmd_macsec_offload_on_replay_protect,
13068                 (void *)&cmd_macsec_offload_on_rp_on_off,
13069                 NULL,
13070         },
13071 };
13072
13073 /* Common result structure for MACsec offload disable */
13074 struct cmd_macsec_offload_off_result {
13075         cmdline_fixed_string_t set;
13076         cmdline_fixed_string_t macsec;
13077         cmdline_fixed_string_t offload;
13078         portid_t port_id;
13079         cmdline_fixed_string_t off;
13080 };
13081
13082 /* Common CLI fields for MACsec offload disable */
13083 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13084         TOKEN_STRING_INITIALIZER
13085                 (struct cmd_macsec_offload_off_result,
13086                  set, "set");
13087 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13088         TOKEN_STRING_INITIALIZER
13089                 (struct cmd_macsec_offload_off_result,
13090                  macsec, "macsec");
13091 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13092         TOKEN_STRING_INITIALIZER
13093                 (struct cmd_macsec_offload_off_result,
13094                  offload, "offload");
13095 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13096         TOKEN_NUM_INITIALIZER
13097                 (struct cmd_macsec_offload_off_result,
13098                  port_id, UINT16);
13099 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13100         TOKEN_STRING_INITIALIZER
13101                 (struct cmd_macsec_offload_off_result,
13102                  off, "off");
13103
13104 static void
13105 cmd_set_macsec_offload_off_parsed(
13106         void *parsed_result,
13107         __attribute__((unused)) struct cmdline *cl,
13108         __attribute__((unused)) void *data)
13109 {
13110         struct cmd_macsec_offload_off_result *res = parsed_result;
13111         int ret = -ENOTSUP;
13112         portid_t port_id = res->port_id;
13113
13114         if (port_id_is_invalid(port_id, ENABLED_WARN))
13115                 return;
13116
13117         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13118 #ifdef RTE_LIBRTE_IXGBE_PMD
13119         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13120 #endif
13121
13122         switch (ret) {
13123         case 0:
13124                 break;
13125         case -ENODEV:
13126                 printf("invalid port_id %d\n", port_id);
13127                 break;
13128         case -ENOTSUP:
13129                 printf("not supported on port %d\n", port_id);
13130                 break;
13131         default:
13132                 printf("programming error: (%s)\n", strerror(-ret));
13133         }
13134 }
13135
13136 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13137         .f = cmd_set_macsec_offload_off_parsed,
13138         .data = NULL,
13139         .help_str = "set macsec offload <port_id> off",
13140         .tokens = {
13141                 (void *)&cmd_macsec_offload_off_set,
13142                 (void *)&cmd_macsec_offload_off_macsec,
13143                 (void *)&cmd_macsec_offload_off_offload,
13144                 (void *)&cmd_macsec_offload_off_port_id,
13145                 (void *)&cmd_macsec_offload_off_off,
13146                 NULL,
13147         },
13148 };
13149
13150 /* Common result structure for MACsec secure connection configure */
13151 struct cmd_macsec_sc_result {
13152         cmdline_fixed_string_t set;
13153         cmdline_fixed_string_t macsec;
13154         cmdline_fixed_string_t sc;
13155         cmdline_fixed_string_t tx_rx;
13156         portid_t port_id;
13157         struct ether_addr mac;
13158         uint16_t pi;
13159 };
13160
13161 /* Common CLI fields for MACsec secure connection configure */
13162 cmdline_parse_token_string_t cmd_macsec_sc_set =
13163         TOKEN_STRING_INITIALIZER
13164                 (struct cmd_macsec_sc_result,
13165                  set, "set");
13166 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13167         TOKEN_STRING_INITIALIZER
13168                 (struct cmd_macsec_sc_result,
13169                  macsec, "macsec");
13170 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13171         TOKEN_STRING_INITIALIZER
13172                 (struct cmd_macsec_sc_result,
13173                  sc, "sc");
13174 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13175         TOKEN_STRING_INITIALIZER
13176                 (struct cmd_macsec_sc_result,
13177                  tx_rx, "tx#rx");
13178 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13179         TOKEN_NUM_INITIALIZER
13180                 (struct cmd_macsec_sc_result,
13181                  port_id, UINT16);
13182 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13183         TOKEN_ETHERADDR_INITIALIZER
13184                 (struct cmd_macsec_sc_result,
13185                  mac);
13186 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13187         TOKEN_NUM_INITIALIZER
13188                 (struct cmd_macsec_sc_result,
13189                  pi, UINT16);
13190
13191 static void
13192 cmd_set_macsec_sc_parsed(
13193         void *parsed_result,
13194         __attribute__((unused)) struct cmdline *cl,
13195         __attribute__((unused)) void *data)
13196 {
13197         struct cmd_macsec_sc_result *res = parsed_result;
13198         int ret = -ENOTSUP;
13199         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13200
13201 #ifdef RTE_LIBRTE_IXGBE_PMD
13202         ret = is_tx ?
13203                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13204                                 res->mac.addr_bytes) :
13205                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13206                                 res->mac.addr_bytes, res->pi);
13207 #endif
13208         RTE_SET_USED(is_tx);
13209
13210         switch (ret) {
13211         case 0:
13212                 break;
13213         case -ENODEV:
13214                 printf("invalid port_id %d\n", res->port_id);
13215                 break;
13216         case -ENOTSUP:
13217                 printf("not supported on port %d\n", res->port_id);
13218                 break;
13219         default:
13220                 printf("programming error: (%s)\n", strerror(-ret));
13221         }
13222 }
13223
13224 cmdline_parse_inst_t cmd_set_macsec_sc = {
13225         .f = cmd_set_macsec_sc_parsed,
13226         .data = NULL,
13227         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13228         .tokens = {
13229                 (void *)&cmd_macsec_sc_set,
13230                 (void *)&cmd_macsec_sc_macsec,
13231                 (void *)&cmd_macsec_sc_sc,
13232                 (void *)&cmd_macsec_sc_tx_rx,
13233                 (void *)&cmd_macsec_sc_port_id,
13234                 (void *)&cmd_macsec_sc_mac,
13235                 (void *)&cmd_macsec_sc_pi,
13236                 NULL,
13237         },
13238 };
13239
13240 /* Common result structure for MACsec secure connection configure */
13241 struct cmd_macsec_sa_result {
13242         cmdline_fixed_string_t set;
13243         cmdline_fixed_string_t macsec;
13244         cmdline_fixed_string_t sa;
13245         cmdline_fixed_string_t tx_rx;
13246         portid_t port_id;
13247         uint8_t idx;
13248         uint8_t an;
13249         uint32_t pn;
13250         cmdline_fixed_string_t key;
13251 };
13252
13253 /* Common CLI fields for MACsec secure connection configure */
13254 cmdline_parse_token_string_t cmd_macsec_sa_set =
13255         TOKEN_STRING_INITIALIZER
13256                 (struct cmd_macsec_sa_result,
13257                  set, "set");
13258 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_macsec_sa_result,
13261                  macsec, "macsec");
13262 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13263         TOKEN_STRING_INITIALIZER
13264                 (struct cmd_macsec_sa_result,
13265                  sa, "sa");
13266 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13267         TOKEN_STRING_INITIALIZER
13268                 (struct cmd_macsec_sa_result,
13269                  tx_rx, "tx#rx");
13270 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13271         TOKEN_NUM_INITIALIZER
13272                 (struct cmd_macsec_sa_result,
13273                  port_id, UINT16);
13274 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13275         TOKEN_NUM_INITIALIZER
13276                 (struct cmd_macsec_sa_result,
13277                  idx, UINT8);
13278 cmdline_parse_token_num_t cmd_macsec_sa_an =
13279         TOKEN_NUM_INITIALIZER
13280                 (struct cmd_macsec_sa_result,
13281                  an, UINT8);
13282 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13283         TOKEN_NUM_INITIALIZER
13284                 (struct cmd_macsec_sa_result,
13285                  pn, UINT32);
13286 cmdline_parse_token_string_t cmd_macsec_sa_key =
13287         TOKEN_STRING_INITIALIZER
13288                 (struct cmd_macsec_sa_result,
13289                  key, NULL);
13290
13291 static void
13292 cmd_set_macsec_sa_parsed(
13293         void *parsed_result,
13294         __attribute__((unused)) struct cmdline *cl,
13295         __attribute__((unused)) void *data)
13296 {
13297         struct cmd_macsec_sa_result *res = parsed_result;
13298         int ret = -ENOTSUP;
13299         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13300         uint8_t key[16] = { 0 };
13301         uint8_t xdgt0;
13302         uint8_t xdgt1;
13303         int key_len;
13304         int i;
13305
13306         key_len = strlen(res->key) / 2;
13307         if (key_len > 16)
13308                 key_len = 16;
13309
13310         for (i = 0; i < key_len; i++) {
13311                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13312                 if (xdgt0 == 0xFF)
13313                         return;
13314                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13315                 if (xdgt1 == 0xFF)
13316                         return;
13317                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13318         }
13319
13320 #ifdef RTE_LIBRTE_IXGBE_PMD
13321         ret = is_tx ?
13322                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13323                         res->idx, res->an, res->pn, key) :
13324                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13325                         res->idx, res->an, res->pn, key);
13326 #endif
13327         RTE_SET_USED(is_tx);
13328         RTE_SET_USED(key);
13329
13330         switch (ret) {
13331         case 0:
13332                 break;
13333         case -EINVAL:
13334                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13335                 break;
13336         case -ENODEV:
13337                 printf("invalid port_id %d\n", res->port_id);
13338                 break;
13339         case -ENOTSUP:
13340                 printf("not supported on port %d\n", res->port_id);
13341                 break;
13342         default:
13343                 printf("programming error: (%s)\n", strerror(-ret));
13344         }
13345 }
13346
13347 cmdline_parse_inst_t cmd_set_macsec_sa = {
13348         .f = cmd_set_macsec_sa_parsed,
13349         .data = NULL,
13350         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13351         .tokens = {
13352                 (void *)&cmd_macsec_sa_set,
13353                 (void *)&cmd_macsec_sa_macsec,
13354                 (void *)&cmd_macsec_sa_sa,
13355                 (void *)&cmd_macsec_sa_tx_rx,
13356                 (void *)&cmd_macsec_sa_port_id,
13357                 (void *)&cmd_macsec_sa_idx,
13358                 (void *)&cmd_macsec_sa_an,
13359                 (void *)&cmd_macsec_sa_pn,
13360                 (void *)&cmd_macsec_sa_key,
13361                 NULL,
13362         },
13363 };
13364
13365 /* VF unicast promiscuous mode configuration */
13366
13367 /* Common result structure for VF unicast promiscuous mode */
13368 struct cmd_vf_promisc_result {
13369         cmdline_fixed_string_t set;
13370         cmdline_fixed_string_t vf;
13371         cmdline_fixed_string_t promisc;
13372         portid_t port_id;
13373         uint32_t vf_id;
13374         cmdline_fixed_string_t on_off;
13375 };
13376
13377 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13378 cmdline_parse_token_string_t cmd_vf_promisc_set =
13379         TOKEN_STRING_INITIALIZER
13380                 (struct cmd_vf_promisc_result,
13381                  set, "set");
13382 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13383         TOKEN_STRING_INITIALIZER
13384                 (struct cmd_vf_promisc_result,
13385                  vf, "vf");
13386 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13387         TOKEN_STRING_INITIALIZER
13388                 (struct cmd_vf_promisc_result,
13389                  promisc, "promisc");
13390 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13391         TOKEN_NUM_INITIALIZER
13392                 (struct cmd_vf_promisc_result,
13393                  port_id, UINT16);
13394 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13395         TOKEN_NUM_INITIALIZER
13396                 (struct cmd_vf_promisc_result,
13397                  vf_id, UINT32);
13398 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13399         TOKEN_STRING_INITIALIZER
13400                 (struct cmd_vf_promisc_result,
13401                  on_off, "on#off");
13402
13403 static void
13404 cmd_set_vf_promisc_parsed(
13405         void *parsed_result,
13406         __attribute__((unused)) struct cmdline *cl,
13407         __attribute__((unused)) void *data)
13408 {
13409         struct cmd_vf_promisc_result *res = parsed_result;
13410         int ret = -ENOTSUP;
13411
13412         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13413
13414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13415                 return;
13416
13417 #ifdef RTE_LIBRTE_I40E_PMD
13418         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13419                                                   res->vf_id, is_on);
13420 #endif
13421
13422         switch (ret) {
13423         case 0:
13424                 break;
13425         case -EINVAL:
13426                 printf("invalid vf_id %d\n", res->vf_id);
13427                 break;
13428         case -ENODEV:
13429                 printf("invalid port_id %d\n", res->port_id);
13430                 break;
13431         case -ENOTSUP:
13432                 printf("function not implemented\n");
13433                 break;
13434         default:
13435                 printf("programming error: (%s)\n", strerror(-ret));
13436         }
13437 }
13438
13439 cmdline_parse_inst_t cmd_set_vf_promisc = {
13440         .f = cmd_set_vf_promisc_parsed,
13441         .data = NULL,
13442         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13443                 "Set unicast promiscuous mode for a VF from the PF",
13444         .tokens = {
13445                 (void *)&cmd_vf_promisc_set,
13446                 (void *)&cmd_vf_promisc_vf,
13447                 (void *)&cmd_vf_promisc_promisc,
13448                 (void *)&cmd_vf_promisc_port_id,
13449                 (void *)&cmd_vf_promisc_vf_id,
13450                 (void *)&cmd_vf_promisc_on_off,
13451                 NULL,
13452         },
13453 };
13454
13455 /* VF multicast promiscuous mode configuration */
13456
13457 /* Common result structure for VF multicast promiscuous mode */
13458 struct cmd_vf_allmulti_result {
13459         cmdline_fixed_string_t set;
13460         cmdline_fixed_string_t vf;
13461         cmdline_fixed_string_t allmulti;
13462         portid_t port_id;
13463         uint32_t vf_id;
13464         cmdline_fixed_string_t on_off;
13465 };
13466
13467 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13468 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13469         TOKEN_STRING_INITIALIZER
13470                 (struct cmd_vf_allmulti_result,
13471                  set, "set");
13472 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13473         TOKEN_STRING_INITIALIZER
13474                 (struct cmd_vf_allmulti_result,
13475                  vf, "vf");
13476 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_allmulti_result,
13479                  allmulti, "allmulti");
13480 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13481         TOKEN_NUM_INITIALIZER
13482                 (struct cmd_vf_allmulti_result,
13483                  port_id, UINT16);
13484 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13485         TOKEN_NUM_INITIALIZER
13486                 (struct cmd_vf_allmulti_result,
13487                  vf_id, UINT32);
13488 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13489         TOKEN_STRING_INITIALIZER
13490                 (struct cmd_vf_allmulti_result,
13491                  on_off, "on#off");
13492
13493 static void
13494 cmd_set_vf_allmulti_parsed(
13495         void *parsed_result,
13496         __attribute__((unused)) struct cmdline *cl,
13497         __attribute__((unused)) void *data)
13498 {
13499         struct cmd_vf_allmulti_result *res = parsed_result;
13500         int ret = -ENOTSUP;
13501
13502         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13503
13504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13505                 return;
13506
13507 #ifdef RTE_LIBRTE_I40E_PMD
13508         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13509                                                     res->vf_id, is_on);
13510 #endif
13511
13512         switch (ret) {
13513         case 0:
13514                 break;
13515         case -EINVAL:
13516                 printf("invalid vf_id %d\n", res->vf_id);
13517                 break;
13518         case -ENODEV:
13519                 printf("invalid port_id %d\n", res->port_id);
13520                 break;
13521         case -ENOTSUP:
13522                 printf("function not implemented\n");
13523                 break;
13524         default:
13525                 printf("programming error: (%s)\n", strerror(-ret));
13526         }
13527 }
13528
13529 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13530         .f = cmd_set_vf_allmulti_parsed,
13531         .data = NULL,
13532         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13533                 "Set multicast promiscuous mode for a VF from the PF",
13534         .tokens = {
13535                 (void *)&cmd_vf_allmulti_set,
13536                 (void *)&cmd_vf_allmulti_vf,
13537                 (void *)&cmd_vf_allmulti_allmulti,
13538                 (void *)&cmd_vf_allmulti_port_id,
13539                 (void *)&cmd_vf_allmulti_vf_id,
13540                 (void *)&cmd_vf_allmulti_on_off,
13541                 NULL,
13542         },
13543 };
13544
13545 /* vf broadcast mode configuration */
13546
13547 /* Common result structure for vf broadcast */
13548 struct cmd_set_vf_broadcast_result {
13549         cmdline_fixed_string_t set;
13550         cmdline_fixed_string_t vf;
13551         cmdline_fixed_string_t broadcast;
13552         portid_t port_id;
13553         uint16_t vf_id;
13554         cmdline_fixed_string_t on_off;
13555 };
13556
13557 /* Common CLI fields for vf broadcast enable disable */
13558 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13559         TOKEN_STRING_INITIALIZER
13560                 (struct cmd_set_vf_broadcast_result,
13561                  set, "set");
13562 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_set_vf_broadcast_result,
13565                  vf, "vf");
13566 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13567         TOKEN_STRING_INITIALIZER
13568                 (struct cmd_set_vf_broadcast_result,
13569                  broadcast, "broadcast");
13570 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13571         TOKEN_NUM_INITIALIZER
13572                 (struct cmd_set_vf_broadcast_result,
13573                  port_id, UINT16);
13574 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13575         TOKEN_NUM_INITIALIZER
13576                 (struct cmd_set_vf_broadcast_result,
13577                  vf_id, UINT16);
13578 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_set_vf_broadcast_result,
13581                  on_off, "on#off");
13582
13583 static void
13584 cmd_set_vf_broadcast_parsed(
13585         void *parsed_result,
13586         __attribute__((unused)) struct cmdline *cl,
13587         __attribute__((unused)) void *data)
13588 {
13589         struct cmd_set_vf_broadcast_result *res = parsed_result;
13590         int ret = -ENOTSUP;
13591
13592         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13593
13594         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13595                 return;
13596
13597 #ifdef RTE_LIBRTE_I40E_PMD
13598         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13599                                             res->vf_id, is_on);
13600 #endif
13601
13602         switch (ret) {
13603         case 0:
13604                 break;
13605         case -EINVAL:
13606                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13607                 break;
13608         case -ENODEV:
13609                 printf("invalid port_id %d\n", res->port_id);
13610                 break;
13611         case -ENOTSUP:
13612                 printf("function not implemented\n");
13613                 break;
13614         default:
13615                 printf("programming error: (%s)\n", strerror(-ret));
13616         }
13617 }
13618
13619 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13620         .f = cmd_set_vf_broadcast_parsed,
13621         .data = NULL,
13622         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13623         .tokens = {
13624                 (void *)&cmd_set_vf_broadcast_set,
13625                 (void *)&cmd_set_vf_broadcast_vf,
13626                 (void *)&cmd_set_vf_broadcast_broadcast,
13627                 (void *)&cmd_set_vf_broadcast_port_id,
13628                 (void *)&cmd_set_vf_broadcast_vf_id,
13629                 (void *)&cmd_set_vf_broadcast_on_off,
13630                 NULL,
13631         },
13632 };
13633
13634 /* vf vlan tag configuration */
13635
13636 /* Common result structure for vf vlan tag */
13637 struct cmd_set_vf_vlan_tag_result {
13638         cmdline_fixed_string_t set;
13639         cmdline_fixed_string_t vf;
13640         cmdline_fixed_string_t vlan;
13641         cmdline_fixed_string_t tag;
13642         portid_t port_id;
13643         uint16_t vf_id;
13644         cmdline_fixed_string_t on_off;
13645 };
13646
13647 /* Common CLI fields for vf vlan tag enable disable */
13648 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13649         TOKEN_STRING_INITIALIZER
13650                 (struct cmd_set_vf_vlan_tag_result,
13651                  set, "set");
13652 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13653         TOKEN_STRING_INITIALIZER
13654                 (struct cmd_set_vf_vlan_tag_result,
13655                  vf, "vf");
13656 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_set_vf_vlan_tag_result,
13659                  vlan, "vlan");
13660 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13661         TOKEN_STRING_INITIALIZER
13662                 (struct cmd_set_vf_vlan_tag_result,
13663                  tag, "tag");
13664 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13665         TOKEN_NUM_INITIALIZER
13666                 (struct cmd_set_vf_vlan_tag_result,
13667                  port_id, UINT16);
13668 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13669         TOKEN_NUM_INITIALIZER
13670                 (struct cmd_set_vf_vlan_tag_result,
13671                  vf_id, UINT16);
13672 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_set_vf_vlan_tag_result,
13675                  on_off, "on#off");
13676
13677 static void
13678 cmd_set_vf_vlan_tag_parsed(
13679         void *parsed_result,
13680         __attribute__((unused)) struct cmdline *cl,
13681         __attribute__((unused)) void *data)
13682 {
13683         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13684         int ret = -ENOTSUP;
13685
13686         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13687
13688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13689                 return;
13690
13691 #ifdef RTE_LIBRTE_I40E_PMD
13692         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13693                                            res->vf_id, is_on);
13694 #endif
13695
13696         switch (ret) {
13697         case 0:
13698                 break;
13699         case -EINVAL:
13700                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13701                 break;
13702         case -ENODEV:
13703                 printf("invalid port_id %d\n", res->port_id);
13704                 break;
13705         case -ENOTSUP:
13706                 printf("function not implemented\n");
13707                 break;
13708         default:
13709                 printf("programming error: (%s)\n", strerror(-ret));
13710         }
13711 }
13712
13713 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13714         .f = cmd_set_vf_vlan_tag_parsed,
13715         .data = NULL,
13716         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13717         .tokens = {
13718                 (void *)&cmd_set_vf_vlan_tag_set,
13719                 (void *)&cmd_set_vf_vlan_tag_vf,
13720                 (void *)&cmd_set_vf_vlan_tag_vlan,
13721                 (void *)&cmd_set_vf_vlan_tag_tag,
13722                 (void *)&cmd_set_vf_vlan_tag_port_id,
13723                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13724                 (void *)&cmd_set_vf_vlan_tag_on_off,
13725                 NULL,
13726         },
13727 };
13728
13729 /* Common definition of VF and TC TX bandwidth configuration */
13730 struct cmd_vf_tc_bw_result {
13731         cmdline_fixed_string_t set;
13732         cmdline_fixed_string_t vf;
13733         cmdline_fixed_string_t tc;
13734         cmdline_fixed_string_t tx;
13735         cmdline_fixed_string_t min_bw;
13736         cmdline_fixed_string_t max_bw;
13737         cmdline_fixed_string_t strict_link_prio;
13738         portid_t port_id;
13739         uint16_t vf_id;
13740         uint8_t tc_no;
13741         uint32_t bw;
13742         cmdline_fixed_string_t bw_list;
13743         uint8_t tc_map;
13744 };
13745
13746 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13747         TOKEN_STRING_INITIALIZER
13748                 (struct cmd_vf_tc_bw_result,
13749                  set, "set");
13750 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13751         TOKEN_STRING_INITIALIZER
13752                 (struct cmd_vf_tc_bw_result,
13753                  vf, "vf");
13754 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13755         TOKEN_STRING_INITIALIZER
13756                 (struct cmd_vf_tc_bw_result,
13757                  tc, "tc");
13758 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13759         TOKEN_STRING_INITIALIZER
13760                 (struct cmd_vf_tc_bw_result,
13761                  tx, "tx");
13762 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_vf_tc_bw_result,
13765                  strict_link_prio, "strict-link-priority");
13766 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_vf_tc_bw_result,
13769                  min_bw, "min-bandwidth");
13770 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_vf_tc_bw_result,
13773                  max_bw, "max-bandwidth");
13774 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13775         TOKEN_NUM_INITIALIZER
13776                 (struct cmd_vf_tc_bw_result,
13777                  port_id, UINT16);
13778 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13779         TOKEN_NUM_INITIALIZER
13780                 (struct cmd_vf_tc_bw_result,
13781                  vf_id, UINT16);
13782 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13783         TOKEN_NUM_INITIALIZER
13784                 (struct cmd_vf_tc_bw_result,
13785                  tc_no, UINT8);
13786 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13787         TOKEN_NUM_INITIALIZER
13788                 (struct cmd_vf_tc_bw_result,
13789                  bw, UINT32);
13790 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13791         TOKEN_STRING_INITIALIZER
13792                 (struct cmd_vf_tc_bw_result,
13793                  bw_list, NULL);
13794 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13795         TOKEN_NUM_INITIALIZER
13796                 (struct cmd_vf_tc_bw_result,
13797                  tc_map, UINT8);
13798
13799 /* VF max bandwidth setting */
13800 static void
13801 cmd_vf_max_bw_parsed(
13802         void *parsed_result,
13803         __attribute__((unused)) struct cmdline *cl,
13804         __attribute__((unused)) void *data)
13805 {
13806         struct cmd_vf_tc_bw_result *res = parsed_result;
13807         int ret = -ENOTSUP;
13808
13809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13810                 return;
13811
13812 #ifdef RTE_LIBRTE_I40E_PMD
13813         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13814                                          res->vf_id, res->bw);
13815 #endif
13816
13817         switch (ret) {
13818         case 0:
13819                 break;
13820         case -EINVAL:
13821                 printf("invalid vf_id %d or bandwidth %d\n",
13822                        res->vf_id, res->bw);
13823                 break;
13824         case -ENODEV:
13825                 printf("invalid port_id %d\n", res->port_id);
13826                 break;
13827         case -ENOTSUP:
13828                 printf("function not implemented\n");
13829                 break;
13830         default:
13831                 printf("programming error: (%s)\n", strerror(-ret));
13832         }
13833 }
13834
13835 cmdline_parse_inst_t cmd_vf_max_bw = {
13836         .f = cmd_vf_max_bw_parsed,
13837         .data = NULL,
13838         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13839         .tokens = {
13840                 (void *)&cmd_vf_tc_bw_set,
13841                 (void *)&cmd_vf_tc_bw_vf,
13842                 (void *)&cmd_vf_tc_bw_tx,
13843                 (void *)&cmd_vf_tc_bw_max_bw,
13844                 (void *)&cmd_vf_tc_bw_port_id,
13845                 (void *)&cmd_vf_tc_bw_vf_id,
13846                 (void *)&cmd_vf_tc_bw_bw,
13847                 NULL,
13848         },
13849 };
13850
13851 static int
13852 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13853                            uint8_t *tc_num,
13854                            char *str)
13855 {
13856         uint32_t size;
13857         const char *p, *p0 = str;
13858         char s[256];
13859         char *end;
13860         char *str_fld[16];
13861         uint16_t i;
13862         int ret;
13863
13864         p = strchr(p0, '(');
13865         if (p == NULL) {
13866                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13867                 return -1;
13868         }
13869         p++;
13870         p0 = strchr(p, ')');
13871         if (p0 == NULL) {
13872                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13873                 return -1;
13874         }
13875         size = p0 - p;
13876         if (size >= sizeof(s)) {
13877                 printf("The string size exceeds the internal buffer size\n");
13878                 return -1;
13879         }
13880         snprintf(s, sizeof(s), "%.*s", size, p);
13881         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13882         if (ret <= 0) {
13883                 printf("Failed to get the bandwidth list. ");
13884                 return -1;
13885         }
13886         *tc_num = ret;
13887         for (i = 0; i < ret; i++)
13888                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13889
13890         return 0;
13891 }
13892
13893 /* TC min bandwidth setting */
13894 static void
13895 cmd_vf_tc_min_bw_parsed(
13896         void *parsed_result,
13897         __attribute__((unused)) struct cmdline *cl,
13898         __attribute__((unused)) void *data)
13899 {
13900         struct cmd_vf_tc_bw_result *res = parsed_result;
13901         uint8_t tc_num;
13902         uint8_t bw[16];
13903         int ret = -ENOTSUP;
13904
13905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13906                 return;
13907
13908         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13909         if (ret)
13910                 return;
13911
13912 #ifdef RTE_LIBRTE_I40E_PMD
13913         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13914                                               tc_num, bw);
13915 #endif
13916
13917         switch (ret) {
13918         case 0:
13919                 break;
13920         case -EINVAL:
13921                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13922                 break;
13923         case -ENODEV:
13924                 printf("invalid port_id %d\n", res->port_id);
13925                 break;
13926         case -ENOTSUP:
13927                 printf("function not implemented\n");
13928                 break;
13929         default:
13930                 printf("programming error: (%s)\n", strerror(-ret));
13931         }
13932 }
13933
13934 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13935         .f = cmd_vf_tc_min_bw_parsed,
13936         .data = NULL,
13937         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13938                     " <bw1, bw2, ...>",
13939         .tokens = {
13940                 (void *)&cmd_vf_tc_bw_set,
13941                 (void *)&cmd_vf_tc_bw_vf,
13942                 (void *)&cmd_vf_tc_bw_tc,
13943                 (void *)&cmd_vf_tc_bw_tx,
13944                 (void *)&cmd_vf_tc_bw_min_bw,
13945                 (void *)&cmd_vf_tc_bw_port_id,
13946                 (void *)&cmd_vf_tc_bw_vf_id,
13947                 (void *)&cmd_vf_tc_bw_bw_list,
13948                 NULL,
13949         },
13950 };
13951
13952 static void
13953 cmd_tc_min_bw_parsed(
13954         void *parsed_result,
13955         __attribute__((unused)) struct cmdline *cl,
13956         __attribute__((unused)) void *data)
13957 {
13958         struct cmd_vf_tc_bw_result *res = parsed_result;
13959         struct rte_port *port;
13960         uint8_t tc_num;
13961         uint8_t bw[16];
13962         int ret = -ENOTSUP;
13963
13964         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13965                 return;
13966
13967         port = &ports[res->port_id];
13968         /** Check if the port is not started **/
13969         if (port->port_status != RTE_PORT_STOPPED) {
13970                 printf("Please stop port %d first\n", res->port_id);
13971                 return;
13972         }
13973
13974         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13975         if (ret)
13976                 return;
13977
13978 #ifdef RTE_LIBRTE_IXGBE_PMD
13979         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13980 #endif
13981
13982         switch (ret) {
13983         case 0:
13984                 break;
13985         case -EINVAL:
13986                 printf("invalid bandwidth\n");
13987                 break;
13988         case -ENODEV:
13989                 printf("invalid port_id %d\n", res->port_id);
13990                 break;
13991         case -ENOTSUP:
13992                 printf("function not implemented\n");
13993                 break;
13994         default:
13995                 printf("programming error: (%s)\n", strerror(-ret));
13996         }
13997 }
13998
13999 cmdline_parse_inst_t cmd_tc_min_bw = {
14000         .f = cmd_tc_min_bw_parsed,
14001         .data = NULL,
14002         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14003         .tokens = {
14004                 (void *)&cmd_vf_tc_bw_set,
14005                 (void *)&cmd_vf_tc_bw_tc,
14006                 (void *)&cmd_vf_tc_bw_tx,
14007                 (void *)&cmd_vf_tc_bw_min_bw,
14008                 (void *)&cmd_vf_tc_bw_port_id,
14009                 (void *)&cmd_vf_tc_bw_bw_list,
14010                 NULL,
14011         },
14012 };
14013
14014 /* TC max bandwidth setting */
14015 static void
14016 cmd_vf_tc_max_bw_parsed(
14017         void *parsed_result,
14018         __attribute__((unused)) struct cmdline *cl,
14019         __attribute__((unused)) void *data)
14020 {
14021         struct cmd_vf_tc_bw_result *res = parsed_result;
14022         int ret = -ENOTSUP;
14023
14024         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14025                 return;
14026
14027 #ifdef RTE_LIBRTE_I40E_PMD
14028         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14029                                             res->tc_no, res->bw);
14030 #endif
14031
14032         switch (ret) {
14033         case 0:
14034                 break;
14035         case -EINVAL:
14036                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14037                        res->vf_id, res->tc_no, res->bw);
14038                 break;
14039         case -ENODEV:
14040                 printf("invalid port_id %d\n", res->port_id);
14041                 break;
14042         case -ENOTSUP:
14043                 printf("function not implemented\n");
14044                 break;
14045         default:
14046                 printf("programming error: (%s)\n", strerror(-ret));
14047         }
14048 }
14049
14050 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14051         .f = cmd_vf_tc_max_bw_parsed,
14052         .data = NULL,
14053         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14054                     " <bandwidth>",
14055         .tokens = {
14056                 (void *)&cmd_vf_tc_bw_set,
14057                 (void *)&cmd_vf_tc_bw_vf,
14058                 (void *)&cmd_vf_tc_bw_tc,
14059                 (void *)&cmd_vf_tc_bw_tx,
14060                 (void *)&cmd_vf_tc_bw_max_bw,
14061                 (void *)&cmd_vf_tc_bw_port_id,
14062                 (void *)&cmd_vf_tc_bw_vf_id,
14063                 (void *)&cmd_vf_tc_bw_tc_no,
14064                 (void *)&cmd_vf_tc_bw_bw,
14065                 NULL,
14066         },
14067 };
14068
14069
14070 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14071
14072 /* *** Set Port default Traffic Management Hierarchy *** */
14073 struct cmd_set_port_tm_hierarchy_default_result {
14074         cmdline_fixed_string_t set;
14075         cmdline_fixed_string_t port;
14076         cmdline_fixed_string_t tm;
14077         cmdline_fixed_string_t hierarchy;
14078         cmdline_fixed_string_t def;
14079         portid_t port_id;
14080 };
14081
14082 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14083         TOKEN_STRING_INITIALIZER(
14084                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14085 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14086         TOKEN_STRING_INITIALIZER(
14087                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14088 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14089         TOKEN_STRING_INITIALIZER(
14090                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14091 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14092         TOKEN_STRING_INITIALIZER(
14093                 struct cmd_set_port_tm_hierarchy_default_result,
14094                         hierarchy, "hierarchy");
14095 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14096         TOKEN_STRING_INITIALIZER(
14097                 struct cmd_set_port_tm_hierarchy_default_result,
14098                         def, "default");
14099 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14100         TOKEN_NUM_INITIALIZER(
14101                 struct cmd_set_port_tm_hierarchy_default_result,
14102                         port_id, UINT16);
14103
14104 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14105         __attribute__((unused)) struct cmdline *cl,
14106         __attribute__((unused)) void *data)
14107 {
14108         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14109         struct rte_port *p;
14110         portid_t port_id = res->port_id;
14111
14112         if (port_id_is_invalid(port_id, ENABLED_WARN))
14113                 return;
14114
14115         p = &ports[port_id];
14116
14117         /* Port tm flag */
14118         if (p->softport.tm_flag == 0) {
14119                 printf("  tm not enabled on port %u (error)\n", port_id);
14120                 return;
14121         }
14122
14123         /* Forward mode: tm */
14124         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14125                 printf("  tm mode not enabled(error)\n");
14126                 return;
14127         }
14128
14129         /* Set the default tm hierarchy */
14130         p->softport.tm.default_hierarchy_enable = 1;
14131 }
14132
14133 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14134         .f = cmd_set_port_tm_hierarchy_default_parsed,
14135         .data = NULL,
14136         .help_str = "set port tm hierarchy default <port_id>",
14137         .tokens = {
14138                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14139                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14140                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14141                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14142                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14143                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14144                 NULL,
14145         },
14146 };
14147 #endif
14148
14149 /* Strict link priority scheduling mode setting */
14150 static void
14151 cmd_strict_link_prio_parsed(
14152         void *parsed_result,
14153         __attribute__((unused)) struct cmdline *cl,
14154         __attribute__((unused)) void *data)
14155 {
14156         struct cmd_vf_tc_bw_result *res = parsed_result;
14157         int ret = -ENOTSUP;
14158
14159         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14160                 return;
14161
14162 #ifdef RTE_LIBRTE_I40E_PMD
14163         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14164 #endif
14165
14166         switch (ret) {
14167         case 0:
14168                 break;
14169         case -EINVAL:
14170                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14171                 break;
14172         case -ENODEV:
14173                 printf("invalid port_id %d\n", res->port_id);
14174                 break;
14175         case -ENOTSUP:
14176                 printf("function not implemented\n");
14177                 break;
14178         default:
14179                 printf("programming error: (%s)\n", strerror(-ret));
14180         }
14181 }
14182
14183 cmdline_parse_inst_t cmd_strict_link_prio = {
14184         .f = cmd_strict_link_prio_parsed,
14185         .data = NULL,
14186         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14187         .tokens = {
14188                 (void *)&cmd_vf_tc_bw_set,
14189                 (void *)&cmd_vf_tc_bw_tx,
14190                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14191                 (void *)&cmd_vf_tc_bw_port_id,
14192                 (void *)&cmd_vf_tc_bw_tc_map,
14193                 NULL,
14194         },
14195 };
14196
14197 /* Load dynamic device personalization*/
14198 struct cmd_ddp_add_result {
14199         cmdline_fixed_string_t ddp;
14200         cmdline_fixed_string_t add;
14201         portid_t port_id;
14202         char filepath[];
14203 };
14204
14205 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14206         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14207 cmdline_parse_token_string_t cmd_ddp_add_add =
14208         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14209 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14210         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14211 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14212         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14213
14214 static void
14215 cmd_ddp_add_parsed(
14216         void *parsed_result,
14217         __attribute__((unused)) struct cmdline *cl,
14218         __attribute__((unused)) void *data)
14219 {
14220         struct cmd_ddp_add_result *res = parsed_result;
14221         uint8_t *buff;
14222         uint32_t size;
14223         char *filepath;
14224         char *file_fld[2];
14225         int file_num;
14226         int ret = -ENOTSUP;
14227
14228         if (res->port_id > nb_ports) {
14229                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14230                 return;
14231         }
14232
14233         if (!all_ports_stopped()) {
14234                 printf("Please stop all ports first\n");
14235                 return;
14236         }
14237
14238         filepath = strdup(res->filepath);
14239         if (filepath == NULL) {
14240                 printf("Failed to allocate memory\n");
14241                 return;
14242         }
14243         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14244
14245         buff = open_ddp_package_file(file_fld[0], &size);
14246         if (!buff) {
14247                 free((void *)filepath);
14248                 return;
14249         }
14250
14251 #ifdef RTE_LIBRTE_I40E_PMD
14252         if (ret == -ENOTSUP)
14253                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14254                                                buff, size,
14255                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14256 #endif
14257
14258         if (ret == -EEXIST)
14259                 printf("Profile has already existed.\n");
14260         else if (ret < 0)
14261                 printf("Failed to load profile.\n");
14262         else if (file_num == 2)
14263                 save_ddp_package_file(file_fld[1], buff, size);
14264
14265         close_ddp_package_file(buff);
14266         free((void *)filepath);
14267 }
14268
14269 cmdline_parse_inst_t cmd_ddp_add = {
14270         .f = cmd_ddp_add_parsed,
14271         .data = NULL,
14272         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14273         .tokens = {
14274                 (void *)&cmd_ddp_add_ddp,
14275                 (void *)&cmd_ddp_add_add,
14276                 (void *)&cmd_ddp_add_port_id,
14277                 (void *)&cmd_ddp_add_filepath,
14278                 NULL,
14279         },
14280 };
14281
14282 /* Delete dynamic device personalization*/
14283 struct cmd_ddp_del_result {
14284         cmdline_fixed_string_t ddp;
14285         cmdline_fixed_string_t del;
14286         portid_t port_id;
14287         char filepath[];
14288 };
14289
14290 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14291         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14292 cmdline_parse_token_string_t cmd_ddp_del_del =
14293         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14294 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14295         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14296 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14297         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14298
14299 static void
14300 cmd_ddp_del_parsed(
14301         void *parsed_result,
14302         __attribute__((unused)) struct cmdline *cl,
14303         __attribute__((unused)) void *data)
14304 {
14305         struct cmd_ddp_del_result *res = parsed_result;
14306         uint8_t *buff;
14307         uint32_t size;
14308         int ret = -ENOTSUP;
14309
14310         if (res->port_id > nb_ports) {
14311                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14312                 return;
14313         }
14314
14315         if (!all_ports_stopped()) {
14316                 printf("Please stop all ports first\n");
14317                 return;
14318         }
14319
14320         buff = open_ddp_package_file(res->filepath, &size);
14321         if (!buff)
14322                 return;
14323
14324 #ifdef RTE_LIBRTE_I40E_PMD
14325         if (ret == -ENOTSUP)
14326                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14327                                                buff, size,
14328                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14329 #endif
14330
14331         if (ret == -EACCES)
14332                 printf("Profile does not exist.\n");
14333         else if (ret < 0)
14334                 printf("Failed to delete profile.\n");
14335
14336         close_ddp_package_file(buff);
14337 }
14338
14339 cmdline_parse_inst_t cmd_ddp_del = {
14340         .f = cmd_ddp_del_parsed,
14341         .data = NULL,
14342         .help_str = "ddp del <port_id> <profile_path>",
14343         .tokens = {
14344                 (void *)&cmd_ddp_del_ddp,
14345                 (void *)&cmd_ddp_del_del,
14346                 (void *)&cmd_ddp_del_port_id,
14347                 (void *)&cmd_ddp_del_filepath,
14348                 NULL,
14349         },
14350 };
14351
14352 /* Get dynamic device personalization profile info */
14353 struct cmd_ddp_info_result {
14354         cmdline_fixed_string_t ddp;
14355         cmdline_fixed_string_t get;
14356         cmdline_fixed_string_t info;
14357         char filepath[];
14358 };
14359
14360 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14361         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14362 cmdline_parse_token_string_t cmd_ddp_info_get =
14363         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14364 cmdline_parse_token_string_t cmd_ddp_info_info =
14365         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14366 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14367         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14368
14369 static void
14370 cmd_ddp_info_parsed(
14371         void *parsed_result,
14372         __attribute__((unused)) struct cmdline *cl,
14373         __attribute__((unused)) void *data)
14374 {
14375         struct cmd_ddp_info_result *res = parsed_result;
14376         uint8_t *pkg;
14377         uint32_t pkg_size;
14378         int ret = -ENOTSUP;
14379 #ifdef RTE_LIBRTE_I40E_PMD
14380         uint32_t i, j, n;
14381         uint8_t *buff;
14382         uint32_t buff_size = 0;
14383         struct rte_pmd_i40e_profile_info info;
14384         uint32_t dev_num = 0;
14385         struct rte_pmd_i40e_ddp_device_id *devs;
14386         uint32_t proto_num = 0;
14387         struct rte_pmd_i40e_proto_info *proto = NULL;
14388         uint32_t pctype_num = 0;
14389         struct rte_pmd_i40e_ptype_info *pctype;
14390         uint32_t ptype_num = 0;
14391         struct rte_pmd_i40e_ptype_info *ptype;
14392         uint8_t proto_id;
14393
14394 #endif
14395
14396         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14397         if (!pkg)
14398                 return;
14399
14400 #ifdef RTE_LIBRTE_I40E_PMD
14401         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14402                                 (uint8_t *)&info, sizeof(info),
14403                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14404         if (!ret) {
14405                 printf("Global Track id:       0x%x\n", info.track_id);
14406                 printf("Global Version:        %d.%d.%d.%d\n",
14407                         info.version.major,
14408                         info.version.minor,
14409                         info.version.update,
14410                         info.version.draft);
14411                 printf("Global Package name:   %s\n\n", info.name);
14412         }
14413
14414         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14415                                 (uint8_t *)&info, sizeof(info),
14416                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14417         if (!ret) {
14418                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14419                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14420                         info.version.major,
14421                         info.version.minor,
14422                         info.version.update,
14423                         info.version.draft);
14424                 printf("i40e Profile name:     %s\n\n", info.name);
14425         }
14426
14427         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14428                                 (uint8_t *)&buff_size, sizeof(buff_size),
14429                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14430         if (!ret && buff_size) {
14431                 buff = (uint8_t *)malloc(buff_size);
14432                 if (buff) {
14433                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14434                                                 buff, buff_size,
14435                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14436                         if (!ret)
14437                                 printf("Package Notes:\n%s\n\n", buff);
14438                         free(buff);
14439                 }
14440         }
14441
14442         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14443                                 (uint8_t *)&dev_num, sizeof(dev_num),
14444                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14445         if (!ret && dev_num) {
14446                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14447                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14448                 if (devs) {
14449                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14450                                                 (uint8_t *)devs, buff_size,
14451                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14452                         if (!ret) {
14453                                 printf("List of supported devices:\n");
14454                                 for (i = 0; i < dev_num; i++) {
14455                                         printf("  %04X:%04X %04X:%04X\n",
14456                                                 devs[i].vendor_dev_id >> 16,
14457                                                 devs[i].vendor_dev_id & 0xFFFF,
14458                                                 devs[i].sub_vendor_dev_id >> 16,
14459                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14460                                 }
14461                                 printf("\n");
14462                         }
14463                         free(devs);
14464                 }
14465         }
14466
14467         /* get information about protocols and packet types */
14468         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14469                 (uint8_t *)&proto_num, sizeof(proto_num),
14470                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14471         if (ret || !proto_num)
14472                 goto no_print_return;
14473
14474         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14475         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14476         if (!proto)
14477                 goto no_print_return;
14478
14479         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14480                                         buff_size,
14481                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14482         if (!ret) {
14483                 printf("List of used protocols:\n");
14484                 for (i = 0; i < proto_num; i++)
14485                         printf("  %2u: %s\n", proto[i].proto_id,
14486                                proto[i].name);
14487                 printf("\n");
14488         }
14489         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14490                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14491                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14492         if (ret || !pctype_num)
14493                 goto no_print_pctypes;
14494
14495         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14496         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14497         if (!pctype)
14498                 goto no_print_pctypes;
14499
14500         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14501                                         buff_size,
14502                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14503         if (ret) {
14504                 free(pctype);
14505                 goto no_print_pctypes;
14506         }
14507
14508         printf("List of defined packet classification types:\n");
14509         for (i = 0; i < pctype_num; i++) {
14510                 printf("  %2u:", pctype[i].ptype_id);
14511                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14512                         proto_id = pctype[i].protocols[j];
14513                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14514                                 for (n = 0; n < proto_num; n++) {
14515                                         if (proto[n].proto_id == proto_id) {
14516                                                 printf(" %s", proto[n].name);
14517                                                 break;
14518                                         }
14519                                 }
14520                         }
14521                 }
14522                 printf("\n");
14523         }
14524         printf("\n");
14525         free(pctype);
14526
14527 no_print_pctypes:
14528
14529         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14530                                         sizeof(ptype_num),
14531                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14532         if (ret || !ptype_num)
14533                 goto no_print_return;
14534
14535         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14536         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14537         if (!ptype)
14538                 goto no_print_return;
14539
14540         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14541                                         buff_size,
14542                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14543         if (ret) {
14544                 free(ptype);
14545                 goto no_print_return;
14546         }
14547         printf("List of defined packet types:\n");
14548         for (i = 0; i < ptype_num; i++) {
14549                 printf("  %2u:", ptype[i].ptype_id);
14550                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14551                         proto_id = ptype[i].protocols[j];
14552                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14553                                 for (n = 0; n < proto_num; n++) {
14554                                         if (proto[n].proto_id == proto_id) {
14555                                                 printf(" %s", proto[n].name);
14556                                                 break;
14557                                         }
14558                                 }
14559                         }
14560                 }
14561                 printf("\n");
14562         }
14563         free(ptype);
14564         printf("\n");
14565
14566         ret = 0;
14567 no_print_return:
14568         if (proto)
14569                 free(proto);
14570 #endif
14571         if (ret == -ENOTSUP)
14572                 printf("Function not supported in PMD driver\n");
14573         close_ddp_package_file(pkg);
14574 }
14575
14576 cmdline_parse_inst_t cmd_ddp_get_info = {
14577         .f = cmd_ddp_info_parsed,
14578         .data = NULL,
14579         .help_str = "ddp get info <profile_path>",
14580         .tokens = {
14581                 (void *)&cmd_ddp_info_ddp,
14582                 (void *)&cmd_ddp_info_get,
14583                 (void *)&cmd_ddp_info_info,
14584                 (void *)&cmd_ddp_info_filepath,
14585                 NULL,
14586         },
14587 };
14588
14589 /* Get dynamic device personalization profile info list*/
14590 #define PROFILE_INFO_SIZE 48
14591 #define MAX_PROFILE_NUM 16
14592
14593 struct cmd_ddp_get_list_result {
14594         cmdline_fixed_string_t ddp;
14595         cmdline_fixed_string_t get;
14596         cmdline_fixed_string_t list;
14597         portid_t port_id;
14598 };
14599
14600 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14601         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14602 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14603         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14604 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14605         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14606 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14607         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14608
14609 static void
14610 cmd_ddp_get_list_parsed(
14611         void *parsed_result,
14612         __attribute__((unused)) struct cmdline *cl,
14613         __attribute__((unused)) void *data)
14614 {
14615         struct cmd_ddp_get_list_result *res = parsed_result;
14616 #ifdef RTE_LIBRTE_I40E_PMD
14617         struct rte_pmd_i40e_profile_list *p_list;
14618         struct rte_pmd_i40e_profile_info *p_info;
14619         uint32_t p_num;
14620         uint32_t size;
14621         uint32_t i;
14622 #endif
14623         int ret = -ENOTSUP;
14624
14625         if (res->port_id > nb_ports) {
14626                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14627                 return;
14628         }
14629
14630 #ifdef RTE_LIBRTE_I40E_PMD
14631         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14632         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14633         if (!p_list)
14634                 printf("%s: Failed to malloc buffer\n", __func__);
14635
14636         if (ret == -ENOTSUP)
14637                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14638                                                 (uint8_t *)p_list, size);
14639
14640         if (!ret) {
14641                 p_num = p_list->p_count;
14642                 printf("Profile number is: %d\n\n", p_num);
14643
14644                 for (i = 0; i < p_num; i++) {
14645                         p_info = &p_list->p_info[i];
14646                         printf("Profile %d:\n", i);
14647                         printf("Track id:     0x%x\n", p_info->track_id);
14648                         printf("Version:      %d.%d.%d.%d\n",
14649                                p_info->version.major,
14650                                p_info->version.minor,
14651                                p_info->version.update,
14652                                p_info->version.draft);
14653                         printf("Profile name: %s\n\n", p_info->name);
14654                 }
14655         }
14656
14657         free(p_list);
14658 #endif
14659
14660         if (ret < 0)
14661                 printf("Failed to get ddp list\n");
14662 }
14663
14664 cmdline_parse_inst_t cmd_ddp_get_list = {
14665         .f = cmd_ddp_get_list_parsed,
14666         .data = NULL,
14667         .help_str = "ddp get list <port_id>",
14668         .tokens = {
14669                 (void *)&cmd_ddp_get_list_ddp,
14670                 (void *)&cmd_ddp_get_list_get,
14671                 (void *)&cmd_ddp_get_list_list,
14672                 (void *)&cmd_ddp_get_list_port_id,
14673                 NULL,
14674         },
14675 };
14676
14677 /* show vf stats */
14678
14679 /* Common result structure for show vf stats */
14680 struct cmd_show_vf_stats_result {
14681         cmdline_fixed_string_t show;
14682         cmdline_fixed_string_t vf;
14683         cmdline_fixed_string_t stats;
14684         portid_t port_id;
14685         uint16_t vf_id;
14686 };
14687
14688 /* Common CLI fields show vf stats*/
14689 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14690         TOKEN_STRING_INITIALIZER
14691                 (struct cmd_show_vf_stats_result,
14692                  show, "show");
14693 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14694         TOKEN_STRING_INITIALIZER
14695                 (struct cmd_show_vf_stats_result,
14696                  vf, "vf");
14697 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14698         TOKEN_STRING_INITIALIZER
14699                 (struct cmd_show_vf_stats_result,
14700                  stats, "stats");
14701 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14702         TOKEN_NUM_INITIALIZER
14703                 (struct cmd_show_vf_stats_result,
14704                  port_id, UINT16);
14705 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14706         TOKEN_NUM_INITIALIZER
14707                 (struct cmd_show_vf_stats_result,
14708                  vf_id, UINT16);
14709
14710 static void
14711 cmd_show_vf_stats_parsed(
14712         void *parsed_result,
14713         __attribute__((unused)) struct cmdline *cl,
14714         __attribute__((unused)) void *data)
14715 {
14716         struct cmd_show_vf_stats_result *res = parsed_result;
14717         struct rte_eth_stats stats;
14718         int ret = -ENOTSUP;
14719         static const char *nic_stats_border = "########################";
14720
14721         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14722                 return;
14723
14724         memset(&stats, 0, sizeof(stats));
14725
14726 #ifdef RTE_LIBRTE_I40E_PMD
14727         if (ret == -ENOTSUP)
14728                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14729                                                 res->vf_id,
14730                                                 &stats);
14731 #endif
14732 #ifdef RTE_LIBRTE_BNXT_PMD
14733         if (ret == -ENOTSUP)
14734                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14735                                                 res->vf_id,
14736                                                 &stats);
14737 #endif
14738
14739         switch (ret) {
14740         case 0:
14741                 break;
14742         case -EINVAL:
14743                 printf("invalid vf_id %d\n", res->vf_id);
14744                 break;
14745         case -ENODEV:
14746                 printf("invalid port_id %d\n", res->port_id);
14747                 break;
14748         case -ENOTSUP:
14749                 printf("function not implemented\n");
14750                 break;
14751         default:
14752                 printf("programming error: (%s)\n", strerror(-ret));
14753         }
14754
14755         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14756                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14757
14758         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14759                "%-"PRIu64"\n",
14760                stats.ipackets, stats.imissed, stats.ibytes);
14761         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14762         printf("  RX-nombuf:  %-10"PRIu64"\n",
14763                stats.rx_nombuf);
14764         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14765                "%-"PRIu64"\n",
14766                stats.opackets, stats.oerrors, stats.obytes);
14767
14768         printf("  %s############################%s\n",
14769                                nic_stats_border, nic_stats_border);
14770 }
14771
14772 cmdline_parse_inst_t cmd_show_vf_stats = {
14773         .f = cmd_show_vf_stats_parsed,
14774         .data = NULL,
14775         .help_str = "show vf stats <port_id> <vf_id>",
14776         .tokens = {
14777                 (void *)&cmd_show_vf_stats_show,
14778                 (void *)&cmd_show_vf_stats_vf,
14779                 (void *)&cmd_show_vf_stats_stats,
14780                 (void *)&cmd_show_vf_stats_port_id,
14781                 (void *)&cmd_show_vf_stats_vf_id,
14782                 NULL,
14783         },
14784 };
14785
14786 /* clear vf stats */
14787
14788 /* Common result structure for clear vf stats */
14789 struct cmd_clear_vf_stats_result {
14790         cmdline_fixed_string_t clear;
14791         cmdline_fixed_string_t vf;
14792         cmdline_fixed_string_t stats;
14793         portid_t port_id;
14794         uint16_t vf_id;
14795 };
14796
14797 /* Common CLI fields clear vf stats*/
14798 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14799         TOKEN_STRING_INITIALIZER
14800                 (struct cmd_clear_vf_stats_result,
14801                  clear, "clear");
14802 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14803         TOKEN_STRING_INITIALIZER
14804                 (struct cmd_clear_vf_stats_result,
14805                  vf, "vf");
14806 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14807         TOKEN_STRING_INITIALIZER
14808                 (struct cmd_clear_vf_stats_result,
14809                  stats, "stats");
14810 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14811         TOKEN_NUM_INITIALIZER
14812                 (struct cmd_clear_vf_stats_result,
14813                  port_id, UINT16);
14814 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14815         TOKEN_NUM_INITIALIZER
14816                 (struct cmd_clear_vf_stats_result,
14817                  vf_id, UINT16);
14818
14819 static void
14820 cmd_clear_vf_stats_parsed(
14821         void *parsed_result,
14822         __attribute__((unused)) struct cmdline *cl,
14823         __attribute__((unused)) void *data)
14824 {
14825         struct cmd_clear_vf_stats_result *res = parsed_result;
14826         int ret = -ENOTSUP;
14827
14828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14829                 return;
14830
14831 #ifdef RTE_LIBRTE_I40E_PMD
14832         if (ret == -ENOTSUP)
14833                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14834                                                   res->vf_id);
14835 #endif
14836 #ifdef RTE_LIBRTE_BNXT_PMD
14837         if (ret == -ENOTSUP)
14838                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14839                                                   res->vf_id);
14840 #endif
14841
14842         switch (ret) {
14843         case 0:
14844                 break;
14845         case -EINVAL:
14846                 printf("invalid vf_id %d\n", res->vf_id);
14847                 break;
14848         case -ENODEV:
14849                 printf("invalid port_id %d\n", res->port_id);
14850                 break;
14851         case -ENOTSUP:
14852                 printf("function not implemented\n");
14853                 break;
14854         default:
14855                 printf("programming error: (%s)\n", strerror(-ret));
14856         }
14857 }
14858
14859 cmdline_parse_inst_t cmd_clear_vf_stats = {
14860         .f = cmd_clear_vf_stats_parsed,
14861         .data = NULL,
14862         .help_str = "clear vf stats <port_id> <vf_id>",
14863         .tokens = {
14864                 (void *)&cmd_clear_vf_stats_clear,
14865                 (void *)&cmd_clear_vf_stats_vf,
14866                 (void *)&cmd_clear_vf_stats_stats,
14867                 (void *)&cmd_clear_vf_stats_port_id,
14868                 (void *)&cmd_clear_vf_stats_vf_id,
14869                 NULL,
14870         },
14871 };
14872
14873 /* port config pctype mapping reset */
14874
14875 /* Common result structure for port config pctype mapping reset */
14876 struct cmd_pctype_mapping_reset_result {
14877         cmdline_fixed_string_t port;
14878         cmdline_fixed_string_t config;
14879         portid_t port_id;
14880         cmdline_fixed_string_t pctype;
14881         cmdline_fixed_string_t mapping;
14882         cmdline_fixed_string_t reset;
14883 };
14884
14885 /* Common CLI fields for port config pctype mapping reset*/
14886 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14887         TOKEN_STRING_INITIALIZER
14888                 (struct cmd_pctype_mapping_reset_result,
14889                  port, "port");
14890 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14891         TOKEN_STRING_INITIALIZER
14892                 (struct cmd_pctype_mapping_reset_result,
14893                  config, "config");
14894 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14895         TOKEN_NUM_INITIALIZER
14896                 (struct cmd_pctype_mapping_reset_result,
14897                  port_id, UINT16);
14898 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14899         TOKEN_STRING_INITIALIZER
14900                 (struct cmd_pctype_mapping_reset_result,
14901                  pctype, "pctype");
14902 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14903         TOKEN_STRING_INITIALIZER
14904                 (struct cmd_pctype_mapping_reset_result,
14905                  mapping, "mapping");
14906 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14907         TOKEN_STRING_INITIALIZER
14908                 (struct cmd_pctype_mapping_reset_result,
14909                  reset, "reset");
14910
14911 static void
14912 cmd_pctype_mapping_reset_parsed(
14913         void *parsed_result,
14914         __attribute__((unused)) struct cmdline *cl,
14915         __attribute__((unused)) void *data)
14916 {
14917         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14918         int ret = -ENOTSUP;
14919
14920         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14921                 return;
14922
14923 #ifdef RTE_LIBRTE_I40E_PMD
14924         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14925 #endif
14926
14927         switch (ret) {
14928         case 0:
14929                 break;
14930         case -ENODEV:
14931                 printf("invalid port_id %d\n", res->port_id);
14932                 break;
14933         case -ENOTSUP:
14934                 printf("function not implemented\n");
14935                 break;
14936         default:
14937                 printf("programming error: (%s)\n", strerror(-ret));
14938         }
14939 }
14940
14941 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14942         .f = cmd_pctype_mapping_reset_parsed,
14943         .data = NULL,
14944         .help_str = "port config <port_id> pctype mapping reset",
14945         .tokens = {
14946                 (void *)&cmd_pctype_mapping_reset_port,
14947                 (void *)&cmd_pctype_mapping_reset_config,
14948                 (void *)&cmd_pctype_mapping_reset_port_id,
14949                 (void *)&cmd_pctype_mapping_reset_pctype,
14950                 (void *)&cmd_pctype_mapping_reset_mapping,
14951                 (void *)&cmd_pctype_mapping_reset_reset,
14952                 NULL,
14953         },
14954 };
14955
14956 /* show port pctype mapping */
14957
14958 /* Common result structure for show port pctype mapping */
14959 struct cmd_pctype_mapping_get_result {
14960         cmdline_fixed_string_t show;
14961         cmdline_fixed_string_t port;
14962         portid_t port_id;
14963         cmdline_fixed_string_t pctype;
14964         cmdline_fixed_string_t mapping;
14965 };
14966
14967 /* Common CLI fields for pctype mapping get */
14968 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14969         TOKEN_STRING_INITIALIZER
14970                 (struct cmd_pctype_mapping_get_result,
14971                  show, "show");
14972 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14973         TOKEN_STRING_INITIALIZER
14974                 (struct cmd_pctype_mapping_get_result,
14975                  port, "port");
14976 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14977         TOKEN_NUM_INITIALIZER
14978                 (struct cmd_pctype_mapping_get_result,
14979                  port_id, UINT16);
14980 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14981         TOKEN_STRING_INITIALIZER
14982                 (struct cmd_pctype_mapping_get_result,
14983                  pctype, "pctype");
14984 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14985         TOKEN_STRING_INITIALIZER
14986                 (struct cmd_pctype_mapping_get_result,
14987                  mapping, "mapping");
14988
14989 static void
14990 cmd_pctype_mapping_get_parsed(
14991         void *parsed_result,
14992         __attribute__((unused)) struct cmdline *cl,
14993         __attribute__((unused)) void *data)
14994 {
14995         struct cmd_pctype_mapping_get_result *res = parsed_result;
14996         int ret = -ENOTSUP;
14997 #ifdef RTE_LIBRTE_I40E_PMD
14998         struct rte_pmd_i40e_flow_type_mapping
14999                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15000         int i, j, first_pctype;
15001 #endif
15002
15003         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15004                 return;
15005
15006 #ifdef RTE_LIBRTE_I40E_PMD
15007         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15008 #endif
15009
15010         switch (ret) {
15011         case 0:
15012                 break;
15013         case -ENODEV:
15014                 printf("invalid port_id %d\n", res->port_id);
15015                 return;
15016         case -ENOTSUP:
15017                 printf("function not implemented\n");
15018                 return;
15019         default:
15020                 printf("programming error: (%s)\n", strerror(-ret));
15021                 return;
15022         }
15023
15024 #ifdef RTE_LIBRTE_I40E_PMD
15025         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15026                 if (mapping[i].pctype != 0ULL) {
15027                         first_pctype = 1;
15028
15029                         printf("pctype: ");
15030                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15031                                 if (mapping[i].pctype & (1ULL << j)) {
15032                                         printf(first_pctype ?
15033                                                "%02d" : ",%02d", j);
15034                                         first_pctype = 0;
15035                                 }
15036                         }
15037                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15038                 }
15039         }
15040 #endif
15041 }
15042
15043 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15044         .f = cmd_pctype_mapping_get_parsed,
15045         .data = NULL,
15046         .help_str = "show port <port_id> pctype mapping",
15047         .tokens = {
15048                 (void *)&cmd_pctype_mapping_get_show,
15049                 (void *)&cmd_pctype_mapping_get_port,
15050                 (void *)&cmd_pctype_mapping_get_port_id,
15051                 (void *)&cmd_pctype_mapping_get_pctype,
15052                 (void *)&cmd_pctype_mapping_get_mapping,
15053                 NULL,
15054         },
15055 };
15056
15057 /* port config pctype mapping update */
15058
15059 /* Common result structure for port config pctype mapping update */
15060 struct cmd_pctype_mapping_update_result {
15061         cmdline_fixed_string_t port;
15062         cmdline_fixed_string_t config;
15063         portid_t port_id;
15064         cmdline_fixed_string_t pctype;
15065         cmdline_fixed_string_t mapping;
15066         cmdline_fixed_string_t update;
15067         cmdline_fixed_string_t pctype_list;
15068         uint16_t flow_type;
15069 };
15070
15071 /* Common CLI fields for pctype mapping update*/
15072 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15073         TOKEN_STRING_INITIALIZER
15074                 (struct cmd_pctype_mapping_update_result,
15075                  port, "port");
15076 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15077         TOKEN_STRING_INITIALIZER
15078                 (struct cmd_pctype_mapping_update_result,
15079                  config, "config");
15080 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15081         TOKEN_NUM_INITIALIZER
15082                 (struct cmd_pctype_mapping_update_result,
15083                  port_id, UINT16);
15084 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15085         TOKEN_STRING_INITIALIZER
15086                 (struct cmd_pctype_mapping_update_result,
15087                  pctype, "pctype");
15088 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15089         TOKEN_STRING_INITIALIZER
15090                 (struct cmd_pctype_mapping_update_result,
15091                  mapping, "mapping");
15092 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15093         TOKEN_STRING_INITIALIZER
15094                 (struct cmd_pctype_mapping_update_result,
15095                  update, "update");
15096 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15097         TOKEN_STRING_INITIALIZER
15098                 (struct cmd_pctype_mapping_update_result,
15099                  pctype_list, NULL);
15100 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15101         TOKEN_NUM_INITIALIZER
15102                 (struct cmd_pctype_mapping_update_result,
15103                  flow_type, UINT16);
15104
15105 static void
15106 cmd_pctype_mapping_update_parsed(
15107         void *parsed_result,
15108         __attribute__((unused)) struct cmdline *cl,
15109         __attribute__((unused)) void *data)
15110 {
15111         struct cmd_pctype_mapping_update_result *res = parsed_result;
15112         int ret = -ENOTSUP;
15113 #ifdef RTE_LIBRTE_I40E_PMD
15114         struct rte_pmd_i40e_flow_type_mapping mapping;
15115         unsigned int i;
15116         unsigned int nb_item;
15117         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15118 #endif
15119
15120         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15121                 return;
15122
15123 #ifdef RTE_LIBRTE_I40E_PMD
15124         nb_item = parse_item_list(res->pctype_list, "pctypes",
15125                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15126         mapping.flow_type = res->flow_type;
15127         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15128                 mapping.pctype |= (1ULL << pctype_list[i]);
15129         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15130                                                 &mapping,
15131                                                 1,
15132                                                 0);
15133 #endif
15134
15135         switch (ret) {
15136         case 0:
15137                 break;
15138         case -EINVAL:
15139                 printf("invalid pctype or flow type\n");
15140                 break;
15141         case -ENODEV:
15142                 printf("invalid port_id %d\n", res->port_id);
15143                 break;
15144         case -ENOTSUP:
15145                 printf("function not implemented\n");
15146                 break;
15147         default:
15148                 printf("programming error: (%s)\n", strerror(-ret));
15149         }
15150 }
15151
15152 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15153         .f = cmd_pctype_mapping_update_parsed,
15154         .data = NULL,
15155         .help_str = "port config <port_id> pctype mapping update"
15156         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15157         .tokens = {
15158                 (void *)&cmd_pctype_mapping_update_port,
15159                 (void *)&cmd_pctype_mapping_update_config,
15160                 (void *)&cmd_pctype_mapping_update_port_id,
15161                 (void *)&cmd_pctype_mapping_update_pctype,
15162                 (void *)&cmd_pctype_mapping_update_mapping,
15163                 (void *)&cmd_pctype_mapping_update_update,
15164                 (void *)&cmd_pctype_mapping_update_pc_type,
15165                 (void *)&cmd_pctype_mapping_update_flow_type,
15166                 NULL,
15167         },
15168 };
15169
15170 /* ptype mapping get */
15171
15172 /* Common result structure for ptype mapping get */
15173 struct cmd_ptype_mapping_get_result {
15174         cmdline_fixed_string_t ptype;
15175         cmdline_fixed_string_t mapping;
15176         cmdline_fixed_string_t get;
15177         portid_t port_id;
15178         uint8_t valid_only;
15179 };
15180
15181 /* Common CLI fields for ptype mapping get */
15182 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15183         TOKEN_STRING_INITIALIZER
15184                 (struct cmd_ptype_mapping_get_result,
15185                  ptype, "ptype");
15186 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15187         TOKEN_STRING_INITIALIZER
15188                 (struct cmd_ptype_mapping_get_result,
15189                  mapping, "mapping");
15190 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15191         TOKEN_STRING_INITIALIZER
15192                 (struct cmd_ptype_mapping_get_result,
15193                  get, "get");
15194 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15195         TOKEN_NUM_INITIALIZER
15196                 (struct cmd_ptype_mapping_get_result,
15197                  port_id, UINT16);
15198 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15199         TOKEN_NUM_INITIALIZER
15200                 (struct cmd_ptype_mapping_get_result,
15201                  valid_only, UINT8);
15202
15203 static void
15204 cmd_ptype_mapping_get_parsed(
15205         void *parsed_result,
15206         __attribute__((unused)) struct cmdline *cl,
15207         __attribute__((unused)) void *data)
15208 {
15209         struct cmd_ptype_mapping_get_result *res = parsed_result;
15210         int ret = -ENOTSUP;
15211 #ifdef RTE_LIBRTE_I40E_PMD
15212         int max_ptype_num = 256;
15213         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15214         uint16_t count;
15215         int i;
15216 #endif
15217
15218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15219                 return;
15220
15221 #ifdef RTE_LIBRTE_I40E_PMD
15222         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15223                                         mapping,
15224                                         max_ptype_num,
15225                                         &count,
15226                                         res->valid_only);
15227 #endif
15228
15229         switch (ret) {
15230         case 0:
15231                 break;
15232         case -ENODEV:
15233                 printf("invalid port_id %d\n", res->port_id);
15234                 break;
15235         case -ENOTSUP:
15236                 printf("function not implemented\n");
15237                 break;
15238         default:
15239                 printf("programming error: (%s)\n", strerror(-ret));
15240         }
15241
15242 #ifdef RTE_LIBRTE_I40E_PMD
15243         if (!ret) {
15244                 for (i = 0; i < count; i++)
15245                         printf("%3d\t0x%08x\n",
15246                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15247         }
15248 #endif
15249 }
15250
15251 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15252         .f = cmd_ptype_mapping_get_parsed,
15253         .data = NULL,
15254         .help_str = "ptype mapping get <port_id> <valid_only>",
15255         .tokens = {
15256                 (void *)&cmd_ptype_mapping_get_ptype,
15257                 (void *)&cmd_ptype_mapping_get_mapping,
15258                 (void *)&cmd_ptype_mapping_get_get,
15259                 (void *)&cmd_ptype_mapping_get_port_id,
15260                 (void *)&cmd_ptype_mapping_get_valid_only,
15261                 NULL,
15262         },
15263 };
15264
15265 /* ptype mapping replace */
15266
15267 /* Common result structure for ptype mapping replace */
15268 struct cmd_ptype_mapping_replace_result {
15269         cmdline_fixed_string_t ptype;
15270         cmdline_fixed_string_t mapping;
15271         cmdline_fixed_string_t replace;
15272         portid_t port_id;
15273         uint32_t target;
15274         uint8_t mask;
15275         uint32_t pkt_type;
15276 };
15277
15278 /* Common CLI fields for ptype mapping replace */
15279 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15280         TOKEN_STRING_INITIALIZER
15281                 (struct cmd_ptype_mapping_replace_result,
15282                  ptype, "ptype");
15283 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15284         TOKEN_STRING_INITIALIZER
15285                 (struct cmd_ptype_mapping_replace_result,
15286                  mapping, "mapping");
15287 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15288         TOKEN_STRING_INITIALIZER
15289                 (struct cmd_ptype_mapping_replace_result,
15290                  replace, "replace");
15291 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15292         TOKEN_NUM_INITIALIZER
15293                 (struct cmd_ptype_mapping_replace_result,
15294                  port_id, UINT16);
15295 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15296         TOKEN_NUM_INITIALIZER
15297                 (struct cmd_ptype_mapping_replace_result,
15298                  target, UINT32);
15299 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15300         TOKEN_NUM_INITIALIZER
15301                 (struct cmd_ptype_mapping_replace_result,
15302                  mask, UINT8);
15303 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15304         TOKEN_NUM_INITIALIZER
15305                 (struct cmd_ptype_mapping_replace_result,
15306                  pkt_type, UINT32);
15307
15308 static void
15309 cmd_ptype_mapping_replace_parsed(
15310         void *parsed_result,
15311         __attribute__((unused)) struct cmdline *cl,
15312         __attribute__((unused)) void *data)
15313 {
15314         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15315         int ret = -ENOTSUP;
15316
15317         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15318                 return;
15319
15320 #ifdef RTE_LIBRTE_I40E_PMD
15321         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15322                                         res->target,
15323                                         res->mask,
15324                                         res->pkt_type);
15325 #endif
15326
15327         switch (ret) {
15328         case 0:
15329                 break;
15330         case -EINVAL:
15331                 printf("invalid ptype 0x%8x or 0x%8x\n",
15332                                 res->target, res->pkt_type);
15333                 break;
15334         case -ENODEV:
15335                 printf("invalid port_id %d\n", res->port_id);
15336                 break;
15337         case -ENOTSUP:
15338                 printf("function not implemented\n");
15339                 break;
15340         default:
15341                 printf("programming error: (%s)\n", strerror(-ret));
15342         }
15343 }
15344
15345 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15346         .f = cmd_ptype_mapping_replace_parsed,
15347         .data = NULL,
15348         .help_str =
15349                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15350         .tokens = {
15351                 (void *)&cmd_ptype_mapping_replace_ptype,
15352                 (void *)&cmd_ptype_mapping_replace_mapping,
15353                 (void *)&cmd_ptype_mapping_replace_replace,
15354                 (void *)&cmd_ptype_mapping_replace_port_id,
15355                 (void *)&cmd_ptype_mapping_replace_target,
15356                 (void *)&cmd_ptype_mapping_replace_mask,
15357                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15358                 NULL,
15359         },
15360 };
15361
15362 /* ptype mapping reset */
15363
15364 /* Common result structure for ptype mapping reset */
15365 struct cmd_ptype_mapping_reset_result {
15366         cmdline_fixed_string_t ptype;
15367         cmdline_fixed_string_t mapping;
15368         cmdline_fixed_string_t reset;
15369         portid_t port_id;
15370 };
15371
15372 /* Common CLI fields for ptype mapping reset*/
15373 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15374         TOKEN_STRING_INITIALIZER
15375                 (struct cmd_ptype_mapping_reset_result,
15376                  ptype, "ptype");
15377 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15378         TOKEN_STRING_INITIALIZER
15379                 (struct cmd_ptype_mapping_reset_result,
15380                  mapping, "mapping");
15381 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15382         TOKEN_STRING_INITIALIZER
15383                 (struct cmd_ptype_mapping_reset_result,
15384                  reset, "reset");
15385 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15386         TOKEN_NUM_INITIALIZER
15387                 (struct cmd_ptype_mapping_reset_result,
15388                  port_id, UINT16);
15389
15390 static void
15391 cmd_ptype_mapping_reset_parsed(
15392         void *parsed_result,
15393         __attribute__((unused)) struct cmdline *cl,
15394         __attribute__((unused)) void *data)
15395 {
15396         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15397         int ret = -ENOTSUP;
15398
15399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15400                 return;
15401
15402 #ifdef RTE_LIBRTE_I40E_PMD
15403         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15404 #endif
15405
15406         switch (ret) {
15407         case 0:
15408                 break;
15409         case -ENODEV:
15410                 printf("invalid port_id %d\n", res->port_id);
15411                 break;
15412         case -ENOTSUP:
15413                 printf("function not implemented\n");
15414                 break;
15415         default:
15416                 printf("programming error: (%s)\n", strerror(-ret));
15417         }
15418 }
15419
15420 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15421         .f = cmd_ptype_mapping_reset_parsed,
15422         .data = NULL,
15423         .help_str = "ptype mapping reset <port_id>",
15424         .tokens = {
15425                 (void *)&cmd_ptype_mapping_reset_ptype,
15426                 (void *)&cmd_ptype_mapping_reset_mapping,
15427                 (void *)&cmd_ptype_mapping_reset_reset,
15428                 (void *)&cmd_ptype_mapping_reset_port_id,
15429                 NULL,
15430         },
15431 };
15432
15433 /* ptype mapping update */
15434
15435 /* Common result structure for ptype mapping update */
15436 struct cmd_ptype_mapping_update_result {
15437         cmdline_fixed_string_t ptype;
15438         cmdline_fixed_string_t mapping;
15439         cmdline_fixed_string_t reset;
15440         portid_t port_id;
15441         uint8_t hw_ptype;
15442         uint32_t sw_ptype;
15443 };
15444
15445 /* Common CLI fields for ptype mapping update*/
15446 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15447         TOKEN_STRING_INITIALIZER
15448                 (struct cmd_ptype_mapping_update_result,
15449                  ptype, "ptype");
15450 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15451         TOKEN_STRING_INITIALIZER
15452                 (struct cmd_ptype_mapping_update_result,
15453                  mapping, "mapping");
15454 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15455         TOKEN_STRING_INITIALIZER
15456                 (struct cmd_ptype_mapping_update_result,
15457                  reset, "update");
15458 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15459         TOKEN_NUM_INITIALIZER
15460                 (struct cmd_ptype_mapping_update_result,
15461                  port_id, UINT16);
15462 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15463         TOKEN_NUM_INITIALIZER
15464                 (struct cmd_ptype_mapping_update_result,
15465                  hw_ptype, UINT8);
15466 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15467         TOKEN_NUM_INITIALIZER
15468                 (struct cmd_ptype_mapping_update_result,
15469                  sw_ptype, UINT32);
15470
15471 static void
15472 cmd_ptype_mapping_update_parsed(
15473         void *parsed_result,
15474         __attribute__((unused)) struct cmdline *cl,
15475         __attribute__((unused)) void *data)
15476 {
15477         struct cmd_ptype_mapping_update_result *res = parsed_result;
15478         int ret = -ENOTSUP;
15479 #ifdef RTE_LIBRTE_I40E_PMD
15480         struct rte_pmd_i40e_ptype_mapping mapping;
15481 #endif
15482         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15483                 return;
15484
15485 #ifdef RTE_LIBRTE_I40E_PMD
15486         mapping.hw_ptype = res->hw_ptype;
15487         mapping.sw_ptype = res->sw_ptype;
15488         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15489                                                 &mapping,
15490                                                 1,
15491                                                 0);
15492 #endif
15493
15494         switch (ret) {
15495         case 0:
15496                 break;
15497         case -EINVAL:
15498                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15499                 break;
15500         case -ENODEV:
15501                 printf("invalid port_id %d\n", res->port_id);
15502                 break;
15503         case -ENOTSUP:
15504                 printf("function not implemented\n");
15505                 break;
15506         default:
15507                 printf("programming error: (%s)\n", strerror(-ret));
15508         }
15509 }
15510
15511 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15512         .f = cmd_ptype_mapping_update_parsed,
15513         .data = NULL,
15514         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15515         .tokens = {
15516                 (void *)&cmd_ptype_mapping_update_ptype,
15517                 (void *)&cmd_ptype_mapping_update_mapping,
15518                 (void *)&cmd_ptype_mapping_update_update,
15519                 (void *)&cmd_ptype_mapping_update_port_id,
15520                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15521                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15522                 NULL,
15523         },
15524 };
15525
15526 /* Common result structure for file commands */
15527 struct cmd_cmdfile_result {
15528         cmdline_fixed_string_t load;
15529         cmdline_fixed_string_t filename;
15530 };
15531
15532 /* Common CLI fields for file commands */
15533 cmdline_parse_token_string_t cmd_load_cmdfile =
15534         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15535 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15536         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15537
15538 static void
15539 cmd_load_from_file_parsed(
15540         void *parsed_result,
15541         __attribute__((unused)) struct cmdline *cl,
15542         __attribute__((unused)) void *data)
15543 {
15544         struct cmd_cmdfile_result *res = parsed_result;
15545
15546         cmdline_read_from_file(res->filename);
15547 }
15548
15549 cmdline_parse_inst_t cmd_load_from_file = {
15550         .f = cmd_load_from_file_parsed,
15551         .data = NULL,
15552         .help_str = "load <filename>",
15553         .tokens = {
15554                 (void *)&cmd_load_cmdfile,
15555                 (void *)&cmd_load_cmdfile_filename,
15556                 NULL,
15557         },
15558 };
15559
15560 /* ******************************************************************************** */
15561
15562 /* list of instructions */
15563 cmdline_parse_ctx_t main_ctx[] = {
15564         (cmdline_parse_inst_t *)&cmd_help_brief,
15565         (cmdline_parse_inst_t *)&cmd_help_long,
15566         (cmdline_parse_inst_t *)&cmd_quit,
15567         (cmdline_parse_inst_t *)&cmd_load_from_file,
15568         (cmdline_parse_inst_t *)&cmd_showport,
15569         (cmdline_parse_inst_t *)&cmd_showqueue,
15570         (cmdline_parse_inst_t *)&cmd_showportall,
15571         (cmdline_parse_inst_t *)&cmd_showcfg,
15572         (cmdline_parse_inst_t *)&cmd_start,
15573         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15574         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15575         (cmdline_parse_inst_t *)&cmd_set_link_up,
15576         (cmdline_parse_inst_t *)&cmd_set_link_down,
15577         (cmdline_parse_inst_t *)&cmd_reset,
15578         (cmdline_parse_inst_t *)&cmd_set_numbers,
15579         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15580         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15581         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15582         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15583         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15584         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15585         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15586         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15587         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15588         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15589         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15590         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15591         (cmdline_parse_inst_t *)&cmd_set_link_check,
15592         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15593         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15594         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15595         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15596 #ifdef RTE_LIBRTE_PMD_BOND
15597         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15598         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15599         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15600         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15601         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15602         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15603         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15604         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15605         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15606         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15607         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15608 #endif
15609         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15610         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15611         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15612         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15613         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15614         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15615         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15616         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15617         (cmdline_parse_inst_t *)&cmd_csum_set,
15618         (cmdline_parse_inst_t *)&cmd_csum_show,
15619         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15620         (cmdline_parse_inst_t *)&cmd_tso_set,
15621         (cmdline_parse_inst_t *)&cmd_tso_show,
15622         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15623         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15624         (cmdline_parse_inst_t *)&cmd_gro_enable,
15625         (cmdline_parse_inst_t *)&cmd_gro_flush,
15626         (cmdline_parse_inst_t *)&cmd_gro_show,
15627         (cmdline_parse_inst_t *)&cmd_gso_enable,
15628         (cmdline_parse_inst_t *)&cmd_gso_size,
15629         (cmdline_parse_inst_t *)&cmd_gso_show,
15630         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15631         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15632         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15633         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15634         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15635         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15636         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15637         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15638         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15639         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15640         (cmdline_parse_inst_t *)&cmd_config_dcb,
15641         (cmdline_parse_inst_t *)&cmd_read_reg,
15642         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15643         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15644         (cmdline_parse_inst_t *)&cmd_write_reg,
15645         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15646         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15647         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15648         (cmdline_parse_inst_t *)&cmd_stop,
15649         (cmdline_parse_inst_t *)&cmd_mac_addr,
15650         (cmdline_parse_inst_t *)&cmd_set_qmap,
15651         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15652         (cmdline_parse_inst_t *)&cmd_operate_port,
15653         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15654         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15655         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15656         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15657         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15658         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15659         (cmdline_parse_inst_t *)&cmd_config_mtu,
15660         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15661         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15662         (cmdline_parse_inst_t *)&cmd_config_rss,
15663         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15664         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15665         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15666         (cmdline_parse_inst_t *)&cmd_showport_reta,
15667         (cmdline_parse_inst_t *)&cmd_config_burst,
15668         (cmdline_parse_inst_t *)&cmd_config_thresh,
15669         (cmdline_parse_inst_t *)&cmd_config_threshold,
15670         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15671         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15672         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15673         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15674         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15675         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15676         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15677         (cmdline_parse_inst_t *)&cmd_global_config,
15678         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15679         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15680         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15681         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15682         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15683         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15684         (cmdline_parse_inst_t *)&cmd_dump,
15685         (cmdline_parse_inst_t *)&cmd_dump_one,
15686         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15687         (cmdline_parse_inst_t *)&cmd_syn_filter,
15688         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15689         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15690         (cmdline_parse_inst_t *)&cmd_flex_filter,
15691         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15692         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15693         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15694         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15695         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15696         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15697         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15698         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15699         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15700         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15701         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15702         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15703         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15704         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15705         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15706         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15707         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15708         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15709         (cmdline_parse_inst_t *)&cmd_flow,
15710         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15711         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15712         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15713         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15714         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15715         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15716         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15717         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15718         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15719         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15720         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15721         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15722         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15723         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15724         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15725         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15726         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15727         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15728         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15729         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15730         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15731         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15732         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15733         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15734         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15735         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15736         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15737         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15738         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15739         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15740         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15741         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15742         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15743         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15744         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15745         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15746         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15747         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15748         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15749         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15750         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15751         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15752         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15753         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15754         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15755         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15756         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15757         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15758         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15759 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15760         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15761 #endif
15762         (cmdline_parse_inst_t *)&cmd_ddp_add,
15763         (cmdline_parse_inst_t *)&cmd_ddp_del,
15764         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15765         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15766         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15767         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15768         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15769         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15770         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15771         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15772
15773         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15774         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15775         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15776         (cmdline_parse_inst_t *)&cmd_queue_region,
15777         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15778         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15779         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15780         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15781         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15782         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15783         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15784         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15785         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15786         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15787         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15788         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15789         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15790         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15791         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15792         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15793         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15794         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15795         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15796         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15797         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15798         NULL,
15799 };
15800
15801 /* read cmdline commands from file */
15802 void
15803 cmdline_read_from_file(const char *filename)
15804 {
15805         struct cmdline *cl;
15806
15807         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15808         if (cl == NULL) {
15809                 printf("Failed to create file based cmdline context: %s\n",
15810                        filename);
15811                 return;
15812         }
15813
15814         cmdline_interact(cl);
15815         cmdline_quit(cl);
15816
15817         cmdline_free(cl);
15818
15819         printf("Read CLI commands from %s\n", filename);
15820 }
15821
15822 /* prompt function, called from main on MASTER lcore */
15823 void
15824 prompt(void)
15825 {
15826         /* initialize non-constant commands */
15827         cmd_set_fwd_mode_init();
15828         cmd_set_fwd_retry_mode_init();
15829
15830         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15831         if (testpmd_cl == NULL)
15832                 return;
15833         cmdline_interact(testpmd_cl);
15834         cmdline_stdin_exit(testpmd_cl);
15835 }
15836
15837 void
15838 prompt_exit(void)
15839 {
15840         if (testpmd_cl != NULL)
15841                 cmdline_quit(testpmd_cl);
15842 }
15843
15844 static void
15845 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15846 {
15847         if (id == (portid_t)RTE_PORT_ALL) {
15848                 portid_t pid;
15849
15850                 RTE_ETH_FOREACH_DEV(pid) {
15851                         /* check if need_reconfig has been set to 1 */
15852                         if (ports[pid].need_reconfig == 0)
15853                                 ports[pid].need_reconfig = dev;
15854                         /* check if need_reconfig_queues has been set to 1 */
15855                         if (ports[pid].need_reconfig_queues == 0)
15856                                 ports[pid].need_reconfig_queues = queue;
15857                 }
15858         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15859                 /* check if need_reconfig has been set to 1 */
15860                 if (ports[id].need_reconfig == 0)
15861                         ports[id].need_reconfig = dev;
15862                 /* check if need_reconfig_queues has been set to 1 */
15863                 if (ports[id].need_reconfig_queues == 0)
15864                         ports[id].need_reconfig_queues = queue;
15865         }
15866 }