app/testpmd: support loopback config for DPAA
[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 nbport (num)\n"
278                         "    Set number of ports.\n\n"
279
280                         "set nbcore (num)\n"
281                         "    Set number of cores.\n\n"
282
283                         "set coremask (mask)\n"
284                         "    Set the forwarding cores hexadecimal mask.\n\n"
285
286                         "set portmask (mask)\n"
287                         "    Set the forwarding ports hexadecimal mask.\n\n"
288
289                         "set burst (num)\n"
290                         "    Set number of packets per burst.\n\n"
291
292                         "set burst tx delay (microseconds) retry (num)\n"
293                         "    Set the transmit delay time and number of retries,"
294                         " effective when retry is enabled.\n\n"
295
296                         "set txpkts (x[,y]*)\n"
297                         "    Set the length of each segment of TXONLY"
298                         " and optionally CSUM packets.\n\n"
299
300                         "set txsplit (off|on|rand)\n"
301                         "    Set the split policy for the TX packets."
302                         " Right now only applicable for CSUM and TXONLY"
303                         " modes\n\n"
304
305                         "set corelist (x[,y]*)\n"
306                         "    Set the list of forwarding cores.\n\n"
307
308                         "set portlist (x[,y]*)\n"
309                         "    Set the list of forwarding ports.\n\n"
310
311                         "set tx loopback (port_id) (on|off)\n"
312                         "    Enable or disable tx loopback.\n\n"
313
314                         "set all queues drop (port_id) (on|off)\n"
315                         "    Set drop enable bit for all queues.\n\n"
316
317                         "set vf split drop (port_id) (vf_id) (on|off)\n"
318                         "    Set split drop enable bit for a VF from the PF.\n\n"
319
320                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
321                         "    Set MAC antispoof for a VF from the PF.\n\n"
322
323                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
324                         "    Enable MACsec offload.\n\n"
325
326                         "set macsec offload (port_id) off\n"
327                         "    Disable MACsec offload.\n\n"
328
329                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
330                         "    Configure MACsec secure connection (SC).\n\n"
331
332                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
333                         "    Configure MACsec secure association (SA).\n\n"
334
335                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
336                         "    Set VF broadcast for a VF from the PF.\n\n"
337
338                         "vlan set strip (on|off) (port_id)\n"
339                         "    Set the VLAN strip on a port.\n\n"
340
341                         "vlan set stripq (on|off) (port_id,queue_id)\n"
342                         "    Set the VLAN strip for a queue on a port.\n\n"
343
344                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
345                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
346
347                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
348                         "    Set VLAN insert for a VF from the PF.\n\n"
349
350                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN antispoof for a VF from the PF.\n\n"
352
353                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
354                         "    Set VLAN tag for a VF from the PF.\n\n"
355
356                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
357                         "    Set a VF's max bandwidth(Mbps).\n\n"
358
359                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
360                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
361
362                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
363                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
364
365                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
366                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
367
368                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
369                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
370
371                         "vlan set filter (on|off) (port_id)\n"
372                         "    Set the VLAN filter on a port.\n\n"
373
374                         "vlan set qinq (on|off) (port_id)\n"
375                         "    Set the VLAN QinQ (extended queue in queue)"
376                         " on a port.\n\n"
377
378                         "vlan set (inner|outer) tpid (value) (port_id)\n"
379                         "    Set the VLAN TPID for Packet Filtering on"
380                         " a port\n\n"
381
382                         "rx_vlan add (vlan_id|all) (port_id)\n"
383                         "    Add a vlan_id, or all identifiers, to the set"
384                         " of VLAN identifiers filtered by port_id.\n\n"
385
386                         "rx_vlan rm (vlan_id|all) (port_id)\n"
387                         "    Remove a vlan_id, or all identifiers, from the set"
388                         " of VLAN identifiers filtered by port_id.\n\n"
389
390                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
391                         "    Add a vlan_id, to the set of VLAN identifiers"
392                         "filtered for VF(s) from port_id.\n\n"
393
394                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
395                         "    Remove a vlan_id, to the set of VLAN identifiers"
396                         "filtered for VF(s) from port_id.\n\n"
397
398                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
399                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
400                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
401                         "   add a tunnel filter of a port.\n\n"
402
403                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
404                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
405                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
406                         "   remove a tunnel filter of a port.\n\n"
407
408                         "rx_vxlan_port add (udp_port) (port_id)\n"
409                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "rx_vxlan_port rm (udp_port) (port_id)\n"
412                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
415                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
416                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
417
418                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
419                         "    Set port based TX VLAN insertion.\n\n"
420
421                         "tx_vlan reset (port_id)\n"
422                         "    Disable hardware insertion of a VLAN header in"
423                         " packets sent on a port.\n\n"
424
425                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
426                         "    Select hardware or software calculation of the"
427                         " checksum when transmitting a packet using the"
428                         " csum forward engine.\n"
429                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
430                         "    outer-ip concerns the outer IP layer in"
431                         " case the packet is recognized as a tunnel packet by"
432                         " the forward engine (vxlan, gre and ipip are supported)\n"
433                         "    Please check the NIC datasheet for HW limits.\n\n"
434
435                         "csum parse-tunnel (on|off) (tx_port_id)\n"
436                         "    If disabled, treat tunnel packets as non-tunneled"
437                         " packets (treat inner headers as payload). The port\n"
438                         "    argument is the port used for TX in csum forward"
439                         " engine.\n\n"
440
441                         "csum show (port_id)\n"
442                         "    Display tx checksum offload configuration\n\n"
443
444                         "tso set (segsize) (portid)\n"
445                         "    Enable TCP Segmentation Offload in csum forward"
446                         " engine.\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "tso show (portid)"
450                         "    Display the status of TCP Segmentation Offload.\n\n"
451
452                         "set port (port_id) gro on|off\n"
453                         "    Enable or disable Generic Receive Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "show port (port_id) gro\n"
457                         "    Display GRO configuration.\n\n"
458
459                         "set gro flush (cycles)\n"
460                         "    Set the cycle to flush GROed packets from"
461                         " reassembly tables.\n\n"
462
463                         "set port (port_id) gso (on|off)"
464                         "    Enable or disable Generic Segmentation Offload in"
465                         " csum forwarding engine.\n\n"
466
467                         "set gso segsz (length)\n"
468                         "    Set max packet length for output GSO segments,"
469                         " including packet header and payload.\n\n"
470
471                         "show port (port_id) gso\n"
472                         "    Show GSO configuration.\n\n"
473
474                         "set fwd (%s)\n"
475                         "    Set packet forwarding mode.\n\n"
476
477                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Add a MAC address on port_id.\n\n"
479
480                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Remove a MAC address from port_id.\n\n"
482
483                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
484                         "    Set the default MAC address for port_id.\n\n"
485
486                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
487                         "    Add a MAC address for a VF on the port.\n\n"
488
489                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
490                         "    Set the MAC address for a VF from the PF.\n\n"
491
492                         "set eth-peer (port_id) (peer_addr)\n"
493                         "    set the peer address for certain port.\n\n"
494
495                         "set port (port_id) uta (mac_address|all) (on|off)\n"
496                         "    Add/Remove a or all unicast hash filter(s)"
497                         "from port X.\n\n"
498
499                         "set promisc (port_id|all) (on|off)\n"
500                         "    Set the promiscuous mode on port_id, or all.\n\n"
501
502                         "set allmulti (port_id|all) (on|off)\n"
503                         "    Set the allmulti mode on port_id, or all.\n\n"
504
505                         "set vf promisc (port_id) (vf_id) (on|off)\n"
506                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
507
508                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
509                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
510
511                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
513                         " (on|off) autoneg (on|off) (port_id)\n"
514                         "set flow_ctrl rx (on|off) (portid)\n"
515                         "set flow_ctrl tx (on|off) (portid)\n"
516                         "set flow_ctrl high_water (high_water) (portid)\n"
517                         "set flow_ctrl low_water (low_water) (portid)\n"
518                         "set flow_ctrl pause_time (pause_time) (portid)\n"
519                         "set flow_ctrl send_xon (send_xon) (portid)\n"
520                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
521                         "set flow_ctrl autoneg (on|off) (port_id)\n"
522                         "    Set the link flow control parameter on a port.\n\n"
523
524                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
525                         " (low_water) (pause_time) (priority) (port_id)\n"
526                         "    Set the priority flow control parameter on a"
527                         " port.\n\n"
528
529                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
530                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
531                         " queue on port.\n"
532                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
533                         " on port 0 to mapping 5.\n\n"
534
535                         "set xstats-hide-zero on|off\n"
536                         "    Set the option to hide the zero values"
537                         " for xstats display.\n"
538
539                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
540                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
541
542                         "set port (port_id) vf (vf_id) (mac_addr)"
543                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
544                         "   Add/Remove unicast or multicast MAC addr filter"
545                         " for a VF.\n\n"
546
547                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
548                         "|MPE) (on|off)\n"
549                         "    AUPE:accepts untagged VLAN;"
550                         "ROPE:accept unicast hash\n\n"
551                         "    BAM:accepts broadcast packets;"
552                         "MPE:accepts all multicast packets\n\n"
553                         "    Enable/Disable a VF receive mode of a port\n\n"
554
555                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
556                         "    Set rate limit for a queue of a port\n\n"
557
558                         "set port (port_id) vf (vf_id) rate (rate_num) "
559                         "queue_mask (queue_mask_value)\n"
560                         "    Set rate limit for queues in VF of a port\n\n"
561
562                         "set port (port_id) mirror-rule (rule_id)"
563                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
564                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
565                         "   Set pool or vlan type mirror rule on a port.\n"
566                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
567                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
568                         " to pool 0.\n\n"
569
570                         "set port (port_id) mirror-rule (rule_id)"
571                         " (uplink-mirror|downlink-mirror) dst-pool"
572                         " (pool_id) (on|off)\n"
573                         "   Set uplink or downlink type mirror rule on a port.\n"
574                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
575                         " 0 on' enable mirror income traffic to pool 0.\n\n"
576
577                         "reset port (port_id) mirror-rule (rule_id)\n"
578                         "   Reset a mirror rule.\n\n"
579
580                         "set flush_rx (on|off)\n"
581                         "   Flush (default) or don't flush RX streams before"
582                         " forwarding. Mainly used with PCAP drivers.\n\n"
583
584                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
585                         "   Set the bypass mode for the lowest port on bypass enabled"
586                         " NIC.\n\n"
587
588                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
589                         "mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the event required to initiate specified bypass mode for"
591                         " the lowest port on a bypass enabled NIC where:\n"
592                         "       timeout   = enable bypass after watchdog timeout.\n"
593                         "       os_on     = enable bypass when OS/board is powered on.\n"
594                         "       os_off    = enable bypass when OS/board is powered off.\n"
595                         "       power_on  = enable bypass when power supply is turned on.\n"
596                         "       power_off = enable bypass when power supply is turned off."
597                         "\n\n"
598
599                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
600                         "   Set the bypass watchdog timeout to 'n' seconds"
601                         " where 0 = instant.\n\n"
602
603                         "show bypass config (port_id)\n"
604                         "   Show the bypass configuration for a bypass enabled NIC"
605                         " using the lowest port on the NIC.\n\n"
606
607 #ifdef RTE_LIBRTE_PMD_BOND
608                         "create bonded device (mode) (socket)\n"
609                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
610
611                         "add bonding slave (slave_id) (port_id)\n"
612                         "       Add a slave device to a bonded device.\n\n"
613
614                         "remove bonding slave (slave_id) (port_id)\n"
615                         "       Remove a slave device from a bonded device.\n\n"
616
617                         "set bonding mode (value) (port_id)\n"
618                         "       Set the bonding mode on a bonded device.\n\n"
619
620                         "set bonding primary (slave_id) (port_id)\n"
621                         "       Set the primary slave for a bonded device.\n\n"
622
623                         "show bonding config (port_id)\n"
624                         "       Show the bonding config for port_id.\n\n"
625
626                         "set bonding mac_addr (port_id) (address)\n"
627                         "       Set the MAC address of a bonded device.\n\n"
628
629                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
630                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
631
632                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
633                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
634
635                         "set bonding mon_period (port_id) (value)\n"
636                         "       Set the bonding link status monitoring polling period in ms.\n\n"
637
638                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
639                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
640
641 #endif
642                         "set link-up port (port_id)\n"
643                         "       Set link up for a port.\n\n"
644
645                         "set link-down port (port_id)\n"
646                         "       Set link down for a port.\n\n"
647
648                         "E-tag set insertion on port-tag-id (value)"
649                         " port (port_id) vf (vf_id)\n"
650                         "    Enable E-tag insertion for a VF on a port\n\n"
651
652                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
653                         "    Disable E-tag insertion for a VF on a port\n\n"
654
655                         "E-tag set stripping (on|off) port (port_id)\n"
656                         "    Enable/disable E-tag stripping on a port\n\n"
657
658                         "E-tag set forwarding (on|off) port (port_id)\n"
659                         "    Enable/disable E-tag based forwarding"
660                         " on a port\n\n"
661
662                         "E-tag set filter add e-tag-id (value) dst-pool"
663                         " (pool_id) port (port_id)\n"
664                         "    Add an E-tag forwarding filter on a port\n\n"
665
666                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
667                         "    Delete an E-tag forwarding filter on a port\n\n"
668
669 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
670                         "set port tm hierarchy default (port_id)\n"
671                         "       Set default traffic Management hierarchy on a port\n\n"
672
673 #endif
674                         "ddp add (port_id) (profile_path[,output_path])\n"
675                         "    Load a profile package on a port\n\n"
676
677                         "ddp del (port_id) (profile_path)\n"
678                         "    Delete a profile package from a port\n\n"
679
680                         "ptype mapping get (port_id) (valid_only)\n"
681                         "    Get ptype mapping on a port\n\n"
682
683                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
684                         "    Replace target with the pkt_type in ptype mapping\n\n"
685
686                         "ptype mapping reset (port_id)\n"
687                         "    Reset ptype mapping on a port\n\n"
688
689                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
690                         "    Update a ptype mapping item on a port\n\n"
691
692                         "set port (port_id) queue-region region_id (value) "
693                         "queue_start_index (value) queue_num (value)\n"
694                         "    Set a queue region on a port\n\n"
695
696                         "set port (port_id) queue-region region_id (value) "
697                         "flowtype (value)\n"
698                         "    Set a flowtype region index on a port\n\n"
699
700                         "set port (port_id) queue-region UP (value) region_id (value)\n"
701                         "    Set the mapping of User Priority to "
702                         "queue region on a port\n\n"
703
704                         "set port (port_id) queue-region flush (on|off)\n"
705                         "    flush all queue region related configuration\n\n"
706
707                         "show port meter cap (port_id)\n"
708                         "    Show port meter capability information\n\n"
709
710                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
711                         "    meter profile add - srtcm rfc 2697\n\n"
712
713                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
714                         "    meter profile add - trtcm rfc 2698\n\n"
715
716                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
717                         "    meter profile add - trtcm rfc 4115\n\n"
718
719                         "del port meter profile (port_id) (profile_id)\n"
720                         "    meter profile delete\n\n"
721
722                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
723                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
724                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
725                         "(dscp_tbl_entry63)]\n"
726                         "    meter create\n\n"
727
728                         "enable port meter (port_id) (mtr_id)\n"
729                         "    meter enable\n\n"
730
731                         "disable port meter (port_id) (mtr_id)\n"
732                         "    meter disable\n\n"
733
734                         "del port meter (port_id) (mtr_id)\n"
735                         "    meter delete\n\n"
736
737                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
738                         "    meter update meter profile\n\n"
739
740                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
741                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
742                         "    update meter dscp table entries\n\n"
743
744                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
745                         "(action0) [(action1) (action2)]\n"
746                         "    meter update policer action\n\n"
747
748                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
749                         "    meter update stats\n\n"
750
751                         "show port (port_id) queue-region\n"
752                         "    show all queue region related configuration info\n\n"
753
754                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
755                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
756                         "       Add port tm node private shaper profile.\n\n"
757
758                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
759                         "       Delete port tm node private shaper profile.\n\n"
760
761                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
762                         " (shaper_profile_id)\n"
763                         "       Add/update port tm node shared shaper.\n\n"
764
765                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
766                         "       Delete port tm node shared shaper.\n\n"
767
768                         "set port tm node shaper profile (port_id) (node_id)"
769                         " (shaper_profile_id)\n"
770                         "       Set port tm node shaper profile.\n\n"
771
772                         "add port tm node wred profile (port_id) (wred_profile_id)"
773                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
774                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
775                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
776                         "       Add port tm node wred profile.\n\n"
777
778                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
779                         "       Delete port tm node wred profile.\n\n"
780
781                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm nonleaf node.\n\n"
786
787                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
788                         " (priority) (weight) (level_id) (shaper_profile_id)"
789                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
790                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
791                         "       Add port tm leaf node.\n\n"
792
793                         "del port tm node (port_id) (node_id)\n"
794                         "       Delete port tm node.\n\n"
795
796                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
797                         " (priority) (weight)\n"
798                         "       Set port tm node parent.\n\n"
799
800                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
801                         "       Commit tm hierarchy.\n\n"
802
803                         , list_pkt_forwarding_modes()
804                 );
805         }
806
807         if (show_all || !strcmp(res->section, "ports")) {
808
809                 cmdline_printf(
810                         cl,
811                         "\n"
812                         "Port Operations:\n"
813                         "----------------\n\n"
814
815                         "port start (port_id|all)\n"
816                         "    Start all ports or port_id.\n\n"
817
818                         "port stop (port_id|all)\n"
819                         "    Stop all ports or port_id.\n\n"
820
821                         "port close (port_id|all)\n"
822                         "    Close all ports or port_id.\n\n"
823
824                         "port attach (ident)\n"
825                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
826
827                         "port detach (port_id)\n"
828                         "    Detach physical or virtual dev by port_id\n\n"
829
830                         "port config (port_id|all)"
831                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
832                         " duplex (half|full|auto)\n"
833                         "    Set speed and duplex for all ports or port_id\n\n"
834
835                         "port config all (rxq|txq|rxd|txd) (value)\n"
836                         "    Set number for rxq/txq/rxd/txd.\n\n"
837
838                         "port config all max-pkt-len (value)\n"
839                         "    Set the max packet length.\n\n"
840
841                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
842                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
843                         " (on|off)\n"
844                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
845                         " for ports.\n\n"
846
847                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
848                         "geneve|nvgre|none|<flowtype_id>)\n"
849                         "    Set the RSS mode.\n\n"
850
851                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
852                         "    Set the RSS redirection table.\n\n"
853
854                         "port config (port_id) dcb vt (on|off) (traffic_class)"
855                         " pfc (on|off)\n"
856                         "    Set the DCB mode.\n\n"
857
858                         "port config all burst (value)\n"
859                         "    Set the number of packets per burst.\n\n"
860
861                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
862                         " (value)\n"
863                         "    Set the ring prefetch/host/writeback threshold"
864                         " for tx/rx queue.\n\n"
865
866                         "port config all (txfreet|txrst|rxfreet) (value)\n"
867                         "    Set free threshold for rx/tx, or set"
868                         " tx rs bit threshold.\n\n"
869                         "port config mtu X value\n"
870                         "    Set the MTU of port X to a given value\n\n"
871
872                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
873                         "    Start/stop a rx/tx queue of port X. Only take effect"
874                         " when port X is started\n\n"
875
876                         "port config (port_id|all) l2-tunnel E-tag ether-type"
877                         " (value)\n"
878                         "    Set the value of E-tag ether-type.\n\n"
879
880                         "port config (port_id|all) l2-tunnel E-tag"
881                         " (enable|disable)\n"
882                         "    Enable/disable the E-tag support.\n\n"
883
884                         "port config (port_id) pctype mapping reset\n"
885                         "    Reset flow type to pctype mapping on a port\n\n"
886
887                         "port config (port_id) pctype mapping update"
888                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
889                         "    Update a flow type to pctype mapping item on a port\n\n"
890                 );
891         }
892
893         if (show_all || !strcmp(res->section, "registers")) {
894
895                 cmdline_printf(
896                         cl,
897                         "\n"
898                         "Registers:\n"
899                         "----------\n\n"
900
901                         "read reg (port_id) (address)\n"
902                         "    Display value of a port register.\n\n"
903
904                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
905                         "    Display a port register bit field.\n\n"
906
907                         "read regbit (port_id) (address) (bit_x)\n"
908                         "    Display a single port register bit.\n\n"
909
910                         "write reg (port_id) (address) (value)\n"
911                         "    Set value of a port register.\n\n"
912
913                         "write regfield (port_id) (address) (bit_x) (bit_y)"
914                         " (value)\n"
915                         "    Set bit field of a port register.\n\n"
916
917                         "write regbit (port_id) (address) (bit_x) (value)\n"
918                         "    Set single bit value of a port register.\n\n"
919                 );
920         }
921         if (show_all || !strcmp(res->section, "filters")) {
922
923                 cmdline_printf(
924                         cl,
925                         "\n"
926                         "filters:\n"
927                         "--------\n\n"
928
929                         "ethertype_filter (port_id) (add|del)"
930                         " (mac_addr|mac_ignr) (mac_address) ethertype"
931                         " (ether_type) (drop|fwd) queue (queue_id)\n"
932                         "    Add/Del an ethertype filter.\n\n"
933
934                         "2tuple_filter (port_id) (add|del)"
935                         " dst_port (dst_port_value) protocol (protocol_value)"
936                         " mask (mask_value) tcp_flags (tcp_flags_value)"
937                         " priority (prio_value) queue (queue_id)\n"
938                         "    Add/Del a 2tuple filter.\n\n"
939
940                         "5tuple_filter (port_id) (add|del)"
941                         " dst_ip (dst_address) src_ip (src_address)"
942                         " dst_port (dst_port_value) src_port (src_port_value)"
943                         " protocol (protocol_value)"
944                         " mask (mask_value) tcp_flags (tcp_flags_value)"
945                         " priority (prio_value) queue (queue_id)\n"
946                         "    Add/Del a 5tuple filter.\n\n"
947
948                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
949                         "    Add/Del syn filter.\n\n"
950
951                         "flex_filter (port_id) (add|del) len (len_value)"
952                         " bytes (bytes_value) mask (mask_value)"
953                         " priority (prio_value) queue (queue_id)\n"
954                         "    Add/Del a flex filter.\n\n"
955
956                         "flow_director_filter (port_id) mode IP (add|del|update)"
957                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
958                         " src (src_ip_address) dst (dst_ip_address)"
959                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
960                         " vlan (vlan_value) flexbytes (flexbytes_value)"
961                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
962                         " fd_id (fd_id_value)\n"
963                         "    Add/Del an IP type flow director filter.\n\n"
964
965                         "flow_director_filter (port_id) mode IP (add|del|update)"
966                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
967                         " src (src_ip_address) (src_port)"
968                         " dst (dst_ip_address) (dst_port)"
969                         " tos (tos_value) ttl (ttl_value)"
970                         " vlan (vlan_value) flexbytes (flexbytes_value)"
971                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
972                         " fd_id (fd_id_value)\n"
973                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
974
975                         "flow_director_filter (port_id) mode IP (add|del|update)"
976                         " flow (ipv4-sctp|ipv6-sctp)"
977                         " src (src_ip_address) (src_port)"
978                         " dst (dst_ip_address) (dst_port)"
979                         " tag (verification_tag) "
980                         " tos (tos_value) ttl (ttl_value)"
981                         " vlan (vlan_value)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a SCTP type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode IP (add|del|update)"
987                         " flow l2_payload ether (ethertype)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a l2 payload type flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " flexbytes (flexbytes_value) (drop|fwd)"
995                         " queue (queue_id) fd_id (fd_id_value)\n"
996                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
999                         " mac (mac_address) vlan (vlan_value)"
1000                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1001                         " flexbytes (flexbytes_value) (drop|fwd)"
1002                         " queue (queue_id) fd_id (fd_id_value)\n"
1003                         "    Add/Del a Tunnel flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode raw (add|del|update)"
1006                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1007                         " fd_id (fd_id_value) packet (packet file name)\n"
1008                         "    Add/Del a raw type flow director filter.\n\n"
1009
1010                         "flush_flow_director (port_id)\n"
1011                         "    Flush all flow director entries of a device.\n\n"
1012
1013                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1014                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1015                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1016                         "    Set flow director IP mask.\n\n"
1017
1018                         "flow_director_mask (port_id) mode MAC-VLAN"
1019                         " vlan (vlan_value)\n"
1020                         "    Set flow director MAC-VLAN mask.\n\n"
1021
1022                         "flow_director_mask (port_id) mode Tunnel"
1023                         " vlan (vlan_value) mac (mac_value)"
1024                         " tunnel-type (tunnel_type_value)"
1025                         " tunnel-id (tunnel_id_value)\n"
1026                         "    Set flow director Tunnel mask.\n\n"
1027
1028                         "flow_director_flex_mask (port_id)"
1029                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1030                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1031                         " (mask)\n"
1032                         "    Configure mask of flex payload.\n\n"
1033
1034                         "flow_director_flex_payload (port_id)"
1035                         " (raw|l2|l3|l4) (config)\n"
1036                         "    Configure flex payload selection.\n\n"
1037
1038                         "get_sym_hash_ena_per_port (port_id)\n"
1039                         "    get symmetric hash enable configuration per port.\n\n"
1040
1041                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1042                         "    set symmetric hash enable configuration per port"
1043                         " to enable or disable.\n\n"
1044
1045                         "get_hash_global_config (port_id)\n"
1046                         "    Get the global configurations of hash filters.\n\n"
1047
1048                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1049                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1050                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1051                         " (enable|disable)\n"
1052                         "    Set the global configurations of hash filters.\n\n"
1053
1054                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1055                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1056                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1057                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1058                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1059                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1060                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1061                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1062                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1063                         "fld-8th|none) (select|add)\n"
1064                         "    Set the input set for hash.\n\n"
1065
1066                         "set_fdir_input_set (port_id) "
1067                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1068                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1069                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1070                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1071                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1072                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1073                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1074                         " (select|add)\n"
1075                         "    Set the input set for FDir.\n\n"
1076
1077                         "flow validate {port_id}"
1078                         " [group {group_id}] [priority {level}]"
1079                         " [ingress] [egress]"
1080                         " pattern {item} [/ {item} [...]] / end"
1081                         " actions {action} [/ {action} [...]] / end\n"
1082                         "    Check whether a flow rule can be created.\n\n"
1083
1084                         "flow create {port_id}"
1085                         " [group {group_id}] [priority {level}]"
1086                         " [ingress] [egress]"
1087                         " pattern {item} [/ {item} [...]] / end"
1088                         " actions {action} [/ {action} [...]] / end\n"
1089                         "    Create a flow rule.\n\n"
1090
1091                         "flow destroy {port_id} rule {rule_id} [...]\n"
1092                         "    Destroy specific flow rules.\n\n"
1093
1094                         "flow flush {port_id}\n"
1095                         "    Destroy all flow rules.\n\n"
1096
1097                         "flow query {port_id} {rule_id} {action}\n"
1098                         "    Query an existing flow rule.\n\n"
1099
1100                         "flow list {port_id} [group {group_id}] [...]\n"
1101                         "    List existing flow rules sorted by priority,"
1102                         " filtered by group identifiers.\n\n"
1103
1104                         "flow isolate {port_id} {boolean}\n"
1105                         "    Restrict ingress traffic to the defined"
1106                         " flow rules\n\n"
1107                 );
1108         }
1109 }
1110
1111 cmdline_parse_token_string_t cmd_help_long_help =
1112         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1113
1114 cmdline_parse_token_string_t cmd_help_long_section =
1115         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1116                         "all#control#display#config#"
1117                         "ports#registers#filters");
1118
1119 cmdline_parse_inst_t cmd_help_long = {
1120         .f = cmd_help_long_parsed,
1121         .data = NULL,
1122         .help_str = "help all|control|display|config|ports|register|filters: "
1123                 "Show help",
1124         .tokens = {
1125                 (void *)&cmd_help_long_help,
1126                 (void *)&cmd_help_long_section,
1127                 NULL,
1128         },
1129 };
1130
1131
1132 /* *** start/stop/close all ports *** */
1133 struct cmd_operate_port_result {
1134         cmdline_fixed_string_t keyword;
1135         cmdline_fixed_string_t name;
1136         cmdline_fixed_string_t value;
1137 };
1138
1139 static void cmd_operate_port_parsed(void *parsed_result,
1140                                 __attribute__((unused)) struct cmdline *cl,
1141                                 __attribute__((unused)) void *data)
1142 {
1143         struct cmd_operate_port_result *res = parsed_result;
1144
1145         if (!strcmp(res->name, "start"))
1146                 start_port(RTE_PORT_ALL);
1147         else if (!strcmp(res->name, "stop"))
1148                 stop_port(RTE_PORT_ALL);
1149         else if (!strcmp(res->name, "close"))
1150                 close_port(RTE_PORT_ALL);
1151         else if (!strcmp(res->name, "reset"))
1152                 reset_port(RTE_PORT_ALL);
1153         else
1154                 printf("Unknown parameter\n");
1155 }
1156
1157 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1158         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1159                                                                 "port");
1160 cmdline_parse_token_string_t cmd_operate_port_all_port =
1161         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1162                                                 "start#stop#close#reset");
1163 cmdline_parse_token_string_t cmd_operate_port_all_all =
1164         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1165
1166 cmdline_parse_inst_t cmd_operate_port = {
1167         .f = cmd_operate_port_parsed,
1168         .data = NULL,
1169         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1170         .tokens = {
1171                 (void *)&cmd_operate_port_all_cmd,
1172                 (void *)&cmd_operate_port_all_port,
1173                 (void *)&cmd_operate_port_all_all,
1174                 NULL,
1175         },
1176 };
1177
1178 /* *** start/stop/close specific port *** */
1179 struct cmd_operate_specific_port_result {
1180         cmdline_fixed_string_t keyword;
1181         cmdline_fixed_string_t name;
1182         uint8_t value;
1183 };
1184
1185 static void cmd_operate_specific_port_parsed(void *parsed_result,
1186                         __attribute__((unused)) struct cmdline *cl,
1187                                 __attribute__((unused)) void *data)
1188 {
1189         struct cmd_operate_specific_port_result *res = parsed_result;
1190
1191         if (!strcmp(res->name, "start"))
1192                 start_port(res->value);
1193         else if (!strcmp(res->name, "stop"))
1194                 stop_port(res->value);
1195         else if (!strcmp(res->name, "close"))
1196                 close_port(res->value);
1197         else if (!strcmp(res->name, "reset"))
1198                 reset_port(res->value);
1199         else
1200                 printf("Unknown parameter\n");
1201 }
1202
1203 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1204         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1205                                                         keyword, "port");
1206 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1207         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1208                                                 name, "start#stop#close#reset");
1209 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1210         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1211                                                         value, UINT8);
1212
1213 cmdline_parse_inst_t cmd_operate_specific_port = {
1214         .f = cmd_operate_specific_port_parsed,
1215         .data = NULL,
1216         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1217         .tokens = {
1218                 (void *)&cmd_operate_specific_port_cmd,
1219                 (void *)&cmd_operate_specific_port_port,
1220                 (void *)&cmd_operate_specific_port_id,
1221                 NULL,
1222         },
1223 };
1224
1225 /* *** attach a specified port *** */
1226 struct cmd_operate_attach_port_result {
1227         cmdline_fixed_string_t port;
1228         cmdline_fixed_string_t keyword;
1229         cmdline_fixed_string_t identifier;
1230 };
1231
1232 static void cmd_operate_attach_port_parsed(void *parsed_result,
1233                                 __attribute__((unused)) struct cmdline *cl,
1234                                 __attribute__((unused)) void *data)
1235 {
1236         struct cmd_operate_attach_port_result *res = parsed_result;
1237
1238         if (!strcmp(res->keyword, "attach"))
1239                 attach_port(res->identifier);
1240         else
1241                 printf("Unknown parameter\n");
1242 }
1243
1244 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1245         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1246                         port, "port");
1247 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1248         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1249                         keyword, "attach");
1250 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1251         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1252                         identifier, NULL);
1253
1254 cmdline_parse_inst_t cmd_operate_attach_port = {
1255         .f = cmd_operate_attach_port_parsed,
1256         .data = NULL,
1257         .help_str = "port attach <identifier>: "
1258                 "(identifier: pci address or virtual dev name)",
1259         .tokens = {
1260                 (void *)&cmd_operate_attach_port_port,
1261                 (void *)&cmd_operate_attach_port_keyword,
1262                 (void *)&cmd_operate_attach_port_identifier,
1263                 NULL,
1264         },
1265 };
1266
1267 /* *** detach a specified port *** */
1268 struct cmd_operate_detach_port_result {
1269         cmdline_fixed_string_t port;
1270         cmdline_fixed_string_t keyword;
1271         portid_t port_id;
1272 };
1273
1274 static void cmd_operate_detach_port_parsed(void *parsed_result,
1275                                 __attribute__((unused)) struct cmdline *cl,
1276                                 __attribute__((unused)) void *data)
1277 {
1278         struct cmd_operate_detach_port_result *res = parsed_result;
1279
1280         if (!strcmp(res->keyword, "detach"))
1281                 detach_port(res->port_id);
1282         else
1283                 printf("Unknown parameter\n");
1284 }
1285
1286 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1287         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1288                         port, "port");
1289 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1290         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1291                         keyword, "detach");
1292 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1293         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1294                         port_id, UINT16);
1295
1296 cmdline_parse_inst_t cmd_operate_detach_port = {
1297         .f = cmd_operate_detach_port_parsed,
1298         .data = NULL,
1299         .help_str = "port detach <port_id>",
1300         .tokens = {
1301                 (void *)&cmd_operate_detach_port_port,
1302                 (void *)&cmd_operate_detach_port_keyword,
1303                 (void *)&cmd_operate_detach_port_port_id,
1304                 NULL,
1305         },
1306 };
1307
1308 /* *** configure speed for all ports *** */
1309 struct cmd_config_speed_all {
1310         cmdline_fixed_string_t port;
1311         cmdline_fixed_string_t keyword;
1312         cmdline_fixed_string_t all;
1313         cmdline_fixed_string_t item1;
1314         cmdline_fixed_string_t item2;
1315         cmdline_fixed_string_t value1;
1316         cmdline_fixed_string_t value2;
1317 };
1318
1319 static int
1320 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1321 {
1322
1323         int duplex;
1324
1325         if (!strcmp(duplexstr, "half")) {
1326                 duplex = ETH_LINK_HALF_DUPLEX;
1327         } else if (!strcmp(duplexstr, "full")) {
1328                 duplex = ETH_LINK_FULL_DUPLEX;
1329         } else if (!strcmp(duplexstr, "auto")) {
1330                 duplex = ETH_LINK_FULL_DUPLEX;
1331         } else {
1332                 printf("Unknown duplex parameter\n");
1333                 return -1;
1334         }
1335
1336         if (!strcmp(speedstr, "10")) {
1337                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1338                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1339         } else if (!strcmp(speedstr, "100")) {
1340                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1341                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1342         } else {
1343                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1344                         printf("Invalid speed/duplex parameters\n");
1345                         return -1;
1346                 }
1347                 if (!strcmp(speedstr, "1000")) {
1348                         *speed = ETH_LINK_SPEED_1G;
1349                 } else if (!strcmp(speedstr, "10000")) {
1350                         *speed = ETH_LINK_SPEED_10G;
1351                 } else if (!strcmp(speedstr, "25000")) {
1352                         *speed = ETH_LINK_SPEED_25G;
1353                 } else if (!strcmp(speedstr, "40000")) {
1354                         *speed = ETH_LINK_SPEED_40G;
1355                 } else if (!strcmp(speedstr, "50000")) {
1356                         *speed = ETH_LINK_SPEED_50G;
1357                 } else if (!strcmp(speedstr, "100000")) {
1358                         *speed = ETH_LINK_SPEED_100G;
1359                 } else if (!strcmp(speedstr, "auto")) {
1360                         *speed = ETH_LINK_SPEED_AUTONEG;
1361                 } else {
1362                         printf("Unknown speed parameter\n");
1363                         return -1;
1364                 }
1365         }
1366
1367         return 0;
1368 }
1369
1370 static void
1371 cmd_config_speed_all_parsed(void *parsed_result,
1372                         __attribute__((unused)) struct cmdline *cl,
1373                         __attribute__((unused)) void *data)
1374 {
1375         struct cmd_config_speed_all *res = parsed_result;
1376         uint32_t link_speed;
1377         portid_t pid;
1378
1379         if (!all_ports_stopped()) {
1380                 printf("Please stop all ports first\n");
1381                 return;
1382         }
1383
1384         if (parse_and_check_speed_duplex(res->value1, res->value2,
1385                         &link_speed) < 0)
1386                 return;
1387
1388         RTE_ETH_FOREACH_DEV(pid) {
1389                 ports[pid].dev_conf.link_speeds = link_speed;
1390         }
1391
1392         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1393 }
1394
1395 cmdline_parse_token_string_t cmd_config_speed_all_port =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1397 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1398         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1399                                                         "config");
1400 cmdline_parse_token_string_t cmd_config_speed_all_all =
1401         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1402 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1403         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1404 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1406                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1407 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1408         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1409 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1410         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1411                                                 "half#full#auto");
1412
1413 cmdline_parse_inst_t cmd_config_speed_all = {
1414         .f = cmd_config_speed_all_parsed,
1415         .data = NULL,
1416         .help_str = "port config all speed "
1417                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1418                                                         "half|full|auto",
1419         .tokens = {
1420                 (void *)&cmd_config_speed_all_port,
1421                 (void *)&cmd_config_speed_all_keyword,
1422                 (void *)&cmd_config_speed_all_all,
1423                 (void *)&cmd_config_speed_all_item1,
1424                 (void *)&cmd_config_speed_all_value1,
1425                 (void *)&cmd_config_speed_all_item2,
1426                 (void *)&cmd_config_speed_all_value2,
1427                 NULL,
1428         },
1429 };
1430
1431 /* *** configure speed for specific port *** */
1432 struct cmd_config_speed_specific {
1433         cmdline_fixed_string_t port;
1434         cmdline_fixed_string_t keyword;
1435         uint8_t id;
1436         cmdline_fixed_string_t item1;
1437         cmdline_fixed_string_t item2;
1438         cmdline_fixed_string_t value1;
1439         cmdline_fixed_string_t value2;
1440 };
1441
1442 static void
1443 cmd_config_speed_specific_parsed(void *parsed_result,
1444                                 __attribute__((unused)) struct cmdline *cl,
1445                                 __attribute__((unused)) void *data)
1446 {
1447         struct cmd_config_speed_specific *res = parsed_result;
1448         uint32_t link_speed;
1449
1450         if (!all_ports_stopped()) {
1451                 printf("Please stop all ports first\n");
1452                 return;
1453         }
1454
1455         if (port_id_is_invalid(res->id, ENABLED_WARN))
1456                 return;
1457
1458         if (parse_and_check_speed_duplex(res->value1, res->value2,
1459                         &link_speed) < 0)
1460                 return;
1461
1462         ports[res->id].dev_conf.link_speeds = link_speed;
1463
1464         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1465 }
1466
1467
1468 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1470                                                                 "port");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1473                                                                 "config");
1474 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1475         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1476 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1477         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1478                                                                 "speed");
1479 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1480         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1481                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1482 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1483         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1484                                                                 "duplex");
1485 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1486         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1487                                                         "half#full#auto");
1488
1489 cmdline_parse_inst_t cmd_config_speed_specific = {
1490         .f = cmd_config_speed_specific_parsed,
1491         .data = NULL,
1492         .help_str = "port config <port_id> speed "
1493                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1494                                                         "half|full|auto",
1495         .tokens = {
1496                 (void *)&cmd_config_speed_specific_port,
1497                 (void *)&cmd_config_speed_specific_keyword,
1498                 (void *)&cmd_config_speed_specific_id,
1499                 (void *)&cmd_config_speed_specific_item1,
1500                 (void *)&cmd_config_speed_specific_value1,
1501                 (void *)&cmd_config_speed_specific_item2,
1502                 (void *)&cmd_config_speed_specific_value2,
1503                 NULL,
1504         },
1505 };
1506
1507 /* *** configure txq/rxq, txd/rxd *** */
1508 struct cmd_config_rx_tx {
1509         cmdline_fixed_string_t port;
1510         cmdline_fixed_string_t keyword;
1511         cmdline_fixed_string_t all;
1512         cmdline_fixed_string_t name;
1513         uint16_t value;
1514 };
1515
1516 static void
1517 cmd_config_rx_tx_parsed(void *parsed_result,
1518                         __attribute__((unused)) struct cmdline *cl,
1519                         __attribute__((unused)) void *data)
1520 {
1521         struct cmd_config_rx_tx *res = parsed_result;
1522
1523         if (!all_ports_stopped()) {
1524                 printf("Please stop all ports first\n");
1525                 return;
1526         }
1527         if (!strcmp(res->name, "rxq")) {
1528                 if (!res->value && !nb_txq) {
1529                         printf("Warning: Either rx or tx queues should be non zero\n");
1530                         return;
1531                 }
1532                 nb_rxq = res->value;
1533         }
1534         else if (!strcmp(res->name, "txq")) {
1535                 if (!res->value && !nb_rxq) {
1536                         printf("Warning: Either rx or tx queues should be non zero\n");
1537                         return;
1538                 }
1539                 nb_txq = res->value;
1540         }
1541         else if (!strcmp(res->name, "rxd")) {
1542                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1543                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1544                                         res->value, RTE_TEST_RX_DESC_MAX);
1545                         return;
1546                 }
1547                 nb_rxd = res->value;
1548         } else if (!strcmp(res->name, "txd")) {
1549                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1550                         printf("txd %d invalid - must be > 0 && <= %d\n",
1551                                         res->value, RTE_TEST_TX_DESC_MAX);
1552                         return;
1553                 }
1554                 nb_txd = res->value;
1555         } else {
1556                 printf("Unknown parameter\n");
1557                 return;
1558         }
1559
1560         fwd_config_setup();
1561
1562         init_port_config();
1563
1564         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1565 }
1566
1567 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1568         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1569 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1571 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1572         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1573 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1574         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1575                                                 "rxq#txq#rxd#txd");
1576 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1577         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1578
1579 cmdline_parse_inst_t cmd_config_rx_tx = {
1580         .f = cmd_config_rx_tx_parsed,
1581         .data = NULL,
1582         .help_str = "port config all rxq|txq|rxd|txd <value>",
1583         .tokens = {
1584                 (void *)&cmd_config_rx_tx_port,
1585                 (void *)&cmd_config_rx_tx_keyword,
1586                 (void *)&cmd_config_rx_tx_all,
1587                 (void *)&cmd_config_rx_tx_name,
1588                 (void *)&cmd_config_rx_tx_value,
1589                 NULL,
1590         },
1591 };
1592
1593 /* *** config max packet length *** */
1594 struct cmd_config_max_pkt_len_result {
1595         cmdline_fixed_string_t port;
1596         cmdline_fixed_string_t keyword;
1597         cmdline_fixed_string_t all;
1598         cmdline_fixed_string_t name;
1599         uint32_t value;
1600 };
1601
1602 static void
1603 cmd_config_max_pkt_len_parsed(void *parsed_result,
1604                                 __attribute__((unused)) struct cmdline *cl,
1605                                 __attribute__((unused)) void *data)
1606 {
1607         struct cmd_config_max_pkt_len_result *res = parsed_result;
1608         portid_t pid;
1609
1610         if (!all_ports_stopped()) {
1611                 printf("Please stop all ports first\n");
1612                 return;
1613         }
1614
1615         RTE_ETH_FOREACH_DEV(pid) {
1616                 struct rte_port *port = &ports[pid];
1617                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1618
1619                 if (!strcmp(res->name, "max-pkt-len")) {
1620                         if (res->value < ETHER_MIN_LEN) {
1621                                 printf("max-pkt-len can not be less than %d\n",
1622                                                 ETHER_MIN_LEN);
1623                                 return;
1624                         }
1625                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1626                                 return;
1627
1628                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1629                         if (res->value > ETHER_MAX_LEN)
1630                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1631                         else
1632                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1633                         port->dev_conf.rxmode.offloads = rx_offloads;
1634                 } else {
1635                         printf("Unknown parameter\n");
1636                         return;
1637                 }
1638         }
1639
1640         init_port_config();
1641
1642         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1643 }
1644
1645 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1646         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1647                                                                 "port");
1648 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1649         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1650                                                                 "config");
1651 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1653                                                                 "all");
1654 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1655         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1656                                                                 "max-pkt-len");
1657 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1658         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1659                                                                 UINT32);
1660
1661 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1662         .f = cmd_config_max_pkt_len_parsed,
1663         .data = NULL,
1664         .help_str = "port config all max-pkt-len <value>",
1665         .tokens = {
1666                 (void *)&cmd_config_max_pkt_len_port,
1667                 (void *)&cmd_config_max_pkt_len_keyword,
1668                 (void *)&cmd_config_max_pkt_len_all,
1669                 (void *)&cmd_config_max_pkt_len_name,
1670                 (void *)&cmd_config_max_pkt_len_value,
1671                 NULL,
1672         },
1673 };
1674
1675 /* *** configure port MTU *** */
1676 struct cmd_config_mtu_result {
1677         cmdline_fixed_string_t port;
1678         cmdline_fixed_string_t keyword;
1679         cmdline_fixed_string_t mtu;
1680         portid_t port_id;
1681         uint16_t value;
1682 };
1683
1684 static void
1685 cmd_config_mtu_parsed(void *parsed_result,
1686                       __attribute__((unused)) struct cmdline *cl,
1687                       __attribute__((unused)) void *data)
1688 {
1689         struct cmd_config_mtu_result *res = parsed_result;
1690
1691         if (res->value < ETHER_MIN_LEN) {
1692                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1693                 return;
1694         }
1695         port_mtu_set(res->port_id, res->value);
1696 }
1697
1698 cmdline_parse_token_string_t cmd_config_mtu_port =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1700                                  "port");
1701 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1702         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1703                                  "config");
1704 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1705         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1706                                  "mtu");
1707 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1708         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1709 cmdline_parse_token_num_t cmd_config_mtu_value =
1710         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1711
1712 cmdline_parse_inst_t cmd_config_mtu = {
1713         .f = cmd_config_mtu_parsed,
1714         .data = NULL,
1715         .help_str = "port config mtu <port_id> <value>",
1716         .tokens = {
1717                 (void *)&cmd_config_mtu_port,
1718                 (void *)&cmd_config_mtu_keyword,
1719                 (void *)&cmd_config_mtu_mtu,
1720                 (void *)&cmd_config_mtu_port_id,
1721                 (void *)&cmd_config_mtu_value,
1722                 NULL,
1723         },
1724 };
1725
1726 /* *** configure rx mode *** */
1727 struct cmd_config_rx_mode_flag {
1728         cmdline_fixed_string_t port;
1729         cmdline_fixed_string_t keyword;
1730         cmdline_fixed_string_t all;
1731         cmdline_fixed_string_t name;
1732         cmdline_fixed_string_t value;
1733 };
1734
1735 static void
1736 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1737                                 __attribute__((unused)) struct cmdline *cl,
1738                                 __attribute__((unused)) void *data)
1739 {
1740         struct cmd_config_rx_mode_flag *res = parsed_result;
1741         portid_t pid;
1742
1743         if (!all_ports_stopped()) {
1744                 printf("Please stop all ports first\n");
1745                 return;
1746         }
1747
1748         RTE_ETH_FOREACH_DEV(pid) {
1749                 struct rte_port *port;
1750                 uint64_t rx_offloads;
1751
1752                 port = &ports[pid];
1753                 rx_offloads = port->dev_conf.rxmode.offloads;
1754                 if (!strcmp(res->name, "crc-strip")) {
1755                         if (!strcmp(res->value, "on"))
1756                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1757                         else if (!strcmp(res->value, "off"))
1758                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1759                         else {
1760                                 printf("Unknown parameter\n");
1761                                 return;
1762                         }
1763                 } else if (!strcmp(res->name, "scatter")) {
1764                         if (!strcmp(res->value, "on")) {
1765                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1766                         } else if (!strcmp(res->value, "off")) {
1767                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1768                         } else {
1769                                 printf("Unknown parameter\n");
1770                                 return;
1771                         }
1772                 } else if (!strcmp(res->name, "rx-cksum")) {
1773                         if (!strcmp(res->value, "on"))
1774                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1775                         else if (!strcmp(res->value, "off"))
1776                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1777                         else {
1778                                 printf("Unknown parameter\n");
1779                                 return;
1780                         }
1781                 } else if (!strcmp(res->name, "rx-timestamp")) {
1782                         if (!strcmp(res->value, "on"))
1783                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1784                         else if (!strcmp(res->value, "off"))
1785                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1786                         else {
1787                                 printf("Unknown parameter\n");
1788                                 return;
1789                         }
1790                 } else if (!strcmp(res->name, "hw-vlan")) {
1791                         if (!strcmp(res->value, "on")) {
1792                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1793                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1794                         } else if (!strcmp(res->value, "off")) {
1795                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1796                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1797                         } else {
1798                                 printf("Unknown parameter\n");
1799                                 return;
1800                         }
1801                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1802                         if (!strcmp(res->value, "on"))
1803                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1804                         else if (!strcmp(res->value, "off"))
1805                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1806                         else {
1807                                 printf("Unknown parameter\n");
1808                                 return;
1809                         }
1810                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1811                         if (!strcmp(res->value, "on"))
1812                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1813                         else if (!strcmp(res->value, "off"))
1814                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1815                         else {
1816                                 printf("Unknown parameter\n");
1817                                 return;
1818                         }
1819                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1820                         if (!strcmp(res->value, "on"))
1821                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1822                         else if (!strcmp(res->value, "off"))
1823                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1824                         else {
1825                                 printf("Unknown parameter\n");
1826                                 return;
1827                         }
1828                 } else if (!strcmp(res->name, "drop-en")) {
1829                         if (!strcmp(res->value, "on"))
1830                                 rx_drop_en = 1;
1831                         else if (!strcmp(res->value, "off"))
1832                                 rx_drop_en = 0;
1833                         else {
1834                                 printf("Unknown parameter\n");
1835                                 return;
1836                         }
1837                 } else {
1838                         printf("Unknown parameter\n");
1839                         return;
1840                 }
1841                 port->dev_conf.rxmode.offloads = rx_offloads;
1842         }
1843
1844         init_port_config();
1845
1846         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1847 }
1848
1849 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1851 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1853                                                                 "config");
1854 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1856 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1858                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1859                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1860 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1862                                                         "on#off");
1863
1864 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1865         .f = cmd_config_rx_mode_flag_parsed,
1866         .data = NULL,
1867         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1868                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1869         .tokens = {
1870                 (void *)&cmd_config_rx_mode_flag_port,
1871                 (void *)&cmd_config_rx_mode_flag_keyword,
1872                 (void *)&cmd_config_rx_mode_flag_all,
1873                 (void *)&cmd_config_rx_mode_flag_name,
1874                 (void *)&cmd_config_rx_mode_flag_value,
1875                 NULL,
1876         },
1877 };
1878
1879 /* *** configure rss *** */
1880 struct cmd_config_rss {
1881         cmdline_fixed_string_t port;
1882         cmdline_fixed_string_t keyword;
1883         cmdline_fixed_string_t all;
1884         cmdline_fixed_string_t name;
1885         cmdline_fixed_string_t value;
1886 };
1887
1888 static void
1889 cmd_config_rss_parsed(void *parsed_result,
1890                         __attribute__((unused)) struct cmdline *cl,
1891                         __attribute__((unused)) void *data)
1892 {
1893         struct cmd_config_rss *res = parsed_result;
1894         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1895         int diag;
1896         uint8_t i;
1897
1898         if (!strcmp(res->value, "all"))
1899                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1900                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1901                                         ETH_RSS_L2_PAYLOAD;
1902         else if (!strcmp(res->value, "ip"))
1903                 rss_conf.rss_hf = ETH_RSS_IP;
1904         else if (!strcmp(res->value, "udp"))
1905                 rss_conf.rss_hf = ETH_RSS_UDP;
1906         else if (!strcmp(res->value, "tcp"))
1907                 rss_conf.rss_hf = ETH_RSS_TCP;
1908         else if (!strcmp(res->value, "sctp"))
1909                 rss_conf.rss_hf = ETH_RSS_SCTP;
1910         else if (!strcmp(res->value, "ether"))
1911                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1912         else if (!strcmp(res->value, "port"))
1913                 rss_conf.rss_hf = ETH_RSS_PORT;
1914         else if (!strcmp(res->value, "vxlan"))
1915                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1916         else if (!strcmp(res->value, "geneve"))
1917                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1918         else if (!strcmp(res->value, "nvgre"))
1919                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1920         else if (!strcmp(res->value, "none"))
1921                 rss_conf.rss_hf = 0;
1922         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1923                                                 atoi(res->value) < 64)
1924                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1925         else {
1926                 printf("Unknown parameter\n");
1927                 return;
1928         }
1929         rss_conf.rss_key = NULL;
1930         for (i = 0; i < rte_eth_dev_count(); i++) {
1931                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1932                 if (diag < 0)
1933                         printf("Configuration of RSS hash at ethernet port %d "
1934                                 "failed with error (%d): %s.\n",
1935                                 i, -diag, strerror(-diag));
1936         }
1937 }
1938
1939 cmdline_parse_token_string_t cmd_config_rss_port =
1940         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1941 cmdline_parse_token_string_t cmd_config_rss_keyword =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1943 cmdline_parse_token_string_t cmd_config_rss_all =
1944         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1945 cmdline_parse_token_string_t cmd_config_rss_name =
1946         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1947 cmdline_parse_token_string_t cmd_config_rss_value =
1948         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1949
1950 cmdline_parse_inst_t cmd_config_rss = {
1951         .f = cmd_config_rss_parsed,
1952         .data = NULL,
1953         .help_str = "port config all rss "
1954                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1955         .tokens = {
1956                 (void *)&cmd_config_rss_port,
1957                 (void *)&cmd_config_rss_keyword,
1958                 (void *)&cmd_config_rss_all,
1959                 (void *)&cmd_config_rss_name,
1960                 (void *)&cmd_config_rss_value,
1961                 NULL,
1962         },
1963 };
1964
1965 /* *** configure rss hash key *** */
1966 struct cmd_config_rss_hash_key {
1967         cmdline_fixed_string_t port;
1968         cmdline_fixed_string_t config;
1969         portid_t port_id;
1970         cmdline_fixed_string_t rss_hash_key;
1971         cmdline_fixed_string_t rss_type;
1972         cmdline_fixed_string_t key;
1973 };
1974
1975 static uint8_t
1976 hexa_digit_to_value(char hexa_digit)
1977 {
1978         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1979                 return (uint8_t) (hexa_digit - '0');
1980         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1981                 return (uint8_t) ((hexa_digit - 'a') + 10);
1982         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1983                 return (uint8_t) ((hexa_digit - 'A') + 10);
1984         /* Invalid hexa digit */
1985         return 0xFF;
1986 }
1987
1988 static uint8_t
1989 parse_and_check_key_hexa_digit(char *key, int idx)
1990 {
1991         uint8_t hexa_v;
1992
1993         hexa_v = hexa_digit_to_value(key[idx]);
1994         if (hexa_v == 0xFF)
1995                 printf("invalid key: character %c at position %d is not a "
1996                        "valid hexa digit\n", key[idx], idx);
1997         return hexa_v;
1998 }
1999
2000 static void
2001 cmd_config_rss_hash_key_parsed(void *parsed_result,
2002                                __attribute__((unused)) struct cmdline *cl,
2003                                __attribute__((unused)) void *data)
2004 {
2005         struct cmd_config_rss_hash_key *res = parsed_result;
2006         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2007         uint8_t xdgt0;
2008         uint8_t xdgt1;
2009         int i;
2010         struct rte_eth_dev_info dev_info;
2011         uint8_t hash_key_size;
2012         uint32_t key_len;
2013
2014         memset(&dev_info, 0, sizeof(dev_info));
2015         rte_eth_dev_info_get(res->port_id, &dev_info);
2016         if (dev_info.hash_key_size > 0 &&
2017                         dev_info.hash_key_size <= sizeof(hash_key))
2018                 hash_key_size = dev_info.hash_key_size;
2019         else {
2020                 printf("dev_info did not provide a valid hash key size\n");
2021                 return;
2022         }
2023         /* Check the length of the RSS hash key */
2024         key_len = strlen(res->key);
2025         if (key_len != (hash_key_size * 2)) {
2026                 printf("key length: %d invalid - key must be a string of %d"
2027                            " hexa-decimal numbers\n",
2028                            (int) key_len, hash_key_size * 2);
2029                 return;
2030         }
2031         /* Translate RSS hash key into binary representation */
2032         for (i = 0; i < hash_key_size; i++) {
2033                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2034                 if (xdgt0 == 0xFF)
2035                         return;
2036                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2037                 if (xdgt1 == 0xFF)
2038                         return;
2039                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2040         }
2041         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2042                         hash_key_size);
2043 }
2044
2045 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2046         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2047 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2048         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2049                                  "config");
2050 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2051         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2052 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2053         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2054                                  rss_hash_key, "rss-hash-key");
2055 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2057                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2058                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2059                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2060                                  "ipv6-tcp-ex#ipv6-udp-ex");
2061 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2062         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2063
2064 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2065         .f = cmd_config_rss_hash_key_parsed,
2066         .data = NULL,
2067         .help_str = "port config <port_id> rss-hash-key "
2068                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2069                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2070                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2071                 "<string of hex digits (variable length, NIC dependent)>",
2072         .tokens = {
2073                 (void *)&cmd_config_rss_hash_key_port,
2074                 (void *)&cmd_config_rss_hash_key_config,
2075                 (void *)&cmd_config_rss_hash_key_port_id,
2076                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2077                 (void *)&cmd_config_rss_hash_key_rss_type,
2078                 (void *)&cmd_config_rss_hash_key_value,
2079                 NULL,
2080         },
2081 };
2082
2083 /* *** configure port rxq/txq start/stop *** */
2084 struct cmd_config_rxtx_queue {
2085         cmdline_fixed_string_t port;
2086         portid_t portid;
2087         cmdline_fixed_string_t rxtxq;
2088         uint16_t qid;
2089         cmdline_fixed_string_t opname;
2090 };
2091
2092 static void
2093 cmd_config_rxtx_queue_parsed(void *parsed_result,
2094                         __attribute__((unused)) struct cmdline *cl,
2095                         __attribute__((unused)) void *data)
2096 {
2097         struct cmd_config_rxtx_queue *res = parsed_result;
2098         uint8_t isrx;
2099         uint8_t isstart;
2100         int ret = 0;
2101
2102         if (test_done == 0) {
2103                 printf("Please stop forwarding first\n");
2104                 return;
2105         }
2106
2107         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2108                 return;
2109
2110         if (port_is_started(res->portid) != 1) {
2111                 printf("Please start port %u first\n", res->portid);
2112                 return;
2113         }
2114
2115         if (!strcmp(res->rxtxq, "rxq"))
2116                 isrx = 1;
2117         else if (!strcmp(res->rxtxq, "txq"))
2118                 isrx = 0;
2119         else {
2120                 printf("Unknown parameter\n");
2121                 return;
2122         }
2123
2124         if (isrx && rx_queue_id_is_invalid(res->qid))
2125                 return;
2126         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2127                 return;
2128
2129         if (!strcmp(res->opname, "start"))
2130                 isstart = 1;
2131         else if (!strcmp(res->opname, "stop"))
2132                 isstart = 0;
2133         else {
2134                 printf("Unknown parameter\n");
2135                 return;
2136         }
2137
2138         if (isstart && isrx)
2139                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2140         else if (!isstart && isrx)
2141                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2142         else if (isstart && !isrx)
2143                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2144         else
2145                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2146
2147         if (ret == -ENOTSUP)
2148                 printf("Function not supported in PMD driver\n");
2149 }
2150
2151 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2152         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2153 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2154         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2155 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2157 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2158         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2159 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2161                                                 "start#stop");
2162
2163 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2164         .f = cmd_config_rxtx_queue_parsed,
2165         .data = NULL,
2166         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2167         .tokens = {
2168                 (void *)&cmd_config_speed_all_port,
2169                 (void *)&cmd_config_rxtx_queue_portid,
2170                 (void *)&cmd_config_rxtx_queue_rxtxq,
2171                 (void *)&cmd_config_rxtx_queue_qid,
2172                 (void *)&cmd_config_rxtx_queue_opname,
2173                 NULL,
2174         },
2175 };
2176
2177 /* *** Configure RSS RETA *** */
2178 struct cmd_config_rss_reta {
2179         cmdline_fixed_string_t port;
2180         cmdline_fixed_string_t keyword;
2181         portid_t port_id;
2182         cmdline_fixed_string_t name;
2183         cmdline_fixed_string_t list_name;
2184         cmdline_fixed_string_t list_of_items;
2185 };
2186
2187 static int
2188 parse_reta_config(const char *str,
2189                   struct rte_eth_rss_reta_entry64 *reta_conf,
2190                   uint16_t nb_entries)
2191 {
2192         int i;
2193         unsigned size;
2194         uint16_t hash_index, idx, shift;
2195         uint16_t nb_queue;
2196         char s[256];
2197         const char *p, *p0 = str;
2198         char *end;
2199         enum fieldnames {
2200                 FLD_HASH_INDEX = 0,
2201                 FLD_QUEUE,
2202                 _NUM_FLD
2203         };
2204         unsigned long int_fld[_NUM_FLD];
2205         char *str_fld[_NUM_FLD];
2206
2207         while ((p = strchr(p0,'(')) != NULL) {
2208                 ++p;
2209                 if((p0 = strchr(p,')')) == NULL)
2210                         return -1;
2211
2212                 size = p0 - p;
2213                 if(size >= sizeof(s))
2214                         return -1;
2215
2216                 snprintf(s, sizeof(s), "%.*s", size, p);
2217                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2218                         return -1;
2219                 for (i = 0; i < _NUM_FLD; i++) {
2220                         errno = 0;
2221                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2222                         if (errno != 0 || end == str_fld[i] ||
2223                                         int_fld[i] > 65535)
2224                                 return -1;
2225                 }
2226
2227                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2228                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2229
2230                 if (hash_index >= nb_entries) {
2231                         printf("Invalid RETA hash index=%d\n", hash_index);
2232                         return -1;
2233                 }
2234
2235                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2236                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2237                 reta_conf[idx].mask |= (1ULL << shift);
2238                 reta_conf[idx].reta[shift] = nb_queue;
2239         }
2240
2241         return 0;
2242 }
2243
2244 static void
2245 cmd_set_rss_reta_parsed(void *parsed_result,
2246                         __attribute__((unused)) struct cmdline *cl,
2247                         __attribute__((unused)) void *data)
2248 {
2249         int ret;
2250         struct rte_eth_dev_info dev_info;
2251         struct rte_eth_rss_reta_entry64 reta_conf[8];
2252         struct cmd_config_rss_reta *res = parsed_result;
2253
2254         memset(&dev_info, 0, sizeof(dev_info));
2255         rte_eth_dev_info_get(res->port_id, &dev_info);
2256         if (dev_info.reta_size == 0) {
2257                 printf("Redirection table size is 0 which is "
2258                                         "invalid for RSS\n");
2259                 return;
2260         } else
2261                 printf("The reta size of port %d is %u\n",
2262                         res->port_id, dev_info.reta_size);
2263         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2264                 printf("Currently do not support more than %u entries of "
2265                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2266                 return;
2267         }
2268
2269         memset(reta_conf, 0, sizeof(reta_conf));
2270         if (!strcmp(res->list_name, "reta")) {
2271                 if (parse_reta_config(res->list_of_items, reta_conf,
2272                                                 dev_info.reta_size)) {
2273                         printf("Invalid RSS Redirection Table "
2274                                         "config entered\n");
2275                         return;
2276                 }
2277                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2278                                 reta_conf, dev_info.reta_size);
2279                 if (ret != 0)
2280                         printf("Bad redirection table parameter, "
2281                                         "return code = %d \n", ret);
2282         }
2283 }
2284
2285 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2286         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2287 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2288         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2289 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2290         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2291 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2292         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2293 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2294         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2295 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2296         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2297                                  NULL);
2298 cmdline_parse_inst_t cmd_config_rss_reta = {
2299         .f = cmd_set_rss_reta_parsed,
2300         .data = NULL,
2301         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2302         .tokens = {
2303                 (void *)&cmd_config_rss_reta_port,
2304                 (void *)&cmd_config_rss_reta_keyword,
2305                 (void *)&cmd_config_rss_reta_port_id,
2306                 (void *)&cmd_config_rss_reta_name,
2307                 (void *)&cmd_config_rss_reta_list_name,
2308                 (void *)&cmd_config_rss_reta_list_of_items,
2309                 NULL,
2310         },
2311 };
2312
2313 /* *** SHOW PORT RETA INFO *** */
2314 struct cmd_showport_reta {
2315         cmdline_fixed_string_t show;
2316         cmdline_fixed_string_t port;
2317         portid_t port_id;
2318         cmdline_fixed_string_t rss;
2319         cmdline_fixed_string_t reta;
2320         uint16_t size;
2321         cmdline_fixed_string_t list_of_items;
2322 };
2323
2324 static int
2325 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2326                            uint16_t nb_entries,
2327                            char *str)
2328 {
2329         uint32_t size;
2330         const char *p, *p0 = str;
2331         char s[256];
2332         char *end;
2333         char *str_fld[8];
2334         uint16_t i;
2335         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2336                         RTE_RETA_GROUP_SIZE;
2337         int ret;
2338
2339         p = strchr(p0, '(');
2340         if (p == NULL)
2341                 return -1;
2342         p++;
2343         p0 = strchr(p, ')');
2344         if (p0 == NULL)
2345                 return -1;
2346         size = p0 - p;
2347         if (size >= sizeof(s)) {
2348                 printf("The string size exceeds the internal buffer size\n");
2349                 return -1;
2350         }
2351         snprintf(s, sizeof(s), "%.*s", size, p);
2352         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2353         if (ret <= 0 || ret != num) {
2354                 printf("The bits of masks do not match the number of "
2355                                         "reta entries: %u\n", num);
2356                 return -1;
2357         }
2358         for (i = 0; i < ret; i++)
2359                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2360
2361         return 0;
2362 }
2363
2364 static void
2365 cmd_showport_reta_parsed(void *parsed_result,
2366                          __attribute__((unused)) struct cmdline *cl,
2367                          __attribute__((unused)) void *data)
2368 {
2369         struct cmd_showport_reta *res = parsed_result;
2370         struct rte_eth_rss_reta_entry64 reta_conf[8];
2371         struct rte_eth_dev_info dev_info;
2372         uint16_t max_reta_size;
2373
2374         memset(&dev_info, 0, sizeof(dev_info));
2375         rte_eth_dev_info_get(res->port_id, &dev_info);
2376         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2377         if (res->size == 0 || res->size > max_reta_size) {
2378                 printf("Invalid redirection table size: %u (1-%u)\n",
2379                         res->size, max_reta_size);
2380                 return;
2381         }
2382
2383         memset(reta_conf, 0, sizeof(reta_conf));
2384         if (showport_parse_reta_config(reta_conf, res->size,
2385                                 res->list_of_items) < 0) {
2386                 printf("Invalid string: %s for reta masks\n",
2387                                         res->list_of_items);
2388                 return;
2389         }
2390         port_rss_reta_info(res->port_id, reta_conf, res->size);
2391 }
2392
2393 cmdline_parse_token_string_t cmd_showport_reta_show =
2394         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2395 cmdline_parse_token_string_t cmd_showport_reta_port =
2396         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2397 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2398         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2399 cmdline_parse_token_string_t cmd_showport_reta_rss =
2400         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2401 cmdline_parse_token_string_t cmd_showport_reta_reta =
2402         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2403 cmdline_parse_token_num_t cmd_showport_reta_size =
2404         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2405 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2406         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2407                                         list_of_items, NULL);
2408
2409 cmdline_parse_inst_t cmd_showport_reta = {
2410         .f = cmd_showport_reta_parsed,
2411         .data = NULL,
2412         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2413         .tokens = {
2414                 (void *)&cmd_showport_reta_show,
2415                 (void *)&cmd_showport_reta_port,
2416                 (void *)&cmd_showport_reta_port_id,
2417                 (void *)&cmd_showport_reta_rss,
2418                 (void *)&cmd_showport_reta_reta,
2419                 (void *)&cmd_showport_reta_size,
2420                 (void *)&cmd_showport_reta_list_of_items,
2421                 NULL,
2422         },
2423 };
2424
2425 /* *** Show RSS hash configuration *** */
2426 struct cmd_showport_rss_hash {
2427         cmdline_fixed_string_t show;
2428         cmdline_fixed_string_t port;
2429         portid_t port_id;
2430         cmdline_fixed_string_t rss_hash;
2431         cmdline_fixed_string_t rss_type;
2432         cmdline_fixed_string_t key; /* optional argument */
2433 };
2434
2435 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2436                                 __attribute__((unused)) struct cmdline *cl,
2437                                 void *show_rss_key)
2438 {
2439         struct cmd_showport_rss_hash *res = parsed_result;
2440
2441         port_rss_hash_conf_show(res->port_id, res->rss_type,
2442                                 show_rss_key != NULL);
2443 }
2444
2445 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2446         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2447 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2448         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2449 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2450         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2451 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2452         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2453                                  "rss-hash");
2454 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2455         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2456                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2457                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2458                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2459                                  "ipv6-tcp-ex#ipv6-udp-ex");
2460 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2461         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2462
2463 cmdline_parse_inst_t cmd_showport_rss_hash = {
2464         .f = cmd_showport_rss_hash_parsed,
2465         .data = NULL,
2466         .help_str = "show port <port_id> rss-hash "
2467                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2468                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2469                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2470         .tokens = {
2471                 (void *)&cmd_showport_rss_hash_show,
2472                 (void *)&cmd_showport_rss_hash_port,
2473                 (void *)&cmd_showport_rss_hash_port_id,
2474                 (void *)&cmd_showport_rss_hash_rss_hash,
2475                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2476                 NULL,
2477         },
2478 };
2479
2480 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2481         .f = cmd_showport_rss_hash_parsed,
2482         .data = (void *)1,
2483         .help_str = "show port <port_id> rss-hash "
2484                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2485                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2486                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2487         .tokens = {
2488                 (void *)&cmd_showport_rss_hash_show,
2489                 (void *)&cmd_showport_rss_hash_port,
2490                 (void *)&cmd_showport_rss_hash_port_id,
2491                 (void *)&cmd_showport_rss_hash_rss_hash,
2492                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2493                 (void *)&cmd_showport_rss_hash_rss_key,
2494                 NULL,
2495         },
2496 };
2497
2498 /* *** Configure DCB *** */
2499 struct cmd_config_dcb {
2500         cmdline_fixed_string_t port;
2501         cmdline_fixed_string_t config;
2502         portid_t port_id;
2503         cmdline_fixed_string_t dcb;
2504         cmdline_fixed_string_t vt;
2505         cmdline_fixed_string_t vt_en;
2506         uint8_t num_tcs;
2507         cmdline_fixed_string_t pfc;
2508         cmdline_fixed_string_t pfc_en;
2509 };
2510
2511 static void
2512 cmd_config_dcb_parsed(void *parsed_result,
2513                         __attribute__((unused)) struct cmdline *cl,
2514                         __attribute__((unused)) void *data)
2515 {
2516         struct cmd_config_dcb *res = parsed_result;
2517         portid_t port_id = res->port_id;
2518         struct rte_port *port;
2519         uint8_t pfc_en;
2520         int ret;
2521
2522         port = &ports[port_id];
2523         /** Check if the port is not started **/
2524         if (port->port_status != RTE_PORT_STOPPED) {
2525                 printf("Please stop port %d first\n", port_id);
2526                 return;
2527         }
2528
2529         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2530                 printf("The invalid number of traffic class,"
2531                         " only 4 or 8 allowed.\n");
2532                 return;
2533         }
2534
2535         if (nb_fwd_lcores < res->num_tcs) {
2536                 printf("nb_cores shouldn't be less than number of TCs.\n");
2537                 return;
2538         }
2539         if (!strncmp(res->pfc_en, "on", 2))
2540                 pfc_en = 1;
2541         else
2542                 pfc_en = 0;
2543
2544         /* DCB in VT mode */
2545         if (!strncmp(res->vt_en, "on", 2))
2546                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2547                                 (enum rte_eth_nb_tcs)res->num_tcs,
2548                                 pfc_en);
2549         else
2550                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2551                                 (enum rte_eth_nb_tcs)res->num_tcs,
2552                                 pfc_en);
2553
2554
2555         if (ret != 0) {
2556                 printf("Cannot initialize network ports.\n");
2557                 return;
2558         }
2559
2560         cmd_reconfig_device_queue(port_id, 1, 1);
2561 }
2562
2563 cmdline_parse_token_string_t cmd_config_dcb_port =
2564         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2565 cmdline_parse_token_string_t cmd_config_dcb_config =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2567 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2568         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2569 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2570         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2571 cmdline_parse_token_string_t cmd_config_dcb_vt =
2572         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2573 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2574         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2575 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2576         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2577 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2578         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2579 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2581
2582 cmdline_parse_inst_t cmd_config_dcb = {
2583         .f = cmd_config_dcb_parsed,
2584         .data = NULL,
2585         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2586         .tokens = {
2587                 (void *)&cmd_config_dcb_port,
2588                 (void *)&cmd_config_dcb_config,
2589                 (void *)&cmd_config_dcb_port_id,
2590                 (void *)&cmd_config_dcb_dcb,
2591                 (void *)&cmd_config_dcb_vt,
2592                 (void *)&cmd_config_dcb_vt_en,
2593                 (void *)&cmd_config_dcb_num_tcs,
2594                 (void *)&cmd_config_dcb_pfc,
2595                 (void *)&cmd_config_dcb_pfc_en,
2596                 NULL,
2597         },
2598 };
2599
2600 /* *** configure number of packets per burst *** */
2601 struct cmd_config_burst {
2602         cmdline_fixed_string_t port;
2603         cmdline_fixed_string_t keyword;
2604         cmdline_fixed_string_t all;
2605         cmdline_fixed_string_t name;
2606         uint16_t value;
2607 };
2608
2609 static void
2610 cmd_config_burst_parsed(void *parsed_result,
2611                         __attribute__((unused)) struct cmdline *cl,
2612                         __attribute__((unused)) void *data)
2613 {
2614         struct cmd_config_burst *res = parsed_result;
2615
2616         if (!all_ports_stopped()) {
2617                 printf("Please stop all ports first\n");
2618                 return;
2619         }
2620
2621         if (!strcmp(res->name, "burst")) {
2622                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2623                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2624                         return;
2625                 }
2626                 nb_pkt_per_burst = res->value;
2627         } else {
2628                 printf("Unknown parameter\n");
2629                 return;
2630         }
2631
2632         init_port_config();
2633
2634         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2635 }
2636
2637 cmdline_parse_token_string_t cmd_config_burst_port =
2638         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2639 cmdline_parse_token_string_t cmd_config_burst_keyword =
2640         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2641 cmdline_parse_token_string_t cmd_config_burst_all =
2642         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2643 cmdline_parse_token_string_t cmd_config_burst_name =
2644         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2645 cmdline_parse_token_num_t cmd_config_burst_value =
2646         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2647
2648 cmdline_parse_inst_t cmd_config_burst = {
2649         .f = cmd_config_burst_parsed,
2650         .data = NULL,
2651         .help_str = "port config all burst <value>",
2652         .tokens = {
2653                 (void *)&cmd_config_burst_port,
2654                 (void *)&cmd_config_burst_keyword,
2655                 (void *)&cmd_config_burst_all,
2656                 (void *)&cmd_config_burst_name,
2657                 (void *)&cmd_config_burst_value,
2658                 NULL,
2659         },
2660 };
2661
2662 /* *** configure rx/tx queues *** */
2663 struct cmd_config_thresh {
2664         cmdline_fixed_string_t port;
2665         cmdline_fixed_string_t keyword;
2666         cmdline_fixed_string_t all;
2667         cmdline_fixed_string_t name;
2668         uint8_t value;
2669 };
2670
2671 static void
2672 cmd_config_thresh_parsed(void *parsed_result,
2673                         __attribute__((unused)) struct cmdline *cl,
2674                         __attribute__((unused)) void *data)
2675 {
2676         struct cmd_config_thresh *res = parsed_result;
2677
2678         if (!all_ports_stopped()) {
2679                 printf("Please stop all ports first\n");
2680                 return;
2681         }
2682
2683         if (!strcmp(res->name, "txpt"))
2684                 tx_pthresh = res->value;
2685         else if(!strcmp(res->name, "txht"))
2686                 tx_hthresh = res->value;
2687         else if(!strcmp(res->name, "txwt"))
2688                 tx_wthresh = res->value;
2689         else if(!strcmp(res->name, "rxpt"))
2690                 rx_pthresh = res->value;
2691         else if(!strcmp(res->name, "rxht"))
2692                 rx_hthresh = res->value;
2693         else if(!strcmp(res->name, "rxwt"))
2694                 rx_wthresh = res->value;
2695         else {
2696                 printf("Unknown parameter\n");
2697                 return;
2698         }
2699
2700         init_port_config();
2701
2702         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2703 }
2704
2705 cmdline_parse_token_string_t cmd_config_thresh_port =
2706         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2707 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2708         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2709 cmdline_parse_token_string_t cmd_config_thresh_all =
2710         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2711 cmdline_parse_token_string_t cmd_config_thresh_name =
2712         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2713                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2714 cmdline_parse_token_num_t cmd_config_thresh_value =
2715         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2716
2717 cmdline_parse_inst_t cmd_config_thresh = {
2718         .f = cmd_config_thresh_parsed,
2719         .data = NULL,
2720         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2721         .tokens = {
2722                 (void *)&cmd_config_thresh_port,
2723                 (void *)&cmd_config_thresh_keyword,
2724                 (void *)&cmd_config_thresh_all,
2725                 (void *)&cmd_config_thresh_name,
2726                 (void *)&cmd_config_thresh_value,
2727                 NULL,
2728         },
2729 };
2730
2731 /* *** configure free/rs threshold *** */
2732 struct cmd_config_threshold {
2733         cmdline_fixed_string_t port;
2734         cmdline_fixed_string_t keyword;
2735         cmdline_fixed_string_t all;
2736         cmdline_fixed_string_t name;
2737         uint16_t value;
2738 };
2739
2740 static void
2741 cmd_config_threshold_parsed(void *parsed_result,
2742                         __attribute__((unused)) struct cmdline *cl,
2743                         __attribute__((unused)) void *data)
2744 {
2745         struct cmd_config_threshold *res = parsed_result;
2746
2747         if (!all_ports_stopped()) {
2748                 printf("Please stop all ports first\n");
2749                 return;
2750         }
2751
2752         if (!strcmp(res->name, "txfreet"))
2753                 tx_free_thresh = res->value;
2754         else if (!strcmp(res->name, "txrst"))
2755                 tx_rs_thresh = res->value;
2756         else if (!strcmp(res->name, "rxfreet"))
2757                 rx_free_thresh = res->value;
2758         else {
2759                 printf("Unknown parameter\n");
2760                 return;
2761         }
2762
2763         init_port_config();
2764
2765         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2766 }
2767
2768 cmdline_parse_token_string_t cmd_config_threshold_port =
2769         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2770 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2771         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2772                                                                 "config");
2773 cmdline_parse_token_string_t cmd_config_threshold_all =
2774         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2775 cmdline_parse_token_string_t cmd_config_threshold_name =
2776         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2777                                                 "txfreet#txrst#rxfreet");
2778 cmdline_parse_token_num_t cmd_config_threshold_value =
2779         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2780
2781 cmdline_parse_inst_t cmd_config_threshold = {
2782         .f = cmd_config_threshold_parsed,
2783         .data = NULL,
2784         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2785         .tokens = {
2786                 (void *)&cmd_config_threshold_port,
2787                 (void *)&cmd_config_threshold_keyword,
2788                 (void *)&cmd_config_threshold_all,
2789                 (void *)&cmd_config_threshold_name,
2790                 (void *)&cmd_config_threshold_value,
2791                 NULL,
2792         },
2793 };
2794
2795 /* *** stop *** */
2796 struct cmd_stop_result {
2797         cmdline_fixed_string_t stop;
2798 };
2799
2800 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2801                             __attribute__((unused)) struct cmdline *cl,
2802                             __attribute__((unused)) void *data)
2803 {
2804         stop_packet_forwarding();
2805 }
2806
2807 cmdline_parse_token_string_t cmd_stop_stop =
2808         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2809
2810 cmdline_parse_inst_t cmd_stop = {
2811         .f = cmd_stop_parsed,
2812         .data = NULL,
2813         .help_str = "stop: Stop packet forwarding",
2814         .tokens = {
2815                 (void *)&cmd_stop_stop,
2816                 NULL,
2817         },
2818 };
2819
2820 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2821
2822 unsigned int
2823 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2824                 unsigned int *parsed_items, int check_unique_values)
2825 {
2826         unsigned int nb_item;
2827         unsigned int value;
2828         unsigned int i;
2829         unsigned int j;
2830         int value_ok;
2831         char c;
2832
2833         /*
2834          * First parse all items in the list and store their value.
2835          */
2836         value = 0;
2837         nb_item = 0;
2838         value_ok = 0;
2839         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2840                 c = str[i];
2841                 if ((c >= '0') && (c <= '9')) {
2842                         value = (unsigned int) (value * 10 + (c - '0'));
2843                         value_ok = 1;
2844                         continue;
2845                 }
2846                 if (c != ',') {
2847                         printf("character %c is not a decimal digit\n", c);
2848                         return 0;
2849                 }
2850                 if (! value_ok) {
2851                         printf("No valid value before comma\n");
2852                         return 0;
2853                 }
2854                 if (nb_item < max_items) {
2855                         parsed_items[nb_item] = value;
2856                         value_ok = 0;
2857                         value = 0;
2858                 }
2859                 nb_item++;
2860         }
2861         if (nb_item >= max_items) {
2862                 printf("Number of %s = %u > %u (maximum items)\n",
2863                        item_name, nb_item + 1, max_items);
2864                 return 0;
2865         }
2866         parsed_items[nb_item++] = value;
2867         if (! check_unique_values)
2868                 return nb_item;
2869
2870         /*
2871          * Then, check that all values in the list are differents.
2872          * No optimization here...
2873          */
2874         for (i = 0; i < nb_item; i++) {
2875                 for (j = i + 1; j < nb_item; j++) {
2876                         if (parsed_items[j] == parsed_items[i]) {
2877                                 printf("duplicated %s %u at index %u and %u\n",
2878                                        item_name, parsed_items[i], i, j);
2879                                 return 0;
2880                         }
2881                 }
2882         }
2883         return nb_item;
2884 }
2885
2886 struct cmd_set_list_result {
2887         cmdline_fixed_string_t cmd_keyword;
2888         cmdline_fixed_string_t list_name;
2889         cmdline_fixed_string_t list_of_items;
2890 };
2891
2892 static void cmd_set_list_parsed(void *parsed_result,
2893                                 __attribute__((unused)) struct cmdline *cl,
2894                                 __attribute__((unused)) void *data)
2895 {
2896         struct cmd_set_list_result *res;
2897         union {
2898                 unsigned int lcorelist[RTE_MAX_LCORE];
2899                 unsigned int portlist[RTE_MAX_ETHPORTS];
2900         } parsed_items;
2901         unsigned int nb_item;
2902
2903         if (test_done == 0) {
2904                 printf("Please stop forwarding first\n");
2905                 return;
2906         }
2907
2908         res = parsed_result;
2909         if (!strcmp(res->list_name, "corelist")) {
2910                 nb_item = parse_item_list(res->list_of_items, "core",
2911                                           RTE_MAX_LCORE,
2912                                           parsed_items.lcorelist, 1);
2913                 if (nb_item > 0) {
2914                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2915                         fwd_config_setup();
2916                 }
2917                 return;
2918         }
2919         if (!strcmp(res->list_name, "portlist")) {
2920                 nb_item = parse_item_list(res->list_of_items, "port",
2921                                           RTE_MAX_ETHPORTS,
2922                                           parsed_items.portlist, 1);
2923                 if (nb_item > 0) {
2924                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2925                         fwd_config_setup();
2926                 }
2927         }
2928 }
2929
2930 cmdline_parse_token_string_t cmd_set_list_keyword =
2931         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2932                                  "set");
2933 cmdline_parse_token_string_t cmd_set_list_name =
2934         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2935                                  "corelist#portlist");
2936 cmdline_parse_token_string_t cmd_set_list_of_items =
2937         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2938                                  NULL);
2939
2940 cmdline_parse_inst_t cmd_set_fwd_list = {
2941         .f = cmd_set_list_parsed,
2942         .data = NULL,
2943         .help_str = "set corelist|portlist <list0[,list1]*>",
2944         .tokens = {
2945                 (void *)&cmd_set_list_keyword,
2946                 (void *)&cmd_set_list_name,
2947                 (void *)&cmd_set_list_of_items,
2948                 NULL,
2949         },
2950 };
2951
2952 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2953
2954 struct cmd_setmask_result {
2955         cmdline_fixed_string_t set;
2956         cmdline_fixed_string_t mask;
2957         uint64_t hexavalue;
2958 };
2959
2960 static void cmd_set_mask_parsed(void *parsed_result,
2961                                 __attribute__((unused)) struct cmdline *cl,
2962                                 __attribute__((unused)) void *data)
2963 {
2964         struct cmd_setmask_result *res = parsed_result;
2965
2966         if (test_done == 0) {
2967                 printf("Please stop forwarding first\n");
2968                 return;
2969         }
2970         if (!strcmp(res->mask, "coremask")) {
2971                 set_fwd_lcores_mask(res->hexavalue);
2972                 fwd_config_setup();
2973         } else if (!strcmp(res->mask, "portmask")) {
2974                 set_fwd_ports_mask(res->hexavalue);
2975                 fwd_config_setup();
2976         }
2977 }
2978
2979 cmdline_parse_token_string_t cmd_setmask_set =
2980         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2981 cmdline_parse_token_string_t cmd_setmask_mask =
2982         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2983                                  "coremask#portmask");
2984 cmdline_parse_token_num_t cmd_setmask_value =
2985         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2986
2987 cmdline_parse_inst_t cmd_set_fwd_mask = {
2988         .f = cmd_set_mask_parsed,
2989         .data = NULL,
2990         .help_str = "set coremask|portmask <hexadecimal value>",
2991         .tokens = {
2992                 (void *)&cmd_setmask_set,
2993                 (void *)&cmd_setmask_mask,
2994                 (void *)&cmd_setmask_value,
2995                 NULL,
2996         },
2997 };
2998
2999 /*
3000  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3001  */
3002 struct cmd_set_result {
3003         cmdline_fixed_string_t set;
3004         cmdline_fixed_string_t what;
3005         uint16_t value;
3006 };
3007
3008 static void cmd_set_parsed(void *parsed_result,
3009                            __attribute__((unused)) struct cmdline *cl,
3010                            __attribute__((unused)) void *data)
3011 {
3012         struct cmd_set_result *res = parsed_result;
3013         if (!strcmp(res->what, "nbport")) {
3014                 set_fwd_ports_number(res->value);
3015                 fwd_config_setup();
3016         } else if (!strcmp(res->what, "nbcore")) {
3017                 set_fwd_lcores_number(res->value);
3018                 fwd_config_setup();
3019         } else if (!strcmp(res->what, "burst"))
3020                 set_nb_pkt_per_burst(res->value);
3021         else if (!strcmp(res->what, "verbose"))
3022                 set_verbose_level(res->value);
3023 }
3024
3025 cmdline_parse_token_string_t cmd_set_set =
3026         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3027 cmdline_parse_token_string_t cmd_set_what =
3028         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3029                                  "nbport#nbcore#burst#verbose");
3030 cmdline_parse_token_num_t cmd_set_value =
3031         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3032
3033 cmdline_parse_inst_t cmd_set_numbers = {
3034         .f = cmd_set_parsed,
3035         .data = NULL,
3036         .help_str = "set nbport|nbcore|burst|verbose <value>",
3037         .tokens = {
3038                 (void *)&cmd_set_set,
3039                 (void *)&cmd_set_what,
3040                 (void *)&cmd_set_value,
3041                 NULL,
3042         },
3043 };
3044
3045 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3046
3047 struct cmd_set_txpkts_result {
3048         cmdline_fixed_string_t cmd_keyword;
3049         cmdline_fixed_string_t txpkts;
3050         cmdline_fixed_string_t seg_lengths;
3051 };
3052
3053 static void
3054 cmd_set_txpkts_parsed(void *parsed_result,
3055                       __attribute__((unused)) struct cmdline *cl,
3056                       __attribute__((unused)) void *data)
3057 {
3058         struct cmd_set_txpkts_result *res;
3059         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3060         unsigned int nb_segs;
3061
3062         res = parsed_result;
3063         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3064                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3065         if (nb_segs > 0)
3066                 set_tx_pkt_segments(seg_lengths, nb_segs);
3067 }
3068
3069 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3070         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3071                                  cmd_keyword, "set");
3072 cmdline_parse_token_string_t cmd_set_txpkts_name =
3073         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3074                                  txpkts, "txpkts");
3075 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3076         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3077                                  seg_lengths, NULL);
3078
3079 cmdline_parse_inst_t cmd_set_txpkts = {
3080         .f = cmd_set_txpkts_parsed,
3081         .data = NULL,
3082         .help_str = "set txpkts <len0[,len1]*>",
3083         .tokens = {
3084                 (void *)&cmd_set_txpkts_keyword,
3085                 (void *)&cmd_set_txpkts_name,
3086                 (void *)&cmd_set_txpkts_lengths,
3087                 NULL,
3088         },
3089 };
3090
3091 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3092
3093 struct cmd_set_txsplit_result {
3094         cmdline_fixed_string_t cmd_keyword;
3095         cmdline_fixed_string_t txsplit;
3096         cmdline_fixed_string_t mode;
3097 };
3098
3099 static void
3100 cmd_set_txsplit_parsed(void *parsed_result,
3101                       __attribute__((unused)) struct cmdline *cl,
3102                       __attribute__((unused)) void *data)
3103 {
3104         struct cmd_set_txsplit_result *res;
3105
3106         res = parsed_result;
3107         set_tx_pkt_split(res->mode);
3108 }
3109
3110 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3111         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3112                                  cmd_keyword, "set");
3113 cmdline_parse_token_string_t cmd_set_txsplit_name =
3114         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3115                                  txsplit, "txsplit");
3116 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3117         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3118                                  mode, NULL);
3119
3120 cmdline_parse_inst_t cmd_set_txsplit = {
3121         .f = cmd_set_txsplit_parsed,
3122         .data = NULL,
3123         .help_str = "set txsplit on|off|rand",
3124         .tokens = {
3125                 (void *)&cmd_set_txsplit_keyword,
3126                 (void *)&cmd_set_txsplit_name,
3127                 (void *)&cmd_set_txsplit_mode,
3128                 NULL,
3129         },
3130 };
3131
3132 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3133 struct cmd_rx_vlan_filter_all_result {
3134         cmdline_fixed_string_t rx_vlan;
3135         cmdline_fixed_string_t what;
3136         cmdline_fixed_string_t all;
3137         portid_t port_id;
3138 };
3139
3140 static void
3141 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3142                               __attribute__((unused)) struct cmdline *cl,
3143                               __attribute__((unused)) void *data)
3144 {
3145         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3146
3147         if (!strcmp(res->what, "add"))
3148                 rx_vlan_all_filter_set(res->port_id, 1);
3149         else
3150                 rx_vlan_all_filter_set(res->port_id, 0);
3151 }
3152
3153 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3154         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3155                                  rx_vlan, "rx_vlan");
3156 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3157         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3158                                  what, "add#rm");
3159 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3160         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3161                                  all, "all");
3162 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3163         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3164                               port_id, UINT16);
3165
3166 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3167         .f = cmd_rx_vlan_filter_all_parsed,
3168         .data = NULL,
3169         .help_str = "rx_vlan add|rm all <port_id>: "
3170                 "Add/Remove all identifiers to/from the set of VLAN "
3171                 "identifiers filtered by a port",
3172         .tokens = {
3173                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3174                 (void *)&cmd_rx_vlan_filter_all_what,
3175                 (void *)&cmd_rx_vlan_filter_all_all,
3176                 (void *)&cmd_rx_vlan_filter_all_portid,
3177                 NULL,
3178         },
3179 };
3180
3181 /* *** VLAN OFFLOAD SET ON A PORT *** */
3182 struct cmd_vlan_offload_result {
3183         cmdline_fixed_string_t vlan;
3184         cmdline_fixed_string_t set;
3185         cmdline_fixed_string_t vlan_type;
3186         cmdline_fixed_string_t what;
3187         cmdline_fixed_string_t on;
3188         cmdline_fixed_string_t port_id;
3189 };
3190
3191 static void
3192 cmd_vlan_offload_parsed(void *parsed_result,
3193                           __attribute__((unused)) struct cmdline *cl,
3194                           __attribute__((unused)) void *data)
3195 {
3196         int on;
3197         struct cmd_vlan_offload_result *res = parsed_result;
3198         char *str;
3199         int i, len = 0;
3200         portid_t port_id = 0;
3201         unsigned int tmp;
3202
3203         str = res->port_id;
3204         len = strnlen(str, STR_TOKEN_SIZE);
3205         i = 0;
3206         /* Get port_id first */
3207         while(i < len){
3208                 if(str[i] == ',')
3209                         break;
3210
3211                 i++;
3212         }
3213         str[i]='\0';
3214         tmp = strtoul(str, NULL, 0);
3215         /* If port_id greater that what portid_t can represent, return */
3216         if(tmp >= RTE_MAX_ETHPORTS)
3217                 return;
3218         port_id = (portid_t)tmp;
3219
3220         if (!strcmp(res->on, "on"))
3221                 on = 1;
3222         else
3223                 on = 0;
3224
3225         if (!strcmp(res->what, "strip"))
3226                 rx_vlan_strip_set(port_id,  on);
3227         else if(!strcmp(res->what, "stripq")){
3228                 uint16_t queue_id = 0;
3229
3230                 /* No queue_id, return */
3231                 if(i + 1 >= len) {
3232                         printf("must specify (port,queue_id)\n");
3233                         return;
3234                 }
3235                 tmp = strtoul(str + i + 1, NULL, 0);
3236                 /* If queue_id greater that what 16-bits can represent, return */
3237                 if(tmp > 0xffff)
3238                         return;
3239
3240                 queue_id = (uint16_t)tmp;
3241                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3242         }
3243         else if (!strcmp(res->what, "filter"))
3244                 rx_vlan_filter_set(port_id, on);
3245         else
3246                 vlan_extend_set(port_id, on);
3247
3248         return;
3249 }
3250
3251 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3252         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3253                                  vlan, "vlan");
3254 cmdline_parse_token_string_t cmd_vlan_offload_set =
3255         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3256                                  set, "set");
3257 cmdline_parse_token_string_t cmd_vlan_offload_what =
3258         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3259                                  what, "strip#filter#qinq#stripq");
3260 cmdline_parse_token_string_t cmd_vlan_offload_on =
3261         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3262                               on, "on#off");
3263 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3264         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3265                               port_id, NULL);
3266
3267 cmdline_parse_inst_t cmd_vlan_offload = {
3268         .f = cmd_vlan_offload_parsed,
3269         .data = NULL,
3270         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3271                 "<port_id[,queue_id]>: "
3272                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3273         .tokens = {
3274                 (void *)&cmd_vlan_offload_vlan,
3275                 (void *)&cmd_vlan_offload_set,
3276                 (void *)&cmd_vlan_offload_what,
3277                 (void *)&cmd_vlan_offload_on,
3278                 (void *)&cmd_vlan_offload_portid,
3279                 NULL,
3280         },
3281 };
3282
3283 /* *** VLAN TPID SET ON A PORT *** */
3284 struct cmd_vlan_tpid_result {
3285         cmdline_fixed_string_t vlan;
3286         cmdline_fixed_string_t set;
3287         cmdline_fixed_string_t vlan_type;
3288         cmdline_fixed_string_t what;
3289         uint16_t tp_id;
3290         portid_t port_id;
3291 };
3292
3293 static void
3294 cmd_vlan_tpid_parsed(void *parsed_result,
3295                           __attribute__((unused)) struct cmdline *cl,
3296                           __attribute__((unused)) void *data)
3297 {
3298         struct cmd_vlan_tpid_result *res = parsed_result;
3299         enum rte_vlan_type vlan_type;
3300
3301         if (!strcmp(res->vlan_type, "inner"))
3302                 vlan_type = ETH_VLAN_TYPE_INNER;
3303         else if (!strcmp(res->vlan_type, "outer"))
3304                 vlan_type = ETH_VLAN_TYPE_OUTER;
3305         else {
3306                 printf("Unknown vlan type\n");
3307                 return;
3308         }
3309         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3310 }
3311
3312 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3313         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3314                                  vlan, "vlan");
3315 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3316         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3317                                  set, "set");
3318 cmdline_parse_token_string_t cmd_vlan_type =
3319         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3320                                  vlan_type, "inner#outer");
3321 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3322         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3323                                  what, "tpid");
3324 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3325         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3326                               tp_id, UINT16);
3327 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3328         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3329                               port_id, UINT16);
3330
3331 cmdline_parse_inst_t cmd_vlan_tpid = {
3332         .f = cmd_vlan_tpid_parsed,
3333         .data = NULL,
3334         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3335                 "Set the VLAN Ether type",
3336         .tokens = {
3337                 (void *)&cmd_vlan_tpid_vlan,
3338                 (void *)&cmd_vlan_tpid_set,
3339                 (void *)&cmd_vlan_type,
3340                 (void *)&cmd_vlan_tpid_what,
3341                 (void *)&cmd_vlan_tpid_tpid,
3342                 (void *)&cmd_vlan_tpid_portid,
3343                 NULL,
3344         },
3345 };
3346
3347 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3348 struct cmd_rx_vlan_filter_result {
3349         cmdline_fixed_string_t rx_vlan;
3350         cmdline_fixed_string_t what;
3351         uint16_t vlan_id;
3352         portid_t port_id;
3353 };
3354
3355 static void
3356 cmd_rx_vlan_filter_parsed(void *parsed_result,
3357                           __attribute__((unused)) struct cmdline *cl,
3358                           __attribute__((unused)) void *data)
3359 {
3360         struct cmd_rx_vlan_filter_result *res = parsed_result;
3361
3362         if (!strcmp(res->what, "add"))
3363                 rx_vft_set(res->port_id, res->vlan_id, 1);
3364         else
3365                 rx_vft_set(res->port_id, res->vlan_id, 0);
3366 }
3367
3368 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3369         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3370                                  rx_vlan, "rx_vlan");
3371 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3372         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3373                                  what, "add#rm");
3374 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3375         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3376                               vlan_id, UINT16);
3377 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3378         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3379                               port_id, UINT16);
3380
3381 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3382         .f = cmd_rx_vlan_filter_parsed,
3383         .data = NULL,
3384         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3385                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3386                 "identifiers filtered by a port",
3387         .tokens = {
3388                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3389                 (void *)&cmd_rx_vlan_filter_what,
3390                 (void *)&cmd_rx_vlan_filter_vlanid,
3391                 (void *)&cmd_rx_vlan_filter_portid,
3392                 NULL,
3393         },
3394 };
3395
3396 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3397 struct cmd_tx_vlan_set_result {
3398         cmdline_fixed_string_t tx_vlan;
3399         cmdline_fixed_string_t set;
3400         portid_t port_id;
3401         uint16_t vlan_id;
3402 };
3403
3404 static void
3405 cmd_tx_vlan_set_parsed(void *parsed_result,
3406                        __attribute__((unused)) struct cmdline *cl,
3407                        __attribute__((unused)) void *data)
3408 {
3409         struct cmd_tx_vlan_set_result *res = parsed_result;
3410
3411         if (!port_is_stopped(res->port_id)) {
3412                 printf("Please stop port %d first\n", res->port_id);
3413                 return;
3414         }
3415
3416         tx_vlan_set(res->port_id, res->vlan_id);
3417
3418         cmd_reconfig_device_queue(res->port_id, 1, 1);
3419 }
3420
3421 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3422         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3423                                  tx_vlan, "tx_vlan");
3424 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3425         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3426                                  set, "set");
3427 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3428         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3429                               port_id, UINT16);
3430 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3431         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3432                               vlan_id, UINT16);
3433
3434 cmdline_parse_inst_t cmd_tx_vlan_set = {
3435         .f = cmd_tx_vlan_set_parsed,
3436         .data = NULL,
3437         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3438                 "Enable hardware insertion of a single VLAN header "
3439                 "with a given TAG Identifier in packets sent on a port",
3440         .tokens = {
3441                 (void *)&cmd_tx_vlan_set_tx_vlan,
3442                 (void *)&cmd_tx_vlan_set_set,
3443                 (void *)&cmd_tx_vlan_set_portid,
3444                 (void *)&cmd_tx_vlan_set_vlanid,
3445                 NULL,
3446         },
3447 };
3448
3449 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3450 struct cmd_tx_vlan_set_qinq_result {
3451         cmdline_fixed_string_t tx_vlan;
3452         cmdline_fixed_string_t set;
3453         portid_t port_id;
3454         uint16_t vlan_id;
3455         uint16_t vlan_id_outer;
3456 };
3457
3458 static void
3459 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3460                             __attribute__((unused)) struct cmdline *cl,
3461                             __attribute__((unused)) void *data)
3462 {
3463         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3464
3465         if (!port_is_stopped(res->port_id)) {
3466                 printf("Please stop port %d first\n", res->port_id);
3467                 return;
3468         }
3469
3470         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3471
3472         cmd_reconfig_device_queue(res->port_id, 1, 1);
3473 }
3474
3475 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3476         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3477                 tx_vlan, "tx_vlan");
3478 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3479         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3480                 set, "set");
3481 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3482         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3483                 port_id, UINT16);
3484 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3485         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3486                 vlan_id, UINT16);
3487 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3488         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3489                 vlan_id_outer, UINT16);
3490
3491 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3492         .f = cmd_tx_vlan_set_qinq_parsed,
3493         .data = NULL,
3494         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3495                 "Enable hardware insertion of double VLAN header "
3496                 "with given TAG Identifiers in packets sent on a port",
3497         .tokens = {
3498                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3499                 (void *)&cmd_tx_vlan_set_qinq_set,
3500                 (void *)&cmd_tx_vlan_set_qinq_portid,
3501                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3502                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3503                 NULL,
3504         },
3505 };
3506
3507 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3508 struct cmd_tx_vlan_set_pvid_result {
3509         cmdline_fixed_string_t tx_vlan;
3510         cmdline_fixed_string_t set;
3511         cmdline_fixed_string_t pvid;
3512         portid_t port_id;
3513         uint16_t vlan_id;
3514         cmdline_fixed_string_t mode;
3515 };
3516
3517 static void
3518 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3519                             __attribute__((unused)) struct cmdline *cl,
3520                             __attribute__((unused)) void *data)
3521 {
3522         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3523
3524         if (strcmp(res->mode, "on") == 0)
3525                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3526         else
3527                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3528 }
3529
3530 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3531         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3532                                  tx_vlan, "tx_vlan");
3533 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3534         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3535                                  set, "set");
3536 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3537         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3538                                  pvid, "pvid");
3539 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3540         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3541                              port_id, UINT16);
3542 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3543         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3544                               vlan_id, UINT16);
3545 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3546         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3547                                  mode, "on#off");
3548
3549 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3550         .f = cmd_tx_vlan_set_pvid_parsed,
3551         .data = NULL,
3552         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3553         .tokens = {
3554                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3555                 (void *)&cmd_tx_vlan_set_pvid_set,
3556                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3557                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3558                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3559                 (void *)&cmd_tx_vlan_set_pvid_mode,
3560                 NULL,
3561         },
3562 };
3563
3564 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3565 struct cmd_tx_vlan_reset_result {
3566         cmdline_fixed_string_t tx_vlan;
3567         cmdline_fixed_string_t reset;
3568         portid_t port_id;
3569 };
3570
3571 static void
3572 cmd_tx_vlan_reset_parsed(void *parsed_result,
3573                          __attribute__((unused)) struct cmdline *cl,
3574                          __attribute__((unused)) void *data)
3575 {
3576         struct cmd_tx_vlan_reset_result *res = parsed_result;
3577
3578         if (!port_is_stopped(res->port_id)) {
3579                 printf("Please stop port %d first\n", res->port_id);
3580                 return;
3581         }
3582
3583         tx_vlan_reset(res->port_id);
3584
3585         cmd_reconfig_device_queue(res->port_id, 1, 1);
3586 }
3587
3588 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3589         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3590                                  tx_vlan, "tx_vlan");
3591 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3592         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3593                                  reset, "reset");
3594 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3595         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3596                               port_id, UINT16);
3597
3598 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3599         .f = cmd_tx_vlan_reset_parsed,
3600         .data = NULL,
3601         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3602                 "VLAN header in packets sent on a port",
3603         .tokens = {
3604                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3605                 (void *)&cmd_tx_vlan_reset_reset,
3606                 (void *)&cmd_tx_vlan_reset_portid,
3607                 NULL,
3608         },
3609 };
3610
3611
3612 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3613 struct cmd_csum_result {
3614         cmdline_fixed_string_t csum;
3615         cmdline_fixed_string_t mode;
3616         cmdline_fixed_string_t proto;
3617         cmdline_fixed_string_t hwsw;
3618         portid_t port_id;
3619 };
3620
3621 static void
3622 csum_show(int port_id)
3623 {
3624         struct rte_eth_dev_info dev_info;
3625         uint64_t tx_offloads;
3626
3627         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3628         printf("Parse tunnel is %s\n",
3629                 (ports[port_id].parse_tunnel) ? "on" : "off");
3630         printf("IP checksum offload is %s\n",
3631                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3632         printf("UDP checksum offload is %s\n",
3633                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3634         printf("TCP checksum offload is %s\n",
3635                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3636         printf("SCTP checksum offload is %s\n",
3637                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3638         printf("Outer-Ip checksum offload is %s\n",
3639                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3640
3641         /* display warnings if configuration is not supported by the NIC */
3642         rte_eth_dev_info_get(port_id, &dev_info);
3643         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3644                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3645                 printf("Warning: hardware IP checksum enabled but not "
3646                         "supported by port %d\n", port_id);
3647         }
3648         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3649                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3650                 printf("Warning: hardware UDP checksum enabled but not "
3651                         "supported by port %d\n", port_id);
3652         }
3653         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3654                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3655                 printf("Warning: hardware TCP checksum enabled but not "
3656                         "supported by port %d\n", port_id);
3657         }
3658         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3659                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3660                 printf("Warning: hardware SCTP checksum enabled but not "
3661                         "supported by port %d\n", port_id);
3662         }
3663         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3664                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3665                 printf("Warning: hardware outer IP checksum enabled but not "
3666                         "supported by port %d\n", port_id);
3667         }
3668 }
3669
3670 static void
3671 cmd_csum_parsed(void *parsed_result,
3672                        __attribute__((unused)) struct cmdline *cl,
3673                        __attribute__((unused)) void *data)
3674 {
3675         struct cmd_csum_result *res = parsed_result;
3676         int hw = 0;
3677         uint64_t csum_offloads = 0;
3678         struct rte_eth_dev_info dev_info;
3679
3680         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3681                 printf("invalid port %d\n", res->port_id);
3682                 return;
3683         }
3684         if (!port_is_stopped(res->port_id)) {
3685                 printf("Please stop port %d first\n", res->port_id);
3686                 return;
3687         }
3688
3689         rte_eth_dev_info_get(res->port_id, &dev_info);
3690         if (!strcmp(res->mode, "set")) {
3691
3692                 if (!strcmp(res->hwsw, "hw"))
3693                         hw = 1;
3694
3695                 if (!strcmp(res->proto, "ip")) {
3696                         if (dev_info.tx_offload_capa &
3697                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3698                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3699                         } else {
3700                                 printf("IP checksum offload is not supported "
3701                                        "by port %u\n", res->port_id);
3702                         }
3703                 } else if (!strcmp(res->proto, "udp")) {
3704                         if (dev_info.tx_offload_capa &
3705                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3706                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3707                         } else {
3708                                 printf("UDP checksum offload is not supported "
3709                                        "by port %u\n", res->port_id);
3710                         }
3711                 } else if (!strcmp(res->proto, "tcp")) {
3712                         if (dev_info.tx_offload_capa &
3713                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3714                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3715                         } else {
3716                                 printf("TCP checksum offload is not supported "
3717                                        "by port %u\n", res->port_id);
3718                         }
3719                 } else if (!strcmp(res->proto, "sctp")) {
3720                         if (dev_info.tx_offload_capa &
3721                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3722                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3723                         } else {
3724                                 printf("SCTP checksum offload is not supported "
3725                                        "by port %u\n", res->port_id);
3726                         }
3727                 } else if (!strcmp(res->proto, "outer-ip")) {
3728                         if (dev_info.tx_offload_capa &
3729                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3730                                 csum_offloads |=
3731                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3732                         } else {
3733                                 printf("Outer IP checksum offload is not "
3734                                        "supported by port %u\n", res->port_id);
3735                         }
3736                 }
3737
3738                 if (hw) {
3739                         ports[res->port_id].dev_conf.txmode.offloads |=
3740                                                         csum_offloads;
3741                 } else {
3742                         ports[res->port_id].dev_conf.txmode.offloads &=
3743                                                         (~csum_offloads);
3744                 }
3745         }
3746         csum_show(res->port_id);
3747
3748         cmd_reconfig_device_queue(res->port_id, 1, 1);
3749 }
3750
3751 cmdline_parse_token_string_t cmd_csum_csum =
3752         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3753                                 csum, "csum");
3754 cmdline_parse_token_string_t cmd_csum_mode =
3755         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3756                                 mode, "set");
3757 cmdline_parse_token_string_t cmd_csum_proto =
3758         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3759                                 proto, "ip#tcp#udp#sctp#outer-ip");
3760 cmdline_parse_token_string_t cmd_csum_hwsw =
3761         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3762                                 hwsw, "hw#sw");
3763 cmdline_parse_token_num_t cmd_csum_portid =
3764         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3765                                 port_id, UINT16);
3766
3767 cmdline_parse_inst_t cmd_csum_set = {
3768         .f = cmd_csum_parsed,
3769         .data = NULL,
3770         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3771                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3772                 "using csum forward engine",
3773         .tokens = {
3774                 (void *)&cmd_csum_csum,
3775                 (void *)&cmd_csum_mode,
3776                 (void *)&cmd_csum_proto,
3777                 (void *)&cmd_csum_hwsw,
3778                 (void *)&cmd_csum_portid,
3779                 NULL,
3780         },
3781 };
3782
3783 cmdline_parse_token_string_t cmd_csum_mode_show =
3784         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3785                                 mode, "show");
3786
3787 cmdline_parse_inst_t cmd_csum_show = {
3788         .f = cmd_csum_parsed,
3789         .data = NULL,
3790         .help_str = "csum show <port_id>: Show checksum offload configuration",
3791         .tokens = {
3792                 (void *)&cmd_csum_csum,
3793                 (void *)&cmd_csum_mode_show,
3794                 (void *)&cmd_csum_portid,
3795                 NULL,
3796         },
3797 };
3798
3799 /* Enable/disable tunnel parsing */
3800 struct cmd_csum_tunnel_result {
3801         cmdline_fixed_string_t csum;
3802         cmdline_fixed_string_t parse;
3803         cmdline_fixed_string_t onoff;
3804         portid_t port_id;
3805 };
3806
3807 static void
3808 cmd_csum_tunnel_parsed(void *parsed_result,
3809                        __attribute__((unused)) struct cmdline *cl,
3810                        __attribute__((unused)) void *data)
3811 {
3812         struct cmd_csum_tunnel_result *res = parsed_result;
3813
3814         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3815                 return;
3816
3817         if (!strcmp(res->onoff, "on"))
3818                 ports[res->port_id].parse_tunnel = 1;
3819         else
3820                 ports[res->port_id].parse_tunnel = 0;
3821
3822         csum_show(res->port_id);
3823 }
3824
3825 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3826         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3827                                 csum, "csum");
3828 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3829         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3830                                 parse, "parse_tunnel");
3831 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3832         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3833                                 onoff, "on#off");
3834 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3835         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3836                                 port_id, UINT16);
3837
3838 cmdline_parse_inst_t cmd_csum_tunnel = {
3839         .f = cmd_csum_tunnel_parsed,
3840         .data = NULL,
3841         .help_str = "csum parse_tunnel on|off <port_id>: "
3842                 "Enable/Disable parsing of tunnels for csum engine",
3843         .tokens = {
3844                 (void *)&cmd_csum_tunnel_csum,
3845                 (void *)&cmd_csum_tunnel_parse,
3846                 (void *)&cmd_csum_tunnel_onoff,
3847                 (void *)&cmd_csum_tunnel_portid,
3848                 NULL,
3849         },
3850 };
3851
3852 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3853 struct cmd_tso_set_result {
3854         cmdline_fixed_string_t tso;
3855         cmdline_fixed_string_t mode;
3856         uint16_t tso_segsz;
3857         portid_t port_id;
3858 };
3859
3860 static void
3861 cmd_tso_set_parsed(void *parsed_result,
3862                        __attribute__((unused)) struct cmdline *cl,
3863                        __attribute__((unused)) void *data)
3864 {
3865         struct cmd_tso_set_result *res = parsed_result;
3866         struct rte_eth_dev_info dev_info;
3867
3868         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3869                 return;
3870         if (!port_is_stopped(res->port_id)) {
3871                 printf("Please stop port %d first\n", res->port_id);
3872                 return;
3873         }
3874
3875         if (!strcmp(res->mode, "set"))
3876                 ports[res->port_id].tso_segsz = res->tso_segsz;
3877
3878         rte_eth_dev_info_get(res->port_id, &dev_info);
3879         if ((ports[res->port_id].tso_segsz != 0) &&
3880                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3881                 printf("Error: TSO is not supported by port %d\n",
3882                        res->port_id);
3883                 return;
3884         }
3885
3886         if (ports[res->port_id].tso_segsz == 0) {
3887                 ports[res->port_id].dev_conf.txmode.offloads &=
3888                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3889                 printf("TSO for non-tunneled packets is disabled\n");
3890         } else {
3891                 ports[res->port_id].dev_conf.txmode.offloads |=
3892                                                 DEV_TX_OFFLOAD_TCP_TSO;
3893                 printf("TSO segment size for non-tunneled packets is %d\n",
3894                         ports[res->port_id].tso_segsz);
3895         }
3896
3897         /* display warnings if configuration is not supported by the NIC */
3898         rte_eth_dev_info_get(res->port_id, &dev_info);
3899         if ((ports[res->port_id].tso_segsz != 0) &&
3900                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3901                 printf("Warning: TSO enabled but not "
3902                         "supported by port %d\n", res->port_id);
3903         }
3904
3905         cmd_reconfig_device_queue(res->port_id, 1, 1);
3906 }
3907
3908 cmdline_parse_token_string_t cmd_tso_set_tso =
3909         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3910                                 tso, "tso");
3911 cmdline_parse_token_string_t cmd_tso_set_mode =
3912         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3913                                 mode, "set");
3914 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3915         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3916                                 tso_segsz, UINT16);
3917 cmdline_parse_token_num_t cmd_tso_set_portid =
3918         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3919                                 port_id, UINT16);
3920
3921 cmdline_parse_inst_t cmd_tso_set = {
3922         .f = cmd_tso_set_parsed,
3923         .data = NULL,
3924         .help_str = "tso set <tso_segsz> <port_id>: "
3925                 "Set TSO segment size of non-tunneled packets for csum engine "
3926                 "(0 to disable)",
3927         .tokens = {
3928                 (void *)&cmd_tso_set_tso,
3929                 (void *)&cmd_tso_set_mode,
3930                 (void *)&cmd_tso_set_tso_segsz,
3931                 (void *)&cmd_tso_set_portid,
3932                 NULL,
3933         },
3934 };
3935
3936 cmdline_parse_token_string_t cmd_tso_show_mode =
3937         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3938                                 mode, "show");
3939
3940
3941 cmdline_parse_inst_t cmd_tso_show = {
3942         .f = cmd_tso_set_parsed,
3943         .data = NULL,
3944         .help_str = "tso show <port_id>: "
3945                 "Show TSO segment size of non-tunneled packets for csum engine",
3946         .tokens = {
3947                 (void *)&cmd_tso_set_tso,
3948                 (void *)&cmd_tso_show_mode,
3949                 (void *)&cmd_tso_set_portid,
3950                 NULL,
3951         },
3952 };
3953
3954 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3955 struct cmd_tunnel_tso_set_result {
3956         cmdline_fixed_string_t tso;
3957         cmdline_fixed_string_t mode;
3958         uint16_t tso_segsz;
3959         portid_t port_id;
3960 };
3961
3962 static struct rte_eth_dev_info
3963 check_tunnel_tso_nic_support(portid_t port_id)
3964 {
3965         struct rte_eth_dev_info dev_info;
3966
3967         rte_eth_dev_info_get(port_id, &dev_info);
3968         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3969                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3970                        "not enabled for port %d\n", port_id);
3971         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3972                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3973                        "not enabled for port %d\n", port_id);
3974         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3975                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3976                        "not enabled for port %d\n", port_id);
3977         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3978                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3979                        "not enabled for port %d\n", port_id);
3980         return dev_info;
3981 }
3982
3983 static void
3984 cmd_tunnel_tso_set_parsed(void *parsed_result,
3985                           __attribute__((unused)) struct cmdline *cl,
3986                           __attribute__((unused)) void *data)
3987 {
3988         struct cmd_tunnel_tso_set_result *res = parsed_result;
3989         struct rte_eth_dev_info dev_info;
3990
3991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3992                 return;
3993         if (!port_is_stopped(res->port_id)) {
3994                 printf("Please stop port %d first\n", res->port_id);
3995                 return;
3996         }
3997
3998         if (!strcmp(res->mode, "set"))
3999                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4000
4001         dev_info = check_tunnel_tso_nic_support(res->port_id);
4002         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4003                 ports[res->port_id].dev_conf.txmode.offloads &=
4004                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4005                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4006                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4007                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4008                 printf("TSO for tunneled packets is disabled\n");
4009         } else {
4010                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4011                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4012                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4013                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4014
4015                 ports[res->port_id].dev_conf.txmode.offloads |=
4016                         (tso_offloads & dev_info.tx_offload_capa);
4017                 printf("TSO segment size for tunneled packets is %d\n",
4018                         ports[res->port_id].tunnel_tso_segsz);
4019
4020                 /* Below conditions are needed to make it work:
4021                  * (1) tunnel TSO is supported by the NIC;
4022                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4023                  * are recognized;
4024                  * (3) for tunneled pkts with outer L3 of IPv4,
4025                  * "csum set outer-ip" must be set to hw, because after tso,
4026                  * total_len of outer IP header is changed, and the checksum
4027                  * of outer IP header calculated by sw should be wrong; that
4028                  * is not necessary for IPv6 tunneled pkts because there's no
4029                  * checksum in IP header anymore.
4030                  */
4031
4032                 if (!ports[res->port_id].parse_tunnel)
4033                         printf("Warning: csum parse_tunnel must be set "
4034                                 "so that tunneled packets are recognized\n");
4035                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4036                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4037                         printf("Warning: csum set outer-ip must be set to hw "
4038                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4039         }
4040
4041         cmd_reconfig_device_queue(res->port_id, 1, 1);
4042 }
4043
4044 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4045         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4046                                 tso, "tunnel_tso");
4047 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4048         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4049                                 mode, "set");
4050 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4051         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4052                                 tso_segsz, UINT16);
4053 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4054         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4055                                 port_id, UINT16);
4056
4057 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4058         .f = cmd_tunnel_tso_set_parsed,
4059         .data = NULL,
4060         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4061                 "Set TSO segment size of tunneled packets for csum engine "
4062                 "(0 to disable)",
4063         .tokens = {
4064                 (void *)&cmd_tunnel_tso_set_tso,
4065                 (void *)&cmd_tunnel_tso_set_mode,
4066                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4067                 (void *)&cmd_tunnel_tso_set_portid,
4068                 NULL,
4069         },
4070 };
4071
4072 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4073         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4074                                 mode, "show");
4075
4076
4077 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4078         .f = cmd_tunnel_tso_set_parsed,
4079         .data = NULL,
4080         .help_str = "tunnel_tso show <port_id> "
4081                 "Show TSO segment size of tunneled packets for csum engine",
4082         .tokens = {
4083                 (void *)&cmd_tunnel_tso_set_tso,
4084                 (void *)&cmd_tunnel_tso_show_mode,
4085                 (void *)&cmd_tunnel_tso_set_portid,
4086                 NULL,
4087         },
4088 };
4089
4090 /* *** SET GRO FOR A PORT *** */
4091 struct cmd_gro_enable_result {
4092         cmdline_fixed_string_t cmd_set;
4093         cmdline_fixed_string_t cmd_port;
4094         cmdline_fixed_string_t cmd_keyword;
4095         cmdline_fixed_string_t cmd_onoff;
4096         portid_t cmd_pid;
4097 };
4098
4099 static void
4100 cmd_gro_enable_parsed(void *parsed_result,
4101                 __attribute__((unused)) struct cmdline *cl,
4102                 __attribute__((unused)) void *data)
4103 {
4104         struct cmd_gro_enable_result *res;
4105
4106         res = parsed_result;
4107         if (!strcmp(res->cmd_keyword, "gro"))
4108                 setup_gro(res->cmd_onoff, res->cmd_pid);
4109 }
4110
4111 cmdline_parse_token_string_t cmd_gro_enable_set =
4112         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4113                         cmd_set, "set");
4114 cmdline_parse_token_string_t cmd_gro_enable_port =
4115         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4116                         cmd_keyword, "port");
4117 cmdline_parse_token_num_t cmd_gro_enable_pid =
4118         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4119                         cmd_pid, UINT16);
4120 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4121         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4122                         cmd_keyword, "gro");
4123 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4124         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4125                         cmd_onoff, "on#off");
4126
4127 cmdline_parse_inst_t cmd_gro_enable = {
4128         .f = cmd_gro_enable_parsed,
4129         .data = NULL,
4130         .help_str = "set port <port_id> gro on|off",
4131         .tokens = {
4132                 (void *)&cmd_gro_enable_set,
4133                 (void *)&cmd_gro_enable_port,
4134                 (void *)&cmd_gro_enable_pid,
4135                 (void *)&cmd_gro_enable_keyword,
4136                 (void *)&cmd_gro_enable_onoff,
4137                 NULL,
4138         },
4139 };
4140
4141 /* *** DISPLAY GRO CONFIGURATION *** */
4142 struct cmd_gro_show_result {
4143         cmdline_fixed_string_t cmd_show;
4144         cmdline_fixed_string_t cmd_port;
4145         cmdline_fixed_string_t cmd_keyword;
4146         portid_t cmd_pid;
4147 };
4148
4149 static void
4150 cmd_gro_show_parsed(void *parsed_result,
4151                 __attribute__((unused)) struct cmdline *cl,
4152                 __attribute__((unused)) void *data)
4153 {
4154         struct cmd_gro_show_result *res;
4155
4156         res = parsed_result;
4157         if (!strcmp(res->cmd_keyword, "gro"))
4158                 show_gro(res->cmd_pid);
4159 }
4160
4161 cmdline_parse_token_string_t cmd_gro_show_show =
4162         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4163                         cmd_show, "show");
4164 cmdline_parse_token_string_t cmd_gro_show_port =
4165         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4166                         cmd_port, "port");
4167 cmdline_parse_token_num_t cmd_gro_show_pid =
4168         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4169                         cmd_pid, UINT16);
4170 cmdline_parse_token_string_t cmd_gro_show_keyword =
4171         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4172                         cmd_keyword, "gro");
4173
4174 cmdline_parse_inst_t cmd_gro_show = {
4175         .f = cmd_gro_show_parsed,
4176         .data = NULL,
4177         .help_str = "show port <port_id> gro",
4178         .tokens = {
4179                 (void *)&cmd_gro_show_show,
4180                 (void *)&cmd_gro_show_port,
4181                 (void *)&cmd_gro_show_pid,
4182                 (void *)&cmd_gro_show_keyword,
4183                 NULL,
4184         },
4185 };
4186
4187 /* *** SET FLUSH CYCLES FOR GRO *** */
4188 struct cmd_gro_flush_result {
4189         cmdline_fixed_string_t cmd_set;
4190         cmdline_fixed_string_t cmd_keyword;
4191         cmdline_fixed_string_t cmd_flush;
4192         uint8_t cmd_cycles;
4193 };
4194
4195 static void
4196 cmd_gro_flush_parsed(void *parsed_result,
4197                 __attribute__((unused)) struct cmdline *cl,
4198                 __attribute__((unused)) void *data)
4199 {
4200         struct cmd_gro_flush_result *res;
4201
4202         res = parsed_result;
4203         if ((!strcmp(res->cmd_keyword, "gro")) &&
4204                         (!strcmp(res->cmd_flush, "flush")))
4205                 setup_gro_flush_cycles(res->cmd_cycles);
4206 }
4207
4208 cmdline_parse_token_string_t cmd_gro_flush_set =
4209         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4210                         cmd_set, "set");
4211 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4212         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4213                         cmd_keyword, "gro");
4214 cmdline_parse_token_string_t cmd_gro_flush_flush =
4215         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4216                         cmd_flush, "flush");
4217 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4218         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4219                         cmd_cycles, UINT8);
4220
4221 cmdline_parse_inst_t cmd_gro_flush = {
4222         .f = cmd_gro_flush_parsed,
4223         .data = NULL,
4224         .help_str = "set gro flush <cycles>",
4225         .tokens = {
4226                 (void *)&cmd_gro_flush_set,
4227                 (void *)&cmd_gro_flush_keyword,
4228                 (void *)&cmd_gro_flush_flush,
4229                 (void *)&cmd_gro_flush_cycles,
4230                 NULL,
4231         },
4232 };
4233
4234 /* *** ENABLE/DISABLE GSO *** */
4235 struct cmd_gso_enable_result {
4236         cmdline_fixed_string_t cmd_set;
4237         cmdline_fixed_string_t cmd_port;
4238         cmdline_fixed_string_t cmd_keyword;
4239         cmdline_fixed_string_t cmd_mode;
4240         portid_t cmd_pid;
4241 };
4242
4243 static void
4244 cmd_gso_enable_parsed(void *parsed_result,
4245                 __attribute__((unused)) struct cmdline *cl,
4246                 __attribute__((unused)) void *data)
4247 {
4248         struct cmd_gso_enable_result *res;
4249
4250         res = parsed_result;
4251         if (!strcmp(res->cmd_keyword, "gso"))
4252                 setup_gso(res->cmd_mode, res->cmd_pid);
4253 }
4254
4255 cmdline_parse_token_string_t cmd_gso_enable_set =
4256         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4257                         cmd_set, "set");
4258 cmdline_parse_token_string_t cmd_gso_enable_port =
4259         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4260                         cmd_port, "port");
4261 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4262         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4263                         cmd_keyword, "gso");
4264 cmdline_parse_token_string_t cmd_gso_enable_mode =
4265         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4266                         cmd_mode, "on#off");
4267 cmdline_parse_token_num_t cmd_gso_enable_pid =
4268         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4269                         cmd_pid, UINT16);
4270
4271 cmdline_parse_inst_t cmd_gso_enable = {
4272         .f = cmd_gso_enable_parsed,
4273         .data = NULL,
4274         .help_str = "set port <port_id> gso on|off",
4275         .tokens = {
4276                 (void *)&cmd_gso_enable_set,
4277                 (void *)&cmd_gso_enable_port,
4278                 (void *)&cmd_gso_enable_pid,
4279                 (void *)&cmd_gso_enable_keyword,
4280                 (void *)&cmd_gso_enable_mode,
4281                 NULL,
4282         },
4283 };
4284
4285 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4286 struct cmd_gso_size_result {
4287         cmdline_fixed_string_t cmd_set;
4288         cmdline_fixed_string_t cmd_keyword;
4289         cmdline_fixed_string_t cmd_segsz;
4290         uint16_t cmd_size;
4291 };
4292
4293 static void
4294 cmd_gso_size_parsed(void *parsed_result,
4295                        __attribute__((unused)) struct cmdline *cl,
4296                        __attribute__((unused)) void *data)
4297 {
4298         struct cmd_gso_size_result *res = parsed_result;
4299
4300         if (test_done == 0) {
4301                 printf("Before setting GSO segsz, please first"
4302                                 " stop fowarding\n");
4303                 return;
4304         }
4305
4306         if (!strcmp(res->cmd_keyword, "gso") &&
4307                         !strcmp(res->cmd_segsz, "segsz")) {
4308                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4309                         printf("gso_size should be larger than %zu."
4310                                         " Please input a legal value\n",
4311                                         RTE_GSO_SEG_SIZE_MIN);
4312                 else
4313                         gso_max_segment_size = res->cmd_size;
4314         }
4315 }
4316
4317 cmdline_parse_token_string_t cmd_gso_size_set =
4318         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4319                                 cmd_set, "set");
4320 cmdline_parse_token_string_t cmd_gso_size_keyword =
4321         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4322                                 cmd_keyword, "gso");
4323 cmdline_parse_token_string_t cmd_gso_size_segsz =
4324         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4325                                 cmd_segsz, "segsz");
4326 cmdline_parse_token_num_t cmd_gso_size_size =
4327         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4328                                 cmd_size, UINT16);
4329
4330 cmdline_parse_inst_t cmd_gso_size = {
4331         .f = cmd_gso_size_parsed,
4332         .data = NULL,
4333         .help_str = "set gso segsz <length>",
4334         .tokens = {
4335                 (void *)&cmd_gso_size_set,
4336                 (void *)&cmd_gso_size_keyword,
4337                 (void *)&cmd_gso_size_segsz,
4338                 (void *)&cmd_gso_size_size,
4339                 NULL,
4340         },
4341 };
4342
4343 /* *** SHOW GSO CONFIGURATION *** */
4344 struct cmd_gso_show_result {
4345         cmdline_fixed_string_t cmd_show;
4346         cmdline_fixed_string_t cmd_port;
4347         cmdline_fixed_string_t cmd_keyword;
4348         portid_t cmd_pid;
4349 };
4350
4351 static void
4352 cmd_gso_show_parsed(void *parsed_result,
4353                        __attribute__((unused)) struct cmdline *cl,
4354                        __attribute__((unused)) void *data)
4355 {
4356         struct cmd_gso_show_result *res = parsed_result;
4357
4358         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4359                 printf("invalid port id %u\n", res->cmd_pid);
4360                 return;
4361         }
4362         if (!strcmp(res->cmd_keyword, "gso")) {
4363                 if (gso_ports[res->cmd_pid].enable) {
4364                         printf("Max GSO'd packet size: %uB\n"
4365                                         "Supported GSO types: TCP/IPv4, "
4366                                         "VxLAN with inner TCP/IPv4 packet, "
4367                                         "GRE with inner TCP/IPv4  packet\n",
4368                                         gso_max_segment_size);
4369                 } else
4370                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4371         }
4372 }
4373
4374 cmdline_parse_token_string_t cmd_gso_show_show =
4375 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4376                 cmd_show, "show");
4377 cmdline_parse_token_string_t cmd_gso_show_port =
4378 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4379                 cmd_port, "port");
4380 cmdline_parse_token_string_t cmd_gso_show_keyword =
4381         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4382                                 cmd_keyword, "gso");
4383 cmdline_parse_token_num_t cmd_gso_show_pid =
4384         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4385                                 cmd_pid, UINT16);
4386
4387 cmdline_parse_inst_t cmd_gso_show = {
4388         .f = cmd_gso_show_parsed,
4389         .data = NULL,
4390         .help_str = "show port <port_id> gso",
4391         .tokens = {
4392                 (void *)&cmd_gso_show_show,
4393                 (void *)&cmd_gso_show_port,
4394                 (void *)&cmd_gso_show_pid,
4395                 (void *)&cmd_gso_show_keyword,
4396                 NULL,
4397         },
4398 };
4399
4400 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4401 struct cmd_set_flush_rx {
4402         cmdline_fixed_string_t set;
4403         cmdline_fixed_string_t flush_rx;
4404         cmdline_fixed_string_t mode;
4405 };
4406
4407 static void
4408 cmd_set_flush_rx_parsed(void *parsed_result,
4409                 __attribute__((unused)) struct cmdline *cl,
4410                 __attribute__((unused)) void *data)
4411 {
4412         struct cmd_set_flush_rx *res = parsed_result;
4413         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4414 }
4415
4416 cmdline_parse_token_string_t cmd_setflushrx_set =
4417         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4418                         set, "set");
4419 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4420         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4421                         flush_rx, "flush_rx");
4422 cmdline_parse_token_string_t cmd_setflushrx_mode =
4423         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4424                         mode, "on#off");
4425
4426
4427 cmdline_parse_inst_t cmd_set_flush_rx = {
4428         .f = cmd_set_flush_rx_parsed,
4429         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4430         .data = NULL,
4431         .tokens = {
4432                 (void *)&cmd_setflushrx_set,
4433                 (void *)&cmd_setflushrx_flush_rx,
4434                 (void *)&cmd_setflushrx_mode,
4435                 NULL,
4436         },
4437 };
4438
4439 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4440 struct cmd_set_link_check {
4441         cmdline_fixed_string_t set;
4442         cmdline_fixed_string_t link_check;
4443         cmdline_fixed_string_t mode;
4444 };
4445
4446 static void
4447 cmd_set_link_check_parsed(void *parsed_result,
4448                 __attribute__((unused)) struct cmdline *cl,
4449                 __attribute__((unused)) void *data)
4450 {
4451         struct cmd_set_link_check *res = parsed_result;
4452         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4453 }
4454
4455 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4456         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4457                         set, "set");
4458 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4459         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4460                         link_check, "link_check");
4461 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4462         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4463                         mode, "on#off");
4464
4465
4466 cmdline_parse_inst_t cmd_set_link_check = {
4467         .f = cmd_set_link_check_parsed,
4468         .help_str = "set link_check on|off: Enable/Disable link status check "
4469                     "when starting/stopping a port",
4470         .data = NULL,
4471         .tokens = {
4472                 (void *)&cmd_setlinkcheck_set,
4473                 (void *)&cmd_setlinkcheck_link_check,
4474                 (void *)&cmd_setlinkcheck_mode,
4475                 NULL,
4476         },
4477 };
4478
4479 /* *** SET NIC BYPASS MODE *** */
4480 struct cmd_set_bypass_mode_result {
4481         cmdline_fixed_string_t set;
4482         cmdline_fixed_string_t bypass;
4483         cmdline_fixed_string_t mode;
4484         cmdline_fixed_string_t value;
4485         portid_t port_id;
4486 };
4487
4488 static void
4489 cmd_set_bypass_mode_parsed(void *parsed_result,
4490                 __attribute__((unused)) struct cmdline *cl,
4491                 __attribute__((unused)) void *data)
4492 {
4493         struct cmd_set_bypass_mode_result *res = parsed_result;
4494         portid_t port_id = res->port_id;
4495         int32_t rc = -EINVAL;
4496
4497 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4498         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4499
4500         if (!strcmp(res->value, "bypass"))
4501                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4502         else if (!strcmp(res->value, "isolate"))
4503                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4504         else
4505                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4506
4507         /* Set the bypass mode for the relevant port. */
4508         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4509 #endif
4510         if (rc != 0)
4511                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4512 }
4513
4514 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4515         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4516                         set, "set");
4517 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4518         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4519                         bypass, "bypass");
4520 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4521         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4522                         mode, "mode");
4523 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4524         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4525                         value, "normal#bypass#isolate");
4526 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4527         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4528                                 port_id, UINT16);
4529
4530 cmdline_parse_inst_t cmd_set_bypass_mode = {
4531         .f = cmd_set_bypass_mode_parsed,
4532         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4533                     "Set the NIC bypass mode for port_id",
4534         .data = NULL,
4535         .tokens = {
4536                 (void *)&cmd_setbypass_mode_set,
4537                 (void *)&cmd_setbypass_mode_bypass,
4538                 (void *)&cmd_setbypass_mode_mode,
4539                 (void *)&cmd_setbypass_mode_value,
4540                 (void *)&cmd_setbypass_mode_port,
4541                 NULL,
4542         },
4543 };
4544
4545 /* *** SET NIC BYPASS EVENT *** */
4546 struct cmd_set_bypass_event_result {
4547         cmdline_fixed_string_t set;
4548         cmdline_fixed_string_t bypass;
4549         cmdline_fixed_string_t event;
4550         cmdline_fixed_string_t event_value;
4551         cmdline_fixed_string_t mode;
4552         cmdline_fixed_string_t mode_value;
4553         portid_t port_id;
4554 };
4555
4556 static void
4557 cmd_set_bypass_event_parsed(void *parsed_result,
4558                 __attribute__((unused)) struct cmdline *cl,
4559                 __attribute__((unused)) void *data)
4560 {
4561         int32_t rc = -EINVAL;
4562         struct cmd_set_bypass_event_result *res = parsed_result;
4563         portid_t port_id = res->port_id;
4564
4565 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4566         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4567         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4568
4569         if (!strcmp(res->event_value, "timeout"))
4570                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4571         else if (!strcmp(res->event_value, "os_on"))
4572                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4573         else if (!strcmp(res->event_value, "os_off"))
4574                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4575         else if (!strcmp(res->event_value, "power_on"))
4576                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4577         else if (!strcmp(res->event_value, "power_off"))
4578                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4579         else
4580                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4581
4582         if (!strcmp(res->mode_value, "bypass"))
4583                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4584         else if (!strcmp(res->mode_value, "isolate"))
4585                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4586         else
4587                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4588
4589         /* Set the watchdog timeout. */
4590         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4591
4592                 rc = -EINVAL;
4593                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4594                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4595                                                            bypass_timeout);
4596                 }
4597                 if (rc != 0) {
4598                         printf("Failed to set timeout value %u "
4599                         "for port %d, errto code: %d.\n",
4600                         bypass_timeout, port_id, rc);
4601                 }
4602         }
4603
4604         /* Set the bypass event to transition to bypass mode. */
4605         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4606                                               bypass_mode);
4607 #endif
4608
4609         if (rc != 0)
4610                 printf("\t Failed to set bypass event for port = %d.\n",
4611                        port_id);
4612 }
4613
4614 cmdline_parse_token_string_t cmd_setbypass_event_set =
4615         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4616                         set, "set");
4617 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4618         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4619                         bypass, "bypass");
4620 cmdline_parse_token_string_t cmd_setbypass_event_event =
4621         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4622                         event, "event");
4623 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4624         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4625                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4626 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4627         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4628                         mode, "mode");
4629 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4630         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4631                         mode_value, "normal#bypass#isolate");
4632 cmdline_parse_token_num_t cmd_setbypass_event_port =
4633         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4634                                 port_id, UINT16);
4635
4636 cmdline_parse_inst_t cmd_set_bypass_event = {
4637         .f = cmd_set_bypass_event_parsed,
4638         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4639                 "power_off mode normal|bypass|isolate <port_id>: "
4640                 "Set the NIC bypass event mode for port_id",
4641         .data = NULL,
4642         .tokens = {
4643                 (void *)&cmd_setbypass_event_set,
4644                 (void *)&cmd_setbypass_event_bypass,
4645                 (void *)&cmd_setbypass_event_event,
4646                 (void *)&cmd_setbypass_event_event_value,
4647                 (void *)&cmd_setbypass_event_mode,
4648                 (void *)&cmd_setbypass_event_mode_value,
4649                 (void *)&cmd_setbypass_event_port,
4650                 NULL,
4651         },
4652 };
4653
4654
4655 /* *** SET NIC BYPASS TIMEOUT *** */
4656 struct cmd_set_bypass_timeout_result {
4657         cmdline_fixed_string_t set;
4658         cmdline_fixed_string_t bypass;
4659         cmdline_fixed_string_t timeout;
4660         cmdline_fixed_string_t value;
4661 };
4662
4663 static void
4664 cmd_set_bypass_timeout_parsed(void *parsed_result,
4665                 __attribute__((unused)) struct cmdline *cl,
4666                 __attribute__((unused)) void *data)
4667 {
4668         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4669
4670 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4671         if (!strcmp(res->value, "1.5"))
4672                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4673         else if (!strcmp(res->value, "2"))
4674                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4675         else if (!strcmp(res->value, "3"))
4676                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4677         else if (!strcmp(res->value, "4"))
4678                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4679         else if (!strcmp(res->value, "8"))
4680                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4681         else if (!strcmp(res->value, "16"))
4682                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4683         else if (!strcmp(res->value, "32"))
4684                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4685         else
4686                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4687 #endif
4688 }
4689
4690 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4691         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4692                         set, "set");
4693 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4694         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4695                         bypass, "bypass");
4696 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4697         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4698                         timeout, "timeout");
4699 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4700         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4701                         value, "0#1.5#2#3#4#8#16#32");
4702
4703 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4704         .f = cmd_set_bypass_timeout_parsed,
4705         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4706                 "Set the NIC bypass watchdog timeout in seconds",
4707         .data = NULL,
4708         .tokens = {
4709                 (void *)&cmd_setbypass_timeout_set,
4710                 (void *)&cmd_setbypass_timeout_bypass,
4711                 (void *)&cmd_setbypass_timeout_timeout,
4712                 (void *)&cmd_setbypass_timeout_value,
4713                 NULL,
4714         },
4715 };
4716
4717 /* *** SHOW NIC BYPASS MODE *** */
4718 struct cmd_show_bypass_config_result {
4719         cmdline_fixed_string_t show;
4720         cmdline_fixed_string_t bypass;
4721         cmdline_fixed_string_t config;
4722         portid_t port_id;
4723 };
4724
4725 static void
4726 cmd_show_bypass_config_parsed(void *parsed_result,
4727                 __attribute__((unused)) struct cmdline *cl,
4728                 __attribute__((unused)) void *data)
4729 {
4730         struct cmd_show_bypass_config_result *res = parsed_result;
4731         portid_t port_id = res->port_id;
4732         int rc = -EINVAL;
4733 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4734         uint32_t event_mode;
4735         uint32_t bypass_mode;
4736         uint32_t timeout = bypass_timeout;
4737         int i;
4738
4739         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4740                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4741         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4742                 {"UNKNOWN", "normal", "bypass", "isolate"};
4743         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4744                 "NONE",
4745                 "OS/board on",
4746                 "power supply on",
4747                 "OS/board off",
4748                 "power supply off",
4749                 "timeout"};
4750         int num_events = (sizeof events) / (sizeof events[0]);
4751
4752         /* Display the bypass mode.*/
4753         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4754                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4755                 return;
4756         }
4757         else {
4758                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4759                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4760
4761                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4762         }
4763
4764         /* Display the bypass timeout.*/
4765         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4766                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4767
4768         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4769
4770         /* Display the bypass events and associated modes. */
4771         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4772
4773                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4774                         printf("\tFailed to get bypass mode for event = %s\n",
4775                                 events[i]);
4776                 } else {
4777                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4778                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4779
4780                         printf("\tbypass event: %-16s = %s\n", events[i],
4781                                 modes[event_mode]);
4782                 }
4783         }
4784 #endif
4785         if (rc != 0)
4786                 printf("\tFailed to get bypass configuration for port = %d\n",
4787                        port_id);
4788 }
4789
4790 cmdline_parse_token_string_t cmd_showbypass_config_show =
4791         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4792                         show, "show");
4793 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4794         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4795                         bypass, "bypass");
4796 cmdline_parse_token_string_t cmd_showbypass_config_config =
4797         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4798                         config, "config");
4799 cmdline_parse_token_num_t cmd_showbypass_config_port =
4800         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4801                                 port_id, UINT16);
4802
4803 cmdline_parse_inst_t cmd_show_bypass_config = {
4804         .f = cmd_show_bypass_config_parsed,
4805         .help_str = "show bypass config <port_id>: "
4806                     "Show the NIC bypass config for port_id",
4807         .data = NULL,
4808         .tokens = {
4809                 (void *)&cmd_showbypass_config_show,
4810                 (void *)&cmd_showbypass_config_bypass,
4811                 (void *)&cmd_showbypass_config_config,
4812                 (void *)&cmd_showbypass_config_port,
4813                 NULL,
4814         },
4815 };
4816
4817 #ifdef RTE_LIBRTE_PMD_BOND
4818 /* *** SET BONDING MODE *** */
4819 struct cmd_set_bonding_mode_result {
4820         cmdline_fixed_string_t set;
4821         cmdline_fixed_string_t bonding;
4822         cmdline_fixed_string_t mode;
4823         uint8_t value;
4824         portid_t port_id;
4825 };
4826
4827 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4828                 __attribute__((unused))  struct cmdline *cl,
4829                 __attribute__((unused)) void *data)
4830 {
4831         struct cmd_set_bonding_mode_result *res = parsed_result;
4832         portid_t port_id = res->port_id;
4833
4834         /* Set the bonding mode for the relevant port. */
4835         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4836                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4837 }
4838
4839 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4840 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4841                 set, "set");
4842 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4843 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4844                 bonding, "bonding");
4845 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4846 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4847                 mode, "mode");
4848 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4849 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4850                 value, UINT8);
4851 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4852 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4853                 port_id, UINT16);
4854
4855 cmdline_parse_inst_t cmd_set_bonding_mode = {
4856                 .f = cmd_set_bonding_mode_parsed,
4857                 .help_str = "set bonding mode <mode_value> <port_id>: "
4858                         "Set the bonding mode for port_id",
4859                 .data = NULL,
4860                 .tokens = {
4861                                 (void *) &cmd_setbonding_mode_set,
4862                                 (void *) &cmd_setbonding_mode_bonding,
4863                                 (void *) &cmd_setbonding_mode_mode,
4864                                 (void *) &cmd_setbonding_mode_value,
4865                                 (void *) &cmd_setbonding_mode_port,
4866                                 NULL
4867                 }
4868 };
4869
4870 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4871 struct cmd_set_bonding_lacp_dedicated_queues_result {
4872         cmdline_fixed_string_t set;
4873         cmdline_fixed_string_t bonding;
4874         cmdline_fixed_string_t lacp;
4875         cmdline_fixed_string_t dedicated_queues;
4876         portid_t port_id;
4877         cmdline_fixed_string_t mode;
4878 };
4879
4880 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4881                 __attribute__((unused))  struct cmdline *cl,
4882                 __attribute__((unused)) void *data)
4883 {
4884         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4885         portid_t port_id = res->port_id;
4886         struct rte_port *port;
4887
4888         port = &ports[port_id];
4889
4890         /** Check if the port is not started **/
4891         if (port->port_status != RTE_PORT_STOPPED) {
4892                 printf("Please stop port %d first\n", port_id);
4893                 return;
4894         }
4895
4896         if (!strcmp(res->mode, "enable")) {
4897                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4898                         printf("Dedicate queues for LACP control packets"
4899                                         " enabled\n");
4900                 else
4901                         printf("Enabling dedicate queues for LACP control "
4902                                         "packets on port %d failed\n", port_id);
4903         } else if (!strcmp(res->mode, "disable")) {
4904                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4905                         printf("Dedicated queues for LACP control packets "
4906                                         "disabled\n");
4907                 else
4908                         printf("Disabling dedicated queues for LACP control "
4909                                         "traffic on port %d failed\n", port_id);
4910         }
4911 }
4912
4913 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4914 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4915                 set, "set");
4916 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4917 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4918                 bonding, "bonding");
4919 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4921                 lacp, "lacp");
4922 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4923 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4924                 dedicated_queues, "dedicated_queues");
4925 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4926 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4927                 port_id, UINT16);
4928 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4929 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4930                 mode, "enable#disable");
4931
4932 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4933                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4934                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4935                         "enable|disable: "
4936                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4937                 .data = NULL,
4938                 .tokens = {
4939                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4940                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4941                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4942                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4943                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4944                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4945                         NULL
4946                 }
4947 };
4948
4949 /* *** SET BALANCE XMIT POLICY *** */
4950 struct cmd_set_bonding_balance_xmit_policy_result {
4951         cmdline_fixed_string_t set;
4952         cmdline_fixed_string_t bonding;
4953         cmdline_fixed_string_t balance_xmit_policy;
4954         portid_t port_id;
4955         cmdline_fixed_string_t policy;
4956 };
4957
4958 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4959                 __attribute__((unused))  struct cmdline *cl,
4960                 __attribute__((unused)) void *data)
4961 {
4962         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4963         portid_t port_id = res->port_id;
4964         uint8_t policy;
4965
4966         if (!strcmp(res->policy, "l2")) {
4967                 policy = BALANCE_XMIT_POLICY_LAYER2;
4968         } else if (!strcmp(res->policy, "l23")) {
4969                 policy = BALANCE_XMIT_POLICY_LAYER23;
4970         } else if (!strcmp(res->policy, "l34")) {
4971                 policy = BALANCE_XMIT_POLICY_LAYER34;
4972         } else {
4973                 printf("\t Invalid xmit policy selection");
4974                 return;
4975         }
4976
4977         /* Set the bonding mode for the relevant port. */
4978         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4979                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4980                                 port_id);
4981         }
4982 }
4983
4984 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4985 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4986                 set, "set");
4987 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4988 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4989                 bonding, "bonding");
4990 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4991 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4992                 balance_xmit_policy, "balance_xmit_policy");
4993 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4994 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4995                 port_id, UINT16);
4996 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4997 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4998                 policy, "l2#l23#l34");
4999
5000 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5001                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5002                 .help_str = "set bonding balance_xmit_policy <port_id> "
5003                         "l2|l23|l34: "
5004                         "Set the bonding balance_xmit_policy for port_id",
5005                 .data = NULL,
5006                 .tokens = {
5007                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5008                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5009                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5010                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5011                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5012                                 NULL
5013                 }
5014 };
5015
5016 /* *** SHOW NIC BONDING CONFIGURATION *** */
5017 struct cmd_show_bonding_config_result {
5018         cmdline_fixed_string_t show;
5019         cmdline_fixed_string_t bonding;
5020         cmdline_fixed_string_t config;
5021         portid_t port_id;
5022 };
5023
5024 static void cmd_show_bonding_config_parsed(void *parsed_result,
5025                 __attribute__((unused))  struct cmdline *cl,
5026                 __attribute__((unused)) void *data)
5027 {
5028         struct cmd_show_bonding_config_result *res = parsed_result;
5029         int bonding_mode, agg_mode;
5030         portid_t slaves[RTE_MAX_ETHPORTS];
5031         int num_slaves, num_active_slaves;
5032         int primary_id;
5033         int i;
5034         portid_t port_id = res->port_id;
5035
5036         /* Display the bonding mode.*/
5037         bonding_mode = rte_eth_bond_mode_get(port_id);
5038         if (bonding_mode < 0) {
5039                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5040                 return;
5041         } else
5042                 printf("\tBonding mode: %d\n", bonding_mode);
5043
5044         if (bonding_mode == BONDING_MODE_BALANCE) {
5045                 int balance_xmit_policy;
5046
5047                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5048                 if (balance_xmit_policy < 0) {
5049                         printf("\tFailed to get balance xmit policy for port = %d\n",
5050                                         port_id);
5051                         return;
5052                 } else {
5053                         printf("\tBalance Xmit Policy: ");
5054
5055                         switch (balance_xmit_policy) {
5056                         case BALANCE_XMIT_POLICY_LAYER2:
5057                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5058                                 break;
5059                         case BALANCE_XMIT_POLICY_LAYER23:
5060                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5061                                 break;
5062                         case BALANCE_XMIT_POLICY_LAYER34:
5063                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5064                                 break;
5065                         }
5066                         printf("\n");
5067                 }
5068         }
5069
5070         if (bonding_mode == BONDING_MODE_8023AD) {
5071                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5072                 printf("\tIEEE802.3AD Aggregator Mode: ");
5073                 switch (agg_mode) {
5074                 case AGG_BANDWIDTH:
5075                         printf("bandwidth");
5076                         break;
5077                 case AGG_STABLE:
5078                         printf("stable");
5079                         break;
5080                 case AGG_COUNT:
5081                         printf("count");
5082                         break;
5083                 }
5084                 printf("\n");
5085         }
5086
5087         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5088
5089         if (num_slaves < 0) {
5090                 printf("\tFailed to get slave list for port = %d\n", port_id);
5091                 return;
5092         }
5093         if (num_slaves > 0) {
5094                 printf("\tSlaves (%d): [", num_slaves);
5095                 for (i = 0; i < num_slaves - 1; i++)
5096                         printf("%d ", slaves[i]);
5097
5098                 printf("%d]\n", slaves[num_slaves - 1]);
5099         } else {
5100                 printf("\tSlaves: []\n");
5101
5102         }
5103
5104         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5105                         RTE_MAX_ETHPORTS);
5106
5107         if (num_active_slaves < 0) {
5108                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5109                 return;
5110         }
5111         if (num_active_slaves > 0) {
5112                 printf("\tActive Slaves (%d): [", num_active_slaves);
5113                 for (i = 0; i < num_active_slaves - 1; i++)
5114                         printf("%d ", slaves[i]);
5115
5116                 printf("%d]\n", slaves[num_active_slaves - 1]);
5117
5118         } else {
5119                 printf("\tActive Slaves: []\n");
5120
5121         }
5122
5123         primary_id = rte_eth_bond_primary_get(port_id);
5124         if (primary_id < 0) {
5125                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5126                 return;
5127         } else
5128                 printf("\tPrimary: [%d]\n", primary_id);
5129
5130 }
5131
5132 cmdline_parse_token_string_t cmd_showbonding_config_show =
5133 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5134                 show, "show");
5135 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5136 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5137                 bonding, "bonding");
5138 cmdline_parse_token_string_t cmd_showbonding_config_config =
5139 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5140                 config, "config");
5141 cmdline_parse_token_num_t cmd_showbonding_config_port =
5142 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5143                 port_id, UINT16);
5144
5145 cmdline_parse_inst_t cmd_show_bonding_config = {
5146                 .f = cmd_show_bonding_config_parsed,
5147                 .help_str = "show bonding config <port_id>: "
5148                         "Show the bonding config for port_id",
5149                 .data = NULL,
5150                 .tokens = {
5151                                 (void *)&cmd_showbonding_config_show,
5152                                 (void *)&cmd_showbonding_config_bonding,
5153                                 (void *)&cmd_showbonding_config_config,
5154                                 (void *)&cmd_showbonding_config_port,
5155                                 NULL
5156                 }
5157 };
5158
5159 /* *** SET BONDING PRIMARY *** */
5160 struct cmd_set_bonding_primary_result {
5161         cmdline_fixed_string_t set;
5162         cmdline_fixed_string_t bonding;
5163         cmdline_fixed_string_t primary;
5164         portid_t slave_id;
5165         portid_t port_id;
5166 };
5167
5168 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5169                 __attribute__((unused))  struct cmdline *cl,
5170                 __attribute__((unused)) void *data)
5171 {
5172         struct cmd_set_bonding_primary_result *res = parsed_result;
5173         portid_t master_port_id = res->port_id;
5174         portid_t slave_port_id = res->slave_id;
5175
5176         /* Set the primary slave for a bonded device. */
5177         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5178                 printf("\t Failed to set primary slave for port = %d.\n",
5179                                 master_port_id);
5180                 return;
5181         }
5182         init_port_config();
5183 }
5184
5185 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5186 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5187                 set, "set");
5188 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5189 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5190                 bonding, "bonding");
5191 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5192 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5193                 primary, "primary");
5194 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5195 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5196                 slave_id, UINT16);
5197 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5198 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5199                 port_id, UINT16);
5200
5201 cmdline_parse_inst_t cmd_set_bonding_primary = {
5202                 .f = cmd_set_bonding_primary_parsed,
5203                 .help_str = "set bonding primary <slave_id> <port_id>: "
5204                         "Set the primary slave for port_id",
5205                 .data = NULL,
5206                 .tokens = {
5207                                 (void *)&cmd_setbonding_primary_set,
5208                                 (void *)&cmd_setbonding_primary_bonding,
5209                                 (void *)&cmd_setbonding_primary_primary,
5210                                 (void *)&cmd_setbonding_primary_slave,
5211                                 (void *)&cmd_setbonding_primary_port,
5212                                 NULL
5213                 }
5214 };
5215
5216 /* *** ADD SLAVE *** */
5217 struct cmd_add_bonding_slave_result {
5218         cmdline_fixed_string_t add;
5219         cmdline_fixed_string_t bonding;
5220         cmdline_fixed_string_t slave;
5221         portid_t slave_id;
5222         portid_t port_id;
5223 };
5224
5225 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5226                 __attribute__((unused))  struct cmdline *cl,
5227                 __attribute__((unused)) void *data)
5228 {
5229         struct cmd_add_bonding_slave_result *res = parsed_result;
5230         portid_t master_port_id = res->port_id;
5231         portid_t slave_port_id = res->slave_id;
5232
5233         /* add the slave for a bonded device. */
5234         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5235                 printf("\t Failed to add slave %d to master port = %d.\n",
5236                                 slave_port_id, master_port_id);
5237                 return;
5238         }
5239         init_port_config();
5240         set_port_slave_flag(slave_port_id);
5241 }
5242
5243 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5244 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5245                 add, "add");
5246 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5247 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5248                 bonding, "bonding");
5249 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5250 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5251                 slave, "slave");
5252 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5253 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5254                 slave_id, UINT16);
5255 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5256 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5257                 port_id, UINT16);
5258
5259 cmdline_parse_inst_t cmd_add_bonding_slave = {
5260                 .f = cmd_add_bonding_slave_parsed,
5261                 .help_str = "add bonding slave <slave_id> <port_id>: "
5262                         "Add a slave device to a bonded device",
5263                 .data = NULL,
5264                 .tokens = {
5265                                 (void *)&cmd_addbonding_slave_add,
5266                                 (void *)&cmd_addbonding_slave_bonding,
5267                                 (void *)&cmd_addbonding_slave_slave,
5268                                 (void *)&cmd_addbonding_slave_slaveid,
5269                                 (void *)&cmd_addbonding_slave_port,
5270                                 NULL
5271                 }
5272 };
5273
5274 /* *** REMOVE SLAVE *** */
5275 struct cmd_remove_bonding_slave_result {
5276         cmdline_fixed_string_t remove;
5277         cmdline_fixed_string_t bonding;
5278         cmdline_fixed_string_t slave;
5279         portid_t slave_id;
5280         portid_t port_id;
5281 };
5282
5283 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5284                 __attribute__((unused))  struct cmdline *cl,
5285                 __attribute__((unused)) void *data)
5286 {
5287         struct cmd_remove_bonding_slave_result *res = parsed_result;
5288         portid_t master_port_id = res->port_id;
5289         portid_t slave_port_id = res->slave_id;
5290
5291         /* remove the slave from a bonded device. */
5292         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5293                 printf("\t Failed to remove slave %d from master port = %d.\n",
5294                                 slave_port_id, master_port_id);
5295                 return;
5296         }
5297         init_port_config();
5298         clear_port_slave_flag(slave_port_id);
5299 }
5300
5301 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5302                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5303                                 remove, "remove");
5304 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5305                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5306                                 bonding, "bonding");
5307 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5308                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5309                                 slave, "slave");
5310 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5311                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5312                                 slave_id, UINT16);
5313 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5314                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5315                                 port_id, UINT16);
5316
5317 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5318                 .f = cmd_remove_bonding_slave_parsed,
5319                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5320                         "Remove a slave device from a bonded device",
5321                 .data = NULL,
5322                 .tokens = {
5323                                 (void *)&cmd_removebonding_slave_remove,
5324                                 (void *)&cmd_removebonding_slave_bonding,
5325                                 (void *)&cmd_removebonding_slave_slave,
5326                                 (void *)&cmd_removebonding_slave_slaveid,
5327                                 (void *)&cmd_removebonding_slave_port,
5328                                 NULL
5329                 }
5330 };
5331
5332 /* *** CREATE BONDED DEVICE *** */
5333 struct cmd_create_bonded_device_result {
5334         cmdline_fixed_string_t create;
5335         cmdline_fixed_string_t bonded;
5336         cmdline_fixed_string_t device;
5337         uint8_t mode;
5338         uint8_t socket;
5339 };
5340
5341 static int bond_dev_num = 0;
5342
5343 static void cmd_create_bonded_device_parsed(void *parsed_result,
5344                 __attribute__((unused))  struct cmdline *cl,
5345                 __attribute__((unused)) void *data)
5346 {
5347         struct cmd_create_bonded_device_result *res = parsed_result;
5348         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5349         int port_id;
5350
5351         if (test_done == 0) {
5352                 printf("Please stop forwarding first\n");
5353                 return;
5354         }
5355
5356         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5357                         bond_dev_num++);
5358
5359         /* Create a new bonded device. */
5360         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5361         if (port_id < 0) {
5362                 printf("\t Failed to create bonded device.\n");
5363                 return;
5364         } else {
5365                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5366                                 port_id);
5367
5368                 /* Update number of ports */
5369                 nb_ports = rte_eth_dev_count();
5370                 reconfig(port_id, res->socket);
5371                 rte_eth_promiscuous_enable(port_id);
5372         }
5373
5374 }
5375
5376 cmdline_parse_token_string_t cmd_createbonded_device_create =
5377                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5378                                 create, "create");
5379 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5380                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5381                                 bonded, "bonded");
5382 cmdline_parse_token_string_t cmd_createbonded_device_device =
5383                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5384                                 device, "device");
5385 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5386                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5387                                 mode, UINT8);
5388 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5389                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5390                                 socket, UINT8);
5391
5392 cmdline_parse_inst_t cmd_create_bonded_device = {
5393                 .f = cmd_create_bonded_device_parsed,
5394                 .help_str = "create bonded device <mode> <socket>: "
5395                         "Create a new bonded device with specific bonding mode and socket",
5396                 .data = NULL,
5397                 .tokens = {
5398                                 (void *)&cmd_createbonded_device_create,
5399                                 (void *)&cmd_createbonded_device_bonded,
5400                                 (void *)&cmd_createbonded_device_device,
5401                                 (void *)&cmd_createbonded_device_mode,
5402                                 (void *)&cmd_createbonded_device_socket,
5403                                 NULL
5404                 }
5405 };
5406
5407 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5408 struct cmd_set_bond_mac_addr_result {
5409         cmdline_fixed_string_t set;
5410         cmdline_fixed_string_t bonding;
5411         cmdline_fixed_string_t mac_addr;
5412         uint16_t port_num;
5413         struct ether_addr address;
5414 };
5415
5416 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5417                 __attribute__((unused))  struct cmdline *cl,
5418                 __attribute__((unused)) void *data)
5419 {
5420         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5421         int ret;
5422
5423         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5424                 return;
5425
5426         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5427
5428         /* check the return value and print it if is < 0 */
5429         if (ret < 0)
5430                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5431 }
5432
5433 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5434                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5435 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5436                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5437                                 "bonding");
5438 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5439                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5440                                 "mac_addr");
5441 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5442                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5443                                 port_num, UINT16);
5444 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5445                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5446
5447 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5448                 .f = cmd_set_bond_mac_addr_parsed,
5449                 .data = (void *) 0,
5450                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5451                 .tokens = {
5452                                 (void *)&cmd_set_bond_mac_addr_set,
5453                                 (void *)&cmd_set_bond_mac_addr_bonding,
5454                                 (void *)&cmd_set_bond_mac_addr_mac,
5455                                 (void *)&cmd_set_bond_mac_addr_portnum,
5456                                 (void *)&cmd_set_bond_mac_addr_addr,
5457                                 NULL
5458                 }
5459 };
5460
5461
5462 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5463 struct cmd_set_bond_mon_period_result {
5464         cmdline_fixed_string_t set;
5465         cmdline_fixed_string_t bonding;
5466         cmdline_fixed_string_t mon_period;
5467         uint16_t port_num;
5468         uint32_t period_ms;
5469 };
5470
5471 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5472                 __attribute__((unused))  struct cmdline *cl,
5473                 __attribute__((unused)) void *data)
5474 {
5475         struct cmd_set_bond_mon_period_result *res = parsed_result;
5476         int ret;
5477
5478         if (res->port_num >= nb_ports) {
5479                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5480                 return;
5481         }
5482
5483         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5484
5485         /* check the return value and print it if is < 0 */
5486         if (ret < 0)
5487                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5488 }
5489
5490 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5491                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5492                                 set, "set");
5493 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5494                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5495                                 bonding, "bonding");
5496 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5497                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5498                                 mon_period,     "mon_period");
5499 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5500                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5501                                 port_num, UINT16);
5502 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5503                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5504                                 period_ms, UINT32);
5505
5506 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5507                 .f = cmd_set_bond_mon_period_parsed,
5508                 .data = (void *) 0,
5509                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5510                 .tokens = {
5511                                 (void *)&cmd_set_bond_mon_period_set,
5512                                 (void *)&cmd_set_bond_mon_period_bonding,
5513                                 (void *)&cmd_set_bond_mon_period_mon_period,
5514                                 (void *)&cmd_set_bond_mon_period_portnum,
5515                                 (void *)&cmd_set_bond_mon_period_period_ms,
5516                                 NULL
5517                 }
5518 };
5519
5520
5521
5522 struct cmd_set_bonding_agg_mode_policy_result {
5523         cmdline_fixed_string_t set;
5524         cmdline_fixed_string_t bonding;
5525         cmdline_fixed_string_t agg_mode;
5526         uint16_t port_num;
5527         cmdline_fixed_string_t policy;
5528 };
5529
5530
5531 static void
5532 cmd_set_bonding_agg_mode(void *parsed_result,
5533                 __attribute__((unused)) struct cmdline *cl,
5534                 __attribute__((unused)) void *data)
5535 {
5536         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5537         uint8_t policy = AGG_BANDWIDTH;
5538
5539         if (res->port_num >= nb_ports) {
5540                 printf("Port id %d must be less than %d\n",
5541                                 res->port_num, nb_ports);
5542                 return;
5543         }
5544
5545         if (!strcmp(res->policy, "bandwidth"))
5546                 policy = AGG_BANDWIDTH;
5547         else if (!strcmp(res->policy, "stable"))
5548                 policy = AGG_STABLE;
5549         else if (!strcmp(res->policy, "count"))
5550                 policy = AGG_COUNT;
5551
5552         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5553 }
5554
5555
5556 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5557         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5558                                 set, "set");
5559 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5560         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5561                                 bonding, "bonding");
5562
5563 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5564         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5565                                 agg_mode, "agg_mode");
5566
5567 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5568         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5569                                 port_num, UINT16);
5570
5571 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5572         TOKEN_STRING_INITIALIZER(
5573                         struct cmd_set_bonding_balance_xmit_policy_result,
5574                 policy, "stable#bandwidth#count");
5575
5576 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5577         .f = cmd_set_bonding_agg_mode,
5578         .data = (void *) 0,
5579         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5580         .tokens = {
5581                         (void *)&cmd_set_bonding_agg_mode_set,
5582                         (void *)&cmd_set_bonding_agg_mode_bonding,
5583                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5584                         (void *)&cmd_set_bonding_agg_mode_portnum,
5585                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5586                         NULL
5587                 }
5588 };
5589
5590
5591 #endif /* RTE_LIBRTE_PMD_BOND */
5592
5593 /* *** SET FORWARDING MODE *** */
5594 struct cmd_set_fwd_mode_result {
5595         cmdline_fixed_string_t set;
5596         cmdline_fixed_string_t fwd;
5597         cmdline_fixed_string_t mode;
5598 };
5599
5600 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5601                                     __attribute__((unused)) struct cmdline *cl,
5602                                     __attribute__((unused)) void *data)
5603 {
5604         struct cmd_set_fwd_mode_result *res = parsed_result;
5605
5606         retry_enabled = 0;
5607         set_pkt_forwarding_mode(res->mode);
5608 }
5609
5610 cmdline_parse_token_string_t cmd_setfwd_set =
5611         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5612 cmdline_parse_token_string_t cmd_setfwd_fwd =
5613         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5614 cmdline_parse_token_string_t cmd_setfwd_mode =
5615         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5616                 "" /* defined at init */);
5617
5618 cmdline_parse_inst_t cmd_set_fwd_mode = {
5619         .f = cmd_set_fwd_mode_parsed,
5620         .data = NULL,
5621         .help_str = NULL, /* defined at init */
5622         .tokens = {
5623                 (void *)&cmd_setfwd_set,
5624                 (void *)&cmd_setfwd_fwd,
5625                 (void *)&cmd_setfwd_mode,
5626                 NULL,
5627         },
5628 };
5629
5630 static void cmd_set_fwd_mode_init(void)
5631 {
5632         char *modes, *c;
5633         static char token[128];
5634         static char help[256];
5635         cmdline_parse_token_string_t *token_struct;
5636
5637         modes = list_pkt_forwarding_modes();
5638         snprintf(help, sizeof(help), "set fwd %s: "
5639                 "Set packet forwarding mode", modes);
5640         cmd_set_fwd_mode.help_str = help;
5641
5642         /* string token separator is # */
5643         for (c = token; *modes != '\0'; modes++)
5644                 if (*modes == '|')
5645                         *c++ = '#';
5646                 else
5647                         *c++ = *modes;
5648         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5649         token_struct->string_data.str = token;
5650 }
5651
5652 /* *** SET RETRY FORWARDING MODE *** */
5653 struct cmd_set_fwd_retry_mode_result {
5654         cmdline_fixed_string_t set;
5655         cmdline_fixed_string_t fwd;
5656         cmdline_fixed_string_t mode;
5657         cmdline_fixed_string_t retry;
5658 };
5659
5660 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5661                             __attribute__((unused)) struct cmdline *cl,
5662                             __attribute__((unused)) void *data)
5663 {
5664         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5665
5666         retry_enabled = 1;
5667         set_pkt_forwarding_mode(res->mode);
5668 }
5669
5670 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5671         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5672                         set, "set");
5673 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5674         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5675                         fwd, "fwd");
5676 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5677         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5678                         mode,
5679                 "" /* defined at init */);
5680 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5681         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5682                         retry, "retry");
5683
5684 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5685         .f = cmd_set_fwd_retry_mode_parsed,
5686         .data = NULL,
5687         .help_str = NULL, /* defined at init */
5688         .tokens = {
5689                 (void *)&cmd_setfwd_retry_set,
5690                 (void *)&cmd_setfwd_retry_fwd,
5691                 (void *)&cmd_setfwd_retry_mode,
5692                 (void *)&cmd_setfwd_retry_retry,
5693                 NULL,
5694         },
5695 };
5696
5697 static void cmd_set_fwd_retry_mode_init(void)
5698 {
5699         char *modes, *c;
5700         static char token[128];
5701         static char help[256];
5702         cmdline_parse_token_string_t *token_struct;
5703
5704         modes = list_pkt_forwarding_retry_modes();
5705         snprintf(help, sizeof(help), "set fwd %s retry: "
5706                 "Set packet forwarding mode with retry", modes);
5707         cmd_set_fwd_retry_mode.help_str = help;
5708
5709         /* string token separator is # */
5710         for (c = token; *modes != '\0'; modes++)
5711                 if (*modes == '|')
5712                         *c++ = '#';
5713                 else
5714                         *c++ = *modes;
5715         token_struct = (cmdline_parse_token_string_t *)
5716                 cmd_set_fwd_retry_mode.tokens[2];
5717         token_struct->string_data.str = token;
5718 }
5719
5720 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5721 struct cmd_set_burst_tx_retry_result {
5722         cmdline_fixed_string_t set;
5723         cmdline_fixed_string_t burst;
5724         cmdline_fixed_string_t tx;
5725         cmdline_fixed_string_t delay;
5726         uint32_t time;
5727         cmdline_fixed_string_t retry;
5728         uint32_t retry_num;
5729 };
5730
5731 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5732                                         __attribute__((unused)) struct cmdline *cl,
5733                                         __attribute__((unused)) void *data)
5734 {
5735         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5736
5737         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5738                 && !strcmp(res->tx, "tx")) {
5739                 if (!strcmp(res->delay, "delay"))
5740                         burst_tx_delay_time = res->time;
5741                 if (!strcmp(res->retry, "retry"))
5742                         burst_tx_retry_num = res->retry_num;
5743         }
5744
5745 }
5746
5747 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5748         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5749 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5750         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5751                                  "burst");
5752 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5753         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5754 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5755         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5756 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5757         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5758 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5759         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5760 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5761         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5762
5763 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5764         .f = cmd_set_burst_tx_retry_parsed,
5765         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5766         .tokens = {
5767                 (void *)&cmd_set_burst_tx_retry_set,
5768                 (void *)&cmd_set_burst_tx_retry_burst,
5769                 (void *)&cmd_set_burst_tx_retry_tx,
5770                 (void *)&cmd_set_burst_tx_retry_delay,
5771                 (void *)&cmd_set_burst_tx_retry_time,
5772                 (void *)&cmd_set_burst_tx_retry_retry,
5773                 (void *)&cmd_set_burst_tx_retry_retry_num,
5774                 NULL,
5775         },
5776 };
5777
5778 /* *** SET PROMISC MODE *** */
5779 struct cmd_set_promisc_mode_result {
5780         cmdline_fixed_string_t set;
5781         cmdline_fixed_string_t promisc;
5782         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5783         uint16_t port_num;               /* valid if "allports" argument == 0 */
5784         cmdline_fixed_string_t mode;
5785 };
5786
5787 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5788                                         __attribute__((unused)) struct cmdline *cl,
5789                                         void *allports)
5790 {
5791         struct cmd_set_promisc_mode_result *res = parsed_result;
5792         int enable;
5793         portid_t i;
5794
5795         if (!strcmp(res->mode, "on"))
5796                 enable = 1;
5797         else
5798                 enable = 0;
5799
5800         /* all ports */
5801         if (allports) {
5802                 RTE_ETH_FOREACH_DEV(i) {
5803                         if (enable)
5804                                 rte_eth_promiscuous_enable(i);
5805                         else
5806                                 rte_eth_promiscuous_disable(i);
5807                 }
5808         }
5809         else {
5810                 if (enable)
5811                         rte_eth_promiscuous_enable(res->port_num);
5812                 else
5813                         rte_eth_promiscuous_disable(res->port_num);
5814         }
5815 }
5816
5817 cmdline_parse_token_string_t cmd_setpromisc_set =
5818         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5819 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5820         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5821                                  "promisc");
5822 cmdline_parse_token_string_t cmd_setpromisc_portall =
5823         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5824                                  "all");
5825 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5826         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5827                               UINT8);
5828 cmdline_parse_token_string_t cmd_setpromisc_mode =
5829         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5830                                  "on#off");
5831
5832 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5833         .f = cmd_set_promisc_mode_parsed,
5834         .data = (void *)1,
5835         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5836         .tokens = {
5837                 (void *)&cmd_setpromisc_set,
5838                 (void *)&cmd_setpromisc_promisc,
5839                 (void *)&cmd_setpromisc_portall,
5840                 (void *)&cmd_setpromisc_mode,
5841                 NULL,
5842         },
5843 };
5844
5845 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5846         .f = cmd_set_promisc_mode_parsed,
5847         .data = (void *)0,
5848         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5849         .tokens = {
5850                 (void *)&cmd_setpromisc_set,
5851                 (void *)&cmd_setpromisc_promisc,
5852                 (void *)&cmd_setpromisc_portnum,
5853                 (void *)&cmd_setpromisc_mode,
5854                 NULL,
5855         },
5856 };
5857
5858 /* *** SET ALLMULTI MODE *** */
5859 struct cmd_set_allmulti_mode_result {
5860         cmdline_fixed_string_t set;
5861         cmdline_fixed_string_t allmulti;
5862         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5863         uint16_t port_num;               /* valid if "allports" argument == 0 */
5864         cmdline_fixed_string_t mode;
5865 };
5866
5867 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5868                                         __attribute__((unused)) struct cmdline *cl,
5869                                         void *allports)
5870 {
5871         struct cmd_set_allmulti_mode_result *res = parsed_result;
5872         int enable;
5873         portid_t i;
5874
5875         if (!strcmp(res->mode, "on"))
5876                 enable = 1;
5877         else
5878                 enable = 0;
5879
5880         /* all ports */
5881         if (allports) {
5882                 RTE_ETH_FOREACH_DEV(i) {
5883                         if (enable)
5884                                 rte_eth_allmulticast_enable(i);
5885                         else
5886                                 rte_eth_allmulticast_disable(i);
5887                 }
5888         }
5889         else {
5890                 if (enable)
5891                         rte_eth_allmulticast_enable(res->port_num);
5892                 else
5893                         rte_eth_allmulticast_disable(res->port_num);
5894         }
5895 }
5896
5897 cmdline_parse_token_string_t cmd_setallmulti_set =
5898         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5899 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5900         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5901                                  "allmulti");
5902 cmdline_parse_token_string_t cmd_setallmulti_portall =
5903         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5904                                  "all");
5905 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5906         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5907                               UINT16);
5908 cmdline_parse_token_string_t cmd_setallmulti_mode =
5909         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5910                                  "on#off");
5911
5912 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5913         .f = cmd_set_allmulti_mode_parsed,
5914         .data = (void *)1,
5915         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5916         .tokens = {
5917                 (void *)&cmd_setallmulti_set,
5918                 (void *)&cmd_setallmulti_allmulti,
5919                 (void *)&cmd_setallmulti_portall,
5920                 (void *)&cmd_setallmulti_mode,
5921                 NULL,
5922         },
5923 };
5924
5925 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5926         .f = cmd_set_allmulti_mode_parsed,
5927         .data = (void *)0,
5928         .help_str = "set allmulti <port_id> on|off: "
5929                 "Set allmulti mode on port_id",
5930         .tokens = {
5931                 (void *)&cmd_setallmulti_set,
5932                 (void *)&cmd_setallmulti_allmulti,
5933                 (void *)&cmd_setallmulti_portnum,
5934                 (void *)&cmd_setallmulti_mode,
5935                 NULL,
5936         },
5937 };
5938
5939 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5940 struct cmd_link_flow_ctrl_set_result {
5941         cmdline_fixed_string_t set;
5942         cmdline_fixed_string_t flow_ctrl;
5943         cmdline_fixed_string_t rx;
5944         cmdline_fixed_string_t rx_lfc_mode;
5945         cmdline_fixed_string_t tx;
5946         cmdline_fixed_string_t tx_lfc_mode;
5947         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5948         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5949         cmdline_fixed_string_t autoneg_str;
5950         cmdline_fixed_string_t autoneg;
5951         cmdline_fixed_string_t hw_str;
5952         uint32_t high_water;
5953         cmdline_fixed_string_t lw_str;
5954         uint32_t low_water;
5955         cmdline_fixed_string_t pt_str;
5956         uint16_t pause_time;
5957         cmdline_fixed_string_t xon_str;
5958         uint16_t send_xon;
5959         portid_t port_id;
5960 };
5961
5962 cmdline_parse_token_string_t cmd_lfc_set_set =
5963         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5964                                 set, "set");
5965 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5966         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5967                                 flow_ctrl, "flow_ctrl");
5968 cmdline_parse_token_string_t cmd_lfc_set_rx =
5969         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5970                                 rx, "rx");
5971 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5972         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5973                                 rx_lfc_mode, "on#off");
5974 cmdline_parse_token_string_t cmd_lfc_set_tx =
5975         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5976                                 tx, "tx");
5977 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5978         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5979                                 tx_lfc_mode, "on#off");
5980 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5981         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5982                                 hw_str, "high_water");
5983 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5984         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5985                                 high_water, UINT32);
5986 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5987         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5988                                 lw_str, "low_water");
5989 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5990         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5991                                 low_water, UINT32);
5992 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5993         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5994                                 pt_str, "pause_time");
5995 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5996         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5997                                 pause_time, UINT16);
5998 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5999         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6000                                 xon_str, "send_xon");
6001 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6002         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6003                                 send_xon, UINT16);
6004 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6005         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6006                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6007 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6008         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6009                                 mac_ctrl_frame_fwd_mode, "on#off");
6010 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6011         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6012                                 autoneg_str, "autoneg");
6013 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6014         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6015                                 autoneg, "on#off");
6016 cmdline_parse_token_num_t cmd_lfc_set_portid =
6017         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6018                                 port_id, UINT16);
6019
6020 /* forward declaration */
6021 static void
6022 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6023                               void *data);
6024
6025 cmdline_parse_inst_t cmd_link_flow_control_set = {
6026         .f = cmd_link_flow_ctrl_set_parsed,
6027         .data = NULL,
6028         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6029                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6030                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6031         .tokens = {
6032                 (void *)&cmd_lfc_set_set,
6033                 (void *)&cmd_lfc_set_flow_ctrl,
6034                 (void *)&cmd_lfc_set_rx,
6035                 (void *)&cmd_lfc_set_rx_mode,
6036                 (void *)&cmd_lfc_set_tx,
6037                 (void *)&cmd_lfc_set_tx_mode,
6038                 (void *)&cmd_lfc_set_high_water,
6039                 (void *)&cmd_lfc_set_low_water,
6040                 (void *)&cmd_lfc_set_pause_time,
6041                 (void *)&cmd_lfc_set_send_xon,
6042                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6043                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6044                 (void *)&cmd_lfc_set_autoneg_str,
6045                 (void *)&cmd_lfc_set_autoneg,
6046                 (void *)&cmd_lfc_set_portid,
6047                 NULL,
6048         },
6049 };
6050
6051 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6052         .f = cmd_link_flow_ctrl_set_parsed,
6053         .data = (void *)&cmd_link_flow_control_set_rx,
6054         .help_str = "set flow_ctrl rx on|off <port_id>: "
6055                 "Change rx flow control parameter",
6056         .tokens = {
6057                 (void *)&cmd_lfc_set_set,
6058                 (void *)&cmd_lfc_set_flow_ctrl,
6059                 (void *)&cmd_lfc_set_rx,
6060                 (void *)&cmd_lfc_set_rx_mode,
6061                 (void *)&cmd_lfc_set_portid,
6062                 NULL,
6063         },
6064 };
6065
6066 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6067         .f = cmd_link_flow_ctrl_set_parsed,
6068         .data = (void *)&cmd_link_flow_control_set_tx,
6069         .help_str = "set flow_ctrl tx on|off <port_id>: "
6070                 "Change tx flow control parameter",
6071         .tokens = {
6072                 (void *)&cmd_lfc_set_set,
6073                 (void *)&cmd_lfc_set_flow_ctrl,
6074                 (void *)&cmd_lfc_set_tx,
6075                 (void *)&cmd_lfc_set_tx_mode,
6076                 (void *)&cmd_lfc_set_portid,
6077                 NULL,
6078         },
6079 };
6080
6081 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6082         .f = cmd_link_flow_ctrl_set_parsed,
6083         .data = (void *)&cmd_link_flow_control_set_hw,
6084         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6085                 "Change high water flow control parameter",
6086         .tokens = {
6087                 (void *)&cmd_lfc_set_set,
6088                 (void *)&cmd_lfc_set_flow_ctrl,
6089                 (void *)&cmd_lfc_set_high_water_str,
6090                 (void *)&cmd_lfc_set_high_water,
6091                 (void *)&cmd_lfc_set_portid,
6092                 NULL,
6093         },
6094 };
6095
6096 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6097         .f = cmd_link_flow_ctrl_set_parsed,
6098         .data = (void *)&cmd_link_flow_control_set_lw,
6099         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6100                 "Change low water flow control parameter",
6101         .tokens = {
6102                 (void *)&cmd_lfc_set_set,
6103                 (void *)&cmd_lfc_set_flow_ctrl,
6104                 (void *)&cmd_lfc_set_low_water_str,
6105                 (void *)&cmd_lfc_set_low_water,
6106                 (void *)&cmd_lfc_set_portid,
6107                 NULL,
6108         },
6109 };
6110
6111 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6112         .f = cmd_link_flow_ctrl_set_parsed,
6113         .data = (void *)&cmd_link_flow_control_set_pt,
6114         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6115                 "Change pause time flow control parameter",
6116         .tokens = {
6117                 (void *)&cmd_lfc_set_set,
6118                 (void *)&cmd_lfc_set_flow_ctrl,
6119                 (void *)&cmd_lfc_set_pause_time_str,
6120                 (void *)&cmd_lfc_set_pause_time,
6121                 (void *)&cmd_lfc_set_portid,
6122                 NULL,
6123         },
6124 };
6125
6126 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6127         .f = cmd_link_flow_ctrl_set_parsed,
6128         .data = (void *)&cmd_link_flow_control_set_xon,
6129         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6130                 "Change send_xon flow control parameter",
6131         .tokens = {
6132                 (void *)&cmd_lfc_set_set,
6133                 (void *)&cmd_lfc_set_flow_ctrl,
6134                 (void *)&cmd_lfc_set_send_xon_str,
6135                 (void *)&cmd_lfc_set_send_xon,
6136                 (void *)&cmd_lfc_set_portid,
6137                 NULL,
6138         },
6139 };
6140
6141 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6142         .f = cmd_link_flow_ctrl_set_parsed,
6143         .data = (void *)&cmd_link_flow_control_set_macfwd,
6144         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6145                 "Change mac ctrl fwd flow control parameter",
6146         .tokens = {
6147                 (void *)&cmd_lfc_set_set,
6148                 (void *)&cmd_lfc_set_flow_ctrl,
6149                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6150                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6151                 (void *)&cmd_lfc_set_portid,
6152                 NULL,
6153         },
6154 };
6155
6156 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6157         .f = cmd_link_flow_ctrl_set_parsed,
6158         .data = (void *)&cmd_link_flow_control_set_autoneg,
6159         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6160                 "Change autoneg flow control parameter",
6161         .tokens = {
6162                 (void *)&cmd_lfc_set_set,
6163                 (void *)&cmd_lfc_set_flow_ctrl,
6164                 (void *)&cmd_lfc_set_autoneg_str,
6165                 (void *)&cmd_lfc_set_autoneg,
6166                 (void *)&cmd_lfc_set_portid,
6167                 NULL,
6168         },
6169 };
6170
6171 static void
6172 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6173                               __attribute__((unused)) struct cmdline *cl,
6174                               void *data)
6175 {
6176         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6177         cmdline_parse_inst_t *cmd = data;
6178         struct rte_eth_fc_conf fc_conf;
6179         int rx_fc_en = 0;
6180         int tx_fc_en = 0;
6181         int ret;
6182
6183         /*
6184          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6185          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6186          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6187          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6188          */
6189         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6190                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6191         };
6192
6193         /* Partial command line, retrieve current configuration */
6194         if (cmd) {
6195                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6196                 if (ret != 0) {
6197                         printf("cannot get current flow ctrl parameters, return"
6198                                "code = %d\n", ret);
6199                         return;
6200                 }
6201
6202                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6203                     (fc_conf.mode == RTE_FC_FULL))
6204                         rx_fc_en = 1;
6205                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6206                     (fc_conf.mode == RTE_FC_FULL))
6207                         tx_fc_en = 1;
6208         }
6209
6210         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6211                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6212
6213         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6214                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6215
6216         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6217
6218         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6219                 fc_conf.high_water = res->high_water;
6220
6221         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6222                 fc_conf.low_water = res->low_water;
6223
6224         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6225                 fc_conf.pause_time = res->pause_time;
6226
6227         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6228                 fc_conf.send_xon = res->send_xon;
6229
6230         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6231                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6232                         fc_conf.mac_ctrl_frame_fwd = 1;
6233                 else
6234                         fc_conf.mac_ctrl_frame_fwd = 0;
6235         }
6236
6237         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6238                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6239
6240         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6241         if (ret != 0)
6242                 printf("bad flow contrl parameter, return code = %d \n", ret);
6243 }
6244
6245 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6246 struct cmd_priority_flow_ctrl_set_result {
6247         cmdline_fixed_string_t set;
6248         cmdline_fixed_string_t pfc_ctrl;
6249         cmdline_fixed_string_t rx;
6250         cmdline_fixed_string_t rx_pfc_mode;
6251         cmdline_fixed_string_t tx;
6252         cmdline_fixed_string_t tx_pfc_mode;
6253         uint32_t high_water;
6254         uint32_t low_water;
6255         uint16_t pause_time;
6256         uint8_t  priority;
6257         portid_t port_id;
6258 };
6259
6260 static void
6261 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6262                        __attribute__((unused)) struct cmdline *cl,
6263                        __attribute__((unused)) void *data)
6264 {
6265         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6266         struct rte_eth_pfc_conf pfc_conf;
6267         int rx_fc_enable, tx_fc_enable;
6268         int ret;
6269
6270         /*
6271          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6272          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6273          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6274          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6275          */
6276         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6277                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6278         };
6279
6280         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6281         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6282         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6283         pfc_conf.fc.high_water = res->high_water;
6284         pfc_conf.fc.low_water  = res->low_water;
6285         pfc_conf.fc.pause_time = res->pause_time;
6286         pfc_conf.priority      = res->priority;
6287
6288         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6289         if (ret != 0)
6290                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6291 }
6292
6293 cmdline_parse_token_string_t cmd_pfc_set_set =
6294         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6295                                 set, "set");
6296 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6297         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6298                                 pfc_ctrl, "pfc_ctrl");
6299 cmdline_parse_token_string_t cmd_pfc_set_rx =
6300         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6301                                 rx, "rx");
6302 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6303         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6304                                 rx_pfc_mode, "on#off");
6305 cmdline_parse_token_string_t cmd_pfc_set_tx =
6306         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6307                                 tx, "tx");
6308 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6309         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6310                                 tx_pfc_mode, "on#off");
6311 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6312         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6313                                 high_water, UINT32);
6314 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6315         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6316                                 low_water, UINT32);
6317 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6318         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6319                                 pause_time, UINT16);
6320 cmdline_parse_token_num_t cmd_pfc_set_priority =
6321         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6322                                 priority, UINT8);
6323 cmdline_parse_token_num_t cmd_pfc_set_portid =
6324         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6325                                 port_id, UINT16);
6326
6327 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6328         .f = cmd_priority_flow_ctrl_set_parsed,
6329         .data = NULL,
6330         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6331                 "<pause_time> <priority> <port_id>: "
6332                 "Configure the Ethernet priority flow control",
6333         .tokens = {
6334                 (void *)&cmd_pfc_set_set,
6335                 (void *)&cmd_pfc_set_flow_ctrl,
6336                 (void *)&cmd_pfc_set_rx,
6337                 (void *)&cmd_pfc_set_rx_mode,
6338                 (void *)&cmd_pfc_set_tx,
6339                 (void *)&cmd_pfc_set_tx_mode,
6340                 (void *)&cmd_pfc_set_high_water,
6341                 (void *)&cmd_pfc_set_low_water,
6342                 (void *)&cmd_pfc_set_pause_time,
6343                 (void *)&cmd_pfc_set_priority,
6344                 (void *)&cmd_pfc_set_portid,
6345                 NULL,
6346         },
6347 };
6348
6349 /* *** RESET CONFIGURATION *** */
6350 struct cmd_reset_result {
6351         cmdline_fixed_string_t reset;
6352         cmdline_fixed_string_t def;
6353 };
6354
6355 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6356                              struct cmdline *cl,
6357                              __attribute__((unused)) void *data)
6358 {
6359         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6360         set_def_fwd_config();
6361 }
6362
6363 cmdline_parse_token_string_t cmd_reset_set =
6364         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6365 cmdline_parse_token_string_t cmd_reset_def =
6366         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6367                                  "default");
6368
6369 cmdline_parse_inst_t cmd_reset = {
6370         .f = cmd_reset_parsed,
6371         .data = NULL,
6372         .help_str = "set default: Reset default forwarding configuration",
6373         .tokens = {
6374                 (void *)&cmd_reset_set,
6375                 (void *)&cmd_reset_def,
6376                 NULL,
6377         },
6378 };
6379
6380 /* *** START FORWARDING *** */
6381 struct cmd_start_result {
6382         cmdline_fixed_string_t start;
6383 };
6384
6385 cmdline_parse_token_string_t cmd_start_start =
6386         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6387
6388 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6389                              __attribute__((unused)) struct cmdline *cl,
6390                              __attribute__((unused)) void *data)
6391 {
6392         start_packet_forwarding(0);
6393 }
6394
6395 cmdline_parse_inst_t cmd_start = {
6396         .f = cmd_start_parsed,
6397         .data = NULL,
6398         .help_str = "start: Start packet forwarding",
6399         .tokens = {
6400                 (void *)&cmd_start_start,
6401                 NULL,
6402         },
6403 };
6404
6405 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6406 struct cmd_start_tx_first_result {
6407         cmdline_fixed_string_t start;
6408         cmdline_fixed_string_t tx_first;
6409 };
6410
6411 static void
6412 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6413                           __attribute__((unused)) struct cmdline *cl,
6414                           __attribute__((unused)) void *data)
6415 {
6416         start_packet_forwarding(1);
6417 }
6418
6419 cmdline_parse_token_string_t cmd_start_tx_first_start =
6420         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6421                                  "start");
6422 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6423         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6424                                  tx_first, "tx_first");
6425
6426 cmdline_parse_inst_t cmd_start_tx_first = {
6427         .f = cmd_start_tx_first_parsed,
6428         .data = NULL,
6429         .help_str = "start tx_first: Start packet forwarding, "
6430                 "after sending 1 burst of packets",
6431         .tokens = {
6432                 (void *)&cmd_start_tx_first_start,
6433                 (void *)&cmd_start_tx_first_tx_first,
6434                 NULL,
6435         },
6436 };
6437
6438 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6439 struct cmd_start_tx_first_n_result {
6440         cmdline_fixed_string_t start;
6441         cmdline_fixed_string_t tx_first;
6442         uint32_t tx_num;
6443 };
6444
6445 static void
6446 cmd_start_tx_first_n_parsed(void *parsed_result,
6447                           __attribute__((unused)) struct cmdline *cl,
6448                           __attribute__((unused)) void *data)
6449 {
6450         struct cmd_start_tx_first_n_result *res = parsed_result;
6451
6452         start_packet_forwarding(res->tx_num);
6453 }
6454
6455 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6456         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6457                         start, "start");
6458 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6459         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6460                         tx_first, "tx_first");
6461 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6462         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6463                         tx_num, UINT32);
6464
6465 cmdline_parse_inst_t cmd_start_tx_first_n = {
6466         .f = cmd_start_tx_first_n_parsed,
6467         .data = NULL,
6468         .help_str = "start tx_first <num>: "
6469                 "packet forwarding, after sending <num> bursts of packets",
6470         .tokens = {
6471                 (void *)&cmd_start_tx_first_n_start,
6472                 (void *)&cmd_start_tx_first_n_tx_first,
6473                 (void *)&cmd_start_tx_first_n_tx_num,
6474                 NULL,
6475         },
6476 };
6477
6478 /* *** SET LINK UP *** */
6479 struct cmd_set_link_up_result {
6480         cmdline_fixed_string_t set;
6481         cmdline_fixed_string_t link_up;
6482         cmdline_fixed_string_t port;
6483         portid_t port_id;
6484 };
6485
6486 cmdline_parse_token_string_t cmd_set_link_up_set =
6487         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6488 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6489         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6490                                 "link-up");
6491 cmdline_parse_token_string_t cmd_set_link_up_port =
6492         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6493 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6494         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6495
6496 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6497                              __attribute__((unused)) struct cmdline *cl,
6498                              __attribute__((unused)) void *data)
6499 {
6500         struct cmd_set_link_up_result *res = parsed_result;
6501         dev_set_link_up(res->port_id);
6502 }
6503
6504 cmdline_parse_inst_t cmd_set_link_up = {
6505         .f = cmd_set_link_up_parsed,
6506         .data = NULL,
6507         .help_str = "set link-up port <port id>",
6508         .tokens = {
6509                 (void *)&cmd_set_link_up_set,
6510                 (void *)&cmd_set_link_up_link_up,
6511                 (void *)&cmd_set_link_up_port,
6512                 (void *)&cmd_set_link_up_port_id,
6513                 NULL,
6514         },
6515 };
6516
6517 /* *** SET LINK DOWN *** */
6518 struct cmd_set_link_down_result {
6519         cmdline_fixed_string_t set;
6520         cmdline_fixed_string_t link_down;
6521         cmdline_fixed_string_t port;
6522         portid_t port_id;
6523 };
6524
6525 cmdline_parse_token_string_t cmd_set_link_down_set =
6526         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6527 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6528         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6529                                 "link-down");
6530 cmdline_parse_token_string_t cmd_set_link_down_port =
6531         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6532 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6533         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6534
6535 static void cmd_set_link_down_parsed(
6536                                 __attribute__((unused)) void *parsed_result,
6537                                 __attribute__((unused)) struct cmdline *cl,
6538                                 __attribute__((unused)) void *data)
6539 {
6540         struct cmd_set_link_down_result *res = parsed_result;
6541         dev_set_link_down(res->port_id);
6542 }
6543
6544 cmdline_parse_inst_t cmd_set_link_down = {
6545         .f = cmd_set_link_down_parsed,
6546         .data = NULL,
6547         .help_str = "set link-down port <port id>",
6548         .tokens = {
6549                 (void *)&cmd_set_link_down_set,
6550                 (void *)&cmd_set_link_down_link_down,
6551                 (void *)&cmd_set_link_down_port,
6552                 (void *)&cmd_set_link_down_port_id,
6553                 NULL,
6554         },
6555 };
6556
6557 /* *** SHOW CFG *** */
6558 struct cmd_showcfg_result {
6559         cmdline_fixed_string_t show;
6560         cmdline_fixed_string_t cfg;
6561         cmdline_fixed_string_t what;
6562 };
6563
6564 static void cmd_showcfg_parsed(void *parsed_result,
6565                                __attribute__((unused)) struct cmdline *cl,
6566                                __attribute__((unused)) void *data)
6567 {
6568         struct cmd_showcfg_result *res = parsed_result;
6569         if (!strcmp(res->what, "rxtx"))
6570                 rxtx_config_display();
6571         else if (!strcmp(res->what, "cores"))
6572                 fwd_lcores_config_display();
6573         else if (!strcmp(res->what, "fwd"))
6574                 pkt_fwd_config_display(&cur_fwd_config);
6575         else if (!strcmp(res->what, "txpkts"))
6576                 show_tx_pkt_segments();
6577 }
6578
6579 cmdline_parse_token_string_t cmd_showcfg_show =
6580         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6581 cmdline_parse_token_string_t cmd_showcfg_port =
6582         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6583 cmdline_parse_token_string_t cmd_showcfg_what =
6584         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6585                                  "rxtx#cores#fwd#txpkts");
6586
6587 cmdline_parse_inst_t cmd_showcfg = {
6588         .f = cmd_showcfg_parsed,
6589         .data = NULL,
6590         .help_str = "show config rxtx|cores|fwd|txpkts",
6591         .tokens = {
6592                 (void *)&cmd_showcfg_show,
6593                 (void *)&cmd_showcfg_port,
6594                 (void *)&cmd_showcfg_what,
6595                 NULL,
6596         },
6597 };
6598
6599 /* *** SHOW ALL PORT INFO *** */
6600 struct cmd_showportall_result {
6601         cmdline_fixed_string_t show;
6602         cmdline_fixed_string_t port;
6603         cmdline_fixed_string_t what;
6604         cmdline_fixed_string_t all;
6605 };
6606
6607 static void cmd_showportall_parsed(void *parsed_result,
6608                                 __attribute__((unused)) struct cmdline *cl,
6609                                 __attribute__((unused)) void *data)
6610 {
6611         portid_t i;
6612
6613         struct cmd_showportall_result *res = parsed_result;
6614         if (!strcmp(res->show, "clear")) {
6615                 if (!strcmp(res->what, "stats"))
6616                         RTE_ETH_FOREACH_DEV(i)
6617                                 nic_stats_clear(i);
6618                 else if (!strcmp(res->what, "xstats"))
6619                         RTE_ETH_FOREACH_DEV(i)
6620                                 nic_xstats_clear(i);
6621         } else if (!strcmp(res->what, "info"))
6622                 RTE_ETH_FOREACH_DEV(i)
6623                         port_infos_display(i);
6624         else if (!strcmp(res->what, "stats"))
6625                 RTE_ETH_FOREACH_DEV(i)
6626                         nic_stats_display(i);
6627         else if (!strcmp(res->what, "xstats"))
6628                 RTE_ETH_FOREACH_DEV(i)
6629                         nic_xstats_display(i);
6630         else if (!strcmp(res->what, "fdir"))
6631                 RTE_ETH_FOREACH_DEV(i)
6632                         fdir_get_infos(i);
6633         else if (!strcmp(res->what, "stat_qmap"))
6634                 RTE_ETH_FOREACH_DEV(i)
6635                         nic_stats_mapping_display(i);
6636         else if (!strcmp(res->what, "dcb_tc"))
6637                 RTE_ETH_FOREACH_DEV(i)
6638                         port_dcb_info_display(i);
6639         else if (!strcmp(res->what, "cap"))
6640                 RTE_ETH_FOREACH_DEV(i)
6641                         port_offload_cap_display(i);
6642 }
6643
6644 cmdline_parse_token_string_t cmd_showportall_show =
6645         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6646                                  "show#clear");
6647 cmdline_parse_token_string_t cmd_showportall_port =
6648         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6649 cmdline_parse_token_string_t cmd_showportall_what =
6650         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6651                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6652 cmdline_parse_token_string_t cmd_showportall_all =
6653         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6654 cmdline_parse_inst_t cmd_showportall = {
6655         .f = cmd_showportall_parsed,
6656         .data = NULL,
6657         .help_str = "show|clear port "
6658                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6659         .tokens = {
6660                 (void *)&cmd_showportall_show,
6661                 (void *)&cmd_showportall_port,
6662                 (void *)&cmd_showportall_what,
6663                 (void *)&cmd_showportall_all,
6664                 NULL,
6665         },
6666 };
6667
6668 /* *** SHOW PORT INFO *** */
6669 struct cmd_showport_result {
6670         cmdline_fixed_string_t show;
6671         cmdline_fixed_string_t port;
6672         cmdline_fixed_string_t what;
6673         uint16_t portnum;
6674 };
6675
6676 static void cmd_showport_parsed(void *parsed_result,
6677                                 __attribute__((unused)) struct cmdline *cl,
6678                                 __attribute__((unused)) void *data)
6679 {
6680         struct cmd_showport_result *res = parsed_result;
6681         if (!strcmp(res->show, "clear")) {
6682                 if (!strcmp(res->what, "stats"))
6683                         nic_stats_clear(res->portnum);
6684                 else if (!strcmp(res->what, "xstats"))
6685                         nic_xstats_clear(res->portnum);
6686         } else if (!strcmp(res->what, "info"))
6687                 port_infos_display(res->portnum);
6688         else if (!strcmp(res->what, "stats"))
6689                 nic_stats_display(res->portnum);
6690         else if (!strcmp(res->what, "xstats"))
6691                 nic_xstats_display(res->portnum);
6692         else if (!strcmp(res->what, "fdir"))
6693                  fdir_get_infos(res->portnum);
6694         else if (!strcmp(res->what, "stat_qmap"))
6695                 nic_stats_mapping_display(res->portnum);
6696         else if (!strcmp(res->what, "dcb_tc"))
6697                 port_dcb_info_display(res->portnum);
6698         else if (!strcmp(res->what, "cap"))
6699                 port_offload_cap_display(res->portnum);
6700 }
6701
6702 cmdline_parse_token_string_t cmd_showport_show =
6703         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6704                                  "show#clear");
6705 cmdline_parse_token_string_t cmd_showport_port =
6706         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6707 cmdline_parse_token_string_t cmd_showport_what =
6708         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6709                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6710 cmdline_parse_token_num_t cmd_showport_portnum =
6711         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6712
6713 cmdline_parse_inst_t cmd_showport = {
6714         .f = cmd_showport_parsed,
6715         .data = NULL,
6716         .help_str = "show|clear port "
6717                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6718                 "<port_id>",
6719         .tokens = {
6720                 (void *)&cmd_showport_show,
6721                 (void *)&cmd_showport_port,
6722                 (void *)&cmd_showport_what,
6723                 (void *)&cmd_showport_portnum,
6724                 NULL,
6725         },
6726 };
6727
6728 /* *** SHOW QUEUE INFO *** */
6729 struct cmd_showqueue_result {
6730         cmdline_fixed_string_t show;
6731         cmdline_fixed_string_t type;
6732         cmdline_fixed_string_t what;
6733         uint16_t portnum;
6734         uint16_t queuenum;
6735 };
6736
6737 static void
6738 cmd_showqueue_parsed(void *parsed_result,
6739         __attribute__((unused)) struct cmdline *cl,
6740         __attribute__((unused)) void *data)
6741 {
6742         struct cmd_showqueue_result *res = parsed_result;
6743
6744         if (!strcmp(res->type, "rxq"))
6745                 rx_queue_infos_display(res->portnum, res->queuenum);
6746         else if (!strcmp(res->type, "txq"))
6747                 tx_queue_infos_display(res->portnum, res->queuenum);
6748 }
6749
6750 cmdline_parse_token_string_t cmd_showqueue_show =
6751         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6752 cmdline_parse_token_string_t cmd_showqueue_type =
6753         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6754 cmdline_parse_token_string_t cmd_showqueue_what =
6755         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6756 cmdline_parse_token_num_t cmd_showqueue_portnum =
6757         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6758 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6759         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6760
6761 cmdline_parse_inst_t cmd_showqueue = {
6762         .f = cmd_showqueue_parsed,
6763         .data = NULL,
6764         .help_str = "show rxq|txq info <port_id> <queue_id>",
6765         .tokens = {
6766                 (void *)&cmd_showqueue_show,
6767                 (void *)&cmd_showqueue_type,
6768                 (void *)&cmd_showqueue_what,
6769                 (void *)&cmd_showqueue_portnum,
6770                 (void *)&cmd_showqueue_queuenum,
6771                 NULL,
6772         },
6773 };
6774
6775 /* *** READ PORT REGISTER *** */
6776 struct cmd_read_reg_result {
6777         cmdline_fixed_string_t read;
6778         cmdline_fixed_string_t reg;
6779         portid_t port_id;
6780         uint32_t reg_off;
6781 };
6782
6783 static void
6784 cmd_read_reg_parsed(void *parsed_result,
6785                     __attribute__((unused)) struct cmdline *cl,
6786                     __attribute__((unused)) void *data)
6787 {
6788         struct cmd_read_reg_result *res = parsed_result;
6789         port_reg_display(res->port_id, res->reg_off);
6790 }
6791
6792 cmdline_parse_token_string_t cmd_read_reg_read =
6793         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6794 cmdline_parse_token_string_t cmd_read_reg_reg =
6795         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6796 cmdline_parse_token_num_t cmd_read_reg_port_id =
6797         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6798 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6799         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6800
6801 cmdline_parse_inst_t cmd_read_reg = {
6802         .f = cmd_read_reg_parsed,
6803         .data = NULL,
6804         .help_str = "read reg <port_id> <reg_off>",
6805         .tokens = {
6806                 (void *)&cmd_read_reg_read,
6807                 (void *)&cmd_read_reg_reg,
6808                 (void *)&cmd_read_reg_port_id,
6809                 (void *)&cmd_read_reg_reg_off,
6810                 NULL,
6811         },
6812 };
6813
6814 /* *** READ PORT REGISTER BIT FIELD *** */
6815 struct cmd_read_reg_bit_field_result {
6816         cmdline_fixed_string_t read;
6817         cmdline_fixed_string_t regfield;
6818         portid_t port_id;
6819         uint32_t reg_off;
6820         uint8_t bit1_pos;
6821         uint8_t bit2_pos;
6822 };
6823
6824 static void
6825 cmd_read_reg_bit_field_parsed(void *parsed_result,
6826                               __attribute__((unused)) struct cmdline *cl,
6827                               __attribute__((unused)) void *data)
6828 {
6829         struct cmd_read_reg_bit_field_result *res = parsed_result;
6830         port_reg_bit_field_display(res->port_id, res->reg_off,
6831                                    res->bit1_pos, res->bit2_pos);
6832 }
6833
6834 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6835         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6836                                  "read");
6837 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6838         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6839                                  regfield, "regfield");
6840 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6841         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6842                               UINT16);
6843 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6844         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6845                               UINT32);
6846 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6847         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6848                               UINT8);
6849 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6850         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6851                               UINT8);
6852
6853 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6854         .f = cmd_read_reg_bit_field_parsed,
6855         .data = NULL,
6856         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6857         "Read register bit field between bit_x and bit_y included",
6858         .tokens = {
6859                 (void *)&cmd_read_reg_bit_field_read,
6860                 (void *)&cmd_read_reg_bit_field_regfield,
6861                 (void *)&cmd_read_reg_bit_field_port_id,
6862                 (void *)&cmd_read_reg_bit_field_reg_off,
6863                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6864                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6865                 NULL,
6866         },
6867 };
6868
6869 /* *** READ PORT REGISTER BIT *** */
6870 struct cmd_read_reg_bit_result {
6871         cmdline_fixed_string_t read;
6872         cmdline_fixed_string_t regbit;
6873         portid_t port_id;
6874         uint32_t reg_off;
6875         uint8_t bit_pos;
6876 };
6877
6878 static void
6879 cmd_read_reg_bit_parsed(void *parsed_result,
6880                         __attribute__((unused)) struct cmdline *cl,
6881                         __attribute__((unused)) void *data)
6882 {
6883         struct cmd_read_reg_bit_result *res = parsed_result;
6884         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6885 }
6886
6887 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6888         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6889 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6890         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6891                                  regbit, "regbit");
6892 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6893         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6894 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6895         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6896 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6897         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6898
6899 cmdline_parse_inst_t cmd_read_reg_bit = {
6900         .f = cmd_read_reg_bit_parsed,
6901         .data = NULL,
6902         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6903         .tokens = {
6904                 (void *)&cmd_read_reg_bit_read,
6905                 (void *)&cmd_read_reg_bit_regbit,
6906                 (void *)&cmd_read_reg_bit_port_id,
6907                 (void *)&cmd_read_reg_bit_reg_off,
6908                 (void *)&cmd_read_reg_bit_bit_pos,
6909                 NULL,
6910         },
6911 };
6912
6913 /* *** WRITE PORT REGISTER *** */
6914 struct cmd_write_reg_result {
6915         cmdline_fixed_string_t write;
6916         cmdline_fixed_string_t reg;
6917         portid_t port_id;
6918         uint32_t reg_off;
6919         uint32_t value;
6920 };
6921
6922 static void
6923 cmd_write_reg_parsed(void *parsed_result,
6924                      __attribute__((unused)) struct cmdline *cl,
6925                      __attribute__((unused)) void *data)
6926 {
6927         struct cmd_write_reg_result *res = parsed_result;
6928         port_reg_set(res->port_id, res->reg_off, res->value);
6929 }
6930
6931 cmdline_parse_token_string_t cmd_write_reg_write =
6932         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6933 cmdline_parse_token_string_t cmd_write_reg_reg =
6934         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6935 cmdline_parse_token_num_t cmd_write_reg_port_id =
6936         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6937 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6938         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6939 cmdline_parse_token_num_t cmd_write_reg_value =
6940         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6941
6942 cmdline_parse_inst_t cmd_write_reg = {
6943         .f = cmd_write_reg_parsed,
6944         .data = NULL,
6945         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6946         .tokens = {
6947                 (void *)&cmd_write_reg_write,
6948                 (void *)&cmd_write_reg_reg,
6949                 (void *)&cmd_write_reg_port_id,
6950                 (void *)&cmd_write_reg_reg_off,
6951                 (void *)&cmd_write_reg_value,
6952                 NULL,
6953         },
6954 };
6955
6956 /* *** WRITE PORT REGISTER BIT FIELD *** */
6957 struct cmd_write_reg_bit_field_result {
6958         cmdline_fixed_string_t write;
6959         cmdline_fixed_string_t regfield;
6960         portid_t port_id;
6961         uint32_t reg_off;
6962         uint8_t bit1_pos;
6963         uint8_t bit2_pos;
6964         uint32_t value;
6965 };
6966
6967 static void
6968 cmd_write_reg_bit_field_parsed(void *parsed_result,
6969                                __attribute__((unused)) struct cmdline *cl,
6970                                __attribute__((unused)) void *data)
6971 {
6972         struct cmd_write_reg_bit_field_result *res = parsed_result;
6973         port_reg_bit_field_set(res->port_id, res->reg_off,
6974                           res->bit1_pos, res->bit2_pos, res->value);
6975 }
6976
6977 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6978         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6979                                  "write");
6980 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6981         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6982                                  regfield, "regfield");
6983 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6985                               UINT16);
6986 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6987         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6988                               UINT32);
6989 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6990         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6991                               UINT8);
6992 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6993         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6994                               UINT8);
6995 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6996         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6997                               UINT32);
6998
6999 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7000         .f = cmd_write_reg_bit_field_parsed,
7001         .data = NULL,
7002         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7003                 "<reg_value>: "
7004                 "Set register bit field between bit_x and bit_y included",
7005         .tokens = {
7006                 (void *)&cmd_write_reg_bit_field_write,
7007                 (void *)&cmd_write_reg_bit_field_regfield,
7008                 (void *)&cmd_write_reg_bit_field_port_id,
7009                 (void *)&cmd_write_reg_bit_field_reg_off,
7010                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7011                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7012                 (void *)&cmd_write_reg_bit_field_value,
7013                 NULL,
7014         },
7015 };
7016
7017 /* *** WRITE PORT REGISTER BIT *** */
7018 struct cmd_write_reg_bit_result {
7019         cmdline_fixed_string_t write;
7020         cmdline_fixed_string_t regbit;
7021         portid_t port_id;
7022         uint32_t reg_off;
7023         uint8_t bit_pos;
7024         uint8_t value;
7025 };
7026
7027 static void
7028 cmd_write_reg_bit_parsed(void *parsed_result,
7029                          __attribute__((unused)) struct cmdline *cl,
7030                          __attribute__((unused)) void *data)
7031 {
7032         struct cmd_write_reg_bit_result *res = parsed_result;
7033         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7034 }
7035
7036 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7037         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7038                                  "write");
7039 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7040         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7041                                  regbit, "regbit");
7042 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7043         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7044 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7045         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7046 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7047         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7048 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7049         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7050
7051 cmdline_parse_inst_t cmd_write_reg_bit = {
7052         .f = cmd_write_reg_bit_parsed,
7053         .data = NULL,
7054         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7055                 "0 <= bit_x <= 31",
7056         .tokens = {
7057                 (void *)&cmd_write_reg_bit_write,
7058                 (void *)&cmd_write_reg_bit_regbit,
7059                 (void *)&cmd_write_reg_bit_port_id,
7060                 (void *)&cmd_write_reg_bit_reg_off,
7061                 (void *)&cmd_write_reg_bit_bit_pos,
7062                 (void *)&cmd_write_reg_bit_value,
7063                 NULL,
7064         },
7065 };
7066
7067 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7068 struct cmd_read_rxd_txd_result {
7069         cmdline_fixed_string_t read;
7070         cmdline_fixed_string_t rxd_txd;
7071         portid_t port_id;
7072         uint16_t queue_id;
7073         uint16_t desc_id;
7074 };
7075
7076 static void
7077 cmd_read_rxd_txd_parsed(void *parsed_result,
7078                         __attribute__((unused)) struct cmdline *cl,
7079                         __attribute__((unused)) void *data)
7080 {
7081         struct cmd_read_rxd_txd_result *res = parsed_result;
7082
7083         if (!strcmp(res->rxd_txd, "rxd"))
7084                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7085         else if (!strcmp(res->rxd_txd, "txd"))
7086                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7087 }
7088
7089 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7090         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7091 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7092         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7093                                  "rxd#txd");
7094 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7095         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7096 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7097         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7098 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7099         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7100
7101 cmdline_parse_inst_t cmd_read_rxd_txd = {
7102         .f = cmd_read_rxd_txd_parsed,
7103         .data = NULL,
7104         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7105         .tokens = {
7106                 (void *)&cmd_read_rxd_txd_read,
7107                 (void *)&cmd_read_rxd_txd_rxd_txd,
7108                 (void *)&cmd_read_rxd_txd_port_id,
7109                 (void *)&cmd_read_rxd_txd_queue_id,
7110                 (void *)&cmd_read_rxd_txd_desc_id,
7111                 NULL,
7112         },
7113 };
7114
7115 /* *** QUIT *** */
7116 struct cmd_quit_result {
7117         cmdline_fixed_string_t quit;
7118 };
7119
7120 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7121                             struct cmdline *cl,
7122                             __attribute__((unused)) void *data)
7123 {
7124         pmd_test_exit();
7125         cmdline_quit(cl);
7126 }
7127
7128 cmdline_parse_token_string_t cmd_quit_quit =
7129         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7130
7131 cmdline_parse_inst_t cmd_quit = {
7132         .f = cmd_quit_parsed,
7133         .data = NULL,
7134         .help_str = "quit: Exit application",
7135         .tokens = {
7136                 (void *)&cmd_quit_quit,
7137                 NULL,
7138         },
7139 };
7140
7141 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7142 struct cmd_mac_addr_result {
7143         cmdline_fixed_string_t mac_addr_cmd;
7144         cmdline_fixed_string_t what;
7145         uint16_t port_num;
7146         struct ether_addr address;
7147 };
7148
7149 static void cmd_mac_addr_parsed(void *parsed_result,
7150                 __attribute__((unused)) struct cmdline *cl,
7151                 __attribute__((unused)) void *data)
7152 {
7153         struct cmd_mac_addr_result *res = parsed_result;
7154         int ret;
7155
7156         if (strcmp(res->what, "add") == 0)
7157                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7158         else if (strcmp(res->what, "set") == 0)
7159                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7160                                                        &res->address);
7161         else
7162                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7163
7164         /* check the return value and print it if is < 0 */
7165         if(ret < 0)
7166                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7167
7168 }
7169
7170 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7171         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7172                                 "mac_addr");
7173 cmdline_parse_token_string_t cmd_mac_addr_what =
7174         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7175                                 "add#remove#set");
7176 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7177                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7178                                         UINT16);
7179 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7180                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7181
7182 cmdline_parse_inst_t cmd_mac_addr = {
7183         .f = cmd_mac_addr_parsed,
7184         .data = (void *)0,
7185         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7186                         "Add/Remove/Set MAC address on port_id",
7187         .tokens = {
7188                 (void *)&cmd_mac_addr_cmd,
7189                 (void *)&cmd_mac_addr_what,
7190                 (void *)&cmd_mac_addr_portnum,
7191                 (void *)&cmd_mac_addr_addr,
7192                 NULL,
7193         },
7194 };
7195
7196 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7197 struct cmd_eth_peer_result {
7198         cmdline_fixed_string_t set;
7199         cmdline_fixed_string_t eth_peer;
7200         portid_t port_id;
7201         cmdline_fixed_string_t peer_addr;
7202 };
7203
7204 static void cmd_set_eth_peer_parsed(void *parsed_result,
7205                         __attribute__((unused)) struct cmdline *cl,
7206                         __attribute__((unused)) void *data)
7207 {
7208                 struct cmd_eth_peer_result *res = parsed_result;
7209
7210                 if (test_done == 0) {
7211                         printf("Please stop forwarding first\n");
7212                         return;
7213                 }
7214                 if (!strcmp(res->eth_peer, "eth-peer")) {
7215                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7216                         fwd_config_setup();
7217                 }
7218 }
7219 cmdline_parse_token_string_t cmd_eth_peer_set =
7220         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7221 cmdline_parse_token_string_t cmd_eth_peer =
7222         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7223 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7224         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7225 cmdline_parse_token_string_t cmd_eth_peer_addr =
7226         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7227
7228 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7229         .f = cmd_set_eth_peer_parsed,
7230         .data = NULL,
7231         .help_str = "set eth-peer <port_id> <peer_mac>",
7232         .tokens = {
7233                 (void *)&cmd_eth_peer_set,
7234                 (void *)&cmd_eth_peer,
7235                 (void *)&cmd_eth_peer_port_id,
7236                 (void *)&cmd_eth_peer_addr,
7237                 NULL,
7238         },
7239 };
7240
7241 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7242 struct cmd_set_qmap_result {
7243         cmdline_fixed_string_t set;
7244         cmdline_fixed_string_t qmap;
7245         cmdline_fixed_string_t what;
7246         portid_t port_id;
7247         uint16_t queue_id;
7248         uint8_t map_value;
7249 };
7250
7251 static void
7252 cmd_set_qmap_parsed(void *parsed_result,
7253                        __attribute__((unused)) struct cmdline *cl,
7254                        __attribute__((unused)) void *data)
7255 {
7256         struct cmd_set_qmap_result *res = parsed_result;
7257         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7258
7259         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7260 }
7261
7262 cmdline_parse_token_string_t cmd_setqmap_set =
7263         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7264                                  set, "set");
7265 cmdline_parse_token_string_t cmd_setqmap_qmap =
7266         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7267                                  qmap, "stat_qmap");
7268 cmdline_parse_token_string_t cmd_setqmap_what =
7269         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7270                                  what, "tx#rx");
7271 cmdline_parse_token_num_t cmd_setqmap_portid =
7272         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7273                               port_id, UINT16);
7274 cmdline_parse_token_num_t cmd_setqmap_queueid =
7275         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7276                               queue_id, UINT16);
7277 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7278         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7279                               map_value, UINT8);
7280
7281 cmdline_parse_inst_t cmd_set_qmap = {
7282         .f = cmd_set_qmap_parsed,
7283         .data = NULL,
7284         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7285                 "Set statistics mapping value on tx|rx queue_id of port_id",
7286         .tokens = {
7287                 (void *)&cmd_setqmap_set,
7288                 (void *)&cmd_setqmap_qmap,
7289                 (void *)&cmd_setqmap_what,
7290                 (void *)&cmd_setqmap_portid,
7291                 (void *)&cmd_setqmap_queueid,
7292                 (void *)&cmd_setqmap_mapvalue,
7293                 NULL,
7294         },
7295 };
7296
7297 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7298 struct cmd_set_xstats_hide_zero_result {
7299         cmdline_fixed_string_t keyword;
7300         cmdline_fixed_string_t name;
7301         cmdline_fixed_string_t on_off;
7302 };
7303
7304 static void
7305 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7306                         __attribute__((unused)) struct cmdline *cl,
7307                         __attribute__((unused)) void *data)
7308 {
7309         struct cmd_set_xstats_hide_zero_result *res;
7310         uint16_t on_off = 0;
7311
7312         res = parsed_result;
7313         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7314         set_xstats_hide_zero(on_off);
7315 }
7316
7317 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7318         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7319                                  keyword, "set");
7320 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7321         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7322                                  name, "xstats-hide-zero");
7323 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7324         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7325                                  on_off, "on#off");
7326
7327 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7328         .f = cmd_set_xstats_hide_zero_parsed,
7329         .data = NULL,
7330         .help_str = "set xstats-hide-zero on|off",
7331         .tokens = {
7332                 (void *)&cmd_set_xstats_hide_zero_keyword,
7333                 (void *)&cmd_set_xstats_hide_zero_name,
7334                 (void *)&cmd_set_xstats_hide_zero_on_off,
7335                 NULL,
7336         },
7337 };
7338
7339 /* *** CONFIGURE UNICAST HASH TABLE *** */
7340 struct cmd_set_uc_hash_table {
7341         cmdline_fixed_string_t set;
7342         cmdline_fixed_string_t port;
7343         portid_t port_id;
7344         cmdline_fixed_string_t what;
7345         struct ether_addr address;
7346         cmdline_fixed_string_t mode;
7347 };
7348
7349 static void
7350 cmd_set_uc_hash_parsed(void *parsed_result,
7351                        __attribute__((unused)) struct cmdline *cl,
7352                        __attribute__((unused)) void *data)
7353 {
7354         int ret=0;
7355         struct cmd_set_uc_hash_table *res = parsed_result;
7356
7357         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7358
7359         if (strcmp(res->what, "uta") == 0)
7360                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7361                                                 &res->address,(uint8_t)is_on);
7362         if (ret < 0)
7363                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7364
7365 }
7366
7367 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7368         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7369                                  set, "set");
7370 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7371         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7372                                  port, "port");
7373 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7374         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7375                               port_id, UINT16);
7376 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7377         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7378                                  what, "uta");
7379 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7380         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7381                                 address);
7382 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7383         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7384                                  mode, "on#off");
7385
7386 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7387         .f = cmd_set_uc_hash_parsed,
7388         .data = NULL,
7389         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7390         .tokens = {
7391                 (void *)&cmd_set_uc_hash_set,
7392                 (void *)&cmd_set_uc_hash_port,
7393                 (void *)&cmd_set_uc_hash_portid,
7394                 (void *)&cmd_set_uc_hash_what,
7395                 (void *)&cmd_set_uc_hash_mac,
7396                 (void *)&cmd_set_uc_hash_mode,
7397                 NULL,
7398         },
7399 };
7400
7401 struct cmd_set_uc_all_hash_table {
7402         cmdline_fixed_string_t set;
7403         cmdline_fixed_string_t port;
7404         portid_t port_id;
7405         cmdline_fixed_string_t what;
7406         cmdline_fixed_string_t value;
7407         cmdline_fixed_string_t mode;
7408 };
7409
7410 static void
7411 cmd_set_uc_all_hash_parsed(void *parsed_result,
7412                        __attribute__((unused)) struct cmdline *cl,
7413                        __attribute__((unused)) void *data)
7414 {
7415         int ret=0;
7416         struct cmd_set_uc_all_hash_table *res = parsed_result;
7417
7418         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7419
7420         if ((strcmp(res->what, "uta") == 0) &&
7421                 (strcmp(res->value, "all") == 0))
7422                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7423         if (ret < 0)
7424                 printf("bad unicast hash table parameter,"
7425                         "return code = %d \n", ret);
7426 }
7427
7428 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7429         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7430                                  set, "set");
7431 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7432         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7433                                  port, "port");
7434 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7435         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7436                               port_id, UINT16);
7437 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7438         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7439                                  what, "uta");
7440 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7441         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7442                                 value,"all");
7443 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7444         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7445                                  mode, "on#off");
7446
7447 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7448         .f = cmd_set_uc_all_hash_parsed,
7449         .data = NULL,
7450         .help_str = "set port <port_id> uta all on|off",
7451         .tokens = {
7452                 (void *)&cmd_set_uc_all_hash_set,
7453                 (void *)&cmd_set_uc_all_hash_port,
7454                 (void *)&cmd_set_uc_all_hash_portid,
7455                 (void *)&cmd_set_uc_all_hash_what,
7456                 (void *)&cmd_set_uc_all_hash_value,
7457                 (void *)&cmd_set_uc_all_hash_mode,
7458                 NULL,
7459         },
7460 };
7461
7462 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7463 struct cmd_set_vf_macvlan_filter {
7464         cmdline_fixed_string_t set;
7465         cmdline_fixed_string_t port;
7466         portid_t port_id;
7467         cmdline_fixed_string_t vf;
7468         uint8_t vf_id;
7469         struct ether_addr address;
7470         cmdline_fixed_string_t filter_type;
7471         cmdline_fixed_string_t mode;
7472 };
7473
7474 static void
7475 cmd_set_vf_macvlan_parsed(void *parsed_result,
7476                        __attribute__((unused)) struct cmdline *cl,
7477                        __attribute__((unused)) void *data)
7478 {
7479         int is_on, ret = 0;
7480         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7481         struct rte_eth_mac_filter filter;
7482
7483         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7484
7485         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7486
7487         /* set VF MAC filter */
7488         filter.is_vf = 1;
7489
7490         /* set VF ID */
7491         filter.dst_id = res->vf_id;
7492
7493         if (!strcmp(res->filter_type, "exact-mac"))
7494                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7495         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7496                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7497         else if (!strcmp(res->filter_type, "hashmac"))
7498                 filter.filter_type = RTE_MAC_HASH_MATCH;
7499         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7500                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7501
7502         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7503
7504         if (is_on)
7505                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7506                                         RTE_ETH_FILTER_MACVLAN,
7507                                         RTE_ETH_FILTER_ADD,
7508                                          &filter);
7509         else
7510                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7511                                         RTE_ETH_FILTER_MACVLAN,
7512                                         RTE_ETH_FILTER_DELETE,
7513                                         &filter);
7514
7515         if (ret < 0)
7516                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7517
7518 }
7519
7520 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7521         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7522                                  set, "set");
7523 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7524         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7525                                  port, "port");
7526 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7527         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7528                               port_id, UINT16);
7529 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7530         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7531                                  vf, "vf");
7532 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7533         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7534                                 vf_id, UINT8);
7535 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7536         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7537                                 address);
7538 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7539         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7540                                 filter_type, "exact-mac#exact-mac-vlan"
7541                                 "#hashmac#hashmac-vlan");
7542 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7543         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7544                                  mode, "on#off");
7545
7546 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7547         .f = cmd_set_vf_macvlan_parsed,
7548         .data = NULL,
7549         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7550                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7551                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7552                 "hash match rule: hash match of MAC and exact match of VLAN",
7553         .tokens = {
7554                 (void *)&cmd_set_vf_macvlan_set,
7555                 (void *)&cmd_set_vf_macvlan_port,
7556                 (void *)&cmd_set_vf_macvlan_portid,
7557                 (void *)&cmd_set_vf_macvlan_vf,
7558                 (void *)&cmd_set_vf_macvlan_vf_id,
7559                 (void *)&cmd_set_vf_macvlan_mac,
7560                 (void *)&cmd_set_vf_macvlan_filter_type,
7561                 (void *)&cmd_set_vf_macvlan_mode,
7562                 NULL,
7563         },
7564 };
7565
7566 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7567 struct cmd_set_vf_traffic {
7568         cmdline_fixed_string_t set;
7569         cmdline_fixed_string_t port;
7570         portid_t port_id;
7571         cmdline_fixed_string_t vf;
7572         uint8_t vf_id;
7573         cmdline_fixed_string_t what;
7574         cmdline_fixed_string_t mode;
7575 };
7576
7577 static void
7578 cmd_set_vf_traffic_parsed(void *parsed_result,
7579                        __attribute__((unused)) struct cmdline *cl,
7580                        __attribute__((unused)) void *data)
7581 {
7582         struct cmd_set_vf_traffic *res = parsed_result;
7583         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7584         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7585
7586         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7587 }
7588
7589 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7590         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7591                                  set, "set");
7592 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7593         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7594                                  port, "port");
7595 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7596         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7597                               port_id, UINT16);
7598 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7599         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7600                                  vf, "vf");
7601 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7602         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7603                               vf_id, UINT8);
7604 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7605         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7606                                  what, "tx#rx");
7607 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7608         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7609                                  mode, "on#off");
7610
7611 cmdline_parse_inst_t cmd_set_vf_traffic = {
7612         .f = cmd_set_vf_traffic_parsed,
7613         .data = NULL,
7614         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7615         .tokens = {
7616                 (void *)&cmd_setvf_traffic_set,
7617                 (void *)&cmd_setvf_traffic_port,
7618                 (void *)&cmd_setvf_traffic_portid,
7619                 (void *)&cmd_setvf_traffic_vf,
7620                 (void *)&cmd_setvf_traffic_vfid,
7621                 (void *)&cmd_setvf_traffic_what,
7622                 (void *)&cmd_setvf_traffic_mode,
7623                 NULL,
7624         },
7625 };
7626
7627 /* *** CONFIGURE VF RECEIVE MODE *** */
7628 struct cmd_set_vf_rxmode {
7629         cmdline_fixed_string_t set;
7630         cmdline_fixed_string_t port;
7631         portid_t port_id;
7632         cmdline_fixed_string_t vf;
7633         uint8_t vf_id;
7634         cmdline_fixed_string_t what;
7635         cmdline_fixed_string_t mode;
7636         cmdline_fixed_string_t on;
7637 };
7638
7639 static void
7640 cmd_set_vf_rxmode_parsed(void *parsed_result,
7641                        __attribute__((unused)) struct cmdline *cl,
7642                        __attribute__((unused)) void *data)
7643 {
7644         int ret = -ENOTSUP;
7645         uint16_t rx_mode = 0;
7646         struct cmd_set_vf_rxmode *res = parsed_result;
7647
7648         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7649         if (!strcmp(res->what,"rxmode")) {
7650                 if (!strcmp(res->mode, "AUPE"))
7651                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7652                 else if (!strcmp(res->mode, "ROPE"))
7653                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7654                 else if (!strcmp(res->mode, "BAM"))
7655                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7656                 else if (!strncmp(res->mode, "MPE",3))
7657                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7658         }
7659
7660         RTE_SET_USED(is_on);
7661
7662 #ifdef RTE_LIBRTE_IXGBE_PMD
7663         if (ret == -ENOTSUP)
7664                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7665                                                   rx_mode, (uint8_t)is_on);
7666 #endif
7667 #ifdef RTE_LIBRTE_BNXT_PMD
7668         if (ret == -ENOTSUP)
7669                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7670                                                  rx_mode, (uint8_t)is_on);
7671 #endif
7672         if (ret < 0)
7673                 printf("bad VF receive mode parameter, return code = %d \n",
7674                 ret);
7675 }
7676
7677 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7678         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7679                                  set, "set");
7680 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7681         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7682                                  port, "port");
7683 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7684         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7685                               port_id, UINT16);
7686 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7687         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7688                                  vf, "vf");
7689 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7690         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7691                               vf_id, UINT8);
7692 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7693         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7694                                  what, "rxmode");
7695 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7696         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7697                                  mode, "AUPE#ROPE#BAM#MPE");
7698 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7699         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7700                                  on, "on#off");
7701
7702 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7703         .f = cmd_set_vf_rxmode_parsed,
7704         .data = NULL,
7705         .help_str = "set port <port_id> vf <vf_id> rxmode "
7706                 "AUPE|ROPE|BAM|MPE on|off",
7707         .tokens = {
7708                 (void *)&cmd_set_vf_rxmode_set,
7709                 (void *)&cmd_set_vf_rxmode_port,
7710                 (void *)&cmd_set_vf_rxmode_portid,
7711                 (void *)&cmd_set_vf_rxmode_vf,
7712                 (void *)&cmd_set_vf_rxmode_vfid,
7713                 (void *)&cmd_set_vf_rxmode_what,
7714                 (void *)&cmd_set_vf_rxmode_mode,
7715                 (void *)&cmd_set_vf_rxmode_on,
7716                 NULL,
7717         },
7718 };
7719
7720 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7721 struct cmd_vf_mac_addr_result {
7722         cmdline_fixed_string_t mac_addr_cmd;
7723         cmdline_fixed_string_t what;
7724         cmdline_fixed_string_t port;
7725         uint16_t port_num;
7726         cmdline_fixed_string_t vf;
7727         uint8_t vf_num;
7728         struct ether_addr address;
7729 };
7730
7731 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7732                 __attribute__((unused)) struct cmdline *cl,
7733                 __attribute__((unused)) void *data)
7734 {
7735         struct cmd_vf_mac_addr_result *res = parsed_result;
7736         int ret = -ENOTSUP;
7737
7738         if (strcmp(res->what, "add") != 0)
7739                 return;
7740
7741 #ifdef RTE_LIBRTE_I40E_PMD
7742         if (ret == -ENOTSUP)
7743                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7744                                                    &res->address);
7745 #endif
7746 #ifdef RTE_LIBRTE_BNXT_PMD
7747         if (ret == -ENOTSUP)
7748                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7749                                                 res->vf_num);
7750 #endif
7751
7752         if(ret < 0)
7753                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7754
7755 }
7756
7757 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7758         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7759                                 mac_addr_cmd,"mac_addr");
7760 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7761         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7762                                 what,"add");
7763 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7764         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7765                                 port,"port");
7766 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7767         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7768                                 port_num, UINT16);
7769 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7770         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7771                                 vf,"vf");
7772 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7773         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7774                                 vf_num, UINT8);
7775 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7776         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7777                                 address);
7778
7779 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7780         .f = cmd_vf_mac_addr_parsed,
7781         .data = (void *)0,
7782         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7783                 "Add MAC address filtering for a VF on port_id",
7784         .tokens = {
7785                 (void *)&cmd_vf_mac_addr_cmd,
7786                 (void *)&cmd_vf_mac_addr_what,
7787                 (void *)&cmd_vf_mac_addr_port,
7788                 (void *)&cmd_vf_mac_addr_portnum,
7789                 (void *)&cmd_vf_mac_addr_vf,
7790                 (void *)&cmd_vf_mac_addr_vfnum,
7791                 (void *)&cmd_vf_mac_addr_addr,
7792                 NULL,
7793         },
7794 };
7795
7796 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7797 struct cmd_vf_rx_vlan_filter {
7798         cmdline_fixed_string_t rx_vlan;
7799         cmdline_fixed_string_t what;
7800         uint16_t vlan_id;
7801         cmdline_fixed_string_t port;
7802         portid_t port_id;
7803         cmdline_fixed_string_t vf;
7804         uint64_t vf_mask;
7805 };
7806
7807 static void
7808 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7809                           __attribute__((unused)) struct cmdline *cl,
7810                           __attribute__((unused)) void *data)
7811 {
7812         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7813         int ret = -ENOTSUP;
7814
7815         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7816
7817 #ifdef RTE_LIBRTE_IXGBE_PMD
7818         if (ret == -ENOTSUP)
7819                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7820                                 res->vlan_id, res->vf_mask, is_add);
7821 #endif
7822 #ifdef RTE_LIBRTE_I40E_PMD
7823         if (ret == -ENOTSUP)
7824                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7825                                 res->vlan_id, res->vf_mask, is_add);
7826 #endif
7827 #ifdef RTE_LIBRTE_BNXT_PMD
7828         if (ret == -ENOTSUP)
7829                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7830                                 res->vlan_id, res->vf_mask, is_add);
7831 #endif
7832
7833         switch (ret) {
7834         case 0:
7835                 break;
7836         case -EINVAL:
7837                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7838                                 res->vlan_id, res->vf_mask);
7839                 break;
7840         case -ENODEV:
7841                 printf("invalid port_id %d\n", res->port_id);
7842                 break;
7843         case -ENOTSUP:
7844                 printf("function not implemented or supported\n");
7845                 break;
7846         default:
7847                 printf("programming error: (%s)\n", strerror(-ret));
7848         }
7849 }
7850
7851 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7852         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7853                                  rx_vlan, "rx_vlan");
7854 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7855         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7856                                  what, "add#rm");
7857 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7858         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7859                               vlan_id, UINT16);
7860 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7861         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7862                                  port, "port");
7863 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7864         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7865                               port_id, UINT16);
7866 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7867         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7868                                  vf, "vf");
7869 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7870         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7871                               vf_mask, UINT64);
7872
7873 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7874         .f = cmd_vf_rx_vlan_filter_parsed,
7875         .data = NULL,
7876         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7877                 "(vf_mask = hexadecimal VF mask)",
7878         .tokens = {
7879                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7880                 (void *)&cmd_vf_rx_vlan_filter_what,
7881                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7882                 (void *)&cmd_vf_rx_vlan_filter_port,
7883                 (void *)&cmd_vf_rx_vlan_filter_portid,
7884                 (void *)&cmd_vf_rx_vlan_filter_vf,
7885                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7886                 NULL,
7887         },
7888 };
7889
7890 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7891 struct cmd_queue_rate_limit_result {
7892         cmdline_fixed_string_t set;
7893         cmdline_fixed_string_t port;
7894         uint16_t port_num;
7895         cmdline_fixed_string_t queue;
7896         uint8_t queue_num;
7897         cmdline_fixed_string_t rate;
7898         uint16_t rate_num;
7899 };
7900
7901 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7902                 __attribute__((unused)) struct cmdline *cl,
7903                 __attribute__((unused)) void *data)
7904 {
7905         struct cmd_queue_rate_limit_result *res = parsed_result;
7906         int ret = 0;
7907
7908         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7909                 && (strcmp(res->queue, "queue") == 0)
7910                 && (strcmp(res->rate, "rate") == 0))
7911                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7912                                         res->rate_num);
7913         if (ret < 0)
7914                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7915
7916 }
7917
7918 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7919         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7920                                 set, "set");
7921 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7922         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7923                                 port, "port");
7924 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7925         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7926                                 port_num, UINT16);
7927 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7928         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7929                                 queue, "queue");
7930 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7931         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7932                                 queue_num, UINT8);
7933 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7934         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7935                                 rate, "rate");
7936 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7937         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7938                                 rate_num, UINT16);
7939
7940 cmdline_parse_inst_t cmd_queue_rate_limit = {
7941         .f = cmd_queue_rate_limit_parsed,
7942         .data = (void *)0,
7943         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7944                 "Set rate limit for a queue on port_id",
7945         .tokens = {
7946                 (void *)&cmd_queue_rate_limit_set,
7947                 (void *)&cmd_queue_rate_limit_port,
7948                 (void *)&cmd_queue_rate_limit_portnum,
7949                 (void *)&cmd_queue_rate_limit_queue,
7950                 (void *)&cmd_queue_rate_limit_queuenum,
7951                 (void *)&cmd_queue_rate_limit_rate,
7952                 (void *)&cmd_queue_rate_limit_ratenum,
7953                 NULL,
7954         },
7955 };
7956
7957 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7958 struct cmd_vf_rate_limit_result {
7959         cmdline_fixed_string_t set;
7960         cmdline_fixed_string_t port;
7961         uint16_t port_num;
7962         cmdline_fixed_string_t vf;
7963         uint8_t vf_num;
7964         cmdline_fixed_string_t rate;
7965         uint16_t rate_num;
7966         cmdline_fixed_string_t q_msk;
7967         uint64_t q_msk_val;
7968 };
7969
7970 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7971                 __attribute__((unused)) struct cmdline *cl,
7972                 __attribute__((unused)) void *data)
7973 {
7974         struct cmd_vf_rate_limit_result *res = parsed_result;
7975         int ret = 0;
7976
7977         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7978                 && (strcmp(res->vf, "vf") == 0)
7979                 && (strcmp(res->rate, "rate") == 0)
7980                 && (strcmp(res->q_msk, "queue_mask") == 0))
7981                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7982                                         res->rate_num, res->q_msk_val);
7983         if (ret < 0)
7984                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7985
7986 }
7987
7988 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7989         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7990                                 set, "set");
7991 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7992         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7993                                 port, "port");
7994 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7995         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7996                                 port_num, UINT16);
7997 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7998         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7999                                 vf, "vf");
8000 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8001         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8002                                 vf_num, UINT8);
8003 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8004         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8005                                 rate, "rate");
8006 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8007         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8008                                 rate_num, UINT16);
8009 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8010         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8011                                 q_msk, "queue_mask");
8012 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8013         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8014                                 q_msk_val, UINT64);
8015
8016 cmdline_parse_inst_t cmd_vf_rate_limit = {
8017         .f = cmd_vf_rate_limit_parsed,
8018         .data = (void *)0,
8019         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8020                 "queue_mask <queue_mask_value>: "
8021                 "Set rate limit for queues of VF on port_id",
8022         .tokens = {
8023                 (void *)&cmd_vf_rate_limit_set,
8024                 (void *)&cmd_vf_rate_limit_port,
8025                 (void *)&cmd_vf_rate_limit_portnum,
8026                 (void *)&cmd_vf_rate_limit_vf,
8027                 (void *)&cmd_vf_rate_limit_vfnum,
8028                 (void *)&cmd_vf_rate_limit_rate,
8029                 (void *)&cmd_vf_rate_limit_ratenum,
8030                 (void *)&cmd_vf_rate_limit_q_msk,
8031                 (void *)&cmd_vf_rate_limit_q_msk_val,
8032                 NULL,
8033         },
8034 };
8035
8036 /* *** ADD TUNNEL FILTER OF A PORT *** */
8037 struct cmd_tunnel_filter_result {
8038         cmdline_fixed_string_t cmd;
8039         cmdline_fixed_string_t what;
8040         portid_t port_id;
8041         struct ether_addr outer_mac;
8042         struct ether_addr inner_mac;
8043         cmdline_ipaddr_t ip_value;
8044         uint16_t inner_vlan;
8045         cmdline_fixed_string_t tunnel_type;
8046         cmdline_fixed_string_t filter_type;
8047         uint32_t tenant_id;
8048         uint16_t queue_num;
8049 };
8050
8051 static void
8052 cmd_tunnel_filter_parsed(void *parsed_result,
8053                           __attribute__((unused)) struct cmdline *cl,
8054                           __attribute__((unused)) void *data)
8055 {
8056         struct cmd_tunnel_filter_result *res = parsed_result;
8057         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8058         int ret = 0;
8059
8060         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8061
8062         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8063         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8064         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8065
8066         if (res->ip_value.family == AF_INET) {
8067                 tunnel_filter_conf.ip_addr.ipv4_addr =
8068                         res->ip_value.addr.ipv4.s_addr;
8069                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8070         } else {
8071                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8072                         &(res->ip_value.addr.ipv6),
8073                         sizeof(struct in6_addr));
8074                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8075         }
8076
8077         if (!strcmp(res->filter_type, "imac-ivlan"))
8078                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8079         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8080                 tunnel_filter_conf.filter_type =
8081                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8082         else if (!strcmp(res->filter_type, "imac-tenid"))
8083                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8084         else if (!strcmp(res->filter_type, "imac"))
8085                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8086         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8087                 tunnel_filter_conf.filter_type =
8088                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8089         else if (!strcmp(res->filter_type, "oip"))
8090                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8091         else if (!strcmp(res->filter_type, "iip"))
8092                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8093         else {
8094                 printf("The filter type is not supported");
8095                 return;
8096         }
8097
8098         if (!strcmp(res->tunnel_type, "vxlan"))
8099                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8100         else if (!strcmp(res->tunnel_type, "nvgre"))
8101                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8102         else if (!strcmp(res->tunnel_type, "ipingre"))
8103                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8104         else {
8105                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8106                 return;
8107         }
8108
8109         tunnel_filter_conf.tenant_id = res->tenant_id;
8110         tunnel_filter_conf.queue_id = res->queue_num;
8111         if (!strcmp(res->what, "add"))
8112                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8113                                         RTE_ETH_FILTER_TUNNEL,
8114                                         RTE_ETH_FILTER_ADD,
8115                                         &tunnel_filter_conf);
8116         else
8117                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8118                                         RTE_ETH_FILTER_TUNNEL,
8119                                         RTE_ETH_FILTER_DELETE,
8120                                         &tunnel_filter_conf);
8121         if (ret < 0)
8122                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8123                                 strerror(-ret));
8124
8125 }
8126 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8128         cmd, "tunnel_filter");
8129 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8130         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8131         what, "add#rm");
8132 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8134         port_id, UINT16);
8135 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8136         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8137         outer_mac);
8138 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8139         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8140         inner_mac);
8141 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8142         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8143         inner_vlan, UINT16);
8144 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8145         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8146         ip_value);
8147 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8148         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8149         tunnel_type, "vxlan#nvgre#ipingre");
8150
8151 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8152         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8153         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8154                 "imac#omac-imac-tenid");
8155 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8156         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8157         tenant_id, UINT32);
8158 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8159         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8160         queue_num, UINT16);
8161
8162 cmdline_parse_inst_t cmd_tunnel_filter = {
8163         .f = cmd_tunnel_filter_parsed,
8164         .data = (void *)0,
8165         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8166                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8167                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8168                 "<queue_id>: Add/Rm tunnel filter of a port",
8169         .tokens = {
8170                 (void *)&cmd_tunnel_filter_cmd,
8171                 (void *)&cmd_tunnel_filter_what,
8172                 (void *)&cmd_tunnel_filter_port_id,
8173                 (void *)&cmd_tunnel_filter_outer_mac,
8174                 (void *)&cmd_tunnel_filter_inner_mac,
8175                 (void *)&cmd_tunnel_filter_ip_value,
8176                 (void *)&cmd_tunnel_filter_innner_vlan,
8177                 (void *)&cmd_tunnel_filter_tunnel_type,
8178                 (void *)&cmd_tunnel_filter_filter_type,
8179                 (void *)&cmd_tunnel_filter_tenant_id,
8180                 (void *)&cmd_tunnel_filter_queue_num,
8181                 NULL,
8182         },
8183 };
8184
8185 /* *** CONFIGURE TUNNEL UDP PORT *** */
8186 struct cmd_tunnel_udp_config {
8187         cmdline_fixed_string_t cmd;
8188         cmdline_fixed_string_t what;
8189         uint16_t udp_port;
8190         portid_t port_id;
8191 };
8192
8193 static void
8194 cmd_tunnel_udp_config_parsed(void *parsed_result,
8195                           __attribute__((unused)) struct cmdline *cl,
8196                           __attribute__((unused)) void *data)
8197 {
8198         struct cmd_tunnel_udp_config *res = parsed_result;
8199         struct rte_eth_udp_tunnel tunnel_udp;
8200         int ret;
8201
8202         tunnel_udp.udp_port = res->udp_port;
8203
8204         if (!strcmp(res->cmd, "rx_vxlan_port"))
8205                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8206
8207         if (!strcmp(res->what, "add"))
8208                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8209                                                       &tunnel_udp);
8210         else
8211                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8212                                                          &tunnel_udp);
8213
8214         if (ret < 0)
8215                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8216 }
8217
8218 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8219         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8220                                 cmd, "rx_vxlan_port");
8221 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8222         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8223                                 what, "add#rm");
8224 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8225         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8226                                 udp_port, UINT16);
8227 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8228         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8229                                 port_id, UINT16);
8230
8231 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8232         .f = cmd_tunnel_udp_config_parsed,
8233         .data = (void *)0,
8234         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8235                 "Add/Remove a tunneling UDP port filter",
8236         .tokens = {
8237                 (void *)&cmd_tunnel_udp_config_cmd,
8238                 (void *)&cmd_tunnel_udp_config_what,
8239                 (void *)&cmd_tunnel_udp_config_udp_port,
8240                 (void *)&cmd_tunnel_udp_config_port_id,
8241                 NULL,
8242         },
8243 };
8244
8245 /* *** GLOBAL CONFIG *** */
8246 struct cmd_global_config_result {
8247         cmdline_fixed_string_t cmd;
8248         portid_t port_id;
8249         cmdline_fixed_string_t cfg_type;
8250         uint8_t len;
8251 };
8252
8253 static void
8254 cmd_global_config_parsed(void *parsed_result,
8255                          __attribute__((unused)) struct cmdline *cl,
8256                          __attribute__((unused)) void *data)
8257 {
8258         struct cmd_global_config_result *res = parsed_result;
8259         struct rte_eth_global_cfg conf;
8260         int ret;
8261
8262         memset(&conf, 0, sizeof(conf));
8263         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8264         conf.cfg.gre_key_len = res->len;
8265         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8266                                       RTE_ETH_FILTER_SET, &conf);
8267         if (ret != 0)
8268                 printf("Global config error\n");
8269 }
8270
8271 cmdline_parse_token_string_t cmd_global_config_cmd =
8272         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8273                 "global_config");
8274 cmdline_parse_token_num_t cmd_global_config_port_id =
8275         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8276                                UINT16);
8277 cmdline_parse_token_string_t cmd_global_config_type =
8278         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8279                 cfg_type, "gre-key-len");
8280 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8281         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8282                 len, UINT8);
8283
8284 cmdline_parse_inst_t cmd_global_config = {
8285         .f = cmd_global_config_parsed,
8286         .data = (void *)NULL,
8287         .help_str = "global_config <port_id> gre-key-len <key_len>",
8288         .tokens = {
8289                 (void *)&cmd_global_config_cmd,
8290                 (void *)&cmd_global_config_port_id,
8291                 (void *)&cmd_global_config_type,
8292                 (void *)&cmd_global_config_gre_key_len,
8293                 NULL,
8294         },
8295 };
8296
8297 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8298 struct cmd_set_mirror_mask_result {
8299         cmdline_fixed_string_t set;
8300         cmdline_fixed_string_t port;
8301         portid_t port_id;
8302         cmdline_fixed_string_t mirror;
8303         uint8_t rule_id;
8304         cmdline_fixed_string_t what;
8305         cmdline_fixed_string_t value;
8306         cmdline_fixed_string_t dstpool;
8307         uint8_t dstpool_id;
8308         cmdline_fixed_string_t on;
8309 };
8310
8311 cmdline_parse_token_string_t cmd_mirror_mask_set =
8312         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8313                                 set, "set");
8314 cmdline_parse_token_string_t cmd_mirror_mask_port =
8315         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8316                                 port, "port");
8317 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8318         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8319                                 port_id, UINT16);
8320 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8321         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8322                                 mirror, "mirror-rule");
8323 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8324         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8325                                 rule_id, UINT8);
8326 cmdline_parse_token_string_t cmd_mirror_mask_what =
8327         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8328                                 what, "pool-mirror-up#pool-mirror-down"
8329                                       "#vlan-mirror");
8330 cmdline_parse_token_string_t cmd_mirror_mask_value =
8331         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8332                                 value, NULL);
8333 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8334         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8335                                 dstpool, "dst-pool");
8336 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8337         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8338                                 dstpool_id, UINT8);
8339 cmdline_parse_token_string_t cmd_mirror_mask_on =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8341                                 on, "on#off");
8342
8343 static void
8344 cmd_set_mirror_mask_parsed(void *parsed_result,
8345                        __attribute__((unused)) struct cmdline *cl,
8346                        __attribute__((unused)) void *data)
8347 {
8348         int ret,nb_item,i;
8349         struct cmd_set_mirror_mask_result *res = parsed_result;
8350         struct rte_eth_mirror_conf mr_conf;
8351
8352         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8353
8354         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8355
8356         mr_conf.dst_pool = res->dstpool_id;
8357
8358         if (!strcmp(res->what, "pool-mirror-up")) {
8359                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8360                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8361         } else if (!strcmp(res->what, "pool-mirror-down")) {
8362                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8363                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8364         } else if (!strcmp(res->what, "vlan-mirror")) {
8365                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8366                 nb_item = parse_item_list(res->value, "vlan",
8367                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8368                 if (nb_item <= 0)
8369                         return;
8370
8371                 for (i = 0; i < nb_item; i++) {
8372                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8373                                 printf("Invalid vlan_id: must be < 4096\n");
8374                                 return;
8375                         }
8376
8377                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8378                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8379                 }
8380         }
8381
8382         if (!strcmp(res->on, "on"))
8383                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8384                                                 res->rule_id, 1);
8385         else
8386                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8387                                                 res->rule_id, 0);
8388         if (ret < 0)
8389                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8390 }
8391
8392 cmdline_parse_inst_t cmd_set_mirror_mask = {
8393                 .f = cmd_set_mirror_mask_parsed,
8394                 .data = NULL,
8395                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8396                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8397                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8398                 .tokens = {
8399                         (void *)&cmd_mirror_mask_set,
8400                         (void *)&cmd_mirror_mask_port,
8401                         (void *)&cmd_mirror_mask_portid,
8402                         (void *)&cmd_mirror_mask_mirror,
8403                         (void *)&cmd_mirror_mask_ruleid,
8404                         (void *)&cmd_mirror_mask_what,
8405                         (void *)&cmd_mirror_mask_value,
8406                         (void *)&cmd_mirror_mask_dstpool,
8407                         (void *)&cmd_mirror_mask_poolid,
8408                         (void *)&cmd_mirror_mask_on,
8409                         NULL,
8410                 },
8411 };
8412
8413 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8414 struct cmd_set_mirror_link_result {
8415         cmdline_fixed_string_t set;
8416         cmdline_fixed_string_t port;
8417         portid_t port_id;
8418         cmdline_fixed_string_t mirror;
8419         uint8_t rule_id;
8420         cmdline_fixed_string_t what;
8421         cmdline_fixed_string_t dstpool;
8422         uint8_t dstpool_id;
8423         cmdline_fixed_string_t on;
8424 };
8425
8426 cmdline_parse_token_string_t cmd_mirror_link_set =
8427         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8428                                  set, "set");
8429 cmdline_parse_token_string_t cmd_mirror_link_port =
8430         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8431                                 port, "port");
8432 cmdline_parse_token_num_t cmd_mirror_link_portid =
8433         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8434                                 port_id, UINT16);
8435 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8436         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8437                                 mirror, "mirror-rule");
8438 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8439         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8440                             rule_id, UINT8);
8441 cmdline_parse_token_string_t cmd_mirror_link_what =
8442         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8443                                 what, "uplink-mirror#downlink-mirror");
8444 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8445         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8446                                 dstpool, "dst-pool");
8447 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8448         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8449                                 dstpool_id, UINT8);
8450 cmdline_parse_token_string_t cmd_mirror_link_on =
8451         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8452                                 on, "on#off");
8453
8454 static void
8455 cmd_set_mirror_link_parsed(void *parsed_result,
8456                        __attribute__((unused)) struct cmdline *cl,
8457                        __attribute__((unused)) void *data)
8458 {
8459         int ret;
8460         struct cmd_set_mirror_link_result *res = parsed_result;
8461         struct rte_eth_mirror_conf mr_conf;
8462
8463         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8464         if (!strcmp(res->what, "uplink-mirror"))
8465                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8466         else
8467                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8468
8469         mr_conf.dst_pool = res->dstpool_id;
8470
8471         if (!strcmp(res->on, "on"))
8472                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8473                                                 res->rule_id, 1);
8474         else
8475                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8476                                                 res->rule_id, 0);
8477
8478         /* check the return value and print it if is < 0 */
8479         if (ret < 0)
8480                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8481
8482 }
8483
8484 cmdline_parse_inst_t cmd_set_mirror_link = {
8485                 .f = cmd_set_mirror_link_parsed,
8486                 .data = NULL,
8487                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8488                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8489                 .tokens = {
8490                         (void *)&cmd_mirror_link_set,
8491                         (void *)&cmd_mirror_link_port,
8492                         (void *)&cmd_mirror_link_portid,
8493                         (void *)&cmd_mirror_link_mirror,
8494                         (void *)&cmd_mirror_link_ruleid,
8495                         (void *)&cmd_mirror_link_what,
8496                         (void *)&cmd_mirror_link_dstpool,
8497                         (void *)&cmd_mirror_link_poolid,
8498                         (void *)&cmd_mirror_link_on,
8499                         NULL,
8500                 },
8501 };
8502
8503 /* *** RESET VM MIRROR RULE *** */
8504 struct cmd_rm_mirror_rule_result {
8505         cmdline_fixed_string_t reset;
8506         cmdline_fixed_string_t port;
8507         portid_t port_id;
8508         cmdline_fixed_string_t mirror;
8509         uint8_t rule_id;
8510 };
8511
8512 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8513         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8514                                  reset, "reset");
8515 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8516         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8517                                 port, "port");
8518 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8519         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8520                                 port_id, UINT16);
8521 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8522         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8523                                 mirror, "mirror-rule");
8524 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8525         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8526                                 rule_id, UINT8);
8527
8528 static void
8529 cmd_reset_mirror_rule_parsed(void *parsed_result,
8530                        __attribute__((unused)) struct cmdline *cl,
8531                        __attribute__((unused)) void *data)
8532 {
8533         int ret;
8534         struct cmd_set_mirror_link_result *res = parsed_result;
8535         /* check rule_id */
8536         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8537         if(ret < 0)
8538                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8539 }
8540
8541 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8542                 .f = cmd_reset_mirror_rule_parsed,
8543                 .data = NULL,
8544                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8545                 .tokens = {
8546                         (void *)&cmd_rm_mirror_rule_reset,
8547                         (void *)&cmd_rm_mirror_rule_port,
8548                         (void *)&cmd_rm_mirror_rule_portid,
8549                         (void *)&cmd_rm_mirror_rule_mirror,
8550                         (void *)&cmd_rm_mirror_rule_ruleid,
8551                         NULL,
8552                 },
8553 };
8554
8555 /* ******************************************************************************** */
8556
8557 struct cmd_dump_result {
8558         cmdline_fixed_string_t dump;
8559 };
8560
8561 static void
8562 dump_struct_sizes(void)
8563 {
8564 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8565         DUMP_SIZE(struct rte_mbuf);
8566         DUMP_SIZE(struct rte_mempool);
8567         DUMP_SIZE(struct rte_ring);
8568 #undef DUMP_SIZE
8569 }
8570
8571 static void cmd_dump_parsed(void *parsed_result,
8572                             __attribute__((unused)) struct cmdline *cl,
8573                             __attribute__((unused)) void *data)
8574 {
8575         struct cmd_dump_result *res = parsed_result;
8576
8577         if (!strcmp(res->dump, "dump_physmem"))
8578                 rte_dump_physmem_layout(stdout);
8579         else if (!strcmp(res->dump, "dump_memzone"))
8580                 rte_memzone_dump(stdout);
8581         else if (!strcmp(res->dump, "dump_struct_sizes"))
8582                 dump_struct_sizes();
8583         else if (!strcmp(res->dump, "dump_ring"))
8584                 rte_ring_list_dump(stdout);
8585         else if (!strcmp(res->dump, "dump_mempool"))
8586                 rte_mempool_list_dump(stdout);
8587         else if (!strcmp(res->dump, "dump_devargs"))
8588                 rte_eal_devargs_dump(stdout);
8589         else if (!strcmp(res->dump, "dump_log_types"))
8590                 rte_log_dump(stdout);
8591 }
8592
8593 cmdline_parse_token_string_t cmd_dump_dump =
8594         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8595                 "dump_physmem#"
8596                 "dump_memzone#"
8597                 "dump_struct_sizes#"
8598                 "dump_ring#"
8599                 "dump_mempool#"
8600                 "dump_devargs#"
8601                 "dump_log_types");
8602
8603 cmdline_parse_inst_t cmd_dump = {
8604         .f = cmd_dump_parsed,  /* function to call */
8605         .data = NULL,      /* 2nd arg of func */
8606         .help_str = "Dump status",
8607         .tokens = {        /* token list, NULL terminated */
8608                 (void *)&cmd_dump_dump,
8609                 NULL,
8610         },
8611 };
8612
8613 /* ******************************************************************************** */
8614
8615 struct cmd_dump_one_result {
8616         cmdline_fixed_string_t dump;
8617         cmdline_fixed_string_t name;
8618 };
8619
8620 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8621                                 __attribute__((unused)) void *data)
8622 {
8623         struct cmd_dump_one_result *res = parsed_result;
8624
8625         if (!strcmp(res->dump, "dump_ring")) {
8626                 struct rte_ring *r;
8627                 r = rte_ring_lookup(res->name);
8628                 if (r == NULL) {
8629                         cmdline_printf(cl, "Cannot find ring\n");
8630                         return;
8631                 }
8632                 rte_ring_dump(stdout, r);
8633         } else if (!strcmp(res->dump, "dump_mempool")) {
8634                 struct rte_mempool *mp;
8635                 mp = rte_mempool_lookup(res->name);
8636                 if (mp == NULL) {
8637                         cmdline_printf(cl, "Cannot find mempool\n");
8638                         return;
8639                 }
8640                 rte_mempool_dump(stdout, mp);
8641         }
8642 }
8643
8644 cmdline_parse_token_string_t cmd_dump_one_dump =
8645         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8646                                  "dump_ring#dump_mempool");
8647
8648 cmdline_parse_token_string_t cmd_dump_one_name =
8649         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8650
8651 cmdline_parse_inst_t cmd_dump_one = {
8652         .f = cmd_dump_one_parsed,  /* function to call */
8653         .data = NULL,      /* 2nd arg of func */
8654         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8655         .tokens = {        /* token list, NULL terminated */
8656                 (void *)&cmd_dump_one_dump,
8657                 (void *)&cmd_dump_one_name,
8658                 NULL,
8659         },
8660 };
8661
8662 /* *** Add/Del syn filter *** */
8663 struct cmd_syn_filter_result {
8664         cmdline_fixed_string_t filter;
8665         portid_t port_id;
8666         cmdline_fixed_string_t ops;
8667         cmdline_fixed_string_t priority;
8668         cmdline_fixed_string_t high;
8669         cmdline_fixed_string_t queue;
8670         uint16_t queue_id;
8671 };
8672
8673 static void
8674 cmd_syn_filter_parsed(void *parsed_result,
8675                         __attribute__((unused)) struct cmdline *cl,
8676                         __attribute__((unused)) void *data)
8677 {
8678         struct cmd_syn_filter_result *res = parsed_result;
8679         struct rte_eth_syn_filter syn_filter;
8680         int ret = 0;
8681
8682         ret = rte_eth_dev_filter_supported(res->port_id,
8683                                         RTE_ETH_FILTER_SYN);
8684         if (ret < 0) {
8685                 printf("syn filter is not supported on port %u.\n",
8686                                 res->port_id);
8687                 return;
8688         }
8689
8690         memset(&syn_filter, 0, sizeof(syn_filter));
8691
8692         if (!strcmp(res->ops, "add")) {
8693                 if (!strcmp(res->high, "high"))
8694                         syn_filter.hig_pri = 1;
8695                 else
8696                         syn_filter.hig_pri = 0;
8697
8698                 syn_filter.queue = res->queue_id;
8699                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8700                                                 RTE_ETH_FILTER_SYN,
8701                                                 RTE_ETH_FILTER_ADD,
8702                                                 &syn_filter);
8703         } else
8704                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8705                                                 RTE_ETH_FILTER_SYN,
8706                                                 RTE_ETH_FILTER_DELETE,
8707                                                 &syn_filter);
8708
8709         if (ret < 0)
8710                 printf("syn filter programming error: (%s)\n",
8711                                 strerror(-ret));
8712 }
8713
8714 cmdline_parse_token_string_t cmd_syn_filter_filter =
8715         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8716         filter, "syn_filter");
8717 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8718         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8719         port_id, UINT16);
8720 cmdline_parse_token_string_t cmd_syn_filter_ops =
8721         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8722         ops, "add#del");
8723 cmdline_parse_token_string_t cmd_syn_filter_priority =
8724         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8725                                 priority, "priority");
8726 cmdline_parse_token_string_t cmd_syn_filter_high =
8727         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8728                                 high, "high#low");
8729 cmdline_parse_token_string_t cmd_syn_filter_queue =
8730         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8731                                 queue, "queue");
8732 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8733         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8734                                 queue_id, UINT16);
8735
8736 cmdline_parse_inst_t cmd_syn_filter = {
8737         .f = cmd_syn_filter_parsed,
8738         .data = NULL,
8739         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8740                 "<queue_id>: Add/Delete syn filter",
8741         .tokens = {
8742                 (void *)&cmd_syn_filter_filter,
8743                 (void *)&cmd_syn_filter_port_id,
8744                 (void *)&cmd_syn_filter_ops,
8745                 (void *)&cmd_syn_filter_priority,
8746                 (void *)&cmd_syn_filter_high,
8747                 (void *)&cmd_syn_filter_queue,
8748                 (void *)&cmd_syn_filter_queue_id,
8749                 NULL,
8750         },
8751 };
8752
8753 /* *** queue region set *** */
8754 struct cmd_queue_region_result {
8755         cmdline_fixed_string_t set;
8756         cmdline_fixed_string_t port;
8757         portid_t port_id;
8758         cmdline_fixed_string_t cmd;
8759         cmdline_fixed_string_t region;
8760         uint8_t  region_id;
8761         cmdline_fixed_string_t queue_start_index;
8762         uint8_t  queue_id;
8763         cmdline_fixed_string_t queue_num;
8764         uint8_t  queue_num_value;
8765 };
8766
8767 static void
8768 cmd_queue_region_parsed(void *parsed_result,
8769                         __attribute__((unused)) struct cmdline *cl,
8770                         __attribute__((unused)) void *data)
8771 {
8772         struct cmd_queue_region_result *res = parsed_result;
8773         int ret = -ENOTSUP;
8774 #ifdef RTE_LIBRTE_I40E_PMD
8775         struct rte_pmd_i40e_queue_region_conf region_conf;
8776         enum rte_pmd_i40e_queue_region_op op_type;
8777 #endif
8778
8779         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8780                 return;
8781
8782 #ifdef RTE_LIBRTE_I40E_PMD
8783         memset(&region_conf, 0, sizeof(region_conf));
8784         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8785         region_conf.region_id = res->region_id;
8786         region_conf.queue_num = res->queue_num_value;
8787         region_conf.queue_start_index = res->queue_id;
8788
8789         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8790                                 op_type, &region_conf);
8791 #endif
8792
8793         switch (ret) {
8794         case 0:
8795                 break;
8796         case -ENOTSUP:
8797                 printf("function not implemented or supported\n");
8798                 break;
8799         default:
8800                 printf("queue region config error: (%s)\n", strerror(-ret));
8801         }
8802 }
8803
8804 cmdline_parse_token_string_t cmd_queue_region_set =
8805 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8806                 set, "set");
8807 cmdline_parse_token_string_t cmd_queue_region_port =
8808         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8809 cmdline_parse_token_num_t cmd_queue_region_port_id =
8810         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8811                                 port_id, UINT16);
8812 cmdline_parse_token_string_t cmd_queue_region_cmd =
8813         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8814                                  cmd, "queue-region");
8815 cmdline_parse_token_string_t cmd_queue_region_id =
8816         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8817                                 region, "region_id");
8818 cmdline_parse_token_num_t cmd_queue_region_index =
8819         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8820                                 region_id, UINT8);
8821 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8822         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8823                                 queue_start_index, "queue_start_index");
8824 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8825         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8826                                 queue_id, UINT8);
8827 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8828         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8829                                 queue_num, "queue_num");
8830 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8831         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8832                                 queue_num_value, UINT8);
8833
8834 cmdline_parse_inst_t cmd_queue_region = {
8835         .f = cmd_queue_region_parsed,
8836         .data = NULL,
8837         .help_str = "set port <port_id> queue-region region_id <value> "
8838                 "queue_start_index <value> queue_num <value>: Set a queue region",
8839         .tokens = {
8840                 (void *)&cmd_queue_region_set,
8841                 (void *)&cmd_queue_region_port,
8842                 (void *)&cmd_queue_region_port_id,
8843                 (void *)&cmd_queue_region_cmd,
8844                 (void *)&cmd_queue_region_id,
8845                 (void *)&cmd_queue_region_index,
8846                 (void *)&cmd_queue_region_queue_start_index,
8847                 (void *)&cmd_queue_region_queue_id,
8848                 (void *)&cmd_queue_region_queue_num,
8849                 (void *)&cmd_queue_region_queue_num_value,
8850                 NULL,
8851         },
8852 };
8853
8854 /* *** queue region and flowtype set *** */
8855 struct cmd_region_flowtype_result {
8856         cmdline_fixed_string_t set;
8857         cmdline_fixed_string_t port;
8858         portid_t port_id;
8859         cmdline_fixed_string_t cmd;
8860         cmdline_fixed_string_t region;
8861         uint8_t  region_id;
8862         cmdline_fixed_string_t flowtype;
8863         uint8_t  flowtype_id;
8864 };
8865
8866 static void
8867 cmd_region_flowtype_parsed(void *parsed_result,
8868                         __attribute__((unused)) struct cmdline *cl,
8869                         __attribute__((unused)) void *data)
8870 {
8871         struct cmd_region_flowtype_result *res = parsed_result;
8872         int ret = -ENOTSUP;
8873 #ifdef RTE_LIBRTE_I40E_PMD
8874         struct rte_pmd_i40e_queue_region_conf region_conf;
8875         enum rte_pmd_i40e_queue_region_op op_type;
8876 #endif
8877
8878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8879                 return;
8880
8881 #ifdef RTE_LIBRTE_I40E_PMD
8882         memset(&region_conf, 0, sizeof(region_conf));
8883
8884         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8885         region_conf.region_id = res->region_id;
8886         region_conf.hw_flowtype = res->flowtype_id;
8887
8888         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8889                         op_type, &region_conf);
8890 #endif
8891
8892         switch (ret) {
8893         case 0:
8894                 break;
8895         case -ENOTSUP:
8896                 printf("function not implemented or supported\n");
8897                 break;
8898         default:
8899                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8900         }
8901 }
8902
8903 cmdline_parse_token_string_t cmd_region_flowtype_set =
8904 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8905                                 set, "set");
8906 cmdline_parse_token_string_t cmd_region_flowtype_port =
8907         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8908                                 port, "port");
8909 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8910         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8911                                 port_id, UINT16);
8912 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8913         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8914                                 cmd, "queue-region");
8915 cmdline_parse_token_string_t cmd_region_flowtype_index =
8916         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8917                                 region, "region_id");
8918 cmdline_parse_token_num_t cmd_region_flowtype_id =
8919         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8920                                 region_id, UINT8);
8921 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8922         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8923                                 flowtype, "flowtype");
8924 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8925         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8926                                 flowtype_id, UINT8);
8927 cmdline_parse_inst_t cmd_region_flowtype = {
8928         .f = cmd_region_flowtype_parsed,
8929         .data = NULL,
8930         .help_str = "set port <port_id> queue-region region_id <value> "
8931                 "flowtype <value>: Set a flowtype region index",
8932         .tokens = {
8933                 (void *)&cmd_region_flowtype_set,
8934                 (void *)&cmd_region_flowtype_port,
8935                 (void *)&cmd_region_flowtype_port_index,
8936                 (void *)&cmd_region_flowtype_cmd,
8937                 (void *)&cmd_region_flowtype_index,
8938                 (void *)&cmd_region_flowtype_id,
8939                 (void *)&cmd_region_flowtype_flow_index,
8940                 (void *)&cmd_region_flowtype_flow_id,
8941                 NULL,
8942         },
8943 };
8944
8945 /* *** User Priority (UP) to queue region (region_id) set *** */
8946 struct cmd_user_priority_region_result {
8947         cmdline_fixed_string_t set;
8948         cmdline_fixed_string_t port;
8949         portid_t port_id;
8950         cmdline_fixed_string_t cmd;
8951         cmdline_fixed_string_t user_priority;
8952         uint8_t  user_priority_id;
8953         cmdline_fixed_string_t region;
8954         uint8_t  region_id;
8955 };
8956
8957 static void
8958 cmd_user_priority_region_parsed(void *parsed_result,
8959                         __attribute__((unused)) struct cmdline *cl,
8960                         __attribute__((unused)) void *data)
8961 {
8962         struct cmd_user_priority_region_result *res = parsed_result;
8963         int ret = -ENOTSUP;
8964 #ifdef RTE_LIBRTE_I40E_PMD
8965         struct rte_pmd_i40e_queue_region_conf region_conf;
8966         enum rte_pmd_i40e_queue_region_op op_type;
8967 #endif
8968
8969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8970                 return;
8971
8972 #ifdef RTE_LIBRTE_I40E_PMD
8973         memset(&region_conf, 0, sizeof(region_conf));
8974         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8975         region_conf.user_priority = res->user_priority_id;
8976         region_conf.region_id = res->region_id;
8977
8978         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8979                                 op_type, &region_conf);
8980 #endif
8981
8982         switch (ret) {
8983         case 0:
8984                 break;
8985         case -ENOTSUP:
8986                 printf("function not implemented or supported\n");
8987                 break;
8988         default:
8989                 printf("user_priority region config error: (%s)\n",
8990                                 strerror(-ret));
8991         }
8992 }
8993
8994 cmdline_parse_token_string_t cmd_user_priority_region_set =
8995         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8996                                 set, "set");
8997 cmdline_parse_token_string_t cmd_user_priority_region_port =
8998         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8999                                 port, "port");
9000 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9001         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9002                                 port_id, UINT16);
9003 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9004         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9005                                 cmd, "queue-region");
9006 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9007         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9008                                 user_priority, "UP");
9009 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9010         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9011                                 user_priority_id, UINT8);
9012 cmdline_parse_token_string_t cmd_user_priority_region_region =
9013         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9014                                 region, "region_id");
9015 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9016         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9017                                 region_id, UINT8);
9018
9019 cmdline_parse_inst_t cmd_user_priority_region = {
9020         .f = cmd_user_priority_region_parsed,
9021         .data = NULL,
9022         .help_str = "set port <port_id> queue-region UP <value> "
9023                 "region_id <value>: Set the mapping of User Priority (UP) "
9024                 "to queue region (region_id) ",
9025         .tokens = {
9026                 (void *)&cmd_user_priority_region_set,
9027                 (void *)&cmd_user_priority_region_port,
9028                 (void *)&cmd_user_priority_region_port_index,
9029                 (void *)&cmd_user_priority_region_cmd,
9030                 (void *)&cmd_user_priority_region_UP,
9031                 (void *)&cmd_user_priority_region_UP_id,
9032                 (void *)&cmd_user_priority_region_region,
9033                 (void *)&cmd_user_priority_region_region_id,
9034                 NULL,
9035         },
9036 };
9037
9038 /* *** flush all queue region related configuration *** */
9039 struct cmd_flush_queue_region_result {
9040         cmdline_fixed_string_t set;
9041         cmdline_fixed_string_t port;
9042         portid_t port_id;
9043         cmdline_fixed_string_t cmd;
9044         cmdline_fixed_string_t flush;
9045         cmdline_fixed_string_t what;
9046 };
9047
9048 static void
9049 cmd_flush_queue_region_parsed(void *parsed_result,
9050                         __attribute__((unused)) struct cmdline *cl,
9051                         __attribute__((unused)) void *data)
9052 {
9053         struct cmd_flush_queue_region_result *res = parsed_result;
9054         int ret = -ENOTSUP;
9055 #ifdef RTE_LIBRTE_I40E_PMD
9056         struct rte_pmd_i40e_queue_region_conf region_conf;
9057         enum rte_pmd_i40e_queue_region_op op_type;
9058 #endif
9059
9060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9061                 return;
9062
9063 #ifdef RTE_LIBRTE_I40E_PMD
9064         memset(&region_conf, 0, sizeof(region_conf));
9065
9066         if (strcmp(res->what, "on") == 0)
9067                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9068         else
9069                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9070
9071         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9072                                 op_type, &region_conf);
9073 #endif
9074
9075         switch (ret) {
9076         case 0:
9077                 break;
9078         case -ENOTSUP:
9079                 printf("function not implemented or supported\n");
9080                 break;
9081         default:
9082                 printf("queue region config flush error: (%s)\n",
9083                                 strerror(-ret));
9084         }
9085 }
9086
9087 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9088         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9089                                 set, "set");
9090 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9091         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9092                                 port, "port");
9093 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9094         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9095                                 port_id, UINT16);
9096 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9097         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9098                                 cmd, "queue-region");
9099 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9100         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9101                                 flush, "flush");
9102 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9103         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9104                                 what, "on#off");
9105
9106 cmdline_parse_inst_t cmd_flush_queue_region = {
9107         .f = cmd_flush_queue_region_parsed,
9108         .data = NULL,
9109         .help_str = "set port <port_id> queue-region flush on|off"
9110                 ": flush all queue region related configuration",
9111         .tokens = {
9112                 (void *)&cmd_flush_queue_region_set,
9113                 (void *)&cmd_flush_queue_region_port,
9114                 (void *)&cmd_flush_queue_region_port_index,
9115                 (void *)&cmd_flush_queue_region_cmd,
9116                 (void *)&cmd_flush_queue_region_flush,
9117                 (void *)&cmd_flush_queue_region_what,
9118                 NULL,
9119         },
9120 };
9121
9122 /* *** get all queue region related configuration info *** */
9123 struct cmd_show_queue_region_info {
9124         cmdline_fixed_string_t show;
9125         cmdline_fixed_string_t port;
9126         portid_t port_id;
9127         cmdline_fixed_string_t cmd;
9128 };
9129
9130 static void
9131 cmd_show_queue_region_info_parsed(void *parsed_result,
9132                         __attribute__((unused)) struct cmdline *cl,
9133                         __attribute__((unused)) void *data)
9134 {
9135         struct cmd_show_queue_region_info *res = parsed_result;
9136         int ret = -ENOTSUP;
9137 #ifdef RTE_LIBRTE_I40E_PMD
9138         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9139         enum rte_pmd_i40e_queue_region_op op_type;
9140 #endif
9141
9142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9143                 return;
9144
9145 #ifdef RTE_LIBRTE_I40E_PMD
9146         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9147
9148         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9149
9150         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9151                                         op_type, &rte_pmd_regions);
9152
9153         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9154 #endif
9155
9156         switch (ret) {
9157         case 0:
9158                 break;
9159         case -ENOTSUP:
9160                 printf("function not implemented or supported\n");
9161                 break;
9162         default:
9163                 printf("queue region config info show error: (%s)\n",
9164                                 strerror(-ret));
9165         }
9166 }
9167
9168 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9169 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9170                                 show, "show");
9171 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9172         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9173                                 port, "port");
9174 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9175         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9176                                 port_id, UINT16);
9177 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9178         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9179                                 cmd, "queue-region");
9180
9181 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9182         .f = cmd_show_queue_region_info_parsed,
9183         .data = NULL,
9184         .help_str = "show port <port_id> queue-region"
9185                 ": show all queue region related configuration info",
9186         .tokens = {
9187                 (void *)&cmd_show_queue_region_info_get,
9188                 (void *)&cmd_show_queue_region_info_port,
9189                 (void *)&cmd_show_queue_region_info_port_index,
9190                 (void *)&cmd_show_queue_region_info_cmd,
9191                 NULL,
9192         },
9193 };
9194
9195 /* *** ADD/REMOVE A 2tuple FILTER *** */
9196 struct cmd_2tuple_filter_result {
9197         cmdline_fixed_string_t filter;
9198         portid_t port_id;
9199         cmdline_fixed_string_t ops;
9200         cmdline_fixed_string_t dst_port;
9201         uint16_t dst_port_value;
9202         cmdline_fixed_string_t protocol;
9203         uint8_t protocol_value;
9204         cmdline_fixed_string_t mask;
9205         uint8_t  mask_value;
9206         cmdline_fixed_string_t tcp_flags;
9207         uint8_t tcp_flags_value;
9208         cmdline_fixed_string_t priority;
9209         uint8_t  priority_value;
9210         cmdline_fixed_string_t queue;
9211         uint16_t  queue_id;
9212 };
9213
9214 static void
9215 cmd_2tuple_filter_parsed(void *parsed_result,
9216                         __attribute__((unused)) struct cmdline *cl,
9217                         __attribute__((unused)) void *data)
9218 {
9219         struct rte_eth_ntuple_filter filter;
9220         struct cmd_2tuple_filter_result *res = parsed_result;
9221         int ret = 0;
9222
9223         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9224         if (ret < 0) {
9225                 printf("ntuple filter is not supported on port %u.\n",
9226                         res->port_id);
9227                 return;
9228         }
9229
9230         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9231
9232         filter.flags = RTE_2TUPLE_FLAGS;
9233         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9234         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9235         filter.proto = res->protocol_value;
9236         filter.priority = res->priority_value;
9237         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9238                 printf("nonzero tcp_flags is only meaningful"
9239                         " when protocol is TCP.\n");
9240                 return;
9241         }
9242         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9243                 printf("invalid TCP flags.\n");
9244                 return;
9245         }
9246
9247         if (res->tcp_flags_value != 0) {
9248                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9249                 filter.tcp_flags = res->tcp_flags_value;
9250         }
9251
9252         /* need convert to big endian. */
9253         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9254         filter.queue = res->queue_id;
9255
9256         if (!strcmp(res->ops, "add"))
9257                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9258                                 RTE_ETH_FILTER_NTUPLE,
9259                                 RTE_ETH_FILTER_ADD,
9260                                 &filter);
9261         else
9262                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9263                                 RTE_ETH_FILTER_NTUPLE,
9264                                 RTE_ETH_FILTER_DELETE,
9265                                 &filter);
9266         if (ret < 0)
9267                 printf("2tuple filter programming error: (%s)\n",
9268                         strerror(-ret));
9269
9270 }
9271
9272 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9273         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9274                                  filter, "2tuple_filter");
9275 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9276         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9277                                 port_id, UINT16);
9278 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9279         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9280                                  ops, "add#del");
9281 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9282         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9283                                 dst_port, "dst_port");
9284 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9285         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9286                                 dst_port_value, UINT16);
9287 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9288         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9289                                 protocol, "protocol");
9290 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9291         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9292                                 protocol_value, UINT8);
9293 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9294         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9295                                 mask, "mask");
9296 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9297         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9298                                 mask_value, INT8);
9299 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9300         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9301                                 tcp_flags, "tcp_flags");
9302 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9303         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9304                                 tcp_flags_value, UINT8);
9305 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9306         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9307                                 priority, "priority");
9308 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9309         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9310                                 priority_value, UINT8);
9311 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9312         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9313                                 queue, "queue");
9314 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9315         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9316                                 queue_id, UINT16);
9317
9318 cmdline_parse_inst_t cmd_2tuple_filter = {
9319         .f = cmd_2tuple_filter_parsed,
9320         .data = NULL,
9321         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9322                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9323                 "<queue_id>: Add a 2tuple filter",
9324         .tokens = {
9325                 (void *)&cmd_2tuple_filter_filter,
9326                 (void *)&cmd_2tuple_filter_port_id,
9327                 (void *)&cmd_2tuple_filter_ops,
9328                 (void *)&cmd_2tuple_filter_dst_port,
9329                 (void *)&cmd_2tuple_filter_dst_port_value,
9330                 (void *)&cmd_2tuple_filter_protocol,
9331                 (void *)&cmd_2tuple_filter_protocol_value,
9332                 (void *)&cmd_2tuple_filter_mask,
9333                 (void *)&cmd_2tuple_filter_mask_value,
9334                 (void *)&cmd_2tuple_filter_tcp_flags,
9335                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9336                 (void *)&cmd_2tuple_filter_priority,
9337                 (void *)&cmd_2tuple_filter_priority_value,
9338                 (void *)&cmd_2tuple_filter_queue,
9339                 (void *)&cmd_2tuple_filter_queue_id,
9340                 NULL,
9341         },
9342 };
9343
9344 /* *** ADD/REMOVE A 5tuple FILTER *** */
9345 struct cmd_5tuple_filter_result {
9346         cmdline_fixed_string_t filter;
9347         portid_t port_id;
9348         cmdline_fixed_string_t ops;
9349         cmdline_fixed_string_t dst_ip;
9350         cmdline_ipaddr_t dst_ip_value;
9351         cmdline_fixed_string_t src_ip;
9352         cmdline_ipaddr_t src_ip_value;
9353         cmdline_fixed_string_t dst_port;
9354         uint16_t dst_port_value;
9355         cmdline_fixed_string_t src_port;
9356         uint16_t src_port_value;
9357         cmdline_fixed_string_t protocol;
9358         uint8_t protocol_value;
9359         cmdline_fixed_string_t mask;
9360         uint8_t  mask_value;
9361         cmdline_fixed_string_t tcp_flags;
9362         uint8_t tcp_flags_value;
9363         cmdline_fixed_string_t priority;
9364         uint8_t  priority_value;
9365         cmdline_fixed_string_t queue;
9366         uint16_t  queue_id;
9367 };
9368
9369 static void
9370 cmd_5tuple_filter_parsed(void *parsed_result,
9371                         __attribute__((unused)) struct cmdline *cl,
9372                         __attribute__((unused)) void *data)
9373 {
9374         struct rte_eth_ntuple_filter filter;
9375         struct cmd_5tuple_filter_result *res = parsed_result;
9376         int ret = 0;
9377
9378         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9379         if (ret < 0) {
9380                 printf("ntuple filter is not supported on port %u.\n",
9381                         res->port_id);
9382                 return;
9383         }
9384
9385         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9386
9387         filter.flags = RTE_5TUPLE_FLAGS;
9388         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9389         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9390         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9391         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9392         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9393         filter.proto = res->protocol_value;
9394         filter.priority = res->priority_value;
9395         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9396                 printf("nonzero tcp_flags is only meaningful"
9397                         " when protocol is TCP.\n");
9398                 return;
9399         }
9400         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9401                 printf("invalid TCP flags.\n");
9402                 return;
9403         }
9404
9405         if (res->tcp_flags_value != 0) {
9406                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9407                 filter.tcp_flags = res->tcp_flags_value;
9408         }
9409
9410         if (res->dst_ip_value.family == AF_INET)
9411                 /* no need to convert, already big endian. */
9412                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9413         else {
9414                 if (filter.dst_ip_mask == 0) {
9415                         printf("can not support ipv6 involved compare.\n");
9416                         return;
9417                 }
9418                 filter.dst_ip = 0;
9419         }
9420
9421         if (res->src_ip_value.family == AF_INET)
9422                 /* no need to convert, already big endian. */
9423                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9424         else {
9425                 if (filter.src_ip_mask == 0) {
9426                         printf("can not support ipv6 involved compare.\n");
9427                         return;
9428                 }
9429                 filter.src_ip = 0;
9430         }
9431         /* need convert to big endian. */
9432         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9433         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9434         filter.queue = res->queue_id;
9435
9436         if (!strcmp(res->ops, "add"))
9437                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9438                                 RTE_ETH_FILTER_NTUPLE,
9439                                 RTE_ETH_FILTER_ADD,
9440                                 &filter);
9441         else
9442                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9443                                 RTE_ETH_FILTER_NTUPLE,
9444                                 RTE_ETH_FILTER_DELETE,
9445                                 &filter);
9446         if (ret < 0)
9447                 printf("5tuple filter programming error: (%s)\n",
9448                         strerror(-ret));
9449 }
9450
9451 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9452         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9453                                  filter, "5tuple_filter");
9454 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9455         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9456                                 port_id, UINT16);
9457 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9458         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9459                                  ops, "add#del");
9460 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9461         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9462                                 dst_ip, "dst_ip");
9463 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9464         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9465                                 dst_ip_value);
9466 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9467         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9468                                 src_ip, "src_ip");
9469 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9470         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9471                                 src_ip_value);
9472 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9473         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9474                                 dst_port, "dst_port");
9475 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9476         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9477                                 dst_port_value, UINT16);
9478 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9479         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9480                                 src_port, "src_port");
9481 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9482         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9483                                 src_port_value, UINT16);
9484 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9485         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9486                                 protocol, "protocol");
9487 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9488         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9489                                 protocol_value, UINT8);
9490 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9491         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9492                                 mask, "mask");
9493 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9494         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9495                                 mask_value, INT8);
9496 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9497         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9498                                 tcp_flags, "tcp_flags");
9499 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9500         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9501                                 tcp_flags_value, UINT8);
9502 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9503         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9504                                 priority, "priority");
9505 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9506         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9507                                 priority_value, UINT8);
9508 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9509         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9510                                 queue, "queue");
9511 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9512         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9513                                 queue_id, UINT16);
9514
9515 cmdline_parse_inst_t cmd_5tuple_filter = {
9516         .f = cmd_5tuple_filter_parsed,
9517         .data = NULL,
9518         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9519                 "src_ip <value> dst_port <value> src_port <value> "
9520                 "protocol <value>  mask <value> tcp_flags <value> "
9521                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9522         .tokens = {
9523                 (void *)&cmd_5tuple_filter_filter,
9524                 (void *)&cmd_5tuple_filter_port_id,
9525                 (void *)&cmd_5tuple_filter_ops,
9526                 (void *)&cmd_5tuple_filter_dst_ip,
9527                 (void *)&cmd_5tuple_filter_dst_ip_value,
9528                 (void *)&cmd_5tuple_filter_src_ip,
9529                 (void *)&cmd_5tuple_filter_src_ip_value,
9530                 (void *)&cmd_5tuple_filter_dst_port,
9531                 (void *)&cmd_5tuple_filter_dst_port_value,
9532                 (void *)&cmd_5tuple_filter_src_port,
9533                 (void *)&cmd_5tuple_filter_src_port_value,
9534                 (void *)&cmd_5tuple_filter_protocol,
9535                 (void *)&cmd_5tuple_filter_protocol_value,
9536                 (void *)&cmd_5tuple_filter_mask,
9537                 (void *)&cmd_5tuple_filter_mask_value,
9538                 (void *)&cmd_5tuple_filter_tcp_flags,
9539                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9540                 (void *)&cmd_5tuple_filter_priority,
9541                 (void *)&cmd_5tuple_filter_priority_value,
9542                 (void *)&cmd_5tuple_filter_queue,
9543                 (void *)&cmd_5tuple_filter_queue_id,
9544                 NULL,
9545         },
9546 };
9547
9548 /* *** ADD/REMOVE A flex FILTER *** */
9549 struct cmd_flex_filter_result {
9550         cmdline_fixed_string_t filter;
9551         cmdline_fixed_string_t ops;
9552         portid_t port_id;
9553         cmdline_fixed_string_t len;
9554         uint8_t len_value;
9555         cmdline_fixed_string_t bytes;
9556         cmdline_fixed_string_t bytes_value;
9557         cmdline_fixed_string_t mask;
9558         cmdline_fixed_string_t mask_value;
9559         cmdline_fixed_string_t priority;
9560         uint8_t priority_value;
9561         cmdline_fixed_string_t queue;
9562         uint16_t queue_id;
9563 };
9564
9565 static int xdigit2val(unsigned char c)
9566 {
9567         int val;
9568         if (isdigit(c))
9569                 val = c - '0';
9570         else if (isupper(c))
9571                 val = c - 'A' + 10;
9572         else
9573                 val = c - 'a' + 10;
9574         return val;
9575 }
9576
9577 static void
9578 cmd_flex_filter_parsed(void *parsed_result,
9579                           __attribute__((unused)) struct cmdline *cl,
9580                           __attribute__((unused)) void *data)
9581 {
9582         int ret = 0;
9583         struct rte_eth_flex_filter filter;
9584         struct cmd_flex_filter_result *res = parsed_result;
9585         char *bytes_ptr, *mask_ptr;
9586         uint16_t len, i, j = 0;
9587         char c;
9588         int val;
9589         uint8_t byte = 0;
9590
9591         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9592                 printf("the len exceed the max length 128\n");
9593                 return;
9594         }
9595         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9596         filter.len = res->len_value;
9597         filter.priority = res->priority_value;
9598         filter.queue = res->queue_id;
9599         bytes_ptr = res->bytes_value;
9600         mask_ptr = res->mask_value;
9601
9602          /* translate bytes string to array. */
9603         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9604                 (bytes_ptr[1] == 'X')))
9605                 bytes_ptr += 2;
9606         len = strnlen(bytes_ptr, res->len_value * 2);
9607         if (len == 0 || (len % 8 != 0)) {
9608                 printf("please check len and bytes input\n");
9609                 return;
9610         }
9611         for (i = 0; i < len; i++) {
9612                 c = bytes_ptr[i];
9613                 if (isxdigit(c) == 0) {
9614                         /* invalid characters. */
9615                         printf("invalid input\n");
9616                         return;
9617                 }
9618                 val = xdigit2val(c);
9619                 if (i % 2) {
9620                         byte |= val;
9621                         filter.bytes[j] = byte;
9622                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9623                         j++;
9624                         byte = 0;
9625                 } else
9626                         byte |= val << 4;
9627         }
9628         printf("\n");
9629          /* translate mask string to uint8_t array. */
9630         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9631                 (mask_ptr[1] == 'X')))
9632                 mask_ptr += 2;
9633         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9634         if (len == 0) {
9635                 printf("invalid input\n");
9636                 return;
9637         }
9638         j = 0;
9639         byte = 0;
9640         for (i = 0; i < len; i++) {
9641                 c = mask_ptr[i];
9642                 if (isxdigit(c) == 0) {
9643                         /* invalid characters. */
9644                         printf("invalid input\n");
9645                         return;
9646                 }
9647                 val = xdigit2val(c);
9648                 if (i % 2) {
9649                         byte |= val;
9650                         filter.mask[j] = byte;
9651                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9652                         j++;
9653                         byte = 0;
9654                 } else
9655                         byte |= val << 4;
9656         }
9657         printf("\n");
9658
9659         if (!strcmp(res->ops, "add"))
9660                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9661                                 RTE_ETH_FILTER_FLEXIBLE,
9662                                 RTE_ETH_FILTER_ADD,
9663                                 &filter);
9664         else
9665                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9666                                 RTE_ETH_FILTER_FLEXIBLE,
9667                                 RTE_ETH_FILTER_DELETE,
9668                                 &filter);
9669
9670         if (ret < 0)
9671                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9672 }
9673
9674 cmdline_parse_token_string_t cmd_flex_filter_filter =
9675         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9676                                 filter, "flex_filter");
9677 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9678         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9679                                 port_id, UINT16);
9680 cmdline_parse_token_string_t cmd_flex_filter_ops =
9681         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9682                                 ops, "add#del");
9683 cmdline_parse_token_string_t cmd_flex_filter_len =
9684         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9685                                 len, "len");
9686 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9687         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9688                                 len_value, UINT8);
9689 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9690         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9691                                 bytes, "bytes");
9692 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9693         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9694                                 bytes_value, NULL);
9695 cmdline_parse_token_string_t cmd_flex_filter_mask =
9696         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9697                                 mask, "mask");
9698 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9699         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9700                                 mask_value, NULL);
9701 cmdline_parse_token_string_t cmd_flex_filter_priority =
9702         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9703                                 priority, "priority");
9704 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9705         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9706                                 priority_value, UINT8);
9707 cmdline_parse_token_string_t cmd_flex_filter_queue =
9708         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9709                                 queue, "queue");
9710 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9711         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9712                                 queue_id, UINT16);
9713 cmdline_parse_inst_t cmd_flex_filter = {
9714         .f = cmd_flex_filter_parsed,
9715         .data = NULL,
9716         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9717                 "<value> mask <value> priority <value> queue <queue_id>: "
9718                 "Add/Del a flex filter",
9719         .tokens = {
9720                 (void *)&cmd_flex_filter_filter,
9721                 (void *)&cmd_flex_filter_port_id,
9722                 (void *)&cmd_flex_filter_ops,
9723                 (void *)&cmd_flex_filter_len,
9724                 (void *)&cmd_flex_filter_len_value,
9725                 (void *)&cmd_flex_filter_bytes,
9726                 (void *)&cmd_flex_filter_bytes_value,
9727                 (void *)&cmd_flex_filter_mask,
9728                 (void *)&cmd_flex_filter_mask_value,
9729                 (void *)&cmd_flex_filter_priority,
9730                 (void *)&cmd_flex_filter_priority_value,
9731                 (void *)&cmd_flex_filter_queue,
9732                 (void *)&cmd_flex_filter_queue_id,
9733                 NULL,
9734         },
9735 };
9736
9737 /* *** Filters Control *** */
9738
9739 /* *** deal with ethertype filter *** */
9740 struct cmd_ethertype_filter_result {
9741         cmdline_fixed_string_t filter;
9742         portid_t port_id;
9743         cmdline_fixed_string_t ops;
9744         cmdline_fixed_string_t mac;
9745         struct ether_addr mac_addr;
9746         cmdline_fixed_string_t ethertype;
9747         uint16_t ethertype_value;
9748         cmdline_fixed_string_t drop;
9749         cmdline_fixed_string_t queue;
9750         uint16_t  queue_id;
9751 };
9752
9753 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9754         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9755                                  filter, "ethertype_filter");
9756 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9757         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9758                               port_id, UINT16);
9759 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9760         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9761                                  ops, "add#del");
9762 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9763         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9764                                  mac, "mac_addr#mac_ignr");
9765 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9766         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9767                                      mac_addr);
9768 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9769         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9770                                  ethertype, "ethertype");
9771 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9772         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9773                               ethertype_value, UINT16);
9774 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9775         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9776                                  drop, "drop#fwd");
9777 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9778         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9779                                  queue, "queue");
9780 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9781         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9782                               queue_id, UINT16);
9783
9784 static void
9785 cmd_ethertype_filter_parsed(void *parsed_result,
9786                           __attribute__((unused)) struct cmdline *cl,
9787                           __attribute__((unused)) void *data)
9788 {
9789         struct cmd_ethertype_filter_result *res = parsed_result;
9790         struct rte_eth_ethertype_filter filter;
9791         int ret = 0;
9792
9793         ret = rte_eth_dev_filter_supported(res->port_id,
9794                         RTE_ETH_FILTER_ETHERTYPE);
9795         if (ret < 0) {
9796                 printf("ethertype filter is not supported on port %u.\n",
9797                         res->port_id);
9798                 return;
9799         }
9800
9801         memset(&filter, 0, sizeof(filter));
9802         if (!strcmp(res->mac, "mac_addr")) {
9803                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9804                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9805                         sizeof(struct ether_addr));
9806         }
9807         if (!strcmp(res->drop, "drop"))
9808                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9809         filter.ether_type = res->ethertype_value;
9810         filter.queue = res->queue_id;
9811
9812         if (!strcmp(res->ops, "add"))
9813                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9814                                 RTE_ETH_FILTER_ETHERTYPE,
9815                                 RTE_ETH_FILTER_ADD,
9816                                 &filter);
9817         else
9818                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9819                                 RTE_ETH_FILTER_ETHERTYPE,
9820                                 RTE_ETH_FILTER_DELETE,
9821                                 &filter);
9822         if (ret < 0)
9823                 printf("ethertype filter programming error: (%s)\n",
9824                         strerror(-ret));
9825 }
9826
9827 cmdline_parse_inst_t cmd_ethertype_filter = {
9828         .f = cmd_ethertype_filter_parsed,
9829         .data = NULL,
9830         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9831                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9832                 "Add or delete an ethertype filter entry",
9833         .tokens = {
9834                 (void *)&cmd_ethertype_filter_filter,
9835                 (void *)&cmd_ethertype_filter_port_id,
9836                 (void *)&cmd_ethertype_filter_ops,
9837                 (void *)&cmd_ethertype_filter_mac,
9838                 (void *)&cmd_ethertype_filter_mac_addr,
9839                 (void *)&cmd_ethertype_filter_ethertype,
9840                 (void *)&cmd_ethertype_filter_ethertype_value,
9841                 (void *)&cmd_ethertype_filter_drop,
9842                 (void *)&cmd_ethertype_filter_queue,
9843                 (void *)&cmd_ethertype_filter_queue_id,
9844                 NULL,
9845         },
9846 };
9847
9848 /* *** deal with flow director filter *** */
9849 struct cmd_flow_director_result {
9850         cmdline_fixed_string_t flow_director_filter;
9851         portid_t port_id;
9852         cmdline_fixed_string_t mode;
9853         cmdline_fixed_string_t mode_value;
9854         cmdline_fixed_string_t ops;
9855         cmdline_fixed_string_t flow;
9856         cmdline_fixed_string_t flow_type;
9857         cmdline_fixed_string_t ether;
9858         uint16_t ether_type;
9859         cmdline_fixed_string_t src;
9860         cmdline_ipaddr_t ip_src;
9861         uint16_t port_src;
9862         cmdline_fixed_string_t dst;
9863         cmdline_ipaddr_t ip_dst;
9864         uint16_t port_dst;
9865         cmdline_fixed_string_t verify_tag;
9866         uint32_t verify_tag_value;
9867         cmdline_ipaddr_t tos;
9868         uint8_t tos_value;
9869         cmdline_ipaddr_t proto;
9870         uint8_t proto_value;
9871         cmdline_ipaddr_t ttl;
9872         uint8_t ttl_value;
9873         cmdline_fixed_string_t vlan;
9874         uint16_t vlan_value;
9875         cmdline_fixed_string_t flexbytes;
9876         cmdline_fixed_string_t flexbytes_value;
9877         cmdline_fixed_string_t pf_vf;
9878         cmdline_fixed_string_t drop;
9879         cmdline_fixed_string_t queue;
9880         uint16_t  queue_id;
9881         cmdline_fixed_string_t fd_id;
9882         uint32_t  fd_id_value;
9883         cmdline_fixed_string_t mac;
9884         struct ether_addr mac_addr;
9885         cmdline_fixed_string_t tunnel;
9886         cmdline_fixed_string_t tunnel_type;
9887         cmdline_fixed_string_t tunnel_id;
9888         uint32_t tunnel_id_value;
9889         cmdline_fixed_string_t packet;
9890         char filepath[];
9891 };
9892
9893 static inline int
9894 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9895 {
9896         char s[256];
9897         const char *p, *p0 = q_arg;
9898         char *end;
9899         unsigned long int_fld;
9900         char *str_fld[max_num];
9901         int i;
9902         unsigned size;
9903         int ret = -1;
9904
9905         p = strchr(p0, '(');
9906         if (p == NULL)
9907                 return -1;
9908         ++p;
9909         p0 = strchr(p, ')');
9910         if (p0 == NULL)
9911                 return -1;
9912
9913         size = p0 - p;
9914         if (size >= sizeof(s))
9915                 return -1;
9916
9917         snprintf(s, sizeof(s), "%.*s", size, p);
9918         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9919         if (ret < 0 || ret > max_num)
9920                 return -1;
9921         for (i = 0; i < ret; i++) {
9922                 errno = 0;
9923                 int_fld = strtoul(str_fld[i], &end, 0);
9924                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9925                         return -1;
9926                 flexbytes[i] = (uint8_t)int_fld;
9927         }
9928         return ret;
9929 }
9930
9931 static uint16_t
9932 str2flowtype(char *string)
9933 {
9934         uint8_t i = 0;
9935         static const struct {
9936                 char str[32];
9937                 uint16_t type;
9938         } flowtype_str[] = {
9939                 {"raw", RTE_ETH_FLOW_RAW},
9940                 {"ipv4", RTE_ETH_FLOW_IPV4},
9941                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9942                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9943                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9944                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9945                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9946                 {"ipv6", RTE_ETH_FLOW_IPV6},
9947                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9948                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9949                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9950                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9951                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9952                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9953         };
9954
9955         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9956                 if (!strcmp(flowtype_str[i].str, string))
9957                         return flowtype_str[i].type;
9958         }
9959
9960         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9961                 return (uint16_t)atoi(string);
9962
9963         return RTE_ETH_FLOW_UNKNOWN;
9964 }
9965
9966 static enum rte_eth_fdir_tunnel_type
9967 str2fdir_tunneltype(char *string)
9968 {
9969         uint8_t i = 0;
9970
9971         static const struct {
9972                 char str[32];
9973                 enum rte_eth_fdir_tunnel_type type;
9974         } tunneltype_str[] = {
9975                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9976                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9977         };
9978
9979         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9980                 if (!strcmp(tunneltype_str[i].str, string))
9981                         return tunneltype_str[i].type;
9982         }
9983         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9984 }
9985
9986 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9987 do { \
9988         if ((ip_addr).family == AF_INET) \
9989                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9990         else { \
9991                 printf("invalid parameter.\n"); \
9992                 return; \
9993         } \
9994 } while (0)
9995
9996 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9997 do { \
9998         if ((ip_addr).family == AF_INET6) \
9999                 rte_memcpy(&(ip), \
10000                                  &((ip_addr).addr.ipv6), \
10001                                  sizeof(struct in6_addr)); \
10002         else { \
10003                 printf("invalid parameter.\n"); \
10004                 return; \
10005         } \
10006 } while (0)
10007
10008 static void
10009 cmd_flow_director_filter_parsed(void *parsed_result,
10010                           __attribute__((unused)) struct cmdline *cl,
10011                           __attribute__((unused)) void *data)
10012 {
10013         struct cmd_flow_director_result *res = parsed_result;
10014         struct rte_eth_fdir_filter entry;
10015         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10016         char *end;
10017         unsigned long vf_id;
10018         int ret = 0;
10019
10020         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10021         if (ret < 0) {
10022                 printf("flow director is not supported on port %u.\n",
10023                         res->port_id);
10024                 return;
10025         }
10026         memset(flexbytes, 0, sizeof(flexbytes));
10027         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10028
10029         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10030                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10031                         printf("Please set mode to MAC-VLAN.\n");
10032                         return;
10033                 }
10034         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10035                 if (strcmp(res->mode_value, "Tunnel")) {
10036                         printf("Please set mode to Tunnel.\n");
10037                         return;
10038                 }
10039         } else {
10040                 if (!strcmp(res->mode_value, "raw")) {
10041 #ifdef RTE_LIBRTE_I40E_PMD
10042                         struct rte_pmd_i40e_flow_type_mapping
10043                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10044                         struct rte_pmd_i40e_pkt_template_conf conf;
10045                         uint16_t flow_type = str2flowtype(res->flow_type);
10046                         uint16_t i, port = res->port_id;
10047                         uint8_t add;
10048
10049                         memset(&conf, 0, sizeof(conf));
10050
10051                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10052                                 printf("Invalid flow type specified.\n");
10053                                 return;
10054                         }
10055                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10056                                                                  mapping);
10057                         if (ret)
10058                                 return;
10059                         if (mapping[flow_type].pctype == 0ULL) {
10060                                 printf("Invalid flow type specified.\n");
10061                                 return;
10062                         }
10063                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10064                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10065                                         conf.input.pctype = i;
10066                                         break;
10067                                 }
10068                         }
10069
10070                         conf.input.packet = open_file(res->filepath,
10071                                                 &conf.input.length);
10072                         if (!conf.input.packet)
10073                                 return;
10074                         if (!strcmp(res->drop, "drop"))
10075                                 conf.action.behavior =
10076                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10077                         else
10078                                 conf.action.behavior =
10079                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10080                         conf.action.report_status =
10081                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10082                         conf.action.rx_queue = res->queue_id;
10083                         conf.soft_id = res->fd_id_value;
10084                         add  = strcmp(res->ops, "del") ? 1 : 0;
10085                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10086                                                                         &conf,
10087                                                                         add);
10088                         if (ret < 0)
10089                                 printf("flow director config error: (%s)\n",
10090                                        strerror(-ret));
10091                         close_file(conf.input.packet);
10092 #endif
10093                         return;
10094                 } else if (strcmp(res->mode_value, "IP")) {
10095                         printf("Please set mode to IP or raw.\n");
10096                         return;
10097                 }
10098                 entry.input.flow_type = str2flowtype(res->flow_type);
10099         }
10100
10101         ret = parse_flexbytes(res->flexbytes_value,
10102                                         flexbytes,
10103                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10104         if (ret < 0) {
10105                 printf("error: Cannot parse flexbytes input.\n");
10106                 return;
10107         }
10108
10109         switch (entry.input.flow_type) {
10110         case RTE_ETH_FLOW_FRAG_IPV4:
10111         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10112                 entry.input.flow.ip4_flow.proto = res->proto_value;
10113                 /* fall-through */
10114         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10115         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10116                 IPV4_ADDR_TO_UINT(res->ip_dst,
10117                         entry.input.flow.ip4_flow.dst_ip);
10118                 IPV4_ADDR_TO_UINT(res->ip_src,
10119                         entry.input.flow.ip4_flow.src_ip);
10120                 entry.input.flow.ip4_flow.tos = res->tos_value;
10121                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10122                 /* need convert to big endian. */
10123                 entry.input.flow.udp4_flow.dst_port =
10124                                 rte_cpu_to_be_16(res->port_dst);
10125                 entry.input.flow.udp4_flow.src_port =
10126                                 rte_cpu_to_be_16(res->port_src);
10127                 break;
10128         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10129                 IPV4_ADDR_TO_UINT(res->ip_dst,
10130                         entry.input.flow.sctp4_flow.ip.dst_ip);
10131                 IPV4_ADDR_TO_UINT(res->ip_src,
10132                         entry.input.flow.sctp4_flow.ip.src_ip);
10133                 entry.input.flow.ip4_flow.tos = res->tos_value;
10134                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10135                 /* need convert to big endian. */
10136                 entry.input.flow.sctp4_flow.dst_port =
10137                                 rte_cpu_to_be_16(res->port_dst);
10138                 entry.input.flow.sctp4_flow.src_port =
10139                                 rte_cpu_to_be_16(res->port_src);
10140                 entry.input.flow.sctp4_flow.verify_tag =
10141                                 rte_cpu_to_be_32(res->verify_tag_value);
10142                 break;
10143         case RTE_ETH_FLOW_FRAG_IPV6:
10144         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10145                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10146                 /* fall-through */
10147         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10148         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10149                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10150                         entry.input.flow.ipv6_flow.dst_ip);
10151                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10152                         entry.input.flow.ipv6_flow.src_ip);
10153                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10154                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10155                 /* need convert to big endian. */
10156                 entry.input.flow.udp6_flow.dst_port =
10157                                 rte_cpu_to_be_16(res->port_dst);
10158                 entry.input.flow.udp6_flow.src_port =
10159                                 rte_cpu_to_be_16(res->port_src);
10160                 break;
10161         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10162                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10163                         entry.input.flow.sctp6_flow.ip.dst_ip);
10164                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10165                         entry.input.flow.sctp6_flow.ip.src_ip);
10166                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10167                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10168                 /* need convert to big endian. */
10169                 entry.input.flow.sctp6_flow.dst_port =
10170                                 rte_cpu_to_be_16(res->port_dst);
10171                 entry.input.flow.sctp6_flow.src_port =
10172                                 rte_cpu_to_be_16(res->port_src);
10173                 entry.input.flow.sctp6_flow.verify_tag =
10174                                 rte_cpu_to_be_32(res->verify_tag_value);
10175                 break;
10176         case RTE_ETH_FLOW_L2_PAYLOAD:
10177                 entry.input.flow.l2_flow.ether_type =
10178                         rte_cpu_to_be_16(res->ether_type);
10179                 break;
10180         default:
10181                 break;
10182         }
10183
10184         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10185                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10186                                  &res->mac_addr,
10187                                  sizeof(struct ether_addr));
10188
10189         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10190                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10191                                  &res->mac_addr,
10192                                  sizeof(struct ether_addr));
10193                 entry.input.flow.tunnel_flow.tunnel_type =
10194                         str2fdir_tunneltype(res->tunnel_type);
10195                 entry.input.flow.tunnel_flow.tunnel_id =
10196                         rte_cpu_to_be_32(res->tunnel_id_value);
10197         }
10198
10199         rte_memcpy(entry.input.flow_ext.flexbytes,
10200                    flexbytes,
10201                    RTE_ETH_FDIR_MAX_FLEXLEN);
10202
10203         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10204
10205         entry.action.flex_off = 0;  /*use 0 by default */
10206         if (!strcmp(res->drop, "drop"))
10207                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10208         else
10209                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10210
10211         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10212             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10213                 if (!strcmp(res->pf_vf, "pf"))
10214                         entry.input.flow_ext.is_vf = 0;
10215                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10216                         struct rte_eth_dev_info dev_info;
10217
10218                         memset(&dev_info, 0, sizeof(dev_info));
10219                         rte_eth_dev_info_get(res->port_id, &dev_info);
10220                         errno = 0;
10221                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10222                         if (errno != 0 || *end != '\0' ||
10223                             vf_id >= dev_info.max_vfs) {
10224                                 printf("invalid parameter %s.\n", res->pf_vf);
10225                                 return;
10226                         }
10227                         entry.input.flow_ext.is_vf = 1;
10228                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10229                 } else {
10230                         printf("invalid parameter %s.\n", res->pf_vf);
10231                         return;
10232                 }
10233         }
10234
10235         /* set to report FD ID by default */
10236         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10237         entry.action.rx_queue = res->queue_id;
10238         entry.soft_id = res->fd_id_value;
10239         if (!strcmp(res->ops, "add"))
10240                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10241                                              RTE_ETH_FILTER_ADD, &entry);
10242         else if (!strcmp(res->ops, "del"))
10243                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10244                                              RTE_ETH_FILTER_DELETE, &entry);
10245         else
10246                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10247                                              RTE_ETH_FILTER_UPDATE, &entry);
10248         if (ret < 0)
10249                 printf("flow director programming error: (%s)\n",
10250                         strerror(-ret));
10251 }
10252
10253 cmdline_parse_token_string_t cmd_flow_director_filter =
10254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10255                                  flow_director_filter, "flow_director_filter");
10256 cmdline_parse_token_num_t cmd_flow_director_port_id =
10257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10258                               port_id, UINT16);
10259 cmdline_parse_token_string_t cmd_flow_director_ops =
10260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10261                                  ops, "add#del#update");
10262 cmdline_parse_token_string_t cmd_flow_director_flow =
10263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10264                                  flow, "flow");
10265 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10267                 flow_type, NULL);
10268 cmdline_parse_token_string_t cmd_flow_director_ether =
10269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10270                                  ether, "ether");
10271 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10272         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10273                               ether_type, UINT16);
10274 cmdline_parse_token_string_t cmd_flow_director_src =
10275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10276                                  src, "src");
10277 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10278         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10279                                  ip_src);
10280 cmdline_parse_token_num_t cmd_flow_director_port_src =
10281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10282                               port_src, UINT16);
10283 cmdline_parse_token_string_t cmd_flow_director_dst =
10284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10285                                  dst, "dst");
10286 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10287         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10288                                  ip_dst);
10289 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10290         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10291                               port_dst, UINT16);
10292 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10294                                   verify_tag, "verify_tag");
10295 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10296         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10297                               verify_tag_value, UINT32);
10298 cmdline_parse_token_string_t cmd_flow_director_tos =
10299         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10300                                  tos, "tos");
10301 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10302         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10303                               tos_value, UINT8);
10304 cmdline_parse_token_string_t cmd_flow_director_proto =
10305         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10306                                  proto, "proto");
10307 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10308         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10309                               proto_value, UINT8);
10310 cmdline_parse_token_string_t cmd_flow_director_ttl =
10311         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10312                                  ttl, "ttl");
10313 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10314         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10315                               ttl_value, UINT8);
10316 cmdline_parse_token_string_t cmd_flow_director_vlan =
10317         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10318                                  vlan, "vlan");
10319 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10320         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10321                               vlan_value, UINT16);
10322 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10323         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10324                                  flexbytes, "flexbytes");
10325 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10326         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10327                               flexbytes_value, NULL);
10328 cmdline_parse_token_string_t cmd_flow_director_drop =
10329         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10330                                  drop, "drop#fwd");
10331 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10333                               pf_vf, NULL);
10334 cmdline_parse_token_string_t cmd_flow_director_queue =
10335         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10336                                  queue, "queue");
10337 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10338         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10339                               queue_id, UINT16);
10340 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10342                                  fd_id, "fd_id");
10343 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10344         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10345                               fd_id_value, UINT32);
10346
10347 cmdline_parse_token_string_t cmd_flow_director_mode =
10348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10349                                  mode, "mode");
10350 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10351         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10352                                  mode_value, "IP");
10353 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10355                                  mode_value, "MAC-VLAN");
10356 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10357         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10358                                  mode_value, "Tunnel");
10359 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10360         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10361                                  mode_value, "raw");
10362 cmdline_parse_token_string_t cmd_flow_director_mac =
10363         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10364                                  mac, "mac");
10365 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10366         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10367                                     mac_addr);
10368 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10369         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10370                                  tunnel, "tunnel");
10371 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10372         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10373                                  tunnel_type, "NVGRE#VxLAN");
10374 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10375         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10376                                  tunnel_id, "tunnel-id");
10377 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10378         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10379                               tunnel_id_value, UINT32);
10380 cmdline_parse_token_string_t cmd_flow_director_packet =
10381         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10382                                  packet, "packet");
10383 cmdline_parse_token_string_t cmd_flow_director_filepath =
10384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10385                                  filepath, NULL);
10386
10387 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10388         .f = cmd_flow_director_filter_parsed,
10389         .data = NULL,
10390         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10391                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10392                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10393                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10394                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10395                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10396                 "fd_id <fd_id_value>: "
10397                 "Add or delete an ip flow director entry on NIC",
10398         .tokens = {
10399                 (void *)&cmd_flow_director_filter,
10400                 (void *)&cmd_flow_director_port_id,
10401                 (void *)&cmd_flow_director_mode,
10402                 (void *)&cmd_flow_director_mode_ip,
10403                 (void *)&cmd_flow_director_ops,
10404                 (void *)&cmd_flow_director_flow,
10405                 (void *)&cmd_flow_director_flow_type,
10406                 (void *)&cmd_flow_director_src,
10407                 (void *)&cmd_flow_director_ip_src,
10408                 (void *)&cmd_flow_director_dst,
10409                 (void *)&cmd_flow_director_ip_dst,
10410                 (void *)&cmd_flow_director_tos,
10411                 (void *)&cmd_flow_director_tos_value,
10412                 (void *)&cmd_flow_director_proto,
10413                 (void *)&cmd_flow_director_proto_value,
10414                 (void *)&cmd_flow_director_ttl,
10415                 (void *)&cmd_flow_director_ttl_value,
10416                 (void *)&cmd_flow_director_vlan,
10417                 (void *)&cmd_flow_director_vlan_value,
10418                 (void *)&cmd_flow_director_flexbytes,
10419                 (void *)&cmd_flow_director_flexbytes_value,
10420                 (void *)&cmd_flow_director_drop,
10421                 (void *)&cmd_flow_director_pf_vf,
10422                 (void *)&cmd_flow_director_queue,
10423                 (void *)&cmd_flow_director_queue_id,
10424                 (void *)&cmd_flow_director_fd_id,
10425                 (void *)&cmd_flow_director_fd_id_value,
10426                 NULL,
10427         },
10428 };
10429
10430 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10431         .f = cmd_flow_director_filter_parsed,
10432         .data = NULL,
10433         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10434                 "director entry on NIC",
10435         .tokens = {
10436                 (void *)&cmd_flow_director_filter,
10437                 (void *)&cmd_flow_director_port_id,
10438                 (void *)&cmd_flow_director_mode,
10439                 (void *)&cmd_flow_director_mode_ip,
10440                 (void *)&cmd_flow_director_ops,
10441                 (void *)&cmd_flow_director_flow,
10442                 (void *)&cmd_flow_director_flow_type,
10443                 (void *)&cmd_flow_director_src,
10444                 (void *)&cmd_flow_director_ip_src,
10445                 (void *)&cmd_flow_director_port_src,
10446                 (void *)&cmd_flow_director_dst,
10447                 (void *)&cmd_flow_director_ip_dst,
10448                 (void *)&cmd_flow_director_port_dst,
10449                 (void *)&cmd_flow_director_tos,
10450                 (void *)&cmd_flow_director_tos_value,
10451                 (void *)&cmd_flow_director_ttl,
10452                 (void *)&cmd_flow_director_ttl_value,
10453                 (void *)&cmd_flow_director_vlan,
10454                 (void *)&cmd_flow_director_vlan_value,
10455                 (void *)&cmd_flow_director_flexbytes,
10456                 (void *)&cmd_flow_director_flexbytes_value,
10457                 (void *)&cmd_flow_director_drop,
10458                 (void *)&cmd_flow_director_pf_vf,
10459                 (void *)&cmd_flow_director_queue,
10460                 (void *)&cmd_flow_director_queue_id,
10461                 (void *)&cmd_flow_director_fd_id,
10462                 (void *)&cmd_flow_director_fd_id_value,
10463                 NULL,
10464         },
10465 };
10466
10467 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10468         .f = cmd_flow_director_filter_parsed,
10469         .data = NULL,
10470         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10471                 "director entry on NIC",
10472         .tokens = {
10473                 (void *)&cmd_flow_director_filter,
10474                 (void *)&cmd_flow_director_port_id,
10475                 (void *)&cmd_flow_director_mode,
10476                 (void *)&cmd_flow_director_mode_ip,
10477                 (void *)&cmd_flow_director_ops,
10478                 (void *)&cmd_flow_director_flow,
10479                 (void *)&cmd_flow_director_flow_type,
10480                 (void *)&cmd_flow_director_src,
10481                 (void *)&cmd_flow_director_ip_src,
10482                 (void *)&cmd_flow_director_port_dst,
10483                 (void *)&cmd_flow_director_dst,
10484                 (void *)&cmd_flow_director_ip_dst,
10485                 (void *)&cmd_flow_director_port_dst,
10486                 (void *)&cmd_flow_director_verify_tag,
10487                 (void *)&cmd_flow_director_verify_tag_value,
10488                 (void *)&cmd_flow_director_tos,
10489                 (void *)&cmd_flow_director_tos_value,
10490                 (void *)&cmd_flow_director_ttl,
10491                 (void *)&cmd_flow_director_ttl_value,
10492                 (void *)&cmd_flow_director_vlan,
10493                 (void *)&cmd_flow_director_vlan_value,
10494                 (void *)&cmd_flow_director_flexbytes,
10495                 (void *)&cmd_flow_director_flexbytes_value,
10496                 (void *)&cmd_flow_director_drop,
10497                 (void *)&cmd_flow_director_pf_vf,
10498                 (void *)&cmd_flow_director_queue,
10499                 (void *)&cmd_flow_director_queue_id,
10500                 (void *)&cmd_flow_director_fd_id,
10501                 (void *)&cmd_flow_director_fd_id_value,
10502                 NULL,
10503         },
10504 };
10505
10506 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10507         .f = cmd_flow_director_filter_parsed,
10508         .data = NULL,
10509         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10510                 "director entry on NIC",
10511         .tokens = {
10512                 (void *)&cmd_flow_director_filter,
10513                 (void *)&cmd_flow_director_port_id,
10514                 (void *)&cmd_flow_director_mode,
10515                 (void *)&cmd_flow_director_mode_ip,
10516                 (void *)&cmd_flow_director_ops,
10517                 (void *)&cmd_flow_director_flow,
10518                 (void *)&cmd_flow_director_flow_type,
10519                 (void *)&cmd_flow_director_ether,
10520                 (void *)&cmd_flow_director_ether_type,
10521                 (void *)&cmd_flow_director_flexbytes,
10522                 (void *)&cmd_flow_director_flexbytes_value,
10523                 (void *)&cmd_flow_director_drop,
10524                 (void *)&cmd_flow_director_pf_vf,
10525                 (void *)&cmd_flow_director_queue,
10526                 (void *)&cmd_flow_director_queue_id,
10527                 (void *)&cmd_flow_director_fd_id,
10528                 (void *)&cmd_flow_director_fd_id_value,
10529                 NULL,
10530         },
10531 };
10532
10533 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10534         .f = cmd_flow_director_filter_parsed,
10535         .data = NULL,
10536         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10537                 "director entry on NIC",
10538         .tokens = {
10539                 (void *)&cmd_flow_director_filter,
10540                 (void *)&cmd_flow_director_port_id,
10541                 (void *)&cmd_flow_director_mode,
10542                 (void *)&cmd_flow_director_mode_mac_vlan,
10543                 (void *)&cmd_flow_director_ops,
10544                 (void *)&cmd_flow_director_mac,
10545                 (void *)&cmd_flow_director_mac_addr,
10546                 (void *)&cmd_flow_director_vlan,
10547                 (void *)&cmd_flow_director_vlan_value,
10548                 (void *)&cmd_flow_director_flexbytes,
10549                 (void *)&cmd_flow_director_flexbytes_value,
10550                 (void *)&cmd_flow_director_drop,
10551                 (void *)&cmd_flow_director_queue,
10552                 (void *)&cmd_flow_director_queue_id,
10553                 (void *)&cmd_flow_director_fd_id,
10554                 (void *)&cmd_flow_director_fd_id_value,
10555                 NULL,
10556         },
10557 };
10558
10559 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10560         .f = cmd_flow_director_filter_parsed,
10561         .data = NULL,
10562         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10563                 "director entry on NIC",
10564         .tokens = {
10565                 (void *)&cmd_flow_director_filter,
10566                 (void *)&cmd_flow_director_port_id,
10567                 (void *)&cmd_flow_director_mode,
10568                 (void *)&cmd_flow_director_mode_tunnel,
10569                 (void *)&cmd_flow_director_ops,
10570                 (void *)&cmd_flow_director_mac,
10571                 (void *)&cmd_flow_director_mac_addr,
10572                 (void *)&cmd_flow_director_vlan,
10573                 (void *)&cmd_flow_director_vlan_value,
10574                 (void *)&cmd_flow_director_tunnel,
10575                 (void *)&cmd_flow_director_tunnel_type,
10576                 (void *)&cmd_flow_director_tunnel_id,
10577                 (void *)&cmd_flow_director_tunnel_id_value,
10578                 (void *)&cmd_flow_director_flexbytes,
10579                 (void *)&cmd_flow_director_flexbytes_value,
10580                 (void *)&cmd_flow_director_drop,
10581                 (void *)&cmd_flow_director_queue,
10582                 (void *)&cmd_flow_director_queue_id,
10583                 (void *)&cmd_flow_director_fd_id,
10584                 (void *)&cmd_flow_director_fd_id_value,
10585                 NULL,
10586         },
10587 };
10588
10589 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10590         .f = cmd_flow_director_filter_parsed,
10591         .data = NULL,
10592         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10593                 "director entry on NIC",
10594         .tokens = {
10595                 (void *)&cmd_flow_director_filter,
10596                 (void *)&cmd_flow_director_port_id,
10597                 (void *)&cmd_flow_director_mode,
10598                 (void *)&cmd_flow_director_mode_raw,
10599                 (void *)&cmd_flow_director_ops,
10600                 (void *)&cmd_flow_director_flow,
10601                 (void *)&cmd_flow_director_flow_type,
10602                 (void *)&cmd_flow_director_drop,
10603                 (void *)&cmd_flow_director_queue,
10604                 (void *)&cmd_flow_director_queue_id,
10605                 (void *)&cmd_flow_director_fd_id,
10606                 (void *)&cmd_flow_director_fd_id_value,
10607                 (void *)&cmd_flow_director_packet,
10608                 (void *)&cmd_flow_director_filepath,
10609                 NULL,
10610         },
10611 };
10612
10613 struct cmd_flush_flow_director_result {
10614         cmdline_fixed_string_t flush_flow_director;
10615         portid_t port_id;
10616 };
10617
10618 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10619         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10620                                  flush_flow_director, "flush_flow_director");
10621 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10622         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10623                               port_id, UINT16);
10624
10625 static void
10626 cmd_flush_flow_director_parsed(void *parsed_result,
10627                           __attribute__((unused)) struct cmdline *cl,
10628                           __attribute__((unused)) void *data)
10629 {
10630         struct cmd_flow_director_result *res = parsed_result;
10631         int ret = 0;
10632
10633         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10634         if (ret < 0) {
10635                 printf("flow director is not supported on port %u.\n",
10636                         res->port_id);
10637                 return;
10638         }
10639
10640         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10641                         RTE_ETH_FILTER_FLUSH, NULL);
10642         if (ret < 0)
10643                 printf("flow director table flushing error: (%s)\n",
10644                         strerror(-ret));
10645 }
10646
10647 cmdline_parse_inst_t cmd_flush_flow_director = {
10648         .f = cmd_flush_flow_director_parsed,
10649         .data = NULL,
10650         .help_str = "flush_flow_director <port_id>: "
10651                 "Flush all flow director entries of a device on NIC",
10652         .tokens = {
10653                 (void *)&cmd_flush_flow_director_flush,
10654                 (void *)&cmd_flush_flow_director_port_id,
10655                 NULL,
10656         },
10657 };
10658
10659 /* *** deal with flow director mask *** */
10660 struct cmd_flow_director_mask_result {
10661         cmdline_fixed_string_t flow_director_mask;
10662         portid_t port_id;
10663         cmdline_fixed_string_t mode;
10664         cmdline_fixed_string_t mode_value;
10665         cmdline_fixed_string_t vlan;
10666         uint16_t vlan_mask;
10667         cmdline_fixed_string_t src_mask;
10668         cmdline_ipaddr_t ipv4_src;
10669         cmdline_ipaddr_t ipv6_src;
10670         uint16_t port_src;
10671         cmdline_fixed_string_t dst_mask;
10672         cmdline_ipaddr_t ipv4_dst;
10673         cmdline_ipaddr_t ipv6_dst;
10674         uint16_t port_dst;
10675         cmdline_fixed_string_t mac;
10676         uint8_t mac_addr_byte_mask;
10677         cmdline_fixed_string_t tunnel_id;
10678         uint32_t tunnel_id_mask;
10679         cmdline_fixed_string_t tunnel_type;
10680         uint8_t tunnel_type_mask;
10681 };
10682
10683 static void
10684 cmd_flow_director_mask_parsed(void *parsed_result,
10685                           __attribute__((unused)) struct cmdline *cl,
10686                           __attribute__((unused)) void *data)
10687 {
10688         struct cmd_flow_director_mask_result *res = parsed_result;
10689         struct rte_eth_fdir_masks *mask;
10690         struct rte_port *port;
10691
10692         if (res->port_id > nb_ports) {
10693                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10694                 return;
10695         }
10696
10697         port = &ports[res->port_id];
10698         /** Check if the port is not started **/
10699         if (port->port_status != RTE_PORT_STOPPED) {
10700                 printf("Please stop port %d first\n", res->port_id);
10701                 return;
10702         }
10703
10704         mask = &port->dev_conf.fdir_conf.mask;
10705
10706         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10707                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10708                         printf("Please set mode to MAC-VLAN.\n");
10709                         return;
10710                 }
10711
10712                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10713         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10714                 if (strcmp(res->mode_value, "Tunnel")) {
10715                         printf("Please set mode to Tunnel.\n");
10716                         return;
10717                 }
10718
10719                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10720                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10721                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10722                 mask->tunnel_type_mask = res->tunnel_type_mask;
10723         } else {
10724                 if (strcmp(res->mode_value, "IP")) {
10725                         printf("Please set mode to IP.\n");
10726                         return;
10727                 }
10728
10729                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10730                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10731                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10732                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10733                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10734                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10735                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10736         }
10737
10738         cmd_reconfig_device_queue(res->port_id, 1, 1);
10739 }
10740
10741 cmdline_parse_token_string_t cmd_flow_director_mask =
10742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10743                                  flow_director_mask, "flow_director_mask");
10744 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10745         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10746                               port_id, UINT16);
10747 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10749                                  vlan, "vlan");
10750 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10751         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10752                               vlan_mask, UINT16);
10753 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10755                                  src_mask, "src_mask");
10756 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10757         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10758                                  ipv4_src);
10759 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10760         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10761                                  ipv6_src);
10762 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10763         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10764                               port_src, UINT16);
10765 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10767                                  dst_mask, "dst_mask");
10768 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10769         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10770                                  ipv4_dst);
10771 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10772         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10773                                  ipv6_dst);
10774 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10775         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10776                               port_dst, UINT16);
10777
10778 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10779         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10780                                  mode, "mode");
10781 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10782         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10783                                  mode_value, "IP");
10784 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10785         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10786                                  mode_value, "MAC-VLAN");
10787 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10788         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10789                                  mode_value, "Tunnel");
10790 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10791         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10792                                  mac, "mac");
10793 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10794         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10795                               mac_addr_byte_mask, UINT8);
10796 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10797         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10798                                  tunnel_type, "tunnel-type");
10799 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10800         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10801                               tunnel_type_mask, UINT8);
10802 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10803         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10804                                  tunnel_id, "tunnel-id");
10805 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10806         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10807                               tunnel_id_mask, UINT32);
10808
10809 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10810         .f = cmd_flow_director_mask_parsed,
10811         .data = NULL,
10812         .help_str = "flow_director_mask ... : "
10813                 "Set IP mode flow director's mask on NIC",
10814         .tokens = {
10815                 (void *)&cmd_flow_director_mask,
10816                 (void *)&cmd_flow_director_mask_port_id,
10817                 (void *)&cmd_flow_director_mask_mode,
10818                 (void *)&cmd_flow_director_mask_mode_ip,
10819                 (void *)&cmd_flow_director_mask_vlan,
10820                 (void *)&cmd_flow_director_mask_vlan_value,
10821                 (void *)&cmd_flow_director_mask_src,
10822                 (void *)&cmd_flow_director_mask_ipv4_src,
10823                 (void *)&cmd_flow_director_mask_ipv6_src,
10824                 (void *)&cmd_flow_director_mask_port_src,
10825                 (void *)&cmd_flow_director_mask_dst,
10826                 (void *)&cmd_flow_director_mask_ipv4_dst,
10827                 (void *)&cmd_flow_director_mask_ipv6_dst,
10828                 (void *)&cmd_flow_director_mask_port_dst,
10829                 NULL,
10830         },
10831 };
10832
10833 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10834         .f = cmd_flow_director_mask_parsed,
10835         .data = NULL,
10836         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10837                 "flow director's mask on NIC",
10838         .tokens = {
10839                 (void *)&cmd_flow_director_mask,
10840                 (void *)&cmd_flow_director_mask_port_id,
10841                 (void *)&cmd_flow_director_mask_mode,
10842                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10843                 (void *)&cmd_flow_director_mask_vlan,
10844                 (void *)&cmd_flow_director_mask_vlan_value,
10845                 NULL,
10846         },
10847 };
10848
10849 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10850         .f = cmd_flow_director_mask_parsed,
10851         .data = NULL,
10852         .help_str = "flow_director_mask ... : Set tunnel mode "
10853                 "flow director's mask on NIC",
10854         .tokens = {
10855                 (void *)&cmd_flow_director_mask,
10856                 (void *)&cmd_flow_director_mask_port_id,
10857                 (void *)&cmd_flow_director_mask_mode,
10858                 (void *)&cmd_flow_director_mask_mode_tunnel,
10859                 (void *)&cmd_flow_director_mask_vlan,
10860                 (void *)&cmd_flow_director_mask_vlan_value,
10861                 (void *)&cmd_flow_director_mask_mac,
10862                 (void *)&cmd_flow_director_mask_mac_value,
10863                 (void *)&cmd_flow_director_mask_tunnel_type,
10864                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10865                 (void *)&cmd_flow_director_mask_tunnel_id,
10866                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10867                 NULL,
10868         },
10869 };
10870
10871 /* *** deal with flow director mask on flexible payload *** */
10872 struct cmd_flow_director_flex_mask_result {
10873         cmdline_fixed_string_t flow_director_flexmask;
10874         portid_t port_id;
10875         cmdline_fixed_string_t flow;
10876         cmdline_fixed_string_t flow_type;
10877         cmdline_fixed_string_t mask;
10878 };
10879
10880 static void
10881 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10882                           __attribute__((unused)) struct cmdline *cl,
10883                           __attribute__((unused)) void *data)
10884 {
10885         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10886         struct rte_eth_fdir_info fdir_info;
10887         struct rte_eth_fdir_flex_mask flex_mask;
10888         struct rte_port *port;
10889         uint32_t flow_type_mask;
10890         uint16_t i;
10891         int ret;
10892
10893         if (res->port_id > nb_ports) {
10894                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10895                 return;
10896         }
10897
10898         port = &ports[res->port_id];
10899         /** Check if the port is not started **/
10900         if (port->port_status != RTE_PORT_STOPPED) {
10901                 printf("Please stop port %d first\n", res->port_id);
10902                 return;
10903         }
10904
10905         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10906         ret = parse_flexbytes(res->mask,
10907                         flex_mask.mask,
10908                         RTE_ETH_FDIR_MAX_FLEXLEN);
10909         if (ret < 0) {
10910                 printf("error: Cannot parse mask input.\n");
10911                 return;
10912         }
10913
10914         memset(&fdir_info, 0, sizeof(fdir_info));
10915         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10916                                 RTE_ETH_FILTER_INFO, &fdir_info);
10917         if (ret < 0) {
10918                 printf("Cannot get FDir filter info\n");
10919                 return;
10920         }
10921
10922         if (!strcmp(res->flow_type, "none")) {
10923                 /* means don't specify the flow type */
10924                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10925                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10926                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10927                                0, sizeof(struct rte_eth_fdir_flex_mask));
10928                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10929                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10930                                  &flex_mask,
10931                                  sizeof(struct rte_eth_fdir_flex_mask));
10932                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10933                 return;
10934         }
10935         flow_type_mask = fdir_info.flow_types_mask[0];
10936         if (!strcmp(res->flow_type, "all")) {
10937                 if (!flow_type_mask) {
10938                         printf("No flow type supported\n");
10939                         return;
10940                 }
10941                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10942                         if (flow_type_mask & (1 << i)) {
10943                                 flex_mask.flow_type = i;
10944                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10945                         }
10946                 }
10947                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10948                 return;
10949         }
10950         flex_mask.flow_type = str2flowtype(res->flow_type);
10951         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10952                 printf("Flow type %s not supported on port %d\n",
10953                                 res->flow_type, res->port_id);
10954                 return;
10955         }
10956         fdir_set_flex_mask(res->port_id, &flex_mask);
10957         cmd_reconfig_device_queue(res->port_id, 1, 1);
10958 }
10959
10960 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10961         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10962                                  flow_director_flexmask,
10963                                  "flow_director_flex_mask");
10964 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10965         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10966                               port_id, UINT16);
10967 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10968         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10969                                  flow, "flow");
10970 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10971         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10972                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10973                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10974 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10975         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10976                                  mask, NULL);
10977
10978 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10979         .f = cmd_flow_director_flex_mask_parsed,
10980         .data = NULL,
10981         .help_str = "flow_director_flex_mask ... : "
10982                 "Set flow director's flex mask on NIC",
10983         .tokens = {
10984                 (void *)&cmd_flow_director_flexmask,
10985                 (void *)&cmd_flow_director_flexmask_port_id,
10986                 (void *)&cmd_flow_director_flexmask_flow,
10987                 (void *)&cmd_flow_director_flexmask_flow_type,
10988                 (void *)&cmd_flow_director_flexmask_mask,
10989                 NULL,
10990         },
10991 };
10992
10993 /* *** deal with flow director flexible payload configuration *** */
10994 struct cmd_flow_director_flexpayload_result {
10995         cmdline_fixed_string_t flow_director_flexpayload;
10996         portid_t port_id;
10997         cmdline_fixed_string_t payload_layer;
10998         cmdline_fixed_string_t payload_cfg;
10999 };
11000
11001 static inline int
11002 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11003 {
11004         char s[256];
11005         const char *p, *p0 = q_arg;
11006         char *end;
11007         unsigned long int_fld;
11008         char *str_fld[max_num];
11009         int i;
11010         unsigned size;
11011         int ret = -1;
11012
11013         p = strchr(p0, '(');
11014         if (p == NULL)
11015                 return -1;
11016         ++p;
11017         p0 = strchr(p, ')');
11018         if (p0 == NULL)
11019                 return -1;
11020
11021         size = p0 - p;
11022         if (size >= sizeof(s))
11023                 return -1;
11024
11025         snprintf(s, sizeof(s), "%.*s", size, p);
11026         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11027         if (ret < 0 || ret > max_num)
11028                 return -1;
11029         for (i = 0; i < ret; i++) {
11030                 errno = 0;
11031                 int_fld = strtoul(str_fld[i], &end, 0);
11032                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11033                         return -1;
11034                 offsets[i] = (uint16_t)int_fld;
11035         }
11036         return ret;
11037 }
11038
11039 static void
11040 cmd_flow_director_flxpld_parsed(void *parsed_result,
11041                           __attribute__((unused)) struct cmdline *cl,
11042                           __attribute__((unused)) void *data)
11043 {
11044         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11045         struct rte_eth_flex_payload_cfg flex_cfg;
11046         struct rte_port *port;
11047         int ret = 0;
11048
11049         if (res->port_id > nb_ports) {
11050                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11051                 return;
11052         }
11053
11054         port = &ports[res->port_id];
11055         /** Check if the port is not started **/
11056         if (port->port_status != RTE_PORT_STOPPED) {
11057                 printf("Please stop port %d first\n", res->port_id);
11058                 return;
11059         }
11060
11061         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11062
11063         if (!strcmp(res->payload_layer, "raw"))
11064                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11065         else if (!strcmp(res->payload_layer, "l2"))
11066                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11067         else if (!strcmp(res->payload_layer, "l3"))
11068                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11069         else if (!strcmp(res->payload_layer, "l4"))
11070                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11071
11072         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11073                             RTE_ETH_FDIR_MAX_FLEXLEN);
11074         if (ret < 0) {
11075                 printf("error: Cannot parse flex payload input.\n");
11076                 return;
11077         }
11078
11079         fdir_set_flex_payload(res->port_id, &flex_cfg);
11080         cmd_reconfig_device_queue(res->port_id, 1, 1);
11081 }
11082
11083 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11084         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11085                                  flow_director_flexpayload,
11086                                  "flow_director_flex_payload");
11087 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11088         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11089                               port_id, UINT16);
11090 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11091         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11092                                  payload_layer, "raw#l2#l3#l4");
11093 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11094         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11095                                  payload_cfg, NULL);
11096
11097 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11098         .f = cmd_flow_director_flxpld_parsed,
11099         .data = NULL,
11100         .help_str = "flow_director_flexpayload ... : "
11101                 "Set flow director's flex payload on NIC",
11102         .tokens = {
11103                 (void *)&cmd_flow_director_flexpayload,
11104                 (void *)&cmd_flow_director_flexpayload_port_id,
11105                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11106                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11107                 NULL,
11108         },
11109 };
11110
11111 /* Generic flow interface command. */
11112 extern cmdline_parse_inst_t cmd_flow;
11113
11114 /* *** Classification Filters Control *** */
11115 /* *** Get symmetric hash enable per port *** */
11116 struct cmd_get_sym_hash_ena_per_port_result {
11117         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11118         portid_t port_id;
11119 };
11120
11121 static void
11122 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11123                                  __rte_unused struct cmdline *cl,
11124                                  __rte_unused void *data)
11125 {
11126         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11127         struct rte_eth_hash_filter_info info;
11128         int ret;
11129
11130         if (rte_eth_dev_filter_supported(res->port_id,
11131                                 RTE_ETH_FILTER_HASH) < 0) {
11132                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11133                                                         res->port_id);
11134                 return;
11135         }
11136
11137         memset(&info, 0, sizeof(info));
11138         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11139         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11140                                                 RTE_ETH_FILTER_GET, &info);
11141
11142         if (ret < 0) {
11143                 printf("Cannot get symmetric hash enable per port "
11144                                         "on port %u\n", res->port_id);
11145                 return;
11146         }
11147
11148         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11149                                 "enabled" : "disabled", res->port_id);
11150 }
11151
11152 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11153         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11154                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11155 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11156         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11157                 port_id, UINT16);
11158
11159 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11160         .f = cmd_get_sym_hash_per_port_parsed,
11161         .data = NULL,
11162         .help_str = "get_sym_hash_ena_per_port <port_id>",
11163         .tokens = {
11164                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11165                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11166                 NULL,
11167         },
11168 };
11169
11170 /* *** Set symmetric hash enable per port *** */
11171 struct cmd_set_sym_hash_ena_per_port_result {
11172         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11173         cmdline_fixed_string_t enable;
11174         portid_t port_id;
11175 };
11176
11177 static void
11178 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11179                                  __rte_unused struct cmdline *cl,
11180                                  __rte_unused void *data)
11181 {
11182         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11183         struct rte_eth_hash_filter_info info;
11184         int ret;
11185
11186         if (rte_eth_dev_filter_supported(res->port_id,
11187                                 RTE_ETH_FILTER_HASH) < 0) {
11188                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11189                                                         res->port_id);
11190                 return;
11191         }
11192
11193         memset(&info, 0, sizeof(info));
11194         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11195         if (!strcmp(res->enable, "enable"))
11196                 info.info.enable = 1;
11197         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11198                                         RTE_ETH_FILTER_SET, &info);
11199         if (ret < 0) {
11200                 printf("Cannot set symmetric hash enable per port on "
11201                                         "port %u\n", res->port_id);
11202                 return;
11203         }
11204         printf("Symmetric hash has been set to %s on port %u\n",
11205                                         res->enable, res->port_id);
11206 }
11207
11208 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11209         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11210                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11211 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11212         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11213                 port_id, UINT16);
11214 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11215         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11216                 enable, "enable#disable");
11217
11218 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11219         .f = cmd_set_sym_hash_per_port_parsed,
11220         .data = NULL,
11221         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11222         .tokens = {
11223                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11224                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11225                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11226                 NULL,
11227         },
11228 };
11229
11230 /* Get global config of hash function */
11231 struct cmd_get_hash_global_config_result {
11232         cmdline_fixed_string_t get_hash_global_config;
11233         portid_t port_id;
11234 };
11235
11236 static char *
11237 flowtype_to_str(uint16_t ftype)
11238 {
11239         uint16_t i;
11240         static struct {
11241                 char str[16];
11242                 uint16_t ftype;
11243         } ftype_table[] = {
11244                 {"ipv4", RTE_ETH_FLOW_IPV4},
11245                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11246                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11247                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11248                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11249                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11250                 {"ipv6", RTE_ETH_FLOW_IPV6},
11251                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11252                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11253                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11254                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11255                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11256                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11257                 {"port", RTE_ETH_FLOW_PORT},
11258                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11259                 {"geneve", RTE_ETH_FLOW_GENEVE},
11260                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11261         };
11262
11263         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11264                 if (ftype_table[i].ftype == ftype)
11265                         return ftype_table[i].str;
11266         }
11267
11268         return NULL;
11269 }
11270
11271 static void
11272 cmd_get_hash_global_config_parsed(void *parsed_result,
11273                                   __rte_unused struct cmdline *cl,
11274                                   __rte_unused void *data)
11275 {
11276         struct cmd_get_hash_global_config_result *res = parsed_result;
11277         struct rte_eth_hash_filter_info info;
11278         uint32_t idx, offset;
11279         uint16_t i;
11280         char *str;
11281         int ret;
11282
11283         if (rte_eth_dev_filter_supported(res->port_id,
11284                         RTE_ETH_FILTER_HASH) < 0) {
11285                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11286                                                         res->port_id);
11287                 return;
11288         }
11289
11290         memset(&info, 0, sizeof(info));
11291         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11292         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11293                                         RTE_ETH_FILTER_GET, &info);
11294         if (ret < 0) {
11295                 printf("Cannot get hash global configurations by port %d\n",
11296                                                         res->port_id);
11297                 return;
11298         }
11299
11300         switch (info.info.global_conf.hash_func) {
11301         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11302                 printf("Hash function is Toeplitz\n");
11303                 break;
11304         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11305                 printf("Hash function is Simple XOR\n");
11306                 break;
11307         default:
11308                 printf("Unknown hash function\n");
11309                 break;
11310         }
11311
11312         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11313                 idx = i / UINT32_BIT;
11314                 offset = i % UINT32_BIT;
11315                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11316                                                 (1UL << offset)))
11317                         continue;
11318                 str = flowtype_to_str(i);
11319                 if (!str)
11320                         continue;
11321                 printf("Symmetric hash is %s globally for flow type %s "
11322                                                         "by port %d\n",
11323                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11324                         (1UL << offset)) ? "enabled" : "disabled"), str,
11325                                                         res->port_id);
11326         }
11327 }
11328
11329 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11330         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11331                 get_hash_global_config, "get_hash_global_config");
11332 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11333         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11334                 port_id, UINT16);
11335
11336 cmdline_parse_inst_t cmd_get_hash_global_config = {
11337         .f = cmd_get_hash_global_config_parsed,
11338         .data = NULL,
11339         .help_str = "get_hash_global_config <port_id>",
11340         .tokens = {
11341                 (void *)&cmd_get_hash_global_config_all,
11342                 (void *)&cmd_get_hash_global_config_port_id,
11343                 NULL,
11344         },
11345 };
11346
11347 /* Set global config of hash function */
11348 struct cmd_set_hash_global_config_result {
11349         cmdline_fixed_string_t set_hash_global_config;
11350         portid_t port_id;
11351         cmdline_fixed_string_t hash_func;
11352         cmdline_fixed_string_t flow_type;
11353         cmdline_fixed_string_t enable;
11354 };
11355
11356 static void
11357 cmd_set_hash_global_config_parsed(void *parsed_result,
11358                                   __rte_unused struct cmdline *cl,
11359                                   __rte_unused void *data)
11360 {
11361         struct cmd_set_hash_global_config_result *res = parsed_result;
11362         struct rte_eth_hash_filter_info info;
11363         uint32_t ftype, idx, offset;
11364         int ret;
11365
11366         if (rte_eth_dev_filter_supported(res->port_id,
11367                                 RTE_ETH_FILTER_HASH) < 0) {
11368                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11369                                                         res->port_id);
11370                 return;
11371         }
11372         memset(&info, 0, sizeof(info));
11373         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11374         if (!strcmp(res->hash_func, "toeplitz"))
11375                 info.info.global_conf.hash_func =
11376                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11377         else if (!strcmp(res->hash_func, "simple_xor"))
11378                 info.info.global_conf.hash_func =
11379                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11380         else if (!strcmp(res->hash_func, "default"))
11381                 info.info.global_conf.hash_func =
11382                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11383
11384         ftype = str2flowtype(res->flow_type);
11385         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11386         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11387         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11388         if (!strcmp(res->enable, "enable"))
11389                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11390                                                 (1UL << offset);
11391         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11392                                         RTE_ETH_FILTER_SET, &info);
11393         if (ret < 0)
11394                 printf("Cannot set global hash configurations by port %d\n",
11395                                                         res->port_id);
11396         else
11397                 printf("Global hash configurations have been set "
11398                         "succcessfully by port %d\n", res->port_id);
11399 }
11400
11401 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11402         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11403                 set_hash_global_config, "set_hash_global_config");
11404 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11405         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11406                 port_id, UINT16);
11407 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11408         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11409                 hash_func, "toeplitz#simple_xor#default");
11410 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11411         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11412                 flow_type,
11413                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11414                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11415 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11416         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11417                 enable, "enable#disable");
11418
11419 cmdline_parse_inst_t cmd_set_hash_global_config = {
11420         .f = cmd_set_hash_global_config_parsed,
11421         .data = NULL,
11422         .help_str = "set_hash_global_config <port_id> "
11423                 "toeplitz|simple_xor|default "
11424                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11425                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11426                 "l2_payload enable|disable",
11427         .tokens = {
11428                 (void *)&cmd_set_hash_global_config_all,
11429                 (void *)&cmd_set_hash_global_config_port_id,
11430                 (void *)&cmd_set_hash_global_config_hash_func,
11431                 (void *)&cmd_set_hash_global_config_flow_type,
11432                 (void *)&cmd_set_hash_global_config_enable,
11433                 NULL,
11434         },
11435 };
11436
11437 /* Set hash input set */
11438 struct cmd_set_hash_input_set_result {
11439         cmdline_fixed_string_t set_hash_input_set;
11440         portid_t port_id;
11441         cmdline_fixed_string_t flow_type;
11442         cmdline_fixed_string_t inset_field;
11443         cmdline_fixed_string_t select;
11444 };
11445
11446 static enum rte_eth_input_set_field
11447 str2inset(char *string)
11448 {
11449         uint16_t i;
11450
11451         static const struct {
11452                 char str[32];
11453                 enum rte_eth_input_set_field inset;
11454         } inset_table[] = {
11455                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11456                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11457                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11458                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11459                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11460                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11461                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11462                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11463                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11464                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11465                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11466                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11467                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11468                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11469                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11470                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11471                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11472                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11473                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11474                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11475                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11476                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11477                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11478                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11479                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11480                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11481                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11482                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11483                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11484                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11485                 {"none", RTE_ETH_INPUT_SET_NONE},
11486         };
11487
11488         for (i = 0; i < RTE_DIM(inset_table); i++) {
11489                 if (!strcmp(string, inset_table[i].str))
11490                         return inset_table[i].inset;
11491         }
11492
11493         return RTE_ETH_INPUT_SET_UNKNOWN;
11494 }
11495
11496 static void
11497 cmd_set_hash_input_set_parsed(void *parsed_result,
11498                               __rte_unused struct cmdline *cl,
11499                               __rte_unused void *data)
11500 {
11501         struct cmd_set_hash_input_set_result *res = parsed_result;
11502         struct rte_eth_hash_filter_info info;
11503
11504         memset(&info, 0, sizeof(info));
11505         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11506         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11507         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11508         info.info.input_set_conf.inset_size = 1;
11509         if (!strcmp(res->select, "select"))
11510                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11511         else if (!strcmp(res->select, "add"))
11512                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11513         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11514                                 RTE_ETH_FILTER_SET, &info);
11515 }
11516
11517 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11518         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11519                 set_hash_input_set, "set_hash_input_set");
11520 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11521         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11522                 port_id, UINT16);
11523 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11524         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11525                 flow_type, NULL);
11526 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11527         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11528                 inset_field,
11529                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11530                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11531                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11532                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11533                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11534                 "fld-8th#none");
11535 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11536         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11537                 select, "select#add");
11538
11539 cmdline_parse_inst_t cmd_set_hash_input_set = {
11540         .f = cmd_set_hash_input_set_parsed,
11541         .data = NULL,
11542         .help_str = "set_hash_input_set <port_id> "
11543         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11544         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11545         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11546         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11547         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11548         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11549         "fld-7th|fld-8th|none select|add",
11550         .tokens = {
11551                 (void *)&cmd_set_hash_input_set_cmd,
11552                 (void *)&cmd_set_hash_input_set_port_id,
11553                 (void *)&cmd_set_hash_input_set_flow_type,
11554                 (void *)&cmd_set_hash_input_set_field,
11555                 (void *)&cmd_set_hash_input_set_select,
11556                 NULL,
11557         },
11558 };
11559
11560 /* Set flow director input set */
11561 struct cmd_set_fdir_input_set_result {
11562         cmdline_fixed_string_t set_fdir_input_set;
11563         portid_t port_id;
11564         cmdline_fixed_string_t flow_type;
11565         cmdline_fixed_string_t inset_field;
11566         cmdline_fixed_string_t select;
11567 };
11568
11569 static void
11570 cmd_set_fdir_input_set_parsed(void *parsed_result,
11571         __rte_unused struct cmdline *cl,
11572         __rte_unused void *data)
11573 {
11574         struct cmd_set_fdir_input_set_result *res = parsed_result;
11575         struct rte_eth_fdir_filter_info info;
11576
11577         memset(&info, 0, sizeof(info));
11578         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11579         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11580         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11581         info.info.input_set_conf.inset_size = 1;
11582         if (!strcmp(res->select, "select"))
11583                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11584         else if (!strcmp(res->select, "add"))
11585                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11586         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11587                 RTE_ETH_FILTER_SET, &info);
11588 }
11589
11590 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11591         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11592         set_fdir_input_set, "set_fdir_input_set");
11593 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11594         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11595         port_id, UINT16);
11596 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11597         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11598         flow_type,
11599         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11600         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11601 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11602         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11603         inset_field,
11604         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11605         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11606         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11607         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11608         "sctp-veri-tag#none");
11609 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11610         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11611         select, "select#add");
11612
11613 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11614         .f = cmd_set_fdir_input_set_parsed,
11615         .data = NULL,
11616         .help_str = "set_fdir_input_set <port_id> "
11617         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11618         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11619         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11620         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11621         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11622         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11623         "sctp-veri-tag|none select|add",
11624         .tokens = {
11625                 (void *)&cmd_set_fdir_input_set_cmd,
11626                 (void *)&cmd_set_fdir_input_set_port_id,
11627                 (void *)&cmd_set_fdir_input_set_flow_type,
11628                 (void *)&cmd_set_fdir_input_set_field,
11629                 (void *)&cmd_set_fdir_input_set_select,
11630                 NULL,
11631         },
11632 };
11633
11634 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11635 struct cmd_mcast_addr_result {
11636         cmdline_fixed_string_t mcast_addr_cmd;
11637         cmdline_fixed_string_t what;
11638         uint16_t port_num;
11639         struct ether_addr mc_addr;
11640 };
11641
11642 static void cmd_mcast_addr_parsed(void *parsed_result,
11643                 __attribute__((unused)) struct cmdline *cl,
11644                 __attribute__((unused)) void *data)
11645 {
11646         struct cmd_mcast_addr_result *res = parsed_result;
11647
11648         if (!is_multicast_ether_addr(&res->mc_addr)) {
11649                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11650                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11651                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11652                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11653                 return;
11654         }
11655         if (strcmp(res->what, "add") == 0)
11656                 mcast_addr_add(res->port_num, &res->mc_addr);
11657         else
11658                 mcast_addr_remove(res->port_num, &res->mc_addr);
11659 }
11660
11661 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11662         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11663                                  mcast_addr_cmd, "mcast_addr");
11664 cmdline_parse_token_string_t cmd_mcast_addr_what =
11665         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11666                                  "add#remove");
11667 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11668         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11669 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11670         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11671
11672 cmdline_parse_inst_t cmd_mcast_addr = {
11673         .f = cmd_mcast_addr_parsed,
11674         .data = (void *)0,
11675         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11676                 "Add/Remove multicast MAC address on port_id",
11677         .tokens = {
11678                 (void *)&cmd_mcast_addr_cmd,
11679                 (void *)&cmd_mcast_addr_what,
11680                 (void *)&cmd_mcast_addr_portnum,
11681                 (void *)&cmd_mcast_addr_addr,
11682                 NULL,
11683         },
11684 };
11685
11686 /* l2 tunnel config
11687  * only support E-tag now.
11688  */
11689
11690 /* Ether type config */
11691 struct cmd_config_l2_tunnel_eth_type_result {
11692         cmdline_fixed_string_t port;
11693         cmdline_fixed_string_t config;
11694         cmdline_fixed_string_t all;
11695         uint8_t id;
11696         cmdline_fixed_string_t l2_tunnel;
11697         cmdline_fixed_string_t l2_tunnel_type;
11698         cmdline_fixed_string_t eth_type;
11699         uint16_t eth_type_val;
11700 };
11701
11702 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11703         TOKEN_STRING_INITIALIZER
11704                 (struct cmd_config_l2_tunnel_eth_type_result,
11705                  port, "port");
11706 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11707         TOKEN_STRING_INITIALIZER
11708                 (struct cmd_config_l2_tunnel_eth_type_result,
11709                  config, "config");
11710 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11711         TOKEN_STRING_INITIALIZER
11712                 (struct cmd_config_l2_tunnel_eth_type_result,
11713                  all, "all");
11714 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11715         TOKEN_NUM_INITIALIZER
11716                 (struct cmd_config_l2_tunnel_eth_type_result,
11717                  id, UINT8);
11718 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11719         TOKEN_STRING_INITIALIZER
11720                 (struct cmd_config_l2_tunnel_eth_type_result,
11721                  l2_tunnel, "l2-tunnel");
11722 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11723         TOKEN_STRING_INITIALIZER
11724                 (struct cmd_config_l2_tunnel_eth_type_result,
11725                  l2_tunnel_type, "E-tag");
11726 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11727         TOKEN_STRING_INITIALIZER
11728                 (struct cmd_config_l2_tunnel_eth_type_result,
11729                  eth_type, "ether-type");
11730 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11731         TOKEN_NUM_INITIALIZER
11732                 (struct cmd_config_l2_tunnel_eth_type_result,
11733                  eth_type_val, UINT16);
11734
11735 static enum rte_eth_tunnel_type
11736 str2fdir_l2_tunnel_type(char *string)
11737 {
11738         uint32_t i = 0;
11739
11740         static const struct {
11741                 char str[32];
11742                 enum rte_eth_tunnel_type type;
11743         } l2_tunnel_type_str[] = {
11744                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11745         };
11746
11747         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11748                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11749                         return l2_tunnel_type_str[i].type;
11750         }
11751         return RTE_TUNNEL_TYPE_NONE;
11752 }
11753
11754 /* ether type config for all ports */
11755 static void
11756 cmd_config_l2_tunnel_eth_type_all_parsed
11757         (void *parsed_result,
11758          __attribute__((unused)) struct cmdline *cl,
11759          __attribute__((unused)) void *data)
11760 {
11761         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11762         struct rte_eth_l2_tunnel_conf entry;
11763         portid_t pid;
11764
11765         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11766         entry.ether_type = res->eth_type_val;
11767
11768         RTE_ETH_FOREACH_DEV(pid) {
11769                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11770         }
11771 }
11772
11773 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11774         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11775         .data = NULL,
11776         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11777         .tokens = {
11778                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11779                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11780                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11781                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11782                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11783                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11784                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11785                 NULL,
11786         },
11787 };
11788
11789 /* ether type config for a specific port */
11790 static void
11791 cmd_config_l2_tunnel_eth_type_specific_parsed(
11792         void *parsed_result,
11793         __attribute__((unused)) struct cmdline *cl,
11794         __attribute__((unused)) void *data)
11795 {
11796         struct cmd_config_l2_tunnel_eth_type_result *res =
11797                  parsed_result;
11798         struct rte_eth_l2_tunnel_conf entry;
11799
11800         if (port_id_is_invalid(res->id, ENABLED_WARN))
11801                 return;
11802
11803         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11804         entry.ether_type = res->eth_type_val;
11805
11806         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11807 }
11808
11809 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11810         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11811         .data = NULL,
11812         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11813         .tokens = {
11814                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11815                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11816                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11817                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11818                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11819                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11820                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11821                 NULL,
11822         },
11823 };
11824
11825 /* Enable/disable l2 tunnel */
11826 struct cmd_config_l2_tunnel_en_dis_result {
11827         cmdline_fixed_string_t port;
11828         cmdline_fixed_string_t config;
11829         cmdline_fixed_string_t all;
11830         uint8_t id;
11831         cmdline_fixed_string_t l2_tunnel;
11832         cmdline_fixed_string_t l2_tunnel_type;
11833         cmdline_fixed_string_t en_dis;
11834 };
11835
11836 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11837         TOKEN_STRING_INITIALIZER
11838                 (struct cmd_config_l2_tunnel_en_dis_result,
11839                  port, "port");
11840 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11841         TOKEN_STRING_INITIALIZER
11842                 (struct cmd_config_l2_tunnel_en_dis_result,
11843                  config, "config");
11844 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11845         TOKEN_STRING_INITIALIZER
11846                 (struct cmd_config_l2_tunnel_en_dis_result,
11847                  all, "all");
11848 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11849         TOKEN_NUM_INITIALIZER
11850                 (struct cmd_config_l2_tunnel_en_dis_result,
11851                  id, UINT8);
11852 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11853         TOKEN_STRING_INITIALIZER
11854                 (struct cmd_config_l2_tunnel_en_dis_result,
11855                  l2_tunnel, "l2-tunnel");
11856 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11857         TOKEN_STRING_INITIALIZER
11858                 (struct cmd_config_l2_tunnel_en_dis_result,
11859                  l2_tunnel_type, "E-tag");
11860 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11861         TOKEN_STRING_INITIALIZER
11862                 (struct cmd_config_l2_tunnel_en_dis_result,
11863                  en_dis, "enable#disable");
11864
11865 /* enable/disable l2 tunnel for all ports */
11866 static void
11867 cmd_config_l2_tunnel_en_dis_all_parsed(
11868         void *parsed_result,
11869         __attribute__((unused)) struct cmdline *cl,
11870         __attribute__((unused)) void *data)
11871 {
11872         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11873         struct rte_eth_l2_tunnel_conf entry;
11874         portid_t pid;
11875         uint8_t en;
11876
11877         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11878
11879         if (!strcmp("enable", res->en_dis))
11880                 en = 1;
11881         else
11882                 en = 0;
11883
11884         RTE_ETH_FOREACH_DEV(pid) {
11885                 rte_eth_dev_l2_tunnel_offload_set(pid,
11886                                                   &entry,
11887                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11888                                                   en);
11889         }
11890 }
11891
11892 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11893         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11894         .data = NULL,
11895         .help_str = "port config all l2-tunnel E-tag enable|disable",
11896         .tokens = {
11897                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11898                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11899                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11900                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11901                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11902                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11903                 NULL,
11904         },
11905 };
11906
11907 /* enable/disable l2 tunnel for a port */
11908 static void
11909 cmd_config_l2_tunnel_en_dis_specific_parsed(
11910         void *parsed_result,
11911         __attribute__((unused)) struct cmdline *cl,
11912         __attribute__((unused)) void *data)
11913 {
11914         struct cmd_config_l2_tunnel_en_dis_result *res =
11915                 parsed_result;
11916         struct rte_eth_l2_tunnel_conf entry;
11917
11918         if (port_id_is_invalid(res->id, ENABLED_WARN))
11919                 return;
11920
11921         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11922
11923         if (!strcmp("enable", res->en_dis))
11924                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11925                                                   &entry,
11926                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11927                                                   1);
11928         else
11929                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11930                                                   &entry,
11931                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11932                                                   0);
11933 }
11934
11935 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11936         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11937         .data = NULL,
11938         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11939         .tokens = {
11940                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11941                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11942                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11943                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11944                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11945                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11946                 NULL,
11947         },
11948 };
11949
11950 /* E-tag configuration */
11951
11952 /* Common result structure for all E-tag configuration */
11953 struct cmd_config_e_tag_result {
11954         cmdline_fixed_string_t e_tag;
11955         cmdline_fixed_string_t set;
11956         cmdline_fixed_string_t insertion;
11957         cmdline_fixed_string_t stripping;
11958         cmdline_fixed_string_t forwarding;
11959         cmdline_fixed_string_t filter;
11960         cmdline_fixed_string_t add;
11961         cmdline_fixed_string_t del;
11962         cmdline_fixed_string_t on;
11963         cmdline_fixed_string_t off;
11964         cmdline_fixed_string_t on_off;
11965         cmdline_fixed_string_t port_tag_id;
11966         uint32_t port_tag_id_val;
11967         cmdline_fixed_string_t e_tag_id;
11968         uint16_t e_tag_id_val;
11969         cmdline_fixed_string_t dst_pool;
11970         uint8_t dst_pool_val;
11971         cmdline_fixed_string_t port;
11972         portid_t port_id;
11973         cmdline_fixed_string_t vf;
11974         uint8_t vf_id;
11975 };
11976
11977 /* Common CLI fields for all E-tag configuration */
11978 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11979         TOKEN_STRING_INITIALIZER
11980                 (struct cmd_config_e_tag_result,
11981                  e_tag, "E-tag");
11982 cmdline_parse_token_string_t cmd_config_e_tag_set =
11983         TOKEN_STRING_INITIALIZER
11984                 (struct cmd_config_e_tag_result,
11985                  set, "set");
11986 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11987         TOKEN_STRING_INITIALIZER
11988                 (struct cmd_config_e_tag_result,
11989                  insertion, "insertion");
11990 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11991         TOKEN_STRING_INITIALIZER
11992                 (struct cmd_config_e_tag_result,
11993                  stripping, "stripping");
11994 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11995         TOKEN_STRING_INITIALIZER
11996                 (struct cmd_config_e_tag_result,
11997                  forwarding, "forwarding");
11998 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11999         TOKEN_STRING_INITIALIZER
12000                 (struct cmd_config_e_tag_result,
12001                  filter, "filter");
12002 cmdline_parse_token_string_t cmd_config_e_tag_add =
12003         TOKEN_STRING_INITIALIZER
12004                 (struct cmd_config_e_tag_result,
12005                  add, "add");
12006 cmdline_parse_token_string_t cmd_config_e_tag_del =
12007         TOKEN_STRING_INITIALIZER
12008                 (struct cmd_config_e_tag_result,
12009                  del, "del");
12010 cmdline_parse_token_string_t cmd_config_e_tag_on =
12011         TOKEN_STRING_INITIALIZER
12012                 (struct cmd_config_e_tag_result,
12013                  on, "on");
12014 cmdline_parse_token_string_t cmd_config_e_tag_off =
12015         TOKEN_STRING_INITIALIZER
12016                 (struct cmd_config_e_tag_result,
12017                  off, "off");
12018 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12019         TOKEN_STRING_INITIALIZER
12020                 (struct cmd_config_e_tag_result,
12021                  on_off, "on#off");
12022 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12023         TOKEN_STRING_INITIALIZER
12024                 (struct cmd_config_e_tag_result,
12025                  port_tag_id, "port-tag-id");
12026 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12027         TOKEN_NUM_INITIALIZER
12028                 (struct cmd_config_e_tag_result,
12029                  port_tag_id_val, UINT32);
12030 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12031         TOKEN_STRING_INITIALIZER
12032                 (struct cmd_config_e_tag_result,
12033                  e_tag_id, "e-tag-id");
12034 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12035         TOKEN_NUM_INITIALIZER
12036                 (struct cmd_config_e_tag_result,
12037                  e_tag_id_val, UINT16);
12038 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12039         TOKEN_STRING_INITIALIZER
12040                 (struct cmd_config_e_tag_result,
12041                  dst_pool, "dst-pool");
12042 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12043         TOKEN_NUM_INITIALIZER
12044                 (struct cmd_config_e_tag_result,
12045                  dst_pool_val, UINT8);
12046 cmdline_parse_token_string_t cmd_config_e_tag_port =
12047         TOKEN_STRING_INITIALIZER
12048                 (struct cmd_config_e_tag_result,
12049                  port, "port");
12050 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12051         TOKEN_NUM_INITIALIZER
12052                 (struct cmd_config_e_tag_result,
12053                  port_id, UINT16);
12054 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12055         TOKEN_STRING_INITIALIZER
12056                 (struct cmd_config_e_tag_result,
12057                  vf, "vf");
12058 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12059         TOKEN_NUM_INITIALIZER
12060                 (struct cmd_config_e_tag_result,
12061                  vf_id, UINT8);
12062
12063 /* E-tag insertion configuration */
12064 static void
12065 cmd_config_e_tag_insertion_en_parsed(
12066         void *parsed_result,
12067         __attribute__((unused)) struct cmdline *cl,
12068         __attribute__((unused)) void *data)
12069 {
12070         struct cmd_config_e_tag_result *res =
12071                 parsed_result;
12072         struct rte_eth_l2_tunnel_conf entry;
12073
12074         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12075                 return;
12076
12077         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12078         entry.tunnel_id = res->port_tag_id_val;
12079         entry.vf_id = res->vf_id;
12080         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12081                                           &entry,
12082                                           ETH_L2_TUNNEL_INSERTION_MASK,
12083                                           1);
12084 }
12085
12086 static void
12087 cmd_config_e_tag_insertion_dis_parsed(
12088         void *parsed_result,
12089         __attribute__((unused)) struct cmdline *cl,
12090         __attribute__((unused)) void *data)
12091 {
12092         struct cmd_config_e_tag_result *res =
12093                 parsed_result;
12094         struct rte_eth_l2_tunnel_conf entry;
12095
12096         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12097                 return;
12098
12099         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12100         entry.vf_id = res->vf_id;
12101
12102         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12103                                           &entry,
12104                                           ETH_L2_TUNNEL_INSERTION_MASK,
12105                                           0);
12106 }
12107
12108 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12109         .f = cmd_config_e_tag_insertion_en_parsed,
12110         .data = NULL,
12111         .help_str = "E-tag ... : E-tag insertion enable",
12112         .tokens = {
12113                 (void *)&cmd_config_e_tag_e_tag,
12114                 (void *)&cmd_config_e_tag_set,
12115                 (void *)&cmd_config_e_tag_insertion,
12116                 (void *)&cmd_config_e_tag_on,
12117                 (void *)&cmd_config_e_tag_port_tag_id,
12118                 (void *)&cmd_config_e_tag_port_tag_id_val,
12119                 (void *)&cmd_config_e_tag_port,
12120                 (void *)&cmd_config_e_tag_port_id,
12121                 (void *)&cmd_config_e_tag_vf,
12122                 (void *)&cmd_config_e_tag_vf_id,
12123                 NULL,
12124         },
12125 };
12126
12127 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12128         .f = cmd_config_e_tag_insertion_dis_parsed,
12129         .data = NULL,
12130         .help_str = "E-tag ... : E-tag insertion disable",
12131         .tokens = {
12132                 (void *)&cmd_config_e_tag_e_tag,
12133                 (void *)&cmd_config_e_tag_set,
12134                 (void *)&cmd_config_e_tag_insertion,
12135                 (void *)&cmd_config_e_tag_off,
12136                 (void *)&cmd_config_e_tag_port,
12137                 (void *)&cmd_config_e_tag_port_id,
12138                 (void *)&cmd_config_e_tag_vf,
12139                 (void *)&cmd_config_e_tag_vf_id,
12140                 NULL,
12141         },
12142 };
12143
12144 /* E-tag stripping configuration */
12145 static void
12146 cmd_config_e_tag_stripping_parsed(
12147         void *parsed_result,
12148         __attribute__((unused)) struct cmdline *cl,
12149         __attribute__((unused)) void *data)
12150 {
12151         struct cmd_config_e_tag_result *res =
12152                 parsed_result;
12153         struct rte_eth_l2_tunnel_conf entry;
12154
12155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12156                 return;
12157
12158         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12159
12160         if (!strcmp(res->on_off, "on"))
12161                 rte_eth_dev_l2_tunnel_offload_set
12162                         (res->port_id,
12163                          &entry,
12164                          ETH_L2_TUNNEL_STRIPPING_MASK,
12165                          1);
12166         else
12167                 rte_eth_dev_l2_tunnel_offload_set
12168                         (res->port_id,
12169                          &entry,
12170                          ETH_L2_TUNNEL_STRIPPING_MASK,
12171                          0);
12172 }
12173
12174 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12175         .f = cmd_config_e_tag_stripping_parsed,
12176         .data = NULL,
12177         .help_str = "E-tag ... : E-tag stripping enable/disable",
12178         .tokens = {
12179                 (void *)&cmd_config_e_tag_e_tag,
12180                 (void *)&cmd_config_e_tag_set,
12181                 (void *)&cmd_config_e_tag_stripping,
12182                 (void *)&cmd_config_e_tag_on_off,
12183                 (void *)&cmd_config_e_tag_port,
12184                 (void *)&cmd_config_e_tag_port_id,
12185                 NULL,
12186         },
12187 };
12188
12189 /* E-tag forwarding configuration */
12190 static void
12191 cmd_config_e_tag_forwarding_parsed(
12192         void *parsed_result,
12193         __attribute__((unused)) struct cmdline *cl,
12194         __attribute__((unused)) void *data)
12195 {
12196         struct cmd_config_e_tag_result *res = parsed_result;
12197         struct rte_eth_l2_tunnel_conf entry;
12198
12199         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12200                 return;
12201
12202         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12203
12204         if (!strcmp(res->on_off, "on"))
12205                 rte_eth_dev_l2_tunnel_offload_set
12206                         (res->port_id,
12207                          &entry,
12208                          ETH_L2_TUNNEL_FORWARDING_MASK,
12209                          1);
12210         else
12211                 rte_eth_dev_l2_tunnel_offload_set
12212                         (res->port_id,
12213                          &entry,
12214                          ETH_L2_TUNNEL_FORWARDING_MASK,
12215                          0);
12216 }
12217
12218 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12219         .f = cmd_config_e_tag_forwarding_parsed,
12220         .data = NULL,
12221         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12222         .tokens = {
12223                 (void *)&cmd_config_e_tag_e_tag,
12224                 (void *)&cmd_config_e_tag_set,
12225                 (void *)&cmd_config_e_tag_forwarding,
12226                 (void *)&cmd_config_e_tag_on_off,
12227                 (void *)&cmd_config_e_tag_port,
12228                 (void *)&cmd_config_e_tag_port_id,
12229                 NULL,
12230         },
12231 };
12232
12233 /* E-tag filter configuration */
12234 static void
12235 cmd_config_e_tag_filter_add_parsed(
12236         void *parsed_result,
12237         __attribute__((unused)) struct cmdline *cl,
12238         __attribute__((unused)) void *data)
12239 {
12240         struct cmd_config_e_tag_result *res = parsed_result;
12241         struct rte_eth_l2_tunnel_conf entry;
12242         int ret = 0;
12243
12244         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12245                 return;
12246
12247         if (res->e_tag_id_val > 0x3fff) {
12248                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12249                 return;
12250         }
12251
12252         ret = rte_eth_dev_filter_supported(res->port_id,
12253                                            RTE_ETH_FILTER_L2_TUNNEL);
12254         if (ret < 0) {
12255                 printf("E-tag filter is not supported on port %u.\n",
12256                        res->port_id);
12257                 return;
12258         }
12259
12260         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12261         entry.tunnel_id = res->e_tag_id_val;
12262         entry.pool = res->dst_pool_val;
12263
12264         ret = rte_eth_dev_filter_ctrl(res->port_id,
12265                                       RTE_ETH_FILTER_L2_TUNNEL,
12266                                       RTE_ETH_FILTER_ADD,
12267                                       &entry);
12268         if (ret < 0)
12269                 printf("E-tag filter programming error: (%s)\n",
12270                        strerror(-ret));
12271 }
12272
12273 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12274         .f = cmd_config_e_tag_filter_add_parsed,
12275         .data = NULL,
12276         .help_str = "E-tag ... : E-tag filter add",
12277         .tokens = {
12278                 (void *)&cmd_config_e_tag_e_tag,
12279                 (void *)&cmd_config_e_tag_set,
12280                 (void *)&cmd_config_e_tag_filter,
12281                 (void *)&cmd_config_e_tag_add,
12282                 (void *)&cmd_config_e_tag_e_tag_id,
12283                 (void *)&cmd_config_e_tag_e_tag_id_val,
12284                 (void *)&cmd_config_e_tag_dst_pool,
12285                 (void *)&cmd_config_e_tag_dst_pool_val,
12286                 (void *)&cmd_config_e_tag_port,
12287                 (void *)&cmd_config_e_tag_port_id,
12288                 NULL,
12289         },
12290 };
12291
12292 static void
12293 cmd_config_e_tag_filter_del_parsed(
12294         void *parsed_result,
12295         __attribute__((unused)) struct cmdline *cl,
12296         __attribute__((unused)) void *data)
12297 {
12298         struct cmd_config_e_tag_result *res = parsed_result;
12299         struct rte_eth_l2_tunnel_conf entry;
12300         int ret = 0;
12301
12302         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12303                 return;
12304
12305         if (res->e_tag_id_val > 0x3fff) {
12306                 printf("e-tag-id must be less than 0x3fff.\n");
12307                 return;
12308         }
12309
12310         ret = rte_eth_dev_filter_supported(res->port_id,
12311                                            RTE_ETH_FILTER_L2_TUNNEL);
12312         if (ret < 0) {
12313                 printf("E-tag filter is not supported on port %u.\n",
12314                        res->port_id);
12315                 return;
12316         }
12317
12318         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12319         entry.tunnel_id = res->e_tag_id_val;
12320
12321         ret = rte_eth_dev_filter_ctrl(res->port_id,
12322                                       RTE_ETH_FILTER_L2_TUNNEL,
12323                                       RTE_ETH_FILTER_DELETE,
12324                                       &entry);
12325         if (ret < 0)
12326                 printf("E-tag filter programming error: (%s)\n",
12327                        strerror(-ret));
12328 }
12329
12330 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12331         .f = cmd_config_e_tag_filter_del_parsed,
12332         .data = NULL,
12333         .help_str = "E-tag ... : E-tag filter delete",
12334         .tokens = {
12335                 (void *)&cmd_config_e_tag_e_tag,
12336                 (void *)&cmd_config_e_tag_set,
12337                 (void *)&cmd_config_e_tag_filter,
12338                 (void *)&cmd_config_e_tag_del,
12339                 (void *)&cmd_config_e_tag_e_tag_id,
12340                 (void *)&cmd_config_e_tag_e_tag_id_val,
12341                 (void *)&cmd_config_e_tag_port,
12342                 (void *)&cmd_config_e_tag_port_id,
12343                 NULL,
12344         },
12345 };
12346
12347 /* vf vlan anti spoof configuration */
12348
12349 /* Common result structure for vf vlan anti spoof */
12350 struct cmd_vf_vlan_anti_spoof_result {
12351         cmdline_fixed_string_t set;
12352         cmdline_fixed_string_t vf;
12353         cmdline_fixed_string_t vlan;
12354         cmdline_fixed_string_t antispoof;
12355         portid_t port_id;
12356         uint32_t vf_id;
12357         cmdline_fixed_string_t on_off;
12358 };
12359
12360 /* Common CLI fields for vf vlan anti spoof enable disable */
12361 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12362         TOKEN_STRING_INITIALIZER
12363                 (struct cmd_vf_vlan_anti_spoof_result,
12364                  set, "set");
12365 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12366         TOKEN_STRING_INITIALIZER
12367                 (struct cmd_vf_vlan_anti_spoof_result,
12368                  vf, "vf");
12369 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12370         TOKEN_STRING_INITIALIZER
12371                 (struct cmd_vf_vlan_anti_spoof_result,
12372                  vlan, "vlan");
12373 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12374         TOKEN_STRING_INITIALIZER
12375                 (struct cmd_vf_vlan_anti_spoof_result,
12376                  antispoof, "antispoof");
12377 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12378         TOKEN_NUM_INITIALIZER
12379                 (struct cmd_vf_vlan_anti_spoof_result,
12380                  port_id, UINT16);
12381 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12382         TOKEN_NUM_INITIALIZER
12383                 (struct cmd_vf_vlan_anti_spoof_result,
12384                  vf_id, UINT32);
12385 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12386         TOKEN_STRING_INITIALIZER
12387                 (struct cmd_vf_vlan_anti_spoof_result,
12388                  on_off, "on#off");
12389
12390 static void
12391 cmd_set_vf_vlan_anti_spoof_parsed(
12392         void *parsed_result,
12393         __attribute__((unused)) struct cmdline *cl,
12394         __attribute__((unused)) void *data)
12395 {
12396         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12397         int ret = -ENOTSUP;
12398
12399         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12400
12401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12402                 return;
12403
12404 #ifdef RTE_LIBRTE_IXGBE_PMD
12405         if (ret == -ENOTSUP)
12406                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12407                                 res->vf_id, is_on);
12408 #endif
12409 #ifdef RTE_LIBRTE_I40E_PMD
12410         if (ret == -ENOTSUP)
12411                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12412                                 res->vf_id, is_on);
12413 #endif
12414 #ifdef RTE_LIBRTE_BNXT_PMD
12415         if (ret == -ENOTSUP)
12416                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12417                                 res->vf_id, is_on);
12418 #endif
12419
12420         switch (ret) {
12421         case 0:
12422                 break;
12423         case -EINVAL:
12424                 printf("invalid vf_id %d\n", res->vf_id);
12425                 break;
12426         case -ENODEV:
12427                 printf("invalid port_id %d\n", res->port_id);
12428                 break;
12429         case -ENOTSUP:
12430                 printf("function not implemented\n");
12431                 break;
12432         default:
12433                 printf("programming error: (%s)\n", strerror(-ret));
12434         }
12435 }
12436
12437 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12438         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12439         .data = NULL,
12440         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12441         .tokens = {
12442                 (void *)&cmd_vf_vlan_anti_spoof_set,
12443                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12444                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12445                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12446                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12447                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12448                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12449                 NULL,
12450         },
12451 };
12452
12453 /* vf mac anti spoof configuration */
12454
12455 /* Common result structure for vf mac anti spoof */
12456 struct cmd_vf_mac_anti_spoof_result {
12457         cmdline_fixed_string_t set;
12458         cmdline_fixed_string_t vf;
12459         cmdline_fixed_string_t mac;
12460         cmdline_fixed_string_t antispoof;
12461         portid_t port_id;
12462         uint32_t vf_id;
12463         cmdline_fixed_string_t on_off;
12464 };
12465
12466 /* Common CLI fields for vf mac anti spoof enable disable */
12467 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12468         TOKEN_STRING_INITIALIZER
12469                 (struct cmd_vf_mac_anti_spoof_result,
12470                  set, "set");
12471 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12472         TOKEN_STRING_INITIALIZER
12473                 (struct cmd_vf_mac_anti_spoof_result,
12474                  vf, "vf");
12475 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12476         TOKEN_STRING_INITIALIZER
12477                 (struct cmd_vf_mac_anti_spoof_result,
12478                  mac, "mac");
12479 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12480         TOKEN_STRING_INITIALIZER
12481                 (struct cmd_vf_mac_anti_spoof_result,
12482                  antispoof, "antispoof");
12483 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12484         TOKEN_NUM_INITIALIZER
12485                 (struct cmd_vf_mac_anti_spoof_result,
12486                  port_id, UINT16);
12487 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12488         TOKEN_NUM_INITIALIZER
12489                 (struct cmd_vf_mac_anti_spoof_result,
12490                  vf_id, UINT32);
12491 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12492         TOKEN_STRING_INITIALIZER
12493                 (struct cmd_vf_mac_anti_spoof_result,
12494                  on_off, "on#off");
12495
12496 static void
12497 cmd_set_vf_mac_anti_spoof_parsed(
12498         void *parsed_result,
12499         __attribute__((unused)) struct cmdline *cl,
12500         __attribute__((unused)) void *data)
12501 {
12502         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12503         int ret = -ENOTSUP;
12504
12505         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12506
12507         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12508                 return;
12509
12510 #ifdef RTE_LIBRTE_IXGBE_PMD
12511         if (ret == -ENOTSUP)
12512                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12513                         res->vf_id, is_on);
12514 #endif
12515 #ifdef RTE_LIBRTE_I40E_PMD
12516         if (ret == -ENOTSUP)
12517                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12518                         res->vf_id, is_on);
12519 #endif
12520 #ifdef RTE_LIBRTE_BNXT_PMD
12521         if (ret == -ENOTSUP)
12522                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12523                         res->vf_id, is_on);
12524 #endif
12525
12526         switch (ret) {
12527         case 0:
12528                 break;
12529         case -EINVAL:
12530                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12531                 break;
12532         case -ENODEV:
12533                 printf("invalid port_id %d\n", res->port_id);
12534                 break;
12535         case -ENOTSUP:
12536                 printf("function not implemented\n");
12537                 break;
12538         default:
12539                 printf("programming error: (%s)\n", strerror(-ret));
12540         }
12541 }
12542
12543 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12544         .f = cmd_set_vf_mac_anti_spoof_parsed,
12545         .data = NULL,
12546         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12547         .tokens = {
12548                 (void *)&cmd_vf_mac_anti_spoof_set,
12549                 (void *)&cmd_vf_mac_anti_spoof_vf,
12550                 (void *)&cmd_vf_mac_anti_spoof_mac,
12551                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12552                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12553                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12554                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12555                 NULL,
12556         },
12557 };
12558
12559 /* vf vlan strip queue configuration */
12560
12561 /* Common result structure for vf mac anti spoof */
12562 struct cmd_vf_vlan_stripq_result {
12563         cmdline_fixed_string_t set;
12564         cmdline_fixed_string_t vf;
12565         cmdline_fixed_string_t vlan;
12566         cmdline_fixed_string_t stripq;
12567         portid_t port_id;
12568         uint16_t vf_id;
12569         cmdline_fixed_string_t on_off;
12570 };
12571
12572 /* Common CLI fields for vf vlan strip enable disable */
12573 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12574         TOKEN_STRING_INITIALIZER
12575                 (struct cmd_vf_vlan_stripq_result,
12576                  set, "set");
12577 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12578         TOKEN_STRING_INITIALIZER
12579                 (struct cmd_vf_vlan_stripq_result,
12580                  vf, "vf");
12581 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12582         TOKEN_STRING_INITIALIZER
12583                 (struct cmd_vf_vlan_stripq_result,
12584                  vlan, "vlan");
12585 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12586         TOKEN_STRING_INITIALIZER
12587                 (struct cmd_vf_vlan_stripq_result,
12588                  stripq, "stripq");
12589 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12590         TOKEN_NUM_INITIALIZER
12591                 (struct cmd_vf_vlan_stripq_result,
12592                  port_id, UINT16);
12593 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12594         TOKEN_NUM_INITIALIZER
12595                 (struct cmd_vf_vlan_stripq_result,
12596                  vf_id, UINT16);
12597 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12598         TOKEN_STRING_INITIALIZER
12599                 (struct cmd_vf_vlan_stripq_result,
12600                  on_off, "on#off");
12601
12602 static void
12603 cmd_set_vf_vlan_stripq_parsed(
12604         void *parsed_result,
12605         __attribute__((unused)) struct cmdline *cl,
12606         __attribute__((unused)) void *data)
12607 {
12608         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12609         int ret = -ENOTSUP;
12610
12611         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12612
12613         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12614                 return;
12615
12616 #ifdef RTE_LIBRTE_IXGBE_PMD
12617         if (ret == -ENOTSUP)
12618                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12619                         res->vf_id, is_on);
12620 #endif
12621 #ifdef RTE_LIBRTE_I40E_PMD
12622         if (ret == -ENOTSUP)
12623                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12624                         res->vf_id, is_on);
12625 #endif
12626 #ifdef RTE_LIBRTE_BNXT_PMD
12627         if (ret == -ENOTSUP)
12628                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12629                         res->vf_id, is_on);
12630 #endif
12631
12632         switch (ret) {
12633         case 0:
12634                 break;
12635         case -EINVAL:
12636                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12637                 break;
12638         case -ENODEV:
12639                 printf("invalid port_id %d\n", res->port_id);
12640                 break;
12641         case -ENOTSUP:
12642                 printf("function not implemented\n");
12643                 break;
12644         default:
12645                 printf("programming error: (%s)\n", strerror(-ret));
12646         }
12647 }
12648
12649 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12650         .f = cmd_set_vf_vlan_stripq_parsed,
12651         .data = NULL,
12652         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12653         .tokens = {
12654                 (void *)&cmd_vf_vlan_stripq_set,
12655                 (void *)&cmd_vf_vlan_stripq_vf,
12656                 (void *)&cmd_vf_vlan_stripq_vlan,
12657                 (void *)&cmd_vf_vlan_stripq_stripq,
12658                 (void *)&cmd_vf_vlan_stripq_port_id,
12659                 (void *)&cmd_vf_vlan_stripq_vf_id,
12660                 (void *)&cmd_vf_vlan_stripq_on_off,
12661                 NULL,
12662         },
12663 };
12664
12665 /* vf vlan insert configuration */
12666
12667 /* Common result structure for vf vlan insert */
12668 struct cmd_vf_vlan_insert_result {
12669         cmdline_fixed_string_t set;
12670         cmdline_fixed_string_t vf;
12671         cmdline_fixed_string_t vlan;
12672         cmdline_fixed_string_t insert;
12673         portid_t port_id;
12674         uint16_t vf_id;
12675         uint16_t vlan_id;
12676 };
12677
12678 /* Common CLI fields for vf vlan insert enable disable */
12679 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12680         TOKEN_STRING_INITIALIZER
12681                 (struct cmd_vf_vlan_insert_result,
12682                  set, "set");
12683 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12684         TOKEN_STRING_INITIALIZER
12685                 (struct cmd_vf_vlan_insert_result,
12686                  vf, "vf");
12687 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12688         TOKEN_STRING_INITIALIZER
12689                 (struct cmd_vf_vlan_insert_result,
12690                  vlan, "vlan");
12691 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12692         TOKEN_STRING_INITIALIZER
12693                 (struct cmd_vf_vlan_insert_result,
12694                  insert, "insert");
12695 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12696         TOKEN_NUM_INITIALIZER
12697                 (struct cmd_vf_vlan_insert_result,
12698                  port_id, UINT16);
12699 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12700         TOKEN_NUM_INITIALIZER
12701                 (struct cmd_vf_vlan_insert_result,
12702                  vf_id, UINT16);
12703 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12704         TOKEN_NUM_INITIALIZER
12705                 (struct cmd_vf_vlan_insert_result,
12706                  vlan_id, UINT16);
12707
12708 static void
12709 cmd_set_vf_vlan_insert_parsed(
12710         void *parsed_result,
12711         __attribute__((unused)) struct cmdline *cl,
12712         __attribute__((unused)) void *data)
12713 {
12714         struct cmd_vf_vlan_insert_result *res = parsed_result;
12715         int ret = -ENOTSUP;
12716
12717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12718                 return;
12719
12720 #ifdef RTE_LIBRTE_IXGBE_PMD
12721         if (ret == -ENOTSUP)
12722                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12723                         res->vlan_id);
12724 #endif
12725 #ifdef RTE_LIBRTE_I40E_PMD
12726         if (ret == -ENOTSUP)
12727                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12728                         res->vlan_id);
12729 #endif
12730 #ifdef RTE_LIBRTE_BNXT_PMD
12731         if (ret == -ENOTSUP)
12732                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12733                         res->vlan_id);
12734 #endif
12735
12736         switch (ret) {
12737         case 0:
12738                 break;
12739         case -EINVAL:
12740                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12741                 break;
12742         case -ENODEV:
12743                 printf("invalid port_id %d\n", res->port_id);
12744                 break;
12745         case -ENOTSUP:
12746                 printf("function not implemented\n");
12747                 break;
12748         default:
12749                 printf("programming error: (%s)\n", strerror(-ret));
12750         }
12751 }
12752
12753 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12754         .f = cmd_set_vf_vlan_insert_parsed,
12755         .data = NULL,
12756         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12757         .tokens = {
12758                 (void *)&cmd_vf_vlan_insert_set,
12759                 (void *)&cmd_vf_vlan_insert_vf,
12760                 (void *)&cmd_vf_vlan_insert_vlan,
12761                 (void *)&cmd_vf_vlan_insert_insert,
12762                 (void *)&cmd_vf_vlan_insert_port_id,
12763                 (void *)&cmd_vf_vlan_insert_vf_id,
12764                 (void *)&cmd_vf_vlan_insert_vlan_id,
12765                 NULL,
12766         },
12767 };
12768
12769 /* tx loopback configuration */
12770
12771 /* Common result structure for tx loopback */
12772 struct cmd_tx_loopback_result {
12773         cmdline_fixed_string_t set;
12774         cmdline_fixed_string_t tx;
12775         cmdline_fixed_string_t loopback;
12776         portid_t port_id;
12777         cmdline_fixed_string_t on_off;
12778 };
12779
12780 /* Common CLI fields for tx loopback enable disable */
12781 cmdline_parse_token_string_t cmd_tx_loopback_set =
12782         TOKEN_STRING_INITIALIZER
12783                 (struct cmd_tx_loopback_result,
12784                  set, "set");
12785 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12786         TOKEN_STRING_INITIALIZER
12787                 (struct cmd_tx_loopback_result,
12788                  tx, "tx");
12789 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12790         TOKEN_STRING_INITIALIZER
12791                 (struct cmd_tx_loopback_result,
12792                  loopback, "loopback");
12793 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12794         TOKEN_NUM_INITIALIZER
12795                 (struct cmd_tx_loopback_result,
12796                  port_id, UINT16);
12797 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12798         TOKEN_STRING_INITIALIZER
12799                 (struct cmd_tx_loopback_result,
12800                  on_off, "on#off");
12801
12802 static void
12803 cmd_set_tx_loopback_parsed(
12804         void *parsed_result,
12805         __attribute__((unused)) struct cmdline *cl,
12806         __attribute__((unused)) void *data)
12807 {
12808         struct cmd_tx_loopback_result *res = parsed_result;
12809         int ret = -ENOTSUP;
12810
12811         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12812
12813         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12814                 return;
12815
12816 #ifdef RTE_LIBRTE_IXGBE_PMD
12817         if (ret == -ENOTSUP)
12818                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12819 #endif
12820 #ifdef RTE_LIBRTE_I40E_PMD
12821         if (ret == -ENOTSUP)
12822                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12823 #endif
12824 #ifdef RTE_LIBRTE_BNXT_PMD
12825         if (ret == -ENOTSUP)
12826                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12827 #endif
12828 #ifdef RTE_LIBRTE_DPAA_PMD
12829         if (ret == -ENOTSUP)
12830                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12831 #endif
12832
12833         switch (ret) {
12834         case 0:
12835                 break;
12836         case -EINVAL:
12837                 printf("invalid is_on %d\n", is_on);
12838                 break;
12839         case -ENODEV:
12840                 printf("invalid port_id %d\n", res->port_id);
12841                 break;
12842         case -ENOTSUP:
12843                 printf("function not implemented\n");
12844                 break;
12845         default:
12846                 printf("programming error: (%s)\n", strerror(-ret));
12847         }
12848 }
12849
12850 cmdline_parse_inst_t cmd_set_tx_loopback = {
12851         .f = cmd_set_tx_loopback_parsed,
12852         .data = NULL,
12853         .help_str = "set tx loopback <port_id> on|off",
12854         .tokens = {
12855                 (void *)&cmd_tx_loopback_set,
12856                 (void *)&cmd_tx_loopback_tx,
12857                 (void *)&cmd_tx_loopback_loopback,
12858                 (void *)&cmd_tx_loopback_port_id,
12859                 (void *)&cmd_tx_loopback_on_off,
12860                 NULL,
12861         },
12862 };
12863
12864 /* all queues drop enable configuration */
12865
12866 /* Common result structure for all queues drop enable */
12867 struct cmd_all_queues_drop_en_result {
12868         cmdline_fixed_string_t set;
12869         cmdline_fixed_string_t all;
12870         cmdline_fixed_string_t queues;
12871         cmdline_fixed_string_t drop;
12872         portid_t port_id;
12873         cmdline_fixed_string_t on_off;
12874 };
12875
12876 /* Common CLI fields for tx loopback enable disable */
12877 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12878         TOKEN_STRING_INITIALIZER
12879                 (struct cmd_all_queues_drop_en_result,
12880                  set, "set");
12881 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_all_queues_drop_en_result,
12884                  all, "all");
12885 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12886         TOKEN_STRING_INITIALIZER
12887                 (struct cmd_all_queues_drop_en_result,
12888                  queues, "queues");
12889 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12890         TOKEN_STRING_INITIALIZER
12891                 (struct cmd_all_queues_drop_en_result,
12892                  drop, "drop");
12893 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12894         TOKEN_NUM_INITIALIZER
12895                 (struct cmd_all_queues_drop_en_result,
12896                  port_id, UINT16);
12897 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12898         TOKEN_STRING_INITIALIZER
12899                 (struct cmd_all_queues_drop_en_result,
12900                  on_off, "on#off");
12901
12902 static void
12903 cmd_set_all_queues_drop_en_parsed(
12904         void *parsed_result,
12905         __attribute__((unused)) struct cmdline *cl,
12906         __attribute__((unused)) void *data)
12907 {
12908         struct cmd_all_queues_drop_en_result *res = parsed_result;
12909         int ret = -ENOTSUP;
12910         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12911
12912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12913                 return;
12914
12915 #ifdef RTE_LIBRTE_IXGBE_PMD
12916         if (ret == -ENOTSUP)
12917                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12918 #endif
12919 #ifdef RTE_LIBRTE_BNXT_PMD
12920         if (ret == -ENOTSUP)
12921                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12922 #endif
12923         switch (ret) {
12924         case 0:
12925                 break;
12926         case -EINVAL:
12927                 printf("invalid is_on %d\n", is_on);
12928                 break;
12929         case -ENODEV:
12930                 printf("invalid port_id %d\n", res->port_id);
12931                 break;
12932         case -ENOTSUP:
12933                 printf("function not implemented\n");
12934                 break;
12935         default:
12936                 printf("programming error: (%s)\n", strerror(-ret));
12937         }
12938 }
12939
12940 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12941         .f = cmd_set_all_queues_drop_en_parsed,
12942         .data = NULL,
12943         .help_str = "set all queues drop <port_id> on|off",
12944         .tokens = {
12945                 (void *)&cmd_all_queues_drop_en_set,
12946                 (void *)&cmd_all_queues_drop_en_all,
12947                 (void *)&cmd_all_queues_drop_en_queues,
12948                 (void *)&cmd_all_queues_drop_en_drop,
12949                 (void *)&cmd_all_queues_drop_en_port_id,
12950                 (void *)&cmd_all_queues_drop_en_on_off,
12951                 NULL,
12952         },
12953 };
12954
12955 /* vf split drop enable configuration */
12956
12957 /* Common result structure for vf split drop enable */
12958 struct cmd_vf_split_drop_en_result {
12959         cmdline_fixed_string_t set;
12960         cmdline_fixed_string_t vf;
12961         cmdline_fixed_string_t split;
12962         cmdline_fixed_string_t drop;
12963         portid_t port_id;
12964         uint16_t vf_id;
12965         cmdline_fixed_string_t on_off;
12966 };
12967
12968 /* Common CLI fields for vf split drop enable disable */
12969 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12970         TOKEN_STRING_INITIALIZER
12971                 (struct cmd_vf_split_drop_en_result,
12972                  set, "set");
12973 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12974         TOKEN_STRING_INITIALIZER
12975                 (struct cmd_vf_split_drop_en_result,
12976                  vf, "vf");
12977 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12978         TOKEN_STRING_INITIALIZER
12979                 (struct cmd_vf_split_drop_en_result,
12980                  split, "split");
12981 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12982         TOKEN_STRING_INITIALIZER
12983                 (struct cmd_vf_split_drop_en_result,
12984                  drop, "drop");
12985 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12986         TOKEN_NUM_INITIALIZER
12987                 (struct cmd_vf_split_drop_en_result,
12988                  port_id, UINT16);
12989 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12990         TOKEN_NUM_INITIALIZER
12991                 (struct cmd_vf_split_drop_en_result,
12992                  vf_id, UINT16);
12993 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12994         TOKEN_STRING_INITIALIZER
12995                 (struct cmd_vf_split_drop_en_result,
12996                  on_off, "on#off");
12997
12998 static void
12999 cmd_set_vf_split_drop_en_parsed(
13000         void *parsed_result,
13001         __attribute__((unused)) struct cmdline *cl,
13002         __attribute__((unused)) void *data)
13003 {
13004         struct cmd_vf_split_drop_en_result *res = parsed_result;
13005         int ret = -ENOTSUP;
13006         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13007
13008         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13009                 return;
13010
13011 #ifdef RTE_LIBRTE_IXGBE_PMD
13012         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13013                         is_on);
13014 #endif
13015         switch (ret) {
13016         case 0:
13017                 break;
13018         case -EINVAL:
13019                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13020                 break;
13021         case -ENODEV:
13022                 printf("invalid port_id %d\n", res->port_id);
13023                 break;
13024         case -ENOTSUP:
13025                 printf("not supported on port %d\n", res->port_id);
13026                 break;
13027         default:
13028                 printf("programming error: (%s)\n", strerror(-ret));
13029         }
13030 }
13031
13032 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13033         .f = cmd_set_vf_split_drop_en_parsed,
13034         .data = NULL,
13035         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13036         .tokens = {
13037                 (void *)&cmd_vf_split_drop_en_set,
13038                 (void *)&cmd_vf_split_drop_en_vf,
13039                 (void *)&cmd_vf_split_drop_en_split,
13040                 (void *)&cmd_vf_split_drop_en_drop,
13041                 (void *)&cmd_vf_split_drop_en_port_id,
13042                 (void *)&cmd_vf_split_drop_en_vf_id,
13043                 (void *)&cmd_vf_split_drop_en_on_off,
13044                 NULL,
13045         },
13046 };
13047
13048 /* vf mac address configuration */
13049
13050 /* Common result structure for vf mac address */
13051 struct cmd_set_vf_mac_addr_result {
13052         cmdline_fixed_string_t set;
13053         cmdline_fixed_string_t vf;
13054         cmdline_fixed_string_t mac;
13055         cmdline_fixed_string_t addr;
13056         portid_t port_id;
13057         uint16_t vf_id;
13058         struct ether_addr mac_addr;
13059
13060 };
13061
13062 /* Common CLI fields for vf split drop enable disable */
13063 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13064         TOKEN_STRING_INITIALIZER
13065                 (struct cmd_set_vf_mac_addr_result,
13066                  set, "set");
13067 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13068         TOKEN_STRING_INITIALIZER
13069                 (struct cmd_set_vf_mac_addr_result,
13070                  vf, "vf");
13071 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13072         TOKEN_STRING_INITIALIZER
13073                 (struct cmd_set_vf_mac_addr_result,
13074                  mac, "mac");
13075 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13076         TOKEN_STRING_INITIALIZER
13077                 (struct cmd_set_vf_mac_addr_result,
13078                  addr, "addr");
13079 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13080         TOKEN_NUM_INITIALIZER
13081                 (struct cmd_set_vf_mac_addr_result,
13082                  port_id, UINT16);
13083 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13084         TOKEN_NUM_INITIALIZER
13085                 (struct cmd_set_vf_mac_addr_result,
13086                  vf_id, UINT16);
13087 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13088         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13089                  mac_addr);
13090
13091 static void
13092 cmd_set_vf_mac_addr_parsed(
13093         void *parsed_result,
13094         __attribute__((unused)) struct cmdline *cl,
13095         __attribute__((unused)) void *data)
13096 {
13097         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13098         int ret = -ENOTSUP;
13099
13100         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13101                 return;
13102
13103 #ifdef RTE_LIBRTE_IXGBE_PMD
13104         if (ret == -ENOTSUP)
13105                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13106                                 &res->mac_addr);
13107 #endif
13108 #ifdef RTE_LIBRTE_I40E_PMD
13109         if (ret == -ENOTSUP)
13110                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13111                                 &res->mac_addr);
13112 #endif
13113 #ifdef RTE_LIBRTE_BNXT_PMD
13114         if (ret == -ENOTSUP)
13115                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13116                                 &res->mac_addr);
13117 #endif
13118
13119         switch (ret) {
13120         case 0:
13121                 break;
13122         case -EINVAL:
13123                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13124                 break;
13125         case -ENODEV:
13126                 printf("invalid port_id %d\n", res->port_id);
13127                 break;
13128         case -ENOTSUP:
13129                 printf("function not implemented\n");
13130                 break;
13131         default:
13132                 printf("programming error: (%s)\n", strerror(-ret));
13133         }
13134 }
13135
13136 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13137         .f = cmd_set_vf_mac_addr_parsed,
13138         .data = NULL,
13139         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13140         .tokens = {
13141                 (void *)&cmd_set_vf_mac_addr_set,
13142                 (void *)&cmd_set_vf_mac_addr_vf,
13143                 (void *)&cmd_set_vf_mac_addr_mac,
13144                 (void *)&cmd_set_vf_mac_addr_addr,
13145                 (void *)&cmd_set_vf_mac_addr_port_id,
13146                 (void *)&cmd_set_vf_mac_addr_vf_id,
13147                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13148                 NULL,
13149         },
13150 };
13151
13152 /* MACsec configuration */
13153
13154 /* Common result structure for MACsec offload enable */
13155 struct cmd_macsec_offload_on_result {
13156         cmdline_fixed_string_t set;
13157         cmdline_fixed_string_t macsec;
13158         cmdline_fixed_string_t offload;
13159         portid_t port_id;
13160         cmdline_fixed_string_t on;
13161         cmdline_fixed_string_t encrypt;
13162         cmdline_fixed_string_t en_on_off;
13163         cmdline_fixed_string_t replay_protect;
13164         cmdline_fixed_string_t rp_on_off;
13165 };
13166
13167 /* Common CLI fields for MACsec offload disable */
13168 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13169         TOKEN_STRING_INITIALIZER
13170                 (struct cmd_macsec_offload_on_result,
13171                  set, "set");
13172 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13173         TOKEN_STRING_INITIALIZER
13174                 (struct cmd_macsec_offload_on_result,
13175                  macsec, "macsec");
13176 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13177         TOKEN_STRING_INITIALIZER
13178                 (struct cmd_macsec_offload_on_result,
13179                  offload, "offload");
13180 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13181         TOKEN_NUM_INITIALIZER
13182                 (struct cmd_macsec_offload_on_result,
13183                  port_id, UINT16);
13184 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13185         TOKEN_STRING_INITIALIZER
13186                 (struct cmd_macsec_offload_on_result,
13187                  on, "on");
13188 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13189         TOKEN_STRING_INITIALIZER
13190                 (struct cmd_macsec_offload_on_result,
13191                  encrypt, "encrypt");
13192 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13193         TOKEN_STRING_INITIALIZER
13194                 (struct cmd_macsec_offload_on_result,
13195                  en_on_off, "on#off");
13196 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13197         TOKEN_STRING_INITIALIZER
13198                 (struct cmd_macsec_offload_on_result,
13199                  replay_protect, "replay-protect");
13200 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13201         TOKEN_STRING_INITIALIZER
13202                 (struct cmd_macsec_offload_on_result,
13203                  rp_on_off, "on#off");
13204
13205 static void
13206 cmd_set_macsec_offload_on_parsed(
13207         void *parsed_result,
13208         __attribute__((unused)) struct cmdline *cl,
13209         __attribute__((unused)) void *data)
13210 {
13211         struct cmd_macsec_offload_on_result *res = parsed_result;
13212         int ret = -ENOTSUP;
13213         portid_t port_id = res->port_id;
13214         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13215         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13216         struct rte_eth_dev_info dev_info;
13217
13218         if (port_id_is_invalid(port_id, ENABLED_WARN))
13219                 return;
13220         if (!port_is_stopped(port_id)) {
13221                 printf("Please stop port %d first\n", port_id);
13222                 return;
13223         }
13224
13225         rte_eth_dev_info_get(port_id, &dev_info);
13226         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13227 #ifdef RTE_LIBRTE_IXGBE_PMD
13228                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13229 #endif
13230         }
13231         RTE_SET_USED(en);
13232         RTE_SET_USED(rp);
13233
13234         switch (ret) {
13235         case 0:
13236                 ports[port_id].dev_conf.txmode.offloads |=
13237                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13238                 cmd_reconfig_device_queue(port_id, 1, 1);
13239                 break;
13240         case -ENODEV:
13241                 printf("invalid port_id %d\n", port_id);
13242                 break;
13243         case -ENOTSUP:
13244                 printf("not supported on port %d\n", port_id);
13245                 break;
13246         default:
13247                 printf("programming error: (%s)\n", strerror(-ret));
13248         }
13249 }
13250
13251 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13252         .f = cmd_set_macsec_offload_on_parsed,
13253         .data = NULL,
13254         .help_str = "set macsec offload <port_id> on "
13255                 "encrypt on|off replay-protect on|off",
13256         .tokens = {
13257                 (void *)&cmd_macsec_offload_on_set,
13258                 (void *)&cmd_macsec_offload_on_macsec,
13259                 (void *)&cmd_macsec_offload_on_offload,
13260                 (void *)&cmd_macsec_offload_on_port_id,
13261                 (void *)&cmd_macsec_offload_on_on,
13262                 (void *)&cmd_macsec_offload_on_encrypt,
13263                 (void *)&cmd_macsec_offload_on_en_on_off,
13264                 (void *)&cmd_macsec_offload_on_replay_protect,
13265                 (void *)&cmd_macsec_offload_on_rp_on_off,
13266                 NULL,
13267         },
13268 };
13269
13270 /* Common result structure for MACsec offload disable */
13271 struct cmd_macsec_offload_off_result {
13272         cmdline_fixed_string_t set;
13273         cmdline_fixed_string_t macsec;
13274         cmdline_fixed_string_t offload;
13275         portid_t port_id;
13276         cmdline_fixed_string_t off;
13277 };
13278
13279 /* Common CLI fields for MACsec offload disable */
13280 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13281         TOKEN_STRING_INITIALIZER
13282                 (struct cmd_macsec_offload_off_result,
13283                  set, "set");
13284 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13285         TOKEN_STRING_INITIALIZER
13286                 (struct cmd_macsec_offload_off_result,
13287                  macsec, "macsec");
13288 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13289         TOKEN_STRING_INITIALIZER
13290                 (struct cmd_macsec_offload_off_result,
13291                  offload, "offload");
13292 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13293         TOKEN_NUM_INITIALIZER
13294                 (struct cmd_macsec_offload_off_result,
13295                  port_id, UINT16);
13296 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13297         TOKEN_STRING_INITIALIZER
13298                 (struct cmd_macsec_offload_off_result,
13299                  off, "off");
13300
13301 static void
13302 cmd_set_macsec_offload_off_parsed(
13303         void *parsed_result,
13304         __attribute__((unused)) struct cmdline *cl,
13305         __attribute__((unused)) void *data)
13306 {
13307         struct cmd_macsec_offload_off_result *res = parsed_result;
13308         int ret = -ENOTSUP;
13309         struct rte_eth_dev_info dev_info;
13310         portid_t port_id = res->port_id;
13311
13312         if (port_id_is_invalid(port_id, ENABLED_WARN))
13313                 return;
13314         if (!port_is_stopped(port_id)) {
13315                 printf("Please stop port %d first\n", port_id);
13316                 return;
13317         }
13318
13319         rte_eth_dev_info_get(port_id, &dev_info);
13320         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13321 #ifdef RTE_LIBRTE_IXGBE_PMD
13322                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13323 #endif
13324         }
13325         switch (ret) {
13326         case 0:
13327                 ports[port_id].dev_conf.txmode.offloads &=
13328                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13329                 cmd_reconfig_device_queue(port_id, 1, 1);
13330                 break;
13331         case -ENODEV:
13332                 printf("invalid port_id %d\n", port_id);
13333                 break;
13334         case -ENOTSUP:
13335                 printf("not supported on port %d\n", port_id);
13336                 break;
13337         default:
13338                 printf("programming error: (%s)\n", strerror(-ret));
13339         }
13340 }
13341
13342 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13343         .f = cmd_set_macsec_offload_off_parsed,
13344         .data = NULL,
13345         .help_str = "set macsec offload <port_id> off",
13346         .tokens = {
13347                 (void *)&cmd_macsec_offload_off_set,
13348                 (void *)&cmd_macsec_offload_off_macsec,
13349                 (void *)&cmd_macsec_offload_off_offload,
13350                 (void *)&cmd_macsec_offload_off_port_id,
13351                 (void *)&cmd_macsec_offload_off_off,
13352                 NULL,
13353         },
13354 };
13355
13356 /* Common result structure for MACsec secure connection configure */
13357 struct cmd_macsec_sc_result {
13358         cmdline_fixed_string_t set;
13359         cmdline_fixed_string_t macsec;
13360         cmdline_fixed_string_t sc;
13361         cmdline_fixed_string_t tx_rx;
13362         portid_t port_id;
13363         struct ether_addr mac;
13364         uint16_t pi;
13365 };
13366
13367 /* Common CLI fields for MACsec secure connection configure */
13368 cmdline_parse_token_string_t cmd_macsec_sc_set =
13369         TOKEN_STRING_INITIALIZER
13370                 (struct cmd_macsec_sc_result,
13371                  set, "set");
13372 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13373         TOKEN_STRING_INITIALIZER
13374                 (struct cmd_macsec_sc_result,
13375                  macsec, "macsec");
13376 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13377         TOKEN_STRING_INITIALIZER
13378                 (struct cmd_macsec_sc_result,
13379                  sc, "sc");
13380 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13381         TOKEN_STRING_INITIALIZER
13382                 (struct cmd_macsec_sc_result,
13383                  tx_rx, "tx#rx");
13384 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13385         TOKEN_NUM_INITIALIZER
13386                 (struct cmd_macsec_sc_result,
13387                  port_id, UINT16);
13388 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13389         TOKEN_ETHERADDR_INITIALIZER
13390                 (struct cmd_macsec_sc_result,
13391                  mac);
13392 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13393         TOKEN_NUM_INITIALIZER
13394                 (struct cmd_macsec_sc_result,
13395                  pi, UINT16);
13396
13397 static void
13398 cmd_set_macsec_sc_parsed(
13399         void *parsed_result,
13400         __attribute__((unused)) struct cmdline *cl,
13401         __attribute__((unused)) void *data)
13402 {
13403         struct cmd_macsec_sc_result *res = parsed_result;
13404         int ret = -ENOTSUP;
13405         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13406
13407 #ifdef RTE_LIBRTE_IXGBE_PMD
13408         ret = is_tx ?
13409                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13410                                 res->mac.addr_bytes) :
13411                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13412                                 res->mac.addr_bytes, res->pi);
13413 #endif
13414         RTE_SET_USED(is_tx);
13415
13416         switch (ret) {
13417         case 0:
13418                 break;
13419         case -ENODEV:
13420                 printf("invalid port_id %d\n", res->port_id);
13421                 break;
13422         case -ENOTSUP:
13423                 printf("not supported on port %d\n", res->port_id);
13424                 break;
13425         default:
13426                 printf("programming error: (%s)\n", strerror(-ret));
13427         }
13428 }
13429
13430 cmdline_parse_inst_t cmd_set_macsec_sc = {
13431         .f = cmd_set_macsec_sc_parsed,
13432         .data = NULL,
13433         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13434         .tokens = {
13435                 (void *)&cmd_macsec_sc_set,
13436                 (void *)&cmd_macsec_sc_macsec,
13437                 (void *)&cmd_macsec_sc_sc,
13438                 (void *)&cmd_macsec_sc_tx_rx,
13439                 (void *)&cmd_macsec_sc_port_id,
13440                 (void *)&cmd_macsec_sc_mac,
13441                 (void *)&cmd_macsec_sc_pi,
13442                 NULL,
13443         },
13444 };
13445
13446 /* Common result structure for MACsec secure connection configure */
13447 struct cmd_macsec_sa_result {
13448         cmdline_fixed_string_t set;
13449         cmdline_fixed_string_t macsec;
13450         cmdline_fixed_string_t sa;
13451         cmdline_fixed_string_t tx_rx;
13452         portid_t port_id;
13453         uint8_t idx;
13454         uint8_t an;
13455         uint32_t pn;
13456         cmdline_fixed_string_t key;
13457 };
13458
13459 /* Common CLI fields for MACsec secure connection configure */
13460 cmdline_parse_token_string_t cmd_macsec_sa_set =
13461         TOKEN_STRING_INITIALIZER
13462                 (struct cmd_macsec_sa_result,
13463                  set, "set");
13464 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_macsec_sa_result,
13467                  macsec, "macsec");
13468 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13469         TOKEN_STRING_INITIALIZER
13470                 (struct cmd_macsec_sa_result,
13471                  sa, "sa");
13472 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13473         TOKEN_STRING_INITIALIZER
13474                 (struct cmd_macsec_sa_result,
13475                  tx_rx, "tx#rx");
13476 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13477         TOKEN_NUM_INITIALIZER
13478                 (struct cmd_macsec_sa_result,
13479                  port_id, UINT16);
13480 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13481         TOKEN_NUM_INITIALIZER
13482                 (struct cmd_macsec_sa_result,
13483                  idx, UINT8);
13484 cmdline_parse_token_num_t cmd_macsec_sa_an =
13485         TOKEN_NUM_INITIALIZER
13486                 (struct cmd_macsec_sa_result,
13487                  an, UINT8);
13488 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13489         TOKEN_NUM_INITIALIZER
13490                 (struct cmd_macsec_sa_result,
13491                  pn, UINT32);
13492 cmdline_parse_token_string_t cmd_macsec_sa_key =
13493         TOKEN_STRING_INITIALIZER
13494                 (struct cmd_macsec_sa_result,
13495                  key, NULL);
13496
13497 static void
13498 cmd_set_macsec_sa_parsed(
13499         void *parsed_result,
13500         __attribute__((unused)) struct cmdline *cl,
13501         __attribute__((unused)) void *data)
13502 {
13503         struct cmd_macsec_sa_result *res = parsed_result;
13504         int ret = -ENOTSUP;
13505         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13506         uint8_t key[16] = { 0 };
13507         uint8_t xdgt0;
13508         uint8_t xdgt1;
13509         int key_len;
13510         int i;
13511
13512         key_len = strlen(res->key) / 2;
13513         if (key_len > 16)
13514                 key_len = 16;
13515
13516         for (i = 0; i < key_len; i++) {
13517                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13518                 if (xdgt0 == 0xFF)
13519                         return;
13520                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13521                 if (xdgt1 == 0xFF)
13522                         return;
13523                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13524         }
13525
13526 #ifdef RTE_LIBRTE_IXGBE_PMD
13527         ret = is_tx ?
13528                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13529                         res->idx, res->an, res->pn, key) :
13530                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13531                         res->idx, res->an, res->pn, key);
13532 #endif
13533         RTE_SET_USED(is_tx);
13534         RTE_SET_USED(key);
13535
13536         switch (ret) {
13537         case 0:
13538                 break;
13539         case -EINVAL:
13540                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13541                 break;
13542         case -ENODEV:
13543                 printf("invalid port_id %d\n", res->port_id);
13544                 break;
13545         case -ENOTSUP:
13546                 printf("not supported on port %d\n", res->port_id);
13547                 break;
13548         default:
13549                 printf("programming error: (%s)\n", strerror(-ret));
13550         }
13551 }
13552
13553 cmdline_parse_inst_t cmd_set_macsec_sa = {
13554         .f = cmd_set_macsec_sa_parsed,
13555         .data = NULL,
13556         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13557         .tokens = {
13558                 (void *)&cmd_macsec_sa_set,
13559                 (void *)&cmd_macsec_sa_macsec,
13560                 (void *)&cmd_macsec_sa_sa,
13561                 (void *)&cmd_macsec_sa_tx_rx,
13562                 (void *)&cmd_macsec_sa_port_id,
13563                 (void *)&cmd_macsec_sa_idx,
13564                 (void *)&cmd_macsec_sa_an,
13565                 (void *)&cmd_macsec_sa_pn,
13566                 (void *)&cmd_macsec_sa_key,
13567                 NULL,
13568         },
13569 };
13570
13571 /* VF unicast promiscuous mode configuration */
13572
13573 /* Common result structure for VF unicast promiscuous mode */
13574 struct cmd_vf_promisc_result {
13575         cmdline_fixed_string_t set;
13576         cmdline_fixed_string_t vf;
13577         cmdline_fixed_string_t promisc;
13578         portid_t port_id;
13579         uint32_t vf_id;
13580         cmdline_fixed_string_t on_off;
13581 };
13582
13583 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13584 cmdline_parse_token_string_t cmd_vf_promisc_set =
13585         TOKEN_STRING_INITIALIZER
13586                 (struct cmd_vf_promisc_result,
13587                  set, "set");
13588 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13589         TOKEN_STRING_INITIALIZER
13590                 (struct cmd_vf_promisc_result,
13591                  vf, "vf");
13592 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13593         TOKEN_STRING_INITIALIZER
13594                 (struct cmd_vf_promisc_result,
13595                  promisc, "promisc");
13596 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13597         TOKEN_NUM_INITIALIZER
13598                 (struct cmd_vf_promisc_result,
13599                  port_id, UINT16);
13600 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13601         TOKEN_NUM_INITIALIZER
13602                 (struct cmd_vf_promisc_result,
13603                  vf_id, UINT32);
13604 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13605         TOKEN_STRING_INITIALIZER
13606                 (struct cmd_vf_promisc_result,
13607                  on_off, "on#off");
13608
13609 static void
13610 cmd_set_vf_promisc_parsed(
13611         void *parsed_result,
13612         __attribute__((unused)) struct cmdline *cl,
13613         __attribute__((unused)) void *data)
13614 {
13615         struct cmd_vf_promisc_result *res = parsed_result;
13616         int ret = -ENOTSUP;
13617
13618         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13619
13620         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13621                 return;
13622
13623 #ifdef RTE_LIBRTE_I40E_PMD
13624         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13625                                                   res->vf_id, is_on);
13626 #endif
13627
13628         switch (ret) {
13629         case 0:
13630                 break;
13631         case -EINVAL:
13632                 printf("invalid vf_id %d\n", res->vf_id);
13633                 break;
13634         case -ENODEV:
13635                 printf("invalid port_id %d\n", res->port_id);
13636                 break;
13637         case -ENOTSUP:
13638                 printf("function not implemented\n");
13639                 break;
13640         default:
13641                 printf("programming error: (%s)\n", strerror(-ret));
13642         }
13643 }
13644
13645 cmdline_parse_inst_t cmd_set_vf_promisc = {
13646         .f = cmd_set_vf_promisc_parsed,
13647         .data = NULL,
13648         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13649                 "Set unicast promiscuous mode for a VF from the PF",
13650         .tokens = {
13651                 (void *)&cmd_vf_promisc_set,
13652                 (void *)&cmd_vf_promisc_vf,
13653                 (void *)&cmd_vf_promisc_promisc,
13654                 (void *)&cmd_vf_promisc_port_id,
13655                 (void *)&cmd_vf_promisc_vf_id,
13656                 (void *)&cmd_vf_promisc_on_off,
13657                 NULL,
13658         },
13659 };
13660
13661 /* VF multicast promiscuous mode configuration */
13662
13663 /* Common result structure for VF multicast promiscuous mode */
13664 struct cmd_vf_allmulti_result {
13665         cmdline_fixed_string_t set;
13666         cmdline_fixed_string_t vf;
13667         cmdline_fixed_string_t allmulti;
13668         portid_t port_id;
13669         uint32_t vf_id;
13670         cmdline_fixed_string_t on_off;
13671 };
13672
13673 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13674 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_vf_allmulti_result,
13677                  set, "set");
13678 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_vf_allmulti_result,
13681                  vf, "vf");
13682 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13683         TOKEN_STRING_INITIALIZER
13684                 (struct cmd_vf_allmulti_result,
13685                  allmulti, "allmulti");
13686 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13687         TOKEN_NUM_INITIALIZER
13688                 (struct cmd_vf_allmulti_result,
13689                  port_id, UINT16);
13690 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13691         TOKEN_NUM_INITIALIZER
13692                 (struct cmd_vf_allmulti_result,
13693                  vf_id, UINT32);
13694 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13695         TOKEN_STRING_INITIALIZER
13696                 (struct cmd_vf_allmulti_result,
13697                  on_off, "on#off");
13698
13699 static void
13700 cmd_set_vf_allmulti_parsed(
13701         void *parsed_result,
13702         __attribute__((unused)) struct cmdline *cl,
13703         __attribute__((unused)) void *data)
13704 {
13705         struct cmd_vf_allmulti_result *res = parsed_result;
13706         int ret = -ENOTSUP;
13707
13708         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13709
13710         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13711                 return;
13712
13713 #ifdef RTE_LIBRTE_I40E_PMD
13714         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13715                                                     res->vf_id, is_on);
13716 #endif
13717
13718         switch (ret) {
13719         case 0:
13720                 break;
13721         case -EINVAL:
13722                 printf("invalid vf_id %d\n", res->vf_id);
13723                 break;
13724         case -ENODEV:
13725                 printf("invalid port_id %d\n", res->port_id);
13726                 break;
13727         case -ENOTSUP:
13728                 printf("function not implemented\n");
13729                 break;
13730         default:
13731                 printf("programming error: (%s)\n", strerror(-ret));
13732         }
13733 }
13734
13735 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13736         .f = cmd_set_vf_allmulti_parsed,
13737         .data = NULL,
13738         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13739                 "Set multicast promiscuous mode for a VF from the PF",
13740         .tokens = {
13741                 (void *)&cmd_vf_allmulti_set,
13742                 (void *)&cmd_vf_allmulti_vf,
13743                 (void *)&cmd_vf_allmulti_allmulti,
13744                 (void *)&cmd_vf_allmulti_port_id,
13745                 (void *)&cmd_vf_allmulti_vf_id,
13746                 (void *)&cmd_vf_allmulti_on_off,
13747                 NULL,
13748         },
13749 };
13750
13751 /* vf broadcast mode configuration */
13752
13753 /* Common result structure for vf broadcast */
13754 struct cmd_set_vf_broadcast_result {
13755         cmdline_fixed_string_t set;
13756         cmdline_fixed_string_t vf;
13757         cmdline_fixed_string_t broadcast;
13758         portid_t port_id;
13759         uint16_t vf_id;
13760         cmdline_fixed_string_t on_off;
13761 };
13762
13763 /* Common CLI fields for vf broadcast enable disable */
13764 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13765         TOKEN_STRING_INITIALIZER
13766                 (struct cmd_set_vf_broadcast_result,
13767                  set, "set");
13768 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13769         TOKEN_STRING_INITIALIZER
13770                 (struct cmd_set_vf_broadcast_result,
13771                  vf, "vf");
13772 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13773         TOKEN_STRING_INITIALIZER
13774                 (struct cmd_set_vf_broadcast_result,
13775                  broadcast, "broadcast");
13776 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13777         TOKEN_NUM_INITIALIZER
13778                 (struct cmd_set_vf_broadcast_result,
13779                  port_id, UINT16);
13780 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13781         TOKEN_NUM_INITIALIZER
13782                 (struct cmd_set_vf_broadcast_result,
13783                  vf_id, UINT16);
13784 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13785         TOKEN_STRING_INITIALIZER
13786                 (struct cmd_set_vf_broadcast_result,
13787                  on_off, "on#off");
13788
13789 static void
13790 cmd_set_vf_broadcast_parsed(
13791         void *parsed_result,
13792         __attribute__((unused)) struct cmdline *cl,
13793         __attribute__((unused)) void *data)
13794 {
13795         struct cmd_set_vf_broadcast_result *res = parsed_result;
13796         int ret = -ENOTSUP;
13797
13798         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13799
13800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13801                 return;
13802
13803 #ifdef RTE_LIBRTE_I40E_PMD
13804         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13805                                             res->vf_id, is_on);
13806 #endif
13807
13808         switch (ret) {
13809         case 0:
13810                 break;
13811         case -EINVAL:
13812                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13813                 break;
13814         case -ENODEV:
13815                 printf("invalid port_id %d\n", res->port_id);
13816                 break;
13817         case -ENOTSUP:
13818                 printf("function not implemented\n");
13819                 break;
13820         default:
13821                 printf("programming error: (%s)\n", strerror(-ret));
13822         }
13823 }
13824
13825 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13826         .f = cmd_set_vf_broadcast_parsed,
13827         .data = NULL,
13828         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13829         .tokens = {
13830                 (void *)&cmd_set_vf_broadcast_set,
13831                 (void *)&cmd_set_vf_broadcast_vf,
13832                 (void *)&cmd_set_vf_broadcast_broadcast,
13833                 (void *)&cmd_set_vf_broadcast_port_id,
13834                 (void *)&cmd_set_vf_broadcast_vf_id,
13835                 (void *)&cmd_set_vf_broadcast_on_off,
13836                 NULL,
13837         },
13838 };
13839
13840 /* vf vlan tag configuration */
13841
13842 /* Common result structure for vf vlan tag */
13843 struct cmd_set_vf_vlan_tag_result {
13844         cmdline_fixed_string_t set;
13845         cmdline_fixed_string_t vf;
13846         cmdline_fixed_string_t vlan;
13847         cmdline_fixed_string_t tag;
13848         portid_t port_id;
13849         uint16_t vf_id;
13850         cmdline_fixed_string_t on_off;
13851 };
13852
13853 /* Common CLI fields for vf vlan tag enable disable */
13854 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_set_vf_vlan_tag_result,
13857                  set, "set");
13858 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_set_vf_vlan_tag_result,
13861                  vf, "vf");
13862 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_set_vf_vlan_tag_result,
13865                  vlan, "vlan");
13866 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13867         TOKEN_STRING_INITIALIZER
13868                 (struct cmd_set_vf_vlan_tag_result,
13869                  tag, "tag");
13870 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13871         TOKEN_NUM_INITIALIZER
13872                 (struct cmd_set_vf_vlan_tag_result,
13873                  port_id, UINT16);
13874 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13875         TOKEN_NUM_INITIALIZER
13876                 (struct cmd_set_vf_vlan_tag_result,
13877                  vf_id, UINT16);
13878 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13879         TOKEN_STRING_INITIALIZER
13880                 (struct cmd_set_vf_vlan_tag_result,
13881                  on_off, "on#off");
13882
13883 static void
13884 cmd_set_vf_vlan_tag_parsed(
13885         void *parsed_result,
13886         __attribute__((unused)) struct cmdline *cl,
13887         __attribute__((unused)) void *data)
13888 {
13889         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13890         int ret = -ENOTSUP;
13891
13892         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13893
13894         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13895                 return;
13896
13897 #ifdef RTE_LIBRTE_I40E_PMD
13898         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13899                                            res->vf_id, is_on);
13900 #endif
13901
13902         switch (ret) {
13903         case 0:
13904                 break;
13905         case -EINVAL:
13906                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13907                 break;
13908         case -ENODEV:
13909                 printf("invalid port_id %d\n", res->port_id);
13910                 break;
13911         case -ENOTSUP:
13912                 printf("function not implemented\n");
13913                 break;
13914         default:
13915                 printf("programming error: (%s)\n", strerror(-ret));
13916         }
13917 }
13918
13919 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13920         .f = cmd_set_vf_vlan_tag_parsed,
13921         .data = NULL,
13922         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13923         .tokens = {
13924                 (void *)&cmd_set_vf_vlan_tag_set,
13925                 (void *)&cmd_set_vf_vlan_tag_vf,
13926                 (void *)&cmd_set_vf_vlan_tag_vlan,
13927                 (void *)&cmd_set_vf_vlan_tag_tag,
13928                 (void *)&cmd_set_vf_vlan_tag_port_id,
13929                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13930                 (void *)&cmd_set_vf_vlan_tag_on_off,
13931                 NULL,
13932         },
13933 };
13934
13935 /* Common definition of VF and TC TX bandwidth configuration */
13936 struct cmd_vf_tc_bw_result {
13937         cmdline_fixed_string_t set;
13938         cmdline_fixed_string_t vf;
13939         cmdline_fixed_string_t tc;
13940         cmdline_fixed_string_t tx;
13941         cmdline_fixed_string_t min_bw;
13942         cmdline_fixed_string_t max_bw;
13943         cmdline_fixed_string_t strict_link_prio;
13944         portid_t port_id;
13945         uint16_t vf_id;
13946         uint8_t tc_no;
13947         uint32_t bw;
13948         cmdline_fixed_string_t bw_list;
13949         uint8_t tc_map;
13950 };
13951
13952 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13953         TOKEN_STRING_INITIALIZER
13954                 (struct cmd_vf_tc_bw_result,
13955                  set, "set");
13956 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_vf_tc_bw_result,
13959                  vf, "vf");
13960 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_vf_tc_bw_result,
13963                  tc, "tc");
13964 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_vf_tc_bw_result,
13967                  tx, "tx");
13968 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_vf_tc_bw_result,
13971                  strict_link_prio, "strict-link-priority");
13972 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13973         TOKEN_STRING_INITIALIZER
13974                 (struct cmd_vf_tc_bw_result,
13975                  min_bw, "min-bandwidth");
13976 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13977         TOKEN_STRING_INITIALIZER
13978                 (struct cmd_vf_tc_bw_result,
13979                  max_bw, "max-bandwidth");
13980 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13981         TOKEN_NUM_INITIALIZER
13982                 (struct cmd_vf_tc_bw_result,
13983                  port_id, UINT16);
13984 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13985         TOKEN_NUM_INITIALIZER
13986                 (struct cmd_vf_tc_bw_result,
13987                  vf_id, UINT16);
13988 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13989         TOKEN_NUM_INITIALIZER
13990                 (struct cmd_vf_tc_bw_result,
13991                  tc_no, UINT8);
13992 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13993         TOKEN_NUM_INITIALIZER
13994                 (struct cmd_vf_tc_bw_result,
13995                  bw, UINT32);
13996 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13997         TOKEN_STRING_INITIALIZER
13998                 (struct cmd_vf_tc_bw_result,
13999                  bw_list, NULL);
14000 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14001         TOKEN_NUM_INITIALIZER
14002                 (struct cmd_vf_tc_bw_result,
14003                  tc_map, UINT8);
14004
14005 /* VF max bandwidth setting */
14006 static void
14007 cmd_vf_max_bw_parsed(
14008         void *parsed_result,
14009         __attribute__((unused)) struct cmdline *cl,
14010         __attribute__((unused)) void *data)
14011 {
14012         struct cmd_vf_tc_bw_result *res = parsed_result;
14013         int ret = -ENOTSUP;
14014
14015         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14016                 return;
14017
14018 #ifdef RTE_LIBRTE_I40E_PMD
14019         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14020                                          res->vf_id, res->bw);
14021 #endif
14022
14023         switch (ret) {
14024         case 0:
14025                 break;
14026         case -EINVAL:
14027                 printf("invalid vf_id %d or bandwidth %d\n",
14028                        res->vf_id, res->bw);
14029                 break;
14030         case -ENODEV:
14031                 printf("invalid port_id %d\n", res->port_id);
14032                 break;
14033         case -ENOTSUP:
14034                 printf("function not implemented\n");
14035                 break;
14036         default:
14037                 printf("programming error: (%s)\n", strerror(-ret));
14038         }
14039 }
14040
14041 cmdline_parse_inst_t cmd_vf_max_bw = {
14042         .f = cmd_vf_max_bw_parsed,
14043         .data = NULL,
14044         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14045         .tokens = {
14046                 (void *)&cmd_vf_tc_bw_set,
14047                 (void *)&cmd_vf_tc_bw_vf,
14048                 (void *)&cmd_vf_tc_bw_tx,
14049                 (void *)&cmd_vf_tc_bw_max_bw,
14050                 (void *)&cmd_vf_tc_bw_port_id,
14051                 (void *)&cmd_vf_tc_bw_vf_id,
14052                 (void *)&cmd_vf_tc_bw_bw,
14053                 NULL,
14054         },
14055 };
14056
14057 static int
14058 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14059                            uint8_t *tc_num,
14060                            char *str)
14061 {
14062         uint32_t size;
14063         const char *p, *p0 = str;
14064         char s[256];
14065         char *end;
14066         char *str_fld[16];
14067         uint16_t i;
14068         int ret;
14069
14070         p = strchr(p0, '(');
14071         if (p == NULL) {
14072                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14073                 return -1;
14074         }
14075         p++;
14076         p0 = strchr(p, ')');
14077         if (p0 == NULL) {
14078                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14079                 return -1;
14080         }
14081         size = p0 - p;
14082         if (size >= sizeof(s)) {
14083                 printf("The string size exceeds the internal buffer size\n");
14084                 return -1;
14085         }
14086         snprintf(s, sizeof(s), "%.*s", size, p);
14087         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14088         if (ret <= 0) {
14089                 printf("Failed to get the bandwidth list. ");
14090                 return -1;
14091         }
14092         *tc_num = ret;
14093         for (i = 0; i < ret; i++)
14094                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14095
14096         return 0;
14097 }
14098
14099 /* TC min bandwidth setting */
14100 static void
14101 cmd_vf_tc_min_bw_parsed(
14102         void *parsed_result,
14103         __attribute__((unused)) struct cmdline *cl,
14104         __attribute__((unused)) void *data)
14105 {
14106         struct cmd_vf_tc_bw_result *res = parsed_result;
14107         uint8_t tc_num;
14108         uint8_t bw[16];
14109         int ret = -ENOTSUP;
14110
14111         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14112                 return;
14113
14114         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14115         if (ret)
14116                 return;
14117
14118 #ifdef RTE_LIBRTE_I40E_PMD
14119         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14120                                               tc_num, bw);
14121 #endif
14122
14123         switch (ret) {
14124         case 0:
14125                 break;
14126         case -EINVAL:
14127                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14128                 break;
14129         case -ENODEV:
14130                 printf("invalid port_id %d\n", res->port_id);
14131                 break;
14132         case -ENOTSUP:
14133                 printf("function not implemented\n");
14134                 break;
14135         default:
14136                 printf("programming error: (%s)\n", strerror(-ret));
14137         }
14138 }
14139
14140 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14141         .f = cmd_vf_tc_min_bw_parsed,
14142         .data = NULL,
14143         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14144                     " <bw1, bw2, ...>",
14145         .tokens = {
14146                 (void *)&cmd_vf_tc_bw_set,
14147                 (void *)&cmd_vf_tc_bw_vf,
14148                 (void *)&cmd_vf_tc_bw_tc,
14149                 (void *)&cmd_vf_tc_bw_tx,
14150                 (void *)&cmd_vf_tc_bw_min_bw,
14151                 (void *)&cmd_vf_tc_bw_port_id,
14152                 (void *)&cmd_vf_tc_bw_vf_id,
14153                 (void *)&cmd_vf_tc_bw_bw_list,
14154                 NULL,
14155         },
14156 };
14157
14158 static void
14159 cmd_tc_min_bw_parsed(
14160         void *parsed_result,
14161         __attribute__((unused)) struct cmdline *cl,
14162         __attribute__((unused)) void *data)
14163 {
14164         struct cmd_vf_tc_bw_result *res = parsed_result;
14165         struct rte_port *port;
14166         uint8_t tc_num;
14167         uint8_t bw[16];
14168         int ret = -ENOTSUP;
14169
14170         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14171                 return;
14172
14173         port = &ports[res->port_id];
14174         /** Check if the port is not started **/
14175         if (port->port_status != RTE_PORT_STOPPED) {
14176                 printf("Please stop port %d first\n", res->port_id);
14177                 return;
14178         }
14179
14180         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14181         if (ret)
14182                 return;
14183
14184 #ifdef RTE_LIBRTE_IXGBE_PMD
14185         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14186 #endif
14187
14188         switch (ret) {
14189         case 0:
14190                 break;
14191         case -EINVAL:
14192                 printf("invalid bandwidth\n");
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_tc_min_bw = {
14206         .f = cmd_tc_min_bw_parsed,
14207         .data = NULL,
14208         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14209         .tokens = {
14210                 (void *)&cmd_vf_tc_bw_set,
14211                 (void *)&cmd_vf_tc_bw_tc,
14212                 (void *)&cmd_vf_tc_bw_tx,
14213                 (void *)&cmd_vf_tc_bw_min_bw,
14214                 (void *)&cmd_vf_tc_bw_port_id,
14215                 (void *)&cmd_vf_tc_bw_bw_list,
14216                 NULL,
14217         },
14218 };
14219
14220 /* TC max bandwidth setting */
14221 static void
14222 cmd_vf_tc_max_bw_parsed(
14223         void *parsed_result,
14224         __attribute__((unused)) struct cmdline *cl,
14225         __attribute__((unused)) void *data)
14226 {
14227         struct cmd_vf_tc_bw_result *res = parsed_result;
14228         int ret = -ENOTSUP;
14229
14230         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14231                 return;
14232
14233 #ifdef RTE_LIBRTE_I40E_PMD
14234         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14235                                             res->tc_no, res->bw);
14236 #endif
14237
14238         switch (ret) {
14239         case 0:
14240                 break;
14241         case -EINVAL:
14242                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14243                        res->vf_id, res->tc_no, res->bw);
14244                 break;
14245         case -ENODEV:
14246                 printf("invalid port_id %d\n", res->port_id);
14247                 break;
14248         case -ENOTSUP:
14249                 printf("function not implemented\n");
14250                 break;
14251         default:
14252                 printf("programming error: (%s)\n", strerror(-ret));
14253         }
14254 }
14255
14256 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14257         .f = cmd_vf_tc_max_bw_parsed,
14258         .data = NULL,
14259         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14260                     " <bandwidth>",
14261         .tokens = {
14262                 (void *)&cmd_vf_tc_bw_set,
14263                 (void *)&cmd_vf_tc_bw_vf,
14264                 (void *)&cmd_vf_tc_bw_tc,
14265                 (void *)&cmd_vf_tc_bw_tx,
14266                 (void *)&cmd_vf_tc_bw_max_bw,
14267                 (void *)&cmd_vf_tc_bw_port_id,
14268                 (void *)&cmd_vf_tc_bw_vf_id,
14269                 (void *)&cmd_vf_tc_bw_tc_no,
14270                 (void *)&cmd_vf_tc_bw_bw,
14271                 NULL,
14272         },
14273 };
14274
14275
14276 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14277
14278 /* *** Set Port default Traffic Management Hierarchy *** */
14279 struct cmd_set_port_tm_hierarchy_default_result {
14280         cmdline_fixed_string_t set;
14281         cmdline_fixed_string_t port;
14282         cmdline_fixed_string_t tm;
14283         cmdline_fixed_string_t hierarchy;
14284         cmdline_fixed_string_t def;
14285         portid_t port_id;
14286 };
14287
14288 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14289         TOKEN_STRING_INITIALIZER(
14290                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14291 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14292         TOKEN_STRING_INITIALIZER(
14293                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14294 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14295         TOKEN_STRING_INITIALIZER(
14296                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14297 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14298         TOKEN_STRING_INITIALIZER(
14299                 struct cmd_set_port_tm_hierarchy_default_result,
14300                         hierarchy, "hierarchy");
14301 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14302         TOKEN_STRING_INITIALIZER(
14303                 struct cmd_set_port_tm_hierarchy_default_result,
14304                         def, "default");
14305 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14306         TOKEN_NUM_INITIALIZER(
14307                 struct cmd_set_port_tm_hierarchy_default_result,
14308                         port_id, UINT16);
14309
14310 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14311         __attribute__((unused)) struct cmdline *cl,
14312         __attribute__((unused)) void *data)
14313 {
14314         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14315         struct rte_port *p;
14316         portid_t port_id = res->port_id;
14317
14318         if (port_id_is_invalid(port_id, ENABLED_WARN))
14319                 return;
14320
14321         p = &ports[port_id];
14322
14323         /* Port tm flag */
14324         if (p->softport.tm_flag == 0) {
14325                 printf("  tm not enabled on port %u (error)\n", port_id);
14326                 return;
14327         }
14328
14329         /* Forward mode: tm */
14330         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14331                 printf("  tm mode not enabled(error)\n");
14332                 return;
14333         }
14334
14335         /* Set the default tm hierarchy */
14336         p->softport.tm.default_hierarchy_enable = 1;
14337 }
14338
14339 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14340         .f = cmd_set_port_tm_hierarchy_default_parsed,
14341         .data = NULL,
14342         .help_str = "set port tm hierarchy default <port_id>",
14343         .tokens = {
14344                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14345                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14346                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14347                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14348                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14349                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14350                 NULL,
14351         },
14352 };
14353 #endif
14354
14355 /* Strict link priority scheduling mode setting */
14356 static void
14357 cmd_strict_link_prio_parsed(
14358         void *parsed_result,
14359         __attribute__((unused)) struct cmdline *cl,
14360         __attribute__((unused)) void *data)
14361 {
14362         struct cmd_vf_tc_bw_result *res = parsed_result;
14363         int ret = -ENOTSUP;
14364
14365         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14366                 return;
14367
14368 #ifdef RTE_LIBRTE_I40E_PMD
14369         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14370 #endif
14371
14372         switch (ret) {
14373         case 0:
14374                 break;
14375         case -EINVAL:
14376                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14377                 break;
14378         case -ENODEV:
14379                 printf("invalid port_id %d\n", res->port_id);
14380                 break;
14381         case -ENOTSUP:
14382                 printf("function not implemented\n");
14383                 break;
14384         default:
14385                 printf("programming error: (%s)\n", strerror(-ret));
14386         }
14387 }
14388
14389 cmdline_parse_inst_t cmd_strict_link_prio = {
14390         .f = cmd_strict_link_prio_parsed,
14391         .data = NULL,
14392         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14393         .tokens = {
14394                 (void *)&cmd_vf_tc_bw_set,
14395                 (void *)&cmd_vf_tc_bw_tx,
14396                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14397                 (void *)&cmd_vf_tc_bw_port_id,
14398                 (void *)&cmd_vf_tc_bw_tc_map,
14399                 NULL,
14400         },
14401 };
14402
14403 /* Load dynamic device personalization*/
14404 struct cmd_ddp_add_result {
14405         cmdline_fixed_string_t ddp;
14406         cmdline_fixed_string_t add;
14407         portid_t port_id;
14408         char filepath[];
14409 };
14410
14411 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14412         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14413 cmdline_parse_token_string_t cmd_ddp_add_add =
14414         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14415 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14416         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14417 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14418         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14419
14420 static void
14421 cmd_ddp_add_parsed(
14422         void *parsed_result,
14423         __attribute__((unused)) struct cmdline *cl,
14424         __attribute__((unused)) void *data)
14425 {
14426         struct cmd_ddp_add_result *res = parsed_result;
14427         uint8_t *buff;
14428         uint32_t size;
14429         char *filepath;
14430         char *file_fld[2];
14431         int file_num;
14432         int ret = -ENOTSUP;
14433
14434         if (res->port_id > nb_ports) {
14435                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14436                 return;
14437         }
14438
14439         if (!all_ports_stopped()) {
14440                 printf("Please stop all ports first\n");
14441                 return;
14442         }
14443
14444         filepath = strdup(res->filepath);
14445         if (filepath == NULL) {
14446                 printf("Failed to allocate memory\n");
14447                 return;
14448         }
14449         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14450
14451         buff = open_file(file_fld[0], &size);
14452         if (!buff) {
14453                 free((void *)filepath);
14454                 return;
14455         }
14456
14457 #ifdef RTE_LIBRTE_I40E_PMD
14458         if (ret == -ENOTSUP)
14459                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14460                                                buff, size,
14461                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14462 #endif
14463
14464         if (ret == -EEXIST)
14465                 printf("Profile has already existed.\n");
14466         else if (ret < 0)
14467                 printf("Failed to load profile.\n");
14468         else if (file_num == 2)
14469                 save_file(file_fld[1], buff, size);
14470
14471         close_file(buff);
14472         free((void *)filepath);
14473 }
14474
14475 cmdline_parse_inst_t cmd_ddp_add = {
14476         .f = cmd_ddp_add_parsed,
14477         .data = NULL,
14478         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14479         .tokens = {
14480                 (void *)&cmd_ddp_add_ddp,
14481                 (void *)&cmd_ddp_add_add,
14482                 (void *)&cmd_ddp_add_port_id,
14483                 (void *)&cmd_ddp_add_filepath,
14484                 NULL,
14485         },
14486 };
14487
14488 /* Delete dynamic device personalization*/
14489 struct cmd_ddp_del_result {
14490         cmdline_fixed_string_t ddp;
14491         cmdline_fixed_string_t del;
14492         portid_t port_id;
14493         char filepath[];
14494 };
14495
14496 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14497         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14498 cmdline_parse_token_string_t cmd_ddp_del_del =
14499         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14500 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14501         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14502 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14503         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14504
14505 static void
14506 cmd_ddp_del_parsed(
14507         void *parsed_result,
14508         __attribute__((unused)) struct cmdline *cl,
14509         __attribute__((unused)) void *data)
14510 {
14511         struct cmd_ddp_del_result *res = parsed_result;
14512         uint8_t *buff;
14513         uint32_t size;
14514         int ret = -ENOTSUP;
14515
14516         if (res->port_id > nb_ports) {
14517                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14518                 return;
14519         }
14520
14521         if (!all_ports_stopped()) {
14522                 printf("Please stop all ports first\n");
14523                 return;
14524         }
14525
14526         buff = open_file(res->filepath, &size);
14527         if (!buff)
14528                 return;
14529
14530 #ifdef RTE_LIBRTE_I40E_PMD
14531         if (ret == -ENOTSUP)
14532                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14533                                                buff, size,
14534                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14535 #endif
14536
14537         if (ret == -EACCES)
14538                 printf("Profile does not exist.\n");
14539         else if (ret < 0)
14540                 printf("Failed to delete profile.\n");
14541
14542         close_file(buff);
14543 }
14544
14545 cmdline_parse_inst_t cmd_ddp_del = {
14546         .f = cmd_ddp_del_parsed,
14547         .data = NULL,
14548         .help_str = "ddp del <port_id> <profile_path>",
14549         .tokens = {
14550                 (void *)&cmd_ddp_del_ddp,
14551                 (void *)&cmd_ddp_del_del,
14552                 (void *)&cmd_ddp_del_port_id,
14553                 (void *)&cmd_ddp_del_filepath,
14554                 NULL,
14555         },
14556 };
14557
14558 /* Get dynamic device personalization profile info */
14559 struct cmd_ddp_info_result {
14560         cmdline_fixed_string_t ddp;
14561         cmdline_fixed_string_t get;
14562         cmdline_fixed_string_t info;
14563         char filepath[];
14564 };
14565
14566 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14567         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14568 cmdline_parse_token_string_t cmd_ddp_info_get =
14569         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14570 cmdline_parse_token_string_t cmd_ddp_info_info =
14571         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14572 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14573         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14574
14575 static void
14576 cmd_ddp_info_parsed(
14577         void *parsed_result,
14578         __attribute__((unused)) struct cmdline *cl,
14579         __attribute__((unused)) void *data)
14580 {
14581         struct cmd_ddp_info_result *res = parsed_result;
14582         uint8_t *pkg;
14583         uint32_t pkg_size;
14584         int ret = -ENOTSUP;
14585 #ifdef RTE_LIBRTE_I40E_PMD
14586         uint32_t i, j, n;
14587         uint8_t *buff;
14588         uint32_t buff_size = 0;
14589         struct rte_pmd_i40e_profile_info info;
14590         uint32_t dev_num = 0;
14591         struct rte_pmd_i40e_ddp_device_id *devs;
14592         uint32_t proto_num = 0;
14593         struct rte_pmd_i40e_proto_info *proto = NULL;
14594         uint32_t pctype_num = 0;
14595         struct rte_pmd_i40e_ptype_info *pctype;
14596         uint32_t ptype_num = 0;
14597         struct rte_pmd_i40e_ptype_info *ptype;
14598         uint8_t proto_id;
14599
14600 #endif
14601
14602         pkg = open_file(res->filepath, &pkg_size);
14603         if (!pkg)
14604                 return;
14605
14606 #ifdef RTE_LIBRTE_I40E_PMD
14607         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14608                                 (uint8_t *)&info, sizeof(info),
14609                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14610         if (!ret) {
14611                 printf("Global Track id:       0x%x\n", info.track_id);
14612                 printf("Global Version:        %d.%d.%d.%d\n",
14613                         info.version.major,
14614                         info.version.minor,
14615                         info.version.update,
14616                         info.version.draft);
14617                 printf("Global Package name:   %s\n\n", info.name);
14618         }
14619
14620         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14621                                 (uint8_t *)&info, sizeof(info),
14622                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14623         if (!ret) {
14624                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14625                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14626                         info.version.major,
14627                         info.version.minor,
14628                         info.version.update,
14629                         info.version.draft);
14630                 printf("i40e Profile name:     %s\n\n", info.name);
14631         }
14632
14633         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14634                                 (uint8_t *)&buff_size, sizeof(buff_size),
14635                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14636         if (!ret && buff_size) {
14637                 buff = (uint8_t *)malloc(buff_size);
14638                 if (buff) {
14639                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14640                                                 buff, buff_size,
14641                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14642                         if (!ret)
14643                                 printf("Package Notes:\n%s\n\n", buff);
14644                         free(buff);
14645                 }
14646         }
14647
14648         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14649                                 (uint8_t *)&dev_num, sizeof(dev_num),
14650                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14651         if (!ret && dev_num) {
14652                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14653                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14654                 if (devs) {
14655                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14656                                                 (uint8_t *)devs, buff_size,
14657                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14658                         if (!ret) {
14659                                 printf("List of supported devices:\n");
14660                                 for (i = 0; i < dev_num; i++) {
14661                                         printf("  %04X:%04X %04X:%04X\n",
14662                                                 devs[i].vendor_dev_id >> 16,
14663                                                 devs[i].vendor_dev_id & 0xFFFF,
14664                                                 devs[i].sub_vendor_dev_id >> 16,
14665                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14666                                 }
14667                                 printf("\n");
14668                         }
14669                         free(devs);
14670                 }
14671         }
14672
14673         /* get information about protocols and packet types */
14674         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14675                 (uint8_t *)&proto_num, sizeof(proto_num),
14676                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14677         if (ret || !proto_num)
14678                 goto no_print_return;
14679
14680         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14681         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14682         if (!proto)
14683                 goto no_print_return;
14684
14685         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14686                                         buff_size,
14687                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14688         if (!ret) {
14689                 printf("List of used protocols:\n");
14690                 for (i = 0; i < proto_num; i++)
14691                         printf("  %2u: %s\n", proto[i].proto_id,
14692                                proto[i].name);
14693                 printf("\n");
14694         }
14695         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14696                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14697                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14698         if (ret || !pctype_num)
14699                 goto no_print_pctypes;
14700
14701         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14702         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14703         if (!pctype)
14704                 goto no_print_pctypes;
14705
14706         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14707                                         buff_size,
14708                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14709         if (ret) {
14710                 free(pctype);
14711                 goto no_print_pctypes;
14712         }
14713
14714         printf("List of defined packet classification types:\n");
14715         for (i = 0; i < pctype_num; i++) {
14716                 printf("  %2u:", pctype[i].ptype_id);
14717                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14718                         proto_id = pctype[i].protocols[j];
14719                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14720                                 for (n = 0; n < proto_num; n++) {
14721                                         if (proto[n].proto_id == proto_id) {
14722                                                 printf(" %s", proto[n].name);
14723                                                 break;
14724                                         }
14725                                 }
14726                         }
14727                 }
14728                 printf("\n");
14729         }
14730         printf("\n");
14731         free(pctype);
14732
14733 no_print_pctypes:
14734
14735         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14736                                         sizeof(ptype_num),
14737                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14738         if (ret || !ptype_num)
14739                 goto no_print_return;
14740
14741         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14742         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14743         if (!ptype)
14744                 goto no_print_return;
14745
14746         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14747                                         buff_size,
14748                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14749         if (ret) {
14750                 free(ptype);
14751                 goto no_print_return;
14752         }
14753         printf("List of defined packet types:\n");
14754         for (i = 0; i < ptype_num; i++) {
14755                 printf("  %2u:", ptype[i].ptype_id);
14756                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14757                         proto_id = ptype[i].protocols[j];
14758                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14759                                 for (n = 0; n < proto_num; n++) {
14760                                         if (proto[n].proto_id == proto_id) {
14761                                                 printf(" %s", proto[n].name);
14762                                                 break;
14763                                         }
14764                                 }
14765                         }
14766                 }
14767                 printf("\n");
14768         }
14769         free(ptype);
14770         printf("\n");
14771
14772         ret = 0;
14773 no_print_return:
14774         if (proto)
14775                 free(proto);
14776 #endif
14777         if (ret == -ENOTSUP)
14778                 printf("Function not supported in PMD driver\n");
14779         close_file(pkg);
14780 }
14781
14782 cmdline_parse_inst_t cmd_ddp_get_info = {
14783         .f = cmd_ddp_info_parsed,
14784         .data = NULL,
14785         .help_str = "ddp get info <profile_path>",
14786         .tokens = {
14787                 (void *)&cmd_ddp_info_ddp,
14788                 (void *)&cmd_ddp_info_get,
14789                 (void *)&cmd_ddp_info_info,
14790                 (void *)&cmd_ddp_info_filepath,
14791                 NULL,
14792         },
14793 };
14794
14795 /* Get dynamic device personalization profile info list*/
14796 #define PROFILE_INFO_SIZE 48
14797 #define MAX_PROFILE_NUM 16
14798
14799 struct cmd_ddp_get_list_result {
14800         cmdline_fixed_string_t ddp;
14801         cmdline_fixed_string_t get;
14802         cmdline_fixed_string_t list;
14803         portid_t port_id;
14804 };
14805
14806 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14807         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14808 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14809         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14810 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14811         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14812 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14813         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14814
14815 static void
14816 cmd_ddp_get_list_parsed(
14817         void *parsed_result,
14818         __attribute__((unused)) struct cmdline *cl,
14819         __attribute__((unused)) void *data)
14820 {
14821         struct cmd_ddp_get_list_result *res = parsed_result;
14822 #ifdef RTE_LIBRTE_I40E_PMD
14823         struct rte_pmd_i40e_profile_list *p_list;
14824         struct rte_pmd_i40e_profile_info *p_info;
14825         uint32_t p_num;
14826         uint32_t size;
14827         uint32_t i;
14828 #endif
14829         int ret = -ENOTSUP;
14830
14831         if (res->port_id > nb_ports) {
14832                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14833                 return;
14834         }
14835
14836 #ifdef RTE_LIBRTE_I40E_PMD
14837         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14838         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14839         if (!p_list)
14840                 printf("%s: Failed to malloc buffer\n", __func__);
14841
14842         if (ret == -ENOTSUP)
14843                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14844                                                 (uint8_t *)p_list, size);
14845
14846         if (!ret) {
14847                 p_num = p_list->p_count;
14848                 printf("Profile number is: %d\n\n", p_num);
14849
14850                 for (i = 0; i < p_num; i++) {
14851                         p_info = &p_list->p_info[i];
14852                         printf("Profile %d:\n", i);
14853                         printf("Track id:     0x%x\n", p_info->track_id);
14854                         printf("Version:      %d.%d.%d.%d\n",
14855                                p_info->version.major,
14856                                p_info->version.minor,
14857                                p_info->version.update,
14858                                p_info->version.draft);
14859                         printf("Profile name: %s\n\n", p_info->name);
14860                 }
14861         }
14862
14863         free(p_list);
14864 #endif
14865
14866         if (ret < 0)
14867                 printf("Failed to get ddp list\n");
14868 }
14869
14870 cmdline_parse_inst_t cmd_ddp_get_list = {
14871         .f = cmd_ddp_get_list_parsed,
14872         .data = NULL,
14873         .help_str = "ddp get list <port_id>",
14874         .tokens = {
14875                 (void *)&cmd_ddp_get_list_ddp,
14876                 (void *)&cmd_ddp_get_list_get,
14877                 (void *)&cmd_ddp_get_list_list,
14878                 (void *)&cmd_ddp_get_list_port_id,
14879                 NULL,
14880         },
14881 };
14882
14883 /* show vf stats */
14884
14885 /* Common result structure for show vf stats */
14886 struct cmd_show_vf_stats_result {
14887         cmdline_fixed_string_t show;
14888         cmdline_fixed_string_t vf;
14889         cmdline_fixed_string_t stats;
14890         portid_t port_id;
14891         uint16_t vf_id;
14892 };
14893
14894 /* Common CLI fields show vf stats*/
14895 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14896         TOKEN_STRING_INITIALIZER
14897                 (struct cmd_show_vf_stats_result,
14898                  show, "show");
14899 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14900         TOKEN_STRING_INITIALIZER
14901                 (struct cmd_show_vf_stats_result,
14902                  vf, "vf");
14903 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14904         TOKEN_STRING_INITIALIZER
14905                 (struct cmd_show_vf_stats_result,
14906                  stats, "stats");
14907 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14908         TOKEN_NUM_INITIALIZER
14909                 (struct cmd_show_vf_stats_result,
14910                  port_id, UINT16);
14911 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14912         TOKEN_NUM_INITIALIZER
14913                 (struct cmd_show_vf_stats_result,
14914                  vf_id, UINT16);
14915
14916 static void
14917 cmd_show_vf_stats_parsed(
14918         void *parsed_result,
14919         __attribute__((unused)) struct cmdline *cl,
14920         __attribute__((unused)) void *data)
14921 {
14922         struct cmd_show_vf_stats_result *res = parsed_result;
14923         struct rte_eth_stats stats;
14924         int ret = -ENOTSUP;
14925         static const char *nic_stats_border = "########################";
14926
14927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14928                 return;
14929
14930         memset(&stats, 0, sizeof(stats));
14931
14932 #ifdef RTE_LIBRTE_I40E_PMD
14933         if (ret == -ENOTSUP)
14934                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14935                                                 res->vf_id,
14936                                                 &stats);
14937 #endif
14938 #ifdef RTE_LIBRTE_BNXT_PMD
14939         if (ret == -ENOTSUP)
14940                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14941                                                 res->vf_id,
14942                                                 &stats);
14943 #endif
14944
14945         switch (ret) {
14946         case 0:
14947                 break;
14948         case -EINVAL:
14949                 printf("invalid vf_id %d\n", res->vf_id);
14950                 break;
14951         case -ENODEV:
14952                 printf("invalid port_id %d\n", res->port_id);
14953                 break;
14954         case -ENOTSUP:
14955                 printf("function not implemented\n");
14956                 break;
14957         default:
14958                 printf("programming error: (%s)\n", strerror(-ret));
14959         }
14960
14961         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14962                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14963
14964         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14965                "%-"PRIu64"\n",
14966                stats.ipackets, stats.imissed, stats.ibytes);
14967         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14968         printf("  RX-nombuf:  %-10"PRIu64"\n",
14969                stats.rx_nombuf);
14970         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14971                "%-"PRIu64"\n",
14972                stats.opackets, stats.oerrors, stats.obytes);
14973
14974         printf("  %s############################%s\n",
14975                                nic_stats_border, nic_stats_border);
14976 }
14977
14978 cmdline_parse_inst_t cmd_show_vf_stats = {
14979         .f = cmd_show_vf_stats_parsed,
14980         .data = NULL,
14981         .help_str = "show vf stats <port_id> <vf_id>",
14982         .tokens = {
14983                 (void *)&cmd_show_vf_stats_show,
14984                 (void *)&cmd_show_vf_stats_vf,
14985                 (void *)&cmd_show_vf_stats_stats,
14986                 (void *)&cmd_show_vf_stats_port_id,
14987                 (void *)&cmd_show_vf_stats_vf_id,
14988                 NULL,
14989         },
14990 };
14991
14992 /* clear vf stats */
14993
14994 /* Common result structure for clear vf stats */
14995 struct cmd_clear_vf_stats_result {
14996         cmdline_fixed_string_t clear;
14997         cmdline_fixed_string_t vf;
14998         cmdline_fixed_string_t stats;
14999         portid_t port_id;
15000         uint16_t vf_id;
15001 };
15002
15003 /* Common CLI fields clear vf stats*/
15004 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15005         TOKEN_STRING_INITIALIZER
15006                 (struct cmd_clear_vf_stats_result,
15007                  clear, "clear");
15008 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15009         TOKEN_STRING_INITIALIZER
15010                 (struct cmd_clear_vf_stats_result,
15011                  vf, "vf");
15012 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_clear_vf_stats_result,
15015                  stats, "stats");
15016 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15017         TOKEN_NUM_INITIALIZER
15018                 (struct cmd_clear_vf_stats_result,
15019                  port_id, UINT16);
15020 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15021         TOKEN_NUM_INITIALIZER
15022                 (struct cmd_clear_vf_stats_result,
15023                  vf_id, UINT16);
15024
15025 static void
15026 cmd_clear_vf_stats_parsed(
15027         void *parsed_result,
15028         __attribute__((unused)) struct cmdline *cl,
15029         __attribute__((unused)) void *data)
15030 {
15031         struct cmd_clear_vf_stats_result *res = parsed_result;
15032         int ret = -ENOTSUP;
15033
15034         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15035                 return;
15036
15037 #ifdef RTE_LIBRTE_I40E_PMD
15038         if (ret == -ENOTSUP)
15039                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15040                                                   res->vf_id);
15041 #endif
15042 #ifdef RTE_LIBRTE_BNXT_PMD
15043         if (ret == -ENOTSUP)
15044                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15045                                                   res->vf_id);
15046 #endif
15047
15048         switch (ret) {
15049         case 0:
15050                 break;
15051         case -EINVAL:
15052                 printf("invalid vf_id %d\n", res->vf_id);
15053                 break;
15054         case -ENODEV:
15055                 printf("invalid port_id %d\n", res->port_id);
15056                 break;
15057         case -ENOTSUP:
15058                 printf("function not implemented\n");
15059                 break;
15060         default:
15061                 printf("programming error: (%s)\n", strerror(-ret));
15062         }
15063 }
15064
15065 cmdline_parse_inst_t cmd_clear_vf_stats = {
15066         .f = cmd_clear_vf_stats_parsed,
15067         .data = NULL,
15068         .help_str = "clear vf stats <port_id> <vf_id>",
15069         .tokens = {
15070                 (void *)&cmd_clear_vf_stats_clear,
15071                 (void *)&cmd_clear_vf_stats_vf,
15072                 (void *)&cmd_clear_vf_stats_stats,
15073                 (void *)&cmd_clear_vf_stats_port_id,
15074                 (void *)&cmd_clear_vf_stats_vf_id,
15075                 NULL,
15076         },
15077 };
15078
15079 /* port config pctype mapping reset */
15080
15081 /* Common result structure for port config pctype mapping reset */
15082 struct cmd_pctype_mapping_reset_result {
15083         cmdline_fixed_string_t port;
15084         cmdline_fixed_string_t config;
15085         portid_t port_id;
15086         cmdline_fixed_string_t pctype;
15087         cmdline_fixed_string_t mapping;
15088         cmdline_fixed_string_t reset;
15089 };
15090
15091 /* Common CLI fields for port config pctype mapping reset*/
15092 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15093         TOKEN_STRING_INITIALIZER
15094                 (struct cmd_pctype_mapping_reset_result,
15095                  port, "port");
15096 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15097         TOKEN_STRING_INITIALIZER
15098                 (struct cmd_pctype_mapping_reset_result,
15099                  config, "config");
15100 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15101         TOKEN_NUM_INITIALIZER
15102                 (struct cmd_pctype_mapping_reset_result,
15103                  port_id, UINT16);
15104 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15105         TOKEN_STRING_INITIALIZER
15106                 (struct cmd_pctype_mapping_reset_result,
15107                  pctype, "pctype");
15108 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15109         TOKEN_STRING_INITIALIZER
15110                 (struct cmd_pctype_mapping_reset_result,
15111                  mapping, "mapping");
15112 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15113         TOKEN_STRING_INITIALIZER
15114                 (struct cmd_pctype_mapping_reset_result,
15115                  reset, "reset");
15116
15117 static void
15118 cmd_pctype_mapping_reset_parsed(
15119         void *parsed_result,
15120         __attribute__((unused)) struct cmdline *cl,
15121         __attribute__((unused)) void *data)
15122 {
15123         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15124         int ret = -ENOTSUP;
15125
15126         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15127                 return;
15128
15129 #ifdef RTE_LIBRTE_I40E_PMD
15130         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15131 #endif
15132
15133         switch (ret) {
15134         case 0:
15135                 break;
15136         case -ENODEV:
15137                 printf("invalid port_id %d\n", res->port_id);
15138                 break;
15139         case -ENOTSUP:
15140                 printf("function not implemented\n");
15141                 break;
15142         default:
15143                 printf("programming error: (%s)\n", strerror(-ret));
15144         }
15145 }
15146
15147 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15148         .f = cmd_pctype_mapping_reset_parsed,
15149         .data = NULL,
15150         .help_str = "port config <port_id> pctype mapping reset",
15151         .tokens = {
15152                 (void *)&cmd_pctype_mapping_reset_port,
15153                 (void *)&cmd_pctype_mapping_reset_config,
15154                 (void *)&cmd_pctype_mapping_reset_port_id,
15155                 (void *)&cmd_pctype_mapping_reset_pctype,
15156                 (void *)&cmd_pctype_mapping_reset_mapping,
15157                 (void *)&cmd_pctype_mapping_reset_reset,
15158                 NULL,
15159         },
15160 };
15161
15162 /* show port pctype mapping */
15163
15164 /* Common result structure for show port pctype mapping */
15165 struct cmd_pctype_mapping_get_result {
15166         cmdline_fixed_string_t show;
15167         cmdline_fixed_string_t port;
15168         portid_t port_id;
15169         cmdline_fixed_string_t pctype;
15170         cmdline_fixed_string_t mapping;
15171 };
15172
15173 /* Common CLI fields for pctype mapping get */
15174 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15175         TOKEN_STRING_INITIALIZER
15176                 (struct cmd_pctype_mapping_get_result,
15177                  show, "show");
15178 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15179         TOKEN_STRING_INITIALIZER
15180                 (struct cmd_pctype_mapping_get_result,
15181                  port, "port");
15182 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15183         TOKEN_NUM_INITIALIZER
15184                 (struct cmd_pctype_mapping_get_result,
15185                  port_id, UINT16);
15186 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15187         TOKEN_STRING_INITIALIZER
15188                 (struct cmd_pctype_mapping_get_result,
15189                  pctype, "pctype");
15190 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15191         TOKEN_STRING_INITIALIZER
15192                 (struct cmd_pctype_mapping_get_result,
15193                  mapping, "mapping");
15194
15195 static void
15196 cmd_pctype_mapping_get_parsed(
15197         void *parsed_result,
15198         __attribute__((unused)) struct cmdline *cl,
15199         __attribute__((unused)) void *data)
15200 {
15201         struct cmd_pctype_mapping_get_result *res = parsed_result;
15202         int ret = -ENOTSUP;
15203 #ifdef RTE_LIBRTE_I40E_PMD
15204         struct rte_pmd_i40e_flow_type_mapping
15205                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15206         int i, j, first_pctype;
15207 #endif
15208
15209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15210                 return;
15211
15212 #ifdef RTE_LIBRTE_I40E_PMD
15213         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15214 #endif
15215
15216         switch (ret) {
15217         case 0:
15218                 break;
15219         case -ENODEV:
15220                 printf("invalid port_id %d\n", res->port_id);
15221                 return;
15222         case -ENOTSUP:
15223                 printf("function not implemented\n");
15224                 return;
15225         default:
15226                 printf("programming error: (%s)\n", strerror(-ret));
15227                 return;
15228         }
15229
15230 #ifdef RTE_LIBRTE_I40E_PMD
15231         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15232                 if (mapping[i].pctype != 0ULL) {
15233                         first_pctype = 1;
15234
15235                         printf("pctype: ");
15236                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15237                                 if (mapping[i].pctype & (1ULL << j)) {
15238                                         printf(first_pctype ?
15239                                                "%02d" : ",%02d", j);
15240                                         first_pctype = 0;
15241                                 }
15242                         }
15243                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15244                 }
15245         }
15246 #endif
15247 }
15248
15249 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15250         .f = cmd_pctype_mapping_get_parsed,
15251         .data = NULL,
15252         .help_str = "show port <port_id> pctype mapping",
15253         .tokens = {
15254                 (void *)&cmd_pctype_mapping_get_show,
15255                 (void *)&cmd_pctype_mapping_get_port,
15256                 (void *)&cmd_pctype_mapping_get_port_id,
15257                 (void *)&cmd_pctype_mapping_get_pctype,
15258                 (void *)&cmd_pctype_mapping_get_mapping,
15259                 NULL,
15260         },
15261 };
15262
15263 /* port config pctype mapping update */
15264
15265 /* Common result structure for port config pctype mapping update */
15266 struct cmd_pctype_mapping_update_result {
15267         cmdline_fixed_string_t port;
15268         cmdline_fixed_string_t config;
15269         portid_t port_id;
15270         cmdline_fixed_string_t pctype;
15271         cmdline_fixed_string_t mapping;
15272         cmdline_fixed_string_t update;
15273         cmdline_fixed_string_t pctype_list;
15274         uint16_t flow_type;
15275 };
15276
15277 /* Common CLI fields for pctype mapping update*/
15278 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15279         TOKEN_STRING_INITIALIZER
15280                 (struct cmd_pctype_mapping_update_result,
15281                  port, "port");
15282 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15283         TOKEN_STRING_INITIALIZER
15284                 (struct cmd_pctype_mapping_update_result,
15285                  config, "config");
15286 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15287         TOKEN_NUM_INITIALIZER
15288                 (struct cmd_pctype_mapping_update_result,
15289                  port_id, UINT16);
15290 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15291         TOKEN_STRING_INITIALIZER
15292                 (struct cmd_pctype_mapping_update_result,
15293                  pctype, "pctype");
15294 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15295         TOKEN_STRING_INITIALIZER
15296                 (struct cmd_pctype_mapping_update_result,
15297                  mapping, "mapping");
15298 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15299         TOKEN_STRING_INITIALIZER
15300                 (struct cmd_pctype_mapping_update_result,
15301                  update, "update");
15302 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15303         TOKEN_STRING_INITIALIZER
15304                 (struct cmd_pctype_mapping_update_result,
15305                  pctype_list, NULL);
15306 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15307         TOKEN_NUM_INITIALIZER
15308                 (struct cmd_pctype_mapping_update_result,
15309                  flow_type, UINT16);
15310
15311 static void
15312 cmd_pctype_mapping_update_parsed(
15313         void *parsed_result,
15314         __attribute__((unused)) struct cmdline *cl,
15315         __attribute__((unused)) void *data)
15316 {
15317         struct cmd_pctype_mapping_update_result *res = parsed_result;
15318         int ret = -ENOTSUP;
15319 #ifdef RTE_LIBRTE_I40E_PMD
15320         struct rte_pmd_i40e_flow_type_mapping mapping;
15321         unsigned int i;
15322         unsigned int nb_item;
15323         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15324 #endif
15325
15326         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15327                 return;
15328
15329 #ifdef RTE_LIBRTE_I40E_PMD
15330         nb_item = parse_item_list(res->pctype_list, "pctypes",
15331                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15332         mapping.flow_type = res->flow_type;
15333         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15334                 mapping.pctype |= (1ULL << pctype_list[i]);
15335         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15336                                                 &mapping,
15337                                                 1,
15338                                                 0);
15339 #endif
15340
15341         switch (ret) {
15342         case 0:
15343                 break;
15344         case -EINVAL:
15345                 printf("invalid pctype or flow type\n");
15346                 break;
15347         case -ENODEV:
15348                 printf("invalid port_id %d\n", res->port_id);
15349                 break;
15350         case -ENOTSUP:
15351                 printf("function not implemented\n");
15352                 break;
15353         default:
15354                 printf("programming error: (%s)\n", strerror(-ret));
15355         }
15356 }
15357
15358 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15359         .f = cmd_pctype_mapping_update_parsed,
15360         .data = NULL,
15361         .help_str = "port config <port_id> pctype mapping update"
15362         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15363         .tokens = {
15364                 (void *)&cmd_pctype_mapping_update_port,
15365                 (void *)&cmd_pctype_mapping_update_config,
15366                 (void *)&cmd_pctype_mapping_update_port_id,
15367                 (void *)&cmd_pctype_mapping_update_pctype,
15368                 (void *)&cmd_pctype_mapping_update_mapping,
15369                 (void *)&cmd_pctype_mapping_update_update,
15370                 (void *)&cmd_pctype_mapping_update_pc_type,
15371                 (void *)&cmd_pctype_mapping_update_flow_type,
15372                 NULL,
15373         },
15374 };
15375
15376 /* ptype mapping get */
15377
15378 /* Common result structure for ptype mapping get */
15379 struct cmd_ptype_mapping_get_result {
15380         cmdline_fixed_string_t ptype;
15381         cmdline_fixed_string_t mapping;
15382         cmdline_fixed_string_t get;
15383         portid_t port_id;
15384         uint8_t valid_only;
15385 };
15386
15387 /* Common CLI fields for ptype mapping get */
15388 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15389         TOKEN_STRING_INITIALIZER
15390                 (struct cmd_ptype_mapping_get_result,
15391                  ptype, "ptype");
15392 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15393         TOKEN_STRING_INITIALIZER
15394                 (struct cmd_ptype_mapping_get_result,
15395                  mapping, "mapping");
15396 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15397         TOKEN_STRING_INITIALIZER
15398                 (struct cmd_ptype_mapping_get_result,
15399                  get, "get");
15400 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15401         TOKEN_NUM_INITIALIZER
15402                 (struct cmd_ptype_mapping_get_result,
15403                  port_id, UINT16);
15404 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15405         TOKEN_NUM_INITIALIZER
15406                 (struct cmd_ptype_mapping_get_result,
15407                  valid_only, UINT8);
15408
15409 static void
15410 cmd_ptype_mapping_get_parsed(
15411         void *parsed_result,
15412         __attribute__((unused)) struct cmdline *cl,
15413         __attribute__((unused)) void *data)
15414 {
15415         struct cmd_ptype_mapping_get_result *res = parsed_result;
15416         int ret = -ENOTSUP;
15417 #ifdef RTE_LIBRTE_I40E_PMD
15418         int max_ptype_num = 256;
15419         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15420         uint16_t count;
15421         int i;
15422 #endif
15423
15424         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15425                 return;
15426
15427 #ifdef RTE_LIBRTE_I40E_PMD
15428         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15429                                         mapping,
15430                                         max_ptype_num,
15431                                         &count,
15432                                         res->valid_only);
15433 #endif
15434
15435         switch (ret) {
15436         case 0:
15437                 break;
15438         case -ENODEV:
15439                 printf("invalid port_id %d\n", res->port_id);
15440                 break;
15441         case -ENOTSUP:
15442                 printf("function not implemented\n");
15443                 break;
15444         default:
15445                 printf("programming error: (%s)\n", strerror(-ret));
15446         }
15447
15448 #ifdef RTE_LIBRTE_I40E_PMD
15449         if (!ret) {
15450                 for (i = 0; i < count; i++)
15451                         printf("%3d\t0x%08x\n",
15452                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15453         }
15454 #endif
15455 }
15456
15457 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15458         .f = cmd_ptype_mapping_get_parsed,
15459         .data = NULL,
15460         .help_str = "ptype mapping get <port_id> <valid_only>",
15461         .tokens = {
15462                 (void *)&cmd_ptype_mapping_get_ptype,
15463                 (void *)&cmd_ptype_mapping_get_mapping,
15464                 (void *)&cmd_ptype_mapping_get_get,
15465                 (void *)&cmd_ptype_mapping_get_port_id,
15466                 (void *)&cmd_ptype_mapping_get_valid_only,
15467                 NULL,
15468         },
15469 };
15470
15471 /* ptype mapping replace */
15472
15473 /* Common result structure for ptype mapping replace */
15474 struct cmd_ptype_mapping_replace_result {
15475         cmdline_fixed_string_t ptype;
15476         cmdline_fixed_string_t mapping;
15477         cmdline_fixed_string_t replace;
15478         portid_t port_id;
15479         uint32_t target;
15480         uint8_t mask;
15481         uint32_t pkt_type;
15482 };
15483
15484 /* Common CLI fields for ptype mapping replace */
15485 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15486         TOKEN_STRING_INITIALIZER
15487                 (struct cmd_ptype_mapping_replace_result,
15488                  ptype, "ptype");
15489 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15490         TOKEN_STRING_INITIALIZER
15491                 (struct cmd_ptype_mapping_replace_result,
15492                  mapping, "mapping");
15493 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15494         TOKEN_STRING_INITIALIZER
15495                 (struct cmd_ptype_mapping_replace_result,
15496                  replace, "replace");
15497 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15498         TOKEN_NUM_INITIALIZER
15499                 (struct cmd_ptype_mapping_replace_result,
15500                  port_id, UINT16);
15501 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15502         TOKEN_NUM_INITIALIZER
15503                 (struct cmd_ptype_mapping_replace_result,
15504                  target, UINT32);
15505 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15506         TOKEN_NUM_INITIALIZER
15507                 (struct cmd_ptype_mapping_replace_result,
15508                  mask, UINT8);
15509 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15510         TOKEN_NUM_INITIALIZER
15511                 (struct cmd_ptype_mapping_replace_result,
15512                  pkt_type, UINT32);
15513
15514 static void
15515 cmd_ptype_mapping_replace_parsed(
15516         void *parsed_result,
15517         __attribute__((unused)) struct cmdline *cl,
15518         __attribute__((unused)) void *data)
15519 {
15520         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15521         int ret = -ENOTSUP;
15522
15523         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15524                 return;
15525
15526 #ifdef RTE_LIBRTE_I40E_PMD
15527         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15528                                         res->target,
15529                                         res->mask,
15530                                         res->pkt_type);
15531 #endif
15532
15533         switch (ret) {
15534         case 0:
15535                 break;
15536         case -EINVAL:
15537                 printf("invalid ptype 0x%8x or 0x%8x\n",
15538                                 res->target, res->pkt_type);
15539                 break;
15540         case -ENODEV:
15541                 printf("invalid port_id %d\n", res->port_id);
15542                 break;
15543         case -ENOTSUP:
15544                 printf("function not implemented\n");
15545                 break;
15546         default:
15547                 printf("programming error: (%s)\n", strerror(-ret));
15548         }
15549 }
15550
15551 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15552         .f = cmd_ptype_mapping_replace_parsed,
15553         .data = NULL,
15554         .help_str =
15555                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15556         .tokens = {
15557                 (void *)&cmd_ptype_mapping_replace_ptype,
15558                 (void *)&cmd_ptype_mapping_replace_mapping,
15559                 (void *)&cmd_ptype_mapping_replace_replace,
15560                 (void *)&cmd_ptype_mapping_replace_port_id,
15561                 (void *)&cmd_ptype_mapping_replace_target,
15562                 (void *)&cmd_ptype_mapping_replace_mask,
15563                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15564                 NULL,
15565         },
15566 };
15567
15568 /* ptype mapping reset */
15569
15570 /* Common result structure for ptype mapping reset */
15571 struct cmd_ptype_mapping_reset_result {
15572         cmdline_fixed_string_t ptype;
15573         cmdline_fixed_string_t mapping;
15574         cmdline_fixed_string_t reset;
15575         portid_t port_id;
15576 };
15577
15578 /* Common CLI fields for ptype mapping reset*/
15579 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15580         TOKEN_STRING_INITIALIZER
15581                 (struct cmd_ptype_mapping_reset_result,
15582                  ptype, "ptype");
15583 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15584         TOKEN_STRING_INITIALIZER
15585                 (struct cmd_ptype_mapping_reset_result,
15586                  mapping, "mapping");
15587 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15588         TOKEN_STRING_INITIALIZER
15589                 (struct cmd_ptype_mapping_reset_result,
15590                  reset, "reset");
15591 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15592         TOKEN_NUM_INITIALIZER
15593                 (struct cmd_ptype_mapping_reset_result,
15594                  port_id, UINT16);
15595
15596 static void
15597 cmd_ptype_mapping_reset_parsed(
15598         void *parsed_result,
15599         __attribute__((unused)) struct cmdline *cl,
15600         __attribute__((unused)) void *data)
15601 {
15602         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15603         int ret = -ENOTSUP;
15604
15605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15606                 return;
15607
15608 #ifdef RTE_LIBRTE_I40E_PMD
15609         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15610 #endif
15611
15612         switch (ret) {
15613         case 0:
15614                 break;
15615         case -ENODEV:
15616                 printf("invalid port_id %d\n", res->port_id);
15617                 break;
15618         case -ENOTSUP:
15619                 printf("function not implemented\n");
15620                 break;
15621         default:
15622                 printf("programming error: (%s)\n", strerror(-ret));
15623         }
15624 }
15625
15626 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15627         .f = cmd_ptype_mapping_reset_parsed,
15628         .data = NULL,
15629         .help_str = "ptype mapping reset <port_id>",
15630         .tokens = {
15631                 (void *)&cmd_ptype_mapping_reset_ptype,
15632                 (void *)&cmd_ptype_mapping_reset_mapping,
15633                 (void *)&cmd_ptype_mapping_reset_reset,
15634                 (void *)&cmd_ptype_mapping_reset_port_id,
15635                 NULL,
15636         },
15637 };
15638
15639 /* ptype mapping update */
15640
15641 /* Common result structure for ptype mapping update */
15642 struct cmd_ptype_mapping_update_result {
15643         cmdline_fixed_string_t ptype;
15644         cmdline_fixed_string_t mapping;
15645         cmdline_fixed_string_t reset;
15646         portid_t port_id;
15647         uint8_t hw_ptype;
15648         uint32_t sw_ptype;
15649 };
15650
15651 /* Common CLI fields for ptype mapping update*/
15652 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15653         TOKEN_STRING_INITIALIZER
15654                 (struct cmd_ptype_mapping_update_result,
15655                  ptype, "ptype");
15656 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15657         TOKEN_STRING_INITIALIZER
15658                 (struct cmd_ptype_mapping_update_result,
15659                  mapping, "mapping");
15660 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15661         TOKEN_STRING_INITIALIZER
15662                 (struct cmd_ptype_mapping_update_result,
15663                  reset, "update");
15664 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15665         TOKEN_NUM_INITIALIZER
15666                 (struct cmd_ptype_mapping_update_result,
15667                  port_id, UINT16);
15668 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15669         TOKEN_NUM_INITIALIZER
15670                 (struct cmd_ptype_mapping_update_result,
15671                  hw_ptype, UINT8);
15672 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15673         TOKEN_NUM_INITIALIZER
15674                 (struct cmd_ptype_mapping_update_result,
15675                  sw_ptype, UINT32);
15676
15677 static void
15678 cmd_ptype_mapping_update_parsed(
15679         void *parsed_result,
15680         __attribute__((unused)) struct cmdline *cl,
15681         __attribute__((unused)) void *data)
15682 {
15683         struct cmd_ptype_mapping_update_result *res = parsed_result;
15684         int ret = -ENOTSUP;
15685 #ifdef RTE_LIBRTE_I40E_PMD
15686         struct rte_pmd_i40e_ptype_mapping mapping;
15687 #endif
15688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15689                 return;
15690
15691 #ifdef RTE_LIBRTE_I40E_PMD
15692         mapping.hw_ptype = res->hw_ptype;
15693         mapping.sw_ptype = res->sw_ptype;
15694         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15695                                                 &mapping,
15696                                                 1,
15697                                                 0);
15698 #endif
15699
15700         switch (ret) {
15701         case 0:
15702                 break;
15703         case -EINVAL:
15704                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15705                 break;
15706         case -ENODEV:
15707                 printf("invalid port_id %d\n", res->port_id);
15708                 break;
15709         case -ENOTSUP:
15710                 printf("function not implemented\n");
15711                 break;
15712         default:
15713                 printf("programming error: (%s)\n", strerror(-ret));
15714         }
15715 }
15716
15717 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15718         .f = cmd_ptype_mapping_update_parsed,
15719         .data = NULL,
15720         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15721         .tokens = {
15722                 (void *)&cmd_ptype_mapping_update_ptype,
15723                 (void *)&cmd_ptype_mapping_update_mapping,
15724                 (void *)&cmd_ptype_mapping_update_update,
15725                 (void *)&cmd_ptype_mapping_update_port_id,
15726                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15727                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15728                 NULL,
15729         },
15730 };
15731
15732 /* Common result structure for file commands */
15733 struct cmd_cmdfile_result {
15734         cmdline_fixed_string_t load;
15735         cmdline_fixed_string_t filename;
15736 };
15737
15738 /* Common CLI fields for file commands */
15739 cmdline_parse_token_string_t cmd_load_cmdfile =
15740         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15741 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15742         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15743
15744 static void
15745 cmd_load_from_file_parsed(
15746         void *parsed_result,
15747         __attribute__((unused)) struct cmdline *cl,
15748         __attribute__((unused)) void *data)
15749 {
15750         struct cmd_cmdfile_result *res = parsed_result;
15751
15752         cmdline_read_from_file(res->filename);
15753 }
15754
15755 cmdline_parse_inst_t cmd_load_from_file = {
15756         .f = cmd_load_from_file_parsed,
15757         .data = NULL,
15758         .help_str = "load <filename>",
15759         .tokens = {
15760                 (void *)&cmd_load_cmdfile,
15761                 (void *)&cmd_load_cmdfile_filename,
15762                 NULL,
15763         },
15764 };
15765
15766 /* ******************************************************************************** */
15767
15768 /* list of instructions */
15769 cmdline_parse_ctx_t main_ctx[] = {
15770         (cmdline_parse_inst_t *)&cmd_help_brief,
15771         (cmdline_parse_inst_t *)&cmd_help_long,
15772         (cmdline_parse_inst_t *)&cmd_quit,
15773         (cmdline_parse_inst_t *)&cmd_load_from_file,
15774         (cmdline_parse_inst_t *)&cmd_showport,
15775         (cmdline_parse_inst_t *)&cmd_showqueue,
15776         (cmdline_parse_inst_t *)&cmd_showportall,
15777         (cmdline_parse_inst_t *)&cmd_showcfg,
15778         (cmdline_parse_inst_t *)&cmd_start,
15779         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15780         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15781         (cmdline_parse_inst_t *)&cmd_set_link_up,
15782         (cmdline_parse_inst_t *)&cmd_set_link_down,
15783         (cmdline_parse_inst_t *)&cmd_reset,
15784         (cmdline_parse_inst_t *)&cmd_set_numbers,
15785         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15786         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15787         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15788         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15789         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15790         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15791         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15792         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15793         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15794         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15795         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15796         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15797         (cmdline_parse_inst_t *)&cmd_set_link_check,
15798         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15799         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15800         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15801         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15802 #ifdef RTE_LIBRTE_PMD_BOND
15803         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15804         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15805         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15806         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15807         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15808         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15809         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15810         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15811         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15812         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15813         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15814 #endif
15815         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15816         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15817         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15818         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15819         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15820         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15821         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15822         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15823         (cmdline_parse_inst_t *)&cmd_csum_set,
15824         (cmdline_parse_inst_t *)&cmd_csum_show,
15825         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15826         (cmdline_parse_inst_t *)&cmd_tso_set,
15827         (cmdline_parse_inst_t *)&cmd_tso_show,
15828         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15829         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15830         (cmdline_parse_inst_t *)&cmd_gro_enable,
15831         (cmdline_parse_inst_t *)&cmd_gro_flush,
15832         (cmdline_parse_inst_t *)&cmd_gro_show,
15833         (cmdline_parse_inst_t *)&cmd_gso_enable,
15834         (cmdline_parse_inst_t *)&cmd_gso_size,
15835         (cmdline_parse_inst_t *)&cmd_gso_show,
15836         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15837         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15838         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15839         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15840         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15841         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15842         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15843         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15844         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15845         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15846         (cmdline_parse_inst_t *)&cmd_config_dcb,
15847         (cmdline_parse_inst_t *)&cmd_read_reg,
15848         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15849         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15850         (cmdline_parse_inst_t *)&cmd_write_reg,
15851         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15852         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15853         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15854         (cmdline_parse_inst_t *)&cmd_stop,
15855         (cmdline_parse_inst_t *)&cmd_mac_addr,
15856         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
15857         (cmdline_parse_inst_t *)&cmd_set_qmap,
15858         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15859         (cmdline_parse_inst_t *)&cmd_operate_port,
15860         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15861         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15862         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15863         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15864         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15865         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15866         (cmdline_parse_inst_t *)&cmd_config_mtu,
15867         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15868         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15869         (cmdline_parse_inst_t *)&cmd_config_rss,
15870         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15871         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15872         (cmdline_parse_inst_t *)&cmd_showport_reta,
15873         (cmdline_parse_inst_t *)&cmd_config_burst,
15874         (cmdline_parse_inst_t *)&cmd_config_thresh,
15875         (cmdline_parse_inst_t *)&cmd_config_threshold,
15876         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15877         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15878         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15879         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15880         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15881         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15882         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15883         (cmdline_parse_inst_t *)&cmd_global_config,
15884         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15885         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15886         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15887         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15888         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15889         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15890         (cmdline_parse_inst_t *)&cmd_dump,
15891         (cmdline_parse_inst_t *)&cmd_dump_one,
15892         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15893         (cmdline_parse_inst_t *)&cmd_syn_filter,
15894         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15895         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15896         (cmdline_parse_inst_t *)&cmd_flex_filter,
15897         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15898         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15899         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15900         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15901         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15902         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15903         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
15904         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15905         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15906         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15907         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15908         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15909         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15910         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15911         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15912         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15913         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15914         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15915         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15916         (cmdline_parse_inst_t *)&cmd_flow,
15917         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15918         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15919         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15920         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15921         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15922         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15923         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15924         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15925         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15926         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15927         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15928         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15929         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15930         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15931         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15932         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15933         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15934         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15935         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15936         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15937         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15938         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15939         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15940         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15941         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15942         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15943         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15944         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15945         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15946         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15947         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15948         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15949         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15950         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15951         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15952         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15953         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15954         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15955         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15956         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15957         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15958         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15959         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15960         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15961         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15962         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15963         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15964         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15965         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15966 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15967         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15968 #endif
15969         (cmdline_parse_inst_t *)&cmd_ddp_add,
15970         (cmdline_parse_inst_t *)&cmd_ddp_del,
15971         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15972         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15973         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15974         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15975         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15976         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15977         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15978         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15979
15980         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15981         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15982         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15983         (cmdline_parse_inst_t *)&cmd_queue_region,
15984         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15985         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15986         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15987         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15988         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15989         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15990         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15991         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15992         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15993         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15994         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15995         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15996         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15997         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15998         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15999         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16000         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16001         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16002         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16003         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16004         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16005         NULL,
16006 };
16007
16008 /* read cmdline commands from file */
16009 void
16010 cmdline_read_from_file(const char *filename)
16011 {
16012         struct cmdline *cl;
16013
16014         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16015         if (cl == NULL) {
16016                 printf("Failed to create file based cmdline context: %s\n",
16017                        filename);
16018                 return;
16019         }
16020
16021         cmdline_interact(cl);
16022         cmdline_quit(cl);
16023
16024         cmdline_free(cl);
16025
16026         printf("Read CLI commands from %s\n", filename);
16027 }
16028
16029 /* prompt function, called from main on MASTER lcore */
16030 void
16031 prompt(void)
16032 {
16033         /* initialize non-constant commands */
16034         cmd_set_fwd_mode_init();
16035         cmd_set_fwd_retry_mode_init();
16036
16037         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16038         if (testpmd_cl == NULL)
16039                 return;
16040         cmdline_interact(testpmd_cl);
16041         cmdline_stdin_exit(testpmd_cl);
16042 }
16043
16044 void
16045 prompt_exit(void)
16046 {
16047         if (testpmd_cl != NULL)
16048                 cmdline_quit(testpmd_cl);
16049 }
16050
16051 static void
16052 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16053 {
16054         if (id == (portid_t)RTE_PORT_ALL) {
16055                 portid_t pid;
16056
16057                 RTE_ETH_FOREACH_DEV(pid) {
16058                         /* check if need_reconfig has been set to 1 */
16059                         if (ports[pid].need_reconfig == 0)
16060                                 ports[pid].need_reconfig = dev;
16061                         /* check if need_reconfig_queues has been set to 1 */
16062                         if (ports[pid].need_reconfig_queues == 0)
16063                                 ports[pid].need_reconfig_queues = queue;
16064                 }
16065         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16066                 /* check if need_reconfig has been set to 1 */
16067                 if (ports[id].need_reconfig == 0)
16068                         ports[id].need_reconfig = dev;
16069                 /* check if need_reconfig_queues has been set to 1 */
16070                 if (ports[id].need_reconfig_queues == 0)
16071                         ports[id].need_reconfig_queues = queue;
16072         }
16073 }