df95bc20b050e0ef25b5b81b151688aac00cb74a
[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_DPAA_PMD
93 #include <rte_pmd_dpaa.h>
94 #endif
95 #ifdef RTE_LIBRTE_IXGBE_PMD
96 #include <rte_pmd_ixgbe.h>
97 #endif
98 #ifdef RTE_LIBRTE_I40E_PMD
99 #include <rte_pmd_i40e.h>
100 #endif
101 #ifdef RTE_LIBRTE_BNXT_PMD
102 #include <rte_pmd_bnxt.h>
103 #endif
104 #include "testpmd.h"
105 #include "cmdline_mtr.h"
106 #include "cmdline_tm.h"
107
108 static struct cmdline *testpmd_cl;
109
110 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
111
112 /* *** Help command with introduction. *** */
113 struct cmd_help_brief_result {
114         cmdline_fixed_string_t help;
115 };
116
117 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
118                                   struct cmdline *cl,
119                                   __attribute__((unused)) void *data)
120 {
121         cmdline_printf(
122                 cl,
123                 "\n"
124                 "Help is available for the following sections:\n\n"
125                 "    help control    : Start and stop forwarding.\n"
126                 "    help display    : Displaying port, stats and config "
127                 "information.\n"
128                 "    help config     : Configuration information.\n"
129                 "    help ports      : Configuring ports.\n"
130                 "    help registers  : Reading and setting port registers.\n"
131                 "    help filters    : Filters configuration help.\n"
132                 "    help all        : All of the above sections.\n\n"
133         );
134
135 }
136
137 cmdline_parse_token_string_t cmd_help_brief_help =
138         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
139
140 cmdline_parse_inst_t cmd_help_brief = {
141         .f = cmd_help_brief_parsed,
142         .data = NULL,
143         .help_str = "help: Show help",
144         .tokens = {
145                 (void *)&cmd_help_brief_help,
146                 NULL,
147         },
148 };
149
150 /* *** Help command with help sections. *** */
151 struct cmd_help_long_result {
152         cmdline_fixed_string_t help;
153         cmdline_fixed_string_t section;
154 };
155
156 static void cmd_help_long_parsed(void *parsed_result,
157                                  struct cmdline *cl,
158                                  __attribute__((unused)) void *data)
159 {
160         int show_all = 0;
161         struct cmd_help_long_result *res = parsed_result;
162
163         if (!strcmp(res->section, "all"))
164                 show_all = 1;
165
166         if (show_all || !strcmp(res->section, "control")) {
167
168                 cmdline_printf(
169                         cl,
170                         "\n"
171                         "Control forwarding:\n"
172                         "-------------------\n\n"
173
174                         "start\n"
175                         "    Start packet forwarding with current configuration.\n\n"
176
177                         "start tx_first\n"
178                         "    Start packet forwarding with current config"
179                         " after sending one burst of packets.\n\n"
180
181                         "stop\n"
182                         "    Stop packet forwarding, and display accumulated"
183                         " statistics.\n\n"
184
185                         "quit\n"
186                         "    Quit to prompt.\n\n"
187                 );
188         }
189
190         if (show_all || !strcmp(res->section, "display")) {
191
192                 cmdline_printf(
193                         cl,
194                         "\n"
195                         "Display:\n"
196                         "--------\n\n"
197
198                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
199                         "    Display information for port_id, or all.\n\n"
200
201                         "show port X rss reta (size) (mask0,mask1,...)\n"
202                         "    Display the rss redirection table entry indicated"
203                         " by masks on port X. size is used to indicate the"
204                         " hardware supported reta size\n\n"
205
206                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
207                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
208                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
209                         "    Display the RSS hash functions and RSS hash key"
210                         " of port X\n\n"
211
212                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
213                         "    Clear information for port_id, or all.\n\n"
214
215                         "show (rxq|txq) info (port_id) (queue_id)\n"
216                         "    Display information for configured RX/TX queue.\n\n"
217
218                         "show config (rxtx|cores|fwd|txpkts)\n"
219                         "    Display the given configuration.\n\n"
220
221                         "read rxd (port_id) (queue_id) (rxd_id)\n"
222                         "    Display an RX descriptor of a port RX queue.\n\n"
223
224                         "read txd (port_id) (queue_id) (txd_id)\n"
225                         "    Display a TX descriptor of a port TX queue.\n\n"
226
227                         "ddp get list (port_id)\n"
228                         "    Get ddp profile info list\n\n"
229
230                         "ddp get info (profile_path)\n"
231                         "    Get ddp profile information.\n\n"
232
233                         "show vf stats (port_id) (vf_id)\n"
234                         "    Display a VF's statistics.\n\n"
235
236                         "clear vf stats (port_id) (vf_id)\n"
237                         "    Reset a VF's statistics.\n\n"
238
239                         "show port (port_id) pctype mapping\n"
240                         "    Get flow ptype to pctype mapping on a port\n\n"
241
242                         "show port meter stats (port_id) (meter_id) (clear)\n"
243                         "    Get meter stats on a port\n\n"
244                         "show port tm cap (port_id)\n"
245                         "       Display the port TM capability.\n\n"
246
247                         "show port tm level cap (port_id) (level_id)\n"
248                         "       Display the port TM hierarchical level capability.\n\n"
249
250                         "show port tm node cap (port_id) (node_id)\n"
251                         "       Display the port TM node capability.\n\n"
252
253                         "show port tm node type (port_id) (node_id)\n"
254                         "       Display the port TM node type.\n\n"
255
256                         "show port tm node stats (port_id) (node_id) (clear)\n"
257                         "       Display the port TM node stats.\n\n"
258
259                 );
260         }
261
262         if (show_all || !strcmp(res->section, "config")) {
263                 cmdline_printf(
264                         cl,
265                         "\n"
266                         "Configuration:\n"
267                         "--------------\n"
268                         "Configuration changes only become active when"
269                         " forwarding is started/restarted.\n\n"
270
271                         "set default\n"
272                         "    Reset forwarding to the default configuration.\n\n"
273
274                         "set verbose (level)\n"
275                         "    Set the debug verbosity level X.\n\n"
276
277                         "set log global|(type) (level)\n"
278                         "    Set the log level.\n\n"
279
280                         "set nbport (num)\n"
281                         "    Set number of ports.\n\n"
282
283                         "set nbcore (num)\n"
284                         "    Set number of cores.\n\n"
285
286                         "set coremask (mask)\n"
287                         "    Set the forwarding cores hexadecimal mask.\n\n"
288
289                         "set portmask (mask)\n"
290                         "    Set the forwarding ports hexadecimal mask.\n\n"
291
292                         "set burst (num)\n"
293                         "    Set number of packets per burst.\n\n"
294
295                         "set burst tx delay (microseconds) retry (num)\n"
296                         "    Set the transmit delay time and number of retries,"
297                         " effective when retry is enabled.\n\n"
298
299                         "set txpkts (x[,y]*)\n"
300                         "    Set the length of each segment of TXONLY"
301                         " and optionally CSUM packets.\n\n"
302
303                         "set txsplit (off|on|rand)\n"
304                         "    Set the split policy for the TX packets."
305                         " Right now only applicable for CSUM and TXONLY"
306                         " modes\n\n"
307
308                         "set corelist (x[,y]*)\n"
309                         "    Set the list of forwarding cores.\n\n"
310
311                         "set portlist (x[,y]*)\n"
312                         "    Set the list of forwarding ports.\n\n"
313
314                         "set tx loopback (port_id) (on|off)\n"
315                         "    Enable or disable tx loopback.\n\n"
316
317                         "set all queues drop (port_id) (on|off)\n"
318                         "    Set drop enable bit for all queues.\n\n"
319
320                         "set vf split drop (port_id) (vf_id) (on|off)\n"
321                         "    Set split drop enable bit for a VF from the PF.\n\n"
322
323                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
324                         "    Set MAC antispoof for a VF from the PF.\n\n"
325
326                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
327                         "    Enable MACsec offload.\n\n"
328
329                         "set macsec offload (port_id) off\n"
330                         "    Disable MACsec offload.\n\n"
331
332                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
333                         "    Configure MACsec secure connection (SC).\n\n"
334
335                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
336                         "    Configure MACsec secure association (SA).\n\n"
337
338                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
339                         "    Set VF broadcast for a VF from the PF.\n\n"
340
341                         "vlan set strip (on|off) (port_id)\n"
342                         "    Set the VLAN strip on a port.\n\n"
343
344                         "vlan set stripq (on|off) (port_id,queue_id)\n"
345                         "    Set the VLAN strip for a queue on a port.\n\n"
346
347                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
348                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
349
350                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
351                         "    Set VLAN insert for a VF from the PF.\n\n"
352
353                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
354                         "    Set VLAN antispoof for a VF from the PF.\n\n"
355
356                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
357                         "    Set VLAN tag for a VF from the PF.\n\n"
358
359                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
360                         "    Set a VF's max bandwidth(Mbps).\n\n"
361
362                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
363                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
364
365                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
366                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
367
368                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
369                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
370
371                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
372                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
373
374                         "vlan set filter (on|off) (port_id)\n"
375                         "    Set the VLAN filter on a port.\n\n"
376
377                         "vlan set qinq (on|off) (port_id)\n"
378                         "    Set the VLAN QinQ (extended queue in queue)"
379                         " on a port.\n\n"
380
381                         "vlan set (inner|outer) tpid (value) (port_id)\n"
382                         "    Set the VLAN TPID for Packet Filtering on"
383                         " a port\n\n"
384
385                         "rx_vlan add (vlan_id|all) (port_id)\n"
386                         "    Add a vlan_id, or all identifiers, to the set"
387                         " of VLAN identifiers filtered by port_id.\n\n"
388
389                         "rx_vlan rm (vlan_id|all) (port_id)\n"
390                         "    Remove a vlan_id, or all identifiers, from the set"
391                         " of VLAN identifiers filtered by port_id.\n\n"
392
393                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
394                         "    Add a vlan_id, to the set of VLAN identifiers"
395                         "filtered for VF(s) from port_id.\n\n"
396
397                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
398                         "    Remove a vlan_id, to the set of VLAN identifiers"
399                         "filtered for VF(s) from port_id.\n\n"
400
401                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
402                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
403                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
404                         "   add a tunnel filter of a port.\n\n"
405
406                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
407                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
408                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
409                         "   remove a tunnel filter of a port.\n\n"
410
411                         "rx_vxlan_port add (udp_port) (port_id)\n"
412                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "rx_vxlan_port rm (udp_port) (port_id)\n"
415                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
418                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
419                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
420
421                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
422                         "    Set port based TX VLAN insertion.\n\n"
423
424                         "tx_vlan reset (port_id)\n"
425                         "    Disable hardware insertion of a VLAN header in"
426                         " packets sent on a port.\n\n"
427
428                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
429                         "    Select hardware or software calculation of the"
430                         " checksum when transmitting a packet using the"
431                         " csum forward engine.\n"
432                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
433                         "    outer-ip concerns the outer IP layer in"
434                         " case the packet is recognized as a tunnel packet by"
435                         " the forward engine (vxlan, gre and ipip are supported)\n"
436                         "    Please check the NIC datasheet for HW limits.\n\n"
437
438                         "csum parse-tunnel (on|off) (tx_port_id)\n"
439                         "    If disabled, treat tunnel packets as non-tunneled"
440                         " packets (treat inner headers as payload). The port\n"
441                         "    argument is the port used for TX in csum forward"
442                         " engine.\n\n"
443
444                         "csum show (port_id)\n"
445                         "    Display tx checksum offload configuration\n\n"
446
447                         "tso set (segsize) (portid)\n"
448                         "    Enable TCP Segmentation Offload in csum forward"
449                         " engine.\n"
450                         "    Please check the NIC datasheet for HW limits.\n\n"
451
452                         "tso show (portid)"
453                         "    Display the status of TCP Segmentation Offload.\n\n"
454
455                         "set port (port_id) gro on|off\n"
456                         "    Enable or disable Generic Receive Offload in"
457                         " csum forwarding engine.\n\n"
458
459                         "show port (port_id) gro\n"
460                         "    Display GRO configuration.\n\n"
461
462                         "set gro flush (cycles)\n"
463                         "    Set the cycle to flush GROed packets from"
464                         " reassembly tables.\n\n"
465
466                         "set port (port_id) gso (on|off)"
467                         "    Enable or disable Generic Segmentation Offload in"
468                         " csum forwarding engine.\n\n"
469
470                         "set gso segsz (length)\n"
471                         "    Set max packet length for output GSO segments,"
472                         " including packet header and payload.\n\n"
473
474                         "show port (port_id) gso\n"
475                         "    Show GSO configuration.\n\n"
476
477                         "set fwd (%s)\n"
478                         "    Set packet forwarding mode.\n\n"
479
480                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Add a MAC address on port_id.\n\n"
482
483                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
484                         "    Remove a MAC address from port_id.\n\n"
485
486                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the default MAC address for port_id.\n\n"
488
489                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
490                         "    Add a MAC address for a VF on the port.\n\n"
491
492                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
493                         "    Set the MAC address for a VF from the PF.\n\n"
494
495                         "set eth-peer (port_id) (peer_addr)\n"
496                         "    set the peer address for certain port.\n\n"
497
498                         "set port (port_id) uta (mac_address|all) (on|off)\n"
499                         "    Add/Remove a or all unicast hash filter(s)"
500                         "from port X.\n\n"
501
502                         "set promisc (port_id|all) (on|off)\n"
503                         "    Set the promiscuous mode on port_id, or all.\n\n"
504
505                         "set allmulti (port_id|all) (on|off)\n"
506                         "    Set the allmulti mode on port_id, or all.\n\n"
507
508                         "set vf promisc (port_id) (vf_id) (on|off)\n"
509                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
510
511                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
512                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
513
514                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
515                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
516                         " (on|off) autoneg (on|off) (port_id)\n"
517                         "set flow_ctrl rx (on|off) (portid)\n"
518                         "set flow_ctrl tx (on|off) (portid)\n"
519                         "set flow_ctrl high_water (high_water) (portid)\n"
520                         "set flow_ctrl low_water (low_water) (portid)\n"
521                         "set flow_ctrl pause_time (pause_time) (portid)\n"
522                         "set flow_ctrl send_xon (send_xon) (portid)\n"
523                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
524                         "set flow_ctrl autoneg (on|off) (port_id)\n"
525                         "    Set the link flow control parameter on a port.\n\n"
526
527                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
528                         " (low_water) (pause_time) (priority) (port_id)\n"
529                         "    Set the priority flow control parameter on a"
530                         " port.\n\n"
531
532                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
533                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
534                         " queue on port.\n"
535                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
536                         " on port 0 to mapping 5.\n\n"
537
538                         "set xstats-hide-zero on|off\n"
539                         "    Set the option to hide the zero values"
540                         " for xstats display.\n"
541
542                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
543                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
544
545                         "set port (port_id) vf (vf_id) (mac_addr)"
546                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
547                         "   Add/Remove unicast or multicast MAC addr filter"
548                         " for a VF.\n\n"
549
550                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
551                         "|MPE) (on|off)\n"
552                         "    AUPE:accepts untagged VLAN;"
553                         "ROPE:accept unicast hash\n\n"
554                         "    BAM:accepts broadcast packets;"
555                         "MPE:accepts all multicast packets\n\n"
556                         "    Enable/Disable a VF receive mode of a port\n\n"
557
558                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
559                         "    Set rate limit for a queue of a port\n\n"
560
561                         "set port (port_id) vf (vf_id) rate (rate_num) "
562                         "queue_mask (queue_mask_value)\n"
563                         "    Set rate limit for queues in VF of a port\n\n"
564
565                         "set port (port_id) mirror-rule (rule_id)"
566                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
567                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
568                         "   Set pool or vlan type mirror rule on a port.\n"
569                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
570                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
571                         " to pool 0.\n\n"
572
573                         "set port (port_id) mirror-rule (rule_id)"
574                         " (uplink-mirror|downlink-mirror) dst-pool"
575                         " (pool_id) (on|off)\n"
576                         "   Set uplink or downlink type mirror rule on a port.\n"
577                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
578                         " 0 on' enable mirror income traffic to pool 0.\n\n"
579
580                         "reset port (port_id) mirror-rule (rule_id)\n"
581                         "   Reset a mirror rule.\n\n"
582
583                         "set flush_rx (on|off)\n"
584                         "   Flush (default) or don't flush RX streams before"
585                         " forwarding. Mainly used with PCAP drivers.\n\n"
586
587                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
588                         "   Set the bypass mode for the lowest port on bypass enabled"
589                         " NIC.\n\n"
590
591                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
592                         "mode (normal|bypass|isolate) (port_id)\n"
593                         "   Set the event required to initiate specified bypass mode for"
594                         " the lowest port on a bypass enabled NIC where:\n"
595                         "       timeout   = enable bypass after watchdog timeout.\n"
596                         "       os_on     = enable bypass when OS/board is powered on.\n"
597                         "       os_off    = enable bypass when OS/board is powered off.\n"
598                         "       power_on  = enable bypass when power supply is turned on.\n"
599                         "       power_off = enable bypass when power supply is turned off."
600                         "\n\n"
601
602                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
603                         "   Set the bypass watchdog timeout to 'n' seconds"
604                         " where 0 = instant.\n\n"
605
606                         "show bypass config (port_id)\n"
607                         "   Show the bypass configuration for a bypass enabled NIC"
608                         " using the lowest port on the NIC.\n\n"
609
610 #ifdef RTE_LIBRTE_PMD_BOND
611                         "create bonded device (mode) (socket)\n"
612                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
613
614                         "add bonding slave (slave_id) (port_id)\n"
615                         "       Add a slave device to a bonded device.\n\n"
616
617                         "remove bonding slave (slave_id) (port_id)\n"
618                         "       Remove a slave device from a bonded device.\n\n"
619
620                         "set bonding mode (value) (port_id)\n"
621                         "       Set the bonding mode on a bonded device.\n\n"
622
623                         "set bonding primary (slave_id) (port_id)\n"
624                         "       Set the primary slave for a bonded device.\n\n"
625
626                         "show bonding config (port_id)\n"
627                         "       Show the bonding config for port_id.\n\n"
628
629                         "set bonding mac_addr (port_id) (address)\n"
630                         "       Set the MAC address of a bonded device.\n\n"
631
632                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
633                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
634
635                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
636                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
637
638                         "set bonding mon_period (port_id) (value)\n"
639                         "       Set the bonding link status monitoring polling period in ms.\n\n"
640
641                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
642                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
643
644 #endif
645                         "set link-up port (port_id)\n"
646                         "       Set link up for a port.\n\n"
647
648                         "set link-down port (port_id)\n"
649                         "       Set link down for a port.\n\n"
650
651                         "E-tag set insertion on port-tag-id (value)"
652                         " port (port_id) vf (vf_id)\n"
653                         "    Enable E-tag insertion for a VF on a port\n\n"
654
655                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
656                         "    Disable E-tag insertion for a VF on a port\n\n"
657
658                         "E-tag set stripping (on|off) port (port_id)\n"
659                         "    Enable/disable E-tag stripping on a port\n\n"
660
661                         "E-tag set forwarding (on|off) port (port_id)\n"
662                         "    Enable/disable E-tag based forwarding"
663                         " on a port\n\n"
664
665                         "E-tag set filter add e-tag-id (value) dst-pool"
666                         " (pool_id) port (port_id)\n"
667                         "    Add an E-tag forwarding filter on a port\n\n"
668
669                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
670                         "    Delete an E-tag forwarding filter on a port\n\n"
671
672 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
673                         "set port tm hierarchy default (port_id)\n"
674                         "       Set default traffic Management hierarchy on a port\n\n"
675
676 #endif
677                         "ddp add (port_id) (profile_path[,output_path])\n"
678                         "    Load a profile package on a port\n\n"
679
680                         "ddp del (port_id) (profile_path)\n"
681                         "    Delete a profile package from a port\n\n"
682
683                         "ptype mapping get (port_id) (valid_only)\n"
684                         "    Get ptype mapping on a port\n\n"
685
686                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
687                         "    Replace target with the pkt_type in ptype mapping\n\n"
688
689                         "ptype mapping reset (port_id)\n"
690                         "    Reset ptype mapping on a port\n\n"
691
692                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
693                         "    Update a ptype mapping item on a port\n\n"
694
695                         "set port (port_id) queue-region region_id (value) "
696                         "queue_start_index (value) queue_num (value)\n"
697                         "    Set a queue region on a port\n\n"
698
699                         "set port (port_id) queue-region region_id (value) "
700                         "flowtype (value)\n"
701                         "    Set a flowtype region index on a port\n\n"
702
703                         "set port (port_id) queue-region UP (value) region_id (value)\n"
704                         "    Set the mapping of User Priority to "
705                         "queue region on a port\n\n"
706
707                         "set port (port_id) queue-region flush (on|off)\n"
708                         "    flush all queue region related configuration\n\n"
709
710                         "show port meter cap (port_id)\n"
711                         "    Show port meter capability information\n\n"
712
713                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
714                         "    meter profile add - srtcm rfc 2697\n\n"
715
716                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
717                         "    meter profile add - trtcm rfc 2698\n\n"
718
719                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
720                         "    meter profile add - trtcm rfc 4115\n\n"
721
722                         "del port meter profile (port_id) (profile_id)\n"
723                         "    meter profile delete\n\n"
724
725                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
726                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
727                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
728                         "(dscp_tbl_entry63)]\n"
729                         "    meter create\n\n"
730
731                         "enable port meter (port_id) (mtr_id)\n"
732                         "    meter enable\n\n"
733
734                         "disable port meter (port_id) (mtr_id)\n"
735                         "    meter disable\n\n"
736
737                         "del port meter (port_id) (mtr_id)\n"
738                         "    meter delete\n\n"
739
740                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
741                         "    meter update meter profile\n\n"
742
743                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
744                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
745                         "    update meter dscp table entries\n\n"
746
747                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
748                         "(action0) [(action1) (action2)]\n"
749                         "    meter update policer action\n\n"
750
751                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
752                         "    meter update stats\n\n"
753
754                         "show port (port_id) queue-region\n"
755                         "    show all queue region related configuration info\n\n"
756
757                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
758                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
759                         "       Add port tm node private shaper profile.\n\n"
760
761                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
762                         "       Delete port tm node private shaper profile.\n\n"
763
764                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
765                         " (shaper_profile_id)\n"
766                         "       Add/update port tm node shared shaper.\n\n"
767
768                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
769                         "       Delete port tm node shared shaper.\n\n"
770
771                         "set port tm node shaper profile (port_id) (node_id)"
772                         " (shaper_profile_id)\n"
773                         "       Set port tm node shaper profile.\n\n"
774
775                         "add port tm node wred profile (port_id) (wred_profile_id)"
776                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
777                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
778                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
779                         "       Add port tm node wred profile.\n\n"
780
781                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
782                         "       Delete port tm node wred profile.\n\n"
783
784                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
785                         " (priority) (weight) (level_id) (shaper_profile_id)"
786                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
787                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
788                         "       Add port tm nonleaf node.\n\n"
789
790                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
791                         " (priority) (weight) (level_id) (shaper_profile_id)"
792                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
793                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
794                         "       Add port tm leaf node.\n\n"
795
796                         "del port tm node (port_id) (node_id)\n"
797                         "       Delete port tm node.\n\n"
798
799                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
800                         " (priority) (weight)\n"
801                         "       Set port tm node parent.\n\n"
802
803                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
804                         "       Commit tm hierarchy.\n\n"
805
806                         , list_pkt_forwarding_modes()
807                 );
808         }
809
810         if (show_all || !strcmp(res->section, "ports")) {
811
812                 cmdline_printf(
813                         cl,
814                         "\n"
815                         "Port Operations:\n"
816                         "----------------\n\n"
817
818                         "port start (port_id|all)\n"
819                         "    Start all ports or port_id.\n\n"
820
821                         "port stop (port_id|all)\n"
822                         "    Stop all ports or port_id.\n\n"
823
824                         "port close (port_id|all)\n"
825                         "    Close all ports or port_id.\n\n"
826
827                         "port attach (ident)\n"
828                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
829
830                         "port detach (port_id)\n"
831                         "    Detach physical or virtual dev by port_id\n\n"
832
833                         "port config (port_id|all)"
834                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
835                         " duplex (half|full|auto)\n"
836                         "    Set speed and duplex for all ports or port_id\n\n"
837
838                         "port config all (rxq|txq|rxd|txd) (value)\n"
839                         "    Set number for rxq/txq/rxd/txd.\n\n"
840
841                         "port config all max-pkt-len (value)\n"
842                         "    Set the max packet length.\n\n"
843
844                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
845                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
846                         " (on|off)\n"
847                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
848                         " for ports.\n\n"
849
850                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
851                         "geneve|nvgre|none|<flowtype_id>)\n"
852                         "    Set the RSS mode.\n\n"
853
854                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
855                         "    Set the RSS redirection table.\n\n"
856
857                         "port config (port_id) dcb vt (on|off) (traffic_class)"
858                         " pfc (on|off)\n"
859                         "    Set the DCB mode.\n\n"
860
861                         "port config all burst (value)\n"
862                         "    Set the number of packets per burst.\n\n"
863
864                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
865                         " (value)\n"
866                         "    Set the ring prefetch/host/writeback threshold"
867                         " for tx/rx queue.\n\n"
868
869                         "port config all (txfreet|txrst|rxfreet) (value)\n"
870                         "    Set free threshold for rx/tx, or set"
871                         " tx rs bit threshold.\n\n"
872                         "port config mtu X value\n"
873                         "    Set the MTU of port X to a given value\n\n"
874
875                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
876                         "    Start/stop a rx/tx queue of port X. Only take effect"
877                         " when port X is started\n\n"
878
879                         "port config (port_id|all) l2-tunnel E-tag ether-type"
880                         " (value)\n"
881                         "    Set the value of E-tag ether-type.\n\n"
882
883                         "port config (port_id|all) l2-tunnel E-tag"
884                         " (enable|disable)\n"
885                         "    Enable/disable the E-tag support.\n\n"
886
887                         "port config (port_id) pctype mapping reset\n"
888                         "    Reset flow type to pctype mapping on a port\n\n"
889
890                         "port config (port_id) pctype mapping update"
891                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
892                         "    Update a flow type to pctype mapping item on a port\n\n"
893
894                         "port config (port_id) pctype (pctype_id) hash_inset|"
895                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
896                         " (field_idx)\n"
897                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
898
899                         "port config (port_id) pctype (pctype_id) hash_inset|"
900                         "fdir_inset|fdir_flx_inset clear all"
901                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
902                 );
903         }
904
905         if (show_all || !strcmp(res->section, "registers")) {
906
907                 cmdline_printf(
908                         cl,
909                         "\n"
910                         "Registers:\n"
911                         "----------\n\n"
912
913                         "read reg (port_id) (address)\n"
914                         "    Display value of a port register.\n\n"
915
916                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
917                         "    Display a port register bit field.\n\n"
918
919                         "read regbit (port_id) (address) (bit_x)\n"
920                         "    Display a single port register bit.\n\n"
921
922                         "write reg (port_id) (address) (value)\n"
923                         "    Set value of a port register.\n\n"
924
925                         "write regfield (port_id) (address) (bit_x) (bit_y)"
926                         " (value)\n"
927                         "    Set bit field of a port register.\n\n"
928
929                         "write regbit (port_id) (address) (bit_x) (value)\n"
930                         "    Set single bit value of a port register.\n\n"
931                 );
932         }
933         if (show_all || !strcmp(res->section, "filters")) {
934
935                 cmdline_printf(
936                         cl,
937                         "\n"
938                         "filters:\n"
939                         "--------\n\n"
940
941                         "ethertype_filter (port_id) (add|del)"
942                         " (mac_addr|mac_ignr) (mac_address) ethertype"
943                         " (ether_type) (drop|fwd) queue (queue_id)\n"
944                         "    Add/Del an ethertype filter.\n\n"
945
946                         "2tuple_filter (port_id) (add|del)"
947                         " dst_port (dst_port_value) protocol (protocol_value)"
948                         " mask (mask_value) tcp_flags (tcp_flags_value)"
949                         " priority (prio_value) queue (queue_id)\n"
950                         "    Add/Del a 2tuple filter.\n\n"
951
952                         "5tuple_filter (port_id) (add|del)"
953                         " dst_ip (dst_address) src_ip (src_address)"
954                         " dst_port (dst_port_value) src_port (src_port_value)"
955                         " protocol (protocol_value)"
956                         " mask (mask_value) tcp_flags (tcp_flags_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a 5tuple filter.\n\n"
959
960                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
961                         "    Add/Del syn filter.\n\n"
962
963                         "flex_filter (port_id) (add|del) len (len_value)"
964                         " bytes (bytes_value) mask (mask_value)"
965                         " priority (prio_value) queue (queue_id)\n"
966                         "    Add/Del a flex filter.\n\n"
967
968                         "flow_director_filter (port_id) mode IP (add|del|update)"
969                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
970                         " src (src_ip_address) dst (dst_ip_address)"
971                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
972                         " vlan (vlan_value) flexbytes (flexbytes_value)"
973                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
974                         " fd_id (fd_id_value)\n"
975                         "    Add/Del an IP type flow director filter.\n\n"
976
977                         "flow_director_filter (port_id) mode IP (add|del|update)"
978                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
979                         " src (src_ip_address) (src_port)"
980                         " dst (dst_ip_address) (dst_port)"
981                         " tos (tos_value) ttl (ttl_value)"
982                         " vlan (vlan_value) flexbytes (flexbytes_value)"
983                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
984                         " fd_id (fd_id_value)\n"
985                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
986
987                         "flow_director_filter (port_id) mode IP (add|del|update)"
988                         " flow (ipv4-sctp|ipv6-sctp)"
989                         " src (src_ip_address) (src_port)"
990                         " dst (dst_ip_address) (dst_port)"
991                         " tag (verification_tag) "
992                         " tos (tos_value) ttl (ttl_value)"
993                         " vlan (vlan_value)"
994                         " flexbytes (flexbytes_value) (drop|fwd)"
995                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
996                         "    Add/Del a SCTP type flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode IP (add|del|update)"
999                         " flow l2_payload ether (ethertype)"
1000                         " flexbytes (flexbytes_value) (drop|fwd)"
1001                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1002                         "    Add/Del a l2 payload type flow director filter.\n\n"
1003
1004                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1005                         " mac (mac_address) vlan (vlan_value)"
1006                         " flexbytes (flexbytes_value) (drop|fwd)"
1007                         " queue (queue_id) fd_id (fd_id_value)\n"
1008                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1009
1010                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1011                         " mac (mac_address) vlan (vlan_value)"
1012                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1013                         " flexbytes (flexbytes_value) (drop|fwd)"
1014                         " queue (queue_id) fd_id (fd_id_value)\n"
1015                         "    Add/Del a Tunnel flow director filter.\n\n"
1016
1017                         "flow_director_filter (port_id) mode raw (add|del|update)"
1018                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1019                         " fd_id (fd_id_value) packet (packet file name)\n"
1020                         "    Add/Del a raw type flow director filter.\n\n"
1021
1022                         "flush_flow_director (port_id)\n"
1023                         "    Flush all flow director entries of a device.\n\n"
1024
1025                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1026                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1027                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1028                         "    Set flow director IP mask.\n\n"
1029
1030                         "flow_director_mask (port_id) mode MAC-VLAN"
1031                         " vlan (vlan_value)\n"
1032                         "    Set flow director MAC-VLAN mask.\n\n"
1033
1034                         "flow_director_mask (port_id) mode Tunnel"
1035                         " vlan (vlan_value) mac (mac_value)"
1036                         " tunnel-type (tunnel_type_value)"
1037                         " tunnel-id (tunnel_id_value)\n"
1038                         "    Set flow director Tunnel mask.\n\n"
1039
1040                         "flow_director_flex_mask (port_id)"
1041                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1042                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1043                         " (mask)\n"
1044                         "    Configure mask of flex payload.\n\n"
1045
1046                         "flow_director_flex_payload (port_id)"
1047                         " (raw|l2|l3|l4) (config)\n"
1048                         "    Configure flex payload selection.\n\n"
1049
1050                         "get_sym_hash_ena_per_port (port_id)\n"
1051                         "    get symmetric hash enable configuration per port.\n\n"
1052
1053                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1054                         "    set symmetric hash enable configuration per port"
1055                         " to enable or disable.\n\n"
1056
1057                         "get_hash_global_config (port_id)\n"
1058                         "    Get the global configurations of hash filters.\n\n"
1059
1060                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1061                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1062                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1063                         " (enable|disable)\n"
1064                         "    Set the global configurations of hash filters.\n\n"
1065
1066                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1067                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1068                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1069                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1070                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1071                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1072                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1073                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1074                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1075                         "fld-8th|none) (select|add)\n"
1076                         "    Set the input set for hash.\n\n"
1077
1078                         "set_fdir_input_set (port_id) "
1079                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1080                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1081                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1082                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1083                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1084                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1085                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1086                         " (select|add)\n"
1087                         "    Set the input set for FDir.\n\n"
1088
1089                         "flow validate {port_id}"
1090                         " [group {group_id}] [priority {level}]"
1091                         " [ingress] [egress]"
1092                         " pattern {item} [/ {item} [...]] / end"
1093                         " actions {action} [/ {action} [...]] / end\n"
1094                         "    Check whether a flow rule can be created.\n\n"
1095
1096                         "flow create {port_id}"
1097                         " [group {group_id}] [priority {level}]"
1098                         " [ingress] [egress]"
1099                         " pattern {item} [/ {item} [...]] / end"
1100                         " actions {action} [/ {action} [...]] / end\n"
1101                         "    Create a flow rule.\n\n"
1102
1103                         "flow destroy {port_id} rule {rule_id} [...]\n"
1104                         "    Destroy specific flow rules.\n\n"
1105
1106                         "flow flush {port_id}\n"
1107                         "    Destroy all flow rules.\n\n"
1108
1109                         "flow query {port_id} {rule_id} {action}\n"
1110                         "    Query an existing flow rule.\n\n"
1111
1112                         "flow list {port_id} [group {group_id}] [...]\n"
1113                         "    List existing flow rules sorted by priority,"
1114                         " filtered by group identifiers.\n\n"
1115
1116                         "flow isolate {port_id} {boolean}\n"
1117                         "    Restrict ingress traffic to the defined"
1118                         " flow rules\n\n"
1119                 );
1120         }
1121 }
1122
1123 cmdline_parse_token_string_t cmd_help_long_help =
1124         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1125
1126 cmdline_parse_token_string_t cmd_help_long_section =
1127         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1128                         "all#control#display#config#"
1129                         "ports#registers#filters");
1130
1131 cmdline_parse_inst_t cmd_help_long = {
1132         .f = cmd_help_long_parsed,
1133         .data = NULL,
1134         .help_str = "help all|control|display|config|ports|register|filters: "
1135                 "Show help",
1136         .tokens = {
1137                 (void *)&cmd_help_long_help,
1138                 (void *)&cmd_help_long_section,
1139                 NULL,
1140         },
1141 };
1142
1143
1144 /* *** start/stop/close all ports *** */
1145 struct cmd_operate_port_result {
1146         cmdline_fixed_string_t keyword;
1147         cmdline_fixed_string_t name;
1148         cmdline_fixed_string_t value;
1149 };
1150
1151 static void cmd_operate_port_parsed(void *parsed_result,
1152                                 __attribute__((unused)) struct cmdline *cl,
1153                                 __attribute__((unused)) void *data)
1154 {
1155         struct cmd_operate_port_result *res = parsed_result;
1156
1157         if (!strcmp(res->name, "start"))
1158                 start_port(RTE_PORT_ALL);
1159         else if (!strcmp(res->name, "stop"))
1160                 stop_port(RTE_PORT_ALL);
1161         else if (!strcmp(res->name, "close"))
1162                 close_port(RTE_PORT_ALL);
1163         else if (!strcmp(res->name, "reset"))
1164                 reset_port(RTE_PORT_ALL);
1165         else
1166                 printf("Unknown parameter\n");
1167 }
1168
1169 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1170         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1171                                                                 "port");
1172 cmdline_parse_token_string_t cmd_operate_port_all_port =
1173         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1174                                                 "start#stop#close#reset");
1175 cmdline_parse_token_string_t cmd_operate_port_all_all =
1176         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1177
1178 cmdline_parse_inst_t cmd_operate_port = {
1179         .f = cmd_operate_port_parsed,
1180         .data = NULL,
1181         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1182         .tokens = {
1183                 (void *)&cmd_operate_port_all_cmd,
1184                 (void *)&cmd_operate_port_all_port,
1185                 (void *)&cmd_operate_port_all_all,
1186                 NULL,
1187         },
1188 };
1189
1190 /* *** start/stop/close specific port *** */
1191 struct cmd_operate_specific_port_result {
1192         cmdline_fixed_string_t keyword;
1193         cmdline_fixed_string_t name;
1194         uint8_t value;
1195 };
1196
1197 static void cmd_operate_specific_port_parsed(void *parsed_result,
1198                         __attribute__((unused)) struct cmdline *cl,
1199                                 __attribute__((unused)) void *data)
1200 {
1201         struct cmd_operate_specific_port_result *res = parsed_result;
1202
1203         if (!strcmp(res->name, "start"))
1204                 start_port(res->value);
1205         else if (!strcmp(res->name, "stop"))
1206                 stop_port(res->value);
1207         else if (!strcmp(res->name, "close"))
1208                 close_port(res->value);
1209         else if (!strcmp(res->name, "reset"))
1210                 reset_port(res->value);
1211         else
1212                 printf("Unknown parameter\n");
1213 }
1214
1215 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1216         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1217                                                         keyword, "port");
1218 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1219         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1220                                                 name, "start#stop#close#reset");
1221 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1222         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1223                                                         value, UINT8);
1224
1225 cmdline_parse_inst_t cmd_operate_specific_port = {
1226         .f = cmd_operate_specific_port_parsed,
1227         .data = NULL,
1228         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1229         .tokens = {
1230                 (void *)&cmd_operate_specific_port_cmd,
1231                 (void *)&cmd_operate_specific_port_port,
1232                 (void *)&cmd_operate_specific_port_id,
1233                 NULL,
1234         },
1235 };
1236
1237 /* *** attach a specified port *** */
1238 struct cmd_operate_attach_port_result {
1239         cmdline_fixed_string_t port;
1240         cmdline_fixed_string_t keyword;
1241         cmdline_fixed_string_t identifier;
1242 };
1243
1244 static void cmd_operate_attach_port_parsed(void *parsed_result,
1245                                 __attribute__((unused)) struct cmdline *cl,
1246                                 __attribute__((unused)) void *data)
1247 {
1248         struct cmd_operate_attach_port_result *res = parsed_result;
1249
1250         if (!strcmp(res->keyword, "attach"))
1251                 attach_port(res->identifier);
1252         else
1253                 printf("Unknown parameter\n");
1254 }
1255
1256 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1257         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1258                         port, "port");
1259 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1260         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1261                         keyword, "attach");
1262 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1264                         identifier, NULL);
1265
1266 cmdline_parse_inst_t cmd_operate_attach_port = {
1267         .f = cmd_operate_attach_port_parsed,
1268         .data = NULL,
1269         .help_str = "port attach <identifier>: "
1270                 "(identifier: pci address or virtual dev name)",
1271         .tokens = {
1272                 (void *)&cmd_operate_attach_port_port,
1273                 (void *)&cmd_operate_attach_port_keyword,
1274                 (void *)&cmd_operate_attach_port_identifier,
1275                 NULL,
1276         },
1277 };
1278
1279 /* *** detach a specified port *** */
1280 struct cmd_operate_detach_port_result {
1281         cmdline_fixed_string_t port;
1282         cmdline_fixed_string_t keyword;
1283         portid_t port_id;
1284 };
1285
1286 static void cmd_operate_detach_port_parsed(void *parsed_result,
1287                                 __attribute__((unused)) struct cmdline *cl,
1288                                 __attribute__((unused)) void *data)
1289 {
1290         struct cmd_operate_detach_port_result *res = parsed_result;
1291
1292         if (!strcmp(res->keyword, "detach"))
1293                 detach_port(res->port_id);
1294         else
1295                 printf("Unknown parameter\n");
1296 }
1297
1298 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1299         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1300                         port, "port");
1301 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1302         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1303                         keyword, "detach");
1304 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1305         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1306                         port_id, UINT16);
1307
1308 cmdline_parse_inst_t cmd_operate_detach_port = {
1309         .f = cmd_operate_detach_port_parsed,
1310         .data = NULL,
1311         .help_str = "port detach <port_id>",
1312         .tokens = {
1313                 (void *)&cmd_operate_detach_port_port,
1314                 (void *)&cmd_operate_detach_port_keyword,
1315                 (void *)&cmd_operate_detach_port_port_id,
1316                 NULL,
1317         },
1318 };
1319
1320 /* *** configure speed for all ports *** */
1321 struct cmd_config_speed_all {
1322         cmdline_fixed_string_t port;
1323         cmdline_fixed_string_t keyword;
1324         cmdline_fixed_string_t all;
1325         cmdline_fixed_string_t item1;
1326         cmdline_fixed_string_t item2;
1327         cmdline_fixed_string_t value1;
1328         cmdline_fixed_string_t value2;
1329 };
1330
1331 static int
1332 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1333 {
1334
1335         int duplex;
1336
1337         if (!strcmp(duplexstr, "half")) {
1338                 duplex = ETH_LINK_HALF_DUPLEX;
1339         } else if (!strcmp(duplexstr, "full")) {
1340                 duplex = ETH_LINK_FULL_DUPLEX;
1341         } else if (!strcmp(duplexstr, "auto")) {
1342                 duplex = ETH_LINK_FULL_DUPLEX;
1343         } else {
1344                 printf("Unknown duplex parameter\n");
1345                 return -1;
1346         }
1347
1348         if (!strcmp(speedstr, "10")) {
1349                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1350                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1351         } else if (!strcmp(speedstr, "100")) {
1352                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1353                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1354         } else {
1355                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1356                         printf("Invalid speed/duplex parameters\n");
1357                         return -1;
1358                 }
1359                 if (!strcmp(speedstr, "1000")) {
1360                         *speed = ETH_LINK_SPEED_1G;
1361                 } else if (!strcmp(speedstr, "10000")) {
1362                         *speed = ETH_LINK_SPEED_10G;
1363                 } else if (!strcmp(speedstr, "25000")) {
1364                         *speed = ETH_LINK_SPEED_25G;
1365                 } else if (!strcmp(speedstr, "40000")) {
1366                         *speed = ETH_LINK_SPEED_40G;
1367                 } else if (!strcmp(speedstr, "50000")) {
1368                         *speed = ETH_LINK_SPEED_50G;
1369                 } else if (!strcmp(speedstr, "100000")) {
1370                         *speed = ETH_LINK_SPEED_100G;
1371                 } else if (!strcmp(speedstr, "auto")) {
1372                         *speed = ETH_LINK_SPEED_AUTONEG;
1373                 } else {
1374                         printf("Unknown speed parameter\n");
1375                         return -1;
1376                 }
1377         }
1378
1379         return 0;
1380 }
1381
1382 static void
1383 cmd_config_speed_all_parsed(void *parsed_result,
1384                         __attribute__((unused)) struct cmdline *cl,
1385                         __attribute__((unused)) void *data)
1386 {
1387         struct cmd_config_speed_all *res = parsed_result;
1388         uint32_t link_speed;
1389         portid_t pid;
1390
1391         if (!all_ports_stopped()) {
1392                 printf("Please stop all ports first\n");
1393                 return;
1394         }
1395
1396         if (parse_and_check_speed_duplex(res->value1, res->value2,
1397                         &link_speed) < 0)
1398                 return;
1399
1400         RTE_ETH_FOREACH_DEV(pid) {
1401                 ports[pid].dev_conf.link_speeds = link_speed;
1402         }
1403
1404         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1405 }
1406
1407 cmdline_parse_token_string_t cmd_config_speed_all_port =
1408         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1409 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1410         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1411                                                         "config");
1412 cmdline_parse_token_string_t cmd_config_speed_all_all =
1413         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1414 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1415         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1416 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1417         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1418                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1419 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1420         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1421 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1422         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1423                                                 "half#full#auto");
1424
1425 cmdline_parse_inst_t cmd_config_speed_all = {
1426         .f = cmd_config_speed_all_parsed,
1427         .data = NULL,
1428         .help_str = "port config all speed "
1429                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1430                                                         "half|full|auto",
1431         .tokens = {
1432                 (void *)&cmd_config_speed_all_port,
1433                 (void *)&cmd_config_speed_all_keyword,
1434                 (void *)&cmd_config_speed_all_all,
1435                 (void *)&cmd_config_speed_all_item1,
1436                 (void *)&cmd_config_speed_all_value1,
1437                 (void *)&cmd_config_speed_all_item2,
1438                 (void *)&cmd_config_speed_all_value2,
1439                 NULL,
1440         },
1441 };
1442
1443 /* *** configure speed for specific port *** */
1444 struct cmd_config_speed_specific {
1445         cmdline_fixed_string_t port;
1446         cmdline_fixed_string_t keyword;
1447         uint8_t id;
1448         cmdline_fixed_string_t item1;
1449         cmdline_fixed_string_t item2;
1450         cmdline_fixed_string_t value1;
1451         cmdline_fixed_string_t value2;
1452 };
1453
1454 static void
1455 cmd_config_speed_specific_parsed(void *parsed_result,
1456                                 __attribute__((unused)) struct cmdline *cl,
1457                                 __attribute__((unused)) void *data)
1458 {
1459         struct cmd_config_speed_specific *res = parsed_result;
1460         uint32_t link_speed;
1461
1462         if (!all_ports_stopped()) {
1463                 printf("Please stop all ports first\n");
1464                 return;
1465         }
1466
1467         if (port_id_is_invalid(res->id, ENABLED_WARN))
1468                 return;
1469
1470         if (parse_and_check_speed_duplex(res->value1, res->value2,
1471                         &link_speed) < 0)
1472                 return;
1473
1474         ports[res->id].dev_conf.link_speeds = link_speed;
1475
1476         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1477 }
1478
1479
1480 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1482                                                                 "port");
1483 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1484         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1485                                                                 "config");
1486 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1487         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1488 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1490                                                                 "speed");
1491 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1492         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1493                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1494 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1495         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1496                                                                 "duplex");
1497 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1498         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1499                                                         "half#full#auto");
1500
1501 cmdline_parse_inst_t cmd_config_speed_specific = {
1502         .f = cmd_config_speed_specific_parsed,
1503         .data = NULL,
1504         .help_str = "port config <port_id> speed "
1505                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1506                                                         "half|full|auto",
1507         .tokens = {
1508                 (void *)&cmd_config_speed_specific_port,
1509                 (void *)&cmd_config_speed_specific_keyword,
1510                 (void *)&cmd_config_speed_specific_id,
1511                 (void *)&cmd_config_speed_specific_item1,
1512                 (void *)&cmd_config_speed_specific_value1,
1513                 (void *)&cmd_config_speed_specific_item2,
1514                 (void *)&cmd_config_speed_specific_value2,
1515                 NULL,
1516         },
1517 };
1518
1519 /* *** configure txq/rxq, txd/rxd *** */
1520 struct cmd_config_rx_tx {
1521         cmdline_fixed_string_t port;
1522         cmdline_fixed_string_t keyword;
1523         cmdline_fixed_string_t all;
1524         cmdline_fixed_string_t name;
1525         uint16_t value;
1526 };
1527
1528 static void
1529 cmd_config_rx_tx_parsed(void *parsed_result,
1530                         __attribute__((unused)) struct cmdline *cl,
1531                         __attribute__((unused)) void *data)
1532 {
1533         struct cmd_config_rx_tx *res = parsed_result;
1534
1535         if (!all_ports_stopped()) {
1536                 printf("Please stop all ports first\n");
1537                 return;
1538         }
1539         if (!strcmp(res->name, "rxq")) {
1540                 if (!res->value && !nb_txq) {
1541                         printf("Warning: Either rx or tx queues should be non zero\n");
1542                         return;
1543                 }
1544                 if (check_nb_rxq(res->value) != 0)
1545                         return;
1546                 nb_rxq = res->value;
1547         }
1548         else if (!strcmp(res->name, "txq")) {
1549                 if (!res->value && !nb_rxq) {
1550                         printf("Warning: Either rx or tx queues should be non zero\n");
1551                         return;
1552                 }
1553                 if (check_nb_txq(res->value) != 0)
1554                         return;
1555                 nb_txq = res->value;
1556         }
1557         else if (!strcmp(res->name, "rxd")) {
1558                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1559                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1560                                         res->value, RTE_TEST_RX_DESC_MAX);
1561                         return;
1562                 }
1563                 nb_rxd = res->value;
1564         } else if (!strcmp(res->name, "txd")) {
1565                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1566                         printf("txd %d invalid - must be > 0 && <= %d\n",
1567                                         res->value, RTE_TEST_TX_DESC_MAX);
1568                         return;
1569                 }
1570                 nb_txd = res->value;
1571         } else {
1572                 printf("Unknown parameter\n");
1573                 return;
1574         }
1575
1576         fwd_config_setup();
1577
1578         init_port_config();
1579
1580         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1581 }
1582
1583 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1584         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1585 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1586         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1587 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1588         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1589 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1590         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1591                                                 "rxq#txq#rxd#txd");
1592 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1593         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1594
1595 cmdline_parse_inst_t cmd_config_rx_tx = {
1596         .f = cmd_config_rx_tx_parsed,
1597         .data = NULL,
1598         .help_str = "port config all rxq|txq|rxd|txd <value>",
1599         .tokens = {
1600                 (void *)&cmd_config_rx_tx_port,
1601                 (void *)&cmd_config_rx_tx_keyword,
1602                 (void *)&cmd_config_rx_tx_all,
1603                 (void *)&cmd_config_rx_tx_name,
1604                 (void *)&cmd_config_rx_tx_value,
1605                 NULL,
1606         },
1607 };
1608
1609 /* *** config max packet length *** */
1610 struct cmd_config_max_pkt_len_result {
1611         cmdline_fixed_string_t port;
1612         cmdline_fixed_string_t keyword;
1613         cmdline_fixed_string_t all;
1614         cmdline_fixed_string_t name;
1615         uint32_t value;
1616 };
1617
1618 static void
1619 cmd_config_max_pkt_len_parsed(void *parsed_result,
1620                                 __attribute__((unused)) struct cmdline *cl,
1621                                 __attribute__((unused)) void *data)
1622 {
1623         struct cmd_config_max_pkt_len_result *res = parsed_result;
1624         portid_t pid;
1625
1626         if (!all_ports_stopped()) {
1627                 printf("Please stop all ports first\n");
1628                 return;
1629         }
1630
1631         RTE_ETH_FOREACH_DEV(pid) {
1632                 struct rte_port *port = &ports[pid];
1633                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1634
1635                 if (!strcmp(res->name, "max-pkt-len")) {
1636                         if (res->value < ETHER_MIN_LEN) {
1637                                 printf("max-pkt-len can not be less than %d\n",
1638                                                 ETHER_MIN_LEN);
1639                                 return;
1640                         }
1641                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1642                                 return;
1643
1644                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1645                         if (res->value > ETHER_MAX_LEN)
1646                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1647                         else
1648                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1649                         port->dev_conf.rxmode.offloads = rx_offloads;
1650                 } else {
1651                         printf("Unknown parameter\n");
1652                         return;
1653                 }
1654         }
1655
1656         init_port_config();
1657
1658         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1659 }
1660
1661 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1663                                                                 "port");
1664 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1666                                                                 "config");
1667 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1669                                                                 "all");
1670 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1672                                                                 "max-pkt-len");
1673 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1674         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1675                                                                 UINT32);
1676
1677 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1678         .f = cmd_config_max_pkt_len_parsed,
1679         .data = NULL,
1680         .help_str = "port config all max-pkt-len <value>",
1681         .tokens = {
1682                 (void *)&cmd_config_max_pkt_len_port,
1683                 (void *)&cmd_config_max_pkt_len_keyword,
1684                 (void *)&cmd_config_max_pkt_len_all,
1685                 (void *)&cmd_config_max_pkt_len_name,
1686                 (void *)&cmd_config_max_pkt_len_value,
1687                 NULL,
1688         },
1689 };
1690
1691 /* *** configure port MTU *** */
1692 struct cmd_config_mtu_result {
1693         cmdline_fixed_string_t port;
1694         cmdline_fixed_string_t keyword;
1695         cmdline_fixed_string_t mtu;
1696         portid_t port_id;
1697         uint16_t value;
1698 };
1699
1700 static void
1701 cmd_config_mtu_parsed(void *parsed_result,
1702                       __attribute__((unused)) struct cmdline *cl,
1703                       __attribute__((unused)) void *data)
1704 {
1705         struct cmd_config_mtu_result *res = parsed_result;
1706
1707         if (res->value < ETHER_MIN_LEN) {
1708                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1709                 return;
1710         }
1711         port_mtu_set(res->port_id, res->value);
1712 }
1713
1714 cmdline_parse_token_string_t cmd_config_mtu_port =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1716                                  "port");
1717 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1719                                  "config");
1720 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1722                                  "mtu");
1723 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1724         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1725 cmdline_parse_token_num_t cmd_config_mtu_value =
1726         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1727
1728 cmdline_parse_inst_t cmd_config_mtu = {
1729         .f = cmd_config_mtu_parsed,
1730         .data = NULL,
1731         .help_str = "port config mtu <port_id> <value>",
1732         .tokens = {
1733                 (void *)&cmd_config_mtu_port,
1734                 (void *)&cmd_config_mtu_keyword,
1735                 (void *)&cmd_config_mtu_mtu,
1736                 (void *)&cmd_config_mtu_port_id,
1737                 (void *)&cmd_config_mtu_value,
1738                 NULL,
1739         },
1740 };
1741
1742 /* *** configure rx mode *** */
1743 struct cmd_config_rx_mode_flag {
1744         cmdline_fixed_string_t port;
1745         cmdline_fixed_string_t keyword;
1746         cmdline_fixed_string_t all;
1747         cmdline_fixed_string_t name;
1748         cmdline_fixed_string_t value;
1749 };
1750
1751 static void
1752 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1753                                 __attribute__((unused)) struct cmdline *cl,
1754                                 __attribute__((unused)) void *data)
1755 {
1756         struct cmd_config_rx_mode_flag *res = parsed_result;
1757         portid_t pid;
1758
1759         if (!all_ports_stopped()) {
1760                 printf("Please stop all ports first\n");
1761                 return;
1762         }
1763
1764         RTE_ETH_FOREACH_DEV(pid) {
1765                 struct rte_port *port;
1766                 uint64_t rx_offloads;
1767
1768                 port = &ports[pid];
1769                 rx_offloads = port->dev_conf.rxmode.offloads;
1770                 if (!strcmp(res->name, "crc-strip")) {
1771                         if (!strcmp(res->value, "on"))
1772                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1773                         else if (!strcmp(res->value, "off"))
1774                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1775                         else {
1776                                 printf("Unknown parameter\n");
1777                                 return;
1778                         }
1779                 } else if (!strcmp(res->name, "scatter")) {
1780                         if (!strcmp(res->value, "on")) {
1781                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1782                         } else if (!strcmp(res->value, "off")) {
1783                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1784                         } else {
1785                                 printf("Unknown parameter\n");
1786                                 return;
1787                         }
1788                 } else if (!strcmp(res->name, "rx-cksum")) {
1789                         if (!strcmp(res->value, "on"))
1790                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1791                         else if (!strcmp(res->value, "off"))
1792                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1793                         else {
1794                                 printf("Unknown parameter\n");
1795                                 return;
1796                         }
1797                 } else if (!strcmp(res->name, "rx-timestamp")) {
1798                         if (!strcmp(res->value, "on"))
1799                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1800                         else if (!strcmp(res->value, "off"))
1801                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1802                         else {
1803                                 printf("Unknown parameter\n");
1804                                 return;
1805                         }
1806                 } else if (!strcmp(res->name, "hw-vlan")) {
1807                         if (!strcmp(res->value, "on")) {
1808                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1809                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1810                         } else if (!strcmp(res->value, "off")) {
1811                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1812                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1813                         } else {
1814                                 printf("Unknown parameter\n");
1815                                 return;
1816                         }
1817                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1818                         if (!strcmp(res->value, "on"))
1819                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1820                         else if (!strcmp(res->value, "off"))
1821                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1822                         else {
1823                                 printf("Unknown parameter\n");
1824                                 return;
1825                         }
1826                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1827                         if (!strcmp(res->value, "on"))
1828                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1829                         else if (!strcmp(res->value, "off"))
1830                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1831                         else {
1832                                 printf("Unknown parameter\n");
1833                                 return;
1834                         }
1835                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1836                         if (!strcmp(res->value, "on"))
1837                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1838                         else if (!strcmp(res->value, "off"))
1839                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1840                         else {
1841                                 printf("Unknown parameter\n");
1842                                 return;
1843                         }
1844                 } else if (!strcmp(res->name, "drop-en")) {
1845                         if (!strcmp(res->value, "on"))
1846                                 rx_drop_en = 1;
1847                         else if (!strcmp(res->value, "off"))
1848                                 rx_drop_en = 0;
1849                         else {
1850                                 printf("Unknown parameter\n");
1851                                 return;
1852                         }
1853                 } else {
1854                         printf("Unknown parameter\n");
1855                         return;
1856                 }
1857                 port->dev_conf.rxmode.offloads = rx_offloads;
1858         }
1859
1860         init_port_config();
1861
1862         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1863 }
1864
1865 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1867 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1868         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1869                                                                 "config");
1870 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1871         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1872 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1873         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1874                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1875                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1876 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1877         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1878                                                         "on#off");
1879
1880 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1881         .f = cmd_config_rx_mode_flag_parsed,
1882         .data = NULL,
1883         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1884                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1885         .tokens = {
1886                 (void *)&cmd_config_rx_mode_flag_port,
1887                 (void *)&cmd_config_rx_mode_flag_keyword,
1888                 (void *)&cmd_config_rx_mode_flag_all,
1889                 (void *)&cmd_config_rx_mode_flag_name,
1890                 (void *)&cmd_config_rx_mode_flag_value,
1891                 NULL,
1892         },
1893 };
1894
1895 /* *** configure rss *** */
1896 struct cmd_config_rss {
1897         cmdline_fixed_string_t port;
1898         cmdline_fixed_string_t keyword;
1899         cmdline_fixed_string_t all;
1900         cmdline_fixed_string_t name;
1901         cmdline_fixed_string_t value;
1902 };
1903
1904 static void
1905 cmd_config_rss_parsed(void *parsed_result,
1906                         __attribute__((unused)) struct cmdline *cl,
1907                         __attribute__((unused)) void *data)
1908 {
1909         struct cmd_config_rss *res = parsed_result;
1910         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1911         int diag;
1912         uint8_t i;
1913
1914         if (!strcmp(res->value, "all"))
1915                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1916                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1917                                         ETH_RSS_L2_PAYLOAD;
1918         else if (!strcmp(res->value, "ip"))
1919                 rss_conf.rss_hf = ETH_RSS_IP;
1920         else if (!strcmp(res->value, "udp"))
1921                 rss_conf.rss_hf = ETH_RSS_UDP;
1922         else if (!strcmp(res->value, "tcp"))
1923                 rss_conf.rss_hf = ETH_RSS_TCP;
1924         else if (!strcmp(res->value, "sctp"))
1925                 rss_conf.rss_hf = ETH_RSS_SCTP;
1926         else if (!strcmp(res->value, "ether"))
1927                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1928         else if (!strcmp(res->value, "port"))
1929                 rss_conf.rss_hf = ETH_RSS_PORT;
1930         else if (!strcmp(res->value, "vxlan"))
1931                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1932         else if (!strcmp(res->value, "geneve"))
1933                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1934         else if (!strcmp(res->value, "nvgre"))
1935                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1936         else if (!strcmp(res->value, "none"))
1937                 rss_conf.rss_hf = 0;
1938         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1939                                                 atoi(res->value) < 64)
1940                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1941         else {
1942                 printf("Unknown parameter\n");
1943                 return;
1944         }
1945         rss_conf.rss_key = NULL;
1946         for (i = 0; i < rte_eth_dev_count(); i++) {
1947                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1948                 if (diag < 0)
1949                         printf("Configuration of RSS hash at ethernet port %d "
1950                                 "failed with error (%d): %s.\n",
1951                                 i, -diag, strerror(-diag));
1952         }
1953 }
1954
1955 cmdline_parse_token_string_t cmd_config_rss_port =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1957 cmdline_parse_token_string_t cmd_config_rss_keyword =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1959 cmdline_parse_token_string_t cmd_config_rss_all =
1960         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1961 cmdline_parse_token_string_t cmd_config_rss_name =
1962         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1963 cmdline_parse_token_string_t cmd_config_rss_value =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1965
1966 cmdline_parse_inst_t cmd_config_rss = {
1967         .f = cmd_config_rss_parsed,
1968         .data = NULL,
1969         .help_str = "port config all rss "
1970                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1971         .tokens = {
1972                 (void *)&cmd_config_rss_port,
1973                 (void *)&cmd_config_rss_keyword,
1974                 (void *)&cmd_config_rss_all,
1975                 (void *)&cmd_config_rss_name,
1976                 (void *)&cmd_config_rss_value,
1977                 NULL,
1978         },
1979 };
1980
1981 /* *** configure rss hash key *** */
1982 struct cmd_config_rss_hash_key {
1983         cmdline_fixed_string_t port;
1984         cmdline_fixed_string_t config;
1985         portid_t port_id;
1986         cmdline_fixed_string_t rss_hash_key;
1987         cmdline_fixed_string_t rss_type;
1988         cmdline_fixed_string_t key;
1989 };
1990
1991 static uint8_t
1992 hexa_digit_to_value(char hexa_digit)
1993 {
1994         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1995                 return (uint8_t) (hexa_digit - '0');
1996         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1997                 return (uint8_t) ((hexa_digit - 'a') + 10);
1998         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1999                 return (uint8_t) ((hexa_digit - 'A') + 10);
2000         /* Invalid hexa digit */
2001         return 0xFF;
2002 }
2003
2004 static uint8_t
2005 parse_and_check_key_hexa_digit(char *key, int idx)
2006 {
2007         uint8_t hexa_v;
2008
2009         hexa_v = hexa_digit_to_value(key[idx]);
2010         if (hexa_v == 0xFF)
2011                 printf("invalid key: character %c at position %d is not a "
2012                        "valid hexa digit\n", key[idx], idx);
2013         return hexa_v;
2014 }
2015
2016 static void
2017 cmd_config_rss_hash_key_parsed(void *parsed_result,
2018                                __attribute__((unused)) struct cmdline *cl,
2019                                __attribute__((unused)) void *data)
2020 {
2021         struct cmd_config_rss_hash_key *res = parsed_result;
2022         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2023         uint8_t xdgt0;
2024         uint8_t xdgt1;
2025         int i;
2026         struct rte_eth_dev_info dev_info;
2027         uint8_t hash_key_size;
2028         uint32_t key_len;
2029
2030         memset(&dev_info, 0, sizeof(dev_info));
2031         rte_eth_dev_info_get(res->port_id, &dev_info);
2032         if (dev_info.hash_key_size > 0 &&
2033                         dev_info.hash_key_size <= sizeof(hash_key))
2034                 hash_key_size = dev_info.hash_key_size;
2035         else {
2036                 printf("dev_info did not provide a valid hash key size\n");
2037                 return;
2038         }
2039         /* Check the length of the RSS hash key */
2040         key_len = strlen(res->key);
2041         if (key_len != (hash_key_size * 2)) {
2042                 printf("key length: %d invalid - key must be a string of %d"
2043                            " hexa-decimal numbers\n",
2044                            (int) key_len, hash_key_size * 2);
2045                 return;
2046         }
2047         /* Translate RSS hash key into binary representation */
2048         for (i = 0; i < hash_key_size; i++) {
2049                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2050                 if (xdgt0 == 0xFF)
2051                         return;
2052                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2053                 if (xdgt1 == 0xFF)
2054                         return;
2055                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2056         }
2057         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2058                         hash_key_size);
2059 }
2060
2061 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2062         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2063 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2065                                  "config");
2066 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2067         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2068 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2070                                  rss_hash_key, "rss-hash-key");
2071 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2073                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2074                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2075                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2076                                  "ipv6-tcp-ex#ipv6-udp-ex");
2077 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2078         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2079
2080 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2081         .f = cmd_config_rss_hash_key_parsed,
2082         .data = NULL,
2083         .help_str = "port config <port_id> rss-hash-key "
2084                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2085                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2086                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2087                 "<string of hex digits (variable length, NIC dependent)>",
2088         .tokens = {
2089                 (void *)&cmd_config_rss_hash_key_port,
2090                 (void *)&cmd_config_rss_hash_key_config,
2091                 (void *)&cmd_config_rss_hash_key_port_id,
2092                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2093                 (void *)&cmd_config_rss_hash_key_rss_type,
2094                 (void *)&cmd_config_rss_hash_key_value,
2095                 NULL,
2096         },
2097 };
2098
2099 /* *** configure port rxq/txq start/stop *** */
2100 struct cmd_config_rxtx_queue {
2101         cmdline_fixed_string_t port;
2102         portid_t portid;
2103         cmdline_fixed_string_t rxtxq;
2104         uint16_t qid;
2105         cmdline_fixed_string_t opname;
2106 };
2107
2108 static void
2109 cmd_config_rxtx_queue_parsed(void *parsed_result,
2110                         __attribute__((unused)) struct cmdline *cl,
2111                         __attribute__((unused)) void *data)
2112 {
2113         struct cmd_config_rxtx_queue *res = parsed_result;
2114         uint8_t isrx;
2115         uint8_t isstart;
2116         int ret = 0;
2117
2118         if (test_done == 0) {
2119                 printf("Please stop forwarding first\n");
2120                 return;
2121         }
2122
2123         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2124                 return;
2125
2126         if (port_is_started(res->portid) != 1) {
2127                 printf("Please start port %u first\n", res->portid);
2128                 return;
2129         }
2130
2131         if (!strcmp(res->rxtxq, "rxq"))
2132                 isrx = 1;
2133         else if (!strcmp(res->rxtxq, "txq"))
2134                 isrx = 0;
2135         else {
2136                 printf("Unknown parameter\n");
2137                 return;
2138         }
2139
2140         if (isrx && rx_queue_id_is_invalid(res->qid))
2141                 return;
2142         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2143                 return;
2144
2145         if (!strcmp(res->opname, "start"))
2146                 isstart = 1;
2147         else if (!strcmp(res->opname, "stop"))
2148                 isstart = 0;
2149         else {
2150                 printf("Unknown parameter\n");
2151                 return;
2152         }
2153
2154         if (isstart && isrx)
2155                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2156         else if (!isstart && isrx)
2157                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2158         else if (isstart && !isrx)
2159                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2160         else
2161                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2162
2163         if (ret == -ENOTSUP)
2164                 printf("Function not supported in PMD driver\n");
2165 }
2166
2167 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2168         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2169 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2170         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2171 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2173 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2174         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2175 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2176         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2177                                                 "start#stop");
2178
2179 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2180         .f = cmd_config_rxtx_queue_parsed,
2181         .data = NULL,
2182         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2183         .tokens = {
2184                 (void *)&cmd_config_speed_all_port,
2185                 (void *)&cmd_config_rxtx_queue_portid,
2186                 (void *)&cmd_config_rxtx_queue_rxtxq,
2187                 (void *)&cmd_config_rxtx_queue_qid,
2188                 (void *)&cmd_config_rxtx_queue_opname,
2189                 NULL,
2190         },
2191 };
2192
2193 /* *** Configure RSS RETA *** */
2194 struct cmd_config_rss_reta {
2195         cmdline_fixed_string_t port;
2196         cmdline_fixed_string_t keyword;
2197         portid_t port_id;
2198         cmdline_fixed_string_t name;
2199         cmdline_fixed_string_t list_name;
2200         cmdline_fixed_string_t list_of_items;
2201 };
2202
2203 static int
2204 parse_reta_config(const char *str,
2205                   struct rte_eth_rss_reta_entry64 *reta_conf,
2206                   uint16_t nb_entries)
2207 {
2208         int i;
2209         unsigned size;
2210         uint16_t hash_index, idx, shift;
2211         uint16_t nb_queue;
2212         char s[256];
2213         const char *p, *p0 = str;
2214         char *end;
2215         enum fieldnames {
2216                 FLD_HASH_INDEX = 0,
2217                 FLD_QUEUE,
2218                 _NUM_FLD
2219         };
2220         unsigned long int_fld[_NUM_FLD];
2221         char *str_fld[_NUM_FLD];
2222
2223         while ((p = strchr(p0,'(')) != NULL) {
2224                 ++p;
2225                 if((p0 = strchr(p,')')) == NULL)
2226                         return -1;
2227
2228                 size = p0 - p;
2229                 if(size >= sizeof(s))
2230                         return -1;
2231
2232                 snprintf(s, sizeof(s), "%.*s", size, p);
2233                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2234                         return -1;
2235                 for (i = 0; i < _NUM_FLD; i++) {
2236                         errno = 0;
2237                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2238                         if (errno != 0 || end == str_fld[i] ||
2239                                         int_fld[i] > 65535)
2240                                 return -1;
2241                 }
2242
2243                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2244                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2245
2246                 if (hash_index >= nb_entries) {
2247                         printf("Invalid RETA hash index=%d\n", hash_index);
2248                         return -1;
2249                 }
2250
2251                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2252                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2253                 reta_conf[idx].mask |= (1ULL << shift);
2254                 reta_conf[idx].reta[shift] = nb_queue;
2255         }
2256
2257         return 0;
2258 }
2259
2260 static void
2261 cmd_set_rss_reta_parsed(void *parsed_result,
2262                         __attribute__((unused)) struct cmdline *cl,
2263                         __attribute__((unused)) void *data)
2264 {
2265         int ret;
2266         struct rte_eth_dev_info dev_info;
2267         struct rte_eth_rss_reta_entry64 reta_conf[8];
2268         struct cmd_config_rss_reta *res = parsed_result;
2269
2270         memset(&dev_info, 0, sizeof(dev_info));
2271         rte_eth_dev_info_get(res->port_id, &dev_info);
2272         if (dev_info.reta_size == 0) {
2273                 printf("Redirection table size is 0 which is "
2274                                         "invalid for RSS\n");
2275                 return;
2276         } else
2277                 printf("The reta size of port %d is %u\n",
2278                         res->port_id, dev_info.reta_size);
2279         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2280                 printf("Currently do not support more than %u entries of "
2281                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2282                 return;
2283         }
2284
2285         memset(reta_conf, 0, sizeof(reta_conf));
2286         if (!strcmp(res->list_name, "reta")) {
2287                 if (parse_reta_config(res->list_of_items, reta_conf,
2288                                                 dev_info.reta_size)) {
2289                         printf("Invalid RSS Redirection Table "
2290                                         "config entered\n");
2291                         return;
2292                 }
2293                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2294                                 reta_conf, dev_info.reta_size);
2295                 if (ret != 0)
2296                         printf("Bad redirection table parameter, "
2297                                         "return code = %d \n", ret);
2298         }
2299 }
2300
2301 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2302         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2303 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2304         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2305 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2306         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2307 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2308         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2309 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2310         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2311 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2312         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2313                                  NULL);
2314 cmdline_parse_inst_t cmd_config_rss_reta = {
2315         .f = cmd_set_rss_reta_parsed,
2316         .data = NULL,
2317         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2318         .tokens = {
2319                 (void *)&cmd_config_rss_reta_port,
2320                 (void *)&cmd_config_rss_reta_keyword,
2321                 (void *)&cmd_config_rss_reta_port_id,
2322                 (void *)&cmd_config_rss_reta_name,
2323                 (void *)&cmd_config_rss_reta_list_name,
2324                 (void *)&cmd_config_rss_reta_list_of_items,
2325                 NULL,
2326         },
2327 };
2328
2329 /* *** SHOW PORT RETA INFO *** */
2330 struct cmd_showport_reta {
2331         cmdline_fixed_string_t show;
2332         cmdline_fixed_string_t port;
2333         portid_t port_id;
2334         cmdline_fixed_string_t rss;
2335         cmdline_fixed_string_t reta;
2336         uint16_t size;
2337         cmdline_fixed_string_t list_of_items;
2338 };
2339
2340 static int
2341 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2342                            uint16_t nb_entries,
2343                            char *str)
2344 {
2345         uint32_t size;
2346         const char *p, *p0 = str;
2347         char s[256];
2348         char *end;
2349         char *str_fld[8];
2350         uint16_t i;
2351         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2352                         RTE_RETA_GROUP_SIZE;
2353         int ret;
2354
2355         p = strchr(p0, '(');
2356         if (p == NULL)
2357                 return -1;
2358         p++;
2359         p0 = strchr(p, ')');
2360         if (p0 == NULL)
2361                 return -1;
2362         size = p0 - p;
2363         if (size >= sizeof(s)) {
2364                 printf("The string size exceeds the internal buffer size\n");
2365                 return -1;
2366         }
2367         snprintf(s, sizeof(s), "%.*s", size, p);
2368         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2369         if (ret <= 0 || ret != num) {
2370                 printf("The bits of masks do not match the number of "
2371                                         "reta entries: %u\n", num);
2372                 return -1;
2373         }
2374         for (i = 0; i < ret; i++)
2375                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2376
2377         return 0;
2378 }
2379
2380 static void
2381 cmd_showport_reta_parsed(void *parsed_result,
2382                          __attribute__((unused)) struct cmdline *cl,
2383                          __attribute__((unused)) void *data)
2384 {
2385         struct cmd_showport_reta *res = parsed_result;
2386         struct rte_eth_rss_reta_entry64 reta_conf[8];
2387         struct rte_eth_dev_info dev_info;
2388         uint16_t max_reta_size;
2389
2390         memset(&dev_info, 0, sizeof(dev_info));
2391         rte_eth_dev_info_get(res->port_id, &dev_info);
2392         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2393         if (res->size == 0 || res->size > max_reta_size) {
2394                 printf("Invalid redirection table size: %u (1-%u)\n",
2395                         res->size, max_reta_size);
2396                 return;
2397         }
2398
2399         memset(reta_conf, 0, sizeof(reta_conf));
2400         if (showport_parse_reta_config(reta_conf, res->size,
2401                                 res->list_of_items) < 0) {
2402                 printf("Invalid string: %s for reta masks\n",
2403                                         res->list_of_items);
2404                 return;
2405         }
2406         port_rss_reta_info(res->port_id, reta_conf, res->size);
2407 }
2408
2409 cmdline_parse_token_string_t cmd_showport_reta_show =
2410         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2411 cmdline_parse_token_string_t cmd_showport_reta_port =
2412         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2413 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2414         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2415 cmdline_parse_token_string_t cmd_showport_reta_rss =
2416         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2417 cmdline_parse_token_string_t cmd_showport_reta_reta =
2418         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2419 cmdline_parse_token_num_t cmd_showport_reta_size =
2420         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2421 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2422         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2423                                         list_of_items, NULL);
2424
2425 cmdline_parse_inst_t cmd_showport_reta = {
2426         .f = cmd_showport_reta_parsed,
2427         .data = NULL,
2428         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2429         .tokens = {
2430                 (void *)&cmd_showport_reta_show,
2431                 (void *)&cmd_showport_reta_port,
2432                 (void *)&cmd_showport_reta_port_id,
2433                 (void *)&cmd_showport_reta_rss,
2434                 (void *)&cmd_showport_reta_reta,
2435                 (void *)&cmd_showport_reta_size,
2436                 (void *)&cmd_showport_reta_list_of_items,
2437                 NULL,
2438         },
2439 };
2440
2441 /* *** Show RSS hash configuration *** */
2442 struct cmd_showport_rss_hash {
2443         cmdline_fixed_string_t show;
2444         cmdline_fixed_string_t port;
2445         portid_t port_id;
2446         cmdline_fixed_string_t rss_hash;
2447         cmdline_fixed_string_t rss_type;
2448         cmdline_fixed_string_t key; /* optional argument */
2449 };
2450
2451 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2452                                 __attribute__((unused)) struct cmdline *cl,
2453                                 void *show_rss_key)
2454 {
2455         struct cmd_showport_rss_hash *res = parsed_result;
2456
2457         port_rss_hash_conf_show(res->port_id, res->rss_type,
2458                                 show_rss_key != NULL);
2459 }
2460
2461 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2462         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2463 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2464         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2465 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2466         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2467 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2468         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2469                                  "rss-hash");
2470 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2471         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2472                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2473                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2474                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2475                                  "ipv6-tcp-ex#ipv6-udp-ex");
2476 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2477         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2478
2479 cmdline_parse_inst_t cmd_showport_rss_hash = {
2480         .f = cmd_showport_rss_hash_parsed,
2481         .data = NULL,
2482         .help_str = "show port <port_id> rss-hash "
2483                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2484                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2485                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2486         .tokens = {
2487                 (void *)&cmd_showport_rss_hash_show,
2488                 (void *)&cmd_showport_rss_hash_port,
2489                 (void *)&cmd_showport_rss_hash_port_id,
2490                 (void *)&cmd_showport_rss_hash_rss_hash,
2491                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2492                 NULL,
2493         },
2494 };
2495
2496 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2497         .f = cmd_showport_rss_hash_parsed,
2498         .data = (void *)1,
2499         .help_str = "show port <port_id> rss-hash "
2500                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2501                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2502                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2503         .tokens = {
2504                 (void *)&cmd_showport_rss_hash_show,
2505                 (void *)&cmd_showport_rss_hash_port,
2506                 (void *)&cmd_showport_rss_hash_port_id,
2507                 (void *)&cmd_showport_rss_hash_rss_hash,
2508                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2509                 (void *)&cmd_showport_rss_hash_rss_key,
2510                 NULL,
2511         },
2512 };
2513
2514 /* *** Configure DCB *** */
2515 struct cmd_config_dcb {
2516         cmdline_fixed_string_t port;
2517         cmdline_fixed_string_t config;
2518         portid_t port_id;
2519         cmdline_fixed_string_t dcb;
2520         cmdline_fixed_string_t vt;
2521         cmdline_fixed_string_t vt_en;
2522         uint8_t num_tcs;
2523         cmdline_fixed_string_t pfc;
2524         cmdline_fixed_string_t pfc_en;
2525 };
2526
2527 static void
2528 cmd_config_dcb_parsed(void *parsed_result,
2529                         __attribute__((unused)) struct cmdline *cl,
2530                         __attribute__((unused)) void *data)
2531 {
2532         struct cmd_config_dcb *res = parsed_result;
2533         portid_t port_id = res->port_id;
2534         struct rte_port *port;
2535         uint8_t pfc_en;
2536         int ret;
2537
2538         port = &ports[port_id];
2539         /** Check if the port is not started **/
2540         if (port->port_status != RTE_PORT_STOPPED) {
2541                 printf("Please stop port %d first\n", port_id);
2542                 return;
2543         }
2544
2545         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2546                 printf("The invalid number of traffic class,"
2547                         " only 4 or 8 allowed.\n");
2548                 return;
2549         }
2550
2551         if (nb_fwd_lcores < res->num_tcs) {
2552                 printf("nb_cores shouldn't be less than number of TCs.\n");
2553                 return;
2554         }
2555         if (!strncmp(res->pfc_en, "on", 2))
2556                 pfc_en = 1;
2557         else
2558                 pfc_en = 0;
2559
2560         /* DCB in VT mode */
2561         if (!strncmp(res->vt_en, "on", 2))
2562                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2563                                 (enum rte_eth_nb_tcs)res->num_tcs,
2564                                 pfc_en);
2565         else
2566                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2567                                 (enum rte_eth_nb_tcs)res->num_tcs,
2568                                 pfc_en);
2569
2570
2571         if (ret != 0) {
2572                 printf("Cannot initialize network ports.\n");
2573                 return;
2574         }
2575
2576         cmd_reconfig_device_queue(port_id, 1, 1);
2577 }
2578
2579 cmdline_parse_token_string_t cmd_config_dcb_port =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2581 cmdline_parse_token_string_t cmd_config_dcb_config =
2582         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2583 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2584         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2585 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2586         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2587 cmdline_parse_token_string_t cmd_config_dcb_vt =
2588         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2589 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2590         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2591 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2592         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2593 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2594         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2595 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2597
2598 cmdline_parse_inst_t cmd_config_dcb = {
2599         .f = cmd_config_dcb_parsed,
2600         .data = NULL,
2601         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2602         .tokens = {
2603                 (void *)&cmd_config_dcb_port,
2604                 (void *)&cmd_config_dcb_config,
2605                 (void *)&cmd_config_dcb_port_id,
2606                 (void *)&cmd_config_dcb_dcb,
2607                 (void *)&cmd_config_dcb_vt,
2608                 (void *)&cmd_config_dcb_vt_en,
2609                 (void *)&cmd_config_dcb_num_tcs,
2610                 (void *)&cmd_config_dcb_pfc,
2611                 (void *)&cmd_config_dcb_pfc_en,
2612                 NULL,
2613         },
2614 };
2615
2616 /* *** configure number of packets per burst *** */
2617 struct cmd_config_burst {
2618         cmdline_fixed_string_t port;
2619         cmdline_fixed_string_t keyword;
2620         cmdline_fixed_string_t all;
2621         cmdline_fixed_string_t name;
2622         uint16_t value;
2623 };
2624
2625 static void
2626 cmd_config_burst_parsed(void *parsed_result,
2627                         __attribute__((unused)) struct cmdline *cl,
2628                         __attribute__((unused)) void *data)
2629 {
2630         struct cmd_config_burst *res = parsed_result;
2631
2632         if (!all_ports_stopped()) {
2633                 printf("Please stop all ports first\n");
2634                 return;
2635         }
2636
2637         if (!strcmp(res->name, "burst")) {
2638                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2639                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2640                         return;
2641                 }
2642                 nb_pkt_per_burst = res->value;
2643         } else {
2644                 printf("Unknown parameter\n");
2645                 return;
2646         }
2647
2648         init_port_config();
2649
2650         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2651 }
2652
2653 cmdline_parse_token_string_t cmd_config_burst_port =
2654         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2655 cmdline_parse_token_string_t cmd_config_burst_keyword =
2656         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2657 cmdline_parse_token_string_t cmd_config_burst_all =
2658         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2659 cmdline_parse_token_string_t cmd_config_burst_name =
2660         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2661 cmdline_parse_token_num_t cmd_config_burst_value =
2662         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2663
2664 cmdline_parse_inst_t cmd_config_burst = {
2665         .f = cmd_config_burst_parsed,
2666         .data = NULL,
2667         .help_str = "port config all burst <value>",
2668         .tokens = {
2669                 (void *)&cmd_config_burst_port,
2670                 (void *)&cmd_config_burst_keyword,
2671                 (void *)&cmd_config_burst_all,
2672                 (void *)&cmd_config_burst_name,
2673                 (void *)&cmd_config_burst_value,
2674                 NULL,
2675         },
2676 };
2677
2678 /* *** configure rx/tx queues *** */
2679 struct cmd_config_thresh {
2680         cmdline_fixed_string_t port;
2681         cmdline_fixed_string_t keyword;
2682         cmdline_fixed_string_t all;
2683         cmdline_fixed_string_t name;
2684         uint8_t value;
2685 };
2686
2687 static void
2688 cmd_config_thresh_parsed(void *parsed_result,
2689                         __attribute__((unused)) struct cmdline *cl,
2690                         __attribute__((unused)) void *data)
2691 {
2692         struct cmd_config_thresh *res = parsed_result;
2693
2694         if (!all_ports_stopped()) {
2695                 printf("Please stop all ports first\n");
2696                 return;
2697         }
2698
2699         if (!strcmp(res->name, "txpt"))
2700                 tx_pthresh = res->value;
2701         else if(!strcmp(res->name, "txht"))
2702                 tx_hthresh = res->value;
2703         else if(!strcmp(res->name, "txwt"))
2704                 tx_wthresh = res->value;
2705         else if(!strcmp(res->name, "rxpt"))
2706                 rx_pthresh = res->value;
2707         else if(!strcmp(res->name, "rxht"))
2708                 rx_hthresh = res->value;
2709         else if(!strcmp(res->name, "rxwt"))
2710                 rx_wthresh = res->value;
2711         else {
2712                 printf("Unknown parameter\n");
2713                 return;
2714         }
2715
2716         init_port_config();
2717
2718         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2719 }
2720
2721 cmdline_parse_token_string_t cmd_config_thresh_port =
2722         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2723 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2724         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2725 cmdline_parse_token_string_t cmd_config_thresh_all =
2726         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2727 cmdline_parse_token_string_t cmd_config_thresh_name =
2728         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2729                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2730 cmdline_parse_token_num_t cmd_config_thresh_value =
2731         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2732
2733 cmdline_parse_inst_t cmd_config_thresh = {
2734         .f = cmd_config_thresh_parsed,
2735         .data = NULL,
2736         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2737         .tokens = {
2738                 (void *)&cmd_config_thresh_port,
2739                 (void *)&cmd_config_thresh_keyword,
2740                 (void *)&cmd_config_thresh_all,
2741                 (void *)&cmd_config_thresh_name,
2742                 (void *)&cmd_config_thresh_value,
2743                 NULL,
2744         },
2745 };
2746
2747 /* *** configure free/rs threshold *** */
2748 struct cmd_config_threshold {
2749         cmdline_fixed_string_t port;
2750         cmdline_fixed_string_t keyword;
2751         cmdline_fixed_string_t all;
2752         cmdline_fixed_string_t name;
2753         uint16_t value;
2754 };
2755
2756 static void
2757 cmd_config_threshold_parsed(void *parsed_result,
2758                         __attribute__((unused)) struct cmdline *cl,
2759                         __attribute__((unused)) void *data)
2760 {
2761         struct cmd_config_threshold *res = parsed_result;
2762
2763         if (!all_ports_stopped()) {
2764                 printf("Please stop all ports first\n");
2765                 return;
2766         }
2767
2768         if (!strcmp(res->name, "txfreet"))
2769                 tx_free_thresh = res->value;
2770         else if (!strcmp(res->name, "txrst"))
2771                 tx_rs_thresh = res->value;
2772         else if (!strcmp(res->name, "rxfreet"))
2773                 rx_free_thresh = res->value;
2774         else {
2775                 printf("Unknown parameter\n");
2776                 return;
2777         }
2778
2779         init_port_config();
2780
2781         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2782 }
2783
2784 cmdline_parse_token_string_t cmd_config_threshold_port =
2785         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2786 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2787         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2788                                                                 "config");
2789 cmdline_parse_token_string_t cmd_config_threshold_all =
2790         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2791 cmdline_parse_token_string_t cmd_config_threshold_name =
2792         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2793                                                 "txfreet#txrst#rxfreet");
2794 cmdline_parse_token_num_t cmd_config_threshold_value =
2795         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2796
2797 cmdline_parse_inst_t cmd_config_threshold = {
2798         .f = cmd_config_threshold_parsed,
2799         .data = NULL,
2800         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2801         .tokens = {
2802                 (void *)&cmd_config_threshold_port,
2803                 (void *)&cmd_config_threshold_keyword,
2804                 (void *)&cmd_config_threshold_all,
2805                 (void *)&cmd_config_threshold_name,
2806                 (void *)&cmd_config_threshold_value,
2807                 NULL,
2808         },
2809 };
2810
2811 /* *** stop *** */
2812 struct cmd_stop_result {
2813         cmdline_fixed_string_t stop;
2814 };
2815
2816 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2817                             __attribute__((unused)) struct cmdline *cl,
2818                             __attribute__((unused)) void *data)
2819 {
2820         stop_packet_forwarding();
2821 }
2822
2823 cmdline_parse_token_string_t cmd_stop_stop =
2824         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2825
2826 cmdline_parse_inst_t cmd_stop = {
2827         .f = cmd_stop_parsed,
2828         .data = NULL,
2829         .help_str = "stop: Stop packet forwarding",
2830         .tokens = {
2831                 (void *)&cmd_stop_stop,
2832                 NULL,
2833         },
2834 };
2835
2836 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2837
2838 unsigned int
2839 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2840                 unsigned int *parsed_items, int check_unique_values)
2841 {
2842         unsigned int nb_item;
2843         unsigned int value;
2844         unsigned int i;
2845         unsigned int j;
2846         int value_ok;
2847         char c;
2848
2849         /*
2850          * First parse all items in the list and store their value.
2851          */
2852         value = 0;
2853         nb_item = 0;
2854         value_ok = 0;
2855         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2856                 c = str[i];
2857                 if ((c >= '0') && (c <= '9')) {
2858                         value = (unsigned int) (value * 10 + (c - '0'));
2859                         value_ok = 1;
2860                         continue;
2861                 }
2862                 if (c != ',') {
2863                         printf("character %c is not a decimal digit\n", c);
2864                         return 0;
2865                 }
2866                 if (! value_ok) {
2867                         printf("No valid value before comma\n");
2868                         return 0;
2869                 }
2870                 if (nb_item < max_items) {
2871                         parsed_items[nb_item] = value;
2872                         value_ok = 0;
2873                         value = 0;
2874                 }
2875                 nb_item++;
2876         }
2877         if (nb_item >= max_items) {
2878                 printf("Number of %s = %u > %u (maximum items)\n",
2879                        item_name, nb_item + 1, max_items);
2880                 return 0;
2881         }
2882         parsed_items[nb_item++] = value;
2883         if (! check_unique_values)
2884                 return nb_item;
2885
2886         /*
2887          * Then, check that all values in the list are differents.
2888          * No optimization here...
2889          */
2890         for (i = 0; i < nb_item; i++) {
2891                 for (j = i + 1; j < nb_item; j++) {
2892                         if (parsed_items[j] == parsed_items[i]) {
2893                                 printf("duplicated %s %u at index %u and %u\n",
2894                                        item_name, parsed_items[i], i, j);
2895                                 return 0;
2896                         }
2897                 }
2898         }
2899         return nb_item;
2900 }
2901
2902 struct cmd_set_list_result {
2903         cmdline_fixed_string_t cmd_keyword;
2904         cmdline_fixed_string_t list_name;
2905         cmdline_fixed_string_t list_of_items;
2906 };
2907
2908 static void cmd_set_list_parsed(void *parsed_result,
2909                                 __attribute__((unused)) struct cmdline *cl,
2910                                 __attribute__((unused)) void *data)
2911 {
2912         struct cmd_set_list_result *res;
2913         union {
2914                 unsigned int lcorelist[RTE_MAX_LCORE];
2915                 unsigned int portlist[RTE_MAX_ETHPORTS];
2916         } parsed_items;
2917         unsigned int nb_item;
2918
2919         if (test_done == 0) {
2920                 printf("Please stop forwarding first\n");
2921                 return;
2922         }
2923
2924         res = parsed_result;
2925         if (!strcmp(res->list_name, "corelist")) {
2926                 nb_item = parse_item_list(res->list_of_items, "core",
2927                                           RTE_MAX_LCORE,
2928                                           parsed_items.lcorelist, 1);
2929                 if (nb_item > 0) {
2930                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2931                         fwd_config_setup();
2932                 }
2933                 return;
2934         }
2935         if (!strcmp(res->list_name, "portlist")) {
2936                 nb_item = parse_item_list(res->list_of_items, "port",
2937                                           RTE_MAX_ETHPORTS,
2938                                           parsed_items.portlist, 1);
2939                 if (nb_item > 0) {
2940                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2941                         fwd_config_setup();
2942                 }
2943         }
2944 }
2945
2946 cmdline_parse_token_string_t cmd_set_list_keyword =
2947         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2948                                  "set");
2949 cmdline_parse_token_string_t cmd_set_list_name =
2950         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2951                                  "corelist#portlist");
2952 cmdline_parse_token_string_t cmd_set_list_of_items =
2953         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2954                                  NULL);
2955
2956 cmdline_parse_inst_t cmd_set_fwd_list = {
2957         .f = cmd_set_list_parsed,
2958         .data = NULL,
2959         .help_str = "set corelist|portlist <list0[,list1]*>",
2960         .tokens = {
2961                 (void *)&cmd_set_list_keyword,
2962                 (void *)&cmd_set_list_name,
2963                 (void *)&cmd_set_list_of_items,
2964                 NULL,
2965         },
2966 };
2967
2968 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2969
2970 struct cmd_setmask_result {
2971         cmdline_fixed_string_t set;
2972         cmdline_fixed_string_t mask;
2973         uint64_t hexavalue;
2974 };
2975
2976 static void cmd_set_mask_parsed(void *parsed_result,
2977                                 __attribute__((unused)) struct cmdline *cl,
2978                                 __attribute__((unused)) void *data)
2979 {
2980         struct cmd_setmask_result *res = parsed_result;
2981
2982         if (test_done == 0) {
2983                 printf("Please stop forwarding first\n");
2984                 return;
2985         }
2986         if (!strcmp(res->mask, "coremask")) {
2987                 set_fwd_lcores_mask(res->hexavalue);
2988                 fwd_config_setup();
2989         } else if (!strcmp(res->mask, "portmask")) {
2990                 set_fwd_ports_mask(res->hexavalue);
2991                 fwd_config_setup();
2992         }
2993 }
2994
2995 cmdline_parse_token_string_t cmd_setmask_set =
2996         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2997 cmdline_parse_token_string_t cmd_setmask_mask =
2998         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2999                                  "coremask#portmask");
3000 cmdline_parse_token_num_t cmd_setmask_value =
3001         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3002
3003 cmdline_parse_inst_t cmd_set_fwd_mask = {
3004         .f = cmd_set_mask_parsed,
3005         .data = NULL,
3006         .help_str = "set coremask|portmask <hexadecimal value>",
3007         .tokens = {
3008                 (void *)&cmd_setmask_set,
3009                 (void *)&cmd_setmask_mask,
3010                 (void *)&cmd_setmask_value,
3011                 NULL,
3012         },
3013 };
3014
3015 /*
3016  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3017  */
3018 struct cmd_set_result {
3019         cmdline_fixed_string_t set;
3020         cmdline_fixed_string_t what;
3021         uint16_t value;
3022 };
3023
3024 static void cmd_set_parsed(void *parsed_result,
3025                            __attribute__((unused)) struct cmdline *cl,
3026                            __attribute__((unused)) void *data)
3027 {
3028         struct cmd_set_result *res = parsed_result;
3029         if (!strcmp(res->what, "nbport")) {
3030                 set_fwd_ports_number(res->value);
3031                 fwd_config_setup();
3032         } else if (!strcmp(res->what, "nbcore")) {
3033                 set_fwd_lcores_number(res->value);
3034                 fwd_config_setup();
3035         } else if (!strcmp(res->what, "burst"))
3036                 set_nb_pkt_per_burst(res->value);
3037         else if (!strcmp(res->what, "verbose"))
3038                 set_verbose_level(res->value);
3039 }
3040
3041 cmdline_parse_token_string_t cmd_set_set =
3042         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3043 cmdline_parse_token_string_t cmd_set_what =
3044         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3045                                  "nbport#nbcore#burst#verbose");
3046 cmdline_parse_token_num_t cmd_set_value =
3047         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3048
3049 cmdline_parse_inst_t cmd_set_numbers = {
3050         .f = cmd_set_parsed,
3051         .data = NULL,
3052         .help_str = "set nbport|nbcore|burst|verbose <value>",
3053         .tokens = {
3054                 (void *)&cmd_set_set,
3055                 (void *)&cmd_set_what,
3056                 (void *)&cmd_set_value,
3057                 NULL,
3058         },
3059 };
3060
3061 /* *** SET LOG LEVEL CONFIGURATION *** */
3062
3063 struct cmd_set_log_result {
3064         cmdline_fixed_string_t set;
3065         cmdline_fixed_string_t log;
3066         cmdline_fixed_string_t type;
3067         uint32_t level;
3068 };
3069
3070 static void
3071 cmd_set_log_parsed(void *parsed_result,
3072                    __attribute__((unused)) struct cmdline *cl,
3073                    __attribute__((unused)) void *data)
3074 {
3075         struct cmd_set_log_result *res;
3076         int ret;
3077
3078         res = parsed_result;
3079         if (!strcmp(res->type, "global"))
3080                 rte_log_set_global_level(res->level);
3081         else {
3082                 ret = rte_log_set_level_regexp(res->type, res->level);
3083                 if (ret < 0)
3084                         printf("Unable to set log level\n");
3085         }
3086 }
3087
3088 cmdline_parse_token_string_t cmd_set_log_set =
3089         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3090 cmdline_parse_token_string_t cmd_set_log_log =
3091         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3092 cmdline_parse_token_string_t cmd_set_log_type =
3093         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3094 cmdline_parse_token_num_t cmd_set_log_level =
3095         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3096
3097 cmdline_parse_inst_t cmd_set_log = {
3098         .f = cmd_set_log_parsed,
3099         .data = NULL,
3100         .help_str = "set log global|<type> <level>",
3101         .tokens = {
3102                 (void *)&cmd_set_log_set,
3103                 (void *)&cmd_set_log_log,
3104                 (void *)&cmd_set_log_type,
3105                 (void *)&cmd_set_log_level,
3106                 NULL,
3107         },
3108 };
3109
3110 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3111
3112 struct cmd_set_txpkts_result {
3113         cmdline_fixed_string_t cmd_keyword;
3114         cmdline_fixed_string_t txpkts;
3115         cmdline_fixed_string_t seg_lengths;
3116 };
3117
3118 static void
3119 cmd_set_txpkts_parsed(void *parsed_result,
3120                       __attribute__((unused)) struct cmdline *cl,
3121                       __attribute__((unused)) void *data)
3122 {
3123         struct cmd_set_txpkts_result *res;
3124         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3125         unsigned int nb_segs;
3126
3127         res = parsed_result;
3128         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3129                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3130         if (nb_segs > 0)
3131                 set_tx_pkt_segments(seg_lengths, nb_segs);
3132 }
3133
3134 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3135         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3136                                  cmd_keyword, "set");
3137 cmdline_parse_token_string_t cmd_set_txpkts_name =
3138         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3139                                  txpkts, "txpkts");
3140 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3141         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3142                                  seg_lengths, NULL);
3143
3144 cmdline_parse_inst_t cmd_set_txpkts = {
3145         .f = cmd_set_txpkts_parsed,
3146         .data = NULL,
3147         .help_str = "set txpkts <len0[,len1]*>",
3148         .tokens = {
3149                 (void *)&cmd_set_txpkts_keyword,
3150                 (void *)&cmd_set_txpkts_name,
3151                 (void *)&cmd_set_txpkts_lengths,
3152                 NULL,
3153         },
3154 };
3155
3156 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3157
3158 struct cmd_set_txsplit_result {
3159         cmdline_fixed_string_t cmd_keyword;
3160         cmdline_fixed_string_t txsplit;
3161         cmdline_fixed_string_t mode;
3162 };
3163
3164 static void
3165 cmd_set_txsplit_parsed(void *parsed_result,
3166                       __attribute__((unused)) struct cmdline *cl,
3167                       __attribute__((unused)) void *data)
3168 {
3169         struct cmd_set_txsplit_result *res;
3170
3171         res = parsed_result;
3172         set_tx_pkt_split(res->mode);
3173 }
3174
3175 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3176         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3177                                  cmd_keyword, "set");
3178 cmdline_parse_token_string_t cmd_set_txsplit_name =
3179         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3180                                  txsplit, "txsplit");
3181 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3182         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3183                                  mode, NULL);
3184
3185 cmdline_parse_inst_t cmd_set_txsplit = {
3186         .f = cmd_set_txsplit_parsed,
3187         .data = NULL,
3188         .help_str = "set txsplit on|off|rand",
3189         .tokens = {
3190                 (void *)&cmd_set_txsplit_keyword,
3191                 (void *)&cmd_set_txsplit_name,
3192                 (void *)&cmd_set_txsplit_mode,
3193                 NULL,
3194         },
3195 };
3196
3197 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3198 struct cmd_rx_vlan_filter_all_result {
3199         cmdline_fixed_string_t rx_vlan;
3200         cmdline_fixed_string_t what;
3201         cmdline_fixed_string_t all;
3202         portid_t port_id;
3203 };
3204
3205 static void
3206 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3207                               __attribute__((unused)) struct cmdline *cl,
3208                               __attribute__((unused)) void *data)
3209 {
3210         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3211
3212         if (!strcmp(res->what, "add"))
3213                 rx_vlan_all_filter_set(res->port_id, 1);
3214         else
3215                 rx_vlan_all_filter_set(res->port_id, 0);
3216 }
3217
3218 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3219         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3220                                  rx_vlan, "rx_vlan");
3221 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3222         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3223                                  what, "add#rm");
3224 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3225         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3226                                  all, "all");
3227 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3228         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3229                               port_id, UINT16);
3230
3231 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3232         .f = cmd_rx_vlan_filter_all_parsed,
3233         .data = NULL,
3234         .help_str = "rx_vlan add|rm all <port_id>: "
3235                 "Add/Remove all identifiers to/from the set of VLAN "
3236                 "identifiers filtered by a port",
3237         .tokens = {
3238                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3239                 (void *)&cmd_rx_vlan_filter_all_what,
3240                 (void *)&cmd_rx_vlan_filter_all_all,
3241                 (void *)&cmd_rx_vlan_filter_all_portid,
3242                 NULL,
3243         },
3244 };
3245
3246 /* *** VLAN OFFLOAD SET ON A PORT *** */
3247 struct cmd_vlan_offload_result {
3248         cmdline_fixed_string_t vlan;
3249         cmdline_fixed_string_t set;
3250         cmdline_fixed_string_t vlan_type;
3251         cmdline_fixed_string_t what;
3252         cmdline_fixed_string_t on;
3253         cmdline_fixed_string_t port_id;
3254 };
3255
3256 static void
3257 cmd_vlan_offload_parsed(void *parsed_result,
3258                           __attribute__((unused)) struct cmdline *cl,
3259                           __attribute__((unused)) void *data)
3260 {
3261         int on;
3262         struct cmd_vlan_offload_result *res = parsed_result;
3263         char *str;
3264         int i, len = 0;
3265         portid_t port_id = 0;
3266         unsigned int tmp;
3267
3268         str = res->port_id;
3269         len = strnlen(str, STR_TOKEN_SIZE);
3270         i = 0;
3271         /* Get port_id first */
3272         while(i < len){
3273                 if(str[i] == ',')
3274                         break;
3275
3276                 i++;
3277         }
3278         str[i]='\0';
3279         tmp = strtoul(str, NULL, 0);
3280         /* If port_id greater that what portid_t can represent, return */
3281         if(tmp >= RTE_MAX_ETHPORTS)
3282                 return;
3283         port_id = (portid_t)tmp;
3284
3285         if (!strcmp(res->on, "on"))
3286                 on = 1;
3287         else
3288                 on = 0;
3289
3290         if (!strcmp(res->what, "strip"))
3291                 rx_vlan_strip_set(port_id,  on);
3292         else if(!strcmp(res->what, "stripq")){
3293                 uint16_t queue_id = 0;
3294
3295                 /* No queue_id, return */
3296                 if(i + 1 >= len) {
3297                         printf("must specify (port,queue_id)\n");
3298                         return;
3299                 }
3300                 tmp = strtoul(str + i + 1, NULL, 0);
3301                 /* If queue_id greater that what 16-bits can represent, return */
3302                 if(tmp > 0xffff)
3303                         return;
3304
3305                 queue_id = (uint16_t)tmp;
3306                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3307         }
3308         else if (!strcmp(res->what, "filter"))
3309                 rx_vlan_filter_set(port_id, on);
3310         else
3311                 vlan_extend_set(port_id, on);
3312
3313         return;
3314 }
3315
3316 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3317         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3318                                  vlan, "vlan");
3319 cmdline_parse_token_string_t cmd_vlan_offload_set =
3320         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3321                                  set, "set");
3322 cmdline_parse_token_string_t cmd_vlan_offload_what =
3323         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3324                                  what, "strip#filter#qinq#stripq");
3325 cmdline_parse_token_string_t cmd_vlan_offload_on =
3326         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3327                               on, "on#off");
3328 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3329         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3330                               port_id, NULL);
3331
3332 cmdline_parse_inst_t cmd_vlan_offload = {
3333         .f = cmd_vlan_offload_parsed,
3334         .data = NULL,
3335         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3336                 "<port_id[,queue_id]>: "
3337                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3338         .tokens = {
3339                 (void *)&cmd_vlan_offload_vlan,
3340                 (void *)&cmd_vlan_offload_set,
3341                 (void *)&cmd_vlan_offload_what,
3342                 (void *)&cmd_vlan_offload_on,
3343                 (void *)&cmd_vlan_offload_portid,
3344                 NULL,
3345         },
3346 };
3347
3348 /* *** VLAN TPID SET ON A PORT *** */
3349 struct cmd_vlan_tpid_result {
3350         cmdline_fixed_string_t vlan;
3351         cmdline_fixed_string_t set;
3352         cmdline_fixed_string_t vlan_type;
3353         cmdline_fixed_string_t what;
3354         uint16_t tp_id;
3355         portid_t port_id;
3356 };
3357
3358 static void
3359 cmd_vlan_tpid_parsed(void *parsed_result,
3360                           __attribute__((unused)) struct cmdline *cl,
3361                           __attribute__((unused)) void *data)
3362 {
3363         struct cmd_vlan_tpid_result *res = parsed_result;
3364         enum rte_vlan_type vlan_type;
3365
3366         if (!strcmp(res->vlan_type, "inner"))
3367                 vlan_type = ETH_VLAN_TYPE_INNER;
3368         else if (!strcmp(res->vlan_type, "outer"))
3369                 vlan_type = ETH_VLAN_TYPE_OUTER;
3370         else {
3371                 printf("Unknown vlan type\n");
3372                 return;
3373         }
3374         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3375 }
3376
3377 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3378         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3379                                  vlan, "vlan");
3380 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3381         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3382                                  set, "set");
3383 cmdline_parse_token_string_t cmd_vlan_type =
3384         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3385                                  vlan_type, "inner#outer");
3386 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3387         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3388                                  what, "tpid");
3389 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3390         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3391                               tp_id, UINT16);
3392 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3393         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3394                               port_id, UINT16);
3395
3396 cmdline_parse_inst_t cmd_vlan_tpid = {
3397         .f = cmd_vlan_tpid_parsed,
3398         .data = NULL,
3399         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3400                 "Set the VLAN Ether type",
3401         .tokens = {
3402                 (void *)&cmd_vlan_tpid_vlan,
3403                 (void *)&cmd_vlan_tpid_set,
3404                 (void *)&cmd_vlan_type,
3405                 (void *)&cmd_vlan_tpid_what,
3406                 (void *)&cmd_vlan_tpid_tpid,
3407                 (void *)&cmd_vlan_tpid_portid,
3408                 NULL,
3409         },
3410 };
3411
3412 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3413 struct cmd_rx_vlan_filter_result {
3414         cmdline_fixed_string_t rx_vlan;
3415         cmdline_fixed_string_t what;
3416         uint16_t vlan_id;
3417         portid_t port_id;
3418 };
3419
3420 static void
3421 cmd_rx_vlan_filter_parsed(void *parsed_result,
3422                           __attribute__((unused)) struct cmdline *cl,
3423                           __attribute__((unused)) void *data)
3424 {
3425         struct cmd_rx_vlan_filter_result *res = parsed_result;
3426
3427         if (!strcmp(res->what, "add"))
3428                 rx_vft_set(res->port_id, res->vlan_id, 1);
3429         else
3430                 rx_vft_set(res->port_id, res->vlan_id, 0);
3431 }
3432
3433 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3434         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3435                                  rx_vlan, "rx_vlan");
3436 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3437         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3438                                  what, "add#rm");
3439 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3440         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3441                               vlan_id, UINT16);
3442 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3443         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3444                               port_id, UINT16);
3445
3446 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3447         .f = cmd_rx_vlan_filter_parsed,
3448         .data = NULL,
3449         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3450                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3451                 "identifiers filtered by a port",
3452         .tokens = {
3453                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3454                 (void *)&cmd_rx_vlan_filter_what,
3455                 (void *)&cmd_rx_vlan_filter_vlanid,
3456                 (void *)&cmd_rx_vlan_filter_portid,
3457                 NULL,
3458         },
3459 };
3460
3461 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3462 struct cmd_tx_vlan_set_result {
3463         cmdline_fixed_string_t tx_vlan;
3464         cmdline_fixed_string_t set;
3465         portid_t port_id;
3466         uint16_t vlan_id;
3467 };
3468
3469 static void
3470 cmd_tx_vlan_set_parsed(void *parsed_result,
3471                        __attribute__((unused)) struct cmdline *cl,
3472                        __attribute__((unused)) void *data)
3473 {
3474         struct cmd_tx_vlan_set_result *res = parsed_result;
3475
3476         if (!port_is_stopped(res->port_id)) {
3477                 printf("Please stop port %d first\n", res->port_id);
3478                 return;
3479         }
3480
3481         tx_vlan_set(res->port_id, res->vlan_id);
3482
3483         cmd_reconfig_device_queue(res->port_id, 1, 1);
3484 }
3485
3486 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3488                                  tx_vlan, "tx_vlan");
3489 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3490         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3491                                  set, "set");
3492 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3494                               port_id, UINT16);
3495 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3496         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3497                               vlan_id, UINT16);
3498
3499 cmdline_parse_inst_t cmd_tx_vlan_set = {
3500         .f = cmd_tx_vlan_set_parsed,
3501         .data = NULL,
3502         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3503                 "Enable hardware insertion of a single VLAN header "
3504                 "with a given TAG Identifier in packets sent on a port",
3505         .tokens = {
3506                 (void *)&cmd_tx_vlan_set_tx_vlan,
3507                 (void *)&cmd_tx_vlan_set_set,
3508                 (void *)&cmd_tx_vlan_set_portid,
3509                 (void *)&cmd_tx_vlan_set_vlanid,
3510                 NULL,
3511         },
3512 };
3513
3514 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3515 struct cmd_tx_vlan_set_qinq_result {
3516         cmdline_fixed_string_t tx_vlan;
3517         cmdline_fixed_string_t set;
3518         portid_t port_id;
3519         uint16_t vlan_id;
3520         uint16_t vlan_id_outer;
3521 };
3522
3523 static void
3524 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3525                             __attribute__((unused)) struct cmdline *cl,
3526                             __attribute__((unused)) void *data)
3527 {
3528         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3529
3530         if (!port_is_stopped(res->port_id)) {
3531                 printf("Please stop port %d first\n", res->port_id);
3532                 return;
3533         }
3534
3535         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3536
3537         cmd_reconfig_device_queue(res->port_id, 1, 1);
3538 }
3539
3540 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3541         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3542                 tx_vlan, "tx_vlan");
3543 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3544         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3545                 set, "set");
3546 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3547         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3548                 port_id, UINT16);
3549 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3550         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3551                 vlan_id, UINT16);
3552 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3553         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3554                 vlan_id_outer, UINT16);
3555
3556 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3557         .f = cmd_tx_vlan_set_qinq_parsed,
3558         .data = NULL,
3559         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3560                 "Enable hardware insertion of double VLAN header "
3561                 "with given TAG Identifiers in packets sent on a port",
3562         .tokens = {
3563                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3564                 (void *)&cmd_tx_vlan_set_qinq_set,
3565                 (void *)&cmd_tx_vlan_set_qinq_portid,
3566                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3567                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3568                 NULL,
3569         },
3570 };
3571
3572 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3573 struct cmd_tx_vlan_set_pvid_result {
3574         cmdline_fixed_string_t tx_vlan;
3575         cmdline_fixed_string_t set;
3576         cmdline_fixed_string_t pvid;
3577         portid_t port_id;
3578         uint16_t vlan_id;
3579         cmdline_fixed_string_t mode;
3580 };
3581
3582 static void
3583 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3584                             __attribute__((unused)) struct cmdline *cl,
3585                             __attribute__((unused)) void *data)
3586 {
3587         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3588
3589         if (strcmp(res->mode, "on") == 0)
3590                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3591         else
3592                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3593 }
3594
3595 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3596         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3597                                  tx_vlan, "tx_vlan");
3598 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3599         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3600                                  set, "set");
3601 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3602         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3603                                  pvid, "pvid");
3604 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3605         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3606                              port_id, UINT16);
3607 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3608         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3609                               vlan_id, UINT16);
3610 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3611         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3612                                  mode, "on#off");
3613
3614 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3615         .f = cmd_tx_vlan_set_pvid_parsed,
3616         .data = NULL,
3617         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3618         .tokens = {
3619                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3620                 (void *)&cmd_tx_vlan_set_pvid_set,
3621                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3622                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3623                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3624                 (void *)&cmd_tx_vlan_set_pvid_mode,
3625                 NULL,
3626         },
3627 };
3628
3629 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3630 struct cmd_tx_vlan_reset_result {
3631         cmdline_fixed_string_t tx_vlan;
3632         cmdline_fixed_string_t reset;
3633         portid_t port_id;
3634 };
3635
3636 static void
3637 cmd_tx_vlan_reset_parsed(void *parsed_result,
3638                          __attribute__((unused)) struct cmdline *cl,
3639                          __attribute__((unused)) void *data)
3640 {
3641         struct cmd_tx_vlan_reset_result *res = parsed_result;
3642
3643         if (!port_is_stopped(res->port_id)) {
3644                 printf("Please stop port %d first\n", res->port_id);
3645                 return;
3646         }
3647
3648         tx_vlan_reset(res->port_id);
3649
3650         cmd_reconfig_device_queue(res->port_id, 1, 1);
3651 }
3652
3653 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3654         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3655                                  tx_vlan, "tx_vlan");
3656 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3657         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3658                                  reset, "reset");
3659 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3660         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3661                               port_id, UINT16);
3662
3663 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3664         .f = cmd_tx_vlan_reset_parsed,
3665         .data = NULL,
3666         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3667                 "VLAN header in packets sent on a port",
3668         .tokens = {
3669                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3670                 (void *)&cmd_tx_vlan_reset_reset,
3671                 (void *)&cmd_tx_vlan_reset_portid,
3672                 NULL,
3673         },
3674 };
3675
3676
3677 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3678 struct cmd_csum_result {
3679         cmdline_fixed_string_t csum;
3680         cmdline_fixed_string_t mode;
3681         cmdline_fixed_string_t proto;
3682         cmdline_fixed_string_t hwsw;
3683         portid_t port_id;
3684 };
3685
3686 static void
3687 csum_show(int port_id)
3688 {
3689         struct rte_eth_dev_info dev_info;
3690         uint64_t tx_offloads;
3691
3692         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3693         printf("Parse tunnel is %s\n",
3694                 (ports[port_id].parse_tunnel) ? "on" : "off");
3695         printf("IP checksum offload is %s\n",
3696                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3697         printf("UDP checksum offload is %s\n",
3698                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3699         printf("TCP checksum offload is %s\n",
3700                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3701         printf("SCTP checksum offload is %s\n",
3702                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3703         printf("Outer-Ip checksum offload is %s\n",
3704                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3705
3706         /* display warnings if configuration is not supported by the NIC */
3707         rte_eth_dev_info_get(port_id, &dev_info);
3708         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3709                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3710                 printf("Warning: hardware IP checksum enabled but not "
3711                         "supported by port %d\n", port_id);
3712         }
3713         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3714                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3715                 printf("Warning: hardware UDP checksum enabled but not "
3716                         "supported by port %d\n", port_id);
3717         }
3718         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3719                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3720                 printf("Warning: hardware TCP checksum enabled but not "
3721                         "supported by port %d\n", port_id);
3722         }
3723         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3724                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3725                 printf("Warning: hardware SCTP checksum enabled but not "
3726                         "supported by port %d\n", port_id);
3727         }
3728         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3729                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3730                 printf("Warning: hardware outer IP checksum enabled but not "
3731                         "supported by port %d\n", port_id);
3732         }
3733 }
3734
3735 static void
3736 cmd_csum_parsed(void *parsed_result,
3737                        __attribute__((unused)) struct cmdline *cl,
3738                        __attribute__((unused)) void *data)
3739 {
3740         struct cmd_csum_result *res = parsed_result;
3741         int hw = 0;
3742         uint64_t csum_offloads = 0;
3743         struct rte_eth_dev_info dev_info;
3744
3745         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3746                 printf("invalid port %d\n", res->port_id);
3747                 return;
3748         }
3749         if (!port_is_stopped(res->port_id)) {
3750                 printf("Please stop port %d first\n", res->port_id);
3751                 return;
3752         }
3753
3754         rte_eth_dev_info_get(res->port_id, &dev_info);
3755         if (!strcmp(res->mode, "set")) {
3756
3757                 if (!strcmp(res->hwsw, "hw"))
3758                         hw = 1;
3759
3760                 if (!strcmp(res->proto, "ip")) {
3761                         if (hw == 0 || (dev_info.tx_offload_capa &
3762                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
3763                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3764                         } else {
3765                                 printf("IP checksum offload is not supported "
3766                                        "by port %u\n", res->port_id);
3767                         }
3768                 } else if (!strcmp(res->proto, "udp")) {
3769                         if (hw == 0 || (dev_info.tx_offload_capa &
3770                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
3771                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3772                         } else {
3773                                 printf("UDP checksum offload is not supported "
3774                                        "by port %u\n", res->port_id);
3775                         }
3776                 } else if (!strcmp(res->proto, "tcp")) {
3777                         if (hw == 0 || (dev_info.tx_offload_capa &
3778                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
3779                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3780                         } else {
3781                                 printf("TCP checksum offload is not supported "
3782                                        "by port %u\n", res->port_id);
3783                         }
3784                 } else if (!strcmp(res->proto, "sctp")) {
3785                         if (hw == 0 || (dev_info.tx_offload_capa &
3786                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
3787                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3788                         } else {
3789                                 printf("SCTP checksum offload is not supported "
3790                                        "by port %u\n", res->port_id);
3791                         }
3792                 } else if (!strcmp(res->proto, "outer-ip")) {
3793                         if (hw == 0 || (dev_info.tx_offload_capa &
3794                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
3795                                 csum_offloads |=
3796                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3797                         } else {
3798                                 printf("Outer IP checksum offload is not "
3799                                        "supported by port %u\n", res->port_id);
3800                         }
3801                 }
3802
3803                 if (hw) {
3804                         ports[res->port_id].dev_conf.txmode.offloads |=
3805                                                         csum_offloads;
3806                 } else {
3807                         ports[res->port_id].dev_conf.txmode.offloads &=
3808                                                         (~csum_offloads);
3809                 }
3810         }
3811         csum_show(res->port_id);
3812
3813         cmd_reconfig_device_queue(res->port_id, 1, 1);
3814 }
3815
3816 cmdline_parse_token_string_t cmd_csum_csum =
3817         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3818                                 csum, "csum");
3819 cmdline_parse_token_string_t cmd_csum_mode =
3820         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3821                                 mode, "set");
3822 cmdline_parse_token_string_t cmd_csum_proto =
3823         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3824                                 proto, "ip#tcp#udp#sctp#outer-ip");
3825 cmdline_parse_token_string_t cmd_csum_hwsw =
3826         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3827                                 hwsw, "hw#sw");
3828 cmdline_parse_token_num_t cmd_csum_portid =
3829         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3830                                 port_id, UINT16);
3831
3832 cmdline_parse_inst_t cmd_csum_set = {
3833         .f = cmd_csum_parsed,
3834         .data = NULL,
3835         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3836                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3837                 "using csum forward engine",
3838         .tokens = {
3839                 (void *)&cmd_csum_csum,
3840                 (void *)&cmd_csum_mode,
3841                 (void *)&cmd_csum_proto,
3842                 (void *)&cmd_csum_hwsw,
3843                 (void *)&cmd_csum_portid,
3844                 NULL,
3845         },
3846 };
3847
3848 cmdline_parse_token_string_t cmd_csum_mode_show =
3849         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3850                                 mode, "show");
3851
3852 cmdline_parse_inst_t cmd_csum_show = {
3853         .f = cmd_csum_parsed,
3854         .data = NULL,
3855         .help_str = "csum show <port_id>: Show checksum offload configuration",
3856         .tokens = {
3857                 (void *)&cmd_csum_csum,
3858                 (void *)&cmd_csum_mode_show,
3859                 (void *)&cmd_csum_portid,
3860                 NULL,
3861         },
3862 };
3863
3864 /* Enable/disable tunnel parsing */
3865 struct cmd_csum_tunnel_result {
3866         cmdline_fixed_string_t csum;
3867         cmdline_fixed_string_t parse;
3868         cmdline_fixed_string_t onoff;
3869         portid_t port_id;
3870 };
3871
3872 static void
3873 cmd_csum_tunnel_parsed(void *parsed_result,
3874                        __attribute__((unused)) struct cmdline *cl,
3875                        __attribute__((unused)) void *data)
3876 {
3877         struct cmd_csum_tunnel_result *res = parsed_result;
3878
3879         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3880                 return;
3881
3882         if (!strcmp(res->onoff, "on"))
3883                 ports[res->port_id].parse_tunnel = 1;
3884         else
3885                 ports[res->port_id].parse_tunnel = 0;
3886
3887         csum_show(res->port_id);
3888 }
3889
3890 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3891         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3892                                 csum, "csum");
3893 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3894         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3895                                 parse, "parse_tunnel");
3896 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3897         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3898                                 onoff, "on#off");
3899 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3900         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3901                                 port_id, UINT16);
3902
3903 cmdline_parse_inst_t cmd_csum_tunnel = {
3904         .f = cmd_csum_tunnel_parsed,
3905         .data = NULL,
3906         .help_str = "csum parse_tunnel on|off <port_id>: "
3907                 "Enable/Disable parsing of tunnels for csum engine",
3908         .tokens = {
3909                 (void *)&cmd_csum_tunnel_csum,
3910                 (void *)&cmd_csum_tunnel_parse,
3911                 (void *)&cmd_csum_tunnel_onoff,
3912                 (void *)&cmd_csum_tunnel_portid,
3913                 NULL,
3914         },
3915 };
3916
3917 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3918 struct cmd_tso_set_result {
3919         cmdline_fixed_string_t tso;
3920         cmdline_fixed_string_t mode;
3921         uint16_t tso_segsz;
3922         portid_t port_id;
3923 };
3924
3925 static void
3926 cmd_tso_set_parsed(void *parsed_result,
3927                        __attribute__((unused)) struct cmdline *cl,
3928                        __attribute__((unused)) void *data)
3929 {
3930         struct cmd_tso_set_result *res = parsed_result;
3931         struct rte_eth_dev_info dev_info;
3932
3933         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3934                 return;
3935         if (!port_is_stopped(res->port_id)) {
3936                 printf("Please stop port %d first\n", res->port_id);
3937                 return;
3938         }
3939
3940         if (!strcmp(res->mode, "set"))
3941                 ports[res->port_id].tso_segsz = res->tso_segsz;
3942
3943         rte_eth_dev_info_get(res->port_id, &dev_info);
3944         if ((ports[res->port_id].tso_segsz != 0) &&
3945                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3946                 printf("Error: TSO is not supported by port %d\n",
3947                        res->port_id);
3948                 return;
3949         }
3950
3951         if (ports[res->port_id].tso_segsz == 0) {
3952                 ports[res->port_id].dev_conf.txmode.offloads &=
3953                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3954                 printf("TSO for non-tunneled packets is disabled\n");
3955         } else {
3956                 ports[res->port_id].dev_conf.txmode.offloads |=
3957                                                 DEV_TX_OFFLOAD_TCP_TSO;
3958                 printf("TSO segment size for non-tunneled packets is %d\n",
3959                         ports[res->port_id].tso_segsz);
3960         }
3961
3962         /* display warnings if configuration is not supported by the NIC */
3963         rte_eth_dev_info_get(res->port_id, &dev_info);
3964         if ((ports[res->port_id].tso_segsz != 0) &&
3965                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3966                 printf("Warning: TSO enabled but not "
3967                         "supported by port %d\n", res->port_id);
3968         }
3969
3970         cmd_reconfig_device_queue(res->port_id, 1, 1);
3971 }
3972
3973 cmdline_parse_token_string_t cmd_tso_set_tso =
3974         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3975                                 tso, "tso");
3976 cmdline_parse_token_string_t cmd_tso_set_mode =
3977         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3978                                 mode, "set");
3979 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3980         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3981                                 tso_segsz, UINT16);
3982 cmdline_parse_token_num_t cmd_tso_set_portid =
3983         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3984                                 port_id, UINT16);
3985
3986 cmdline_parse_inst_t cmd_tso_set = {
3987         .f = cmd_tso_set_parsed,
3988         .data = NULL,
3989         .help_str = "tso set <tso_segsz> <port_id>: "
3990                 "Set TSO segment size of non-tunneled packets for csum engine "
3991                 "(0 to disable)",
3992         .tokens = {
3993                 (void *)&cmd_tso_set_tso,
3994                 (void *)&cmd_tso_set_mode,
3995                 (void *)&cmd_tso_set_tso_segsz,
3996                 (void *)&cmd_tso_set_portid,
3997                 NULL,
3998         },
3999 };
4000
4001 cmdline_parse_token_string_t cmd_tso_show_mode =
4002         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4003                                 mode, "show");
4004
4005
4006 cmdline_parse_inst_t cmd_tso_show = {
4007         .f = cmd_tso_set_parsed,
4008         .data = NULL,
4009         .help_str = "tso show <port_id>: "
4010                 "Show TSO segment size of non-tunneled packets for csum engine",
4011         .tokens = {
4012                 (void *)&cmd_tso_set_tso,
4013                 (void *)&cmd_tso_show_mode,
4014                 (void *)&cmd_tso_set_portid,
4015                 NULL,
4016         },
4017 };
4018
4019 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4020 struct cmd_tunnel_tso_set_result {
4021         cmdline_fixed_string_t tso;
4022         cmdline_fixed_string_t mode;
4023         uint16_t tso_segsz;
4024         portid_t port_id;
4025 };
4026
4027 static struct rte_eth_dev_info
4028 check_tunnel_tso_nic_support(portid_t port_id)
4029 {
4030         struct rte_eth_dev_info dev_info;
4031
4032         rte_eth_dev_info_get(port_id, &dev_info);
4033         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4034                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4035                        "not enabled for port %d\n", port_id);
4036         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4037                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4038                        "not enabled for port %d\n", port_id);
4039         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4040                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4041                        "not enabled for port %d\n", port_id);
4042         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4043                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4044                        "not enabled for port %d\n", port_id);
4045         return dev_info;
4046 }
4047
4048 static void
4049 cmd_tunnel_tso_set_parsed(void *parsed_result,
4050                           __attribute__((unused)) struct cmdline *cl,
4051                           __attribute__((unused)) void *data)
4052 {
4053         struct cmd_tunnel_tso_set_result *res = parsed_result;
4054         struct rte_eth_dev_info dev_info;
4055
4056         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4057                 return;
4058         if (!port_is_stopped(res->port_id)) {
4059                 printf("Please stop port %d first\n", res->port_id);
4060                 return;
4061         }
4062
4063         if (!strcmp(res->mode, "set"))
4064                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4065
4066         dev_info = check_tunnel_tso_nic_support(res->port_id);
4067         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4068                 ports[res->port_id].dev_conf.txmode.offloads &=
4069                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4070                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4071                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4072                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4073                 printf("TSO for tunneled packets is disabled\n");
4074         } else {
4075                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4076                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4077                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4078                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4079
4080                 ports[res->port_id].dev_conf.txmode.offloads |=
4081                         (tso_offloads & dev_info.tx_offload_capa);
4082                 printf("TSO segment size for tunneled packets is %d\n",
4083                         ports[res->port_id].tunnel_tso_segsz);
4084
4085                 /* Below conditions are needed to make it work:
4086                  * (1) tunnel TSO is supported by the NIC;
4087                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4088                  * are recognized;
4089                  * (3) for tunneled pkts with outer L3 of IPv4,
4090                  * "csum set outer-ip" must be set to hw, because after tso,
4091                  * total_len of outer IP header is changed, and the checksum
4092                  * of outer IP header calculated by sw should be wrong; that
4093                  * is not necessary for IPv6 tunneled pkts because there's no
4094                  * checksum in IP header anymore.
4095                  */
4096
4097                 if (!ports[res->port_id].parse_tunnel)
4098                         printf("Warning: csum parse_tunnel must be set "
4099                                 "so that tunneled packets are recognized\n");
4100                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4101                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4102                         printf("Warning: csum set outer-ip must be set to hw "
4103                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4104         }
4105
4106         cmd_reconfig_device_queue(res->port_id, 1, 1);
4107 }
4108
4109 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4110         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4111                                 tso, "tunnel_tso");
4112 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4113         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4114                                 mode, "set");
4115 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4116         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4117                                 tso_segsz, UINT16);
4118 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4119         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4120                                 port_id, UINT16);
4121
4122 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4123         .f = cmd_tunnel_tso_set_parsed,
4124         .data = NULL,
4125         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4126                 "Set TSO segment size of tunneled packets for csum engine "
4127                 "(0 to disable)",
4128         .tokens = {
4129                 (void *)&cmd_tunnel_tso_set_tso,
4130                 (void *)&cmd_tunnel_tso_set_mode,
4131                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4132                 (void *)&cmd_tunnel_tso_set_portid,
4133                 NULL,
4134         },
4135 };
4136
4137 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4138         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4139                                 mode, "show");
4140
4141
4142 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4143         .f = cmd_tunnel_tso_set_parsed,
4144         .data = NULL,
4145         .help_str = "tunnel_tso show <port_id> "
4146                 "Show TSO segment size of tunneled packets for csum engine",
4147         .tokens = {
4148                 (void *)&cmd_tunnel_tso_set_tso,
4149                 (void *)&cmd_tunnel_tso_show_mode,
4150                 (void *)&cmd_tunnel_tso_set_portid,
4151                 NULL,
4152         },
4153 };
4154
4155 /* *** SET GRO FOR A PORT *** */
4156 struct cmd_gro_enable_result {
4157         cmdline_fixed_string_t cmd_set;
4158         cmdline_fixed_string_t cmd_port;
4159         cmdline_fixed_string_t cmd_keyword;
4160         cmdline_fixed_string_t cmd_onoff;
4161         portid_t cmd_pid;
4162 };
4163
4164 static void
4165 cmd_gro_enable_parsed(void *parsed_result,
4166                 __attribute__((unused)) struct cmdline *cl,
4167                 __attribute__((unused)) void *data)
4168 {
4169         struct cmd_gro_enable_result *res;
4170
4171         res = parsed_result;
4172         if (!strcmp(res->cmd_keyword, "gro"))
4173                 setup_gro(res->cmd_onoff, res->cmd_pid);
4174 }
4175
4176 cmdline_parse_token_string_t cmd_gro_enable_set =
4177         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4178                         cmd_set, "set");
4179 cmdline_parse_token_string_t cmd_gro_enable_port =
4180         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4181                         cmd_keyword, "port");
4182 cmdline_parse_token_num_t cmd_gro_enable_pid =
4183         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4184                         cmd_pid, UINT16);
4185 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4186         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4187                         cmd_keyword, "gro");
4188 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4189         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4190                         cmd_onoff, "on#off");
4191
4192 cmdline_parse_inst_t cmd_gro_enable = {
4193         .f = cmd_gro_enable_parsed,
4194         .data = NULL,
4195         .help_str = "set port <port_id> gro on|off",
4196         .tokens = {
4197                 (void *)&cmd_gro_enable_set,
4198                 (void *)&cmd_gro_enable_port,
4199                 (void *)&cmd_gro_enable_pid,
4200                 (void *)&cmd_gro_enable_keyword,
4201                 (void *)&cmd_gro_enable_onoff,
4202                 NULL,
4203         },
4204 };
4205
4206 /* *** DISPLAY GRO CONFIGURATION *** */
4207 struct cmd_gro_show_result {
4208         cmdline_fixed_string_t cmd_show;
4209         cmdline_fixed_string_t cmd_port;
4210         cmdline_fixed_string_t cmd_keyword;
4211         portid_t cmd_pid;
4212 };
4213
4214 static void
4215 cmd_gro_show_parsed(void *parsed_result,
4216                 __attribute__((unused)) struct cmdline *cl,
4217                 __attribute__((unused)) void *data)
4218 {
4219         struct cmd_gro_show_result *res;
4220
4221         res = parsed_result;
4222         if (!strcmp(res->cmd_keyword, "gro"))
4223                 show_gro(res->cmd_pid);
4224 }
4225
4226 cmdline_parse_token_string_t cmd_gro_show_show =
4227         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4228                         cmd_show, "show");
4229 cmdline_parse_token_string_t cmd_gro_show_port =
4230         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4231                         cmd_port, "port");
4232 cmdline_parse_token_num_t cmd_gro_show_pid =
4233         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4234                         cmd_pid, UINT16);
4235 cmdline_parse_token_string_t cmd_gro_show_keyword =
4236         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4237                         cmd_keyword, "gro");
4238
4239 cmdline_parse_inst_t cmd_gro_show = {
4240         .f = cmd_gro_show_parsed,
4241         .data = NULL,
4242         .help_str = "show port <port_id> gro",
4243         .tokens = {
4244                 (void *)&cmd_gro_show_show,
4245                 (void *)&cmd_gro_show_port,
4246                 (void *)&cmd_gro_show_pid,
4247                 (void *)&cmd_gro_show_keyword,
4248                 NULL,
4249         },
4250 };
4251
4252 /* *** SET FLUSH CYCLES FOR GRO *** */
4253 struct cmd_gro_flush_result {
4254         cmdline_fixed_string_t cmd_set;
4255         cmdline_fixed_string_t cmd_keyword;
4256         cmdline_fixed_string_t cmd_flush;
4257         uint8_t cmd_cycles;
4258 };
4259
4260 static void
4261 cmd_gro_flush_parsed(void *parsed_result,
4262                 __attribute__((unused)) struct cmdline *cl,
4263                 __attribute__((unused)) void *data)
4264 {
4265         struct cmd_gro_flush_result *res;
4266
4267         res = parsed_result;
4268         if ((!strcmp(res->cmd_keyword, "gro")) &&
4269                         (!strcmp(res->cmd_flush, "flush")))
4270                 setup_gro_flush_cycles(res->cmd_cycles);
4271 }
4272
4273 cmdline_parse_token_string_t cmd_gro_flush_set =
4274         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4275                         cmd_set, "set");
4276 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4277         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4278                         cmd_keyword, "gro");
4279 cmdline_parse_token_string_t cmd_gro_flush_flush =
4280         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4281                         cmd_flush, "flush");
4282 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4283         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4284                         cmd_cycles, UINT8);
4285
4286 cmdline_parse_inst_t cmd_gro_flush = {
4287         .f = cmd_gro_flush_parsed,
4288         .data = NULL,
4289         .help_str = "set gro flush <cycles>",
4290         .tokens = {
4291                 (void *)&cmd_gro_flush_set,
4292                 (void *)&cmd_gro_flush_keyword,
4293                 (void *)&cmd_gro_flush_flush,
4294                 (void *)&cmd_gro_flush_cycles,
4295                 NULL,
4296         },
4297 };
4298
4299 /* *** ENABLE/DISABLE GSO *** */
4300 struct cmd_gso_enable_result {
4301         cmdline_fixed_string_t cmd_set;
4302         cmdline_fixed_string_t cmd_port;
4303         cmdline_fixed_string_t cmd_keyword;
4304         cmdline_fixed_string_t cmd_mode;
4305         portid_t cmd_pid;
4306 };
4307
4308 static void
4309 cmd_gso_enable_parsed(void *parsed_result,
4310                 __attribute__((unused)) struct cmdline *cl,
4311                 __attribute__((unused)) void *data)
4312 {
4313         struct cmd_gso_enable_result *res;
4314
4315         res = parsed_result;
4316         if (!strcmp(res->cmd_keyword, "gso"))
4317                 setup_gso(res->cmd_mode, res->cmd_pid);
4318 }
4319
4320 cmdline_parse_token_string_t cmd_gso_enable_set =
4321         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4322                         cmd_set, "set");
4323 cmdline_parse_token_string_t cmd_gso_enable_port =
4324         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4325                         cmd_port, "port");
4326 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4327         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4328                         cmd_keyword, "gso");
4329 cmdline_parse_token_string_t cmd_gso_enable_mode =
4330         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4331                         cmd_mode, "on#off");
4332 cmdline_parse_token_num_t cmd_gso_enable_pid =
4333         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4334                         cmd_pid, UINT16);
4335
4336 cmdline_parse_inst_t cmd_gso_enable = {
4337         .f = cmd_gso_enable_parsed,
4338         .data = NULL,
4339         .help_str = "set port <port_id> gso on|off",
4340         .tokens = {
4341                 (void *)&cmd_gso_enable_set,
4342                 (void *)&cmd_gso_enable_port,
4343                 (void *)&cmd_gso_enable_pid,
4344                 (void *)&cmd_gso_enable_keyword,
4345                 (void *)&cmd_gso_enable_mode,
4346                 NULL,
4347         },
4348 };
4349
4350 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4351 struct cmd_gso_size_result {
4352         cmdline_fixed_string_t cmd_set;
4353         cmdline_fixed_string_t cmd_keyword;
4354         cmdline_fixed_string_t cmd_segsz;
4355         uint16_t cmd_size;
4356 };
4357
4358 static void
4359 cmd_gso_size_parsed(void *parsed_result,
4360                        __attribute__((unused)) struct cmdline *cl,
4361                        __attribute__((unused)) void *data)
4362 {
4363         struct cmd_gso_size_result *res = parsed_result;
4364
4365         if (test_done == 0) {
4366                 printf("Before setting GSO segsz, please first"
4367                                 " stop fowarding\n");
4368                 return;
4369         }
4370
4371         if (!strcmp(res->cmd_keyword, "gso") &&
4372                         !strcmp(res->cmd_segsz, "segsz")) {
4373                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4374                         printf("gso_size should be larger than %zu."
4375                                         " Please input a legal value\n",
4376                                         RTE_GSO_SEG_SIZE_MIN);
4377                 else
4378                         gso_max_segment_size = res->cmd_size;
4379         }
4380 }
4381
4382 cmdline_parse_token_string_t cmd_gso_size_set =
4383         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4384                                 cmd_set, "set");
4385 cmdline_parse_token_string_t cmd_gso_size_keyword =
4386         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4387                                 cmd_keyword, "gso");
4388 cmdline_parse_token_string_t cmd_gso_size_segsz =
4389         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4390                                 cmd_segsz, "segsz");
4391 cmdline_parse_token_num_t cmd_gso_size_size =
4392         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4393                                 cmd_size, UINT16);
4394
4395 cmdline_parse_inst_t cmd_gso_size = {
4396         .f = cmd_gso_size_parsed,
4397         .data = NULL,
4398         .help_str = "set gso segsz <length>",
4399         .tokens = {
4400                 (void *)&cmd_gso_size_set,
4401                 (void *)&cmd_gso_size_keyword,
4402                 (void *)&cmd_gso_size_segsz,
4403                 (void *)&cmd_gso_size_size,
4404                 NULL,
4405         },
4406 };
4407
4408 /* *** SHOW GSO CONFIGURATION *** */
4409 struct cmd_gso_show_result {
4410         cmdline_fixed_string_t cmd_show;
4411         cmdline_fixed_string_t cmd_port;
4412         cmdline_fixed_string_t cmd_keyword;
4413         portid_t cmd_pid;
4414 };
4415
4416 static void
4417 cmd_gso_show_parsed(void *parsed_result,
4418                        __attribute__((unused)) struct cmdline *cl,
4419                        __attribute__((unused)) void *data)
4420 {
4421         struct cmd_gso_show_result *res = parsed_result;
4422
4423         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4424                 printf("invalid port id %u\n", res->cmd_pid);
4425                 return;
4426         }
4427         if (!strcmp(res->cmd_keyword, "gso")) {
4428                 if (gso_ports[res->cmd_pid].enable) {
4429                         printf("Max GSO'd packet size: %uB\n"
4430                                         "Supported GSO types: TCP/IPv4, "
4431                                         "VxLAN with inner TCP/IPv4 packet, "
4432                                         "GRE with inner TCP/IPv4  packet\n",
4433                                         gso_max_segment_size);
4434                 } else
4435                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4436         }
4437 }
4438
4439 cmdline_parse_token_string_t cmd_gso_show_show =
4440 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4441                 cmd_show, "show");
4442 cmdline_parse_token_string_t cmd_gso_show_port =
4443 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4444                 cmd_port, "port");
4445 cmdline_parse_token_string_t cmd_gso_show_keyword =
4446         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4447                                 cmd_keyword, "gso");
4448 cmdline_parse_token_num_t cmd_gso_show_pid =
4449         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4450                                 cmd_pid, UINT16);
4451
4452 cmdline_parse_inst_t cmd_gso_show = {
4453         .f = cmd_gso_show_parsed,
4454         .data = NULL,
4455         .help_str = "show port <port_id> gso",
4456         .tokens = {
4457                 (void *)&cmd_gso_show_show,
4458                 (void *)&cmd_gso_show_port,
4459                 (void *)&cmd_gso_show_pid,
4460                 (void *)&cmd_gso_show_keyword,
4461                 NULL,
4462         },
4463 };
4464
4465 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4466 struct cmd_set_flush_rx {
4467         cmdline_fixed_string_t set;
4468         cmdline_fixed_string_t flush_rx;
4469         cmdline_fixed_string_t mode;
4470 };
4471
4472 static void
4473 cmd_set_flush_rx_parsed(void *parsed_result,
4474                 __attribute__((unused)) struct cmdline *cl,
4475                 __attribute__((unused)) void *data)
4476 {
4477         struct cmd_set_flush_rx *res = parsed_result;
4478         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4479 }
4480
4481 cmdline_parse_token_string_t cmd_setflushrx_set =
4482         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4483                         set, "set");
4484 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4485         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4486                         flush_rx, "flush_rx");
4487 cmdline_parse_token_string_t cmd_setflushrx_mode =
4488         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4489                         mode, "on#off");
4490
4491
4492 cmdline_parse_inst_t cmd_set_flush_rx = {
4493         .f = cmd_set_flush_rx_parsed,
4494         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4495         .data = NULL,
4496         .tokens = {
4497                 (void *)&cmd_setflushrx_set,
4498                 (void *)&cmd_setflushrx_flush_rx,
4499                 (void *)&cmd_setflushrx_mode,
4500                 NULL,
4501         },
4502 };
4503
4504 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4505 struct cmd_set_link_check {
4506         cmdline_fixed_string_t set;
4507         cmdline_fixed_string_t link_check;
4508         cmdline_fixed_string_t mode;
4509 };
4510
4511 static void
4512 cmd_set_link_check_parsed(void *parsed_result,
4513                 __attribute__((unused)) struct cmdline *cl,
4514                 __attribute__((unused)) void *data)
4515 {
4516         struct cmd_set_link_check *res = parsed_result;
4517         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4518 }
4519
4520 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4521         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4522                         set, "set");
4523 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4524         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4525                         link_check, "link_check");
4526 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4527         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4528                         mode, "on#off");
4529
4530
4531 cmdline_parse_inst_t cmd_set_link_check = {
4532         .f = cmd_set_link_check_parsed,
4533         .help_str = "set link_check on|off: Enable/Disable link status check "
4534                     "when starting/stopping a port",
4535         .data = NULL,
4536         .tokens = {
4537                 (void *)&cmd_setlinkcheck_set,
4538                 (void *)&cmd_setlinkcheck_link_check,
4539                 (void *)&cmd_setlinkcheck_mode,
4540                 NULL,
4541         },
4542 };
4543
4544 /* *** SET NIC BYPASS MODE *** */
4545 struct cmd_set_bypass_mode_result {
4546         cmdline_fixed_string_t set;
4547         cmdline_fixed_string_t bypass;
4548         cmdline_fixed_string_t mode;
4549         cmdline_fixed_string_t value;
4550         portid_t port_id;
4551 };
4552
4553 static void
4554 cmd_set_bypass_mode_parsed(void *parsed_result,
4555                 __attribute__((unused)) struct cmdline *cl,
4556                 __attribute__((unused)) void *data)
4557 {
4558         struct cmd_set_bypass_mode_result *res = parsed_result;
4559         portid_t port_id = res->port_id;
4560         int32_t rc = -EINVAL;
4561
4562 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4563         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4564
4565         if (!strcmp(res->value, "bypass"))
4566                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4567         else if (!strcmp(res->value, "isolate"))
4568                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4569         else
4570                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4571
4572         /* Set the bypass mode for the relevant port. */
4573         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4574 #endif
4575         if (rc != 0)
4576                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4577 }
4578
4579 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4580         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4581                         set, "set");
4582 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4583         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4584                         bypass, "bypass");
4585 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4586         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4587                         mode, "mode");
4588 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4589         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4590                         value, "normal#bypass#isolate");
4591 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4592         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4593                                 port_id, UINT16);
4594
4595 cmdline_parse_inst_t cmd_set_bypass_mode = {
4596         .f = cmd_set_bypass_mode_parsed,
4597         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4598                     "Set the NIC bypass mode for port_id",
4599         .data = NULL,
4600         .tokens = {
4601                 (void *)&cmd_setbypass_mode_set,
4602                 (void *)&cmd_setbypass_mode_bypass,
4603                 (void *)&cmd_setbypass_mode_mode,
4604                 (void *)&cmd_setbypass_mode_value,
4605                 (void *)&cmd_setbypass_mode_port,
4606                 NULL,
4607         },
4608 };
4609
4610 /* *** SET NIC BYPASS EVENT *** */
4611 struct cmd_set_bypass_event_result {
4612         cmdline_fixed_string_t set;
4613         cmdline_fixed_string_t bypass;
4614         cmdline_fixed_string_t event;
4615         cmdline_fixed_string_t event_value;
4616         cmdline_fixed_string_t mode;
4617         cmdline_fixed_string_t mode_value;
4618         portid_t port_id;
4619 };
4620
4621 static void
4622 cmd_set_bypass_event_parsed(void *parsed_result,
4623                 __attribute__((unused)) struct cmdline *cl,
4624                 __attribute__((unused)) void *data)
4625 {
4626         int32_t rc = -EINVAL;
4627         struct cmd_set_bypass_event_result *res = parsed_result;
4628         portid_t port_id = res->port_id;
4629
4630 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4631         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4632         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4633
4634         if (!strcmp(res->event_value, "timeout"))
4635                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4636         else if (!strcmp(res->event_value, "os_on"))
4637                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4638         else if (!strcmp(res->event_value, "os_off"))
4639                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4640         else if (!strcmp(res->event_value, "power_on"))
4641                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4642         else if (!strcmp(res->event_value, "power_off"))
4643                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4644         else
4645                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4646
4647         if (!strcmp(res->mode_value, "bypass"))
4648                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4649         else if (!strcmp(res->mode_value, "isolate"))
4650                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4651         else
4652                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4653
4654         /* Set the watchdog timeout. */
4655         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4656
4657                 rc = -EINVAL;
4658                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4659                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4660                                                            bypass_timeout);
4661                 }
4662                 if (rc != 0) {
4663                         printf("Failed to set timeout value %u "
4664                         "for port %d, errto code: %d.\n",
4665                         bypass_timeout, port_id, rc);
4666                 }
4667         }
4668
4669         /* Set the bypass event to transition to bypass mode. */
4670         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4671                                               bypass_mode);
4672 #endif
4673
4674         if (rc != 0)
4675                 printf("\t Failed to set bypass event for port = %d.\n",
4676                        port_id);
4677 }
4678
4679 cmdline_parse_token_string_t cmd_setbypass_event_set =
4680         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4681                         set, "set");
4682 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4683         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4684                         bypass, "bypass");
4685 cmdline_parse_token_string_t cmd_setbypass_event_event =
4686         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4687                         event, "event");
4688 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4689         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4690                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4691 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4692         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4693                         mode, "mode");
4694 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4695         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4696                         mode_value, "normal#bypass#isolate");
4697 cmdline_parse_token_num_t cmd_setbypass_event_port =
4698         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4699                                 port_id, UINT16);
4700
4701 cmdline_parse_inst_t cmd_set_bypass_event = {
4702         .f = cmd_set_bypass_event_parsed,
4703         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4704                 "power_off mode normal|bypass|isolate <port_id>: "
4705                 "Set the NIC bypass event mode for port_id",
4706         .data = NULL,
4707         .tokens = {
4708                 (void *)&cmd_setbypass_event_set,
4709                 (void *)&cmd_setbypass_event_bypass,
4710                 (void *)&cmd_setbypass_event_event,
4711                 (void *)&cmd_setbypass_event_event_value,
4712                 (void *)&cmd_setbypass_event_mode,
4713                 (void *)&cmd_setbypass_event_mode_value,
4714                 (void *)&cmd_setbypass_event_port,
4715                 NULL,
4716         },
4717 };
4718
4719
4720 /* *** SET NIC BYPASS TIMEOUT *** */
4721 struct cmd_set_bypass_timeout_result {
4722         cmdline_fixed_string_t set;
4723         cmdline_fixed_string_t bypass;
4724         cmdline_fixed_string_t timeout;
4725         cmdline_fixed_string_t value;
4726 };
4727
4728 static void
4729 cmd_set_bypass_timeout_parsed(void *parsed_result,
4730                 __attribute__((unused)) struct cmdline *cl,
4731                 __attribute__((unused)) void *data)
4732 {
4733         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4734
4735 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4736         if (!strcmp(res->value, "1.5"))
4737                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4738         else if (!strcmp(res->value, "2"))
4739                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4740         else if (!strcmp(res->value, "3"))
4741                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4742         else if (!strcmp(res->value, "4"))
4743                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4744         else if (!strcmp(res->value, "8"))
4745                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4746         else if (!strcmp(res->value, "16"))
4747                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4748         else if (!strcmp(res->value, "32"))
4749                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4750         else
4751                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4752 #endif
4753 }
4754
4755 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4756         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4757                         set, "set");
4758 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4759         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4760                         bypass, "bypass");
4761 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4762         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4763                         timeout, "timeout");
4764 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4765         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4766                         value, "0#1.5#2#3#4#8#16#32");
4767
4768 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4769         .f = cmd_set_bypass_timeout_parsed,
4770         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4771                 "Set the NIC bypass watchdog timeout in seconds",
4772         .data = NULL,
4773         .tokens = {
4774                 (void *)&cmd_setbypass_timeout_set,
4775                 (void *)&cmd_setbypass_timeout_bypass,
4776                 (void *)&cmd_setbypass_timeout_timeout,
4777                 (void *)&cmd_setbypass_timeout_value,
4778                 NULL,
4779         },
4780 };
4781
4782 /* *** SHOW NIC BYPASS MODE *** */
4783 struct cmd_show_bypass_config_result {
4784         cmdline_fixed_string_t show;
4785         cmdline_fixed_string_t bypass;
4786         cmdline_fixed_string_t config;
4787         portid_t port_id;
4788 };
4789
4790 static void
4791 cmd_show_bypass_config_parsed(void *parsed_result,
4792                 __attribute__((unused)) struct cmdline *cl,
4793                 __attribute__((unused)) void *data)
4794 {
4795         struct cmd_show_bypass_config_result *res = parsed_result;
4796         portid_t port_id = res->port_id;
4797         int rc = -EINVAL;
4798 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4799         uint32_t event_mode;
4800         uint32_t bypass_mode;
4801         uint32_t timeout = bypass_timeout;
4802         int i;
4803
4804         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4805                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4806         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4807                 {"UNKNOWN", "normal", "bypass", "isolate"};
4808         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4809                 "NONE",
4810                 "OS/board on",
4811                 "power supply on",
4812                 "OS/board off",
4813                 "power supply off",
4814                 "timeout"};
4815         int num_events = (sizeof events) / (sizeof events[0]);
4816
4817         /* Display the bypass mode.*/
4818         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4819                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4820                 return;
4821         }
4822         else {
4823                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4824                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4825
4826                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4827         }
4828
4829         /* Display the bypass timeout.*/
4830         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4831                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4832
4833         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4834
4835         /* Display the bypass events and associated modes. */
4836         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4837
4838                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4839                         printf("\tFailed to get bypass mode for event = %s\n",
4840                                 events[i]);
4841                 } else {
4842                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4843                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4844
4845                         printf("\tbypass event: %-16s = %s\n", events[i],
4846                                 modes[event_mode]);
4847                 }
4848         }
4849 #endif
4850         if (rc != 0)
4851                 printf("\tFailed to get bypass configuration for port = %d\n",
4852                        port_id);
4853 }
4854
4855 cmdline_parse_token_string_t cmd_showbypass_config_show =
4856         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4857                         show, "show");
4858 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4859         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4860                         bypass, "bypass");
4861 cmdline_parse_token_string_t cmd_showbypass_config_config =
4862         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4863                         config, "config");
4864 cmdline_parse_token_num_t cmd_showbypass_config_port =
4865         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4866                                 port_id, UINT16);
4867
4868 cmdline_parse_inst_t cmd_show_bypass_config = {
4869         .f = cmd_show_bypass_config_parsed,
4870         .help_str = "show bypass config <port_id>: "
4871                     "Show the NIC bypass config for port_id",
4872         .data = NULL,
4873         .tokens = {
4874                 (void *)&cmd_showbypass_config_show,
4875                 (void *)&cmd_showbypass_config_bypass,
4876                 (void *)&cmd_showbypass_config_config,
4877                 (void *)&cmd_showbypass_config_port,
4878                 NULL,
4879         },
4880 };
4881
4882 #ifdef RTE_LIBRTE_PMD_BOND
4883 /* *** SET BONDING MODE *** */
4884 struct cmd_set_bonding_mode_result {
4885         cmdline_fixed_string_t set;
4886         cmdline_fixed_string_t bonding;
4887         cmdline_fixed_string_t mode;
4888         uint8_t value;
4889         portid_t port_id;
4890 };
4891
4892 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4893                 __attribute__((unused))  struct cmdline *cl,
4894                 __attribute__((unused)) void *data)
4895 {
4896         struct cmd_set_bonding_mode_result *res = parsed_result;
4897         portid_t port_id = res->port_id;
4898
4899         /* Set the bonding mode for the relevant port. */
4900         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4901                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4902 }
4903
4904 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4905 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4906                 set, "set");
4907 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4908 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4909                 bonding, "bonding");
4910 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4911 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4912                 mode, "mode");
4913 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4914 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4915                 value, UINT8);
4916 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4917 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4918                 port_id, UINT16);
4919
4920 cmdline_parse_inst_t cmd_set_bonding_mode = {
4921                 .f = cmd_set_bonding_mode_parsed,
4922                 .help_str = "set bonding mode <mode_value> <port_id>: "
4923                         "Set the bonding mode for port_id",
4924                 .data = NULL,
4925                 .tokens = {
4926                                 (void *) &cmd_setbonding_mode_set,
4927                                 (void *) &cmd_setbonding_mode_bonding,
4928                                 (void *) &cmd_setbonding_mode_mode,
4929                                 (void *) &cmd_setbonding_mode_value,
4930                                 (void *) &cmd_setbonding_mode_port,
4931                                 NULL
4932                 }
4933 };
4934
4935 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4936 struct cmd_set_bonding_lacp_dedicated_queues_result {
4937         cmdline_fixed_string_t set;
4938         cmdline_fixed_string_t bonding;
4939         cmdline_fixed_string_t lacp;
4940         cmdline_fixed_string_t dedicated_queues;
4941         portid_t port_id;
4942         cmdline_fixed_string_t mode;
4943 };
4944
4945 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4946                 __attribute__((unused))  struct cmdline *cl,
4947                 __attribute__((unused)) void *data)
4948 {
4949         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4950         portid_t port_id = res->port_id;
4951         struct rte_port *port;
4952
4953         port = &ports[port_id];
4954
4955         /** Check if the port is not started **/
4956         if (port->port_status != RTE_PORT_STOPPED) {
4957                 printf("Please stop port %d first\n", port_id);
4958                 return;
4959         }
4960
4961         if (!strcmp(res->mode, "enable")) {
4962                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4963                         printf("Dedicate queues for LACP control packets"
4964                                         " enabled\n");
4965                 else
4966                         printf("Enabling dedicate queues for LACP control "
4967                                         "packets on port %d failed\n", port_id);
4968         } else if (!strcmp(res->mode, "disable")) {
4969                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4970                         printf("Dedicated queues for LACP control packets "
4971                                         "disabled\n");
4972                 else
4973                         printf("Disabling dedicated queues for LACP control "
4974                                         "traffic on port %d failed\n", port_id);
4975         }
4976 }
4977
4978 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4979 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4980                 set, "set");
4981 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4982 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4983                 bonding, "bonding");
4984 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4985 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4986                 lacp, "lacp");
4987 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4988 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4989                 dedicated_queues, "dedicated_queues");
4990 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4991 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4992                 port_id, UINT16);
4993 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4994 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4995                 mode, "enable#disable");
4996
4997 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4998                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4999                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5000                         "enable|disable: "
5001                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5002                 .data = NULL,
5003                 .tokens = {
5004                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5005                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5006                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5007                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5008                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5009                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5010                         NULL
5011                 }
5012 };
5013
5014 /* *** SET BALANCE XMIT POLICY *** */
5015 struct cmd_set_bonding_balance_xmit_policy_result {
5016         cmdline_fixed_string_t set;
5017         cmdline_fixed_string_t bonding;
5018         cmdline_fixed_string_t balance_xmit_policy;
5019         portid_t port_id;
5020         cmdline_fixed_string_t policy;
5021 };
5022
5023 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5024                 __attribute__((unused))  struct cmdline *cl,
5025                 __attribute__((unused)) void *data)
5026 {
5027         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5028         portid_t port_id = res->port_id;
5029         uint8_t policy;
5030
5031         if (!strcmp(res->policy, "l2")) {
5032                 policy = BALANCE_XMIT_POLICY_LAYER2;
5033         } else if (!strcmp(res->policy, "l23")) {
5034                 policy = BALANCE_XMIT_POLICY_LAYER23;
5035         } else if (!strcmp(res->policy, "l34")) {
5036                 policy = BALANCE_XMIT_POLICY_LAYER34;
5037         } else {
5038                 printf("\t Invalid xmit policy selection");
5039                 return;
5040         }
5041
5042         /* Set the bonding mode for the relevant port. */
5043         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5044                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5045                                 port_id);
5046         }
5047 }
5048
5049 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5051                 set, "set");
5052 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5053 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5054                 bonding, "bonding");
5055 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5056 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5057                 balance_xmit_policy, "balance_xmit_policy");
5058 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5059 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5060                 port_id, UINT16);
5061 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5062 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5063                 policy, "l2#l23#l34");
5064
5065 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5066                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5067                 .help_str = "set bonding balance_xmit_policy <port_id> "
5068                         "l2|l23|l34: "
5069                         "Set the bonding balance_xmit_policy for port_id",
5070                 .data = NULL,
5071                 .tokens = {
5072                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5073                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5074                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5075                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5076                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5077                                 NULL
5078                 }
5079 };
5080
5081 /* *** SHOW NIC BONDING CONFIGURATION *** */
5082 struct cmd_show_bonding_config_result {
5083         cmdline_fixed_string_t show;
5084         cmdline_fixed_string_t bonding;
5085         cmdline_fixed_string_t config;
5086         portid_t port_id;
5087 };
5088
5089 static void cmd_show_bonding_config_parsed(void *parsed_result,
5090                 __attribute__((unused))  struct cmdline *cl,
5091                 __attribute__((unused)) void *data)
5092 {
5093         struct cmd_show_bonding_config_result *res = parsed_result;
5094         int bonding_mode, agg_mode;
5095         portid_t slaves[RTE_MAX_ETHPORTS];
5096         int num_slaves, num_active_slaves;
5097         int primary_id;
5098         int i;
5099         portid_t port_id = res->port_id;
5100
5101         /* Display the bonding mode.*/
5102         bonding_mode = rte_eth_bond_mode_get(port_id);
5103         if (bonding_mode < 0) {
5104                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5105                 return;
5106         } else
5107                 printf("\tBonding mode: %d\n", bonding_mode);
5108
5109         if (bonding_mode == BONDING_MODE_BALANCE) {
5110                 int balance_xmit_policy;
5111
5112                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5113                 if (balance_xmit_policy < 0) {
5114                         printf("\tFailed to get balance xmit policy for port = %d\n",
5115                                         port_id);
5116                         return;
5117                 } else {
5118                         printf("\tBalance Xmit Policy: ");
5119
5120                         switch (balance_xmit_policy) {
5121                         case BALANCE_XMIT_POLICY_LAYER2:
5122                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5123                                 break;
5124                         case BALANCE_XMIT_POLICY_LAYER23:
5125                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5126                                 break;
5127                         case BALANCE_XMIT_POLICY_LAYER34:
5128                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5129                                 break;
5130                         }
5131                         printf("\n");
5132                 }
5133         }
5134
5135         if (bonding_mode == BONDING_MODE_8023AD) {
5136                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5137                 printf("\tIEEE802.3AD Aggregator Mode: ");
5138                 switch (agg_mode) {
5139                 case AGG_BANDWIDTH:
5140                         printf("bandwidth");
5141                         break;
5142                 case AGG_STABLE:
5143                         printf("stable");
5144                         break;
5145                 case AGG_COUNT:
5146                         printf("count");
5147                         break;
5148                 }
5149                 printf("\n");
5150         }
5151
5152         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5153
5154         if (num_slaves < 0) {
5155                 printf("\tFailed to get slave list for port = %d\n", port_id);
5156                 return;
5157         }
5158         if (num_slaves > 0) {
5159                 printf("\tSlaves (%d): [", num_slaves);
5160                 for (i = 0; i < num_slaves - 1; i++)
5161                         printf("%d ", slaves[i]);
5162
5163                 printf("%d]\n", slaves[num_slaves - 1]);
5164         } else {
5165                 printf("\tSlaves: []\n");
5166
5167         }
5168
5169         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5170                         RTE_MAX_ETHPORTS);
5171
5172         if (num_active_slaves < 0) {
5173                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5174                 return;
5175         }
5176         if (num_active_slaves > 0) {
5177                 printf("\tActive Slaves (%d): [", num_active_slaves);
5178                 for (i = 0; i < num_active_slaves - 1; i++)
5179                         printf("%d ", slaves[i]);
5180
5181                 printf("%d]\n", slaves[num_active_slaves - 1]);
5182
5183         } else {
5184                 printf("\tActive Slaves: []\n");
5185
5186         }
5187
5188         primary_id = rte_eth_bond_primary_get(port_id);
5189         if (primary_id < 0) {
5190                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5191                 return;
5192         } else
5193                 printf("\tPrimary: [%d]\n", primary_id);
5194
5195 }
5196
5197 cmdline_parse_token_string_t cmd_showbonding_config_show =
5198 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5199                 show, "show");
5200 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5201 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5202                 bonding, "bonding");
5203 cmdline_parse_token_string_t cmd_showbonding_config_config =
5204 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5205                 config, "config");
5206 cmdline_parse_token_num_t cmd_showbonding_config_port =
5207 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5208                 port_id, UINT16);
5209
5210 cmdline_parse_inst_t cmd_show_bonding_config = {
5211                 .f = cmd_show_bonding_config_parsed,
5212                 .help_str = "show bonding config <port_id>: "
5213                         "Show the bonding config for port_id",
5214                 .data = NULL,
5215                 .tokens = {
5216                                 (void *)&cmd_showbonding_config_show,
5217                                 (void *)&cmd_showbonding_config_bonding,
5218                                 (void *)&cmd_showbonding_config_config,
5219                                 (void *)&cmd_showbonding_config_port,
5220                                 NULL
5221                 }
5222 };
5223
5224 /* *** SET BONDING PRIMARY *** */
5225 struct cmd_set_bonding_primary_result {
5226         cmdline_fixed_string_t set;
5227         cmdline_fixed_string_t bonding;
5228         cmdline_fixed_string_t primary;
5229         portid_t slave_id;
5230         portid_t port_id;
5231 };
5232
5233 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5234                 __attribute__((unused))  struct cmdline *cl,
5235                 __attribute__((unused)) void *data)
5236 {
5237         struct cmd_set_bonding_primary_result *res = parsed_result;
5238         portid_t master_port_id = res->port_id;
5239         portid_t slave_port_id = res->slave_id;
5240
5241         /* Set the primary slave for a bonded device. */
5242         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5243                 printf("\t Failed to set primary slave for port = %d.\n",
5244                                 master_port_id);
5245                 return;
5246         }
5247         init_port_config();
5248 }
5249
5250 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5251 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5252                 set, "set");
5253 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5254 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5255                 bonding, "bonding");
5256 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5257 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5258                 primary, "primary");
5259 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5260 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5261                 slave_id, UINT16);
5262 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5263 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5264                 port_id, UINT16);
5265
5266 cmdline_parse_inst_t cmd_set_bonding_primary = {
5267                 .f = cmd_set_bonding_primary_parsed,
5268                 .help_str = "set bonding primary <slave_id> <port_id>: "
5269                         "Set the primary slave for port_id",
5270                 .data = NULL,
5271                 .tokens = {
5272                                 (void *)&cmd_setbonding_primary_set,
5273                                 (void *)&cmd_setbonding_primary_bonding,
5274                                 (void *)&cmd_setbonding_primary_primary,
5275                                 (void *)&cmd_setbonding_primary_slave,
5276                                 (void *)&cmd_setbonding_primary_port,
5277                                 NULL
5278                 }
5279 };
5280
5281 /* *** ADD SLAVE *** */
5282 struct cmd_add_bonding_slave_result {
5283         cmdline_fixed_string_t add;
5284         cmdline_fixed_string_t bonding;
5285         cmdline_fixed_string_t slave;
5286         portid_t slave_id;
5287         portid_t port_id;
5288 };
5289
5290 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5291                 __attribute__((unused))  struct cmdline *cl,
5292                 __attribute__((unused)) void *data)
5293 {
5294         struct cmd_add_bonding_slave_result *res = parsed_result;
5295         portid_t master_port_id = res->port_id;
5296         portid_t slave_port_id = res->slave_id;
5297
5298         /* add the slave for a bonded device. */
5299         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5300                 printf("\t Failed to add slave %d to master port = %d.\n",
5301                                 slave_port_id, master_port_id);
5302                 return;
5303         }
5304         init_port_config();
5305         set_port_slave_flag(slave_port_id);
5306 }
5307
5308 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5309 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5310                 add, "add");
5311 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5312 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5313                 bonding, "bonding");
5314 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5315 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5316                 slave, "slave");
5317 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5318 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5319                 slave_id, UINT16);
5320 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5321 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5322                 port_id, UINT16);
5323
5324 cmdline_parse_inst_t cmd_add_bonding_slave = {
5325                 .f = cmd_add_bonding_slave_parsed,
5326                 .help_str = "add bonding slave <slave_id> <port_id>: "
5327                         "Add a slave device to a bonded device",
5328                 .data = NULL,
5329                 .tokens = {
5330                                 (void *)&cmd_addbonding_slave_add,
5331                                 (void *)&cmd_addbonding_slave_bonding,
5332                                 (void *)&cmd_addbonding_slave_slave,
5333                                 (void *)&cmd_addbonding_slave_slaveid,
5334                                 (void *)&cmd_addbonding_slave_port,
5335                                 NULL
5336                 }
5337 };
5338
5339 /* *** REMOVE SLAVE *** */
5340 struct cmd_remove_bonding_slave_result {
5341         cmdline_fixed_string_t remove;
5342         cmdline_fixed_string_t bonding;
5343         cmdline_fixed_string_t slave;
5344         portid_t slave_id;
5345         portid_t port_id;
5346 };
5347
5348 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5349                 __attribute__((unused))  struct cmdline *cl,
5350                 __attribute__((unused)) void *data)
5351 {
5352         struct cmd_remove_bonding_slave_result *res = parsed_result;
5353         portid_t master_port_id = res->port_id;
5354         portid_t slave_port_id = res->slave_id;
5355
5356         /* remove the slave from a bonded device. */
5357         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5358                 printf("\t Failed to remove slave %d from master port = %d.\n",
5359                                 slave_port_id, master_port_id);
5360                 return;
5361         }
5362         init_port_config();
5363         clear_port_slave_flag(slave_port_id);
5364 }
5365
5366 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5367                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5368                                 remove, "remove");
5369 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5370                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5371                                 bonding, "bonding");
5372 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5373                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5374                                 slave, "slave");
5375 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5376                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5377                                 slave_id, UINT16);
5378 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5379                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5380                                 port_id, UINT16);
5381
5382 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5383                 .f = cmd_remove_bonding_slave_parsed,
5384                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5385                         "Remove a slave device from a bonded device",
5386                 .data = NULL,
5387                 .tokens = {
5388                                 (void *)&cmd_removebonding_slave_remove,
5389                                 (void *)&cmd_removebonding_slave_bonding,
5390                                 (void *)&cmd_removebonding_slave_slave,
5391                                 (void *)&cmd_removebonding_slave_slaveid,
5392                                 (void *)&cmd_removebonding_slave_port,
5393                                 NULL
5394                 }
5395 };
5396
5397 /* *** CREATE BONDED DEVICE *** */
5398 struct cmd_create_bonded_device_result {
5399         cmdline_fixed_string_t create;
5400         cmdline_fixed_string_t bonded;
5401         cmdline_fixed_string_t device;
5402         uint8_t mode;
5403         uint8_t socket;
5404 };
5405
5406 static int bond_dev_num = 0;
5407
5408 static void cmd_create_bonded_device_parsed(void *parsed_result,
5409                 __attribute__((unused))  struct cmdline *cl,
5410                 __attribute__((unused)) void *data)
5411 {
5412         struct cmd_create_bonded_device_result *res = parsed_result;
5413         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5414         int port_id;
5415
5416         if (test_done == 0) {
5417                 printf("Please stop forwarding first\n");
5418                 return;
5419         }
5420
5421         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5422                         bond_dev_num++);
5423
5424         /* Create a new bonded device. */
5425         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5426         if (port_id < 0) {
5427                 printf("\t Failed to create bonded device.\n");
5428                 return;
5429         } else {
5430                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5431                                 port_id);
5432
5433                 /* Update number of ports */
5434                 nb_ports = rte_eth_dev_count();
5435                 reconfig(port_id, res->socket);
5436                 rte_eth_promiscuous_enable(port_id);
5437         }
5438
5439 }
5440
5441 cmdline_parse_token_string_t cmd_createbonded_device_create =
5442                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5443                                 create, "create");
5444 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5445                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5446                                 bonded, "bonded");
5447 cmdline_parse_token_string_t cmd_createbonded_device_device =
5448                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5449                                 device, "device");
5450 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5451                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5452                                 mode, UINT8);
5453 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5454                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5455                                 socket, UINT8);
5456
5457 cmdline_parse_inst_t cmd_create_bonded_device = {
5458                 .f = cmd_create_bonded_device_parsed,
5459                 .help_str = "create bonded device <mode> <socket>: "
5460                         "Create a new bonded device with specific bonding mode and socket",
5461                 .data = NULL,
5462                 .tokens = {
5463                                 (void *)&cmd_createbonded_device_create,
5464                                 (void *)&cmd_createbonded_device_bonded,
5465                                 (void *)&cmd_createbonded_device_device,
5466                                 (void *)&cmd_createbonded_device_mode,
5467                                 (void *)&cmd_createbonded_device_socket,
5468                                 NULL
5469                 }
5470 };
5471
5472 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5473 struct cmd_set_bond_mac_addr_result {
5474         cmdline_fixed_string_t set;
5475         cmdline_fixed_string_t bonding;
5476         cmdline_fixed_string_t mac_addr;
5477         uint16_t port_num;
5478         struct ether_addr address;
5479 };
5480
5481 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5482                 __attribute__((unused))  struct cmdline *cl,
5483                 __attribute__((unused)) void *data)
5484 {
5485         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5486         int ret;
5487
5488         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5489                 return;
5490
5491         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5492
5493         /* check the return value and print it if is < 0 */
5494         if (ret < 0)
5495                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5496 }
5497
5498 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5499                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5500 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5501                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5502                                 "bonding");
5503 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5504                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5505                                 "mac_addr");
5506 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5507                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5508                                 port_num, UINT16);
5509 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5510                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5511
5512 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5513                 .f = cmd_set_bond_mac_addr_parsed,
5514                 .data = (void *) 0,
5515                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5516                 .tokens = {
5517                                 (void *)&cmd_set_bond_mac_addr_set,
5518                                 (void *)&cmd_set_bond_mac_addr_bonding,
5519                                 (void *)&cmd_set_bond_mac_addr_mac,
5520                                 (void *)&cmd_set_bond_mac_addr_portnum,
5521                                 (void *)&cmd_set_bond_mac_addr_addr,
5522                                 NULL
5523                 }
5524 };
5525
5526
5527 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5528 struct cmd_set_bond_mon_period_result {
5529         cmdline_fixed_string_t set;
5530         cmdline_fixed_string_t bonding;
5531         cmdline_fixed_string_t mon_period;
5532         uint16_t port_num;
5533         uint32_t period_ms;
5534 };
5535
5536 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5537                 __attribute__((unused))  struct cmdline *cl,
5538                 __attribute__((unused)) void *data)
5539 {
5540         struct cmd_set_bond_mon_period_result *res = parsed_result;
5541         int ret;
5542
5543         if (res->port_num >= nb_ports) {
5544                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5545                 return;
5546         }
5547
5548         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5549
5550         /* check the return value and print it if is < 0 */
5551         if (ret < 0)
5552                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5553 }
5554
5555 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5556                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5557                                 set, "set");
5558 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5559                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5560                                 bonding, "bonding");
5561 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5562                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5563                                 mon_period,     "mon_period");
5564 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5565                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5566                                 port_num, UINT16);
5567 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5568                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5569                                 period_ms, UINT32);
5570
5571 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5572                 .f = cmd_set_bond_mon_period_parsed,
5573                 .data = (void *) 0,
5574                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5575                 .tokens = {
5576                                 (void *)&cmd_set_bond_mon_period_set,
5577                                 (void *)&cmd_set_bond_mon_period_bonding,
5578                                 (void *)&cmd_set_bond_mon_period_mon_period,
5579                                 (void *)&cmd_set_bond_mon_period_portnum,
5580                                 (void *)&cmd_set_bond_mon_period_period_ms,
5581                                 NULL
5582                 }
5583 };
5584
5585
5586
5587 struct cmd_set_bonding_agg_mode_policy_result {
5588         cmdline_fixed_string_t set;
5589         cmdline_fixed_string_t bonding;
5590         cmdline_fixed_string_t agg_mode;
5591         uint16_t port_num;
5592         cmdline_fixed_string_t policy;
5593 };
5594
5595
5596 static void
5597 cmd_set_bonding_agg_mode(void *parsed_result,
5598                 __attribute__((unused)) struct cmdline *cl,
5599                 __attribute__((unused)) void *data)
5600 {
5601         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5602         uint8_t policy = AGG_BANDWIDTH;
5603
5604         if (res->port_num >= nb_ports) {
5605                 printf("Port id %d must be less than %d\n",
5606                                 res->port_num, nb_ports);
5607                 return;
5608         }
5609
5610         if (!strcmp(res->policy, "bandwidth"))
5611                 policy = AGG_BANDWIDTH;
5612         else if (!strcmp(res->policy, "stable"))
5613                 policy = AGG_STABLE;
5614         else if (!strcmp(res->policy, "count"))
5615                 policy = AGG_COUNT;
5616
5617         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5618 }
5619
5620
5621 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5622         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5623                                 set, "set");
5624 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5625         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5626                                 bonding, "bonding");
5627
5628 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5630                                 agg_mode, "agg_mode");
5631
5632 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5633         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5634                                 port_num, UINT16);
5635
5636 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5637         TOKEN_STRING_INITIALIZER(
5638                         struct cmd_set_bonding_balance_xmit_policy_result,
5639                 policy, "stable#bandwidth#count");
5640
5641 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5642         .f = cmd_set_bonding_agg_mode,
5643         .data = (void *) 0,
5644         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5645         .tokens = {
5646                         (void *)&cmd_set_bonding_agg_mode_set,
5647                         (void *)&cmd_set_bonding_agg_mode_bonding,
5648                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5649                         (void *)&cmd_set_bonding_agg_mode_portnum,
5650                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5651                         NULL
5652                 }
5653 };
5654
5655
5656 #endif /* RTE_LIBRTE_PMD_BOND */
5657
5658 /* *** SET FORWARDING MODE *** */
5659 struct cmd_set_fwd_mode_result {
5660         cmdline_fixed_string_t set;
5661         cmdline_fixed_string_t fwd;
5662         cmdline_fixed_string_t mode;
5663 };
5664
5665 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5666                                     __attribute__((unused)) struct cmdline *cl,
5667                                     __attribute__((unused)) void *data)
5668 {
5669         struct cmd_set_fwd_mode_result *res = parsed_result;
5670
5671         retry_enabled = 0;
5672         set_pkt_forwarding_mode(res->mode);
5673 }
5674
5675 cmdline_parse_token_string_t cmd_setfwd_set =
5676         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5677 cmdline_parse_token_string_t cmd_setfwd_fwd =
5678         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5679 cmdline_parse_token_string_t cmd_setfwd_mode =
5680         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5681                 "" /* defined at init */);
5682
5683 cmdline_parse_inst_t cmd_set_fwd_mode = {
5684         .f = cmd_set_fwd_mode_parsed,
5685         .data = NULL,
5686         .help_str = NULL, /* defined at init */
5687         .tokens = {
5688                 (void *)&cmd_setfwd_set,
5689                 (void *)&cmd_setfwd_fwd,
5690                 (void *)&cmd_setfwd_mode,
5691                 NULL,
5692         },
5693 };
5694
5695 static void cmd_set_fwd_mode_init(void)
5696 {
5697         char *modes, *c;
5698         static char token[128];
5699         static char help[256];
5700         cmdline_parse_token_string_t *token_struct;
5701
5702         modes = list_pkt_forwarding_modes();
5703         snprintf(help, sizeof(help), "set fwd %s: "
5704                 "Set packet forwarding mode", modes);
5705         cmd_set_fwd_mode.help_str = help;
5706
5707         /* string token separator is # */
5708         for (c = token; *modes != '\0'; modes++)
5709                 if (*modes == '|')
5710                         *c++ = '#';
5711                 else
5712                         *c++ = *modes;
5713         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5714         token_struct->string_data.str = token;
5715 }
5716
5717 /* *** SET RETRY FORWARDING MODE *** */
5718 struct cmd_set_fwd_retry_mode_result {
5719         cmdline_fixed_string_t set;
5720         cmdline_fixed_string_t fwd;
5721         cmdline_fixed_string_t mode;
5722         cmdline_fixed_string_t retry;
5723 };
5724
5725 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5726                             __attribute__((unused)) struct cmdline *cl,
5727                             __attribute__((unused)) void *data)
5728 {
5729         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5730
5731         retry_enabled = 1;
5732         set_pkt_forwarding_mode(res->mode);
5733 }
5734
5735 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5736         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5737                         set, "set");
5738 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5739         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5740                         fwd, "fwd");
5741 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5742         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5743                         mode,
5744                 "" /* defined at init */);
5745 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5746         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5747                         retry, "retry");
5748
5749 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5750         .f = cmd_set_fwd_retry_mode_parsed,
5751         .data = NULL,
5752         .help_str = NULL, /* defined at init */
5753         .tokens = {
5754                 (void *)&cmd_setfwd_retry_set,
5755                 (void *)&cmd_setfwd_retry_fwd,
5756                 (void *)&cmd_setfwd_retry_mode,
5757                 (void *)&cmd_setfwd_retry_retry,
5758                 NULL,
5759         },
5760 };
5761
5762 static void cmd_set_fwd_retry_mode_init(void)
5763 {
5764         char *modes, *c;
5765         static char token[128];
5766         static char help[256];
5767         cmdline_parse_token_string_t *token_struct;
5768
5769         modes = list_pkt_forwarding_retry_modes();
5770         snprintf(help, sizeof(help), "set fwd %s retry: "
5771                 "Set packet forwarding mode with retry", modes);
5772         cmd_set_fwd_retry_mode.help_str = help;
5773
5774         /* string token separator is # */
5775         for (c = token; *modes != '\0'; modes++)
5776                 if (*modes == '|')
5777                         *c++ = '#';
5778                 else
5779                         *c++ = *modes;
5780         token_struct = (cmdline_parse_token_string_t *)
5781                 cmd_set_fwd_retry_mode.tokens[2];
5782         token_struct->string_data.str = token;
5783 }
5784
5785 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5786 struct cmd_set_burst_tx_retry_result {
5787         cmdline_fixed_string_t set;
5788         cmdline_fixed_string_t burst;
5789         cmdline_fixed_string_t tx;
5790         cmdline_fixed_string_t delay;
5791         uint32_t time;
5792         cmdline_fixed_string_t retry;
5793         uint32_t retry_num;
5794 };
5795
5796 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5797                                         __attribute__((unused)) struct cmdline *cl,
5798                                         __attribute__((unused)) void *data)
5799 {
5800         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5801
5802         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5803                 && !strcmp(res->tx, "tx")) {
5804                 if (!strcmp(res->delay, "delay"))
5805                         burst_tx_delay_time = res->time;
5806                 if (!strcmp(res->retry, "retry"))
5807                         burst_tx_retry_num = res->retry_num;
5808         }
5809
5810 }
5811
5812 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5813         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5814 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5815         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5816                                  "burst");
5817 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5818         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5819 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5820         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5821 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5822         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5823 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5824         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5825 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5826         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5827
5828 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5829         .f = cmd_set_burst_tx_retry_parsed,
5830         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5831         .tokens = {
5832                 (void *)&cmd_set_burst_tx_retry_set,
5833                 (void *)&cmd_set_burst_tx_retry_burst,
5834                 (void *)&cmd_set_burst_tx_retry_tx,
5835                 (void *)&cmd_set_burst_tx_retry_delay,
5836                 (void *)&cmd_set_burst_tx_retry_time,
5837                 (void *)&cmd_set_burst_tx_retry_retry,
5838                 (void *)&cmd_set_burst_tx_retry_retry_num,
5839                 NULL,
5840         },
5841 };
5842
5843 /* *** SET PROMISC MODE *** */
5844 struct cmd_set_promisc_mode_result {
5845         cmdline_fixed_string_t set;
5846         cmdline_fixed_string_t promisc;
5847         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5848         uint16_t port_num;               /* valid if "allports" argument == 0 */
5849         cmdline_fixed_string_t mode;
5850 };
5851
5852 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5853                                         __attribute__((unused)) struct cmdline *cl,
5854                                         void *allports)
5855 {
5856         struct cmd_set_promisc_mode_result *res = parsed_result;
5857         int enable;
5858         portid_t i;
5859
5860         if (!strcmp(res->mode, "on"))
5861                 enable = 1;
5862         else
5863                 enable = 0;
5864
5865         /* all ports */
5866         if (allports) {
5867                 RTE_ETH_FOREACH_DEV(i) {
5868                         if (enable)
5869                                 rte_eth_promiscuous_enable(i);
5870                         else
5871                                 rte_eth_promiscuous_disable(i);
5872                 }
5873         }
5874         else {
5875                 if (enable)
5876                         rte_eth_promiscuous_enable(res->port_num);
5877                 else
5878                         rte_eth_promiscuous_disable(res->port_num);
5879         }
5880 }
5881
5882 cmdline_parse_token_string_t cmd_setpromisc_set =
5883         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5884 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5885         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5886                                  "promisc");
5887 cmdline_parse_token_string_t cmd_setpromisc_portall =
5888         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5889                                  "all");
5890 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5891         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5892                               UINT16);
5893 cmdline_parse_token_string_t cmd_setpromisc_mode =
5894         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5895                                  "on#off");
5896
5897 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5898         .f = cmd_set_promisc_mode_parsed,
5899         .data = (void *)1,
5900         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5901         .tokens = {
5902                 (void *)&cmd_setpromisc_set,
5903                 (void *)&cmd_setpromisc_promisc,
5904                 (void *)&cmd_setpromisc_portall,
5905                 (void *)&cmd_setpromisc_mode,
5906                 NULL,
5907         },
5908 };
5909
5910 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5911         .f = cmd_set_promisc_mode_parsed,
5912         .data = (void *)0,
5913         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5914         .tokens = {
5915                 (void *)&cmd_setpromisc_set,
5916                 (void *)&cmd_setpromisc_promisc,
5917                 (void *)&cmd_setpromisc_portnum,
5918                 (void *)&cmd_setpromisc_mode,
5919                 NULL,
5920         },
5921 };
5922
5923 /* *** SET ALLMULTI MODE *** */
5924 struct cmd_set_allmulti_mode_result {
5925         cmdline_fixed_string_t set;
5926         cmdline_fixed_string_t allmulti;
5927         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5928         uint16_t port_num;               /* valid if "allports" argument == 0 */
5929         cmdline_fixed_string_t mode;
5930 };
5931
5932 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5933                                         __attribute__((unused)) struct cmdline *cl,
5934                                         void *allports)
5935 {
5936         struct cmd_set_allmulti_mode_result *res = parsed_result;
5937         int enable;
5938         portid_t i;
5939
5940         if (!strcmp(res->mode, "on"))
5941                 enable = 1;
5942         else
5943                 enable = 0;
5944
5945         /* all ports */
5946         if (allports) {
5947                 RTE_ETH_FOREACH_DEV(i) {
5948                         if (enable)
5949                                 rte_eth_allmulticast_enable(i);
5950                         else
5951                                 rte_eth_allmulticast_disable(i);
5952                 }
5953         }
5954         else {
5955                 if (enable)
5956                         rte_eth_allmulticast_enable(res->port_num);
5957                 else
5958                         rte_eth_allmulticast_disable(res->port_num);
5959         }
5960 }
5961
5962 cmdline_parse_token_string_t cmd_setallmulti_set =
5963         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5964 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5965         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5966                                  "allmulti");
5967 cmdline_parse_token_string_t cmd_setallmulti_portall =
5968         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5969                                  "all");
5970 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5971         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5972                               UINT16);
5973 cmdline_parse_token_string_t cmd_setallmulti_mode =
5974         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5975                                  "on#off");
5976
5977 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5978         .f = cmd_set_allmulti_mode_parsed,
5979         .data = (void *)1,
5980         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5981         .tokens = {
5982                 (void *)&cmd_setallmulti_set,
5983                 (void *)&cmd_setallmulti_allmulti,
5984                 (void *)&cmd_setallmulti_portall,
5985                 (void *)&cmd_setallmulti_mode,
5986                 NULL,
5987         },
5988 };
5989
5990 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5991         .f = cmd_set_allmulti_mode_parsed,
5992         .data = (void *)0,
5993         .help_str = "set allmulti <port_id> on|off: "
5994                 "Set allmulti mode on port_id",
5995         .tokens = {
5996                 (void *)&cmd_setallmulti_set,
5997                 (void *)&cmd_setallmulti_allmulti,
5998                 (void *)&cmd_setallmulti_portnum,
5999                 (void *)&cmd_setallmulti_mode,
6000                 NULL,
6001         },
6002 };
6003
6004 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6005 struct cmd_link_flow_ctrl_set_result {
6006         cmdline_fixed_string_t set;
6007         cmdline_fixed_string_t flow_ctrl;
6008         cmdline_fixed_string_t rx;
6009         cmdline_fixed_string_t rx_lfc_mode;
6010         cmdline_fixed_string_t tx;
6011         cmdline_fixed_string_t tx_lfc_mode;
6012         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6013         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6014         cmdline_fixed_string_t autoneg_str;
6015         cmdline_fixed_string_t autoneg;
6016         cmdline_fixed_string_t hw_str;
6017         uint32_t high_water;
6018         cmdline_fixed_string_t lw_str;
6019         uint32_t low_water;
6020         cmdline_fixed_string_t pt_str;
6021         uint16_t pause_time;
6022         cmdline_fixed_string_t xon_str;
6023         uint16_t send_xon;
6024         portid_t port_id;
6025 };
6026
6027 cmdline_parse_token_string_t cmd_lfc_set_set =
6028         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6029                                 set, "set");
6030 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6031         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6032                                 flow_ctrl, "flow_ctrl");
6033 cmdline_parse_token_string_t cmd_lfc_set_rx =
6034         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6035                                 rx, "rx");
6036 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6037         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6038                                 rx_lfc_mode, "on#off");
6039 cmdline_parse_token_string_t cmd_lfc_set_tx =
6040         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6041                                 tx, "tx");
6042 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6043         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6044                                 tx_lfc_mode, "on#off");
6045 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6046         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6047                                 hw_str, "high_water");
6048 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6049         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6050                                 high_water, UINT32);
6051 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6052         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6053                                 lw_str, "low_water");
6054 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6055         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6056                                 low_water, UINT32);
6057 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6058         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6059                                 pt_str, "pause_time");
6060 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6061         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6062                                 pause_time, UINT16);
6063 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6064         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6065                                 xon_str, "send_xon");
6066 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6067         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6068                                 send_xon, UINT16);
6069 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6070         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6071                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6072 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6073         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6074                                 mac_ctrl_frame_fwd_mode, "on#off");
6075 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6076         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6077                                 autoneg_str, "autoneg");
6078 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6079         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6080                                 autoneg, "on#off");
6081 cmdline_parse_token_num_t cmd_lfc_set_portid =
6082         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6083                                 port_id, UINT16);
6084
6085 /* forward declaration */
6086 static void
6087 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6088                               void *data);
6089
6090 cmdline_parse_inst_t cmd_link_flow_control_set = {
6091         .f = cmd_link_flow_ctrl_set_parsed,
6092         .data = NULL,
6093         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6094                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6095                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6096         .tokens = {
6097                 (void *)&cmd_lfc_set_set,
6098                 (void *)&cmd_lfc_set_flow_ctrl,
6099                 (void *)&cmd_lfc_set_rx,
6100                 (void *)&cmd_lfc_set_rx_mode,
6101                 (void *)&cmd_lfc_set_tx,
6102                 (void *)&cmd_lfc_set_tx_mode,
6103                 (void *)&cmd_lfc_set_high_water,
6104                 (void *)&cmd_lfc_set_low_water,
6105                 (void *)&cmd_lfc_set_pause_time,
6106                 (void *)&cmd_lfc_set_send_xon,
6107                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6108                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6109                 (void *)&cmd_lfc_set_autoneg_str,
6110                 (void *)&cmd_lfc_set_autoneg,
6111                 (void *)&cmd_lfc_set_portid,
6112                 NULL,
6113         },
6114 };
6115
6116 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6117         .f = cmd_link_flow_ctrl_set_parsed,
6118         .data = (void *)&cmd_link_flow_control_set_rx,
6119         .help_str = "set flow_ctrl rx on|off <port_id>: "
6120                 "Change rx flow control parameter",
6121         .tokens = {
6122                 (void *)&cmd_lfc_set_set,
6123                 (void *)&cmd_lfc_set_flow_ctrl,
6124                 (void *)&cmd_lfc_set_rx,
6125                 (void *)&cmd_lfc_set_rx_mode,
6126                 (void *)&cmd_lfc_set_portid,
6127                 NULL,
6128         },
6129 };
6130
6131 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6132         .f = cmd_link_flow_ctrl_set_parsed,
6133         .data = (void *)&cmd_link_flow_control_set_tx,
6134         .help_str = "set flow_ctrl tx on|off <port_id>: "
6135                 "Change tx flow control parameter",
6136         .tokens = {
6137                 (void *)&cmd_lfc_set_set,
6138                 (void *)&cmd_lfc_set_flow_ctrl,
6139                 (void *)&cmd_lfc_set_tx,
6140                 (void *)&cmd_lfc_set_tx_mode,
6141                 (void *)&cmd_lfc_set_portid,
6142                 NULL,
6143         },
6144 };
6145
6146 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6147         .f = cmd_link_flow_ctrl_set_parsed,
6148         .data = (void *)&cmd_link_flow_control_set_hw,
6149         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6150                 "Change high water flow control parameter",
6151         .tokens = {
6152                 (void *)&cmd_lfc_set_set,
6153                 (void *)&cmd_lfc_set_flow_ctrl,
6154                 (void *)&cmd_lfc_set_high_water_str,
6155                 (void *)&cmd_lfc_set_high_water,
6156                 (void *)&cmd_lfc_set_portid,
6157                 NULL,
6158         },
6159 };
6160
6161 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6162         .f = cmd_link_flow_ctrl_set_parsed,
6163         .data = (void *)&cmd_link_flow_control_set_lw,
6164         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6165                 "Change low water flow control parameter",
6166         .tokens = {
6167                 (void *)&cmd_lfc_set_set,
6168                 (void *)&cmd_lfc_set_flow_ctrl,
6169                 (void *)&cmd_lfc_set_low_water_str,
6170                 (void *)&cmd_lfc_set_low_water,
6171                 (void *)&cmd_lfc_set_portid,
6172                 NULL,
6173         },
6174 };
6175
6176 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6177         .f = cmd_link_flow_ctrl_set_parsed,
6178         .data = (void *)&cmd_link_flow_control_set_pt,
6179         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6180                 "Change pause time flow control parameter",
6181         .tokens = {
6182                 (void *)&cmd_lfc_set_set,
6183                 (void *)&cmd_lfc_set_flow_ctrl,
6184                 (void *)&cmd_lfc_set_pause_time_str,
6185                 (void *)&cmd_lfc_set_pause_time,
6186                 (void *)&cmd_lfc_set_portid,
6187                 NULL,
6188         },
6189 };
6190
6191 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6192         .f = cmd_link_flow_ctrl_set_parsed,
6193         .data = (void *)&cmd_link_flow_control_set_xon,
6194         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6195                 "Change send_xon flow control parameter",
6196         .tokens = {
6197                 (void *)&cmd_lfc_set_set,
6198                 (void *)&cmd_lfc_set_flow_ctrl,
6199                 (void *)&cmd_lfc_set_send_xon_str,
6200                 (void *)&cmd_lfc_set_send_xon,
6201                 (void *)&cmd_lfc_set_portid,
6202                 NULL,
6203         },
6204 };
6205
6206 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6207         .f = cmd_link_flow_ctrl_set_parsed,
6208         .data = (void *)&cmd_link_flow_control_set_macfwd,
6209         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6210                 "Change mac ctrl fwd flow control parameter",
6211         .tokens = {
6212                 (void *)&cmd_lfc_set_set,
6213                 (void *)&cmd_lfc_set_flow_ctrl,
6214                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6215                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6216                 (void *)&cmd_lfc_set_portid,
6217                 NULL,
6218         },
6219 };
6220
6221 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6222         .f = cmd_link_flow_ctrl_set_parsed,
6223         .data = (void *)&cmd_link_flow_control_set_autoneg,
6224         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6225                 "Change autoneg flow control parameter",
6226         .tokens = {
6227                 (void *)&cmd_lfc_set_set,
6228                 (void *)&cmd_lfc_set_flow_ctrl,
6229                 (void *)&cmd_lfc_set_autoneg_str,
6230                 (void *)&cmd_lfc_set_autoneg,
6231                 (void *)&cmd_lfc_set_portid,
6232                 NULL,
6233         },
6234 };
6235
6236 static void
6237 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6238                               __attribute__((unused)) struct cmdline *cl,
6239                               void *data)
6240 {
6241         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6242         cmdline_parse_inst_t *cmd = data;
6243         struct rte_eth_fc_conf fc_conf;
6244         int rx_fc_en = 0;
6245         int tx_fc_en = 0;
6246         int ret;
6247
6248         /*
6249          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6250          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6251          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6252          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6253          */
6254         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6255                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6256         };
6257
6258         /* Partial command line, retrieve current configuration */
6259         if (cmd) {
6260                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6261                 if (ret != 0) {
6262                         printf("cannot get current flow ctrl parameters, return"
6263                                "code = %d\n", ret);
6264                         return;
6265                 }
6266
6267                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6268                     (fc_conf.mode == RTE_FC_FULL))
6269                         rx_fc_en = 1;
6270                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6271                     (fc_conf.mode == RTE_FC_FULL))
6272                         tx_fc_en = 1;
6273         }
6274
6275         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6276                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6277
6278         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6279                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6280
6281         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6282
6283         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6284                 fc_conf.high_water = res->high_water;
6285
6286         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6287                 fc_conf.low_water = res->low_water;
6288
6289         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6290                 fc_conf.pause_time = res->pause_time;
6291
6292         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6293                 fc_conf.send_xon = res->send_xon;
6294
6295         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6296                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6297                         fc_conf.mac_ctrl_frame_fwd = 1;
6298                 else
6299                         fc_conf.mac_ctrl_frame_fwd = 0;
6300         }
6301
6302         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6303                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6304
6305         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6306         if (ret != 0)
6307                 printf("bad flow contrl parameter, return code = %d \n", ret);
6308 }
6309
6310 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6311 struct cmd_priority_flow_ctrl_set_result {
6312         cmdline_fixed_string_t set;
6313         cmdline_fixed_string_t pfc_ctrl;
6314         cmdline_fixed_string_t rx;
6315         cmdline_fixed_string_t rx_pfc_mode;
6316         cmdline_fixed_string_t tx;
6317         cmdline_fixed_string_t tx_pfc_mode;
6318         uint32_t high_water;
6319         uint32_t low_water;
6320         uint16_t pause_time;
6321         uint8_t  priority;
6322         portid_t port_id;
6323 };
6324
6325 static void
6326 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6327                        __attribute__((unused)) struct cmdline *cl,
6328                        __attribute__((unused)) void *data)
6329 {
6330         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6331         struct rte_eth_pfc_conf pfc_conf;
6332         int rx_fc_enable, tx_fc_enable;
6333         int ret;
6334
6335         /*
6336          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6337          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6338          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6339          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6340          */
6341         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6342                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6343         };
6344
6345         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6346         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6347         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6348         pfc_conf.fc.high_water = res->high_water;
6349         pfc_conf.fc.low_water  = res->low_water;
6350         pfc_conf.fc.pause_time = res->pause_time;
6351         pfc_conf.priority      = res->priority;
6352
6353         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6354         if (ret != 0)
6355                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6356 }
6357
6358 cmdline_parse_token_string_t cmd_pfc_set_set =
6359         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6360                                 set, "set");
6361 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6362         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6363                                 pfc_ctrl, "pfc_ctrl");
6364 cmdline_parse_token_string_t cmd_pfc_set_rx =
6365         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6366                                 rx, "rx");
6367 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6368         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6369                                 rx_pfc_mode, "on#off");
6370 cmdline_parse_token_string_t cmd_pfc_set_tx =
6371         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6372                                 tx, "tx");
6373 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6374         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6375                                 tx_pfc_mode, "on#off");
6376 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6377         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6378                                 high_water, UINT32);
6379 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6380         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6381                                 low_water, UINT32);
6382 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6383         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6384                                 pause_time, UINT16);
6385 cmdline_parse_token_num_t cmd_pfc_set_priority =
6386         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6387                                 priority, UINT8);
6388 cmdline_parse_token_num_t cmd_pfc_set_portid =
6389         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6390                                 port_id, UINT16);
6391
6392 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6393         .f = cmd_priority_flow_ctrl_set_parsed,
6394         .data = NULL,
6395         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6396                 "<pause_time> <priority> <port_id>: "
6397                 "Configure the Ethernet priority flow control",
6398         .tokens = {
6399                 (void *)&cmd_pfc_set_set,
6400                 (void *)&cmd_pfc_set_flow_ctrl,
6401                 (void *)&cmd_pfc_set_rx,
6402                 (void *)&cmd_pfc_set_rx_mode,
6403                 (void *)&cmd_pfc_set_tx,
6404                 (void *)&cmd_pfc_set_tx_mode,
6405                 (void *)&cmd_pfc_set_high_water,
6406                 (void *)&cmd_pfc_set_low_water,
6407                 (void *)&cmd_pfc_set_pause_time,
6408                 (void *)&cmd_pfc_set_priority,
6409                 (void *)&cmd_pfc_set_portid,
6410                 NULL,
6411         },
6412 };
6413
6414 /* *** RESET CONFIGURATION *** */
6415 struct cmd_reset_result {
6416         cmdline_fixed_string_t reset;
6417         cmdline_fixed_string_t def;
6418 };
6419
6420 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6421                              struct cmdline *cl,
6422                              __attribute__((unused)) void *data)
6423 {
6424         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6425         set_def_fwd_config();
6426 }
6427
6428 cmdline_parse_token_string_t cmd_reset_set =
6429         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6430 cmdline_parse_token_string_t cmd_reset_def =
6431         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6432                                  "default");
6433
6434 cmdline_parse_inst_t cmd_reset = {
6435         .f = cmd_reset_parsed,
6436         .data = NULL,
6437         .help_str = "set default: Reset default forwarding configuration",
6438         .tokens = {
6439                 (void *)&cmd_reset_set,
6440                 (void *)&cmd_reset_def,
6441                 NULL,
6442         },
6443 };
6444
6445 /* *** START FORWARDING *** */
6446 struct cmd_start_result {
6447         cmdline_fixed_string_t start;
6448 };
6449
6450 cmdline_parse_token_string_t cmd_start_start =
6451         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6452
6453 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6454                              __attribute__((unused)) struct cmdline *cl,
6455                              __attribute__((unused)) void *data)
6456 {
6457         start_packet_forwarding(0);
6458 }
6459
6460 cmdline_parse_inst_t cmd_start = {
6461         .f = cmd_start_parsed,
6462         .data = NULL,
6463         .help_str = "start: Start packet forwarding",
6464         .tokens = {
6465                 (void *)&cmd_start_start,
6466                 NULL,
6467         },
6468 };
6469
6470 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6471 struct cmd_start_tx_first_result {
6472         cmdline_fixed_string_t start;
6473         cmdline_fixed_string_t tx_first;
6474 };
6475
6476 static void
6477 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6478                           __attribute__((unused)) struct cmdline *cl,
6479                           __attribute__((unused)) void *data)
6480 {
6481         start_packet_forwarding(1);
6482 }
6483
6484 cmdline_parse_token_string_t cmd_start_tx_first_start =
6485         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6486                                  "start");
6487 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6488         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6489                                  tx_first, "tx_first");
6490
6491 cmdline_parse_inst_t cmd_start_tx_first = {
6492         .f = cmd_start_tx_first_parsed,
6493         .data = NULL,
6494         .help_str = "start tx_first: Start packet forwarding, "
6495                 "after sending 1 burst of packets",
6496         .tokens = {
6497                 (void *)&cmd_start_tx_first_start,
6498                 (void *)&cmd_start_tx_first_tx_first,
6499                 NULL,
6500         },
6501 };
6502
6503 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6504 struct cmd_start_tx_first_n_result {
6505         cmdline_fixed_string_t start;
6506         cmdline_fixed_string_t tx_first;
6507         uint32_t tx_num;
6508 };
6509
6510 static void
6511 cmd_start_tx_first_n_parsed(void *parsed_result,
6512                           __attribute__((unused)) struct cmdline *cl,
6513                           __attribute__((unused)) void *data)
6514 {
6515         struct cmd_start_tx_first_n_result *res = parsed_result;
6516
6517         start_packet_forwarding(res->tx_num);
6518 }
6519
6520 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6521         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6522                         start, "start");
6523 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6524         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6525                         tx_first, "tx_first");
6526 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6527         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6528                         tx_num, UINT32);
6529
6530 cmdline_parse_inst_t cmd_start_tx_first_n = {
6531         .f = cmd_start_tx_first_n_parsed,
6532         .data = NULL,
6533         .help_str = "start tx_first <num>: "
6534                 "packet forwarding, after sending <num> bursts of packets",
6535         .tokens = {
6536                 (void *)&cmd_start_tx_first_n_start,
6537                 (void *)&cmd_start_tx_first_n_tx_first,
6538                 (void *)&cmd_start_tx_first_n_tx_num,
6539                 NULL,
6540         },
6541 };
6542
6543 /* *** SET LINK UP *** */
6544 struct cmd_set_link_up_result {
6545         cmdline_fixed_string_t set;
6546         cmdline_fixed_string_t link_up;
6547         cmdline_fixed_string_t port;
6548         portid_t port_id;
6549 };
6550
6551 cmdline_parse_token_string_t cmd_set_link_up_set =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6553 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6554         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6555                                 "link-up");
6556 cmdline_parse_token_string_t cmd_set_link_up_port =
6557         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6558 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6559         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6560
6561 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6562                              __attribute__((unused)) struct cmdline *cl,
6563                              __attribute__((unused)) void *data)
6564 {
6565         struct cmd_set_link_up_result *res = parsed_result;
6566         dev_set_link_up(res->port_id);
6567 }
6568
6569 cmdline_parse_inst_t cmd_set_link_up = {
6570         .f = cmd_set_link_up_parsed,
6571         .data = NULL,
6572         .help_str = "set link-up port <port id>",
6573         .tokens = {
6574                 (void *)&cmd_set_link_up_set,
6575                 (void *)&cmd_set_link_up_link_up,
6576                 (void *)&cmd_set_link_up_port,
6577                 (void *)&cmd_set_link_up_port_id,
6578                 NULL,
6579         },
6580 };
6581
6582 /* *** SET LINK DOWN *** */
6583 struct cmd_set_link_down_result {
6584         cmdline_fixed_string_t set;
6585         cmdline_fixed_string_t link_down;
6586         cmdline_fixed_string_t port;
6587         portid_t port_id;
6588 };
6589
6590 cmdline_parse_token_string_t cmd_set_link_down_set =
6591         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6592 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6593         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6594                                 "link-down");
6595 cmdline_parse_token_string_t cmd_set_link_down_port =
6596         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6597 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6598         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6599
6600 static void cmd_set_link_down_parsed(
6601                                 __attribute__((unused)) void *parsed_result,
6602                                 __attribute__((unused)) struct cmdline *cl,
6603                                 __attribute__((unused)) void *data)
6604 {
6605         struct cmd_set_link_down_result *res = parsed_result;
6606         dev_set_link_down(res->port_id);
6607 }
6608
6609 cmdline_parse_inst_t cmd_set_link_down = {
6610         .f = cmd_set_link_down_parsed,
6611         .data = NULL,
6612         .help_str = "set link-down port <port id>",
6613         .tokens = {
6614                 (void *)&cmd_set_link_down_set,
6615                 (void *)&cmd_set_link_down_link_down,
6616                 (void *)&cmd_set_link_down_port,
6617                 (void *)&cmd_set_link_down_port_id,
6618                 NULL,
6619         },
6620 };
6621
6622 /* *** SHOW CFG *** */
6623 struct cmd_showcfg_result {
6624         cmdline_fixed_string_t show;
6625         cmdline_fixed_string_t cfg;
6626         cmdline_fixed_string_t what;
6627 };
6628
6629 static void cmd_showcfg_parsed(void *parsed_result,
6630                                __attribute__((unused)) struct cmdline *cl,
6631                                __attribute__((unused)) void *data)
6632 {
6633         struct cmd_showcfg_result *res = parsed_result;
6634         if (!strcmp(res->what, "rxtx"))
6635                 rxtx_config_display();
6636         else if (!strcmp(res->what, "cores"))
6637                 fwd_lcores_config_display();
6638         else if (!strcmp(res->what, "fwd"))
6639                 pkt_fwd_config_display(&cur_fwd_config);
6640         else if (!strcmp(res->what, "txpkts"))
6641                 show_tx_pkt_segments();
6642 }
6643
6644 cmdline_parse_token_string_t cmd_showcfg_show =
6645         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6646 cmdline_parse_token_string_t cmd_showcfg_port =
6647         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6648 cmdline_parse_token_string_t cmd_showcfg_what =
6649         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6650                                  "rxtx#cores#fwd#txpkts");
6651
6652 cmdline_parse_inst_t cmd_showcfg = {
6653         .f = cmd_showcfg_parsed,
6654         .data = NULL,
6655         .help_str = "show config rxtx|cores|fwd|txpkts",
6656         .tokens = {
6657                 (void *)&cmd_showcfg_show,
6658                 (void *)&cmd_showcfg_port,
6659                 (void *)&cmd_showcfg_what,
6660                 NULL,
6661         },
6662 };
6663
6664 /* *** SHOW ALL PORT INFO *** */
6665 struct cmd_showportall_result {
6666         cmdline_fixed_string_t show;
6667         cmdline_fixed_string_t port;
6668         cmdline_fixed_string_t what;
6669         cmdline_fixed_string_t all;
6670 };
6671
6672 static void cmd_showportall_parsed(void *parsed_result,
6673                                 __attribute__((unused)) struct cmdline *cl,
6674                                 __attribute__((unused)) void *data)
6675 {
6676         portid_t i;
6677
6678         struct cmd_showportall_result *res = parsed_result;
6679         if (!strcmp(res->show, "clear")) {
6680                 if (!strcmp(res->what, "stats"))
6681                         RTE_ETH_FOREACH_DEV(i)
6682                                 nic_stats_clear(i);
6683                 else if (!strcmp(res->what, "xstats"))
6684                         RTE_ETH_FOREACH_DEV(i)
6685                                 nic_xstats_clear(i);
6686         } else if (!strcmp(res->what, "info"))
6687                 RTE_ETH_FOREACH_DEV(i)
6688                         port_infos_display(i);
6689         else if (!strcmp(res->what, "stats"))
6690                 RTE_ETH_FOREACH_DEV(i)
6691                         nic_stats_display(i);
6692         else if (!strcmp(res->what, "xstats"))
6693                 RTE_ETH_FOREACH_DEV(i)
6694                         nic_xstats_display(i);
6695         else if (!strcmp(res->what, "fdir"))
6696                 RTE_ETH_FOREACH_DEV(i)
6697                         fdir_get_infos(i);
6698         else if (!strcmp(res->what, "stat_qmap"))
6699                 RTE_ETH_FOREACH_DEV(i)
6700                         nic_stats_mapping_display(i);
6701         else if (!strcmp(res->what, "dcb_tc"))
6702                 RTE_ETH_FOREACH_DEV(i)
6703                         port_dcb_info_display(i);
6704         else if (!strcmp(res->what, "cap"))
6705                 RTE_ETH_FOREACH_DEV(i)
6706                         port_offload_cap_display(i);
6707 }
6708
6709 cmdline_parse_token_string_t cmd_showportall_show =
6710         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6711                                  "show#clear");
6712 cmdline_parse_token_string_t cmd_showportall_port =
6713         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6714 cmdline_parse_token_string_t cmd_showportall_what =
6715         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6716                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6717 cmdline_parse_token_string_t cmd_showportall_all =
6718         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6719 cmdline_parse_inst_t cmd_showportall = {
6720         .f = cmd_showportall_parsed,
6721         .data = NULL,
6722         .help_str = "show|clear port "
6723                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6724         .tokens = {
6725                 (void *)&cmd_showportall_show,
6726                 (void *)&cmd_showportall_port,
6727                 (void *)&cmd_showportall_what,
6728                 (void *)&cmd_showportall_all,
6729                 NULL,
6730         },
6731 };
6732
6733 /* *** SHOW PORT INFO *** */
6734 struct cmd_showport_result {
6735         cmdline_fixed_string_t show;
6736         cmdline_fixed_string_t port;
6737         cmdline_fixed_string_t what;
6738         uint16_t portnum;
6739 };
6740
6741 static void cmd_showport_parsed(void *parsed_result,
6742                                 __attribute__((unused)) struct cmdline *cl,
6743                                 __attribute__((unused)) void *data)
6744 {
6745         struct cmd_showport_result *res = parsed_result;
6746         if (!strcmp(res->show, "clear")) {
6747                 if (!strcmp(res->what, "stats"))
6748                         nic_stats_clear(res->portnum);
6749                 else if (!strcmp(res->what, "xstats"))
6750                         nic_xstats_clear(res->portnum);
6751         } else if (!strcmp(res->what, "info"))
6752                 port_infos_display(res->portnum);
6753         else if (!strcmp(res->what, "stats"))
6754                 nic_stats_display(res->portnum);
6755         else if (!strcmp(res->what, "xstats"))
6756                 nic_xstats_display(res->portnum);
6757         else if (!strcmp(res->what, "fdir"))
6758                  fdir_get_infos(res->portnum);
6759         else if (!strcmp(res->what, "stat_qmap"))
6760                 nic_stats_mapping_display(res->portnum);
6761         else if (!strcmp(res->what, "dcb_tc"))
6762                 port_dcb_info_display(res->portnum);
6763         else if (!strcmp(res->what, "cap"))
6764                 port_offload_cap_display(res->portnum);
6765 }
6766
6767 cmdline_parse_token_string_t cmd_showport_show =
6768         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6769                                  "show#clear");
6770 cmdline_parse_token_string_t cmd_showport_port =
6771         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6772 cmdline_parse_token_string_t cmd_showport_what =
6773         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6774                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6775 cmdline_parse_token_num_t cmd_showport_portnum =
6776         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6777
6778 cmdline_parse_inst_t cmd_showport = {
6779         .f = cmd_showport_parsed,
6780         .data = NULL,
6781         .help_str = "show|clear port "
6782                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6783                 "<port_id>",
6784         .tokens = {
6785                 (void *)&cmd_showport_show,
6786                 (void *)&cmd_showport_port,
6787                 (void *)&cmd_showport_what,
6788                 (void *)&cmd_showport_portnum,
6789                 NULL,
6790         },
6791 };
6792
6793 /* *** SHOW QUEUE INFO *** */
6794 struct cmd_showqueue_result {
6795         cmdline_fixed_string_t show;
6796         cmdline_fixed_string_t type;
6797         cmdline_fixed_string_t what;
6798         uint16_t portnum;
6799         uint16_t queuenum;
6800 };
6801
6802 static void
6803 cmd_showqueue_parsed(void *parsed_result,
6804         __attribute__((unused)) struct cmdline *cl,
6805         __attribute__((unused)) void *data)
6806 {
6807         struct cmd_showqueue_result *res = parsed_result;
6808
6809         if (!strcmp(res->type, "rxq"))
6810                 rx_queue_infos_display(res->portnum, res->queuenum);
6811         else if (!strcmp(res->type, "txq"))
6812                 tx_queue_infos_display(res->portnum, res->queuenum);
6813 }
6814
6815 cmdline_parse_token_string_t cmd_showqueue_show =
6816         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6817 cmdline_parse_token_string_t cmd_showqueue_type =
6818         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6819 cmdline_parse_token_string_t cmd_showqueue_what =
6820         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6821 cmdline_parse_token_num_t cmd_showqueue_portnum =
6822         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6823 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6824         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6825
6826 cmdline_parse_inst_t cmd_showqueue = {
6827         .f = cmd_showqueue_parsed,
6828         .data = NULL,
6829         .help_str = "show rxq|txq info <port_id> <queue_id>",
6830         .tokens = {
6831                 (void *)&cmd_showqueue_show,
6832                 (void *)&cmd_showqueue_type,
6833                 (void *)&cmd_showqueue_what,
6834                 (void *)&cmd_showqueue_portnum,
6835                 (void *)&cmd_showqueue_queuenum,
6836                 NULL,
6837         },
6838 };
6839
6840 /* *** READ PORT REGISTER *** */
6841 struct cmd_read_reg_result {
6842         cmdline_fixed_string_t read;
6843         cmdline_fixed_string_t reg;
6844         portid_t port_id;
6845         uint32_t reg_off;
6846 };
6847
6848 static void
6849 cmd_read_reg_parsed(void *parsed_result,
6850                     __attribute__((unused)) struct cmdline *cl,
6851                     __attribute__((unused)) void *data)
6852 {
6853         struct cmd_read_reg_result *res = parsed_result;
6854         port_reg_display(res->port_id, res->reg_off);
6855 }
6856
6857 cmdline_parse_token_string_t cmd_read_reg_read =
6858         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6859 cmdline_parse_token_string_t cmd_read_reg_reg =
6860         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6861 cmdline_parse_token_num_t cmd_read_reg_port_id =
6862         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6863 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6864         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6865
6866 cmdline_parse_inst_t cmd_read_reg = {
6867         .f = cmd_read_reg_parsed,
6868         .data = NULL,
6869         .help_str = "read reg <port_id> <reg_off>",
6870         .tokens = {
6871                 (void *)&cmd_read_reg_read,
6872                 (void *)&cmd_read_reg_reg,
6873                 (void *)&cmd_read_reg_port_id,
6874                 (void *)&cmd_read_reg_reg_off,
6875                 NULL,
6876         },
6877 };
6878
6879 /* *** READ PORT REGISTER BIT FIELD *** */
6880 struct cmd_read_reg_bit_field_result {
6881         cmdline_fixed_string_t read;
6882         cmdline_fixed_string_t regfield;
6883         portid_t port_id;
6884         uint32_t reg_off;
6885         uint8_t bit1_pos;
6886         uint8_t bit2_pos;
6887 };
6888
6889 static void
6890 cmd_read_reg_bit_field_parsed(void *parsed_result,
6891                               __attribute__((unused)) struct cmdline *cl,
6892                               __attribute__((unused)) void *data)
6893 {
6894         struct cmd_read_reg_bit_field_result *res = parsed_result;
6895         port_reg_bit_field_display(res->port_id, res->reg_off,
6896                                    res->bit1_pos, res->bit2_pos);
6897 }
6898
6899 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6900         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6901                                  "read");
6902 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6903         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6904                                  regfield, "regfield");
6905 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6906         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6907                               UINT16);
6908 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6909         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6910                               UINT32);
6911 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6912         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6913                               UINT8);
6914 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6915         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6916                               UINT8);
6917
6918 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6919         .f = cmd_read_reg_bit_field_parsed,
6920         .data = NULL,
6921         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6922         "Read register bit field between bit_x and bit_y included",
6923         .tokens = {
6924                 (void *)&cmd_read_reg_bit_field_read,
6925                 (void *)&cmd_read_reg_bit_field_regfield,
6926                 (void *)&cmd_read_reg_bit_field_port_id,
6927                 (void *)&cmd_read_reg_bit_field_reg_off,
6928                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6929                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6930                 NULL,
6931         },
6932 };
6933
6934 /* *** READ PORT REGISTER BIT *** */
6935 struct cmd_read_reg_bit_result {
6936         cmdline_fixed_string_t read;
6937         cmdline_fixed_string_t regbit;
6938         portid_t port_id;
6939         uint32_t reg_off;
6940         uint8_t bit_pos;
6941 };
6942
6943 static void
6944 cmd_read_reg_bit_parsed(void *parsed_result,
6945                         __attribute__((unused)) struct cmdline *cl,
6946                         __attribute__((unused)) void *data)
6947 {
6948         struct cmd_read_reg_bit_result *res = parsed_result;
6949         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6950 }
6951
6952 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6953         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6954 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6955         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6956                                  regbit, "regbit");
6957 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6958         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6959 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6960         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6961 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6962         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6963
6964 cmdline_parse_inst_t cmd_read_reg_bit = {
6965         .f = cmd_read_reg_bit_parsed,
6966         .data = NULL,
6967         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6968         .tokens = {
6969                 (void *)&cmd_read_reg_bit_read,
6970                 (void *)&cmd_read_reg_bit_regbit,
6971                 (void *)&cmd_read_reg_bit_port_id,
6972                 (void *)&cmd_read_reg_bit_reg_off,
6973                 (void *)&cmd_read_reg_bit_bit_pos,
6974                 NULL,
6975         },
6976 };
6977
6978 /* *** WRITE PORT REGISTER *** */
6979 struct cmd_write_reg_result {
6980         cmdline_fixed_string_t write;
6981         cmdline_fixed_string_t reg;
6982         portid_t port_id;
6983         uint32_t reg_off;
6984         uint32_t value;
6985 };
6986
6987 static void
6988 cmd_write_reg_parsed(void *parsed_result,
6989                      __attribute__((unused)) struct cmdline *cl,
6990                      __attribute__((unused)) void *data)
6991 {
6992         struct cmd_write_reg_result *res = parsed_result;
6993         port_reg_set(res->port_id, res->reg_off, res->value);
6994 }
6995
6996 cmdline_parse_token_string_t cmd_write_reg_write =
6997         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6998 cmdline_parse_token_string_t cmd_write_reg_reg =
6999         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7000 cmdline_parse_token_num_t cmd_write_reg_port_id =
7001         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7002 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7003         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7004 cmdline_parse_token_num_t cmd_write_reg_value =
7005         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7006
7007 cmdline_parse_inst_t cmd_write_reg = {
7008         .f = cmd_write_reg_parsed,
7009         .data = NULL,
7010         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7011         .tokens = {
7012                 (void *)&cmd_write_reg_write,
7013                 (void *)&cmd_write_reg_reg,
7014                 (void *)&cmd_write_reg_port_id,
7015                 (void *)&cmd_write_reg_reg_off,
7016                 (void *)&cmd_write_reg_value,
7017                 NULL,
7018         },
7019 };
7020
7021 /* *** WRITE PORT REGISTER BIT FIELD *** */
7022 struct cmd_write_reg_bit_field_result {
7023         cmdline_fixed_string_t write;
7024         cmdline_fixed_string_t regfield;
7025         portid_t port_id;
7026         uint32_t reg_off;
7027         uint8_t bit1_pos;
7028         uint8_t bit2_pos;
7029         uint32_t value;
7030 };
7031
7032 static void
7033 cmd_write_reg_bit_field_parsed(void *parsed_result,
7034                                __attribute__((unused)) struct cmdline *cl,
7035                                __attribute__((unused)) void *data)
7036 {
7037         struct cmd_write_reg_bit_field_result *res = parsed_result;
7038         port_reg_bit_field_set(res->port_id, res->reg_off,
7039                           res->bit1_pos, res->bit2_pos, res->value);
7040 }
7041
7042 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7043         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7044                                  "write");
7045 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7046         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7047                                  regfield, "regfield");
7048 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7049         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7050                               UINT16);
7051 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7052         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7053                               UINT32);
7054 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7055         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7056                               UINT8);
7057 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7059                               UINT8);
7060 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7062                               UINT32);
7063
7064 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7065         .f = cmd_write_reg_bit_field_parsed,
7066         .data = NULL,
7067         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7068                 "<reg_value>: "
7069                 "Set register bit field between bit_x and bit_y included",
7070         .tokens = {
7071                 (void *)&cmd_write_reg_bit_field_write,
7072                 (void *)&cmd_write_reg_bit_field_regfield,
7073                 (void *)&cmd_write_reg_bit_field_port_id,
7074                 (void *)&cmd_write_reg_bit_field_reg_off,
7075                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7076                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7077                 (void *)&cmd_write_reg_bit_field_value,
7078                 NULL,
7079         },
7080 };
7081
7082 /* *** WRITE PORT REGISTER BIT *** */
7083 struct cmd_write_reg_bit_result {
7084         cmdline_fixed_string_t write;
7085         cmdline_fixed_string_t regbit;
7086         portid_t port_id;
7087         uint32_t reg_off;
7088         uint8_t bit_pos;
7089         uint8_t value;
7090 };
7091
7092 static void
7093 cmd_write_reg_bit_parsed(void *parsed_result,
7094                          __attribute__((unused)) struct cmdline *cl,
7095                          __attribute__((unused)) void *data)
7096 {
7097         struct cmd_write_reg_bit_result *res = parsed_result;
7098         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7099 }
7100
7101 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7102         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7103                                  "write");
7104 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7105         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7106                                  regbit, "regbit");
7107 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7108         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7109 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7110         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7111 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7112         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7113 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7114         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7115
7116 cmdline_parse_inst_t cmd_write_reg_bit = {
7117         .f = cmd_write_reg_bit_parsed,
7118         .data = NULL,
7119         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7120                 "0 <= bit_x <= 31",
7121         .tokens = {
7122                 (void *)&cmd_write_reg_bit_write,
7123                 (void *)&cmd_write_reg_bit_regbit,
7124                 (void *)&cmd_write_reg_bit_port_id,
7125                 (void *)&cmd_write_reg_bit_reg_off,
7126                 (void *)&cmd_write_reg_bit_bit_pos,
7127                 (void *)&cmd_write_reg_bit_value,
7128                 NULL,
7129         },
7130 };
7131
7132 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7133 struct cmd_read_rxd_txd_result {
7134         cmdline_fixed_string_t read;
7135         cmdline_fixed_string_t rxd_txd;
7136         portid_t port_id;
7137         uint16_t queue_id;
7138         uint16_t desc_id;
7139 };
7140
7141 static void
7142 cmd_read_rxd_txd_parsed(void *parsed_result,
7143                         __attribute__((unused)) struct cmdline *cl,
7144                         __attribute__((unused)) void *data)
7145 {
7146         struct cmd_read_rxd_txd_result *res = parsed_result;
7147
7148         if (!strcmp(res->rxd_txd, "rxd"))
7149                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7150         else if (!strcmp(res->rxd_txd, "txd"))
7151                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7152 }
7153
7154 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7155         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7156 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7157         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7158                                  "rxd#txd");
7159 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7160         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7161 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7162         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7163 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7164         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7165
7166 cmdline_parse_inst_t cmd_read_rxd_txd = {
7167         .f = cmd_read_rxd_txd_parsed,
7168         .data = NULL,
7169         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7170         .tokens = {
7171                 (void *)&cmd_read_rxd_txd_read,
7172                 (void *)&cmd_read_rxd_txd_rxd_txd,
7173                 (void *)&cmd_read_rxd_txd_port_id,
7174                 (void *)&cmd_read_rxd_txd_queue_id,
7175                 (void *)&cmd_read_rxd_txd_desc_id,
7176                 NULL,
7177         },
7178 };
7179
7180 /* *** QUIT *** */
7181 struct cmd_quit_result {
7182         cmdline_fixed_string_t quit;
7183 };
7184
7185 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7186                             struct cmdline *cl,
7187                             __attribute__((unused)) void *data)
7188 {
7189         pmd_test_exit();
7190         cmdline_quit(cl);
7191 }
7192
7193 cmdline_parse_token_string_t cmd_quit_quit =
7194         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7195
7196 cmdline_parse_inst_t cmd_quit = {
7197         .f = cmd_quit_parsed,
7198         .data = NULL,
7199         .help_str = "quit: Exit application",
7200         .tokens = {
7201                 (void *)&cmd_quit_quit,
7202                 NULL,
7203         },
7204 };
7205
7206 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7207 struct cmd_mac_addr_result {
7208         cmdline_fixed_string_t mac_addr_cmd;
7209         cmdline_fixed_string_t what;
7210         uint16_t port_num;
7211         struct ether_addr address;
7212 };
7213
7214 static void cmd_mac_addr_parsed(void *parsed_result,
7215                 __attribute__((unused)) struct cmdline *cl,
7216                 __attribute__((unused)) void *data)
7217 {
7218         struct cmd_mac_addr_result *res = parsed_result;
7219         int ret;
7220
7221         if (strcmp(res->what, "add") == 0)
7222                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7223         else if (strcmp(res->what, "set") == 0)
7224                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7225                                                        &res->address);
7226         else
7227                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7228
7229         /* check the return value and print it if is < 0 */
7230         if(ret < 0)
7231                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7232
7233 }
7234
7235 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7236         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7237                                 "mac_addr");
7238 cmdline_parse_token_string_t cmd_mac_addr_what =
7239         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7240                                 "add#remove#set");
7241 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7242                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7243                                         UINT16);
7244 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7245                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7246
7247 cmdline_parse_inst_t cmd_mac_addr = {
7248         .f = cmd_mac_addr_parsed,
7249         .data = (void *)0,
7250         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7251                         "Add/Remove/Set MAC address on port_id",
7252         .tokens = {
7253                 (void *)&cmd_mac_addr_cmd,
7254                 (void *)&cmd_mac_addr_what,
7255                 (void *)&cmd_mac_addr_portnum,
7256                 (void *)&cmd_mac_addr_addr,
7257                 NULL,
7258         },
7259 };
7260
7261 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7262 struct cmd_eth_peer_result {
7263         cmdline_fixed_string_t set;
7264         cmdline_fixed_string_t eth_peer;
7265         portid_t port_id;
7266         cmdline_fixed_string_t peer_addr;
7267 };
7268
7269 static void cmd_set_eth_peer_parsed(void *parsed_result,
7270                         __attribute__((unused)) struct cmdline *cl,
7271                         __attribute__((unused)) void *data)
7272 {
7273                 struct cmd_eth_peer_result *res = parsed_result;
7274
7275                 if (test_done == 0) {
7276                         printf("Please stop forwarding first\n");
7277                         return;
7278                 }
7279                 if (!strcmp(res->eth_peer, "eth-peer")) {
7280                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7281                         fwd_config_setup();
7282                 }
7283 }
7284 cmdline_parse_token_string_t cmd_eth_peer_set =
7285         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7286 cmdline_parse_token_string_t cmd_eth_peer =
7287         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7288 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7289         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7290 cmdline_parse_token_string_t cmd_eth_peer_addr =
7291         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7292
7293 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7294         .f = cmd_set_eth_peer_parsed,
7295         .data = NULL,
7296         .help_str = "set eth-peer <port_id> <peer_mac>",
7297         .tokens = {
7298                 (void *)&cmd_eth_peer_set,
7299                 (void *)&cmd_eth_peer,
7300                 (void *)&cmd_eth_peer_port_id,
7301                 (void *)&cmd_eth_peer_addr,
7302                 NULL,
7303         },
7304 };
7305
7306 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7307 struct cmd_set_qmap_result {
7308         cmdline_fixed_string_t set;
7309         cmdline_fixed_string_t qmap;
7310         cmdline_fixed_string_t what;
7311         portid_t port_id;
7312         uint16_t queue_id;
7313         uint8_t map_value;
7314 };
7315
7316 static void
7317 cmd_set_qmap_parsed(void *parsed_result,
7318                        __attribute__((unused)) struct cmdline *cl,
7319                        __attribute__((unused)) void *data)
7320 {
7321         struct cmd_set_qmap_result *res = parsed_result;
7322         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7323
7324         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7325 }
7326
7327 cmdline_parse_token_string_t cmd_setqmap_set =
7328         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7329                                  set, "set");
7330 cmdline_parse_token_string_t cmd_setqmap_qmap =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7332                                  qmap, "stat_qmap");
7333 cmdline_parse_token_string_t cmd_setqmap_what =
7334         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7335                                  what, "tx#rx");
7336 cmdline_parse_token_num_t cmd_setqmap_portid =
7337         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7338                               port_id, UINT16);
7339 cmdline_parse_token_num_t cmd_setqmap_queueid =
7340         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7341                               queue_id, UINT16);
7342 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7343         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7344                               map_value, UINT8);
7345
7346 cmdline_parse_inst_t cmd_set_qmap = {
7347         .f = cmd_set_qmap_parsed,
7348         .data = NULL,
7349         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7350                 "Set statistics mapping value on tx|rx queue_id of port_id",
7351         .tokens = {
7352                 (void *)&cmd_setqmap_set,
7353                 (void *)&cmd_setqmap_qmap,
7354                 (void *)&cmd_setqmap_what,
7355                 (void *)&cmd_setqmap_portid,
7356                 (void *)&cmd_setqmap_queueid,
7357                 (void *)&cmd_setqmap_mapvalue,
7358                 NULL,
7359         },
7360 };
7361
7362 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7363 struct cmd_set_xstats_hide_zero_result {
7364         cmdline_fixed_string_t keyword;
7365         cmdline_fixed_string_t name;
7366         cmdline_fixed_string_t on_off;
7367 };
7368
7369 static void
7370 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7371                         __attribute__((unused)) struct cmdline *cl,
7372                         __attribute__((unused)) void *data)
7373 {
7374         struct cmd_set_xstats_hide_zero_result *res;
7375         uint16_t on_off = 0;
7376
7377         res = parsed_result;
7378         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7379         set_xstats_hide_zero(on_off);
7380 }
7381
7382 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7383         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7384                                  keyword, "set");
7385 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7386         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7387                                  name, "xstats-hide-zero");
7388 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7389         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7390                                  on_off, "on#off");
7391
7392 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7393         .f = cmd_set_xstats_hide_zero_parsed,
7394         .data = NULL,
7395         .help_str = "set xstats-hide-zero on|off",
7396         .tokens = {
7397                 (void *)&cmd_set_xstats_hide_zero_keyword,
7398                 (void *)&cmd_set_xstats_hide_zero_name,
7399                 (void *)&cmd_set_xstats_hide_zero_on_off,
7400                 NULL,
7401         },
7402 };
7403
7404 /* *** CONFIGURE UNICAST HASH TABLE *** */
7405 struct cmd_set_uc_hash_table {
7406         cmdline_fixed_string_t set;
7407         cmdline_fixed_string_t port;
7408         portid_t port_id;
7409         cmdline_fixed_string_t what;
7410         struct ether_addr address;
7411         cmdline_fixed_string_t mode;
7412 };
7413
7414 static void
7415 cmd_set_uc_hash_parsed(void *parsed_result,
7416                        __attribute__((unused)) struct cmdline *cl,
7417                        __attribute__((unused)) void *data)
7418 {
7419         int ret=0;
7420         struct cmd_set_uc_hash_table *res = parsed_result;
7421
7422         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7423
7424         if (strcmp(res->what, "uta") == 0)
7425                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7426                                                 &res->address,(uint8_t)is_on);
7427         if (ret < 0)
7428                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7429
7430 }
7431
7432 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7433         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7434                                  set, "set");
7435 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7437                                  port, "port");
7438 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7439         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7440                               port_id, UINT16);
7441 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7443                                  what, "uta");
7444 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7445         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7446                                 address);
7447 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7448         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7449                                  mode, "on#off");
7450
7451 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7452         .f = cmd_set_uc_hash_parsed,
7453         .data = NULL,
7454         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7455         .tokens = {
7456                 (void *)&cmd_set_uc_hash_set,
7457                 (void *)&cmd_set_uc_hash_port,
7458                 (void *)&cmd_set_uc_hash_portid,
7459                 (void *)&cmd_set_uc_hash_what,
7460                 (void *)&cmd_set_uc_hash_mac,
7461                 (void *)&cmd_set_uc_hash_mode,
7462                 NULL,
7463         },
7464 };
7465
7466 struct cmd_set_uc_all_hash_table {
7467         cmdline_fixed_string_t set;
7468         cmdline_fixed_string_t port;
7469         portid_t port_id;
7470         cmdline_fixed_string_t what;
7471         cmdline_fixed_string_t value;
7472         cmdline_fixed_string_t mode;
7473 };
7474
7475 static void
7476 cmd_set_uc_all_hash_parsed(void *parsed_result,
7477                        __attribute__((unused)) struct cmdline *cl,
7478                        __attribute__((unused)) void *data)
7479 {
7480         int ret=0;
7481         struct cmd_set_uc_all_hash_table *res = parsed_result;
7482
7483         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7484
7485         if ((strcmp(res->what, "uta") == 0) &&
7486                 (strcmp(res->value, "all") == 0))
7487                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7488         if (ret < 0)
7489                 printf("bad unicast hash table parameter,"
7490                         "return code = %d \n", ret);
7491 }
7492
7493 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7494         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7495                                  set, "set");
7496 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7497         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7498                                  port, "port");
7499 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7500         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7501                               port_id, UINT16);
7502 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7503         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7504                                  what, "uta");
7505 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7506         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7507                                 value,"all");
7508 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7509         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7510                                  mode, "on#off");
7511
7512 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7513         .f = cmd_set_uc_all_hash_parsed,
7514         .data = NULL,
7515         .help_str = "set port <port_id> uta all on|off",
7516         .tokens = {
7517                 (void *)&cmd_set_uc_all_hash_set,
7518                 (void *)&cmd_set_uc_all_hash_port,
7519                 (void *)&cmd_set_uc_all_hash_portid,
7520                 (void *)&cmd_set_uc_all_hash_what,
7521                 (void *)&cmd_set_uc_all_hash_value,
7522                 (void *)&cmd_set_uc_all_hash_mode,
7523                 NULL,
7524         },
7525 };
7526
7527 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7528 struct cmd_set_vf_macvlan_filter {
7529         cmdline_fixed_string_t set;
7530         cmdline_fixed_string_t port;
7531         portid_t port_id;
7532         cmdline_fixed_string_t vf;
7533         uint8_t vf_id;
7534         struct ether_addr address;
7535         cmdline_fixed_string_t filter_type;
7536         cmdline_fixed_string_t mode;
7537 };
7538
7539 static void
7540 cmd_set_vf_macvlan_parsed(void *parsed_result,
7541                        __attribute__((unused)) struct cmdline *cl,
7542                        __attribute__((unused)) void *data)
7543 {
7544         int is_on, ret = 0;
7545         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7546         struct rte_eth_mac_filter filter;
7547
7548         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7549
7550         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7551
7552         /* set VF MAC filter */
7553         filter.is_vf = 1;
7554
7555         /* set VF ID */
7556         filter.dst_id = res->vf_id;
7557
7558         if (!strcmp(res->filter_type, "exact-mac"))
7559                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7560         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7561                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7562         else if (!strcmp(res->filter_type, "hashmac"))
7563                 filter.filter_type = RTE_MAC_HASH_MATCH;
7564         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7565                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7566
7567         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7568
7569         if (is_on)
7570                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7571                                         RTE_ETH_FILTER_MACVLAN,
7572                                         RTE_ETH_FILTER_ADD,
7573                                          &filter);
7574         else
7575                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7576                                         RTE_ETH_FILTER_MACVLAN,
7577                                         RTE_ETH_FILTER_DELETE,
7578                                         &filter);
7579
7580         if (ret < 0)
7581                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7582
7583 }
7584
7585 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7586         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7587                                  set, "set");
7588 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7589         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7590                                  port, "port");
7591 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7592         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7593                               port_id, UINT16);
7594 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7595         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7596                                  vf, "vf");
7597 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7598         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7599                                 vf_id, UINT8);
7600 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7601         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7602                                 address);
7603 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7604         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7605                                 filter_type, "exact-mac#exact-mac-vlan"
7606                                 "#hashmac#hashmac-vlan");
7607 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7608         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7609                                  mode, "on#off");
7610
7611 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7612         .f = cmd_set_vf_macvlan_parsed,
7613         .data = NULL,
7614         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7615                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7616                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7617                 "hash match rule: hash match of MAC and exact match of VLAN",
7618         .tokens = {
7619                 (void *)&cmd_set_vf_macvlan_set,
7620                 (void *)&cmd_set_vf_macvlan_port,
7621                 (void *)&cmd_set_vf_macvlan_portid,
7622                 (void *)&cmd_set_vf_macvlan_vf,
7623                 (void *)&cmd_set_vf_macvlan_vf_id,
7624                 (void *)&cmd_set_vf_macvlan_mac,
7625                 (void *)&cmd_set_vf_macvlan_filter_type,
7626                 (void *)&cmd_set_vf_macvlan_mode,
7627                 NULL,
7628         },
7629 };
7630
7631 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7632 struct cmd_set_vf_traffic {
7633         cmdline_fixed_string_t set;
7634         cmdline_fixed_string_t port;
7635         portid_t port_id;
7636         cmdline_fixed_string_t vf;
7637         uint8_t vf_id;
7638         cmdline_fixed_string_t what;
7639         cmdline_fixed_string_t mode;
7640 };
7641
7642 static void
7643 cmd_set_vf_traffic_parsed(void *parsed_result,
7644                        __attribute__((unused)) struct cmdline *cl,
7645                        __attribute__((unused)) void *data)
7646 {
7647         struct cmd_set_vf_traffic *res = parsed_result;
7648         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7649         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7650
7651         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7652 }
7653
7654 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7655         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7656                                  set, "set");
7657 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7658         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7659                                  port, "port");
7660 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7661         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7662                               port_id, UINT16);
7663 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7664         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7665                                  vf, "vf");
7666 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7667         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7668                               vf_id, UINT8);
7669 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7670         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7671                                  what, "tx#rx");
7672 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7673         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7674                                  mode, "on#off");
7675
7676 cmdline_parse_inst_t cmd_set_vf_traffic = {
7677         .f = cmd_set_vf_traffic_parsed,
7678         .data = NULL,
7679         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7680         .tokens = {
7681                 (void *)&cmd_setvf_traffic_set,
7682                 (void *)&cmd_setvf_traffic_port,
7683                 (void *)&cmd_setvf_traffic_portid,
7684                 (void *)&cmd_setvf_traffic_vf,
7685                 (void *)&cmd_setvf_traffic_vfid,
7686                 (void *)&cmd_setvf_traffic_what,
7687                 (void *)&cmd_setvf_traffic_mode,
7688                 NULL,
7689         },
7690 };
7691
7692 /* *** CONFIGURE VF RECEIVE MODE *** */
7693 struct cmd_set_vf_rxmode {
7694         cmdline_fixed_string_t set;
7695         cmdline_fixed_string_t port;
7696         portid_t port_id;
7697         cmdline_fixed_string_t vf;
7698         uint8_t vf_id;
7699         cmdline_fixed_string_t what;
7700         cmdline_fixed_string_t mode;
7701         cmdline_fixed_string_t on;
7702 };
7703
7704 static void
7705 cmd_set_vf_rxmode_parsed(void *parsed_result,
7706                        __attribute__((unused)) struct cmdline *cl,
7707                        __attribute__((unused)) void *data)
7708 {
7709         int ret = -ENOTSUP;
7710         uint16_t rx_mode = 0;
7711         struct cmd_set_vf_rxmode *res = parsed_result;
7712
7713         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7714         if (!strcmp(res->what,"rxmode")) {
7715                 if (!strcmp(res->mode, "AUPE"))
7716                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7717                 else if (!strcmp(res->mode, "ROPE"))
7718                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7719                 else if (!strcmp(res->mode, "BAM"))
7720                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7721                 else if (!strncmp(res->mode, "MPE",3))
7722                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7723         }
7724
7725         RTE_SET_USED(is_on);
7726
7727 #ifdef RTE_LIBRTE_IXGBE_PMD
7728         if (ret == -ENOTSUP)
7729                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7730                                                   rx_mode, (uint8_t)is_on);
7731 #endif
7732 #ifdef RTE_LIBRTE_BNXT_PMD
7733         if (ret == -ENOTSUP)
7734                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7735                                                  rx_mode, (uint8_t)is_on);
7736 #endif
7737         if (ret < 0)
7738                 printf("bad VF receive mode parameter, return code = %d \n",
7739                 ret);
7740 }
7741
7742 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7743         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7744                                  set, "set");
7745 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7746         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7747                                  port, "port");
7748 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7749         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7750                               port_id, UINT16);
7751 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7752         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7753                                  vf, "vf");
7754 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7755         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7756                               vf_id, UINT8);
7757 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7758         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7759                                  what, "rxmode");
7760 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7761         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7762                                  mode, "AUPE#ROPE#BAM#MPE");
7763 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7764         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7765                                  on, "on#off");
7766
7767 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7768         .f = cmd_set_vf_rxmode_parsed,
7769         .data = NULL,
7770         .help_str = "set port <port_id> vf <vf_id> rxmode "
7771                 "AUPE|ROPE|BAM|MPE on|off",
7772         .tokens = {
7773                 (void *)&cmd_set_vf_rxmode_set,
7774                 (void *)&cmd_set_vf_rxmode_port,
7775                 (void *)&cmd_set_vf_rxmode_portid,
7776                 (void *)&cmd_set_vf_rxmode_vf,
7777                 (void *)&cmd_set_vf_rxmode_vfid,
7778                 (void *)&cmd_set_vf_rxmode_what,
7779                 (void *)&cmd_set_vf_rxmode_mode,
7780                 (void *)&cmd_set_vf_rxmode_on,
7781                 NULL,
7782         },
7783 };
7784
7785 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7786 struct cmd_vf_mac_addr_result {
7787         cmdline_fixed_string_t mac_addr_cmd;
7788         cmdline_fixed_string_t what;
7789         cmdline_fixed_string_t port;
7790         uint16_t port_num;
7791         cmdline_fixed_string_t vf;
7792         uint8_t vf_num;
7793         struct ether_addr address;
7794 };
7795
7796 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7797                 __attribute__((unused)) struct cmdline *cl,
7798                 __attribute__((unused)) void *data)
7799 {
7800         struct cmd_vf_mac_addr_result *res = parsed_result;
7801         int ret = -ENOTSUP;
7802
7803         if (strcmp(res->what, "add") != 0)
7804                 return;
7805
7806 #ifdef RTE_LIBRTE_I40E_PMD
7807         if (ret == -ENOTSUP)
7808                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7809                                                    &res->address);
7810 #endif
7811 #ifdef RTE_LIBRTE_BNXT_PMD
7812         if (ret == -ENOTSUP)
7813                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7814                                                 res->vf_num);
7815 #endif
7816
7817         if(ret < 0)
7818                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7819
7820 }
7821
7822 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7823         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7824                                 mac_addr_cmd,"mac_addr");
7825 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7826         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7827                                 what,"add");
7828 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7829         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7830                                 port,"port");
7831 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7832         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7833                                 port_num, UINT16);
7834 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7835         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7836                                 vf,"vf");
7837 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7838         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7839                                 vf_num, UINT8);
7840 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7841         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7842                                 address);
7843
7844 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7845         .f = cmd_vf_mac_addr_parsed,
7846         .data = (void *)0,
7847         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7848                 "Add MAC address filtering for a VF on port_id",
7849         .tokens = {
7850                 (void *)&cmd_vf_mac_addr_cmd,
7851                 (void *)&cmd_vf_mac_addr_what,
7852                 (void *)&cmd_vf_mac_addr_port,
7853                 (void *)&cmd_vf_mac_addr_portnum,
7854                 (void *)&cmd_vf_mac_addr_vf,
7855                 (void *)&cmd_vf_mac_addr_vfnum,
7856                 (void *)&cmd_vf_mac_addr_addr,
7857                 NULL,
7858         },
7859 };
7860
7861 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7862 struct cmd_vf_rx_vlan_filter {
7863         cmdline_fixed_string_t rx_vlan;
7864         cmdline_fixed_string_t what;
7865         uint16_t vlan_id;
7866         cmdline_fixed_string_t port;
7867         portid_t port_id;
7868         cmdline_fixed_string_t vf;
7869         uint64_t vf_mask;
7870 };
7871
7872 static void
7873 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7874                           __attribute__((unused)) struct cmdline *cl,
7875                           __attribute__((unused)) void *data)
7876 {
7877         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7878         int ret = -ENOTSUP;
7879
7880         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7881
7882 #ifdef RTE_LIBRTE_IXGBE_PMD
7883         if (ret == -ENOTSUP)
7884                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7885                                 res->vlan_id, res->vf_mask, is_add);
7886 #endif
7887 #ifdef RTE_LIBRTE_I40E_PMD
7888         if (ret == -ENOTSUP)
7889                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7890                                 res->vlan_id, res->vf_mask, is_add);
7891 #endif
7892 #ifdef RTE_LIBRTE_BNXT_PMD
7893         if (ret == -ENOTSUP)
7894                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7895                                 res->vlan_id, res->vf_mask, is_add);
7896 #endif
7897
7898         switch (ret) {
7899         case 0:
7900                 break;
7901         case -EINVAL:
7902                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7903                                 res->vlan_id, res->vf_mask);
7904                 break;
7905         case -ENODEV:
7906                 printf("invalid port_id %d\n", res->port_id);
7907                 break;
7908         case -ENOTSUP:
7909                 printf("function not implemented or supported\n");
7910                 break;
7911         default:
7912                 printf("programming error: (%s)\n", strerror(-ret));
7913         }
7914 }
7915
7916 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7917         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7918                                  rx_vlan, "rx_vlan");
7919 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7920         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7921                                  what, "add#rm");
7922 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7923         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7924                               vlan_id, UINT16);
7925 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7926         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7927                                  port, "port");
7928 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7929         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7930                               port_id, UINT16);
7931 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7932         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7933                                  vf, "vf");
7934 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7935         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7936                               vf_mask, UINT64);
7937
7938 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7939         .f = cmd_vf_rx_vlan_filter_parsed,
7940         .data = NULL,
7941         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7942                 "(vf_mask = hexadecimal VF mask)",
7943         .tokens = {
7944                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7945                 (void *)&cmd_vf_rx_vlan_filter_what,
7946                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7947                 (void *)&cmd_vf_rx_vlan_filter_port,
7948                 (void *)&cmd_vf_rx_vlan_filter_portid,
7949                 (void *)&cmd_vf_rx_vlan_filter_vf,
7950                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7951                 NULL,
7952         },
7953 };
7954
7955 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7956 struct cmd_queue_rate_limit_result {
7957         cmdline_fixed_string_t set;
7958         cmdline_fixed_string_t port;
7959         uint16_t port_num;
7960         cmdline_fixed_string_t queue;
7961         uint8_t queue_num;
7962         cmdline_fixed_string_t rate;
7963         uint16_t rate_num;
7964 };
7965
7966 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7967                 __attribute__((unused)) struct cmdline *cl,
7968                 __attribute__((unused)) void *data)
7969 {
7970         struct cmd_queue_rate_limit_result *res = parsed_result;
7971         int ret = 0;
7972
7973         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7974                 && (strcmp(res->queue, "queue") == 0)
7975                 && (strcmp(res->rate, "rate") == 0))
7976                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7977                                         res->rate_num);
7978         if (ret < 0)
7979                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7980
7981 }
7982
7983 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7984         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7985                                 set, "set");
7986 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7987         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7988                                 port, "port");
7989 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7990         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7991                                 port_num, UINT16);
7992 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7993         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7994                                 queue, "queue");
7995 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7996         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7997                                 queue_num, UINT8);
7998 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7999         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8000                                 rate, "rate");
8001 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8002         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8003                                 rate_num, UINT16);
8004
8005 cmdline_parse_inst_t cmd_queue_rate_limit = {
8006         .f = cmd_queue_rate_limit_parsed,
8007         .data = (void *)0,
8008         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8009                 "Set rate limit for a queue on port_id",
8010         .tokens = {
8011                 (void *)&cmd_queue_rate_limit_set,
8012                 (void *)&cmd_queue_rate_limit_port,
8013                 (void *)&cmd_queue_rate_limit_portnum,
8014                 (void *)&cmd_queue_rate_limit_queue,
8015                 (void *)&cmd_queue_rate_limit_queuenum,
8016                 (void *)&cmd_queue_rate_limit_rate,
8017                 (void *)&cmd_queue_rate_limit_ratenum,
8018                 NULL,
8019         },
8020 };
8021
8022 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8023 struct cmd_vf_rate_limit_result {
8024         cmdline_fixed_string_t set;
8025         cmdline_fixed_string_t port;
8026         uint16_t port_num;
8027         cmdline_fixed_string_t vf;
8028         uint8_t vf_num;
8029         cmdline_fixed_string_t rate;
8030         uint16_t rate_num;
8031         cmdline_fixed_string_t q_msk;
8032         uint64_t q_msk_val;
8033 };
8034
8035 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8036                 __attribute__((unused)) struct cmdline *cl,
8037                 __attribute__((unused)) void *data)
8038 {
8039         struct cmd_vf_rate_limit_result *res = parsed_result;
8040         int ret = 0;
8041
8042         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8043                 && (strcmp(res->vf, "vf") == 0)
8044                 && (strcmp(res->rate, "rate") == 0)
8045                 && (strcmp(res->q_msk, "queue_mask") == 0))
8046                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8047                                         res->rate_num, res->q_msk_val);
8048         if (ret < 0)
8049                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8050
8051 }
8052
8053 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8054         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8055                                 set, "set");
8056 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8057         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8058                                 port, "port");
8059 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8060         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8061                                 port_num, UINT16);
8062 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8063         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8064                                 vf, "vf");
8065 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8066         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8067                                 vf_num, UINT8);
8068 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8069         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8070                                 rate, "rate");
8071 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8072         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8073                                 rate_num, UINT16);
8074 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8075         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8076                                 q_msk, "queue_mask");
8077 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8078         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8079                                 q_msk_val, UINT64);
8080
8081 cmdline_parse_inst_t cmd_vf_rate_limit = {
8082         .f = cmd_vf_rate_limit_parsed,
8083         .data = (void *)0,
8084         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8085                 "queue_mask <queue_mask_value>: "
8086                 "Set rate limit for queues of VF on port_id",
8087         .tokens = {
8088                 (void *)&cmd_vf_rate_limit_set,
8089                 (void *)&cmd_vf_rate_limit_port,
8090                 (void *)&cmd_vf_rate_limit_portnum,
8091                 (void *)&cmd_vf_rate_limit_vf,
8092                 (void *)&cmd_vf_rate_limit_vfnum,
8093                 (void *)&cmd_vf_rate_limit_rate,
8094                 (void *)&cmd_vf_rate_limit_ratenum,
8095                 (void *)&cmd_vf_rate_limit_q_msk,
8096                 (void *)&cmd_vf_rate_limit_q_msk_val,
8097                 NULL,
8098         },
8099 };
8100
8101 /* *** ADD TUNNEL FILTER OF A PORT *** */
8102 struct cmd_tunnel_filter_result {
8103         cmdline_fixed_string_t cmd;
8104         cmdline_fixed_string_t what;
8105         portid_t port_id;
8106         struct ether_addr outer_mac;
8107         struct ether_addr inner_mac;
8108         cmdline_ipaddr_t ip_value;
8109         uint16_t inner_vlan;
8110         cmdline_fixed_string_t tunnel_type;
8111         cmdline_fixed_string_t filter_type;
8112         uint32_t tenant_id;
8113         uint16_t queue_num;
8114 };
8115
8116 static void
8117 cmd_tunnel_filter_parsed(void *parsed_result,
8118                           __attribute__((unused)) struct cmdline *cl,
8119                           __attribute__((unused)) void *data)
8120 {
8121         struct cmd_tunnel_filter_result *res = parsed_result;
8122         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8123         int ret = 0;
8124
8125         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8126
8127         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8128         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8129         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8130
8131         if (res->ip_value.family == AF_INET) {
8132                 tunnel_filter_conf.ip_addr.ipv4_addr =
8133                         res->ip_value.addr.ipv4.s_addr;
8134                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8135         } else {
8136                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8137                         &(res->ip_value.addr.ipv6),
8138                         sizeof(struct in6_addr));
8139                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8140         }
8141
8142         if (!strcmp(res->filter_type, "imac-ivlan"))
8143                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8144         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8145                 tunnel_filter_conf.filter_type =
8146                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8147         else if (!strcmp(res->filter_type, "imac-tenid"))
8148                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8149         else if (!strcmp(res->filter_type, "imac"))
8150                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8151         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8152                 tunnel_filter_conf.filter_type =
8153                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8154         else if (!strcmp(res->filter_type, "oip"))
8155                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8156         else if (!strcmp(res->filter_type, "iip"))
8157                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8158         else {
8159                 printf("The filter type is not supported");
8160                 return;
8161         }
8162
8163         if (!strcmp(res->tunnel_type, "vxlan"))
8164                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8165         else if (!strcmp(res->tunnel_type, "nvgre"))
8166                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8167         else if (!strcmp(res->tunnel_type, "ipingre"))
8168                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8169         else {
8170                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8171                 return;
8172         }
8173
8174         tunnel_filter_conf.tenant_id = res->tenant_id;
8175         tunnel_filter_conf.queue_id = res->queue_num;
8176         if (!strcmp(res->what, "add"))
8177                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8178                                         RTE_ETH_FILTER_TUNNEL,
8179                                         RTE_ETH_FILTER_ADD,
8180                                         &tunnel_filter_conf);
8181         else
8182                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8183                                         RTE_ETH_FILTER_TUNNEL,
8184                                         RTE_ETH_FILTER_DELETE,
8185                                         &tunnel_filter_conf);
8186         if (ret < 0)
8187                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8188                                 strerror(-ret));
8189
8190 }
8191 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8192         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8193         cmd, "tunnel_filter");
8194 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8195         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8196         what, "add#rm");
8197 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8198         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8199         port_id, UINT16);
8200 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8201         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8202         outer_mac);
8203 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8204         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8205         inner_mac);
8206 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8207         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8208         inner_vlan, UINT16);
8209 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8210         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8211         ip_value);
8212 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8213         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8214         tunnel_type, "vxlan#nvgre#ipingre");
8215
8216 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8217         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8218         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8219                 "imac#omac-imac-tenid");
8220 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8221         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8222         tenant_id, UINT32);
8223 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8224         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8225         queue_num, UINT16);
8226
8227 cmdline_parse_inst_t cmd_tunnel_filter = {
8228         .f = cmd_tunnel_filter_parsed,
8229         .data = (void *)0,
8230         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8231                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8232                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8233                 "<queue_id>: Add/Rm tunnel filter of a port",
8234         .tokens = {
8235                 (void *)&cmd_tunnel_filter_cmd,
8236                 (void *)&cmd_tunnel_filter_what,
8237                 (void *)&cmd_tunnel_filter_port_id,
8238                 (void *)&cmd_tunnel_filter_outer_mac,
8239                 (void *)&cmd_tunnel_filter_inner_mac,
8240                 (void *)&cmd_tunnel_filter_ip_value,
8241                 (void *)&cmd_tunnel_filter_innner_vlan,
8242                 (void *)&cmd_tunnel_filter_tunnel_type,
8243                 (void *)&cmd_tunnel_filter_filter_type,
8244                 (void *)&cmd_tunnel_filter_tenant_id,
8245                 (void *)&cmd_tunnel_filter_queue_num,
8246                 NULL,
8247         },
8248 };
8249
8250 /* *** CONFIGURE TUNNEL UDP PORT *** */
8251 struct cmd_tunnel_udp_config {
8252         cmdline_fixed_string_t cmd;
8253         cmdline_fixed_string_t what;
8254         uint16_t udp_port;
8255         portid_t port_id;
8256 };
8257
8258 static void
8259 cmd_tunnel_udp_config_parsed(void *parsed_result,
8260                           __attribute__((unused)) struct cmdline *cl,
8261                           __attribute__((unused)) void *data)
8262 {
8263         struct cmd_tunnel_udp_config *res = parsed_result;
8264         struct rte_eth_udp_tunnel tunnel_udp;
8265         int ret;
8266
8267         tunnel_udp.udp_port = res->udp_port;
8268
8269         if (!strcmp(res->cmd, "rx_vxlan_port"))
8270                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8271
8272         if (!strcmp(res->what, "add"))
8273                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8274                                                       &tunnel_udp);
8275         else
8276                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8277                                                          &tunnel_udp);
8278
8279         if (ret < 0)
8280                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8281 }
8282
8283 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8284         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8285                                 cmd, "rx_vxlan_port");
8286 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8287         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8288                                 what, "add#rm");
8289 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8290         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8291                                 udp_port, UINT16);
8292 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8293         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8294                                 port_id, UINT16);
8295
8296 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8297         .f = cmd_tunnel_udp_config_parsed,
8298         .data = (void *)0,
8299         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8300                 "Add/Remove a tunneling UDP port filter",
8301         .tokens = {
8302                 (void *)&cmd_tunnel_udp_config_cmd,
8303                 (void *)&cmd_tunnel_udp_config_what,
8304                 (void *)&cmd_tunnel_udp_config_udp_port,
8305                 (void *)&cmd_tunnel_udp_config_port_id,
8306                 NULL,
8307         },
8308 };
8309
8310 /* *** GLOBAL CONFIG *** */
8311 struct cmd_global_config_result {
8312         cmdline_fixed_string_t cmd;
8313         portid_t port_id;
8314         cmdline_fixed_string_t cfg_type;
8315         uint8_t len;
8316 };
8317
8318 static void
8319 cmd_global_config_parsed(void *parsed_result,
8320                          __attribute__((unused)) struct cmdline *cl,
8321                          __attribute__((unused)) void *data)
8322 {
8323         struct cmd_global_config_result *res = parsed_result;
8324         struct rte_eth_global_cfg conf;
8325         int ret;
8326
8327         memset(&conf, 0, sizeof(conf));
8328         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8329         conf.cfg.gre_key_len = res->len;
8330         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8331                                       RTE_ETH_FILTER_SET, &conf);
8332         if (ret != 0)
8333                 printf("Global config error\n");
8334 }
8335
8336 cmdline_parse_token_string_t cmd_global_config_cmd =
8337         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8338                 "global_config");
8339 cmdline_parse_token_num_t cmd_global_config_port_id =
8340         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8341                                UINT16);
8342 cmdline_parse_token_string_t cmd_global_config_type =
8343         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8344                 cfg_type, "gre-key-len");
8345 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8346         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8347                 len, UINT8);
8348
8349 cmdline_parse_inst_t cmd_global_config = {
8350         .f = cmd_global_config_parsed,
8351         .data = (void *)NULL,
8352         .help_str = "global_config <port_id> gre-key-len <key_len>",
8353         .tokens = {
8354                 (void *)&cmd_global_config_cmd,
8355                 (void *)&cmd_global_config_port_id,
8356                 (void *)&cmd_global_config_type,
8357                 (void *)&cmd_global_config_gre_key_len,
8358                 NULL,
8359         },
8360 };
8361
8362 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8363 struct cmd_set_mirror_mask_result {
8364         cmdline_fixed_string_t set;
8365         cmdline_fixed_string_t port;
8366         portid_t port_id;
8367         cmdline_fixed_string_t mirror;
8368         uint8_t rule_id;
8369         cmdline_fixed_string_t what;
8370         cmdline_fixed_string_t value;
8371         cmdline_fixed_string_t dstpool;
8372         uint8_t dstpool_id;
8373         cmdline_fixed_string_t on;
8374 };
8375
8376 cmdline_parse_token_string_t cmd_mirror_mask_set =
8377         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8378                                 set, "set");
8379 cmdline_parse_token_string_t cmd_mirror_mask_port =
8380         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8381                                 port, "port");
8382 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8383         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8384                                 port_id, UINT16);
8385 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8386         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8387                                 mirror, "mirror-rule");
8388 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8389         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8390                                 rule_id, UINT8);
8391 cmdline_parse_token_string_t cmd_mirror_mask_what =
8392         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8393                                 what, "pool-mirror-up#pool-mirror-down"
8394                                       "#vlan-mirror");
8395 cmdline_parse_token_string_t cmd_mirror_mask_value =
8396         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8397                                 value, NULL);
8398 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8399         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8400                                 dstpool, "dst-pool");
8401 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8402         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8403                                 dstpool_id, UINT8);
8404 cmdline_parse_token_string_t cmd_mirror_mask_on =
8405         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8406                                 on, "on#off");
8407
8408 static void
8409 cmd_set_mirror_mask_parsed(void *parsed_result,
8410                        __attribute__((unused)) struct cmdline *cl,
8411                        __attribute__((unused)) void *data)
8412 {
8413         int ret,nb_item,i;
8414         struct cmd_set_mirror_mask_result *res = parsed_result;
8415         struct rte_eth_mirror_conf mr_conf;
8416
8417         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8418
8419         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8420
8421         mr_conf.dst_pool = res->dstpool_id;
8422
8423         if (!strcmp(res->what, "pool-mirror-up")) {
8424                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8425                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8426         } else if (!strcmp(res->what, "pool-mirror-down")) {
8427                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8428                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8429         } else if (!strcmp(res->what, "vlan-mirror")) {
8430                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8431                 nb_item = parse_item_list(res->value, "vlan",
8432                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8433                 if (nb_item <= 0)
8434                         return;
8435
8436                 for (i = 0; i < nb_item; i++) {
8437                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8438                                 printf("Invalid vlan_id: must be < 4096\n");
8439                                 return;
8440                         }
8441
8442                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8443                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8444                 }
8445         }
8446
8447         if (!strcmp(res->on, "on"))
8448                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8449                                                 res->rule_id, 1);
8450         else
8451                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8452                                                 res->rule_id, 0);
8453         if (ret < 0)
8454                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8455 }
8456
8457 cmdline_parse_inst_t cmd_set_mirror_mask = {
8458                 .f = cmd_set_mirror_mask_parsed,
8459                 .data = NULL,
8460                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8461                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8462                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8463                 .tokens = {
8464                         (void *)&cmd_mirror_mask_set,
8465                         (void *)&cmd_mirror_mask_port,
8466                         (void *)&cmd_mirror_mask_portid,
8467                         (void *)&cmd_mirror_mask_mirror,
8468                         (void *)&cmd_mirror_mask_ruleid,
8469                         (void *)&cmd_mirror_mask_what,
8470                         (void *)&cmd_mirror_mask_value,
8471                         (void *)&cmd_mirror_mask_dstpool,
8472                         (void *)&cmd_mirror_mask_poolid,
8473                         (void *)&cmd_mirror_mask_on,
8474                         NULL,
8475                 },
8476 };
8477
8478 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8479 struct cmd_set_mirror_link_result {
8480         cmdline_fixed_string_t set;
8481         cmdline_fixed_string_t port;
8482         portid_t port_id;
8483         cmdline_fixed_string_t mirror;
8484         uint8_t rule_id;
8485         cmdline_fixed_string_t what;
8486         cmdline_fixed_string_t dstpool;
8487         uint8_t dstpool_id;
8488         cmdline_fixed_string_t on;
8489 };
8490
8491 cmdline_parse_token_string_t cmd_mirror_link_set =
8492         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8493                                  set, "set");
8494 cmdline_parse_token_string_t cmd_mirror_link_port =
8495         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8496                                 port, "port");
8497 cmdline_parse_token_num_t cmd_mirror_link_portid =
8498         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8499                                 port_id, UINT16);
8500 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8501         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8502                                 mirror, "mirror-rule");
8503 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8504         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8505                             rule_id, UINT8);
8506 cmdline_parse_token_string_t cmd_mirror_link_what =
8507         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8508                                 what, "uplink-mirror#downlink-mirror");
8509 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8510         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8511                                 dstpool, "dst-pool");
8512 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8513         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8514                                 dstpool_id, UINT8);
8515 cmdline_parse_token_string_t cmd_mirror_link_on =
8516         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8517                                 on, "on#off");
8518
8519 static void
8520 cmd_set_mirror_link_parsed(void *parsed_result,
8521                        __attribute__((unused)) struct cmdline *cl,
8522                        __attribute__((unused)) void *data)
8523 {
8524         int ret;
8525         struct cmd_set_mirror_link_result *res = parsed_result;
8526         struct rte_eth_mirror_conf mr_conf;
8527
8528         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8529         if (!strcmp(res->what, "uplink-mirror"))
8530                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8531         else
8532                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8533
8534         mr_conf.dst_pool = res->dstpool_id;
8535
8536         if (!strcmp(res->on, "on"))
8537                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8538                                                 res->rule_id, 1);
8539         else
8540                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8541                                                 res->rule_id, 0);
8542
8543         /* check the return value and print it if is < 0 */
8544         if (ret < 0)
8545                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8546
8547 }
8548
8549 cmdline_parse_inst_t cmd_set_mirror_link = {
8550                 .f = cmd_set_mirror_link_parsed,
8551                 .data = NULL,
8552                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8553                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8554                 .tokens = {
8555                         (void *)&cmd_mirror_link_set,
8556                         (void *)&cmd_mirror_link_port,
8557                         (void *)&cmd_mirror_link_portid,
8558                         (void *)&cmd_mirror_link_mirror,
8559                         (void *)&cmd_mirror_link_ruleid,
8560                         (void *)&cmd_mirror_link_what,
8561                         (void *)&cmd_mirror_link_dstpool,
8562                         (void *)&cmd_mirror_link_poolid,
8563                         (void *)&cmd_mirror_link_on,
8564                         NULL,
8565                 },
8566 };
8567
8568 /* *** RESET VM MIRROR RULE *** */
8569 struct cmd_rm_mirror_rule_result {
8570         cmdline_fixed_string_t reset;
8571         cmdline_fixed_string_t port;
8572         portid_t port_id;
8573         cmdline_fixed_string_t mirror;
8574         uint8_t rule_id;
8575 };
8576
8577 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8578         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8579                                  reset, "reset");
8580 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8581         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8582                                 port, "port");
8583 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8584         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8585                                 port_id, UINT16);
8586 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8587         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8588                                 mirror, "mirror-rule");
8589 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8590         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8591                                 rule_id, UINT8);
8592
8593 static void
8594 cmd_reset_mirror_rule_parsed(void *parsed_result,
8595                        __attribute__((unused)) struct cmdline *cl,
8596                        __attribute__((unused)) void *data)
8597 {
8598         int ret;
8599         struct cmd_set_mirror_link_result *res = parsed_result;
8600         /* check rule_id */
8601         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8602         if(ret < 0)
8603                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8604 }
8605
8606 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8607                 .f = cmd_reset_mirror_rule_parsed,
8608                 .data = NULL,
8609                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8610                 .tokens = {
8611                         (void *)&cmd_rm_mirror_rule_reset,
8612                         (void *)&cmd_rm_mirror_rule_port,
8613                         (void *)&cmd_rm_mirror_rule_portid,
8614                         (void *)&cmd_rm_mirror_rule_mirror,
8615                         (void *)&cmd_rm_mirror_rule_ruleid,
8616                         NULL,
8617                 },
8618 };
8619
8620 /* ******************************************************************************** */
8621
8622 struct cmd_dump_result {
8623         cmdline_fixed_string_t dump;
8624 };
8625
8626 static void
8627 dump_struct_sizes(void)
8628 {
8629 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8630         DUMP_SIZE(struct rte_mbuf);
8631         DUMP_SIZE(struct rte_mempool);
8632         DUMP_SIZE(struct rte_ring);
8633 #undef DUMP_SIZE
8634 }
8635
8636 static void cmd_dump_parsed(void *parsed_result,
8637                             __attribute__((unused)) struct cmdline *cl,
8638                             __attribute__((unused)) void *data)
8639 {
8640         struct cmd_dump_result *res = parsed_result;
8641
8642         if (!strcmp(res->dump, "dump_physmem"))
8643                 rte_dump_physmem_layout(stdout);
8644         else if (!strcmp(res->dump, "dump_memzone"))
8645                 rte_memzone_dump(stdout);
8646         else if (!strcmp(res->dump, "dump_struct_sizes"))
8647                 dump_struct_sizes();
8648         else if (!strcmp(res->dump, "dump_ring"))
8649                 rte_ring_list_dump(stdout);
8650         else if (!strcmp(res->dump, "dump_mempool"))
8651                 rte_mempool_list_dump(stdout);
8652         else if (!strcmp(res->dump, "dump_devargs"))
8653                 rte_eal_devargs_dump(stdout);
8654         else if (!strcmp(res->dump, "dump_log_types"))
8655                 rte_log_dump(stdout);
8656 }
8657
8658 cmdline_parse_token_string_t cmd_dump_dump =
8659         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8660                 "dump_physmem#"
8661                 "dump_memzone#"
8662                 "dump_struct_sizes#"
8663                 "dump_ring#"
8664                 "dump_mempool#"
8665                 "dump_devargs#"
8666                 "dump_log_types");
8667
8668 cmdline_parse_inst_t cmd_dump = {
8669         .f = cmd_dump_parsed,  /* function to call */
8670         .data = NULL,      /* 2nd arg of func */
8671         .help_str = "Dump status",
8672         .tokens = {        /* token list, NULL terminated */
8673                 (void *)&cmd_dump_dump,
8674                 NULL,
8675         },
8676 };
8677
8678 /* ******************************************************************************** */
8679
8680 struct cmd_dump_one_result {
8681         cmdline_fixed_string_t dump;
8682         cmdline_fixed_string_t name;
8683 };
8684
8685 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8686                                 __attribute__((unused)) void *data)
8687 {
8688         struct cmd_dump_one_result *res = parsed_result;
8689
8690         if (!strcmp(res->dump, "dump_ring")) {
8691                 struct rte_ring *r;
8692                 r = rte_ring_lookup(res->name);
8693                 if (r == NULL) {
8694                         cmdline_printf(cl, "Cannot find ring\n");
8695                         return;
8696                 }
8697                 rte_ring_dump(stdout, r);
8698         } else if (!strcmp(res->dump, "dump_mempool")) {
8699                 struct rte_mempool *mp;
8700                 mp = rte_mempool_lookup(res->name);
8701                 if (mp == NULL) {
8702                         cmdline_printf(cl, "Cannot find mempool\n");
8703                         return;
8704                 }
8705                 rte_mempool_dump(stdout, mp);
8706         }
8707 }
8708
8709 cmdline_parse_token_string_t cmd_dump_one_dump =
8710         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8711                                  "dump_ring#dump_mempool");
8712
8713 cmdline_parse_token_string_t cmd_dump_one_name =
8714         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8715
8716 cmdline_parse_inst_t cmd_dump_one = {
8717         .f = cmd_dump_one_parsed,  /* function to call */
8718         .data = NULL,      /* 2nd arg of func */
8719         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8720         .tokens = {        /* token list, NULL terminated */
8721                 (void *)&cmd_dump_one_dump,
8722                 (void *)&cmd_dump_one_name,
8723                 NULL,
8724         },
8725 };
8726
8727 /* *** Add/Del syn filter *** */
8728 struct cmd_syn_filter_result {
8729         cmdline_fixed_string_t filter;
8730         portid_t port_id;
8731         cmdline_fixed_string_t ops;
8732         cmdline_fixed_string_t priority;
8733         cmdline_fixed_string_t high;
8734         cmdline_fixed_string_t queue;
8735         uint16_t queue_id;
8736 };
8737
8738 static void
8739 cmd_syn_filter_parsed(void *parsed_result,
8740                         __attribute__((unused)) struct cmdline *cl,
8741                         __attribute__((unused)) void *data)
8742 {
8743         struct cmd_syn_filter_result *res = parsed_result;
8744         struct rte_eth_syn_filter syn_filter;
8745         int ret = 0;
8746
8747         ret = rte_eth_dev_filter_supported(res->port_id,
8748                                         RTE_ETH_FILTER_SYN);
8749         if (ret < 0) {
8750                 printf("syn filter is not supported on port %u.\n",
8751                                 res->port_id);
8752                 return;
8753         }
8754
8755         memset(&syn_filter, 0, sizeof(syn_filter));
8756
8757         if (!strcmp(res->ops, "add")) {
8758                 if (!strcmp(res->high, "high"))
8759                         syn_filter.hig_pri = 1;
8760                 else
8761                         syn_filter.hig_pri = 0;
8762
8763                 syn_filter.queue = res->queue_id;
8764                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8765                                                 RTE_ETH_FILTER_SYN,
8766                                                 RTE_ETH_FILTER_ADD,
8767                                                 &syn_filter);
8768         } else
8769                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8770                                                 RTE_ETH_FILTER_SYN,
8771                                                 RTE_ETH_FILTER_DELETE,
8772                                                 &syn_filter);
8773
8774         if (ret < 0)
8775                 printf("syn filter programming error: (%s)\n",
8776                                 strerror(-ret));
8777 }
8778
8779 cmdline_parse_token_string_t cmd_syn_filter_filter =
8780         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8781         filter, "syn_filter");
8782 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8783         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8784         port_id, UINT16);
8785 cmdline_parse_token_string_t cmd_syn_filter_ops =
8786         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8787         ops, "add#del");
8788 cmdline_parse_token_string_t cmd_syn_filter_priority =
8789         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8790                                 priority, "priority");
8791 cmdline_parse_token_string_t cmd_syn_filter_high =
8792         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8793                                 high, "high#low");
8794 cmdline_parse_token_string_t cmd_syn_filter_queue =
8795         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8796                                 queue, "queue");
8797 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8798         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8799                                 queue_id, UINT16);
8800
8801 cmdline_parse_inst_t cmd_syn_filter = {
8802         .f = cmd_syn_filter_parsed,
8803         .data = NULL,
8804         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8805                 "<queue_id>: Add/Delete syn filter",
8806         .tokens = {
8807                 (void *)&cmd_syn_filter_filter,
8808                 (void *)&cmd_syn_filter_port_id,
8809                 (void *)&cmd_syn_filter_ops,
8810                 (void *)&cmd_syn_filter_priority,
8811                 (void *)&cmd_syn_filter_high,
8812                 (void *)&cmd_syn_filter_queue,
8813                 (void *)&cmd_syn_filter_queue_id,
8814                 NULL,
8815         },
8816 };
8817
8818 /* *** queue region set *** */
8819 struct cmd_queue_region_result {
8820         cmdline_fixed_string_t set;
8821         cmdline_fixed_string_t port;
8822         portid_t port_id;
8823         cmdline_fixed_string_t cmd;
8824         cmdline_fixed_string_t region;
8825         uint8_t  region_id;
8826         cmdline_fixed_string_t queue_start_index;
8827         uint8_t  queue_id;
8828         cmdline_fixed_string_t queue_num;
8829         uint8_t  queue_num_value;
8830 };
8831
8832 static void
8833 cmd_queue_region_parsed(void *parsed_result,
8834                         __attribute__((unused)) struct cmdline *cl,
8835                         __attribute__((unused)) void *data)
8836 {
8837         struct cmd_queue_region_result *res = parsed_result;
8838         int ret = -ENOTSUP;
8839 #ifdef RTE_LIBRTE_I40E_PMD
8840         struct rte_pmd_i40e_queue_region_conf region_conf;
8841         enum rte_pmd_i40e_queue_region_op op_type;
8842 #endif
8843
8844         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8845                 return;
8846
8847 #ifdef RTE_LIBRTE_I40E_PMD
8848         memset(&region_conf, 0, sizeof(region_conf));
8849         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8850         region_conf.region_id = res->region_id;
8851         region_conf.queue_num = res->queue_num_value;
8852         region_conf.queue_start_index = res->queue_id;
8853
8854         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8855                                 op_type, &region_conf);
8856 #endif
8857
8858         switch (ret) {
8859         case 0:
8860                 break;
8861         case -ENOTSUP:
8862                 printf("function not implemented or supported\n");
8863                 break;
8864         default:
8865                 printf("queue region config error: (%s)\n", strerror(-ret));
8866         }
8867 }
8868
8869 cmdline_parse_token_string_t cmd_queue_region_set =
8870 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8871                 set, "set");
8872 cmdline_parse_token_string_t cmd_queue_region_port =
8873         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8874 cmdline_parse_token_num_t cmd_queue_region_port_id =
8875         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8876                                 port_id, UINT16);
8877 cmdline_parse_token_string_t cmd_queue_region_cmd =
8878         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8879                                  cmd, "queue-region");
8880 cmdline_parse_token_string_t cmd_queue_region_id =
8881         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8882                                 region, "region_id");
8883 cmdline_parse_token_num_t cmd_queue_region_index =
8884         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8885                                 region_id, UINT8);
8886 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8887         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8888                                 queue_start_index, "queue_start_index");
8889 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8890         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8891                                 queue_id, UINT8);
8892 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8893         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8894                                 queue_num, "queue_num");
8895 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8896         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8897                                 queue_num_value, UINT8);
8898
8899 cmdline_parse_inst_t cmd_queue_region = {
8900         .f = cmd_queue_region_parsed,
8901         .data = NULL,
8902         .help_str = "set port <port_id> queue-region region_id <value> "
8903                 "queue_start_index <value> queue_num <value>: Set a queue region",
8904         .tokens = {
8905                 (void *)&cmd_queue_region_set,
8906                 (void *)&cmd_queue_region_port,
8907                 (void *)&cmd_queue_region_port_id,
8908                 (void *)&cmd_queue_region_cmd,
8909                 (void *)&cmd_queue_region_id,
8910                 (void *)&cmd_queue_region_index,
8911                 (void *)&cmd_queue_region_queue_start_index,
8912                 (void *)&cmd_queue_region_queue_id,
8913                 (void *)&cmd_queue_region_queue_num,
8914                 (void *)&cmd_queue_region_queue_num_value,
8915                 NULL,
8916         },
8917 };
8918
8919 /* *** queue region and flowtype set *** */
8920 struct cmd_region_flowtype_result {
8921         cmdline_fixed_string_t set;
8922         cmdline_fixed_string_t port;
8923         portid_t port_id;
8924         cmdline_fixed_string_t cmd;
8925         cmdline_fixed_string_t region;
8926         uint8_t  region_id;
8927         cmdline_fixed_string_t flowtype;
8928         uint8_t  flowtype_id;
8929 };
8930
8931 static void
8932 cmd_region_flowtype_parsed(void *parsed_result,
8933                         __attribute__((unused)) struct cmdline *cl,
8934                         __attribute__((unused)) void *data)
8935 {
8936         struct cmd_region_flowtype_result *res = parsed_result;
8937         int ret = -ENOTSUP;
8938 #ifdef RTE_LIBRTE_I40E_PMD
8939         struct rte_pmd_i40e_queue_region_conf region_conf;
8940         enum rte_pmd_i40e_queue_region_op op_type;
8941 #endif
8942
8943         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8944                 return;
8945
8946 #ifdef RTE_LIBRTE_I40E_PMD
8947         memset(&region_conf, 0, sizeof(region_conf));
8948
8949         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8950         region_conf.region_id = res->region_id;
8951         region_conf.hw_flowtype = res->flowtype_id;
8952
8953         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8954                         op_type, &region_conf);
8955 #endif
8956
8957         switch (ret) {
8958         case 0:
8959                 break;
8960         case -ENOTSUP:
8961                 printf("function not implemented or supported\n");
8962                 break;
8963         default:
8964                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8965         }
8966 }
8967
8968 cmdline_parse_token_string_t cmd_region_flowtype_set =
8969 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8970                                 set, "set");
8971 cmdline_parse_token_string_t cmd_region_flowtype_port =
8972         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8973                                 port, "port");
8974 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8975         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8976                                 port_id, UINT16);
8977 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8978         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8979                                 cmd, "queue-region");
8980 cmdline_parse_token_string_t cmd_region_flowtype_index =
8981         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8982                                 region, "region_id");
8983 cmdline_parse_token_num_t cmd_region_flowtype_id =
8984         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8985                                 region_id, UINT8);
8986 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8987         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8988                                 flowtype, "flowtype");
8989 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8990         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8991                                 flowtype_id, UINT8);
8992 cmdline_parse_inst_t cmd_region_flowtype = {
8993         .f = cmd_region_flowtype_parsed,
8994         .data = NULL,
8995         .help_str = "set port <port_id> queue-region region_id <value> "
8996                 "flowtype <value>: Set a flowtype region index",
8997         .tokens = {
8998                 (void *)&cmd_region_flowtype_set,
8999                 (void *)&cmd_region_flowtype_port,
9000                 (void *)&cmd_region_flowtype_port_index,
9001                 (void *)&cmd_region_flowtype_cmd,
9002                 (void *)&cmd_region_flowtype_index,
9003                 (void *)&cmd_region_flowtype_id,
9004                 (void *)&cmd_region_flowtype_flow_index,
9005                 (void *)&cmd_region_flowtype_flow_id,
9006                 NULL,
9007         },
9008 };
9009
9010 /* *** User Priority (UP) to queue region (region_id) set *** */
9011 struct cmd_user_priority_region_result {
9012         cmdline_fixed_string_t set;
9013         cmdline_fixed_string_t port;
9014         portid_t port_id;
9015         cmdline_fixed_string_t cmd;
9016         cmdline_fixed_string_t user_priority;
9017         uint8_t  user_priority_id;
9018         cmdline_fixed_string_t region;
9019         uint8_t  region_id;
9020 };
9021
9022 static void
9023 cmd_user_priority_region_parsed(void *parsed_result,
9024                         __attribute__((unused)) struct cmdline *cl,
9025                         __attribute__((unused)) void *data)
9026 {
9027         struct cmd_user_priority_region_result *res = parsed_result;
9028         int ret = -ENOTSUP;
9029 #ifdef RTE_LIBRTE_I40E_PMD
9030         struct rte_pmd_i40e_queue_region_conf region_conf;
9031         enum rte_pmd_i40e_queue_region_op op_type;
9032 #endif
9033
9034         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9035                 return;
9036
9037 #ifdef RTE_LIBRTE_I40E_PMD
9038         memset(&region_conf, 0, sizeof(region_conf));
9039         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9040         region_conf.user_priority = res->user_priority_id;
9041         region_conf.region_id = res->region_id;
9042
9043         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9044                                 op_type, &region_conf);
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("user_priority region config error: (%s)\n",
9055                                 strerror(-ret));
9056         }
9057 }
9058
9059 cmdline_parse_token_string_t cmd_user_priority_region_set =
9060         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9061                                 set, "set");
9062 cmdline_parse_token_string_t cmd_user_priority_region_port =
9063         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9064                                 port, "port");
9065 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9066         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9067                                 port_id, UINT16);
9068 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9069         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9070                                 cmd, "queue-region");
9071 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9072         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9073                                 user_priority, "UP");
9074 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9075         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9076                                 user_priority_id, UINT8);
9077 cmdline_parse_token_string_t cmd_user_priority_region_region =
9078         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9079                                 region, "region_id");
9080 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9081         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9082                                 region_id, UINT8);
9083
9084 cmdline_parse_inst_t cmd_user_priority_region = {
9085         .f = cmd_user_priority_region_parsed,
9086         .data = NULL,
9087         .help_str = "set port <port_id> queue-region UP <value> "
9088                 "region_id <value>: Set the mapping of User Priority (UP) "
9089                 "to queue region (region_id) ",
9090         .tokens = {
9091                 (void *)&cmd_user_priority_region_set,
9092                 (void *)&cmd_user_priority_region_port,
9093                 (void *)&cmd_user_priority_region_port_index,
9094                 (void *)&cmd_user_priority_region_cmd,
9095                 (void *)&cmd_user_priority_region_UP,
9096                 (void *)&cmd_user_priority_region_UP_id,
9097                 (void *)&cmd_user_priority_region_region,
9098                 (void *)&cmd_user_priority_region_region_id,
9099                 NULL,
9100         },
9101 };
9102
9103 /* *** flush all queue region related configuration *** */
9104 struct cmd_flush_queue_region_result {
9105         cmdline_fixed_string_t set;
9106         cmdline_fixed_string_t port;
9107         portid_t port_id;
9108         cmdline_fixed_string_t cmd;
9109         cmdline_fixed_string_t flush;
9110         cmdline_fixed_string_t what;
9111 };
9112
9113 static void
9114 cmd_flush_queue_region_parsed(void *parsed_result,
9115                         __attribute__((unused)) struct cmdline *cl,
9116                         __attribute__((unused)) void *data)
9117 {
9118         struct cmd_flush_queue_region_result *res = parsed_result;
9119         int ret = -ENOTSUP;
9120 #ifdef RTE_LIBRTE_I40E_PMD
9121         struct rte_pmd_i40e_queue_region_conf region_conf;
9122         enum rte_pmd_i40e_queue_region_op op_type;
9123 #endif
9124
9125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9126                 return;
9127
9128 #ifdef RTE_LIBRTE_I40E_PMD
9129         memset(&region_conf, 0, sizeof(region_conf));
9130
9131         if (strcmp(res->what, "on") == 0)
9132                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9133         else
9134                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9135
9136         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9137                                 op_type, &region_conf);
9138 #endif
9139
9140         switch (ret) {
9141         case 0:
9142                 break;
9143         case -ENOTSUP:
9144                 printf("function not implemented or supported\n");
9145                 break;
9146         default:
9147                 printf("queue region config flush error: (%s)\n",
9148                                 strerror(-ret));
9149         }
9150 }
9151
9152 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9153         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9154                                 set, "set");
9155 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9156         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9157                                 port, "port");
9158 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9159         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9160                                 port_id, UINT16);
9161 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9162         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9163                                 cmd, "queue-region");
9164 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9165         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9166                                 flush, "flush");
9167 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9168         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9169                                 what, "on#off");
9170
9171 cmdline_parse_inst_t cmd_flush_queue_region = {
9172         .f = cmd_flush_queue_region_parsed,
9173         .data = NULL,
9174         .help_str = "set port <port_id> queue-region flush on|off"
9175                 ": flush all queue region related configuration",
9176         .tokens = {
9177                 (void *)&cmd_flush_queue_region_set,
9178                 (void *)&cmd_flush_queue_region_port,
9179                 (void *)&cmd_flush_queue_region_port_index,
9180                 (void *)&cmd_flush_queue_region_cmd,
9181                 (void *)&cmd_flush_queue_region_flush,
9182                 (void *)&cmd_flush_queue_region_what,
9183                 NULL,
9184         },
9185 };
9186
9187 /* *** get all queue region related configuration info *** */
9188 struct cmd_show_queue_region_info {
9189         cmdline_fixed_string_t show;
9190         cmdline_fixed_string_t port;
9191         portid_t port_id;
9192         cmdline_fixed_string_t cmd;
9193 };
9194
9195 static void
9196 cmd_show_queue_region_info_parsed(void *parsed_result,
9197                         __attribute__((unused)) struct cmdline *cl,
9198                         __attribute__((unused)) void *data)
9199 {
9200         struct cmd_show_queue_region_info *res = parsed_result;
9201         int ret = -ENOTSUP;
9202 #ifdef RTE_LIBRTE_I40E_PMD
9203         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9204         enum rte_pmd_i40e_queue_region_op op_type;
9205 #endif
9206
9207         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9208                 return;
9209
9210 #ifdef RTE_LIBRTE_I40E_PMD
9211         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9212
9213         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9214
9215         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9216                                         op_type, &rte_pmd_regions);
9217
9218         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9219 #endif
9220
9221         switch (ret) {
9222         case 0:
9223                 break;
9224         case -ENOTSUP:
9225                 printf("function not implemented or supported\n");
9226                 break;
9227         default:
9228                 printf("queue region config info show error: (%s)\n",
9229                                 strerror(-ret));
9230         }
9231 }
9232
9233 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9234 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9235                                 show, "show");
9236 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9237         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9238                                 port, "port");
9239 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9240         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9241                                 port_id, UINT16);
9242 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9243         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9244                                 cmd, "queue-region");
9245
9246 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9247         .f = cmd_show_queue_region_info_parsed,
9248         .data = NULL,
9249         .help_str = "show port <port_id> queue-region"
9250                 ": show all queue region related configuration info",
9251         .tokens = {
9252                 (void *)&cmd_show_queue_region_info_get,
9253                 (void *)&cmd_show_queue_region_info_port,
9254                 (void *)&cmd_show_queue_region_info_port_index,
9255                 (void *)&cmd_show_queue_region_info_cmd,
9256                 NULL,
9257         },
9258 };
9259
9260 /* *** ADD/REMOVE A 2tuple FILTER *** */
9261 struct cmd_2tuple_filter_result {
9262         cmdline_fixed_string_t filter;
9263         portid_t port_id;
9264         cmdline_fixed_string_t ops;
9265         cmdline_fixed_string_t dst_port;
9266         uint16_t dst_port_value;
9267         cmdline_fixed_string_t protocol;
9268         uint8_t protocol_value;
9269         cmdline_fixed_string_t mask;
9270         uint8_t  mask_value;
9271         cmdline_fixed_string_t tcp_flags;
9272         uint8_t tcp_flags_value;
9273         cmdline_fixed_string_t priority;
9274         uint8_t  priority_value;
9275         cmdline_fixed_string_t queue;
9276         uint16_t  queue_id;
9277 };
9278
9279 static void
9280 cmd_2tuple_filter_parsed(void *parsed_result,
9281                         __attribute__((unused)) struct cmdline *cl,
9282                         __attribute__((unused)) void *data)
9283 {
9284         struct rte_eth_ntuple_filter filter;
9285         struct cmd_2tuple_filter_result *res = parsed_result;
9286         int ret = 0;
9287
9288         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9289         if (ret < 0) {
9290                 printf("ntuple filter is not supported on port %u.\n",
9291                         res->port_id);
9292                 return;
9293         }
9294
9295         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9296
9297         filter.flags = RTE_2TUPLE_FLAGS;
9298         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9299         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9300         filter.proto = res->protocol_value;
9301         filter.priority = res->priority_value;
9302         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9303                 printf("nonzero tcp_flags is only meaningful"
9304                         " when protocol is TCP.\n");
9305                 return;
9306         }
9307         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9308                 printf("invalid TCP flags.\n");
9309                 return;
9310         }
9311
9312         if (res->tcp_flags_value != 0) {
9313                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9314                 filter.tcp_flags = res->tcp_flags_value;
9315         }
9316
9317         /* need convert to big endian. */
9318         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9319         filter.queue = res->queue_id;
9320
9321         if (!strcmp(res->ops, "add"))
9322                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9323                                 RTE_ETH_FILTER_NTUPLE,
9324                                 RTE_ETH_FILTER_ADD,
9325                                 &filter);
9326         else
9327                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9328                                 RTE_ETH_FILTER_NTUPLE,
9329                                 RTE_ETH_FILTER_DELETE,
9330                                 &filter);
9331         if (ret < 0)
9332                 printf("2tuple filter programming error: (%s)\n",
9333                         strerror(-ret));
9334
9335 }
9336
9337 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9338         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9339                                  filter, "2tuple_filter");
9340 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9341         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9342                                 port_id, UINT16);
9343 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9344         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9345                                  ops, "add#del");
9346 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9347         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9348                                 dst_port, "dst_port");
9349 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9350         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9351                                 dst_port_value, UINT16);
9352 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9353         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9354                                 protocol, "protocol");
9355 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9356         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9357                                 protocol_value, UINT8);
9358 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9359         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9360                                 mask, "mask");
9361 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9362         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9363                                 mask_value, INT8);
9364 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9365         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9366                                 tcp_flags, "tcp_flags");
9367 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9368         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9369                                 tcp_flags_value, UINT8);
9370 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9371         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9372                                 priority, "priority");
9373 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9374         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9375                                 priority_value, UINT8);
9376 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9377         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9378                                 queue, "queue");
9379 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9380         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9381                                 queue_id, UINT16);
9382
9383 cmdline_parse_inst_t cmd_2tuple_filter = {
9384         .f = cmd_2tuple_filter_parsed,
9385         .data = NULL,
9386         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9387                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9388                 "<queue_id>: Add a 2tuple filter",
9389         .tokens = {
9390                 (void *)&cmd_2tuple_filter_filter,
9391                 (void *)&cmd_2tuple_filter_port_id,
9392                 (void *)&cmd_2tuple_filter_ops,
9393                 (void *)&cmd_2tuple_filter_dst_port,
9394                 (void *)&cmd_2tuple_filter_dst_port_value,
9395                 (void *)&cmd_2tuple_filter_protocol,
9396                 (void *)&cmd_2tuple_filter_protocol_value,
9397                 (void *)&cmd_2tuple_filter_mask,
9398                 (void *)&cmd_2tuple_filter_mask_value,
9399                 (void *)&cmd_2tuple_filter_tcp_flags,
9400                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9401                 (void *)&cmd_2tuple_filter_priority,
9402                 (void *)&cmd_2tuple_filter_priority_value,
9403                 (void *)&cmd_2tuple_filter_queue,
9404                 (void *)&cmd_2tuple_filter_queue_id,
9405                 NULL,
9406         },
9407 };
9408
9409 /* *** ADD/REMOVE A 5tuple FILTER *** */
9410 struct cmd_5tuple_filter_result {
9411         cmdline_fixed_string_t filter;
9412         portid_t port_id;
9413         cmdline_fixed_string_t ops;
9414         cmdline_fixed_string_t dst_ip;
9415         cmdline_ipaddr_t dst_ip_value;
9416         cmdline_fixed_string_t src_ip;
9417         cmdline_ipaddr_t src_ip_value;
9418         cmdline_fixed_string_t dst_port;
9419         uint16_t dst_port_value;
9420         cmdline_fixed_string_t src_port;
9421         uint16_t src_port_value;
9422         cmdline_fixed_string_t protocol;
9423         uint8_t protocol_value;
9424         cmdline_fixed_string_t mask;
9425         uint8_t  mask_value;
9426         cmdline_fixed_string_t tcp_flags;
9427         uint8_t tcp_flags_value;
9428         cmdline_fixed_string_t priority;
9429         uint8_t  priority_value;
9430         cmdline_fixed_string_t queue;
9431         uint16_t  queue_id;
9432 };
9433
9434 static void
9435 cmd_5tuple_filter_parsed(void *parsed_result,
9436                         __attribute__((unused)) struct cmdline *cl,
9437                         __attribute__((unused)) void *data)
9438 {
9439         struct rte_eth_ntuple_filter filter;
9440         struct cmd_5tuple_filter_result *res = parsed_result;
9441         int ret = 0;
9442
9443         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9444         if (ret < 0) {
9445                 printf("ntuple filter is not supported on port %u.\n",
9446                         res->port_id);
9447                 return;
9448         }
9449
9450         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9451
9452         filter.flags = RTE_5TUPLE_FLAGS;
9453         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9454         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9455         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9456         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9457         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9458         filter.proto = res->protocol_value;
9459         filter.priority = res->priority_value;
9460         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9461                 printf("nonzero tcp_flags is only meaningful"
9462                         " when protocol is TCP.\n");
9463                 return;
9464         }
9465         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9466                 printf("invalid TCP flags.\n");
9467                 return;
9468         }
9469
9470         if (res->tcp_flags_value != 0) {
9471                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9472                 filter.tcp_flags = res->tcp_flags_value;
9473         }
9474
9475         if (res->dst_ip_value.family == AF_INET)
9476                 /* no need to convert, already big endian. */
9477                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9478         else {
9479                 if (filter.dst_ip_mask == 0) {
9480                         printf("can not support ipv6 involved compare.\n");
9481                         return;
9482                 }
9483                 filter.dst_ip = 0;
9484         }
9485
9486         if (res->src_ip_value.family == AF_INET)
9487                 /* no need to convert, already big endian. */
9488                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9489         else {
9490                 if (filter.src_ip_mask == 0) {
9491                         printf("can not support ipv6 involved compare.\n");
9492                         return;
9493                 }
9494                 filter.src_ip = 0;
9495         }
9496         /* need convert to big endian. */
9497         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9498         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9499         filter.queue = res->queue_id;
9500
9501         if (!strcmp(res->ops, "add"))
9502                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9503                                 RTE_ETH_FILTER_NTUPLE,
9504                                 RTE_ETH_FILTER_ADD,
9505                                 &filter);
9506         else
9507                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9508                                 RTE_ETH_FILTER_NTUPLE,
9509                                 RTE_ETH_FILTER_DELETE,
9510                                 &filter);
9511         if (ret < 0)
9512                 printf("5tuple filter programming error: (%s)\n",
9513                         strerror(-ret));
9514 }
9515
9516 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9517         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9518                                  filter, "5tuple_filter");
9519 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9520         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9521                                 port_id, UINT16);
9522 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9523         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9524                                  ops, "add#del");
9525 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9526         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9527                                 dst_ip, "dst_ip");
9528 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9529         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9530                                 dst_ip_value);
9531 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9532         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9533                                 src_ip, "src_ip");
9534 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9535         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9536                                 src_ip_value);
9537 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9538         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9539                                 dst_port, "dst_port");
9540 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9541         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9542                                 dst_port_value, UINT16);
9543 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9544         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9545                                 src_port, "src_port");
9546 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9547         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9548                                 src_port_value, UINT16);
9549 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9550         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9551                                 protocol, "protocol");
9552 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9553         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9554                                 protocol_value, UINT8);
9555 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9556         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9557                                 mask, "mask");
9558 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9559         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9560                                 mask_value, INT8);
9561 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9562         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9563                                 tcp_flags, "tcp_flags");
9564 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9565         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9566                                 tcp_flags_value, UINT8);
9567 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9568         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9569                                 priority, "priority");
9570 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9571         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9572                                 priority_value, UINT8);
9573 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9574         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9575                                 queue, "queue");
9576 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9577         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9578                                 queue_id, UINT16);
9579
9580 cmdline_parse_inst_t cmd_5tuple_filter = {
9581         .f = cmd_5tuple_filter_parsed,
9582         .data = NULL,
9583         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9584                 "src_ip <value> dst_port <value> src_port <value> "
9585                 "protocol <value>  mask <value> tcp_flags <value> "
9586                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9587         .tokens = {
9588                 (void *)&cmd_5tuple_filter_filter,
9589                 (void *)&cmd_5tuple_filter_port_id,
9590                 (void *)&cmd_5tuple_filter_ops,
9591                 (void *)&cmd_5tuple_filter_dst_ip,
9592                 (void *)&cmd_5tuple_filter_dst_ip_value,
9593                 (void *)&cmd_5tuple_filter_src_ip,
9594                 (void *)&cmd_5tuple_filter_src_ip_value,
9595                 (void *)&cmd_5tuple_filter_dst_port,
9596                 (void *)&cmd_5tuple_filter_dst_port_value,
9597                 (void *)&cmd_5tuple_filter_src_port,
9598                 (void *)&cmd_5tuple_filter_src_port_value,
9599                 (void *)&cmd_5tuple_filter_protocol,
9600                 (void *)&cmd_5tuple_filter_protocol_value,
9601                 (void *)&cmd_5tuple_filter_mask,
9602                 (void *)&cmd_5tuple_filter_mask_value,
9603                 (void *)&cmd_5tuple_filter_tcp_flags,
9604                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9605                 (void *)&cmd_5tuple_filter_priority,
9606                 (void *)&cmd_5tuple_filter_priority_value,
9607                 (void *)&cmd_5tuple_filter_queue,
9608                 (void *)&cmd_5tuple_filter_queue_id,
9609                 NULL,
9610         },
9611 };
9612
9613 /* *** ADD/REMOVE A flex FILTER *** */
9614 struct cmd_flex_filter_result {
9615         cmdline_fixed_string_t filter;
9616         cmdline_fixed_string_t ops;
9617         portid_t port_id;
9618         cmdline_fixed_string_t len;
9619         uint8_t len_value;
9620         cmdline_fixed_string_t bytes;
9621         cmdline_fixed_string_t bytes_value;
9622         cmdline_fixed_string_t mask;
9623         cmdline_fixed_string_t mask_value;
9624         cmdline_fixed_string_t priority;
9625         uint8_t priority_value;
9626         cmdline_fixed_string_t queue;
9627         uint16_t queue_id;
9628 };
9629
9630 static int xdigit2val(unsigned char c)
9631 {
9632         int val;
9633         if (isdigit(c))
9634                 val = c - '0';
9635         else if (isupper(c))
9636                 val = c - 'A' + 10;
9637         else
9638                 val = c - 'a' + 10;
9639         return val;
9640 }
9641
9642 static void
9643 cmd_flex_filter_parsed(void *parsed_result,
9644                           __attribute__((unused)) struct cmdline *cl,
9645                           __attribute__((unused)) void *data)
9646 {
9647         int ret = 0;
9648         struct rte_eth_flex_filter filter;
9649         struct cmd_flex_filter_result *res = parsed_result;
9650         char *bytes_ptr, *mask_ptr;
9651         uint16_t len, i, j = 0;
9652         char c;
9653         int val;
9654         uint8_t byte = 0;
9655
9656         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9657                 printf("the len exceed the max length 128\n");
9658                 return;
9659         }
9660         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9661         filter.len = res->len_value;
9662         filter.priority = res->priority_value;
9663         filter.queue = res->queue_id;
9664         bytes_ptr = res->bytes_value;
9665         mask_ptr = res->mask_value;
9666
9667          /* translate bytes string to array. */
9668         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9669                 (bytes_ptr[1] == 'X')))
9670                 bytes_ptr += 2;
9671         len = strnlen(bytes_ptr, res->len_value * 2);
9672         if (len == 0 || (len % 8 != 0)) {
9673                 printf("please check len and bytes input\n");
9674                 return;
9675         }
9676         for (i = 0; i < len; i++) {
9677                 c = bytes_ptr[i];
9678                 if (isxdigit(c) == 0) {
9679                         /* invalid characters. */
9680                         printf("invalid input\n");
9681                         return;
9682                 }
9683                 val = xdigit2val(c);
9684                 if (i % 2) {
9685                         byte |= val;
9686                         filter.bytes[j] = byte;
9687                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9688                         j++;
9689                         byte = 0;
9690                 } else
9691                         byte |= val << 4;
9692         }
9693         printf("\n");
9694          /* translate mask string to uint8_t array. */
9695         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9696                 (mask_ptr[1] == 'X')))
9697                 mask_ptr += 2;
9698         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9699         if (len == 0) {
9700                 printf("invalid input\n");
9701                 return;
9702         }
9703         j = 0;
9704         byte = 0;
9705         for (i = 0; i < len; i++) {
9706                 c = mask_ptr[i];
9707                 if (isxdigit(c) == 0) {
9708                         /* invalid characters. */
9709                         printf("invalid input\n");
9710                         return;
9711                 }
9712                 val = xdigit2val(c);
9713                 if (i % 2) {
9714                         byte |= val;
9715                         filter.mask[j] = byte;
9716                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9717                         j++;
9718                         byte = 0;
9719                 } else
9720                         byte |= val << 4;
9721         }
9722         printf("\n");
9723
9724         if (!strcmp(res->ops, "add"))
9725                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9726                                 RTE_ETH_FILTER_FLEXIBLE,
9727                                 RTE_ETH_FILTER_ADD,
9728                                 &filter);
9729         else
9730                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9731                                 RTE_ETH_FILTER_FLEXIBLE,
9732                                 RTE_ETH_FILTER_DELETE,
9733                                 &filter);
9734
9735         if (ret < 0)
9736                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9737 }
9738
9739 cmdline_parse_token_string_t cmd_flex_filter_filter =
9740         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9741                                 filter, "flex_filter");
9742 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9743         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9744                                 port_id, UINT16);
9745 cmdline_parse_token_string_t cmd_flex_filter_ops =
9746         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9747                                 ops, "add#del");
9748 cmdline_parse_token_string_t cmd_flex_filter_len =
9749         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9750                                 len, "len");
9751 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9752         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9753                                 len_value, UINT8);
9754 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9755         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9756                                 bytes, "bytes");
9757 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9758         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9759                                 bytes_value, NULL);
9760 cmdline_parse_token_string_t cmd_flex_filter_mask =
9761         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9762                                 mask, "mask");
9763 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9764         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9765                                 mask_value, NULL);
9766 cmdline_parse_token_string_t cmd_flex_filter_priority =
9767         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9768                                 priority, "priority");
9769 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9770         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9771                                 priority_value, UINT8);
9772 cmdline_parse_token_string_t cmd_flex_filter_queue =
9773         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9774                                 queue, "queue");
9775 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9776         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9777                                 queue_id, UINT16);
9778 cmdline_parse_inst_t cmd_flex_filter = {
9779         .f = cmd_flex_filter_parsed,
9780         .data = NULL,
9781         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9782                 "<value> mask <value> priority <value> queue <queue_id>: "
9783                 "Add/Del a flex filter",
9784         .tokens = {
9785                 (void *)&cmd_flex_filter_filter,
9786                 (void *)&cmd_flex_filter_port_id,
9787                 (void *)&cmd_flex_filter_ops,
9788                 (void *)&cmd_flex_filter_len,
9789                 (void *)&cmd_flex_filter_len_value,
9790                 (void *)&cmd_flex_filter_bytes,
9791                 (void *)&cmd_flex_filter_bytes_value,
9792                 (void *)&cmd_flex_filter_mask,
9793                 (void *)&cmd_flex_filter_mask_value,
9794                 (void *)&cmd_flex_filter_priority,
9795                 (void *)&cmd_flex_filter_priority_value,
9796                 (void *)&cmd_flex_filter_queue,
9797                 (void *)&cmd_flex_filter_queue_id,
9798                 NULL,
9799         },
9800 };
9801
9802 /* *** Filters Control *** */
9803
9804 /* *** deal with ethertype filter *** */
9805 struct cmd_ethertype_filter_result {
9806         cmdline_fixed_string_t filter;
9807         portid_t port_id;
9808         cmdline_fixed_string_t ops;
9809         cmdline_fixed_string_t mac;
9810         struct ether_addr mac_addr;
9811         cmdline_fixed_string_t ethertype;
9812         uint16_t ethertype_value;
9813         cmdline_fixed_string_t drop;
9814         cmdline_fixed_string_t queue;
9815         uint16_t  queue_id;
9816 };
9817
9818 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9819         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9820                                  filter, "ethertype_filter");
9821 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9822         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9823                               port_id, UINT16);
9824 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9825         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9826                                  ops, "add#del");
9827 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9828         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9829                                  mac, "mac_addr#mac_ignr");
9830 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9831         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9832                                      mac_addr);
9833 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9834         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9835                                  ethertype, "ethertype");
9836 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9837         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9838                               ethertype_value, UINT16);
9839 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9840         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9841                                  drop, "drop#fwd");
9842 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9843         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9844                                  queue, "queue");
9845 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9846         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9847                               queue_id, UINT16);
9848
9849 static void
9850 cmd_ethertype_filter_parsed(void *parsed_result,
9851                           __attribute__((unused)) struct cmdline *cl,
9852                           __attribute__((unused)) void *data)
9853 {
9854         struct cmd_ethertype_filter_result *res = parsed_result;
9855         struct rte_eth_ethertype_filter filter;
9856         int ret = 0;
9857
9858         ret = rte_eth_dev_filter_supported(res->port_id,
9859                         RTE_ETH_FILTER_ETHERTYPE);
9860         if (ret < 0) {
9861                 printf("ethertype filter is not supported on port %u.\n",
9862                         res->port_id);
9863                 return;
9864         }
9865
9866         memset(&filter, 0, sizeof(filter));
9867         if (!strcmp(res->mac, "mac_addr")) {
9868                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9869                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9870                         sizeof(struct ether_addr));
9871         }
9872         if (!strcmp(res->drop, "drop"))
9873                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9874         filter.ether_type = res->ethertype_value;
9875         filter.queue = res->queue_id;
9876
9877         if (!strcmp(res->ops, "add"))
9878                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9879                                 RTE_ETH_FILTER_ETHERTYPE,
9880                                 RTE_ETH_FILTER_ADD,
9881                                 &filter);
9882         else
9883                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9884                                 RTE_ETH_FILTER_ETHERTYPE,
9885                                 RTE_ETH_FILTER_DELETE,
9886                                 &filter);
9887         if (ret < 0)
9888                 printf("ethertype filter programming error: (%s)\n",
9889                         strerror(-ret));
9890 }
9891
9892 cmdline_parse_inst_t cmd_ethertype_filter = {
9893         .f = cmd_ethertype_filter_parsed,
9894         .data = NULL,
9895         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9896                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9897                 "Add or delete an ethertype filter entry",
9898         .tokens = {
9899                 (void *)&cmd_ethertype_filter_filter,
9900                 (void *)&cmd_ethertype_filter_port_id,
9901                 (void *)&cmd_ethertype_filter_ops,
9902                 (void *)&cmd_ethertype_filter_mac,
9903                 (void *)&cmd_ethertype_filter_mac_addr,
9904                 (void *)&cmd_ethertype_filter_ethertype,
9905                 (void *)&cmd_ethertype_filter_ethertype_value,
9906                 (void *)&cmd_ethertype_filter_drop,
9907                 (void *)&cmd_ethertype_filter_queue,
9908                 (void *)&cmd_ethertype_filter_queue_id,
9909                 NULL,
9910         },
9911 };
9912
9913 /* *** deal with flow director filter *** */
9914 struct cmd_flow_director_result {
9915         cmdline_fixed_string_t flow_director_filter;
9916         portid_t port_id;
9917         cmdline_fixed_string_t mode;
9918         cmdline_fixed_string_t mode_value;
9919         cmdline_fixed_string_t ops;
9920         cmdline_fixed_string_t flow;
9921         cmdline_fixed_string_t flow_type;
9922         cmdline_fixed_string_t ether;
9923         uint16_t ether_type;
9924         cmdline_fixed_string_t src;
9925         cmdline_ipaddr_t ip_src;
9926         uint16_t port_src;
9927         cmdline_fixed_string_t dst;
9928         cmdline_ipaddr_t ip_dst;
9929         uint16_t port_dst;
9930         cmdline_fixed_string_t verify_tag;
9931         uint32_t verify_tag_value;
9932         cmdline_ipaddr_t tos;
9933         uint8_t tos_value;
9934         cmdline_ipaddr_t proto;
9935         uint8_t proto_value;
9936         cmdline_ipaddr_t ttl;
9937         uint8_t ttl_value;
9938         cmdline_fixed_string_t vlan;
9939         uint16_t vlan_value;
9940         cmdline_fixed_string_t flexbytes;
9941         cmdline_fixed_string_t flexbytes_value;
9942         cmdline_fixed_string_t pf_vf;
9943         cmdline_fixed_string_t drop;
9944         cmdline_fixed_string_t queue;
9945         uint16_t  queue_id;
9946         cmdline_fixed_string_t fd_id;
9947         uint32_t  fd_id_value;
9948         cmdline_fixed_string_t mac;
9949         struct ether_addr mac_addr;
9950         cmdline_fixed_string_t tunnel;
9951         cmdline_fixed_string_t tunnel_type;
9952         cmdline_fixed_string_t tunnel_id;
9953         uint32_t tunnel_id_value;
9954         cmdline_fixed_string_t packet;
9955         char filepath[];
9956 };
9957
9958 static inline int
9959 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9960 {
9961         char s[256];
9962         const char *p, *p0 = q_arg;
9963         char *end;
9964         unsigned long int_fld;
9965         char *str_fld[max_num];
9966         int i;
9967         unsigned size;
9968         int ret = -1;
9969
9970         p = strchr(p0, '(');
9971         if (p == NULL)
9972                 return -1;
9973         ++p;
9974         p0 = strchr(p, ')');
9975         if (p0 == NULL)
9976                 return -1;
9977
9978         size = p0 - p;
9979         if (size >= sizeof(s))
9980                 return -1;
9981
9982         snprintf(s, sizeof(s), "%.*s", size, p);
9983         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9984         if (ret < 0 || ret > max_num)
9985                 return -1;
9986         for (i = 0; i < ret; i++) {
9987                 errno = 0;
9988                 int_fld = strtoul(str_fld[i], &end, 0);
9989                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9990                         return -1;
9991                 flexbytes[i] = (uint8_t)int_fld;
9992         }
9993         return ret;
9994 }
9995
9996 static uint16_t
9997 str2flowtype(char *string)
9998 {
9999         uint8_t i = 0;
10000         static const struct {
10001                 char str[32];
10002                 uint16_t type;
10003         } flowtype_str[] = {
10004                 {"raw", RTE_ETH_FLOW_RAW},
10005                 {"ipv4", RTE_ETH_FLOW_IPV4},
10006                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10007                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10008                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10009                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10010                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10011                 {"ipv6", RTE_ETH_FLOW_IPV6},
10012                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10013                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10014                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10015                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10016                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10017                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10018         };
10019
10020         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10021                 if (!strcmp(flowtype_str[i].str, string))
10022                         return flowtype_str[i].type;
10023         }
10024
10025         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10026                 return (uint16_t)atoi(string);
10027
10028         return RTE_ETH_FLOW_UNKNOWN;
10029 }
10030
10031 static enum rte_eth_fdir_tunnel_type
10032 str2fdir_tunneltype(char *string)
10033 {
10034         uint8_t i = 0;
10035
10036         static const struct {
10037                 char str[32];
10038                 enum rte_eth_fdir_tunnel_type type;
10039         } tunneltype_str[] = {
10040                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10041                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10042         };
10043
10044         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10045                 if (!strcmp(tunneltype_str[i].str, string))
10046                         return tunneltype_str[i].type;
10047         }
10048         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10049 }
10050
10051 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10052 do { \
10053         if ((ip_addr).family == AF_INET) \
10054                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10055         else { \
10056                 printf("invalid parameter.\n"); \
10057                 return; \
10058         } \
10059 } while (0)
10060
10061 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10062 do { \
10063         if ((ip_addr).family == AF_INET6) \
10064                 rte_memcpy(&(ip), \
10065                                  &((ip_addr).addr.ipv6), \
10066                                  sizeof(struct in6_addr)); \
10067         else { \
10068                 printf("invalid parameter.\n"); \
10069                 return; \
10070         } \
10071 } while (0)
10072
10073 static void
10074 cmd_flow_director_filter_parsed(void *parsed_result,
10075                           __attribute__((unused)) struct cmdline *cl,
10076                           __attribute__((unused)) void *data)
10077 {
10078         struct cmd_flow_director_result *res = parsed_result;
10079         struct rte_eth_fdir_filter entry;
10080         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10081         char *end;
10082         unsigned long vf_id;
10083         int ret = 0;
10084
10085         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10086         if (ret < 0) {
10087                 printf("flow director is not supported on port %u.\n",
10088                         res->port_id);
10089                 return;
10090         }
10091         memset(flexbytes, 0, sizeof(flexbytes));
10092         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10093
10094         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10095                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10096                         printf("Please set mode to MAC-VLAN.\n");
10097                         return;
10098                 }
10099         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10100                 if (strcmp(res->mode_value, "Tunnel")) {
10101                         printf("Please set mode to Tunnel.\n");
10102                         return;
10103                 }
10104         } else {
10105                 if (!strcmp(res->mode_value, "raw")) {
10106 #ifdef RTE_LIBRTE_I40E_PMD
10107                         struct rte_pmd_i40e_flow_type_mapping
10108                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10109                         struct rte_pmd_i40e_pkt_template_conf conf;
10110                         uint16_t flow_type = str2flowtype(res->flow_type);
10111                         uint16_t i, port = res->port_id;
10112                         uint8_t add;
10113
10114                         memset(&conf, 0, sizeof(conf));
10115
10116                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10117                                 printf("Invalid flow type specified.\n");
10118                                 return;
10119                         }
10120                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10121                                                                  mapping);
10122                         if (ret)
10123                                 return;
10124                         if (mapping[flow_type].pctype == 0ULL) {
10125                                 printf("Invalid flow type specified.\n");
10126                                 return;
10127                         }
10128                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10129                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10130                                         conf.input.pctype = i;
10131                                         break;
10132                                 }
10133                         }
10134
10135                         conf.input.packet = open_file(res->filepath,
10136                                                 &conf.input.length);
10137                         if (!conf.input.packet)
10138                                 return;
10139                         if (!strcmp(res->drop, "drop"))
10140                                 conf.action.behavior =
10141                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10142                         else
10143                                 conf.action.behavior =
10144                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10145                         conf.action.report_status =
10146                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10147                         conf.action.rx_queue = res->queue_id;
10148                         conf.soft_id = res->fd_id_value;
10149                         add  = strcmp(res->ops, "del") ? 1 : 0;
10150                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10151                                                                         &conf,
10152                                                                         add);
10153                         if (ret < 0)
10154                                 printf("flow director config error: (%s)\n",
10155                                        strerror(-ret));
10156                         close_file(conf.input.packet);
10157 #endif
10158                         return;
10159                 } else if (strcmp(res->mode_value, "IP")) {
10160                         printf("Please set mode to IP or raw.\n");
10161                         return;
10162                 }
10163                 entry.input.flow_type = str2flowtype(res->flow_type);
10164         }
10165
10166         ret = parse_flexbytes(res->flexbytes_value,
10167                                         flexbytes,
10168                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10169         if (ret < 0) {
10170                 printf("error: Cannot parse flexbytes input.\n");
10171                 return;
10172         }
10173
10174         switch (entry.input.flow_type) {
10175         case RTE_ETH_FLOW_FRAG_IPV4:
10176         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10177                 entry.input.flow.ip4_flow.proto = res->proto_value;
10178                 /* fall-through */
10179         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10180         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10181                 IPV4_ADDR_TO_UINT(res->ip_dst,
10182                         entry.input.flow.ip4_flow.dst_ip);
10183                 IPV4_ADDR_TO_UINT(res->ip_src,
10184                         entry.input.flow.ip4_flow.src_ip);
10185                 entry.input.flow.ip4_flow.tos = res->tos_value;
10186                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10187                 /* need convert to big endian. */
10188                 entry.input.flow.udp4_flow.dst_port =
10189                                 rte_cpu_to_be_16(res->port_dst);
10190                 entry.input.flow.udp4_flow.src_port =
10191                                 rte_cpu_to_be_16(res->port_src);
10192                 break;
10193         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10194                 IPV4_ADDR_TO_UINT(res->ip_dst,
10195                         entry.input.flow.sctp4_flow.ip.dst_ip);
10196                 IPV4_ADDR_TO_UINT(res->ip_src,
10197                         entry.input.flow.sctp4_flow.ip.src_ip);
10198                 entry.input.flow.ip4_flow.tos = res->tos_value;
10199                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10200                 /* need convert to big endian. */
10201                 entry.input.flow.sctp4_flow.dst_port =
10202                                 rte_cpu_to_be_16(res->port_dst);
10203                 entry.input.flow.sctp4_flow.src_port =
10204                                 rte_cpu_to_be_16(res->port_src);
10205                 entry.input.flow.sctp4_flow.verify_tag =
10206                                 rte_cpu_to_be_32(res->verify_tag_value);
10207                 break;
10208         case RTE_ETH_FLOW_FRAG_IPV6:
10209         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10210                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10211                 /* fall-through */
10212         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10213         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10214                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10215                         entry.input.flow.ipv6_flow.dst_ip);
10216                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10217                         entry.input.flow.ipv6_flow.src_ip);
10218                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10219                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10220                 /* need convert to big endian. */
10221                 entry.input.flow.udp6_flow.dst_port =
10222                                 rte_cpu_to_be_16(res->port_dst);
10223                 entry.input.flow.udp6_flow.src_port =
10224                                 rte_cpu_to_be_16(res->port_src);
10225                 break;
10226         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10227                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10228                         entry.input.flow.sctp6_flow.ip.dst_ip);
10229                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10230                         entry.input.flow.sctp6_flow.ip.src_ip);
10231                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10232                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10233                 /* need convert to big endian. */
10234                 entry.input.flow.sctp6_flow.dst_port =
10235                                 rte_cpu_to_be_16(res->port_dst);
10236                 entry.input.flow.sctp6_flow.src_port =
10237                                 rte_cpu_to_be_16(res->port_src);
10238                 entry.input.flow.sctp6_flow.verify_tag =
10239                                 rte_cpu_to_be_32(res->verify_tag_value);
10240                 break;
10241         case RTE_ETH_FLOW_L2_PAYLOAD:
10242                 entry.input.flow.l2_flow.ether_type =
10243                         rte_cpu_to_be_16(res->ether_type);
10244                 break;
10245         default:
10246                 break;
10247         }
10248
10249         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10250                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10251                                  &res->mac_addr,
10252                                  sizeof(struct ether_addr));
10253
10254         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10255                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10256                                  &res->mac_addr,
10257                                  sizeof(struct ether_addr));
10258                 entry.input.flow.tunnel_flow.tunnel_type =
10259                         str2fdir_tunneltype(res->tunnel_type);
10260                 entry.input.flow.tunnel_flow.tunnel_id =
10261                         rte_cpu_to_be_32(res->tunnel_id_value);
10262         }
10263
10264         rte_memcpy(entry.input.flow_ext.flexbytes,
10265                    flexbytes,
10266                    RTE_ETH_FDIR_MAX_FLEXLEN);
10267
10268         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10269
10270         entry.action.flex_off = 0;  /*use 0 by default */
10271         if (!strcmp(res->drop, "drop"))
10272                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10273         else
10274                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10275
10276         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10277             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10278                 if (!strcmp(res->pf_vf, "pf"))
10279                         entry.input.flow_ext.is_vf = 0;
10280                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10281                         struct rte_eth_dev_info dev_info;
10282
10283                         memset(&dev_info, 0, sizeof(dev_info));
10284                         rte_eth_dev_info_get(res->port_id, &dev_info);
10285                         errno = 0;
10286                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10287                         if (errno != 0 || *end != '\0' ||
10288                             vf_id >= dev_info.max_vfs) {
10289                                 printf("invalid parameter %s.\n", res->pf_vf);
10290                                 return;
10291                         }
10292                         entry.input.flow_ext.is_vf = 1;
10293                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10294                 } else {
10295                         printf("invalid parameter %s.\n", res->pf_vf);
10296                         return;
10297                 }
10298         }
10299
10300         /* set to report FD ID by default */
10301         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10302         entry.action.rx_queue = res->queue_id;
10303         entry.soft_id = res->fd_id_value;
10304         if (!strcmp(res->ops, "add"))
10305                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10306                                              RTE_ETH_FILTER_ADD, &entry);
10307         else if (!strcmp(res->ops, "del"))
10308                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10309                                              RTE_ETH_FILTER_DELETE, &entry);
10310         else
10311                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10312                                              RTE_ETH_FILTER_UPDATE, &entry);
10313         if (ret < 0)
10314                 printf("flow director programming error: (%s)\n",
10315                         strerror(-ret));
10316 }
10317
10318 cmdline_parse_token_string_t cmd_flow_director_filter =
10319         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10320                                  flow_director_filter, "flow_director_filter");
10321 cmdline_parse_token_num_t cmd_flow_director_port_id =
10322         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10323                               port_id, UINT16);
10324 cmdline_parse_token_string_t cmd_flow_director_ops =
10325         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10326                                  ops, "add#del#update");
10327 cmdline_parse_token_string_t cmd_flow_director_flow =
10328         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10329                                  flow, "flow");
10330 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10331         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10332                 flow_type, NULL);
10333 cmdline_parse_token_string_t cmd_flow_director_ether =
10334         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10335                                  ether, "ether");
10336 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10337         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10338                               ether_type, UINT16);
10339 cmdline_parse_token_string_t cmd_flow_director_src =
10340         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10341                                  src, "src");
10342 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10343         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10344                                  ip_src);
10345 cmdline_parse_token_num_t cmd_flow_director_port_src =
10346         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10347                               port_src, UINT16);
10348 cmdline_parse_token_string_t cmd_flow_director_dst =
10349         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10350                                  dst, "dst");
10351 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10352         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10353                                  ip_dst);
10354 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10355         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10356                               port_dst, UINT16);
10357 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10358         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10359                                   verify_tag, "verify_tag");
10360 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10361         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10362                               verify_tag_value, UINT32);
10363 cmdline_parse_token_string_t cmd_flow_director_tos =
10364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10365                                  tos, "tos");
10366 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10367         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10368                               tos_value, UINT8);
10369 cmdline_parse_token_string_t cmd_flow_director_proto =
10370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10371                                  proto, "proto");
10372 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10373         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10374                               proto_value, UINT8);
10375 cmdline_parse_token_string_t cmd_flow_director_ttl =
10376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10377                                  ttl, "ttl");
10378 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10379         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10380                               ttl_value, UINT8);
10381 cmdline_parse_token_string_t cmd_flow_director_vlan =
10382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10383                                  vlan, "vlan");
10384 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10385         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10386                               vlan_value, UINT16);
10387 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10389                                  flexbytes, "flexbytes");
10390 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10391         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10392                               flexbytes_value, NULL);
10393 cmdline_parse_token_string_t cmd_flow_director_drop =
10394         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10395                                  drop, "drop#fwd");
10396 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10397         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10398                               pf_vf, NULL);
10399 cmdline_parse_token_string_t cmd_flow_director_queue =
10400         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10401                                  queue, "queue");
10402 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10403         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10404                               queue_id, UINT16);
10405 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10406         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10407                                  fd_id, "fd_id");
10408 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10409         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10410                               fd_id_value, UINT32);
10411
10412 cmdline_parse_token_string_t cmd_flow_director_mode =
10413         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10414                                  mode, "mode");
10415 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10417                                  mode_value, "IP");
10418 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10419         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10420                                  mode_value, "MAC-VLAN");
10421 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10423                                  mode_value, "Tunnel");
10424 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10426                                  mode_value, "raw");
10427 cmdline_parse_token_string_t cmd_flow_director_mac =
10428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10429                                  mac, "mac");
10430 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10431         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10432                                     mac_addr);
10433 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10435                                  tunnel, "tunnel");
10436 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10438                                  tunnel_type, "NVGRE#VxLAN");
10439 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10441                                  tunnel_id, "tunnel-id");
10442 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10444                               tunnel_id_value, UINT32);
10445 cmdline_parse_token_string_t cmd_flow_director_packet =
10446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10447                                  packet, "packet");
10448 cmdline_parse_token_string_t cmd_flow_director_filepath =
10449         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10450                                  filepath, NULL);
10451
10452 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10453         .f = cmd_flow_director_filter_parsed,
10454         .data = NULL,
10455         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10456                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10457                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10458                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10459                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10460                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10461                 "fd_id <fd_id_value>: "
10462                 "Add or delete an ip flow director entry on NIC",
10463         .tokens = {
10464                 (void *)&cmd_flow_director_filter,
10465                 (void *)&cmd_flow_director_port_id,
10466                 (void *)&cmd_flow_director_mode,
10467                 (void *)&cmd_flow_director_mode_ip,
10468                 (void *)&cmd_flow_director_ops,
10469                 (void *)&cmd_flow_director_flow,
10470                 (void *)&cmd_flow_director_flow_type,
10471                 (void *)&cmd_flow_director_src,
10472                 (void *)&cmd_flow_director_ip_src,
10473                 (void *)&cmd_flow_director_dst,
10474                 (void *)&cmd_flow_director_ip_dst,
10475                 (void *)&cmd_flow_director_tos,
10476                 (void *)&cmd_flow_director_tos_value,
10477                 (void *)&cmd_flow_director_proto,
10478                 (void *)&cmd_flow_director_proto_value,
10479                 (void *)&cmd_flow_director_ttl,
10480                 (void *)&cmd_flow_director_ttl_value,
10481                 (void *)&cmd_flow_director_vlan,
10482                 (void *)&cmd_flow_director_vlan_value,
10483                 (void *)&cmd_flow_director_flexbytes,
10484                 (void *)&cmd_flow_director_flexbytes_value,
10485                 (void *)&cmd_flow_director_drop,
10486                 (void *)&cmd_flow_director_pf_vf,
10487                 (void *)&cmd_flow_director_queue,
10488                 (void *)&cmd_flow_director_queue_id,
10489                 (void *)&cmd_flow_director_fd_id,
10490                 (void *)&cmd_flow_director_fd_id_value,
10491                 NULL,
10492         },
10493 };
10494
10495 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10496         .f = cmd_flow_director_filter_parsed,
10497         .data = NULL,
10498         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10499                 "director entry on NIC",
10500         .tokens = {
10501                 (void *)&cmd_flow_director_filter,
10502                 (void *)&cmd_flow_director_port_id,
10503                 (void *)&cmd_flow_director_mode,
10504                 (void *)&cmd_flow_director_mode_ip,
10505                 (void *)&cmd_flow_director_ops,
10506                 (void *)&cmd_flow_director_flow,
10507                 (void *)&cmd_flow_director_flow_type,
10508                 (void *)&cmd_flow_director_src,
10509                 (void *)&cmd_flow_director_ip_src,
10510                 (void *)&cmd_flow_director_port_src,
10511                 (void *)&cmd_flow_director_dst,
10512                 (void *)&cmd_flow_director_ip_dst,
10513                 (void *)&cmd_flow_director_port_dst,
10514                 (void *)&cmd_flow_director_tos,
10515                 (void *)&cmd_flow_director_tos_value,
10516                 (void *)&cmd_flow_director_ttl,
10517                 (void *)&cmd_flow_director_ttl_value,
10518                 (void *)&cmd_flow_director_vlan,
10519                 (void *)&cmd_flow_director_vlan_value,
10520                 (void *)&cmd_flow_director_flexbytes,
10521                 (void *)&cmd_flow_director_flexbytes_value,
10522                 (void *)&cmd_flow_director_drop,
10523                 (void *)&cmd_flow_director_pf_vf,
10524                 (void *)&cmd_flow_director_queue,
10525                 (void *)&cmd_flow_director_queue_id,
10526                 (void *)&cmd_flow_director_fd_id,
10527                 (void *)&cmd_flow_director_fd_id_value,
10528                 NULL,
10529         },
10530 };
10531
10532 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10533         .f = cmd_flow_director_filter_parsed,
10534         .data = NULL,
10535         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10536                 "director entry on NIC",
10537         .tokens = {
10538                 (void *)&cmd_flow_director_filter,
10539                 (void *)&cmd_flow_director_port_id,
10540                 (void *)&cmd_flow_director_mode,
10541                 (void *)&cmd_flow_director_mode_ip,
10542                 (void *)&cmd_flow_director_ops,
10543                 (void *)&cmd_flow_director_flow,
10544                 (void *)&cmd_flow_director_flow_type,
10545                 (void *)&cmd_flow_director_src,
10546                 (void *)&cmd_flow_director_ip_src,
10547                 (void *)&cmd_flow_director_port_dst,
10548                 (void *)&cmd_flow_director_dst,
10549                 (void *)&cmd_flow_director_ip_dst,
10550                 (void *)&cmd_flow_director_port_dst,
10551                 (void *)&cmd_flow_director_verify_tag,
10552                 (void *)&cmd_flow_director_verify_tag_value,
10553                 (void *)&cmd_flow_director_tos,
10554                 (void *)&cmd_flow_director_tos_value,
10555                 (void *)&cmd_flow_director_ttl,
10556                 (void *)&cmd_flow_director_ttl_value,
10557                 (void *)&cmd_flow_director_vlan,
10558                 (void *)&cmd_flow_director_vlan_value,
10559                 (void *)&cmd_flow_director_flexbytes,
10560                 (void *)&cmd_flow_director_flexbytes_value,
10561                 (void *)&cmd_flow_director_drop,
10562                 (void *)&cmd_flow_director_pf_vf,
10563                 (void *)&cmd_flow_director_queue,
10564                 (void *)&cmd_flow_director_queue_id,
10565                 (void *)&cmd_flow_director_fd_id,
10566                 (void *)&cmd_flow_director_fd_id_value,
10567                 NULL,
10568         },
10569 };
10570
10571 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10572         .f = cmd_flow_director_filter_parsed,
10573         .data = NULL,
10574         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10575                 "director entry on NIC",
10576         .tokens = {
10577                 (void *)&cmd_flow_director_filter,
10578                 (void *)&cmd_flow_director_port_id,
10579                 (void *)&cmd_flow_director_mode,
10580                 (void *)&cmd_flow_director_mode_ip,
10581                 (void *)&cmd_flow_director_ops,
10582                 (void *)&cmd_flow_director_flow,
10583                 (void *)&cmd_flow_director_flow_type,
10584                 (void *)&cmd_flow_director_ether,
10585                 (void *)&cmd_flow_director_ether_type,
10586                 (void *)&cmd_flow_director_flexbytes,
10587                 (void *)&cmd_flow_director_flexbytes_value,
10588                 (void *)&cmd_flow_director_drop,
10589                 (void *)&cmd_flow_director_pf_vf,
10590                 (void *)&cmd_flow_director_queue,
10591                 (void *)&cmd_flow_director_queue_id,
10592                 (void *)&cmd_flow_director_fd_id,
10593                 (void *)&cmd_flow_director_fd_id_value,
10594                 NULL,
10595         },
10596 };
10597
10598 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10599         .f = cmd_flow_director_filter_parsed,
10600         .data = NULL,
10601         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10602                 "director entry on NIC",
10603         .tokens = {
10604                 (void *)&cmd_flow_director_filter,
10605                 (void *)&cmd_flow_director_port_id,
10606                 (void *)&cmd_flow_director_mode,
10607                 (void *)&cmd_flow_director_mode_mac_vlan,
10608                 (void *)&cmd_flow_director_ops,
10609                 (void *)&cmd_flow_director_mac,
10610                 (void *)&cmd_flow_director_mac_addr,
10611                 (void *)&cmd_flow_director_vlan,
10612                 (void *)&cmd_flow_director_vlan_value,
10613                 (void *)&cmd_flow_director_flexbytes,
10614                 (void *)&cmd_flow_director_flexbytes_value,
10615                 (void *)&cmd_flow_director_drop,
10616                 (void *)&cmd_flow_director_queue,
10617                 (void *)&cmd_flow_director_queue_id,
10618                 (void *)&cmd_flow_director_fd_id,
10619                 (void *)&cmd_flow_director_fd_id_value,
10620                 NULL,
10621         },
10622 };
10623
10624 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10625         .f = cmd_flow_director_filter_parsed,
10626         .data = NULL,
10627         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10628                 "director entry on NIC",
10629         .tokens = {
10630                 (void *)&cmd_flow_director_filter,
10631                 (void *)&cmd_flow_director_port_id,
10632                 (void *)&cmd_flow_director_mode,
10633                 (void *)&cmd_flow_director_mode_tunnel,
10634                 (void *)&cmd_flow_director_ops,
10635                 (void *)&cmd_flow_director_mac,
10636                 (void *)&cmd_flow_director_mac_addr,
10637                 (void *)&cmd_flow_director_vlan,
10638                 (void *)&cmd_flow_director_vlan_value,
10639                 (void *)&cmd_flow_director_tunnel,
10640                 (void *)&cmd_flow_director_tunnel_type,
10641                 (void *)&cmd_flow_director_tunnel_id,
10642                 (void *)&cmd_flow_director_tunnel_id_value,
10643                 (void *)&cmd_flow_director_flexbytes,
10644                 (void *)&cmd_flow_director_flexbytes_value,
10645                 (void *)&cmd_flow_director_drop,
10646                 (void *)&cmd_flow_director_queue,
10647                 (void *)&cmd_flow_director_queue_id,
10648                 (void *)&cmd_flow_director_fd_id,
10649                 (void *)&cmd_flow_director_fd_id_value,
10650                 NULL,
10651         },
10652 };
10653
10654 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10655         .f = cmd_flow_director_filter_parsed,
10656         .data = NULL,
10657         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10658                 "director entry on NIC",
10659         .tokens = {
10660                 (void *)&cmd_flow_director_filter,
10661                 (void *)&cmd_flow_director_port_id,
10662                 (void *)&cmd_flow_director_mode,
10663                 (void *)&cmd_flow_director_mode_raw,
10664                 (void *)&cmd_flow_director_ops,
10665                 (void *)&cmd_flow_director_flow,
10666                 (void *)&cmd_flow_director_flow_type,
10667                 (void *)&cmd_flow_director_drop,
10668                 (void *)&cmd_flow_director_queue,
10669                 (void *)&cmd_flow_director_queue_id,
10670                 (void *)&cmd_flow_director_fd_id,
10671                 (void *)&cmd_flow_director_fd_id_value,
10672                 (void *)&cmd_flow_director_packet,
10673                 (void *)&cmd_flow_director_filepath,
10674                 NULL,
10675         },
10676 };
10677
10678 struct cmd_flush_flow_director_result {
10679         cmdline_fixed_string_t flush_flow_director;
10680         portid_t port_id;
10681 };
10682
10683 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10684         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10685                                  flush_flow_director, "flush_flow_director");
10686 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10687         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10688                               port_id, UINT16);
10689
10690 static void
10691 cmd_flush_flow_director_parsed(void *parsed_result,
10692                           __attribute__((unused)) struct cmdline *cl,
10693                           __attribute__((unused)) void *data)
10694 {
10695         struct cmd_flow_director_result *res = parsed_result;
10696         int ret = 0;
10697
10698         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10699         if (ret < 0) {
10700                 printf("flow director is not supported on port %u.\n",
10701                         res->port_id);
10702                 return;
10703         }
10704
10705         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10706                         RTE_ETH_FILTER_FLUSH, NULL);
10707         if (ret < 0)
10708                 printf("flow director table flushing error: (%s)\n",
10709                         strerror(-ret));
10710 }
10711
10712 cmdline_parse_inst_t cmd_flush_flow_director = {
10713         .f = cmd_flush_flow_director_parsed,
10714         .data = NULL,
10715         .help_str = "flush_flow_director <port_id>: "
10716                 "Flush all flow director entries of a device on NIC",
10717         .tokens = {
10718                 (void *)&cmd_flush_flow_director_flush,
10719                 (void *)&cmd_flush_flow_director_port_id,
10720                 NULL,
10721         },
10722 };
10723
10724 /* *** deal with flow director mask *** */
10725 struct cmd_flow_director_mask_result {
10726         cmdline_fixed_string_t flow_director_mask;
10727         portid_t port_id;
10728         cmdline_fixed_string_t mode;
10729         cmdline_fixed_string_t mode_value;
10730         cmdline_fixed_string_t vlan;
10731         uint16_t vlan_mask;
10732         cmdline_fixed_string_t src_mask;
10733         cmdline_ipaddr_t ipv4_src;
10734         cmdline_ipaddr_t ipv6_src;
10735         uint16_t port_src;
10736         cmdline_fixed_string_t dst_mask;
10737         cmdline_ipaddr_t ipv4_dst;
10738         cmdline_ipaddr_t ipv6_dst;
10739         uint16_t port_dst;
10740         cmdline_fixed_string_t mac;
10741         uint8_t mac_addr_byte_mask;
10742         cmdline_fixed_string_t tunnel_id;
10743         uint32_t tunnel_id_mask;
10744         cmdline_fixed_string_t tunnel_type;
10745         uint8_t tunnel_type_mask;
10746 };
10747
10748 static void
10749 cmd_flow_director_mask_parsed(void *parsed_result,
10750                           __attribute__((unused)) struct cmdline *cl,
10751                           __attribute__((unused)) void *data)
10752 {
10753         struct cmd_flow_director_mask_result *res = parsed_result;
10754         struct rte_eth_fdir_masks *mask;
10755         struct rte_port *port;
10756
10757         if (res->port_id > nb_ports) {
10758                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10759                 return;
10760         }
10761
10762         port = &ports[res->port_id];
10763         /** Check if the port is not started **/
10764         if (port->port_status != RTE_PORT_STOPPED) {
10765                 printf("Please stop port %d first\n", res->port_id);
10766                 return;
10767         }
10768
10769         mask = &port->dev_conf.fdir_conf.mask;
10770
10771         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10772                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10773                         printf("Please set mode to MAC-VLAN.\n");
10774                         return;
10775                 }
10776
10777                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10778         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10779                 if (strcmp(res->mode_value, "Tunnel")) {
10780                         printf("Please set mode to Tunnel.\n");
10781                         return;
10782                 }
10783
10784                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10785                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10786                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10787                 mask->tunnel_type_mask = res->tunnel_type_mask;
10788         } else {
10789                 if (strcmp(res->mode_value, "IP")) {
10790                         printf("Please set mode to IP.\n");
10791                         return;
10792                 }
10793
10794                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10795                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10796                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10797                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10798                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10799                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10800                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10801         }
10802
10803         cmd_reconfig_device_queue(res->port_id, 1, 1);
10804 }
10805
10806 cmdline_parse_token_string_t cmd_flow_director_mask =
10807         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10808                                  flow_director_mask, "flow_director_mask");
10809 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10810         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10811                               port_id, UINT16);
10812 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10813         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10814                                  vlan, "vlan");
10815 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10816         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10817                               vlan_mask, UINT16);
10818 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10819         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10820                                  src_mask, "src_mask");
10821 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10822         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10823                                  ipv4_src);
10824 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10825         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10826                                  ipv6_src);
10827 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10828         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10829                               port_src, UINT16);
10830 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10831         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10832                                  dst_mask, "dst_mask");
10833 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10834         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10835                                  ipv4_dst);
10836 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10837         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10838                                  ipv6_dst);
10839 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10840         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10841                               port_dst, UINT16);
10842
10843 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10844         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10845                                  mode, "mode");
10846 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10847         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10848                                  mode_value, "IP");
10849 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10851                                  mode_value, "MAC-VLAN");
10852 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10853         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10854                                  mode_value, "Tunnel");
10855 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10857                                  mac, "mac");
10858 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10859         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10860                               mac_addr_byte_mask, UINT8);
10861 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10863                                  tunnel_type, "tunnel-type");
10864 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10865         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10866                               tunnel_type_mask, UINT8);
10867 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10869                                  tunnel_id, "tunnel-id");
10870 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10871         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10872                               tunnel_id_mask, UINT32);
10873
10874 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10875         .f = cmd_flow_director_mask_parsed,
10876         .data = NULL,
10877         .help_str = "flow_director_mask ... : "
10878                 "Set IP mode flow director's mask on NIC",
10879         .tokens = {
10880                 (void *)&cmd_flow_director_mask,
10881                 (void *)&cmd_flow_director_mask_port_id,
10882                 (void *)&cmd_flow_director_mask_mode,
10883                 (void *)&cmd_flow_director_mask_mode_ip,
10884                 (void *)&cmd_flow_director_mask_vlan,
10885                 (void *)&cmd_flow_director_mask_vlan_value,
10886                 (void *)&cmd_flow_director_mask_src,
10887                 (void *)&cmd_flow_director_mask_ipv4_src,
10888                 (void *)&cmd_flow_director_mask_ipv6_src,
10889                 (void *)&cmd_flow_director_mask_port_src,
10890                 (void *)&cmd_flow_director_mask_dst,
10891                 (void *)&cmd_flow_director_mask_ipv4_dst,
10892                 (void *)&cmd_flow_director_mask_ipv6_dst,
10893                 (void *)&cmd_flow_director_mask_port_dst,
10894                 NULL,
10895         },
10896 };
10897
10898 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10899         .f = cmd_flow_director_mask_parsed,
10900         .data = NULL,
10901         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10902                 "flow director's mask on NIC",
10903         .tokens = {
10904                 (void *)&cmd_flow_director_mask,
10905                 (void *)&cmd_flow_director_mask_port_id,
10906                 (void *)&cmd_flow_director_mask_mode,
10907                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10908                 (void *)&cmd_flow_director_mask_vlan,
10909                 (void *)&cmd_flow_director_mask_vlan_value,
10910                 NULL,
10911         },
10912 };
10913
10914 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10915         .f = cmd_flow_director_mask_parsed,
10916         .data = NULL,
10917         .help_str = "flow_director_mask ... : Set tunnel mode "
10918                 "flow director's mask on NIC",
10919         .tokens = {
10920                 (void *)&cmd_flow_director_mask,
10921                 (void *)&cmd_flow_director_mask_port_id,
10922                 (void *)&cmd_flow_director_mask_mode,
10923                 (void *)&cmd_flow_director_mask_mode_tunnel,
10924                 (void *)&cmd_flow_director_mask_vlan,
10925                 (void *)&cmd_flow_director_mask_vlan_value,
10926                 (void *)&cmd_flow_director_mask_mac,
10927                 (void *)&cmd_flow_director_mask_mac_value,
10928                 (void *)&cmd_flow_director_mask_tunnel_type,
10929                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10930                 (void *)&cmd_flow_director_mask_tunnel_id,
10931                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10932                 NULL,
10933         },
10934 };
10935
10936 /* *** deal with flow director mask on flexible payload *** */
10937 struct cmd_flow_director_flex_mask_result {
10938         cmdline_fixed_string_t flow_director_flexmask;
10939         portid_t port_id;
10940         cmdline_fixed_string_t flow;
10941         cmdline_fixed_string_t flow_type;
10942         cmdline_fixed_string_t mask;
10943 };
10944
10945 static void
10946 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10947                           __attribute__((unused)) struct cmdline *cl,
10948                           __attribute__((unused)) void *data)
10949 {
10950         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10951         struct rte_eth_fdir_info fdir_info;
10952         struct rte_eth_fdir_flex_mask flex_mask;
10953         struct rte_port *port;
10954         uint64_t flow_type_mask;
10955         uint16_t i;
10956         int ret;
10957
10958         if (res->port_id > nb_ports) {
10959                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10960                 return;
10961         }
10962
10963         port = &ports[res->port_id];
10964         /** Check if the port is not started **/
10965         if (port->port_status != RTE_PORT_STOPPED) {
10966                 printf("Please stop port %d first\n", res->port_id);
10967                 return;
10968         }
10969
10970         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10971         ret = parse_flexbytes(res->mask,
10972                         flex_mask.mask,
10973                         RTE_ETH_FDIR_MAX_FLEXLEN);
10974         if (ret < 0) {
10975                 printf("error: Cannot parse mask input.\n");
10976                 return;
10977         }
10978
10979         memset(&fdir_info, 0, sizeof(fdir_info));
10980         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10981                                 RTE_ETH_FILTER_INFO, &fdir_info);
10982         if (ret < 0) {
10983                 printf("Cannot get FDir filter info\n");
10984                 return;
10985         }
10986
10987         if (!strcmp(res->flow_type, "none")) {
10988                 /* means don't specify the flow type */
10989                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10990                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10991                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10992                                0, sizeof(struct rte_eth_fdir_flex_mask));
10993                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10994                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10995                                  &flex_mask,
10996                                  sizeof(struct rte_eth_fdir_flex_mask));
10997                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10998                 return;
10999         }
11000         flow_type_mask = fdir_info.flow_types_mask[0];
11001         if (!strcmp(res->flow_type, "all")) {
11002                 if (!flow_type_mask) {
11003                         printf("No flow type supported\n");
11004                         return;
11005                 }
11006                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11007                         if (flow_type_mask & (1ULL << i)) {
11008                                 flex_mask.flow_type = i;
11009                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11010                         }
11011                 }
11012                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11013                 return;
11014         }
11015         flex_mask.flow_type = str2flowtype(res->flow_type);
11016         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11017                 printf("Flow type %s not supported on port %d\n",
11018                                 res->flow_type, res->port_id);
11019                 return;
11020         }
11021         fdir_set_flex_mask(res->port_id, &flex_mask);
11022         cmd_reconfig_device_queue(res->port_id, 1, 1);
11023 }
11024
11025 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11026         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11027                                  flow_director_flexmask,
11028                                  "flow_director_flex_mask");
11029 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11030         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11031                               port_id, UINT16);
11032 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11033         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11034                                  flow, "flow");
11035 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11036         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11037                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11038                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11039 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11040         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11041                                  mask, NULL);
11042
11043 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11044         .f = cmd_flow_director_flex_mask_parsed,
11045         .data = NULL,
11046         .help_str = "flow_director_flex_mask ... : "
11047                 "Set flow director's flex mask on NIC",
11048         .tokens = {
11049                 (void *)&cmd_flow_director_flexmask,
11050                 (void *)&cmd_flow_director_flexmask_port_id,
11051                 (void *)&cmd_flow_director_flexmask_flow,
11052                 (void *)&cmd_flow_director_flexmask_flow_type,
11053                 (void *)&cmd_flow_director_flexmask_mask,
11054                 NULL,
11055         },
11056 };
11057
11058 /* *** deal with flow director flexible payload configuration *** */
11059 struct cmd_flow_director_flexpayload_result {
11060         cmdline_fixed_string_t flow_director_flexpayload;
11061         portid_t port_id;
11062         cmdline_fixed_string_t payload_layer;
11063         cmdline_fixed_string_t payload_cfg;
11064 };
11065
11066 static inline int
11067 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11068 {
11069         char s[256];
11070         const char *p, *p0 = q_arg;
11071         char *end;
11072         unsigned long int_fld;
11073         char *str_fld[max_num];
11074         int i;
11075         unsigned size;
11076         int ret = -1;
11077
11078         p = strchr(p0, '(');
11079         if (p == NULL)
11080                 return -1;
11081         ++p;
11082         p0 = strchr(p, ')');
11083         if (p0 == NULL)
11084                 return -1;
11085
11086         size = p0 - p;
11087         if (size >= sizeof(s))
11088                 return -1;
11089
11090         snprintf(s, sizeof(s), "%.*s", size, p);
11091         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11092         if (ret < 0 || ret > max_num)
11093                 return -1;
11094         for (i = 0; i < ret; i++) {
11095                 errno = 0;
11096                 int_fld = strtoul(str_fld[i], &end, 0);
11097                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11098                         return -1;
11099                 offsets[i] = (uint16_t)int_fld;
11100         }
11101         return ret;
11102 }
11103
11104 static void
11105 cmd_flow_director_flxpld_parsed(void *parsed_result,
11106                           __attribute__((unused)) struct cmdline *cl,
11107                           __attribute__((unused)) void *data)
11108 {
11109         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11110         struct rte_eth_flex_payload_cfg flex_cfg;
11111         struct rte_port *port;
11112         int ret = 0;
11113
11114         if (res->port_id > nb_ports) {
11115                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11116                 return;
11117         }
11118
11119         port = &ports[res->port_id];
11120         /** Check if the port is not started **/
11121         if (port->port_status != RTE_PORT_STOPPED) {
11122                 printf("Please stop port %d first\n", res->port_id);
11123                 return;
11124         }
11125
11126         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11127
11128         if (!strcmp(res->payload_layer, "raw"))
11129                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11130         else if (!strcmp(res->payload_layer, "l2"))
11131                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11132         else if (!strcmp(res->payload_layer, "l3"))
11133                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11134         else if (!strcmp(res->payload_layer, "l4"))
11135                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11136
11137         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11138                             RTE_ETH_FDIR_MAX_FLEXLEN);
11139         if (ret < 0) {
11140                 printf("error: Cannot parse flex payload input.\n");
11141                 return;
11142         }
11143
11144         fdir_set_flex_payload(res->port_id, &flex_cfg);
11145         cmd_reconfig_device_queue(res->port_id, 1, 1);
11146 }
11147
11148 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11150                                  flow_director_flexpayload,
11151                                  "flow_director_flex_payload");
11152 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11153         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11154                               port_id, UINT16);
11155 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11156         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11157                                  payload_layer, "raw#l2#l3#l4");
11158 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11159         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11160                                  payload_cfg, NULL);
11161
11162 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11163         .f = cmd_flow_director_flxpld_parsed,
11164         .data = NULL,
11165         .help_str = "flow_director_flexpayload ... : "
11166                 "Set flow director's flex payload on NIC",
11167         .tokens = {
11168                 (void *)&cmd_flow_director_flexpayload,
11169                 (void *)&cmd_flow_director_flexpayload_port_id,
11170                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11171                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11172                 NULL,
11173         },
11174 };
11175
11176 /* Generic flow interface command. */
11177 extern cmdline_parse_inst_t cmd_flow;
11178
11179 /* *** Classification Filters Control *** */
11180 /* *** Get symmetric hash enable per port *** */
11181 struct cmd_get_sym_hash_ena_per_port_result {
11182         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11183         portid_t port_id;
11184 };
11185
11186 static void
11187 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11188                                  __rte_unused struct cmdline *cl,
11189                                  __rte_unused void *data)
11190 {
11191         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11192         struct rte_eth_hash_filter_info info;
11193         int ret;
11194
11195         if (rte_eth_dev_filter_supported(res->port_id,
11196                                 RTE_ETH_FILTER_HASH) < 0) {
11197                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11198                                                         res->port_id);
11199                 return;
11200         }
11201
11202         memset(&info, 0, sizeof(info));
11203         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11204         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11205                                                 RTE_ETH_FILTER_GET, &info);
11206
11207         if (ret < 0) {
11208                 printf("Cannot get symmetric hash enable per port "
11209                                         "on port %u\n", res->port_id);
11210                 return;
11211         }
11212
11213         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11214                                 "enabled" : "disabled", res->port_id);
11215 }
11216
11217 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11218         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11219                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11220 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11221         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11222                 port_id, UINT16);
11223
11224 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11225         .f = cmd_get_sym_hash_per_port_parsed,
11226         .data = NULL,
11227         .help_str = "get_sym_hash_ena_per_port <port_id>",
11228         .tokens = {
11229                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11230                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11231                 NULL,
11232         },
11233 };
11234
11235 /* *** Set symmetric hash enable per port *** */
11236 struct cmd_set_sym_hash_ena_per_port_result {
11237         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11238         cmdline_fixed_string_t enable;
11239         portid_t port_id;
11240 };
11241
11242 static void
11243 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11244                                  __rte_unused struct cmdline *cl,
11245                                  __rte_unused void *data)
11246 {
11247         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11248         struct rte_eth_hash_filter_info info;
11249         int ret;
11250
11251         if (rte_eth_dev_filter_supported(res->port_id,
11252                                 RTE_ETH_FILTER_HASH) < 0) {
11253                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11254                                                         res->port_id);
11255                 return;
11256         }
11257
11258         memset(&info, 0, sizeof(info));
11259         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11260         if (!strcmp(res->enable, "enable"))
11261                 info.info.enable = 1;
11262         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11263                                         RTE_ETH_FILTER_SET, &info);
11264         if (ret < 0) {
11265                 printf("Cannot set symmetric hash enable per port on "
11266                                         "port %u\n", res->port_id);
11267                 return;
11268         }
11269         printf("Symmetric hash has been set to %s on port %u\n",
11270                                         res->enable, res->port_id);
11271 }
11272
11273 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11274         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11275                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11276 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11277         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11278                 port_id, UINT16);
11279 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11280         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11281                 enable, "enable#disable");
11282
11283 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11284         .f = cmd_set_sym_hash_per_port_parsed,
11285         .data = NULL,
11286         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11287         .tokens = {
11288                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11289                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11290                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11291                 NULL,
11292         },
11293 };
11294
11295 /* Get global config of hash function */
11296 struct cmd_get_hash_global_config_result {
11297         cmdline_fixed_string_t get_hash_global_config;
11298         portid_t port_id;
11299 };
11300
11301 static char *
11302 flowtype_to_str(uint16_t ftype)
11303 {
11304         uint16_t i;
11305         static struct {
11306                 char str[16];
11307                 uint16_t ftype;
11308         } ftype_table[] = {
11309                 {"ipv4", RTE_ETH_FLOW_IPV4},
11310                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11311                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11312                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11313                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11314                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11315                 {"ipv6", RTE_ETH_FLOW_IPV6},
11316                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11317                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11318                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11319                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11320                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11321                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11322                 {"port", RTE_ETH_FLOW_PORT},
11323                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11324                 {"geneve", RTE_ETH_FLOW_GENEVE},
11325                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11326         };
11327
11328         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11329                 if (ftype_table[i].ftype == ftype)
11330                         return ftype_table[i].str;
11331         }
11332
11333         return NULL;
11334 }
11335
11336 static void
11337 cmd_get_hash_global_config_parsed(void *parsed_result,
11338                                   __rte_unused struct cmdline *cl,
11339                                   __rte_unused void *data)
11340 {
11341         struct cmd_get_hash_global_config_result *res = parsed_result;
11342         struct rte_eth_hash_filter_info info;
11343         uint32_t idx, offset;
11344         uint16_t i;
11345         char *str;
11346         int ret;
11347
11348         if (rte_eth_dev_filter_supported(res->port_id,
11349                         RTE_ETH_FILTER_HASH) < 0) {
11350                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11351                                                         res->port_id);
11352                 return;
11353         }
11354
11355         memset(&info, 0, sizeof(info));
11356         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11357         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11358                                         RTE_ETH_FILTER_GET, &info);
11359         if (ret < 0) {
11360                 printf("Cannot get hash global configurations by port %d\n",
11361                                                         res->port_id);
11362                 return;
11363         }
11364
11365         switch (info.info.global_conf.hash_func) {
11366         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11367                 printf("Hash function is Toeplitz\n");
11368                 break;
11369         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11370                 printf("Hash function is Simple XOR\n");
11371                 break;
11372         default:
11373                 printf("Unknown hash function\n");
11374                 break;
11375         }
11376
11377         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11378                 idx = i / UINT64_BIT;
11379                 offset = i % UINT64_BIT;
11380                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11381                                                 (1ULL << offset)))
11382                         continue;
11383                 str = flowtype_to_str(i);
11384                 if (!str)
11385                         continue;
11386                 printf("Symmetric hash is %s globally for flow type %s "
11387                                                         "by port %d\n",
11388                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11389                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11390                                                         res->port_id);
11391         }
11392 }
11393
11394 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11395         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11396                 get_hash_global_config, "get_hash_global_config");
11397 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11398         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11399                 port_id, UINT16);
11400
11401 cmdline_parse_inst_t cmd_get_hash_global_config = {
11402         .f = cmd_get_hash_global_config_parsed,
11403         .data = NULL,
11404         .help_str = "get_hash_global_config <port_id>",
11405         .tokens = {
11406                 (void *)&cmd_get_hash_global_config_all,
11407                 (void *)&cmd_get_hash_global_config_port_id,
11408                 NULL,
11409         },
11410 };
11411
11412 /* Set global config of hash function */
11413 struct cmd_set_hash_global_config_result {
11414         cmdline_fixed_string_t set_hash_global_config;
11415         portid_t port_id;
11416         cmdline_fixed_string_t hash_func;
11417         cmdline_fixed_string_t flow_type;
11418         cmdline_fixed_string_t enable;
11419 };
11420
11421 static void
11422 cmd_set_hash_global_config_parsed(void *parsed_result,
11423                                   __rte_unused struct cmdline *cl,
11424                                   __rte_unused void *data)
11425 {
11426         struct cmd_set_hash_global_config_result *res = parsed_result;
11427         struct rte_eth_hash_filter_info info;
11428         uint32_t ftype, idx, offset;
11429         int ret;
11430
11431         if (rte_eth_dev_filter_supported(res->port_id,
11432                                 RTE_ETH_FILTER_HASH) < 0) {
11433                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11434                                                         res->port_id);
11435                 return;
11436         }
11437         memset(&info, 0, sizeof(info));
11438         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11439         if (!strcmp(res->hash_func, "toeplitz"))
11440                 info.info.global_conf.hash_func =
11441                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11442         else if (!strcmp(res->hash_func, "simple_xor"))
11443                 info.info.global_conf.hash_func =
11444                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11445         else if (!strcmp(res->hash_func, "default"))
11446                 info.info.global_conf.hash_func =
11447                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11448
11449         ftype = str2flowtype(res->flow_type);
11450         idx = ftype / UINT64_BIT;
11451         offset = ftype % UINT64_BIT;
11452         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11453         if (!strcmp(res->enable, "enable"))
11454                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11455                                                 (1ULL << offset);
11456         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11457                                         RTE_ETH_FILTER_SET, &info);
11458         if (ret < 0)
11459                 printf("Cannot set global hash configurations by port %d\n",
11460                                                         res->port_id);
11461         else
11462                 printf("Global hash configurations have been set "
11463                         "succcessfully by port %d\n", res->port_id);
11464 }
11465
11466 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11467         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11468                 set_hash_global_config, "set_hash_global_config");
11469 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11470         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11471                 port_id, UINT16);
11472 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11473         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11474                 hash_func, "toeplitz#simple_xor#default");
11475 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11476         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11477                 flow_type,
11478                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11479                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11480 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11481         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11482                 enable, "enable#disable");
11483
11484 cmdline_parse_inst_t cmd_set_hash_global_config = {
11485         .f = cmd_set_hash_global_config_parsed,
11486         .data = NULL,
11487         .help_str = "set_hash_global_config <port_id> "
11488                 "toeplitz|simple_xor|default "
11489                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11490                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11491                 "l2_payload enable|disable",
11492         .tokens = {
11493                 (void *)&cmd_set_hash_global_config_all,
11494                 (void *)&cmd_set_hash_global_config_port_id,
11495                 (void *)&cmd_set_hash_global_config_hash_func,
11496                 (void *)&cmd_set_hash_global_config_flow_type,
11497                 (void *)&cmd_set_hash_global_config_enable,
11498                 NULL,
11499         },
11500 };
11501
11502 /* Set hash input set */
11503 struct cmd_set_hash_input_set_result {
11504         cmdline_fixed_string_t set_hash_input_set;
11505         portid_t port_id;
11506         cmdline_fixed_string_t flow_type;
11507         cmdline_fixed_string_t inset_field;
11508         cmdline_fixed_string_t select;
11509 };
11510
11511 static enum rte_eth_input_set_field
11512 str2inset(char *string)
11513 {
11514         uint16_t i;
11515
11516         static const struct {
11517                 char str[32];
11518                 enum rte_eth_input_set_field inset;
11519         } inset_table[] = {
11520                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11521                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11522                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11523                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11524                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11525                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11526                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11527                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11528                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11529                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11530                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11531                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11532                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11533                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11534                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11535                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11536                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11537                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11538                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11539                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11540                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11541                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11542                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11543                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11544                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11545                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11546                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11547                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11548                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11549                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11550                 {"none", RTE_ETH_INPUT_SET_NONE},
11551         };
11552
11553         for (i = 0; i < RTE_DIM(inset_table); i++) {
11554                 if (!strcmp(string, inset_table[i].str))
11555                         return inset_table[i].inset;
11556         }
11557
11558         return RTE_ETH_INPUT_SET_UNKNOWN;
11559 }
11560
11561 static void
11562 cmd_set_hash_input_set_parsed(void *parsed_result,
11563                               __rte_unused struct cmdline *cl,
11564                               __rte_unused void *data)
11565 {
11566         struct cmd_set_hash_input_set_result *res = parsed_result;
11567         struct rte_eth_hash_filter_info info;
11568
11569         memset(&info, 0, sizeof(info));
11570         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11571         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11572         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11573         info.info.input_set_conf.inset_size = 1;
11574         if (!strcmp(res->select, "select"))
11575                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11576         else if (!strcmp(res->select, "add"))
11577                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11578         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11579                                 RTE_ETH_FILTER_SET, &info);
11580 }
11581
11582 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11583         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11584                 set_hash_input_set, "set_hash_input_set");
11585 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11586         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11587                 port_id, UINT16);
11588 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11589         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11590                 flow_type, NULL);
11591 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11592         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11593                 inset_field,
11594                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11595                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11596                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11597                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11598                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11599                 "fld-8th#none");
11600 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11601         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11602                 select, "select#add");
11603
11604 cmdline_parse_inst_t cmd_set_hash_input_set = {
11605         .f = cmd_set_hash_input_set_parsed,
11606         .data = NULL,
11607         .help_str = "set_hash_input_set <port_id> "
11608         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11609         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11610         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11611         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11612         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11613         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11614         "fld-7th|fld-8th|none select|add",
11615         .tokens = {
11616                 (void *)&cmd_set_hash_input_set_cmd,
11617                 (void *)&cmd_set_hash_input_set_port_id,
11618                 (void *)&cmd_set_hash_input_set_flow_type,
11619                 (void *)&cmd_set_hash_input_set_field,
11620                 (void *)&cmd_set_hash_input_set_select,
11621                 NULL,
11622         },
11623 };
11624
11625 /* Set flow director input set */
11626 struct cmd_set_fdir_input_set_result {
11627         cmdline_fixed_string_t set_fdir_input_set;
11628         portid_t port_id;
11629         cmdline_fixed_string_t flow_type;
11630         cmdline_fixed_string_t inset_field;
11631         cmdline_fixed_string_t select;
11632 };
11633
11634 static void
11635 cmd_set_fdir_input_set_parsed(void *parsed_result,
11636         __rte_unused struct cmdline *cl,
11637         __rte_unused void *data)
11638 {
11639         struct cmd_set_fdir_input_set_result *res = parsed_result;
11640         struct rte_eth_fdir_filter_info info;
11641
11642         memset(&info, 0, sizeof(info));
11643         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11644         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11645         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11646         info.info.input_set_conf.inset_size = 1;
11647         if (!strcmp(res->select, "select"))
11648                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11649         else if (!strcmp(res->select, "add"))
11650                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11651         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11652                 RTE_ETH_FILTER_SET, &info);
11653 }
11654
11655 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11656         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11657         set_fdir_input_set, "set_fdir_input_set");
11658 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11659         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11660         port_id, UINT16);
11661 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11662         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11663         flow_type,
11664         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11665         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11666 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11667         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11668         inset_field,
11669         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11670         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11671         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11672         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11673         "sctp-veri-tag#none");
11674 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11675         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11676         select, "select#add");
11677
11678 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11679         .f = cmd_set_fdir_input_set_parsed,
11680         .data = NULL,
11681         .help_str = "set_fdir_input_set <port_id> "
11682         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11683         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11684         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11685         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11686         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11687         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11688         "sctp-veri-tag|none select|add",
11689         .tokens = {
11690                 (void *)&cmd_set_fdir_input_set_cmd,
11691                 (void *)&cmd_set_fdir_input_set_port_id,
11692                 (void *)&cmd_set_fdir_input_set_flow_type,
11693                 (void *)&cmd_set_fdir_input_set_field,
11694                 (void *)&cmd_set_fdir_input_set_select,
11695                 NULL,
11696         },
11697 };
11698
11699 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11700 struct cmd_mcast_addr_result {
11701         cmdline_fixed_string_t mcast_addr_cmd;
11702         cmdline_fixed_string_t what;
11703         uint16_t port_num;
11704         struct ether_addr mc_addr;
11705 };
11706
11707 static void cmd_mcast_addr_parsed(void *parsed_result,
11708                 __attribute__((unused)) struct cmdline *cl,
11709                 __attribute__((unused)) void *data)
11710 {
11711         struct cmd_mcast_addr_result *res = parsed_result;
11712
11713         if (!is_multicast_ether_addr(&res->mc_addr)) {
11714                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11715                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11716                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11717                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11718                 return;
11719         }
11720         if (strcmp(res->what, "add") == 0)
11721                 mcast_addr_add(res->port_num, &res->mc_addr);
11722         else
11723                 mcast_addr_remove(res->port_num, &res->mc_addr);
11724 }
11725
11726 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11727         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11728                                  mcast_addr_cmd, "mcast_addr");
11729 cmdline_parse_token_string_t cmd_mcast_addr_what =
11730         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11731                                  "add#remove");
11732 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11733         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11734 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11735         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11736
11737 cmdline_parse_inst_t cmd_mcast_addr = {
11738         .f = cmd_mcast_addr_parsed,
11739         .data = (void *)0,
11740         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11741                 "Add/Remove multicast MAC address on port_id",
11742         .tokens = {
11743                 (void *)&cmd_mcast_addr_cmd,
11744                 (void *)&cmd_mcast_addr_what,
11745                 (void *)&cmd_mcast_addr_portnum,
11746                 (void *)&cmd_mcast_addr_addr,
11747                 NULL,
11748         },
11749 };
11750
11751 /* l2 tunnel config
11752  * only support E-tag now.
11753  */
11754
11755 /* Ether type config */
11756 struct cmd_config_l2_tunnel_eth_type_result {
11757         cmdline_fixed_string_t port;
11758         cmdline_fixed_string_t config;
11759         cmdline_fixed_string_t all;
11760         uint8_t id;
11761         cmdline_fixed_string_t l2_tunnel;
11762         cmdline_fixed_string_t l2_tunnel_type;
11763         cmdline_fixed_string_t eth_type;
11764         uint16_t eth_type_val;
11765 };
11766
11767 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11768         TOKEN_STRING_INITIALIZER
11769                 (struct cmd_config_l2_tunnel_eth_type_result,
11770                  port, "port");
11771 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11772         TOKEN_STRING_INITIALIZER
11773                 (struct cmd_config_l2_tunnel_eth_type_result,
11774                  config, "config");
11775 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11776         TOKEN_STRING_INITIALIZER
11777                 (struct cmd_config_l2_tunnel_eth_type_result,
11778                  all, "all");
11779 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11780         TOKEN_NUM_INITIALIZER
11781                 (struct cmd_config_l2_tunnel_eth_type_result,
11782                  id, UINT8);
11783 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11784         TOKEN_STRING_INITIALIZER
11785                 (struct cmd_config_l2_tunnel_eth_type_result,
11786                  l2_tunnel, "l2-tunnel");
11787 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11788         TOKEN_STRING_INITIALIZER
11789                 (struct cmd_config_l2_tunnel_eth_type_result,
11790                  l2_tunnel_type, "E-tag");
11791 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11792         TOKEN_STRING_INITIALIZER
11793                 (struct cmd_config_l2_tunnel_eth_type_result,
11794                  eth_type, "ether-type");
11795 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11796         TOKEN_NUM_INITIALIZER
11797                 (struct cmd_config_l2_tunnel_eth_type_result,
11798                  eth_type_val, UINT16);
11799
11800 static enum rte_eth_tunnel_type
11801 str2fdir_l2_tunnel_type(char *string)
11802 {
11803         uint32_t i = 0;
11804
11805         static const struct {
11806                 char str[32];
11807                 enum rte_eth_tunnel_type type;
11808         } l2_tunnel_type_str[] = {
11809                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11810         };
11811
11812         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11813                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11814                         return l2_tunnel_type_str[i].type;
11815         }
11816         return RTE_TUNNEL_TYPE_NONE;
11817 }
11818
11819 /* ether type config for all ports */
11820 static void
11821 cmd_config_l2_tunnel_eth_type_all_parsed
11822         (void *parsed_result,
11823          __attribute__((unused)) struct cmdline *cl,
11824          __attribute__((unused)) void *data)
11825 {
11826         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11827         struct rte_eth_l2_tunnel_conf entry;
11828         portid_t pid;
11829
11830         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11831         entry.ether_type = res->eth_type_val;
11832
11833         RTE_ETH_FOREACH_DEV(pid) {
11834                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11835         }
11836 }
11837
11838 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11839         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11840         .data = NULL,
11841         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11842         .tokens = {
11843                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11844                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11845                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11846                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11847                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11848                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11849                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11850                 NULL,
11851         },
11852 };
11853
11854 /* ether type config for a specific port */
11855 static void
11856 cmd_config_l2_tunnel_eth_type_specific_parsed(
11857         void *parsed_result,
11858         __attribute__((unused)) struct cmdline *cl,
11859         __attribute__((unused)) void *data)
11860 {
11861         struct cmd_config_l2_tunnel_eth_type_result *res =
11862                  parsed_result;
11863         struct rte_eth_l2_tunnel_conf entry;
11864
11865         if (port_id_is_invalid(res->id, ENABLED_WARN))
11866                 return;
11867
11868         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11869         entry.ether_type = res->eth_type_val;
11870
11871         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11872 }
11873
11874 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11875         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11876         .data = NULL,
11877         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11878         .tokens = {
11879                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11880                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11881                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11882                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11883                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11884                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11885                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11886                 NULL,
11887         },
11888 };
11889
11890 /* Enable/disable l2 tunnel */
11891 struct cmd_config_l2_tunnel_en_dis_result {
11892         cmdline_fixed_string_t port;
11893         cmdline_fixed_string_t config;
11894         cmdline_fixed_string_t all;
11895         uint8_t id;
11896         cmdline_fixed_string_t l2_tunnel;
11897         cmdline_fixed_string_t l2_tunnel_type;
11898         cmdline_fixed_string_t en_dis;
11899 };
11900
11901 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11902         TOKEN_STRING_INITIALIZER
11903                 (struct cmd_config_l2_tunnel_en_dis_result,
11904                  port, "port");
11905 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11906         TOKEN_STRING_INITIALIZER
11907                 (struct cmd_config_l2_tunnel_en_dis_result,
11908                  config, "config");
11909 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11910         TOKEN_STRING_INITIALIZER
11911                 (struct cmd_config_l2_tunnel_en_dis_result,
11912                  all, "all");
11913 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11914         TOKEN_NUM_INITIALIZER
11915                 (struct cmd_config_l2_tunnel_en_dis_result,
11916                  id, UINT8);
11917 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11918         TOKEN_STRING_INITIALIZER
11919                 (struct cmd_config_l2_tunnel_en_dis_result,
11920                  l2_tunnel, "l2-tunnel");
11921 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11922         TOKEN_STRING_INITIALIZER
11923                 (struct cmd_config_l2_tunnel_en_dis_result,
11924                  l2_tunnel_type, "E-tag");
11925 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11926         TOKEN_STRING_INITIALIZER
11927                 (struct cmd_config_l2_tunnel_en_dis_result,
11928                  en_dis, "enable#disable");
11929
11930 /* enable/disable l2 tunnel for all ports */
11931 static void
11932 cmd_config_l2_tunnel_en_dis_all_parsed(
11933         void *parsed_result,
11934         __attribute__((unused)) struct cmdline *cl,
11935         __attribute__((unused)) void *data)
11936 {
11937         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11938         struct rte_eth_l2_tunnel_conf entry;
11939         portid_t pid;
11940         uint8_t en;
11941
11942         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11943
11944         if (!strcmp("enable", res->en_dis))
11945                 en = 1;
11946         else
11947                 en = 0;
11948
11949         RTE_ETH_FOREACH_DEV(pid) {
11950                 rte_eth_dev_l2_tunnel_offload_set(pid,
11951                                                   &entry,
11952                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11953                                                   en);
11954         }
11955 }
11956
11957 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11958         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11959         .data = NULL,
11960         .help_str = "port config all l2-tunnel E-tag enable|disable",
11961         .tokens = {
11962                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11963                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11964                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11965                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11966                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11967                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11968                 NULL,
11969         },
11970 };
11971
11972 /* enable/disable l2 tunnel for a port */
11973 static void
11974 cmd_config_l2_tunnel_en_dis_specific_parsed(
11975         void *parsed_result,
11976         __attribute__((unused)) struct cmdline *cl,
11977         __attribute__((unused)) void *data)
11978 {
11979         struct cmd_config_l2_tunnel_en_dis_result *res =
11980                 parsed_result;
11981         struct rte_eth_l2_tunnel_conf entry;
11982
11983         if (port_id_is_invalid(res->id, ENABLED_WARN))
11984                 return;
11985
11986         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11987
11988         if (!strcmp("enable", res->en_dis))
11989                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11990                                                   &entry,
11991                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11992                                                   1);
11993         else
11994                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11995                                                   &entry,
11996                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11997                                                   0);
11998 }
11999
12000 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12001         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12002         .data = NULL,
12003         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12004         .tokens = {
12005                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12006                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12007                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12008                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12009                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12010                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12011                 NULL,
12012         },
12013 };
12014
12015 /* E-tag configuration */
12016
12017 /* Common result structure for all E-tag configuration */
12018 struct cmd_config_e_tag_result {
12019         cmdline_fixed_string_t e_tag;
12020         cmdline_fixed_string_t set;
12021         cmdline_fixed_string_t insertion;
12022         cmdline_fixed_string_t stripping;
12023         cmdline_fixed_string_t forwarding;
12024         cmdline_fixed_string_t filter;
12025         cmdline_fixed_string_t add;
12026         cmdline_fixed_string_t del;
12027         cmdline_fixed_string_t on;
12028         cmdline_fixed_string_t off;
12029         cmdline_fixed_string_t on_off;
12030         cmdline_fixed_string_t port_tag_id;
12031         uint32_t port_tag_id_val;
12032         cmdline_fixed_string_t e_tag_id;
12033         uint16_t e_tag_id_val;
12034         cmdline_fixed_string_t dst_pool;
12035         uint8_t dst_pool_val;
12036         cmdline_fixed_string_t port;
12037         portid_t port_id;
12038         cmdline_fixed_string_t vf;
12039         uint8_t vf_id;
12040 };
12041
12042 /* Common CLI fields for all E-tag configuration */
12043 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12044         TOKEN_STRING_INITIALIZER
12045                 (struct cmd_config_e_tag_result,
12046                  e_tag, "E-tag");
12047 cmdline_parse_token_string_t cmd_config_e_tag_set =
12048         TOKEN_STRING_INITIALIZER
12049                 (struct cmd_config_e_tag_result,
12050                  set, "set");
12051 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12052         TOKEN_STRING_INITIALIZER
12053                 (struct cmd_config_e_tag_result,
12054                  insertion, "insertion");
12055 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12056         TOKEN_STRING_INITIALIZER
12057                 (struct cmd_config_e_tag_result,
12058                  stripping, "stripping");
12059 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12060         TOKEN_STRING_INITIALIZER
12061                 (struct cmd_config_e_tag_result,
12062                  forwarding, "forwarding");
12063 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12064         TOKEN_STRING_INITIALIZER
12065                 (struct cmd_config_e_tag_result,
12066                  filter, "filter");
12067 cmdline_parse_token_string_t cmd_config_e_tag_add =
12068         TOKEN_STRING_INITIALIZER
12069                 (struct cmd_config_e_tag_result,
12070                  add, "add");
12071 cmdline_parse_token_string_t cmd_config_e_tag_del =
12072         TOKEN_STRING_INITIALIZER
12073                 (struct cmd_config_e_tag_result,
12074                  del, "del");
12075 cmdline_parse_token_string_t cmd_config_e_tag_on =
12076         TOKEN_STRING_INITIALIZER
12077                 (struct cmd_config_e_tag_result,
12078                  on, "on");
12079 cmdline_parse_token_string_t cmd_config_e_tag_off =
12080         TOKEN_STRING_INITIALIZER
12081                 (struct cmd_config_e_tag_result,
12082                  off, "off");
12083 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12084         TOKEN_STRING_INITIALIZER
12085                 (struct cmd_config_e_tag_result,
12086                  on_off, "on#off");
12087 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12088         TOKEN_STRING_INITIALIZER
12089                 (struct cmd_config_e_tag_result,
12090                  port_tag_id, "port-tag-id");
12091 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12092         TOKEN_NUM_INITIALIZER
12093                 (struct cmd_config_e_tag_result,
12094                  port_tag_id_val, UINT32);
12095 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12096         TOKEN_STRING_INITIALIZER
12097                 (struct cmd_config_e_tag_result,
12098                  e_tag_id, "e-tag-id");
12099 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12100         TOKEN_NUM_INITIALIZER
12101                 (struct cmd_config_e_tag_result,
12102                  e_tag_id_val, UINT16);
12103 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12104         TOKEN_STRING_INITIALIZER
12105                 (struct cmd_config_e_tag_result,
12106                  dst_pool, "dst-pool");
12107 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12108         TOKEN_NUM_INITIALIZER
12109                 (struct cmd_config_e_tag_result,
12110                  dst_pool_val, UINT8);
12111 cmdline_parse_token_string_t cmd_config_e_tag_port =
12112         TOKEN_STRING_INITIALIZER
12113                 (struct cmd_config_e_tag_result,
12114                  port, "port");
12115 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12116         TOKEN_NUM_INITIALIZER
12117                 (struct cmd_config_e_tag_result,
12118                  port_id, UINT16);
12119 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12120         TOKEN_STRING_INITIALIZER
12121                 (struct cmd_config_e_tag_result,
12122                  vf, "vf");
12123 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12124         TOKEN_NUM_INITIALIZER
12125                 (struct cmd_config_e_tag_result,
12126                  vf_id, UINT8);
12127
12128 /* E-tag insertion configuration */
12129 static void
12130 cmd_config_e_tag_insertion_en_parsed(
12131         void *parsed_result,
12132         __attribute__((unused)) struct cmdline *cl,
12133         __attribute__((unused)) void *data)
12134 {
12135         struct cmd_config_e_tag_result *res =
12136                 parsed_result;
12137         struct rte_eth_l2_tunnel_conf entry;
12138
12139         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12140                 return;
12141
12142         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12143         entry.tunnel_id = res->port_tag_id_val;
12144         entry.vf_id = res->vf_id;
12145         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12146                                           &entry,
12147                                           ETH_L2_TUNNEL_INSERTION_MASK,
12148                                           1);
12149 }
12150
12151 static void
12152 cmd_config_e_tag_insertion_dis_parsed(
12153         void *parsed_result,
12154         __attribute__((unused)) struct cmdline *cl,
12155         __attribute__((unused)) void *data)
12156 {
12157         struct cmd_config_e_tag_result *res =
12158                 parsed_result;
12159         struct rte_eth_l2_tunnel_conf entry;
12160
12161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12162                 return;
12163
12164         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12165         entry.vf_id = res->vf_id;
12166
12167         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12168                                           &entry,
12169                                           ETH_L2_TUNNEL_INSERTION_MASK,
12170                                           0);
12171 }
12172
12173 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12174         .f = cmd_config_e_tag_insertion_en_parsed,
12175         .data = NULL,
12176         .help_str = "E-tag ... : E-tag insertion enable",
12177         .tokens = {
12178                 (void *)&cmd_config_e_tag_e_tag,
12179                 (void *)&cmd_config_e_tag_set,
12180                 (void *)&cmd_config_e_tag_insertion,
12181                 (void *)&cmd_config_e_tag_on,
12182                 (void *)&cmd_config_e_tag_port_tag_id,
12183                 (void *)&cmd_config_e_tag_port_tag_id_val,
12184                 (void *)&cmd_config_e_tag_port,
12185                 (void *)&cmd_config_e_tag_port_id,
12186                 (void *)&cmd_config_e_tag_vf,
12187                 (void *)&cmd_config_e_tag_vf_id,
12188                 NULL,
12189         },
12190 };
12191
12192 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12193         .f = cmd_config_e_tag_insertion_dis_parsed,
12194         .data = NULL,
12195         .help_str = "E-tag ... : E-tag insertion disable",
12196         .tokens = {
12197                 (void *)&cmd_config_e_tag_e_tag,
12198                 (void *)&cmd_config_e_tag_set,
12199                 (void *)&cmd_config_e_tag_insertion,
12200                 (void *)&cmd_config_e_tag_off,
12201                 (void *)&cmd_config_e_tag_port,
12202                 (void *)&cmd_config_e_tag_port_id,
12203                 (void *)&cmd_config_e_tag_vf,
12204                 (void *)&cmd_config_e_tag_vf_id,
12205                 NULL,
12206         },
12207 };
12208
12209 /* E-tag stripping configuration */
12210 static void
12211 cmd_config_e_tag_stripping_parsed(
12212         void *parsed_result,
12213         __attribute__((unused)) struct cmdline *cl,
12214         __attribute__((unused)) void *data)
12215 {
12216         struct cmd_config_e_tag_result *res =
12217                 parsed_result;
12218         struct rte_eth_l2_tunnel_conf entry;
12219
12220         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12221                 return;
12222
12223         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12224
12225         if (!strcmp(res->on_off, "on"))
12226                 rte_eth_dev_l2_tunnel_offload_set
12227                         (res->port_id,
12228                          &entry,
12229                          ETH_L2_TUNNEL_STRIPPING_MASK,
12230                          1);
12231         else
12232                 rte_eth_dev_l2_tunnel_offload_set
12233                         (res->port_id,
12234                          &entry,
12235                          ETH_L2_TUNNEL_STRIPPING_MASK,
12236                          0);
12237 }
12238
12239 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12240         .f = cmd_config_e_tag_stripping_parsed,
12241         .data = NULL,
12242         .help_str = "E-tag ... : E-tag stripping enable/disable",
12243         .tokens = {
12244                 (void *)&cmd_config_e_tag_e_tag,
12245                 (void *)&cmd_config_e_tag_set,
12246                 (void *)&cmd_config_e_tag_stripping,
12247                 (void *)&cmd_config_e_tag_on_off,
12248                 (void *)&cmd_config_e_tag_port,
12249                 (void *)&cmd_config_e_tag_port_id,
12250                 NULL,
12251         },
12252 };
12253
12254 /* E-tag forwarding configuration */
12255 static void
12256 cmd_config_e_tag_forwarding_parsed(
12257         void *parsed_result,
12258         __attribute__((unused)) struct cmdline *cl,
12259         __attribute__((unused)) void *data)
12260 {
12261         struct cmd_config_e_tag_result *res = parsed_result;
12262         struct rte_eth_l2_tunnel_conf entry;
12263
12264         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12265                 return;
12266
12267         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12268
12269         if (!strcmp(res->on_off, "on"))
12270                 rte_eth_dev_l2_tunnel_offload_set
12271                         (res->port_id,
12272                          &entry,
12273                          ETH_L2_TUNNEL_FORWARDING_MASK,
12274                          1);
12275         else
12276                 rte_eth_dev_l2_tunnel_offload_set
12277                         (res->port_id,
12278                          &entry,
12279                          ETH_L2_TUNNEL_FORWARDING_MASK,
12280                          0);
12281 }
12282
12283 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12284         .f = cmd_config_e_tag_forwarding_parsed,
12285         .data = NULL,
12286         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12287         .tokens = {
12288                 (void *)&cmd_config_e_tag_e_tag,
12289                 (void *)&cmd_config_e_tag_set,
12290                 (void *)&cmd_config_e_tag_forwarding,
12291                 (void *)&cmd_config_e_tag_on_off,
12292                 (void *)&cmd_config_e_tag_port,
12293                 (void *)&cmd_config_e_tag_port_id,
12294                 NULL,
12295         },
12296 };
12297
12298 /* E-tag filter configuration */
12299 static void
12300 cmd_config_e_tag_filter_add_parsed(
12301         void *parsed_result,
12302         __attribute__((unused)) struct cmdline *cl,
12303         __attribute__((unused)) void *data)
12304 {
12305         struct cmd_config_e_tag_result *res = parsed_result;
12306         struct rte_eth_l2_tunnel_conf entry;
12307         int ret = 0;
12308
12309         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12310                 return;
12311
12312         if (res->e_tag_id_val > 0x3fff) {
12313                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12314                 return;
12315         }
12316
12317         ret = rte_eth_dev_filter_supported(res->port_id,
12318                                            RTE_ETH_FILTER_L2_TUNNEL);
12319         if (ret < 0) {
12320                 printf("E-tag filter is not supported on port %u.\n",
12321                        res->port_id);
12322                 return;
12323         }
12324
12325         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12326         entry.tunnel_id = res->e_tag_id_val;
12327         entry.pool = res->dst_pool_val;
12328
12329         ret = rte_eth_dev_filter_ctrl(res->port_id,
12330                                       RTE_ETH_FILTER_L2_TUNNEL,
12331                                       RTE_ETH_FILTER_ADD,
12332                                       &entry);
12333         if (ret < 0)
12334                 printf("E-tag filter programming error: (%s)\n",
12335                        strerror(-ret));
12336 }
12337
12338 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12339         .f = cmd_config_e_tag_filter_add_parsed,
12340         .data = NULL,
12341         .help_str = "E-tag ... : E-tag filter add",
12342         .tokens = {
12343                 (void *)&cmd_config_e_tag_e_tag,
12344                 (void *)&cmd_config_e_tag_set,
12345                 (void *)&cmd_config_e_tag_filter,
12346                 (void *)&cmd_config_e_tag_add,
12347                 (void *)&cmd_config_e_tag_e_tag_id,
12348                 (void *)&cmd_config_e_tag_e_tag_id_val,
12349                 (void *)&cmd_config_e_tag_dst_pool,
12350                 (void *)&cmd_config_e_tag_dst_pool_val,
12351                 (void *)&cmd_config_e_tag_port,
12352                 (void *)&cmd_config_e_tag_port_id,
12353                 NULL,
12354         },
12355 };
12356
12357 static void
12358 cmd_config_e_tag_filter_del_parsed(
12359         void *parsed_result,
12360         __attribute__((unused)) struct cmdline *cl,
12361         __attribute__((unused)) void *data)
12362 {
12363         struct cmd_config_e_tag_result *res = parsed_result;
12364         struct rte_eth_l2_tunnel_conf entry;
12365         int ret = 0;
12366
12367         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12368                 return;
12369
12370         if (res->e_tag_id_val > 0x3fff) {
12371                 printf("e-tag-id must be less than 0x3fff.\n");
12372                 return;
12373         }
12374
12375         ret = rte_eth_dev_filter_supported(res->port_id,
12376                                            RTE_ETH_FILTER_L2_TUNNEL);
12377         if (ret < 0) {
12378                 printf("E-tag filter is not supported on port %u.\n",
12379                        res->port_id);
12380                 return;
12381         }
12382
12383         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12384         entry.tunnel_id = res->e_tag_id_val;
12385
12386         ret = rte_eth_dev_filter_ctrl(res->port_id,
12387                                       RTE_ETH_FILTER_L2_TUNNEL,
12388                                       RTE_ETH_FILTER_DELETE,
12389                                       &entry);
12390         if (ret < 0)
12391                 printf("E-tag filter programming error: (%s)\n",
12392                        strerror(-ret));
12393 }
12394
12395 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12396         .f = cmd_config_e_tag_filter_del_parsed,
12397         .data = NULL,
12398         .help_str = "E-tag ... : E-tag filter delete",
12399         .tokens = {
12400                 (void *)&cmd_config_e_tag_e_tag,
12401                 (void *)&cmd_config_e_tag_set,
12402                 (void *)&cmd_config_e_tag_filter,
12403                 (void *)&cmd_config_e_tag_del,
12404                 (void *)&cmd_config_e_tag_e_tag_id,
12405                 (void *)&cmd_config_e_tag_e_tag_id_val,
12406                 (void *)&cmd_config_e_tag_port,
12407                 (void *)&cmd_config_e_tag_port_id,
12408                 NULL,
12409         },
12410 };
12411
12412 /* vf vlan anti spoof configuration */
12413
12414 /* Common result structure for vf vlan anti spoof */
12415 struct cmd_vf_vlan_anti_spoof_result {
12416         cmdline_fixed_string_t set;
12417         cmdline_fixed_string_t vf;
12418         cmdline_fixed_string_t vlan;
12419         cmdline_fixed_string_t antispoof;
12420         portid_t port_id;
12421         uint32_t vf_id;
12422         cmdline_fixed_string_t on_off;
12423 };
12424
12425 /* Common CLI fields for vf vlan anti spoof enable disable */
12426 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12427         TOKEN_STRING_INITIALIZER
12428                 (struct cmd_vf_vlan_anti_spoof_result,
12429                  set, "set");
12430 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12431         TOKEN_STRING_INITIALIZER
12432                 (struct cmd_vf_vlan_anti_spoof_result,
12433                  vf, "vf");
12434 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12435         TOKEN_STRING_INITIALIZER
12436                 (struct cmd_vf_vlan_anti_spoof_result,
12437                  vlan, "vlan");
12438 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12439         TOKEN_STRING_INITIALIZER
12440                 (struct cmd_vf_vlan_anti_spoof_result,
12441                  antispoof, "antispoof");
12442 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12443         TOKEN_NUM_INITIALIZER
12444                 (struct cmd_vf_vlan_anti_spoof_result,
12445                  port_id, UINT16);
12446 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12447         TOKEN_NUM_INITIALIZER
12448                 (struct cmd_vf_vlan_anti_spoof_result,
12449                  vf_id, UINT32);
12450 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12451         TOKEN_STRING_INITIALIZER
12452                 (struct cmd_vf_vlan_anti_spoof_result,
12453                  on_off, "on#off");
12454
12455 static void
12456 cmd_set_vf_vlan_anti_spoof_parsed(
12457         void *parsed_result,
12458         __attribute__((unused)) struct cmdline *cl,
12459         __attribute__((unused)) void *data)
12460 {
12461         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12462         int ret = -ENOTSUP;
12463
12464         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12465
12466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12467                 return;
12468
12469 #ifdef RTE_LIBRTE_IXGBE_PMD
12470         if (ret == -ENOTSUP)
12471                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12472                                 res->vf_id, is_on);
12473 #endif
12474 #ifdef RTE_LIBRTE_I40E_PMD
12475         if (ret == -ENOTSUP)
12476                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12477                                 res->vf_id, is_on);
12478 #endif
12479 #ifdef RTE_LIBRTE_BNXT_PMD
12480         if (ret == -ENOTSUP)
12481                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12482                                 res->vf_id, is_on);
12483 #endif
12484
12485         switch (ret) {
12486         case 0:
12487                 break;
12488         case -EINVAL:
12489                 printf("invalid vf_id %d\n", res->vf_id);
12490                 break;
12491         case -ENODEV:
12492                 printf("invalid port_id %d\n", res->port_id);
12493                 break;
12494         case -ENOTSUP:
12495                 printf("function not implemented\n");
12496                 break;
12497         default:
12498                 printf("programming error: (%s)\n", strerror(-ret));
12499         }
12500 }
12501
12502 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12503         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12504         .data = NULL,
12505         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12506         .tokens = {
12507                 (void *)&cmd_vf_vlan_anti_spoof_set,
12508                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12509                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12510                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12511                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12512                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12513                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12514                 NULL,
12515         },
12516 };
12517
12518 /* vf mac anti spoof configuration */
12519
12520 /* Common result structure for vf mac anti spoof */
12521 struct cmd_vf_mac_anti_spoof_result {
12522         cmdline_fixed_string_t set;
12523         cmdline_fixed_string_t vf;
12524         cmdline_fixed_string_t mac;
12525         cmdline_fixed_string_t antispoof;
12526         portid_t port_id;
12527         uint32_t vf_id;
12528         cmdline_fixed_string_t on_off;
12529 };
12530
12531 /* Common CLI fields for vf mac anti spoof enable disable */
12532 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_vf_mac_anti_spoof_result,
12535                  set, "set");
12536 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_vf_mac_anti_spoof_result,
12539                  vf, "vf");
12540 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12541         TOKEN_STRING_INITIALIZER
12542                 (struct cmd_vf_mac_anti_spoof_result,
12543                  mac, "mac");
12544 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12545         TOKEN_STRING_INITIALIZER
12546                 (struct cmd_vf_mac_anti_spoof_result,
12547                  antispoof, "antispoof");
12548 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12549         TOKEN_NUM_INITIALIZER
12550                 (struct cmd_vf_mac_anti_spoof_result,
12551                  port_id, UINT16);
12552 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12553         TOKEN_NUM_INITIALIZER
12554                 (struct cmd_vf_mac_anti_spoof_result,
12555                  vf_id, UINT32);
12556 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12557         TOKEN_STRING_INITIALIZER
12558                 (struct cmd_vf_mac_anti_spoof_result,
12559                  on_off, "on#off");
12560
12561 static void
12562 cmd_set_vf_mac_anti_spoof_parsed(
12563         void *parsed_result,
12564         __attribute__((unused)) struct cmdline *cl,
12565         __attribute__((unused)) void *data)
12566 {
12567         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12568         int ret = -ENOTSUP;
12569
12570         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12571
12572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12573                 return;
12574
12575 #ifdef RTE_LIBRTE_IXGBE_PMD
12576         if (ret == -ENOTSUP)
12577                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12578                         res->vf_id, is_on);
12579 #endif
12580 #ifdef RTE_LIBRTE_I40E_PMD
12581         if (ret == -ENOTSUP)
12582                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12583                         res->vf_id, is_on);
12584 #endif
12585 #ifdef RTE_LIBRTE_BNXT_PMD
12586         if (ret == -ENOTSUP)
12587                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12588                         res->vf_id, is_on);
12589 #endif
12590
12591         switch (ret) {
12592         case 0:
12593                 break;
12594         case -EINVAL:
12595                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12596                 break;
12597         case -ENODEV:
12598                 printf("invalid port_id %d\n", res->port_id);
12599                 break;
12600         case -ENOTSUP:
12601                 printf("function not implemented\n");
12602                 break;
12603         default:
12604                 printf("programming error: (%s)\n", strerror(-ret));
12605         }
12606 }
12607
12608 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12609         .f = cmd_set_vf_mac_anti_spoof_parsed,
12610         .data = NULL,
12611         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12612         .tokens = {
12613                 (void *)&cmd_vf_mac_anti_spoof_set,
12614                 (void *)&cmd_vf_mac_anti_spoof_vf,
12615                 (void *)&cmd_vf_mac_anti_spoof_mac,
12616                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12617                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12618                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12619                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12620                 NULL,
12621         },
12622 };
12623
12624 /* vf vlan strip queue configuration */
12625
12626 /* Common result structure for vf mac anti spoof */
12627 struct cmd_vf_vlan_stripq_result {
12628         cmdline_fixed_string_t set;
12629         cmdline_fixed_string_t vf;
12630         cmdline_fixed_string_t vlan;
12631         cmdline_fixed_string_t stripq;
12632         portid_t port_id;
12633         uint16_t vf_id;
12634         cmdline_fixed_string_t on_off;
12635 };
12636
12637 /* Common CLI fields for vf vlan strip enable disable */
12638 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12639         TOKEN_STRING_INITIALIZER
12640                 (struct cmd_vf_vlan_stripq_result,
12641                  set, "set");
12642 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12643         TOKEN_STRING_INITIALIZER
12644                 (struct cmd_vf_vlan_stripq_result,
12645                  vf, "vf");
12646 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12647         TOKEN_STRING_INITIALIZER
12648                 (struct cmd_vf_vlan_stripq_result,
12649                  vlan, "vlan");
12650 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12651         TOKEN_STRING_INITIALIZER
12652                 (struct cmd_vf_vlan_stripq_result,
12653                  stripq, "stripq");
12654 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12655         TOKEN_NUM_INITIALIZER
12656                 (struct cmd_vf_vlan_stripq_result,
12657                  port_id, UINT16);
12658 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12659         TOKEN_NUM_INITIALIZER
12660                 (struct cmd_vf_vlan_stripq_result,
12661                  vf_id, UINT16);
12662 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12663         TOKEN_STRING_INITIALIZER
12664                 (struct cmd_vf_vlan_stripq_result,
12665                  on_off, "on#off");
12666
12667 static void
12668 cmd_set_vf_vlan_stripq_parsed(
12669         void *parsed_result,
12670         __attribute__((unused)) struct cmdline *cl,
12671         __attribute__((unused)) void *data)
12672 {
12673         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12674         int ret = -ENOTSUP;
12675
12676         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12677
12678         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12679                 return;
12680
12681 #ifdef RTE_LIBRTE_IXGBE_PMD
12682         if (ret == -ENOTSUP)
12683                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12684                         res->vf_id, is_on);
12685 #endif
12686 #ifdef RTE_LIBRTE_I40E_PMD
12687         if (ret == -ENOTSUP)
12688                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12689                         res->vf_id, is_on);
12690 #endif
12691 #ifdef RTE_LIBRTE_BNXT_PMD
12692         if (ret == -ENOTSUP)
12693                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12694                         res->vf_id, is_on);
12695 #endif
12696
12697         switch (ret) {
12698         case 0:
12699                 break;
12700         case -EINVAL:
12701                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12702                 break;
12703         case -ENODEV:
12704                 printf("invalid port_id %d\n", res->port_id);
12705                 break;
12706         case -ENOTSUP:
12707                 printf("function not implemented\n");
12708                 break;
12709         default:
12710                 printf("programming error: (%s)\n", strerror(-ret));
12711         }
12712 }
12713
12714 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12715         .f = cmd_set_vf_vlan_stripq_parsed,
12716         .data = NULL,
12717         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12718         .tokens = {
12719                 (void *)&cmd_vf_vlan_stripq_set,
12720                 (void *)&cmd_vf_vlan_stripq_vf,
12721                 (void *)&cmd_vf_vlan_stripq_vlan,
12722                 (void *)&cmd_vf_vlan_stripq_stripq,
12723                 (void *)&cmd_vf_vlan_stripq_port_id,
12724                 (void *)&cmd_vf_vlan_stripq_vf_id,
12725                 (void *)&cmd_vf_vlan_stripq_on_off,
12726                 NULL,
12727         },
12728 };
12729
12730 /* vf vlan insert configuration */
12731
12732 /* Common result structure for vf vlan insert */
12733 struct cmd_vf_vlan_insert_result {
12734         cmdline_fixed_string_t set;
12735         cmdline_fixed_string_t vf;
12736         cmdline_fixed_string_t vlan;
12737         cmdline_fixed_string_t insert;
12738         portid_t port_id;
12739         uint16_t vf_id;
12740         uint16_t vlan_id;
12741 };
12742
12743 /* Common CLI fields for vf vlan insert enable disable */
12744 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12745         TOKEN_STRING_INITIALIZER
12746                 (struct cmd_vf_vlan_insert_result,
12747                  set, "set");
12748 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12749         TOKEN_STRING_INITIALIZER
12750                 (struct cmd_vf_vlan_insert_result,
12751                  vf, "vf");
12752 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_vf_vlan_insert_result,
12755                  vlan, "vlan");
12756 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_vf_vlan_insert_result,
12759                  insert, "insert");
12760 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12761         TOKEN_NUM_INITIALIZER
12762                 (struct cmd_vf_vlan_insert_result,
12763                  port_id, UINT16);
12764 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12765         TOKEN_NUM_INITIALIZER
12766                 (struct cmd_vf_vlan_insert_result,
12767                  vf_id, UINT16);
12768 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12769         TOKEN_NUM_INITIALIZER
12770                 (struct cmd_vf_vlan_insert_result,
12771                  vlan_id, UINT16);
12772
12773 static void
12774 cmd_set_vf_vlan_insert_parsed(
12775         void *parsed_result,
12776         __attribute__((unused)) struct cmdline *cl,
12777         __attribute__((unused)) void *data)
12778 {
12779         struct cmd_vf_vlan_insert_result *res = parsed_result;
12780         int ret = -ENOTSUP;
12781
12782         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12783                 return;
12784
12785 #ifdef RTE_LIBRTE_IXGBE_PMD
12786         if (ret == -ENOTSUP)
12787                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12788                         res->vlan_id);
12789 #endif
12790 #ifdef RTE_LIBRTE_I40E_PMD
12791         if (ret == -ENOTSUP)
12792                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12793                         res->vlan_id);
12794 #endif
12795 #ifdef RTE_LIBRTE_BNXT_PMD
12796         if (ret == -ENOTSUP)
12797                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12798                         res->vlan_id);
12799 #endif
12800
12801         switch (ret) {
12802         case 0:
12803                 break;
12804         case -EINVAL:
12805                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12806                 break;
12807         case -ENODEV:
12808                 printf("invalid port_id %d\n", res->port_id);
12809                 break;
12810         case -ENOTSUP:
12811                 printf("function not implemented\n");
12812                 break;
12813         default:
12814                 printf("programming error: (%s)\n", strerror(-ret));
12815         }
12816 }
12817
12818 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12819         .f = cmd_set_vf_vlan_insert_parsed,
12820         .data = NULL,
12821         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12822         .tokens = {
12823                 (void *)&cmd_vf_vlan_insert_set,
12824                 (void *)&cmd_vf_vlan_insert_vf,
12825                 (void *)&cmd_vf_vlan_insert_vlan,
12826                 (void *)&cmd_vf_vlan_insert_insert,
12827                 (void *)&cmd_vf_vlan_insert_port_id,
12828                 (void *)&cmd_vf_vlan_insert_vf_id,
12829                 (void *)&cmd_vf_vlan_insert_vlan_id,
12830                 NULL,
12831         },
12832 };
12833
12834 /* tx loopback configuration */
12835
12836 /* Common result structure for tx loopback */
12837 struct cmd_tx_loopback_result {
12838         cmdline_fixed_string_t set;
12839         cmdline_fixed_string_t tx;
12840         cmdline_fixed_string_t loopback;
12841         portid_t port_id;
12842         cmdline_fixed_string_t on_off;
12843 };
12844
12845 /* Common CLI fields for tx loopback enable disable */
12846 cmdline_parse_token_string_t cmd_tx_loopback_set =
12847         TOKEN_STRING_INITIALIZER
12848                 (struct cmd_tx_loopback_result,
12849                  set, "set");
12850 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12851         TOKEN_STRING_INITIALIZER
12852                 (struct cmd_tx_loopback_result,
12853                  tx, "tx");
12854 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12855         TOKEN_STRING_INITIALIZER
12856                 (struct cmd_tx_loopback_result,
12857                  loopback, "loopback");
12858 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12859         TOKEN_NUM_INITIALIZER
12860                 (struct cmd_tx_loopback_result,
12861                  port_id, UINT16);
12862 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_tx_loopback_result,
12865                  on_off, "on#off");
12866
12867 static void
12868 cmd_set_tx_loopback_parsed(
12869         void *parsed_result,
12870         __attribute__((unused)) struct cmdline *cl,
12871         __attribute__((unused)) void *data)
12872 {
12873         struct cmd_tx_loopback_result *res = parsed_result;
12874         int ret = -ENOTSUP;
12875
12876         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12877
12878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12879                 return;
12880
12881 #ifdef RTE_LIBRTE_IXGBE_PMD
12882         if (ret == -ENOTSUP)
12883                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12884 #endif
12885 #ifdef RTE_LIBRTE_I40E_PMD
12886         if (ret == -ENOTSUP)
12887                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12888 #endif
12889 #ifdef RTE_LIBRTE_BNXT_PMD
12890         if (ret == -ENOTSUP)
12891                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12892 #endif
12893 #ifdef RTE_LIBRTE_DPAA_PMD
12894         if (ret == -ENOTSUP)
12895                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12896 #endif
12897
12898         switch (ret) {
12899         case 0:
12900                 break;
12901         case -EINVAL:
12902                 printf("invalid is_on %d\n", is_on);
12903                 break;
12904         case -ENODEV:
12905                 printf("invalid port_id %d\n", res->port_id);
12906                 break;
12907         case -ENOTSUP:
12908                 printf("function not implemented\n");
12909                 break;
12910         default:
12911                 printf("programming error: (%s)\n", strerror(-ret));
12912         }
12913 }
12914
12915 cmdline_parse_inst_t cmd_set_tx_loopback = {
12916         .f = cmd_set_tx_loopback_parsed,
12917         .data = NULL,
12918         .help_str = "set tx loopback <port_id> on|off",
12919         .tokens = {
12920                 (void *)&cmd_tx_loopback_set,
12921                 (void *)&cmd_tx_loopback_tx,
12922                 (void *)&cmd_tx_loopback_loopback,
12923                 (void *)&cmd_tx_loopback_port_id,
12924                 (void *)&cmd_tx_loopback_on_off,
12925                 NULL,
12926         },
12927 };
12928
12929 /* all queues drop enable configuration */
12930
12931 /* Common result structure for all queues drop enable */
12932 struct cmd_all_queues_drop_en_result {
12933         cmdline_fixed_string_t set;
12934         cmdline_fixed_string_t all;
12935         cmdline_fixed_string_t queues;
12936         cmdline_fixed_string_t drop;
12937         portid_t port_id;
12938         cmdline_fixed_string_t on_off;
12939 };
12940
12941 /* Common CLI fields for tx loopback enable disable */
12942 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12943         TOKEN_STRING_INITIALIZER
12944                 (struct cmd_all_queues_drop_en_result,
12945                  set, "set");
12946 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12947         TOKEN_STRING_INITIALIZER
12948                 (struct cmd_all_queues_drop_en_result,
12949                  all, "all");
12950 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12951         TOKEN_STRING_INITIALIZER
12952                 (struct cmd_all_queues_drop_en_result,
12953                  queues, "queues");
12954 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12955         TOKEN_STRING_INITIALIZER
12956                 (struct cmd_all_queues_drop_en_result,
12957                  drop, "drop");
12958 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12959         TOKEN_NUM_INITIALIZER
12960                 (struct cmd_all_queues_drop_en_result,
12961                  port_id, UINT16);
12962 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12963         TOKEN_STRING_INITIALIZER
12964                 (struct cmd_all_queues_drop_en_result,
12965                  on_off, "on#off");
12966
12967 static void
12968 cmd_set_all_queues_drop_en_parsed(
12969         void *parsed_result,
12970         __attribute__((unused)) struct cmdline *cl,
12971         __attribute__((unused)) void *data)
12972 {
12973         struct cmd_all_queues_drop_en_result *res = parsed_result;
12974         int ret = -ENOTSUP;
12975         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12976
12977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12978                 return;
12979
12980 #ifdef RTE_LIBRTE_IXGBE_PMD
12981         if (ret == -ENOTSUP)
12982                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12983 #endif
12984 #ifdef RTE_LIBRTE_BNXT_PMD
12985         if (ret == -ENOTSUP)
12986                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12987 #endif
12988         switch (ret) {
12989         case 0:
12990                 break;
12991         case -EINVAL:
12992                 printf("invalid is_on %d\n", is_on);
12993                 break;
12994         case -ENODEV:
12995                 printf("invalid port_id %d\n", res->port_id);
12996                 break;
12997         case -ENOTSUP:
12998                 printf("function not implemented\n");
12999                 break;
13000         default:
13001                 printf("programming error: (%s)\n", strerror(-ret));
13002         }
13003 }
13004
13005 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13006         .f = cmd_set_all_queues_drop_en_parsed,
13007         .data = NULL,
13008         .help_str = "set all queues drop <port_id> on|off",
13009         .tokens = {
13010                 (void *)&cmd_all_queues_drop_en_set,
13011                 (void *)&cmd_all_queues_drop_en_all,
13012                 (void *)&cmd_all_queues_drop_en_queues,
13013                 (void *)&cmd_all_queues_drop_en_drop,
13014                 (void *)&cmd_all_queues_drop_en_port_id,
13015                 (void *)&cmd_all_queues_drop_en_on_off,
13016                 NULL,
13017         },
13018 };
13019
13020 /* vf split drop enable configuration */
13021
13022 /* Common result structure for vf split drop enable */
13023 struct cmd_vf_split_drop_en_result {
13024         cmdline_fixed_string_t set;
13025         cmdline_fixed_string_t vf;
13026         cmdline_fixed_string_t split;
13027         cmdline_fixed_string_t drop;
13028         portid_t port_id;
13029         uint16_t vf_id;
13030         cmdline_fixed_string_t on_off;
13031 };
13032
13033 /* Common CLI fields for vf split drop enable disable */
13034 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13035         TOKEN_STRING_INITIALIZER
13036                 (struct cmd_vf_split_drop_en_result,
13037                  set, "set");
13038 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13039         TOKEN_STRING_INITIALIZER
13040                 (struct cmd_vf_split_drop_en_result,
13041                  vf, "vf");
13042 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13043         TOKEN_STRING_INITIALIZER
13044                 (struct cmd_vf_split_drop_en_result,
13045                  split, "split");
13046 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13047         TOKEN_STRING_INITIALIZER
13048                 (struct cmd_vf_split_drop_en_result,
13049                  drop, "drop");
13050 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13051         TOKEN_NUM_INITIALIZER
13052                 (struct cmd_vf_split_drop_en_result,
13053                  port_id, UINT16);
13054 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13055         TOKEN_NUM_INITIALIZER
13056                 (struct cmd_vf_split_drop_en_result,
13057                  vf_id, UINT16);
13058 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13059         TOKEN_STRING_INITIALIZER
13060                 (struct cmd_vf_split_drop_en_result,
13061                  on_off, "on#off");
13062
13063 static void
13064 cmd_set_vf_split_drop_en_parsed(
13065         void *parsed_result,
13066         __attribute__((unused)) struct cmdline *cl,
13067         __attribute__((unused)) void *data)
13068 {
13069         struct cmd_vf_split_drop_en_result *res = parsed_result;
13070         int ret = -ENOTSUP;
13071         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13072
13073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13074                 return;
13075
13076 #ifdef RTE_LIBRTE_IXGBE_PMD
13077         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13078                         is_on);
13079 #endif
13080         switch (ret) {
13081         case 0:
13082                 break;
13083         case -EINVAL:
13084                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13085                 break;
13086         case -ENODEV:
13087                 printf("invalid port_id %d\n", res->port_id);
13088                 break;
13089         case -ENOTSUP:
13090                 printf("not supported on port %d\n", res->port_id);
13091                 break;
13092         default:
13093                 printf("programming error: (%s)\n", strerror(-ret));
13094         }
13095 }
13096
13097 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13098         .f = cmd_set_vf_split_drop_en_parsed,
13099         .data = NULL,
13100         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13101         .tokens = {
13102                 (void *)&cmd_vf_split_drop_en_set,
13103                 (void *)&cmd_vf_split_drop_en_vf,
13104                 (void *)&cmd_vf_split_drop_en_split,
13105                 (void *)&cmd_vf_split_drop_en_drop,
13106                 (void *)&cmd_vf_split_drop_en_port_id,
13107                 (void *)&cmd_vf_split_drop_en_vf_id,
13108                 (void *)&cmd_vf_split_drop_en_on_off,
13109                 NULL,
13110         },
13111 };
13112
13113 /* vf mac address configuration */
13114
13115 /* Common result structure for vf mac address */
13116 struct cmd_set_vf_mac_addr_result {
13117         cmdline_fixed_string_t set;
13118         cmdline_fixed_string_t vf;
13119         cmdline_fixed_string_t mac;
13120         cmdline_fixed_string_t addr;
13121         portid_t port_id;
13122         uint16_t vf_id;
13123         struct ether_addr mac_addr;
13124
13125 };
13126
13127 /* Common CLI fields for vf split drop enable disable */
13128 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13129         TOKEN_STRING_INITIALIZER
13130                 (struct cmd_set_vf_mac_addr_result,
13131                  set, "set");
13132 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13133         TOKEN_STRING_INITIALIZER
13134                 (struct cmd_set_vf_mac_addr_result,
13135                  vf, "vf");
13136 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13137         TOKEN_STRING_INITIALIZER
13138                 (struct cmd_set_vf_mac_addr_result,
13139                  mac, "mac");
13140 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13141         TOKEN_STRING_INITIALIZER
13142                 (struct cmd_set_vf_mac_addr_result,
13143                  addr, "addr");
13144 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13145         TOKEN_NUM_INITIALIZER
13146                 (struct cmd_set_vf_mac_addr_result,
13147                  port_id, UINT16);
13148 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13149         TOKEN_NUM_INITIALIZER
13150                 (struct cmd_set_vf_mac_addr_result,
13151                  vf_id, UINT16);
13152 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13153         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13154                  mac_addr);
13155
13156 static void
13157 cmd_set_vf_mac_addr_parsed(
13158         void *parsed_result,
13159         __attribute__((unused)) struct cmdline *cl,
13160         __attribute__((unused)) void *data)
13161 {
13162         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13163         int ret = -ENOTSUP;
13164
13165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13166                 return;
13167
13168 #ifdef RTE_LIBRTE_IXGBE_PMD
13169         if (ret == -ENOTSUP)
13170                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13171                                 &res->mac_addr);
13172 #endif
13173 #ifdef RTE_LIBRTE_I40E_PMD
13174         if (ret == -ENOTSUP)
13175                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13176                                 &res->mac_addr);
13177 #endif
13178 #ifdef RTE_LIBRTE_BNXT_PMD
13179         if (ret == -ENOTSUP)
13180                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13181                                 &res->mac_addr);
13182 #endif
13183
13184         switch (ret) {
13185         case 0:
13186                 break;
13187         case -EINVAL:
13188                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13189                 break;
13190         case -ENODEV:
13191                 printf("invalid port_id %d\n", res->port_id);
13192                 break;
13193         case -ENOTSUP:
13194                 printf("function not implemented\n");
13195                 break;
13196         default:
13197                 printf("programming error: (%s)\n", strerror(-ret));
13198         }
13199 }
13200
13201 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13202         .f = cmd_set_vf_mac_addr_parsed,
13203         .data = NULL,
13204         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13205         .tokens = {
13206                 (void *)&cmd_set_vf_mac_addr_set,
13207                 (void *)&cmd_set_vf_mac_addr_vf,
13208                 (void *)&cmd_set_vf_mac_addr_mac,
13209                 (void *)&cmd_set_vf_mac_addr_addr,
13210                 (void *)&cmd_set_vf_mac_addr_port_id,
13211                 (void *)&cmd_set_vf_mac_addr_vf_id,
13212                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13213                 NULL,
13214         },
13215 };
13216
13217 /* MACsec configuration */
13218
13219 /* Common result structure for MACsec offload enable */
13220 struct cmd_macsec_offload_on_result {
13221         cmdline_fixed_string_t set;
13222         cmdline_fixed_string_t macsec;
13223         cmdline_fixed_string_t offload;
13224         portid_t port_id;
13225         cmdline_fixed_string_t on;
13226         cmdline_fixed_string_t encrypt;
13227         cmdline_fixed_string_t en_on_off;
13228         cmdline_fixed_string_t replay_protect;
13229         cmdline_fixed_string_t rp_on_off;
13230 };
13231
13232 /* Common CLI fields for MACsec offload disable */
13233 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13234         TOKEN_STRING_INITIALIZER
13235                 (struct cmd_macsec_offload_on_result,
13236                  set, "set");
13237 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13238         TOKEN_STRING_INITIALIZER
13239                 (struct cmd_macsec_offload_on_result,
13240                  macsec, "macsec");
13241 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13242         TOKEN_STRING_INITIALIZER
13243                 (struct cmd_macsec_offload_on_result,
13244                  offload, "offload");
13245 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13246         TOKEN_NUM_INITIALIZER
13247                 (struct cmd_macsec_offload_on_result,
13248                  port_id, UINT16);
13249 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13250         TOKEN_STRING_INITIALIZER
13251                 (struct cmd_macsec_offload_on_result,
13252                  on, "on");
13253 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13254         TOKEN_STRING_INITIALIZER
13255                 (struct cmd_macsec_offload_on_result,
13256                  encrypt, "encrypt");
13257 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13258         TOKEN_STRING_INITIALIZER
13259                 (struct cmd_macsec_offload_on_result,
13260                  en_on_off, "on#off");
13261 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13262         TOKEN_STRING_INITIALIZER
13263                 (struct cmd_macsec_offload_on_result,
13264                  replay_protect, "replay-protect");
13265 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13266         TOKEN_STRING_INITIALIZER
13267                 (struct cmd_macsec_offload_on_result,
13268                  rp_on_off, "on#off");
13269
13270 static void
13271 cmd_set_macsec_offload_on_parsed(
13272         void *parsed_result,
13273         __attribute__((unused)) struct cmdline *cl,
13274         __attribute__((unused)) void *data)
13275 {
13276         struct cmd_macsec_offload_on_result *res = parsed_result;
13277         int ret = -ENOTSUP;
13278         portid_t port_id = res->port_id;
13279         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13280         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13281         struct rte_eth_dev_info dev_info;
13282
13283         if (port_id_is_invalid(port_id, ENABLED_WARN))
13284                 return;
13285         if (!port_is_stopped(port_id)) {
13286                 printf("Please stop port %d first\n", port_id);
13287                 return;
13288         }
13289
13290         rte_eth_dev_info_get(port_id, &dev_info);
13291         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13292 #ifdef RTE_LIBRTE_IXGBE_PMD
13293                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13294 #endif
13295         }
13296         RTE_SET_USED(en);
13297         RTE_SET_USED(rp);
13298
13299         switch (ret) {
13300         case 0:
13301                 ports[port_id].dev_conf.txmode.offloads |=
13302                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13303                 cmd_reconfig_device_queue(port_id, 1, 1);
13304                 break;
13305         case -ENODEV:
13306                 printf("invalid port_id %d\n", port_id);
13307                 break;
13308         case -ENOTSUP:
13309                 printf("not supported on port %d\n", port_id);
13310                 break;
13311         default:
13312                 printf("programming error: (%s)\n", strerror(-ret));
13313         }
13314 }
13315
13316 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13317         .f = cmd_set_macsec_offload_on_parsed,
13318         .data = NULL,
13319         .help_str = "set macsec offload <port_id> on "
13320                 "encrypt on|off replay-protect on|off",
13321         .tokens = {
13322                 (void *)&cmd_macsec_offload_on_set,
13323                 (void *)&cmd_macsec_offload_on_macsec,
13324                 (void *)&cmd_macsec_offload_on_offload,
13325                 (void *)&cmd_macsec_offload_on_port_id,
13326                 (void *)&cmd_macsec_offload_on_on,
13327                 (void *)&cmd_macsec_offload_on_encrypt,
13328                 (void *)&cmd_macsec_offload_on_en_on_off,
13329                 (void *)&cmd_macsec_offload_on_replay_protect,
13330                 (void *)&cmd_macsec_offload_on_rp_on_off,
13331                 NULL,
13332         },
13333 };
13334
13335 /* Common result structure for MACsec offload disable */
13336 struct cmd_macsec_offload_off_result {
13337         cmdline_fixed_string_t set;
13338         cmdline_fixed_string_t macsec;
13339         cmdline_fixed_string_t offload;
13340         portid_t port_id;
13341         cmdline_fixed_string_t off;
13342 };
13343
13344 /* Common CLI fields for MACsec offload disable */
13345 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13346         TOKEN_STRING_INITIALIZER
13347                 (struct cmd_macsec_offload_off_result,
13348                  set, "set");
13349 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13350         TOKEN_STRING_INITIALIZER
13351                 (struct cmd_macsec_offload_off_result,
13352                  macsec, "macsec");
13353 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13354         TOKEN_STRING_INITIALIZER
13355                 (struct cmd_macsec_offload_off_result,
13356                  offload, "offload");
13357 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13358         TOKEN_NUM_INITIALIZER
13359                 (struct cmd_macsec_offload_off_result,
13360                  port_id, UINT16);
13361 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13362         TOKEN_STRING_INITIALIZER
13363                 (struct cmd_macsec_offload_off_result,
13364                  off, "off");
13365
13366 static void
13367 cmd_set_macsec_offload_off_parsed(
13368         void *parsed_result,
13369         __attribute__((unused)) struct cmdline *cl,
13370         __attribute__((unused)) void *data)
13371 {
13372         struct cmd_macsec_offload_off_result *res = parsed_result;
13373         int ret = -ENOTSUP;
13374         struct rte_eth_dev_info dev_info;
13375         portid_t port_id = res->port_id;
13376
13377         if (port_id_is_invalid(port_id, ENABLED_WARN))
13378                 return;
13379         if (!port_is_stopped(port_id)) {
13380                 printf("Please stop port %d first\n", port_id);
13381                 return;
13382         }
13383
13384         rte_eth_dev_info_get(port_id, &dev_info);
13385         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13386 #ifdef RTE_LIBRTE_IXGBE_PMD
13387                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13388 #endif
13389         }
13390         switch (ret) {
13391         case 0:
13392                 ports[port_id].dev_conf.txmode.offloads &=
13393                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13394                 cmd_reconfig_device_queue(port_id, 1, 1);
13395                 break;
13396         case -ENODEV:
13397                 printf("invalid port_id %d\n", port_id);
13398                 break;
13399         case -ENOTSUP:
13400                 printf("not supported on port %d\n", port_id);
13401                 break;
13402         default:
13403                 printf("programming error: (%s)\n", strerror(-ret));
13404         }
13405 }
13406
13407 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13408         .f = cmd_set_macsec_offload_off_parsed,
13409         .data = NULL,
13410         .help_str = "set macsec offload <port_id> off",
13411         .tokens = {
13412                 (void *)&cmd_macsec_offload_off_set,
13413                 (void *)&cmd_macsec_offload_off_macsec,
13414                 (void *)&cmd_macsec_offload_off_offload,
13415                 (void *)&cmd_macsec_offload_off_port_id,
13416                 (void *)&cmd_macsec_offload_off_off,
13417                 NULL,
13418         },
13419 };
13420
13421 /* Common result structure for MACsec secure connection configure */
13422 struct cmd_macsec_sc_result {
13423         cmdline_fixed_string_t set;
13424         cmdline_fixed_string_t macsec;
13425         cmdline_fixed_string_t sc;
13426         cmdline_fixed_string_t tx_rx;
13427         portid_t port_id;
13428         struct ether_addr mac;
13429         uint16_t pi;
13430 };
13431
13432 /* Common CLI fields for MACsec secure connection configure */
13433 cmdline_parse_token_string_t cmd_macsec_sc_set =
13434         TOKEN_STRING_INITIALIZER
13435                 (struct cmd_macsec_sc_result,
13436                  set, "set");
13437 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13438         TOKEN_STRING_INITIALIZER
13439                 (struct cmd_macsec_sc_result,
13440                  macsec, "macsec");
13441 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13442         TOKEN_STRING_INITIALIZER
13443                 (struct cmd_macsec_sc_result,
13444                  sc, "sc");
13445 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13446         TOKEN_STRING_INITIALIZER
13447                 (struct cmd_macsec_sc_result,
13448                  tx_rx, "tx#rx");
13449 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13450         TOKEN_NUM_INITIALIZER
13451                 (struct cmd_macsec_sc_result,
13452                  port_id, UINT16);
13453 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13454         TOKEN_ETHERADDR_INITIALIZER
13455                 (struct cmd_macsec_sc_result,
13456                  mac);
13457 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13458         TOKEN_NUM_INITIALIZER
13459                 (struct cmd_macsec_sc_result,
13460                  pi, UINT16);
13461
13462 static void
13463 cmd_set_macsec_sc_parsed(
13464         void *parsed_result,
13465         __attribute__((unused)) struct cmdline *cl,
13466         __attribute__((unused)) void *data)
13467 {
13468         struct cmd_macsec_sc_result *res = parsed_result;
13469         int ret = -ENOTSUP;
13470         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13471
13472 #ifdef RTE_LIBRTE_IXGBE_PMD
13473         ret = is_tx ?
13474                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13475                                 res->mac.addr_bytes) :
13476                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13477                                 res->mac.addr_bytes, res->pi);
13478 #endif
13479         RTE_SET_USED(is_tx);
13480
13481         switch (ret) {
13482         case 0:
13483                 break;
13484         case -ENODEV:
13485                 printf("invalid port_id %d\n", res->port_id);
13486                 break;
13487         case -ENOTSUP:
13488                 printf("not supported on port %d\n", res->port_id);
13489                 break;
13490         default:
13491                 printf("programming error: (%s)\n", strerror(-ret));
13492         }
13493 }
13494
13495 cmdline_parse_inst_t cmd_set_macsec_sc = {
13496         .f = cmd_set_macsec_sc_parsed,
13497         .data = NULL,
13498         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13499         .tokens = {
13500                 (void *)&cmd_macsec_sc_set,
13501                 (void *)&cmd_macsec_sc_macsec,
13502                 (void *)&cmd_macsec_sc_sc,
13503                 (void *)&cmd_macsec_sc_tx_rx,
13504                 (void *)&cmd_macsec_sc_port_id,
13505                 (void *)&cmd_macsec_sc_mac,
13506                 (void *)&cmd_macsec_sc_pi,
13507                 NULL,
13508         },
13509 };
13510
13511 /* Common result structure for MACsec secure connection configure */
13512 struct cmd_macsec_sa_result {
13513         cmdline_fixed_string_t set;
13514         cmdline_fixed_string_t macsec;
13515         cmdline_fixed_string_t sa;
13516         cmdline_fixed_string_t tx_rx;
13517         portid_t port_id;
13518         uint8_t idx;
13519         uint8_t an;
13520         uint32_t pn;
13521         cmdline_fixed_string_t key;
13522 };
13523
13524 /* Common CLI fields for MACsec secure connection configure */
13525 cmdline_parse_token_string_t cmd_macsec_sa_set =
13526         TOKEN_STRING_INITIALIZER
13527                 (struct cmd_macsec_sa_result,
13528                  set, "set");
13529 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13530         TOKEN_STRING_INITIALIZER
13531                 (struct cmd_macsec_sa_result,
13532                  macsec, "macsec");
13533 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13534         TOKEN_STRING_INITIALIZER
13535                 (struct cmd_macsec_sa_result,
13536                  sa, "sa");
13537 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_macsec_sa_result,
13540                  tx_rx, "tx#rx");
13541 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13542         TOKEN_NUM_INITIALIZER
13543                 (struct cmd_macsec_sa_result,
13544                  port_id, UINT16);
13545 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13546         TOKEN_NUM_INITIALIZER
13547                 (struct cmd_macsec_sa_result,
13548                  idx, UINT8);
13549 cmdline_parse_token_num_t cmd_macsec_sa_an =
13550         TOKEN_NUM_INITIALIZER
13551                 (struct cmd_macsec_sa_result,
13552                  an, UINT8);
13553 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13554         TOKEN_NUM_INITIALIZER
13555                 (struct cmd_macsec_sa_result,
13556                  pn, UINT32);
13557 cmdline_parse_token_string_t cmd_macsec_sa_key =
13558         TOKEN_STRING_INITIALIZER
13559                 (struct cmd_macsec_sa_result,
13560                  key, NULL);
13561
13562 static void
13563 cmd_set_macsec_sa_parsed(
13564         void *parsed_result,
13565         __attribute__((unused)) struct cmdline *cl,
13566         __attribute__((unused)) void *data)
13567 {
13568         struct cmd_macsec_sa_result *res = parsed_result;
13569         int ret = -ENOTSUP;
13570         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13571         uint8_t key[16] = { 0 };
13572         uint8_t xdgt0;
13573         uint8_t xdgt1;
13574         int key_len;
13575         int i;
13576
13577         key_len = strlen(res->key) / 2;
13578         if (key_len > 16)
13579                 key_len = 16;
13580
13581         for (i = 0; i < key_len; i++) {
13582                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13583                 if (xdgt0 == 0xFF)
13584                         return;
13585                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13586                 if (xdgt1 == 0xFF)
13587                         return;
13588                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13589         }
13590
13591 #ifdef RTE_LIBRTE_IXGBE_PMD
13592         ret = is_tx ?
13593                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13594                         res->idx, res->an, res->pn, key) :
13595                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13596                         res->idx, res->an, res->pn, key);
13597 #endif
13598         RTE_SET_USED(is_tx);
13599         RTE_SET_USED(key);
13600
13601         switch (ret) {
13602         case 0:
13603                 break;
13604         case -EINVAL:
13605                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13606                 break;
13607         case -ENODEV:
13608                 printf("invalid port_id %d\n", res->port_id);
13609                 break;
13610         case -ENOTSUP:
13611                 printf("not supported on port %d\n", res->port_id);
13612                 break;
13613         default:
13614                 printf("programming error: (%s)\n", strerror(-ret));
13615         }
13616 }
13617
13618 cmdline_parse_inst_t cmd_set_macsec_sa = {
13619         .f = cmd_set_macsec_sa_parsed,
13620         .data = NULL,
13621         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13622         .tokens = {
13623                 (void *)&cmd_macsec_sa_set,
13624                 (void *)&cmd_macsec_sa_macsec,
13625                 (void *)&cmd_macsec_sa_sa,
13626                 (void *)&cmd_macsec_sa_tx_rx,
13627                 (void *)&cmd_macsec_sa_port_id,
13628                 (void *)&cmd_macsec_sa_idx,
13629                 (void *)&cmd_macsec_sa_an,
13630                 (void *)&cmd_macsec_sa_pn,
13631                 (void *)&cmd_macsec_sa_key,
13632                 NULL,
13633         },
13634 };
13635
13636 /* VF unicast promiscuous mode configuration */
13637
13638 /* Common result structure for VF unicast promiscuous mode */
13639 struct cmd_vf_promisc_result {
13640         cmdline_fixed_string_t set;
13641         cmdline_fixed_string_t vf;
13642         cmdline_fixed_string_t promisc;
13643         portid_t port_id;
13644         uint32_t vf_id;
13645         cmdline_fixed_string_t on_off;
13646 };
13647
13648 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13649 cmdline_parse_token_string_t cmd_vf_promisc_set =
13650         TOKEN_STRING_INITIALIZER
13651                 (struct cmd_vf_promisc_result,
13652                  set, "set");
13653 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13654         TOKEN_STRING_INITIALIZER
13655                 (struct cmd_vf_promisc_result,
13656                  vf, "vf");
13657 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13658         TOKEN_STRING_INITIALIZER
13659                 (struct cmd_vf_promisc_result,
13660                  promisc, "promisc");
13661 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13662         TOKEN_NUM_INITIALIZER
13663                 (struct cmd_vf_promisc_result,
13664                  port_id, UINT16);
13665 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13666         TOKEN_NUM_INITIALIZER
13667                 (struct cmd_vf_promisc_result,
13668                  vf_id, UINT32);
13669 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13670         TOKEN_STRING_INITIALIZER
13671                 (struct cmd_vf_promisc_result,
13672                  on_off, "on#off");
13673
13674 static void
13675 cmd_set_vf_promisc_parsed(
13676         void *parsed_result,
13677         __attribute__((unused)) struct cmdline *cl,
13678         __attribute__((unused)) void *data)
13679 {
13680         struct cmd_vf_promisc_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_unicast_promisc(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\n", res->vf_id);
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_promisc = {
13711         .f = cmd_set_vf_promisc_parsed,
13712         .data = NULL,
13713         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13714                 "Set unicast promiscuous mode for a VF from the PF",
13715         .tokens = {
13716                 (void *)&cmd_vf_promisc_set,
13717                 (void *)&cmd_vf_promisc_vf,
13718                 (void *)&cmd_vf_promisc_promisc,
13719                 (void *)&cmd_vf_promisc_port_id,
13720                 (void *)&cmd_vf_promisc_vf_id,
13721                 (void *)&cmd_vf_promisc_on_off,
13722                 NULL,
13723         },
13724 };
13725
13726 /* VF multicast promiscuous mode configuration */
13727
13728 /* Common result structure for VF multicast promiscuous mode */
13729 struct cmd_vf_allmulti_result {
13730         cmdline_fixed_string_t set;
13731         cmdline_fixed_string_t vf;
13732         cmdline_fixed_string_t allmulti;
13733         portid_t port_id;
13734         uint32_t vf_id;
13735         cmdline_fixed_string_t on_off;
13736 };
13737
13738 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13739 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13740         TOKEN_STRING_INITIALIZER
13741                 (struct cmd_vf_allmulti_result,
13742                  set, "set");
13743 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_vf_allmulti_result,
13746                  vf, "vf");
13747 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13748         TOKEN_STRING_INITIALIZER
13749                 (struct cmd_vf_allmulti_result,
13750                  allmulti, "allmulti");
13751 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13752         TOKEN_NUM_INITIALIZER
13753                 (struct cmd_vf_allmulti_result,
13754                  port_id, UINT16);
13755 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13756         TOKEN_NUM_INITIALIZER
13757                 (struct cmd_vf_allmulti_result,
13758                  vf_id, UINT32);
13759 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13760         TOKEN_STRING_INITIALIZER
13761                 (struct cmd_vf_allmulti_result,
13762                  on_off, "on#off");
13763
13764 static void
13765 cmd_set_vf_allmulti_parsed(
13766         void *parsed_result,
13767         __attribute__((unused)) struct cmdline *cl,
13768         __attribute__((unused)) void *data)
13769 {
13770         struct cmd_vf_allmulti_result *res = parsed_result;
13771         int ret = -ENOTSUP;
13772
13773         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13774
13775         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13776                 return;
13777
13778 #ifdef RTE_LIBRTE_I40E_PMD
13779         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13780                                                     res->vf_id, is_on);
13781 #endif
13782
13783         switch (ret) {
13784         case 0:
13785                 break;
13786         case -EINVAL:
13787                 printf("invalid vf_id %d\n", res->vf_id);
13788                 break;
13789         case -ENODEV:
13790                 printf("invalid port_id %d\n", res->port_id);
13791                 break;
13792         case -ENOTSUP:
13793                 printf("function not implemented\n");
13794                 break;
13795         default:
13796                 printf("programming error: (%s)\n", strerror(-ret));
13797         }
13798 }
13799
13800 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13801         .f = cmd_set_vf_allmulti_parsed,
13802         .data = NULL,
13803         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13804                 "Set multicast promiscuous mode for a VF from the PF",
13805         .tokens = {
13806                 (void *)&cmd_vf_allmulti_set,
13807                 (void *)&cmd_vf_allmulti_vf,
13808                 (void *)&cmd_vf_allmulti_allmulti,
13809                 (void *)&cmd_vf_allmulti_port_id,
13810                 (void *)&cmd_vf_allmulti_vf_id,
13811                 (void *)&cmd_vf_allmulti_on_off,
13812                 NULL,
13813         },
13814 };
13815
13816 /* vf broadcast mode configuration */
13817
13818 /* Common result structure for vf broadcast */
13819 struct cmd_set_vf_broadcast_result {
13820         cmdline_fixed_string_t set;
13821         cmdline_fixed_string_t vf;
13822         cmdline_fixed_string_t broadcast;
13823         portid_t port_id;
13824         uint16_t vf_id;
13825         cmdline_fixed_string_t on_off;
13826 };
13827
13828 /* Common CLI fields for vf broadcast enable disable */
13829 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13830         TOKEN_STRING_INITIALIZER
13831                 (struct cmd_set_vf_broadcast_result,
13832                  set, "set");
13833 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13834         TOKEN_STRING_INITIALIZER
13835                 (struct cmd_set_vf_broadcast_result,
13836                  vf, "vf");
13837 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13838         TOKEN_STRING_INITIALIZER
13839                 (struct cmd_set_vf_broadcast_result,
13840                  broadcast, "broadcast");
13841 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13842         TOKEN_NUM_INITIALIZER
13843                 (struct cmd_set_vf_broadcast_result,
13844                  port_id, UINT16);
13845 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13846         TOKEN_NUM_INITIALIZER
13847                 (struct cmd_set_vf_broadcast_result,
13848                  vf_id, UINT16);
13849 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13850         TOKEN_STRING_INITIALIZER
13851                 (struct cmd_set_vf_broadcast_result,
13852                  on_off, "on#off");
13853
13854 static void
13855 cmd_set_vf_broadcast_parsed(
13856         void *parsed_result,
13857         __attribute__((unused)) struct cmdline *cl,
13858         __attribute__((unused)) void *data)
13859 {
13860         struct cmd_set_vf_broadcast_result *res = parsed_result;
13861         int ret = -ENOTSUP;
13862
13863         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13864
13865         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13866                 return;
13867
13868 #ifdef RTE_LIBRTE_I40E_PMD
13869         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13870                                             res->vf_id, is_on);
13871 #endif
13872
13873         switch (ret) {
13874         case 0:
13875                 break;
13876         case -EINVAL:
13877                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13878                 break;
13879         case -ENODEV:
13880                 printf("invalid port_id %d\n", res->port_id);
13881                 break;
13882         case -ENOTSUP:
13883                 printf("function not implemented\n");
13884                 break;
13885         default:
13886                 printf("programming error: (%s)\n", strerror(-ret));
13887         }
13888 }
13889
13890 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13891         .f = cmd_set_vf_broadcast_parsed,
13892         .data = NULL,
13893         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13894         .tokens = {
13895                 (void *)&cmd_set_vf_broadcast_set,
13896                 (void *)&cmd_set_vf_broadcast_vf,
13897                 (void *)&cmd_set_vf_broadcast_broadcast,
13898                 (void *)&cmd_set_vf_broadcast_port_id,
13899                 (void *)&cmd_set_vf_broadcast_vf_id,
13900                 (void *)&cmd_set_vf_broadcast_on_off,
13901                 NULL,
13902         },
13903 };
13904
13905 /* vf vlan tag configuration */
13906
13907 /* Common result structure for vf vlan tag */
13908 struct cmd_set_vf_vlan_tag_result {
13909         cmdline_fixed_string_t set;
13910         cmdline_fixed_string_t vf;
13911         cmdline_fixed_string_t vlan;
13912         cmdline_fixed_string_t tag;
13913         portid_t port_id;
13914         uint16_t vf_id;
13915         cmdline_fixed_string_t on_off;
13916 };
13917
13918 /* Common CLI fields for vf vlan tag enable disable */
13919 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13920         TOKEN_STRING_INITIALIZER
13921                 (struct cmd_set_vf_vlan_tag_result,
13922                  set, "set");
13923 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13924         TOKEN_STRING_INITIALIZER
13925                 (struct cmd_set_vf_vlan_tag_result,
13926                  vf, "vf");
13927 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13928         TOKEN_STRING_INITIALIZER
13929                 (struct cmd_set_vf_vlan_tag_result,
13930                  vlan, "vlan");
13931 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13932         TOKEN_STRING_INITIALIZER
13933                 (struct cmd_set_vf_vlan_tag_result,
13934                  tag, "tag");
13935 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13936         TOKEN_NUM_INITIALIZER
13937                 (struct cmd_set_vf_vlan_tag_result,
13938                  port_id, UINT16);
13939 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13940         TOKEN_NUM_INITIALIZER
13941                 (struct cmd_set_vf_vlan_tag_result,
13942                  vf_id, UINT16);
13943 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13944         TOKEN_STRING_INITIALIZER
13945                 (struct cmd_set_vf_vlan_tag_result,
13946                  on_off, "on#off");
13947
13948 static void
13949 cmd_set_vf_vlan_tag_parsed(
13950         void *parsed_result,
13951         __attribute__((unused)) struct cmdline *cl,
13952         __attribute__((unused)) void *data)
13953 {
13954         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13955         int ret = -ENOTSUP;
13956
13957         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13958
13959         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13960                 return;
13961
13962 #ifdef RTE_LIBRTE_I40E_PMD
13963         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13964                                            res->vf_id, is_on);
13965 #endif
13966
13967         switch (ret) {
13968         case 0:
13969                 break;
13970         case -EINVAL:
13971                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13972                 break;
13973         case -ENODEV:
13974                 printf("invalid port_id %d\n", res->port_id);
13975                 break;
13976         case -ENOTSUP:
13977                 printf("function not implemented\n");
13978                 break;
13979         default:
13980                 printf("programming error: (%s)\n", strerror(-ret));
13981         }
13982 }
13983
13984 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13985         .f = cmd_set_vf_vlan_tag_parsed,
13986         .data = NULL,
13987         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13988         .tokens = {
13989                 (void *)&cmd_set_vf_vlan_tag_set,
13990                 (void *)&cmd_set_vf_vlan_tag_vf,
13991                 (void *)&cmd_set_vf_vlan_tag_vlan,
13992                 (void *)&cmd_set_vf_vlan_tag_tag,
13993                 (void *)&cmd_set_vf_vlan_tag_port_id,
13994                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13995                 (void *)&cmd_set_vf_vlan_tag_on_off,
13996                 NULL,
13997         },
13998 };
13999
14000 /* Common definition of VF and TC TX bandwidth configuration */
14001 struct cmd_vf_tc_bw_result {
14002         cmdline_fixed_string_t set;
14003         cmdline_fixed_string_t vf;
14004         cmdline_fixed_string_t tc;
14005         cmdline_fixed_string_t tx;
14006         cmdline_fixed_string_t min_bw;
14007         cmdline_fixed_string_t max_bw;
14008         cmdline_fixed_string_t strict_link_prio;
14009         portid_t port_id;
14010         uint16_t vf_id;
14011         uint8_t tc_no;
14012         uint32_t bw;
14013         cmdline_fixed_string_t bw_list;
14014         uint8_t tc_map;
14015 };
14016
14017 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14018         TOKEN_STRING_INITIALIZER
14019                 (struct cmd_vf_tc_bw_result,
14020                  set, "set");
14021 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14022         TOKEN_STRING_INITIALIZER
14023                 (struct cmd_vf_tc_bw_result,
14024                  vf, "vf");
14025 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14026         TOKEN_STRING_INITIALIZER
14027                 (struct cmd_vf_tc_bw_result,
14028                  tc, "tc");
14029 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14030         TOKEN_STRING_INITIALIZER
14031                 (struct cmd_vf_tc_bw_result,
14032                  tx, "tx");
14033 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14034         TOKEN_STRING_INITIALIZER
14035                 (struct cmd_vf_tc_bw_result,
14036                  strict_link_prio, "strict-link-priority");
14037 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14038         TOKEN_STRING_INITIALIZER
14039                 (struct cmd_vf_tc_bw_result,
14040                  min_bw, "min-bandwidth");
14041 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14042         TOKEN_STRING_INITIALIZER
14043                 (struct cmd_vf_tc_bw_result,
14044                  max_bw, "max-bandwidth");
14045 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14046         TOKEN_NUM_INITIALIZER
14047                 (struct cmd_vf_tc_bw_result,
14048                  port_id, UINT16);
14049 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14050         TOKEN_NUM_INITIALIZER
14051                 (struct cmd_vf_tc_bw_result,
14052                  vf_id, UINT16);
14053 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14054         TOKEN_NUM_INITIALIZER
14055                 (struct cmd_vf_tc_bw_result,
14056                  tc_no, UINT8);
14057 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14058         TOKEN_NUM_INITIALIZER
14059                 (struct cmd_vf_tc_bw_result,
14060                  bw, UINT32);
14061 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14062         TOKEN_STRING_INITIALIZER
14063                 (struct cmd_vf_tc_bw_result,
14064                  bw_list, NULL);
14065 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14066         TOKEN_NUM_INITIALIZER
14067                 (struct cmd_vf_tc_bw_result,
14068                  tc_map, UINT8);
14069
14070 /* VF max bandwidth setting */
14071 static void
14072 cmd_vf_max_bw_parsed(
14073         void *parsed_result,
14074         __attribute__((unused)) struct cmdline *cl,
14075         __attribute__((unused)) void *data)
14076 {
14077         struct cmd_vf_tc_bw_result *res = parsed_result;
14078         int ret = -ENOTSUP;
14079
14080         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14081                 return;
14082
14083 #ifdef RTE_LIBRTE_I40E_PMD
14084         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14085                                          res->vf_id, res->bw);
14086 #endif
14087
14088         switch (ret) {
14089         case 0:
14090                 break;
14091         case -EINVAL:
14092                 printf("invalid vf_id %d or bandwidth %d\n",
14093                        res->vf_id, res->bw);
14094                 break;
14095         case -ENODEV:
14096                 printf("invalid port_id %d\n", res->port_id);
14097                 break;
14098         case -ENOTSUP:
14099                 printf("function not implemented\n");
14100                 break;
14101         default:
14102                 printf("programming error: (%s)\n", strerror(-ret));
14103         }
14104 }
14105
14106 cmdline_parse_inst_t cmd_vf_max_bw = {
14107         .f = cmd_vf_max_bw_parsed,
14108         .data = NULL,
14109         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14110         .tokens = {
14111                 (void *)&cmd_vf_tc_bw_set,
14112                 (void *)&cmd_vf_tc_bw_vf,
14113                 (void *)&cmd_vf_tc_bw_tx,
14114                 (void *)&cmd_vf_tc_bw_max_bw,
14115                 (void *)&cmd_vf_tc_bw_port_id,
14116                 (void *)&cmd_vf_tc_bw_vf_id,
14117                 (void *)&cmd_vf_tc_bw_bw,
14118                 NULL,
14119         },
14120 };
14121
14122 static int
14123 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14124                            uint8_t *tc_num,
14125                            char *str)
14126 {
14127         uint32_t size;
14128         const char *p, *p0 = str;
14129         char s[256];
14130         char *end;
14131         char *str_fld[16];
14132         uint16_t i;
14133         int ret;
14134
14135         p = strchr(p0, '(');
14136         if (p == NULL) {
14137                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14138                 return -1;
14139         }
14140         p++;
14141         p0 = strchr(p, ')');
14142         if (p0 == NULL) {
14143                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14144                 return -1;
14145         }
14146         size = p0 - p;
14147         if (size >= sizeof(s)) {
14148                 printf("The string size exceeds the internal buffer size\n");
14149                 return -1;
14150         }
14151         snprintf(s, sizeof(s), "%.*s", size, p);
14152         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14153         if (ret <= 0) {
14154                 printf("Failed to get the bandwidth list. ");
14155                 return -1;
14156         }
14157         *tc_num = ret;
14158         for (i = 0; i < ret; i++)
14159                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14160
14161         return 0;
14162 }
14163
14164 /* TC min bandwidth setting */
14165 static void
14166 cmd_vf_tc_min_bw_parsed(
14167         void *parsed_result,
14168         __attribute__((unused)) struct cmdline *cl,
14169         __attribute__((unused)) void *data)
14170 {
14171         struct cmd_vf_tc_bw_result *res = parsed_result;
14172         uint8_t tc_num;
14173         uint8_t bw[16];
14174         int ret = -ENOTSUP;
14175
14176         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14177                 return;
14178
14179         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14180         if (ret)
14181                 return;
14182
14183 #ifdef RTE_LIBRTE_I40E_PMD
14184         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14185                                               tc_num, bw);
14186 #endif
14187
14188         switch (ret) {
14189         case 0:
14190                 break;
14191         case -EINVAL:
14192                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14193                 break;
14194         case -ENODEV:
14195                 printf("invalid port_id %d\n", res->port_id);
14196                 break;
14197         case -ENOTSUP:
14198                 printf("function not implemented\n");
14199                 break;
14200         default:
14201                 printf("programming error: (%s)\n", strerror(-ret));
14202         }
14203 }
14204
14205 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14206         .f = cmd_vf_tc_min_bw_parsed,
14207         .data = NULL,
14208         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14209                     " <bw1, bw2, ...>",
14210         .tokens = {
14211                 (void *)&cmd_vf_tc_bw_set,
14212                 (void *)&cmd_vf_tc_bw_vf,
14213                 (void *)&cmd_vf_tc_bw_tc,
14214                 (void *)&cmd_vf_tc_bw_tx,
14215                 (void *)&cmd_vf_tc_bw_min_bw,
14216                 (void *)&cmd_vf_tc_bw_port_id,
14217                 (void *)&cmd_vf_tc_bw_vf_id,
14218                 (void *)&cmd_vf_tc_bw_bw_list,
14219                 NULL,
14220         },
14221 };
14222
14223 static void
14224 cmd_tc_min_bw_parsed(
14225         void *parsed_result,
14226         __attribute__((unused)) struct cmdline *cl,
14227         __attribute__((unused)) void *data)
14228 {
14229         struct cmd_vf_tc_bw_result *res = parsed_result;
14230         struct rte_port *port;
14231         uint8_t tc_num;
14232         uint8_t bw[16];
14233         int ret = -ENOTSUP;
14234
14235         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14236                 return;
14237
14238         port = &ports[res->port_id];
14239         /** Check if the port is not started **/
14240         if (port->port_status != RTE_PORT_STOPPED) {
14241                 printf("Please stop port %d first\n", res->port_id);
14242                 return;
14243         }
14244
14245         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14246         if (ret)
14247                 return;
14248
14249 #ifdef RTE_LIBRTE_IXGBE_PMD
14250         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14251 #endif
14252
14253         switch (ret) {
14254         case 0:
14255                 break;
14256         case -EINVAL:
14257                 printf("invalid bandwidth\n");
14258                 break;
14259         case -ENODEV:
14260                 printf("invalid port_id %d\n", res->port_id);
14261                 break;
14262         case -ENOTSUP:
14263                 printf("function not implemented\n");
14264                 break;
14265         default:
14266                 printf("programming error: (%s)\n", strerror(-ret));
14267         }
14268 }
14269
14270 cmdline_parse_inst_t cmd_tc_min_bw = {
14271         .f = cmd_tc_min_bw_parsed,
14272         .data = NULL,
14273         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14274         .tokens = {
14275                 (void *)&cmd_vf_tc_bw_set,
14276                 (void *)&cmd_vf_tc_bw_tc,
14277                 (void *)&cmd_vf_tc_bw_tx,
14278                 (void *)&cmd_vf_tc_bw_min_bw,
14279                 (void *)&cmd_vf_tc_bw_port_id,
14280                 (void *)&cmd_vf_tc_bw_bw_list,
14281                 NULL,
14282         },
14283 };
14284
14285 /* TC max bandwidth setting */
14286 static void
14287 cmd_vf_tc_max_bw_parsed(
14288         void *parsed_result,
14289         __attribute__((unused)) struct cmdline *cl,
14290         __attribute__((unused)) void *data)
14291 {
14292         struct cmd_vf_tc_bw_result *res = parsed_result;
14293         int ret = -ENOTSUP;
14294
14295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14296                 return;
14297
14298 #ifdef RTE_LIBRTE_I40E_PMD
14299         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14300                                             res->tc_no, res->bw);
14301 #endif
14302
14303         switch (ret) {
14304         case 0:
14305                 break;
14306         case -EINVAL:
14307                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14308                        res->vf_id, res->tc_no, res->bw);
14309                 break;
14310         case -ENODEV:
14311                 printf("invalid port_id %d\n", res->port_id);
14312                 break;
14313         case -ENOTSUP:
14314                 printf("function not implemented\n");
14315                 break;
14316         default:
14317                 printf("programming error: (%s)\n", strerror(-ret));
14318         }
14319 }
14320
14321 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14322         .f = cmd_vf_tc_max_bw_parsed,
14323         .data = NULL,
14324         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14325                     " <bandwidth>",
14326         .tokens = {
14327                 (void *)&cmd_vf_tc_bw_set,
14328                 (void *)&cmd_vf_tc_bw_vf,
14329                 (void *)&cmd_vf_tc_bw_tc,
14330                 (void *)&cmd_vf_tc_bw_tx,
14331                 (void *)&cmd_vf_tc_bw_max_bw,
14332                 (void *)&cmd_vf_tc_bw_port_id,
14333                 (void *)&cmd_vf_tc_bw_vf_id,
14334                 (void *)&cmd_vf_tc_bw_tc_no,
14335                 (void *)&cmd_vf_tc_bw_bw,
14336                 NULL,
14337         },
14338 };
14339
14340
14341 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14342
14343 /* *** Set Port default Traffic Management Hierarchy *** */
14344 struct cmd_set_port_tm_hierarchy_default_result {
14345         cmdline_fixed_string_t set;
14346         cmdline_fixed_string_t port;
14347         cmdline_fixed_string_t tm;
14348         cmdline_fixed_string_t hierarchy;
14349         cmdline_fixed_string_t def;
14350         portid_t port_id;
14351 };
14352
14353 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14354         TOKEN_STRING_INITIALIZER(
14355                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14356 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14357         TOKEN_STRING_INITIALIZER(
14358                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14359 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14360         TOKEN_STRING_INITIALIZER(
14361                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14362 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14363         TOKEN_STRING_INITIALIZER(
14364                 struct cmd_set_port_tm_hierarchy_default_result,
14365                         hierarchy, "hierarchy");
14366 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14367         TOKEN_STRING_INITIALIZER(
14368                 struct cmd_set_port_tm_hierarchy_default_result,
14369                         def, "default");
14370 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14371         TOKEN_NUM_INITIALIZER(
14372                 struct cmd_set_port_tm_hierarchy_default_result,
14373                         port_id, UINT16);
14374
14375 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14376         __attribute__((unused)) struct cmdline *cl,
14377         __attribute__((unused)) void *data)
14378 {
14379         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14380         struct rte_port *p;
14381         portid_t port_id = res->port_id;
14382
14383         if (port_id_is_invalid(port_id, ENABLED_WARN))
14384                 return;
14385
14386         p = &ports[port_id];
14387
14388         /* Port tm flag */
14389         if (p->softport.tm_flag == 0) {
14390                 printf("  tm not enabled on port %u (error)\n", port_id);
14391                 return;
14392         }
14393
14394         /* Forward mode: tm */
14395         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14396                 printf("  tm mode not enabled(error)\n");
14397                 return;
14398         }
14399
14400         /* Set the default tm hierarchy */
14401         p->softport.tm.default_hierarchy_enable = 1;
14402 }
14403
14404 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14405         .f = cmd_set_port_tm_hierarchy_default_parsed,
14406         .data = NULL,
14407         .help_str = "set port tm hierarchy default <port_id>",
14408         .tokens = {
14409                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14410                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14411                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14412                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14413                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14414                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14415                 NULL,
14416         },
14417 };
14418 #endif
14419
14420 /* Strict link priority scheduling mode setting */
14421 static void
14422 cmd_strict_link_prio_parsed(
14423         void *parsed_result,
14424         __attribute__((unused)) struct cmdline *cl,
14425         __attribute__((unused)) void *data)
14426 {
14427         struct cmd_vf_tc_bw_result *res = parsed_result;
14428         int ret = -ENOTSUP;
14429
14430         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14431                 return;
14432
14433 #ifdef RTE_LIBRTE_I40E_PMD
14434         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14435 #endif
14436
14437         switch (ret) {
14438         case 0:
14439                 break;
14440         case -EINVAL:
14441                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14442                 break;
14443         case -ENODEV:
14444                 printf("invalid port_id %d\n", res->port_id);
14445                 break;
14446         case -ENOTSUP:
14447                 printf("function not implemented\n");
14448                 break;
14449         default:
14450                 printf("programming error: (%s)\n", strerror(-ret));
14451         }
14452 }
14453
14454 cmdline_parse_inst_t cmd_strict_link_prio = {
14455         .f = cmd_strict_link_prio_parsed,
14456         .data = NULL,
14457         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14458         .tokens = {
14459                 (void *)&cmd_vf_tc_bw_set,
14460                 (void *)&cmd_vf_tc_bw_tx,
14461                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14462                 (void *)&cmd_vf_tc_bw_port_id,
14463                 (void *)&cmd_vf_tc_bw_tc_map,
14464                 NULL,
14465         },
14466 };
14467
14468 /* Load dynamic device personalization*/
14469 struct cmd_ddp_add_result {
14470         cmdline_fixed_string_t ddp;
14471         cmdline_fixed_string_t add;
14472         portid_t port_id;
14473         char filepath[];
14474 };
14475
14476 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14477         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14478 cmdline_parse_token_string_t cmd_ddp_add_add =
14479         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14480 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14481         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14482 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14483         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14484
14485 static void
14486 cmd_ddp_add_parsed(
14487         void *parsed_result,
14488         __attribute__((unused)) struct cmdline *cl,
14489         __attribute__((unused)) void *data)
14490 {
14491         struct cmd_ddp_add_result *res = parsed_result;
14492         uint8_t *buff;
14493         uint32_t size;
14494         char *filepath;
14495         char *file_fld[2];
14496         int file_num;
14497         int ret = -ENOTSUP;
14498
14499         if (res->port_id > nb_ports) {
14500                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14501                 return;
14502         }
14503
14504         if (!all_ports_stopped()) {
14505                 printf("Please stop all ports first\n");
14506                 return;
14507         }
14508
14509         filepath = strdup(res->filepath);
14510         if (filepath == NULL) {
14511                 printf("Failed to allocate memory\n");
14512                 return;
14513         }
14514         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14515
14516         buff = open_file(file_fld[0], &size);
14517         if (!buff) {
14518                 free((void *)filepath);
14519                 return;
14520         }
14521
14522 #ifdef RTE_LIBRTE_I40E_PMD
14523         if (ret == -ENOTSUP)
14524                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14525                                                buff, size,
14526                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14527 #endif
14528
14529         if (ret == -EEXIST)
14530                 printf("Profile has already existed.\n");
14531         else if (ret < 0)
14532                 printf("Failed to load profile.\n");
14533         else if (file_num == 2)
14534                 save_file(file_fld[1], buff, size);
14535
14536         close_file(buff);
14537         free((void *)filepath);
14538 }
14539
14540 cmdline_parse_inst_t cmd_ddp_add = {
14541         .f = cmd_ddp_add_parsed,
14542         .data = NULL,
14543         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14544         .tokens = {
14545                 (void *)&cmd_ddp_add_ddp,
14546                 (void *)&cmd_ddp_add_add,
14547                 (void *)&cmd_ddp_add_port_id,
14548                 (void *)&cmd_ddp_add_filepath,
14549                 NULL,
14550         },
14551 };
14552
14553 /* Delete dynamic device personalization*/
14554 struct cmd_ddp_del_result {
14555         cmdline_fixed_string_t ddp;
14556         cmdline_fixed_string_t del;
14557         portid_t port_id;
14558         char filepath[];
14559 };
14560
14561 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14562         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14563 cmdline_parse_token_string_t cmd_ddp_del_del =
14564         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14565 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14566         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14567 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14568         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14569
14570 static void
14571 cmd_ddp_del_parsed(
14572         void *parsed_result,
14573         __attribute__((unused)) struct cmdline *cl,
14574         __attribute__((unused)) void *data)
14575 {
14576         struct cmd_ddp_del_result *res = parsed_result;
14577         uint8_t *buff;
14578         uint32_t size;
14579         int ret = -ENOTSUP;
14580
14581         if (res->port_id > nb_ports) {
14582                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14583                 return;
14584         }
14585
14586         if (!all_ports_stopped()) {
14587                 printf("Please stop all ports first\n");
14588                 return;
14589         }
14590
14591         buff = open_file(res->filepath, &size);
14592         if (!buff)
14593                 return;
14594
14595 #ifdef RTE_LIBRTE_I40E_PMD
14596         if (ret == -ENOTSUP)
14597                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14598                                                buff, size,
14599                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14600 #endif
14601
14602         if (ret == -EACCES)
14603                 printf("Profile does not exist.\n");
14604         else if (ret < 0)
14605                 printf("Failed to delete profile.\n");
14606
14607         close_file(buff);
14608 }
14609
14610 cmdline_parse_inst_t cmd_ddp_del = {
14611         .f = cmd_ddp_del_parsed,
14612         .data = NULL,
14613         .help_str = "ddp del <port_id> <profile_path>",
14614         .tokens = {
14615                 (void *)&cmd_ddp_del_ddp,
14616                 (void *)&cmd_ddp_del_del,
14617                 (void *)&cmd_ddp_del_port_id,
14618                 (void *)&cmd_ddp_del_filepath,
14619                 NULL,
14620         },
14621 };
14622
14623 /* Get dynamic device personalization profile info */
14624 struct cmd_ddp_info_result {
14625         cmdline_fixed_string_t ddp;
14626         cmdline_fixed_string_t get;
14627         cmdline_fixed_string_t info;
14628         char filepath[];
14629 };
14630
14631 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14632         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14633 cmdline_parse_token_string_t cmd_ddp_info_get =
14634         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14635 cmdline_parse_token_string_t cmd_ddp_info_info =
14636         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14637 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14638         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14639
14640 static void
14641 cmd_ddp_info_parsed(
14642         void *parsed_result,
14643         __attribute__((unused)) struct cmdline *cl,
14644         __attribute__((unused)) void *data)
14645 {
14646         struct cmd_ddp_info_result *res = parsed_result;
14647         uint8_t *pkg;
14648         uint32_t pkg_size;
14649         int ret = -ENOTSUP;
14650 #ifdef RTE_LIBRTE_I40E_PMD
14651         uint32_t i, j, n;
14652         uint8_t *buff;
14653         uint32_t buff_size = 0;
14654         struct rte_pmd_i40e_profile_info info;
14655         uint32_t dev_num = 0;
14656         struct rte_pmd_i40e_ddp_device_id *devs;
14657         uint32_t proto_num = 0;
14658         struct rte_pmd_i40e_proto_info *proto = NULL;
14659         uint32_t pctype_num = 0;
14660         struct rte_pmd_i40e_ptype_info *pctype;
14661         uint32_t ptype_num = 0;
14662         struct rte_pmd_i40e_ptype_info *ptype;
14663         uint8_t proto_id;
14664
14665 #endif
14666
14667         pkg = open_file(res->filepath, &pkg_size);
14668         if (!pkg)
14669                 return;
14670
14671 #ifdef RTE_LIBRTE_I40E_PMD
14672         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14673                                 (uint8_t *)&info, sizeof(info),
14674                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14675         if (!ret) {
14676                 printf("Global Track id:       0x%x\n", info.track_id);
14677                 printf("Global Version:        %d.%d.%d.%d\n",
14678                         info.version.major,
14679                         info.version.minor,
14680                         info.version.update,
14681                         info.version.draft);
14682                 printf("Global Package name:   %s\n\n", info.name);
14683         }
14684
14685         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14686                                 (uint8_t *)&info, sizeof(info),
14687                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14688         if (!ret) {
14689                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14690                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14691                         info.version.major,
14692                         info.version.minor,
14693                         info.version.update,
14694                         info.version.draft);
14695                 printf("i40e Profile name:     %s\n\n", info.name);
14696         }
14697
14698         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14699                                 (uint8_t *)&buff_size, sizeof(buff_size),
14700                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14701         if (!ret && buff_size) {
14702                 buff = (uint8_t *)malloc(buff_size);
14703                 if (buff) {
14704                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14705                                                 buff, buff_size,
14706                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14707                         if (!ret)
14708                                 printf("Package Notes:\n%s\n\n", buff);
14709                         free(buff);
14710                 }
14711         }
14712
14713         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14714                                 (uint8_t *)&dev_num, sizeof(dev_num),
14715                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14716         if (!ret && dev_num) {
14717                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14718                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14719                 if (devs) {
14720                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14721                                                 (uint8_t *)devs, buff_size,
14722                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14723                         if (!ret) {
14724                                 printf("List of supported devices:\n");
14725                                 for (i = 0; i < dev_num; i++) {
14726                                         printf("  %04X:%04X %04X:%04X\n",
14727                                                 devs[i].vendor_dev_id >> 16,
14728                                                 devs[i].vendor_dev_id & 0xFFFF,
14729                                                 devs[i].sub_vendor_dev_id >> 16,
14730                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14731                                 }
14732                                 printf("\n");
14733                         }
14734                         free(devs);
14735                 }
14736         }
14737
14738         /* get information about protocols and packet types */
14739         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14740                 (uint8_t *)&proto_num, sizeof(proto_num),
14741                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14742         if (ret || !proto_num)
14743                 goto no_print_return;
14744
14745         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14746         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14747         if (!proto)
14748                 goto no_print_return;
14749
14750         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14751                                         buff_size,
14752                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14753         if (!ret) {
14754                 printf("List of used protocols:\n");
14755                 for (i = 0; i < proto_num; i++)
14756                         printf("  %2u: %s\n", proto[i].proto_id,
14757                                proto[i].name);
14758                 printf("\n");
14759         }
14760         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14761                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14762                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14763         if (ret || !pctype_num)
14764                 goto no_print_pctypes;
14765
14766         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14767         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14768         if (!pctype)
14769                 goto no_print_pctypes;
14770
14771         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14772                                         buff_size,
14773                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14774         if (ret) {
14775                 free(pctype);
14776                 goto no_print_pctypes;
14777         }
14778
14779         printf("List of defined packet classification types:\n");
14780         for (i = 0; i < pctype_num; i++) {
14781                 printf("  %2u:", pctype[i].ptype_id);
14782                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14783                         proto_id = pctype[i].protocols[j];
14784                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14785                                 for (n = 0; n < proto_num; n++) {
14786                                         if (proto[n].proto_id == proto_id) {
14787                                                 printf(" %s", proto[n].name);
14788                                                 break;
14789                                         }
14790                                 }
14791                         }
14792                 }
14793                 printf("\n");
14794         }
14795         printf("\n");
14796         free(pctype);
14797
14798 no_print_pctypes:
14799
14800         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14801                                         sizeof(ptype_num),
14802                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14803         if (ret || !ptype_num)
14804                 goto no_print_return;
14805
14806         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14807         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14808         if (!ptype)
14809                 goto no_print_return;
14810
14811         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14812                                         buff_size,
14813                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14814         if (ret) {
14815                 free(ptype);
14816                 goto no_print_return;
14817         }
14818         printf("List of defined packet types:\n");
14819         for (i = 0; i < ptype_num; i++) {
14820                 printf("  %2u:", ptype[i].ptype_id);
14821                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14822                         proto_id = ptype[i].protocols[j];
14823                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14824                                 for (n = 0; n < proto_num; n++) {
14825                                         if (proto[n].proto_id == proto_id) {
14826                                                 printf(" %s", proto[n].name);
14827                                                 break;
14828                                         }
14829                                 }
14830                         }
14831                 }
14832                 printf("\n");
14833         }
14834         free(ptype);
14835         printf("\n");
14836
14837         ret = 0;
14838 no_print_return:
14839         if (proto)
14840                 free(proto);
14841 #endif
14842         if (ret == -ENOTSUP)
14843                 printf("Function not supported in PMD driver\n");
14844         close_file(pkg);
14845 }
14846
14847 cmdline_parse_inst_t cmd_ddp_get_info = {
14848         .f = cmd_ddp_info_parsed,
14849         .data = NULL,
14850         .help_str = "ddp get info <profile_path>",
14851         .tokens = {
14852                 (void *)&cmd_ddp_info_ddp,
14853                 (void *)&cmd_ddp_info_get,
14854                 (void *)&cmd_ddp_info_info,
14855                 (void *)&cmd_ddp_info_filepath,
14856                 NULL,
14857         },
14858 };
14859
14860 /* Get dynamic device personalization profile info list*/
14861 #define PROFILE_INFO_SIZE 48
14862 #define MAX_PROFILE_NUM 16
14863
14864 struct cmd_ddp_get_list_result {
14865         cmdline_fixed_string_t ddp;
14866         cmdline_fixed_string_t get;
14867         cmdline_fixed_string_t list;
14868         portid_t port_id;
14869 };
14870
14871 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14872         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14873 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14874         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14875 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14876         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14877 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14878         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14879
14880 static void
14881 cmd_ddp_get_list_parsed(
14882         void *parsed_result,
14883         __attribute__((unused)) struct cmdline *cl,
14884         __attribute__((unused)) void *data)
14885 {
14886         struct cmd_ddp_get_list_result *res = parsed_result;
14887 #ifdef RTE_LIBRTE_I40E_PMD
14888         struct rte_pmd_i40e_profile_list *p_list;
14889         struct rte_pmd_i40e_profile_info *p_info;
14890         uint32_t p_num;
14891         uint32_t size;
14892         uint32_t i;
14893 #endif
14894         int ret = -ENOTSUP;
14895
14896         if (res->port_id > nb_ports) {
14897                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14898                 return;
14899         }
14900
14901 #ifdef RTE_LIBRTE_I40E_PMD
14902         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14903         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14904         if (!p_list)
14905                 printf("%s: Failed to malloc buffer\n", __func__);
14906
14907         if (ret == -ENOTSUP)
14908                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14909                                                 (uint8_t *)p_list, size);
14910
14911         if (!ret) {
14912                 p_num = p_list->p_count;
14913                 printf("Profile number is: %d\n\n", p_num);
14914
14915                 for (i = 0; i < p_num; i++) {
14916                         p_info = &p_list->p_info[i];
14917                         printf("Profile %d:\n", i);
14918                         printf("Track id:     0x%x\n", p_info->track_id);
14919                         printf("Version:      %d.%d.%d.%d\n",
14920                                p_info->version.major,
14921                                p_info->version.minor,
14922                                p_info->version.update,
14923                                p_info->version.draft);
14924                         printf("Profile name: %s\n\n", p_info->name);
14925                 }
14926         }
14927
14928         free(p_list);
14929 #endif
14930
14931         if (ret < 0)
14932                 printf("Failed to get ddp list\n");
14933 }
14934
14935 cmdline_parse_inst_t cmd_ddp_get_list = {
14936         .f = cmd_ddp_get_list_parsed,
14937         .data = NULL,
14938         .help_str = "ddp get list <port_id>",
14939         .tokens = {
14940                 (void *)&cmd_ddp_get_list_ddp,
14941                 (void *)&cmd_ddp_get_list_get,
14942                 (void *)&cmd_ddp_get_list_list,
14943                 (void *)&cmd_ddp_get_list_port_id,
14944                 NULL,
14945         },
14946 };
14947
14948 /* Configure input set */
14949 struct cmd_cfg_input_set_result {
14950         cmdline_fixed_string_t port;
14951         cmdline_fixed_string_t cfg;
14952         portid_t port_id;
14953         cmdline_fixed_string_t pctype;
14954         uint8_t pctype_id;
14955         cmdline_fixed_string_t inset_type;
14956         cmdline_fixed_string_t opt;
14957         cmdline_fixed_string_t field;
14958         uint8_t field_idx;
14959 };
14960
14961 static void
14962 cmd_cfg_input_set_parsed(
14963         void *parsed_result,
14964         __attribute__((unused)) struct cmdline *cl,
14965         __attribute__((unused)) void *data)
14966 {
14967         struct cmd_cfg_input_set_result *res = parsed_result;
14968 #ifdef RTE_LIBRTE_I40E_PMD
14969         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14970         struct rte_pmd_i40e_inset inset;
14971 #endif
14972         int ret = -ENOTSUP;
14973
14974         if (res->port_id > nb_ports) {
14975                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14976                 return;
14977         }
14978
14979         if (!all_ports_stopped()) {
14980                 printf("Please stop all ports first\n");
14981                 return;
14982         }
14983
14984 #ifdef RTE_LIBRTE_I40E_PMD
14985         if (!strcmp(res->inset_type, "hash_inset"))
14986                 inset_type = INSET_HASH;
14987         else if (!strcmp(res->inset_type, "fdir_inset"))
14988                 inset_type = INSET_FDIR;
14989         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14990                 inset_type = INSET_FDIR_FLX;
14991         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14992                                      &inset, inset_type);
14993         if (ret) {
14994                 printf("Failed to get input set.\n");
14995                 return;
14996         }
14997
14998         if (!strcmp(res->opt, "get")) {
14999                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15000                                                    res->field_idx);
15001                 if (ret)
15002                         printf("Field index %d is enabled.\n", res->field_idx);
15003                 else
15004                         printf("Field index %d is disabled.\n", res->field_idx);
15005                 return;
15006         } else if (!strcmp(res->opt, "set"))
15007                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15008                                                    res->field_idx);
15009         else if (!strcmp(res->opt, "clear"))
15010                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15011                                                      res->field_idx);
15012         if (ret) {
15013                 printf("Failed to configure input set field.\n");
15014                 return;
15015         }
15016
15017         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15018                                      &inset, inset_type);
15019         if (ret) {
15020                 printf("Failed to set input set.\n");
15021                 return;
15022         }
15023 #endif
15024
15025         if (ret == -ENOTSUP)
15026                 printf("Function not supported\n");
15027 }
15028
15029 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15030         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15031                                  port, "port");
15032 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15033         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15034                                  cfg, "config");
15035 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15036         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15037                               port_id, UINT16);
15038 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15039         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15040                                  pctype, "pctype");
15041 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15042         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15043                               pctype_id, UINT8);
15044 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15045         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15046                                  inset_type,
15047                                  "hash_inset#fdir_inset#fdir_flx_inset");
15048 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15049         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15050                                  opt, "get#set#clear");
15051 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15052         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15053                                  field, "field");
15054 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15055         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15056                               field_idx, UINT8);
15057
15058 cmdline_parse_inst_t cmd_cfg_input_set = {
15059         .f = cmd_cfg_input_set_parsed,
15060         .data = NULL,
15061         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15062                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15063         .tokens = {
15064                 (void *)&cmd_cfg_input_set_port,
15065                 (void *)&cmd_cfg_input_set_cfg,
15066                 (void *)&cmd_cfg_input_set_port_id,
15067                 (void *)&cmd_cfg_input_set_pctype,
15068                 (void *)&cmd_cfg_input_set_pctype_id,
15069                 (void *)&cmd_cfg_input_set_inset_type,
15070                 (void *)&cmd_cfg_input_set_opt,
15071                 (void *)&cmd_cfg_input_set_field,
15072                 (void *)&cmd_cfg_input_set_field_idx,
15073                 NULL,
15074         },
15075 };
15076
15077 /* Clear input set */
15078 struct cmd_clear_input_set_result {
15079         cmdline_fixed_string_t port;
15080         cmdline_fixed_string_t cfg;
15081         portid_t port_id;
15082         cmdline_fixed_string_t pctype;
15083         uint8_t pctype_id;
15084         cmdline_fixed_string_t inset_type;
15085         cmdline_fixed_string_t clear;
15086         cmdline_fixed_string_t all;
15087 };
15088
15089 static void
15090 cmd_clear_input_set_parsed(
15091         void *parsed_result,
15092         __attribute__((unused)) struct cmdline *cl,
15093         __attribute__((unused)) void *data)
15094 {
15095         struct cmd_clear_input_set_result *res = parsed_result;
15096 #ifdef RTE_LIBRTE_I40E_PMD
15097         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15098         struct rte_pmd_i40e_inset inset;
15099 #endif
15100         int ret = -ENOTSUP;
15101
15102         if (res->port_id > nb_ports) {
15103                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
15104                 return;
15105         }
15106
15107         if (!all_ports_stopped()) {
15108                 printf("Please stop all ports first\n");
15109                 return;
15110         }
15111
15112 #ifdef RTE_LIBRTE_I40E_PMD
15113         if (!strcmp(res->inset_type, "hash_inset"))
15114                 inset_type = INSET_HASH;
15115         else if (!strcmp(res->inset_type, "fdir_inset"))
15116                 inset_type = INSET_FDIR;
15117         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15118                 inset_type = INSET_FDIR_FLX;
15119
15120         memset(&inset, 0, sizeof(inset));
15121
15122         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15123                                      &inset, inset_type);
15124         if (ret) {
15125                 printf("Failed to clear input set.\n");
15126                 return;
15127         }
15128
15129 #endif
15130
15131         if (ret == -ENOTSUP)
15132                 printf("Function not supported\n");
15133 }
15134
15135 cmdline_parse_token_string_t cmd_clear_input_set_port =
15136         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15137                                  port, "port");
15138 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15139         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15140                                  cfg, "config");
15141 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15142         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15143                               port_id, UINT16);
15144 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15145         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15146                                  pctype, "pctype");
15147 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15148         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15149                               pctype_id, UINT8);
15150 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15151         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15152                                  inset_type,
15153                                  "hash_inset#fdir_inset#fdir_flx_inset");
15154 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15155         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15156                                  clear, "clear");
15157 cmdline_parse_token_string_t cmd_clear_input_set_all =
15158         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15159                                  all, "all");
15160
15161 cmdline_parse_inst_t cmd_clear_input_set = {
15162         .f = cmd_clear_input_set_parsed,
15163         .data = NULL,
15164         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15165                     "fdir_inset|fdir_flx_inset clear all",
15166         .tokens = {
15167                 (void *)&cmd_clear_input_set_port,
15168                 (void *)&cmd_clear_input_set_cfg,
15169                 (void *)&cmd_clear_input_set_port_id,
15170                 (void *)&cmd_clear_input_set_pctype,
15171                 (void *)&cmd_clear_input_set_pctype_id,
15172                 (void *)&cmd_clear_input_set_inset_type,
15173                 (void *)&cmd_clear_input_set_clear,
15174                 (void *)&cmd_clear_input_set_all,
15175                 NULL,
15176         },
15177 };
15178
15179 /* show vf stats */
15180
15181 /* Common result structure for show vf stats */
15182 struct cmd_show_vf_stats_result {
15183         cmdline_fixed_string_t show;
15184         cmdline_fixed_string_t vf;
15185         cmdline_fixed_string_t stats;
15186         portid_t port_id;
15187         uint16_t vf_id;
15188 };
15189
15190 /* Common CLI fields show vf stats*/
15191 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15192         TOKEN_STRING_INITIALIZER
15193                 (struct cmd_show_vf_stats_result,
15194                  show, "show");
15195 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15196         TOKEN_STRING_INITIALIZER
15197                 (struct cmd_show_vf_stats_result,
15198                  vf, "vf");
15199 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15200         TOKEN_STRING_INITIALIZER
15201                 (struct cmd_show_vf_stats_result,
15202                  stats, "stats");
15203 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15204         TOKEN_NUM_INITIALIZER
15205                 (struct cmd_show_vf_stats_result,
15206                  port_id, UINT16);
15207 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15208         TOKEN_NUM_INITIALIZER
15209                 (struct cmd_show_vf_stats_result,
15210                  vf_id, UINT16);
15211
15212 static void
15213 cmd_show_vf_stats_parsed(
15214         void *parsed_result,
15215         __attribute__((unused)) struct cmdline *cl,
15216         __attribute__((unused)) void *data)
15217 {
15218         struct cmd_show_vf_stats_result *res = parsed_result;
15219         struct rte_eth_stats stats;
15220         int ret = -ENOTSUP;
15221         static const char *nic_stats_border = "########################";
15222
15223         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15224                 return;
15225
15226         memset(&stats, 0, sizeof(stats));
15227
15228 #ifdef RTE_LIBRTE_I40E_PMD
15229         if (ret == -ENOTSUP)
15230                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15231                                                 res->vf_id,
15232                                                 &stats);
15233 #endif
15234 #ifdef RTE_LIBRTE_BNXT_PMD
15235         if (ret == -ENOTSUP)
15236                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15237                                                 res->vf_id,
15238                                                 &stats);
15239 #endif
15240
15241         switch (ret) {
15242         case 0:
15243                 break;
15244         case -EINVAL:
15245                 printf("invalid vf_id %d\n", res->vf_id);
15246                 break;
15247         case -ENODEV:
15248                 printf("invalid port_id %d\n", res->port_id);
15249                 break;
15250         case -ENOTSUP:
15251                 printf("function not implemented\n");
15252                 break;
15253         default:
15254                 printf("programming error: (%s)\n", strerror(-ret));
15255         }
15256
15257         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15258                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15259
15260         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15261                "%-"PRIu64"\n",
15262                stats.ipackets, stats.imissed, stats.ibytes);
15263         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15264         printf("  RX-nombuf:  %-10"PRIu64"\n",
15265                stats.rx_nombuf);
15266         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15267                "%-"PRIu64"\n",
15268                stats.opackets, stats.oerrors, stats.obytes);
15269
15270         printf("  %s############################%s\n",
15271                                nic_stats_border, nic_stats_border);
15272 }
15273
15274 cmdline_parse_inst_t cmd_show_vf_stats = {
15275         .f = cmd_show_vf_stats_parsed,
15276         .data = NULL,
15277         .help_str = "show vf stats <port_id> <vf_id>",
15278         .tokens = {
15279                 (void *)&cmd_show_vf_stats_show,
15280                 (void *)&cmd_show_vf_stats_vf,
15281                 (void *)&cmd_show_vf_stats_stats,
15282                 (void *)&cmd_show_vf_stats_port_id,
15283                 (void *)&cmd_show_vf_stats_vf_id,
15284                 NULL,
15285         },
15286 };
15287
15288 /* clear vf stats */
15289
15290 /* Common result structure for clear vf stats */
15291 struct cmd_clear_vf_stats_result {
15292         cmdline_fixed_string_t clear;
15293         cmdline_fixed_string_t vf;
15294         cmdline_fixed_string_t stats;
15295         portid_t port_id;
15296         uint16_t vf_id;
15297 };
15298
15299 /* Common CLI fields clear vf stats*/
15300 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15301         TOKEN_STRING_INITIALIZER
15302                 (struct cmd_clear_vf_stats_result,
15303                  clear, "clear");
15304 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15305         TOKEN_STRING_INITIALIZER
15306                 (struct cmd_clear_vf_stats_result,
15307                  vf, "vf");
15308 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15309         TOKEN_STRING_INITIALIZER
15310                 (struct cmd_clear_vf_stats_result,
15311                  stats, "stats");
15312 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15313         TOKEN_NUM_INITIALIZER
15314                 (struct cmd_clear_vf_stats_result,
15315                  port_id, UINT16);
15316 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15317         TOKEN_NUM_INITIALIZER
15318                 (struct cmd_clear_vf_stats_result,
15319                  vf_id, UINT16);
15320
15321 static void
15322 cmd_clear_vf_stats_parsed(
15323         void *parsed_result,
15324         __attribute__((unused)) struct cmdline *cl,
15325         __attribute__((unused)) void *data)
15326 {
15327         struct cmd_clear_vf_stats_result *res = parsed_result;
15328         int ret = -ENOTSUP;
15329
15330         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15331                 return;
15332
15333 #ifdef RTE_LIBRTE_I40E_PMD
15334         if (ret == -ENOTSUP)
15335                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15336                                                   res->vf_id);
15337 #endif
15338 #ifdef RTE_LIBRTE_BNXT_PMD
15339         if (ret == -ENOTSUP)
15340                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15341                                                   res->vf_id);
15342 #endif
15343
15344         switch (ret) {
15345         case 0:
15346                 break;
15347         case -EINVAL:
15348                 printf("invalid vf_id %d\n", res->vf_id);
15349                 break;
15350         case -ENODEV:
15351                 printf("invalid port_id %d\n", res->port_id);
15352                 break;
15353         case -ENOTSUP:
15354                 printf("function not implemented\n");
15355                 break;
15356         default:
15357                 printf("programming error: (%s)\n", strerror(-ret));
15358         }
15359 }
15360
15361 cmdline_parse_inst_t cmd_clear_vf_stats = {
15362         .f = cmd_clear_vf_stats_parsed,
15363         .data = NULL,
15364         .help_str = "clear vf stats <port_id> <vf_id>",
15365         .tokens = {
15366                 (void *)&cmd_clear_vf_stats_clear,
15367                 (void *)&cmd_clear_vf_stats_vf,
15368                 (void *)&cmd_clear_vf_stats_stats,
15369                 (void *)&cmd_clear_vf_stats_port_id,
15370                 (void *)&cmd_clear_vf_stats_vf_id,
15371                 NULL,
15372         },
15373 };
15374
15375 /* port config pctype mapping reset */
15376
15377 /* Common result structure for port config pctype mapping reset */
15378 struct cmd_pctype_mapping_reset_result {
15379         cmdline_fixed_string_t port;
15380         cmdline_fixed_string_t config;
15381         portid_t port_id;
15382         cmdline_fixed_string_t pctype;
15383         cmdline_fixed_string_t mapping;
15384         cmdline_fixed_string_t reset;
15385 };
15386
15387 /* Common CLI fields for port config pctype mapping reset*/
15388 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15389         TOKEN_STRING_INITIALIZER
15390                 (struct cmd_pctype_mapping_reset_result,
15391                  port, "port");
15392 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15393         TOKEN_STRING_INITIALIZER
15394                 (struct cmd_pctype_mapping_reset_result,
15395                  config, "config");
15396 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15397         TOKEN_NUM_INITIALIZER
15398                 (struct cmd_pctype_mapping_reset_result,
15399                  port_id, UINT16);
15400 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15401         TOKEN_STRING_INITIALIZER
15402                 (struct cmd_pctype_mapping_reset_result,
15403                  pctype, "pctype");
15404 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15405         TOKEN_STRING_INITIALIZER
15406                 (struct cmd_pctype_mapping_reset_result,
15407                  mapping, "mapping");
15408 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15409         TOKEN_STRING_INITIALIZER
15410                 (struct cmd_pctype_mapping_reset_result,
15411                  reset, "reset");
15412
15413 static void
15414 cmd_pctype_mapping_reset_parsed(
15415         void *parsed_result,
15416         __attribute__((unused)) struct cmdline *cl,
15417         __attribute__((unused)) void *data)
15418 {
15419         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15420         int ret = -ENOTSUP;
15421
15422         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15423                 return;
15424
15425 #ifdef RTE_LIBRTE_I40E_PMD
15426         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15427 #endif
15428
15429         switch (ret) {
15430         case 0:
15431                 break;
15432         case -ENODEV:
15433                 printf("invalid port_id %d\n", res->port_id);
15434                 break;
15435         case -ENOTSUP:
15436                 printf("function not implemented\n");
15437                 break;
15438         default:
15439                 printf("programming error: (%s)\n", strerror(-ret));
15440         }
15441 }
15442
15443 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15444         .f = cmd_pctype_mapping_reset_parsed,
15445         .data = NULL,
15446         .help_str = "port config <port_id> pctype mapping reset",
15447         .tokens = {
15448                 (void *)&cmd_pctype_mapping_reset_port,
15449                 (void *)&cmd_pctype_mapping_reset_config,
15450                 (void *)&cmd_pctype_mapping_reset_port_id,
15451                 (void *)&cmd_pctype_mapping_reset_pctype,
15452                 (void *)&cmd_pctype_mapping_reset_mapping,
15453                 (void *)&cmd_pctype_mapping_reset_reset,
15454                 NULL,
15455         },
15456 };
15457
15458 /* show port pctype mapping */
15459
15460 /* Common result structure for show port pctype mapping */
15461 struct cmd_pctype_mapping_get_result {
15462         cmdline_fixed_string_t show;
15463         cmdline_fixed_string_t port;
15464         portid_t port_id;
15465         cmdline_fixed_string_t pctype;
15466         cmdline_fixed_string_t mapping;
15467 };
15468
15469 /* Common CLI fields for pctype mapping get */
15470 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15471         TOKEN_STRING_INITIALIZER
15472                 (struct cmd_pctype_mapping_get_result,
15473                  show, "show");
15474 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15475         TOKEN_STRING_INITIALIZER
15476                 (struct cmd_pctype_mapping_get_result,
15477                  port, "port");
15478 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15479         TOKEN_NUM_INITIALIZER
15480                 (struct cmd_pctype_mapping_get_result,
15481                  port_id, UINT16);
15482 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15483         TOKEN_STRING_INITIALIZER
15484                 (struct cmd_pctype_mapping_get_result,
15485                  pctype, "pctype");
15486 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15487         TOKEN_STRING_INITIALIZER
15488                 (struct cmd_pctype_mapping_get_result,
15489                  mapping, "mapping");
15490
15491 static void
15492 cmd_pctype_mapping_get_parsed(
15493         void *parsed_result,
15494         __attribute__((unused)) struct cmdline *cl,
15495         __attribute__((unused)) void *data)
15496 {
15497         struct cmd_pctype_mapping_get_result *res = parsed_result;
15498         int ret = -ENOTSUP;
15499 #ifdef RTE_LIBRTE_I40E_PMD
15500         struct rte_pmd_i40e_flow_type_mapping
15501                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15502         int i, j, first_pctype;
15503 #endif
15504
15505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15506                 return;
15507
15508 #ifdef RTE_LIBRTE_I40E_PMD
15509         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15510 #endif
15511
15512         switch (ret) {
15513         case 0:
15514                 break;
15515         case -ENODEV:
15516                 printf("invalid port_id %d\n", res->port_id);
15517                 return;
15518         case -ENOTSUP:
15519                 printf("function not implemented\n");
15520                 return;
15521         default:
15522                 printf("programming error: (%s)\n", strerror(-ret));
15523                 return;
15524         }
15525
15526 #ifdef RTE_LIBRTE_I40E_PMD
15527         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15528                 if (mapping[i].pctype != 0ULL) {
15529                         first_pctype = 1;
15530
15531                         printf("pctype: ");
15532                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15533                                 if (mapping[i].pctype & (1ULL << j)) {
15534                                         printf(first_pctype ?
15535                                                "%02d" : ",%02d", j);
15536                                         first_pctype = 0;
15537                                 }
15538                         }
15539                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15540                 }
15541         }
15542 #endif
15543 }
15544
15545 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15546         .f = cmd_pctype_mapping_get_parsed,
15547         .data = NULL,
15548         .help_str = "show port <port_id> pctype mapping",
15549         .tokens = {
15550                 (void *)&cmd_pctype_mapping_get_show,
15551                 (void *)&cmd_pctype_mapping_get_port,
15552                 (void *)&cmd_pctype_mapping_get_port_id,
15553                 (void *)&cmd_pctype_mapping_get_pctype,
15554                 (void *)&cmd_pctype_mapping_get_mapping,
15555                 NULL,
15556         },
15557 };
15558
15559 /* port config pctype mapping update */
15560
15561 /* Common result structure for port config pctype mapping update */
15562 struct cmd_pctype_mapping_update_result {
15563         cmdline_fixed_string_t port;
15564         cmdline_fixed_string_t config;
15565         portid_t port_id;
15566         cmdline_fixed_string_t pctype;
15567         cmdline_fixed_string_t mapping;
15568         cmdline_fixed_string_t update;
15569         cmdline_fixed_string_t pctype_list;
15570         uint16_t flow_type;
15571 };
15572
15573 /* Common CLI fields for pctype mapping update*/
15574 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15575         TOKEN_STRING_INITIALIZER
15576                 (struct cmd_pctype_mapping_update_result,
15577                  port, "port");
15578 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15579         TOKEN_STRING_INITIALIZER
15580                 (struct cmd_pctype_mapping_update_result,
15581                  config, "config");
15582 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15583         TOKEN_NUM_INITIALIZER
15584                 (struct cmd_pctype_mapping_update_result,
15585                  port_id, UINT16);
15586 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15587         TOKEN_STRING_INITIALIZER
15588                 (struct cmd_pctype_mapping_update_result,
15589                  pctype, "pctype");
15590 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15591         TOKEN_STRING_INITIALIZER
15592                 (struct cmd_pctype_mapping_update_result,
15593                  mapping, "mapping");
15594 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15595         TOKEN_STRING_INITIALIZER
15596                 (struct cmd_pctype_mapping_update_result,
15597                  update, "update");
15598 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15599         TOKEN_STRING_INITIALIZER
15600                 (struct cmd_pctype_mapping_update_result,
15601                  pctype_list, NULL);
15602 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15603         TOKEN_NUM_INITIALIZER
15604                 (struct cmd_pctype_mapping_update_result,
15605                  flow_type, UINT16);
15606
15607 static void
15608 cmd_pctype_mapping_update_parsed(
15609         void *parsed_result,
15610         __attribute__((unused)) struct cmdline *cl,
15611         __attribute__((unused)) void *data)
15612 {
15613         struct cmd_pctype_mapping_update_result *res = parsed_result;
15614         int ret = -ENOTSUP;
15615 #ifdef RTE_LIBRTE_I40E_PMD
15616         struct rte_pmd_i40e_flow_type_mapping mapping;
15617         unsigned int i;
15618         unsigned int nb_item;
15619         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15620 #endif
15621
15622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15623                 return;
15624
15625 #ifdef RTE_LIBRTE_I40E_PMD
15626         nb_item = parse_item_list(res->pctype_list, "pctypes",
15627                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15628         mapping.flow_type = res->flow_type;
15629         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15630                 mapping.pctype |= (1ULL << pctype_list[i]);
15631         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15632                                                 &mapping,
15633                                                 1,
15634                                                 0);
15635 #endif
15636
15637         switch (ret) {
15638         case 0:
15639                 break;
15640         case -EINVAL:
15641                 printf("invalid pctype or flow type\n");
15642                 break;
15643         case -ENODEV:
15644                 printf("invalid port_id %d\n", res->port_id);
15645                 break;
15646         case -ENOTSUP:
15647                 printf("function not implemented\n");
15648                 break;
15649         default:
15650                 printf("programming error: (%s)\n", strerror(-ret));
15651         }
15652 }
15653
15654 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15655         .f = cmd_pctype_mapping_update_parsed,
15656         .data = NULL,
15657         .help_str = "port config <port_id> pctype mapping update"
15658         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15659         .tokens = {
15660                 (void *)&cmd_pctype_mapping_update_port,
15661                 (void *)&cmd_pctype_mapping_update_config,
15662                 (void *)&cmd_pctype_mapping_update_port_id,
15663                 (void *)&cmd_pctype_mapping_update_pctype,
15664                 (void *)&cmd_pctype_mapping_update_mapping,
15665                 (void *)&cmd_pctype_mapping_update_update,
15666                 (void *)&cmd_pctype_mapping_update_pc_type,
15667                 (void *)&cmd_pctype_mapping_update_flow_type,
15668                 NULL,
15669         },
15670 };
15671
15672 /* ptype mapping get */
15673
15674 /* Common result structure for ptype mapping get */
15675 struct cmd_ptype_mapping_get_result {
15676         cmdline_fixed_string_t ptype;
15677         cmdline_fixed_string_t mapping;
15678         cmdline_fixed_string_t get;
15679         portid_t port_id;
15680         uint8_t valid_only;
15681 };
15682
15683 /* Common CLI fields for ptype mapping get */
15684 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15685         TOKEN_STRING_INITIALIZER
15686                 (struct cmd_ptype_mapping_get_result,
15687                  ptype, "ptype");
15688 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15689         TOKEN_STRING_INITIALIZER
15690                 (struct cmd_ptype_mapping_get_result,
15691                  mapping, "mapping");
15692 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15693         TOKEN_STRING_INITIALIZER
15694                 (struct cmd_ptype_mapping_get_result,
15695                  get, "get");
15696 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15697         TOKEN_NUM_INITIALIZER
15698                 (struct cmd_ptype_mapping_get_result,
15699                  port_id, UINT16);
15700 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15701         TOKEN_NUM_INITIALIZER
15702                 (struct cmd_ptype_mapping_get_result,
15703                  valid_only, UINT8);
15704
15705 static void
15706 cmd_ptype_mapping_get_parsed(
15707         void *parsed_result,
15708         __attribute__((unused)) struct cmdline *cl,
15709         __attribute__((unused)) void *data)
15710 {
15711         struct cmd_ptype_mapping_get_result *res = parsed_result;
15712         int ret = -ENOTSUP;
15713 #ifdef RTE_LIBRTE_I40E_PMD
15714         int max_ptype_num = 256;
15715         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15716         uint16_t count;
15717         int i;
15718 #endif
15719
15720         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15721                 return;
15722
15723 #ifdef RTE_LIBRTE_I40E_PMD
15724         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15725                                         mapping,
15726                                         max_ptype_num,
15727                                         &count,
15728                                         res->valid_only);
15729 #endif
15730
15731         switch (ret) {
15732         case 0:
15733                 break;
15734         case -ENODEV:
15735                 printf("invalid port_id %d\n", res->port_id);
15736                 break;
15737         case -ENOTSUP:
15738                 printf("function not implemented\n");
15739                 break;
15740         default:
15741                 printf("programming error: (%s)\n", strerror(-ret));
15742         }
15743
15744 #ifdef RTE_LIBRTE_I40E_PMD
15745         if (!ret) {
15746                 for (i = 0; i < count; i++)
15747                         printf("%3d\t0x%08x\n",
15748                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15749         }
15750 #endif
15751 }
15752
15753 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15754         .f = cmd_ptype_mapping_get_parsed,
15755         .data = NULL,
15756         .help_str = "ptype mapping get <port_id> <valid_only>",
15757         .tokens = {
15758                 (void *)&cmd_ptype_mapping_get_ptype,
15759                 (void *)&cmd_ptype_mapping_get_mapping,
15760                 (void *)&cmd_ptype_mapping_get_get,
15761                 (void *)&cmd_ptype_mapping_get_port_id,
15762                 (void *)&cmd_ptype_mapping_get_valid_only,
15763                 NULL,
15764         },
15765 };
15766
15767 /* ptype mapping replace */
15768
15769 /* Common result structure for ptype mapping replace */
15770 struct cmd_ptype_mapping_replace_result {
15771         cmdline_fixed_string_t ptype;
15772         cmdline_fixed_string_t mapping;
15773         cmdline_fixed_string_t replace;
15774         portid_t port_id;
15775         uint32_t target;
15776         uint8_t mask;
15777         uint32_t pkt_type;
15778 };
15779
15780 /* Common CLI fields for ptype mapping replace */
15781 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15782         TOKEN_STRING_INITIALIZER
15783                 (struct cmd_ptype_mapping_replace_result,
15784                  ptype, "ptype");
15785 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15786         TOKEN_STRING_INITIALIZER
15787                 (struct cmd_ptype_mapping_replace_result,
15788                  mapping, "mapping");
15789 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15790         TOKEN_STRING_INITIALIZER
15791                 (struct cmd_ptype_mapping_replace_result,
15792                  replace, "replace");
15793 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15794         TOKEN_NUM_INITIALIZER
15795                 (struct cmd_ptype_mapping_replace_result,
15796                  port_id, UINT16);
15797 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15798         TOKEN_NUM_INITIALIZER
15799                 (struct cmd_ptype_mapping_replace_result,
15800                  target, UINT32);
15801 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15802         TOKEN_NUM_INITIALIZER
15803                 (struct cmd_ptype_mapping_replace_result,
15804                  mask, UINT8);
15805 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15806         TOKEN_NUM_INITIALIZER
15807                 (struct cmd_ptype_mapping_replace_result,
15808                  pkt_type, UINT32);
15809
15810 static void
15811 cmd_ptype_mapping_replace_parsed(
15812         void *parsed_result,
15813         __attribute__((unused)) struct cmdline *cl,
15814         __attribute__((unused)) void *data)
15815 {
15816         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15817         int ret = -ENOTSUP;
15818
15819         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15820                 return;
15821
15822 #ifdef RTE_LIBRTE_I40E_PMD
15823         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15824                                         res->target,
15825                                         res->mask,
15826                                         res->pkt_type);
15827 #endif
15828
15829         switch (ret) {
15830         case 0:
15831                 break;
15832         case -EINVAL:
15833                 printf("invalid ptype 0x%8x or 0x%8x\n",
15834                                 res->target, res->pkt_type);
15835                 break;
15836         case -ENODEV:
15837                 printf("invalid port_id %d\n", res->port_id);
15838                 break;
15839         case -ENOTSUP:
15840                 printf("function not implemented\n");
15841                 break;
15842         default:
15843                 printf("programming error: (%s)\n", strerror(-ret));
15844         }
15845 }
15846
15847 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15848         .f = cmd_ptype_mapping_replace_parsed,
15849         .data = NULL,
15850         .help_str =
15851                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15852         .tokens = {
15853                 (void *)&cmd_ptype_mapping_replace_ptype,
15854                 (void *)&cmd_ptype_mapping_replace_mapping,
15855                 (void *)&cmd_ptype_mapping_replace_replace,
15856                 (void *)&cmd_ptype_mapping_replace_port_id,
15857                 (void *)&cmd_ptype_mapping_replace_target,
15858                 (void *)&cmd_ptype_mapping_replace_mask,
15859                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15860                 NULL,
15861         },
15862 };
15863
15864 /* ptype mapping reset */
15865
15866 /* Common result structure for ptype mapping reset */
15867 struct cmd_ptype_mapping_reset_result {
15868         cmdline_fixed_string_t ptype;
15869         cmdline_fixed_string_t mapping;
15870         cmdline_fixed_string_t reset;
15871         portid_t port_id;
15872 };
15873
15874 /* Common CLI fields for ptype mapping reset*/
15875 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15876         TOKEN_STRING_INITIALIZER
15877                 (struct cmd_ptype_mapping_reset_result,
15878                  ptype, "ptype");
15879 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15880         TOKEN_STRING_INITIALIZER
15881                 (struct cmd_ptype_mapping_reset_result,
15882                  mapping, "mapping");
15883 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15884         TOKEN_STRING_INITIALIZER
15885                 (struct cmd_ptype_mapping_reset_result,
15886                  reset, "reset");
15887 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15888         TOKEN_NUM_INITIALIZER
15889                 (struct cmd_ptype_mapping_reset_result,
15890                  port_id, UINT16);
15891
15892 static void
15893 cmd_ptype_mapping_reset_parsed(
15894         void *parsed_result,
15895         __attribute__((unused)) struct cmdline *cl,
15896         __attribute__((unused)) void *data)
15897 {
15898         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15899         int ret = -ENOTSUP;
15900
15901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15902                 return;
15903
15904 #ifdef RTE_LIBRTE_I40E_PMD
15905         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15906 #endif
15907
15908         switch (ret) {
15909         case 0:
15910                 break;
15911         case -ENODEV:
15912                 printf("invalid port_id %d\n", res->port_id);
15913                 break;
15914         case -ENOTSUP:
15915                 printf("function not implemented\n");
15916                 break;
15917         default:
15918                 printf("programming error: (%s)\n", strerror(-ret));
15919         }
15920 }
15921
15922 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15923         .f = cmd_ptype_mapping_reset_parsed,
15924         .data = NULL,
15925         .help_str = "ptype mapping reset <port_id>",
15926         .tokens = {
15927                 (void *)&cmd_ptype_mapping_reset_ptype,
15928                 (void *)&cmd_ptype_mapping_reset_mapping,
15929                 (void *)&cmd_ptype_mapping_reset_reset,
15930                 (void *)&cmd_ptype_mapping_reset_port_id,
15931                 NULL,
15932         },
15933 };
15934
15935 /* ptype mapping update */
15936
15937 /* Common result structure for ptype mapping update */
15938 struct cmd_ptype_mapping_update_result {
15939         cmdline_fixed_string_t ptype;
15940         cmdline_fixed_string_t mapping;
15941         cmdline_fixed_string_t reset;
15942         portid_t port_id;
15943         uint8_t hw_ptype;
15944         uint32_t sw_ptype;
15945 };
15946
15947 /* Common CLI fields for ptype mapping update*/
15948 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15949         TOKEN_STRING_INITIALIZER
15950                 (struct cmd_ptype_mapping_update_result,
15951                  ptype, "ptype");
15952 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15953         TOKEN_STRING_INITIALIZER
15954                 (struct cmd_ptype_mapping_update_result,
15955                  mapping, "mapping");
15956 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15957         TOKEN_STRING_INITIALIZER
15958                 (struct cmd_ptype_mapping_update_result,
15959                  reset, "update");
15960 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15961         TOKEN_NUM_INITIALIZER
15962                 (struct cmd_ptype_mapping_update_result,
15963                  port_id, UINT16);
15964 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15965         TOKEN_NUM_INITIALIZER
15966                 (struct cmd_ptype_mapping_update_result,
15967                  hw_ptype, UINT8);
15968 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15969         TOKEN_NUM_INITIALIZER
15970                 (struct cmd_ptype_mapping_update_result,
15971                  sw_ptype, UINT32);
15972
15973 static void
15974 cmd_ptype_mapping_update_parsed(
15975         void *parsed_result,
15976         __attribute__((unused)) struct cmdline *cl,
15977         __attribute__((unused)) void *data)
15978 {
15979         struct cmd_ptype_mapping_update_result *res = parsed_result;
15980         int ret = -ENOTSUP;
15981 #ifdef RTE_LIBRTE_I40E_PMD
15982         struct rte_pmd_i40e_ptype_mapping mapping;
15983 #endif
15984         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15985                 return;
15986
15987 #ifdef RTE_LIBRTE_I40E_PMD
15988         mapping.hw_ptype = res->hw_ptype;
15989         mapping.sw_ptype = res->sw_ptype;
15990         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15991                                                 &mapping,
15992                                                 1,
15993                                                 0);
15994 #endif
15995
15996         switch (ret) {
15997         case 0:
15998                 break;
15999         case -EINVAL:
16000                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16001                 break;
16002         case -ENODEV:
16003                 printf("invalid port_id %d\n", res->port_id);
16004                 break;
16005         case -ENOTSUP:
16006                 printf("function not implemented\n");
16007                 break;
16008         default:
16009                 printf("programming error: (%s)\n", strerror(-ret));
16010         }
16011 }
16012
16013 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16014         .f = cmd_ptype_mapping_update_parsed,
16015         .data = NULL,
16016         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16017         .tokens = {
16018                 (void *)&cmd_ptype_mapping_update_ptype,
16019                 (void *)&cmd_ptype_mapping_update_mapping,
16020                 (void *)&cmd_ptype_mapping_update_update,
16021                 (void *)&cmd_ptype_mapping_update_port_id,
16022                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16023                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16024                 NULL,
16025         },
16026 };
16027
16028 /* Common result structure for file commands */
16029 struct cmd_cmdfile_result {
16030         cmdline_fixed_string_t load;
16031         cmdline_fixed_string_t filename;
16032 };
16033
16034 /* Common CLI fields for file commands */
16035 cmdline_parse_token_string_t cmd_load_cmdfile =
16036         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16037 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16038         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16039
16040 static void
16041 cmd_load_from_file_parsed(
16042         void *parsed_result,
16043         __attribute__((unused)) struct cmdline *cl,
16044         __attribute__((unused)) void *data)
16045 {
16046         struct cmd_cmdfile_result *res = parsed_result;
16047
16048         cmdline_read_from_file(res->filename);
16049 }
16050
16051 cmdline_parse_inst_t cmd_load_from_file = {
16052         .f = cmd_load_from_file_parsed,
16053         .data = NULL,
16054         .help_str = "load <filename>",
16055         .tokens = {
16056                 (void *)&cmd_load_cmdfile,
16057                 (void *)&cmd_load_cmdfile_filename,
16058                 NULL,
16059         },
16060 };
16061
16062 /* ******************************************************************************** */
16063
16064 /* list of instructions */
16065 cmdline_parse_ctx_t main_ctx[] = {
16066         (cmdline_parse_inst_t *)&cmd_help_brief,
16067         (cmdline_parse_inst_t *)&cmd_help_long,
16068         (cmdline_parse_inst_t *)&cmd_quit,
16069         (cmdline_parse_inst_t *)&cmd_load_from_file,
16070         (cmdline_parse_inst_t *)&cmd_showport,
16071         (cmdline_parse_inst_t *)&cmd_showqueue,
16072         (cmdline_parse_inst_t *)&cmd_showportall,
16073         (cmdline_parse_inst_t *)&cmd_showcfg,
16074         (cmdline_parse_inst_t *)&cmd_start,
16075         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16076         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16077         (cmdline_parse_inst_t *)&cmd_set_link_up,
16078         (cmdline_parse_inst_t *)&cmd_set_link_down,
16079         (cmdline_parse_inst_t *)&cmd_reset,
16080         (cmdline_parse_inst_t *)&cmd_set_numbers,
16081         (cmdline_parse_inst_t *)&cmd_set_log,
16082         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16083         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16084         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16085         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16086         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16087         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16088         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16089         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16090         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16091         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16092         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16093         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16094         (cmdline_parse_inst_t *)&cmd_set_link_check,
16095         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16096         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16097         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16098         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16099 #ifdef RTE_LIBRTE_PMD_BOND
16100         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16101         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16102         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16103         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16104         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16105         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16106         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16107         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16108         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16109         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16110         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16111 #endif
16112         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16113         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16114         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16115         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16116         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16117         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16118         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16119         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16120         (cmdline_parse_inst_t *)&cmd_csum_set,
16121         (cmdline_parse_inst_t *)&cmd_csum_show,
16122         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16123         (cmdline_parse_inst_t *)&cmd_tso_set,
16124         (cmdline_parse_inst_t *)&cmd_tso_show,
16125         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16126         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16127         (cmdline_parse_inst_t *)&cmd_gro_enable,
16128         (cmdline_parse_inst_t *)&cmd_gro_flush,
16129         (cmdline_parse_inst_t *)&cmd_gro_show,
16130         (cmdline_parse_inst_t *)&cmd_gso_enable,
16131         (cmdline_parse_inst_t *)&cmd_gso_size,
16132         (cmdline_parse_inst_t *)&cmd_gso_show,
16133         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16134         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16135         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16136         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16137         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16138         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16139         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16140         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16141         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16142         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16143         (cmdline_parse_inst_t *)&cmd_config_dcb,
16144         (cmdline_parse_inst_t *)&cmd_read_reg,
16145         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16146         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16147         (cmdline_parse_inst_t *)&cmd_write_reg,
16148         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16149         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16150         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16151         (cmdline_parse_inst_t *)&cmd_stop,
16152         (cmdline_parse_inst_t *)&cmd_mac_addr,
16153         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16154         (cmdline_parse_inst_t *)&cmd_set_qmap,
16155         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16156         (cmdline_parse_inst_t *)&cmd_operate_port,
16157         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16158         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16159         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16160         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16161         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16162         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16163         (cmdline_parse_inst_t *)&cmd_config_mtu,
16164         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16165         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16166         (cmdline_parse_inst_t *)&cmd_config_rss,
16167         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16168         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16169         (cmdline_parse_inst_t *)&cmd_showport_reta,
16170         (cmdline_parse_inst_t *)&cmd_config_burst,
16171         (cmdline_parse_inst_t *)&cmd_config_thresh,
16172         (cmdline_parse_inst_t *)&cmd_config_threshold,
16173         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16174         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16175         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16176         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16177         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16178         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16179         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16180         (cmdline_parse_inst_t *)&cmd_global_config,
16181         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16182         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16183         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16184         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16185         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16186         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16187         (cmdline_parse_inst_t *)&cmd_dump,
16188         (cmdline_parse_inst_t *)&cmd_dump_one,
16189         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16190         (cmdline_parse_inst_t *)&cmd_syn_filter,
16191         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16192         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16193         (cmdline_parse_inst_t *)&cmd_flex_filter,
16194         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16195         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16196         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16197         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16198         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16199         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16200         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16201         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16202         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16203         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16204         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16205         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16206         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16207         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16208         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16209         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16210         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16211         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16212         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16213         (cmdline_parse_inst_t *)&cmd_flow,
16214         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16215         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16216         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16217         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16218         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16219         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16220         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16221         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16222         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16223         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16224         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16225         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16226         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16227         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16228         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16229         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16230         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16231         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16232         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16233         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16234         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16235         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16236         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16237         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16238         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16239         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16240         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16241         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16242         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16243         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16244         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16245         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16246         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16247         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16248         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16249         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16250         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16251         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16252         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16253         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16254         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16255         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16256         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16257         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16258         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16259         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16260         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16261         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16262         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16263 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16264         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16265 #endif
16266         (cmdline_parse_inst_t *)&cmd_ddp_add,
16267         (cmdline_parse_inst_t *)&cmd_ddp_del,
16268         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16269         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16270         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16271         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16272         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16273         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16274         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16275         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16276         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16277         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16278
16279         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16280         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16281         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16282         (cmdline_parse_inst_t *)&cmd_queue_region,
16283         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16284         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16285         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16286         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16287         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16288         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16289         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16290         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16291         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16292         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16293         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16294         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16295         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16296         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16297         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16298         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16299         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16300         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16301         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16302         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16303         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16304         NULL,
16305 };
16306
16307 /* read cmdline commands from file */
16308 void
16309 cmdline_read_from_file(const char *filename)
16310 {
16311         struct cmdline *cl;
16312
16313         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16314         if (cl == NULL) {
16315                 printf("Failed to create file based cmdline context: %s\n",
16316                        filename);
16317                 return;
16318         }
16319
16320         cmdline_interact(cl);
16321         cmdline_quit(cl);
16322
16323         cmdline_free(cl);
16324
16325         printf("Read CLI commands from %s\n", filename);
16326 }
16327
16328 /* prompt function, called from main on MASTER lcore */
16329 void
16330 prompt(void)
16331 {
16332         /* initialize non-constant commands */
16333         cmd_set_fwd_mode_init();
16334         cmd_set_fwd_retry_mode_init();
16335
16336         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16337         if (testpmd_cl == NULL)
16338                 return;
16339         cmdline_interact(testpmd_cl);
16340         cmdline_stdin_exit(testpmd_cl);
16341 }
16342
16343 void
16344 prompt_exit(void)
16345 {
16346         if (testpmd_cl != NULL)
16347                 cmdline_quit(testpmd_cl);
16348 }
16349
16350 static void
16351 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16352 {
16353         if (id == (portid_t)RTE_PORT_ALL) {
16354                 portid_t pid;
16355
16356                 RTE_ETH_FOREACH_DEV(pid) {
16357                         /* check if need_reconfig has been set to 1 */
16358                         if (ports[pid].need_reconfig == 0)
16359                                 ports[pid].need_reconfig = dev;
16360                         /* check if need_reconfig_queues has been set to 1 */
16361                         if (ports[pid].need_reconfig_queues == 0)
16362                                 ports[pid].need_reconfig_queues = queue;
16363                 }
16364         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16365                 /* check if need_reconfig has been set to 1 */
16366                 if (ports[id].need_reconfig == 0)
16367                         ports[id].need_reconfig = dev;
16368                 /* check if need_reconfig_queues has been set to 1 */
16369                 if (ports[id].need_reconfig_queues == 0)
16370                         ports[id].need_reconfig_queues = queue;
16371         }
16372 }