app/testpmd: remove txqflags option
[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 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3113 struct cmd_rx_vlan_filter_all_result {
3114         cmdline_fixed_string_t rx_vlan;
3115         cmdline_fixed_string_t what;
3116         cmdline_fixed_string_t all;
3117         portid_t port_id;
3118 };
3119
3120 static void
3121 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3122                               __attribute__((unused)) struct cmdline *cl,
3123                               __attribute__((unused)) void *data)
3124 {
3125         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3126
3127         if (!strcmp(res->what, "add"))
3128                 rx_vlan_all_filter_set(res->port_id, 1);
3129         else
3130                 rx_vlan_all_filter_set(res->port_id, 0);
3131 }
3132
3133 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3134         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3135                                  rx_vlan, "rx_vlan");
3136 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3137         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3138                                  what, "add#rm");
3139 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3140         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3141                                  all, "all");
3142 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3143         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3144                               port_id, UINT16);
3145
3146 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3147         .f = cmd_rx_vlan_filter_all_parsed,
3148         .data = NULL,
3149         .help_str = "rx_vlan add|rm all <port_id>: "
3150                 "Add/Remove all identifiers to/from the set of VLAN "
3151                 "identifiers filtered by a port",
3152         .tokens = {
3153                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3154                 (void *)&cmd_rx_vlan_filter_all_what,
3155                 (void *)&cmd_rx_vlan_filter_all_all,
3156                 (void *)&cmd_rx_vlan_filter_all_portid,
3157                 NULL,
3158         },
3159 };
3160
3161 /* *** VLAN OFFLOAD SET ON A PORT *** */
3162 struct cmd_vlan_offload_result {
3163         cmdline_fixed_string_t vlan;
3164         cmdline_fixed_string_t set;
3165         cmdline_fixed_string_t vlan_type;
3166         cmdline_fixed_string_t what;
3167         cmdline_fixed_string_t on;
3168         cmdline_fixed_string_t port_id;
3169 };
3170
3171 static void
3172 cmd_vlan_offload_parsed(void *parsed_result,
3173                           __attribute__((unused)) struct cmdline *cl,
3174                           __attribute__((unused)) void *data)
3175 {
3176         int on;
3177         struct cmd_vlan_offload_result *res = parsed_result;
3178         char *str;
3179         int i, len = 0;
3180         portid_t port_id = 0;
3181         unsigned int tmp;
3182
3183         str = res->port_id;
3184         len = strnlen(str, STR_TOKEN_SIZE);
3185         i = 0;
3186         /* Get port_id first */
3187         while(i < len){
3188                 if(str[i] == ',')
3189                         break;
3190
3191                 i++;
3192         }
3193         str[i]='\0';
3194         tmp = strtoul(str, NULL, 0);
3195         /* If port_id greater that what portid_t can represent, return */
3196         if(tmp >= RTE_MAX_ETHPORTS)
3197                 return;
3198         port_id = (portid_t)tmp;
3199
3200         if (!strcmp(res->on, "on"))
3201                 on = 1;
3202         else
3203                 on = 0;
3204
3205         if (!strcmp(res->what, "strip"))
3206                 rx_vlan_strip_set(port_id,  on);
3207         else if(!strcmp(res->what, "stripq")){
3208                 uint16_t queue_id = 0;
3209
3210                 /* No queue_id, return */
3211                 if(i + 1 >= len) {
3212                         printf("must specify (port,queue_id)\n");
3213                         return;
3214                 }
3215                 tmp = strtoul(str + i + 1, NULL, 0);
3216                 /* If queue_id greater that what 16-bits can represent, return */
3217                 if(tmp > 0xffff)
3218                         return;
3219
3220                 queue_id = (uint16_t)tmp;
3221                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3222         }
3223         else if (!strcmp(res->what, "filter"))
3224                 rx_vlan_filter_set(port_id, on);
3225         else
3226                 vlan_extend_set(port_id, on);
3227
3228         return;
3229 }
3230
3231 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3232         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3233                                  vlan, "vlan");
3234 cmdline_parse_token_string_t cmd_vlan_offload_set =
3235         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3236                                  set, "set");
3237 cmdline_parse_token_string_t cmd_vlan_offload_what =
3238         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3239                                  what, "strip#filter#qinq#stripq");
3240 cmdline_parse_token_string_t cmd_vlan_offload_on =
3241         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3242                               on, "on#off");
3243 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3244         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3245                               port_id, NULL);
3246
3247 cmdline_parse_inst_t cmd_vlan_offload = {
3248         .f = cmd_vlan_offload_parsed,
3249         .data = NULL,
3250         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3251                 "<port_id[,queue_id]>: "
3252                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3253         .tokens = {
3254                 (void *)&cmd_vlan_offload_vlan,
3255                 (void *)&cmd_vlan_offload_set,
3256                 (void *)&cmd_vlan_offload_what,
3257                 (void *)&cmd_vlan_offload_on,
3258                 (void *)&cmd_vlan_offload_portid,
3259                 NULL,
3260         },
3261 };
3262
3263 /* *** VLAN TPID SET ON A PORT *** */
3264 struct cmd_vlan_tpid_result {
3265         cmdline_fixed_string_t vlan;
3266         cmdline_fixed_string_t set;
3267         cmdline_fixed_string_t vlan_type;
3268         cmdline_fixed_string_t what;
3269         uint16_t tp_id;
3270         portid_t port_id;
3271 };
3272
3273 static void
3274 cmd_vlan_tpid_parsed(void *parsed_result,
3275                           __attribute__((unused)) struct cmdline *cl,
3276                           __attribute__((unused)) void *data)
3277 {
3278         struct cmd_vlan_tpid_result *res = parsed_result;
3279         enum rte_vlan_type vlan_type;
3280
3281         if (!strcmp(res->vlan_type, "inner"))
3282                 vlan_type = ETH_VLAN_TYPE_INNER;
3283         else if (!strcmp(res->vlan_type, "outer"))
3284                 vlan_type = ETH_VLAN_TYPE_OUTER;
3285         else {
3286                 printf("Unknown vlan type\n");
3287                 return;
3288         }
3289         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3290 }
3291
3292 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3293         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3294                                  vlan, "vlan");
3295 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3296         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3297                                  set, "set");
3298 cmdline_parse_token_string_t cmd_vlan_type =
3299         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3300                                  vlan_type, "inner#outer");
3301 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3302         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3303                                  what, "tpid");
3304 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3305         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3306                               tp_id, UINT16);
3307 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3308         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3309                               port_id, UINT16);
3310
3311 cmdline_parse_inst_t cmd_vlan_tpid = {
3312         .f = cmd_vlan_tpid_parsed,
3313         .data = NULL,
3314         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3315                 "Set the VLAN Ether type",
3316         .tokens = {
3317                 (void *)&cmd_vlan_tpid_vlan,
3318                 (void *)&cmd_vlan_tpid_set,
3319                 (void *)&cmd_vlan_type,
3320                 (void *)&cmd_vlan_tpid_what,
3321                 (void *)&cmd_vlan_tpid_tpid,
3322                 (void *)&cmd_vlan_tpid_portid,
3323                 NULL,
3324         },
3325 };
3326
3327 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3328 struct cmd_rx_vlan_filter_result {
3329         cmdline_fixed_string_t rx_vlan;
3330         cmdline_fixed_string_t what;
3331         uint16_t vlan_id;
3332         portid_t port_id;
3333 };
3334
3335 static void
3336 cmd_rx_vlan_filter_parsed(void *parsed_result,
3337                           __attribute__((unused)) struct cmdline *cl,
3338                           __attribute__((unused)) void *data)
3339 {
3340         struct cmd_rx_vlan_filter_result *res = parsed_result;
3341
3342         if (!strcmp(res->what, "add"))
3343                 rx_vft_set(res->port_id, res->vlan_id, 1);
3344         else
3345                 rx_vft_set(res->port_id, res->vlan_id, 0);
3346 }
3347
3348 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3349         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3350                                  rx_vlan, "rx_vlan");
3351 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3352         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3353                                  what, "add#rm");
3354 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3355         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3356                               vlan_id, UINT16);
3357 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3358         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3359                               port_id, UINT16);
3360
3361 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3362         .f = cmd_rx_vlan_filter_parsed,
3363         .data = NULL,
3364         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3365                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3366                 "identifiers filtered by a port",
3367         .tokens = {
3368                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3369                 (void *)&cmd_rx_vlan_filter_what,
3370                 (void *)&cmd_rx_vlan_filter_vlanid,
3371                 (void *)&cmd_rx_vlan_filter_portid,
3372                 NULL,
3373         },
3374 };
3375
3376 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3377 struct cmd_tx_vlan_set_result {
3378         cmdline_fixed_string_t tx_vlan;
3379         cmdline_fixed_string_t set;
3380         portid_t port_id;
3381         uint16_t vlan_id;
3382 };
3383
3384 static void
3385 cmd_tx_vlan_set_parsed(void *parsed_result,
3386                        __attribute__((unused)) struct cmdline *cl,
3387                        __attribute__((unused)) void *data)
3388 {
3389         struct cmd_tx_vlan_set_result *res = parsed_result;
3390
3391         if (!port_is_stopped(res->port_id)) {
3392                 printf("Please stop port %d first\n", res->port_id);
3393                 return;
3394         }
3395
3396         tx_vlan_set(res->port_id, res->vlan_id);
3397
3398         cmd_reconfig_device_queue(res->port_id, 1, 1);
3399 }
3400
3401 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3402         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3403                                  tx_vlan, "tx_vlan");
3404 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3405         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3406                                  set, "set");
3407 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3408         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3409                               port_id, UINT16);
3410 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3411         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3412                               vlan_id, UINT16);
3413
3414 cmdline_parse_inst_t cmd_tx_vlan_set = {
3415         .f = cmd_tx_vlan_set_parsed,
3416         .data = NULL,
3417         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3418                 "Enable hardware insertion of a single VLAN header "
3419                 "with a given TAG Identifier in packets sent on a port",
3420         .tokens = {
3421                 (void *)&cmd_tx_vlan_set_tx_vlan,
3422                 (void *)&cmd_tx_vlan_set_set,
3423                 (void *)&cmd_tx_vlan_set_portid,
3424                 (void *)&cmd_tx_vlan_set_vlanid,
3425                 NULL,
3426         },
3427 };
3428
3429 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3430 struct cmd_tx_vlan_set_qinq_result {
3431         cmdline_fixed_string_t tx_vlan;
3432         cmdline_fixed_string_t set;
3433         portid_t port_id;
3434         uint16_t vlan_id;
3435         uint16_t vlan_id_outer;
3436 };
3437
3438 static void
3439 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3440                             __attribute__((unused)) struct cmdline *cl,
3441                             __attribute__((unused)) void *data)
3442 {
3443         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3444
3445         if (!port_is_stopped(res->port_id)) {
3446                 printf("Please stop port %d first\n", res->port_id);
3447                 return;
3448         }
3449
3450         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3451
3452         cmd_reconfig_device_queue(res->port_id, 1, 1);
3453 }
3454
3455 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3456         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3457                 tx_vlan, "tx_vlan");
3458 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3459         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3460                 set, "set");
3461 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3462         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3463                 port_id, UINT16);
3464 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3465         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3466                 vlan_id, UINT16);
3467 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3468         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3469                 vlan_id_outer, UINT16);
3470
3471 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3472         .f = cmd_tx_vlan_set_qinq_parsed,
3473         .data = NULL,
3474         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3475                 "Enable hardware insertion of double VLAN header "
3476                 "with given TAG Identifiers in packets sent on a port",
3477         .tokens = {
3478                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3479                 (void *)&cmd_tx_vlan_set_qinq_set,
3480                 (void *)&cmd_tx_vlan_set_qinq_portid,
3481                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3482                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3483                 NULL,
3484         },
3485 };
3486
3487 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3488 struct cmd_tx_vlan_set_pvid_result {
3489         cmdline_fixed_string_t tx_vlan;
3490         cmdline_fixed_string_t set;
3491         cmdline_fixed_string_t pvid;
3492         portid_t port_id;
3493         uint16_t vlan_id;
3494         cmdline_fixed_string_t mode;
3495 };
3496
3497 static void
3498 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3499                             __attribute__((unused)) struct cmdline *cl,
3500                             __attribute__((unused)) void *data)
3501 {
3502         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3503
3504         if (strcmp(res->mode, "on") == 0)
3505                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3506         else
3507                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3508 }
3509
3510 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3511         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3512                                  tx_vlan, "tx_vlan");
3513 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3514         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3515                                  set, "set");
3516 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3517         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3518                                  pvid, "pvid");
3519 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3520         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3521                              port_id, UINT16);
3522 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3523         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3524                               vlan_id, UINT16);
3525 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3526         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3527                                  mode, "on#off");
3528
3529 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3530         .f = cmd_tx_vlan_set_pvid_parsed,
3531         .data = NULL,
3532         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3533         .tokens = {
3534                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3535                 (void *)&cmd_tx_vlan_set_pvid_set,
3536                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3537                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3538                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3539                 (void *)&cmd_tx_vlan_set_pvid_mode,
3540                 NULL,
3541         },
3542 };
3543
3544 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3545 struct cmd_tx_vlan_reset_result {
3546         cmdline_fixed_string_t tx_vlan;
3547         cmdline_fixed_string_t reset;
3548         portid_t port_id;
3549 };
3550
3551 static void
3552 cmd_tx_vlan_reset_parsed(void *parsed_result,
3553                          __attribute__((unused)) struct cmdline *cl,
3554                          __attribute__((unused)) void *data)
3555 {
3556         struct cmd_tx_vlan_reset_result *res = parsed_result;
3557
3558         if (!port_is_stopped(res->port_id)) {
3559                 printf("Please stop port %d first\n", res->port_id);
3560                 return;
3561         }
3562
3563         tx_vlan_reset(res->port_id);
3564
3565         cmd_reconfig_device_queue(res->port_id, 1, 1);
3566 }
3567
3568 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3569         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3570                                  tx_vlan, "tx_vlan");
3571 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3572         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3573                                  reset, "reset");
3574 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3575         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3576                               port_id, UINT16);
3577
3578 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3579         .f = cmd_tx_vlan_reset_parsed,
3580         .data = NULL,
3581         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3582                 "VLAN header in packets sent on a port",
3583         .tokens = {
3584                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3585                 (void *)&cmd_tx_vlan_reset_reset,
3586                 (void *)&cmd_tx_vlan_reset_portid,
3587                 NULL,
3588         },
3589 };
3590
3591
3592 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3593 struct cmd_csum_result {
3594         cmdline_fixed_string_t csum;
3595         cmdline_fixed_string_t mode;
3596         cmdline_fixed_string_t proto;
3597         cmdline_fixed_string_t hwsw;
3598         portid_t port_id;
3599 };
3600
3601 static void
3602 csum_show(int port_id)
3603 {
3604         struct rte_eth_dev_info dev_info;
3605         uint64_t tx_offloads;
3606
3607         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3608         printf("Parse tunnel is %s\n",
3609                 (ports[port_id].parse_tunnel) ? "on" : "off");
3610         printf("IP checksum offload is %s\n",
3611                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3612         printf("UDP checksum offload is %s\n",
3613                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3614         printf("TCP checksum offload is %s\n",
3615                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3616         printf("SCTP checksum offload is %s\n",
3617                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3618         printf("Outer-Ip checksum offload is %s\n",
3619                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3620
3621         /* display warnings if configuration is not supported by the NIC */
3622         rte_eth_dev_info_get(port_id, &dev_info);
3623         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3624                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3625                 printf("Warning: hardware IP checksum enabled but not "
3626                         "supported by port %d\n", port_id);
3627         }
3628         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3629                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3630                 printf("Warning: hardware UDP checksum enabled but not "
3631                         "supported by port %d\n", port_id);
3632         }
3633         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3634                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3635                 printf("Warning: hardware TCP checksum enabled but not "
3636                         "supported by port %d\n", port_id);
3637         }
3638         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3639                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3640                 printf("Warning: hardware SCTP checksum enabled but not "
3641                         "supported by port %d\n", port_id);
3642         }
3643         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3644                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3645                 printf("Warning: hardware outer IP checksum enabled but not "
3646                         "supported by port %d\n", port_id);
3647         }
3648 }
3649
3650 static void
3651 cmd_csum_parsed(void *parsed_result,
3652                        __attribute__((unused)) struct cmdline *cl,
3653                        __attribute__((unused)) void *data)
3654 {
3655         struct cmd_csum_result *res = parsed_result;
3656         int hw = 0;
3657         uint64_t csum_offloads = 0;
3658
3659         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3660                 printf("invalid port %d\n", res->port_id);
3661                 return;
3662         }
3663         if (!port_is_stopped(res->port_id)) {
3664                 printf("Please stop port %d first\n", res->port_id);
3665                 return;
3666         }
3667
3668         if (!strcmp(res->mode, "set")) {
3669
3670                 if (!strcmp(res->hwsw, "hw"))
3671                         hw = 1;
3672
3673                 if (!strcmp(res->proto, "ip")) {
3674                         csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3675                 } else if (!strcmp(res->proto, "udp")) {
3676                         csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3677                 } else if (!strcmp(res->proto, "tcp")) {
3678                         csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3679                 } else if (!strcmp(res->proto, "sctp")) {
3680                         csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3681                 } else if (!strcmp(res->proto, "outer-ip")) {
3682                         csum_offloads |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3683                 }
3684
3685                 if (hw) {
3686                         ports[res->port_id].dev_conf.txmode.offloads |=
3687                                                         csum_offloads;
3688                 } else {
3689                         ports[res->port_id].dev_conf.txmode.offloads &=
3690                                                         (~csum_offloads);
3691                 }
3692         }
3693         csum_show(res->port_id);
3694
3695         cmd_reconfig_device_queue(res->port_id, 1, 1);
3696 }
3697
3698 cmdline_parse_token_string_t cmd_csum_csum =
3699         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3700                                 csum, "csum");
3701 cmdline_parse_token_string_t cmd_csum_mode =
3702         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3703                                 mode, "set");
3704 cmdline_parse_token_string_t cmd_csum_proto =
3705         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3706                                 proto, "ip#tcp#udp#sctp#outer-ip");
3707 cmdline_parse_token_string_t cmd_csum_hwsw =
3708         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3709                                 hwsw, "hw#sw");
3710 cmdline_parse_token_num_t cmd_csum_portid =
3711         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3712                                 port_id, UINT16);
3713
3714 cmdline_parse_inst_t cmd_csum_set = {
3715         .f = cmd_csum_parsed,
3716         .data = NULL,
3717         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3718                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3719                 "using csum forward engine",
3720         .tokens = {
3721                 (void *)&cmd_csum_csum,
3722                 (void *)&cmd_csum_mode,
3723                 (void *)&cmd_csum_proto,
3724                 (void *)&cmd_csum_hwsw,
3725                 (void *)&cmd_csum_portid,
3726                 NULL,
3727         },
3728 };
3729
3730 cmdline_parse_token_string_t cmd_csum_mode_show =
3731         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3732                                 mode, "show");
3733
3734 cmdline_parse_inst_t cmd_csum_show = {
3735         .f = cmd_csum_parsed,
3736         .data = NULL,
3737         .help_str = "csum show <port_id>: Show checksum offload configuration",
3738         .tokens = {
3739                 (void *)&cmd_csum_csum,
3740                 (void *)&cmd_csum_mode_show,
3741                 (void *)&cmd_csum_portid,
3742                 NULL,
3743         },
3744 };
3745
3746 /* Enable/disable tunnel parsing */
3747 struct cmd_csum_tunnel_result {
3748         cmdline_fixed_string_t csum;
3749         cmdline_fixed_string_t parse;
3750         cmdline_fixed_string_t onoff;
3751         portid_t port_id;
3752 };
3753
3754 static void
3755 cmd_csum_tunnel_parsed(void *parsed_result,
3756                        __attribute__((unused)) struct cmdline *cl,
3757                        __attribute__((unused)) void *data)
3758 {
3759         struct cmd_csum_tunnel_result *res = parsed_result;
3760
3761         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3762                 return;
3763
3764         if (!strcmp(res->onoff, "on"))
3765                 ports[res->port_id].parse_tunnel = 1;
3766         else
3767                 ports[res->port_id].parse_tunnel = 0;
3768
3769         csum_show(res->port_id);
3770 }
3771
3772 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3773         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3774                                 csum, "csum");
3775 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3776         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3777                                 parse, "parse_tunnel");
3778 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3779         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3780                                 onoff, "on#off");
3781 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3782         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3783                                 port_id, UINT16);
3784
3785 cmdline_parse_inst_t cmd_csum_tunnel = {
3786         .f = cmd_csum_tunnel_parsed,
3787         .data = NULL,
3788         .help_str = "csum parse_tunnel on|off <port_id>: "
3789                 "Enable/Disable parsing of tunnels for csum engine",
3790         .tokens = {
3791                 (void *)&cmd_csum_tunnel_csum,
3792                 (void *)&cmd_csum_tunnel_parse,
3793                 (void *)&cmd_csum_tunnel_onoff,
3794                 (void *)&cmd_csum_tunnel_portid,
3795                 NULL,
3796         },
3797 };
3798
3799 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3800 struct cmd_tso_set_result {
3801         cmdline_fixed_string_t tso;
3802         cmdline_fixed_string_t mode;
3803         uint16_t tso_segsz;
3804         portid_t port_id;
3805 };
3806
3807 static void
3808 cmd_tso_set_parsed(void *parsed_result,
3809                        __attribute__((unused)) struct cmdline *cl,
3810                        __attribute__((unused)) void *data)
3811 {
3812         struct cmd_tso_set_result *res = parsed_result;
3813         struct rte_eth_dev_info dev_info;
3814
3815         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3816                 return;
3817         if (!port_is_stopped(res->port_id)) {
3818                 printf("Please stop port %d first\n", res->port_id);
3819                 return;
3820         }
3821
3822         if (!strcmp(res->mode, "set"))
3823                 ports[res->port_id].tso_segsz = res->tso_segsz;
3824
3825         if (ports[res->port_id].tso_segsz == 0) {
3826                 ports[res->port_id].dev_conf.txmode.offloads &=
3827                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3828                 printf("TSO for non-tunneled packets is disabled\n");
3829         } else {
3830                 ports[res->port_id].dev_conf.txmode.offloads |=
3831                                                 DEV_TX_OFFLOAD_TCP_TSO;
3832                 printf("TSO segment size for non-tunneled packets is %d\n",
3833                         ports[res->port_id].tso_segsz);
3834         }
3835
3836         /* display warnings if configuration is not supported by the NIC */
3837         rte_eth_dev_info_get(res->port_id, &dev_info);
3838         if ((ports[res->port_id].tso_segsz != 0) &&
3839                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3840                 printf("Warning: TSO enabled but not "
3841                         "supported by port %d\n", res->port_id);
3842         }
3843
3844         cmd_reconfig_device_queue(res->port_id, 1, 1);
3845 }
3846
3847 cmdline_parse_token_string_t cmd_tso_set_tso =
3848         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3849                                 tso, "tso");
3850 cmdline_parse_token_string_t cmd_tso_set_mode =
3851         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3852                                 mode, "set");
3853 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3854         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3855                                 tso_segsz, UINT16);
3856 cmdline_parse_token_num_t cmd_tso_set_portid =
3857         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3858                                 port_id, UINT16);
3859
3860 cmdline_parse_inst_t cmd_tso_set = {
3861         .f = cmd_tso_set_parsed,
3862         .data = NULL,
3863         .help_str = "tso set <tso_segsz> <port_id>: "
3864                 "Set TSO segment size of non-tunneled packets for csum engine "
3865                 "(0 to disable)",
3866         .tokens = {
3867                 (void *)&cmd_tso_set_tso,
3868                 (void *)&cmd_tso_set_mode,
3869                 (void *)&cmd_tso_set_tso_segsz,
3870                 (void *)&cmd_tso_set_portid,
3871                 NULL,
3872         },
3873 };
3874
3875 cmdline_parse_token_string_t cmd_tso_show_mode =
3876         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3877                                 mode, "show");
3878
3879
3880 cmdline_parse_inst_t cmd_tso_show = {
3881         .f = cmd_tso_set_parsed,
3882         .data = NULL,
3883         .help_str = "tso show <port_id>: "
3884                 "Show TSO segment size of non-tunneled packets for csum engine",
3885         .tokens = {
3886                 (void *)&cmd_tso_set_tso,
3887                 (void *)&cmd_tso_show_mode,
3888                 (void *)&cmd_tso_set_portid,
3889                 NULL,
3890         },
3891 };
3892
3893 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3894 struct cmd_tunnel_tso_set_result {
3895         cmdline_fixed_string_t tso;
3896         cmdline_fixed_string_t mode;
3897         uint16_t tso_segsz;
3898         portid_t port_id;
3899 };
3900
3901 static void
3902 check_tunnel_tso_nic_support(portid_t port_id)
3903 {
3904         struct rte_eth_dev_info dev_info;
3905
3906         rte_eth_dev_info_get(port_id, &dev_info);
3907         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3908                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3909                        "supported by port %d\n", port_id);
3910         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3911                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3912                         "supported by port %d\n", port_id);
3913         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3914                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3915                        "supported by port %d\n", port_id);
3916         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3917                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3918                        "supported by port %d\n", port_id);
3919 }
3920
3921 static void
3922 cmd_tunnel_tso_set_parsed(void *parsed_result,
3923                           __attribute__((unused)) struct cmdline *cl,
3924                           __attribute__((unused)) void *data)
3925 {
3926         struct cmd_tunnel_tso_set_result *res = parsed_result;
3927
3928         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3929                 return;
3930         if (!port_is_stopped(res->port_id)) {
3931                 printf("Please stop port %d first\n", res->port_id);
3932                 return;
3933         }
3934
3935         if (!strcmp(res->mode, "set"))
3936                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3937
3938         if (ports[res->port_id].tunnel_tso_segsz == 0) {
3939                 ports[res->port_id].dev_conf.txmode.offloads &=
3940                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3941                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
3942                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3943                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
3944                 printf("TSO for tunneled packets is disabled\n");
3945         } else {
3946                 ports[res->port_id].dev_conf.txmode.offloads |=
3947                         (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3948                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
3949                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3950                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
3951                 printf("TSO segment size for tunneled packets is %d\n",
3952                         ports[res->port_id].tunnel_tso_segsz);
3953
3954                 /* Below conditions are needed to make it work:
3955                  * (1) tunnel TSO is supported by the NIC;
3956                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3957                  * are recognized;
3958                  * (3) for tunneled pkts with outer L3 of IPv4,
3959                  * "csum set outer-ip" must be set to hw, because after tso,
3960                  * total_len of outer IP header is changed, and the checksum
3961                  * of outer IP header calculated by sw should be wrong; that
3962                  * is not necessary for IPv6 tunneled pkts because there's no
3963                  * checksum in IP header anymore.
3964                  */
3965                 check_tunnel_tso_nic_support(res->port_id);
3966
3967                 if (!ports[res->port_id].parse_tunnel)
3968                         printf("Warning: csum parse_tunnel must be set "
3969                                 "so that tunneled packets are recognized\n");
3970                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
3971                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
3972                         printf("Warning: csum set outer-ip must be set to hw "
3973                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3974         }
3975
3976         cmd_reconfig_device_queue(res->port_id, 1, 1);
3977 }
3978
3979 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3980         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3981                                 tso, "tunnel_tso");
3982 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3983         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3984                                 mode, "set");
3985 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3986         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3987                                 tso_segsz, UINT16);
3988 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3989         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3990                                 port_id, UINT16);
3991
3992 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3993         .f = cmd_tunnel_tso_set_parsed,
3994         .data = NULL,
3995         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3996                 "Set TSO segment size of tunneled packets for csum engine "
3997                 "(0 to disable)",
3998         .tokens = {
3999                 (void *)&cmd_tunnel_tso_set_tso,
4000                 (void *)&cmd_tunnel_tso_set_mode,
4001                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4002                 (void *)&cmd_tunnel_tso_set_portid,
4003                 NULL,
4004         },
4005 };
4006
4007 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4008         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4009                                 mode, "show");
4010
4011
4012 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4013         .f = cmd_tunnel_tso_set_parsed,
4014         .data = NULL,
4015         .help_str = "tunnel_tso show <port_id> "
4016                 "Show TSO segment size of tunneled packets for csum engine",
4017         .tokens = {
4018                 (void *)&cmd_tunnel_tso_set_tso,
4019                 (void *)&cmd_tunnel_tso_show_mode,
4020                 (void *)&cmd_tunnel_tso_set_portid,
4021                 NULL,
4022         },
4023 };
4024
4025 /* *** SET GRO FOR A PORT *** */
4026 struct cmd_gro_enable_result {
4027         cmdline_fixed_string_t cmd_set;
4028         cmdline_fixed_string_t cmd_port;
4029         cmdline_fixed_string_t cmd_keyword;
4030         cmdline_fixed_string_t cmd_onoff;
4031         portid_t cmd_pid;
4032 };
4033
4034 static void
4035 cmd_gro_enable_parsed(void *parsed_result,
4036                 __attribute__((unused)) struct cmdline *cl,
4037                 __attribute__((unused)) void *data)
4038 {
4039         struct cmd_gro_enable_result *res;
4040
4041         res = parsed_result;
4042         if (!strcmp(res->cmd_keyword, "gro"))
4043                 setup_gro(res->cmd_onoff, res->cmd_pid);
4044 }
4045
4046 cmdline_parse_token_string_t cmd_gro_enable_set =
4047         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4048                         cmd_set, "set");
4049 cmdline_parse_token_string_t cmd_gro_enable_port =
4050         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4051                         cmd_keyword, "port");
4052 cmdline_parse_token_num_t cmd_gro_enable_pid =
4053         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4054                         cmd_pid, UINT16);
4055 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4056         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4057                         cmd_keyword, "gro");
4058 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4059         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4060                         cmd_onoff, "on#off");
4061
4062 cmdline_parse_inst_t cmd_gro_enable = {
4063         .f = cmd_gro_enable_parsed,
4064         .data = NULL,
4065         .help_str = "set port <port_id> gro on|off",
4066         .tokens = {
4067                 (void *)&cmd_gro_enable_set,
4068                 (void *)&cmd_gro_enable_port,
4069                 (void *)&cmd_gro_enable_pid,
4070                 (void *)&cmd_gro_enable_keyword,
4071                 (void *)&cmd_gro_enable_onoff,
4072                 NULL,
4073         },
4074 };
4075
4076 /* *** DISPLAY GRO CONFIGURATION *** */
4077 struct cmd_gro_show_result {
4078         cmdline_fixed_string_t cmd_show;
4079         cmdline_fixed_string_t cmd_port;
4080         cmdline_fixed_string_t cmd_keyword;
4081         portid_t cmd_pid;
4082 };
4083
4084 static void
4085 cmd_gro_show_parsed(void *parsed_result,
4086                 __attribute__((unused)) struct cmdline *cl,
4087                 __attribute__((unused)) void *data)
4088 {
4089         struct cmd_gro_show_result *res;
4090
4091         res = parsed_result;
4092         if (!strcmp(res->cmd_keyword, "gro"))
4093                 show_gro(res->cmd_pid);
4094 }
4095
4096 cmdline_parse_token_string_t cmd_gro_show_show =
4097         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4098                         cmd_show, "show");
4099 cmdline_parse_token_string_t cmd_gro_show_port =
4100         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4101                         cmd_port, "port");
4102 cmdline_parse_token_num_t cmd_gro_show_pid =
4103         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4104                         cmd_pid, UINT16);
4105 cmdline_parse_token_string_t cmd_gro_show_keyword =
4106         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4107                         cmd_keyword, "gro");
4108
4109 cmdline_parse_inst_t cmd_gro_show = {
4110         .f = cmd_gro_show_parsed,
4111         .data = NULL,
4112         .help_str = "show port <port_id> gro",
4113         .tokens = {
4114                 (void *)&cmd_gro_show_show,
4115                 (void *)&cmd_gro_show_port,
4116                 (void *)&cmd_gro_show_pid,
4117                 (void *)&cmd_gro_show_keyword,
4118                 NULL,
4119         },
4120 };
4121
4122 /* *** SET FLUSH CYCLES FOR GRO *** */
4123 struct cmd_gro_flush_result {
4124         cmdline_fixed_string_t cmd_set;
4125         cmdline_fixed_string_t cmd_keyword;
4126         cmdline_fixed_string_t cmd_flush;
4127         uint8_t cmd_cycles;
4128 };
4129
4130 static void
4131 cmd_gro_flush_parsed(void *parsed_result,
4132                 __attribute__((unused)) struct cmdline *cl,
4133                 __attribute__((unused)) void *data)
4134 {
4135         struct cmd_gro_flush_result *res;
4136
4137         res = parsed_result;
4138         if ((!strcmp(res->cmd_keyword, "gro")) &&
4139                         (!strcmp(res->cmd_flush, "flush")))
4140                 setup_gro_flush_cycles(res->cmd_cycles);
4141 }
4142
4143 cmdline_parse_token_string_t cmd_gro_flush_set =
4144         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4145                         cmd_set, "set");
4146 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4147         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4148                         cmd_keyword, "gro");
4149 cmdline_parse_token_string_t cmd_gro_flush_flush =
4150         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4151                         cmd_flush, "flush");
4152 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4153         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4154                         cmd_cycles, UINT8);
4155
4156 cmdline_parse_inst_t cmd_gro_flush = {
4157         .f = cmd_gro_flush_parsed,
4158         .data = NULL,
4159         .help_str = "set gro flush <cycles>",
4160         .tokens = {
4161                 (void *)&cmd_gro_flush_set,
4162                 (void *)&cmd_gro_flush_keyword,
4163                 (void *)&cmd_gro_flush_flush,
4164                 (void *)&cmd_gro_flush_cycles,
4165                 NULL,
4166         },
4167 };
4168
4169 /* *** ENABLE/DISABLE GSO *** */
4170 struct cmd_gso_enable_result {
4171         cmdline_fixed_string_t cmd_set;
4172         cmdline_fixed_string_t cmd_port;
4173         cmdline_fixed_string_t cmd_keyword;
4174         cmdline_fixed_string_t cmd_mode;
4175         portid_t cmd_pid;
4176 };
4177
4178 static void
4179 cmd_gso_enable_parsed(void *parsed_result,
4180                 __attribute__((unused)) struct cmdline *cl,
4181                 __attribute__((unused)) void *data)
4182 {
4183         struct cmd_gso_enable_result *res;
4184
4185         res = parsed_result;
4186         if (!strcmp(res->cmd_keyword, "gso"))
4187                 setup_gso(res->cmd_mode, res->cmd_pid);
4188 }
4189
4190 cmdline_parse_token_string_t cmd_gso_enable_set =
4191         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4192                         cmd_set, "set");
4193 cmdline_parse_token_string_t cmd_gso_enable_port =
4194         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4195                         cmd_port, "port");
4196 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4197         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4198                         cmd_keyword, "gso");
4199 cmdline_parse_token_string_t cmd_gso_enable_mode =
4200         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4201                         cmd_mode, "on#off");
4202 cmdline_parse_token_num_t cmd_gso_enable_pid =
4203         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4204                         cmd_pid, UINT16);
4205
4206 cmdline_parse_inst_t cmd_gso_enable = {
4207         .f = cmd_gso_enable_parsed,
4208         .data = NULL,
4209         .help_str = "set port <port_id> gso on|off",
4210         .tokens = {
4211                 (void *)&cmd_gso_enable_set,
4212                 (void *)&cmd_gso_enable_port,
4213                 (void *)&cmd_gso_enable_pid,
4214                 (void *)&cmd_gso_enable_keyword,
4215                 (void *)&cmd_gso_enable_mode,
4216                 NULL,
4217         },
4218 };
4219
4220 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4221 struct cmd_gso_size_result {
4222         cmdline_fixed_string_t cmd_set;
4223         cmdline_fixed_string_t cmd_keyword;
4224         cmdline_fixed_string_t cmd_segsz;
4225         uint16_t cmd_size;
4226 };
4227
4228 static void
4229 cmd_gso_size_parsed(void *parsed_result,
4230                        __attribute__((unused)) struct cmdline *cl,
4231                        __attribute__((unused)) void *data)
4232 {
4233         struct cmd_gso_size_result *res = parsed_result;
4234
4235         if (test_done == 0) {
4236                 printf("Before setting GSO segsz, please first"
4237                                 " stop fowarding\n");
4238                 return;
4239         }
4240
4241         if (!strcmp(res->cmd_keyword, "gso") &&
4242                         !strcmp(res->cmd_segsz, "segsz")) {
4243                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4244                         printf("gso_size should be larger than %zu."
4245                                         " Please input a legal value\n",
4246                                         RTE_GSO_SEG_SIZE_MIN);
4247                 else
4248                         gso_max_segment_size = res->cmd_size;
4249         }
4250 }
4251
4252 cmdline_parse_token_string_t cmd_gso_size_set =
4253         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4254                                 cmd_set, "set");
4255 cmdline_parse_token_string_t cmd_gso_size_keyword =
4256         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4257                                 cmd_keyword, "gso");
4258 cmdline_parse_token_string_t cmd_gso_size_segsz =
4259         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4260                                 cmd_segsz, "segsz");
4261 cmdline_parse_token_num_t cmd_gso_size_size =
4262         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4263                                 cmd_size, UINT16);
4264
4265 cmdline_parse_inst_t cmd_gso_size = {
4266         .f = cmd_gso_size_parsed,
4267         .data = NULL,
4268         .help_str = "set gso segsz <length>",
4269         .tokens = {
4270                 (void *)&cmd_gso_size_set,
4271                 (void *)&cmd_gso_size_keyword,
4272                 (void *)&cmd_gso_size_segsz,
4273                 (void *)&cmd_gso_size_size,
4274                 NULL,
4275         },
4276 };
4277
4278 /* *** SHOW GSO CONFIGURATION *** */
4279 struct cmd_gso_show_result {
4280         cmdline_fixed_string_t cmd_show;
4281         cmdline_fixed_string_t cmd_port;
4282         cmdline_fixed_string_t cmd_keyword;
4283         portid_t cmd_pid;
4284 };
4285
4286 static void
4287 cmd_gso_show_parsed(void *parsed_result,
4288                        __attribute__((unused)) struct cmdline *cl,
4289                        __attribute__((unused)) void *data)
4290 {
4291         struct cmd_gso_show_result *res = parsed_result;
4292
4293         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4294                 printf("invalid port id %u\n", res->cmd_pid);
4295                 return;
4296         }
4297         if (!strcmp(res->cmd_keyword, "gso")) {
4298                 if (gso_ports[res->cmd_pid].enable) {
4299                         printf("Max GSO'd packet size: %uB\n"
4300                                         "Supported GSO types: TCP/IPv4, "
4301                                         "VxLAN with inner TCP/IPv4 packet, "
4302                                         "GRE with inner TCP/IPv4  packet\n",
4303                                         gso_max_segment_size);
4304                 } else
4305                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4306         }
4307 }
4308
4309 cmdline_parse_token_string_t cmd_gso_show_show =
4310 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4311                 cmd_show, "show");
4312 cmdline_parse_token_string_t cmd_gso_show_port =
4313 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4314                 cmd_port, "port");
4315 cmdline_parse_token_string_t cmd_gso_show_keyword =
4316         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4317                                 cmd_keyword, "gso");
4318 cmdline_parse_token_num_t cmd_gso_show_pid =
4319         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4320                                 cmd_pid, UINT16);
4321
4322 cmdline_parse_inst_t cmd_gso_show = {
4323         .f = cmd_gso_show_parsed,
4324         .data = NULL,
4325         .help_str = "show port <port_id> gso",
4326         .tokens = {
4327                 (void *)&cmd_gso_show_show,
4328                 (void *)&cmd_gso_show_port,
4329                 (void *)&cmd_gso_show_pid,
4330                 (void *)&cmd_gso_show_keyword,
4331                 NULL,
4332         },
4333 };
4334
4335 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4336 struct cmd_set_flush_rx {
4337         cmdline_fixed_string_t set;
4338         cmdline_fixed_string_t flush_rx;
4339         cmdline_fixed_string_t mode;
4340 };
4341
4342 static void
4343 cmd_set_flush_rx_parsed(void *parsed_result,
4344                 __attribute__((unused)) struct cmdline *cl,
4345                 __attribute__((unused)) void *data)
4346 {
4347         struct cmd_set_flush_rx *res = parsed_result;
4348         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4349 }
4350
4351 cmdline_parse_token_string_t cmd_setflushrx_set =
4352         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4353                         set, "set");
4354 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4355         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4356                         flush_rx, "flush_rx");
4357 cmdline_parse_token_string_t cmd_setflushrx_mode =
4358         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4359                         mode, "on#off");
4360
4361
4362 cmdline_parse_inst_t cmd_set_flush_rx = {
4363         .f = cmd_set_flush_rx_parsed,
4364         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4365         .data = NULL,
4366         .tokens = {
4367                 (void *)&cmd_setflushrx_set,
4368                 (void *)&cmd_setflushrx_flush_rx,
4369                 (void *)&cmd_setflushrx_mode,
4370                 NULL,
4371         },
4372 };
4373
4374 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4375 struct cmd_set_link_check {
4376         cmdline_fixed_string_t set;
4377         cmdline_fixed_string_t link_check;
4378         cmdline_fixed_string_t mode;
4379 };
4380
4381 static void
4382 cmd_set_link_check_parsed(void *parsed_result,
4383                 __attribute__((unused)) struct cmdline *cl,
4384                 __attribute__((unused)) void *data)
4385 {
4386         struct cmd_set_link_check *res = parsed_result;
4387         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4388 }
4389
4390 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4391         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4392                         set, "set");
4393 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4394         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4395                         link_check, "link_check");
4396 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4397         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4398                         mode, "on#off");
4399
4400
4401 cmdline_parse_inst_t cmd_set_link_check = {
4402         .f = cmd_set_link_check_parsed,
4403         .help_str = "set link_check on|off: Enable/Disable link status check "
4404                     "when starting/stopping a port",
4405         .data = NULL,
4406         .tokens = {
4407                 (void *)&cmd_setlinkcheck_set,
4408                 (void *)&cmd_setlinkcheck_link_check,
4409                 (void *)&cmd_setlinkcheck_mode,
4410                 NULL,
4411         },
4412 };
4413
4414 /* *** SET NIC BYPASS MODE *** */
4415 struct cmd_set_bypass_mode_result {
4416         cmdline_fixed_string_t set;
4417         cmdline_fixed_string_t bypass;
4418         cmdline_fixed_string_t mode;
4419         cmdline_fixed_string_t value;
4420         portid_t port_id;
4421 };
4422
4423 static void
4424 cmd_set_bypass_mode_parsed(void *parsed_result,
4425                 __attribute__((unused)) struct cmdline *cl,
4426                 __attribute__((unused)) void *data)
4427 {
4428         struct cmd_set_bypass_mode_result *res = parsed_result;
4429         portid_t port_id = res->port_id;
4430         int32_t rc = -EINVAL;
4431
4432 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4433         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4434
4435         if (!strcmp(res->value, "bypass"))
4436                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4437         else if (!strcmp(res->value, "isolate"))
4438                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4439         else
4440                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4441
4442         /* Set the bypass mode for the relevant port. */
4443         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4444 #endif
4445         if (rc != 0)
4446                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4447 }
4448
4449 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4450         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4451                         set, "set");
4452 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4453         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4454                         bypass, "bypass");
4455 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4456         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4457                         mode, "mode");
4458 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4460                         value, "normal#bypass#isolate");
4461 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4462         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4463                                 port_id, UINT16);
4464
4465 cmdline_parse_inst_t cmd_set_bypass_mode = {
4466         .f = cmd_set_bypass_mode_parsed,
4467         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4468                     "Set the NIC bypass mode for port_id",
4469         .data = NULL,
4470         .tokens = {
4471                 (void *)&cmd_setbypass_mode_set,
4472                 (void *)&cmd_setbypass_mode_bypass,
4473                 (void *)&cmd_setbypass_mode_mode,
4474                 (void *)&cmd_setbypass_mode_value,
4475                 (void *)&cmd_setbypass_mode_port,
4476                 NULL,
4477         },
4478 };
4479
4480 /* *** SET NIC BYPASS EVENT *** */
4481 struct cmd_set_bypass_event_result {
4482         cmdline_fixed_string_t set;
4483         cmdline_fixed_string_t bypass;
4484         cmdline_fixed_string_t event;
4485         cmdline_fixed_string_t event_value;
4486         cmdline_fixed_string_t mode;
4487         cmdline_fixed_string_t mode_value;
4488         portid_t port_id;
4489 };
4490
4491 static void
4492 cmd_set_bypass_event_parsed(void *parsed_result,
4493                 __attribute__((unused)) struct cmdline *cl,
4494                 __attribute__((unused)) void *data)
4495 {
4496         int32_t rc = -EINVAL;
4497         struct cmd_set_bypass_event_result *res = parsed_result;
4498         portid_t port_id = res->port_id;
4499
4500 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4501         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4502         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4503
4504         if (!strcmp(res->event_value, "timeout"))
4505                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4506         else if (!strcmp(res->event_value, "os_on"))
4507                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4508         else if (!strcmp(res->event_value, "os_off"))
4509                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4510         else if (!strcmp(res->event_value, "power_on"))
4511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4512         else if (!strcmp(res->event_value, "power_off"))
4513                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4514         else
4515                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4516
4517         if (!strcmp(res->mode_value, "bypass"))
4518                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4519         else if (!strcmp(res->mode_value, "isolate"))
4520                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4521         else
4522                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4523
4524         /* Set the watchdog timeout. */
4525         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4526
4527                 rc = -EINVAL;
4528                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4529                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4530                                                            bypass_timeout);
4531                 }
4532                 if (rc != 0) {
4533                         printf("Failed to set timeout value %u "
4534                         "for port %d, errto code: %d.\n",
4535                         bypass_timeout, port_id, rc);
4536                 }
4537         }
4538
4539         /* Set the bypass event to transition to bypass mode. */
4540         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4541                                               bypass_mode);
4542 #endif
4543
4544         if (rc != 0)
4545                 printf("\t Failed to set bypass event for port = %d.\n",
4546                        port_id);
4547 }
4548
4549 cmdline_parse_token_string_t cmd_setbypass_event_set =
4550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4551                         set, "set");
4552 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4554                         bypass, "bypass");
4555 cmdline_parse_token_string_t cmd_setbypass_event_event =
4556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4557                         event, "event");
4558 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4560                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4561 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4563                         mode, "mode");
4564 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4566                         mode_value, "normal#bypass#isolate");
4567 cmdline_parse_token_num_t cmd_setbypass_event_port =
4568         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4569                                 port_id, UINT16);
4570
4571 cmdline_parse_inst_t cmd_set_bypass_event = {
4572         .f = cmd_set_bypass_event_parsed,
4573         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4574                 "power_off mode normal|bypass|isolate <port_id>: "
4575                 "Set the NIC bypass event mode for port_id",
4576         .data = NULL,
4577         .tokens = {
4578                 (void *)&cmd_setbypass_event_set,
4579                 (void *)&cmd_setbypass_event_bypass,
4580                 (void *)&cmd_setbypass_event_event,
4581                 (void *)&cmd_setbypass_event_event_value,
4582                 (void *)&cmd_setbypass_event_mode,
4583                 (void *)&cmd_setbypass_event_mode_value,
4584                 (void *)&cmd_setbypass_event_port,
4585                 NULL,
4586         },
4587 };
4588
4589
4590 /* *** SET NIC BYPASS TIMEOUT *** */
4591 struct cmd_set_bypass_timeout_result {
4592         cmdline_fixed_string_t set;
4593         cmdline_fixed_string_t bypass;
4594         cmdline_fixed_string_t timeout;
4595         cmdline_fixed_string_t value;
4596 };
4597
4598 static void
4599 cmd_set_bypass_timeout_parsed(void *parsed_result,
4600                 __attribute__((unused)) struct cmdline *cl,
4601                 __attribute__((unused)) void *data)
4602 {
4603         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4604
4605 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4606         if (!strcmp(res->value, "1.5"))
4607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4608         else if (!strcmp(res->value, "2"))
4609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4610         else if (!strcmp(res->value, "3"))
4611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4612         else if (!strcmp(res->value, "4"))
4613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4614         else if (!strcmp(res->value, "8"))
4615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4616         else if (!strcmp(res->value, "16"))
4617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4618         else if (!strcmp(res->value, "32"))
4619                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4620         else
4621                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4622 #endif
4623 }
4624
4625 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4626         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4627                         set, "set");
4628 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4630                         bypass, "bypass");
4631 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4633                         timeout, "timeout");
4634 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4636                         value, "0#1.5#2#3#4#8#16#32");
4637
4638 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4639         .f = cmd_set_bypass_timeout_parsed,
4640         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4641                 "Set the NIC bypass watchdog timeout in seconds",
4642         .data = NULL,
4643         .tokens = {
4644                 (void *)&cmd_setbypass_timeout_set,
4645                 (void *)&cmd_setbypass_timeout_bypass,
4646                 (void *)&cmd_setbypass_timeout_timeout,
4647                 (void *)&cmd_setbypass_timeout_value,
4648                 NULL,
4649         },
4650 };
4651
4652 /* *** SHOW NIC BYPASS MODE *** */
4653 struct cmd_show_bypass_config_result {
4654         cmdline_fixed_string_t show;
4655         cmdline_fixed_string_t bypass;
4656         cmdline_fixed_string_t config;
4657         portid_t port_id;
4658 };
4659
4660 static void
4661 cmd_show_bypass_config_parsed(void *parsed_result,
4662                 __attribute__((unused)) struct cmdline *cl,
4663                 __attribute__((unused)) void *data)
4664 {
4665         struct cmd_show_bypass_config_result *res = parsed_result;
4666         portid_t port_id = res->port_id;
4667         int rc = -EINVAL;
4668 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4669         uint32_t event_mode;
4670         uint32_t bypass_mode;
4671         uint32_t timeout = bypass_timeout;
4672         int i;
4673
4674         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4675                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4676         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4677                 {"UNKNOWN", "normal", "bypass", "isolate"};
4678         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4679                 "NONE",
4680                 "OS/board on",
4681                 "power supply on",
4682                 "OS/board off",
4683                 "power supply off",
4684                 "timeout"};
4685         int num_events = (sizeof events) / (sizeof events[0]);
4686
4687         /* Display the bypass mode.*/
4688         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4689                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4690                 return;
4691         }
4692         else {
4693                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4694                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4695
4696                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4697         }
4698
4699         /* Display the bypass timeout.*/
4700         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4701                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4702
4703         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4704
4705         /* Display the bypass events and associated modes. */
4706         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4707
4708                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4709                         printf("\tFailed to get bypass mode for event = %s\n",
4710                                 events[i]);
4711                 } else {
4712                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4713                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4714
4715                         printf("\tbypass event: %-16s = %s\n", events[i],
4716                                 modes[event_mode]);
4717                 }
4718         }
4719 #endif
4720         if (rc != 0)
4721                 printf("\tFailed to get bypass configuration for port = %d\n",
4722                        port_id);
4723 }
4724
4725 cmdline_parse_token_string_t cmd_showbypass_config_show =
4726         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4727                         show, "show");
4728 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4729         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4730                         bypass, "bypass");
4731 cmdline_parse_token_string_t cmd_showbypass_config_config =
4732         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4733                         config, "config");
4734 cmdline_parse_token_num_t cmd_showbypass_config_port =
4735         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4736                                 port_id, UINT16);
4737
4738 cmdline_parse_inst_t cmd_show_bypass_config = {
4739         .f = cmd_show_bypass_config_parsed,
4740         .help_str = "show bypass config <port_id>: "
4741                     "Show the NIC bypass config for port_id",
4742         .data = NULL,
4743         .tokens = {
4744                 (void *)&cmd_showbypass_config_show,
4745                 (void *)&cmd_showbypass_config_bypass,
4746                 (void *)&cmd_showbypass_config_config,
4747                 (void *)&cmd_showbypass_config_port,
4748                 NULL,
4749         },
4750 };
4751
4752 #ifdef RTE_LIBRTE_PMD_BOND
4753 /* *** SET BONDING MODE *** */
4754 struct cmd_set_bonding_mode_result {
4755         cmdline_fixed_string_t set;
4756         cmdline_fixed_string_t bonding;
4757         cmdline_fixed_string_t mode;
4758         uint8_t value;
4759         portid_t port_id;
4760 };
4761
4762 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4763                 __attribute__((unused))  struct cmdline *cl,
4764                 __attribute__((unused)) void *data)
4765 {
4766         struct cmd_set_bonding_mode_result *res = parsed_result;
4767         portid_t port_id = res->port_id;
4768
4769         /* Set the bonding mode for the relevant port. */
4770         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4771                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4772 }
4773
4774 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4775 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4776                 set, "set");
4777 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4778 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4779                 bonding, "bonding");
4780 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4781 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4782                 mode, "mode");
4783 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4784 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4785                 value, UINT8);
4786 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4787 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4788                 port_id, UINT16);
4789
4790 cmdline_parse_inst_t cmd_set_bonding_mode = {
4791                 .f = cmd_set_bonding_mode_parsed,
4792                 .help_str = "set bonding mode <mode_value> <port_id>: "
4793                         "Set the bonding mode for port_id",
4794                 .data = NULL,
4795                 .tokens = {
4796                                 (void *) &cmd_setbonding_mode_set,
4797                                 (void *) &cmd_setbonding_mode_bonding,
4798                                 (void *) &cmd_setbonding_mode_mode,
4799                                 (void *) &cmd_setbonding_mode_value,
4800                                 (void *) &cmd_setbonding_mode_port,
4801                                 NULL
4802                 }
4803 };
4804
4805 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4806 struct cmd_set_bonding_lacp_dedicated_queues_result {
4807         cmdline_fixed_string_t set;
4808         cmdline_fixed_string_t bonding;
4809         cmdline_fixed_string_t lacp;
4810         cmdline_fixed_string_t dedicated_queues;
4811         portid_t port_id;
4812         cmdline_fixed_string_t mode;
4813 };
4814
4815 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4816                 __attribute__((unused))  struct cmdline *cl,
4817                 __attribute__((unused)) void *data)
4818 {
4819         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4820         portid_t port_id = res->port_id;
4821         struct rte_port *port;
4822
4823         port = &ports[port_id];
4824
4825         /** Check if the port is not started **/
4826         if (port->port_status != RTE_PORT_STOPPED) {
4827                 printf("Please stop port %d first\n", port_id);
4828                 return;
4829         }
4830
4831         if (!strcmp(res->mode, "enable")) {
4832                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4833                         printf("Dedicate queues for LACP control packets"
4834                                         " enabled\n");
4835                 else
4836                         printf("Enabling dedicate queues for LACP control "
4837                                         "packets on port %d failed\n", port_id);
4838         } else if (!strcmp(res->mode, "disable")) {
4839                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4840                         printf("Dedicated queues for LACP control packets "
4841                                         "disabled\n");
4842                 else
4843                         printf("Disabling dedicated queues for LACP control "
4844                                         "traffic on port %d failed\n", port_id);
4845         }
4846 }
4847
4848 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4849 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4850                 set, "set");
4851 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4852 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4853                 bonding, "bonding");
4854 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4855 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4856                 lacp, "lacp");
4857 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4858 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4859                 dedicated_queues, "dedicated_queues");
4860 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4861 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4862                 port_id, UINT16);
4863 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4864 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4865                 mode, "enable#disable");
4866
4867 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4868                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4869                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4870                         "enable|disable: "
4871                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4872                 .data = NULL,
4873                 .tokens = {
4874                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4875                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4876                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4877                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4878                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4879                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4880                         NULL
4881                 }
4882 };
4883
4884 /* *** SET BALANCE XMIT POLICY *** */
4885 struct cmd_set_bonding_balance_xmit_policy_result {
4886         cmdline_fixed_string_t set;
4887         cmdline_fixed_string_t bonding;
4888         cmdline_fixed_string_t balance_xmit_policy;
4889         portid_t port_id;
4890         cmdline_fixed_string_t policy;
4891 };
4892
4893 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4894                 __attribute__((unused))  struct cmdline *cl,
4895                 __attribute__((unused)) void *data)
4896 {
4897         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4898         portid_t port_id = res->port_id;
4899         uint8_t policy;
4900
4901         if (!strcmp(res->policy, "l2")) {
4902                 policy = BALANCE_XMIT_POLICY_LAYER2;
4903         } else if (!strcmp(res->policy, "l23")) {
4904                 policy = BALANCE_XMIT_POLICY_LAYER23;
4905         } else if (!strcmp(res->policy, "l34")) {
4906                 policy = BALANCE_XMIT_POLICY_LAYER34;
4907         } else {
4908                 printf("\t Invalid xmit policy selection");
4909                 return;
4910         }
4911
4912         /* Set the bonding mode for the relevant port. */
4913         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4914                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4915                                 port_id);
4916         }
4917 }
4918
4919 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4921                 set, "set");
4922 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4923 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4924                 bonding, "bonding");
4925 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4926 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4927                 balance_xmit_policy, "balance_xmit_policy");
4928 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4929 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4930                 port_id, UINT16);
4931 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4932 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4933                 policy, "l2#l23#l34");
4934
4935 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4936                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4937                 .help_str = "set bonding balance_xmit_policy <port_id> "
4938                         "l2|l23|l34: "
4939                         "Set the bonding balance_xmit_policy for port_id",
4940                 .data = NULL,
4941                 .tokens = {
4942                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4943                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4944                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4945                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4946                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4947                                 NULL
4948                 }
4949 };
4950
4951 /* *** SHOW NIC BONDING CONFIGURATION *** */
4952 struct cmd_show_bonding_config_result {
4953         cmdline_fixed_string_t show;
4954         cmdline_fixed_string_t bonding;
4955         cmdline_fixed_string_t config;
4956         portid_t port_id;
4957 };
4958
4959 static void cmd_show_bonding_config_parsed(void *parsed_result,
4960                 __attribute__((unused))  struct cmdline *cl,
4961                 __attribute__((unused)) void *data)
4962 {
4963         struct cmd_show_bonding_config_result *res = parsed_result;
4964         int bonding_mode, agg_mode;
4965         portid_t slaves[RTE_MAX_ETHPORTS];
4966         int num_slaves, num_active_slaves;
4967         int primary_id;
4968         int i;
4969         portid_t port_id = res->port_id;
4970
4971         /* Display the bonding mode.*/
4972         bonding_mode = rte_eth_bond_mode_get(port_id);
4973         if (bonding_mode < 0) {
4974                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4975                 return;
4976         } else
4977                 printf("\tBonding mode: %d\n", bonding_mode);
4978
4979         if (bonding_mode == BONDING_MODE_BALANCE) {
4980                 int balance_xmit_policy;
4981
4982                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4983                 if (balance_xmit_policy < 0) {
4984                         printf("\tFailed to get balance xmit policy for port = %d\n",
4985                                         port_id);
4986                         return;
4987                 } else {
4988                         printf("\tBalance Xmit Policy: ");
4989
4990                         switch (balance_xmit_policy) {
4991                         case BALANCE_XMIT_POLICY_LAYER2:
4992                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4993                                 break;
4994                         case BALANCE_XMIT_POLICY_LAYER23:
4995                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4996                                 break;
4997                         case BALANCE_XMIT_POLICY_LAYER34:
4998                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4999                                 break;
5000                         }
5001                         printf("\n");
5002                 }
5003         }
5004
5005         if (bonding_mode == BONDING_MODE_8023AD) {
5006                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5007                 printf("\tIEEE802.3AD Aggregator Mode: ");
5008                 switch (agg_mode) {
5009                 case AGG_BANDWIDTH:
5010                         printf("bandwidth");
5011                         break;
5012                 case AGG_STABLE:
5013                         printf("stable");
5014                         break;
5015                 case AGG_COUNT:
5016                         printf("count");
5017                         break;
5018                 }
5019                 printf("\n");
5020         }
5021
5022         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5023
5024         if (num_slaves < 0) {
5025                 printf("\tFailed to get slave list for port = %d\n", port_id);
5026                 return;
5027         }
5028         if (num_slaves > 0) {
5029                 printf("\tSlaves (%d): [", num_slaves);
5030                 for (i = 0; i < num_slaves - 1; i++)
5031                         printf("%d ", slaves[i]);
5032
5033                 printf("%d]\n", slaves[num_slaves - 1]);
5034         } else {
5035                 printf("\tSlaves: []\n");
5036
5037         }
5038
5039         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5040                         RTE_MAX_ETHPORTS);
5041
5042         if (num_active_slaves < 0) {
5043                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5044                 return;
5045         }
5046         if (num_active_slaves > 0) {
5047                 printf("\tActive Slaves (%d): [", num_active_slaves);
5048                 for (i = 0; i < num_active_slaves - 1; i++)
5049                         printf("%d ", slaves[i]);
5050
5051                 printf("%d]\n", slaves[num_active_slaves - 1]);
5052
5053         } else {
5054                 printf("\tActive Slaves: []\n");
5055
5056         }
5057
5058         primary_id = rte_eth_bond_primary_get(port_id);
5059         if (primary_id < 0) {
5060                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5061                 return;
5062         } else
5063                 printf("\tPrimary: [%d]\n", primary_id);
5064
5065 }
5066
5067 cmdline_parse_token_string_t cmd_showbonding_config_show =
5068 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5069                 show, "show");
5070 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5071 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5072                 bonding, "bonding");
5073 cmdline_parse_token_string_t cmd_showbonding_config_config =
5074 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5075                 config, "config");
5076 cmdline_parse_token_num_t cmd_showbonding_config_port =
5077 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5078                 port_id, UINT16);
5079
5080 cmdline_parse_inst_t cmd_show_bonding_config = {
5081                 .f = cmd_show_bonding_config_parsed,
5082                 .help_str = "show bonding config <port_id>: "
5083                         "Show the bonding config for port_id",
5084                 .data = NULL,
5085                 .tokens = {
5086                                 (void *)&cmd_showbonding_config_show,
5087                                 (void *)&cmd_showbonding_config_bonding,
5088                                 (void *)&cmd_showbonding_config_config,
5089                                 (void *)&cmd_showbonding_config_port,
5090                                 NULL
5091                 }
5092 };
5093
5094 /* *** SET BONDING PRIMARY *** */
5095 struct cmd_set_bonding_primary_result {
5096         cmdline_fixed_string_t set;
5097         cmdline_fixed_string_t bonding;
5098         cmdline_fixed_string_t primary;
5099         portid_t slave_id;
5100         portid_t port_id;
5101 };
5102
5103 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5104                 __attribute__((unused))  struct cmdline *cl,
5105                 __attribute__((unused)) void *data)
5106 {
5107         struct cmd_set_bonding_primary_result *res = parsed_result;
5108         portid_t master_port_id = res->port_id;
5109         portid_t slave_port_id = res->slave_id;
5110
5111         /* Set the primary slave for a bonded device. */
5112         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5113                 printf("\t Failed to set primary slave for port = %d.\n",
5114                                 master_port_id);
5115                 return;
5116         }
5117         init_port_config();
5118 }
5119
5120 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5121 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5122                 set, "set");
5123 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5124 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5125                 bonding, "bonding");
5126 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5127 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5128                 primary, "primary");
5129 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5130 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5131                 slave_id, UINT16);
5132 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5133 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5134                 port_id, UINT16);
5135
5136 cmdline_parse_inst_t cmd_set_bonding_primary = {
5137                 .f = cmd_set_bonding_primary_parsed,
5138                 .help_str = "set bonding primary <slave_id> <port_id>: "
5139                         "Set the primary slave for port_id",
5140                 .data = NULL,
5141                 .tokens = {
5142                                 (void *)&cmd_setbonding_primary_set,
5143                                 (void *)&cmd_setbonding_primary_bonding,
5144                                 (void *)&cmd_setbonding_primary_primary,
5145                                 (void *)&cmd_setbonding_primary_slave,
5146                                 (void *)&cmd_setbonding_primary_port,
5147                                 NULL
5148                 }
5149 };
5150
5151 /* *** ADD SLAVE *** */
5152 struct cmd_add_bonding_slave_result {
5153         cmdline_fixed_string_t add;
5154         cmdline_fixed_string_t bonding;
5155         cmdline_fixed_string_t slave;
5156         portid_t slave_id;
5157         portid_t port_id;
5158 };
5159
5160 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5161                 __attribute__((unused))  struct cmdline *cl,
5162                 __attribute__((unused)) void *data)
5163 {
5164         struct cmd_add_bonding_slave_result *res = parsed_result;
5165         portid_t master_port_id = res->port_id;
5166         portid_t slave_port_id = res->slave_id;
5167
5168         /* add the slave for a bonded device. */
5169         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5170                 printf("\t Failed to add slave %d to master port = %d.\n",
5171                                 slave_port_id, master_port_id);
5172                 return;
5173         }
5174         init_port_config();
5175         set_port_slave_flag(slave_port_id);
5176 }
5177
5178 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5179 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5180                 add, "add");
5181 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5182 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5183                 bonding, "bonding");
5184 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5185 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5186                 slave, "slave");
5187 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5188 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5189                 slave_id, UINT16);
5190 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5191 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5192                 port_id, UINT16);
5193
5194 cmdline_parse_inst_t cmd_add_bonding_slave = {
5195                 .f = cmd_add_bonding_slave_parsed,
5196                 .help_str = "add bonding slave <slave_id> <port_id>: "
5197                         "Add a slave device to a bonded device",
5198                 .data = NULL,
5199                 .tokens = {
5200                                 (void *)&cmd_addbonding_slave_add,
5201                                 (void *)&cmd_addbonding_slave_bonding,
5202                                 (void *)&cmd_addbonding_slave_slave,
5203                                 (void *)&cmd_addbonding_slave_slaveid,
5204                                 (void *)&cmd_addbonding_slave_port,
5205                                 NULL
5206                 }
5207 };
5208
5209 /* *** REMOVE SLAVE *** */
5210 struct cmd_remove_bonding_slave_result {
5211         cmdline_fixed_string_t remove;
5212         cmdline_fixed_string_t bonding;
5213         cmdline_fixed_string_t slave;
5214         portid_t slave_id;
5215         portid_t port_id;
5216 };
5217
5218 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5219                 __attribute__((unused))  struct cmdline *cl,
5220                 __attribute__((unused)) void *data)
5221 {
5222         struct cmd_remove_bonding_slave_result *res = parsed_result;
5223         portid_t master_port_id = res->port_id;
5224         portid_t slave_port_id = res->slave_id;
5225
5226         /* remove the slave from a bonded device. */
5227         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5228                 printf("\t Failed to remove slave %d from master port = %d.\n",
5229                                 slave_port_id, master_port_id);
5230                 return;
5231         }
5232         init_port_config();
5233         clear_port_slave_flag(slave_port_id);
5234 }
5235
5236 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5237                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5238                                 remove, "remove");
5239 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5240                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5241                                 bonding, "bonding");
5242 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5243                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5244                                 slave, "slave");
5245 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5246                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5247                                 slave_id, UINT16);
5248 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5249                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5250                                 port_id, UINT16);
5251
5252 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5253                 .f = cmd_remove_bonding_slave_parsed,
5254                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5255                         "Remove a slave device from a bonded device",
5256                 .data = NULL,
5257                 .tokens = {
5258                                 (void *)&cmd_removebonding_slave_remove,
5259                                 (void *)&cmd_removebonding_slave_bonding,
5260                                 (void *)&cmd_removebonding_slave_slave,
5261                                 (void *)&cmd_removebonding_slave_slaveid,
5262                                 (void *)&cmd_removebonding_slave_port,
5263                                 NULL
5264                 }
5265 };
5266
5267 /* *** CREATE BONDED DEVICE *** */
5268 struct cmd_create_bonded_device_result {
5269         cmdline_fixed_string_t create;
5270         cmdline_fixed_string_t bonded;
5271         cmdline_fixed_string_t device;
5272         uint8_t mode;
5273         uint8_t socket;
5274 };
5275
5276 static int bond_dev_num = 0;
5277
5278 static void cmd_create_bonded_device_parsed(void *parsed_result,
5279                 __attribute__((unused))  struct cmdline *cl,
5280                 __attribute__((unused)) void *data)
5281 {
5282         struct cmd_create_bonded_device_result *res = parsed_result;
5283         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5284         int port_id;
5285
5286         if (test_done == 0) {
5287                 printf("Please stop forwarding first\n");
5288                 return;
5289         }
5290
5291         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5292                         bond_dev_num++);
5293
5294         /* Create a new bonded device. */
5295         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5296         if (port_id < 0) {
5297                 printf("\t Failed to create bonded device.\n");
5298                 return;
5299         } else {
5300                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5301                                 port_id);
5302
5303                 /* Update number of ports */
5304                 nb_ports = rte_eth_dev_count();
5305                 reconfig(port_id, res->socket);
5306                 rte_eth_promiscuous_enable(port_id);
5307         }
5308
5309 }
5310
5311 cmdline_parse_token_string_t cmd_createbonded_device_create =
5312                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5313                                 create, "create");
5314 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5315                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5316                                 bonded, "bonded");
5317 cmdline_parse_token_string_t cmd_createbonded_device_device =
5318                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5319                                 device, "device");
5320 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5321                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5322                                 mode, UINT8);
5323 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5324                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5325                                 socket, UINT8);
5326
5327 cmdline_parse_inst_t cmd_create_bonded_device = {
5328                 .f = cmd_create_bonded_device_parsed,
5329                 .help_str = "create bonded device <mode> <socket>: "
5330                         "Create a new bonded device with specific bonding mode and socket",
5331                 .data = NULL,
5332                 .tokens = {
5333                                 (void *)&cmd_createbonded_device_create,
5334                                 (void *)&cmd_createbonded_device_bonded,
5335                                 (void *)&cmd_createbonded_device_device,
5336                                 (void *)&cmd_createbonded_device_mode,
5337                                 (void *)&cmd_createbonded_device_socket,
5338                                 NULL
5339                 }
5340 };
5341
5342 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5343 struct cmd_set_bond_mac_addr_result {
5344         cmdline_fixed_string_t set;
5345         cmdline_fixed_string_t bonding;
5346         cmdline_fixed_string_t mac_addr;
5347         uint16_t port_num;
5348         struct ether_addr address;
5349 };
5350
5351 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5352                 __attribute__((unused))  struct cmdline *cl,
5353                 __attribute__((unused)) void *data)
5354 {
5355         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5356         int ret;
5357
5358         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5359                 return;
5360
5361         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5362
5363         /* check the return value and print it if is < 0 */
5364         if (ret < 0)
5365                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5366 }
5367
5368 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5369                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5370 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5371                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5372                                 "bonding");
5373 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5374                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5375                                 "mac_addr");
5376 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5377                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5378                                 port_num, UINT16);
5379 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5380                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5381
5382 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5383                 .f = cmd_set_bond_mac_addr_parsed,
5384                 .data = (void *) 0,
5385                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5386                 .tokens = {
5387                                 (void *)&cmd_set_bond_mac_addr_set,
5388                                 (void *)&cmd_set_bond_mac_addr_bonding,
5389                                 (void *)&cmd_set_bond_mac_addr_mac,
5390                                 (void *)&cmd_set_bond_mac_addr_portnum,
5391                                 (void *)&cmd_set_bond_mac_addr_addr,
5392                                 NULL
5393                 }
5394 };
5395
5396
5397 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5398 struct cmd_set_bond_mon_period_result {
5399         cmdline_fixed_string_t set;
5400         cmdline_fixed_string_t bonding;
5401         cmdline_fixed_string_t mon_period;
5402         uint16_t port_num;
5403         uint32_t period_ms;
5404 };
5405
5406 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5407                 __attribute__((unused))  struct cmdline *cl,
5408                 __attribute__((unused)) void *data)
5409 {
5410         struct cmd_set_bond_mon_period_result *res = parsed_result;
5411         int ret;
5412
5413         if (res->port_num >= nb_ports) {
5414                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5415                 return;
5416         }
5417
5418         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5419
5420         /* check the return value and print it if is < 0 */
5421         if (ret < 0)
5422                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5423 }
5424
5425 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5426                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5427                                 set, "set");
5428 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5429                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5430                                 bonding, "bonding");
5431 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5432                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5433                                 mon_period,     "mon_period");
5434 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5435                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5436                                 port_num, UINT16);
5437 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5438                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5439                                 period_ms, UINT32);
5440
5441 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5442                 .f = cmd_set_bond_mon_period_parsed,
5443                 .data = (void *) 0,
5444                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5445                 .tokens = {
5446                                 (void *)&cmd_set_bond_mon_period_set,
5447                                 (void *)&cmd_set_bond_mon_period_bonding,
5448                                 (void *)&cmd_set_bond_mon_period_mon_period,
5449                                 (void *)&cmd_set_bond_mon_period_portnum,
5450                                 (void *)&cmd_set_bond_mon_period_period_ms,
5451                                 NULL
5452                 }
5453 };
5454
5455
5456
5457 struct cmd_set_bonding_agg_mode_policy_result {
5458         cmdline_fixed_string_t set;
5459         cmdline_fixed_string_t bonding;
5460         cmdline_fixed_string_t agg_mode;
5461         uint16_t port_num;
5462         cmdline_fixed_string_t policy;
5463 };
5464
5465
5466 static void
5467 cmd_set_bonding_agg_mode(void *parsed_result,
5468                 __attribute__((unused)) struct cmdline *cl,
5469                 __attribute__((unused)) void *data)
5470 {
5471         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5472         uint8_t policy = AGG_BANDWIDTH;
5473
5474         if (res->port_num >= nb_ports) {
5475                 printf("Port id %d must be less than %d\n",
5476                                 res->port_num, nb_ports);
5477                 return;
5478         }
5479
5480         if (!strcmp(res->policy, "bandwidth"))
5481                 policy = AGG_BANDWIDTH;
5482         else if (!strcmp(res->policy, "stable"))
5483                 policy = AGG_STABLE;
5484         else if (!strcmp(res->policy, "count"))
5485                 policy = AGG_COUNT;
5486
5487         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5488 }
5489
5490
5491 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5492         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5493                                 set, "set");
5494 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5495         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5496                                 bonding, "bonding");
5497
5498 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5499         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5500                                 agg_mode, "agg_mode");
5501
5502 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5503         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5504                                 port_num, UINT16);
5505
5506 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5507         TOKEN_STRING_INITIALIZER(
5508                         struct cmd_set_bonding_balance_xmit_policy_result,
5509                 policy, "stable#bandwidth#count");
5510
5511 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5512         .f = cmd_set_bonding_agg_mode,
5513         .data = (void *) 0,
5514         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5515         .tokens = {
5516                         (void *)&cmd_set_bonding_agg_mode_set,
5517                         (void *)&cmd_set_bonding_agg_mode_bonding,
5518                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5519                         (void *)&cmd_set_bonding_agg_mode_portnum,
5520                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5521                         NULL
5522                 }
5523 };
5524
5525
5526 #endif /* RTE_LIBRTE_PMD_BOND */
5527
5528 /* *** SET FORWARDING MODE *** */
5529 struct cmd_set_fwd_mode_result {
5530         cmdline_fixed_string_t set;
5531         cmdline_fixed_string_t fwd;
5532         cmdline_fixed_string_t mode;
5533 };
5534
5535 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5536                                     __attribute__((unused)) struct cmdline *cl,
5537                                     __attribute__((unused)) void *data)
5538 {
5539         struct cmd_set_fwd_mode_result *res = parsed_result;
5540
5541         retry_enabled = 0;
5542         set_pkt_forwarding_mode(res->mode);
5543 }
5544
5545 cmdline_parse_token_string_t cmd_setfwd_set =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5547 cmdline_parse_token_string_t cmd_setfwd_fwd =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5549 cmdline_parse_token_string_t cmd_setfwd_mode =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5551                 "" /* defined at init */);
5552
5553 cmdline_parse_inst_t cmd_set_fwd_mode = {
5554         .f = cmd_set_fwd_mode_parsed,
5555         .data = NULL,
5556         .help_str = NULL, /* defined at init */
5557         .tokens = {
5558                 (void *)&cmd_setfwd_set,
5559                 (void *)&cmd_setfwd_fwd,
5560                 (void *)&cmd_setfwd_mode,
5561                 NULL,
5562         },
5563 };
5564
5565 static void cmd_set_fwd_mode_init(void)
5566 {
5567         char *modes, *c;
5568         static char token[128];
5569         static char help[256];
5570         cmdline_parse_token_string_t *token_struct;
5571
5572         modes = list_pkt_forwarding_modes();
5573         snprintf(help, sizeof(help), "set fwd %s: "
5574                 "Set packet forwarding mode", modes);
5575         cmd_set_fwd_mode.help_str = help;
5576
5577         /* string token separator is # */
5578         for (c = token; *modes != '\0'; modes++)
5579                 if (*modes == '|')
5580                         *c++ = '#';
5581                 else
5582                         *c++ = *modes;
5583         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5584         token_struct->string_data.str = token;
5585 }
5586
5587 /* *** SET RETRY FORWARDING MODE *** */
5588 struct cmd_set_fwd_retry_mode_result {
5589         cmdline_fixed_string_t set;
5590         cmdline_fixed_string_t fwd;
5591         cmdline_fixed_string_t mode;
5592         cmdline_fixed_string_t retry;
5593 };
5594
5595 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5596                             __attribute__((unused)) struct cmdline *cl,
5597                             __attribute__((unused)) void *data)
5598 {
5599         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5600
5601         retry_enabled = 1;
5602         set_pkt_forwarding_mode(res->mode);
5603 }
5604
5605 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5606         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5607                         set, "set");
5608 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5609         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5610                         fwd, "fwd");
5611 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5612         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5613                         mode,
5614                 "" /* defined at init */);
5615 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5616         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5617                         retry, "retry");
5618
5619 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5620         .f = cmd_set_fwd_retry_mode_parsed,
5621         .data = NULL,
5622         .help_str = NULL, /* defined at init */
5623         .tokens = {
5624                 (void *)&cmd_setfwd_retry_set,
5625                 (void *)&cmd_setfwd_retry_fwd,
5626                 (void *)&cmd_setfwd_retry_mode,
5627                 (void *)&cmd_setfwd_retry_retry,
5628                 NULL,
5629         },
5630 };
5631
5632 static void cmd_set_fwd_retry_mode_init(void)
5633 {
5634         char *modes, *c;
5635         static char token[128];
5636         static char help[256];
5637         cmdline_parse_token_string_t *token_struct;
5638
5639         modes = list_pkt_forwarding_retry_modes();
5640         snprintf(help, sizeof(help), "set fwd %s retry: "
5641                 "Set packet forwarding mode with retry", modes);
5642         cmd_set_fwd_retry_mode.help_str = help;
5643
5644         /* string token separator is # */
5645         for (c = token; *modes != '\0'; modes++)
5646                 if (*modes == '|')
5647                         *c++ = '#';
5648                 else
5649                         *c++ = *modes;
5650         token_struct = (cmdline_parse_token_string_t *)
5651                 cmd_set_fwd_retry_mode.tokens[2];
5652         token_struct->string_data.str = token;
5653 }
5654
5655 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5656 struct cmd_set_burst_tx_retry_result {
5657         cmdline_fixed_string_t set;
5658         cmdline_fixed_string_t burst;
5659         cmdline_fixed_string_t tx;
5660         cmdline_fixed_string_t delay;
5661         uint32_t time;
5662         cmdline_fixed_string_t retry;
5663         uint32_t retry_num;
5664 };
5665
5666 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5667                                         __attribute__((unused)) struct cmdline *cl,
5668                                         __attribute__((unused)) void *data)
5669 {
5670         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5671
5672         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5673                 && !strcmp(res->tx, "tx")) {
5674                 if (!strcmp(res->delay, "delay"))
5675                         burst_tx_delay_time = res->time;
5676                 if (!strcmp(res->retry, "retry"))
5677                         burst_tx_retry_num = res->retry_num;
5678         }
5679
5680 }
5681
5682 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5683         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5684 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5685         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5686                                  "burst");
5687 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5688         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5689 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5690         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5691 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5692         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5693 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5695 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5696         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5697
5698 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5699         .f = cmd_set_burst_tx_retry_parsed,
5700         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5701         .tokens = {
5702                 (void *)&cmd_set_burst_tx_retry_set,
5703                 (void *)&cmd_set_burst_tx_retry_burst,
5704                 (void *)&cmd_set_burst_tx_retry_tx,
5705                 (void *)&cmd_set_burst_tx_retry_delay,
5706                 (void *)&cmd_set_burst_tx_retry_time,
5707                 (void *)&cmd_set_burst_tx_retry_retry,
5708                 (void *)&cmd_set_burst_tx_retry_retry_num,
5709                 NULL,
5710         },
5711 };
5712
5713 /* *** SET PROMISC MODE *** */
5714 struct cmd_set_promisc_mode_result {
5715         cmdline_fixed_string_t set;
5716         cmdline_fixed_string_t promisc;
5717         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5718         uint16_t port_num;               /* valid if "allports" argument == 0 */
5719         cmdline_fixed_string_t mode;
5720 };
5721
5722 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5723                                         __attribute__((unused)) struct cmdline *cl,
5724                                         void *allports)
5725 {
5726         struct cmd_set_promisc_mode_result *res = parsed_result;
5727         int enable;
5728         portid_t i;
5729
5730         if (!strcmp(res->mode, "on"))
5731                 enable = 1;
5732         else
5733                 enable = 0;
5734
5735         /* all ports */
5736         if (allports) {
5737                 RTE_ETH_FOREACH_DEV(i) {
5738                         if (enable)
5739                                 rte_eth_promiscuous_enable(i);
5740                         else
5741                                 rte_eth_promiscuous_disable(i);
5742                 }
5743         }
5744         else {
5745                 if (enable)
5746                         rte_eth_promiscuous_enable(res->port_num);
5747                 else
5748                         rte_eth_promiscuous_disable(res->port_num);
5749         }
5750 }
5751
5752 cmdline_parse_token_string_t cmd_setpromisc_set =
5753         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5754 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5755         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5756                                  "promisc");
5757 cmdline_parse_token_string_t cmd_setpromisc_portall =
5758         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5759                                  "all");
5760 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5761         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5762                               UINT8);
5763 cmdline_parse_token_string_t cmd_setpromisc_mode =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5765                                  "on#off");
5766
5767 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5768         .f = cmd_set_promisc_mode_parsed,
5769         .data = (void *)1,
5770         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5771         .tokens = {
5772                 (void *)&cmd_setpromisc_set,
5773                 (void *)&cmd_setpromisc_promisc,
5774                 (void *)&cmd_setpromisc_portall,
5775                 (void *)&cmd_setpromisc_mode,
5776                 NULL,
5777         },
5778 };
5779
5780 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5781         .f = cmd_set_promisc_mode_parsed,
5782         .data = (void *)0,
5783         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5784         .tokens = {
5785                 (void *)&cmd_setpromisc_set,
5786                 (void *)&cmd_setpromisc_promisc,
5787                 (void *)&cmd_setpromisc_portnum,
5788                 (void *)&cmd_setpromisc_mode,
5789                 NULL,
5790         },
5791 };
5792
5793 /* *** SET ALLMULTI MODE *** */
5794 struct cmd_set_allmulti_mode_result {
5795         cmdline_fixed_string_t set;
5796         cmdline_fixed_string_t allmulti;
5797         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5798         uint16_t port_num;               /* valid if "allports" argument == 0 */
5799         cmdline_fixed_string_t mode;
5800 };
5801
5802 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5803                                         __attribute__((unused)) struct cmdline *cl,
5804                                         void *allports)
5805 {
5806         struct cmd_set_allmulti_mode_result *res = parsed_result;
5807         int enable;
5808         portid_t i;
5809
5810         if (!strcmp(res->mode, "on"))
5811                 enable = 1;
5812         else
5813                 enable = 0;
5814
5815         /* all ports */
5816         if (allports) {
5817                 RTE_ETH_FOREACH_DEV(i) {
5818                         if (enable)
5819                                 rte_eth_allmulticast_enable(i);
5820                         else
5821                                 rte_eth_allmulticast_disable(i);
5822                 }
5823         }
5824         else {
5825                 if (enable)
5826                         rte_eth_allmulticast_enable(res->port_num);
5827                 else
5828                         rte_eth_allmulticast_disable(res->port_num);
5829         }
5830 }
5831
5832 cmdline_parse_token_string_t cmd_setallmulti_set =
5833         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5834 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5835         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5836                                  "allmulti");
5837 cmdline_parse_token_string_t cmd_setallmulti_portall =
5838         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5839                                  "all");
5840 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5841         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5842                               UINT16);
5843 cmdline_parse_token_string_t cmd_setallmulti_mode =
5844         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5845                                  "on#off");
5846
5847 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5848         .f = cmd_set_allmulti_mode_parsed,
5849         .data = (void *)1,
5850         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5851         .tokens = {
5852                 (void *)&cmd_setallmulti_set,
5853                 (void *)&cmd_setallmulti_allmulti,
5854                 (void *)&cmd_setallmulti_portall,
5855                 (void *)&cmd_setallmulti_mode,
5856                 NULL,
5857         },
5858 };
5859
5860 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5861         .f = cmd_set_allmulti_mode_parsed,
5862         .data = (void *)0,
5863         .help_str = "set allmulti <port_id> on|off: "
5864                 "Set allmulti mode on port_id",
5865         .tokens = {
5866                 (void *)&cmd_setallmulti_set,
5867                 (void *)&cmd_setallmulti_allmulti,
5868                 (void *)&cmd_setallmulti_portnum,
5869                 (void *)&cmd_setallmulti_mode,
5870                 NULL,
5871         },
5872 };
5873
5874 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5875 struct cmd_link_flow_ctrl_set_result {
5876         cmdline_fixed_string_t set;
5877         cmdline_fixed_string_t flow_ctrl;
5878         cmdline_fixed_string_t rx;
5879         cmdline_fixed_string_t rx_lfc_mode;
5880         cmdline_fixed_string_t tx;
5881         cmdline_fixed_string_t tx_lfc_mode;
5882         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5883         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5884         cmdline_fixed_string_t autoneg_str;
5885         cmdline_fixed_string_t autoneg;
5886         cmdline_fixed_string_t hw_str;
5887         uint32_t high_water;
5888         cmdline_fixed_string_t lw_str;
5889         uint32_t low_water;
5890         cmdline_fixed_string_t pt_str;
5891         uint16_t pause_time;
5892         cmdline_fixed_string_t xon_str;
5893         uint16_t send_xon;
5894         portid_t port_id;
5895 };
5896
5897 cmdline_parse_token_string_t cmd_lfc_set_set =
5898         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5899                                 set, "set");
5900 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5901         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5902                                 flow_ctrl, "flow_ctrl");
5903 cmdline_parse_token_string_t cmd_lfc_set_rx =
5904         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5905                                 rx, "rx");
5906 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5907         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5908                                 rx_lfc_mode, "on#off");
5909 cmdline_parse_token_string_t cmd_lfc_set_tx =
5910         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5911                                 tx, "tx");
5912 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5913         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5914                                 tx_lfc_mode, "on#off");
5915 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5916         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5917                                 hw_str, "high_water");
5918 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5919         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5920                                 high_water, UINT32);
5921 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5922         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5923                                 lw_str, "low_water");
5924 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5925         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5926                                 low_water, UINT32);
5927 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5928         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5929                                 pt_str, "pause_time");
5930 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5931         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5932                                 pause_time, UINT16);
5933 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5934         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5935                                 xon_str, "send_xon");
5936 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5937         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5938                                 send_xon, UINT16);
5939 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5940         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5941                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5942 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5943         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5944                                 mac_ctrl_frame_fwd_mode, "on#off");
5945 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5946         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5947                                 autoneg_str, "autoneg");
5948 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5949         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5950                                 autoneg, "on#off");
5951 cmdline_parse_token_num_t cmd_lfc_set_portid =
5952         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5953                                 port_id, UINT16);
5954
5955 /* forward declaration */
5956 static void
5957 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5958                               void *data);
5959
5960 cmdline_parse_inst_t cmd_link_flow_control_set = {
5961         .f = cmd_link_flow_ctrl_set_parsed,
5962         .data = NULL,
5963         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5964                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5965                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5966         .tokens = {
5967                 (void *)&cmd_lfc_set_set,
5968                 (void *)&cmd_lfc_set_flow_ctrl,
5969                 (void *)&cmd_lfc_set_rx,
5970                 (void *)&cmd_lfc_set_rx_mode,
5971                 (void *)&cmd_lfc_set_tx,
5972                 (void *)&cmd_lfc_set_tx_mode,
5973                 (void *)&cmd_lfc_set_high_water,
5974                 (void *)&cmd_lfc_set_low_water,
5975                 (void *)&cmd_lfc_set_pause_time,
5976                 (void *)&cmd_lfc_set_send_xon,
5977                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5978                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5979                 (void *)&cmd_lfc_set_autoneg_str,
5980                 (void *)&cmd_lfc_set_autoneg,
5981                 (void *)&cmd_lfc_set_portid,
5982                 NULL,
5983         },
5984 };
5985
5986 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5987         .f = cmd_link_flow_ctrl_set_parsed,
5988         .data = (void *)&cmd_link_flow_control_set_rx,
5989         .help_str = "set flow_ctrl rx on|off <port_id>: "
5990                 "Change rx flow control parameter",
5991         .tokens = {
5992                 (void *)&cmd_lfc_set_set,
5993                 (void *)&cmd_lfc_set_flow_ctrl,
5994                 (void *)&cmd_lfc_set_rx,
5995                 (void *)&cmd_lfc_set_rx_mode,
5996                 (void *)&cmd_lfc_set_portid,
5997                 NULL,
5998         },
5999 };
6000
6001 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6002         .f = cmd_link_flow_ctrl_set_parsed,
6003         .data = (void *)&cmd_link_flow_control_set_tx,
6004         .help_str = "set flow_ctrl tx on|off <port_id>: "
6005                 "Change tx flow control parameter",
6006         .tokens = {
6007                 (void *)&cmd_lfc_set_set,
6008                 (void *)&cmd_lfc_set_flow_ctrl,
6009                 (void *)&cmd_lfc_set_tx,
6010                 (void *)&cmd_lfc_set_tx_mode,
6011                 (void *)&cmd_lfc_set_portid,
6012                 NULL,
6013         },
6014 };
6015
6016 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6017         .f = cmd_link_flow_ctrl_set_parsed,
6018         .data = (void *)&cmd_link_flow_control_set_hw,
6019         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6020                 "Change high water flow control parameter",
6021         .tokens = {
6022                 (void *)&cmd_lfc_set_set,
6023                 (void *)&cmd_lfc_set_flow_ctrl,
6024                 (void *)&cmd_lfc_set_high_water_str,
6025                 (void *)&cmd_lfc_set_high_water,
6026                 (void *)&cmd_lfc_set_portid,
6027                 NULL,
6028         },
6029 };
6030
6031 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6032         .f = cmd_link_flow_ctrl_set_parsed,
6033         .data = (void *)&cmd_link_flow_control_set_lw,
6034         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6035                 "Change low water flow control parameter",
6036         .tokens = {
6037                 (void *)&cmd_lfc_set_set,
6038                 (void *)&cmd_lfc_set_flow_ctrl,
6039                 (void *)&cmd_lfc_set_low_water_str,
6040                 (void *)&cmd_lfc_set_low_water,
6041                 (void *)&cmd_lfc_set_portid,
6042                 NULL,
6043         },
6044 };
6045
6046 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6047         .f = cmd_link_flow_ctrl_set_parsed,
6048         .data = (void *)&cmd_link_flow_control_set_pt,
6049         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6050                 "Change pause time flow control parameter",
6051         .tokens = {
6052                 (void *)&cmd_lfc_set_set,
6053                 (void *)&cmd_lfc_set_flow_ctrl,
6054                 (void *)&cmd_lfc_set_pause_time_str,
6055                 (void *)&cmd_lfc_set_pause_time,
6056                 (void *)&cmd_lfc_set_portid,
6057                 NULL,
6058         },
6059 };
6060
6061 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6062         .f = cmd_link_flow_ctrl_set_parsed,
6063         .data = (void *)&cmd_link_flow_control_set_xon,
6064         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6065                 "Change send_xon flow control parameter",
6066         .tokens = {
6067                 (void *)&cmd_lfc_set_set,
6068                 (void *)&cmd_lfc_set_flow_ctrl,
6069                 (void *)&cmd_lfc_set_send_xon_str,
6070                 (void *)&cmd_lfc_set_send_xon,
6071                 (void *)&cmd_lfc_set_portid,
6072                 NULL,
6073         },
6074 };
6075
6076 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6077         .f = cmd_link_flow_ctrl_set_parsed,
6078         .data = (void *)&cmd_link_flow_control_set_macfwd,
6079         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6080                 "Change mac ctrl fwd flow control parameter",
6081         .tokens = {
6082                 (void *)&cmd_lfc_set_set,
6083                 (void *)&cmd_lfc_set_flow_ctrl,
6084                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6085                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6086                 (void *)&cmd_lfc_set_portid,
6087                 NULL,
6088         },
6089 };
6090
6091 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6092         .f = cmd_link_flow_ctrl_set_parsed,
6093         .data = (void *)&cmd_link_flow_control_set_autoneg,
6094         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6095                 "Change autoneg flow control parameter",
6096         .tokens = {
6097                 (void *)&cmd_lfc_set_set,
6098                 (void *)&cmd_lfc_set_flow_ctrl,
6099                 (void *)&cmd_lfc_set_autoneg_str,
6100                 (void *)&cmd_lfc_set_autoneg,
6101                 (void *)&cmd_lfc_set_portid,
6102                 NULL,
6103         },
6104 };
6105
6106 static void
6107 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6108                               __attribute__((unused)) struct cmdline *cl,
6109                               void *data)
6110 {
6111         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6112         cmdline_parse_inst_t *cmd = data;
6113         struct rte_eth_fc_conf fc_conf;
6114         int rx_fc_en = 0;
6115         int tx_fc_en = 0;
6116         int ret;
6117
6118         /*
6119          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6120          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6121          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6122          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6123          */
6124         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6125                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6126         };
6127
6128         /* Partial command line, retrieve current configuration */
6129         if (cmd) {
6130                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6131                 if (ret != 0) {
6132                         printf("cannot get current flow ctrl parameters, return"
6133                                "code = %d\n", ret);
6134                         return;
6135                 }
6136
6137                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6138                     (fc_conf.mode == RTE_FC_FULL))
6139                         rx_fc_en = 1;
6140                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6141                     (fc_conf.mode == RTE_FC_FULL))
6142                         tx_fc_en = 1;
6143         }
6144
6145         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6146                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6147
6148         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6149                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6150
6151         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6152
6153         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6154                 fc_conf.high_water = res->high_water;
6155
6156         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6157                 fc_conf.low_water = res->low_water;
6158
6159         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6160                 fc_conf.pause_time = res->pause_time;
6161
6162         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6163                 fc_conf.send_xon = res->send_xon;
6164
6165         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6166                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6167                         fc_conf.mac_ctrl_frame_fwd = 1;
6168                 else
6169                         fc_conf.mac_ctrl_frame_fwd = 0;
6170         }
6171
6172         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6173                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6174
6175         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6176         if (ret != 0)
6177                 printf("bad flow contrl parameter, return code = %d \n", ret);
6178 }
6179
6180 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6181 struct cmd_priority_flow_ctrl_set_result {
6182         cmdline_fixed_string_t set;
6183         cmdline_fixed_string_t pfc_ctrl;
6184         cmdline_fixed_string_t rx;
6185         cmdline_fixed_string_t rx_pfc_mode;
6186         cmdline_fixed_string_t tx;
6187         cmdline_fixed_string_t tx_pfc_mode;
6188         uint32_t high_water;
6189         uint32_t low_water;
6190         uint16_t pause_time;
6191         uint8_t  priority;
6192         portid_t port_id;
6193 };
6194
6195 static void
6196 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6197                        __attribute__((unused)) struct cmdline *cl,
6198                        __attribute__((unused)) void *data)
6199 {
6200         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6201         struct rte_eth_pfc_conf pfc_conf;
6202         int rx_fc_enable, tx_fc_enable;
6203         int ret;
6204
6205         /*
6206          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6207          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6208          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6209          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6210          */
6211         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6212                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6213         };
6214
6215         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6216         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6217         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6218         pfc_conf.fc.high_water = res->high_water;
6219         pfc_conf.fc.low_water  = res->low_water;
6220         pfc_conf.fc.pause_time = res->pause_time;
6221         pfc_conf.priority      = res->priority;
6222
6223         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6224         if (ret != 0)
6225                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6226 }
6227
6228 cmdline_parse_token_string_t cmd_pfc_set_set =
6229         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6230                                 set, "set");
6231 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6232         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6233                                 pfc_ctrl, "pfc_ctrl");
6234 cmdline_parse_token_string_t cmd_pfc_set_rx =
6235         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6236                                 rx, "rx");
6237 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6238         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6239                                 rx_pfc_mode, "on#off");
6240 cmdline_parse_token_string_t cmd_pfc_set_tx =
6241         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6242                                 tx, "tx");
6243 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6244         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6245                                 tx_pfc_mode, "on#off");
6246 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6247         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6248                                 high_water, UINT32);
6249 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6250         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6251                                 low_water, UINT32);
6252 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6253         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6254                                 pause_time, UINT16);
6255 cmdline_parse_token_num_t cmd_pfc_set_priority =
6256         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6257                                 priority, UINT8);
6258 cmdline_parse_token_num_t cmd_pfc_set_portid =
6259         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6260                                 port_id, UINT16);
6261
6262 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6263         .f = cmd_priority_flow_ctrl_set_parsed,
6264         .data = NULL,
6265         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6266                 "<pause_time> <priority> <port_id>: "
6267                 "Configure the Ethernet priority flow control",
6268         .tokens = {
6269                 (void *)&cmd_pfc_set_set,
6270                 (void *)&cmd_pfc_set_flow_ctrl,
6271                 (void *)&cmd_pfc_set_rx,
6272                 (void *)&cmd_pfc_set_rx_mode,
6273                 (void *)&cmd_pfc_set_tx,
6274                 (void *)&cmd_pfc_set_tx_mode,
6275                 (void *)&cmd_pfc_set_high_water,
6276                 (void *)&cmd_pfc_set_low_water,
6277                 (void *)&cmd_pfc_set_pause_time,
6278                 (void *)&cmd_pfc_set_priority,
6279                 (void *)&cmd_pfc_set_portid,
6280                 NULL,
6281         },
6282 };
6283
6284 /* *** RESET CONFIGURATION *** */
6285 struct cmd_reset_result {
6286         cmdline_fixed_string_t reset;
6287         cmdline_fixed_string_t def;
6288 };
6289
6290 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6291                              struct cmdline *cl,
6292                              __attribute__((unused)) void *data)
6293 {
6294         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6295         set_def_fwd_config();
6296 }
6297
6298 cmdline_parse_token_string_t cmd_reset_set =
6299         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6300 cmdline_parse_token_string_t cmd_reset_def =
6301         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6302                                  "default");
6303
6304 cmdline_parse_inst_t cmd_reset = {
6305         .f = cmd_reset_parsed,
6306         .data = NULL,
6307         .help_str = "set default: Reset default forwarding configuration",
6308         .tokens = {
6309                 (void *)&cmd_reset_set,
6310                 (void *)&cmd_reset_def,
6311                 NULL,
6312         },
6313 };
6314
6315 /* *** START FORWARDING *** */
6316 struct cmd_start_result {
6317         cmdline_fixed_string_t start;
6318 };
6319
6320 cmdline_parse_token_string_t cmd_start_start =
6321         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6322
6323 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6324                              __attribute__((unused)) struct cmdline *cl,
6325                              __attribute__((unused)) void *data)
6326 {
6327         start_packet_forwarding(0);
6328 }
6329
6330 cmdline_parse_inst_t cmd_start = {
6331         .f = cmd_start_parsed,
6332         .data = NULL,
6333         .help_str = "start: Start packet forwarding",
6334         .tokens = {
6335                 (void *)&cmd_start_start,
6336                 NULL,
6337         },
6338 };
6339
6340 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6341 struct cmd_start_tx_first_result {
6342         cmdline_fixed_string_t start;
6343         cmdline_fixed_string_t tx_first;
6344 };
6345
6346 static void
6347 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6348                           __attribute__((unused)) struct cmdline *cl,
6349                           __attribute__((unused)) void *data)
6350 {
6351         start_packet_forwarding(1);
6352 }
6353
6354 cmdline_parse_token_string_t cmd_start_tx_first_start =
6355         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6356                                  "start");
6357 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6358         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6359                                  tx_first, "tx_first");
6360
6361 cmdline_parse_inst_t cmd_start_tx_first = {
6362         .f = cmd_start_tx_first_parsed,
6363         .data = NULL,
6364         .help_str = "start tx_first: Start packet forwarding, "
6365                 "after sending 1 burst of packets",
6366         .tokens = {
6367                 (void *)&cmd_start_tx_first_start,
6368                 (void *)&cmd_start_tx_first_tx_first,
6369                 NULL,
6370         },
6371 };
6372
6373 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6374 struct cmd_start_tx_first_n_result {
6375         cmdline_fixed_string_t start;
6376         cmdline_fixed_string_t tx_first;
6377         uint32_t tx_num;
6378 };
6379
6380 static void
6381 cmd_start_tx_first_n_parsed(void *parsed_result,
6382                           __attribute__((unused)) struct cmdline *cl,
6383                           __attribute__((unused)) void *data)
6384 {
6385         struct cmd_start_tx_first_n_result *res = parsed_result;
6386
6387         start_packet_forwarding(res->tx_num);
6388 }
6389
6390 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6391         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6392                         start, "start");
6393 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6394         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6395                         tx_first, "tx_first");
6396 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6397         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6398                         tx_num, UINT32);
6399
6400 cmdline_parse_inst_t cmd_start_tx_first_n = {
6401         .f = cmd_start_tx_first_n_parsed,
6402         .data = NULL,
6403         .help_str = "start tx_first <num>: "
6404                 "packet forwarding, after sending <num> bursts of packets",
6405         .tokens = {
6406                 (void *)&cmd_start_tx_first_n_start,
6407                 (void *)&cmd_start_tx_first_n_tx_first,
6408                 (void *)&cmd_start_tx_first_n_tx_num,
6409                 NULL,
6410         },
6411 };
6412
6413 /* *** SET LINK UP *** */
6414 struct cmd_set_link_up_result {
6415         cmdline_fixed_string_t set;
6416         cmdline_fixed_string_t link_up;
6417         cmdline_fixed_string_t port;
6418         portid_t port_id;
6419 };
6420
6421 cmdline_parse_token_string_t cmd_set_link_up_set =
6422         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6423 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6424         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6425                                 "link-up");
6426 cmdline_parse_token_string_t cmd_set_link_up_port =
6427         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6428 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6429         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6430
6431 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6432                              __attribute__((unused)) struct cmdline *cl,
6433                              __attribute__((unused)) void *data)
6434 {
6435         struct cmd_set_link_up_result *res = parsed_result;
6436         dev_set_link_up(res->port_id);
6437 }
6438
6439 cmdline_parse_inst_t cmd_set_link_up = {
6440         .f = cmd_set_link_up_parsed,
6441         .data = NULL,
6442         .help_str = "set link-up port <port id>",
6443         .tokens = {
6444                 (void *)&cmd_set_link_up_set,
6445                 (void *)&cmd_set_link_up_link_up,
6446                 (void *)&cmd_set_link_up_port,
6447                 (void *)&cmd_set_link_up_port_id,
6448                 NULL,
6449         },
6450 };
6451
6452 /* *** SET LINK DOWN *** */
6453 struct cmd_set_link_down_result {
6454         cmdline_fixed_string_t set;
6455         cmdline_fixed_string_t link_down;
6456         cmdline_fixed_string_t port;
6457         portid_t port_id;
6458 };
6459
6460 cmdline_parse_token_string_t cmd_set_link_down_set =
6461         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6462 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6463         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6464                                 "link-down");
6465 cmdline_parse_token_string_t cmd_set_link_down_port =
6466         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6467 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6468         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6469
6470 static void cmd_set_link_down_parsed(
6471                                 __attribute__((unused)) void *parsed_result,
6472                                 __attribute__((unused)) struct cmdline *cl,
6473                                 __attribute__((unused)) void *data)
6474 {
6475         struct cmd_set_link_down_result *res = parsed_result;
6476         dev_set_link_down(res->port_id);
6477 }
6478
6479 cmdline_parse_inst_t cmd_set_link_down = {
6480         .f = cmd_set_link_down_parsed,
6481         .data = NULL,
6482         .help_str = "set link-down port <port id>",
6483         .tokens = {
6484                 (void *)&cmd_set_link_down_set,
6485                 (void *)&cmd_set_link_down_link_down,
6486                 (void *)&cmd_set_link_down_port,
6487                 (void *)&cmd_set_link_down_port_id,
6488                 NULL,
6489         },
6490 };
6491
6492 /* *** SHOW CFG *** */
6493 struct cmd_showcfg_result {
6494         cmdline_fixed_string_t show;
6495         cmdline_fixed_string_t cfg;
6496         cmdline_fixed_string_t what;
6497 };
6498
6499 static void cmd_showcfg_parsed(void *parsed_result,
6500                                __attribute__((unused)) struct cmdline *cl,
6501                                __attribute__((unused)) void *data)
6502 {
6503         struct cmd_showcfg_result *res = parsed_result;
6504         if (!strcmp(res->what, "rxtx"))
6505                 rxtx_config_display();
6506         else if (!strcmp(res->what, "cores"))
6507                 fwd_lcores_config_display();
6508         else if (!strcmp(res->what, "fwd"))
6509                 pkt_fwd_config_display(&cur_fwd_config);
6510         else if (!strcmp(res->what, "txpkts"))
6511                 show_tx_pkt_segments();
6512 }
6513
6514 cmdline_parse_token_string_t cmd_showcfg_show =
6515         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6516 cmdline_parse_token_string_t cmd_showcfg_port =
6517         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6518 cmdline_parse_token_string_t cmd_showcfg_what =
6519         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6520                                  "rxtx#cores#fwd#txpkts");
6521
6522 cmdline_parse_inst_t cmd_showcfg = {
6523         .f = cmd_showcfg_parsed,
6524         .data = NULL,
6525         .help_str = "show config rxtx|cores|fwd|txpkts",
6526         .tokens = {
6527                 (void *)&cmd_showcfg_show,
6528                 (void *)&cmd_showcfg_port,
6529                 (void *)&cmd_showcfg_what,
6530                 NULL,
6531         },
6532 };
6533
6534 /* *** SHOW ALL PORT INFO *** */
6535 struct cmd_showportall_result {
6536         cmdline_fixed_string_t show;
6537         cmdline_fixed_string_t port;
6538         cmdline_fixed_string_t what;
6539         cmdline_fixed_string_t all;
6540 };
6541
6542 static void cmd_showportall_parsed(void *parsed_result,
6543                                 __attribute__((unused)) struct cmdline *cl,
6544                                 __attribute__((unused)) void *data)
6545 {
6546         portid_t i;
6547
6548         struct cmd_showportall_result *res = parsed_result;
6549         if (!strcmp(res->show, "clear")) {
6550                 if (!strcmp(res->what, "stats"))
6551                         RTE_ETH_FOREACH_DEV(i)
6552                                 nic_stats_clear(i);
6553                 else if (!strcmp(res->what, "xstats"))
6554                         RTE_ETH_FOREACH_DEV(i)
6555                                 nic_xstats_clear(i);
6556         } else if (!strcmp(res->what, "info"))
6557                 RTE_ETH_FOREACH_DEV(i)
6558                         port_infos_display(i);
6559         else if (!strcmp(res->what, "stats"))
6560                 RTE_ETH_FOREACH_DEV(i)
6561                         nic_stats_display(i);
6562         else if (!strcmp(res->what, "xstats"))
6563                 RTE_ETH_FOREACH_DEV(i)
6564                         nic_xstats_display(i);
6565         else if (!strcmp(res->what, "fdir"))
6566                 RTE_ETH_FOREACH_DEV(i)
6567                         fdir_get_infos(i);
6568         else if (!strcmp(res->what, "stat_qmap"))
6569                 RTE_ETH_FOREACH_DEV(i)
6570                         nic_stats_mapping_display(i);
6571         else if (!strcmp(res->what, "dcb_tc"))
6572                 RTE_ETH_FOREACH_DEV(i)
6573                         port_dcb_info_display(i);
6574         else if (!strcmp(res->what, "cap"))
6575                 RTE_ETH_FOREACH_DEV(i)
6576                         port_offload_cap_display(i);
6577 }
6578
6579 cmdline_parse_token_string_t cmd_showportall_show =
6580         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6581                                  "show#clear");
6582 cmdline_parse_token_string_t cmd_showportall_port =
6583         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6584 cmdline_parse_token_string_t cmd_showportall_what =
6585         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6586                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6587 cmdline_parse_token_string_t cmd_showportall_all =
6588         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6589 cmdline_parse_inst_t cmd_showportall = {
6590         .f = cmd_showportall_parsed,
6591         .data = NULL,
6592         .help_str = "show|clear port "
6593                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6594         .tokens = {
6595                 (void *)&cmd_showportall_show,
6596                 (void *)&cmd_showportall_port,
6597                 (void *)&cmd_showportall_what,
6598                 (void *)&cmd_showportall_all,
6599                 NULL,
6600         },
6601 };
6602
6603 /* *** SHOW PORT INFO *** */
6604 struct cmd_showport_result {
6605         cmdline_fixed_string_t show;
6606         cmdline_fixed_string_t port;
6607         cmdline_fixed_string_t what;
6608         uint16_t portnum;
6609 };
6610
6611 static void cmd_showport_parsed(void *parsed_result,
6612                                 __attribute__((unused)) struct cmdline *cl,
6613                                 __attribute__((unused)) void *data)
6614 {
6615         struct cmd_showport_result *res = parsed_result;
6616         if (!strcmp(res->show, "clear")) {
6617                 if (!strcmp(res->what, "stats"))
6618                         nic_stats_clear(res->portnum);
6619                 else if (!strcmp(res->what, "xstats"))
6620                         nic_xstats_clear(res->portnum);
6621         } else if (!strcmp(res->what, "info"))
6622                 port_infos_display(res->portnum);
6623         else if (!strcmp(res->what, "stats"))
6624                 nic_stats_display(res->portnum);
6625         else if (!strcmp(res->what, "xstats"))
6626                 nic_xstats_display(res->portnum);
6627         else if (!strcmp(res->what, "fdir"))
6628                  fdir_get_infos(res->portnum);
6629         else if (!strcmp(res->what, "stat_qmap"))
6630                 nic_stats_mapping_display(res->portnum);
6631         else if (!strcmp(res->what, "dcb_tc"))
6632                 port_dcb_info_display(res->portnum);
6633         else if (!strcmp(res->what, "cap"))
6634                 port_offload_cap_display(res->portnum);
6635 }
6636
6637 cmdline_parse_token_string_t cmd_showport_show =
6638         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6639                                  "show#clear");
6640 cmdline_parse_token_string_t cmd_showport_port =
6641         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6642 cmdline_parse_token_string_t cmd_showport_what =
6643         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6644                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6645 cmdline_parse_token_num_t cmd_showport_portnum =
6646         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6647
6648 cmdline_parse_inst_t cmd_showport = {
6649         .f = cmd_showport_parsed,
6650         .data = NULL,
6651         .help_str = "show|clear port "
6652                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6653                 "<port_id>",
6654         .tokens = {
6655                 (void *)&cmd_showport_show,
6656                 (void *)&cmd_showport_port,
6657                 (void *)&cmd_showport_what,
6658                 (void *)&cmd_showport_portnum,
6659                 NULL,
6660         },
6661 };
6662
6663 /* *** SHOW QUEUE INFO *** */
6664 struct cmd_showqueue_result {
6665         cmdline_fixed_string_t show;
6666         cmdline_fixed_string_t type;
6667         cmdline_fixed_string_t what;
6668         uint16_t portnum;
6669         uint16_t queuenum;
6670 };
6671
6672 static void
6673 cmd_showqueue_parsed(void *parsed_result,
6674         __attribute__((unused)) struct cmdline *cl,
6675         __attribute__((unused)) void *data)
6676 {
6677         struct cmd_showqueue_result *res = parsed_result;
6678
6679         if (!strcmp(res->type, "rxq"))
6680                 rx_queue_infos_display(res->portnum, res->queuenum);
6681         else if (!strcmp(res->type, "txq"))
6682                 tx_queue_infos_display(res->portnum, res->queuenum);
6683 }
6684
6685 cmdline_parse_token_string_t cmd_showqueue_show =
6686         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6687 cmdline_parse_token_string_t cmd_showqueue_type =
6688         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6689 cmdline_parse_token_string_t cmd_showqueue_what =
6690         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6691 cmdline_parse_token_num_t cmd_showqueue_portnum =
6692         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6693 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6694         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6695
6696 cmdline_parse_inst_t cmd_showqueue = {
6697         .f = cmd_showqueue_parsed,
6698         .data = NULL,
6699         .help_str = "show rxq|txq info <port_id> <queue_id>",
6700         .tokens = {
6701                 (void *)&cmd_showqueue_show,
6702                 (void *)&cmd_showqueue_type,
6703                 (void *)&cmd_showqueue_what,
6704                 (void *)&cmd_showqueue_portnum,
6705                 (void *)&cmd_showqueue_queuenum,
6706                 NULL,
6707         },
6708 };
6709
6710 /* *** READ PORT REGISTER *** */
6711 struct cmd_read_reg_result {
6712         cmdline_fixed_string_t read;
6713         cmdline_fixed_string_t reg;
6714         portid_t port_id;
6715         uint32_t reg_off;
6716 };
6717
6718 static void
6719 cmd_read_reg_parsed(void *parsed_result,
6720                     __attribute__((unused)) struct cmdline *cl,
6721                     __attribute__((unused)) void *data)
6722 {
6723         struct cmd_read_reg_result *res = parsed_result;
6724         port_reg_display(res->port_id, res->reg_off);
6725 }
6726
6727 cmdline_parse_token_string_t cmd_read_reg_read =
6728         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6729 cmdline_parse_token_string_t cmd_read_reg_reg =
6730         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6731 cmdline_parse_token_num_t cmd_read_reg_port_id =
6732         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6733 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6734         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6735
6736 cmdline_parse_inst_t cmd_read_reg = {
6737         .f = cmd_read_reg_parsed,
6738         .data = NULL,
6739         .help_str = "read reg <port_id> <reg_off>",
6740         .tokens = {
6741                 (void *)&cmd_read_reg_read,
6742                 (void *)&cmd_read_reg_reg,
6743                 (void *)&cmd_read_reg_port_id,
6744                 (void *)&cmd_read_reg_reg_off,
6745                 NULL,
6746         },
6747 };
6748
6749 /* *** READ PORT REGISTER BIT FIELD *** */
6750 struct cmd_read_reg_bit_field_result {
6751         cmdline_fixed_string_t read;
6752         cmdline_fixed_string_t regfield;
6753         portid_t port_id;
6754         uint32_t reg_off;
6755         uint8_t bit1_pos;
6756         uint8_t bit2_pos;
6757 };
6758
6759 static void
6760 cmd_read_reg_bit_field_parsed(void *parsed_result,
6761                               __attribute__((unused)) struct cmdline *cl,
6762                               __attribute__((unused)) void *data)
6763 {
6764         struct cmd_read_reg_bit_field_result *res = parsed_result;
6765         port_reg_bit_field_display(res->port_id, res->reg_off,
6766                                    res->bit1_pos, res->bit2_pos);
6767 }
6768
6769 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6770         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6771                                  "read");
6772 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6773         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6774                                  regfield, "regfield");
6775 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6776         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6777                               UINT16);
6778 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6779         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6780                               UINT32);
6781 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6782         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6783                               UINT8);
6784 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6785         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6786                               UINT8);
6787
6788 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6789         .f = cmd_read_reg_bit_field_parsed,
6790         .data = NULL,
6791         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6792         "Read register bit field between bit_x and bit_y included",
6793         .tokens = {
6794                 (void *)&cmd_read_reg_bit_field_read,
6795                 (void *)&cmd_read_reg_bit_field_regfield,
6796                 (void *)&cmd_read_reg_bit_field_port_id,
6797                 (void *)&cmd_read_reg_bit_field_reg_off,
6798                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6799                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6800                 NULL,
6801         },
6802 };
6803
6804 /* *** READ PORT REGISTER BIT *** */
6805 struct cmd_read_reg_bit_result {
6806         cmdline_fixed_string_t read;
6807         cmdline_fixed_string_t regbit;
6808         portid_t port_id;
6809         uint32_t reg_off;
6810         uint8_t bit_pos;
6811 };
6812
6813 static void
6814 cmd_read_reg_bit_parsed(void *parsed_result,
6815                         __attribute__((unused)) struct cmdline *cl,
6816                         __attribute__((unused)) void *data)
6817 {
6818         struct cmd_read_reg_bit_result *res = parsed_result;
6819         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6820 }
6821
6822 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6823         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6824 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6825         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6826                                  regbit, "regbit");
6827 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6828         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6829 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6830         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6831 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6832         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6833
6834 cmdline_parse_inst_t cmd_read_reg_bit = {
6835         .f = cmd_read_reg_bit_parsed,
6836         .data = NULL,
6837         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6838         .tokens = {
6839                 (void *)&cmd_read_reg_bit_read,
6840                 (void *)&cmd_read_reg_bit_regbit,
6841                 (void *)&cmd_read_reg_bit_port_id,
6842                 (void *)&cmd_read_reg_bit_reg_off,
6843                 (void *)&cmd_read_reg_bit_bit_pos,
6844                 NULL,
6845         },
6846 };
6847
6848 /* *** WRITE PORT REGISTER *** */
6849 struct cmd_write_reg_result {
6850         cmdline_fixed_string_t write;
6851         cmdline_fixed_string_t reg;
6852         portid_t port_id;
6853         uint32_t reg_off;
6854         uint32_t value;
6855 };
6856
6857 static void
6858 cmd_write_reg_parsed(void *parsed_result,
6859                      __attribute__((unused)) struct cmdline *cl,
6860                      __attribute__((unused)) void *data)
6861 {
6862         struct cmd_write_reg_result *res = parsed_result;
6863         port_reg_set(res->port_id, res->reg_off, res->value);
6864 }
6865
6866 cmdline_parse_token_string_t cmd_write_reg_write =
6867         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6868 cmdline_parse_token_string_t cmd_write_reg_reg =
6869         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6870 cmdline_parse_token_num_t cmd_write_reg_port_id =
6871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6872 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6873         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6874 cmdline_parse_token_num_t cmd_write_reg_value =
6875         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6876
6877 cmdline_parse_inst_t cmd_write_reg = {
6878         .f = cmd_write_reg_parsed,
6879         .data = NULL,
6880         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6881         .tokens = {
6882                 (void *)&cmd_write_reg_write,
6883                 (void *)&cmd_write_reg_reg,
6884                 (void *)&cmd_write_reg_port_id,
6885                 (void *)&cmd_write_reg_reg_off,
6886                 (void *)&cmd_write_reg_value,
6887                 NULL,
6888         },
6889 };
6890
6891 /* *** WRITE PORT REGISTER BIT FIELD *** */
6892 struct cmd_write_reg_bit_field_result {
6893         cmdline_fixed_string_t write;
6894         cmdline_fixed_string_t regfield;
6895         portid_t port_id;
6896         uint32_t reg_off;
6897         uint8_t bit1_pos;
6898         uint8_t bit2_pos;
6899         uint32_t value;
6900 };
6901
6902 static void
6903 cmd_write_reg_bit_field_parsed(void *parsed_result,
6904                                __attribute__((unused)) struct cmdline *cl,
6905                                __attribute__((unused)) void *data)
6906 {
6907         struct cmd_write_reg_bit_field_result *res = parsed_result;
6908         port_reg_bit_field_set(res->port_id, res->reg_off,
6909                           res->bit1_pos, res->bit2_pos, res->value);
6910 }
6911
6912 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6913         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6914                                  "write");
6915 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6916         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6917                                  regfield, "regfield");
6918 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6919         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6920                               UINT16);
6921 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6922         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6923                               UINT32);
6924 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6925         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6926                               UINT8);
6927 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6928         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6929                               UINT8);
6930 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6931         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6932                               UINT32);
6933
6934 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6935         .f = cmd_write_reg_bit_field_parsed,
6936         .data = NULL,
6937         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6938                 "<reg_value>: "
6939                 "Set register bit field between bit_x and bit_y included",
6940         .tokens = {
6941                 (void *)&cmd_write_reg_bit_field_write,
6942                 (void *)&cmd_write_reg_bit_field_regfield,
6943                 (void *)&cmd_write_reg_bit_field_port_id,
6944                 (void *)&cmd_write_reg_bit_field_reg_off,
6945                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6946                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6947                 (void *)&cmd_write_reg_bit_field_value,
6948                 NULL,
6949         },
6950 };
6951
6952 /* *** WRITE PORT REGISTER BIT *** */
6953 struct cmd_write_reg_bit_result {
6954         cmdline_fixed_string_t write;
6955         cmdline_fixed_string_t regbit;
6956         portid_t port_id;
6957         uint32_t reg_off;
6958         uint8_t bit_pos;
6959         uint8_t value;
6960 };
6961
6962 static void
6963 cmd_write_reg_bit_parsed(void *parsed_result,
6964                          __attribute__((unused)) struct cmdline *cl,
6965                          __attribute__((unused)) void *data)
6966 {
6967         struct cmd_write_reg_bit_result *res = parsed_result;
6968         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6969 }
6970
6971 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6972         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6973                                  "write");
6974 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6975         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6976                                  regbit, "regbit");
6977 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6978         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6979 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6980         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6981 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6982         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6983 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6985
6986 cmdline_parse_inst_t cmd_write_reg_bit = {
6987         .f = cmd_write_reg_bit_parsed,
6988         .data = NULL,
6989         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6990                 "0 <= bit_x <= 31",
6991         .tokens = {
6992                 (void *)&cmd_write_reg_bit_write,
6993                 (void *)&cmd_write_reg_bit_regbit,
6994                 (void *)&cmd_write_reg_bit_port_id,
6995                 (void *)&cmd_write_reg_bit_reg_off,
6996                 (void *)&cmd_write_reg_bit_bit_pos,
6997                 (void *)&cmd_write_reg_bit_value,
6998                 NULL,
6999         },
7000 };
7001
7002 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7003 struct cmd_read_rxd_txd_result {
7004         cmdline_fixed_string_t read;
7005         cmdline_fixed_string_t rxd_txd;
7006         portid_t port_id;
7007         uint16_t queue_id;
7008         uint16_t desc_id;
7009 };
7010
7011 static void
7012 cmd_read_rxd_txd_parsed(void *parsed_result,
7013                         __attribute__((unused)) struct cmdline *cl,
7014                         __attribute__((unused)) void *data)
7015 {
7016         struct cmd_read_rxd_txd_result *res = parsed_result;
7017
7018         if (!strcmp(res->rxd_txd, "rxd"))
7019                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7020         else if (!strcmp(res->rxd_txd, "txd"))
7021                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7022 }
7023
7024 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7025         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7026 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7027         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7028                                  "rxd#txd");
7029 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7030         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7031 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7032         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7033 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7034         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7035
7036 cmdline_parse_inst_t cmd_read_rxd_txd = {
7037         .f = cmd_read_rxd_txd_parsed,
7038         .data = NULL,
7039         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7040         .tokens = {
7041                 (void *)&cmd_read_rxd_txd_read,
7042                 (void *)&cmd_read_rxd_txd_rxd_txd,
7043                 (void *)&cmd_read_rxd_txd_port_id,
7044                 (void *)&cmd_read_rxd_txd_queue_id,
7045                 (void *)&cmd_read_rxd_txd_desc_id,
7046                 NULL,
7047         },
7048 };
7049
7050 /* *** QUIT *** */
7051 struct cmd_quit_result {
7052         cmdline_fixed_string_t quit;
7053 };
7054
7055 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7056                             struct cmdline *cl,
7057                             __attribute__((unused)) void *data)
7058 {
7059         pmd_test_exit();
7060         cmdline_quit(cl);
7061 }
7062
7063 cmdline_parse_token_string_t cmd_quit_quit =
7064         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7065
7066 cmdline_parse_inst_t cmd_quit = {
7067         .f = cmd_quit_parsed,
7068         .data = NULL,
7069         .help_str = "quit: Exit application",
7070         .tokens = {
7071                 (void *)&cmd_quit_quit,
7072                 NULL,
7073         },
7074 };
7075
7076 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7077 struct cmd_mac_addr_result {
7078         cmdline_fixed_string_t mac_addr_cmd;
7079         cmdline_fixed_string_t what;
7080         uint16_t port_num;
7081         struct ether_addr address;
7082 };
7083
7084 static void cmd_mac_addr_parsed(void *parsed_result,
7085                 __attribute__((unused)) struct cmdline *cl,
7086                 __attribute__((unused)) void *data)
7087 {
7088         struct cmd_mac_addr_result *res = parsed_result;
7089         int ret;
7090
7091         if (strcmp(res->what, "add") == 0)
7092                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7093         else if (strcmp(res->what, "set") == 0)
7094                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7095                                                        &res->address);
7096         else
7097                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7098
7099         /* check the return value and print it if is < 0 */
7100         if(ret < 0)
7101                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7102
7103 }
7104
7105 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7106         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7107                                 "mac_addr");
7108 cmdline_parse_token_string_t cmd_mac_addr_what =
7109         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7110                                 "add#remove#set");
7111 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7112                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7113                                         UINT16);
7114 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7115                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7116
7117 cmdline_parse_inst_t cmd_mac_addr = {
7118         .f = cmd_mac_addr_parsed,
7119         .data = (void *)0,
7120         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7121                         "Add/Remove/Set MAC address on port_id",
7122         .tokens = {
7123                 (void *)&cmd_mac_addr_cmd,
7124                 (void *)&cmd_mac_addr_what,
7125                 (void *)&cmd_mac_addr_portnum,
7126                 (void *)&cmd_mac_addr_addr,
7127                 NULL,
7128         },
7129 };
7130
7131
7132 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7133 struct cmd_set_qmap_result {
7134         cmdline_fixed_string_t set;
7135         cmdline_fixed_string_t qmap;
7136         cmdline_fixed_string_t what;
7137         portid_t port_id;
7138         uint16_t queue_id;
7139         uint8_t map_value;
7140 };
7141
7142 static void
7143 cmd_set_qmap_parsed(void *parsed_result,
7144                        __attribute__((unused)) struct cmdline *cl,
7145                        __attribute__((unused)) void *data)
7146 {
7147         struct cmd_set_qmap_result *res = parsed_result;
7148         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7149
7150         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7151 }
7152
7153 cmdline_parse_token_string_t cmd_setqmap_set =
7154         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7155                                  set, "set");
7156 cmdline_parse_token_string_t cmd_setqmap_qmap =
7157         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7158                                  qmap, "stat_qmap");
7159 cmdline_parse_token_string_t cmd_setqmap_what =
7160         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7161                                  what, "tx#rx");
7162 cmdline_parse_token_num_t cmd_setqmap_portid =
7163         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7164                               port_id, UINT16);
7165 cmdline_parse_token_num_t cmd_setqmap_queueid =
7166         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7167                               queue_id, UINT16);
7168 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7169         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7170                               map_value, UINT8);
7171
7172 cmdline_parse_inst_t cmd_set_qmap = {
7173         .f = cmd_set_qmap_parsed,
7174         .data = NULL,
7175         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7176                 "Set statistics mapping value on tx|rx queue_id of port_id",
7177         .tokens = {
7178                 (void *)&cmd_setqmap_set,
7179                 (void *)&cmd_setqmap_qmap,
7180                 (void *)&cmd_setqmap_what,
7181                 (void *)&cmd_setqmap_portid,
7182                 (void *)&cmd_setqmap_queueid,
7183                 (void *)&cmd_setqmap_mapvalue,
7184                 NULL,
7185         },
7186 };
7187
7188 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7189 struct cmd_set_xstats_hide_zero_result {
7190         cmdline_fixed_string_t keyword;
7191         cmdline_fixed_string_t name;
7192         cmdline_fixed_string_t on_off;
7193 };
7194
7195 static void
7196 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7197                         __attribute__((unused)) struct cmdline *cl,
7198                         __attribute__((unused)) void *data)
7199 {
7200         struct cmd_set_xstats_hide_zero_result *res;
7201         uint16_t on_off = 0;
7202
7203         res = parsed_result;
7204         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7205         set_xstats_hide_zero(on_off);
7206 }
7207
7208 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7209         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7210                                  keyword, "set");
7211 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7212         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7213                                  name, "xstats-hide-zero");
7214 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7215         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7216                                  on_off, "on#off");
7217
7218 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7219         .f = cmd_set_xstats_hide_zero_parsed,
7220         .data = NULL,
7221         .help_str = "set xstats-hide-zero on|off",
7222         .tokens = {
7223                 (void *)&cmd_set_xstats_hide_zero_keyword,
7224                 (void *)&cmd_set_xstats_hide_zero_name,
7225                 (void *)&cmd_set_xstats_hide_zero_on_off,
7226                 NULL,
7227         },
7228 };
7229
7230 /* *** CONFIGURE UNICAST HASH TABLE *** */
7231 struct cmd_set_uc_hash_table {
7232         cmdline_fixed_string_t set;
7233         cmdline_fixed_string_t port;
7234         portid_t port_id;
7235         cmdline_fixed_string_t what;
7236         struct ether_addr address;
7237         cmdline_fixed_string_t mode;
7238 };
7239
7240 static void
7241 cmd_set_uc_hash_parsed(void *parsed_result,
7242                        __attribute__((unused)) struct cmdline *cl,
7243                        __attribute__((unused)) void *data)
7244 {
7245         int ret=0;
7246         struct cmd_set_uc_hash_table *res = parsed_result;
7247
7248         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7249
7250         if (strcmp(res->what, "uta") == 0)
7251                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7252                                                 &res->address,(uint8_t)is_on);
7253         if (ret < 0)
7254                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7255
7256 }
7257
7258 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7259         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7260                                  set, "set");
7261 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7262         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7263                                  port, "port");
7264 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7265         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7266                               port_id, UINT16);
7267 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7268         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7269                                  what, "uta");
7270 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7271         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7272                                 address);
7273 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7274         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7275                                  mode, "on#off");
7276
7277 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7278         .f = cmd_set_uc_hash_parsed,
7279         .data = NULL,
7280         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7281         .tokens = {
7282                 (void *)&cmd_set_uc_hash_set,
7283                 (void *)&cmd_set_uc_hash_port,
7284                 (void *)&cmd_set_uc_hash_portid,
7285                 (void *)&cmd_set_uc_hash_what,
7286                 (void *)&cmd_set_uc_hash_mac,
7287                 (void *)&cmd_set_uc_hash_mode,
7288                 NULL,
7289         },
7290 };
7291
7292 struct cmd_set_uc_all_hash_table {
7293         cmdline_fixed_string_t set;
7294         cmdline_fixed_string_t port;
7295         portid_t port_id;
7296         cmdline_fixed_string_t what;
7297         cmdline_fixed_string_t value;
7298         cmdline_fixed_string_t mode;
7299 };
7300
7301 static void
7302 cmd_set_uc_all_hash_parsed(void *parsed_result,
7303                        __attribute__((unused)) struct cmdline *cl,
7304                        __attribute__((unused)) void *data)
7305 {
7306         int ret=0;
7307         struct cmd_set_uc_all_hash_table *res = parsed_result;
7308
7309         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7310
7311         if ((strcmp(res->what, "uta") == 0) &&
7312                 (strcmp(res->value, "all") == 0))
7313                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7314         if (ret < 0)
7315                 printf("bad unicast hash table parameter,"
7316                         "return code = %d \n", ret);
7317 }
7318
7319 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7320         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7321                                  set, "set");
7322 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7323         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7324                                  port, "port");
7325 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7326         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7327                               port_id, UINT16);
7328 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7329         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7330                                  what, "uta");
7331 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7332         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7333                                 value,"all");
7334 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7335         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7336                                  mode, "on#off");
7337
7338 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7339         .f = cmd_set_uc_all_hash_parsed,
7340         .data = NULL,
7341         .help_str = "set port <port_id> uta all on|off",
7342         .tokens = {
7343                 (void *)&cmd_set_uc_all_hash_set,
7344                 (void *)&cmd_set_uc_all_hash_port,
7345                 (void *)&cmd_set_uc_all_hash_portid,
7346                 (void *)&cmd_set_uc_all_hash_what,
7347                 (void *)&cmd_set_uc_all_hash_value,
7348                 (void *)&cmd_set_uc_all_hash_mode,
7349                 NULL,
7350         },
7351 };
7352
7353 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7354 struct cmd_set_vf_macvlan_filter {
7355         cmdline_fixed_string_t set;
7356         cmdline_fixed_string_t port;
7357         portid_t port_id;
7358         cmdline_fixed_string_t vf;
7359         uint8_t vf_id;
7360         struct ether_addr address;
7361         cmdline_fixed_string_t filter_type;
7362         cmdline_fixed_string_t mode;
7363 };
7364
7365 static void
7366 cmd_set_vf_macvlan_parsed(void *parsed_result,
7367                        __attribute__((unused)) struct cmdline *cl,
7368                        __attribute__((unused)) void *data)
7369 {
7370         int is_on, ret = 0;
7371         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7372         struct rte_eth_mac_filter filter;
7373
7374         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7375
7376         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7377
7378         /* set VF MAC filter */
7379         filter.is_vf = 1;
7380
7381         /* set VF ID */
7382         filter.dst_id = res->vf_id;
7383
7384         if (!strcmp(res->filter_type, "exact-mac"))
7385                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7386         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7387                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7388         else if (!strcmp(res->filter_type, "hashmac"))
7389                 filter.filter_type = RTE_MAC_HASH_MATCH;
7390         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7391                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7392
7393         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7394
7395         if (is_on)
7396                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7397                                         RTE_ETH_FILTER_MACVLAN,
7398                                         RTE_ETH_FILTER_ADD,
7399                                          &filter);
7400         else
7401                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7402                                         RTE_ETH_FILTER_MACVLAN,
7403                                         RTE_ETH_FILTER_DELETE,
7404                                         &filter);
7405
7406         if (ret < 0)
7407                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7408
7409 }
7410
7411 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7412         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7413                                  set, "set");
7414 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7415         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7416                                  port, "port");
7417 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7418         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7419                               port_id, UINT16);
7420 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7421         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7422                                  vf, "vf");
7423 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7424         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7425                                 vf_id, UINT8);
7426 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7427         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7428                                 address);
7429 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7431                                 filter_type, "exact-mac#exact-mac-vlan"
7432                                 "#hashmac#hashmac-vlan");
7433 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7434         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7435                                  mode, "on#off");
7436
7437 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7438         .f = cmd_set_vf_macvlan_parsed,
7439         .data = NULL,
7440         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7441                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7442                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7443                 "hash match rule: hash match of MAC and exact match of VLAN",
7444         .tokens = {
7445                 (void *)&cmd_set_vf_macvlan_set,
7446                 (void *)&cmd_set_vf_macvlan_port,
7447                 (void *)&cmd_set_vf_macvlan_portid,
7448                 (void *)&cmd_set_vf_macvlan_vf,
7449                 (void *)&cmd_set_vf_macvlan_vf_id,
7450                 (void *)&cmd_set_vf_macvlan_mac,
7451                 (void *)&cmd_set_vf_macvlan_filter_type,
7452                 (void *)&cmd_set_vf_macvlan_mode,
7453                 NULL,
7454         },
7455 };
7456
7457 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7458 struct cmd_set_vf_traffic {
7459         cmdline_fixed_string_t set;
7460         cmdline_fixed_string_t port;
7461         portid_t port_id;
7462         cmdline_fixed_string_t vf;
7463         uint8_t vf_id;
7464         cmdline_fixed_string_t what;
7465         cmdline_fixed_string_t mode;
7466 };
7467
7468 static void
7469 cmd_set_vf_traffic_parsed(void *parsed_result,
7470                        __attribute__((unused)) struct cmdline *cl,
7471                        __attribute__((unused)) void *data)
7472 {
7473         struct cmd_set_vf_traffic *res = parsed_result;
7474         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7475         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7476
7477         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7478 }
7479
7480 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7481         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7482                                  set, "set");
7483 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7484         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7485                                  port, "port");
7486 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7487         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7488                               port_id, UINT16);
7489 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7490         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7491                                  vf, "vf");
7492 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7493         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7494                               vf_id, UINT8);
7495 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7496         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7497                                  what, "tx#rx");
7498 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7499         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7500                                  mode, "on#off");
7501
7502 cmdline_parse_inst_t cmd_set_vf_traffic = {
7503         .f = cmd_set_vf_traffic_parsed,
7504         .data = NULL,
7505         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7506         .tokens = {
7507                 (void *)&cmd_setvf_traffic_set,
7508                 (void *)&cmd_setvf_traffic_port,
7509                 (void *)&cmd_setvf_traffic_portid,
7510                 (void *)&cmd_setvf_traffic_vf,
7511                 (void *)&cmd_setvf_traffic_vfid,
7512                 (void *)&cmd_setvf_traffic_what,
7513                 (void *)&cmd_setvf_traffic_mode,
7514                 NULL,
7515         },
7516 };
7517
7518 /* *** CONFIGURE VF RECEIVE MODE *** */
7519 struct cmd_set_vf_rxmode {
7520         cmdline_fixed_string_t set;
7521         cmdline_fixed_string_t port;
7522         portid_t port_id;
7523         cmdline_fixed_string_t vf;
7524         uint8_t vf_id;
7525         cmdline_fixed_string_t what;
7526         cmdline_fixed_string_t mode;
7527         cmdline_fixed_string_t on;
7528 };
7529
7530 static void
7531 cmd_set_vf_rxmode_parsed(void *parsed_result,
7532                        __attribute__((unused)) struct cmdline *cl,
7533                        __attribute__((unused)) void *data)
7534 {
7535         int ret = -ENOTSUP;
7536         uint16_t rx_mode = 0;
7537         struct cmd_set_vf_rxmode *res = parsed_result;
7538
7539         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7540         if (!strcmp(res->what,"rxmode")) {
7541                 if (!strcmp(res->mode, "AUPE"))
7542                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7543                 else if (!strcmp(res->mode, "ROPE"))
7544                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7545                 else if (!strcmp(res->mode, "BAM"))
7546                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7547                 else if (!strncmp(res->mode, "MPE",3))
7548                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7549         }
7550
7551         RTE_SET_USED(is_on);
7552
7553 #ifdef RTE_LIBRTE_IXGBE_PMD
7554         if (ret == -ENOTSUP)
7555                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7556                                                   rx_mode, (uint8_t)is_on);
7557 #endif
7558 #ifdef RTE_LIBRTE_BNXT_PMD
7559         if (ret == -ENOTSUP)
7560                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7561                                                  rx_mode, (uint8_t)is_on);
7562 #endif
7563         if (ret < 0)
7564                 printf("bad VF receive mode parameter, return code = %d \n",
7565                 ret);
7566 }
7567
7568 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7569         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7570                                  set, "set");
7571 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7572         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7573                                  port, "port");
7574 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7575         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7576                               port_id, UINT16);
7577 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7578         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7579                                  vf, "vf");
7580 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7581         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7582                               vf_id, UINT8);
7583 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7584         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7585                                  what, "rxmode");
7586 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7587         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7588                                  mode, "AUPE#ROPE#BAM#MPE");
7589 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7590         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7591                                  on, "on#off");
7592
7593 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7594         .f = cmd_set_vf_rxmode_parsed,
7595         .data = NULL,
7596         .help_str = "set port <port_id> vf <vf_id> rxmode "
7597                 "AUPE|ROPE|BAM|MPE on|off",
7598         .tokens = {
7599                 (void *)&cmd_set_vf_rxmode_set,
7600                 (void *)&cmd_set_vf_rxmode_port,
7601                 (void *)&cmd_set_vf_rxmode_portid,
7602                 (void *)&cmd_set_vf_rxmode_vf,
7603                 (void *)&cmd_set_vf_rxmode_vfid,
7604                 (void *)&cmd_set_vf_rxmode_what,
7605                 (void *)&cmd_set_vf_rxmode_mode,
7606                 (void *)&cmd_set_vf_rxmode_on,
7607                 NULL,
7608         },
7609 };
7610
7611 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7612 struct cmd_vf_mac_addr_result {
7613         cmdline_fixed_string_t mac_addr_cmd;
7614         cmdline_fixed_string_t what;
7615         cmdline_fixed_string_t port;
7616         uint16_t port_num;
7617         cmdline_fixed_string_t vf;
7618         uint8_t vf_num;
7619         struct ether_addr address;
7620 };
7621
7622 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7623                 __attribute__((unused)) struct cmdline *cl,
7624                 __attribute__((unused)) void *data)
7625 {
7626         struct cmd_vf_mac_addr_result *res = parsed_result;
7627         int ret = -ENOTSUP;
7628
7629         if (strcmp(res->what, "add") != 0)
7630                 return;
7631
7632 #ifdef RTE_LIBRTE_I40E_PMD
7633         if (ret == -ENOTSUP)
7634                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7635                                                    &res->address);
7636 #endif
7637 #ifdef RTE_LIBRTE_BNXT_PMD
7638         if (ret == -ENOTSUP)
7639                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7640                                                 res->vf_num);
7641 #endif
7642
7643         if(ret < 0)
7644                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7645
7646 }
7647
7648 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7649         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7650                                 mac_addr_cmd,"mac_addr");
7651 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7652         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7653                                 what,"add");
7654 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7655         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7656                                 port,"port");
7657 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7658         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7659                                 port_num, UINT16);
7660 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7661         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7662                                 vf,"vf");
7663 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7664         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7665                                 vf_num, UINT8);
7666 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7667         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7668                                 address);
7669
7670 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7671         .f = cmd_vf_mac_addr_parsed,
7672         .data = (void *)0,
7673         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7674                 "Add MAC address filtering for a VF on port_id",
7675         .tokens = {
7676                 (void *)&cmd_vf_mac_addr_cmd,
7677                 (void *)&cmd_vf_mac_addr_what,
7678                 (void *)&cmd_vf_mac_addr_port,
7679                 (void *)&cmd_vf_mac_addr_portnum,
7680                 (void *)&cmd_vf_mac_addr_vf,
7681                 (void *)&cmd_vf_mac_addr_vfnum,
7682                 (void *)&cmd_vf_mac_addr_addr,
7683                 NULL,
7684         },
7685 };
7686
7687 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7688 struct cmd_vf_rx_vlan_filter {
7689         cmdline_fixed_string_t rx_vlan;
7690         cmdline_fixed_string_t what;
7691         uint16_t vlan_id;
7692         cmdline_fixed_string_t port;
7693         portid_t port_id;
7694         cmdline_fixed_string_t vf;
7695         uint64_t vf_mask;
7696 };
7697
7698 static void
7699 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7700                           __attribute__((unused)) struct cmdline *cl,
7701                           __attribute__((unused)) void *data)
7702 {
7703         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7704         int ret = -ENOTSUP;
7705
7706         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7707
7708 #ifdef RTE_LIBRTE_IXGBE_PMD
7709         if (ret == -ENOTSUP)
7710                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7711                                 res->vlan_id, res->vf_mask, is_add);
7712 #endif
7713 #ifdef RTE_LIBRTE_I40E_PMD
7714         if (ret == -ENOTSUP)
7715                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7716                                 res->vlan_id, res->vf_mask, is_add);
7717 #endif
7718 #ifdef RTE_LIBRTE_BNXT_PMD
7719         if (ret == -ENOTSUP)
7720                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7721                                 res->vlan_id, res->vf_mask, is_add);
7722 #endif
7723
7724         switch (ret) {
7725         case 0:
7726                 break;
7727         case -EINVAL:
7728                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7729                                 res->vlan_id, res->vf_mask);
7730                 break;
7731         case -ENODEV:
7732                 printf("invalid port_id %d\n", res->port_id);
7733                 break;
7734         case -ENOTSUP:
7735                 printf("function not implemented or supported\n");
7736                 break;
7737         default:
7738                 printf("programming error: (%s)\n", strerror(-ret));
7739         }
7740 }
7741
7742 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7743         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7744                                  rx_vlan, "rx_vlan");
7745 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7746         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7747                                  what, "add#rm");
7748 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7749         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7750                               vlan_id, UINT16);
7751 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7752         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7753                                  port, "port");
7754 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7755         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7756                               port_id, UINT16);
7757 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7758         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7759                                  vf, "vf");
7760 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7761         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7762                               vf_mask, UINT64);
7763
7764 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7765         .f = cmd_vf_rx_vlan_filter_parsed,
7766         .data = NULL,
7767         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7768                 "(vf_mask = hexadecimal VF mask)",
7769         .tokens = {
7770                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7771                 (void *)&cmd_vf_rx_vlan_filter_what,
7772                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7773                 (void *)&cmd_vf_rx_vlan_filter_port,
7774                 (void *)&cmd_vf_rx_vlan_filter_portid,
7775                 (void *)&cmd_vf_rx_vlan_filter_vf,
7776                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7777                 NULL,
7778         },
7779 };
7780
7781 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7782 struct cmd_queue_rate_limit_result {
7783         cmdline_fixed_string_t set;
7784         cmdline_fixed_string_t port;
7785         uint16_t port_num;
7786         cmdline_fixed_string_t queue;
7787         uint8_t queue_num;
7788         cmdline_fixed_string_t rate;
7789         uint16_t rate_num;
7790 };
7791
7792 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7793                 __attribute__((unused)) struct cmdline *cl,
7794                 __attribute__((unused)) void *data)
7795 {
7796         struct cmd_queue_rate_limit_result *res = parsed_result;
7797         int ret = 0;
7798
7799         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7800                 && (strcmp(res->queue, "queue") == 0)
7801                 && (strcmp(res->rate, "rate") == 0))
7802                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7803                                         res->rate_num);
7804         if (ret < 0)
7805                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7806
7807 }
7808
7809 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7810         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7811                                 set, "set");
7812 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7813         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7814                                 port, "port");
7815 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7816         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7817                                 port_num, UINT16);
7818 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7819         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7820                                 queue, "queue");
7821 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7822         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7823                                 queue_num, UINT8);
7824 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7825         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7826                                 rate, "rate");
7827 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7828         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7829                                 rate_num, UINT16);
7830
7831 cmdline_parse_inst_t cmd_queue_rate_limit = {
7832         .f = cmd_queue_rate_limit_parsed,
7833         .data = (void *)0,
7834         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7835                 "Set rate limit for a queue on port_id",
7836         .tokens = {
7837                 (void *)&cmd_queue_rate_limit_set,
7838                 (void *)&cmd_queue_rate_limit_port,
7839                 (void *)&cmd_queue_rate_limit_portnum,
7840                 (void *)&cmd_queue_rate_limit_queue,
7841                 (void *)&cmd_queue_rate_limit_queuenum,
7842                 (void *)&cmd_queue_rate_limit_rate,
7843                 (void *)&cmd_queue_rate_limit_ratenum,
7844                 NULL,
7845         },
7846 };
7847
7848 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7849 struct cmd_vf_rate_limit_result {
7850         cmdline_fixed_string_t set;
7851         cmdline_fixed_string_t port;
7852         uint16_t port_num;
7853         cmdline_fixed_string_t vf;
7854         uint8_t vf_num;
7855         cmdline_fixed_string_t rate;
7856         uint16_t rate_num;
7857         cmdline_fixed_string_t q_msk;
7858         uint64_t q_msk_val;
7859 };
7860
7861 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7862                 __attribute__((unused)) struct cmdline *cl,
7863                 __attribute__((unused)) void *data)
7864 {
7865         struct cmd_vf_rate_limit_result *res = parsed_result;
7866         int ret = 0;
7867
7868         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7869                 && (strcmp(res->vf, "vf") == 0)
7870                 && (strcmp(res->rate, "rate") == 0)
7871                 && (strcmp(res->q_msk, "queue_mask") == 0))
7872                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7873                                         res->rate_num, res->q_msk_val);
7874         if (ret < 0)
7875                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7876
7877 }
7878
7879 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7880         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7881                                 set, "set");
7882 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7883         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7884                                 port, "port");
7885 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7886         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7887                                 port_num, UINT16);
7888 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7889         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7890                                 vf, "vf");
7891 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7892         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7893                                 vf_num, UINT8);
7894 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7895         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7896                                 rate, "rate");
7897 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7898         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7899                                 rate_num, UINT16);
7900 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7901         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7902                                 q_msk, "queue_mask");
7903 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7904         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7905                                 q_msk_val, UINT64);
7906
7907 cmdline_parse_inst_t cmd_vf_rate_limit = {
7908         .f = cmd_vf_rate_limit_parsed,
7909         .data = (void *)0,
7910         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7911                 "queue_mask <queue_mask_value>: "
7912                 "Set rate limit for queues of VF on port_id",
7913         .tokens = {
7914                 (void *)&cmd_vf_rate_limit_set,
7915                 (void *)&cmd_vf_rate_limit_port,
7916                 (void *)&cmd_vf_rate_limit_portnum,
7917                 (void *)&cmd_vf_rate_limit_vf,
7918                 (void *)&cmd_vf_rate_limit_vfnum,
7919                 (void *)&cmd_vf_rate_limit_rate,
7920                 (void *)&cmd_vf_rate_limit_ratenum,
7921                 (void *)&cmd_vf_rate_limit_q_msk,
7922                 (void *)&cmd_vf_rate_limit_q_msk_val,
7923                 NULL,
7924         },
7925 };
7926
7927 /* *** ADD TUNNEL FILTER OF A PORT *** */
7928 struct cmd_tunnel_filter_result {
7929         cmdline_fixed_string_t cmd;
7930         cmdline_fixed_string_t what;
7931         portid_t port_id;
7932         struct ether_addr outer_mac;
7933         struct ether_addr inner_mac;
7934         cmdline_ipaddr_t ip_value;
7935         uint16_t inner_vlan;
7936         cmdline_fixed_string_t tunnel_type;
7937         cmdline_fixed_string_t filter_type;
7938         uint32_t tenant_id;
7939         uint16_t queue_num;
7940 };
7941
7942 static void
7943 cmd_tunnel_filter_parsed(void *parsed_result,
7944                           __attribute__((unused)) struct cmdline *cl,
7945                           __attribute__((unused)) void *data)
7946 {
7947         struct cmd_tunnel_filter_result *res = parsed_result;
7948         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7949         int ret = 0;
7950
7951         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7952
7953         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7954         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7955         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7956
7957         if (res->ip_value.family == AF_INET) {
7958                 tunnel_filter_conf.ip_addr.ipv4_addr =
7959                         res->ip_value.addr.ipv4.s_addr;
7960                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7961         } else {
7962                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7963                         &(res->ip_value.addr.ipv6),
7964                         sizeof(struct in6_addr));
7965                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7966         }
7967
7968         if (!strcmp(res->filter_type, "imac-ivlan"))
7969                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7970         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7971                 tunnel_filter_conf.filter_type =
7972                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7973         else if (!strcmp(res->filter_type, "imac-tenid"))
7974                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7975         else if (!strcmp(res->filter_type, "imac"))
7976                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7977         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7978                 tunnel_filter_conf.filter_type =
7979                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7980         else if (!strcmp(res->filter_type, "oip"))
7981                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7982         else if (!strcmp(res->filter_type, "iip"))
7983                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7984         else {
7985                 printf("The filter type is not supported");
7986                 return;
7987         }
7988
7989         if (!strcmp(res->tunnel_type, "vxlan"))
7990                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7991         else if (!strcmp(res->tunnel_type, "nvgre"))
7992                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7993         else if (!strcmp(res->tunnel_type, "ipingre"))
7994                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7995         else {
7996                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7997                 return;
7998         }
7999
8000         tunnel_filter_conf.tenant_id = res->tenant_id;
8001         tunnel_filter_conf.queue_id = res->queue_num;
8002         if (!strcmp(res->what, "add"))
8003                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8004                                         RTE_ETH_FILTER_TUNNEL,
8005                                         RTE_ETH_FILTER_ADD,
8006                                         &tunnel_filter_conf);
8007         else
8008                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8009                                         RTE_ETH_FILTER_TUNNEL,
8010                                         RTE_ETH_FILTER_DELETE,
8011                                         &tunnel_filter_conf);
8012         if (ret < 0)
8013                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8014                                 strerror(-ret));
8015
8016 }
8017 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8018         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8019         cmd, "tunnel_filter");
8020 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8021         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8022         what, "add#rm");
8023 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8024         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8025         port_id, UINT16);
8026 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8027         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8028         outer_mac);
8029 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8030         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8031         inner_mac);
8032 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8033         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8034         inner_vlan, UINT16);
8035 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8036         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8037         ip_value);
8038 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8039         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8040         tunnel_type, "vxlan#nvgre#ipingre");
8041
8042 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8043         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8044         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8045                 "imac#omac-imac-tenid");
8046 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8047         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8048         tenant_id, UINT32);
8049 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8050         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8051         queue_num, UINT16);
8052
8053 cmdline_parse_inst_t cmd_tunnel_filter = {
8054         .f = cmd_tunnel_filter_parsed,
8055         .data = (void *)0,
8056         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8057                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8058                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8059                 "<queue_id>: Add/Rm tunnel filter of a port",
8060         .tokens = {
8061                 (void *)&cmd_tunnel_filter_cmd,
8062                 (void *)&cmd_tunnel_filter_what,
8063                 (void *)&cmd_tunnel_filter_port_id,
8064                 (void *)&cmd_tunnel_filter_outer_mac,
8065                 (void *)&cmd_tunnel_filter_inner_mac,
8066                 (void *)&cmd_tunnel_filter_ip_value,
8067                 (void *)&cmd_tunnel_filter_innner_vlan,
8068                 (void *)&cmd_tunnel_filter_tunnel_type,
8069                 (void *)&cmd_tunnel_filter_filter_type,
8070                 (void *)&cmd_tunnel_filter_tenant_id,
8071                 (void *)&cmd_tunnel_filter_queue_num,
8072                 NULL,
8073         },
8074 };
8075
8076 /* *** CONFIGURE TUNNEL UDP PORT *** */
8077 struct cmd_tunnel_udp_config {
8078         cmdline_fixed_string_t cmd;
8079         cmdline_fixed_string_t what;
8080         uint16_t udp_port;
8081         portid_t port_id;
8082 };
8083
8084 static void
8085 cmd_tunnel_udp_config_parsed(void *parsed_result,
8086                           __attribute__((unused)) struct cmdline *cl,
8087                           __attribute__((unused)) void *data)
8088 {
8089         struct cmd_tunnel_udp_config *res = parsed_result;
8090         struct rte_eth_udp_tunnel tunnel_udp;
8091         int ret;
8092
8093         tunnel_udp.udp_port = res->udp_port;
8094
8095         if (!strcmp(res->cmd, "rx_vxlan_port"))
8096                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8097
8098         if (!strcmp(res->what, "add"))
8099                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8100                                                       &tunnel_udp);
8101         else
8102                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8103                                                          &tunnel_udp);
8104
8105         if (ret < 0)
8106                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8107 }
8108
8109 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8110         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8111                                 cmd, "rx_vxlan_port");
8112 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8113         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8114                                 what, "add#rm");
8115 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8116         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8117                                 udp_port, UINT16);
8118 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8119         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8120                                 port_id, UINT16);
8121
8122 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8123         .f = cmd_tunnel_udp_config_parsed,
8124         .data = (void *)0,
8125         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8126                 "Add/Remove a tunneling UDP port filter",
8127         .tokens = {
8128                 (void *)&cmd_tunnel_udp_config_cmd,
8129                 (void *)&cmd_tunnel_udp_config_what,
8130                 (void *)&cmd_tunnel_udp_config_udp_port,
8131                 (void *)&cmd_tunnel_udp_config_port_id,
8132                 NULL,
8133         },
8134 };
8135
8136 /* *** GLOBAL CONFIG *** */
8137 struct cmd_global_config_result {
8138         cmdline_fixed_string_t cmd;
8139         portid_t port_id;
8140         cmdline_fixed_string_t cfg_type;
8141         uint8_t len;
8142 };
8143
8144 static void
8145 cmd_global_config_parsed(void *parsed_result,
8146                          __attribute__((unused)) struct cmdline *cl,
8147                          __attribute__((unused)) void *data)
8148 {
8149         struct cmd_global_config_result *res = parsed_result;
8150         struct rte_eth_global_cfg conf;
8151         int ret;
8152
8153         memset(&conf, 0, sizeof(conf));
8154         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8155         conf.cfg.gre_key_len = res->len;
8156         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8157                                       RTE_ETH_FILTER_SET, &conf);
8158         if (ret != 0)
8159                 printf("Global config error\n");
8160 }
8161
8162 cmdline_parse_token_string_t cmd_global_config_cmd =
8163         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8164                 "global_config");
8165 cmdline_parse_token_num_t cmd_global_config_port_id =
8166         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8167                                UINT16);
8168 cmdline_parse_token_string_t cmd_global_config_type =
8169         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8170                 cfg_type, "gre-key-len");
8171 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8172         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8173                 len, UINT8);
8174
8175 cmdline_parse_inst_t cmd_global_config = {
8176         .f = cmd_global_config_parsed,
8177         .data = (void *)NULL,
8178         .help_str = "global_config <port_id> gre-key-len <key_len>",
8179         .tokens = {
8180                 (void *)&cmd_global_config_cmd,
8181                 (void *)&cmd_global_config_port_id,
8182                 (void *)&cmd_global_config_type,
8183                 (void *)&cmd_global_config_gre_key_len,
8184                 NULL,
8185         },
8186 };
8187
8188 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8189 struct cmd_set_mirror_mask_result {
8190         cmdline_fixed_string_t set;
8191         cmdline_fixed_string_t port;
8192         portid_t port_id;
8193         cmdline_fixed_string_t mirror;
8194         uint8_t rule_id;
8195         cmdline_fixed_string_t what;
8196         cmdline_fixed_string_t value;
8197         cmdline_fixed_string_t dstpool;
8198         uint8_t dstpool_id;
8199         cmdline_fixed_string_t on;
8200 };
8201
8202 cmdline_parse_token_string_t cmd_mirror_mask_set =
8203         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8204                                 set, "set");
8205 cmdline_parse_token_string_t cmd_mirror_mask_port =
8206         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8207                                 port, "port");
8208 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8209         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8210                                 port_id, UINT16);
8211 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8213                                 mirror, "mirror-rule");
8214 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8215         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8216                                 rule_id, UINT8);
8217 cmdline_parse_token_string_t cmd_mirror_mask_what =
8218         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8219                                 what, "pool-mirror-up#pool-mirror-down"
8220                                       "#vlan-mirror");
8221 cmdline_parse_token_string_t cmd_mirror_mask_value =
8222         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8223                                 value, NULL);
8224 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8225         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8226                                 dstpool, "dst-pool");
8227 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8228         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8229                                 dstpool_id, UINT8);
8230 cmdline_parse_token_string_t cmd_mirror_mask_on =
8231         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8232                                 on, "on#off");
8233
8234 static void
8235 cmd_set_mirror_mask_parsed(void *parsed_result,
8236                        __attribute__((unused)) struct cmdline *cl,
8237                        __attribute__((unused)) void *data)
8238 {
8239         int ret,nb_item,i;
8240         struct cmd_set_mirror_mask_result *res = parsed_result;
8241         struct rte_eth_mirror_conf mr_conf;
8242
8243         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8244
8245         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8246
8247         mr_conf.dst_pool = res->dstpool_id;
8248
8249         if (!strcmp(res->what, "pool-mirror-up")) {
8250                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8251                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8252         } else if (!strcmp(res->what, "pool-mirror-down")) {
8253                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8254                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8255         } else if (!strcmp(res->what, "vlan-mirror")) {
8256                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8257                 nb_item = parse_item_list(res->value, "vlan",
8258                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8259                 if (nb_item <= 0)
8260                         return;
8261
8262                 for (i = 0; i < nb_item; i++) {
8263                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8264                                 printf("Invalid vlan_id: must be < 4096\n");
8265                                 return;
8266                         }
8267
8268                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8269                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8270                 }
8271         }
8272
8273         if (!strcmp(res->on, "on"))
8274                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8275                                                 res->rule_id, 1);
8276         else
8277                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8278                                                 res->rule_id, 0);
8279         if (ret < 0)
8280                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8281 }
8282
8283 cmdline_parse_inst_t cmd_set_mirror_mask = {
8284                 .f = cmd_set_mirror_mask_parsed,
8285                 .data = NULL,
8286                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8287                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8288                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8289                 .tokens = {
8290                         (void *)&cmd_mirror_mask_set,
8291                         (void *)&cmd_mirror_mask_port,
8292                         (void *)&cmd_mirror_mask_portid,
8293                         (void *)&cmd_mirror_mask_mirror,
8294                         (void *)&cmd_mirror_mask_ruleid,
8295                         (void *)&cmd_mirror_mask_what,
8296                         (void *)&cmd_mirror_mask_value,
8297                         (void *)&cmd_mirror_mask_dstpool,
8298                         (void *)&cmd_mirror_mask_poolid,
8299                         (void *)&cmd_mirror_mask_on,
8300                         NULL,
8301                 },
8302 };
8303
8304 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8305 struct cmd_set_mirror_link_result {
8306         cmdline_fixed_string_t set;
8307         cmdline_fixed_string_t port;
8308         portid_t port_id;
8309         cmdline_fixed_string_t mirror;
8310         uint8_t rule_id;
8311         cmdline_fixed_string_t what;
8312         cmdline_fixed_string_t dstpool;
8313         uint8_t dstpool_id;
8314         cmdline_fixed_string_t on;
8315 };
8316
8317 cmdline_parse_token_string_t cmd_mirror_link_set =
8318         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8319                                  set, "set");
8320 cmdline_parse_token_string_t cmd_mirror_link_port =
8321         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8322                                 port, "port");
8323 cmdline_parse_token_num_t cmd_mirror_link_portid =
8324         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8325                                 port_id, UINT16);
8326 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8327         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8328                                 mirror, "mirror-rule");
8329 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8330         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8331                             rule_id, UINT8);
8332 cmdline_parse_token_string_t cmd_mirror_link_what =
8333         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8334                                 what, "uplink-mirror#downlink-mirror");
8335 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8336         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8337                                 dstpool, "dst-pool");
8338 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8339         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8340                                 dstpool_id, UINT8);
8341 cmdline_parse_token_string_t cmd_mirror_link_on =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8343                                 on, "on#off");
8344
8345 static void
8346 cmd_set_mirror_link_parsed(void *parsed_result,
8347                        __attribute__((unused)) struct cmdline *cl,
8348                        __attribute__((unused)) void *data)
8349 {
8350         int ret;
8351         struct cmd_set_mirror_link_result *res = parsed_result;
8352         struct rte_eth_mirror_conf mr_conf;
8353
8354         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8355         if (!strcmp(res->what, "uplink-mirror"))
8356                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8357         else
8358                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8359
8360         mr_conf.dst_pool = res->dstpool_id;
8361
8362         if (!strcmp(res->on, "on"))
8363                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8364                                                 res->rule_id, 1);
8365         else
8366                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8367                                                 res->rule_id, 0);
8368
8369         /* check the return value and print it if is < 0 */
8370         if (ret < 0)
8371                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8372
8373 }
8374
8375 cmdline_parse_inst_t cmd_set_mirror_link = {
8376                 .f = cmd_set_mirror_link_parsed,
8377                 .data = NULL,
8378                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8379                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8380                 .tokens = {
8381                         (void *)&cmd_mirror_link_set,
8382                         (void *)&cmd_mirror_link_port,
8383                         (void *)&cmd_mirror_link_portid,
8384                         (void *)&cmd_mirror_link_mirror,
8385                         (void *)&cmd_mirror_link_ruleid,
8386                         (void *)&cmd_mirror_link_what,
8387                         (void *)&cmd_mirror_link_dstpool,
8388                         (void *)&cmd_mirror_link_poolid,
8389                         (void *)&cmd_mirror_link_on,
8390                         NULL,
8391                 },
8392 };
8393
8394 /* *** RESET VM MIRROR RULE *** */
8395 struct cmd_rm_mirror_rule_result {
8396         cmdline_fixed_string_t reset;
8397         cmdline_fixed_string_t port;
8398         portid_t port_id;
8399         cmdline_fixed_string_t mirror;
8400         uint8_t rule_id;
8401 };
8402
8403 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8404         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8405                                  reset, "reset");
8406 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8407         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8408                                 port, "port");
8409 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8410         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8411                                 port_id, UINT16);
8412 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8413         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8414                                 mirror, "mirror-rule");
8415 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8416         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8417                                 rule_id, UINT8);
8418
8419 static void
8420 cmd_reset_mirror_rule_parsed(void *parsed_result,
8421                        __attribute__((unused)) struct cmdline *cl,
8422                        __attribute__((unused)) void *data)
8423 {
8424         int ret;
8425         struct cmd_set_mirror_link_result *res = parsed_result;
8426         /* check rule_id */
8427         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8428         if(ret < 0)
8429                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8430 }
8431
8432 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8433                 .f = cmd_reset_mirror_rule_parsed,
8434                 .data = NULL,
8435                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8436                 .tokens = {
8437                         (void *)&cmd_rm_mirror_rule_reset,
8438                         (void *)&cmd_rm_mirror_rule_port,
8439                         (void *)&cmd_rm_mirror_rule_portid,
8440                         (void *)&cmd_rm_mirror_rule_mirror,
8441                         (void *)&cmd_rm_mirror_rule_ruleid,
8442                         NULL,
8443                 },
8444 };
8445
8446 /* ******************************************************************************** */
8447
8448 struct cmd_dump_result {
8449         cmdline_fixed_string_t dump;
8450 };
8451
8452 static void
8453 dump_struct_sizes(void)
8454 {
8455 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8456         DUMP_SIZE(struct rte_mbuf);
8457         DUMP_SIZE(struct rte_mempool);
8458         DUMP_SIZE(struct rte_ring);
8459 #undef DUMP_SIZE
8460 }
8461
8462 static void cmd_dump_parsed(void *parsed_result,
8463                             __attribute__((unused)) struct cmdline *cl,
8464                             __attribute__((unused)) void *data)
8465 {
8466         struct cmd_dump_result *res = parsed_result;
8467
8468         if (!strcmp(res->dump, "dump_physmem"))
8469                 rte_dump_physmem_layout(stdout);
8470         else if (!strcmp(res->dump, "dump_memzone"))
8471                 rte_memzone_dump(stdout);
8472         else if (!strcmp(res->dump, "dump_struct_sizes"))
8473                 dump_struct_sizes();
8474         else if (!strcmp(res->dump, "dump_ring"))
8475                 rte_ring_list_dump(stdout);
8476         else if (!strcmp(res->dump, "dump_mempool"))
8477                 rte_mempool_list_dump(stdout);
8478         else if (!strcmp(res->dump, "dump_devargs"))
8479                 rte_eal_devargs_dump(stdout);
8480         else if (!strcmp(res->dump, "dump_log_types"))
8481                 rte_log_dump(stdout);
8482 }
8483
8484 cmdline_parse_token_string_t cmd_dump_dump =
8485         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8486                 "dump_physmem#"
8487                 "dump_memzone#"
8488                 "dump_struct_sizes#"
8489                 "dump_ring#"
8490                 "dump_mempool#"
8491                 "dump_devargs#"
8492                 "dump_log_types");
8493
8494 cmdline_parse_inst_t cmd_dump = {
8495         .f = cmd_dump_parsed,  /* function to call */
8496         .data = NULL,      /* 2nd arg of func */
8497         .help_str = "Dump status",
8498         .tokens = {        /* token list, NULL terminated */
8499                 (void *)&cmd_dump_dump,
8500                 NULL,
8501         },
8502 };
8503
8504 /* ******************************************************************************** */
8505
8506 struct cmd_dump_one_result {
8507         cmdline_fixed_string_t dump;
8508         cmdline_fixed_string_t name;
8509 };
8510
8511 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8512                                 __attribute__((unused)) void *data)
8513 {
8514         struct cmd_dump_one_result *res = parsed_result;
8515
8516         if (!strcmp(res->dump, "dump_ring")) {
8517                 struct rte_ring *r;
8518                 r = rte_ring_lookup(res->name);
8519                 if (r == NULL) {
8520                         cmdline_printf(cl, "Cannot find ring\n");
8521                         return;
8522                 }
8523                 rte_ring_dump(stdout, r);
8524         } else if (!strcmp(res->dump, "dump_mempool")) {
8525                 struct rte_mempool *mp;
8526                 mp = rte_mempool_lookup(res->name);
8527                 if (mp == NULL) {
8528                         cmdline_printf(cl, "Cannot find mempool\n");
8529                         return;
8530                 }
8531                 rte_mempool_dump(stdout, mp);
8532         }
8533 }
8534
8535 cmdline_parse_token_string_t cmd_dump_one_dump =
8536         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8537                                  "dump_ring#dump_mempool");
8538
8539 cmdline_parse_token_string_t cmd_dump_one_name =
8540         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8541
8542 cmdline_parse_inst_t cmd_dump_one = {
8543         .f = cmd_dump_one_parsed,  /* function to call */
8544         .data = NULL,      /* 2nd arg of func */
8545         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8546         .tokens = {        /* token list, NULL terminated */
8547                 (void *)&cmd_dump_one_dump,
8548                 (void *)&cmd_dump_one_name,
8549                 NULL,
8550         },
8551 };
8552
8553 /* *** Add/Del syn filter *** */
8554 struct cmd_syn_filter_result {
8555         cmdline_fixed_string_t filter;
8556         portid_t port_id;
8557         cmdline_fixed_string_t ops;
8558         cmdline_fixed_string_t priority;
8559         cmdline_fixed_string_t high;
8560         cmdline_fixed_string_t queue;
8561         uint16_t queue_id;
8562 };
8563
8564 static void
8565 cmd_syn_filter_parsed(void *parsed_result,
8566                         __attribute__((unused)) struct cmdline *cl,
8567                         __attribute__((unused)) void *data)
8568 {
8569         struct cmd_syn_filter_result *res = parsed_result;
8570         struct rte_eth_syn_filter syn_filter;
8571         int ret = 0;
8572
8573         ret = rte_eth_dev_filter_supported(res->port_id,
8574                                         RTE_ETH_FILTER_SYN);
8575         if (ret < 0) {
8576                 printf("syn filter is not supported on port %u.\n",
8577                                 res->port_id);
8578                 return;
8579         }
8580
8581         memset(&syn_filter, 0, sizeof(syn_filter));
8582
8583         if (!strcmp(res->ops, "add")) {
8584                 if (!strcmp(res->high, "high"))
8585                         syn_filter.hig_pri = 1;
8586                 else
8587                         syn_filter.hig_pri = 0;
8588
8589                 syn_filter.queue = res->queue_id;
8590                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8591                                                 RTE_ETH_FILTER_SYN,
8592                                                 RTE_ETH_FILTER_ADD,
8593                                                 &syn_filter);
8594         } else
8595                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8596                                                 RTE_ETH_FILTER_SYN,
8597                                                 RTE_ETH_FILTER_DELETE,
8598                                                 &syn_filter);
8599
8600         if (ret < 0)
8601                 printf("syn filter programming error: (%s)\n",
8602                                 strerror(-ret));
8603 }
8604
8605 cmdline_parse_token_string_t cmd_syn_filter_filter =
8606         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8607         filter, "syn_filter");
8608 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8609         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8610         port_id, UINT16);
8611 cmdline_parse_token_string_t cmd_syn_filter_ops =
8612         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8613         ops, "add#del");
8614 cmdline_parse_token_string_t cmd_syn_filter_priority =
8615         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8616                                 priority, "priority");
8617 cmdline_parse_token_string_t cmd_syn_filter_high =
8618         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8619                                 high, "high#low");
8620 cmdline_parse_token_string_t cmd_syn_filter_queue =
8621         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8622                                 queue, "queue");
8623 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8624         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8625                                 queue_id, UINT16);
8626
8627 cmdline_parse_inst_t cmd_syn_filter = {
8628         .f = cmd_syn_filter_parsed,
8629         .data = NULL,
8630         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8631                 "<queue_id>: Add/Delete syn filter",
8632         .tokens = {
8633                 (void *)&cmd_syn_filter_filter,
8634                 (void *)&cmd_syn_filter_port_id,
8635                 (void *)&cmd_syn_filter_ops,
8636                 (void *)&cmd_syn_filter_priority,
8637                 (void *)&cmd_syn_filter_high,
8638                 (void *)&cmd_syn_filter_queue,
8639                 (void *)&cmd_syn_filter_queue_id,
8640                 NULL,
8641         },
8642 };
8643
8644 /* *** queue region set *** */
8645 struct cmd_queue_region_result {
8646         cmdline_fixed_string_t set;
8647         cmdline_fixed_string_t port;
8648         portid_t port_id;
8649         cmdline_fixed_string_t cmd;
8650         cmdline_fixed_string_t region;
8651         uint8_t  region_id;
8652         cmdline_fixed_string_t queue_start_index;
8653         uint8_t  queue_id;
8654         cmdline_fixed_string_t queue_num;
8655         uint8_t  queue_num_value;
8656 };
8657
8658 static void
8659 cmd_queue_region_parsed(void *parsed_result,
8660                         __attribute__((unused)) struct cmdline *cl,
8661                         __attribute__((unused)) void *data)
8662 {
8663         struct cmd_queue_region_result *res = parsed_result;
8664         int ret = -ENOTSUP;
8665 #ifdef RTE_LIBRTE_I40E_PMD
8666         struct rte_pmd_i40e_queue_region_conf region_conf;
8667         enum rte_pmd_i40e_queue_region_op op_type;
8668 #endif
8669
8670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8671                 return;
8672
8673 #ifdef RTE_LIBRTE_I40E_PMD
8674         memset(&region_conf, 0, sizeof(region_conf));
8675         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8676         region_conf.region_id = res->region_id;
8677         region_conf.queue_num = res->queue_num_value;
8678         region_conf.queue_start_index = res->queue_id;
8679
8680         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8681                                 op_type, &region_conf);
8682 #endif
8683
8684         switch (ret) {
8685         case 0:
8686                 break;
8687         case -ENOTSUP:
8688                 printf("function not implemented or supported\n");
8689                 break;
8690         default:
8691                 printf("queue region config error: (%s)\n", strerror(-ret));
8692         }
8693 }
8694
8695 cmdline_parse_token_string_t cmd_queue_region_set =
8696 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8697                 set, "set");
8698 cmdline_parse_token_string_t cmd_queue_region_port =
8699         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8700 cmdline_parse_token_num_t cmd_queue_region_port_id =
8701         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8702                                 port_id, UINT16);
8703 cmdline_parse_token_string_t cmd_queue_region_cmd =
8704         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8705                                  cmd, "queue-region");
8706 cmdline_parse_token_string_t cmd_queue_region_id =
8707         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8708                                 region, "region_id");
8709 cmdline_parse_token_num_t cmd_queue_region_index =
8710         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8711                                 region_id, UINT8);
8712 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8713         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8714                                 queue_start_index, "queue_start_index");
8715 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8716         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8717                                 queue_id, UINT8);
8718 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8719         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8720                                 queue_num, "queue_num");
8721 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8722         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8723                                 queue_num_value, UINT8);
8724
8725 cmdline_parse_inst_t cmd_queue_region = {
8726         .f = cmd_queue_region_parsed,
8727         .data = NULL,
8728         .help_str = "set port <port_id> queue-region region_id <value> "
8729                 "queue_start_index <value> queue_num <value>: Set a queue region",
8730         .tokens = {
8731                 (void *)&cmd_queue_region_set,
8732                 (void *)&cmd_queue_region_port,
8733                 (void *)&cmd_queue_region_port_id,
8734                 (void *)&cmd_queue_region_cmd,
8735                 (void *)&cmd_queue_region_id,
8736                 (void *)&cmd_queue_region_index,
8737                 (void *)&cmd_queue_region_queue_start_index,
8738                 (void *)&cmd_queue_region_queue_id,
8739                 (void *)&cmd_queue_region_queue_num,
8740                 (void *)&cmd_queue_region_queue_num_value,
8741                 NULL,
8742         },
8743 };
8744
8745 /* *** queue region and flowtype set *** */
8746 struct cmd_region_flowtype_result {
8747         cmdline_fixed_string_t set;
8748         cmdline_fixed_string_t port;
8749         portid_t port_id;
8750         cmdline_fixed_string_t cmd;
8751         cmdline_fixed_string_t region;
8752         uint8_t  region_id;
8753         cmdline_fixed_string_t flowtype;
8754         uint8_t  flowtype_id;
8755 };
8756
8757 static void
8758 cmd_region_flowtype_parsed(void *parsed_result,
8759                         __attribute__((unused)) struct cmdline *cl,
8760                         __attribute__((unused)) void *data)
8761 {
8762         struct cmd_region_flowtype_result *res = parsed_result;
8763         int ret = -ENOTSUP;
8764 #ifdef RTE_LIBRTE_I40E_PMD
8765         struct rte_pmd_i40e_queue_region_conf region_conf;
8766         enum rte_pmd_i40e_queue_region_op op_type;
8767 #endif
8768
8769         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8770                 return;
8771
8772 #ifdef RTE_LIBRTE_I40E_PMD
8773         memset(&region_conf, 0, sizeof(region_conf));
8774
8775         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8776         region_conf.region_id = res->region_id;
8777         region_conf.hw_flowtype = res->flowtype_id;
8778
8779         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8780                         op_type, &region_conf);
8781 #endif
8782
8783         switch (ret) {
8784         case 0:
8785                 break;
8786         case -ENOTSUP:
8787                 printf("function not implemented or supported\n");
8788                 break;
8789         default:
8790                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8791         }
8792 }
8793
8794 cmdline_parse_token_string_t cmd_region_flowtype_set =
8795 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8796                                 set, "set");
8797 cmdline_parse_token_string_t cmd_region_flowtype_port =
8798         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8799                                 port, "port");
8800 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8801         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8802                                 port_id, UINT16);
8803 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8804         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8805                                 cmd, "queue-region");
8806 cmdline_parse_token_string_t cmd_region_flowtype_index =
8807         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8808                                 region, "region_id");
8809 cmdline_parse_token_num_t cmd_region_flowtype_id =
8810         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8811                                 region_id, UINT8);
8812 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8813         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8814                                 flowtype, "flowtype");
8815 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8816         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8817                                 flowtype_id, UINT8);
8818 cmdline_parse_inst_t cmd_region_flowtype = {
8819         .f = cmd_region_flowtype_parsed,
8820         .data = NULL,
8821         .help_str = "set port <port_id> queue-region region_id <value> "
8822                 "flowtype <value>: Set a flowtype region index",
8823         .tokens = {
8824                 (void *)&cmd_region_flowtype_set,
8825                 (void *)&cmd_region_flowtype_port,
8826                 (void *)&cmd_region_flowtype_port_index,
8827                 (void *)&cmd_region_flowtype_cmd,
8828                 (void *)&cmd_region_flowtype_index,
8829                 (void *)&cmd_region_flowtype_id,
8830                 (void *)&cmd_region_flowtype_flow_index,
8831                 (void *)&cmd_region_flowtype_flow_id,
8832                 NULL,
8833         },
8834 };
8835
8836 /* *** User Priority (UP) to queue region (region_id) set *** */
8837 struct cmd_user_priority_region_result {
8838         cmdline_fixed_string_t set;
8839         cmdline_fixed_string_t port;
8840         portid_t port_id;
8841         cmdline_fixed_string_t cmd;
8842         cmdline_fixed_string_t user_priority;
8843         uint8_t  user_priority_id;
8844         cmdline_fixed_string_t region;
8845         uint8_t  region_id;
8846 };
8847
8848 static void
8849 cmd_user_priority_region_parsed(void *parsed_result,
8850                         __attribute__((unused)) struct cmdline *cl,
8851                         __attribute__((unused)) void *data)
8852 {
8853         struct cmd_user_priority_region_result *res = parsed_result;
8854         int ret = -ENOTSUP;
8855 #ifdef RTE_LIBRTE_I40E_PMD
8856         struct rte_pmd_i40e_queue_region_conf region_conf;
8857         enum rte_pmd_i40e_queue_region_op op_type;
8858 #endif
8859
8860         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8861                 return;
8862
8863 #ifdef RTE_LIBRTE_I40E_PMD
8864         memset(&region_conf, 0, sizeof(region_conf));
8865         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8866         region_conf.user_priority = res->user_priority_id;
8867         region_conf.region_id = res->region_id;
8868
8869         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8870                                 op_type, &region_conf);
8871 #endif
8872
8873         switch (ret) {
8874         case 0:
8875                 break;
8876         case -ENOTSUP:
8877                 printf("function not implemented or supported\n");
8878                 break;
8879         default:
8880                 printf("user_priority region config error: (%s)\n",
8881                                 strerror(-ret));
8882         }
8883 }
8884
8885 cmdline_parse_token_string_t cmd_user_priority_region_set =
8886         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8887                                 set, "set");
8888 cmdline_parse_token_string_t cmd_user_priority_region_port =
8889         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8890                                 port, "port");
8891 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8892         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8893                                 port_id, UINT16);
8894 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8895         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8896                                 cmd, "queue-region");
8897 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8899                                 user_priority, "UP");
8900 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8901         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8902                                 user_priority_id, UINT8);
8903 cmdline_parse_token_string_t cmd_user_priority_region_region =
8904         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8905                                 region, "region_id");
8906 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8907         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8908                                 region_id, UINT8);
8909
8910 cmdline_parse_inst_t cmd_user_priority_region = {
8911         .f = cmd_user_priority_region_parsed,
8912         .data = NULL,
8913         .help_str = "set port <port_id> queue-region UP <value> "
8914                 "region_id <value>: Set the mapping of User Priority (UP) "
8915                 "to queue region (region_id) ",
8916         .tokens = {
8917                 (void *)&cmd_user_priority_region_set,
8918                 (void *)&cmd_user_priority_region_port,
8919                 (void *)&cmd_user_priority_region_port_index,
8920                 (void *)&cmd_user_priority_region_cmd,
8921                 (void *)&cmd_user_priority_region_UP,
8922                 (void *)&cmd_user_priority_region_UP_id,
8923                 (void *)&cmd_user_priority_region_region,
8924                 (void *)&cmd_user_priority_region_region_id,
8925                 NULL,
8926         },
8927 };
8928
8929 /* *** flush all queue region related configuration *** */
8930 struct cmd_flush_queue_region_result {
8931         cmdline_fixed_string_t set;
8932         cmdline_fixed_string_t port;
8933         portid_t port_id;
8934         cmdline_fixed_string_t cmd;
8935         cmdline_fixed_string_t flush;
8936         cmdline_fixed_string_t what;
8937 };
8938
8939 static void
8940 cmd_flush_queue_region_parsed(void *parsed_result,
8941                         __attribute__((unused)) struct cmdline *cl,
8942                         __attribute__((unused)) void *data)
8943 {
8944         struct cmd_flush_queue_region_result *res = parsed_result;
8945         int ret = -ENOTSUP;
8946 #ifdef RTE_LIBRTE_I40E_PMD
8947         struct rte_pmd_i40e_queue_region_conf region_conf;
8948         enum rte_pmd_i40e_queue_region_op op_type;
8949 #endif
8950
8951         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8952                 return;
8953
8954 #ifdef RTE_LIBRTE_I40E_PMD
8955         memset(&region_conf, 0, sizeof(region_conf));
8956
8957         if (strcmp(res->what, "on") == 0)
8958                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8959         else
8960                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8961
8962         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8963                                 op_type, &region_conf);
8964 #endif
8965
8966         switch (ret) {
8967         case 0:
8968                 break;
8969         case -ENOTSUP:
8970                 printf("function not implemented or supported\n");
8971                 break;
8972         default:
8973                 printf("queue region config flush error: (%s)\n",
8974                                 strerror(-ret));
8975         }
8976 }
8977
8978 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8979         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8980                                 set, "set");
8981 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8982         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8983                                 port, "port");
8984 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8985         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8986                                 port_id, UINT16);
8987 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8988         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8989                                 cmd, "queue-region");
8990 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8992                                 flush, "flush");
8993 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8994         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8995                                 what, "on#off");
8996
8997 cmdline_parse_inst_t cmd_flush_queue_region = {
8998         .f = cmd_flush_queue_region_parsed,
8999         .data = NULL,
9000         .help_str = "set port <port_id> queue-region flush on|off"
9001                 ": flush all queue region related configuration",
9002         .tokens = {
9003                 (void *)&cmd_flush_queue_region_set,
9004                 (void *)&cmd_flush_queue_region_port,
9005                 (void *)&cmd_flush_queue_region_port_index,
9006                 (void *)&cmd_flush_queue_region_cmd,
9007                 (void *)&cmd_flush_queue_region_flush,
9008                 (void *)&cmd_flush_queue_region_what,
9009                 NULL,
9010         },
9011 };
9012
9013 /* *** get all queue region related configuration info *** */
9014 struct cmd_show_queue_region_info {
9015         cmdline_fixed_string_t show;
9016         cmdline_fixed_string_t port;
9017         portid_t port_id;
9018         cmdline_fixed_string_t cmd;
9019 };
9020
9021 static void
9022 cmd_show_queue_region_info_parsed(void *parsed_result,
9023                         __attribute__((unused)) struct cmdline *cl,
9024                         __attribute__((unused)) void *data)
9025 {
9026         struct cmd_show_queue_region_info *res = parsed_result;
9027         int ret = -ENOTSUP;
9028 #ifdef RTE_LIBRTE_I40E_PMD
9029         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9030         enum rte_pmd_i40e_queue_region_op op_type;
9031 #endif
9032
9033         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9034                 return;
9035
9036 #ifdef RTE_LIBRTE_I40E_PMD
9037         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9038
9039         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9040
9041         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9042                                         op_type, &rte_pmd_regions);
9043
9044         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9045 #endif
9046
9047         switch (ret) {
9048         case 0:
9049                 break;
9050         case -ENOTSUP:
9051                 printf("function not implemented or supported\n");
9052                 break;
9053         default:
9054                 printf("queue region config info show error: (%s)\n",
9055                                 strerror(-ret));
9056         }
9057 }
9058
9059 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9060 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9061                                 show, "show");
9062 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9063         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9064                                 port, "port");
9065 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9066         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9067                                 port_id, UINT16);
9068 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9069         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9070                                 cmd, "queue-region");
9071
9072 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9073         .f = cmd_show_queue_region_info_parsed,
9074         .data = NULL,
9075         .help_str = "show port <port_id> queue-region"
9076                 ": show all queue region related configuration info",
9077         .tokens = {
9078                 (void *)&cmd_show_queue_region_info_get,
9079                 (void *)&cmd_show_queue_region_info_port,
9080                 (void *)&cmd_show_queue_region_info_port_index,
9081                 (void *)&cmd_show_queue_region_info_cmd,
9082                 NULL,
9083         },
9084 };
9085
9086 /* *** ADD/REMOVE A 2tuple FILTER *** */
9087 struct cmd_2tuple_filter_result {
9088         cmdline_fixed_string_t filter;
9089         portid_t port_id;
9090         cmdline_fixed_string_t ops;
9091         cmdline_fixed_string_t dst_port;
9092         uint16_t dst_port_value;
9093         cmdline_fixed_string_t protocol;
9094         uint8_t protocol_value;
9095         cmdline_fixed_string_t mask;
9096         uint8_t  mask_value;
9097         cmdline_fixed_string_t tcp_flags;
9098         uint8_t tcp_flags_value;
9099         cmdline_fixed_string_t priority;
9100         uint8_t  priority_value;
9101         cmdline_fixed_string_t queue;
9102         uint16_t  queue_id;
9103 };
9104
9105 static void
9106 cmd_2tuple_filter_parsed(void *parsed_result,
9107                         __attribute__((unused)) struct cmdline *cl,
9108                         __attribute__((unused)) void *data)
9109 {
9110         struct rte_eth_ntuple_filter filter;
9111         struct cmd_2tuple_filter_result *res = parsed_result;
9112         int ret = 0;
9113
9114         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9115         if (ret < 0) {
9116                 printf("ntuple filter is not supported on port %u.\n",
9117                         res->port_id);
9118                 return;
9119         }
9120
9121         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9122
9123         filter.flags = RTE_2TUPLE_FLAGS;
9124         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9125         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9126         filter.proto = res->protocol_value;
9127         filter.priority = res->priority_value;
9128         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9129                 printf("nonzero tcp_flags is only meaningful"
9130                         " when protocol is TCP.\n");
9131                 return;
9132         }
9133         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9134                 printf("invalid TCP flags.\n");
9135                 return;
9136         }
9137
9138         if (res->tcp_flags_value != 0) {
9139                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9140                 filter.tcp_flags = res->tcp_flags_value;
9141         }
9142
9143         /* need convert to big endian. */
9144         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9145         filter.queue = res->queue_id;
9146
9147         if (!strcmp(res->ops, "add"))
9148                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9149                                 RTE_ETH_FILTER_NTUPLE,
9150                                 RTE_ETH_FILTER_ADD,
9151                                 &filter);
9152         else
9153                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9154                                 RTE_ETH_FILTER_NTUPLE,
9155                                 RTE_ETH_FILTER_DELETE,
9156                                 &filter);
9157         if (ret < 0)
9158                 printf("2tuple filter programming error: (%s)\n",
9159                         strerror(-ret));
9160
9161 }
9162
9163 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9164         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9165                                  filter, "2tuple_filter");
9166 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9167         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9168                                 port_id, UINT16);
9169 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9170         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9171                                  ops, "add#del");
9172 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9173         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9174                                 dst_port, "dst_port");
9175 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9176         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9177                                 dst_port_value, UINT16);
9178 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9179         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9180                                 protocol, "protocol");
9181 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9182         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9183                                 protocol_value, UINT8);
9184 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9185         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9186                                 mask, "mask");
9187 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9188         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9189                                 mask_value, INT8);
9190 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9191         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9192                                 tcp_flags, "tcp_flags");
9193 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9194         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9195                                 tcp_flags_value, UINT8);
9196 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9197         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9198                                 priority, "priority");
9199 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9200         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9201                                 priority_value, UINT8);
9202 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9203         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9204                                 queue, "queue");
9205 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9206         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9207                                 queue_id, UINT16);
9208
9209 cmdline_parse_inst_t cmd_2tuple_filter = {
9210         .f = cmd_2tuple_filter_parsed,
9211         .data = NULL,
9212         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9213                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9214                 "<queue_id>: Add a 2tuple filter",
9215         .tokens = {
9216                 (void *)&cmd_2tuple_filter_filter,
9217                 (void *)&cmd_2tuple_filter_port_id,
9218                 (void *)&cmd_2tuple_filter_ops,
9219                 (void *)&cmd_2tuple_filter_dst_port,
9220                 (void *)&cmd_2tuple_filter_dst_port_value,
9221                 (void *)&cmd_2tuple_filter_protocol,
9222                 (void *)&cmd_2tuple_filter_protocol_value,
9223                 (void *)&cmd_2tuple_filter_mask,
9224                 (void *)&cmd_2tuple_filter_mask_value,
9225                 (void *)&cmd_2tuple_filter_tcp_flags,
9226                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9227                 (void *)&cmd_2tuple_filter_priority,
9228                 (void *)&cmd_2tuple_filter_priority_value,
9229                 (void *)&cmd_2tuple_filter_queue,
9230                 (void *)&cmd_2tuple_filter_queue_id,
9231                 NULL,
9232         },
9233 };
9234
9235 /* *** ADD/REMOVE A 5tuple FILTER *** */
9236 struct cmd_5tuple_filter_result {
9237         cmdline_fixed_string_t filter;
9238         portid_t port_id;
9239         cmdline_fixed_string_t ops;
9240         cmdline_fixed_string_t dst_ip;
9241         cmdline_ipaddr_t dst_ip_value;
9242         cmdline_fixed_string_t src_ip;
9243         cmdline_ipaddr_t src_ip_value;
9244         cmdline_fixed_string_t dst_port;
9245         uint16_t dst_port_value;
9246         cmdline_fixed_string_t src_port;
9247         uint16_t src_port_value;
9248         cmdline_fixed_string_t protocol;
9249         uint8_t protocol_value;
9250         cmdline_fixed_string_t mask;
9251         uint8_t  mask_value;
9252         cmdline_fixed_string_t tcp_flags;
9253         uint8_t tcp_flags_value;
9254         cmdline_fixed_string_t priority;
9255         uint8_t  priority_value;
9256         cmdline_fixed_string_t queue;
9257         uint16_t  queue_id;
9258 };
9259
9260 static void
9261 cmd_5tuple_filter_parsed(void *parsed_result,
9262                         __attribute__((unused)) struct cmdline *cl,
9263                         __attribute__((unused)) void *data)
9264 {
9265         struct rte_eth_ntuple_filter filter;
9266         struct cmd_5tuple_filter_result *res = parsed_result;
9267         int ret = 0;
9268
9269         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9270         if (ret < 0) {
9271                 printf("ntuple filter is not supported on port %u.\n",
9272                         res->port_id);
9273                 return;
9274         }
9275
9276         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9277
9278         filter.flags = RTE_5TUPLE_FLAGS;
9279         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9280         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9281         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9282         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9283         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9284         filter.proto = res->protocol_value;
9285         filter.priority = res->priority_value;
9286         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9287                 printf("nonzero tcp_flags is only meaningful"
9288                         " when protocol is TCP.\n");
9289                 return;
9290         }
9291         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9292                 printf("invalid TCP flags.\n");
9293                 return;
9294         }
9295
9296         if (res->tcp_flags_value != 0) {
9297                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9298                 filter.tcp_flags = res->tcp_flags_value;
9299         }
9300
9301         if (res->dst_ip_value.family == AF_INET)
9302                 /* no need to convert, already big endian. */
9303                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9304         else {
9305                 if (filter.dst_ip_mask == 0) {
9306                         printf("can not support ipv6 involved compare.\n");
9307                         return;
9308                 }
9309                 filter.dst_ip = 0;
9310         }
9311
9312         if (res->src_ip_value.family == AF_INET)
9313                 /* no need to convert, already big endian. */
9314                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9315         else {
9316                 if (filter.src_ip_mask == 0) {
9317                         printf("can not support ipv6 involved compare.\n");
9318                         return;
9319                 }
9320                 filter.src_ip = 0;
9321         }
9322         /* need convert to big endian. */
9323         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9324         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9325         filter.queue = res->queue_id;
9326
9327         if (!strcmp(res->ops, "add"))
9328                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9329                                 RTE_ETH_FILTER_NTUPLE,
9330                                 RTE_ETH_FILTER_ADD,
9331                                 &filter);
9332         else
9333                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9334                                 RTE_ETH_FILTER_NTUPLE,
9335                                 RTE_ETH_FILTER_DELETE,
9336                                 &filter);
9337         if (ret < 0)
9338                 printf("5tuple filter programming error: (%s)\n",
9339                         strerror(-ret));
9340 }
9341
9342 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9343         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9344                                  filter, "5tuple_filter");
9345 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9346         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9347                                 port_id, UINT16);
9348 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9349         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9350                                  ops, "add#del");
9351 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9352         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9353                                 dst_ip, "dst_ip");
9354 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9355         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9356                                 dst_ip_value);
9357 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9359                                 src_ip, "src_ip");
9360 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9361         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9362                                 src_ip_value);
9363 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9364         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9365                                 dst_port, "dst_port");
9366 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9367         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9368                                 dst_port_value, UINT16);
9369 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9370         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9371                                 src_port, "src_port");
9372 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9373         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9374                                 src_port_value, UINT16);
9375 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9376         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9377                                 protocol, "protocol");
9378 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9379         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9380                                 protocol_value, UINT8);
9381 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9382         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9383                                 mask, "mask");
9384 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9385         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9386                                 mask_value, INT8);
9387 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9388         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9389                                 tcp_flags, "tcp_flags");
9390 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9391         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9392                                 tcp_flags_value, UINT8);
9393 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9394         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9395                                 priority, "priority");
9396 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9397         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9398                                 priority_value, UINT8);
9399 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9400         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9401                                 queue, "queue");
9402 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9403         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9404                                 queue_id, UINT16);
9405
9406 cmdline_parse_inst_t cmd_5tuple_filter = {
9407         .f = cmd_5tuple_filter_parsed,
9408         .data = NULL,
9409         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9410                 "src_ip <value> dst_port <value> src_port <value> "
9411                 "protocol <value>  mask <value> tcp_flags <value> "
9412                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9413         .tokens = {
9414                 (void *)&cmd_5tuple_filter_filter,
9415                 (void *)&cmd_5tuple_filter_port_id,
9416                 (void *)&cmd_5tuple_filter_ops,
9417                 (void *)&cmd_5tuple_filter_dst_ip,
9418                 (void *)&cmd_5tuple_filter_dst_ip_value,
9419                 (void *)&cmd_5tuple_filter_src_ip,
9420                 (void *)&cmd_5tuple_filter_src_ip_value,
9421                 (void *)&cmd_5tuple_filter_dst_port,
9422                 (void *)&cmd_5tuple_filter_dst_port_value,
9423                 (void *)&cmd_5tuple_filter_src_port,
9424                 (void *)&cmd_5tuple_filter_src_port_value,
9425                 (void *)&cmd_5tuple_filter_protocol,
9426                 (void *)&cmd_5tuple_filter_protocol_value,
9427                 (void *)&cmd_5tuple_filter_mask,
9428                 (void *)&cmd_5tuple_filter_mask_value,
9429                 (void *)&cmd_5tuple_filter_tcp_flags,
9430                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9431                 (void *)&cmd_5tuple_filter_priority,
9432                 (void *)&cmd_5tuple_filter_priority_value,
9433                 (void *)&cmd_5tuple_filter_queue,
9434                 (void *)&cmd_5tuple_filter_queue_id,
9435                 NULL,
9436         },
9437 };
9438
9439 /* *** ADD/REMOVE A flex FILTER *** */
9440 struct cmd_flex_filter_result {
9441         cmdline_fixed_string_t filter;
9442         cmdline_fixed_string_t ops;
9443         portid_t port_id;
9444         cmdline_fixed_string_t len;
9445         uint8_t len_value;
9446         cmdline_fixed_string_t bytes;
9447         cmdline_fixed_string_t bytes_value;
9448         cmdline_fixed_string_t mask;
9449         cmdline_fixed_string_t mask_value;
9450         cmdline_fixed_string_t priority;
9451         uint8_t priority_value;
9452         cmdline_fixed_string_t queue;
9453         uint16_t queue_id;
9454 };
9455
9456 static int xdigit2val(unsigned char c)
9457 {
9458         int val;
9459         if (isdigit(c))
9460                 val = c - '0';
9461         else if (isupper(c))
9462                 val = c - 'A' + 10;
9463         else
9464                 val = c - 'a' + 10;
9465         return val;
9466 }
9467
9468 static void
9469 cmd_flex_filter_parsed(void *parsed_result,
9470                           __attribute__((unused)) struct cmdline *cl,
9471                           __attribute__((unused)) void *data)
9472 {
9473         int ret = 0;
9474         struct rte_eth_flex_filter filter;
9475         struct cmd_flex_filter_result *res = parsed_result;
9476         char *bytes_ptr, *mask_ptr;
9477         uint16_t len, i, j = 0;
9478         char c;
9479         int val;
9480         uint8_t byte = 0;
9481
9482         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9483                 printf("the len exceed the max length 128\n");
9484                 return;
9485         }
9486         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9487         filter.len = res->len_value;
9488         filter.priority = res->priority_value;
9489         filter.queue = res->queue_id;
9490         bytes_ptr = res->bytes_value;
9491         mask_ptr = res->mask_value;
9492
9493          /* translate bytes string to array. */
9494         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9495                 (bytes_ptr[1] == 'X')))
9496                 bytes_ptr += 2;
9497         len = strnlen(bytes_ptr, res->len_value * 2);
9498         if (len == 0 || (len % 8 != 0)) {
9499                 printf("please check len and bytes input\n");
9500                 return;
9501         }
9502         for (i = 0; i < len; i++) {
9503                 c = bytes_ptr[i];
9504                 if (isxdigit(c) == 0) {
9505                         /* invalid characters. */
9506                         printf("invalid input\n");
9507                         return;
9508                 }
9509                 val = xdigit2val(c);
9510                 if (i % 2) {
9511                         byte |= val;
9512                         filter.bytes[j] = byte;
9513                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9514                         j++;
9515                         byte = 0;
9516                 } else
9517                         byte |= val << 4;
9518         }
9519         printf("\n");
9520          /* translate mask string to uint8_t array. */
9521         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9522                 (mask_ptr[1] == 'X')))
9523                 mask_ptr += 2;
9524         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9525         if (len == 0) {
9526                 printf("invalid input\n");
9527                 return;
9528         }
9529         j = 0;
9530         byte = 0;
9531         for (i = 0; i < len; i++) {
9532                 c = mask_ptr[i];
9533                 if (isxdigit(c) == 0) {
9534                         /* invalid characters. */
9535                         printf("invalid input\n");
9536                         return;
9537                 }
9538                 val = xdigit2val(c);
9539                 if (i % 2) {
9540                         byte |= val;
9541                         filter.mask[j] = byte;
9542                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9543                         j++;
9544                         byte = 0;
9545                 } else
9546                         byte |= val << 4;
9547         }
9548         printf("\n");
9549
9550         if (!strcmp(res->ops, "add"))
9551                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9552                                 RTE_ETH_FILTER_FLEXIBLE,
9553                                 RTE_ETH_FILTER_ADD,
9554                                 &filter);
9555         else
9556                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9557                                 RTE_ETH_FILTER_FLEXIBLE,
9558                                 RTE_ETH_FILTER_DELETE,
9559                                 &filter);
9560
9561         if (ret < 0)
9562                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9563 }
9564
9565 cmdline_parse_token_string_t cmd_flex_filter_filter =
9566         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9567                                 filter, "flex_filter");
9568 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9569         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9570                                 port_id, UINT16);
9571 cmdline_parse_token_string_t cmd_flex_filter_ops =
9572         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9573                                 ops, "add#del");
9574 cmdline_parse_token_string_t cmd_flex_filter_len =
9575         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9576                                 len, "len");
9577 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9578         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9579                                 len_value, UINT8);
9580 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9581         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9582                                 bytes, "bytes");
9583 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9584         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9585                                 bytes_value, NULL);
9586 cmdline_parse_token_string_t cmd_flex_filter_mask =
9587         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9588                                 mask, "mask");
9589 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9590         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9591                                 mask_value, NULL);
9592 cmdline_parse_token_string_t cmd_flex_filter_priority =
9593         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9594                                 priority, "priority");
9595 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9596         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9597                                 priority_value, UINT8);
9598 cmdline_parse_token_string_t cmd_flex_filter_queue =
9599         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9600                                 queue, "queue");
9601 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9602         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9603                                 queue_id, UINT16);
9604 cmdline_parse_inst_t cmd_flex_filter = {
9605         .f = cmd_flex_filter_parsed,
9606         .data = NULL,
9607         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9608                 "<value> mask <value> priority <value> queue <queue_id>: "
9609                 "Add/Del a flex filter",
9610         .tokens = {
9611                 (void *)&cmd_flex_filter_filter,
9612                 (void *)&cmd_flex_filter_port_id,
9613                 (void *)&cmd_flex_filter_ops,
9614                 (void *)&cmd_flex_filter_len,
9615                 (void *)&cmd_flex_filter_len_value,
9616                 (void *)&cmd_flex_filter_bytes,
9617                 (void *)&cmd_flex_filter_bytes_value,
9618                 (void *)&cmd_flex_filter_mask,
9619                 (void *)&cmd_flex_filter_mask_value,
9620                 (void *)&cmd_flex_filter_priority,
9621                 (void *)&cmd_flex_filter_priority_value,
9622                 (void *)&cmd_flex_filter_queue,
9623                 (void *)&cmd_flex_filter_queue_id,
9624                 NULL,
9625         },
9626 };
9627
9628 /* *** Filters Control *** */
9629
9630 /* *** deal with ethertype filter *** */
9631 struct cmd_ethertype_filter_result {
9632         cmdline_fixed_string_t filter;
9633         portid_t port_id;
9634         cmdline_fixed_string_t ops;
9635         cmdline_fixed_string_t mac;
9636         struct ether_addr mac_addr;
9637         cmdline_fixed_string_t ethertype;
9638         uint16_t ethertype_value;
9639         cmdline_fixed_string_t drop;
9640         cmdline_fixed_string_t queue;
9641         uint16_t  queue_id;
9642 };
9643
9644 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9645         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9646                                  filter, "ethertype_filter");
9647 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9648         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9649                               port_id, UINT16);
9650 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9651         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9652                                  ops, "add#del");
9653 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9654         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9655                                  mac, "mac_addr#mac_ignr");
9656 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9657         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9658                                      mac_addr);
9659 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9660         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9661                                  ethertype, "ethertype");
9662 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9663         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9664                               ethertype_value, UINT16);
9665 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9666         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9667                                  drop, "drop#fwd");
9668 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9669         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9670                                  queue, "queue");
9671 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9672         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9673                               queue_id, UINT16);
9674
9675 static void
9676 cmd_ethertype_filter_parsed(void *parsed_result,
9677                           __attribute__((unused)) struct cmdline *cl,
9678                           __attribute__((unused)) void *data)
9679 {
9680         struct cmd_ethertype_filter_result *res = parsed_result;
9681         struct rte_eth_ethertype_filter filter;
9682         int ret = 0;
9683
9684         ret = rte_eth_dev_filter_supported(res->port_id,
9685                         RTE_ETH_FILTER_ETHERTYPE);
9686         if (ret < 0) {
9687                 printf("ethertype filter is not supported on port %u.\n",
9688                         res->port_id);
9689                 return;
9690         }
9691
9692         memset(&filter, 0, sizeof(filter));
9693         if (!strcmp(res->mac, "mac_addr")) {
9694                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9695                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9696                         sizeof(struct ether_addr));
9697         }
9698         if (!strcmp(res->drop, "drop"))
9699                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9700         filter.ether_type = res->ethertype_value;
9701         filter.queue = res->queue_id;
9702
9703         if (!strcmp(res->ops, "add"))
9704                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9705                                 RTE_ETH_FILTER_ETHERTYPE,
9706                                 RTE_ETH_FILTER_ADD,
9707                                 &filter);
9708         else
9709                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9710                                 RTE_ETH_FILTER_ETHERTYPE,
9711                                 RTE_ETH_FILTER_DELETE,
9712                                 &filter);
9713         if (ret < 0)
9714                 printf("ethertype filter programming error: (%s)\n",
9715                         strerror(-ret));
9716 }
9717
9718 cmdline_parse_inst_t cmd_ethertype_filter = {
9719         .f = cmd_ethertype_filter_parsed,
9720         .data = NULL,
9721         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9722                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9723                 "Add or delete an ethertype filter entry",
9724         .tokens = {
9725                 (void *)&cmd_ethertype_filter_filter,
9726                 (void *)&cmd_ethertype_filter_port_id,
9727                 (void *)&cmd_ethertype_filter_ops,
9728                 (void *)&cmd_ethertype_filter_mac,
9729                 (void *)&cmd_ethertype_filter_mac_addr,
9730                 (void *)&cmd_ethertype_filter_ethertype,
9731                 (void *)&cmd_ethertype_filter_ethertype_value,
9732                 (void *)&cmd_ethertype_filter_drop,
9733                 (void *)&cmd_ethertype_filter_queue,
9734                 (void *)&cmd_ethertype_filter_queue_id,
9735                 NULL,
9736         },
9737 };
9738
9739 /* *** deal with flow director filter *** */
9740 struct cmd_flow_director_result {
9741         cmdline_fixed_string_t flow_director_filter;
9742         portid_t port_id;
9743         cmdline_fixed_string_t mode;
9744         cmdline_fixed_string_t mode_value;
9745         cmdline_fixed_string_t ops;
9746         cmdline_fixed_string_t flow;
9747         cmdline_fixed_string_t flow_type;
9748         cmdline_fixed_string_t ether;
9749         uint16_t ether_type;
9750         cmdline_fixed_string_t src;
9751         cmdline_ipaddr_t ip_src;
9752         uint16_t port_src;
9753         cmdline_fixed_string_t dst;
9754         cmdline_ipaddr_t ip_dst;
9755         uint16_t port_dst;
9756         cmdline_fixed_string_t verify_tag;
9757         uint32_t verify_tag_value;
9758         cmdline_ipaddr_t tos;
9759         uint8_t tos_value;
9760         cmdline_ipaddr_t proto;
9761         uint8_t proto_value;
9762         cmdline_ipaddr_t ttl;
9763         uint8_t ttl_value;
9764         cmdline_fixed_string_t vlan;
9765         uint16_t vlan_value;
9766         cmdline_fixed_string_t flexbytes;
9767         cmdline_fixed_string_t flexbytes_value;
9768         cmdline_fixed_string_t pf_vf;
9769         cmdline_fixed_string_t drop;
9770         cmdline_fixed_string_t queue;
9771         uint16_t  queue_id;
9772         cmdline_fixed_string_t fd_id;
9773         uint32_t  fd_id_value;
9774         cmdline_fixed_string_t mac;
9775         struct ether_addr mac_addr;
9776         cmdline_fixed_string_t tunnel;
9777         cmdline_fixed_string_t tunnel_type;
9778         cmdline_fixed_string_t tunnel_id;
9779         uint32_t tunnel_id_value;
9780 };
9781
9782 static inline int
9783 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9784 {
9785         char s[256];
9786         const char *p, *p0 = q_arg;
9787         char *end;
9788         unsigned long int_fld;
9789         char *str_fld[max_num];
9790         int i;
9791         unsigned size;
9792         int ret = -1;
9793
9794         p = strchr(p0, '(');
9795         if (p == NULL)
9796                 return -1;
9797         ++p;
9798         p0 = strchr(p, ')');
9799         if (p0 == NULL)
9800                 return -1;
9801
9802         size = p0 - p;
9803         if (size >= sizeof(s))
9804                 return -1;
9805
9806         snprintf(s, sizeof(s), "%.*s", size, p);
9807         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9808         if (ret < 0 || ret > max_num)
9809                 return -1;
9810         for (i = 0; i < ret; i++) {
9811                 errno = 0;
9812                 int_fld = strtoul(str_fld[i], &end, 0);
9813                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9814                         return -1;
9815                 flexbytes[i] = (uint8_t)int_fld;
9816         }
9817         return ret;
9818 }
9819
9820 static uint16_t
9821 str2flowtype(char *string)
9822 {
9823         uint8_t i = 0;
9824         static const struct {
9825                 char str[32];
9826                 uint16_t type;
9827         } flowtype_str[] = {
9828                 {"raw", RTE_ETH_FLOW_RAW},
9829                 {"ipv4", RTE_ETH_FLOW_IPV4},
9830                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9831                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9832                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9833                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9834                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9835                 {"ipv6", RTE_ETH_FLOW_IPV6},
9836                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9837                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9838                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9839                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9840                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9841                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9842         };
9843
9844         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9845                 if (!strcmp(flowtype_str[i].str, string))
9846                         return flowtype_str[i].type;
9847         }
9848
9849         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9850                 return (uint16_t)atoi(string);
9851
9852         return RTE_ETH_FLOW_UNKNOWN;
9853 }
9854
9855 static enum rte_eth_fdir_tunnel_type
9856 str2fdir_tunneltype(char *string)
9857 {
9858         uint8_t i = 0;
9859
9860         static const struct {
9861                 char str[32];
9862                 enum rte_eth_fdir_tunnel_type type;
9863         } tunneltype_str[] = {
9864                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9865                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9866         };
9867
9868         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9869                 if (!strcmp(tunneltype_str[i].str, string))
9870                         return tunneltype_str[i].type;
9871         }
9872         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9873 }
9874
9875 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9876 do { \
9877         if ((ip_addr).family == AF_INET) \
9878                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9879         else { \
9880                 printf("invalid parameter.\n"); \
9881                 return; \
9882         } \
9883 } while (0)
9884
9885 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9886 do { \
9887         if ((ip_addr).family == AF_INET6) \
9888                 rte_memcpy(&(ip), \
9889                                  &((ip_addr).addr.ipv6), \
9890                                  sizeof(struct in6_addr)); \
9891         else { \
9892                 printf("invalid parameter.\n"); \
9893                 return; \
9894         } \
9895 } while (0)
9896
9897 static void
9898 cmd_flow_director_filter_parsed(void *parsed_result,
9899                           __attribute__((unused)) struct cmdline *cl,
9900                           __attribute__((unused)) void *data)
9901 {
9902         struct cmd_flow_director_result *res = parsed_result;
9903         struct rte_eth_fdir_filter entry;
9904         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9905         char *end;
9906         unsigned long vf_id;
9907         int ret = 0;
9908
9909         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9910         if (ret < 0) {
9911                 printf("flow director is not supported on port %u.\n",
9912                         res->port_id);
9913                 return;
9914         }
9915         memset(flexbytes, 0, sizeof(flexbytes));
9916         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9917
9918         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9919                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9920                         printf("Please set mode to MAC-VLAN.\n");
9921                         return;
9922                 }
9923         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9924                 if (strcmp(res->mode_value, "Tunnel")) {
9925                         printf("Please set mode to Tunnel.\n");
9926                         return;
9927                 }
9928         } else {
9929                 if (strcmp(res->mode_value, "IP")) {
9930                         printf("Please set mode to IP.\n");
9931                         return;
9932                 }
9933                 entry.input.flow_type = str2flowtype(res->flow_type);
9934         }
9935
9936         ret = parse_flexbytes(res->flexbytes_value,
9937                                         flexbytes,
9938                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9939         if (ret < 0) {
9940                 printf("error: Cannot parse flexbytes input.\n");
9941                 return;
9942         }
9943
9944         switch (entry.input.flow_type) {
9945         case RTE_ETH_FLOW_FRAG_IPV4:
9946         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9947                 entry.input.flow.ip4_flow.proto = res->proto_value;
9948                 /* fall-through */
9949         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9950         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9951                 IPV4_ADDR_TO_UINT(res->ip_dst,
9952                         entry.input.flow.ip4_flow.dst_ip);
9953                 IPV4_ADDR_TO_UINT(res->ip_src,
9954                         entry.input.flow.ip4_flow.src_ip);
9955                 entry.input.flow.ip4_flow.tos = res->tos_value;
9956                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9957                 /* need convert to big endian. */
9958                 entry.input.flow.udp4_flow.dst_port =
9959                                 rte_cpu_to_be_16(res->port_dst);
9960                 entry.input.flow.udp4_flow.src_port =
9961                                 rte_cpu_to_be_16(res->port_src);
9962                 break;
9963         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9964                 IPV4_ADDR_TO_UINT(res->ip_dst,
9965                         entry.input.flow.sctp4_flow.ip.dst_ip);
9966                 IPV4_ADDR_TO_UINT(res->ip_src,
9967                         entry.input.flow.sctp4_flow.ip.src_ip);
9968                 entry.input.flow.ip4_flow.tos = res->tos_value;
9969                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9970                 /* need convert to big endian. */
9971                 entry.input.flow.sctp4_flow.dst_port =
9972                                 rte_cpu_to_be_16(res->port_dst);
9973                 entry.input.flow.sctp4_flow.src_port =
9974                                 rte_cpu_to_be_16(res->port_src);
9975                 entry.input.flow.sctp4_flow.verify_tag =
9976                                 rte_cpu_to_be_32(res->verify_tag_value);
9977                 break;
9978         case RTE_ETH_FLOW_FRAG_IPV6:
9979         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9980                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9981                 /* fall-through */
9982         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9983         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9984                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9985                         entry.input.flow.ipv6_flow.dst_ip);
9986                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9987                         entry.input.flow.ipv6_flow.src_ip);
9988                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9989                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9990                 /* need convert to big endian. */
9991                 entry.input.flow.udp6_flow.dst_port =
9992                                 rte_cpu_to_be_16(res->port_dst);
9993                 entry.input.flow.udp6_flow.src_port =
9994                                 rte_cpu_to_be_16(res->port_src);
9995                 break;
9996         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9997                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9998                         entry.input.flow.sctp6_flow.ip.dst_ip);
9999                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10000                         entry.input.flow.sctp6_flow.ip.src_ip);
10001                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10002                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10003                 /* need convert to big endian. */
10004                 entry.input.flow.sctp6_flow.dst_port =
10005                                 rte_cpu_to_be_16(res->port_dst);
10006                 entry.input.flow.sctp6_flow.src_port =
10007                                 rte_cpu_to_be_16(res->port_src);
10008                 entry.input.flow.sctp6_flow.verify_tag =
10009                                 rte_cpu_to_be_32(res->verify_tag_value);
10010                 break;
10011         case RTE_ETH_FLOW_L2_PAYLOAD:
10012                 entry.input.flow.l2_flow.ether_type =
10013                         rte_cpu_to_be_16(res->ether_type);
10014                 break;
10015         default:
10016                 break;
10017         }
10018
10019         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10020                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10021                                  &res->mac_addr,
10022                                  sizeof(struct ether_addr));
10023
10024         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10025                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10026                                  &res->mac_addr,
10027                                  sizeof(struct ether_addr));
10028                 entry.input.flow.tunnel_flow.tunnel_type =
10029                         str2fdir_tunneltype(res->tunnel_type);
10030                 entry.input.flow.tunnel_flow.tunnel_id =
10031                         rte_cpu_to_be_32(res->tunnel_id_value);
10032         }
10033
10034         rte_memcpy(entry.input.flow_ext.flexbytes,
10035                    flexbytes,
10036                    RTE_ETH_FDIR_MAX_FLEXLEN);
10037
10038         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10039
10040         entry.action.flex_off = 0;  /*use 0 by default */
10041         if (!strcmp(res->drop, "drop"))
10042                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10043         else
10044                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10045
10046         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10047             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10048                 if (!strcmp(res->pf_vf, "pf"))
10049                         entry.input.flow_ext.is_vf = 0;
10050                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10051                         struct rte_eth_dev_info dev_info;
10052
10053                         memset(&dev_info, 0, sizeof(dev_info));
10054                         rte_eth_dev_info_get(res->port_id, &dev_info);
10055                         errno = 0;
10056                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10057                         if (errno != 0 || *end != '\0' ||
10058                             vf_id >= dev_info.max_vfs) {
10059                                 printf("invalid parameter %s.\n", res->pf_vf);
10060                                 return;
10061                         }
10062                         entry.input.flow_ext.is_vf = 1;
10063                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10064                 } else {
10065                         printf("invalid parameter %s.\n", res->pf_vf);
10066                         return;
10067                 }
10068         }
10069
10070         /* set to report FD ID by default */
10071         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10072         entry.action.rx_queue = res->queue_id;
10073         entry.soft_id = res->fd_id_value;
10074         if (!strcmp(res->ops, "add"))
10075                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10076                                              RTE_ETH_FILTER_ADD, &entry);
10077         else if (!strcmp(res->ops, "del"))
10078                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10079                                              RTE_ETH_FILTER_DELETE, &entry);
10080         else
10081                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10082                                              RTE_ETH_FILTER_UPDATE, &entry);
10083         if (ret < 0)
10084                 printf("flow director programming error: (%s)\n",
10085                         strerror(-ret));
10086 }
10087
10088 cmdline_parse_token_string_t cmd_flow_director_filter =
10089         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10090                                  flow_director_filter, "flow_director_filter");
10091 cmdline_parse_token_num_t cmd_flow_director_port_id =
10092         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10093                               port_id, UINT16);
10094 cmdline_parse_token_string_t cmd_flow_director_ops =
10095         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10096                                  ops, "add#del#update");
10097 cmdline_parse_token_string_t cmd_flow_director_flow =
10098         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10099                                  flow, "flow");
10100 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10101         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10102                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10103                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10104 cmdline_parse_token_string_t cmd_flow_director_ether =
10105         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10106                                  ether, "ether");
10107 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10108         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10109                               ether_type, UINT16);
10110 cmdline_parse_token_string_t cmd_flow_director_src =
10111         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10112                                  src, "src");
10113 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10114         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10115                                  ip_src);
10116 cmdline_parse_token_num_t cmd_flow_director_port_src =
10117         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10118                               port_src, UINT16);
10119 cmdline_parse_token_string_t cmd_flow_director_dst =
10120         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10121                                  dst, "dst");
10122 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10123         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10124                                  ip_dst);
10125 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10126         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10127                               port_dst, UINT16);
10128 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10129         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10130                                   verify_tag, "verify_tag");
10131 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10132         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10133                               verify_tag_value, UINT32);
10134 cmdline_parse_token_string_t cmd_flow_director_tos =
10135         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10136                                  tos, "tos");
10137 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10138         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10139                               tos_value, UINT8);
10140 cmdline_parse_token_string_t cmd_flow_director_proto =
10141         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10142                                  proto, "proto");
10143 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10144         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10145                               proto_value, UINT8);
10146 cmdline_parse_token_string_t cmd_flow_director_ttl =
10147         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10148                                  ttl, "ttl");
10149 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10150         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10151                               ttl_value, UINT8);
10152 cmdline_parse_token_string_t cmd_flow_director_vlan =
10153         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10154                                  vlan, "vlan");
10155 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10156         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10157                               vlan_value, UINT16);
10158 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10159         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10160                                  flexbytes, "flexbytes");
10161 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10162         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10163                               flexbytes_value, NULL);
10164 cmdline_parse_token_string_t cmd_flow_director_drop =
10165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10166                                  drop, "drop#fwd");
10167 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10168         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10169                               pf_vf, NULL);
10170 cmdline_parse_token_string_t cmd_flow_director_queue =
10171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10172                                  queue, "queue");
10173 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10174         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10175                               queue_id, UINT16);
10176 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10178                                  fd_id, "fd_id");
10179 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10180         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10181                               fd_id_value, UINT32);
10182
10183 cmdline_parse_token_string_t cmd_flow_director_mode =
10184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10185                                  mode, "mode");
10186 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10187         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10188                                  mode_value, "IP");
10189 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10191                                  mode_value, "MAC-VLAN");
10192 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10194                                  mode_value, "Tunnel");
10195 cmdline_parse_token_string_t cmd_flow_director_mac =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10197                                  mac, "mac");
10198 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10199         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10200                                     mac_addr);
10201 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10203                                  tunnel, "tunnel");
10204 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10205         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10206                                  tunnel_type, "NVGRE#VxLAN");
10207 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10209                                  tunnel_id, "tunnel-id");
10210 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10211         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10212                               tunnel_id_value, UINT32);
10213
10214 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10215         .f = cmd_flow_director_filter_parsed,
10216         .data = NULL,
10217         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10218                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10219                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10220                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10221                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10222                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10223                 "fd_id <fd_id_value>: "
10224                 "Add or delete an ip flow director entry on NIC",
10225         .tokens = {
10226                 (void *)&cmd_flow_director_filter,
10227                 (void *)&cmd_flow_director_port_id,
10228                 (void *)&cmd_flow_director_mode,
10229                 (void *)&cmd_flow_director_mode_ip,
10230                 (void *)&cmd_flow_director_ops,
10231                 (void *)&cmd_flow_director_flow,
10232                 (void *)&cmd_flow_director_flow_type,
10233                 (void *)&cmd_flow_director_src,
10234                 (void *)&cmd_flow_director_ip_src,
10235                 (void *)&cmd_flow_director_dst,
10236                 (void *)&cmd_flow_director_ip_dst,
10237                 (void *)&cmd_flow_director_tos,
10238                 (void *)&cmd_flow_director_tos_value,
10239                 (void *)&cmd_flow_director_proto,
10240                 (void *)&cmd_flow_director_proto_value,
10241                 (void *)&cmd_flow_director_ttl,
10242                 (void *)&cmd_flow_director_ttl_value,
10243                 (void *)&cmd_flow_director_vlan,
10244                 (void *)&cmd_flow_director_vlan_value,
10245                 (void *)&cmd_flow_director_flexbytes,
10246                 (void *)&cmd_flow_director_flexbytes_value,
10247                 (void *)&cmd_flow_director_drop,
10248                 (void *)&cmd_flow_director_pf_vf,
10249                 (void *)&cmd_flow_director_queue,
10250                 (void *)&cmd_flow_director_queue_id,
10251                 (void *)&cmd_flow_director_fd_id,
10252                 (void *)&cmd_flow_director_fd_id_value,
10253                 NULL,
10254         },
10255 };
10256
10257 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10258         .f = cmd_flow_director_filter_parsed,
10259         .data = NULL,
10260         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10261                 "director entry on NIC",
10262         .tokens = {
10263                 (void *)&cmd_flow_director_filter,
10264                 (void *)&cmd_flow_director_port_id,
10265                 (void *)&cmd_flow_director_mode,
10266                 (void *)&cmd_flow_director_mode_ip,
10267                 (void *)&cmd_flow_director_ops,
10268                 (void *)&cmd_flow_director_flow,
10269                 (void *)&cmd_flow_director_flow_type,
10270                 (void *)&cmd_flow_director_src,
10271                 (void *)&cmd_flow_director_ip_src,
10272                 (void *)&cmd_flow_director_port_src,
10273                 (void *)&cmd_flow_director_dst,
10274                 (void *)&cmd_flow_director_ip_dst,
10275                 (void *)&cmd_flow_director_port_dst,
10276                 (void *)&cmd_flow_director_tos,
10277                 (void *)&cmd_flow_director_tos_value,
10278                 (void *)&cmd_flow_director_ttl,
10279                 (void *)&cmd_flow_director_ttl_value,
10280                 (void *)&cmd_flow_director_vlan,
10281                 (void *)&cmd_flow_director_vlan_value,
10282                 (void *)&cmd_flow_director_flexbytes,
10283                 (void *)&cmd_flow_director_flexbytes_value,
10284                 (void *)&cmd_flow_director_drop,
10285                 (void *)&cmd_flow_director_pf_vf,
10286                 (void *)&cmd_flow_director_queue,
10287                 (void *)&cmd_flow_director_queue_id,
10288                 (void *)&cmd_flow_director_fd_id,
10289                 (void *)&cmd_flow_director_fd_id_value,
10290                 NULL,
10291         },
10292 };
10293
10294 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10295         .f = cmd_flow_director_filter_parsed,
10296         .data = NULL,
10297         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10298                 "director entry on NIC",
10299         .tokens = {
10300                 (void *)&cmd_flow_director_filter,
10301                 (void *)&cmd_flow_director_port_id,
10302                 (void *)&cmd_flow_director_mode,
10303                 (void *)&cmd_flow_director_mode_ip,
10304                 (void *)&cmd_flow_director_ops,
10305                 (void *)&cmd_flow_director_flow,
10306                 (void *)&cmd_flow_director_flow_type,
10307                 (void *)&cmd_flow_director_src,
10308                 (void *)&cmd_flow_director_ip_src,
10309                 (void *)&cmd_flow_director_port_dst,
10310                 (void *)&cmd_flow_director_dst,
10311                 (void *)&cmd_flow_director_ip_dst,
10312                 (void *)&cmd_flow_director_port_dst,
10313                 (void *)&cmd_flow_director_verify_tag,
10314                 (void *)&cmd_flow_director_verify_tag_value,
10315                 (void *)&cmd_flow_director_tos,
10316                 (void *)&cmd_flow_director_tos_value,
10317                 (void *)&cmd_flow_director_ttl,
10318                 (void *)&cmd_flow_director_ttl_value,
10319                 (void *)&cmd_flow_director_vlan,
10320                 (void *)&cmd_flow_director_vlan_value,
10321                 (void *)&cmd_flow_director_flexbytes,
10322                 (void *)&cmd_flow_director_flexbytes_value,
10323                 (void *)&cmd_flow_director_drop,
10324                 (void *)&cmd_flow_director_pf_vf,
10325                 (void *)&cmd_flow_director_queue,
10326                 (void *)&cmd_flow_director_queue_id,
10327                 (void *)&cmd_flow_director_fd_id,
10328                 (void *)&cmd_flow_director_fd_id_value,
10329                 NULL,
10330         },
10331 };
10332
10333 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10334         .f = cmd_flow_director_filter_parsed,
10335         .data = NULL,
10336         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10337                 "director entry on NIC",
10338         .tokens = {
10339                 (void *)&cmd_flow_director_filter,
10340                 (void *)&cmd_flow_director_port_id,
10341                 (void *)&cmd_flow_director_mode,
10342                 (void *)&cmd_flow_director_mode_ip,
10343                 (void *)&cmd_flow_director_ops,
10344                 (void *)&cmd_flow_director_flow,
10345                 (void *)&cmd_flow_director_flow_type,
10346                 (void *)&cmd_flow_director_ether,
10347                 (void *)&cmd_flow_director_ether_type,
10348                 (void *)&cmd_flow_director_flexbytes,
10349                 (void *)&cmd_flow_director_flexbytes_value,
10350                 (void *)&cmd_flow_director_drop,
10351                 (void *)&cmd_flow_director_pf_vf,
10352                 (void *)&cmd_flow_director_queue,
10353                 (void *)&cmd_flow_director_queue_id,
10354                 (void *)&cmd_flow_director_fd_id,
10355                 (void *)&cmd_flow_director_fd_id_value,
10356                 NULL,
10357         },
10358 };
10359
10360 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10361         .f = cmd_flow_director_filter_parsed,
10362         .data = NULL,
10363         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10364                 "director entry on NIC",
10365         .tokens = {
10366                 (void *)&cmd_flow_director_filter,
10367                 (void *)&cmd_flow_director_port_id,
10368                 (void *)&cmd_flow_director_mode,
10369                 (void *)&cmd_flow_director_mode_mac_vlan,
10370                 (void *)&cmd_flow_director_ops,
10371                 (void *)&cmd_flow_director_mac,
10372                 (void *)&cmd_flow_director_mac_addr,
10373                 (void *)&cmd_flow_director_vlan,
10374                 (void *)&cmd_flow_director_vlan_value,
10375                 (void *)&cmd_flow_director_flexbytes,
10376                 (void *)&cmd_flow_director_flexbytes_value,
10377                 (void *)&cmd_flow_director_drop,
10378                 (void *)&cmd_flow_director_queue,
10379                 (void *)&cmd_flow_director_queue_id,
10380                 (void *)&cmd_flow_director_fd_id,
10381                 (void *)&cmd_flow_director_fd_id_value,
10382                 NULL,
10383         },
10384 };
10385
10386 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10387         .f = cmd_flow_director_filter_parsed,
10388         .data = NULL,
10389         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10390                 "director entry on NIC",
10391         .tokens = {
10392                 (void *)&cmd_flow_director_filter,
10393                 (void *)&cmd_flow_director_port_id,
10394                 (void *)&cmd_flow_director_mode,
10395                 (void *)&cmd_flow_director_mode_tunnel,
10396                 (void *)&cmd_flow_director_ops,
10397                 (void *)&cmd_flow_director_mac,
10398                 (void *)&cmd_flow_director_mac_addr,
10399                 (void *)&cmd_flow_director_vlan,
10400                 (void *)&cmd_flow_director_vlan_value,
10401                 (void *)&cmd_flow_director_tunnel,
10402                 (void *)&cmd_flow_director_tunnel_type,
10403                 (void *)&cmd_flow_director_tunnel_id,
10404                 (void *)&cmd_flow_director_tunnel_id_value,
10405                 (void *)&cmd_flow_director_flexbytes,
10406                 (void *)&cmd_flow_director_flexbytes_value,
10407                 (void *)&cmd_flow_director_drop,
10408                 (void *)&cmd_flow_director_queue,
10409                 (void *)&cmd_flow_director_queue_id,
10410                 (void *)&cmd_flow_director_fd_id,
10411                 (void *)&cmd_flow_director_fd_id_value,
10412                 NULL,
10413         },
10414 };
10415
10416 struct cmd_flush_flow_director_result {
10417         cmdline_fixed_string_t flush_flow_director;
10418         portid_t port_id;
10419 };
10420
10421 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10422         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10423                                  flush_flow_director, "flush_flow_director");
10424 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10425         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10426                               port_id, UINT16);
10427
10428 static void
10429 cmd_flush_flow_director_parsed(void *parsed_result,
10430                           __attribute__((unused)) struct cmdline *cl,
10431                           __attribute__((unused)) void *data)
10432 {
10433         struct cmd_flow_director_result *res = parsed_result;
10434         int ret = 0;
10435
10436         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10437         if (ret < 0) {
10438                 printf("flow director is not supported on port %u.\n",
10439                         res->port_id);
10440                 return;
10441         }
10442
10443         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10444                         RTE_ETH_FILTER_FLUSH, NULL);
10445         if (ret < 0)
10446                 printf("flow director table flushing error: (%s)\n",
10447                         strerror(-ret));
10448 }
10449
10450 cmdline_parse_inst_t cmd_flush_flow_director = {
10451         .f = cmd_flush_flow_director_parsed,
10452         .data = NULL,
10453         .help_str = "flush_flow_director <port_id>: "
10454                 "Flush all flow director entries of a device on NIC",
10455         .tokens = {
10456                 (void *)&cmd_flush_flow_director_flush,
10457                 (void *)&cmd_flush_flow_director_port_id,
10458                 NULL,
10459         },
10460 };
10461
10462 /* *** deal with flow director mask *** */
10463 struct cmd_flow_director_mask_result {
10464         cmdline_fixed_string_t flow_director_mask;
10465         portid_t port_id;
10466         cmdline_fixed_string_t mode;
10467         cmdline_fixed_string_t mode_value;
10468         cmdline_fixed_string_t vlan;
10469         uint16_t vlan_mask;
10470         cmdline_fixed_string_t src_mask;
10471         cmdline_ipaddr_t ipv4_src;
10472         cmdline_ipaddr_t ipv6_src;
10473         uint16_t port_src;
10474         cmdline_fixed_string_t dst_mask;
10475         cmdline_ipaddr_t ipv4_dst;
10476         cmdline_ipaddr_t ipv6_dst;
10477         uint16_t port_dst;
10478         cmdline_fixed_string_t mac;
10479         uint8_t mac_addr_byte_mask;
10480         cmdline_fixed_string_t tunnel_id;
10481         uint32_t tunnel_id_mask;
10482         cmdline_fixed_string_t tunnel_type;
10483         uint8_t tunnel_type_mask;
10484 };
10485
10486 static void
10487 cmd_flow_director_mask_parsed(void *parsed_result,
10488                           __attribute__((unused)) struct cmdline *cl,
10489                           __attribute__((unused)) void *data)
10490 {
10491         struct cmd_flow_director_mask_result *res = parsed_result;
10492         struct rte_eth_fdir_masks *mask;
10493         struct rte_port *port;
10494
10495         if (res->port_id > nb_ports) {
10496                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10497                 return;
10498         }
10499
10500         port = &ports[res->port_id];
10501         /** Check if the port is not started **/
10502         if (port->port_status != RTE_PORT_STOPPED) {
10503                 printf("Please stop port %d first\n", res->port_id);
10504                 return;
10505         }
10506
10507         mask = &port->dev_conf.fdir_conf.mask;
10508
10509         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10510                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10511                         printf("Please set mode to MAC-VLAN.\n");
10512                         return;
10513                 }
10514
10515                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10516         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10517                 if (strcmp(res->mode_value, "Tunnel")) {
10518                         printf("Please set mode to Tunnel.\n");
10519                         return;
10520                 }
10521
10522                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10523                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10524                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10525                 mask->tunnel_type_mask = res->tunnel_type_mask;
10526         } else {
10527                 if (strcmp(res->mode_value, "IP")) {
10528                         printf("Please set mode to IP.\n");
10529                         return;
10530                 }
10531
10532                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10533                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10534                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10535                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10536                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10537                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10538                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10539         }
10540
10541         cmd_reconfig_device_queue(res->port_id, 1, 1);
10542 }
10543
10544 cmdline_parse_token_string_t cmd_flow_director_mask =
10545         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10546                                  flow_director_mask, "flow_director_mask");
10547 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10548         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10549                               port_id, UINT16);
10550 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10551         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10552                                  vlan, "vlan");
10553 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10554         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10555                               vlan_mask, UINT16);
10556 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10557         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10558                                  src_mask, "src_mask");
10559 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10560         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10561                                  ipv4_src);
10562 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10563         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10564                                  ipv6_src);
10565 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10566         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10567                               port_src, UINT16);
10568 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10570                                  dst_mask, "dst_mask");
10571 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10572         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10573                                  ipv4_dst);
10574 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10575         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10576                                  ipv6_dst);
10577 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10578         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10579                               port_dst, UINT16);
10580
10581 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10582         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10583                                  mode, "mode");
10584 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10585         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10586                                  mode_value, "IP");
10587 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10588         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10589                                  mode_value, "MAC-VLAN");
10590 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10591         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10592                                  mode_value, "Tunnel");
10593 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10594         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10595                                  mac, "mac");
10596 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10597         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10598                               mac_addr_byte_mask, UINT8);
10599 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10600         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10601                                  tunnel_type, "tunnel-type");
10602 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10603         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10604                               tunnel_type_mask, UINT8);
10605 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10607                                  tunnel_id, "tunnel-id");
10608 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10609         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10610                               tunnel_id_mask, UINT32);
10611
10612 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10613         .f = cmd_flow_director_mask_parsed,
10614         .data = NULL,
10615         .help_str = "flow_director_mask ... : "
10616                 "Set IP mode flow director's mask on NIC",
10617         .tokens = {
10618                 (void *)&cmd_flow_director_mask,
10619                 (void *)&cmd_flow_director_mask_port_id,
10620                 (void *)&cmd_flow_director_mask_mode,
10621                 (void *)&cmd_flow_director_mask_mode_ip,
10622                 (void *)&cmd_flow_director_mask_vlan,
10623                 (void *)&cmd_flow_director_mask_vlan_value,
10624                 (void *)&cmd_flow_director_mask_src,
10625                 (void *)&cmd_flow_director_mask_ipv4_src,
10626                 (void *)&cmd_flow_director_mask_ipv6_src,
10627                 (void *)&cmd_flow_director_mask_port_src,
10628                 (void *)&cmd_flow_director_mask_dst,
10629                 (void *)&cmd_flow_director_mask_ipv4_dst,
10630                 (void *)&cmd_flow_director_mask_ipv6_dst,
10631                 (void *)&cmd_flow_director_mask_port_dst,
10632                 NULL,
10633         },
10634 };
10635
10636 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10637         .f = cmd_flow_director_mask_parsed,
10638         .data = NULL,
10639         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10640                 "flow director's mask on NIC",
10641         .tokens = {
10642                 (void *)&cmd_flow_director_mask,
10643                 (void *)&cmd_flow_director_mask_port_id,
10644                 (void *)&cmd_flow_director_mask_mode,
10645                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10646                 (void *)&cmd_flow_director_mask_vlan,
10647                 (void *)&cmd_flow_director_mask_vlan_value,
10648                 NULL,
10649         },
10650 };
10651
10652 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10653         .f = cmd_flow_director_mask_parsed,
10654         .data = NULL,
10655         .help_str = "flow_director_mask ... : Set tunnel mode "
10656                 "flow director's mask on NIC",
10657         .tokens = {
10658                 (void *)&cmd_flow_director_mask,
10659                 (void *)&cmd_flow_director_mask_port_id,
10660                 (void *)&cmd_flow_director_mask_mode,
10661                 (void *)&cmd_flow_director_mask_mode_tunnel,
10662                 (void *)&cmd_flow_director_mask_vlan,
10663                 (void *)&cmd_flow_director_mask_vlan_value,
10664                 (void *)&cmd_flow_director_mask_mac,
10665                 (void *)&cmd_flow_director_mask_mac_value,
10666                 (void *)&cmd_flow_director_mask_tunnel_type,
10667                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10668                 (void *)&cmd_flow_director_mask_tunnel_id,
10669                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10670                 NULL,
10671         },
10672 };
10673
10674 /* *** deal with flow director mask on flexible payload *** */
10675 struct cmd_flow_director_flex_mask_result {
10676         cmdline_fixed_string_t flow_director_flexmask;
10677         portid_t port_id;
10678         cmdline_fixed_string_t flow;
10679         cmdline_fixed_string_t flow_type;
10680         cmdline_fixed_string_t mask;
10681 };
10682
10683 static void
10684 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10685                           __attribute__((unused)) struct cmdline *cl,
10686                           __attribute__((unused)) void *data)
10687 {
10688         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10689         struct rte_eth_fdir_info fdir_info;
10690         struct rte_eth_fdir_flex_mask flex_mask;
10691         struct rte_port *port;
10692         uint32_t flow_type_mask;
10693         uint16_t i;
10694         int ret;
10695
10696         if (res->port_id > nb_ports) {
10697                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10698                 return;
10699         }
10700
10701         port = &ports[res->port_id];
10702         /** Check if the port is not started **/
10703         if (port->port_status != RTE_PORT_STOPPED) {
10704                 printf("Please stop port %d first\n", res->port_id);
10705                 return;
10706         }
10707
10708         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10709         ret = parse_flexbytes(res->mask,
10710                         flex_mask.mask,
10711                         RTE_ETH_FDIR_MAX_FLEXLEN);
10712         if (ret < 0) {
10713                 printf("error: Cannot parse mask input.\n");
10714                 return;
10715         }
10716
10717         memset(&fdir_info, 0, sizeof(fdir_info));
10718         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10719                                 RTE_ETH_FILTER_INFO, &fdir_info);
10720         if (ret < 0) {
10721                 printf("Cannot get FDir filter info\n");
10722                 return;
10723         }
10724
10725         if (!strcmp(res->flow_type, "none")) {
10726                 /* means don't specify the flow type */
10727                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10728                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10729                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10730                                0, sizeof(struct rte_eth_fdir_flex_mask));
10731                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10732                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10733                                  &flex_mask,
10734                                  sizeof(struct rte_eth_fdir_flex_mask));
10735                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10736                 return;
10737         }
10738         flow_type_mask = fdir_info.flow_types_mask[0];
10739         if (!strcmp(res->flow_type, "all")) {
10740                 if (!flow_type_mask) {
10741                         printf("No flow type supported\n");
10742                         return;
10743                 }
10744                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10745                         if (flow_type_mask & (1 << i)) {
10746                                 flex_mask.flow_type = i;
10747                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10748                         }
10749                 }
10750                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10751                 return;
10752         }
10753         flex_mask.flow_type = str2flowtype(res->flow_type);
10754         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10755                 printf("Flow type %s not supported on port %d\n",
10756                                 res->flow_type, res->port_id);
10757                 return;
10758         }
10759         fdir_set_flex_mask(res->port_id, &flex_mask);
10760         cmd_reconfig_device_queue(res->port_id, 1, 1);
10761 }
10762
10763 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10764         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10765                                  flow_director_flexmask,
10766                                  "flow_director_flex_mask");
10767 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10768         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10769                               port_id, UINT16);
10770 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10771         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10772                                  flow, "flow");
10773 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10775                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10776                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10777 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10779                                  mask, NULL);
10780
10781 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10782         .f = cmd_flow_director_flex_mask_parsed,
10783         .data = NULL,
10784         .help_str = "flow_director_flex_mask ... : "
10785                 "Set flow director's flex mask on NIC",
10786         .tokens = {
10787                 (void *)&cmd_flow_director_flexmask,
10788                 (void *)&cmd_flow_director_flexmask_port_id,
10789                 (void *)&cmd_flow_director_flexmask_flow,
10790                 (void *)&cmd_flow_director_flexmask_flow_type,
10791                 (void *)&cmd_flow_director_flexmask_mask,
10792                 NULL,
10793         },
10794 };
10795
10796 /* *** deal with flow director flexible payload configuration *** */
10797 struct cmd_flow_director_flexpayload_result {
10798         cmdline_fixed_string_t flow_director_flexpayload;
10799         portid_t port_id;
10800         cmdline_fixed_string_t payload_layer;
10801         cmdline_fixed_string_t payload_cfg;
10802 };
10803
10804 static inline int
10805 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10806 {
10807         char s[256];
10808         const char *p, *p0 = q_arg;
10809         char *end;
10810         unsigned long int_fld;
10811         char *str_fld[max_num];
10812         int i;
10813         unsigned size;
10814         int ret = -1;
10815
10816         p = strchr(p0, '(');
10817         if (p == NULL)
10818                 return -1;
10819         ++p;
10820         p0 = strchr(p, ')');
10821         if (p0 == NULL)
10822                 return -1;
10823
10824         size = p0 - p;
10825         if (size >= sizeof(s))
10826                 return -1;
10827
10828         snprintf(s, sizeof(s), "%.*s", size, p);
10829         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10830         if (ret < 0 || ret > max_num)
10831                 return -1;
10832         for (i = 0; i < ret; i++) {
10833                 errno = 0;
10834                 int_fld = strtoul(str_fld[i], &end, 0);
10835                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10836                         return -1;
10837                 offsets[i] = (uint16_t)int_fld;
10838         }
10839         return ret;
10840 }
10841
10842 static void
10843 cmd_flow_director_flxpld_parsed(void *parsed_result,
10844                           __attribute__((unused)) struct cmdline *cl,
10845                           __attribute__((unused)) void *data)
10846 {
10847         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10848         struct rte_eth_flex_payload_cfg flex_cfg;
10849         struct rte_port *port;
10850         int ret = 0;
10851
10852         if (res->port_id > nb_ports) {
10853                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10854                 return;
10855         }
10856
10857         port = &ports[res->port_id];
10858         /** Check if the port is not started **/
10859         if (port->port_status != RTE_PORT_STOPPED) {
10860                 printf("Please stop port %d first\n", res->port_id);
10861                 return;
10862         }
10863
10864         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10865
10866         if (!strcmp(res->payload_layer, "raw"))
10867                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10868         else if (!strcmp(res->payload_layer, "l2"))
10869                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10870         else if (!strcmp(res->payload_layer, "l3"))
10871                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10872         else if (!strcmp(res->payload_layer, "l4"))
10873                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10874
10875         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10876                             RTE_ETH_FDIR_MAX_FLEXLEN);
10877         if (ret < 0) {
10878                 printf("error: Cannot parse flex payload input.\n");
10879                 return;
10880         }
10881
10882         fdir_set_flex_payload(res->port_id, &flex_cfg);
10883         cmd_reconfig_device_queue(res->port_id, 1, 1);
10884 }
10885
10886 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10888                                  flow_director_flexpayload,
10889                                  "flow_director_flex_payload");
10890 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10891         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10892                               port_id, UINT16);
10893 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10894         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10895                                  payload_layer, "raw#l2#l3#l4");
10896 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10897         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10898                                  payload_cfg, NULL);
10899
10900 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10901         .f = cmd_flow_director_flxpld_parsed,
10902         .data = NULL,
10903         .help_str = "flow_director_flexpayload ... : "
10904                 "Set flow director's flex payload on NIC",
10905         .tokens = {
10906                 (void *)&cmd_flow_director_flexpayload,
10907                 (void *)&cmd_flow_director_flexpayload_port_id,
10908                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10909                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10910                 NULL,
10911         },
10912 };
10913
10914 /* Generic flow interface command. */
10915 extern cmdline_parse_inst_t cmd_flow;
10916
10917 /* *** Classification Filters Control *** */
10918 /* *** Get symmetric hash enable per port *** */
10919 struct cmd_get_sym_hash_ena_per_port_result {
10920         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10921         portid_t port_id;
10922 };
10923
10924 static void
10925 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10926                                  __rte_unused struct cmdline *cl,
10927                                  __rte_unused void *data)
10928 {
10929         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10930         struct rte_eth_hash_filter_info info;
10931         int ret;
10932
10933         if (rte_eth_dev_filter_supported(res->port_id,
10934                                 RTE_ETH_FILTER_HASH) < 0) {
10935                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10936                                                         res->port_id);
10937                 return;
10938         }
10939
10940         memset(&info, 0, sizeof(info));
10941         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10942         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10943                                                 RTE_ETH_FILTER_GET, &info);
10944
10945         if (ret < 0) {
10946                 printf("Cannot get symmetric hash enable per port "
10947                                         "on port %u\n", res->port_id);
10948                 return;
10949         }
10950
10951         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10952                                 "enabled" : "disabled", res->port_id);
10953 }
10954
10955 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10956         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10957                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10958 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10959         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10960                 port_id, UINT16);
10961
10962 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10963         .f = cmd_get_sym_hash_per_port_parsed,
10964         .data = NULL,
10965         .help_str = "get_sym_hash_ena_per_port <port_id>",
10966         .tokens = {
10967                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10968                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10969                 NULL,
10970         },
10971 };
10972
10973 /* *** Set symmetric hash enable per port *** */
10974 struct cmd_set_sym_hash_ena_per_port_result {
10975         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10976         cmdline_fixed_string_t enable;
10977         portid_t port_id;
10978 };
10979
10980 static void
10981 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10982                                  __rte_unused struct cmdline *cl,
10983                                  __rte_unused void *data)
10984 {
10985         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10986         struct rte_eth_hash_filter_info info;
10987         int ret;
10988
10989         if (rte_eth_dev_filter_supported(res->port_id,
10990                                 RTE_ETH_FILTER_HASH) < 0) {
10991                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10992                                                         res->port_id);
10993                 return;
10994         }
10995
10996         memset(&info, 0, sizeof(info));
10997         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10998         if (!strcmp(res->enable, "enable"))
10999                 info.info.enable = 1;
11000         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11001                                         RTE_ETH_FILTER_SET, &info);
11002         if (ret < 0) {
11003                 printf("Cannot set symmetric hash enable per port on "
11004                                         "port %u\n", res->port_id);
11005                 return;
11006         }
11007         printf("Symmetric hash has been set to %s on port %u\n",
11008                                         res->enable, res->port_id);
11009 }
11010
11011 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11012         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11013                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11014 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11015         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11016                 port_id, UINT16);
11017 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11018         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11019                 enable, "enable#disable");
11020
11021 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11022         .f = cmd_set_sym_hash_per_port_parsed,
11023         .data = NULL,
11024         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11025         .tokens = {
11026                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11027                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11028                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11029                 NULL,
11030         },
11031 };
11032
11033 /* Get global config of hash function */
11034 struct cmd_get_hash_global_config_result {
11035         cmdline_fixed_string_t get_hash_global_config;
11036         portid_t port_id;
11037 };
11038
11039 static char *
11040 flowtype_to_str(uint16_t ftype)
11041 {
11042         uint16_t i;
11043         static struct {
11044                 char str[16];
11045                 uint16_t ftype;
11046         } ftype_table[] = {
11047                 {"ipv4", RTE_ETH_FLOW_IPV4},
11048                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11049                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11050                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11051                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11052                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11053                 {"ipv6", RTE_ETH_FLOW_IPV6},
11054                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11055                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11056                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11057                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11058                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11059                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11060                 {"port", RTE_ETH_FLOW_PORT},
11061                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11062                 {"geneve", RTE_ETH_FLOW_GENEVE},
11063                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11064         };
11065
11066         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11067                 if (ftype_table[i].ftype == ftype)
11068                         return ftype_table[i].str;
11069         }
11070
11071         return NULL;
11072 }
11073
11074 static void
11075 cmd_get_hash_global_config_parsed(void *parsed_result,
11076                                   __rte_unused struct cmdline *cl,
11077                                   __rte_unused void *data)
11078 {
11079         struct cmd_get_hash_global_config_result *res = parsed_result;
11080         struct rte_eth_hash_filter_info info;
11081         uint32_t idx, offset;
11082         uint16_t i;
11083         char *str;
11084         int ret;
11085
11086         if (rte_eth_dev_filter_supported(res->port_id,
11087                         RTE_ETH_FILTER_HASH) < 0) {
11088                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11089                                                         res->port_id);
11090                 return;
11091         }
11092
11093         memset(&info, 0, sizeof(info));
11094         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11095         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11096                                         RTE_ETH_FILTER_GET, &info);
11097         if (ret < 0) {
11098                 printf("Cannot get hash global configurations by port %d\n",
11099                                                         res->port_id);
11100                 return;
11101         }
11102
11103         switch (info.info.global_conf.hash_func) {
11104         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11105                 printf("Hash function is Toeplitz\n");
11106                 break;
11107         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11108                 printf("Hash function is Simple XOR\n");
11109                 break;
11110         default:
11111                 printf("Unknown hash function\n");
11112                 break;
11113         }
11114
11115         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11116                 idx = i / UINT32_BIT;
11117                 offset = i % UINT32_BIT;
11118                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11119                                                 (1UL << offset)))
11120                         continue;
11121                 str = flowtype_to_str(i);
11122                 if (!str)
11123                         continue;
11124                 printf("Symmetric hash is %s globally for flow type %s "
11125                                                         "by port %d\n",
11126                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11127                         (1UL << offset)) ? "enabled" : "disabled"), str,
11128                                                         res->port_id);
11129         }
11130 }
11131
11132 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11133         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11134                 get_hash_global_config, "get_hash_global_config");
11135 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11136         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11137                 port_id, UINT16);
11138
11139 cmdline_parse_inst_t cmd_get_hash_global_config = {
11140         .f = cmd_get_hash_global_config_parsed,
11141         .data = NULL,
11142         .help_str = "get_hash_global_config <port_id>",
11143         .tokens = {
11144                 (void *)&cmd_get_hash_global_config_all,
11145                 (void *)&cmd_get_hash_global_config_port_id,
11146                 NULL,
11147         },
11148 };
11149
11150 /* Set global config of hash function */
11151 struct cmd_set_hash_global_config_result {
11152         cmdline_fixed_string_t set_hash_global_config;
11153         portid_t port_id;
11154         cmdline_fixed_string_t hash_func;
11155         cmdline_fixed_string_t flow_type;
11156         cmdline_fixed_string_t enable;
11157 };
11158
11159 static void
11160 cmd_set_hash_global_config_parsed(void *parsed_result,
11161                                   __rte_unused struct cmdline *cl,
11162                                   __rte_unused void *data)
11163 {
11164         struct cmd_set_hash_global_config_result *res = parsed_result;
11165         struct rte_eth_hash_filter_info info;
11166         uint32_t ftype, idx, offset;
11167         int ret;
11168
11169         if (rte_eth_dev_filter_supported(res->port_id,
11170                                 RTE_ETH_FILTER_HASH) < 0) {
11171                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11172                                                         res->port_id);
11173                 return;
11174         }
11175         memset(&info, 0, sizeof(info));
11176         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11177         if (!strcmp(res->hash_func, "toeplitz"))
11178                 info.info.global_conf.hash_func =
11179                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11180         else if (!strcmp(res->hash_func, "simple_xor"))
11181                 info.info.global_conf.hash_func =
11182                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11183         else if (!strcmp(res->hash_func, "default"))
11184                 info.info.global_conf.hash_func =
11185                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11186
11187         ftype = str2flowtype(res->flow_type);
11188         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11189         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11190         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11191         if (!strcmp(res->enable, "enable"))
11192                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11193                                                 (1UL << offset);
11194         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11195                                         RTE_ETH_FILTER_SET, &info);
11196         if (ret < 0)
11197                 printf("Cannot set global hash configurations by port %d\n",
11198                                                         res->port_id);
11199         else
11200                 printf("Global hash configurations have been set "
11201                         "succcessfully by port %d\n", res->port_id);
11202 }
11203
11204 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11205         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11206                 set_hash_global_config, "set_hash_global_config");
11207 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11208         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11209                 port_id, UINT16);
11210 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11211         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11212                 hash_func, "toeplitz#simple_xor#default");
11213 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11214         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11215                 flow_type,
11216                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11217                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11218 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11219         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11220                 enable, "enable#disable");
11221
11222 cmdline_parse_inst_t cmd_set_hash_global_config = {
11223         .f = cmd_set_hash_global_config_parsed,
11224         .data = NULL,
11225         .help_str = "set_hash_global_config <port_id> "
11226                 "toeplitz|simple_xor|default "
11227                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11228                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11229                 "l2_payload enable|disable",
11230         .tokens = {
11231                 (void *)&cmd_set_hash_global_config_all,
11232                 (void *)&cmd_set_hash_global_config_port_id,
11233                 (void *)&cmd_set_hash_global_config_hash_func,
11234                 (void *)&cmd_set_hash_global_config_flow_type,
11235                 (void *)&cmd_set_hash_global_config_enable,
11236                 NULL,
11237         },
11238 };
11239
11240 /* Set hash input set */
11241 struct cmd_set_hash_input_set_result {
11242         cmdline_fixed_string_t set_hash_input_set;
11243         portid_t port_id;
11244         cmdline_fixed_string_t flow_type;
11245         cmdline_fixed_string_t inset_field;
11246         cmdline_fixed_string_t select;
11247 };
11248
11249 static enum rte_eth_input_set_field
11250 str2inset(char *string)
11251 {
11252         uint16_t i;
11253
11254         static const struct {
11255                 char str[32];
11256                 enum rte_eth_input_set_field inset;
11257         } inset_table[] = {
11258                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11259                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11260                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11261                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11262                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11263                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11264                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11265                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11266                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11267                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11268                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11269                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11270                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11271                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11272                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11273                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11274                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11275                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11276                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11277                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11278                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11279                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11280                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11281                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11282                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11283                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11284                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11285                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11286                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11287                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11288                 {"none", RTE_ETH_INPUT_SET_NONE},
11289         };
11290
11291         for (i = 0; i < RTE_DIM(inset_table); i++) {
11292                 if (!strcmp(string, inset_table[i].str))
11293                         return inset_table[i].inset;
11294         }
11295
11296         return RTE_ETH_INPUT_SET_UNKNOWN;
11297 }
11298
11299 static void
11300 cmd_set_hash_input_set_parsed(void *parsed_result,
11301                               __rte_unused struct cmdline *cl,
11302                               __rte_unused void *data)
11303 {
11304         struct cmd_set_hash_input_set_result *res = parsed_result;
11305         struct rte_eth_hash_filter_info info;
11306
11307         memset(&info, 0, sizeof(info));
11308         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11309         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11310         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11311         info.info.input_set_conf.inset_size = 1;
11312         if (!strcmp(res->select, "select"))
11313                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11314         else if (!strcmp(res->select, "add"))
11315                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11316         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11317                                 RTE_ETH_FILTER_SET, &info);
11318 }
11319
11320 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11321         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11322                 set_hash_input_set, "set_hash_input_set");
11323 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11324         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11325                 port_id, UINT16);
11326 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11327         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11328                 flow_type, NULL);
11329 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11330         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11331                 inset_field,
11332                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11333                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11334                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11335                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11336                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11337                 "fld-8th#none");
11338 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11339         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11340                 select, "select#add");
11341
11342 cmdline_parse_inst_t cmd_set_hash_input_set = {
11343         .f = cmd_set_hash_input_set_parsed,
11344         .data = NULL,
11345         .help_str = "set_hash_input_set <port_id> "
11346         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11347         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11348         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11349         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11350         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11351         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11352         "fld-7th|fld-8th|none select|add",
11353         .tokens = {
11354                 (void *)&cmd_set_hash_input_set_cmd,
11355                 (void *)&cmd_set_hash_input_set_port_id,
11356                 (void *)&cmd_set_hash_input_set_flow_type,
11357                 (void *)&cmd_set_hash_input_set_field,
11358                 (void *)&cmd_set_hash_input_set_select,
11359                 NULL,
11360         },
11361 };
11362
11363 /* Set flow director input set */
11364 struct cmd_set_fdir_input_set_result {
11365         cmdline_fixed_string_t set_fdir_input_set;
11366         portid_t port_id;
11367         cmdline_fixed_string_t flow_type;
11368         cmdline_fixed_string_t inset_field;
11369         cmdline_fixed_string_t select;
11370 };
11371
11372 static void
11373 cmd_set_fdir_input_set_parsed(void *parsed_result,
11374         __rte_unused struct cmdline *cl,
11375         __rte_unused void *data)
11376 {
11377         struct cmd_set_fdir_input_set_result *res = parsed_result;
11378         struct rte_eth_fdir_filter_info info;
11379
11380         memset(&info, 0, sizeof(info));
11381         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11382         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11383         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11384         info.info.input_set_conf.inset_size = 1;
11385         if (!strcmp(res->select, "select"))
11386                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11387         else if (!strcmp(res->select, "add"))
11388                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11389         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11390                 RTE_ETH_FILTER_SET, &info);
11391 }
11392
11393 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11394         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11395         set_fdir_input_set, "set_fdir_input_set");
11396 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11397         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11398         port_id, UINT16);
11399 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11400         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11401         flow_type,
11402         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11403         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11404 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11405         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11406         inset_field,
11407         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11408         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11409         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11410         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11411         "sctp-veri-tag#none");
11412 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11413         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11414         select, "select#add");
11415
11416 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11417         .f = cmd_set_fdir_input_set_parsed,
11418         .data = NULL,
11419         .help_str = "set_fdir_input_set <port_id> "
11420         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11421         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11422         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11423         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11424         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11425         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11426         "sctp-veri-tag|none select|add",
11427         .tokens = {
11428                 (void *)&cmd_set_fdir_input_set_cmd,
11429                 (void *)&cmd_set_fdir_input_set_port_id,
11430                 (void *)&cmd_set_fdir_input_set_flow_type,
11431                 (void *)&cmd_set_fdir_input_set_field,
11432                 (void *)&cmd_set_fdir_input_set_select,
11433                 NULL,
11434         },
11435 };
11436
11437 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11438 struct cmd_mcast_addr_result {
11439         cmdline_fixed_string_t mcast_addr_cmd;
11440         cmdline_fixed_string_t what;
11441         uint16_t port_num;
11442         struct ether_addr mc_addr;
11443 };
11444
11445 static void cmd_mcast_addr_parsed(void *parsed_result,
11446                 __attribute__((unused)) struct cmdline *cl,
11447                 __attribute__((unused)) void *data)
11448 {
11449         struct cmd_mcast_addr_result *res = parsed_result;
11450
11451         if (!is_multicast_ether_addr(&res->mc_addr)) {
11452                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11453                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11454                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11455                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11456                 return;
11457         }
11458         if (strcmp(res->what, "add") == 0)
11459                 mcast_addr_add(res->port_num, &res->mc_addr);
11460         else
11461                 mcast_addr_remove(res->port_num, &res->mc_addr);
11462 }
11463
11464 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11465         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11466                                  mcast_addr_cmd, "mcast_addr");
11467 cmdline_parse_token_string_t cmd_mcast_addr_what =
11468         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11469                                  "add#remove");
11470 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11471         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11472 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11473         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11474
11475 cmdline_parse_inst_t cmd_mcast_addr = {
11476         .f = cmd_mcast_addr_parsed,
11477         .data = (void *)0,
11478         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11479                 "Add/Remove multicast MAC address on port_id",
11480         .tokens = {
11481                 (void *)&cmd_mcast_addr_cmd,
11482                 (void *)&cmd_mcast_addr_what,
11483                 (void *)&cmd_mcast_addr_portnum,
11484                 (void *)&cmd_mcast_addr_addr,
11485                 NULL,
11486         },
11487 };
11488
11489 /* l2 tunnel config
11490  * only support E-tag now.
11491  */
11492
11493 /* Ether type config */
11494 struct cmd_config_l2_tunnel_eth_type_result {
11495         cmdline_fixed_string_t port;
11496         cmdline_fixed_string_t config;
11497         cmdline_fixed_string_t all;
11498         uint8_t id;
11499         cmdline_fixed_string_t l2_tunnel;
11500         cmdline_fixed_string_t l2_tunnel_type;
11501         cmdline_fixed_string_t eth_type;
11502         uint16_t eth_type_val;
11503 };
11504
11505 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11506         TOKEN_STRING_INITIALIZER
11507                 (struct cmd_config_l2_tunnel_eth_type_result,
11508                  port, "port");
11509 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11510         TOKEN_STRING_INITIALIZER
11511                 (struct cmd_config_l2_tunnel_eth_type_result,
11512                  config, "config");
11513 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11514         TOKEN_STRING_INITIALIZER
11515                 (struct cmd_config_l2_tunnel_eth_type_result,
11516                  all, "all");
11517 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11518         TOKEN_NUM_INITIALIZER
11519                 (struct cmd_config_l2_tunnel_eth_type_result,
11520                  id, UINT8);
11521 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_config_l2_tunnel_eth_type_result,
11524                  l2_tunnel, "l2-tunnel");
11525 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11526         TOKEN_STRING_INITIALIZER
11527                 (struct cmd_config_l2_tunnel_eth_type_result,
11528                  l2_tunnel_type, "E-tag");
11529 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11530         TOKEN_STRING_INITIALIZER
11531                 (struct cmd_config_l2_tunnel_eth_type_result,
11532                  eth_type, "ether-type");
11533 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11534         TOKEN_NUM_INITIALIZER
11535                 (struct cmd_config_l2_tunnel_eth_type_result,
11536                  eth_type_val, UINT16);
11537
11538 static enum rte_eth_tunnel_type
11539 str2fdir_l2_tunnel_type(char *string)
11540 {
11541         uint32_t i = 0;
11542
11543         static const struct {
11544                 char str[32];
11545                 enum rte_eth_tunnel_type type;
11546         } l2_tunnel_type_str[] = {
11547                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11548         };
11549
11550         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11551                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11552                         return l2_tunnel_type_str[i].type;
11553         }
11554         return RTE_TUNNEL_TYPE_NONE;
11555 }
11556
11557 /* ether type config for all ports */
11558 static void
11559 cmd_config_l2_tunnel_eth_type_all_parsed
11560         (void *parsed_result,
11561          __attribute__((unused)) struct cmdline *cl,
11562          __attribute__((unused)) void *data)
11563 {
11564         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11565         struct rte_eth_l2_tunnel_conf entry;
11566         portid_t pid;
11567
11568         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11569         entry.ether_type = res->eth_type_val;
11570
11571         RTE_ETH_FOREACH_DEV(pid) {
11572                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11573         }
11574 }
11575
11576 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11577         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11578         .data = NULL,
11579         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11580         .tokens = {
11581                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11582                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11583                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11584                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11585                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11586                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11587                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11588                 NULL,
11589         },
11590 };
11591
11592 /* ether type config for a specific port */
11593 static void
11594 cmd_config_l2_tunnel_eth_type_specific_parsed(
11595         void *parsed_result,
11596         __attribute__((unused)) struct cmdline *cl,
11597         __attribute__((unused)) void *data)
11598 {
11599         struct cmd_config_l2_tunnel_eth_type_result *res =
11600                  parsed_result;
11601         struct rte_eth_l2_tunnel_conf entry;
11602
11603         if (port_id_is_invalid(res->id, ENABLED_WARN))
11604                 return;
11605
11606         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11607         entry.ether_type = res->eth_type_val;
11608
11609         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11610 }
11611
11612 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11613         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11614         .data = NULL,
11615         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11616         .tokens = {
11617                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11618                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11619                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11620                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11621                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11622                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11623                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11624                 NULL,
11625         },
11626 };
11627
11628 /* Enable/disable l2 tunnel */
11629 struct cmd_config_l2_tunnel_en_dis_result {
11630         cmdline_fixed_string_t port;
11631         cmdline_fixed_string_t config;
11632         cmdline_fixed_string_t all;
11633         uint8_t id;
11634         cmdline_fixed_string_t l2_tunnel;
11635         cmdline_fixed_string_t l2_tunnel_type;
11636         cmdline_fixed_string_t en_dis;
11637 };
11638
11639 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_config_l2_tunnel_en_dis_result,
11642                  port, "port");
11643 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11644         TOKEN_STRING_INITIALIZER
11645                 (struct cmd_config_l2_tunnel_en_dis_result,
11646                  config, "config");
11647 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11648         TOKEN_STRING_INITIALIZER
11649                 (struct cmd_config_l2_tunnel_en_dis_result,
11650                  all, "all");
11651 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11652         TOKEN_NUM_INITIALIZER
11653                 (struct cmd_config_l2_tunnel_en_dis_result,
11654                  id, UINT8);
11655 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11656         TOKEN_STRING_INITIALIZER
11657                 (struct cmd_config_l2_tunnel_en_dis_result,
11658                  l2_tunnel, "l2-tunnel");
11659 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11660         TOKEN_STRING_INITIALIZER
11661                 (struct cmd_config_l2_tunnel_en_dis_result,
11662                  l2_tunnel_type, "E-tag");
11663 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11664         TOKEN_STRING_INITIALIZER
11665                 (struct cmd_config_l2_tunnel_en_dis_result,
11666                  en_dis, "enable#disable");
11667
11668 /* enable/disable l2 tunnel for all ports */
11669 static void
11670 cmd_config_l2_tunnel_en_dis_all_parsed(
11671         void *parsed_result,
11672         __attribute__((unused)) struct cmdline *cl,
11673         __attribute__((unused)) void *data)
11674 {
11675         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11676         struct rte_eth_l2_tunnel_conf entry;
11677         portid_t pid;
11678         uint8_t en;
11679
11680         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11681
11682         if (!strcmp("enable", res->en_dis))
11683                 en = 1;
11684         else
11685                 en = 0;
11686
11687         RTE_ETH_FOREACH_DEV(pid) {
11688                 rte_eth_dev_l2_tunnel_offload_set(pid,
11689                                                   &entry,
11690                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11691                                                   en);
11692         }
11693 }
11694
11695 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11696         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11697         .data = NULL,
11698         .help_str = "port config all l2-tunnel E-tag enable|disable",
11699         .tokens = {
11700                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11701                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11702                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11703                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11704                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11705                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11706                 NULL,
11707         },
11708 };
11709
11710 /* enable/disable l2 tunnel for a port */
11711 static void
11712 cmd_config_l2_tunnel_en_dis_specific_parsed(
11713         void *parsed_result,
11714         __attribute__((unused)) struct cmdline *cl,
11715         __attribute__((unused)) void *data)
11716 {
11717         struct cmd_config_l2_tunnel_en_dis_result *res =
11718                 parsed_result;
11719         struct rte_eth_l2_tunnel_conf entry;
11720
11721         if (port_id_is_invalid(res->id, ENABLED_WARN))
11722                 return;
11723
11724         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11725
11726         if (!strcmp("enable", res->en_dis))
11727                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11728                                                   &entry,
11729                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11730                                                   1);
11731         else
11732                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11733                                                   &entry,
11734                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11735                                                   0);
11736 }
11737
11738 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11739         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11740         .data = NULL,
11741         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11742         .tokens = {
11743                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11744                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11745                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11746                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11747                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11748                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11749                 NULL,
11750         },
11751 };
11752
11753 /* E-tag configuration */
11754
11755 /* Common result structure for all E-tag configuration */
11756 struct cmd_config_e_tag_result {
11757         cmdline_fixed_string_t e_tag;
11758         cmdline_fixed_string_t set;
11759         cmdline_fixed_string_t insertion;
11760         cmdline_fixed_string_t stripping;
11761         cmdline_fixed_string_t forwarding;
11762         cmdline_fixed_string_t filter;
11763         cmdline_fixed_string_t add;
11764         cmdline_fixed_string_t del;
11765         cmdline_fixed_string_t on;
11766         cmdline_fixed_string_t off;
11767         cmdline_fixed_string_t on_off;
11768         cmdline_fixed_string_t port_tag_id;
11769         uint32_t port_tag_id_val;
11770         cmdline_fixed_string_t e_tag_id;
11771         uint16_t e_tag_id_val;
11772         cmdline_fixed_string_t dst_pool;
11773         uint8_t dst_pool_val;
11774         cmdline_fixed_string_t port;
11775         portid_t port_id;
11776         cmdline_fixed_string_t vf;
11777         uint8_t vf_id;
11778 };
11779
11780 /* Common CLI fields for all E-tag configuration */
11781 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11782         TOKEN_STRING_INITIALIZER
11783                 (struct cmd_config_e_tag_result,
11784                  e_tag, "E-tag");
11785 cmdline_parse_token_string_t cmd_config_e_tag_set =
11786         TOKEN_STRING_INITIALIZER
11787                 (struct cmd_config_e_tag_result,
11788                  set, "set");
11789 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11790         TOKEN_STRING_INITIALIZER
11791                 (struct cmd_config_e_tag_result,
11792                  insertion, "insertion");
11793 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11794         TOKEN_STRING_INITIALIZER
11795                 (struct cmd_config_e_tag_result,
11796                  stripping, "stripping");
11797 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11798         TOKEN_STRING_INITIALIZER
11799                 (struct cmd_config_e_tag_result,
11800                  forwarding, "forwarding");
11801 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_config_e_tag_result,
11804                  filter, "filter");
11805 cmdline_parse_token_string_t cmd_config_e_tag_add =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_config_e_tag_result,
11808                  add, "add");
11809 cmdline_parse_token_string_t cmd_config_e_tag_del =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_config_e_tag_result,
11812                  del, "del");
11813 cmdline_parse_token_string_t cmd_config_e_tag_on =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_config_e_tag_result,
11816                  on, "on");
11817 cmdline_parse_token_string_t cmd_config_e_tag_off =
11818         TOKEN_STRING_INITIALIZER
11819                 (struct cmd_config_e_tag_result,
11820                  off, "off");
11821 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_config_e_tag_result,
11824                  on_off, "on#off");
11825 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11826         TOKEN_STRING_INITIALIZER
11827                 (struct cmd_config_e_tag_result,
11828                  port_tag_id, "port-tag-id");
11829 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11830         TOKEN_NUM_INITIALIZER
11831                 (struct cmd_config_e_tag_result,
11832                  port_tag_id_val, UINT32);
11833 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11834         TOKEN_STRING_INITIALIZER
11835                 (struct cmd_config_e_tag_result,
11836                  e_tag_id, "e-tag-id");
11837 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11838         TOKEN_NUM_INITIALIZER
11839                 (struct cmd_config_e_tag_result,
11840                  e_tag_id_val, UINT16);
11841 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11842         TOKEN_STRING_INITIALIZER
11843                 (struct cmd_config_e_tag_result,
11844                  dst_pool, "dst-pool");
11845 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11846         TOKEN_NUM_INITIALIZER
11847                 (struct cmd_config_e_tag_result,
11848                  dst_pool_val, UINT8);
11849 cmdline_parse_token_string_t cmd_config_e_tag_port =
11850         TOKEN_STRING_INITIALIZER
11851                 (struct cmd_config_e_tag_result,
11852                  port, "port");
11853 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11854         TOKEN_NUM_INITIALIZER
11855                 (struct cmd_config_e_tag_result,
11856                  port_id, UINT16);
11857 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11858         TOKEN_STRING_INITIALIZER
11859                 (struct cmd_config_e_tag_result,
11860                  vf, "vf");
11861 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11862         TOKEN_NUM_INITIALIZER
11863                 (struct cmd_config_e_tag_result,
11864                  vf_id, UINT8);
11865
11866 /* E-tag insertion configuration */
11867 static void
11868 cmd_config_e_tag_insertion_en_parsed(
11869         void *parsed_result,
11870         __attribute__((unused)) struct cmdline *cl,
11871         __attribute__((unused)) void *data)
11872 {
11873         struct cmd_config_e_tag_result *res =
11874                 parsed_result;
11875         struct rte_eth_l2_tunnel_conf entry;
11876
11877         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11878                 return;
11879
11880         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11881         entry.tunnel_id = res->port_tag_id_val;
11882         entry.vf_id = res->vf_id;
11883         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11884                                           &entry,
11885                                           ETH_L2_TUNNEL_INSERTION_MASK,
11886                                           1);
11887 }
11888
11889 static void
11890 cmd_config_e_tag_insertion_dis_parsed(
11891         void *parsed_result,
11892         __attribute__((unused)) struct cmdline *cl,
11893         __attribute__((unused)) void *data)
11894 {
11895         struct cmd_config_e_tag_result *res =
11896                 parsed_result;
11897         struct rte_eth_l2_tunnel_conf entry;
11898
11899         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11900                 return;
11901
11902         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11903         entry.vf_id = res->vf_id;
11904
11905         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11906                                           &entry,
11907                                           ETH_L2_TUNNEL_INSERTION_MASK,
11908                                           0);
11909 }
11910
11911 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11912         .f = cmd_config_e_tag_insertion_en_parsed,
11913         .data = NULL,
11914         .help_str = "E-tag ... : E-tag insertion enable",
11915         .tokens = {
11916                 (void *)&cmd_config_e_tag_e_tag,
11917                 (void *)&cmd_config_e_tag_set,
11918                 (void *)&cmd_config_e_tag_insertion,
11919                 (void *)&cmd_config_e_tag_on,
11920                 (void *)&cmd_config_e_tag_port_tag_id,
11921                 (void *)&cmd_config_e_tag_port_tag_id_val,
11922                 (void *)&cmd_config_e_tag_port,
11923                 (void *)&cmd_config_e_tag_port_id,
11924                 (void *)&cmd_config_e_tag_vf,
11925                 (void *)&cmd_config_e_tag_vf_id,
11926                 NULL,
11927         },
11928 };
11929
11930 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11931         .f = cmd_config_e_tag_insertion_dis_parsed,
11932         .data = NULL,
11933         .help_str = "E-tag ... : E-tag insertion disable",
11934         .tokens = {
11935                 (void *)&cmd_config_e_tag_e_tag,
11936                 (void *)&cmd_config_e_tag_set,
11937                 (void *)&cmd_config_e_tag_insertion,
11938                 (void *)&cmd_config_e_tag_off,
11939                 (void *)&cmd_config_e_tag_port,
11940                 (void *)&cmd_config_e_tag_port_id,
11941                 (void *)&cmd_config_e_tag_vf,
11942                 (void *)&cmd_config_e_tag_vf_id,
11943                 NULL,
11944         },
11945 };
11946
11947 /* E-tag stripping configuration */
11948 static void
11949 cmd_config_e_tag_stripping_parsed(
11950         void *parsed_result,
11951         __attribute__((unused)) struct cmdline *cl,
11952         __attribute__((unused)) void *data)
11953 {
11954         struct cmd_config_e_tag_result *res =
11955                 parsed_result;
11956         struct rte_eth_l2_tunnel_conf entry;
11957
11958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11959                 return;
11960
11961         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11962
11963         if (!strcmp(res->on_off, "on"))
11964                 rte_eth_dev_l2_tunnel_offload_set
11965                         (res->port_id,
11966                          &entry,
11967                          ETH_L2_TUNNEL_STRIPPING_MASK,
11968                          1);
11969         else
11970                 rte_eth_dev_l2_tunnel_offload_set
11971                         (res->port_id,
11972                          &entry,
11973                          ETH_L2_TUNNEL_STRIPPING_MASK,
11974                          0);
11975 }
11976
11977 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11978         .f = cmd_config_e_tag_stripping_parsed,
11979         .data = NULL,
11980         .help_str = "E-tag ... : E-tag stripping enable/disable",
11981         .tokens = {
11982                 (void *)&cmd_config_e_tag_e_tag,
11983                 (void *)&cmd_config_e_tag_set,
11984                 (void *)&cmd_config_e_tag_stripping,
11985                 (void *)&cmd_config_e_tag_on_off,
11986                 (void *)&cmd_config_e_tag_port,
11987                 (void *)&cmd_config_e_tag_port_id,
11988                 NULL,
11989         },
11990 };
11991
11992 /* E-tag forwarding configuration */
11993 static void
11994 cmd_config_e_tag_forwarding_parsed(
11995         void *parsed_result,
11996         __attribute__((unused)) struct cmdline *cl,
11997         __attribute__((unused)) void *data)
11998 {
11999         struct cmd_config_e_tag_result *res = parsed_result;
12000         struct rte_eth_l2_tunnel_conf entry;
12001
12002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12003                 return;
12004
12005         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12006
12007         if (!strcmp(res->on_off, "on"))
12008                 rte_eth_dev_l2_tunnel_offload_set
12009                         (res->port_id,
12010                          &entry,
12011                          ETH_L2_TUNNEL_FORWARDING_MASK,
12012                          1);
12013         else
12014                 rte_eth_dev_l2_tunnel_offload_set
12015                         (res->port_id,
12016                          &entry,
12017                          ETH_L2_TUNNEL_FORWARDING_MASK,
12018                          0);
12019 }
12020
12021 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12022         .f = cmd_config_e_tag_forwarding_parsed,
12023         .data = NULL,
12024         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12025         .tokens = {
12026                 (void *)&cmd_config_e_tag_e_tag,
12027                 (void *)&cmd_config_e_tag_set,
12028                 (void *)&cmd_config_e_tag_forwarding,
12029                 (void *)&cmd_config_e_tag_on_off,
12030                 (void *)&cmd_config_e_tag_port,
12031                 (void *)&cmd_config_e_tag_port_id,
12032                 NULL,
12033         },
12034 };
12035
12036 /* E-tag filter configuration */
12037 static void
12038 cmd_config_e_tag_filter_add_parsed(
12039         void *parsed_result,
12040         __attribute__((unused)) struct cmdline *cl,
12041         __attribute__((unused)) void *data)
12042 {
12043         struct cmd_config_e_tag_result *res = parsed_result;
12044         struct rte_eth_l2_tunnel_conf entry;
12045         int ret = 0;
12046
12047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12048                 return;
12049
12050         if (res->e_tag_id_val > 0x3fff) {
12051                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12052                 return;
12053         }
12054
12055         ret = rte_eth_dev_filter_supported(res->port_id,
12056                                            RTE_ETH_FILTER_L2_TUNNEL);
12057         if (ret < 0) {
12058                 printf("E-tag filter is not supported on port %u.\n",
12059                        res->port_id);
12060                 return;
12061         }
12062
12063         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12064         entry.tunnel_id = res->e_tag_id_val;
12065         entry.pool = res->dst_pool_val;
12066
12067         ret = rte_eth_dev_filter_ctrl(res->port_id,
12068                                       RTE_ETH_FILTER_L2_TUNNEL,
12069                                       RTE_ETH_FILTER_ADD,
12070                                       &entry);
12071         if (ret < 0)
12072                 printf("E-tag filter programming error: (%s)\n",
12073                        strerror(-ret));
12074 }
12075
12076 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12077         .f = cmd_config_e_tag_filter_add_parsed,
12078         .data = NULL,
12079         .help_str = "E-tag ... : E-tag filter add",
12080         .tokens = {
12081                 (void *)&cmd_config_e_tag_e_tag,
12082                 (void *)&cmd_config_e_tag_set,
12083                 (void *)&cmd_config_e_tag_filter,
12084                 (void *)&cmd_config_e_tag_add,
12085                 (void *)&cmd_config_e_tag_e_tag_id,
12086                 (void *)&cmd_config_e_tag_e_tag_id_val,
12087                 (void *)&cmd_config_e_tag_dst_pool,
12088                 (void *)&cmd_config_e_tag_dst_pool_val,
12089                 (void *)&cmd_config_e_tag_port,
12090                 (void *)&cmd_config_e_tag_port_id,
12091                 NULL,
12092         },
12093 };
12094
12095 static void
12096 cmd_config_e_tag_filter_del_parsed(
12097         void *parsed_result,
12098         __attribute__((unused)) struct cmdline *cl,
12099         __attribute__((unused)) void *data)
12100 {
12101         struct cmd_config_e_tag_result *res = parsed_result;
12102         struct rte_eth_l2_tunnel_conf entry;
12103         int ret = 0;
12104
12105         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12106                 return;
12107
12108         if (res->e_tag_id_val > 0x3fff) {
12109                 printf("e-tag-id must be less than 0x3fff.\n");
12110                 return;
12111         }
12112
12113         ret = rte_eth_dev_filter_supported(res->port_id,
12114                                            RTE_ETH_FILTER_L2_TUNNEL);
12115         if (ret < 0) {
12116                 printf("E-tag filter is not supported on port %u.\n",
12117                        res->port_id);
12118                 return;
12119         }
12120
12121         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12122         entry.tunnel_id = res->e_tag_id_val;
12123
12124         ret = rte_eth_dev_filter_ctrl(res->port_id,
12125                                       RTE_ETH_FILTER_L2_TUNNEL,
12126                                       RTE_ETH_FILTER_DELETE,
12127                                       &entry);
12128         if (ret < 0)
12129                 printf("E-tag filter programming error: (%s)\n",
12130                        strerror(-ret));
12131 }
12132
12133 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12134         .f = cmd_config_e_tag_filter_del_parsed,
12135         .data = NULL,
12136         .help_str = "E-tag ... : E-tag filter delete",
12137         .tokens = {
12138                 (void *)&cmd_config_e_tag_e_tag,
12139                 (void *)&cmd_config_e_tag_set,
12140                 (void *)&cmd_config_e_tag_filter,
12141                 (void *)&cmd_config_e_tag_del,
12142                 (void *)&cmd_config_e_tag_e_tag_id,
12143                 (void *)&cmd_config_e_tag_e_tag_id_val,
12144                 (void *)&cmd_config_e_tag_port,
12145                 (void *)&cmd_config_e_tag_port_id,
12146                 NULL,
12147         },
12148 };
12149
12150 /* vf vlan anti spoof configuration */
12151
12152 /* Common result structure for vf vlan anti spoof */
12153 struct cmd_vf_vlan_anti_spoof_result {
12154         cmdline_fixed_string_t set;
12155         cmdline_fixed_string_t vf;
12156         cmdline_fixed_string_t vlan;
12157         cmdline_fixed_string_t antispoof;
12158         portid_t port_id;
12159         uint32_t vf_id;
12160         cmdline_fixed_string_t on_off;
12161 };
12162
12163 /* Common CLI fields for vf vlan anti spoof enable disable */
12164 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12165         TOKEN_STRING_INITIALIZER
12166                 (struct cmd_vf_vlan_anti_spoof_result,
12167                  set, "set");
12168 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12169         TOKEN_STRING_INITIALIZER
12170                 (struct cmd_vf_vlan_anti_spoof_result,
12171                  vf, "vf");
12172 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12173         TOKEN_STRING_INITIALIZER
12174                 (struct cmd_vf_vlan_anti_spoof_result,
12175                  vlan, "vlan");
12176 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12177         TOKEN_STRING_INITIALIZER
12178                 (struct cmd_vf_vlan_anti_spoof_result,
12179                  antispoof, "antispoof");
12180 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12181         TOKEN_NUM_INITIALIZER
12182                 (struct cmd_vf_vlan_anti_spoof_result,
12183                  port_id, UINT16);
12184 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12185         TOKEN_NUM_INITIALIZER
12186                 (struct cmd_vf_vlan_anti_spoof_result,
12187                  vf_id, UINT32);
12188 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12189         TOKEN_STRING_INITIALIZER
12190                 (struct cmd_vf_vlan_anti_spoof_result,
12191                  on_off, "on#off");
12192
12193 static void
12194 cmd_set_vf_vlan_anti_spoof_parsed(
12195         void *parsed_result,
12196         __attribute__((unused)) struct cmdline *cl,
12197         __attribute__((unused)) void *data)
12198 {
12199         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12200         int ret = -ENOTSUP;
12201
12202         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12203
12204         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12205                 return;
12206
12207 #ifdef RTE_LIBRTE_IXGBE_PMD
12208         if (ret == -ENOTSUP)
12209                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12210                                 res->vf_id, is_on);
12211 #endif
12212 #ifdef RTE_LIBRTE_I40E_PMD
12213         if (ret == -ENOTSUP)
12214                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12215                                 res->vf_id, is_on);
12216 #endif
12217 #ifdef RTE_LIBRTE_BNXT_PMD
12218         if (ret == -ENOTSUP)
12219                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12220                                 res->vf_id, is_on);
12221 #endif
12222
12223         switch (ret) {
12224         case 0:
12225                 break;
12226         case -EINVAL:
12227                 printf("invalid vf_id %d\n", res->vf_id);
12228                 break;
12229         case -ENODEV:
12230                 printf("invalid port_id %d\n", res->port_id);
12231                 break;
12232         case -ENOTSUP:
12233                 printf("function not implemented\n");
12234                 break;
12235         default:
12236                 printf("programming error: (%s)\n", strerror(-ret));
12237         }
12238 }
12239
12240 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12241         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12242         .data = NULL,
12243         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12244         .tokens = {
12245                 (void *)&cmd_vf_vlan_anti_spoof_set,
12246                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12247                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12248                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12249                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12250                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12251                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12252                 NULL,
12253         },
12254 };
12255
12256 /* vf mac anti spoof configuration */
12257
12258 /* Common result structure for vf mac anti spoof */
12259 struct cmd_vf_mac_anti_spoof_result {
12260         cmdline_fixed_string_t set;
12261         cmdline_fixed_string_t vf;
12262         cmdline_fixed_string_t mac;
12263         cmdline_fixed_string_t antispoof;
12264         portid_t port_id;
12265         uint32_t vf_id;
12266         cmdline_fixed_string_t on_off;
12267 };
12268
12269 /* Common CLI fields for vf mac anti spoof enable disable */
12270 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12271         TOKEN_STRING_INITIALIZER
12272                 (struct cmd_vf_mac_anti_spoof_result,
12273                  set, "set");
12274 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12275         TOKEN_STRING_INITIALIZER
12276                 (struct cmd_vf_mac_anti_spoof_result,
12277                  vf, "vf");
12278 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12279         TOKEN_STRING_INITIALIZER
12280                 (struct cmd_vf_mac_anti_spoof_result,
12281                  mac, "mac");
12282 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12283         TOKEN_STRING_INITIALIZER
12284                 (struct cmd_vf_mac_anti_spoof_result,
12285                  antispoof, "antispoof");
12286 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12287         TOKEN_NUM_INITIALIZER
12288                 (struct cmd_vf_mac_anti_spoof_result,
12289                  port_id, UINT16);
12290 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12291         TOKEN_NUM_INITIALIZER
12292                 (struct cmd_vf_mac_anti_spoof_result,
12293                  vf_id, UINT32);
12294 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12295         TOKEN_STRING_INITIALIZER
12296                 (struct cmd_vf_mac_anti_spoof_result,
12297                  on_off, "on#off");
12298
12299 static void
12300 cmd_set_vf_mac_anti_spoof_parsed(
12301         void *parsed_result,
12302         __attribute__((unused)) struct cmdline *cl,
12303         __attribute__((unused)) void *data)
12304 {
12305         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12306         int ret = -ENOTSUP;
12307
12308         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12309
12310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12311                 return;
12312
12313 #ifdef RTE_LIBRTE_IXGBE_PMD
12314         if (ret == -ENOTSUP)
12315                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12316                         res->vf_id, is_on);
12317 #endif
12318 #ifdef RTE_LIBRTE_I40E_PMD
12319         if (ret == -ENOTSUP)
12320                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12321                         res->vf_id, is_on);
12322 #endif
12323 #ifdef RTE_LIBRTE_BNXT_PMD
12324         if (ret == -ENOTSUP)
12325                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12326                         res->vf_id, is_on);
12327 #endif
12328
12329         switch (ret) {
12330         case 0:
12331                 break;
12332         case -EINVAL:
12333                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12334                 break;
12335         case -ENODEV:
12336                 printf("invalid port_id %d\n", res->port_id);
12337                 break;
12338         case -ENOTSUP:
12339                 printf("function not implemented\n");
12340                 break;
12341         default:
12342                 printf("programming error: (%s)\n", strerror(-ret));
12343         }
12344 }
12345
12346 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12347         .f = cmd_set_vf_mac_anti_spoof_parsed,
12348         .data = NULL,
12349         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12350         .tokens = {
12351                 (void *)&cmd_vf_mac_anti_spoof_set,
12352                 (void *)&cmd_vf_mac_anti_spoof_vf,
12353                 (void *)&cmd_vf_mac_anti_spoof_mac,
12354                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12355                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12356                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12357                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12358                 NULL,
12359         },
12360 };
12361
12362 /* vf vlan strip queue configuration */
12363
12364 /* Common result structure for vf mac anti spoof */
12365 struct cmd_vf_vlan_stripq_result {
12366         cmdline_fixed_string_t set;
12367         cmdline_fixed_string_t vf;
12368         cmdline_fixed_string_t vlan;
12369         cmdline_fixed_string_t stripq;
12370         portid_t port_id;
12371         uint16_t vf_id;
12372         cmdline_fixed_string_t on_off;
12373 };
12374
12375 /* Common CLI fields for vf vlan strip enable disable */
12376 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_vf_vlan_stripq_result,
12379                  set, "set");
12380 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12381         TOKEN_STRING_INITIALIZER
12382                 (struct cmd_vf_vlan_stripq_result,
12383                  vf, "vf");
12384 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12385         TOKEN_STRING_INITIALIZER
12386                 (struct cmd_vf_vlan_stripq_result,
12387                  vlan, "vlan");
12388 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12389         TOKEN_STRING_INITIALIZER
12390                 (struct cmd_vf_vlan_stripq_result,
12391                  stripq, "stripq");
12392 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12393         TOKEN_NUM_INITIALIZER
12394                 (struct cmd_vf_vlan_stripq_result,
12395                  port_id, UINT16);
12396 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12397         TOKEN_NUM_INITIALIZER
12398                 (struct cmd_vf_vlan_stripq_result,
12399                  vf_id, UINT16);
12400 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12401         TOKEN_STRING_INITIALIZER
12402                 (struct cmd_vf_vlan_stripq_result,
12403                  on_off, "on#off");
12404
12405 static void
12406 cmd_set_vf_vlan_stripq_parsed(
12407         void *parsed_result,
12408         __attribute__((unused)) struct cmdline *cl,
12409         __attribute__((unused)) void *data)
12410 {
12411         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12412         int ret = -ENOTSUP;
12413
12414         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12415
12416         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12417                 return;
12418
12419 #ifdef RTE_LIBRTE_IXGBE_PMD
12420         if (ret == -ENOTSUP)
12421                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12422                         res->vf_id, is_on);
12423 #endif
12424 #ifdef RTE_LIBRTE_I40E_PMD
12425         if (ret == -ENOTSUP)
12426                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12427                         res->vf_id, is_on);
12428 #endif
12429 #ifdef RTE_LIBRTE_BNXT_PMD
12430         if (ret == -ENOTSUP)
12431                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12432                         res->vf_id, is_on);
12433 #endif
12434
12435         switch (ret) {
12436         case 0:
12437                 break;
12438         case -EINVAL:
12439                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12440                 break;
12441         case -ENODEV:
12442                 printf("invalid port_id %d\n", res->port_id);
12443                 break;
12444         case -ENOTSUP:
12445                 printf("function not implemented\n");
12446                 break;
12447         default:
12448                 printf("programming error: (%s)\n", strerror(-ret));
12449         }
12450 }
12451
12452 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12453         .f = cmd_set_vf_vlan_stripq_parsed,
12454         .data = NULL,
12455         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12456         .tokens = {
12457                 (void *)&cmd_vf_vlan_stripq_set,
12458                 (void *)&cmd_vf_vlan_stripq_vf,
12459                 (void *)&cmd_vf_vlan_stripq_vlan,
12460                 (void *)&cmd_vf_vlan_stripq_stripq,
12461                 (void *)&cmd_vf_vlan_stripq_port_id,
12462                 (void *)&cmd_vf_vlan_stripq_vf_id,
12463                 (void *)&cmd_vf_vlan_stripq_on_off,
12464                 NULL,
12465         },
12466 };
12467
12468 /* vf vlan insert configuration */
12469
12470 /* Common result structure for vf vlan insert */
12471 struct cmd_vf_vlan_insert_result {
12472         cmdline_fixed_string_t set;
12473         cmdline_fixed_string_t vf;
12474         cmdline_fixed_string_t vlan;
12475         cmdline_fixed_string_t insert;
12476         portid_t port_id;
12477         uint16_t vf_id;
12478         uint16_t vlan_id;
12479 };
12480
12481 /* Common CLI fields for vf vlan insert enable disable */
12482 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_vf_vlan_insert_result,
12485                  set, "set");
12486 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_vf_vlan_insert_result,
12489                  vf, "vf");
12490 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_vf_vlan_insert_result,
12493                  vlan, "vlan");
12494 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12495         TOKEN_STRING_INITIALIZER
12496                 (struct cmd_vf_vlan_insert_result,
12497                  insert, "insert");
12498 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12499         TOKEN_NUM_INITIALIZER
12500                 (struct cmd_vf_vlan_insert_result,
12501                  port_id, UINT16);
12502 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12503         TOKEN_NUM_INITIALIZER
12504                 (struct cmd_vf_vlan_insert_result,
12505                  vf_id, UINT16);
12506 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12507         TOKEN_NUM_INITIALIZER
12508                 (struct cmd_vf_vlan_insert_result,
12509                  vlan_id, UINT16);
12510
12511 static void
12512 cmd_set_vf_vlan_insert_parsed(
12513         void *parsed_result,
12514         __attribute__((unused)) struct cmdline *cl,
12515         __attribute__((unused)) void *data)
12516 {
12517         struct cmd_vf_vlan_insert_result *res = parsed_result;
12518         int ret = -ENOTSUP;
12519
12520         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12521                 return;
12522
12523 #ifdef RTE_LIBRTE_IXGBE_PMD
12524         if (ret == -ENOTSUP)
12525                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12526                         res->vlan_id);
12527 #endif
12528 #ifdef RTE_LIBRTE_I40E_PMD
12529         if (ret == -ENOTSUP)
12530                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12531                         res->vlan_id);
12532 #endif
12533 #ifdef RTE_LIBRTE_BNXT_PMD
12534         if (ret == -ENOTSUP)
12535                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12536                         res->vlan_id);
12537 #endif
12538
12539         switch (ret) {
12540         case 0:
12541                 break;
12542         case -EINVAL:
12543                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12544                 break;
12545         case -ENODEV:
12546                 printf("invalid port_id %d\n", res->port_id);
12547                 break;
12548         case -ENOTSUP:
12549                 printf("function not implemented\n");
12550                 break;
12551         default:
12552                 printf("programming error: (%s)\n", strerror(-ret));
12553         }
12554 }
12555
12556 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12557         .f = cmd_set_vf_vlan_insert_parsed,
12558         .data = NULL,
12559         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12560         .tokens = {
12561                 (void *)&cmd_vf_vlan_insert_set,
12562                 (void *)&cmd_vf_vlan_insert_vf,
12563                 (void *)&cmd_vf_vlan_insert_vlan,
12564                 (void *)&cmd_vf_vlan_insert_insert,
12565                 (void *)&cmd_vf_vlan_insert_port_id,
12566                 (void *)&cmd_vf_vlan_insert_vf_id,
12567                 (void *)&cmd_vf_vlan_insert_vlan_id,
12568                 NULL,
12569         },
12570 };
12571
12572 /* tx loopback configuration */
12573
12574 /* Common result structure for tx loopback */
12575 struct cmd_tx_loopback_result {
12576         cmdline_fixed_string_t set;
12577         cmdline_fixed_string_t tx;
12578         cmdline_fixed_string_t loopback;
12579         portid_t port_id;
12580         cmdline_fixed_string_t on_off;
12581 };
12582
12583 /* Common CLI fields for tx loopback enable disable */
12584 cmdline_parse_token_string_t cmd_tx_loopback_set =
12585         TOKEN_STRING_INITIALIZER
12586                 (struct cmd_tx_loopback_result,
12587                  set, "set");
12588 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12589         TOKEN_STRING_INITIALIZER
12590                 (struct cmd_tx_loopback_result,
12591                  tx, "tx");
12592 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12593         TOKEN_STRING_INITIALIZER
12594                 (struct cmd_tx_loopback_result,
12595                  loopback, "loopback");
12596 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12597         TOKEN_NUM_INITIALIZER
12598                 (struct cmd_tx_loopback_result,
12599                  port_id, UINT16);
12600 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12601         TOKEN_STRING_INITIALIZER
12602                 (struct cmd_tx_loopback_result,
12603                  on_off, "on#off");
12604
12605 static void
12606 cmd_set_tx_loopback_parsed(
12607         void *parsed_result,
12608         __attribute__((unused)) struct cmdline *cl,
12609         __attribute__((unused)) void *data)
12610 {
12611         struct cmd_tx_loopback_result *res = parsed_result;
12612         int ret = -ENOTSUP;
12613
12614         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12615
12616         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12617                 return;
12618
12619 #ifdef RTE_LIBRTE_IXGBE_PMD
12620         if (ret == -ENOTSUP)
12621                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12622 #endif
12623 #ifdef RTE_LIBRTE_I40E_PMD
12624         if (ret == -ENOTSUP)
12625                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12626 #endif
12627 #ifdef RTE_LIBRTE_BNXT_PMD
12628         if (ret == -ENOTSUP)
12629                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12630 #endif
12631
12632         switch (ret) {
12633         case 0:
12634                 break;
12635         case -EINVAL:
12636                 printf("invalid is_on %d\n", is_on);
12637                 break;
12638         case -ENODEV:
12639                 printf("invalid port_id %d\n", res->port_id);
12640                 break;
12641         case -ENOTSUP:
12642                 printf("function not implemented\n");
12643                 break;
12644         default:
12645                 printf("programming error: (%s)\n", strerror(-ret));
12646         }
12647 }
12648
12649 cmdline_parse_inst_t cmd_set_tx_loopback = {
12650         .f = cmd_set_tx_loopback_parsed,
12651         .data = NULL,
12652         .help_str = "set tx loopback <port_id> on|off",
12653         .tokens = {
12654                 (void *)&cmd_tx_loopback_set,
12655                 (void *)&cmd_tx_loopback_tx,
12656                 (void *)&cmd_tx_loopback_loopback,
12657                 (void *)&cmd_tx_loopback_port_id,
12658                 (void *)&cmd_tx_loopback_on_off,
12659                 NULL,
12660         },
12661 };
12662
12663 /* all queues drop enable configuration */
12664
12665 /* Common result structure for all queues drop enable */
12666 struct cmd_all_queues_drop_en_result {
12667         cmdline_fixed_string_t set;
12668         cmdline_fixed_string_t all;
12669         cmdline_fixed_string_t queues;
12670         cmdline_fixed_string_t drop;
12671         portid_t port_id;
12672         cmdline_fixed_string_t on_off;
12673 };
12674
12675 /* Common CLI fields for tx loopback enable disable */
12676 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12677         TOKEN_STRING_INITIALIZER
12678                 (struct cmd_all_queues_drop_en_result,
12679                  set, "set");
12680 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12681         TOKEN_STRING_INITIALIZER
12682                 (struct cmd_all_queues_drop_en_result,
12683                  all, "all");
12684 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12685         TOKEN_STRING_INITIALIZER
12686                 (struct cmd_all_queues_drop_en_result,
12687                  queues, "queues");
12688 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12689         TOKEN_STRING_INITIALIZER
12690                 (struct cmd_all_queues_drop_en_result,
12691                  drop, "drop");
12692 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12693         TOKEN_NUM_INITIALIZER
12694                 (struct cmd_all_queues_drop_en_result,
12695                  port_id, UINT16);
12696 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12697         TOKEN_STRING_INITIALIZER
12698                 (struct cmd_all_queues_drop_en_result,
12699                  on_off, "on#off");
12700
12701 static void
12702 cmd_set_all_queues_drop_en_parsed(
12703         void *parsed_result,
12704         __attribute__((unused)) struct cmdline *cl,
12705         __attribute__((unused)) void *data)
12706 {
12707         struct cmd_all_queues_drop_en_result *res = parsed_result;
12708         int ret = -ENOTSUP;
12709         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12710
12711         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12712                 return;
12713
12714 #ifdef RTE_LIBRTE_IXGBE_PMD
12715         if (ret == -ENOTSUP)
12716                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12717 #endif
12718 #ifdef RTE_LIBRTE_BNXT_PMD
12719         if (ret == -ENOTSUP)
12720                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12721 #endif
12722         switch (ret) {
12723         case 0:
12724                 break;
12725         case -EINVAL:
12726                 printf("invalid is_on %d\n", is_on);
12727                 break;
12728         case -ENODEV:
12729                 printf("invalid port_id %d\n", res->port_id);
12730                 break;
12731         case -ENOTSUP:
12732                 printf("function not implemented\n");
12733                 break;
12734         default:
12735                 printf("programming error: (%s)\n", strerror(-ret));
12736         }
12737 }
12738
12739 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12740         .f = cmd_set_all_queues_drop_en_parsed,
12741         .data = NULL,
12742         .help_str = "set all queues drop <port_id> on|off",
12743         .tokens = {
12744                 (void *)&cmd_all_queues_drop_en_set,
12745                 (void *)&cmd_all_queues_drop_en_all,
12746                 (void *)&cmd_all_queues_drop_en_queues,
12747                 (void *)&cmd_all_queues_drop_en_drop,
12748                 (void *)&cmd_all_queues_drop_en_port_id,
12749                 (void *)&cmd_all_queues_drop_en_on_off,
12750                 NULL,
12751         },
12752 };
12753
12754 /* vf split drop enable configuration */
12755
12756 /* Common result structure for vf split drop enable */
12757 struct cmd_vf_split_drop_en_result {
12758         cmdline_fixed_string_t set;
12759         cmdline_fixed_string_t vf;
12760         cmdline_fixed_string_t split;
12761         cmdline_fixed_string_t drop;
12762         portid_t port_id;
12763         uint16_t vf_id;
12764         cmdline_fixed_string_t on_off;
12765 };
12766
12767 /* Common CLI fields for vf split drop enable disable */
12768 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12769         TOKEN_STRING_INITIALIZER
12770                 (struct cmd_vf_split_drop_en_result,
12771                  set, "set");
12772 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_vf_split_drop_en_result,
12775                  vf, "vf");
12776 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12777         TOKEN_STRING_INITIALIZER
12778                 (struct cmd_vf_split_drop_en_result,
12779                  split, "split");
12780 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12781         TOKEN_STRING_INITIALIZER
12782                 (struct cmd_vf_split_drop_en_result,
12783                  drop, "drop");
12784 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12785         TOKEN_NUM_INITIALIZER
12786                 (struct cmd_vf_split_drop_en_result,
12787                  port_id, UINT16);
12788 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12789         TOKEN_NUM_INITIALIZER
12790                 (struct cmd_vf_split_drop_en_result,
12791                  vf_id, UINT16);
12792 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_vf_split_drop_en_result,
12795                  on_off, "on#off");
12796
12797 static void
12798 cmd_set_vf_split_drop_en_parsed(
12799         void *parsed_result,
12800         __attribute__((unused)) struct cmdline *cl,
12801         __attribute__((unused)) void *data)
12802 {
12803         struct cmd_vf_split_drop_en_result *res = parsed_result;
12804         int ret = -ENOTSUP;
12805         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12806
12807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12808                 return;
12809
12810 #ifdef RTE_LIBRTE_IXGBE_PMD
12811         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12812                         is_on);
12813 #endif
12814         switch (ret) {
12815         case 0:
12816                 break;
12817         case -EINVAL:
12818                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12819                 break;
12820         case -ENODEV:
12821                 printf("invalid port_id %d\n", res->port_id);
12822                 break;
12823         case -ENOTSUP:
12824                 printf("not supported on port %d\n", res->port_id);
12825                 break;
12826         default:
12827                 printf("programming error: (%s)\n", strerror(-ret));
12828         }
12829 }
12830
12831 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12832         .f = cmd_set_vf_split_drop_en_parsed,
12833         .data = NULL,
12834         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12835         .tokens = {
12836                 (void *)&cmd_vf_split_drop_en_set,
12837                 (void *)&cmd_vf_split_drop_en_vf,
12838                 (void *)&cmd_vf_split_drop_en_split,
12839                 (void *)&cmd_vf_split_drop_en_drop,
12840                 (void *)&cmd_vf_split_drop_en_port_id,
12841                 (void *)&cmd_vf_split_drop_en_vf_id,
12842                 (void *)&cmd_vf_split_drop_en_on_off,
12843                 NULL,
12844         },
12845 };
12846
12847 /* vf mac address configuration */
12848
12849 /* Common result structure for vf mac address */
12850 struct cmd_set_vf_mac_addr_result {
12851         cmdline_fixed_string_t set;
12852         cmdline_fixed_string_t vf;
12853         cmdline_fixed_string_t mac;
12854         cmdline_fixed_string_t addr;
12855         portid_t port_id;
12856         uint16_t vf_id;
12857         struct ether_addr mac_addr;
12858
12859 };
12860
12861 /* Common CLI fields for vf split drop enable disable */
12862 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_set_vf_mac_addr_result,
12865                  set, "set");
12866 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_set_vf_mac_addr_result,
12869                  vf, "vf");
12870 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_set_vf_mac_addr_result,
12873                  mac, "mac");
12874 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12875         TOKEN_STRING_INITIALIZER
12876                 (struct cmd_set_vf_mac_addr_result,
12877                  addr, "addr");
12878 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12879         TOKEN_NUM_INITIALIZER
12880                 (struct cmd_set_vf_mac_addr_result,
12881                  port_id, UINT16);
12882 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12883         TOKEN_NUM_INITIALIZER
12884                 (struct cmd_set_vf_mac_addr_result,
12885                  vf_id, UINT16);
12886 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12887         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12888                  mac_addr);
12889
12890 static void
12891 cmd_set_vf_mac_addr_parsed(
12892         void *parsed_result,
12893         __attribute__((unused)) struct cmdline *cl,
12894         __attribute__((unused)) void *data)
12895 {
12896         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12897         int ret = -ENOTSUP;
12898
12899         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12900                 return;
12901
12902 #ifdef RTE_LIBRTE_IXGBE_PMD
12903         if (ret == -ENOTSUP)
12904                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12905                                 &res->mac_addr);
12906 #endif
12907 #ifdef RTE_LIBRTE_I40E_PMD
12908         if (ret == -ENOTSUP)
12909                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12910                                 &res->mac_addr);
12911 #endif
12912 #ifdef RTE_LIBRTE_BNXT_PMD
12913         if (ret == -ENOTSUP)
12914                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12915                                 &res->mac_addr);
12916 #endif
12917
12918         switch (ret) {
12919         case 0:
12920                 break;
12921         case -EINVAL:
12922                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12923                 break;
12924         case -ENODEV:
12925                 printf("invalid port_id %d\n", res->port_id);
12926                 break;
12927         case -ENOTSUP:
12928                 printf("function not implemented\n");
12929                 break;
12930         default:
12931                 printf("programming error: (%s)\n", strerror(-ret));
12932         }
12933 }
12934
12935 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12936         .f = cmd_set_vf_mac_addr_parsed,
12937         .data = NULL,
12938         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12939         .tokens = {
12940                 (void *)&cmd_set_vf_mac_addr_set,
12941                 (void *)&cmd_set_vf_mac_addr_vf,
12942                 (void *)&cmd_set_vf_mac_addr_mac,
12943                 (void *)&cmd_set_vf_mac_addr_addr,
12944                 (void *)&cmd_set_vf_mac_addr_port_id,
12945                 (void *)&cmd_set_vf_mac_addr_vf_id,
12946                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12947                 NULL,
12948         },
12949 };
12950
12951 /* MACsec configuration */
12952
12953 /* Common result structure for MACsec offload enable */
12954 struct cmd_macsec_offload_on_result {
12955         cmdline_fixed_string_t set;
12956         cmdline_fixed_string_t macsec;
12957         cmdline_fixed_string_t offload;
12958         portid_t port_id;
12959         cmdline_fixed_string_t on;
12960         cmdline_fixed_string_t encrypt;
12961         cmdline_fixed_string_t en_on_off;
12962         cmdline_fixed_string_t replay_protect;
12963         cmdline_fixed_string_t rp_on_off;
12964 };
12965
12966 /* Common CLI fields for MACsec offload disable */
12967 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_macsec_offload_on_result,
12970                  set, "set");
12971 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_macsec_offload_on_result,
12974                  macsec, "macsec");
12975 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_macsec_offload_on_result,
12978                  offload, "offload");
12979 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12980         TOKEN_NUM_INITIALIZER
12981                 (struct cmd_macsec_offload_on_result,
12982                  port_id, UINT16);
12983 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12984         TOKEN_STRING_INITIALIZER
12985                 (struct cmd_macsec_offload_on_result,
12986                  on, "on");
12987 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12988         TOKEN_STRING_INITIALIZER
12989                 (struct cmd_macsec_offload_on_result,
12990                  encrypt, "encrypt");
12991 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_macsec_offload_on_result,
12994                  en_on_off, "on#off");
12995 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12996         TOKEN_STRING_INITIALIZER
12997                 (struct cmd_macsec_offload_on_result,
12998                  replay_protect, "replay-protect");
12999 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13000         TOKEN_STRING_INITIALIZER
13001                 (struct cmd_macsec_offload_on_result,
13002                  rp_on_off, "on#off");
13003
13004 static void
13005 cmd_set_macsec_offload_on_parsed(
13006         void *parsed_result,
13007         __attribute__((unused)) struct cmdline *cl,
13008         __attribute__((unused)) void *data)
13009 {
13010         struct cmd_macsec_offload_on_result *res = parsed_result;
13011         int ret = -ENOTSUP;
13012         portid_t port_id = res->port_id;
13013         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13014         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13015
13016         if (port_id_is_invalid(port_id, ENABLED_WARN))
13017                 return;
13018         if (!port_is_stopped(port_id)) {
13019                 printf("Please stop port %d first\n", port_id);
13020                 return;
13021         }
13022
13023         ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_MACSEC_INSERT;
13024 #ifdef RTE_LIBRTE_IXGBE_PMD
13025         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13026 #endif
13027         RTE_SET_USED(en);
13028         RTE_SET_USED(rp);
13029
13030         switch (ret) {
13031         case 0:
13032                 cmd_reconfig_device_queue(port_id, 1, 1);
13033                 break;
13034         case -ENODEV:
13035                 printf("invalid port_id %d\n", port_id);
13036                 break;
13037         case -ENOTSUP:
13038                 printf("not supported on port %d\n", port_id);
13039                 break;
13040         default:
13041                 printf("programming error: (%s)\n", strerror(-ret));
13042         }
13043 }
13044
13045 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13046         .f = cmd_set_macsec_offload_on_parsed,
13047         .data = NULL,
13048         .help_str = "set macsec offload <port_id> on "
13049                 "encrypt on|off replay-protect on|off",
13050         .tokens = {
13051                 (void *)&cmd_macsec_offload_on_set,
13052                 (void *)&cmd_macsec_offload_on_macsec,
13053                 (void *)&cmd_macsec_offload_on_offload,
13054                 (void *)&cmd_macsec_offload_on_port_id,
13055                 (void *)&cmd_macsec_offload_on_on,
13056                 (void *)&cmd_macsec_offload_on_encrypt,
13057                 (void *)&cmd_macsec_offload_on_en_on_off,
13058                 (void *)&cmd_macsec_offload_on_replay_protect,
13059                 (void *)&cmd_macsec_offload_on_rp_on_off,
13060                 NULL,
13061         },
13062 };
13063
13064 /* Common result structure for MACsec offload disable */
13065 struct cmd_macsec_offload_off_result {
13066         cmdline_fixed_string_t set;
13067         cmdline_fixed_string_t macsec;
13068         cmdline_fixed_string_t offload;
13069         portid_t port_id;
13070         cmdline_fixed_string_t off;
13071 };
13072
13073 /* Common CLI fields for MACsec offload disable */
13074 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_macsec_offload_off_result,
13077                  set, "set");
13078 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_macsec_offload_off_result,
13081                  macsec, "macsec");
13082 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13083         TOKEN_STRING_INITIALIZER
13084                 (struct cmd_macsec_offload_off_result,
13085                  offload, "offload");
13086 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13087         TOKEN_NUM_INITIALIZER
13088                 (struct cmd_macsec_offload_off_result,
13089                  port_id, UINT16);
13090 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13091         TOKEN_STRING_INITIALIZER
13092                 (struct cmd_macsec_offload_off_result,
13093                  off, "off");
13094
13095 static void
13096 cmd_set_macsec_offload_off_parsed(
13097         void *parsed_result,
13098         __attribute__((unused)) struct cmdline *cl,
13099         __attribute__((unused)) void *data)
13100 {
13101         struct cmd_macsec_offload_off_result *res = parsed_result;
13102         int ret = -ENOTSUP;
13103         portid_t port_id = res->port_id;
13104
13105         if (port_id_is_invalid(port_id, ENABLED_WARN))
13106                 return;
13107         if (!port_is_stopped(port_id)) {
13108                 printf("Please stop port %d first\n", port_id);
13109                 return;
13110         }
13111
13112         ports[port_id].dev_conf.txmode.offloads &=
13113                                         ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13114 #ifdef RTE_LIBRTE_IXGBE_PMD
13115         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13116 #endif
13117
13118         switch (ret) {
13119         case 0:
13120                 cmd_reconfig_device_queue(port_id, 1, 1);
13121                 break;
13122         case -ENODEV:
13123                 printf("invalid port_id %d\n", port_id);
13124                 break;
13125         case -ENOTSUP:
13126                 printf("not supported on port %d\n", port_id);
13127                 break;
13128         default:
13129                 printf("programming error: (%s)\n", strerror(-ret));
13130         }
13131 }
13132
13133 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13134         .f = cmd_set_macsec_offload_off_parsed,
13135         .data = NULL,
13136         .help_str = "set macsec offload <port_id> off",
13137         .tokens = {
13138                 (void *)&cmd_macsec_offload_off_set,
13139                 (void *)&cmd_macsec_offload_off_macsec,
13140                 (void *)&cmd_macsec_offload_off_offload,
13141                 (void *)&cmd_macsec_offload_off_port_id,
13142                 (void *)&cmd_macsec_offload_off_off,
13143                 NULL,
13144         },
13145 };
13146
13147 /* Common result structure for MACsec secure connection configure */
13148 struct cmd_macsec_sc_result {
13149         cmdline_fixed_string_t set;
13150         cmdline_fixed_string_t macsec;
13151         cmdline_fixed_string_t sc;
13152         cmdline_fixed_string_t tx_rx;
13153         portid_t port_id;
13154         struct ether_addr mac;
13155         uint16_t pi;
13156 };
13157
13158 /* Common CLI fields for MACsec secure connection configure */
13159 cmdline_parse_token_string_t cmd_macsec_sc_set =
13160         TOKEN_STRING_INITIALIZER
13161                 (struct cmd_macsec_sc_result,
13162                  set, "set");
13163 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13164         TOKEN_STRING_INITIALIZER
13165                 (struct cmd_macsec_sc_result,
13166                  macsec, "macsec");
13167 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13168         TOKEN_STRING_INITIALIZER
13169                 (struct cmd_macsec_sc_result,
13170                  sc, "sc");
13171 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13172         TOKEN_STRING_INITIALIZER
13173                 (struct cmd_macsec_sc_result,
13174                  tx_rx, "tx#rx");
13175 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13176         TOKEN_NUM_INITIALIZER
13177                 (struct cmd_macsec_sc_result,
13178                  port_id, UINT16);
13179 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13180         TOKEN_ETHERADDR_INITIALIZER
13181                 (struct cmd_macsec_sc_result,
13182                  mac);
13183 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13184         TOKEN_NUM_INITIALIZER
13185                 (struct cmd_macsec_sc_result,
13186                  pi, UINT16);
13187
13188 static void
13189 cmd_set_macsec_sc_parsed(
13190         void *parsed_result,
13191         __attribute__((unused)) struct cmdline *cl,
13192         __attribute__((unused)) void *data)
13193 {
13194         struct cmd_macsec_sc_result *res = parsed_result;
13195         int ret = -ENOTSUP;
13196         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13197
13198 #ifdef RTE_LIBRTE_IXGBE_PMD
13199         ret = is_tx ?
13200                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13201                                 res->mac.addr_bytes) :
13202                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13203                                 res->mac.addr_bytes, res->pi);
13204 #endif
13205         RTE_SET_USED(is_tx);
13206
13207         switch (ret) {
13208         case 0:
13209                 break;
13210         case -ENODEV:
13211                 printf("invalid port_id %d\n", res->port_id);
13212                 break;
13213         case -ENOTSUP:
13214                 printf("not supported on port %d\n", res->port_id);
13215                 break;
13216         default:
13217                 printf("programming error: (%s)\n", strerror(-ret));
13218         }
13219 }
13220
13221 cmdline_parse_inst_t cmd_set_macsec_sc = {
13222         .f = cmd_set_macsec_sc_parsed,
13223         .data = NULL,
13224         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13225         .tokens = {
13226                 (void *)&cmd_macsec_sc_set,
13227                 (void *)&cmd_macsec_sc_macsec,
13228                 (void *)&cmd_macsec_sc_sc,
13229                 (void *)&cmd_macsec_sc_tx_rx,
13230                 (void *)&cmd_macsec_sc_port_id,
13231                 (void *)&cmd_macsec_sc_mac,
13232                 (void *)&cmd_macsec_sc_pi,
13233                 NULL,
13234         },
13235 };
13236
13237 /* Common result structure for MACsec secure connection configure */
13238 struct cmd_macsec_sa_result {
13239         cmdline_fixed_string_t set;
13240         cmdline_fixed_string_t macsec;
13241         cmdline_fixed_string_t sa;
13242         cmdline_fixed_string_t tx_rx;
13243         portid_t port_id;
13244         uint8_t idx;
13245         uint8_t an;
13246         uint32_t pn;
13247         cmdline_fixed_string_t key;
13248 };
13249
13250 /* Common CLI fields for MACsec secure connection configure */
13251 cmdline_parse_token_string_t cmd_macsec_sa_set =
13252         TOKEN_STRING_INITIALIZER
13253                 (struct cmd_macsec_sa_result,
13254                  set, "set");
13255 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13256         TOKEN_STRING_INITIALIZER
13257                 (struct cmd_macsec_sa_result,
13258                  macsec, "macsec");
13259 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13260         TOKEN_STRING_INITIALIZER
13261                 (struct cmd_macsec_sa_result,
13262                  sa, "sa");
13263 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13264         TOKEN_STRING_INITIALIZER
13265                 (struct cmd_macsec_sa_result,
13266                  tx_rx, "tx#rx");
13267 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13268         TOKEN_NUM_INITIALIZER
13269                 (struct cmd_macsec_sa_result,
13270                  port_id, UINT16);
13271 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13272         TOKEN_NUM_INITIALIZER
13273                 (struct cmd_macsec_sa_result,
13274                  idx, UINT8);
13275 cmdline_parse_token_num_t cmd_macsec_sa_an =
13276         TOKEN_NUM_INITIALIZER
13277                 (struct cmd_macsec_sa_result,
13278                  an, UINT8);
13279 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13280         TOKEN_NUM_INITIALIZER
13281                 (struct cmd_macsec_sa_result,
13282                  pn, UINT32);
13283 cmdline_parse_token_string_t cmd_macsec_sa_key =
13284         TOKEN_STRING_INITIALIZER
13285                 (struct cmd_macsec_sa_result,
13286                  key, NULL);
13287
13288 static void
13289 cmd_set_macsec_sa_parsed(
13290         void *parsed_result,
13291         __attribute__((unused)) struct cmdline *cl,
13292         __attribute__((unused)) void *data)
13293 {
13294         struct cmd_macsec_sa_result *res = parsed_result;
13295         int ret = -ENOTSUP;
13296         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13297         uint8_t key[16] = { 0 };
13298         uint8_t xdgt0;
13299         uint8_t xdgt1;
13300         int key_len;
13301         int i;
13302
13303         key_len = strlen(res->key) / 2;
13304         if (key_len > 16)
13305                 key_len = 16;
13306
13307         for (i = 0; i < key_len; i++) {
13308                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13309                 if (xdgt0 == 0xFF)
13310                         return;
13311                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13312                 if (xdgt1 == 0xFF)
13313                         return;
13314                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13315         }
13316
13317 #ifdef RTE_LIBRTE_IXGBE_PMD
13318         ret = is_tx ?
13319                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13320                         res->idx, res->an, res->pn, key) :
13321                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13322                         res->idx, res->an, res->pn, key);
13323 #endif
13324         RTE_SET_USED(is_tx);
13325         RTE_SET_USED(key);
13326
13327         switch (ret) {
13328         case 0:
13329                 break;
13330         case -EINVAL:
13331                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13332                 break;
13333         case -ENODEV:
13334                 printf("invalid port_id %d\n", res->port_id);
13335                 break;
13336         case -ENOTSUP:
13337                 printf("not supported on port %d\n", res->port_id);
13338                 break;
13339         default:
13340                 printf("programming error: (%s)\n", strerror(-ret));
13341         }
13342 }
13343
13344 cmdline_parse_inst_t cmd_set_macsec_sa = {
13345         .f = cmd_set_macsec_sa_parsed,
13346         .data = NULL,
13347         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13348         .tokens = {
13349                 (void *)&cmd_macsec_sa_set,
13350                 (void *)&cmd_macsec_sa_macsec,
13351                 (void *)&cmd_macsec_sa_sa,
13352                 (void *)&cmd_macsec_sa_tx_rx,
13353                 (void *)&cmd_macsec_sa_port_id,
13354                 (void *)&cmd_macsec_sa_idx,
13355                 (void *)&cmd_macsec_sa_an,
13356                 (void *)&cmd_macsec_sa_pn,
13357                 (void *)&cmd_macsec_sa_key,
13358                 NULL,
13359         },
13360 };
13361
13362 /* VF unicast promiscuous mode configuration */
13363
13364 /* Common result structure for VF unicast promiscuous mode */
13365 struct cmd_vf_promisc_result {
13366         cmdline_fixed_string_t set;
13367         cmdline_fixed_string_t vf;
13368         cmdline_fixed_string_t promisc;
13369         portid_t port_id;
13370         uint32_t vf_id;
13371         cmdline_fixed_string_t on_off;
13372 };
13373
13374 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13375 cmdline_parse_token_string_t cmd_vf_promisc_set =
13376         TOKEN_STRING_INITIALIZER
13377                 (struct cmd_vf_promisc_result,
13378                  set, "set");
13379 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13380         TOKEN_STRING_INITIALIZER
13381                 (struct cmd_vf_promisc_result,
13382                  vf, "vf");
13383 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13384         TOKEN_STRING_INITIALIZER
13385                 (struct cmd_vf_promisc_result,
13386                  promisc, "promisc");
13387 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13388         TOKEN_NUM_INITIALIZER
13389                 (struct cmd_vf_promisc_result,
13390                  port_id, UINT16);
13391 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13392         TOKEN_NUM_INITIALIZER
13393                 (struct cmd_vf_promisc_result,
13394                  vf_id, UINT32);
13395 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13396         TOKEN_STRING_INITIALIZER
13397                 (struct cmd_vf_promisc_result,
13398                  on_off, "on#off");
13399
13400 static void
13401 cmd_set_vf_promisc_parsed(
13402         void *parsed_result,
13403         __attribute__((unused)) struct cmdline *cl,
13404         __attribute__((unused)) void *data)
13405 {
13406         struct cmd_vf_promisc_result *res = parsed_result;
13407         int ret = -ENOTSUP;
13408
13409         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13410
13411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13412                 return;
13413
13414 #ifdef RTE_LIBRTE_I40E_PMD
13415         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13416                                                   res->vf_id, is_on);
13417 #endif
13418
13419         switch (ret) {
13420         case 0:
13421                 break;
13422         case -EINVAL:
13423                 printf("invalid vf_id %d\n", res->vf_id);
13424                 break;
13425         case -ENODEV:
13426                 printf("invalid port_id %d\n", res->port_id);
13427                 break;
13428         case -ENOTSUP:
13429                 printf("function not implemented\n");
13430                 break;
13431         default:
13432                 printf("programming error: (%s)\n", strerror(-ret));
13433         }
13434 }
13435
13436 cmdline_parse_inst_t cmd_set_vf_promisc = {
13437         .f = cmd_set_vf_promisc_parsed,
13438         .data = NULL,
13439         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13440                 "Set unicast promiscuous mode for a VF from the PF",
13441         .tokens = {
13442                 (void *)&cmd_vf_promisc_set,
13443                 (void *)&cmd_vf_promisc_vf,
13444                 (void *)&cmd_vf_promisc_promisc,
13445                 (void *)&cmd_vf_promisc_port_id,
13446                 (void *)&cmd_vf_promisc_vf_id,
13447                 (void *)&cmd_vf_promisc_on_off,
13448                 NULL,
13449         },
13450 };
13451
13452 /* VF multicast promiscuous mode configuration */
13453
13454 /* Common result structure for VF multicast promiscuous mode */
13455 struct cmd_vf_allmulti_result {
13456         cmdline_fixed_string_t set;
13457         cmdline_fixed_string_t vf;
13458         cmdline_fixed_string_t allmulti;
13459         portid_t port_id;
13460         uint32_t vf_id;
13461         cmdline_fixed_string_t on_off;
13462 };
13463
13464 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13465 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13466         TOKEN_STRING_INITIALIZER
13467                 (struct cmd_vf_allmulti_result,
13468                  set, "set");
13469 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_vf_allmulti_result,
13472                  vf, "vf");
13473 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_vf_allmulti_result,
13476                  allmulti, "allmulti");
13477 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13478         TOKEN_NUM_INITIALIZER
13479                 (struct cmd_vf_allmulti_result,
13480                  port_id, UINT16);
13481 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13482         TOKEN_NUM_INITIALIZER
13483                 (struct cmd_vf_allmulti_result,
13484                  vf_id, UINT32);
13485 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13486         TOKEN_STRING_INITIALIZER
13487                 (struct cmd_vf_allmulti_result,
13488                  on_off, "on#off");
13489
13490 static void
13491 cmd_set_vf_allmulti_parsed(
13492         void *parsed_result,
13493         __attribute__((unused)) struct cmdline *cl,
13494         __attribute__((unused)) void *data)
13495 {
13496         struct cmd_vf_allmulti_result *res = parsed_result;
13497         int ret = -ENOTSUP;
13498
13499         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13500
13501         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13502                 return;
13503
13504 #ifdef RTE_LIBRTE_I40E_PMD
13505         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13506                                                     res->vf_id, is_on);
13507 #endif
13508
13509         switch (ret) {
13510         case 0:
13511                 break;
13512         case -EINVAL:
13513                 printf("invalid vf_id %d\n", res->vf_id);
13514                 break;
13515         case -ENODEV:
13516                 printf("invalid port_id %d\n", res->port_id);
13517                 break;
13518         case -ENOTSUP:
13519                 printf("function not implemented\n");
13520                 break;
13521         default:
13522                 printf("programming error: (%s)\n", strerror(-ret));
13523         }
13524 }
13525
13526 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13527         .f = cmd_set_vf_allmulti_parsed,
13528         .data = NULL,
13529         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13530                 "Set multicast promiscuous mode for a VF from the PF",
13531         .tokens = {
13532                 (void *)&cmd_vf_allmulti_set,
13533                 (void *)&cmd_vf_allmulti_vf,
13534                 (void *)&cmd_vf_allmulti_allmulti,
13535                 (void *)&cmd_vf_allmulti_port_id,
13536                 (void *)&cmd_vf_allmulti_vf_id,
13537                 (void *)&cmd_vf_allmulti_on_off,
13538                 NULL,
13539         },
13540 };
13541
13542 /* vf broadcast mode configuration */
13543
13544 /* Common result structure for vf broadcast */
13545 struct cmd_set_vf_broadcast_result {
13546         cmdline_fixed_string_t set;
13547         cmdline_fixed_string_t vf;
13548         cmdline_fixed_string_t broadcast;
13549         portid_t port_id;
13550         uint16_t vf_id;
13551         cmdline_fixed_string_t on_off;
13552 };
13553
13554 /* Common CLI fields for vf broadcast enable disable */
13555 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13556         TOKEN_STRING_INITIALIZER
13557                 (struct cmd_set_vf_broadcast_result,
13558                  set, "set");
13559 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13560         TOKEN_STRING_INITIALIZER
13561                 (struct cmd_set_vf_broadcast_result,
13562                  vf, "vf");
13563 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13564         TOKEN_STRING_INITIALIZER
13565                 (struct cmd_set_vf_broadcast_result,
13566                  broadcast, "broadcast");
13567 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13568         TOKEN_NUM_INITIALIZER
13569                 (struct cmd_set_vf_broadcast_result,
13570                  port_id, UINT16);
13571 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13572         TOKEN_NUM_INITIALIZER
13573                 (struct cmd_set_vf_broadcast_result,
13574                  vf_id, UINT16);
13575 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13576         TOKEN_STRING_INITIALIZER
13577                 (struct cmd_set_vf_broadcast_result,
13578                  on_off, "on#off");
13579
13580 static void
13581 cmd_set_vf_broadcast_parsed(
13582         void *parsed_result,
13583         __attribute__((unused)) struct cmdline *cl,
13584         __attribute__((unused)) void *data)
13585 {
13586         struct cmd_set_vf_broadcast_result *res = parsed_result;
13587         int ret = -ENOTSUP;
13588
13589         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13590
13591         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13592                 return;
13593
13594 #ifdef RTE_LIBRTE_I40E_PMD
13595         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13596                                             res->vf_id, is_on);
13597 #endif
13598
13599         switch (ret) {
13600         case 0:
13601                 break;
13602         case -EINVAL:
13603                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13604                 break;
13605         case -ENODEV:
13606                 printf("invalid port_id %d\n", res->port_id);
13607                 break;
13608         case -ENOTSUP:
13609                 printf("function not implemented\n");
13610                 break;
13611         default:
13612                 printf("programming error: (%s)\n", strerror(-ret));
13613         }
13614 }
13615
13616 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13617         .f = cmd_set_vf_broadcast_parsed,
13618         .data = NULL,
13619         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13620         .tokens = {
13621                 (void *)&cmd_set_vf_broadcast_set,
13622                 (void *)&cmd_set_vf_broadcast_vf,
13623                 (void *)&cmd_set_vf_broadcast_broadcast,
13624                 (void *)&cmd_set_vf_broadcast_port_id,
13625                 (void *)&cmd_set_vf_broadcast_vf_id,
13626                 (void *)&cmd_set_vf_broadcast_on_off,
13627                 NULL,
13628         },
13629 };
13630
13631 /* vf vlan tag configuration */
13632
13633 /* Common result structure for vf vlan tag */
13634 struct cmd_set_vf_vlan_tag_result {
13635         cmdline_fixed_string_t set;
13636         cmdline_fixed_string_t vf;
13637         cmdline_fixed_string_t vlan;
13638         cmdline_fixed_string_t tag;
13639         portid_t port_id;
13640         uint16_t vf_id;
13641         cmdline_fixed_string_t on_off;
13642 };
13643
13644 /* Common CLI fields for vf vlan tag enable disable */
13645 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13646         TOKEN_STRING_INITIALIZER
13647                 (struct cmd_set_vf_vlan_tag_result,
13648                  set, "set");
13649 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13650         TOKEN_STRING_INITIALIZER
13651                 (struct cmd_set_vf_vlan_tag_result,
13652                  vf, "vf");
13653 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13654         TOKEN_STRING_INITIALIZER
13655                 (struct cmd_set_vf_vlan_tag_result,
13656                  vlan, "vlan");
13657 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13658         TOKEN_STRING_INITIALIZER
13659                 (struct cmd_set_vf_vlan_tag_result,
13660                  tag, "tag");
13661 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13662         TOKEN_NUM_INITIALIZER
13663                 (struct cmd_set_vf_vlan_tag_result,
13664                  port_id, UINT16);
13665 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13666         TOKEN_NUM_INITIALIZER
13667                 (struct cmd_set_vf_vlan_tag_result,
13668                  vf_id, UINT16);
13669 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13670         TOKEN_STRING_INITIALIZER
13671                 (struct cmd_set_vf_vlan_tag_result,
13672                  on_off, "on#off");
13673
13674 static void
13675 cmd_set_vf_vlan_tag_parsed(
13676         void *parsed_result,
13677         __attribute__((unused)) struct cmdline *cl,
13678         __attribute__((unused)) void *data)
13679 {
13680         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13681         int ret = -ENOTSUP;
13682
13683         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13684
13685         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13686                 return;
13687
13688 #ifdef RTE_LIBRTE_I40E_PMD
13689         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13690                                            res->vf_id, is_on);
13691 #endif
13692
13693         switch (ret) {
13694         case 0:
13695                 break;
13696         case -EINVAL:
13697                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13698                 break;
13699         case -ENODEV:
13700                 printf("invalid port_id %d\n", res->port_id);
13701                 break;
13702         case -ENOTSUP:
13703                 printf("function not implemented\n");
13704                 break;
13705         default:
13706                 printf("programming error: (%s)\n", strerror(-ret));
13707         }
13708 }
13709
13710 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13711         .f = cmd_set_vf_vlan_tag_parsed,
13712         .data = NULL,
13713         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13714         .tokens = {
13715                 (void *)&cmd_set_vf_vlan_tag_set,
13716                 (void *)&cmd_set_vf_vlan_tag_vf,
13717                 (void *)&cmd_set_vf_vlan_tag_vlan,
13718                 (void *)&cmd_set_vf_vlan_tag_tag,
13719                 (void *)&cmd_set_vf_vlan_tag_port_id,
13720                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13721                 (void *)&cmd_set_vf_vlan_tag_on_off,
13722                 NULL,
13723         },
13724 };
13725
13726 /* Common definition of VF and TC TX bandwidth configuration */
13727 struct cmd_vf_tc_bw_result {
13728         cmdline_fixed_string_t set;
13729         cmdline_fixed_string_t vf;
13730         cmdline_fixed_string_t tc;
13731         cmdline_fixed_string_t tx;
13732         cmdline_fixed_string_t min_bw;
13733         cmdline_fixed_string_t max_bw;
13734         cmdline_fixed_string_t strict_link_prio;
13735         portid_t port_id;
13736         uint16_t vf_id;
13737         uint8_t tc_no;
13738         uint32_t bw;
13739         cmdline_fixed_string_t bw_list;
13740         uint8_t tc_map;
13741 };
13742
13743 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_vf_tc_bw_result,
13746                  set, "set");
13747 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13748         TOKEN_STRING_INITIALIZER
13749                 (struct cmd_vf_tc_bw_result,
13750                  vf, "vf");
13751 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13752         TOKEN_STRING_INITIALIZER
13753                 (struct cmd_vf_tc_bw_result,
13754                  tc, "tc");
13755 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13756         TOKEN_STRING_INITIALIZER
13757                 (struct cmd_vf_tc_bw_result,
13758                  tx, "tx");
13759 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13760         TOKEN_STRING_INITIALIZER
13761                 (struct cmd_vf_tc_bw_result,
13762                  strict_link_prio, "strict-link-priority");
13763 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13764         TOKEN_STRING_INITIALIZER
13765                 (struct cmd_vf_tc_bw_result,
13766                  min_bw, "min-bandwidth");
13767 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13768         TOKEN_STRING_INITIALIZER
13769                 (struct cmd_vf_tc_bw_result,
13770                  max_bw, "max-bandwidth");
13771 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13772         TOKEN_NUM_INITIALIZER
13773                 (struct cmd_vf_tc_bw_result,
13774                  port_id, UINT16);
13775 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13776         TOKEN_NUM_INITIALIZER
13777                 (struct cmd_vf_tc_bw_result,
13778                  vf_id, UINT16);
13779 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13780         TOKEN_NUM_INITIALIZER
13781                 (struct cmd_vf_tc_bw_result,
13782                  tc_no, UINT8);
13783 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13784         TOKEN_NUM_INITIALIZER
13785                 (struct cmd_vf_tc_bw_result,
13786                  bw, UINT32);
13787 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13788         TOKEN_STRING_INITIALIZER
13789                 (struct cmd_vf_tc_bw_result,
13790                  bw_list, NULL);
13791 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13792         TOKEN_NUM_INITIALIZER
13793                 (struct cmd_vf_tc_bw_result,
13794                  tc_map, UINT8);
13795
13796 /* VF max bandwidth setting */
13797 static void
13798 cmd_vf_max_bw_parsed(
13799         void *parsed_result,
13800         __attribute__((unused)) struct cmdline *cl,
13801         __attribute__((unused)) void *data)
13802 {
13803         struct cmd_vf_tc_bw_result *res = parsed_result;
13804         int ret = -ENOTSUP;
13805
13806         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13807                 return;
13808
13809 #ifdef RTE_LIBRTE_I40E_PMD
13810         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13811                                          res->vf_id, res->bw);
13812 #endif
13813
13814         switch (ret) {
13815         case 0:
13816                 break;
13817         case -EINVAL:
13818                 printf("invalid vf_id %d or bandwidth %d\n",
13819                        res->vf_id, res->bw);
13820                 break;
13821         case -ENODEV:
13822                 printf("invalid port_id %d\n", res->port_id);
13823                 break;
13824         case -ENOTSUP:
13825                 printf("function not implemented\n");
13826                 break;
13827         default:
13828                 printf("programming error: (%s)\n", strerror(-ret));
13829         }
13830 }
13831
13832 cmdline_parse_inst_t cmd_vf_max_bw = {
13833         .f = cmd_vf_max_bw_parsed,
13834         .data = NULL,
13835         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13836         .tokens = {
13837                 (void *)&cmd_vf_tc_bw_set,
13838                 (void *)&cmd_vf_tc_bw_vf,
13839                 (void *)&cmd_vf_tc_bw_tx,
13840                 (void *)&cmd_vf_tc_bw_max_bw,
13841                 (void *)&cmd_vf_tc_bw_port_id,
13842                 (void *)&cmd_vf_tc_bw_vf_id,
13843                 (void *)&cmd_vf_tc_bw_bw,
13844                 NULL,
13845         },
13846 };
13847
13848 static int
13849 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13850                            uint8_t *tc_num,
13851                            char *str)
13852 {
13853         uint32_t size;
13854         const char *p, *p0 = str;
13855         char s[256];
13856         char *end;
13857         char *str_fld[16];
13858         uint16_t i;
13859         int ret;
13860
13861         p = strchr(p0, '(');
13862         if (p == NULL) {
13863                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13864                 return -1;
13865         }
13866         p++;
13867         p0 = strchr(p, ')');
13868         if (p0 == NULL) {
13869                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13870                 return -1;
13871         }
13872         size = p0 - p;
13873         if (size >= sizeof(s)) {
13874                 printf("The string size exceeds the internal buffer size\n");
13875                 return -1;
13876         }
13877         snprintf(s, sizeof(s), "%.*s", size, p);
13878         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13879         if (ret <= 0) {
13880                 printf("Failed to get the bandwidth list. ");
13881                 return -1;
13882         }
13883         *tc_num = ret;
13884         for (i = 0; i < ret; i++)
13885                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13886
13887         return 0;
13888 }
13889
13890 /* TC min bandwidth setting */
13891 static void
13892 cmd_vf_tc_min_bw_parsed(
13893         void *parsed_result,
13894         __attribute__((unused)) struct cmdline *cl,
13895         __attribute__((unused)) void *data)
13896 {
13897         struct cmd_vf_tc_bw_result *res = parsed_result;
13898         uint8_t tc_num;
13899         uint8_t bw[16];
13900         int ret = -ENOTSUP;
13901
13902         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13903                 return;
13904
13905         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13906         if (ret)
13907                 return;
13908
13909 #ifdef RTE_LIBRTE_I40E_PMD
13910         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13911                                               tc_num, bw);
13912 #endif
13913
13914         switch (ret) {
13915         case 0:
13916                 break;
13917         case -EINVAL:
13918                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13919                 break;
13920         case -ENODEV:
13921                 printf("invalid port_id %d\n", res->port_id);
13922                 break;
13923         case -ENOTSUP:
13924                 printf("function not implemented\n");
13925                 break;
13926         default:
13927                 printf("programming error: (%s)\n", strerror(-ret));
13928         }
13929 }
13930
13931 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13932         .f = cmd_vf_tc_min_bw_parsed,
13933         .data = NULL,
13934         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13935                     " <bw1, bw2, ...>",
13936         .tokens = {
13937                 (void *)&cmd_vf_tc_bw_set,
13938                 (void *)&cmd_vf_tc_bw_vf,
13939                 (void *)&cmd_vf_tc_bw_tc,
13940                 (void *)&cmd_vf_tc_bw_tx,
13941                 (void *)&cmd_vf_tc_bw_min_bw,
13942                 (void *)&cmd_vf_tc_bw_port_id,
13943                 (void *)&cmd_vf_tc_bw_vf_id,
13944                 (void *)&cmd_vf_tc_bw_bw_list,
13945                 NULL,
13946         },
13947 };
13948
13949 static void
13950 cmd_tc_min_bw_parsed(
13951         void *parsed_result,
13952         __attribute__((unused)) struct cmdline *cl,
13953         __attribute__((unused)) void *data)
13954 {
13955         struct cmd_vf_tc_bw_result *res = parsed_result;
13956         struct rte_port *port;
13957         uint8_t tc_num;
13958         uint8_t bw[16];
13959         int ret = -ENOTSUP;
13960
13961         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13962                 return;
13963
13964         port = &ports[res->port_id];
13965         /** Check if the port is not started **/
13966         if (port->port_status != RTE_PORT_STOPPED) {
13967                 printf("Please stop port %d first\n", res->port_id);
13968                 return;
13969         }
13970
13971         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13972         if (ret)
13973                 return;
13974
13975 #ifdef RTE_LIBRTE_IXGBE_PMD
13976         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13977 #endif
13978
13979         switch (ret) {
13980         case 0:
13981                 break;
13982         case -EINVAL:
13983                 printf("invalid bandwidth\n");
13984                 break;
13985         case -ENODEV:
13986                 printf("invalid port_id %d\n", res->port_id);
13987                 break;
13988         case -ENOTSUP:
13989                 printf("function not implemented\n");
13990                 break;
13991         default:
13992                 printf("programming error: (%s)\n", strerror(-ret));
13993         }
13994 }
13995
13996 cmdline_parse_inst_t cmd_tc_min_bw = {
13997         .f = cmd_tc_min_bw_parsed,
13998         .data = NULL,
13999         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14000         .tokens = {
14001                 (void *)&cmd_vf_tc_bw_set,
14002                 (void *)&cmd_vf_tc_bw_tc,
14003                 (void *)&cmd_vf_tc_bw_tx,
14004                 (void *)&cmd_vf_tc_bw_min_bw,
14005                 (void *)&cmd_vf_tc_bw_port_id,
14006                 (void *)&cmd_vf_tc_bw_bw_list,
14007                 NULL,
14008         },
14009 };
14010
14011 /* TC max bandwidth setting */
14012 static void
14013 cmd_vf_tc_max_bw_parsed(
14014         void *parsed_result,
14015         __attribute__((unused)) struct cmdline *cl,
14016         __attribute__((unused)) void *data)
14017 {
14018         struct cmd_vf_tc_bw_result *res = parsed_result;
14019         int ret = -ENOTSUP;
14020
14021         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14022                 return;
14023
14024 #ifdef RTE_LIBRTE_I40E_PMD
14025         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14026                                             res->tc_no, res->bw);
14027 #endif
14028
14029         switch (ret) {
14030         case 0:
14031                 break;
14032         case -EINVAL:
14033                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14034                        res->vf_id, res->tc_no, res->bw);
14035                 break;
14036         case -ENODEV:
14037                 printf("invalid port_id %d\n", res->port_id);
14038                 break;
14039         case -ENOTSUP:
14040                 printf("function not implemented\n");
14041                 break;
14042         default:
14043                 printf("programming error: (%s)\n", strerror(-ret));
14044         }
14045 }
14046
14047 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14048         .f = cmd_vf_tc_max_bw_parsed,
14049         .data = NULL,
14050         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14051                     " <bandwidth>",
14052         .tokens = {
14053                 (void *)&cmd_vf_tc_bw_set,
14054                 (void *)&cmd_vf_tc_bw_vf,
14055                 (void *)&cmd_vf_tc_bw_tc,
14056                 (void *)&cmd_vf_tc_bw_tx,
14057                 (void *)&cmd_vf_tc_bw_max_bw,
14058                 (void *)&cmd_vf_tc_bw_port_id,
14059                 (void *)&cmd_vf_tc_bw_vf_id,
14060                 (void *)&cmd_vf_tc_bw_tc_no,
14061                 (void *)&cmd_vf_tc_bw_bw,
14062                 NULL,
14063         },
14064 };
14065
14066
14067 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14068
14069 /* *** Set Port default Traffic Management Hierarchy *** */
14070 struct cmd_set_port_tm_hierarchy_default_result {
14071         cmdline_fixed_string_t set;
14072         cmdline_fixed_string_t port;
14073         cmdline_fixed_string_t tm;
14074         cmdline_fixed_string_t hierarchy;
14075         cmdline_fixed_string_t def;
14076         portid_t port_id;
14077 };
14078
14079 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14080         TOKEN_STRING_INITIALIZER(
14081                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14082 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14083         TOKEN_STRING_INITIALIZER(
14084                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14085 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14086         TOKEN_STRING_INITIALIZER(
14087                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14088 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14089         TOKEN_STRING_INITIALIZER(
14090                 struct cmd_set_port_tm_hierarchy_default_result,
14091                         hierarchy, "hierarchy");
14092 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14093         TOKEN_STRING_INITIALIZER(
14094                 struct cmd_set_port_tm_hierarchy_default_result,
14095                         def, "default");
14096 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14097         TOKEN_NUM_INITIALIZER(
14098                 struct cmd_set_port_tm_hierarchy_default_result,
14099                         port_id, UINT16);
14100
14101 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14102         __attribute__((unused)) struct cmdline *cl,
14103         __attribute__((unused)) void *data)
14104 {
14105         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14106         struct rte_port *p;
14107         portid_t port_id = res->port_id;
14108
14109         if (port_id_is_invalid(port_id, ENABLED_WARN))
14110                 return;
14111
14112         p = &ports[port_id];
14113
14114         /* Port tm flag */
14115         if (p->softport.tm_flag == 0) {
14116                 printf("  tm not enabled on port %u (error)\n", port_id);
14117                 return;
14118         }
14119
14120         /* Forward mode: tm */
14121         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14122                 printf("  tm mode not enabled(error)\n");
14123                 return;
14124         }
14125
14126         /* Set the default tm hierarchy */
14127         p->softport.tm.default_hierarchy_enable = 1;
14128 }
14129
14130 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14131         .f = cmd_set_port_tm_hierarchy_default_parsed,
14132         .data = NULL,
14133         .help_str = "set port tm hierarchy default <port_id>",
14134         .tokens = {
14135                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14136                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14137                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14138                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14139                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14140                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14141                 NULL,
14142         },
14143 };
14144 #endif
14145
14146 /* Strict link priority scheduling mode setting */
14147 static void
14148 cmd_strict_link_prio_parsed(
14149         void *parsed_result,
14150         __attribute__((unused)) struct cmdline *cl,
14151         __attribute__((unused)) void *data)
14152 {
14153         struct cmd_vf_tc_bw_result *res = parsed_result;
14154         int ret = -ENOTSUP;
14155
14156         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14157                 return;
14158
14159 #ifdef RTE_LIBRTE_I40E_PMD
14160         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14161 #endif
14162
14163         switch (ret) {
14164         case 0:
14165                 break;
14166         case -EINVAL:
14167                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14168                 break;
14169         case -ENODEV:
14170                 printf("invalid port_id %d\n", res->port_id);
14171                 break;
14172         case -ENOTSUP:
14173                 printf("function not implemented\n");
14174                 break;
14175         default:
14176                 printf("programming error: (%s)\n", strerror(-ret));
14177         }
14178 }
14179
14180 cmdline_parse_inst_t cmd_strict_link_prio = {
14181         .f = cmd_strict_link_prio_parsed,
14182         .data = NULL,
14183         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14184         .tokens = {
14185                 (void *)&cmd_vf_tc_bw_set,
14186                 (void *)&cmd_vf_tc_bw_tx,
14187                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14188                 (void *)&cmd_vf_tc_bw_port_id,
14189                 (void *)&cmd_vf_tc_bw_tc_map,
14190                 NULL,
14191         },
14192 };
14193
14194 /* Load dynamic device personalization*/
14195 struct cmd_ddp_add_result {
14196         cmdline_fixed_string_t ddp;
14197         cmdline_fixed_string_t add;
14198         portid_t port_id;
14199         char filepath[];
14200 };
14201
14202 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14203         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14204 cmdline_parse_token_string_t cmd_ddp_add_add =
14205         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14206 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14207         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14208 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14209         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14210
14211 static void
14212 cmd_ddp_add_parsed(
14213         void *parsed_result,
14214         __attribute__((unused)) struct cmdline *cl,
14215         __attribute__((unused)) void *data)
14216 {
14217         struct cmd_ddp_add_result *res = parsed_result;
14218         uint8_t *buff;
14219         uint32_t size;
14220         char *filepath;
14221         char *file_fld[2];
14222         int file_num;
14223         int ret = -ENOTSUP;
14224
14225         if (res->port_id > nb_ports) {
14226                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14227                 return;
14228         }
14229
14230         if (!all_ports_stopped()) {
14231                 printf("Please stop all ports first\n");
14232                 return;
14233         }
14234
14235         filepath = strdup(res->filepath);
14236         if (filepath == NULL) {
14237                 printf("Failed to allocate memory\n");
14238                 return;
14239         }
14240         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14241
14242         buff = open_ddp_package_file(file_fld[0], &size);
14243         if (!buff) {
14244                 free((void *)filepath);
14245                 return;
14246         }
14247
14248 #ifdef RTE_LIBRTE_I40E_PMD
14249         if (ret == -ENOTSUP)
14250                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14251                                                buff, size,
14252                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14253 #endif
14254
14255         if (ret == -EEXIST)
14256                 printf("Profile has already existed.\n");
14257         else if (ret < 0)
14258                 printf("Failed to load profile.\n");
14259         else if (file_num == 2)
14260                 save_ddp_package_file(file_fld[1], buff, size);
14261
14262         close_ddp_package_file(buff);
14263         free((void *)filepath);
14264 }
14265
14266 cmdline_parse_inst_t cmd_ddp_add = {
14267         .f = cmd_ddp_add_parsed,
14268         .data = NULL,
14269         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14270         .tokens = {
14271                 (void *)&cmd_ddp_add_ddp,
14272                 (void *)&cmd_ddp_add_add,
14273                 (void *)&cmd_ddp_add_port_id,
14274                 (void *)&cmd_ddp_add_filepath,
14275                 NULL,
14276         },
14277 };
14278
14279 /* Delete dynamic device personalization*/
14280 struct cmd_ddp_del_result {
14281         cmdline_fixed_string_t ddp;
14282         cmdline_fixed_string_t del;
14283         portid_t port_id;
14284         char filepath[];
14285 };
14286
14287 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14288         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14289 cmdline_parse_token_string_t cmd_ddp_del_del =
14290         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14291 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14292         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14293 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14294         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14295
14296 static void
14297 cmd_ddp_del_parsed(
14298         void *parsed_result,
14299         __attribute__((unused)) struct cmdline *cl,
14300         __attribute__((unused)) void *data)
14301 {
14302         struct cmd_ddp_del_result *res = parsed_result;
14303         uint8_t *buff;
14304         uint32_t size;
14305         int ret = -ENOTSUP;
14306
14307         if (res->port_id > nb_ports) {
14308                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14309                 return;
14310         }
14311
14312         if (!all_ports_stopped()) {
14313                 printf("Please stop all ports first\n");
14314                 return;
14315         }
14316
14317         buff = open_ddp_package_file(res->filepath, &size);
14318         if (!buff)
14319                 return;
14320
14321 #ifdef RTE_LIBRTE_I40E_PMD
14322         if (ret == -ENOTSUP)
14323                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14324                                                buff, size,
14325                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14326 #endif
14327
14328         if (ret == -EACCES)
14329                 printf("Profile does not exist.\n");
14330         else if (ret < 0)
14331                 printf("Failed to delete profile.\n");
14332
14333         close_ddp_package_file(buff);
14334 }
14335
14336 cmdline_parse_inst_t cmd_ddp_del = {
14337         .f = cmd_ddp_del_parsed,
14338         .data = NULL,
14339         .help_str = "ddp del <port_id> <profile_path>",
14340         .tokens = {
14341                 (void *)&cmd_ddp_del_ddp,
14342                 (void *)&cmd_ddp_del_del,
14343                 (void *)&cmd_ddp_del_port_id,
14344                 (void *)&cmd_ddp_del_filepath,
14345                 NULL,
14346         },
14347 };
14348
14349 /* Get dynamic device personalization profile info */
14350 struct cmd_ddp_info_result {
14351         cmdline_fixed_string_t ddp;
14352         cmdline_fixed_string_t get;
14353         cmdline_fixed_string_t info;
14354         char filepath[];
14355 };
14356
14357 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14358         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14359 cmdline_parse_token_string_t cmd_ddp_info_get =
14360         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14361 cmdline_parse_token_string_t cmd_ddp_info_info =
14362         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14363 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14364         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14365
14366 static void
14367 cmd_ddp_info_parsed(
14368         void *parsed_result,
14369         __attribute__((unused)) struct cmdline *cl,
14370         __attribute__((unused)) void *data)
14371 {
14372         struct cmd_ddp_info_result *res = parsed_result;
14373         uint8_t *pkg;
14374         uint32_t pkg_size;
14375         int ret = -ENOTSUP;
14376 #ifdef RTE_LIBRTE_I40E_PMD
14377         uint32_t i, j, n;
14378         uint8_t *buff;
14379         uint32_t buff_size = 0;
14380         struct rte_pmd_i40e_profile_info info;
14381         uint32_t dev_num = 0;
14382         struct rte_pmd_i40e_ddp_device_id *devs;
14383         uint32_t proto_num = 0;
14384         struct rte_pmd_i40e_proto_info *proto = NULL;
14385         uint32_t pctype_num = 0;
14386         struct rte_pmd_i40e_ptype_info *pctype;
14387         uint32_t ptype_num = 0;
14388         struct rte_pmd_i40e_ptype_info *ptype;
14389         uint8_t proto_id;
14390
14391 #endif
14392
14393         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14394         if (!pkg)
14395                 return;
14396
14397 #ifdef RTE_LIBRTE_I40E_PMD
14398         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14399                                 (uint8_t *)&info, sizeof(info),
14400                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14401         if (!ret) {
14402                 printf("Global Track id:       0x%x\n", info.track_id);
14403                 printf("Global Version:        %d.%d.%d.%d\n",
14404                         info.version.major,
14405                         info.version.minor,
14406                         info.version.update,
14407                         info.version.draft);
14408                 printf("Global Package name:   %s\n\n", info.name);
14409         }
14410
14411         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14412                                 (uint8_t *)&info, sizeof(info),
14413                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14414         if (!ret) {
14415                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14416                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14417                         info.version.major,
14418                         info.version.minor,
14419                         info.version.update,
14420                         info.version.draft);
14421                 printf("i40e Profile name:     %s\n\n", info.name);
14422         }
14423
14424         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14425                                 (uint8_t *)&buff_size, sizeof(buff_size),
14426                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14427         if (!ret && buff_size) {
14428                 buff = (uint8_t *)malloc(buff_size);
14429                 if (buff) {
14430                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14431                                                 buff, buff_size,
14432                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14433                         if (!ret)
14434                                 printf("Package Notes:\n%s\n\n", buff);
14435                         free(buff);
14436                 }
14437         }
14438
14439         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14440                                 (uint8_t *)&dev_num, sizeof(dev_num),
14441                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14442         if (!ret && dev_num) {
14443                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14444                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14445                 if (devs) {
14446                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14447                                                 (uint8_t *)devs, buff_size,
14448                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14449                         if (!ret) {
14450                                 printf("List of supported devices:\n");
14451                                 for (i = 0; i < dev_num; i++) {
14452                                         printf("  %04X:%04X %04X:%04X\n",
14453                                                 devs[i].vendor_dev_id >> 16,
14454                                                 devs[i].vendor_dev_id & 0xFFFF,
14455                                                 devs[i].sub_vendor_dev_id >> 16,
14456                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14457                                 }
14458                                 printf("\n");
14459                         }
14460                         free(devs);
14461                 }
14462         }
14463
14464         /* get information about protocols and packet types */
14465         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14466                 (uint8_t *)&proto_num, sizeof(proto_num),
14467                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14468         if (ret || !proto_num)
14469                 goto no_print_return;
14470
14471         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14472         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14473         if (!proto)
14474                 goto no_print_return;
14475
14476         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14477                                         buff_size,
14478                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14479         if (!ret) {
14480                 printf("List of used protocols:\n");
14481                 for (i = 0; i < proto_num; i++)
14482                         printf("  %2u: %s\n", proto[i].proto_id,
14483                                proto[i].name);
14484                 printf("\n");
14485         }
14486         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14487                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14488                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14489         if (ret || !pctype_num)
14490                 goto no_print_pctypes;
14491
14492         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14493         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14494         if (!pctype)
14495                 goto no_print_pctypes;
14496
14497         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14498                                         buff_size,
14499                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14500         if (ret) {
14501                 free(pctype);
14502                 goto no_print_pctypes;
14503         }
14504
14505         printf("List of defined packet classification types:\n");
14506         for (i = 0; i < pctype_num; i++) {
14507                 printf("  %2u:", pctype[i].ptype_id);
14508                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14509                         proto_id = pctype[i].protocols[j];
14510                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14511                                 for (n = 0; n < proto_num; n++) {
14512                                         if (proto[n].proto_id == proto_id) {
14513                                                 printf(" %s", proto[n].name);
14514                                                 break;
14515                                         }
14516                                 }
14517                         }
14518                 }
14519                 printf("\n");
14520         }
14521         printf("\n");
14522         free(pctype);
14523
14524 no_print_pctypes:
14525
14526         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14527                                         sizeof(ptype_num),
14528                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14529         if (ret || !ptype_num)
14530                 goto no_print_return;
14531
14532         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14533         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14534         if (!ptype)
14535                 goto no_print_return;
14536
14537         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14538                                         buff_size,
14539                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14540         if (ret) {
14541                 free(ptype);
14542                 goto no_print_return;
14543         }
14544         printf("List of defined packet types:\n");
14545         for (i = 0; i < ptype_num; i++) {
14546                 printf("  %2u:", ptype[i].ptype_id);
14547                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14548                         proto_id = ptype[i].protocols[j];
14549                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14550                                 for (n = 0; n < proto_num; n++) {
14551                                         if (proto[n].proto_id == proto_id) {
14552                                                 printf(" %s", proto[n].name);
14553                                                 break;
14554                                         }
14555                                 }
14556                         }
14557                 }
14558                 printf("\n");
14559         }
14560         free(ptype);
14561         printf("\n");
14562
14563         ret = 0;
14564 no_print_return:
14565         if (proto)
14566                 free(proto);
14567 #endif
14568         if (ret == -ENOTSUP)
14569                 printf("Function not supported in PMD driver\n");
14570         close_ddp_package_file(pkg);
14571 }
14572
14573 cmdline_parse_inst_t cmd_ddp_get_info = {
14574         .f = cmd_ddp_info_parsed,
14575         .data = NULL,
14576         .help_str = "ddp get info <profile_path>",
14577         .tokens = {
14578                 (void *)&cmd_ddp_info_ddp,
14579                 (void *)&cmd_ddp_info_get,
14580                 (void *)&cmd_ddp_info_info,
14581                 (void *)&cmd_ddp_info_filepath,
14582                 NULL,
14583         },
14584 };
14585
14586 /* Get dynamic device personalization profile info list*/
14587 #define PROFILE_INFO_SIZE 48
14588 #define MAX_PROFILE_NUM 16
14589
14590 struct cmd_ddp_get_list_result {
14591         cmdline_fixed_string_t ddp;
14592         cmdline_fixed_string_t get;
14593         cmdline_fixed_string_t list;
14594         portid_t port_id;
14595 };
14596
14597 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14598         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14599 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14600         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14601 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14602         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14603 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14604         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14605
14606 static void
14607 cmd_ddp_get_list_parsed(
14608         void *parsed_result,
14609         __attribute__((unused)) struct cmdline *cl,
14610         __attribute__((unused)) void *data)
14611 {
14612         struct cmd_ddp_get_list_result *res = parsed_result;
14613 #ifdef RTE_LIBRTE_I40E_PMD
14614         struct rte_pmd_i40e_profile_list *p_list;
14615         struct rte_pmd_i40e_profile_info *p_info;
14616         uint32_t p_num;
14617         uint32_t size;
14618         uint32_t i;
14619 #endif
14620         int ret = -ENOTSUP;
14621
14622         if (res->port_id > nb_ports) {
14623                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14624                 return;
14625         }
14626
14627 #ifdef RTE_LIBRTE_I40E_PMD
14628         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14629         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14630         if (!p_list)
14631                 printf("%s: Failed to malloc buffer\n", __func__);
14632
14633         if (ret == -ENOTSUP)
14634                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14635                                                 (uint8_t *)p_list, size);
14636
14637         if (!ret) {
14638                 p_num = p_list->p_count;
14639                 printf("Profile number is: %d\n\n", p_num);
14640
14641                 for (i = 0; i < p_num; i++) {
14642                         p_info = &p_list->p_info[i];
14643                         printf("Profile %d:\n", i);
14644                         printf("Track id:     0x%x\n", p_info->track_id);
14645                         printf("Version:      %d.%d.%d.%d\n",
14646                                p_info->version.major,
14647                                p_info->version.minor,
14648                                p_info->version.update,
14649                                p_info->version.draft);
14650                         printf("Profile name: %s\n\n", p_info->name);
14651                 }
14652         }
14653
14654         free(p_list);
14655 #endif
14656
14657         if (ret < 0)
14658                 printf("Failed to get ddp list\n");
14659 }
14660
14661 cmdline_parse_inst_t cmd_ddp_get_list = {
14662         .f = cmd_ddp_get_list_parsed,
14663         .data = NULL,
14664         .help_str = "ddp get list <port_id>",
14665         .tokens = {
14666                 (void *)&cmd_ddp_get_list_ddp,
14667                 (void *)&cmd_ddp_get_list_get,
14668                 (void *)&cmd_ddp_get_list_list,
14669                 (void *)&cmd_ddp_get_list_port_id,
14670                 NULL,
14671         },
14672 };
14673
14674 /* show vf stats */
14675
14676 /* Common result structure for show vf stats */
14677 struct cmd_show_vf_stats_result {
14678         cmdline_fixed_string_t show;
14679         cmdline_fixed_string_t vf;
14680         cmdline_fixed_string_t stats;
14681         portid_t port_id;
14682         uint16_t vf_id;
14683 };
14684
14685 /* Common CLI fields show vf stats*/
14686 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14687         TOKEN_STRING_INITIALIZER
14688                 (struct cmd_show_vf_stats_result,
14689                  show, "show");
14690 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14691         TOKEN_STRING_INITIALIZER
14692                 (struct cmd_show_vf_stats_result,
14693                  vf, "vf");
14694 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14695         TOKEN_STRING_INITIALIZER
14696                 (struct cmd_show_vf_stats_result,
14697                  stats, "stats");
14698 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14699         TOKEN_NUM_INITIALIZER
14700                 (struct cmd_show_vf_stats_result,
14701                  port_id, UINT16);
14702 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14703         TOKEN_NUM_INITIALIZER
14704                 (struct cmd_show_vf_stats_result,
14705                  vf_id, UINT16);
14706
14707 static void
14708 cmd_show_vf_stats_parsed(
14709         void *parsed_result,
14710         __attribute__((unused)) struct cmdline *cl,
14711         __attribute__((unused)) void *data)
14712 {
14713         struct cmd_show_vf_stats_result *res = parsed_result;
14714         struct rte_eth_stats stats;
14715         int ret = -ENOTSUP;
14716         static const char *nic_stats_border = "########################";
14717
14718         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14719                 return;
14720
14721         memset(&stats, 0, sizeof(stats));
14722
14723 #ifdef RTE_LIBRTE_I40E_PMD
14724         if (ret == -ENOTSUP)
14725                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14726                                                 res->vf_id,
14727                                                 &stats);
14728 #endif
14729 #ifdef RTE_LIBRTE_BNXT_PMD
14730         if (ret == -ENOTSUP)
14731                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14732                                                 res->vf_id,
14733                                                 &stats);
14734 #endif
14735
14736         switch (ret) {
14737         case 0:
14738                 break;
14739         case -EINVAL:
14740                 printf("invalid vf_id %d\n", res->vf_id);
14741                 break;
14742         case -ENODEV:
14743                 printf("invalid port_id %d\n", res->port_id);
14744                 break;
14745         case -ENOTSUP:
14746                 printf("function not implemented\n");
14747                 break;
14748         default:
14749                 printf("programming error: (%s)\n", strerror(-ret));
14750         }
14751
14752         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14753                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14754
14755         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14756                "%-"PRIu64"\n",
14757                stats.ipackets, stats.imissed, stats.ibytes);
14758         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14759         printf("  RX-nombuf:  %-10"PRIu64"\n",
14760                stats.rx_nombuf);
14761         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14762                "%-"PRIu64"\n",
14763                stats.opackets, stats.oerrors, stats.obytes);
14764
14765         printf("  %s############################%s\n",
14766                                nic_stats_border, nic_stats_border);
14767 }
14768
14769 cmdline_parse_inst_t cmd_show_vf_stats = {
14770         .f = cmd_show_vf_stats_parsed,
14771         .data = NULL,
14772         .help_str = "show vf stats <port_id> <vf_id>",
14773         .tokens = {
14774                 (void *)&cmd_show_vf_stats_show,
14775                 (void *)&cmd_show_vf_stats_vf,
14776                 (void *)&cmd_show_vf_stats_stats,
14777                 (void *)&cmd_show_vf_stats_port_id,
14778                 (void *)&cmd_show_vf_stats_vf_id,
14779                 NULL,
14780         },
14781 };
14782
14783 /* clear vf stats */
14784
14785 /* Common result structure for clear vf stats */
14786 struct cmd_clear_vf_stats_result {
14787         cmdline_fixed_string_t clear;
14788         cmdline_fixed_string_t vf;
14789         cmdline_fixed_string_t stats;
14790         portid_t port_id;
14791         uint16_t vf_id;
14792 };
14793
14794 /* Common CLI fields clear vf stats*/
14795 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14796         TOKEN_STRING_INITIALIZER
14797                 (struct cmd_clear_vf_stats_result,
14798                  clear, "clear");
14799 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14800         TOKEN_STRING_INITIALIZER
14801                 (struct cmd_clear_vf_stats_result,
14802                  vf, "vf");
14803 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14804         TOKEN_STRING_INITIALIZER
14805                 (struct cmd_clear_vf_stats_result,
14806                  stats, "stats");
14807 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14808         TOKEN_NUM_INITIALIZER
14809                 (struct cmd_clear_vf_stats_result,
14810                  port_id, UINT16);
14811 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14812         TOKEN_NUM_INITIALIZER
14813                 (struct cmd_clear_vf_stats_result,
14814                  vf_id, UINT16);
14815
14816 static void
14817 cmd_clear_vf_stats_parsed(
14818         void *parsed_result,
14819         __attribute__((unused)) struct cmdline *cl,
14820         __attribute__((unused)) void *data)
14821 {
14822         struct cmd_clear_vf_stats_result *res = parsed_result;
14823         int ret = -ENOTSUP;
14824
14825         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14826                 return;
14827
14828 #ifdef RTE_LIBRTE_I40E_PMD
14829         if (ret == -ENOTSUP)
14830                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14831                                                   res->vf_id);
14832 #endif
14833 #ifdef RTE_LIBRTE_BNXT_PMD
14834         if (ret == -ENOTSUP)
14835                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14836                                                   res->vf_id);
14837 #endif
14838
14839         switch (ret) {
14840         case 0:
14841                 break;
14842         case -EINVAL:
14843                 printf("invalid vf_id %d\n", res->vf_id);
14844                 break;
14845         case -ENODEV:
14846                 printf("invalid port_id %d\n", res->port_id);
14847                 break;
14848         case -ENOTSUP:
14849                 printf("function not implemented\n");
14850                 break;
14851         default:
14852                 printf("programming error: (%s)\n", strerror(-ret));
14853         }
14854 }
14855
14856 cmdline_parse_inst_t cmd_clear_vf_stats = {
14857         .f = cmd_clear_vf_stats_parsed,
14858         .data = NULL,
14859         .help_str = "clear vf stats <port_id> <vf_id>",
14860         .tokens = {
14861                 (void *)&cmd_clear_vf_stats_clear,
14862                 (void *)&cmd_clear_vf_stats_vf,
14863                 (void *)&cmd_clear_vf_stats_stats,
14864                 (void *)&cmd_clear_vf_stats_port_id,
14865                 (void *)&cmd_clear_vf_stats_vf_id,
14866                 NULL,
14867         },
14868 };
14869
14870 /* port config pctype mapping reset */
14871
14872 /* Common result structure for port config pctype mapping reset */
14873 struct cmd_pctype_mapping_reset_result {
14874         cmdline_fixed_string_t port;
14875         cmdline_fixed_string_t config;
14876         portid_t port_id;
14877         cmdline_fixed_string_t pctype;
14878         cmdline_fixed_string_t mapping;
14879         cmdline_fixed_string_t reset;
14880 };
14881
14882 /* Common CLI fields for port config pctype mapping reset*/
14883 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14884         TOKEN_STRING_INITIALIZER
14885                 (struct cmd_pctype_mapping_reset_result,
14886                  port, "port");
14887 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14888         TOKEN_STRING_INITIALIZER
14889                 (struct cmd_pctype_mapping_reset_result,
14890                  config, "config");
14891 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14892         TOKEN_NUM_INITIALIZER
14893                 (struct cmd_pctype_mapping_reset_result,
14894                  port_id, UINT16);
14895 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14896         TOKEN_STRING_INITIALIZER
14897                 (struct cmd_pctype_mapping_reset_result,
14898                  pctype, "pctype");
14899 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14900         TOKEN_STRING_INITIALIZER
14901                 (struct cmd_pctype_mapping_reset_result,
14902                  mapping, "mapping");
14903 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14904         TOKEN_STRING_INITIALIZER
14905                 (struct cmd_pctype_mapping_reset_result,
14906                  reset, "reset");
14907
14908 static void
14909 cmd_pctype_mapping_reset_parsed(
14910         void *parsed_result,
14911         __attribute__((unused)) struct cmdline *cl,
14912         __attribute__((unused)) void *data)
14913 {
14914         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14915         int ret = -ENOTSUP;
14916
14917         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14918                 return;
14919
14920 #ifdef RTE_LIBRTE_I40E_PMD
14921         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14922 #endif
14923
14924         switch (ret) {
14925         case 0:
14926                 break;
14927         case -ENODEV:
14928                 printf("invalid port_id %d\n", res->port_id);
14929                 break;
14930         case -ENOTSUP:
14931                 printf("function not implemented\n");
14932                 break;
14933         default:
14934                 printf("programming error: (%s)\n", strerror(-ret));
14935         }
14936 }
14937
14938 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14939         .f = cmd_pctype_mapping_reset_parsed,
14940         .data = NULL,
14941         .help_str = "port config <port_id> pctype mapping reset",
14942         .tokens = {
14943                 (void *)&cmd_pctype_mapping_reset_port,
14944                 (void *)&cmd_pctype_mapping_reset_config,
14945                 (void *)&cmd_pctype_mapping_reset_port_id,
14946                 (void *)&cmd_pctype_mapping_reset_pctype,
14947                 (void *)&cmd_pctype_mapping_reset_mapping,
14948                 (void *)&cmd_pctype_mapping_reset_reset,
14949                 NULL,
14950         },
14951 };
14952
14953 /* show port pctype mapping */
14954
14955 /* Common result structure for show port pctype mapping */
14956 struct cmd_pctype_mapping_get_result {
14957         cmdline_fixed_string_t show;
14958         cmdline_fixed_string_t port;
14959         portid_t port_id;
14960         cmdline_fixed_string_t pctype;
14961         cmdline_fixed_string_t mapping;
14962 };
14963
14964 /* Common CLI fields for pctype mapping get */
14965 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14966         TOKEN_STRING_INITIALIZER
14967                 (struct cmd_pctype_mapping_get_result,
14968                  show, "show");
14969 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14970         TOKEN_STRING_INITIALIZER
14971                 (struct cmd_pctype_mapping_get_result,
14972                  port, "port");
14973 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14974         TOKEN_NUM_INITIALIZER
14975                 (struct cmd_pctype_mapping_get_result,
14976                  port_id, UINT16);
14977 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14978         TOKEN_STRING_INITIALIZER
14979                 (struct cmd_pctype_mapping_get_result,
14980                  pctype, "pctype");
14981 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14982         TOKEN_STRING_INITIALIZER
14983                 (struct cmd_pctype_mapping_get_result,
14984                  mapping, "mapping");
14985
14986 static void
14987 cmd_pctype_mapping_get_parsed(
14988         void *parsed_result,
14989         __attribute__((unused)) struct cmdline *cl,
14990         __attribute__((unused)) void *data)
14991 {
14992         struct cmd_pctype_mapping_get_result *res = parsed_result;
14993         int ret = -ENOTSUP;
14994 #ifdef RTE_LIBRTE_I40E_PMD
14995         struct rte_pmd_i40e_flow_type_mapping
14996                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14997         int i, j, first_pctype;
14998 #endif
14999
15000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15001                 return;
15002
15003 #ifdef RTE_LIBRTE_I40E_PMD
15004         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15005 #endif
15006
15007         switch (ret) {
15008         case 0:
15009                 break;
15010         case -ENODEV:
15011                 printf("invalid port_id %d\n", res->port_id);
15012                 return;
15013         case -ENOTSUP:
15014                 printf("function not implemented\n");
15015                 return;
15016         default:
15017                 printf("programming error: (%s)\n", strerror(-ret));
15018                 return;
15019         }
15020
15021 #ifdef RTE_LIBRTE_I40E_PMD
15022         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15023                 if (mapping[i].pctype != 0ULL) {
15024                         first_pctype = 1;
15025
15026                         printf("pctype: ");
15027                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15028                                 if (mapping[i].pctype & (1ULL << j)) {
15029                                         printf(first_pctype ?
15030                                                "%02d" : ",%02d", j);
15031                                         first_pctype = 0;
15032                                 }
15033                         }
15034                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15035                 }
15036         }
15037 #endif
15038 }
15039
15040 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15041         .f = cmd_pctype_mapping_get_parsed,
15042         .data = NULL,
15043         .help_str = "show port <port_id> pctype mapping",
15044         .tokens = {
15045                 (void *)&cmd_pctype_mapping_get_show,
15046                 (void *)&cmd_pctype_mapping_get_port,
15047                 (void *)&cmd_pctype_mapping_get_port_id,
15048                 (void *)&cmd_pctype_mapping_get_pctype,
15049                 (void *)&cmd_pctype_mapping_get_mapping,
15050                 NULL,
15051         },
15052 };
15053
15054 /* port config pctype mapping update */
15055
15056 /* Common result structure for port config pctype mapping update */
15057 struct cmd_pctype_mapping_update_result {
15058         cmdline_fixed_string_t port;
15059         cmdline_fixed_string_t config;
15060         portid_t port_id;
15061         cmdline_fixed_string_t pctype;
15062         cmdline_fixed_string_t mapping;
15063         cmdline_fixed_string_t update;
15064         cmdline_fixed_string_t pctype_list;
15065         uint16_t flow_type;
15066 };
15067
15068 /* Common CLI fields for pctype mapping update*/
15069 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15070         TOKEN_STRING_INITIALIZER
15071                 (struct cmd_pctype_mapping_update_result,
15072                  port, "port");
15073 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15074         TOKEN_STRING_INITIALIZER
15075                 (struct cmd_pctype_mapping_update_result,
15076                  config, "config");
15077 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15078         TOKEN_NUM_INITIALIZER
15079                 (struct cmd_pctype_mapping_update_result,
15080                  port_id, UINT16);
15081 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15082         TOKEN_STRING_INITIALIZER
15083                 (struct cmd_pctype_mapping_update_result,
15084                  pctype, "pctype");
15085 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15086         TOKEN_STRING_INITIALIZER
15087                 (struct cmd_pctype_mapping_update_result,
15088                  mapping, "mapping");
15089 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15090         TOKEN_STRING_INITIALIZER
15091                 (struct cmd_pctype_mapping_update_result,
15092                  update, "update");
15093 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15094         TOKEN_STRING_INITIALIZER
15095                 (struct cmd_pctype_mapping_update_result,
15096                  pctype_list, NULL);
15097 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15098         TOKEN_NUM_INITIALIZER
15099                 (struct cmd_pctype_mapping_update_result,
15100                  flow_type, UINT16);
15101
15102 static void
15103 cmd_pctype_mapping_update_parsed(
15104         void *parsed_result,
15105         __attribute__((unused)) struct cmdline *cl,
15106         __attribute__((unused)) void *data)
15107 {
15108         struct cmd_pctype_mapping_update_result *res = parsed_result;
15109         int ret = -ENOTSUP;
15110 #ifdef RTE_LIBRTE_I40E_PMD
15111         struct rte_pmd_i40e_flow_type_mapping mapping;
15112         unsigned int i;
15113         unsigned int nb_item;
15114         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15115 #endif
15116
15117         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15118                 return;
15119
15120 #ifdef RTE_LIBRTE_I40E_PMD
15121         nb_item = parse_item_list(res->pctype_list, "pctypes",
15122                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15123         mapping.flow_type = res->flow_type;
15124         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15125                 mapping.pctype |= (1ULL << pctype_list[i]);
15126         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15127                                                 &mapping,
15128                                                 1,
15129                                                 0);
15130 #endif
15131
15132         switch (ret) {
15133         case 0:
15134                 break;
15135         case -EINVAL:
15136                 printf("invalid pctype or flow type\n");
15137                 break;
15138         case -ENODEV:
15139                 printf("invalid port_id %d\n", res->port_id);
15140                 break;
15141         case -ENOTSUP:
15142                 printf("function not implemented\n");
15143                 break;
15144         default:
15145                 printf("programming error: (%s)\n", strerror(-ret));
15146         }
15147 }
15148
15149 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15150         .f = cmd_pctype_mapping_update_parsed,
15151         .data = NULL,
15152         .help_str = "port config <port_id> pctype mapping update"
15153         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15154         .tokens = {
15155                 (void *)&cmd_pctype_mapping_update_port,
15156                 (void *)&cmd_pctype_mapping_update_config,
15157                 (void *)&cmd_pctype_mapping_update_port_id,
15158                 (void *)&cmd_pctype_mapping_update_pctype,
15159                 (void *)&cmd_pctype_mapping_update_mapping,
15160                 (void *)&cmd_pctype_mapping_update_update,
15161                 (void *)&cmd_pctype_mapping_update_pc_type,
15162                 (void *)&cmd_pctype_mapping_update_flow_type,
15163                 NULL,
15164         },
15165 };
15166
15167 /* ptype mapping get */
15168
15169 /* Common result structure for ptype mapping get */
15170 struct cmd_ptype_mapping_get_result {
15171         cmdline_fixed_string_t ptype;
15172         cmdline_fixed_string_t mapping;
15173         cmdline_fixed_string_t get;
15174         portid_t port_id;
15175         uint8_t valid_only;
15176 };
15177
15178 /* Common CLI fields for ptype mapping get */
15179 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15180         TOKEN_STRING_INITIALIZER
15181                 (struct cmd_ptype_mapping_get_result,
15182                  ptype, "ptype");
15183 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15184         TOKEN_STRING_INITIALIZER
15185                 (struct cmd_ptype_mapping_get_result,
15186                  mapping, "mapping");
15187 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15188         TOKEN_STRING_INITIALIZER
15189                 (struct cmd_ptype_mapping_get_result,
15190                  get, "get");
15191 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15192         TOKEN_NUM_INITIALIZER
15193                 (struct cmd_ptype_mapping_get_result,
15194                  port_id, UINT16);
15195 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15196         TOKEN_NUM_INITIALIZER
15197                 (struct cmd_ptype_mapping_get_result,
15198                  valid_only, UINT8);
15199
15200 static void
15201 cmd_ptype_mapping_get_parsed(
15202         void *parsed_result,
15203         __attribute__((unused)) struct cmdline *cl,
15204         __attribute__((unused)) void *data)
15205 {
15206         struct cmd_ptype_mapping_get_result *res = parsed_result;
15207         int ret = -ENOTSUP;
15208 #ifdef RTE_LIBRTE_I40E_PMD
15209         int max_ptype_num = 256;
15210         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15211         uint16_t count;
15212         int i;
15213 #endif
15214
15215         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15216                 return;
15217
15218 #ifdef RTE_LIBRTE_I40E_PMD
15219         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15220                                         mapping,
15221                                         max_ptype_num,
15222                                         &count,
15223                                         res->valid_only);
15224 #endif
15225
15226         switch (ret) {
15227         case 0:
15228                 break;
15229         case -ENODEV:
15230                 printf("invalid port_id %d\n", res->port_id);
15231                 break;
15232         case -ENOTSUP:
15233                 printf("function not implemented\n");
15234                 break;
15235         default:
15236                 printf("programming error: (%s)\n", strerror(-ret));
15237         }
15238
15239 #ifdef RTE_LIBRTE_I40E_PMD
15240         if (!ret) {
15241                 for (i = 0; i < count; i++)
15242                         printf("%3d\t0x%08x\n",
15243                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15244         }
15245 #endif
15246 }
15247
15248 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15249         .f = cmd_ptype_mapping_get_parsed,
15250         .data = NULL,
15251         .help_str = "ptype mapping get <port_id> <valid_only>",
15252         .tokens = {
15253                 (void *)&cmd_ptype_mapping_get_ptype,
15254                 (void *)&cmd_ptype_mapping_get_mapping,
15255                 (void *)&cmd_ptype_mapping_get_get,
15256                 (void *)&cmd_ptype_mapping_get_port_id,
15257                 (void *)&cmd_ptype_mapping_get_valid_only,
15258                 NULL,
15259         },
15260 };
15261
15262 /* ptype mapping replace */
15263
15264 /* Common result structure for ptype mapping replace */
15265 struct cmd_ptype_mapping_replace_result {
15266         cmdline_fixed_string_t ptype;
15267         cmdline_fixed_string_t mapping;
15268         cmdline_fixed_string_t replace;
15269         portid_t port_id;
15270         uint32_t target;
15271         uint8_t mask;
15272         uint32_t pkt_type;
15273 };
15274
15275 /* Common CLI fields for ptype mapping replace */
15276 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15277         TOKEN_STRING_INITIALIZER
15278                 (struct cmd_ptype_mapping_replace_result,
15279                  ptype, "ptype");
15280 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15281         TOKEN_STRING_INITIALIZER
15282                 (struct cmd_ptype_mapping_replace_result,
15283                  mapping, "mapping");
15284 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15285         TOKEN_STRING_INITIALIZER
15286                 (struct cmd_ptype_mapping_replace_result,
15287                  replace, "replace");
15288 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15289         TOKEN_NUM_INITIALIZER
15290                 (struct cmd_ptype_mapping_replace_result,
15291                  port_id, UINT16);
15292 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15293         TOKEN_NUM_INITIALIZER
15294                 (struct cmd_ptype_mapping_replace_result,
15295                  target, UINT32);
15296 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15297         TOKEN_NUM_INITIALIZER
15298                 (struct cmd_ptype_mapping_replace_result,
15299                  mask, UINT8);
15300 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15301         TOKEN_NUM_INITIALIZER
15302                 (struct cmd_ptype_mapping_replace_result,
15303                  pkt_type, UINT32);
15304
15305 static void
15306 cmd_ptype_mapping_replace_parsed(
15307         void *parsed_result,
15308         __attribute__((unused)) struct cmdline *cl,
15309         __attribute__((unused)) void *data)
15310 {
15311         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15312         int ret = -ENOTSUP;
15313
15314         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15315                 return;
15316
15317 #ifdef RTE_LIBRTE_I40E_PMD
15318         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15319                                         res->target,
15320                                         res->mask,
15321                                         res->pkt_type);
15322 #endif
15323
15324         switch (ret) {
15325         case 0:
15326                 break;
15327         case -EINVAL:
15328                 printf("invalid ptype 0x%8x or 0x%8x\n",
15329                                 res->target, res->pkt_type);
15330                 break;
15331         case -ENODEV:
15332                 printf("invalid port_id %d\n", res->port_id);
15333                 break;
15334         case -ENOTSUP:
15335                 printf("function not implemented\n");
15336                 break;
15337         default:
15338                 printf("programming error: (%s)\n", strerror(-ret));
15339         }
15340 }
15341
15342 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15343         .f = cmd_ptype_mapping_replace_parsed,
15344         .data = NULL,
15345         .help_str =
15346                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15347         .tokens = {
15348                 (void *)&cmd_ptype_mapping_replace_ptype,
15349                 (void *)&cmd_ptype_mapping_replace_mapping,
15350                 (void *)&cmd_ptype_mapping_replace_replace,
15351                 (void *)&cmd_ptype_mapping_replace_port_id,
15352                 (void *)&cmd_ptype_mapping_replace_target,
15353                 (void *)&cmd_ptype_mapping_replace_mask,
15354                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15355                 NULL,
15356         },
15357 };
15358
15359 /* ptype mapping reset */
15360
15361 /* Common result structure for ptype mapping reset */
15362 struct cmd_ptype_mapping_reset_result {
15363         cmdline_fixed_string_t ptype;
15364         cmdline_fixed_string_t mapping;
15365         cmdline_fixed_string_t reset;
15366         portid_t port_id;
15367 };
15368
15369 /* Common CLI fields for ptype mapping reset*/
15370 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15371         TOKEN_STRING_INITIALIZER
15372                 (struct cmd_ptype_mapping_reset_result,
15373                  ptype, "ptype");
15374 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15375         TOKEN_STRING_INITIALIZER
15376                 (struct cmd_ptype_mapping_reset_result,
15377                  mapping, "mapping");
15378 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15379         TOKEN_STRING_INITIALIZER
15380                 (struct cmd_ptype_mapping_reset_result,
15381                  reset, "reset");
15382 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15383         TOKEN_NUM_INITIALIZER
15384                 (struct cmd_ptype_mapping_reset_result,
15385                  port_id, UINT16);
15386
15387 static void
15388 cmd_ptype_mapping_reset_parsed(
15389         void *parsed_result,
15390         __attribute__((unused)) struct cmdline *cl,
15391         __attribute__((unused)) void *data)
15392 {
15393         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15394         int ret = -ENOTSUP;
15395
15396         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15397                 return;
15398
15399 #ifdef RTE_LIBRTE_I40E_PMD
15400         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15401 #endif
15402
15403         switch (ret) {
15404         case 0:
15405                 break;
15406         case -ENODEV:
15407                 printf("invalid port_id %d\n", res->port_id);
15408                 break;
15409         case -ENOTSUP:
15410                 printf("function not implemented\n");
15411                 break;
15412         default:
15413                 printf("programming error: (%s)\n", strerror(-ret));
15414         }
15415 }
15416
15417 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15418         .f = cmd_ptype_mapping_reset_parsed,
15419         .data = NULL,
15420         .help_str = "ptype mapping reset <port_id>",
15421         .tokens = {
15422                 (void *)&cmd_ptype_mapping_reset_ptype,
15423                 (void *)&cmd_ptype_mapping_reset_mapping,
15424                 (void *)&cmd_ptype_mapping_reset_reset,
15425                 (void *)&cmd_ptype_mapping_reset_port_id,
15426                 NULL,
15427         },
15428 };
15429
15430 /* ptype mapping update */
15431
15432 /* Common result structure for ptype mapping update */
15433 struct cmd_ptype_mapping_update_result {
15434         cmdline_fixed_string_t ptype;
15435         cmdline_fixed_string_t mapping;
15436         cmdline_fixed_string_t reset;
15437         portid_t port_id;
15438         uint8_t hw_ptype;
15439         uint32_t sw_ptype;
15440 };
15441
15442 /* Common CLI fields for ptype mapping update*/
15443 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15444         TOKEN_STRING_INITIALIZER
15445                 (struct cmd_ptype_mapping_update_result,
15446                  ptype, "ptype");
15447 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15448         TOKEN_STRING_INITIALIZER
15449                 (struct cmd_ptype_mapping_update_result,
15450                  mapping, "mapping");
15451 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15452         TOKEN_STRING_INITIALIZER
15453                 (struct cmd_ptype_mapping_update_result,
15454                  reset, "update");
15455 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15456         TOKEN_NUM_INITIALIZER
15457                 (struct cmd_ptype_mapping_update_result,
15458                  port_id, UINT16);
15459 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15460         TOKEN_NUM_INITIALIZER
15461                 (struct cmd_ptype_mapping_update_result,
15462                  hw_ptype, UINT8);
15463 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15464         TOKEN_NUM_INITIALIZER
15465                 (struct cmd_ptype_mapping_update_result,
15466                  sw_ptype, UINT32);
15467
15468 static void
15469 cmd_ptype_mapping_update_parsed(
15470         void *parsed_result,
15471         __attribute__((unused)) struct cmdline *cl,
15472         __attribute__((unused)) void *data)
15473 {
15474         struct cmd_ptype_mapping_update_result *res = parsed_result;
15475         int ret = -ENOTSUP;
15476 #ifdef RTE_LIBRTE_I40E_PMD
15477         struct rte_pmd_i40e_ptype_mapping mapping;
15478 #endif
15479         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15480                 return;
15481
15482 #ifdef RTE_LIBRTE_I40E_PMD
15483         mapping.hw_ptype = res->hw_ptype;
15484         mapping.sw_ptype = res->sw_ptype;
15485         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15486                                                 &mapping,
15487                                                 1,
15488                                                 0);
15489 #endif
15490
15491         switch (ret) {
15492         case 0:
15493                 break;
15494         case -EINVAL:
15495                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15496                 break;
15497         case -ENODEV:
15498                 printf("invalid port_id %d\n", res->port_id);
15499                 break;
15500         case -ENOTSUP:
15501                 printf("function not implemented\n");
15502                 break;
15503         default:
15504                 printf("programming error: (%s)\n", strerror(-ret));
15505         }
15506 }
15507
15508 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15509         .f = cmd_ptype_mapping_update_parsed,
15510         .data = NULL,
15511         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15512         .tokens = {
15513                 (void *)&cmd_ptype_mapping_update_ptype,
15514                 (void *)&cmd_ptype_mapping_update_mapping,
15515                 (void *)&cmd_ptype_mapping_update_update,
15516                 (void *)&cmd_ptype_mapping_update_port_id,
15517                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15518                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15519                 NULL,
15520         },
15521 };
15522
15523 /* Common result structure for file commands */
15524 struct cmd_cmdfile_result {
15525         cmdline_fixed_string_t load;
15526         cmdline_fixed_string_t filename;
15527 };
15528
15529 /* Common CLI fields for file commands */
15530 cmdline_parse_token_string_t cmd_load_cmdfile =
15531         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15532 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15533         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15534
15535 static void
15536 cmd_load_from_file_parsed(
15537         void *parsed_result,
15538         __attribute__((unused)) struct cmdline *cl,
15539         __attribute__((unused)) void *data)
15540 {
15541         struct cmd_cmdfile_result *res = parsed_result;
15542
15543         cmdline_read_from_file(res->filename);
15544 }
15545
15546 cmdline_parse_inst_t cmd_load_from_file = {
15547         .f = cmd_load_from_file_parsed,
15548         .data = NULL,
15549         .help_str = "load <filename>",
15550         .tokens = {
15551                 (void *)&cmd_load_cmdfile,
15552                 (void *)&cmd_load_cmdfile_filename,
15553                 NULL,
15554         },
15555 };
15556
15557 /* ******************************************************************************** */
15558
15559 /* list of instructions */
15560 cmdline_parse_ctx_t main_ctx[] = {
15561         (cmdline_parse_inst_t *)&cmd_help_brief,
15562         (cmdline_parse_inst_t *)&cmd_help_long,
15563         (cmdline_parse_inst_t *)&cmd_quit,
15564         (cmdline_parse_inst_t *)&cmd_load_from_file,
15565         (cmdline_parse_inst_t *)&cmd_showport,
15566         (cmdline_parse_inst_t *)&cmd_showqueue,
15567         (cmdline_parse_inst_t *)&cmd_showportall,
15568         (cmdline_parse_inst_t *)&cmd_showcfg,
15569         (cmdline_parse_inst_t *)&cmd_start,
15570         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15571         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15572         (cmdline_parse_inst_t *)&cmd_set_link_up,
15573         (cmdline_parse_inst_t *)&cmd_set_link_down,
15574         (cmdline_parse_inst_t *)&cmd_reset,
15575         (cmdline_parse_inst_t *)&cmd_set_numbers,
15576         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15577         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15578         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15579         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15580         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15581         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15582         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15583         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15584         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15585         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15586         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15587         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15588         (cmdline_parse_inst_t *)&cmd_set_link_check,
15589         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15590         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15591         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15592         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15593 #ifdef RTE_LIBRTE_PMD_BOND
15594         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15595         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15596         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15597         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15598         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15599         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15600         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15601         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15602         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15603         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15604         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15605 #endif
15606         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15607         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15608         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15609         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15610         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15611         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15612         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15613         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15614         (cmdline_parse_inst_t *)&cmd_csum_set,
15615         (cmdline_parse_inst_t *)&cmd_csum_show,
15616         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15617         (cmdline_parse_inst_t *)&cmd_tso_set,
15618         (cmdline_parse_inst_t *)&cmd_tso_show,
15619         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15620         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15621         (cmdline_parse_inst_t *)&cmd_gro_enable,
15622         (cmdline_parse_inst_t *)&cmd_gro_flush,
15623         (cmdline_parse_inst_t *)&cmd_gro_show,
15624         (cmdline_parse_inst_t *)&cmd_gso_enable,
15625         (cmdline_parse_inst_t *)&cmd_gso_size,
15626         (cmdline_parse_inst_t *)&cmd_gso_show,
15627         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15628         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15629         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15630         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15631         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15632         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15633         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15634         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15635         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15636         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15637         (cmdline_parse_inst_t *)&cmd_config_dcb,
15638         (cmdline_parse_inst_t *)&cmd_read_reg,
15639         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15640         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15641         (cmdline_parse_inst_t *)&cmd_write_reg,
15642         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15643         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15644         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15645         (cmdline_parse_inst_t *)&cmd_stop,
15646         (cmdline_parse_inst_t *)&cmd_mac_addr,
15647         (cmdline_parse_inst_t *)&cmd_set_qmap,
15648         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15649         (cmdline_parse_inst_t *)&cmd_operate_port,
15650         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15651         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15652         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15653         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15654         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15655         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15656         (cmdline_parse_inst_t *)&cmd_config_mtu,
15657         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15658         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15659         (cmdline_parse_inst_t *)&cmd_config_rss,
15660         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15661         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15662         (cmdline_parse_inst_t *)&cmd_showport_reta,
15663         (cmdline_parse_inst_t *)&cmd_config_burst,
15664         (cmdline_parse_inst_t *)&cmd_config_thresh,
15665         (cmdline_parse_inst_t *)&cmd_config_threshold,
15666         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15667         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15668         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15669         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15670         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15671         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15672         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15673         (cmdline_parse_inst_t *)&cmd_global_config,
15674         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15675         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15676         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15677         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15678         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15679         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15680         (cmdline_parse_inst_t *)&cmd_dump,
15681         (cmdline_parse_inst_t *)&cmd_dump_one,
15682         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15683         (cmdline_parse_inst_t *)&cmd_syn_filter,
15684         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15685         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15686         (cmdline_parse_inst_t *)&cmd_flex_filter,
15687         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15688         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15689         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15690         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15691         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15692         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15693         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15694         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15695         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15696         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15697         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15698         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15699         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15700         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15701         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15702         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15703         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15704         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15705         (cmdline_parse_inst_t *)&cmd_flow,
15706         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15707         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15708         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15709         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15710         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15711         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15712         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15713         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15714         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15715         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15716         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15717         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15718         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15719         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15720         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15721         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15722         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15723         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15724         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15725         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15726         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15727         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15728         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15729         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15730         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15731         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15732         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15733         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15734         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15735         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15736         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15737         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15738         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15739         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15740         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15741         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15742         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15743         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15744         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15745         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15746         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15747         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15748         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15749         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15750         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15751         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15752         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15753         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15754         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15755 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15756         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15757 #endif
15758         (cmdline_parse_inst_t *)&cmd_ddp_add,
15759         (cmdline_parse_inst_t *)&cmd_ddp_del,
15760         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15761         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15762         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15763         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15764         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15765         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15766         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15767         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15768
15769         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15770         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15771         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15772         (cmdline_parse_inst_t *)&cmd_queue_region,
15773         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15774         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15775         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15776         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15777         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15778         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15779         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15780         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15781         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15782         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15783         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15784         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15785         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15786         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15787         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15788         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15789         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15790         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15791         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15792         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15793         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15794         NULL,
15795 };
15796
15797 /* read cmdline commands from file */
15798 void
15799 cmdline_read_from_file(const char *filename)
15800 {
15801         struct cmdline *cl;
15802
15803         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15804         if (cl == NULL) {
15805                 printf("Failed to create file based cmdline context: %s\n",
15806                        filename);
15807                 return;
15808         }
15809
15810         cmdline_interact(cl);
15811         cmdline_quit(cl);
15812
15813         cmdline_free(cl);
15814
15815         printf("Read CLI commands from %s\n", filename);
15816 }
15817
15818 /* prompt function, called from main on MASTER lcore */
15819 void
15820 prompt(void)
15821 {
15822         /* initialize non-constant commands */
15823         cmd_set_fwd_mode_init();
15824         cmd_set_fwd_retry_mode_init();
15825
15826         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15827         if (testpmd_cl == NULL)
15828                 return;
15829         cmdline_interact(testpmd_cl);
15830         cmdline_stdin_exit(testpmd_cl);
15831 }
15832
15833 void
15834 prompt_exit(void)
15835 {
15836         if (testpmd_cl != NULL)
15837                 cmdline_quit(testpmd_cl);
15838 }
15839
15840 static void
15841 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15842 {
15843         if (id == (portid_t)RTE_PORT_ALL) {
15844                 portid_t pid;
15845
15846                 RTE_ETH_FOREACH_DEV(pid) {
15847                         /* check if need_reconfig has been set to 1 */
15848                         if (ports[pid].need_reconfig == 0)
15849                                 ports[pid].need_reconfig = dev;
15850                         /* check if need_reconfig_queues has been set to 1 */
15851                         if (ports[pid].need_reconfig_queues == 0)
15852                                 ports[pid].need_reconfig_queues = queue;
15853                 }
15854         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15855                 /* check if need_reconfig has been set to 1 */
15856                 if (ports[id].need_reconfig == 0)
15857                         ports[id].need_reconfig = dev;
15858                 /* check if need_reconfig_queues has been set to 1 */
15859                 if (ports[id].need_reconfig_queues == 0)
15860                         ports[id].need_reconfig_queues = queue;
15861         }
15862 }