app/testpmd: add ethernet peer command
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set eth-peer (port_id) (peer_addr)\n"
490                         "    set the peer address for certain port.\n\n"
491
492                         "set port (port_id) uta (mac_address|all) (on|off)\n"
493                         "    Add/Remove a or all unicast hash filter(s)"
494                         "from port X.\n\n"
495
496                         "set promisc (port_id|all) (on|off)\n"
497                         "    Set the promiscuous mode on port_id, or all.\n\n"
498
499                         "set allmulti (port_id|all) (on|off)\n"
500                         "    Set the allmulti mode on port_id, or all.\n\n"
501
502                         "set vf promisc (port_id) (vf_id) (on|off)\n"
503                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
506                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
507
508                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
509                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
510                         " (on|off) autoneg (on|off) (port_id)\n"
511                         "set flow_ctrl rx (on|off) (portid)\n"
512                         "set flow_ctrl tx (on|off) (portid)\n"
513                         "set flow_ctrl high_water (high_water) (portid)\n"
514                         "set flow_ctrl low_water (low_water) (portid)\n"
515                         "set flow_ctrl pause_time (pause_time) (portid)\n"
516                         "set flow_ctrl send_xon (send_xon) (portid)\n"
517                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
518                         "set flow_ctrl autoneg (on|off) (port_id)\n"
519                         "    Set the link flow control parameter on a port.\n\n"
520
521                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
522                         " (low_water) (pause_time) (priority) (port_id)\n"
523                         "    Set the priority flow control parameter on a"
524                         " port.\n\n"
525
526                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
527                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
528                         " queue on port.\n"
529                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
530                         " on port 0 to mapping 5.\n\n"
531
532                         "set xstats-hide-zero on|off\n"
533                         "    Set the option to hide the zero values"
534                         " for xstats display.\n"
535
536                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
537                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
538
539                         "set port (port_id) vf (vf_id) (mac_addr)"
540                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
541                         "   Add/Remove unicast or multicast MAC addr filter"
542                         " for a VF.\n\n"
543
544                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
545                         "|MPE) (on|off)\n"
546                         "    AUPE:accepts untagged VLAN;"
547                         "ROPE:accept unicast hash\n\n"
548                         "    BAM:accepts broadcast packets;"
549                         "MPE:accepts all multicast packets\n\n"
550                         "    Enable/Disable a VF receive mode of a port\n\n"
551
552                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
553                         "    Set rate limit for a queue of a port\n\n"
554
555                         "set port (port_id) vf (vf_id) rate (rate_num) "
556                         "queue_mask (queue_mask_value)\n"
557                         "    Set rate limit for queues in VF of a port\n\n"
558
559                         "set port (port_id) mirror-rule (rule_id)"
560                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
561                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
562                         "   Set pool or vlan type mirror rule on a port.\n"
563                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
564                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
565                         " to pool 0.\n\n"
566
567                         "set port (port_id) mirror-rule (rule_id)"
568                         " (uplink-mirror|downlink-mirror) dst-pool"
569                         " (pool_id) (on|off)\n"
570                         "   Set uplink or downlink type mirror rule on a port.\n"
571                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
572                         " 0 on' enable mirror income traffic to pool 0.\n\n"
573
574                         "reset port (port_id) mirror-rule (rule_id)\n"
575                         "   Reset a mirror rule.\n\n"
576
577                         "set flush_rx (on|off)\n"
578                         "   Flush (default) or don't flush RX streams before"
579                         " forwarding. Mainly used with PCAP drivers.\n\n"
580
581                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
582                         "   Set the bypass mode for the lowest port on bypass enabled"
583                         " NIC.\n\n"
584
585                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
586                         "mode (normal|bypass|isolate) (port_id)\n"
587                         "   Set the event required to initiate specified bypass mode for"
588                         " the lowest port on a bypass enabled NIC where:\n"
589                         "       timeout   = enable bypass after watchdog timeout.\n"
590                         "       os_on     = enable bypass when OS/board is powered on.\n"
591                         "       os_off    = enable bypass when OS/board is powered off.\n"
592                         "       power_on  = enable bypass when power supply is turned on.\n"
593                         "       power_off = enable bypass when power supply is turned off."
594                         "\n\n"
595
596                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
597                         "   Set the bypass watchdog timeout to 'n' seconds"
598                         " where 0 = instant.\n\n"
599
600                         "show bypass config (port_id)\n"
601                         "   Show the bypass configuration for a bypass enabled NIC"
602                         " using the lowest port on the NIC.\n\n"
603
604 #ifdef RTE_LIBRTE_PMD_BOND
605                         "create bonded device (mode) (socket)\n"
606                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
607
608                         "add bonding slave (slave_id) (port_id)\n"
609                         "       Add a slave device to a bonded device.\n\n"
610
611                         "remove bonding slave (slave_id) (port_id)\n"
612                         "       Remove a slave device from a bonded device.\n\n"
613
614                         "set bonding mode (value) (port_id)\n"
615                         "       Set the bonding mode on a bonded device.\n\n"
616
617                         "set bonding primary (slave_id) (port_id)\n"
618                         "       Set the primary slave for a bonded device.\n\n"
619
620                         "show bonding config (port_id)\n"
621                         "       Show the bonding config for port_id.\n\n"
622
623                         "set bonding mac_addr (port_id) (address)\n"
624                         "       Set the MAC address of a bonded device.\n\n"
625
626                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
627                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
628
629                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
630                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
631
632                         "set bonding mon_period (port_id) (value)\n"
633                         "       Set the bonding link status monitoring polling period in ms.\n\n"
634
635                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
636                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
637
638 #endif
639                         "set link-up port (port_id)\n"
640                         "       Set link up for a port.\n\n"
641
642                         "set link-down port (port_id)\n"
643                         "       Set link down for a port.\n\n"
644
645                         "E-tag set insertion on port-tag-id (value)"
646                         " port (port_id) vf (vf_id)\n"
647                         "    Enable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
650                         "    Disable E-tag insertion for a VF on a port\n\n"
651
652                         "E-tag set stripping (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag stripping on a port\n\n"
654
655                         "E-tag set forwarding (on|off) port (port_id)\n"
656                         "    Enable/disable E-tag based forwarding"
657                         " on a port\n\n"
658
659                         "E-tag set filter add e-tag-id (value) dst-pool"
660                         " (pool_id) port (port_id)\n"
661                         "    Add an E-tag forwarding filter on a port\n\n"
662
663                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
664                         "    Delete an E-tag forwarding filter on a port\n\n"
665
666 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
667                         "set port tm hierarchy default (port_id)\n"
668                         "       Set default traffic Management hierarchy on a port\n\n"
669
670 #endif
671                         "ddp add (port_id) (profile_path[,output_path])\n"
672                         "    Load a profile package on a port\n\n"
673
674                         "ddp del (port_id) (profile_path)\n"
675                         "    Delete a profile package from a port\n\n"
676
677                         "ptype mapping get (port_id) (valid_only)\n"
678                         "    Get ptype mapping on a port\n\n"
679
680                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
681                         "    Replace target with the pkt_type in ptype mapping\n\n"
682
683                         "ptype mapping reset (port_id)\n"
684                         "    Reset ptype mapping on a port\n\n"
685
686                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
687                         "    Update a ptype mapping item on a port\n\n"
688
689                         "set port (port_id) queue-region region_id (value) "
690                         "queue_start_index (value) queue_num (value)\n"
691                         "    Set a queue region on a port\n\n"
692
693                         "set port (port_id) queue-region region_id (value) "
694                         "flowtype (value)\n"
695                         "    Set a flowtype region index on a port\n\n"
696
697                         "set port (port_id) queue-region UP (value) region_id (value)\n"
698                         "    Set the mapping of User Priority to "
699                         "queue region on a port\n\n"
700
701                         "set port (port_id) queue-region flush (on|off)\n"
702                         "    flush all queue region related configuration\n\n"
703
704                         "show port meter cap (port_id)\n"
705                         "    Show port meter capability information\n\n"
706
707                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
708                         "    meter profile add - srtcm rfc 2697\n\n"
709
710                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
711                         "    meter profile add - trtcm rfc 2698\n\n"
712
713                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
714                         "    meter profile add - trtcm rfc 4115\n\n"
715
716                         "del port meter profile (port_id) (profile_id)\n"
717                         "    meter profile delete\n\n"
718
719                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
720                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
721                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
722                         "(dscp_tbl_entry63)]\n"
723                         "    meter create\n\n"
724
725                         "enable port meter (port_id) (mtr_id)\n"
726                         "    meter enable\n\n"
727
728                         "disable port meter (port_id) (mtr_id)\n"
729                         "    meter disable\n\n"
730
731                         "del port meter (port_id) (mtr_id)\n"
732                         "    meter delete\n\n"
733
734                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
735                         "    meter update meter profile\n\n"
736
737                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
738                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
739                         "    update meter dscp table entries\n\n"
740
741                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
742                         "(action0) [(action1) (action2)]\n"
743                         "    meter update policer action\n\n"
744
745                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
746                         "    meter update stats\n\n"
747
748                         "show port (port_id) queue-region\n"
749                         "    show all queue region related configuration info\n\n"
750
751                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
752                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
753                         "       Add port tm node private shaper profile.\n\n"
754
755                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
756                         "       Delete port tm node private shaper profile.\n\n"
757
758                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
759                         " (shaper_profile_id)\n"
760                         "       Add/update port tm node shared shaper.\n\n"
761
762                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
763                         "       Delete port tm node shared shaper.\n\n"
764
765                         "set port tm node shaper profile (port_id) (node_id)"
766                         " (shaper_profile_id)\n"
767                         "       Set port tm node shaper profile.\n\n"
768
769                         "add port tm node wred profile (port_id) (wred_profile_id)"
770                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
771                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
772                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
773                         "       Add port tm node wred profile.\n\n"
774
775                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
776                         "       Delete port tm node wred profile.\n\n"
777
778                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
779                         " (priority) (weight) (level_id) (shaper_profile_id)"
780                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
781                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
782                         "       Add port tm nonleaf node.\n\n"
783
784                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
785                         " (priority) (weight) (level_id) (shaper_profile_id)"
786                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
787                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
788                         "       Add port tm leaf node.\n\n"
789
790                         "del port tm node (port_id) (node_id)\n"
791                         "       Delete port tm node.\n\n"
792
793                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
794                         " (priority) (weight)\n"
795                         "       Set port tm node parent.\n\n"
796
797                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
798                         "       Commit tm hierarchy.\n\n"
799
800                         , list_pkt_forwarding_modes()
801                 );
802         }
803
804         if (show_all || !strcmp(res->section, "ports")) {
805
806                 cmdline_printf(
807                         cl,
808                         "\n"
809                         "Port Operations:\n"
810                         "----------------\n\n"
811
812                         "port start (port_id|all)\n"
813                         "    Start all ports or port_id.\n\n"
814
815                         "port stop (port_id|all)\n"
816                         "    Stop all ports or port_id.\n\n"
817
818                         "port close (port_id|all)\n"
819                         "    Close all ports or port_id.\n\n"
820
821                         "port attach (ident)\n"
822                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
823
824                         "port detach (port_id)\n"
825                         "    Detach physical or virtual dev by port_id\n\n"
826
827                         "port config (port_id|all)"
828                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
829                         " duplex (half|full|auto)\n"
830                         "    Set speed and duplex for all ports or port_id\n\n"
831
832                         "port config all (rxq|txq|rxd|txd) (value)\n"
833                         "    Set number for rxq/txq/rxd/txd.\n\n"
834
835                         "port config all max-pkt-len (value)\n"
836                         "    Set the max packet length.\n\n"
837
838                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
839                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
840                         " (on|off)\n"
841                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
842                         " for ports.\n\n"
843
844                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
845                         "geneve|nvgre|none|<flowtype_id>)\n"
846                         "    Set the RSS mode.\n\n"
847
848                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
849                         "    Set the RSS redirection table.\n\n"
850
851                         "port config (port_id) dcb vt (on|off) (traffic_class)"
852                         " pfc (on|off)\n"
853                         "    Set the DCB mode.\n\n"
854
855                         "port config all burst (value)\n"
856                         "    Set the number of packets per burst.\n\n"
857
858                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
859                         " (value)\n"
860                         "    Set the ring prefetch/host/writeback threshold"
861                         " for tx/rx queue.\n\n"
862
863                         "port config all (txfreet|txrst|rxfreet) (value)\n"
864                         "    Set free threshold for rx/tx, or set"
865                         " tx rs bit threshold.\n\n"
866                         "port config mtu X value\n"
867                         "    Set the MTU of port X to a given value\n\n"
868
869                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
870                         "    Start/stop a rx/tx queue of port X. Only take effect"
871                         " when port X is started\n\n"
872
873                         "port config (port_id|all) l2-tunnel E-tag ether-type"
874                         " (value)\n"
875                         "    Set the value of E-tag ether-type.\n\n"
876
877                         "port config (port_id|all) l2-tunnel E-tag"
878                         " (enable|disable)\n"
879                         "    Enable/disable the E-tag support.\n\n"
880
881                         "port config (port_id) pctype mapping reset\n"
882                         "    Reset flow type to pctype mapping on a port\n\n"
883
884                         "port config (port_id) pctype mapping update"
885                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
886                         "    Update a flow type to pctype mapping item on a port\n\n"
887                 );
888         }
889
890         if (show_all || !strcmp(res->section, "registers")) {
891
892                 cmdline_printf(
893                         cl,
894                         "\n"
895                         "Registers:\n"
896                         "----------\n\n"
897
898                         "read reg (port_id) (address)\n"
899                         "    Display value of a port register.\n\n"
900
901                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
902                         "    Display a port register bit field.\n\n"
903
904                         "read regbit (port_id) (address) (bit_x)\n"
905                         "    Display a single port register bit.\n\n"
906
907                         "write reg (port_id) (address) (value)\n"
908                         "    Set value of a port register.\n\n"
909
910                         "write regfield (port_id) (address) (bit_x) (bit_y)"
911                         " (value)\n"
912                         "    Set bit field of a port register.\n\n"
913
914                         "write regbit (port_id) (address) (bit_x) (value)\n"
915                         "    Set single bit value of a port register.\n\n"
916                 );
917         }
918         if (show_all || !strcmp(res->section, "filters")) {
919
920                 cmdline_printf(
921                         cl,
922                         "\n"
923                         "filters:\n"
924                         "--------\n\n"
925
926                         "ethertype_filter (port_id) (add|del)"
927                         " (mac_addr|mac_ignr) (mac_address) ethertype"
928                         " (ether_type) (drop|fwd) queue (queue_id)\n"
929                         "    Add/Del an ethertype filter.\n\n"
930
931                         "2tuple_filter (port_id) (add|del)"
932                         " dst_port (dst_port_value) protocol (protocol_value)"
933                         " mask (mask_value) tcp_flags (tcp_flags_value)"
934                         " priority (prio_value) queue (queue_id)\n"
935                         "    Add/Del a 2tuple filter.\n\n"
936
937                         "5tuple_filter (port_id) (add|del)"
938                         " dst_ip (dst_address) src_ip (src_address)"
939                         " dst_port (dst_port_value) src_port (src_port_value)"
940                         " protocol (protocol_value)"
941                         " mask (mask_value) tcp_flags (tcp_flags_value)"
942                         " priority (prio_value) queue (queue_id)\n"
943                         "    Add/Del a 5tuple filter.\n\n"
944
945                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
946                         "    Add/Del syn filter.\n\n"
947
948                         "flex_filter (port_id) (add|del) len (len_value)"
949                         " bytes (bytes_value) mask (mask_value)"
950                         " priority (prio_value) queue (queue_id)\n"
951                         "    Add/Del a flex filter.\n\n"
952
953                         "flow_director_filter (port_id) mode IP (add|del|update)"
954                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
955                         " src (src_ip_address) dst (dst_ip_address)"
956                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
957                         " vlan (vlan_value) flexbytes (flexbytes_value)"
958                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
959                         " fd_id (fd_id_value)\n"
960                         "    Add/Del an IP type flow director filter.\n\n"
961
962                         "flow_director_filter (port_id) mode IP (add|del|update)"
963                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
964                         " src (src_ip_address) (src_port)"
965                         " dst (dst_ip_address) (dst_port)"
966                         " tos (tos_value) ttl (ttl_value)"
967                         " vlan (vlan_value) flexbytes (flexbytes_value)"
968                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
969                         " fd_id (fd_id_value)\n"
970                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
971
972                         "flow_director_filter (port_id) mode IP (add|del|update)"
973                         " flow (ipv4-sctp|ipv6-sctp)"
974                         " src (src_ip_address) (src_port)"
975                         " dst (dst_ip_address) (dst_port)"
976                         " tag (verification_tag) "
977                         " tos (tos_value) ttl (ttl_value)"
978                         " vlan (vlan_value)"
979                         " flexbytes (flexbytes_value) (drop|fwd)"
980                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
981                         "    Add/Del a SCTP type flow director filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow l2_payload ether (ethertype)"
985                         " flexbytes (flexbytes_value) (drop|fwd)"
986                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
987                         "    Add/Del a l2 payload type flow director filter.\n\n"
988
989                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
990                         " mac (mac_address) vlan (vlan_value)"
991                         " flexbytes (flexbytes_value) (drop|fwd)"
992                         " queue (queue_id) fd_id (fd_id_value)\n"
993                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
996                         " mac (mac_address) vlan (vlan_value)"
997                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a Tunnel flow director filter.\n\n"
1001
1002                         "flush_flow_director (port_id)\n"
1003                         "    Flush all flow director entries of a device.\n\n"
1004
1005                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1006                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1007                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1008                         "    Set flow director IP mask.\n\n"
1009
1010                         "flow_director_mask (port_id) mode MAC-VLAN"
1011                         " vlan (vlan_value)\n"
1012                         "    Set flow director MAC-VLAN mask.\n\n"
1013
1014                         "flow_director_mask (port_id) mode Tunnel"
1015                         " vlan (vlan_value) mac (mac_value)"
1016                         " tunnel-type (tunnel_type_value)"
1017                         " tunnel-id (tunnel_id_value)\n"
1018                         "    Set flow director Tunnel mask.\n\n"
1019
1020                         "flow_director_flex_mask (port_id)"
1021                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1022                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1023                         " (mask)\n"
1024                         "    Configure mask of flex payload.\n\n"
1025
1026                         "flow_director_flex_payload (port_id)"
1027                         " (raw|l2|l3|l4) (config)\n"
1028                         "    Configure flex payload selection.\n\n"
1029
1030                         "get_sym_hash_ena_per_port (port_id)\n"
1031                         "    get symmetric hash enable configuration per port.\n\n"
1032
1033                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1034                         "    set symmetric hash enable configuration per port"
1035                         " to enable or disable.\n\n"
1036
1037                         "get_hash_global_config (port_id)\n"
1038                         "    Get the global configurations of hash filters.\n\n"
1039
1040                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1041                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1042                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1043                         " (enable|disable)\n"
1044                         "    Set the global configurations of hash filters.\n\n"
1045
1046                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1047                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1048                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1049                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1050                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1051                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1052                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1053                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1054                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1055                         "fld-8th|none) (select|add)\n"
1056                         "    Set the input set for hash.\n\n"
1057
1058                         "set_fdir_input_set (port_id) "
1059                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1060                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1061                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1062                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1063                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1064                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1065                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1066                         " (select|add)\n"
1067                         "    Set the input set for FDir.\n\n"
1068
1069                         "flow validate {port_id}"
1070                         " [group {group_id}] [priority {level}]"
1071                         " [ingress] [egress]"
1072                         " pattern {item} [/ {item} [...]] / end"
1073                         " actions {action} [/ {action} [...]] / end\n"
1074                         "    Check whether a flow rule can be created.\n\n"
1075
1076                         "flow create {port_id}"
1077                         " [group {group_id}] [priority {level}]"
1078                         " [ingress] [egress]"
1079                         " pattern {item} [/ {item} [...]] / end"
1080                         " actions {action} [/ {action} [...]] / end\n"
1081                         "    Create a flow rule.\n\n"
1082
1083                         "flow destroy {port_id} rule {rule_id} [...]\n"
1084                         "    Destroy specific flow rules.\n\n"
1085
1086                         "flow flush {port_id}\n"
1087                         "    Destroy all flow rules.\n\n"
1088
1089                         "flow query {port_id} {rule_id} {action}\n"
1090                         "    Query an existing flow rule.\n\n"
1091
1092                         "flow list {port_id} [group {group_id}] [...]\n"
1093                         "    List existing flow rules sorted by priority,"
1094                         " filtered by group identifiers.\n\n"
1095
1096                         "flow isolate {port_id} {boolean}\n"
1097                         "    Restrict ingress traffic to the defined"
1098                         " flow rules\n\n"
1099                 );
1100         }
1101 }
1102
1103 cmdline_parse_token_string_t cmd_help_long_help =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1105
1106 cmdline_parse_token_string_t cmd_help_long_section =
1107         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1108                         "all#control#display#config#"
1109                         "ports#registers#filters");
1110
1111 cmdline_parse_inst_t cmd_help_long = {
1112         .f = cmd_help_long_parsed,
1113         .data = NULL,
1114         .help_str = "help all|control|display|config|ports|register|filters: "
1115                 "Show help",
1116         .tokens = {
1117                 (void *)&cmd_help_long_help,
1118                 (void *)&cmd_help_long_section,
1119                 NULL,
1120         },
1121 };
1122
1123
1124 /* *** start/stop/close all ports *** */
1125 struct cmd_operate_port_result {
1126         cmdline_fixed_string_t keyword;
1127         cmdline_fixed_string_t name;
1128         cmdline_fixed_string_t value;
1129 };
1130
1131 static void cmd_operate_port_parsed(void *parsed_result,
1132                                 __attribute__((unused)) struct cmdline *cl,
1133                                 __attribute__((unused)) void *data)
1134 {
1135         struct cmd_operate_port_result *res = parsed_result;
1136
1137         if (!strcmp(res->name, "start"))
1138                 start_port(RTE_PORT_ALL);
1139         else if (!strcmp(res->name, "stop"))
1140                 stop_port(RTE_PORT_ALL);
1141         else if (!strcmp(res->name, "close"))
1142                 close_port(RTE_PORT_ALL);
1143         else if (!strcmp(res->name, "reset"))
1144                 reset_port(RTE_PORT_ALL);
1145         else
1146                 printf("Unknown parameter\n");
1147 }
1148
1149 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1151                                                                 "port");
1152 cmdline_parse_token_string_t cmd_operate_port_all_port =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1154                                                 "start#stop#close#reset");
1155 cmdline_parse_token_string_t cmd_operate_port_all_all =
1156         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1157
1158 cmdline_parse_inst_t cmd_operate_port = {
1159         .f = cmd_operate_port_parsed,
1160         .data = NULL,
1161         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1162         .tokens = {
1163                 (void *)&cmd_operate_port_all_cmd,
1164                 (void *)&cmd_operate_port_all_port,
1165                 (void *)&cmd_operate_port_all_all,
1166                 NULL,
1167         },
1168 };
1169
1170 /* *** start/stop/close specific port *** */
1171 struct cmd_operate_specific_port_result {
1172         cmdline_fixed_string_t keyword;
1173         cmdline_fixed_string_t name;
1174         uint8_t value;
1175 };
1176
1177 static void cmd_operate_specific_port_parsed(void *parsed_result,
1178                         __attribute__((unused)) struct cmdline *cl,
1179                                 __attribute__((unused)) void *data)
1180 {
1181         struct cmd_operate_specific_port_result *res = parsed_result;
1182
1183         if (!strcmp(res->name, "start"))
1184                 start_port(res->value);
1185         else if (!strcmp(res->name, "stop"))
1186                 stop_port(res->value);
1187         else if (!strcmp(res->name, "close"))
1188                 close_port(res->value);
1189         else if (!strcmp(res->name, "reset"))
1190                 reset_port(res->value);
1191         else
1192                 printf("Unknown parameter\n");
1193 }
1194
1195 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                         keyword, "port");
1198 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1199         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                 name, "start#stop#close#reset");
1201 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1202         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1203                                                         value, UINT8);
1204
1205 cmdline_parse_inst_t cmd_operate_specific_port = {
1206         .f = cmd_operate_specific_port_parsed,
1207         .data = NULL,
1208         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1209         .tokens = {
1210                 (void *)&cmd_operate_specific_port_cmd,
1211                 (void *)&cmd_operate_specific_port_port,
1212                 (void *)&cmd_operate_specific_port_id,
1213                 NULL,
1214         },
1215 };
1216
1217 /* *** attach a specified port *** */
1218 struct cmd_operate_attach_port_result {
1219         cmdline_fixed_string_t port;
1220         cmdline_fixed_string_t keyword;
1221         cmdline_fixed_string_t identifier;
1222 };
1223
1224 static void cmd_operate_attach_port_parsed(void *parsed_result,
1225                                 __attribute__((unused)) struct cmdline *cl,
1226                                 __attribute__((unused)) void *data)
1227 {
1228         struct cmd_operate_attach_port_result *res = parsed_result;
1229
1230         if (!strcmp(res->keyword, "attach"))
1231                 attach_port(res->identifier);
1232         else
1233                 printf("Unknown parameter\n");
1234 }
1235
1236 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         port, "port");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         keyword, "attach");
1242 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1243         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1244                         identifier, NULL);
1245
1246 cmdline_parse_inst_t cmd_operate_attach_port = {
1247         .f = cmd_operate_attach_port_parsed,
1248         .data = NULL,
1249         .help_str = "port attach <identifier>: "
1250                 "(identifier: pci address or virtual dev name)",
1251         .tokens = {
1252                 (void *)&cmd_operate_attach_port_port,
1253                 (void *)&cmd_operate_attach_port_keyword,
1254                 (void *)&cmd_operate_attach_port_identifier,
1255                 NULL,
1256         },
1257 };
1258
1259 /* *** detach a specified port *** */
1260 struct cmd_operate_detach_port_result {
1261         cmdline_fixed_string_t port;
1262         cmdline_fixed_string_t keyword;
1263         portid_t port_id;
1264 };
1265
1266 static void cmd_operate_detach_port_parsed(void *parsed_result,
1267                                 __attribute__((unused)) struct cmdline *cl,
1268                                 __attribute__((unused)) void *data)
1269 {
1270         struct cmd_operate_detach_port_result *res = parsed_result;
1271
1272         if (!strcmp(res->keyword, "detach"))
1273                 detach_port(res->port_id);
1274         else
1275                 printf("Unknown parameter\n");
1276 }
1277
1278 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         port, "port");
1281 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1282         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         keyword, "detach");
1284 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1285         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1286                         port_id, UINT16);
1287
1288 cmdline_parse_inst_t cmd_operate_detach_port = {
1289         .f = cmd_operate_detach_port_parsed,
1290         .data = NULL,
1291         .help_str = "port detach <port_id>",
1292         .tokens = {
1293                 (void *)&cmd_operate_detach_port_port,
1294                 (void *)&cmd_operate_detach_port_keyword,
1295                 (void *)&cmd_operate_detach_port_port_id,
1296                 NULL,
1297         },
1298 };
1299
1300 /* *** configure speed for all ports *** */
1301 struct cmd_config_speed_all {
1302         cmdline_fixed_string_t port;
1303         cmdline_fixed_string_t keyword;
1304         cmdline_fixed_string_t all;
1305         cmdline_fixed_string_t item1;
1306         cmdline_fixed_string_t item2;
1307         cmdline_fixed_string_t value1;
1308         cmdline_fixed_string_t value2;
1309 };
1310
1311 static int
1312 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1313 {
1314
1315         int duplex;
1316
1317         if (!strcmp(duplexstr, "half")) {
1318                 duplex = ETH_LINK_HALF_DUPLEX;
1319         } else if (!strcmp(duplexstr, "full")) {
1320                 duplex = ETH_LINK_FULL_DUPLEX;
1321         } else if (!strcmp(duplexstr, "auto")) {
1322                 duplex = ETH_LINK_FULL_DUPLEX;
1323         } else {
1324                 printf("Unknown duplex parameter\n");
1325                 return -1;
1326         }
1327
1328         if (!strcmp(speedstr, "10")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1331         } else if (!strcmp(speedstr, "100")) {
1332                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1333                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1334         } else {
1335                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1336                         printf("Invalid speed/duplex parameters\n");
1337                         return -1;
1338                 }
1339                 if (!strcmp(speedstr, "1000")) {
1340                         *speed = ETH_LINK_SPEED_1G;
1341                 } else if (!strcmp(speedstr, "10000")) {
1342                         *speed = ETH_LINK_SPEED_10G;
1343                 } else if (!strcmp(speedstr, "25000")) {
1344                         *speed = ETH_LINK_SPEED_25G;
1345                 } else if (!strcmp(speedstr, "40000")) {
1346                         *speed = ETH_LINK_SPEED_40G;
1347                 } else if (!strcmp(speedstr, "50000")) {
1348                         *speed = ETH_LINK_SPEED_50G;
1349                 } else if (!strcmp(speedstr, "100000")) {
1350                         *speed = ETH_LINK_SPEED_100G;
1351                 } else if (!strcmp(speedstr, "auto")) {
1352                         *speed = ETH_LINK_SPEED_AUTONEG;
1353                 } else {
1354                         printf("Unknown speed parameter\n");
1355                         return -1;
1356                 }
1357         }
1358
1359         return 0;
1360 }
1361
1362 static void
1363 cmd_config_speed_all_parsed(void *parsed_result,
1364                         __attribute__((unused)) struct cmdline *cl,
1365                         __attribute__((unused)) void *data)
1366 {
1367         struct cmd_config_speed_all *res = parsed_result;
1368         uint32_t link_speed;
1369         portid_t pid;
1370
1371         if (!all_ports_stopped()) {
1372                 printf("Please stop all ports first\n");
1373                 return;
1374         }
1375
1376         if (parse_and_check_speed_duplex(res->value1, res->value2,
1377                         &link_speed) < 0)
1378                 return;
1379
1380         RTE_ETH_FOREACH_DEV(pid) {
1381                 ports[pid].dev_conf.link_speeds = link_speed;
1382         }
1383
1384         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1385 }
1386
1387 cmdline_parse_token_string_t cmd_config_speed_all_port =
1388         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1389 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1391                                                         "config");
1392 cmdline_parse_token_string_t cmd_config_speed_all_all =
1393         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1394 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1395         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1396 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1398                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1399 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1400         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1401 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1403                                                 "half#full#auto");
1404
1405 cmdline_parse_inst_t cmd_config_speed_all = {
1406         .f = cmd_config_speed_all_parsed,
1407         .data = NULL,
1408         .help_str = "port config all speed "
1409                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1410                                                         "half|full|auto",
1411         .tokens = {
1412                 (void *)&cmd_config_speed_all_port,
1413                 (void *)&cmd_config_speed_all_keyword,
1414                 (void *)&cmd_config_speed_all_all,
1415                 (void *)&cmd_config_speed_all_item1,
1416                 (void *)&cmd_config_speed_all_value1,
1417                 (void *)&cmd_config_speed_all_item2,
1418                 (void *)&cmd_config_speed_all_value2,
1419                 NULL,
1420         },
1421 };
1422
1423 /* *** configure speed for specific port *** */
1424 struct cmd_config_speed_specific {
1425         cmdline_fixed_string_t port;
1426         cmdline_fixed_string_t keyword;
1427         uint8_t id;
1428         cmdline_fixed_string_t item1;
1429         cmdline_fixed_string_t item2;
1430         cmdline_fixed_string_t value1;
1431         cmdline_fixed_string_t value2;
1432 };
1433
1434 static void
1435 cmd_config_speed_specific_parsed(void *parsed_result,
1436                                 __attribute__((unused)) struct cmdline *cl,
1437                                 __attribute__((unused)) void *data)
1438 {
1439         struct cmd_config_speed_specific *res = parsed_result;
1440         uint32_t link_speed;
1441
1442         if (!all_ports_stopped()) {
1443                 printf("Please stop all ports first\n");
1444                 return;
1445         }
1446
1447         if (port_id_is_invalid(res->id, ENABLED_WARN))
1448                 return;
1449
1450         if (parse_and_check_speed_duplex(res->value1, res->value2,
1451                         &link_speed) < 0)
1452                 return;
1453
1454         ports[res->id].dev_conf.link_speeds = link_speed;
1455
1456         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1457 }
1458
1459
1460 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1462                                                                 "port");
1463 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1464         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1465                                                                 "config");
1466 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1467         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1468 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1470                                                                 "speed");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1473                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1476                                                                 "duplex");
1477 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1478         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1479                                                         "half#full#auto");
1480
1481 cmdline_parse_inst_t cmd_config_speed_specific = {
1482         .f = cmd_config_speed_specific_parsed,
1483         .data = NULL,
1484         .help_str = "port config <port_id> speed "
1485                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1486                                                         "half|full|auto",
1487         .tokens = {
1488                 (void *)&cmd_config_speed_specific_port,
1489                 (void *)&cmd_config_speed_specific_keyword,
1490                 (void *)&cmd_config_speed_specific_id,
1491                 (void *)&cmd_config_speed_specific_item1,
1492                 (void *)&cmd_config_speed_specific_value1,
1493                 (void *)&cmd_config_speed_specific_item2,
1494                 (void *)&cmd_config_speed_specific_value2,
1495                 NULL,
1496         },
1497 };
1498
1499 /* *** configure txq/rxq, txd/rxd *** */
1500 struct cmd_config_rx_tx {
1501         cmdline_fixed_string_t port;
1502         cmdline_fixed_string_t keyword;
1503         cmdline_fixed_string_t all;
1504         cmdline_fixed_string_t name;
1505         uint16_t value;
1506 };
1507
1508 static void
1509 cmd_config_rx_tx_parsed(void *parsed_result,
1510                         __attribute__((unused)) struct cmdline *cl,
1511                         __attribute__((unused)) void *data)
1512 {
1513         struct cmd_config_rx_tx *res = parsed_result;
1514
1515         if (!all_ports_stopped()) {
1516                 printf("Please stop all ports first\n");
1517                 return;
1518         }
1519         if (!strcmp(res->name, "rxq")) {
1520                 if (!res->value && !nb_txq) {
1521                         printf("Warning: Either rx or tx queues should be non zero\n");
1522                         return;
1523                 }
1524                 nb_rxq = res->value;
1525         }
1526         else if (!strcmp(res->name, "txq")) {
1527                 if (!res->value && !nb_rxq) {
1528                         printf("Warning: Either rx or tx queues should be non zero\n");
1529                         return;
1530                 }
1531                 nb_txq = res->value;
1532         }
1533         else if (!strcmp(res->name, "rxd")) {
1534                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1535                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1536                                         res->value, RTE_TEST_RX_DESC_MAX);
1537                         return;
1538                 }
1539                 nb_rxd = res->value;
1540         } else if (!strcmp(res->name, "txd")) {
1541                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1542                         printf("txd %d invalid - must be > 0 && <= %d\n",
1543                                         res->value, RTE_TEST_TX_DESC_MAX);
1544                         return;
1545                 }
1546                 nb_txd = res->value;
1547         } else {
1548                 printf("Unknown parameter\n");
1549                 return;
1550         }
1551
1552         fwd_config_setup();
1553
1554         init_port_config();
1555
1556         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1557 }
1558
1559 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1561 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1563 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1565 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1567                                                 "rxq#txq#rxd#txd");
1568 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1569         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1570
1571 cmdline_parse_inst_t cmd_config_rx_tx = {
1572         .f = cmd_config_rx_tx_parsed,
1573         .data = NULL,
1574         .help_str = "port config all rxq|txq|rxd|txd <value>",
1575         .tokens = {
1576                 (void *)&cmd_config_rx_tx_port,
1577                 (void *)&cmd_config_rx_tx_keyword,
1578                 (void *)&cmd_config_rx_tx_all,
1579                 (void *)&cmd_config_rx_tx_name,
1580                 (void *)&cmd_config_rx_tx_value,
1581                 NULL,
1582         },
1583 };
1584
1585 /* *** config max packet length *** */
1586 struct cmd_config_max_pkt_len_result {
1587         cmdline_fixed_string_t port;
1588         cmdline_fixed_string_t keyword;
1589         cmdline_fixed_string_t all;
1590         cmdline_fixed_string_t name;
1591         uint32_t value;
1592 };
1593
1594 static void
1595 cmd_config_max_pkt_len_parsed(void *parsed_result,
1596                                 __attribute__((unused)) struct cmdline *cl,
1597                                 __attribute__((unused)) void *data)
1598 {
1599         struct cmd_config_max_pkt_len_result *res = parsed_result;
1600         portid_t pid;
1601
1602         if (!all_ports_stopped()) {
1603                 printf("Please stop all ports first\n");
1604                 return;
1605         }
1606
1607         RTE_ETH_FOREACH_DEV(pid) {
1608                 struct rte_port *port = &ports[pid];
1609                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1610
1611                 if (!strcmp(res->name, "max-pkt-len")) {
1612                         if (res->value < ETHER_MIN_LEN) {
1613                                 printf("max-pkt-len can not be less than %d\n",
1614                                                 ETHER_MIN_LEN);
1615                                 return;
1616                         }
1617                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1618                                 return;
1619
1620                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1621                         if (res->value > ETHER_MAX_LEN)
1622                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1623                         else
1624                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1625                         port->dev_conf.rxmode.offloads = rx_offloads;
1626                 } else {
1627                         printf("Unknown parameter\n");
1628                         return;
1629                 }
1630         }
1631
1632         init_port_config();
1633
1634         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1635 }
1636
1637 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1638         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1639                                                                 "port");
1640 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1642                                                                 "config");
1643 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1645                                                                 "all");
1646 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1648                                                                 "max-pkt-len");
1649 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1650         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1651                                                                 UINT32);
1652
1653 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1654         .f = cmd_config_max_pkt_len_parsed,
1655         .data = NULL,
1656         .help_str = "port config all max-pkt-len <value>",
1657         .tokens = {
1658                 (void *)&cmd_config_max_pkt_len_port,
1659                 (void *)&cmd_config_max_pkt_len_keyword,
1660                 (void *)&cmd_config_max_pkt_len_all,
1661                 (void *)&cmd_config_max_pkt_len_name,
1662                 (void *)&cmd_config_max_pkt_len_value,
1663                 NULL,
1664         },
1665 };
1666
1667 /* *** configure port MTU *** */
1668 struct cmd_config_mtu_result {
1669         cmdline_fixed_string_t port;
1670         cmdline_fixed_string_t keyword;
1671         cmdline_fixed_string_t mtu;
1672         portid_t port_id;
1673         uint16_t value;
1674 };
1675
1676 static void
1677 cmd_config_mtu_parsed(void *parsed_result,
1678                       __attribute__((unused)) struct cmdline *cl,
1679                       __attribute__((unused)) void *data)
1680 {
1681         struct cmd_config_mtu_result *res = parsed_result;
1682
1683         if (res->value < ETHER_MIN_LEN) {
1684                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1685                 return;
1686         }
1687         port_mtu_set(res->port_id, res->value);
1688 }
1689
1690 cmdline_parse_token_string_t cmd_config_mtu_port =
1691         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1692                                  "port");
1693 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1695                                  "config");
1696 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1697         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1698                                  "mtu");
1699 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1700         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1701 cmdline_parse_token_num_t cmd_config_mtu_value =
1702         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1703
1704 cmdline_parse_inst_t cmd_config_mtu = {
1705         .f = cmd_config_mtu_parsed,
1706         .data = NULL,
1707         .help_str = "port config mtu <port_id> <value>",
1708         .tokens = {
1709                 (void *)&cmd_config_mtu_port,
1710                 (void *)&cmd_config_mtu_keyword,
1711                 (void *)&cmd_config_mtu_mtu,
1712                 (void *)&cmd_config_mtu_port_id,
1713                 (void *)&cmd_config_mtu_value,
1714                 NULL,
1715         },
1716 };
1717
1718 /* *** configure rx mode *** */
1719 struct cmd_config_rx_mode_flag {
1720         cmdline_fixed_string_t port;
1721         cmdline_fixed_string_t keyword;
1722         cmdline_fixed_string_t all;
1723         cmdline_fixed_string_t name;
1724         cmdline_fixed_string_t value;
1725 };
1726
1727 static void
1728 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1729                                 __attribute__((unused)) struct cmdline *cl,
1730                                 __attribute__((unused)) void *data)
1731 {
1732         struct cmd_config_rx_mode_flag *res = parsed_result;
1733         portid_t pid;
1734
1735         if (!all_ports_stopped()) {
1736                 printf("Please stop all ports first\n");
1737                 return;
1738         }
1739
1740         RTE_ETH_FOREACH_DEV(pid) {
1741                 struct rte_port *port;
1742                 uint64_t rx_offloads;
1743
1744                 port = &ports[pid];
1745                 rx_offloads = port->dev_conf.rxmode.offloads;
1746                 if (!strcmp(res->name, "crc-strip")) {
1747                         if (!strcmp(res->value, "on"))
1748                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1749                         else if (!strcmp(res->value, "off"))
1750                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1751                         else {
1752                                 printf("Unknown parameter\n");
1753                                 return;
1754                         }
1755                 } else if (!strcmp(res->name, "scatter")) {
1756                         if (!strcmp(res->value, "on")) {
1757                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1758                         } else if (!strcmp(res->value, "off")) {
1759                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1760                         } else {
1761                                 printf("Unknown parameter\n");
1762                                 return;
1763                         }
1764                 } else if (!strcmp(res->name, "rx-cksum")) {
1765                         if (!strcmp(res->value, "on"))
1766                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1767                         else if (!strcmp(res->value, "off"))
1768                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1769                         else {
1770                                 printf("Unknown parameter\n");
1771                                 return;
1772                         }
1773                 } else if (!strcmp(res->name, "rx-timestamp")) {
1774                         if (!strcmp(res->value, "on"))
1775                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1776                         else if (!strcmp(res->value, "off"))
1777                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1778                         else {
1779                                 printf("Unknown parameter\n");
1780                                 return;
1781                         }
1782                 } else if (!strcmp(res->name, "hw-vlan")) {
1783                         if (!strcmp(res->value, "on")) {
1784                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1785                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1786                         } else if (!strcmp(res->value, "off")) {
1787                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1788                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1789                         } else {
1790                                 printf("Unknown parameter\n");
1791                                 return;
1792                         }
1793                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1794                         if (!strcmp(res->value, "on"))
1795                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1796                         else if (!strcmp(res->value, "off"))
1797                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1798                         else {
1799                                 printf("Unknown parameter\n");
1800                                 return;
1801                         }
1802                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1803                         if (!strcmp(res->value, "on"))
1804                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1805                         else if (!strcmp(res->value, "off"))
1806                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1807                         else {
1808                                 printf("Unknown parameter\n");
1809                                 return;
1810                         }
1811                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1812                         if (!strcmp(res->value, "on"))
1813                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1814                         else if (!strcmp(res->value, "off"))
1815                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1816                         else {
1817                                 printf("Unknown parameter\n");
1818                                 return;
1819                         }
1820                 } else if (!strcmp(res->name, "drop-en")) {
1821                         if (!strcmp(res->value, "on"))
1822                                 rx_drop_en = 1;
1823                         else if (!strcmp(res->value, "off"))
1824                                 rx_drop_en = 0;
1825                         else {
1826                                 printf("Unknown parameter\n");
1827                                 return;
1828                         }
1829                 } else {
1830                         printf("Unknown parameter\n");
1831                         return;
1832                 }
1833                 port->dev_conf.rxmode.offloads = rx_offloads;
1834         }
1835
1836         init_port_config();
1837
1838         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1839 }
1840
1841 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1843 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1845                                                                 "config");
1846 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1848 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1850                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1851                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1852 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1854                                                         "on#off");
1855
1856 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1857         .f = cmd_config_rx_mode_flag_parsed,
1858         .data = NULL,
1859         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1860                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1861         .tokens = {
1862                 (void *)&cmd_config_rx_mode_flag_port,
1863                 (void *)&cmd_config_rx_mode_flag_keyword,
1864                 (void *)&cmd_config_rx_mode_flag_all,
1865                 (void *)&cmd_config_rx_mode_flag_name,
1866                 (void *)&cmd_config_rx_mode_flag_value,
1867                 NULL,
1868         },
1869 };
1870
1871 /* *** configure rss *** */
1872 struct cmd_config_rss {
1873         cmdline_fixed_string_t port;
1874         cmdline_fixed_string_t keyword;
1875         cmdline_fixed_string_t all;
1876         cmdline_fixed_string_t name;
1877         cmdline_fixed_string_t value;
1878 };
1879
1880 static void
1881 cmd_config_rss_parsed(void *parsed_result,
1882                         __attribute__((unused)) struct cmdline *cl,
1883                         __attribute__((unused)) void *data)
1884 {
1885         struct cmd_config_rss *res = parsed_result;
1886         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1887         int diag;
1888         uint8_t i;
1889
1890         if (!strcmp(res->value, "all"))
1891                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1892                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1893                                         ETH_RSS_L2_PAYLOAD;
1894         else if (!strcmp(res->value, "ip"))
1895                 rss_conf.rss_hf = ETH_RSS_IP;
1896         else if (!strcmp(res->value, "udp"))
1897                 rss_conf.rss_hf = ETH_RSS_UDP;
1898         else if (!strcmp(res->value, "tcp"))
1899                 rss_conf.rss_hf = ETH_RSS_TCP;
1900         else if (!strcmp(res->value, "sctp"))
1901                 rss_conf.rss_hf = ETH_RSS_SCTP;
1902         else if (!strcmp(res->value, "ether"))
1903                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1904         else if (!strcmp(res->value, "port"))
1905                 rss_conf.rss_hf = ETH_RSS_PORT;
1906         else if (!strcmp(res->value, "vxlan"))
1907                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1908         else if (!strcmp(res->value, "geneve"))
1909                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1910         else if (!strcmp(res->value, "nvgre"))
1911                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1912         else if (!strcmp(res->value, "none"))
1913                 rss_conf.rss_hf = 0;
1914         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1915                                                 atoi(res->value) < 64)
1916                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1917         else {
1918                 printf("Unknown parameter\n");
1919                 return;
1920         }
1921         rss_conf.rss_key = NULL;
1922         for (i = 0; i < rte_eth_dev_count(); i++) {
1923                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1924                 if (diag < 0)
1925                         printf("Configuration of RSS hash at ethernet port %d "
1926                                 "failed with error (%d): %s.\n",
1927                                 i, -diag, strerror(-diag));
1928         }
1929 }
1930
1931 cmdline_parse_token_string_t cmd_config_rss_port =
1932         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1933 cmdline_parse_token_string_t cmd_config_rss_keyword =
1934         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1935 cmdline_parse_token_string_t cmd_config_rss_all =
1936         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1937 cmdline_parse_token_string_t cmd_config_rss_name =
1938         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1939 cmdline_parse_token_string_t cmd_config_rss_value =
1940         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1941
1942 cmdline_parse_inst_t cmd_config_rss = {
1943         .f = cmd_config_rss_parsed,
1944         .data = NULL,
1945         .help_str = "port config all rss "
1946                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1947         .tokens = {
1948                 (void *)&cmd_config_rss_port,
1949                 (void *)&cmd_config_rss_keyword,
1950                 (void *)&cmd_config_rss_all,
1951                 (void *)&cmd_config_rss_name,
1952                 (void *)&cmd_config_rss_value,
1953                 NULL,
1954         },
1955 };
1956
1957 /* *** configure rss hash key *** */
1958 struct cmd_config_rss_hash_key {
1959         cmdline_fixed_string_t port;
1960         cmdline_fixed_string_t config;
1961         portid_t port_id;
1962         cmdline_fixed_string_t rss_hash_key;
1963         cmdline_fixed_string_t rss_type;
1964         cmdline_fixed_string_t key;
1965 };
1966
1967 static uint8_t
1968 hexa_digit_to_value(char hexa_digit)
1969 {
1970         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1971                 return (uint8_t) (hexa_digit - '0');
1972         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1973                 return (uint8_t) ((hexa_digit - 'a') + 10);
1974         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1975                 return (uint8_t) ((hexa_digit - 'A') + 10);
1976         /* Invalid hexa digit */
1977         return 0xFF;
1978 }
1979
1980 static uint8_t
1981 parse_and_check_key_hexa_digit(char *key, int idx)
1982 {
1983         uint8_t hexa_v;
1984
1985         hexa_v = hexa_digit_to_value(key[idx]);
1986         if (hexa_v == 0xFF)
1987                 printf("invalid key: character %c at position %d is not a "
1988                        "valid hexa digit\n", key[idx], idx);
1989         return hexa_v;
1990 }
1991
1992 static void
1993 cmd_config_rss_hash_key_parsed(void *parsed_result,
1994                                __attribute__((unused)) struct cmdline *cl,
1995                                __attribute__((unused)) void *data)
1996 {
1997         struct cmd_config_rss_hash_key *res = parsed_result;
1998         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1999         uint8_t xdgt0;
2000         uint8_t xdgt1;
2001         int i;
2002         struct rte_eth_dev_info dev_info;
2003         uint8_t hash_key_size;
2004         uint32_t key_len;
2005
2006         memset(&dev_info, 0, sizeof(dev_info));
2007         rte_eth_dev_info_get(res->port_id, &dev_info);
2008         if (dev_info.hash_key_size > 0 &&
2009                         dev_info.hash_key_size <= sizeof(hash_key))
2010                 hash_key_size = dev_info.hash_key_size;
2011         else {
2012                 printf("dev_info did not provide a valid hash key size\n");
2013                 return;
2014         }
2015         /* Check the length of the RSS hash key */
2016         key_len = strlen(res->key);
2017         if (key_len != (hash_key_size * 2)) {
2018                 printf("key length: %d invalid - key must be a string of %d"
2019                            " hexa-decimal numbers\n",
2020                            (int) key_len, hash_key_size * 2);
2021                 return;
2022         }
2023         /* Translate RSS hash key into binary representation */
2024         for (i = 0; i < hash_key_size; i++) {
2025                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2026                 if (xdgt0 == 0xFF)
2027                         return;
2028                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2029                 if (xdgt1 == 0xFF)
2030                         return;
2031                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2032         }
2033         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2034                         hash_key_size);
2035 }
2036
2037 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2038         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2039 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2040         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2041                                  "config");
2042 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2043         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2044 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2045         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2046                                  rss_hash_key, "rss-hash-key");
2047 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2048         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2049                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2050                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2051                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2052                                  "ipv6-tcp-ex#ipv6-udp-ex");
2053 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2055
2056 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2057         .f = cmd_config_rss_hash_key_parsed,
2058         .data = NULL,
2059         .help_str = "port config <port_id> rss-hash-key "
2060                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2061                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2062                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2063                 "<string of hex digits (variable length, NIC dependent)>",
2064         .tokens = {
2065                 (void *)&cmd_config_rss_hash_key_port,
2066                 (void *)&cmd_config_rss_hash_key_config,
2067                 (void *)&cmd_config_rss_hash_key_port_id,
2068                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2069                 (void *)&cmd_config_rss_hash_key_rss_type,
2070                 (void *)&cmd_config_rss_hash_key_value,
2071                 NULL,
2072         },
2073 };
2074
2075 /* *** configure port rxq/txq start/stop *** */
2076 struct cmd_config_rxtx_queue {
2077         cmdline_fixed_string_t port;
2078         portid_t portid;
2079         cmdline_fixed_string_t rxtxq;
2080         uint16_t qid;
2081         cmdline_fixed_string_t opname;
2082 };
2083
2084 static void
2085 cmd_config_rxtx_queue_parsed(void *parsed_result,
2086                         __attribute__((unused)) struct cmdline *cl,
2087                         __attribute__((unused)) void *data)
2088 {
2089         struct cmd_config_rxtx_queue *res = parsed_result;
2090         uint8_t isrx;
2091         uint8_t isstart;
2092         int ret = 0;
2093
2094         if (test_done == 0) {
2095                 printf("Please stop forwarding first\n");
2096                 return;
2097         }
2098
2099         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2100                 return;
2101
2102         if (port_is_started(res->portid) != 1) {
2103                 printf("Please start port %u first\n", res->portid);
2104                 return;
2105         }
2106
2107         if (!strcmp(res->rxtxq, "rxq"))
2108                 isrx = 1;
2109         else if (!strcmp(res->rxtxq, "txq"))
2110                 isrx = 0;
2111         else {
2112                 printf("Unknown parameter\n");
2113                 return;
2114         }
2115
2116         if (isrx && rx_queue_id_is_invalid(res->qid))
2117                 return;
2118         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2119                 return;
2120
2121         if (!strcmp(res->opname, "start"))
2122                 isstart = 1;
2123         else if (!strcmp(res->opname, "stop"))
2124                 isstart = 0;
2125         else {
2126                 printf("Unknown parameter\n");
2127                 return;
2128         }
2129
2130         if (isstart && isrx)
2131                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2132         else if (!isstart && isrx)
2133                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2134         else if (isstart && !isrx)
2135                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2136         else
2137                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2138
2139         if (ret == -ENOTSUP)
2140                 printf("Function not supported in PMD driver\n");
2141 }
2142
2143 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2144         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2145 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2146         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2147 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2148         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2149 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2150         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2151 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2152         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2153                                                 "start#stop");
2154
2155 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2156         .f = cmd_config_rxtx_queue_parsed,
2157         .data = NULL,
2158         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2159         .tokens = {
2160                 (void *)&cmd_config_speed_all_port,
2161                 (void *)&cmd_config_rxtx_queue_portid,
2162                 (void *)&cmd_config_rxtx_queue_rxtxq,
2163                 (void *)&cmd_config_rxtx_queue_qid,
2164                 (void *)&cmd_config_rxtx_queue_opname,
2165                 NULL,
2166         },
2167 };
2168
2169 /* *** Configure RSS RETA *** */
2170 struct cmd_config_rss_reta {
2171         cmdline_fixed_string_t port;
2172         cmdline_fixed_string_t keyword;
2173         portid_t port_id;
2174         cmdline_fixed_string_t name;
2175         cmdline_fixed_string_t list_name;
2176         cmdline_fixed_string_t list_of_items;
2177 };
2178
2179 static int
2180 parse_reta_config(const char *str,
2181                   struct rte_eth_rss_reta_entry64 *reta_conf,
2182                   uint16_t nb_entries)
2183 {
2184         int i;
2185         unsigned size;
2186         uint16_t hash_index, idx, shift;
2187         uint16_t nb_queue;
2188         char s[256];
2189         const char *p, *p0 = str;
2190         char *end;
2191         enum fieldnames {
2192                 FLD_HASH_INDEX = 0,
2193                 FLD_QUEUE,
2194                 _NUM_FLD
2195         };
2196         unsigned long int_fld[_NUM_FLD];
2197         char *str_fld[_NUM_FLD];
2198
2199         while ((p = strchr(p0,'(')) != NULL) {
2200                 ++p;
2201                 if((p0 = strchr(p,')')) == NULL)
2202                         return -1;
2203
2204                 size = p0 - p;
2205                 if(size >= sizeof(s))
2206                         return -1;
2207
2208                 snprintf(s, sizeof(s), "%.*s", size, p);
2209                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2210                         return -1;
2211                 for (i = 0; i < _NUM_FLD; i++) {
2212                         errno = 0;
2213                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2214                         if (errno != 0 || end == str_fld[i] ||
2215                                         int_fld[i] > 65535)
2216                                 return -1;
2217                 }
2218
2219                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2220                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2221
2222                 if (hash_index >= nb_entries) {
2223                         printf("Invalid RETA hash index=%d\n", hash_index);
2224                         return -1;
2225                 }
2226
2227                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2228                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2229                 reta_conf[idx].mask |= (1ULL << shift);
2230                 reta_conf[idx].reta[shift] = nb_queue;
2231         }
2232
2233         return 0;
2234 }
2235
2236 static void
2237 cmd_set_rss_reta_parsed(void *parsed_result,
2238                         __attribute__((unused)) struct cmdline *cl,
2239                         __attribute__((unused)) void *data)
2240 {
2241         int ret;
2242         struct rte_eth_dev_info dev_info;
2243         struct rte_eth_rss_reta_entry64 reta_conf[8];
2244         struct cmd_config_rss_reta *res = parsed_result;
2245
2246         memset(&dev_info, 0, sizeof(dev_info));
2247         rte_eth_dev_info_get(res->port_id, &dev_info);
2248         if (dev_info.reta_size == 0) {
2249                 printf("Redirection table size is 0 which is "
2250                                         "invalid for RSS\n");
2251                 return;
2252         } else
2253                 printf("The reta size of port %d is %u\n",
2254                         res->port_id, dev_info.reta_size);
2255         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2256                 printf("Currently do not support more than %u entries of "
2257                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2258                 return;
2259         }
2260
2261         memset(reta_conf, 0, sizeof(reta_conf));
2262         if (!strcmp(res->list_name, "reta")) {
2263                 if (parse_reta_config(res->list_of_items, reta_conf,
2264                                                 dev_info.reta_size)) {
2265                         printf("Invalid RSS Redirection Table "
2266                                         "config entered\n");
2267                         return;
2268                 }
2269                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2270                                 reta_conf, dev_info.reta_size);
2271                 if (ret != 0)
2272                         printf("Bad redirection table parameter, "
2273                                         "return code = %d \n", ret);
2274         }
2275 }
2276
2277 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2278         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2279 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2280         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2281 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2282         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2283 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2285 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2286         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2287 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2288         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2289                                  NULL);
2290 cmdline_parse_inst_t cmd_config_rss_reta = {
2291         .f = cmd_set_rss_reta_parsed,
2292         .data = NULL,
2293         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2294         .tokens = {
2295                 (void *)&cmd_config_rss_reta_port,
2296                 (void *)&cmd_config_rss_reta_keyword,
2297                 (void *)&cmd_config_rss_reta_port_id,
2298                 (void *)&cmd_config_rss_reta_name,
2299                 (void *)&cmd_config_rss_reta_list_name,
2300                 (void *)&cmd_config_rss_reta_list_of_items,
2301                 NULL,
2302         },
2303 };
2304
2305 /* *** SHOW PORT RETA INFO *** */
2306 struct cmd_showport_reta {
2307         cmdline_fixed_string_t show;
2308         cmdline_fixed_string_t port;
2309         portid_t port_id;
2310         cmdline_fixed_string_t rss;
2311         cmdline_fixed_string_t reta;
2312         uint16_t size;
2313         cmdline_fixed_string_t list_of_items;
2314 };
2315
2316 static int
2317 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2318                            uint16_t nb_entries,
2319                            char *str)
2320 {
2321         uint32_t size;
2322         const char *p, *p0 = str;
2323         char s[256];
2324         char *end;
2325         char *str_fld[8];
2326         uint16_t i;
2327         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2328                         RTE_RETA_GROUP_SIZE;
2329         int ret;
2330
2331         p = strchr(p0, '(');
2332         if (p == NULL)
2333                 return -1;
2334         p++;
2335         p0 = strchr(p, ')');
2336         if (p0 == NULL)
2337                 return -1;
2338         size = p0 - p;
2339         if (size >= sizeof(s)) {
2340                 printf("The string size exceeds the internal buffer size\n");
2341                 return -1;
2342         }
2343         snprintf(s, sizeof(s), "%.*s", size, p);
2344         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2345         if (ret <= 0 || ret != num) {
2346                 printf("The bits of masks do not match the number of "
2347                                         "reta entries: %u\n", num);
2348                 return -1;
2349         }
2350         for (i = 0; i < ret; i++)
2351                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2352
2353         return 0;
2354 }
2355
2356 static void
2357 cmd_showport_reta_parsed(void *parsed_result,
2358                          __attribute__((unused)) struct cmdline *cl,
2359                          __attribute__((unused)) void *data)
2360 {
2361         struct cmd_showport_reta *res = parsed_result;
2362         struct rte_eth_rss_reta_entry64 reta_conf[8];
2363         struct rte_eth_dev_info dev_info;
2364         uint16_t max_reta_size;
2365
2366         memset(&dev_info, 0, sizeof(dev_info));
2367         rte_eth_dev_info_get(res->port_id, &dev_info);
2368         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2369         if (res->size == 0 || res->size > max_reta_size) {
2370                 printf("Invalid redirection table size: %u (1-%u)\n",
2371                         res->size, max_reta_size);
2372                 return;
2373         }
2374
2375         memset(reta_conf, 0, sizeof(reta_conf));
2376         if (showport_parse_reta_config(reta_conf, res->size,
2377                                 res->list_of_items) < 0) {
2378                 printf("Invalid string: %s for reta masks\n",
2379                                         res->list_of_items);
2380                 return;
2381         }
2382         port_rss_reta_info(res->port_id, reta_conf, res->size);
2383 }
2384
2385 cmdline_parse_token_string_t cmd_showport_reta_show =
2386         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2387 cmdline_parse_token_string_t cmd_showport_reta_port =
2388         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2389 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2390         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2391 cmdline_parse_token_string_t cmd_showport_reta_rss =
2392         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2393 cmdline_parse_token_string_t cmd_showport_reta_reta =
2394         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2395 cmdline_parse_token_num_t cmd_showport_reta_size =
2396         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2397 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2398         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2399                                         list_of_items, NULL);
2400
2401 cmdline_parse_inst_t cmd_showport_reta = {
2402         .f = cmd_showport_reta_parsed,
2403         .data = NULL,
2404         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2405         .tokens = {
2406                 (void *)&cmd_showport_reta_show,
2407                 (void *)&cmd_showport_reta_port,
2408                 (void *)&cmd_showport_reta_port_id,
2409                 (void *)&cmd_showport_reta_rss,
2410                 (void *)&cmd_showport_reta_reta,
2411                 (void *)&cmd_showport_reta_size,
2412                 (void *)&cmd_showport_reta_list_of_items,
2413                 NULL,
2414         },
2415 };
2416
2417 /* *** Show RSS hash configuration *** */
2418 struct cmd_showport_rss_hash {
2419         cmdline_fixed_string_t show;
2420         cmdline_fixed_string_t port;
2421         portid_t port_id;
2422         cmdline_fixed_string_t rss_hash;
2423         cmdline_fixed_string_t rss_type;
2424         cmdline_fixed_string_t key; /* optional argument */
2425 };
2426
2427 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2428                                 __attribute__((unused)) struct cmdline *cl,
2429                                 void *show_rss_key)
2430 {
2431         struct cmd_showport_rss_hash *res = parsed_result;
2432
2433         port_rss_hash_conf_show(res->port_id, res->rss_type,
2434                                 show_rss_key != NULL);
2435 }
2436
2437 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2438         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2439 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2440         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2441 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2442         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2443 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2444         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2445                                  "rss-hash");
2446 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2447         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2448                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2449                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2450                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2451                                  "ipv6-tcp-ex#ipv6-udp-ex");
2452 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2453         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2454
2455 cmdline_parse_inst_t cmd_showport_rss_hash = {
2456         .f = cmd_showport_rss_hash_parsed,
2457         .data = NULL,
2458         .help_str = "show port <port_id> rss-hash "
2459                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2460                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2461                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2462         .tokens = {
2463                 (void *)&cmd_showport_rss_hash_show,
2464                 (void *)&cmd_showport_rss_hash_port,
2465                 (void *)&cmd_showport_rss_hash_port_id,
2466                 (void *)&cmd_showport_rss_hash_rss_hash,
2467                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2468                 NULL,
2469         },
2470 };
2471
2472 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2473         .f = cmd_showport_rss_hash_parsed,
2474         .data = (void *)1,
2475         .help_str = "show port <port_id> rss-hash "
2476                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2477                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2478                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2479         .tokens = {
2480                 (void *)&cmd_showport_rss_hash_show,
2481                 (void *)&cmd_showport_rss_hash_port,
2482                 (void *)&cmd_showport_rss_hash_port_id,
2483                 (void *)&cmd_showport_rss_hash_rss_hash,
2484                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2485                 (void *)&cmd_showport_rss_hash_rss_key,
2486                 NULL,
2487         },
2488 };
2489
2490 /* *** Configure DCB *** */
2491 struct cmd_config_dcb {
2492         cmdline_fixed_string_t port;
2493         cmdline_fixed_string_t config;
2494         portid_t port_id;
2495         cmdline_fixed_string_t dcb;
2496         cmdline_fixed_string_t vt;
2497         cmdline_fixed_string_t vt_en;
2498         uint8_t num_tcs;
2499         cmdline_fixed_string_t pfc;
2500         cmdline_fixed_string_t pfc_en;
2501 };
2502
2503 static void
2504 cmd_config_dcb_parsed(void *parsed_result,
2505                         __attribute__((unused)) struct cmdline *cl,
2506                         __attribute__((unused)) void *data)
2507 {
2508         struct cmd_config_dcb *res = parsed_result;
2509         portid_t port_id = res->port_id;
2510         struct rte_port *port;
2511         uint8_t pfc_en;
2512         int ret;
2513
2514         port = &ports[port_id];
2515         /** Check if the port is not started **/
2516         if (port->port_status != RTE_PORT_STOPPED) {
2517                 printf("Please stop port %d first\n", port_id);
2518                 return;
2519         }
2520
2521         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2522                 printf("The invalid number of traffic class,"
2523                         " only 4 or 8 allowed.\n");
2524                 return;
2525         }
2526
2527         if (nb_fwd_lcores < res->num_tcs) {
2528                 printf("nb_cores shouldn't be less than number of TCs.\n");
2529                 return;
2530         }
2531         if (!strncmp(res->pfc_en, "on", 2))
2532                 pfc_en = 1;
2533         else
2534                 pfc_en = 0;
2535
2536         /* DCB in VT mode */
2537         if (!strncmp(res->vt_en, "on", 2))
2538                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2539                                 (enum rte_eth_nb_tcs)res->num_tcs,
2540                                 pfc_en);
2541         else
2542                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2543                                 (enum rte_eth_nb_tcs)res->num_tcs,
2544                                 pfc_en);
2545
2546
2547         if (ret != 0) {
2548                 printf("Cannot initialize network ports.\n");
2549                 return;
2550         }
2551
2552         cmd_reconfig_device_queue(port_id, 1, 1);
2553 }
2554
2555 cmdline_parse_token_string_t cmd_config_dcb_port =
2556         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2557 cmdline_parse_token_string_t cmd_config_dcb_config =
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2559 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2560         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2561 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2562         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2563 cmdline_parse_token_string_t cmd_config_dcb_vt =
2564         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2565 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2567 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2568         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2569 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2570         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2571 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2572         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2573
2574 cmdline_parse_inst_t cmd_config_dcb = {
2575         .f = cmd_config_dcb_parsed,
2576         .data = NULL,
2577         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2578         .tokens = {
2579                 (void *)&cmd_config_dcb_port,
2580                 (void *)&cmd_config_dcb_config,
2581                 (void *)&cmd_config_dcb_port_id,
2582                 (void *)&cmd_config_dcb_dcb,
2583                 (void *)&cmd_config_dcb_vt,
2584                 (void *)&cmd_config_dcb_vt_en,
2585                 (void *)&cmd_config_dcb_num_tcs,
2586                 (void *)&cmd_config_dcb_pfc,
2587                 (void *)&cmd_config_dcb_pfc_en,
2588                 NULL,
2589         },
2590 };
2591
2592 /* *** configure number of packets per burst *** */
2593 struct cmd_config_burst {
2594         cmdline_fixed_string_t port;
2595         cmdline_fixed_string_t keyword;
2596         cmdline_fixed_string_t all;
2597         cmdline_fixed_string_t name;
2598         uint16_t value;
2599 };
2600
2601 static void
2602 cmd_config_burst_parsed(void *parsed_result,
2603                         __attribute__((unused)) struct cmdline *cl,
2604                         __attribute__((unused)) void *data)
2605 {
2606         struct cmd_config_burst *res = parsed_result;
2607
2608         if (!all_ports_stopped()) {
2609                 printf("Please stop all ports first\n");
2610                 return;
2611         }
2612
2613         if (!strcmp(res->name, "burst")) {
2614                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2615                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2616                         return;
2617                 }
2618                 nb_pkt_per_burst = res->value;
2619         } else {
2620                 printf("Unknown parameter\n");
2621                 return;
2622         }
2623
2624         init_port_config();
2625
2626         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2627 }
2628
2629 cmdline_parse_token_string_t cmd_config_burst_port =
2630         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2631 cmdline_parse_token_string_t cmd_config_burst_keyword =
2632         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2633 cmdline_parse_token_string_t cmd_config_burst_all =
2634         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2635 cmdline_parse_token_string_t cmd_config_burst_name =
2636         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2637 cmdline_parse_token_num_t cmd_config_burst_value =
2638         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2639
2640 cmdline_parse_inst_t cmd_config_burst = {
2641         .f = cmd_config_burst_parsed,
2642         .data = NULL,
2643         .help_str = "port config all burst <value>",
2644         .tokens = {
2645                 (void *)&cmd_config_burst_port,
2646                 (void *)&cmd_config_burst_keyword,
2647                 (void *)&cmd_config_burst_all,
2648                 (void *)&cmd_config_burst_name,
2649                 (void *)&cmd_config_burst_value,
2650                 NULL,
2651         },
2652 };
2653
2654 /* *** configure rx/tx queues *** */
2655 struct cmd_config_thresh {
2656         cmdline_fixed_string_t port;
2657         cmdline_fixed_string_t keyword;
2658         cmdline_fixed_string_t all;
2659         cmdline_fixed_string_t name;
2660         uint8_t value;
2661 };
2662
2663 static void
2664 cmd_config_thresh_parsed(void *parsed_result,
2665                         __attribute__((unused)) struct cmdline *cl,
2666                         __attribute__((unused)) void *data)
2667 {
2668         struct cmd_config_thresh *res = parsed_result;
2669
2670         if (!all_ports_stopped()) {
2671                 printf("Please stop all ports first\n");
2672                 return;
2673         }
2674
2675         if (!strcmp(res->name, "txpt"))
2676                 tx_pthresh = res->value;
2677         else if(!strcmp(res->name, "txht"))
2678                 tx_hthresh = res->value;
2679         else if(!strcmp(res->name, "txwt"))
2680                 tx_wthresh = res->value;
2681         else if(!strcmp(res->name, "rxpt"))
2682                 rx_pthresh = res->value;
2683         else if(!strcmp(res->name, "rxht"))
2684                 rx_hthresh = res->value;
2685         else if(!strcmp(res->name, "rxwt"))
2686                 rx_wthresh = res->value;
2687         else {
2688                 printf("Unknown parameter\n");
2689                 return;
2690         }
2691
2692         init_port_config();
2693
2694         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2695 }
2696
2697 cmdline_parse_token_string_t cmd_config_thresh_port =
2698         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2699 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2700         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2701 cmdline_parse_token_string_t cmd_config_thresh_all =
2702         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2703 cmdline_parse_token_string_t cmd_config_thresh_name =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2705                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2706 cmdline_parse_token_num_t cmd_config_thresh_value =
2707         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2708
2709 cmdline_parse_inst_t cmd_config_thresh = {
2710         .f = cmd_config_thresh_parsed,
2711         .data = NULL,
2712         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2713         .tokens = {
2714                 (void *)&cmd_config_thresh_port,
2715                 (void *)&cmd_config_thresh_keyword,
2716                 (void *)&cmd_config_thresh_all,
2717                 (void *)&cmd_config_thresh_name,
2718                 (void *)&cmd_config_thresh_value,
2719                 NULL,
2720         },
2721 };
2722
2723 /* *** configure free/rs threshold *** */
2724 struct cmd_config_threshold {
2725         cmdline_fixed_string_t port;
2726         cmdline_fixed_string_t keyword;
2727         cmdline_fixed_string_t all;
2728         cmdline_fixed_string_t name;
2729         uint16_t value;
2730 };
2731
2732 static void
2733 cmd_config_threshold_parsed(void *parsed_result,
2734                         __attribute__((unused)) struct cmdline *cl,
2735                         __attribute__((unused)) void *data)
2736 {
2737         struct cmd_config_threshold *res = parsed_result;
2738
2739         if (!all_ports_stopped()) {
2740                 printf("Please stop all ports first\n");
2741                 return;
2742         }
2743
2744         if (!strcmp(res->name, "txfreet"))
2745                 tx_free_thresh = res->value;
2746         else if (!strcmp(res->name, "txrst"))
2747                 tx_rs_thresh = res->value;
2748         else if (!strcmp(res->name, "rxfreet"))
2749                 rx_free_thresh = res->value;
2750         else {
2751                 printf("Unknown parameter\n");
2752                 return;
2753         }
2754
2755         init_port_config();
2756
2757         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2758 }
2759
2760 cmdline_parse_token_string_t cmd_config_threshold_port =
2761         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2762 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2763         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2764                                                                 "config");
2765 cmdline_parse_token_string_t cmd_config_threshold_all =
2766         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2767 cmdline_parse_token_string_t cmd_config_threshold_name =
2768         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2769                                                 "txfreet#txrst#rxfreet");
2770 cmdline_parse_token_num_t cmd_config_threshold_value =
2771         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2772
2773 cmdline_parse_inst_t cmd_config_threshold = {
2774         .f = cmd_config_threshold_parsed,
2775         .data = NULL,
2776         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2777         .tokens = {
2778                 (void *)&cmd_config_threshold_port,
2779                 (void *)&cmd_config_threshold_keyword,
2780                 (void *)&cmd_config_threshold_all,
2781                 (void *)&cmd_config_threshold_name,
2782                 (void *)&cmd_config_threshold_value,
2783                 NULL,
2784         },
2785 };
2786
2787 /* *** stop *** */
2788 struct cmd_stop_result {
2789         cmdline_fixed_string_t stop;
2790 };
2791
2792 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2793                             __attribute__((unused)) struct cmdline *cl,
2794                             __attribute__((unused)) void *data)
2795 {
2796         stop_packet_forwarding();
2797 }
2798
2799 cmdline_parse_token_string_t cmd_stop_stop =
2800         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2801
2802 cmdline_parse_inst_t cmd_stop = {
2803         .f = cmd_stop_parsed,
2804         .data = NULL,
2805         .help_str = "stop: Stop packet forwarding",
2806         .tokens = {
2807                 (void *)&cmd_stop_stop,
2808                 NULL,
2809         },
2810 };
2811
2812 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2813
2814 unsigned int
2815 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2816                 unsigned int *parsed_items, int check_unique_values)
2817 {
2818         unsigned int nb_item;
2819         unsigned int value;
2820         unsigned int i;
2821         unsigned int j;
2822         int value_ok;
2823         char c;
2824
2825         /*
2826          * First parse all items in the list and store their value.
2827          */
2828         value = 0;
2829         nb_item = 0;
2830         value_ok = 0;
2831         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2832                 c = str[i];
2833                 if ((c >= '0') && (c <= '9')) {
2834                         value = (unsigned int) (value * 10 + (c - '0'));
2835                         value_ok = 1;
2836                         continue;
2837                 }
2838                 if (c != ',') {
2839                         printf("character %c is not a decimal digit\n", c);
2840                         return 0;
2841                 }
2842                 if (! value_ok) {
2843                         printf("No valid value before comma\n");
2844                         return 0;
2845                 }
2846                 if (nb_item < max_items) {
2847                         parsed_items[nb_item] = value;
2848                         value_ok = 0;
2849                         value = 0;
2850                 }
2851                 nb_item++;
2852         }
2853         if (nb_item >= max_items) {
2854                 printf("Number of %s = %u > %u (maximum items)\n",
2855                        item_name, nb_item + 1, max_items);
2856                 return 0;
2857         }
2858         parsed_items[nb_item++] = value;
2859         if (! check_unique_values)
2860                 return nb_item;
2861
2862         /*
2863          * Then, check that all values in the list are differents.
2864          * No optimization here...
2865          */
2866         for (i = 0; i < nb_item; i++) {
2867                 for (j = i + 1; j < nb_item; j++) {
2868                         if (parsed_items[j] == parsed_items[i]) {
2869                                 printf("duplicated %s %u at index %u and %u\n",
2870                                        item_name, parsed_items[i], i, j);
2871                                 return 0;
2872                         }
2873                 }
2874         }
2875         return nb_item;
2876 }
2877
2878 struct cmd_set_list_result {
2879         cmdline_fixed_string_t cmd_keyword;
2880         cmdline_fixed_string_t list_name;
2881         cmdline_fixed_string_t list_of_items;
2882 };
2883
2884 static void cmd_set_list_parsed(void *parsed_result,
2885                                 __attribute__((unused)) struct cmdline *cl,
2886                                 __attribute__((unused)) void *data)
2887 {
2888         struct cmd_set_list_result *res;
2889         union {
2890                 unsigned int lcorelist[RTE_MAX_LCORE];
2891                 unsigned int portlist[RTE_MAX_ETHPORTS];
2892         } parsed_items;
2893         unsigned int nb_item;
2894
2895         if (test_done == 0) {
2896                 printf("Please stop forwarding first\n");
2897                 return;
2898         }
2899
2900         res = parsed_result;
2901         if (!strcmp(res->list_name, "corelist")) {
2902                 nb_item = parse_item_list(res->list_of_items, "core",
2903                                           RTE_MAX_LCORE,
2904                                           parsed_items.lcorelist, 1);
2905                 if (nb_item > 0) {
2906                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2907                         fwd_config_setup();
2908                 }
2909                 return;
2910         }
2911         if (!strcmp(res->list_name, "portlist")) {
2912                 nb_item = parse_item_list(res->list_of_items, "port",
2913                                           RTE_MAX_ETHPORTS,
2914                                           parsed_items.portlist, 1);
2915                 if (nb_item > 0) {
2916                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2917                         fwd_config_setup();
2918                 }
2919         }
2920 }
2921
2922 cmdline_parse_token_string_t cmd_set_list_keyword =
2923         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2924                                  "set");
2925 cmdline_parse_token_string_t cmd_set_list_name =
2926         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2927                                  "corelist#portlist");
2928 cmdline_parse_token_string_t cmd_set_list_of_items =
2929         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2930                                  NULL);
2931
2932 cmdline_parse_inst_t cmd_set_fwd_list = {
2933         .f = cmd_set_list_parsed,
2934         .data = NULL,
2935         .help_str = "set corelist|portlist <list0[,list1]*>",
2936         .tokens = {
2937                 (void *)&cmd_set_list_keyword,
2938                 (void *)&cmd_set_list_name,
2939                 (void *)&cmd_set_list_of_items,
2940                 NULL,
2941         },
2942 };
2943
2944 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2945
2946 struct cmd_setmask_result {
2947         cmdline_fixed_string_t set;
2948         cmdline_fixed_string_t mask;
2949         uint64_t hexavalue;
2950 };
2951
2952 static void cmd_set_mask_parsed(void *parsed_result,
2953                                 __attribute__((unused)) struct cmdline *cl,
2954                                 __attribute__((unused)) void *data)
2955 {
2956         struct cmd_setmask_result *res = parsed_result;
2957
2958         if (test_done == 0) {
2959                 printf("Please stop forwarding first\n");
2960                 return;
2961         }
2962         if (!strcmp(res->mask, "coremask")) {
2963                 set_fwd_lcores_mask(res->hexavalue);
2964                 fwd_config_setup();
2965         } else if (!strcmp(res->mask, "portmask")) {
2966                 set_fwd_ports_mask(res->hexavalue);
2967                 fwd_config_setup();
2968         }
2969 }
2970
2971 cmdline_parse_token_string_t cmd_setmask_set =
2972         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2973 cmdline_parse_token_string_t cmd_setmask_mask =
2974         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2975                                  "coremask#portmask");
2976 cmdline_parse_token_num_t cmd_setmask_value =
2977         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2978
2979 cmdline_parse_inst_t cmd_set_fwd_mask = {
2980         .f = cmd_set_mask_parsed,
2981         .data = NULL,
2982         .help_str = "set coremask|portmask <hexadecimal value>",
2983         .tokens = {
2984                 (void *)&cmd_setmask_set,
2985                 (void *)&cmd_setmask_mask,
2986                 (void *)&cmd_setmask_value,
2987                 NULL,
2988         },
2989 };
2990
2991 /*
2992  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2993  */
2994 struct cmd_set_result {
2995         cmdline_fixed_string_t set;
2996         cmdline_fixed_string_t what;
2997         uint16_t value;
2998 };
2999
3000 static void cmd_set_parsed(void *parsed_result,
3001                            __attribute__((unused)) struct cmdline *cl,
3002                            __attribute__((unused)) void *data)
3003 {
3004         struct cmd_set_result *res = parsed_result;
3005         if (!strcmp(res->what, "nbport")) {
3006                 set_fwd_ports_number(res->value);
3007                 fwd_config_setup();
3008         } else if (!strcmp(res->what, "nbcore")) {
3009                 set_fwd_lcores_number(res->value);
3010                 fwd_config_setup();
3011         } else if (!strcmp(res->what, "burst"))
3012                 set_nb_pkt_per_burst(res->value);
3013         else if (!strcmp(res->what, "verbose"))
3014                 set_verbose_level(res->value);
3015 }
3016
3017 cmdline_parse_token_string_t cmd_set_set =
3018         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3019 cmdline_parse_token_string_t cmd_set_what =
3020         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3021                                  "nbport#nbcore#burst#verbose");
3022 cmdline_parse_token_num_t cmd_set_value =
3023         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3024
3025 cmdline_parse_inst_t cmd_set_numbers = {
3026         .f = cmd_set_parsed,
3027         .data = NULL,
3028         .help_str = "set nbport|nbcore|burst|verbose <value>",
3029         .tokens = {
3030                 (void *)&cmd_set_set,
3031                 (void *)&cmd_set_what,
3032                 (void *)&cmd_set_value,
3033                 NULL,
3034         },
3035 };
3036
3037 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3038
3039 struct cmd_set_txpkts_result {
3040         cmdline_fixed_string_t cmd_keyword;
3041         cmdline_fixed_string_t txpkts;
3042         cmdline_fixed_string_t seg_lengths;
3043 };
3044
3045 static void
3046 cmd_set_txpkts_parsed(void *parsed_result,
3047                       __attribute__((unused)) struct cmdline *cl,
3048                       __attribute__((unused)) void *data)
3049 {
3050         struct cmd_set_txpkts_result *res;
3051         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3052         unsigned int nb_segs;
3053
3054         res = parsed_result;
3055         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3056                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3057         if (nb_segs > 0)
3058                 set_tx_pkt_segments(seg_lengths, nb_segs);
3059 }
3060
3061 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3062         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3063                                  cmd_keyword, "set");
3064 cmdline_parse_token_string_t cmd_set_txpkts_name =
3065         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3066                                  txpkts, "txpkts");
3067 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3068         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3069                                  seg_lengths, NULL);
3070
3071 cmdline_parse_inst_t cmd_set_txpkts = {
3072         .f = cmd_set_txpkts_parsed,
3073         .data = NULL,
3074         .help_str = "set txpkts <len0[,len1]*>",
3075         .tokens = {
3076                 (void *)&cmd_set_txpkts_keyword,
3077                 (void *)&cmd_set_txpkts_name,
3078                 (void *)&cmd_set_txpkts_lengths,
3079                 NULL,
3080         },
3081 };
3082
3083 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3084
3085 struct cmd_set_txsplit_result {
3086         cmdline_fixed_string_t cmd_keyword;
3087         cmdline_fixed_string_t txsplit;
3088         cmdline_fixed_string_t mode;
3089 };
3090
3091 static void
3092 cmd_set_txsplit_parsed(void *parsed_result,
3093                       __attribute__((unused)) struct cmdline *cl,
3094                       __attribute__((unused)) void *data)
3095 {
3096         struct cmd_set_txsplit_result *res;
3097
3098         res = parsed_result;
3099         set_tx_pkt_split(res->mode);
3100 }
3101
3102 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3103         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3104                                  cmd_keyword, "set");
3105 cmdline_parse_token_string_t cmd_set_txsplit_name =
3106         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3107                                  txsplit, "txsplit");
3108 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3109         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3110                                  mode, NULL);
3111
3112 cmdline_parse_inst_t cmd_set_txsplit = {
3113         .f = cmd_set_txsplit_parsed,
3114         .data = NULL,
3115         .help_str = "set txsplit on|off|rand",
3116         .tokens = {
3117                 (void *)&cmd_set_txsplit_keyword,
3118                 (void *)&cmd_set_txsplit_name,
3119                 (void *)&cmd_set_txsplit_mode,
3120                 NULL,
3121         },
3122 };
3123
3124 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3125 struct cmd_rx_vlan_filter_all_result {
3126         cmdline_fixed_string_t rx_vlan;
3127         cmdline_fixed_string_t what;
3128         cmdline_fixed_string_t all;
3129         portid_t port_id;
3130 };
3131
3132 static void
3133 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3134                               __attribute__((unused)) struct cmdline *cl,
3135                               __attribute__((unused)) void *data)
3136 {
3137         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3138
3139         if (!strcmp(res->what, "add"))
3140                 rx_vlan_all_filter_set(res->port_id, 1);
3141         else
3142                 rx_vlan_all_filter_set(res->port_id, 0);
3143 }
3144
3145 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3146         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3147                                  rx_vlan, "rx_vlan");
3148 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3149         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3150                                  what, "add#rm");
3151 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3152         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3153                                  all, "all");
3154 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3155         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3156                               port_id, UINT16);
3157
3158 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3159         .f = cmd_rx_vlan_filter_all_parsed,
3160         .data = NULL,
3161         .help_str = "rx_vlan add|rm all <port_id>: "
3162                 "Add/Remove all identifiers to/from the set of VLAN "
3163                 "identifiers filtered by a port",
3164         .tokens = {
3165                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3166                 (void *)&cmd_rx_vlan_filter_all_what,
3167                 (void *)&cmd_rx_vlan_filter_all_all,
3168                 (void *)&cmd_rx_vlan_filter_all_portid,
3169                 NULL,
3170         },
3171 };
3172
3173 /* *** VLAN OFFLOAD SET ON A PORT *** */
3174 struct cmd_vlan_offload_result {
3175         cmdline_fixed_string_t vlan;
3176         cmdline_fixed_string_t set;
3177         cmdline_fixed_string_t vlan_type;
3178         cmdline_fixed_string_t what;
3179         cmdline_fixed_string_t on;
3180         cmdline_fixed_string_t port_id;
3181 };
3182
3183 static void
3184 cmd_vlan_offload_parsed(void *parsed_result,
3185                           __attribute__((unused)) struct cmdline *cl,
3186                           __attribute__((unused)) void *data)
3187 {
3188         int on;
3189         struct cmd_vlan_offload_result *res = parsed_result;
3190         char *str;
3191         int i, len = 0;
3192         portid_t port_id = 0;
3193         unsigned int tmp;
3194
3195         str = res->port_id;
3196         len = strnlen(str, STR_TOKEN_SIZE);
3197         i = 0;
3198         /* Get port_id first */
3199         while(i < len){
3200                 if(str[i] == ',')
3201                         break;
3202
3203                 i++;
3204         }
3205         str[i]='\0';
3206         tmp = strtoul(str, NULL, 0);
3207         /* If port_id greater that what portid_t can represent, return */
3208         if(tmp >= RTE_MAX_ETHPORTS)
3209                 return;
3210         port_id = (portid_t)tmp;
3211
3212         if (!strcmp(res->on, "on"))
3213                 on = 1;
3214         else
3215                 on = 0;
3216
3217         if (!strcmp(res->what, "strip"))
3218                 rx_vlan_strip_set(port_id,  on);
3219         else if(!strcmp(res->what, "stripq")){
3220                 uint16_t queue_id = 0;
3221
3222                 /* No queue_id, return */
3223                 if(i + 1 >= len) {
3224                         printf("must specify (port,queue_id)\n");
3225                         return;
3226                 }
3227                 tmp = strtoul(str + i + 1, NULL, 0);
3228                 /* If queue_id greater that what 16-bits can represent, return */
3229                 if(tmp > 0xffff)
3230                         return;
3231
3232                 queue_id = (uint16_t)tmp;
3233                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3234         }
3235         else if (!strcmp(res->what, "filter"))
3236                 rx_vlan_filter_set(port_id, on);
3237         else
3238                 vlan_extend_set(port_id, on);
3239
3240         return;
3241 }
3242
3243 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3244         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3245                                  vlan, "vlan");
3246 cmdline_parse_token_string_t cmd_vlan_offload_set =
3247         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3248                                  set, "set");
3249 cmdline_parse_token_string_t cmd_vlan_offload_what =
3250         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3251                                  what, "strip#filter#qinq#stripq");
3252 cmdline_parse_token_string_t cmd_vlan_offload_on =
3253         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3254                               on, "on#off");
3255 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3256         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3257                               port_id, NULL);
3258
3259 cmdline_parse_inst_t cmd_vlan_offload = {
3260         .f = cmd_vlan_offload_parsed,
3261         .data = NULL,
3262         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3263                 "<port_id[,queue_id]>: "
3264                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3265         .tokens = {
3266                 (void *)&cmd_vlan_offload_vlan,
3267                 (void *)&cmd_vlan_offload_set,
3268                 (void *)&cmd_vlan_offload_what,
3269                 (void *)&cmd_vlan_offload_on,
3270                 (void *)&cmd_vlan_offload_portid,
3271                 NULL,
3272         },
3273 };
3274
3275 /* *** VLAN TPID SET ON A PORT *** */
3276 struct cmd_vlan_tpid_result {
3277         cmdline_fixed_string_t vlan;
3278         cmdline_fixed_string_t set;
3279         cmdline_fixed_string_t vlan_type;
3280         cmdline_fixed_string_t what;
3281         uint16_t tp_id;
3282         portid_t port_id;
3283 };
3284
3285 static void
3286 cmd_vlan_tpid_parsed(void *parsed_result,
3287                           __attribute__((unused)) struct cmdline *cl,
3288                           __attribute__((unused)) void *data)
3289 {
3290         struct cmd_vlan_tpid_result *res = parsed_result;
3291         enum rte_vlan_type vlan_type;
3292
3293         if (!strcmp(res->vlan_type, "inner"))
3294                 vlan_type = ETH_VLAN_TYPE_INNER;
3295         else if (!strcmp(res->vlan_type, "outer"))
3296                 vlan_type = ETH_VLAN_TYPE_OUTER;
3297         else {
3298                 printf("Unknown vlan type\n");
3299                 return;
3300         }
3301         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3302 }
3303
3304 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3305         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3306                                  vlan, "vlan");
3307 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3308         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3309                                  set, "set");
3310 cmdline_parse_token_string_t cmd_vlan_type =
3311         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3312                                  vlan_type, "inner#outer");
3313 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3314         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3315                                  what, "tpid");
3316 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3317         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3318                               tp_id, UINT16);
3319 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3320         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3321                               port_id, UINT16);
3322
3323 cmdline_parse_inst_t cmd_vlan_tpid = {
3324         .f = cmd_vlan_tpid_parsed,
3325         .data = NULL,
3326         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3327                 "Set the VLAN Ether type",
3328         .tokens = {
3329                 (void *)&cmd_vlan_tpid_vlan,
3330                 (void *)&cmd_vlan_tpid_set,
3331                 (void *)&cmd_vlan_type,
3332                 (void *)&cmd_vlan_tpid_what,
3333                 (void *)&cmd_vlan_tpid_tpid,
3334                 (void *)&cmd_vlan_tpid_portid,
3335                 NULL,
3336         },
3337 };
3338
3339 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3340 struct cmd_rx_vlan_filter_result {
3341         cmdline_fixed_string_t rx_vlan;
3342         cmdline_fixed_string_t what;
3343         uint16_t vlan_id;
3344         portid_t port_id;
3345 };
3346
3347 static void
3348 cmd_rx_vlan_filter_parsed(void *parsed_result,
3349                           __attribute__((unused)) struct cmdline *cl,
3350                           __attribute__((unused)) void *data)
3351 {
3352         struct cmd_rx_vlan_filter_result *res = parsed_result;
3353
3354         if (!strcmp(res->what, "add"))
3355                 rx_vft_set(res->port_id, res->vlan_id, 1);
3356         else
3357                 rx_vft_set(res->port_id, res->vlan_id, 0);
3358 }
3359
3360 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3361         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3362                                  rx_vlan, "rx_vlan");
3363 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3364         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3365                                  what, "add#rm");
3366 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3367         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3368                               vlan_id, UINT16);
3369 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3370         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3371                               port_id, UINT16);
3372
3373 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3374         .f = cmd_rx_vlan_filter_parsed,
3375         .data = NULL,
3376         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3377                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3378                 "identifiers filtered by a port",
3379         .tokens = {
3380                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3381                 (void *)&cmd_rx_vlan_filter_what,
3382                 (void *)&cmd_rx_vlan_filter_vlanid,
3383                 (void *)&cmd_rx_vlan_filter_portid,
3384                 NULL,
3385         },
3386 };
3387
3388 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3389 struct cmd_tx_vlan_set_result {
3390         cmdline_fixed_string_t tx_vlan;
3391         cmdline_fixed_string_t set;
3392         portid_t port_id;
3393         uint16_t vlan_id;
3394 };
3395
3396 static void
3397 cmd_tx_vlan_set_parsed(void *parsed_result,
3398                        __attribute__((unused)) struct cmdline *cl,
3399                        __attribute__((unused)) void *data)
3400 {
3401         struct cmd_tx_vlan_set_result *res = parsed_result;
3402
3403         if (!port_is_stopped(res->port_id)) {
3404                 printf("Please stop port %d first\n", res->port_id);
3405                 return;
3406         }
3407
3408         tx_vlan_set(res->port_id, res->vlan_id);
3409
3410         cmd_reconfig_device_queue(res->port_id, 1, 1);
3411 }
3412
3413 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3414         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3415                                  tx_vlan, "tx_vlan");
3416 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3417         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3418                                  set, "set");
3419 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3420         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3421                               port_id, UINT16);
3422 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3423         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3424                               vlan_id, UINT16);
3425
3426 cmdline_parse_inst_t cmd_tx_vlan_set = {
3427         .f = cmd_tx_vlan_set_parsed,
3428         .data = NULL,
3429         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3430                 "Enable hardware insertion of a single VLAN header "
3431                 "with a given TAG Identifier in packets sent on a port",
3432         .tokens = {
3433                 (void *)&cmd_tx_vlan_set_tx_vlan,
3434                 (void *)&cmd_tx_vlan_set_set,
3435                 (void *)&cmd_tx_vlan_set_portid,
3436                 (void *)&cmd_tx_vlan_set_vlanid,
3437                 NULL,
3438         },
3439 };
3440
3441 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3442 struct cmd_tx_vlan_set_qinq_result {
3443         cmdline_fixed_string_t tx_vlan;
3444         cmdline_fixed_string_t set;
3445         portid_t port_id;
3446         uint16_t vlan_id;
3447         uint16_t vlan_id_outer;
3448 };
3449
3450 static void
3451 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3452                             __attribute__((unused)) struct cmdline *cl,
3453                             __attribute__((unused)) void *data)
3454 {
3455         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3456
3457         if (!port_is_stopped(res->port_id)) {
3458                 printf("Please stop port %d first\n", res->port_id);
3459                 return;
3460         }
3461
3462         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3463
3464         cmd_reconfig_device_queue(res->port_id, 1, 1);
3465 }
3466
3467 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3468         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3469                 tx_vlan, "tx_vlan");
3470 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3471         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3472                 set, "set");
3473 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3474         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3475                 port_id, UINT16);
3476 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3477         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3478                 vlan_id, UINT16);
3479 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3480         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3481                 vlan_id_outer, UINT16);
3482
3483 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3484         .f = cmd_tx_vlan_set_qinq_parsed,
3485         .data = NULL,
3486         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3487                 "Enable hardware insertion of double VLAN header "
3488                 "with given TAG Identifiers in packets sent on a port",
3489         .tokens = {
3490                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3491                 (void *)&cmd_tx_vlan_set_qinq_set,
3492                 (void *)&cmd_tx_vlan_set_qinq_portid,
3493                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3494                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3495                 NULL,
3496         },
3497 };
3498
3499 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3500 struct cmd_tx_vlan_set_pvid_result {
3501         cmdline_fixed_string_t tx_vlan;
3502         cmdline_fixed_string_t set;
3503         cmdline_fixed_string_t pvid;
3504         portid_t port_id;
3505         uint16_t vlan_id;
3506         cmdline_fixed_string_t mode;
3507 };
3508
3509 static void
3510 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3511                             __attribute__((unused)) struct cmdline *cl,
3512                             __attribute__((unused)) void *data)
3513 {
3514         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3515
3516         if (strcmp(res->mode, "on") == 0)
3517                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3518         else
3519                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3520 }
3521
3522 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3523         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3524                                  tx_vlan, "tx_vlan");
3525 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3526         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3527                                  set, "set");
3528 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3529         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3530                                  pvid, "pvid");
3531 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3532         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3533                              port_id, UINT16);
3534 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3535         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3536                               vlan_id, UINT16);
3537 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3538         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3539                                  mode, "on#off");
3540
3541 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3542         .f = cmd_tx_vlan_set_pvid_parsed,
3543         .data = NULL,
3544         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3545         .tokens = {
3546                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3547                 (void *)&cmd_tx_vlan_set_pvid_set,
3548                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3549                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3550                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3551                 (void *)&cmd_tx_vlan_set_pvid_mode,
3552                 NULL,
3553         },
3554 };
3555
3556 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3557 struct cmd_tx_vlan_reset_result {
3558         cmdline_fixed_string_t tx_vlan;
3559         cmdline_fixed_string_t reset;
3560         portid_t port_id;
3561 };
3562
3563 static void
3564 cmd_tx_vlan_reset_parsed(void *parsed_result,
3565                          __attribute__((unused)) struct cmdline *cl,
3566                          __attribute__((unused)) void *data)
3567 {
3568         struct cmd_tx_vlan_reset_result *res = parsed_result;
3569
3570         if (!port_is_stopped(res->port_id)) {
3571                 printf("Please stop port %d first\n", res->port_id);
3572                 return;
3573         }
3574
3575         tx_vlan_reset(res->port_id);
3576
3577         cmd_reconfig_device_queue(res->port_id, 1, 1);
3578 }
3579
3580 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3581         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3582                                  tx_vlan, "tx_vlan");
3583 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3584         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3585                                  reset, "reset");
3586 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3587         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3588                               port_id, UINT16);
3589
3590 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3591         .f = cmd_tx_vlan_reset_parsed,
3592         .data = NULL,
3593         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3594                 "VLAN header in packets sent on a port",
3595         .tokens = {
3596                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3597                 (void *)&cmd_tx_vlan_reset_reset,
3598                 (void *)&cmd_tx_vlan_reset_portid,
3599                 NULL,
3600         },
3601 };
3602
3603
3604 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3605 struct cmd_csum_result {
3606         cmdline_fixed_string_t csum;
3607         cmdline_fixed_string_t mode;
3608         cmdline_fixed_string_t proto;
3609         cmdline_fixed_string_t hwsw;
3610         portid_t port_id;
3611 };
3612
3613 static void
3614 csum_show(int port_id)
3615 {
3616         struct rte_eth_dev_info dev_info;
3617         uint64_t tx_offloads;
3618
3619         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3620         printf("Parse tunnel is %s\n",
3621                 (ports[port_id].parse_tunnel) ? "on" : "off");
3622         printf("IP checksum offload is %s\n",
3623                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3624         printf("UDP checksum offload is %s\n",
3625                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3626         printf("TCP checksum offload is %s\n",
3627                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3628         printf("SCTP checksum offload is %s\n",
3629                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3630         printf("Outer-Ip checksum offload is %s\n",
3631                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3632
3633         /* display warnings if configuration is not supported by the NIC */
3634         rte_eth_dev_info_get(port_id, &dev_info);
3635         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3636                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3637                 printf("Warning: hardware IP checksum enabled but not "
3638                         "supported by port %d\n", port_id);
3639         }
3640         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3641                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3642                 printf("Warning: hardware UDP checksum enabled but not "
3643                         "supported by port %d\n", port_id);
3644         }
3645         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3646                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3647                 printf("Warning: hardware TCP checksum enabled but not "
3648                         "supported by port %d\n", port_id);
3649         }
3650         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3651                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3652                 printf("Warning: hardware SCTP checksum enabled but not "
3653                         "supported by port %d\n", port_id);
3654         }
3655         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3656                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3657                 printf("Warning: hardware outer IP checksum enabled but not "
3658                         "supported by port %d\n", port_id);
3659         }
3660 }
3661
3662 static void
3663 cmd_csum_parsed(void *parsed_result,
3664                        __attribute__((unused)) struct cmdline *cl,
3665                        __attribute__((unused)) void *data)
3666 {
3667         struct cmd_csum_result *res = parsed_result;
3668         int hw = 0;
3669         uint64_t csum_offloads = 0;
3670         struct rte_eth_dev_info dev_info;
3671
3672         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3673                 printf("invalid port %d\n", res->port_id);
3674                 return;
3675         }
3676         if (!port_is_stopped(res->port_id)) {
3677                 printf("Please stop port %d first\n", res->port_id);
3678                 return;
3679         }
3680
3681         rte_eth_dev_info_get(res->port_id, &dev_info);
3682         if (!strcmp(res->mode, "set")) {
3683
3684                 if (!strcmp(res->hwsw, "hw"))
3685                         hw = 1;
3686
3687                 if (!strcmp(res->proto, "ip")) {
3688                         if (dev_info.tx_offload_capa &
3689                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3690                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3691                         } else {
3692                                 printf("IP checksum offload is not supported "
3693                                        "by port %u\n", res->port_id);
3694                         }
3695                 } else if (!strcmp(res->proto, "udp")) {
3696                         if (dev_info.tx_offload_capa &
3697                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3698                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3699                         } else {
3700                                 printf("UDP checksum offload is not supported "
3701                                        "by port %u\n", res->port_id);
3702                         }
3703                 } else if (!strcmp(res->proto, "tcp")) {
3704                         if (dev_info.tx_offload_capa &
3705                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3706                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3707                         } else {
3708                                 printf("TCP checksum offload is not supported "
3709                                        "by port %u\n", res->port_id);
3710                         }
3711                 } else if (!strcmp(res->proto, "sctp")) {
3712                         if (dev_info.tx_offload_capa &
3713                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3714                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3715                         } else {
3716                                 printf("SCTP checksum offload is not supported "
3717                                        "by port %u\n", res->port_id);
3718                         }
3719                 } else if (!strcmp(res->proto, "outer-ip")) {
3720                         if (dev_info.tx_offload_capa &
3721                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3722                                 csum_offloads |=
3723                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3724                         } else {
3725                                 printf("Outer IP checksum offload is not "
3726                                        "supported by port %u\n", res->port_id);
3727                         }
3728                 }
3729
3730                 if (hw) {
3731                         ports[res->port_id].dev_conf.txmode.offloads |=
3732                                                         csum_offloads;
3733                 } else {
3734                         ports[res->port_id].dev_conf.txmode.offloads &=
3735                                                         (~csum_offloads);
3736                 }
3737         }
3738         csum_show(res->port_id);
3739
3740         cmd_reconfig_device_queue(res->port_id, 1, 1);
3741 }
3742
3743 cmdline_parse_token_string_t cmd_csum_csum =
3744         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3745                                 csum, "csum");
3746 cmdline_parse_token_string_t cmd_csum_mode =
3747         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3748                                 mode, "set");
3749 cmdline_parse_token_string_t cmd_csum_proto =
3750         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3751                                 proto, "ip#tcp#udp#sctp#outer-ip");
3752 cmdline_parse_token_string_t cmd_csum_hwsw =
3753         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3754                                 hwsw, "hw#sw");
3755 cmdline_parse_token_num_t cmd_csum_portid =
3756         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3757                                 port_id, UINT16);
3758
3759 cmdline_parse_inst_t cmd_csum_set = {
3760         .f = cmd_csum_parsed,
3761         .data = NULL,
3762         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3763                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3764                 "using csum forward engine",
3765         .tokens = {
3766                 (void *)&cmd_csum_csum,
3767                 (void *)&cmd_csum_mode,
3768                 (void *)&cmd_csum_proto,
3769                 (void *)&cmd_csum_hwsw,
3770                 (void *)&cmd_csum_portid,
3771                 NULL,
3772         },
3773 };
3774
3775 cmdline_parse_token_string_t cmd_csum_mode_show =
3776         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3777                                 mode, "show");
3778
3779 cmdline_parse_inst_t cmd_csum_show = {
3780         .f = cmd_csum_parsed,
3781         .data = NULL,
3782         .help_str = "csum show <port_id>: Show checksum offload configuration",
3783         .tokens = {
3784                 (void *)&cmd_csum_csum,
3785                 (void *)&cmd_csum_mode_show,
3786                 (void *)&cmd_csum_portid,
3787                 NULL,
3788         },
3789 };
3790
3791 /* Enable/disable tunnel parsing */
3792 struct cmd_csum_tunnel_result {
3793         cmdline_fixed_string_t csum;
3794         cmdline_fixed_string_t parse;
3795         cmdline_fixed_string_t onoff;
3796         portid_t port_id;
3797 };
3798
3799 static void
3800 cmd_csum_tunnel_parsed(void *parsed_result,
3801                        __attribute__((unused)) struct cmdline *cl,
3802                        __attribute__((unused)) void *data)
3803 {
3804         struct cmd_csum_tunnel_result *res = parsed_result;
3805
3806         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3807                 return;
3808
3809         if (!strcmp(res->onoff, "on"))
3810                 ports[res->port_id].parse_tunnel = 1;
3811         else
3812                 ports[res->port_id].parse_tunnel = 0;
3813
3814         csum_show(res->port_id);
3815 }
3816
3817 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3818         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3819                                 csum, "csum");
3820 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3821         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3822                                 parse, "parse_tunnel");
3823 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3824         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3825                                 onoff, "on#off");
3826 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3827         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3828                                 port_id, UINT16);
3829
3830 cmdline_parse_inst_t cmd_csum_tunnel = {
3831         .f = cmd_csum_tunnel_parsed,
3832         .data = NULL,
3833         .help_str = "csum parse_tunnel on|off <port_id>: "
3834                 "Enable/Disable parsing of tunnels for csum engine",
3835         .tokens = {
3836                 (void *)&cmd_csum_tunnel_csum,
3837                 (void *)&cmd_csum_tunnel_parse,
3838                 (void *)&cmd_csum_tunnel_onoff,
3839                 (void *)&cmd_csum_tunnel_portid,
3840                 NULL,
3841         },
3842 };
3843
3844 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3845 struct cmd_tso_set_result {
3846         cmdline_fixed_string_t tso;
3847         cmdline_fixed_string_t mode;
3848         uint16_t tso_segsz;
3849         portid_t port_id;
3850 };
3851
3852 static void
3853 cmd_tso_set_parsed(void *parsed_result,
3854                        __attribute__((unused)) struct cmdline *cl,
3855                        __attribute__((unused)) void *data)
3856 {
3857         struct cmd_tso_set_result *res = parsed_result;
3858         struct rte_eth_dev_info dev_info;
3859
3860         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3861                 return;
3862         if (!port_is_stopped(res->port_id)) {
3863                 printf("Please stop port %d first\n", res->port_id);
3864                 return;
3865         }
3866
3867         if (!strcmp(res->mode, "set"))
3868                 ports[res->port_id].tso_segsz = res->tso_segsz;
3869
3870         rte_eth_dev_info_get(res->port_id, &dev_info);
3871         if ((ports[res->port_id].tso_segsz != 0) &&
3872                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3873                 printf("Error: TSO is not supported by port %d\n",
3874                        res->port_id);
3875                 return;
3876         }
3877
3878         if (ports[res->port_id].tso_segsz == 0) {
3879                 ports[res->port_id].dev_conf.txmode.offloads &=
3880                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3881                 printf("TSO for non-tunneled packets is disabled\n");
3882         } else {
3883                 ports[res->port_id].dev_conf.txmode.offloads |=
3884                                                 DEV_TX_OFFLOAD_TCP_TSO;
3885                 printf("TSO segment size for non-tunneled packets is %d\n",
3886                         ports[res->port_id].tso_segsz);
3887         }
3888
3889         /* display warnings if configuration is not supported by the NIC */
3890         rte_eth_dev_info_get(res->port_id, &dev_info);
3891         if ((ports[res->port_id].tso_segsz != 0) &&
3892                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3893                 printf("Warning: TSO enabled but not "
3894                         "supported by port %d\n", res->port_id);
3895         }
3896
3897         cmd_reconfig_device_queue(res->port_id, 1, 1);
3898 }
3899
3900 cmdline_parse_token_string_t cmd_tso_set_tso =
3901         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3902                                 tso, "tso");
3903 cmdline_parse_token_string_t cmd_tso_set_mode =
3904         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3905                                 mode, "set");
3906 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3907         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3908                                 tso_segsz, UINT16);
3909 cmdline_parse_token_num_t cmd_tso_set_portid =
3910         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3911                                 port_id, UINT16);
3912
3913 cmdline_parse_inst_t cmd_tso_set = {
3914         .f = cmd_tso_set_parsed,
3915         .data = NULL,
3916         .help_str = "tso set <tso_segsz> <port_id>: "
3917                 "Set TSO segment size of non-tunneled packets for csum engine "
3918                 "(0 to disable)",
3919         .tokens = {
3920                 (void *)&cmd_tso_set_tso,
3921                 (void *)&cmd_tso_set_mode,
3922                 (void *)&cmd_tso_set_tso_segsz,
3923                 (void *)&cmd_tso_set_portid,
3924                 NULL,
3925         },
3926 };
3927
3928 cmdline_parse_token_string_t cmd_tso_show_mode =
3929         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3930                                 mode, "show");
3931
3932
3933 cmdline_parse_inst_t cmd_tso_show = {
3934         .f = cmd_tso_set_parsed,
3935         .data = NULL,
3936         .help_str = "tso show <port_id>: "
3937                 "Show TSO segment size of non-tunneled packets for csum engine",
3938         .tokens = {
3939                 (void *)&cmd_tso_set_tso,
3940                 (void *)&cmd_tso_show_mode,
3941                 (void *)&cmd_tso_set_portid,
3942                 NULL,
3943         },
3944 };
3945
3946 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3947 struct cmd_tunnel_tso_set_result {
3948         cmdline_fixed_string_t tso;
3949         cmdline_fixed_string_t mode;
3950         uint16_t tso_segsz;
3951         portid_t port_id;
3952 };
3953
3954 static struct rte_eth_dev_info
3955 check_tunnel_tso_nic_support(portid_t port_id)
3956 {
3957         struct rte_eth_dev_info dev_info;
3958
3959         rte_eth_dev_info_get(port_id, &dev_info);
3960         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3961                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3962                        "not enabled for port %d\n", port_id);
3963         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3964                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3965                        "not enabled for port %d\n", port_id);
3966         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3967                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3968                        "not enabled for port %d\n", port_id);
3969         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3970                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3971                        "not enabled for port %d\n", port_id);
3972         return dev_info;
3973 }
3974
3975 static void
3976 cmd_tunnel_tso_set_parsed(void *parsed_result,
3977                           __attribute__((unused)) struct cmdline *cl,
3978                           __attribute__((unused)) void *data)
3979 {
3980         struct cmd_tunnel_tso_set_result *res = parsed_result;
3981         struct rte_eth_dev_info dev_info;
3982
3983         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3984                 return;
3985         if (!port_is_stopped(res->port_id)) {
3986                 printf("Please stop port %d first\n", res->port_id);
3987                 return;
3988         }
3989
3990         if (!strcmp(res->mode, "set"))
3991                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3992
3993         dev_info = check_tunnel_tso_nic_support(res->port_id);
3994         if (ports[res->port_id].tunnel_tso_segsz == 0) {
3995                 ports[res->port_id].dev_conf.txmode.offloads &=
3996                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3997                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
3998                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3999                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4000                 printf("TSO for tunneled packets is disabled\n");
4001         } else {
4002                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4003                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4004                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4005                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4006
4007                 ports[res->port_id].dev_conf.txmode.offloads |=
4008                         (tso_offloads & dev_info.tx_offload_capa);
4009                 printf("TSO segment size for tunneled packets is %d\n",
4010                         ports[res->port_id].tunnel_tso_segsz);
4011
4012                 /* Below conditions are needed to make it work:
4013                  * (1) tunnel TSO is supported by the NIC;
4014                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4015                  * are recognized;
4016                  * (3) for tunneled pkts with outer L3 of IPv4,
4017                  * "csum set outer-ip" must be set to hw, because after tso,
4018                  * total_len of outer IP header is changed, and the checksum
4019                  * of outer IP header calculated by sw should be wrong; that
4020                  * is not necessary for IPv6 tunneled pkts because there's no
4021                  * checksum in IP header anymore.
4022                  */
4023
4024                 if (!ports[res->port_id].parse_tunnel)
4025                         printf("Warning: csum parse_tunnel must be set "
4026                                 "so that tunneled packets are recognized\n");
4027                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4028                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4029                         printf("Warning: csum set outer-ip must be set to hw "
4030                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4031         }
4032
4033         cmd_reconfig_device_queue(res->port_id, 1, 1);
4034 }
4035
4036 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4037         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4038                                 tso, "tunnel_tso");
4039 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4040         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4041                                 mode, "set");
4042 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4043         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4044                                 tso_segsz, UINT16);
4045 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4046         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4047                                 port_id, UINT16);
4048
4049 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4050         .f = cmd_tunnel_tso_set_parsed,
4051         .data = NULL,
4052         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4053                 "Set TSO segment size of tunneled packets for csum engine "
4054                 "(0 to disable)",
4055         .tokens = {
4056                 (void *)&cmd_tunnel_tso_set_tso,
4057                 (void *)&cmd_tunnel_tso_set_mode,
4058                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4059                 (void *)&cmd_tunnel_tso_set_portid,
4060                 NULL,
4061         },
4062 };
4063
4064 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4065         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4066                                 mode, "show");
4067
4068
4069 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4070         .f = cmd_tunnel_tso_set_parsed,
4071         .data = NULL,
4072         .help_str = "tunnel_tso show <port_id> "
4073                 "Show TSO segment size of tunneled packets for csum engine",
4074         .tokens = {
4075                 (void *)&cmd_tunnel_tso_set_tso,
4076                 (void *)&cmd_tunnel_tso_show_mode,
4077                 (void *)&cmd_tunnel_tso_set_portid,
4078                 NULL,
4079         },
4080 };
4081
4082 /* *** SET GRO FOR A PORT *** */
4083 struct cmd_gro_enable_result {
4084         cmdline_fixed_string_t cmd_set;
4085         cmdline_fixed_string_t cmd_port;
4086         cmdline_fixed_string_t cmd_keyword;
4087         cmdline_fixed_string_t cmd_onoff;
4088         portid_t cmd_pid;
4089 };
4090
4091 static void
4092 cmd_gro_enable_parsed(void *parsed_result,
4093                 __attribute__((unused)) struct cmdline *cl,
4094                 __attribute__((unused)) void *data)
4095 {
4096         struct cmd_gro_enable_result *res;
4097
4098         res = parsed_result;
4099         if (!strcmp(res->cmd_keyword, "gro"))
4100                 setup_gro(res->cmd_onoff, res->cmd_pid);
4101 }
4102
4103 cmdline_parse_token_string_t cmd_gro_enable_set =
4104         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4105                         cmd_set, "set");
4106 cmdline_parse_token_string_t cmd_gro_enable_port =
4107         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4108                         cmd_keyword, "port");
4109 cmdline_parse_token_num_t cmd_gro_enable_pid =
4110         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4111                         cmd_pid, UINT16);
4112 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4113         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4114                         cmd_keyword, "gro");
4115 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4116         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4117                         cmd_onoff, "on#off");
4118
4119 cmdline_parse_inst_t cmd_gro_enable = {
4120         .f = cmd_gro_enable_parsed,
4121         .data = NULL,
4122         .help_str = "set port <port_id> gro on|off",
4123         .tokens = {
4124                 (void *)&cmd_gro_enable_set,
4125                 (void *)&cmd_gro_enable_port,
4126                 (void *)&cmd_gro_enable_pid,
4127                 (void *)&cmd_gro_enable_keyword,
4128                 (void *)&cmd_gro_enable_onoff,
4129                 NULL,
4130         },
4131 };
4132
4133 /* *** DISPLAY GRO CONFIGURATION *** */
4134 struct cmd_gro_show_result {
4135         cmdline_fixed_string_t cmd_show;
4136         cmdline_fixed_string_t cmd_port;
4137         cmdline_fixed_string_t cmd_keyword;
4138         portid_t cmd_pid;
4139 };
4140
4141 static void
4142 cmd_gro_show_parsed(void *parsed_result,
4143                 __attribute__((unused)) struct cmdline *cl,
4144                 __attribute__((unused)) void *data)
4145 {
4146         struct cmd_gro_show_result *res;
4147
4148         res = parsed_result;
4149         if (!strcmp(res->cmd_keyword, "gro"))
4150                 show_gro(res->cmd_pid);
4151 }
4152
4153 cmdline_parse_token_string_t cmd_gro_show_show =
4154         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4155                         cmd_show, "show");
4156 cmdline_parse_token_string_t cmd_gro_show_port =
4157         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4158                         cmd_port, "port");
4159 cmdline_parse_token_num_t cmd_gro_show_pid =
4160         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4161                         cmd_pid, UINT16);
4162 cmdline_parse_token_string_t cmd_gro_show_keyword =
4163         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4164                         cmd_keyword, "gro");
4165
4166 cmdline_parse_inst_t cmd_gro_show = {
4167         .f = cmd_gro_show_parsed,
4168         .data = NULL,
4169         .help_str = "show port <port_id> gro",
4170         .tokens = {
4171                 (void *)&cmd_gro_show_show,
4172                 (void *)&cmd_gro_show_port,
4173                 (void *)&cmd_gro_show_pid,
4174                 (void *)&cmd_gro_show_keyword,
4175                 NULL,
4176         },
4177 };
4178
4179 /* *** SET FLUSH CYCLES FOR GRO *** */
4180 struct cmd_gro_flush_result {
4181         cmdline_fixed_string_t cmd_set;
4182         cmdline_fixed_string_t cmd_keyword;
4183         cmdline_fixed_string_t cmd_flush;
4184         uint8_t cmd_cycles;
4185 };
4186
4187 static void
4188 cmd_gro_flush_parsed(void *parsed_result,
4189                 __attribute__((unused)) struct cmdline *cl,
4190                 __attribute__((unused)) void *data)
4191 {
4192         struct cmd_gro_flush_result *res;
4193
4194         res = parsed_result;
4195         if ((!strcmp(res->cmd_keyword, "gro")) &&
4196                         (!strcmp(res->cmd_flush, "flush")))
4197                 setup_gro_flush_cycles(res->cmd_cycles);
4198 }
4199
4200 cmdline_parse_token_string_t cmd_gro_flush_set =
4201         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4202                         cmd_set, "set");
4203 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4204         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4205                         cmd_keyword, "gro");
4206 cmdline_parse_token_string_t cmd_gro_flush_flush =
4207         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4208                         cmd_flush, "flush");
4209 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4210         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4211                         cmd_cycles, UINT8);
4212
4213 cmdline_parse_inst_t cmd_gro_flush = {
4214         .f = cmd_gro_flush_parsed,
4215         .data = NULL,
4216         .help_str = "set gro flush <cycles>",
4217         .tokens = {
4218                 (void *)&cmd_gro_flush_set,
4219                 (void *)&cmd_gro_flush_keyword,
4220                 (void *)&cmd_gro_flush_flush,
4221                 (void *)&cmd_gro_flush_cycles,
4222                 NULL,
4223         },
4224 };
4225
4226 /* *** ENABLE/DISABLE GSO *** */
4227 struct cmd_gso_enable_result {
4228         cmdline_fixed_string_t cmd_set;
4229         cmdline_fixed_string_t cmd_port;
4230         cmdline_fixed_string_t cmd_keyword;
4231         cmdline_fixed_string_t cmd_mode;
4232         portid_t cmd_pid;
4233 };
4234
4235 static void
4236 cmd_gso_enable_parsed(void *parsed_result,
4237                 __attribute__((unused)) struct cmdline *cl,
4238                 __attribute__((unused)) void *data)
4239 {
4240         struct cmd_gso_enable_result *res;
4241
4242         res = parsed_result;
4243         if (!strcmp(res->cmd_keyword, "gso"))
4244                 setup_gso(res->cmd_mode, res->cmd_pid);
4245 }
4246
4247 cmdline_parse_token_string_t cmd_gso_enable_set =
4248         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4249                         cmd_set, "set");
4250 cmdline_parse_token_string_t cmd_gso_enable_port =
4251         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4252                         cmd_port, "port");
4253 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4254         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4255                         cmd_keyword, "gso");
4256 cmdline_parse_token_string_t cmd_gso_enable_mode =
4257         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4258                         cmd_mode, "on#off");
4259 cmdline_parse_token_num_t cmd_gso_enable_pid =
4260         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4261                         cmd_pid, UINT16);
4262
4263 cmdline_parse_inst_t cmd_gso_enable = {
4264         .f = cmd_gso_enable_parsed,
4265         .data = NULL,
4266         .help_str = "set port <port_id> gso on|off",
4267         .tokens = {
4268                 (void *)&cmd_gso_enable_set,
4269                 (void *)&cmd_gso_enable_port,
4270                 (void *)&cmd_gso_enable_pid,
4271                 (void *)&cmd_gso_enable_keyword,
4272                 (void *)&cmd_gso_enable_mode,
4273                 NULL,
4274         },
4275 };
4276
4277 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4278 struct cmd_gso_size_result {
4279         cmdline_fixed_string_t cmd_set;
4280         cmdline_fixed_string_t cmd_keyword;
4281         cmdline_fixed_string_t cmd_segsz;
4282         uint16_t cmd_size;
4283 };
4284
4285 static void
4286 cmd_gso_size_parsed(void *parsed_result,
4287                        __attribute__((unused)) struct cmdline *cl,
4288                        __attribute__((unused)) void *data)
4289 {
4290         struct cmd_gso_size_result *res = parsed_result;
4291
4292         if (test_done == 0) {
4293                 printf("Before setting GSO segsz, please first"
4294                                 " stop fowarding\n");
4295                 return;
4296         }
4297
4298         if (!strcmp(res->cmd_keyword, "gso") &&
4299                         !strcmp(res->cmd_segsz, "segsz")) {
4300                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4301                         printf("gso_size should be larger than %zu."
4302                                         " Please input a legal value\n",
4303                                         RTE_GSO_SEG_SIZE_MIN);
4304                 else
4305                         gso_max_segment_size = res->cmd_size;
4306         }
4307 }
4308
4309 cmdline_parse_token_string_t cmd_gso_size_set =
4310         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4311                                 cmd_set, "set");
4312 cmdline_parse_token_string_t cmd_gso_size_keyword =
4313         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4314                                 cmd_keyword, "gso");
4315 cmdline_parse_token_string_t cmd_gso_size_segsz =
4316         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4317                                 cmd_segsz, "segsz");
4318 cmdline_parse_token_num_t cmd_gso_size_size =
4319         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4320                                 cmd_size, UINT16);
4321
4322 cmdline_parse_inst_t cmd_gso_size = {
4323         .f = cmd_gso_size_parsed,
4324         .data = NULL,
4325         .help_str = "set gso segsz <length>",
4326         .tokens = {
4327                 (void *)&cmd_gso_size_set,
4328                 (void *)&cmd_gso_size_keyword,
4329                 (void *)&cmd_gso_size_segsz,
4330                 (void *)&cmd_gso_size_size,
4331                 NULL,
4332         },
4333 };
4334
4335 /* *** SHOW GSO CONFIGURATION *** */
4336 struct cmd_gso_show_result {
4337         cmdline_fixed_string_t cmd_show;
4338         cmdline_fixed_string_t cmd_port;
4339         cmdline_fixed_string_t cmd_keyword;
4340         portid_t cmd_pid;
4341 };
4342
4343 static void
4344 cmd_gso_show_parsed(void *parsed_result,
4345                        __attribute__((unused)) struct cmdline *cl,
4346                        __attribute__((unused)) void *data)
4347 {
4348         struct cmd_gso_show_result *res = parsed_result;
4349
4350         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4351                 printf("invalid port id %u\n", res->cmd_pid);
4352                 return;
4353         }
4354         if (!strcmp(res->cmd_keyword, "gso")) {
4355                 if (gso_ports[res->cmd_pid].enable) {
4356                         printf("Max GSO'd packet size: %uB\n"
4357                                         "Supported GSO types: TCP/IPv4, "
4358                                         "VxLAN with inner TCP/IPv4 packet, "
4359                                         "GRE with inner TCP/IPv4  packet\n",
4360                                         gso_max_segment_size);
4361                 } else
4362                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4363         }
4364 }
4365
4366 cmdline_parse_token_string_t cmd_gso_show_show =
4367 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4368                 cmd_show, "show");
4369 cmdline_parse_token_string_t cmd_gso_show_port =
4370 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4371                 cmd_port, "port");
4372 cmdline_parse_token_string_t cmd_gso_show_keyword =
4373         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4374                                 cmd_keyword, "gso");
4375 cmdline_parse_token_num_t cmd_gso_show_pid =
4376         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4377                                 cmd_pid, UINT16);
4378
4379 cmdline_parse_inst_t cmd_gso_show = {
4380         .f = cmd_gso_show_parsed,
4381         .data = NULL,
4382         .help_str = "show port <port_id> gso",
4383         .tokens = {
4384                 (void *)&cmd_gso_show_show,
4385                 (void *)&cmd_gso_show_port,
4386                 (void *)&cmd_gso_show_pid,
4387                 (void *)&cmd_gso_show_keyword,
4388                 NULL,
4389         },
4390 };
4391
4392 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4393 struct cmd_set_flush_rx {
4394         cmdline_fixed_string_t set;
4395         cmdline_fixed_string_t flush_rx;
4396         cmdline_fixed_string_t mode;
4397 };
4398
4399 static void
4400 cmd_set_flush_rx_parsed(void *parsed_result,
4401                 __attribute__((unused)) struct cmdline *cl,
4402                 __attribute__((unused)) void *data)
4403 {
4404         struct cmd_set_flush_rx *res = parsed_result;
4405         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4406 }
4407
4408 cmdline_parse_token_string_t cmd_setflushrx_set =
4409         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4410                         set, "set");
4411 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4412         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4413                         flush_rx, "flush_rx");
4414 cmdline_parse_token_string_t cmd_setflushrx_mode =
4415         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4416                         mode, "on#off");
4417
4418
4419 cmdline_parse_inst_t cmd_set_flush_rx = {
4420         .f = cmd_set_flush_rx_parsed,
4421         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4422         .data = NULL,
4423         .tokens = {
4424                 (void *)&cmd_setflushrx_set,
4425                 (void *)&cmd_setflushrx_flush_rx,
4426                 (void *)&cmd_setflushrx_mode,
4427                 NULL,
4428         },
4429 };
4430
4431 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4432 struct cmd_set_link_check {
4433         cmdline_fixed_string_t set;
4434         cmdline_fixed_string_t link_check;
4435         cmdline_fixed_string_t mode;
4436 };
4437
4438 static void
4439 cmd_set_link_check_parsed(void *parsed_result,
4440                 __attribute__((unused)) struct cmdline *cl,
4441                 __attribute__((unused)) void *data)
4442 {
4443         struct cmd_set_link_check *res = parsed_result;
4444         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4445 }
4446
4447 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4448         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4449                         set, "set");
4450 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4451         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4452                         link_check, "link_check");
4453 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4454         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4455                         mode, "on#off");
4456
4457
4458 cmdline_parse_inst_t cmd_set_link_check = {
4459         .f = cmd_set_link_check_parsed,
4460         .help_str = "set link_check on|off: Enable/Disable link status check "
4461                     "when starting/stopping a port",
4462         .data = NULL,
4463         .tokens = {
4464                 (void *)&cmd_setlinkcheck_set,
4465                 (void *)&cmd_setlinkcheck_link_check,
4466                 (void *)&cmd_setlinkcheck_mode,
4467                 NULL,
4468         },
4469 };
4470
4471 /* *** SET NIC BYPASS MODE *** */
4472 struct cmd_set_bypass_mode_result {
4473         cmdline_fixed_string_t set;
4474         cmdline_fixed_string_t bypass;
4475         cmdline_fixed_string_t mode;
4476         cmdline_fixed_string_t value;
4477         portid_t port_id;
4478 };
4479
4480 static void
4481 cmd_set_bypass_mode_parsed(void *parsed_result,
4482                 __attribute__((unused)) struct cmdline *cl,
4483                 __attribute__((unused)) void *data)
4484 {
4485         struct cmd_set_bypass_mode_result *res = parsed_result;
4486         portid_t port_id = res->port_id;
4487         int32_t rc = -EINVAL;
4488
4489 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4490         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4491
4492         if (!strcmp(res->value, "bypass"))
4493                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4494         else if (!strcmp(res->value, "isolate"))
4495                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4496         else
4497                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4498
4499         /* Set the bypass mode for the relevant port. */
4500         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4501 #endif
4502         if (rc != 0)
4503                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4504 }
4505
4506 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4507         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4508                         set, "set");
4509 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4510         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4511                         bypass, "bypass");
4512 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4513         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4514                         mode, "mode");
4515 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4516         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4517                         value, "normal#bypass#isolate");
4518 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4519         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4520                                 port_id, UINT16);
4521
4522 cmdline_parse_inst_t cmd_set_bypass_mode = {
4523         .f = cmd_set_bypass_mode_parsed,
4524         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4525                     "Set the NIC bypass mode for port_id",
4526         .data = NULL,
4527         .tokens = {
4528                 (void *)&cmd_setbypass_mode_set,
4529                 (void *)&cmd_setbypass_mode_bypass,
4530                 (void *)&cmd_setbypass_mode_mode,
4531                 (void *)&cmd_setbypass_mode_value,
4532                 (void *)&cmd_setbypass_mode_port,
4533                 NULL,
4534         },
4535 };
4536
4537 /* *** SET NIC BYPASS EVENT *** */
4538 struct cmd_set_bypass_event_result {
4539         cmdline_fixed_string_t set;
4540         cmdline_fixed_string_t bypass;
4541         cmdline_fixed_string_t event;
4542         cmdline_fixed_string_t event_value;
4543         cmdline_fixed_string_t mode;
4544         cmdline_fixed_string_t mode_value;
4545         portid_t port_id;
4546 };
4547
4548 static void
4549 cmd_set_bypass_event_parsed(void *parsed_result,
4550                 __attribute__((unused)) struct cmdline *cl,
4551                 __attribute__((unused)) void *data)
4552 {
4553         int32_t rc = -EINVAL;
4554         struct cmd_set_bypass_event_result *res = parsed_result;
4555         portid_t port_id = res->port_id;
4556
4557 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4558         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4559         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4560
4561         if (!strcmp(res->event_value, "timeout"))
4562                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4563         else if (!strcmp(res->event_value, "os_on"))
4564                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4565         else if (!strcmp(res->event_value, "os_off"))
4566                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4567         else if (!strcmp(res->event_value, "power_on"))
4568                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4569         else if (!strcmp(res->event_value, "power_off"))
4570                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4571         else
4572                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4573
4574         if (!strcmp(res->mode_value, "bypass"))
4575                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4576         else if (!strcmp(res->mode_value, "isolate"))
4577                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4578         else
4579                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4580
4581         /* Set the watchdog timeout. */
4582         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4583
4584                 rc = -EINVAL;
4585                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4586                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4587                                                            bypass_timeout);
4588                 }
4589                 if (rc != 0) {
4590                         printf("Failed to set timeout value %u "
4591                         "for port %d, errto code: %d.\n",
4592                         bypass_timeout, port_id, rc);
4593                 }
4594         }
4595
4596         /* Set the bypass event to transition to bypass mode. */
4597         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4598                                               bypass_mode);
4599 #endif
4600
4601         if (rc != 0)
4602                 printf("\t Failed to set bypass event for port = %d.\n",
4603                        port_id);
4604 }
4605
4606 cmdline_parse_token_string_t cmd_setbypass_event_set =
4607         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4608                         set, "set");
4609 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4610         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4611                         bypass, "bypass");
4612 cmdline_parse_token_string_t cmd_setbypass_event_event =
4613         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4614                         event, "event");
4615 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4616         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4617                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4618 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4619         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4620                         mode, "mode");
4621 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4622         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4623                         mode_value, "normal#bypass#isolate");
4624 cmdline_parse_token_num_t cmd_setbypass_event_port =
4625         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4626                                 port_id, UINT16);
4627
4628 cmdline_parse_inst_t cmd_set_bypass_event = {
4629         .f = cmd_set_bypass_event_parsed,
4630         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4631                 "power_off mode normal|bypass|isolate <port_id>: "
4632                 "Set the NIC bypass event mode for port_id",
4633         .data = NULL,
4634         .tokens = {
4635                 (void *)&cmd_setbypass_event_set,
4636                 (void *)&cmd_setbypass_event_bypass,
4637                 (void *)&cmd_setbypass_event_event,
4638                 (void *)&cmd_setbypass_event_event_value,
4639                 (void *)&cmd_setbypass_event_mode,
4640                 (void *)&cmd_setbypass_event_mode_value,
4641                 (void *)&cmd_setbypass_event_port,
4642                 NULL,
4643         },
4644 };
4645
4646
4647 /* *** SET NIC BYPASS TIMEOUT *** */
4648 struct cmd_set_bypass_timeout_result {
4649         cmdline_fixed_string_t set;
4650         cmdline_fixed_string_t bypass;
4651         cmdline_fixed_string_t timeout;
4652         cmdline_fixed_string_t value;
4653 };
4654
4655 static void
4656 cmd_set_bypass_timeout_parsed(void *parsed_result,
4657                 __attribute__((unused)) struct cmdline *cl,
4658                 __attribute__((unused)) void *data)
4659 {
4660         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4661
4662 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4663         if (!strcmp(res->value, "1.5"))
4664                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4665         else if (!strcmp(res->value, "2"))
4666                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4667         else if (!strcmp(res->value, "3"))
4668                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4669         else if (!strcmp(res->value, "4"))
4670                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4671         else if (!strcmp(res->value, "8"))
4672                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4673         else if (!strcmp(res->value, "16"))
4674                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4675         else if (!strcmp(res->value, "32"))
4676                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4677         else
4678                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4679 #endif
4680 }
4681
4682 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4683         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4684                         set, "set");
4685 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4686         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4687                         bypass, "bypass");
4688 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4689         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4690                         timeout, "timeout");
4691 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4692         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4693                         value, "0#1.5#2#3#4#8#16#32");
4694
4695 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4696         .f = cmd_set_bypass_timeout_parsed,
4697         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4698                 "Set the NIC bypass watchdog timeout in seconds",
4699         .data = NULL,
4700         .tokens = {
4701                 (void *)&cmd_setbypass_timeout_set,
4702                 (void *)&cmd_setbypass_timeout_bypass,
4703                 (void *)&cmd_setbypass_timeout_timeout,
4704                 (void *)&cmd_setbypass_timeout_value,
4705                 NULL,
4706         },
4707 };
4708
4709 /* *** SHOW NIC BYPASS MODE *** */
4710 struct cmd_show_bypass_config_result {
4711         cmdline_fixed_string_t show;
4712         cmdline_fixed_string_t bypass;
4713         cmdline_fixed_string_t config;
4714         portid_t port_id;
4715 };
4716
4717 static void
4718 cmd_show_bypass_config_parsed(void *parsed_result,
4719                 __attribute__((unused)) struct cmdline *cl,
4720                 __attribute__((unused)) void *data)
4721 {
4722         struct cmd_show_bypass_config_result *res = parsed_result;
4723         portid_t port_id = res->port_id;
4724         int rc = -EINVAL;
4725 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4726         uint32_t event_mode;
4727         uint32_t bypass_mode;
4728         uint32_t timeout = bypass_timeout;
4729         int i;
4730
4731         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4732                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4733         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4734                 {"UNKNOWN", "normal", "bypass", "isolate"};
4735         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4736                 "NONE",
4737                 "OS/board on",
4738                 "power supply on",
4739                 "OS/board off",
4740                 "power supply off",
4741                 "timeout"};
4742         int num_events = (sizeof events) / (sizeof events[0]);
4743
4744         /* Display the bypass mode.*/
4745         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4746                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4747                 return;
4748         }
4749         else {
4750                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4751                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4752
4753                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4754         }
4755
4756         /* Display the bypass timeout.*/
4757         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4758                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4759
4760         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4761
4762         /* Display the bypass events and associated modes. */
4763         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4764
4765                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4766                         printf("\tFailed to get bypass mode for event = %s\n",
4767                                 events[i]);
4768                 } else {
4769                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4770                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4771
4772                         printf("\tbypass event: %-16s = %s\n", events[i],
4773                                 modes[event_mode]);
4774                 }
4775         }
4776 #endif
4777         if (rc != 0)
4778                 printf("\tFailed to get bypass configuration for port = %d\n",
4779                        port_id);
4780 }
4781
4782 cmdline_parse_token_string_t cmd_showbypass_config_show =
4783         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4784                         show, "show");
4785 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4786         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4787                         bypass, "bypass");
4788 cmdline_parse_token_string_t cmd_showbypass_config_config =
4789         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4790                         config, "config");
4791 cmdline_parse_token_num_t cmd_showbypass_config_port =
4792         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4793                                 port_id, UINT16);
4794
4795 cmdline_parse_inst_t cmd_show_bypass_config = {
4796         .f = cmd_show_bypass_config_parsed,
4797         .help_str = "show bypass config <port_id>: "
4798                     "Show the NIC bypass config for port_id",
4799         .data = NULL,
4800         .tokens = {
4801                 (void *)&cmd_showbypass_config_show,
4802                 (void *)&cmd_showbypass_config_bypass,
4803                 (void *)&cmd_showbypass_config_config,
4804                 (void *)&cmd_showbypass_config_port,
4805                 NULL,
4806         },
4807 };
4808
4809 #ifdef RTE_LIBRTE_PMD_BOND
4810 /* *** SET BONDING MODE *** */
4811 struct cmd_set_bonding_mode_result {
4812         cmdline_fixed_string_t set;
4813         cmdline_fixed_string_t bonding;
4814         cmdline_fixed_string_t mode;
4815         uint8_t value;
4816         portid_t port_id;
4817 };
4818
4819 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4820                 __attribute__((unused))  struct cmdline *cl,
4821                 __attribute__((unused)) void *data)
4822 {
4823         struct cmd_set_bonding_mode_result *res = parsed_result;
4824         portid_t port_id = res->port_id;
4825
4826         /* Set the bonding mode for the relevant port. */
4827         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4828                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4829 }
4830
4831 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4832 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4833                 set, "set");
4834 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4835 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4836                 bonding, "bonding");
4837 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4838 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4839                 mode, "mode");
4840 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4841 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4842                 value, UINT8);
4843 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4844 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4845                 port_id, UINT16);
4846
4847 cmdline_parse_inst_t cmd_set_bonding_mode = {
4848                 .f = cmd_set_bonding_mode_parsed,
4849                 .help_str = "set bonding mode <mode_value> <port_id>: "
4850                         "Set the bonding mode for port_id",
4851                 .data = NULL,
4852                 .tokens = {
4853                                 (void *) &cmd_setbonding_mode_set,
4854                                 (void *) &cmd_setbonding_mode_bonding,
4855                                 (void *) &cmd_setbonding_mode_mode,
4856                                 (void *) &cmd_setbonding_mode_value,
4857                                 (void *) &cmd_setbonding_mode_port,
4858                                 NULL
4859                 }
4860 };
4861
4862 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4863 struct cmd_set_bonding_lacp_dedicated_queues_result {
4864         cmdline_fixed_string_t set;
4865         cmdline_fixed_string_t bonding;
4866         cmdline_fixed_string_t lacp;
4867         cmdline_fixed_string_t dedicated_queues;
4868         portid_t port_id;
4869         cmdline_fixed_string_t mode;
4870 };
4871
4872 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4873                 __attribute__((unused))  struct cmdline *cl,
4874                 __attribute__((unused)) void *data)
4875 {
4876         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4877         portid_t port_id = res->port_id;
4878         struct rte_port *port;
4879
4880         port = &ports[port_id];
4881
4882         /** Check if the port is not started **/
4883         if (port->port_status != RTE_PORT_STOPPED) {
4884                 printf("Please stop port %d first\n", port_id);
4885                 return;
4886         }
4887
4888         if (!strcmp(res->mode, "enable")) {
4889                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4890                         printf("Dedicate queues for LACP control packets"
4891                                         " enabled\n");
4892                 else
4893                         printf("Enabling dedicate queues for LACP control "
4894                                         "packets on port %d failed\n", port_id);
4895         } else if (!strcmp(res->mode, "disable")) {
4896                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4897                         printf("Dedicated queues for LACP control packets "
4898                                         "disabled\n");
4899                 else
4900                         printf("Disabling dedicated queues for LACP control "
4901                                         "traffic on port %d failed\n", port_id);
4902         }
4903 }
4904
4905 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4906 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4907                 set, "set");
4908 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4910                 bonding, "bonding");
4911 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4912 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4913                 lacp, "lacp");
4914 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4916                 dedicated_queues, "dedicated_queues");
4917 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4918 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4919                 port_id, UINT16);
4920 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4922                 mode, "enable#disable");
4923
4924 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4925                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4926                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4927                         "enable|disable: "
4928                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4929                 .data = NULL,
4930                 .tokens = {
4931                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4932                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4933                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4934                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4935                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4936                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4937                         NULL
4938                 }
4939 };
4940
4941 /* *** SET BALANCE XMIT POLICY *** */
4942 struct cmd_set_bonding_balance_xmit_policy_result {
4943         cmdline_fixed_string_t set;
4944         cmdline_fixed_string_t bonding;
4945         cmdline_fixed_string_t balance_xmit_policy;
4946         portid_t port_id;
4947         cmdline_fixed_string_t policy;
4948 };
4949
4950 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4951                 __attribute__((unused))  struct cmdline *cl,
4952                 __attribute__((unused)) void *data)
4953 {
4954         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4955         portid_t port_id = res->port_id;
4956         uint8_t policy;
4957
4958         if (!strcmp(res->policy, "l2")) {
4959                 policy = BALANCE_XMIT_POLICY_LAYER2;
4960         } else if (!strcmp(res->policy, "l23")) {
4961                 policy = BALANCE_XMIT_POLICY_LAYER23;
4962         } else if (!strcmp(res->policy, "l34")) {
4963                 policy = BALANCE_XMIT_POLICY_LAYER34;
4964         } else {
4965                 printf("\t Invalid xmit policy selection");
4966                 return;
4967         }
4968
4969         /* Set the bonding mode for the relevant port. */
4970         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4971                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4972                                 port_id);
4973         }
4974 }
4975
4976 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4977 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4978                 set, "set");
4979 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4980 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4981                 bonding, "bonding");
4982 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4983 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4984                 balance_xmit_policy, "balance_xmit_policy");
4985 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4986 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4987                 port_id, UINT16);
4988 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4989 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4990                 policy, "l2#l23#l34");
4991
4992 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4993                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4994                 .help_str = "set bonding balance_xmit_policy <port_id> "
4995                         "l2|l23|l34: "
4996                         "Set the bonding balance_xmit_policy for port_id",
4997                 .data = NULL,
4998                 .tokens = {
4999                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5000                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5001                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5002                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5003                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5004                                 NULL
5005                 }
5006 };
5007
5008 /* *** SHOW NIC BONDING CONFIGURATION *** */
5009 struct cmd_show_bonding_config_result {
5010         cmdline_fixed_string_t show;
5011         cmdline_fixed_string_t bonding;
5012         cmdline_fixed_string_t config;
5013         portid_t port_id;
5014 };
5015
5016 static void cmd_show_bonding_config_parsed(void *parsed_result,
5017                 __attribute__((unused))  struct cmdline *cl,
5018                 __attribute__((unused)) void *data)
5019 {
5020         struct cmd_show_bonding_config_result *res = parsed_result;
5021         int bonding_mode, agg_mode;
5022         portid_t slaves[RTE_MAX_ETHPORTS];
5023         int num_slaves, num_active_slaves;
5024         int primary_id;
5025         int i;
5026         portid_t port_id = res->port_id;
5027
5028         /* Display the bonding mode.*/
5029         bonding_mode = rte_eth_bond_mode_get(port_id);
5030         if (bonding_mode < 0) {
5031                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5032                 return;
5033         } else
5034                 printf("\tBonding mode: %d\n", bonding_mode);
5035
5036         if (bonding_mode == BONDING_MODE_BALANCE) {
5037                 int balance_xmit_policy;
5038
5039                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5040                 if (balance_xmit_policy < 0) {
5041                         printf("\tFailed to get balance xmit policy for port = %d\n",
5042                                         port_id);
5043                         return;
5044                 } else {
5045                         printf("\tBalance Xmit Policy: ");
5046
5047                         switch (balance_xmit_policy) {
5048                         case BALANCE_XMIT_POLICY_LAYER2:
5049                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5050                                 break;
5051                         case BALANCE_XMIT_POLICY_LAYER23:
5052                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5053                                 break;
5054                         case BALANCE_XMIT_POLICY_LAYER34:
5055                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5056                                 break;
5057                         }
5058                         printf("\n");
5059                 }
5060         }
5061
5062         if (bonding_mode == BONDING_MODE_8023AD) {
5063                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5064                 printf("\tIEEE802.3AD Aggregator Mode: ");
5065                 switch (agg_mode) {
5066                 case AGG_BANDWIDTH:
5067                         printf("bandwidth");
5068                         break;
5069                 case AGG_STABLE:
5070                         printf("stable");
5071                         break;
5072                 case AGG_COUNT:
5073                         printf("count");
5074                         break;
5075                 }
5076                 printf("\n");
5077         }
5078
5079         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5080
5081         if (num_slaves < 0) {
5082                 printf("\tFailed to get slave list for port = %d\n", port_id);
5083                 return;
5084         }
5085         if (num_slaves > 0) {
5086                 printf("\tSlaves (%d): [", num_slaves);
5087                 for (i = 0; i < num_slaves - 1; i++)
5088                         printf("%d ", slaves[i]);
5089
5090                 printf("%d]\n", slaves[num_slaves - 1]);
5091         } else {
5092                 printf("\tSlaves: []\n");
5093
5094         }
5095
5096         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5097                         RTE_MAX_ETHPORTS);
5098
5099         if (num_active_slaves < 0) {
5100                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5101                 return;
5102         }
5103         if (num_active_slaves > 0) {
5104                 printf("\tActive Slaves (%d): [", num_active_slaves);
5105                 for (i = 0; i < num_active_slaves - 1; i++)
5106                         printf("%d ", slaves[i]);
5107
5108                 printf("%d]\n", slaves[num_active_slaves - 1]);
5109
5110         } else {
5111                 printf("\tActive Slaves: []\n");
5112
5113         }
5114
5115         primary_id = rte_eth_bond_primary_get(port_id);
5116         if (primary_id < 0) {
5117                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5118                 return;
5119         } else
5120                 printf("\tPrimary: [%d]\n", primary_id);
5121
5122 }
5123
5124 cmdline_parse_token_string_t cmd_showbonding_config_show =
5125 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5126                 show, "show");
5127 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5128 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5129                 bonding, "bonding");
5130 cmdline_parse_token_string_t cmd_showbonding_config_config =
5131 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5132                 config, "config");
5133 cmdline_parse_token_num_t cmd_showbonding_config_port =
5134 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5135                 port_id, UINT16);
5136
5137 cmdline_parse_inst_t cmd_show_bonding_config = {
5138                 .f = cmd_show_bonding_config_parsed,
5139                 .help_str = "show bonding config <port_id>: "
5140                         "Show the bonding config for port_id",
5141                 .data = NULL,
5142                 .tokens = {
5143                                 (void *)&cmd_showbonding_config_show,
5144                                 (void *)&cmd_showbonding_config_bonding,
5145                                 (void *)&cmd_showbonding_config_config,
5146                                 (void *)&cmd_showbonding_config_port,
5147                                 NULL
5148                 }
5149 };
5150
5151 /* *** SET BONDING PRIMARY *** */
5152 struct cmd_set_bonding_primary_result {
5153         cmdline_fixed_string_t set;
5154         cmdline_fixed_string_t bonding;
5155         cmdline_fixed_string_t primary;
5156         portid_t slave_id;
5157         portid_t port_id;
5158 };
5159
5160 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5161                 __attribute__((unused))  struct cmdline *cl,
5162                 __attribute__((unused)) void *data)
5163 {
5164         struct cmd_set_bonding_primary_result *res = parsed_result;
5165         portid_t master_port_id = res->port_id;
5166         portid_t slave_port_id = res->slave_id;
5167
5168         /* Set the primary slave for a bonded device. */
5169         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5170                 printf("\t Failed to set primary slave for port = %d.\n",
5171                                 master_port_id);
5172                 return;
5173         }
5174         init_port_config();
5175 }
5176
5177 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5178 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5179                 set, "set");
5180 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5181 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5182                 bonding, "bonding");
5183 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5184 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5185                 primary, "primary");
5186 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5187 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5188                 slave_id, UINT16);
5189 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5190 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5191                 port_id, UINT16);
5192
5193 cmdline_parse_inst_t cmd_set_bonding_primary = {
5194                 .f = cmd_set_bonding_primary_parsed,
5195                 .help_str = "set bonding primary <slave_id> <port_id>: "
5196                         "Set the primary slave for port_id",
5197                 .data = NULL,
5198                 .tokens = {
5199                                 (void *)&cmd_setbonding_primary_set,
5200                                 (void *)&cmd_setbonding_primary_bonding,
5201                                 (void *)&cmd_setbonding_primary_primary,
5202                                 (void *)&cmd_setbonding_primary_slave,
5203                                 (void *)&cmd_setbonding_primary_port,
5204                                 NULL
5205                 }
5206 };
5207
5208 /* *** ADD SLAVE *** */
5209 struct cmd_add_bonding_slave_result {
5210         cmdline_fixed_string_t add;
5211         cmdline_fixed_string_t bonding;
5212         cmdline_fixed_string_t slave;
5213         portid_t slave_id;
5214         portid_t port_id;
5215 };
5216
5217 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5218                 __attribute__((unused))  struct cmdline *cl,
5219                 __attribute__((unused)) void *data)
5220 {
5221         struct cmd_add_bonding_slave_result *res = parsed_result;
5222         portid_t master_port_id = res->port_id;
5223         portid_t slave_port_id = res->slave_id;
5224
5225         /* add the slave for a bonded device. */
5226         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5227                 printf("\t Failed to add slave %d to master port = %d.\n",
5228                                 slave_port_id, master_port_id);
5229                 return;
5230         }
5231         init_port_config();
5232         set_port_slave_flag(slave_port_id);
5233 }
5234
5235 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5236 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5237                 add, "add");
5238 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5239 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5240                 bonding, "bonding");
5241 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5242 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5243                 slave, "slave");
5244 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5245 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5246                 slave_id, UINT16);
5247 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5248 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5249                 port_id, UINT16);
5250
5251 cmdline_parse_inst_t cmd_add_bonding_slave = {
5252                 .f = cmd_add_bonding_slave_parsed,
5253                 .help_str = "add bonding slave <slave_id> <port_id>: "
5254                         "Add a slave device to a bonded device",
5255                 .data = NULL,
5256                 .tokens = {
5257                                 (void *)&cmd_addbonding_slave_add,
5258                                 (void *)&cmd_addbonding_slave_bonding,
5259                                 (void *)&cmd_addbonding_slave_slave,
5260                                 (void *)&cmd_addbonding_slave_slaveid,
5261                                 (void *)&cmd_addbonding_slave_port,
5262                                 NULL
5263                 }
5264 };
5265
5266 /* *** REMOVE SLAVE *** */
5267 struct cmd_remove_bonding_slave_result {
5268         cmdline_fixed_string_t remove;
5269         cmdline_fixed_string_t bonding;
5270         cmdline_fixed_string_t slave;
5271         portid_t slave_id;
5272         portid_t port_id;
5273 };
5274
5275 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5276                 __attribute__((unused))  struct cmdline *cl,
5277                 __attribute__((unused)) void *data)
5278 {
5279         struct cmd_remove_bonding_slave_result *res = parsed_result;
5280         portid_t master_port_id = res->port_id;
5281         portid_t slave_port_id = res->slave_id;
5282
5283         /* remove the slave from a bonded device. */
5284         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5285                 printf("\t Failed to remove slave %d from master port = %d.\n",
5286                                 slave_port_id, master_port_id);
5287                 return;
5288         }
5289         init_port_config();
5290         clear_port_slave_flag(slave_port_id);
5291 }
5292
5293 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5294                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5295                                 remove, "remove");
5296 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5297                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5298                                 bonding, "bonding");
5299 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5300                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5301                                 slave, "slave");
5302 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5303                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5304                                 slave_id, UINT16);
5305 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5306                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5307                                 port_id, UINT16);
5308
5309 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5310                 .f = cmd_remove_bonding_slave_parsed,
5311                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5312                         "Remove a slave device from a bonded device",
5313                 .data = NULL,
5314                 .tokens = {
5315                                 (void *)&cmd_removebonding_slave_remove,
5316                                 (void *)&cmd_removebonding_slave_bonding,
5317                                 (void *)&cmd_removebonding_slave_slave,
5318                                 (void *)&cmd_removebonding_slave_slaveid,
5319                                 (void *)&cmd_removebonding_slave_port,
5320                                 NULL
5321                 }
5322 };
5323
5324 /* *** CREATE BONDED DEVICE *** */
5325 struct cmd_create_bonded_device_result {
5326         cmdline_fixed_string_t create;
5327         cmdline_fixed_string_t bonded;
5328         cmdline_fixed_string_t device;
5329         uint8_t mode;
5330         uint8_t socket;
5331 };
5332
5333 static int bond_dev_num = 0;
5334
5335 static void cmd_create_bonded_device_parsed(void *parsed_result,
5336                 __attribute__((unused))  struct cmdline *cl,
5337                 __attribute__((unused)) void *data)
5338 {
5339         struct cmd_create_bonded_device_result *res = parsed_result;
5340         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5341         int port_id;
5342
5343         if (test_done == 0) {
5344                 printf("Please stop forwarding first\n");
5345                 return;
5346         }
5347
5348         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5349                         bond_dev_num++);
5350
5351         /* Create a new bonded device. */
5352         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5353         if (port_id < 0) {
5354                 printf("\t Failed to create bonded device.\n");
5355                 return;
5356         } else {
5357                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5358                                 port_id);
5359
5360                 /* Update number of ports */
5361                 nb_ports = rte_eth_dev_count();
5362                 reconfig(port_id, res->socket);
5363                 rte_eth_promiscuous_enable(port_id);
5364         }
5365
5366 }
5367
5368 cmdline_parse_token_string_t cmd_createbonded_device_create =
5369                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5370                                 create, "create");
5371 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5372                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5373                                 bonded, "bonded");
5374 cmdline_parse_token_string_t cmd_createbonded_device_device =
5375                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5376                                 device, "device");
5377 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5378                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5379                                 mode, UINT8);
5380 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5381                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5382                                 socket, UINT8);
5383
5384 cmdline_parse_inst_t cmd_create_bonded_device = {
5385                 .f = cmd_create_bonded_device_parsed,
5386                 .help_str = "create bonded device <mode> <socket>: "
5387                         "Create a new bonded device with specific bonding mode and socket",
5388                 .data = NULL,
5389                 .tokens = {
5390                                 (void *)&cmd_createbonded_device_create,
5391                                 (void *)&cmd_createbonded_device_bonded,
5392                                 (void *)&cmd_createbonded_device_device,
5393                                 (void *)&cmd_createbonded_device_mode,
5394                                 (void *)&cmd_createbonded_device_socket,
5395                                 NULL
5396                 }
5397 };
5398
5399 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5400 struct cmd_set_bond_mac_addr_result {
5401         cmdline_fixed_string_t set;
5402         cmdline_fixed_string_t bonding;
5403         cmdline_fixed_string_t mac_addr;
5404         uint16_t port_num;
5405         struct ether_addr address;
5406 };
5407
5408 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5409                 __attribute__((unused))  struct cmdline *cl,
5410                 __attribute__((unused)) void *data)
5411 {
5412         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5413         int ret;
5414
5415         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5416                 return;
5417
5418         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5419
5420         /* check the return value and print it if is < 0 */
5421         if (ret < 0)
5422                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5423 }
5424
5425 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5426                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5427 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5428                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5429                                 "bonding");
5430 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5431                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5432                                 "mac_addr");
5433 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5434                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5435                                 port_num, UINT16);
5436 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5437                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5438
5439 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5440                 .f = cmd_set_bond_mac_addr_parsed,
5441                 .data = (void *) 0,
5442                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5443                 .tokens = {
5444                                 (void *)&cmd_set_bond_mac_addr_set,
5445                                 (void *)&cmd_set_bond_mac_addr_bonding,
5446                                 (void *)&cmd_set_bond_mac_addr_mac,
5447                                 (void *)&cmd_set_bond_mac_addr_portnum,
5448                                 (void *)&cmd_set_bond_mac_addr_addr,
5449                                 NULL
5450                 }
5451 };
5452
5453
5454 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5455 struct cmd_set_bond_mon_period_result {
5456         cmdline_fixed_string_t set;
5457         cmdline_fixed_string_t bonding;
5458         cmdline_fixed_string_t mon_period;
5459         uint16_t port_num;
5460         uint32_t period_ms;
5461 };
5462
5463 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5464                 __attribute__((unused))  struct cmdline *cl,
5465                 __attribute__((unused)) void *data)
5466 {
5467         struct cmd_set_bond_mon_period_result *res = parsed_result;
5468         int ret;
5469
5470         if (res->port_num >= nb_ports) {
5471                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5472                 return;
5473         }
5474
5475         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5476
5477         /* check the return value and print it if is < 0 */
5478         if (ret < 0)
5479                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5480 }
5481
5482 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5483                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5484                                 set, "set");
5485 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5486                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5487                                 bonding, "bonding");
5488 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5489                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5490                                 mon_period,     "mon_period");
5491 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5492                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5493                                 port_num, UINT16);
5494 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5495                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5496                                 period_ms, UINT32);
5497
5498 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5499                 .f = cmd_set_bond_mon_period_parsed,
5500                 .data = (void *) 0,
5501                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5502                 .tokens = {
5503                                 (void *)&cmd_set_bond_mon_period_set,
5504                                 (void *)&cmd_set_bond_mon_period_bonding,
5505                                 (void *)&cmd_set_bond_mon_period_mon_period,
5506                                 (void *)&cmd_set_bond_mon_period_portnum,
5507                                 (void *)&cmd_set_bond_mon_period_period_ms,
5508                                 NULL
5509                 }
5510 };
5511
5512
5513
5514 struct cmd_set_bonding_agg_mode_policy_result {
5515         cmdline_fixed_string_t set;
5516         cmdline_fixed_string_t bonding;
5517         cmdline_fixed_string_t agg_mode;
5518         uint16_t port_num;
5519         cmdline_fixed_string_t policy;
5520 };
5521
5522
5523 static void
5524 cmd_set_bonding_agg_mode(void *parsed_result,
5525                 __attribute__((unused)) struct cmdline *cl,
5526                 __attribute__((unused)) void *data)
5527 {
5528         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5529         uint8_t policy = AGG_BANDWIDTH;
5530
5531         if (res->port_num >= nb_ports) {
5532                 printf("Port id %d must be less than %d\n",
5533                                 res->port_num, nb_ports);
5534                 return;
5535         }
5536
5537         if (!strcmp(res->policy, "bandwidth"))
5538                 policy = AGG_BANDWIDTH;
5539         else if (!strcmp(res->policy, "stable"))
5540                 policy = AGG_STABLE;
5541         else if (!strcmp(res->policy, "count"))
5542                 policy = AGG_COUNT;
5543
5544         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5545 }
5546
5547
5548 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5550                                 set, "set");
5551 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5552         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5553                                 bonding, "bonding");
5554
5555 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5557                                 agg_mode, "agg_mode");
5558
5559 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5560         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5561                                 port_num, UINT16);
5562
5563 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5564         TOKEN_STRING_INITIALIZER(
5565                         struct cmd_set_bonding_balance_xmit_policy_result,
5566                 policy, "stable#bandwidth#count");
5567
5568 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5569         .f = cmd_set_bonding_agg_mode,
5570         .data = (void *) 0,
5571         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5572         .tokens = {
5573                         (void *)&cmd_set_bonding_agg_mode_set,
5574                         (void *)&cmd_set_bonding_agg_mode_bonding,
5575                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5576                         (void *)&cmd_set_bonding_agg_mode_portnum,
5577                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5578                         NULL
5579                 }
5580 };
5581
5582
5583 #endif /* RTE_LIBRTE_PMD_BOND */
5584
5585 /* *** SET FORWARDING MODE *** */
5586 struct cmd_set_fwd_mode_result {
5587         cmdline_fixed_string_t set;
5588         cmdline_fixed_string_t fwd;
5589         cmdline_fixed_string_t mode;
5590 };
5591
5592 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5593                                     __attribute__((unused)) struct cmdline *cl,
5594                                     __attribute__((unused)) void *data)
5595 {
5596         struct cmd_set_fwd_mode_result *res = parsed_result;
5597
5598         retry_enabled = 0;
5599         set_pkt_forwarding_mode(res->mode);
5600 }
5601
5602 cmdline_parse_token_string_t cmd_setfwd_set =
5603         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5604 cmdline_parse_token_string_t cmd_setfwd_fwd =
5605         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5606 cmdline_parse_token_string_t cmd_setfwd_mode =
5607         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5608                 "" /* defined at init */);
5609
5610 cmdline_parse_inst_t cmd_set_fwd_mode = {
5611         .f = cmd_set_fwd_mode_parsed,
5612         .data = NULL,
5613         .help_str = NULL, /* defined at init */
5614         .tokens = {
5615                 (void *)&cmd_setfwd_set,
5616                 (void *)&cmd_setfwd_fwd,
5617                 (void *)&cmd_setfwd_mode,
5618                 NULL,
5619         },
5620 };
5621
5622 static void cmd_set_fwd_mode_init(void)
5623 {
5624         char *modes, *c;
5625         static char token[128];
5626         static char help[256];
5627         cmdline_parse_token_string_t *token_struct;
5628
5629         modes = list_pkt_forwarding_modes();
5630         snprintf(help, sizeof(help), "set fwd %s: "
5631                 "Set packet forwarding mode", modes);
5632         cmd_set_fwd_mode.help_str = help;
5633
5634         /* string token separator is # */
5635         for (c = token; *modes != '\0'; modes++)
5636                 if (*modes == '|')
5637                         *c++ = '#';
5638                 else
5639                         *c++ = *modes;
5640         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5641         token_struct->string_data.str = token;
5642 }
5643
5644 /* *** SET RETRY FORWARDING MODE *** */
5645 struct cmd_set_fwd_retry_mode_result {
5646         cmdline_fixed_string_t set;
5647         cmdline_fixed_string_t fwd;
5648         cmdline_fixed_string_t mode;
5649         cmdline_fixed_string_t retry;
5650 };
5651
5652 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5653                             __attribute__((unused)) struct cmdline *cl,
5654                             __attribute__((unused)) void *data)
5655 {
5656         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5657
5658         retry_enabled = 1;
5659         set_pkt_forwarding_mode(res->mode);
5660 }
5661
5662 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5663         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5664                         set, "set");
5665 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5666         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5667                         fwd, "fwd");
5668 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5669         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5670                         mode,
5671                 "" /* defined at init */);
5672 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5673         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5674                         retry, "retry");
5675
5676 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5677         .f = cmd_set_fwd_retry_mode_parsed,
5678         .data = NULL,
5679         .help_str = NULL, /* defined at init */
5680         .tokens = {
5681                 (void *)&cmd_setfwd_retry_set,
5682                 (void *)&cmd_setfwd_retry_fwd,
5683                 (void *)&cmd_setfwd_retry_mode,
5684                 (void *)&cmd_setfwd_retry_retry,
5685                 NULL,
5686         },
5687 };
5688
5689 static void cmd_set_fwd_retry_mode_init(void)
5690 {
5691         char *modes, *c;
5692         static char token[128];
5693         static char help[256];
5694         cmdline_parse_token_string_t *token_struct;
5695
5696         modes = list_pkt_forwarding_retry_modes();
5697         snprintf(help, sizeof(help), "set fwd %s retry: "
5698                 "Set packet forwarding mode with retry", modes);
5699         cmd_set_fwd_retry_mode.help_str = help;
5700
5701         /* string token separator is # */
5702         for (c = token; *modes != '\0'; modes++)
5703                 if (*modes == '|')
5704                         *c++ = '#';
5705                 else
5706                         *c++ = *modes;
5707         token_struct = (cmdline_parse_token_string_t *)
5708                 cmd_set_fwd_retry_mode.tokens[2];
5709         token_struct->string_data.str = token;
5710 }
5711
5712 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5713 struct cmd_set_burst_tx_retry_result {
5714         cmdline_fixed_string_t set;
5715         cmdline_fixed_string_t burst;
5716         cmdline_fixed_string_t tx;
5717         cmdline_fixed_string_t delay;
5718         uint32_t time;
5719         cmdline_fixed_string_t retry;
5720         uint32_t retry_num;
5721 };
5722
5723 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5724                                         __attribute__((unused)) struct cmdline *cl,
5725                                         __attribute__((unused)) void *data)
5726 {
5727         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5728
5729         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5730                 && !strcmp(res->tx, "tx")) {
5731                 if (!strcmp(res->delay, "delay"))
5732                         burst_tx_delay_time = res->time;
5733                 if (!strcmp(res->retry, "retry"))
5734                         burst_tx_retry_num = res->retry_num;
5735         }
5736
5737 }
5738
5739 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5740         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5741 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5742         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5743                                  "burst");
5744 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5745         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5746 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5747         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5748 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5749         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5750 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5751         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5752 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5753         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5754
5755 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5756         .f = cmd_set_burst_tx_retry_parsed,
5757         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5758         .tokens = {
5759                 (void *)&cmd_set_burst_tx_retry_set,
5760                 (void *)&cmd_set_burst_tx_retry_burst,
5761                 (void *)&cmd_set_burst_tx_retry_tx,
5762                 (void *)&cmd_set_burst_tx_retry_delay,
5763                 (void *)&cmd_set_burst_tx_retry_time,
5764                 (void *)&cmd_set_burst_tx_retry_retry,
5765                 (void *)&cmd_set_burst_tx_retry_retry_num,
5766                 NULL,
5767         },
5768 };
5769
5770 /* *** SET PROMISC MODE *** */
5771 struct cmd_set_promisc_mode_result {
5772         cmdline_fixed_string_t set;
5773         cmdline_fixed_string_t promisc;
5774         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5775         uint16_t port_num;               /* valid if "allports" argument == 0 */
5776         cmdline_fixed_string_t mode;
5777 };
5778
5779 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5780                                         __attribute__((unused)) struct cmdline *cl,
5781                                         void *allports)
5782 {
5783         struct cmd_set_promisc_mode_result *res = parsed_result;
5784         int enable;
5785         portid_t i;
5786
5787         if (!strcmp(res->mode, "on"))
5788                 enable = 1;
5789         else
5790                 enable = 0;
5791
5792         /* all ports */
5793         if (allports) {
5794                 RTE_ETH_FOREACH_DEV(i) {
5795                         if (enable)
5796                                 rte_eth_promiscuous_enable(i);
5797                         else
5798                                 rte_eth_promiscuous_disable(i);
5799                 }
5800         }
5801         else {
5802                 if (enable)
5803                         rte_eth_promiscuous_enable(res->port_num);
5804                 else
5805                         rte_eth_promiscuous_disable(res->port_num);
5806         }
5807 }
5808
5809 cmdline_parse_token_string_t cmd_setpromisc_set =
5810         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5811 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5812         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5813                                  "promisc");
5814 cmdline_parse_token_string_t cmd_setpromisc_portall =
5815         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5816                                  "all");
5817 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5818         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5819                               UINT8);
5820 cmdline_parse_token_string_t cmd_setpromisc_mode =
5821         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5822                                  "on#off");
5823
5824 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5825         .f = cmd_set_promisc_mode_parsed,
5826         .data = (void *)1,
5827         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5828         .tokens = {
5829                 (void *)&cmd_setpromisc_set,
5830                 (void *)&cmd_setpromisc_promisc,
5831                 (void *)&cmd_setpromisc_portall,
5832                 (void *)&cmd_setpromisc_mode,
5833                 NULL,
5834         },
5835 };
5836
5837 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5838         .f = cmd_set_promisc_mode_parsed,
5839         .data = (void *)0,
5840         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5841         .tokens = {
5842                 (void *)&cmd_setpromisc_set,
5843                 (void *)&cmd_setpromisc_promisc,
5844                 (void *)&cmd_setpromisc_portnum,
5845                 (void *)&cmd_setpromisc_mode,
5846                 NULL,
5847         },
5848 };
5849
5850 /* *** SET ALLMULTI MODE *** */
5851 struct cmd_set_allmulti_mode_result {
5852         cmdline_fixed_string_t set;
5853         cmdline_fixed_string_t allmulti;
5854         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5855         uint16_t port_num;               /* valid if "allports" argument == 0 */
5856         cmdline_fixed_string_t mode;
5857 };
5858
5859 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5860                                         __attribute__((unused)) struct cmdline *cl,
5861                                         void *allports)
5862 {
5863         struct cmd_set_allmulti_mode_result *res = parsed_result;
5864         int enable;
5865         portid_t i;
5866
5867         if (!strcmp(res->mode, "on"))
5868                 enable = 1;
5869         else
5870                 enable = 0;
5871
5872         /* all ports */
5873         if (allports) {
5874                 RTE_ETH_FOREACH_DEV(i) {
5875                         if (enable)
5876                                 rte_eth_allmulticast_enable(i);
5877                         else
5878                                 rte_eth_allmulticast_disable(i);
5879                 }
5880         }
5881         else {
5882                 if (enable)
5883                         rte_eth_allmulticast_enable(res->port_num);
5884                 else
5885                         rte_eth_allmulticast_disable(res->port_num);
5886         }
5887 }
5888
5889 cmdline_parse_token_string_t cmd_setallmulti_set =
5890         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5891 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5892         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5893                                  "allmulti");
5894 cmdline_parse_token_string_t cmd_setallmulti_portall =
5895         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5896                                  "all");
5897 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5898         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5899                               UINT16);
5900 cmdline_parse_token_string_t cmd_setallmulti_mode =
5901         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5902                                  "on#off");
5903
5904 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5905         .f = cmd_set_allmulti_mode_parsed,
5906         .data = (void *)1,
5907         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5908         .tokens = {
5909                 (void *)&cmd_setallmulti_set,
5910                 (void *)&cmd_setallmulti_allmulti,
5911                 (void *)&cmd_setallmulti_portall,
5912                 (void *)&cmd_setallmulti_mode,
5913                 NULL,
5914         },
5915 };
5916
5917 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5918         .f = cmd_set_allmulti_mode_parsed,
5919         .data = (void *)0,
5920         .help_str = "set allmulti <port_id> on|off: "
5921                 "Set allmulti mode on port_id",
5922         .tokens = {
5923                 (void *)&cmd_setallmulti_set,
5924                 (void *)&cmd_setallmulti_allmulti,
5925                 (void *)&cmd_setallmulti_portnum,
5926                 (void *)&cmd_setallmulti_mode,
5927                 NULL,
5928         },
5929 };
5930
5931 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5932 struct cmd_link_flow_ctrl_set_result {
5933         cmdline_fixed_string_t set;
5934         cmdline_fixed_string_t flow_ctrl;
5935         cmdline_fixed_string_t rx;
5936         cmdline_fixed_string_t rx_lfc_mode;
5937         cmdline_fixed_string_t tx;
5938         cmdline_fixed_string_t tx_lfc_mode;
5939         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5940         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5941         cmdline_fixed_string_t autoneg_str;
5942         cmdline_fixed_string_t autoneg;
5943         cmdline_fixed_string_t hw_str;
5944         uint32_t high_water;
5945         cmdline_fixed_string_t lw_str;
5946         uint32_t low_water;
5947         cmdline_fixed_string_t pt_str;
5948         uint16_t pause_time;
5949         cmdline_fixed_string_t xon_str;
5950         uint16_t send_xon;
5951         portid_t port_id;
5952 };
5953
5954 cmdline_parse_token_string_t cmd_lfc_set_set =
5955         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5956                                 set, "set");
5957 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5958         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5959                                 flow_ctrl, "flow_ctrl");
5960 cmdline_parse_token_string_t cmd_lfc_set_rx =
5961         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5962                                 rx, "rx");
5963 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5964         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5965                                 rx_lfc_mode, "on#off");
5966 cmdline_parse_token_string_t cmd_lfc_set_tx =
5967         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5968                                 tx, "tx");
5969 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5970         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5971                                 tx_lfc_mode, "on#off");
5972 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5973         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5974                                 hw_str, "high_water");
5975 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5976         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5977                                 high_water, UINT32);
5978 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5979         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5980                                 lw_str, "low_water");
5981 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5982         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5983                                 low_water, UINT32);
5984 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5985         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5986                                 pt_str, "pause_time");
5987 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5988         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5989                                 pause_time, UINT16);
5990 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5991         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5992                                 xon_str, "send_xon");
5993 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5994         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5995                                 send_xon, UINT16);
5996 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5997         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5998                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5999 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6000         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6001                                 mac_ctrl_frame_fwd_mode, "on#off");
6002 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6003         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6004                                 autoneg_str, "autoneg");
6005 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6006         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6007                                 autoneg, "on#off");
6008 cmdline_parse_token_num_t cmd_lfc_set_portid =
6009         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6010                                 port_id, UINT16);
6011
6012 /* forward declaration */
6013 static void
6014 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6015                               void *data);
6016
6017 cmdline_parse_inst_t cmd_link_flow_control_set = {
6018         .f = cmd_link_flow_ctrl_set_parsed,
6019         .data = NULL,
6020         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6021                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6022                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6023         .tokens = {
6024                 (void *)&cmd_lfc_set_set,
6025                 (void *)&cmd_lfc_set_flow_ctrl,
6026                 (void *)&cmd_lfc_set_rx,
6027                 (void *)&cmd_lfc_set_rx_mode,
6028                 (void *)&cmd_lfc_set_tx,
6029                 (void *)&cmd_lfc_set_tx_mode,
6030                 (void *)&cmd_lfc_set_high_water,
6031                 (void *)&cmd_lfc_set_low_water,
6032                 (void *)&cmd_lfc_set_pause_time,
6033                 (void *)&cmd_lfc_set_send_xon,
6034                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6035                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6036                 (void *)&cmd_lfc_set_autoneg_str,
6037                 (void *)&cmd_lfc_set_autoneg,
6038                 (void *)&cmd_lfc_set_portid,
6039                 NULL,
6040         },
6041 };
6042
6043 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6044         .f = cmd_link_flow_ctrl_set_parsed,
6045         .data = (void *)&cmd_link_flow_control_set_rx,
6046         .help_str = "set flow_ctrl rx on|off <port_id>: "
6047                 "Change rx flow control parameter",
6048         .tokens = {
6049                 (void *)&cmd_lfc_set_set,
6050                 (void *)&cmd_lfc_set_flow_ctrl,
6051                 (void *)&cmd_lfc_set_rx,
6052                 (void *)&cmd_lfc_set_rx_mode,
6053                 (void *)&cmd_lfc_set_portid,
6054                 NULL,
6055         },
6056 };
6057
6058 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6059         .f = cmd_link_flow_ctrl_set_parsed,
6060         .data = (void *)&cmd_link_flow_control_set_tx,
6061         .help_str = "set flow_ctrl tx on|off <port_id>: "
6062                 "Change tx flow control parameter",
6063         .tokens = {
6064                 (void *)&cmd_lfc_set_set,
6065                 (void *)&cmd_lfc_set_flow_ctrl,
6066                 (void *)&cmd_lfc_set_tx,
6067                 (void *)&cmd_lfc_set_tx_mode,
6068                 (void *)&cmd_lfc_set_portid,
6069                 NULL,
6070         },
6071 };
6072
6073 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6074         .f = cmd_link_flow_ctrl_set_parsed,
6075         .data = (void *)&cmd_link_flow_control_set_hw,
6076         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6077                 "Change high water flow control parameter",
6078         .tokens = {
6079                 (void *)&cmd_lfc_set_set,
6080                 (void *)&cmd_lfc_set_flow_ctrl,
6081                 (void *)&cmd_lfc_set_high_water_str,
6082                 (void *)&cmd_lfc_set_high_water,
6083                 (void *)&cmd_lfc_set_portid,
6084                 NULL,
6085         },
6086 };
6087
6088 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6089         .f = cmd_link_flow_ctrl_set_parsed,
6090         .data = (void *)&cmd_link_flow_control_set_lw,
6091         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6092                 "Change low water flow control parameter",
6093         .tokens = {
6094                 (void *)&cmd_lfc_set_set,
6095                 (void *)&cmd_lfc_set_flow_ctrl,
6096                 (void *)&cmd_lfc_set_low_water_str,
6097                 (void *)&cmd_lfc_set_low_water,
6098                 (void *)&cmd_lfc_set_portid,
6099                 NULL,
6100         },
6101 };
6102
6103 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6104         .f = cmd_link_flow_ctrl_set_parsed,
6105         .data = (void *)&cmd_link_flow_control_set_pt,
6106         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6107                 "Change pause time flow control parameter",
6108         .tokens = {
6109                 (void *)&cmd_lfc_set_set,
6110                 (void *)&cmd_lfc_set_flow_ctrl,
6111                 (void *)&cmd_lfc_set_pause_time_str,
6112                 (void *)&cmd_lfc_set_pause_time,
6113                 (void *)&cmd_lfc_set_portid,
6114                 NULL,
6115         },
6116 };
6117
6118 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6119         .f = cmd_link_flow_ctrl_set_parsed,
6120         .data = (void *)&cmd_link_flow_control_set_xon,
6121         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6122                 "Change send_xon flow control parameter",
6123         .tokens = {
6124                 (void *)&cmd_lfc_set_set,
6125                 (void *)&cmd_lfc_set_flow_ctrl,
6126                 (void *)&cmd_lfc_set_send_xon_str,
6127                 (void *)&cmd_lfc_set_send_xon,
6128                 (void *)&cmd_lfc_set_portid,
6129                 NULL,
6130         },
6131 };
6132
6133 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6134         .f = cmd_link_flow_ctrl_set_parsed,
6135         .data = (void *)&cmd_link_flow_control_set_macfwd,
6136         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6137                 "Change mac ctrl fwd flow control parameter",
6138         .tokens = {
6139                 (void *)&cmd_lfc_set_set,
6140                 (void *)&cmd_lfc_set_flow_ctrl,
6141                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6142                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6143                 (void *)&cmd_lfc_set_portid,
6144                 NULL,
6145         },
6146 };
6147
6148 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6149         .f = cmd_link_flow_ctrl_set_parsed,
6150         .data = (void *)&cmd_link_flow_control_set_autoneg,
6151         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6152                 "Change autoneg flow control parameter",
6153         .tokens = {
6154                 (void *)&cmd_lfc_set_set,
6155                 (void *)&cmd_lfc_set_flow_ctrl,
6156                 (void *)&cmd_lfc_set_autoneg_str,
6157                 (void *)&cmd_lfc_set_autoneg,
6158                 (void *)&cmd_lfc_set_portid,
6159                 NULL,
6160         },
6161 };
6162
6163 static void
6164 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6165                               __attribute__((unused)) struct cmdline *cl,
6166                               void *data)
6167 {
6168         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6169         cmdline_parse_inst_t *cmd = data;
6170         struct rte_eth_fc_conf fc_conf;
6171         int rx_fc_en = 0;
6172         int tx_fc_en = 0;
6173         int ret;
6174
6175         /*
6176          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6177          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6178          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6179          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6180          */
6181         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6182                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6183         };
6184
6185         /* Partial command line, retrieve current configuration */
6186         if (cmd) {
6187                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6188                 if (ret != 0) {
6189                         printf("cannot get current flow ctrl parameters, return"
6190                                "code = %d\n", ret);
6191                         return;
6192                 }
6193
6194                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6195                     (fc_conf.mode == RTE_FC_FULL))
6196                         rx_fc_en = 1;
6197                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6198                     (fc_conf.mode == RTE_FC_FULL))
6199                         tx_fc_en = 1;
6200         }
6201
6202         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6203                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6204
6205         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6206                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6207
6208         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6209
6210         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6211                 fc_conf.high_water = res->high_water;
6212
6213         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6214                 fc_conf.low_water = res->low_water;
6215
6216         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6217                 fc_conf.pause_time = res->pause_time;
6218
6219         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6220                 fc_conf.send_xon = res->send_xon;
6221
6222         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6223                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6224                         fc_conf.mac_ctrl_frame_fwd = 1;
6225                 else
6226                         fc_conf.mac_ctrl_frame_fwd = 0;
6227         }
6228
6229         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6230                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6231
6232         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6233         if (ret != 0)
6234                 printf("bad flow contrl parameter, return code = %d \n", ret);
6235 }
6236
6237 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6238 struct cmd_priority_flow_ctrl_set_result {
6239         cmdline_fixed_string_t set;
6240         cmdline_fixed_string_t pfc_ctrl;
6241         cmdline_fixed_string_t rx;
6242         cmdline_fixed_string_t rx_pfc_mode;
6243         cmdline_fixed_string_t tx;
6244         cmdline_fixed_string_t tx_pfc_mode;
6245         uint32_t high_water;
6246         uint32_t low_water;
6247         uint16_t pause_time;
6248         uint8_t  priority;
6249         portid_t port_id;
6250 };
6251
6252 static void
6253 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6254                        __attribute__((unused)) struct cmdline *cl,
6255                        __attribute__((unused)) void *data)
6256 {
6257         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6258         struct rte_eth_pfc_conf pfc_conf;
6259         int rx_fc_enable, tx_fc_enable;
6260         int ret;
6261
6262         /*
6263          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6264          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6265          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6266          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6267          */
6268         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6269                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6270         };
6271
6272         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6273         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6274         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6275         pfc_conf.fc.high_water = res->high_water;
6276         pfc_conf.fc.low_water  = res->low_water;
6277         pfc_conf.fc.pause_time = res->pause_time;
6278         pfc_conf.priority      = res->priority;
6279
6280         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6281         if (ret != 0)
6282                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6283 }
6284
6285 cmdline_parse_token_string_t cmd_pfc_set_set =
6286         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6287                                 set, "set");
6288 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6289         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6290                                 pfc_ctrl, "pfc_ctrl");
6291 cmdline_parse_token_string_t cmd_pfc_set_rx =
6292         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6293                                 rx, "rx");
6294 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6295         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6296                                 rx_pfc_mode, "on#off");
6297 cmdline_parse_token_string_t cmd_pfc_set_tx =
6298         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6299                                 tx, "tx");
6300 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6301         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6302                                 tx_pfc_mode, "on#off");
6303 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6304         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6305                                 high_water, UINT32);
6306 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6307         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6308                                 low_water, UINT32);
6309 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6310         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6311                                 pause_time, UINT16);
6312 cmdline_parse_token_num_t cmd_pfc_set_priority =
6313         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6314                                 priority, UINT8);
6315 cmdline_parse_token_num_t cmd_pfc_set_portid =
6316         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6317                                 port_id, UINT16);
6318
6319 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6320         .f = cmd_priority_flow_ctrl_set_parsed,
6321         .data = NULL,
6322         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6323                 "<pause_time> <priority> <port_id>: "
6324                 "Configure the Ethernet priority flow control",
6325         .tokens = {
6326                 (void *)&cmd_pfc_set_set,
6327                 (void *)&cmd_pfc_set_flow_ctrl,
6328                 (void *)&cmd_pfc_set_rx,
6329                 (void *)&cmd_pfc_set_rx_mode,
6330                 (void *)&cmd_pfc_set_tx,
6331                 (void *)&cmd_pfc_set_tx_mode,
6332                 (void *)&cmd_pfc_set_high_water,
6333                 (void *)&cmd_pfc_set_low_water,
6334                 (void *)&cmd_pfc_set_pause_time,
6335                 (void *)&cmd_pfc_set_priority,
6336                 (void *)&cmd_pfc_set_portid,
6337                 NULL,
6338         },
6339 };
6340
6341 /* *** RESET CONFIGURATION *** */
6342 struct cmd_reset_result {
6343         cmdline_fixed_string_t reset;
6344         cmdline_fixed_string_t def;
6345 };
6346
6347 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6348                              struct cmdline *cl,
6349                              __attribute__((unused)) void *data)
6350 {
6351         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6352         set_def_fwd_config();
6353 }
6354
6355 cmdline_parse_token_string_t cmd_reset_set =
6356         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6357 cmdline_parse_token_string_t cmd_reset_def =
6358         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6359                                  "default");
6360
6361 cmdline_parse_inst_t cmd_reset = {
6362         .f = cmd_reset_parsed,
6363         .data = NULL,
6364         .help_str = "set default: Reset default forwarding configuration",
6365         .tokens = {
6366                 (void *)&cmd_reset_set,
6367                 (void *)&cmd_reset_def,
6368                 NULL,
6369         },
6370 };
6371
6372 /* *** START FORWARDING *** */
6373 struct cmd_start_result {
6374         cmdline_fixed_string_t start;
6375 };
6376
6377 cmdline_parse_token_string_t cmd_start_start =
6378         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6379
6380 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6381                              __attribute__((unused)) struct cmdline *cl,
6382                              __attribute__((unused)) void *data)
6383 {
6384         start_packet_forwarding(0);
6385 }
6386
6387 cmdline_parse_inst_t cmd_start = {
6388         .f = cmd_start_parsed,
6389         .data = NULL,
6390         .help_str = "start: Start packet forwarding",
6391         .tokens = {
6392                 (void *)&cmd_start_start,
6393                 NULL,
6394         },
6395 };
6396
6397 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6398 struct cmd_start_tx_first_result {
6399         cmdline_fixed_string_t start;
6400         cmdline_fixed_string_t tx_first;
6401 };
6402
6403 static void
6404 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6405                           __attribute__((unused)) struct cmdline *cl,
6406                           __attribute__((unused)) void *data)
6407 {
6408         start_packet_forwarding(1);
6409 }
6410
6411 cmdline_parse_token_string_t cmd_start_tx_first_start =
6412         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6413                                  "start");
6414 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6415         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6416                                  tx_first, "tx_first");
6417
6418 cmdline_parse_inst_t cmd_start_tx_first = {
6419         .f = cmd_start_tx_first_parsed,
6420         .data = NULL,
6421         .help_str = "start tx_first: Start packet forwarding, "
6422                 "after sending 1 burst of packets",
6423         .tokens = {
6424                 (void *)&cmd_start_tx_first_start,
6425                 (void *)&cmd_start_tx_first_tx_first,
6426                 NULL,
6427         },
6428 };
6429
6430 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6431 struct cmd_start_tx_first_n_result {
6432         cmdline_fixed_string_t start;
6433         cmdline_fixed_string_t tx_first;
6434         uint32_t tx_num;
6435 };
6436
6437 static void
6438 cmd_start_tx_first_n_parsed(void *parsed_result,
6439                           __attribute__((unused)) struct cmdline *cl,
6440                           __attribute__((unused)) void *data)
6441 {
6442         struct cmd_start_tx_first_n_result *res = parsed_result;
6443
6444         start_packet_forwarding(res->tx_num);
6445 }
6446
6447 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6448         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6449                         start, "start");
6450 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6451         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6452                         tx_first, "tx_first");
6453 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6454         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6455                         tx_num, UINT32);
6456
6457 cmdline_parse_inst_t cmd_start_tx_first_n = {
6458         .f = cmd_start_tx_first_n_parsed,
6459         .data = NULL,
6460         .help_str = "start tx_first <num>: "
6461                 "packet forwarding, after sending <num> bursts of packets",
6462         .tokens = {
6463                 (void *)&cmd_start_tx_first_n_start,
6464                 (void *)&cmd_start_tx_first_n_tx_first,
6465                 (void *)&cmd_start_tx_first_n_tx_num,
6466                 NULL,
6467         },
6468 };
6469
6470 /* *** SET LINK UP *** */
6471 struct cmd_set_link_up_result {
6472         cmdline_fixed_string_t set;
6473         cmdline_fixed_string_t link_up;
6474         cmdline_fixed_string_t port;
6475         portid_t port_id;
6476 };
6477
6478 cmdline_parse_token_string_t cmd_set_link_up_set =
6479         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6480 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6482                                 "link-up");
6483 cmdline_parse_token_string_t cmd_set_link_up_port =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6485 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6486         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6487
6488 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6489                              __attribute__((unused)) struct cmdline *cl,
6490                              __attribute__((unused)) void *data)
6491 {
6492         struct cmd_set_link_up_result *res = parsed_result;
6493         dev_set_link_up(res->port_id);
6494 }
6495
6496 cmdline_parse_inst_t cmd_set_link_up = {
6497         .f = cmd_set_link_up_parsed,
6498         .data = NULL,
6499         .help_str = "set link-up port <port id>",
6500         .tokens = {
6501                 (void *)&cmd_set_link_up_set,
6502                 (void *)&cmd_set_link_up_link_up,
6503                 (void *)&cmd_set_link_up_port,
6504                 (void *)&cmd_set_link_up_port_id,
6505                 NULL,
6506         },
6507 };
6508
6509 /* *** SET LINK DOWN *** */
6510 struct cmd_set_link_down_result {
6511         cmdline_fixed_string_t set;
6512         cmdline_fixed_string_t link_down;
6513         cmdline_fixed_string_t port;
6514         portid_t port_id;
6515 };
6516
6517 cmdline_parse_token_string_t cmd_set_link_down_set =
6518         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6519 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6520         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6521                                 "link-down");
6522 cmdline_parse_token_string_t cmd_set_link_down_port =
6523         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6524 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6525         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6526
6527 static void cmd_set_link_down_parsed(
6528                                 __attribute__((unused)) void *parsed_result,
6529                                 __attribute__((unused)) struct cmdline *cl,
6530                                 __attribute__((unused)) void *data)
6531 {
6532         struct cmd_set_link_down_result *res = parsed_result;
6533         dev_set_link_down(res->port_id);
6534 }
6535
6536 cmdline_parse_inst_t cmd_set_link_down = {
6537         .f = cmd_set_link_down_parsed,
6538         .data = NULL,
6539         .help_str = "set link-down port <port id>",
6540         .tokens = {
6541                 (void *)&cmd_set_link_down_set,
6542                 (void *)&cmd_set_link_down_link_down,
6543                 (void *)&cmd_set_link_down_port,
6544                 (void *)&cmd_set_link_down_port_id,
6545                 NULL,
6546         },
6547 };
6548
6549 /* *** SHOW CFG *** */
6550 struct cmd_showcfg_result {
6551         cmdline_fixed_string_t show;
6552         cmdline_fixed_string_t cfg;
6553         cmdline_fixed_string_t what;
6554 };
6555
6556 static void cmd_showcfg_parsed(void *parsed_result,
6557                                __attribute__((unused)) struct cmdline *cl,
6558                                __attribute__((unused)) void *data)
6559 {
6560         struct cmd_showcfg_result *res = parsed_result;
6561         if (!strcmp(res->what, "rxtx"))
6562                 rxtx_config_display();
6563         else if (!strcmp(res->what, "cores"))
6564                 fwd_lcores_config_display();
6565         else if (!strcmp(res->what, "fwd"))
6566                 pkt_fwd_config_display(&cur_fwd_config);
6567         else if (!strcmp(res->what, "txpkts"))
6568                 show_tx_pkt_segments();
6569 }
6570
6571 cmdline_parse_token_string_t cmd_showcfg_show =
6572         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6573 cmdline_parse_token_string_t cmd_showcfg_port =
6574         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6575 cmdline_parse_token_string_t cmd_showcfg_what =
6576         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6577                                  "rxtx#cores#fwd#txpkts");
6578
6579 cmdline_parse_inst_t cmd_showcfg = {
6580         .f = cmd_showcfg_parsed,
6581         .data = NULL,
6582         .help_str = "show config rxtx|cores|fwd|txpkts",
6583         .tokens = {
6584                 (void *)&cmd_showcfg_show,
6585                 (void *)&cmd_showcfg_port,
6586                 (void *)&cmd_showcfg_what,
6587                 NULL,
6588         },
6589 };
6590
6591 /* *** SHOW ALL PORT INFO *** */
6592 struct cmd_showportall_result {
6593         cmdline_fixed_string_t show;
6594         cmdline_fixed_string_t port;
6595         cmdline_fixed_string_t what;
6596         cmdline_fixed_string_t all;
6597 };
6598
6599 static void cmd_showportall_parsed(void *parsed_result,
6600                                 __attribute__((unused)) struct cmdline *cl,
6601                                 __attribute__((unused)) void *data)
6602 {
6603         portid_t i;
6604
6605         struct cmd_showportall_result *res = parsed_result;
6606         if (!strcmp(res->show, "clear")) {
6607                 if (!strcmp(res->what, "stats"))
6608                         RTE_ETH_FOREACH_DEV(i)
6609                                 nic_stats_clear(i);
6610                 else if (!strcmp(res->what, "xstats"))
6611                         RTE_ETH_FOREACH_DEV(i)
6612                                 nic_xstats_clear(i);
6613         } else if (!strcmp(res->what, "info"))
6614                 RTE_ETH_FOREACH_DEV(i)
6615                         port_infos_display(i);
6616         else if (!strcmp(res->what, "stats"))
6617                 RTE_ETH_FOREACH_DEV(i)
6618                         nic_stats_display(i);
6619         else if (!strcmp(res->what, "xstats"))
6620                 RTE_ETH_FOREACH_DEV(i)
6621                         nic_xstats_display(i);
6622         else if (!strcmp(res->what, "fdir"))
6623                 RTE_ETH_FOREACH_DEV(i)
6624                         fdir_get_infos(i);
6625         else if (!strcmp(res->what, "stat_qmap"))
6626                 RTE_ETH_FOREACH_DEV(i)
6627                         nic_stats_mapping_display(i);
6628         else if (!strcmp(res->what, "dcb_tc"))
6629                 RTE_ETH_FOREACH_DEV(i)
6630                         port_dcb_info_display(i);
6631         else if (!strcmp(res->what, "cap"))
6632                 RTE_ETH_FOREACH_DEV(i)
6633                         port_offload_cap_display(i);
6634 }
6635
6636 cmdline_parse_token_string_t cmd_showportall_show =
6637         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6638                                  "show#clear");
6639 cmdline_parse_token_string_t cmd_showportall_port =
6640         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6641 cmdline_parse_token_string_t cmd_showportall_what =
6642         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6643                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6644 cmdline_parse_token_string_t cmd_showportall_all =
6645         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6646 cmdline_parse_inst_t cmd_showportall = {
6647         .f = cmd_showportall_parsed,
6648         .data = NULL,
6649         .help_str = "show|clear port "
6650                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6651         .tokens = {
6652                 (void *)&cmd_showportall_show,
6653                 (void *)&cmd_showportall_port,
6654                 (void *)&cmd_showportall_what,
6655                 (void *)&cmd_showportall_all,
6656                 NULL,
6657         },
6658 };
6659
6660 /* *** SHOW PORT INFO *** */
6661 struct cmd_showport_result {
6662         cmdline_fixed_string_t show;
6663         cmdline_fixed_string_t port;
6664         cmdline_fixed_string_t what;
6665         uint16_t portnum;
6666 };
6667
6668 static void cmd_showport_parsed(void *parsed_result,
6669                                 __attribute__((unused)) struct cmdline *cl,
6670                                 __attribute__((unused)) void *data)
6671 {
6672         struct cmd_showport_result *res = parsed_result;
6673         if (!strcmp(res->show, "clear")) {
6674                 if (!strcmp(res->what, "stats"))
6675                         nic_stats_clear(res->portnum);
6676                 else if (!strcmp(res->what, "xstats"))
6677                         nic_xstats_clear(res->portnum);
6678         } else if (!strcmp(res->what, "info"))
6679                 port_infos_display(res->portnum);
6680         else if (!strcmp(res->what, "stats"))
6681                 nic_stats_display(res->portnum);
6682         else if (!strcmp(res->what, "xstats"))
6683                 nic_xstats_display(res->portnum);
6684         else if (!strcmp(res->what, "fdir"))
6685                  fdir_get_infos(res->portnum);
6686         else if (!strcmp(res->what, "stat_qmap"))
6687                 nic_stats_mapping_display(res->portnum);
6688         else if (!strcmp(res->what, "dcb_tc"))
6689                 port_dcb_info_display(res->portnum);
6690         else if (!strcmp(res->what, "cap"))
6691                 port_offload_cap_display(res->portnum);
6692 }
6693
6694 cmdline_parse_token_string_t cmd_showport_show =
6695         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6696                                  "show#clear");
6697 cmdline_parse_token_string_t cmd_showport_port =
6698         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6699 cmdline_parse_token_string_t cmd_showport_what =
6700         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6701                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6702 cmdline_parse_token_num_t cmd_showport_portnum =
6703         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6704
6705 cmdline_parse_inst_t cmd_showport = {
6706         .f = cmd_showport_parsed,
6707         .data = NULL,
6708         .help_str = "show|clear port "
6709                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6710                 "<port_id>",
6711         .tokens = {
6712                 (void *)&cmd_showport_show,
6713                 (void *)&cmd_showport_port,
6714                 (void *)&cmd_showport_what,
6715                 (void *)&cmd_showport_portnum,
6716                 NULL,
6717         },
6718 };
6719
6720 /* *** SHOW QUEUE INFO *** */
6721 struct cmd_showqueue_result {
6722         cmdline_fixed_string_t show;
6723         cmdline_fixed_string_t type;
6724         cmdline_fixed_string_t what;
6725         uint16_t portnum;
6726         uint16_t queuenum;
6727 };
6728
6729 static void
6730 cmd_showqueue_parsed(void *parsed_result,
6731         __attribute__((unused)) struct cmdline *cl,
6732         __attribute__((unused)) void *data)
6733 {
6734         struct cmd_showqueue_result *res = parsed_result;
6735
6736         if (!strcmp(res->type, "rxq"))
6737                 rx_queue_infos_display(res->portnum, res->queuenum);
6738         else if (!strcmp(res->type, "txq"))
6739                 tx_queue_infos_display(res->portnum, res->queuenum);
6740 }
6741
6742 cmdline_parse_token_string_t cmd_showqueue_show =
6743         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6744 cmdline_parse_token_string_t cmd_showqueue_type =
6745         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6746 cmdline_parse_token_string_t cmd_showqueue_what =
6747         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6748 cmdline_parse_token_num_t cmd_showqueue_portnum =
6749         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6750 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6751         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6752
6753 cmdline_parse_inst_t cmd_showqueue = {
6754         .f = cmd_showqueue_parsed,
6755         .data = NULL,
6756         .help_str = "show rxq|txq info <port_id> <queue_id>",
6757         .tokens = {
6758                 (void *)&cmd_showqueue_show,
6759                 (void *)&cmd_showqueue_type,
6760                 (void *)&cmd_showqueue_what,
6761                 (void *)&cmd_showqueue_portnum,
6762                 (void *)&cmd_showqueue_queuenum,
6763                 NULL,
6764         },
6765 };
6766
6767 /* *** READ PORT REGISTER *** */
6768 struct cmd_read_reg_result {
6769         cmdline_fixed_string_t read;
6770         cmdline_fixed_string_t reg;
6771         portid_t port_id;
6772         uint32_t reg_off;
6773 };
6774
6775 static void
6776 cmd_read_reg_parsed(void *parsed_result,
6777                     __attribute__((unused)) struct cmdline *cl,
6778                     __attribute__((unused)) void *data)
6779 {
6780         struct cmd_read_reg_result *res = parsed_result;
6781         port_reg_display(res->port_id, res->reg_off);
6782 }
6783
6784 cmdline_parse_token_string_t cmd_read_reg_read =
6785         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6786 cmdline_parse_token_string_t cmd_read_reg_reg =
6787         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6788 cmdline_parse_token_num_t cmd_read_reg_port_id =
6789         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6790 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6791         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6792
6793 cmdline_parse_inst_t cmd_read_reg = {
6794         .f = cmd_read_reg_parsed,
6795         .data = NULL,
6796         .help_str = "read reg <port_id> <reg_off>",
6797         .tokens = {
6798                 (void *)&cmd_read_reg_read,
6799                 (void *)&cmd_read_reg_reg,
6800                 (void *)&cmd_read_reg_port_id,
6801                 (void *)&cmd_read_reg_reg_off,
6802                 NULL,
6803         },
6804 };
6805
6806 /* *** READ PORT REGISTER BIT FIELD *** */
6807 struct cmd_read_reg_bit_field_result {
6808         cmdline_fixed_string_t read;
6809         cmdline_fixed_string_t regfield;
6810         portid_t port_id;
6811         uint32_t reg_off;
6812         uint8_t bit1_pos;
6813         uint8_t bit2_pos;
6814 };
6815
6816 static void
6817 cmd_read_reg_bit_field_parsed(void *parsed_result,
6818                               __attribute__((unused)) struct cmdline *cl,
6819                               __attribute__((unused)) void *data)
6820 {
6821         struct cmd_read_reg_bit_field_result *res = parsed_result;
6822         port_reg_bit_field_display(res->port_id, res->reg_off,
6823                                    res->bit1_pos, res->bit2_pos);
6824 }
6825
6826 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6827         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6828                                  "read");
6829 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6830         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6831                                  regfield, "regfield");
6832 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6833         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6834                               UINT16);
6835 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6836         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6837                               UINT32);
6838 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6839         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6840                               UINT8);
6841 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6842         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6843                               UINT8);
6844
6845 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6846         .f = cmd_read_reg_bit_field_parsed,
6847         .data = NULL,
6848         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6849         "Read register bit field between bit_x and bit_y included",
6850         .tokens = {
6851                 (void *)&cmd_read_reg_bit_field_read,
6852                 (void *)&cmd_read_reg_bit_field_regfield,
6853                 (void *)&cmd_read_reg_bit_field_port_id,
6854                 (void *)&cmd_read_reg_bit_field_reg_off,
6855                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6856                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6857                 NULL,
6858         },
6859 };
6860
6861 /* *** READ PORT REGISTER BIT *** */
6862 struct cmd_read_reg_bit_result {
6863         cmdline_fixed_string_t read;
6864         cmdline_fixed_string_t regbit;
6865         portid_t port_id;
6866         uint32_t reg_off;
6867         uint8_t bit_pos;
6868 };
6869
6870 static void
6871 cmd_read_reg_bit_parsed(void *parsed_result,
6872                         __attribute__((unused)) struct cmdline *cl,
6873                         __attribute__((unused)) void *data)
6874 {
6875         struct cmd_read_reg_bit_result *res = parsed_result;
6876         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6877 }
6878
6879 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6880         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6881 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6882         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6883                                  regbit, "regbit");
6884 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6885         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6886 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6887         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6888 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6889         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6890
6891 cmdline_parse_inst_t cmd_read_reg_bit = {
6892         .f = cmd_read_reg_bit_parsed,
6893         .data = NULL,
6894         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6895         .tokens = {
6896                 (void *)&cmd_read_reg_bit_read,
6897                 (void *)&cmd_read_reg_bit_regbit,
6898                 (void *)&cmd_read_reg_bit_port_id,
6899                 (void *)&cmd_read_reg_bit_reg_off,
6900                 (void *)&cmd_read_reg_bit_bit_pos,
6901                 NULL,
6902         },
6903 };
6904
6905 /* *** WRITE PORT REGISTER *** */
6906 struct cmd_write_reg_result {
6907         cmdline_fixed_string_t write;
6908         cmdline_fixed_string_t reg;
6909         portid_t port_id;
6910         uint32_t reg_off;
6911         uint32_t value;
6912 };
6913
6914 static void
6915 cmd_write_reg_parsed(void *parsed_result,
6916                      __attribute__((unused)) struct cmdline *cl,
6917                      __attribute__((unused)) void *data)
6918 {
6919         struct cmd_write_reg_result *res = parsed_result;
6920         port_reg_set(res->port_id, res->reg_off, res->value);
6921 }
6922
6923 cmdline_parse_token_string_t cmd_write_reg_write =
6924         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6925 cmdline_parse_token_string_t cmd_write_reg_reg =
6926         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6927 cmdline_parse_token_num_t cmd_write_reg_port_id =
6928         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6929 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6930         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6931 cmdline_parse_token_num_t cmd_write_reg_value =
6932         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6933
6934 cmdline_parse_inst_t cmd_write_reg = {
6935         .f = cmd_write_reg_parsed,
6936         .data = NULL,
6937         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6938         .tokens = {
6939                 (void *)&cmd_write_reg_write,
6940                 (void *)&cmd_write_reg_reg,
6941                 (void *)&cmd_write_reg_port_id,
6942                 (void *)&cmd_write_reg_reg_off,
6943                 (void *)&cmd_write_reg_value,
6944                 NULL,
6945         },
6946 };
6947
6948 /* *** WRITE PORT REGISTER BIT FIELD *** */
6949 struct cmd_write_reg_bit_field_result {
6950         cmdline_fixed_string_t write;
6951         cmdline_fixed_string_t regfield;
6952         portid_t port_id;
6953         uint32_t reg_off;
6954         uint8_t bit1_pos;
6955         uint8_t bit2_pos;
6956         uint32_t value;
6957 };
6958
6959 static void
6960 cmd_write_reg_bit_field_parsed(void *parsed_result,
6961                                __attribute__((unused)) struct cmdline *cl,
6962                                __attribute__((unused)) void *data)
6963 {
6964         struct cmd_write_reg_bit_field_result *res = parsed_result;
6965         port_reg_bit_field_set(res->port_id, res->reg_off,
6966                           res->bit1_pos, res->bit2_pos, res->value);
6967 }
6968
6969 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6970         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6971                                  "write");
6972 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6973         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6974                                  regfield, "regfield");
6975 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6977                               UINT16);
6978 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6979         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6980                               UINT32);
6981 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6982         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6983                               UINT8);
6984 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6985         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6986                               UINT8);
6987 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6988         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6989                               UINT32);
6990
6991 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6992         .f = cmd_write_reg_bit_field_parsed,
6993         .data = NULL,
6994         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6995                 "<reg_value>: "
6996                 "Set register bit field between bit_x and bit_y included",
6997         .tokens = {
6998                 (void *)&cmd_write_reg_bit_field_write,
6999                 (void *)&cmd_write_reg_bit_field_regfield,
7000                 (void *)&cmd_write_reg_bit_field_port_id,
7001                 (void *)&cmd_write_reg_bit_field_reg_off,
7002                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7003                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7004                 (void *)&cmd_write_reg_bit_field_value,
7005                 NULL,
7006         },
7007 };
7008
7009 /* *** WRITE PORT REGISTER BIT *** */
7010 struct cmd_write_reg_bit_result {
7011         cmdline_fixed_string_t write;
7012         cmdline_fixed_string_t regbit;
7013         portid_t port_id;
7014         uint32_t reg_off;
7015         uint8_t bit_pos;
7016         uint8_t value;
7017 };
7018
7019 static void
7020 cmd_write_reg_bit_parsed(void *parsed_result,
7021                          __attribute__((unused)) struct cmdline *cl,
7022                          __attribute__((unused)) void *data)
7023 {
7024         struct cmd_write_reg_bit_result *res = parsed_result;
7025         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7026 }
7027
7028 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7029         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7030                                  "write");
7031 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7032         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7033                                  regbit, "regbit");
7034 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7035         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7036 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7037         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7038 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7039         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7040 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7041         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7042
7043 cmdline_parse_inst_t cmd_write_reg_bit = {
7044         .f = cmd_write_reg_bit_parsed,
7045         .data = NULL,
7046         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7047                 "0 <= bit_x <= 31",
7048         .tokens = {
7049                 (void *)&cmd_write_reg_bit_write,
7050                 (void *)&cmd_write_reg_bit_regbit,
7051                 (void *)&cmd_write_reg_bit_port_id,
7052                 (void *)&cmd_write_reg_bit_reg_off,
7053                 (void *)&cmd_write_reg_bit_bit_pos,
7054                 (void *)&cmd_write_reg_bit_value,
7055                 NULL,
7056         },
7057 };
7058
7059 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7060 struct cmd_read_rxd_txd_result {
7061         cmdline_fixed_string_t read;
7062         cmdline_fixed_string_t rxd_txd;
7063         portid_t port_id;
7064         uint16_t queue_id;
7065         uint16_t desc_id;
7066 };
7067
7068 static void
7069 cmd_read_rxd_txd_parsed(void *parsed_result,
7070                         __attribute__((unused)) struct cmdline *cl,
7071                         __attribute__((unused)) void *data)
7072 {
7073         struct cmd_read_rxd_txd_result *res = parsed_result;
7074
7075         if (!strcmp(res->rxd_txd, "rxd"))
7076                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7077         else if (!strcmp(res->rxd_txd, "txd"))
7078                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7079 }
7080
7081 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7082         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7083 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7084         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7085                                  "rxd#txd");
7086 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7087         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7088 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7089         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7090 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7091         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7092
7093 cmdline_parse_inst_t cmd_read_rxd_txd = {
7094         .f = cmd_read_rxd_txd_parsed,
7095         .data = NULL,
7096         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7097         .tokens = {
7098                 (void *)&cmd_read_rxd_txd_read,
7099                 (void *)&cmd_read_rxd_txd_rxd_txd,
7100                 (void *)&cmd_read_rxd_txd_port_id,
7101                 (void *)&cmd_read_rxd_txd_queue_id,
7102                 (void *)&cmd_read_rxd_txd_desc_id,
7103                 NULL,
7104         },
7105 };
7106
7107 /* *** QUIT *** */
7108 struct cmd_quit_result {
7109         cmdline_fixed_string_t quit;
7110 };
7111
7112 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7113                             struct cmdline *cl,
7114                             __attribute__((unused)) void *data)
7115 {
7116         pmd_test_exit();
7117         cmdline_quit(cl);
7118 }
7119
7120 cmdline_parse_token_string_t cmd_quit_quit =
7121         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7122
7123 cmdline_parse_inst_t cmd_quit = {
7124         .f = cmd_quit_parsed,
7125         .data = NULL,
7126         .help_str = "quit: Exit application",
7127         .tokens = {
7128                 (void *)&cmd_quit_quit,
7129                 NULL,
7130         },
7131 };
7132
7133 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7134 struct cmd_mac_addr_result {
7135         cmdline_fixed_string_t mac_addr_cmd;
7136         cmdline_fixed_string_t what;
7137         uint16_t port_num;
7138         struct ether_addr address;
7139 };
7140
7141 static void cmd_mac_addr_parsed(void *parsed_result,
7142                 __attribute__((unused)) struct cmdline *cl,
7143                 __attribute__((unused)) void *data)
7144 {
7145         struct cmd_mac_addr_result *res = parsed_result;
7146         int ret;
7147
7148         if (strcmp(res->what, "add") == 0)
7149                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7150         else if (strcmp(res->what, "set") == 0)
7151                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7152                                                        &res->address);
7153         else
7154                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7155
7156         /* check the return value and print it if is < 0 */
7157         if(ret < 0)
7158                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7159
7160 }
7161
7162 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7163         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7164                                 "mac_addr");
7165 cmdline_parse_token_string_t cmd_mac_addr_what =
7166         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7167                                 "add#remove#set");
7168 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7169                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7170                                         UINT16);
7171 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7172                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7173
7174 cmdline_parse_inst_t cmd_mac_addr = {
7175         .f = cmd_mac_addr_parsed,
7176         .data = (void *)0,
7177         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7178                         "Add/Remove/Set MAC address on port_id",
7179         .tokens = {
7180                 (void *)&cmd_mac_addr_cmd,
7181                 (void *)&cmd_mac_addr_what,
7182                 (void *)&cmd_mac_addr_portnum,
7183                 (void *)&cmd_mac_addr_addr,
7184                 NULL,
7185         },
7186 };
7187
7188 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7189 struct cmd_eth_peer_result {
7190         cmdline_fixed_string_t set;
7191         cmdline_fixed_string_t eth_peer;
7192         portid_t port_id;
7193         cmdline_fixed_string_t peer_addr;
7194 };
7195
7196 static void cmd_set_eth_peer_parsed(void *parsed_result,
7197                         __attribute__((unused)) struct cmdline *cl,
7198                         __attribute__((unused)) void *data)
7199 {
7200                 struct cmd_eth_peer_result *res = parsed_result;
7201
7202                 if (test_done == 0) {
7203                         printf("Please stop forwarding first\n");
7204                         return;
7205                 }
7206                 if (!strcmp(res->eth_peer, "eth-peer")) {
7207                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7208                         fwd_config_setup();
7209                 }
7210 }
7211 cmdline_parse_token_string_t cmd_eth_peer_set =
7212         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7213 cmdline_parse_token_string_t cmd_eth_peer =
7214         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7215 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7216         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7217 cmdline_parse_token_string_t cmd_eth_peer_addr =
7218         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7219
7220 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7221         .f = cmd_set_eth_peer_parsed,
7222         .data = NULL,
7223         .help_str = "set eth-peer <port_id> <peer_mac>",
7224         .tokens = {
7225                 (void *)&cmd_eth_peer_set,
7226                 (void *)&cmd_eth_peer,
7227                 (void *)&cmd_eth_peer_port_id,
7228                 (void *)&cmd_eth_peer_addr,
7229                 NULL,
7230         },
7231 };
7232
7233 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7234 struct cmd_set_qmap_result {
7235         cmdline_fixed_string_t set;
7236         cmdline_fixed_string_t qmap;
7237         cmdline_fixed_string_t what;
7238         portid_t port_id;
7239         uint16_t queue_id;
7240         uint8_t map_value;
7241 };
7242
7243 static void
7244 cmd_set_qmap_parsed(void *parsed_result,
7245                        __attribute__((unused)) struct cmdline *cl,
7246                        __attribute__((unused)) void *data)
7247 {
7248         struct cmd_set_qmap_result *res = parsed_result;
7249         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7250
7251         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7252 }
7253
7254 cmdline_parse_token_string_t cmd_setqmap_set =
7255         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7256                                  set, "set");
7257 cmdline_parse_token_string_t cmd_setqmap_qmap =
7258         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7259                                  qmap, "stat_qmap");
7260 cmdline_parse_token_string_t cmd_setqmap_what =
7261         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7262                                  what, "tx#rx");
7263 cmdline_parse_token_num_t cmd_setqmap_portid =
7264         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7265                               port_id, UINT16);
7266 cmdline_parse_token_num_t cmd_setqmap_queueid =
7267         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7268                               queue_id, UINT16);
7269 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7270         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7271                               map_value, UINT8);
7272
7273 cmdline_parse_inst_t cmd_set_qmap = {
7274         .f = cmd_set_qmap_parsed,
7275         .data = NULL,
7276         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7277                 "Set statistics mapping value on tx|rx queue_id of port_id",
7278         .tokens = {
7279                 (void *)&cmd_setqmap_set,
7280                 (void *)&cmd_setqmap_qmap,
7281                 (void *)&cmd_setqmap_what,
7282                 (void *)&cmd_setqmap_portid,
7283                 (void *)&cmd_setqmap_queueid,
7284                 (void *)&cmd_setqmap_mapvalue,
7285                 NULL,
7286         },
7287 };
7288
7289 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7290 struct cmd_set_xstats_hide_zero_result {
7291         cmdline_fixed_string_t keyword;
7292         cmdline_fixed_string_t name;
7293         cmdline_fixed_string_t on_off;
7294 };
7295
7296 static void
7297 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7298                         __attribute__((unused)) struct cmdline *cl,
7299                         __attribute__((unused)) void *data)
7300 {
7301         struct cmd_set_xstats_hide_zero_result *res;
7302         uint16_t on_off = 0;
7303
7304         res = parsed_result;
7305         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7306         set_xstats_hide_zero(on_off);
7307 }
7308
7309 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7310         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7311                                  keyword, "set");
7312 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7313         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7314                                  name, "xstats-hide-zero");
7315 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7316         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7317                                  on_off, "on#off");
7318
7319 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7320         .f = cmd_set_xstats_hide_zero_parsed,
7321         .data = NULL,
7322         .help_str = "set xstats-hide-zero on|off",
7323         .tokens = {
7324                 (void *)&cmd_set_xstats_hide_zero_keyword,
7325                 (void *)&cmd_set_xstats_hide_zero_name,
7326                 (void *)&cmd_set_xstats_hide_zero_on_off,
7327                 NULL,
7328         },
7329 };
7330
7331 /* *** CONFIGURE UNICAST HASH TABLE *** */
7332 struct cmd_set_uc_hash_table {
7333         cmdline_fixed_string_t set;
7334         cmdline_fixed_string_t port;
7335         portid_t port_id;
7336         cmdline_fixed_string_t what;
7337         struct ether_addr address;
7338         cmdline_fixed_string_t mode;
7339 };
7340
7341 static void
7342 cmd_set_uc_hash_parsed(void *parsed_result,
7343                        __attribute__((unused)) struct cmdline *cl,
7344                        __attribute__((unused)) void *data)
7345 {
7346         int ret=0;
7347         struct cmd_set_uc_hash_table *res = parsed_result;
7348
7349         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7350
7351         if (strcmp(res->what, "uta") == 0)
7352                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7353                                                 &res->address,(uint8_t)is_on);
7354         if (ret < 0)
7355                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7356
7357 }
7358
7359 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7360         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7361                                  set, "set");
7362 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7363         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7364                                  port, "port");
7365 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7366         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7367                               port_id, UINT16);
7368 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7369         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7370                                  what, "uta");
7371 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7372         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7373                                 address);
7374 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7375         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7376                                  mode, "on#off");
7377
7378 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7379         .f = cmd_set_uc_hash_parsed,
7380         .data = NULL,
7381         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7382         .tokens = {
7383                 (void *)&cmd_set_uc_hash_set,
7384                 (void *)&cmd_set_uc_hash_port,
7385                 (void *)&cmd_set_uc_hash_portid,
7386                 (void *)&cmd_set_uc_hash_what,
7387                 (void *)&cmd_set_uc_hash_mac,
7388                 (void *)&cmd_set_uc_hash_mode,
7389                 NULL,
7390         },
7391 };
7392
7393 struct cmd_set_uc_all_hash_table {
7394         cmdline_fixed_string_t set;
7395         cmdline_fixed_string_t port;
7396         portid_t port_id;
7397         cmdline_fixed_string_t what;
7398         cmdline_fixed_string_t value;
7399         cmdline_fixed_string_t mode;
7400 };
7401
7402 static void
7403 cmd_set_uc_all_hash_parsed(void *parsed_result,
7404                        __attribute__((unused)) struct cmdline *cl,
7405                        __attribute__((unused)) void *data)
7406 {
7407         int ret=0;
7408         struct cmd_set_uc_all_hash_table *res = parsed_result;
7409
7410         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7411
7412         if ((strcmp(res->what, "uta") == 0) &&
7413                 (strcmp(res->value, "all") == 0))
7414                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7415         if (ret < 0)
7416                 printf("bad unicast hash table parameter,"
7417                         "return code = %d \n", ret);
7418 }
7419
7420 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7421         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7422                                  set, "set");
7423 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7424         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7425                                  port, "port");
7426 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7427         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7428                               port_id, UINT16);
7429 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7431                                  what, "uta");
7432 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7433         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7434                                 value,"all");
7435 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7437                                  mode, "on#off");
7438
7439 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7440         .f = cmd_set_uc_all_hash_parsed,
7441         .data = NULL,
7442         .help_str = "set port <port_id> uta all on|off",
7443         .tokens = {
7444                 (void *)&cmd_set_uc_all_hash_set,
7445                 (void *)&cmd_set_uc_all_hash_port,
7446                 (void *)&cmd_set_uc_all_hash_portid,
7447                 (void *)&cmd_set_uc_all_hash_what,
7448                 (void *)&cmd_set_uc_all_hash_value,
7449                 (void *)&cmd_set_uc_all_hash_mode,
7450                 NULL,
7451         },
7452 };
7453
7454 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7455 struct cmd_set_vf_macvlan_filter {
7456         cmdline_fixed_string_t set;
7457         cmdline_fixed_string_t port;
7458         portid_t port_id;
7459         cmdline_fixed_string_t vf;
7460         uint8_t vf_id;
7461         struct ether_addr address;
7462         cmdline_fixed_string_t filter_type;
7463         cmdline_fixed_string_t mode;
7464 };
7465
7466 static void
7467 cmd_set_vf_macvlan_parsed(void *parsed_result,
7468                        __attribute__((unused)) struct cmdline *cl,
7469                        __attribute__((unused)) void *data)
7470 {
7471         int is_on, ret = 0;
7472         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7473         struct rte_eth_mac_filter filter;
7474
7475         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7476
7477         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7478
7479         /* set VF MAC filter */
7480         filter.is_vf = 1;
7481
7482         /* set VF ID */
7483         filter.dst_id = res->vf_id;
7484
7485         if (!strcmp(res->filter_type, "exact-mac"))
7486                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7487         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7488                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7489         else if (!strcmp(res->filter_type, "hashmac"))
7490                 filter.filter_type = RTE_MAC_HASH_MATCH;
7491         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7492                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7493
7494         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7495
7496         if (is_on)
7497                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7498                                         RTE_ETH_FILTER_MACVLAN,
7499                                         RTE_ETH_FILTER_ADD,
7500                                          &filter);
7501         else
7502                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7503                                         RTE_ETH_FILTER_MACVLAN,
7504                                         RTE_ETH_FILTER_DELETE,
7505                                         &filter);
7506
7507         if (ret < 0)
7508                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7509
7510 }
7511
7512 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7513         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7514                                  set, "set");
7515 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7516         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7517                                  port, "port");
7518 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7519         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7520                               port_id, UINT16);
7521 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7522         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7523                                  vf, "vf");
7524 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7525         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7526                                 vf_id, UINT8);
7527 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7528         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7529                                 address);
7530 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7531         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7532                                 filter_type, "exact-mac#exact-mac-vlan"
7533                                 "#hashmac#hashmac-vlan");
7534 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7535         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7536                                  mode, "on#off");
7537
7538 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7539         .f = cmd_set_vf_macvlan_parsed,
7540         .data = NULL,
7541         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7542                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7543                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7544                 "hash match rule: hash match of MAC and exact match of VLAN",
7545         .tokens = {
7546                 (void *)&cmd_set_vf_macvlan_set,
7547                 (void *)&cmd_set_vf_macvlan_port,
7548                 (void *)&cmd_set_vf_macvlan_portid,
7549                 (void *)&cmd_set_vf_macvlan_vf,
7550                 (void *)&cmd_set_vf_macvlan_vf_id,
7551                 (void *)&cmd_set_vf_macvlan_mac,
7552                 (void *)&cmd_set_vf_macvlan_filter_type,
7553                 (void *)&cmd_set_vf_macvlan_mode,
7554                 NULL,
7555         },
7556 };
7557
7558 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7559 struct cmd_set_vf_traffic {
7560         cmdline_fixed_string_t set;
7561         cmdline_fixed_string_t port;
7562         portid_t port_id;
7563         cmdline_fixed_string_t vf;
7564         uint8_t vf_id;
7565         cmdline_fixed_string_t what;
7566         cmdline_fixed_string_t mode;
7567 };
7568
7569 static void
7570 cmd_set_vf_traffic_parsed(void *parsed_result,
7571                        __attribute__((unused)) struct cmdline *cl,
7572                        __attribute__((unused)) void *data)
7573 {
7574         struct cmd_set_vf_traffic *res = parsed_result;
7575         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7576         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7577
7578         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7579 }
7580
7581 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7582         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7583                                  set, "set");
7584 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7585         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7586                                  port, "port");
7587 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7588         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7589                               port_id, UINT16);
7590 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7591         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7592                                  vf, "vf");
7593 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7594         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7595                               vf_id, UINT8);
7596 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7597         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7598                                  what, "tx#rx");
7599 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7600         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7601                                  mode, "on#off");
7602
7603 cmdline_parse_inst_t cmd_set_vf_traffic = {
7604         .f = cmd_set_vf_traffic_parsed,
7605         .data = NULL,
7606         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7607         .tokens = {
7608                 (void *)&cmd_setvf_traffic_set,
7609                 (void *)&cmd_setvf_traffic_port,
7610                 (void *)&cmd_setvf_traffic_portid,
7611                 (void *)&cmd_setvf_traffic_vf,
7612                 (void *)&cmd_setvf_traffic_vfid,
7613                 (void *)&cmd_setvf_traffic_what,
7614                 (void *)&cmd_setvf_traffic_mode,
7615                 NULL,
7616         },
7617 };
7618
7619 /* *** CONFIGURE VF RECEIVE MODE *** */
7620 struct cmd_set_vf_rxmode {
7621         cmdline_fixed_string_t set;
7622         cmdline_fixed_string_t port;
7623         portid_t port_id;
7624         cmdline_fixed_string_t vf;
7625         uint8_t vf_id;
7626         cmdline_fixed_string_t what;
7627         cmdline_fixed_string_t mode;
7628         cmdline_fixed_string_t on;
7629 };
7630
7631 static void
7632 cmd_set_vf_rxmode_parsed(void *parsed_result,
7633                        __attribute__((unused)) struct cmdline *cl,
7634                        __attribute__((unused)) void *data)
7635 {
7636         int ret = -ENOTSUP;
7637         uint16_t rx_mode = 0;
7638         struct cmd_set_vf_rxmode *res = parsed_result;
7639
7640         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7641         if (!strcmp(res->what,"rxmode")) {
7642                 if (!strcmp(res->mode, "AUPE"))
7643                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7644                 else if (!strcmp(res->mode, "ROPE"))
7645                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7646                 else if (!strcmp(res->mode, "BAM"))
7647                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7648                 else if (!strncmp(res->mode, "MPE",3))
7649                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7650         }
7651
7652         RTE_SET_USED(is_on);
7653
7654 #ifdef RTE_LIBRTE_IXGBE_PMD
7655         if (ret == -ENOTSUP)
7656                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7657                                                   rx_mode, (uint8_t)is_on);
7658 #endif
7659 #ifdef RTE_LIBRTE_BNXT_PMD
7660         if (ret == -ENOTSUP)
7661                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7662                                                  rx_mode, (uint8_t)is_on);
7663 #endif
7664         if (ret < 0)
7665                 printf("bad VF receive mode parameter, return code = %d \n",
7666                 ret);
7667 }
7668
7669 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7670         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7671                                  set, "set");
7672 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7673         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7674                                  port, "port");
7675 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7676         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7677                               port_id, UINT16);
7678 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7679         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7680                                  vf, "vf");
7681 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7682         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7683                               vf_id, UINT8);
7684 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7685         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7686                                  what, "rxmode");
7687 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7688         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7689                                  mode, "AUPE#ROPE#BAM#MPE");
7690 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7691         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7692                                  on, "on#off");
7693
7694 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7695         .f = cmd_set_vf_rxmode_parsed,
7696         .data = NULL,
7697         .help_str = "set port <port_id> vf <vf_id> rxmode "
7698                 "AUPE|ROPE|BAM|MPE on|off",
7699         .tokens = {
7700                 (void *)&cmd_set_vf_rxmode_set,
7701                 (void *)&cmd_set_vf_rxmode_port,
7702                 (void *)&cmd_set_vf_rxmode_portid,
7703                 (void *)&cmd_set_vf_rxmode_vf,
7704                 (void *)&cmd_set_vf_rxmode_vfid,
7705                 (void *)&cmd_set_vf_rxmode_what,
7706                 (void *)&cmd_set_vf_rxmode_mode,
7707                 (void *)&cmd_set_vf_rxmode_on,
7708                 NULL,
7709         },
7710 };
7711
7712 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7713 struct cmd_vf_mac_addr_result {
7714         cmdline_fixed_string_t mac_addr_cmd;
7715         cmdline_fixed_string_t what;
7716         cmdline_fixed_string_t port;
7717         uint16_t port_num;
7718         cmdline_fixed_string_t vf;
7719         uint8_t vf_num;
7720         struct ether_addr address;
7721 };
7722
7723 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7724                 __attribute__((unused)) struct cmdline *cl,
7725                 __attribute__((unused)) void *data)
7726 {
7727         struct cmd_vf_mac_addr_result *res = parsed_result;
7728         int ret = -ENOTSUP;
7729
7730         if (strcmp(res->what, "add") != 0)
7731                 return;
7732
7733 #ifdef RTE_LIBRTE_I40E_PMD
7734         if (ret == -ENOTSUP)
7735                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7736                                                    &res->address);
7737 #endif
7738 #ifdef RTE_LIBRTE_BNXT_PMD
7739         if (ret == -ENOTSUP)
7740                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7741                                                 res->vf_num);
7742 #endif
7743
7744         if(ret < 0)
7745                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7746
7747 }
7748
7749 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7750         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7751                                 mac_addr_cmd,"mac_addr");
7752 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7753         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7754                                 what,"add");
7755 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7756         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7757                                 port,"port");
7758 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7759         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7760                                 port_num, UINT16);
7761 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7762         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7763                                 vf,"vf");
7764 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7765         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7766                                 vf_num, UINT8);
7767 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7768         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7769                                 address);
7770
7771 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7772         .f = cmd_vf_mac_addr_parsed,
7773         .data = (void *)0,
7774         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7775                 "Add MAC address filtering for a VF on port_id",
7776         .tokens = {
7777                 (void *)&cmd_vf_mac_addr_cmd,
7778                 (void *)&cmd_vf_mac_addr_what,
7779                 (void *)&cmd_vf_mac_addr_port,
7780                 (void *)&cmd_vf_mac_addr_portnum,
7781                 (void *)&cmd_vf_mac_addr_vf,
7782                 (void *)&cmd_vf_mac_addr_vfnum,
7783                 (void *)&cmd_vf_mac_addr_addr,
7784                 NULL,
7785         },
7786 };
7787
7788 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7789 struct cmd_vf_rx_vlan_filter {
7790         cmdline_fixed_string_t rx_vlan;
7791         cmdline_fixed_string_t what;
7792         uint16_t vlan_id;
7793         cmdline_fixed_string_t port;
7794         portid_t port_id;
7795         cmdline_fixed_string_t vf;
7796         uint64_t vf_mask;
7797 };
7798
7799 static void
7800 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7801                           __attribute__((unused)) struct cmdline *cl,
7802                           __attribute__((unused)) void *data)
7803 {
7804         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7805         int ret = -ENOTSUP;
7806
7807         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7808
7809 #ifdef RTE_LIBRTE_IXGBE_PMD
7810         if (ret == -ENOTSUP)
7811                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7812                                 res->vlan_id, res->vf_mask, is_add);
7813 #endif
7814 #ifdef RTE_LIBRTE_I40E_PMD
7815         if (ret == -ENOTSUP)
7816                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7817                                 res->vlan_id, res->vf_mask, is_add);
7818 #endif
7819 #ifdef RTE_LIBRTE_BNXT_PMD
7820         if (ret == -ENOTSUP)
7821                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7822                                 res->vlan_id, res->vf_mask, is_add);
7823 #endif
7824
7825         switch (ret) {
7826         case 0:
7827                 break;
7828         case -EINVAL:
7829                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7830                                 res->vlan_id, res->vf_mask);
7831                 break;
7832         case -ENODEV:
7833                 printf("invalid port_id %d\n", res->port_id);
7834                 break;
7835         case -ENOTSUP:
7836                 printf("function not implemented or supported\n");
7837                 break;
7838         default:
7839                 printf("programming error: (%s)\n", strerror(-ret));
7840         }
7841 }
7842
7843 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7844         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7845                                  rx_vlan, "rx_vlan");
7846 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7847         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7848                                  what, "add#rm");
7849 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7850         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7851                               vlan_id, UINT16);
7852 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7853         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7854                                  port, "port");
7855 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7856         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7857                               port_id, UINT16);
7858 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7859         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7860                                  vf, "vf");
7861 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7862         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7863                               vf_mask, UINT64);
7864
7865 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7866         .f = cmd_vf_rx_vlan_filter_parsed,
7867         .data = NULL,
7868         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7869                 "(vf_mask = hexadecimal VF mask)",
7870         .tokens = {
7871                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7872                 (void *)&cmd_vf_rx_vlan_filter_what,
7873                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7874                 (void *)&cmd_vf_rx_vlan_filter_port,
7875                 (void *)&cmd_vf_rx_vlan_filter_portid,
7876                 (void *)&cmd_vf_rx_vlan_filter_vf,
7877                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7878                 NULL,
7879         },
7880 };
7881
7882 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7883 struct cmd_queue_rate_limit_result {
7884         cmdline_fixed_string_t set;
7885         cmdline_fixed_string_t port;
7886         uint16_t port_num;
7887         cmdline_fixed_string_t queue;
7888         uint8_t queue_num;
7889         cmdline_fixed_string_t rate;
7890         uint16_t rate_num;
7891 };
7892
7893 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7894                 __attribute__((unused)) struct cmdline *cl,
7895                 __attribute__((unused)) void *data)
7896 {
7897         struct cmd_queue_rate_limit_result *res = parsed_result;
7898         int ret = 0;
7899
7900         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7901                 && (strcmp(res->queue, "queue") == 0)
7902                 && (strcmp(res->rate, "rate") == 0))
7903                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7904                                         res->rate_num);
7905         if (ret < 0)
7906                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7907
7908 }
7909
7910 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7911         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7912                                 set, "set");
7913 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7914         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7915                                 port, "port");
7916 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7917         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7918                                 port_num, UINT16);
7919 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7920         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7921                                 queue, "queue");
7922 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7923         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7924                                 queue_num, UINT8);
7925 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7926         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7927                                 rate, "rate");
7928 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7929         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7930                                 rate_num, UINT16);
7931
7932 cmdline_parse_inst_t cmd_queue_rate_limit = {
7933         .f = cmd_queue_rate_limit_parsed,
7934         .data = (void *)0,
7935         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7936                 "Set rate limit for a queue on port_id",
7937         .tokens = {
7938                 (void *)&cmd_queue_rate_limit_set,
7939                 (void *)&cmd_queue_rate_limit_port,
7940                 (void *)&cmd_queue_rate_limit_portnum,
7941                 (void *)&cmd_queue_rate_limit_queue,
7942                 (void *)&cmd_queue_rate_limit_queuenum,
7943                 (void *)&cmd_queue_rate_limit_rate,
7944                 (void *)&cmd_queue_rate_limit_ratenum,
7945                 NULL,
7946         },
7947 };
7948
7949 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7950 struct cmd_vf_rate_limit_result {
7951         cmdline_fixed_string_t set;
7952         cmdline_fixed_string_t port;
7953         uint16_t port_num;
7954         cmdline_fixed_string_t vf;
7955         uint8_t vf_num;
7956         cmdline_fixed_string_t rate;
7957         uint16_t rate_num;
7958         cmdline_fixed_string_t q_msk;
7959         uint64_t q_msk_val;
7960 };
7961
7962 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7963                 __attribute__((unused)) struct cmdline *cl,
7964                 __attribute__((unused)) void *data)
7965 {
7966         struct cmd_vf_rate_limit_result *res = parsed_result;
7967         int ret = 0;
7968
7969         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7970                 && (strcmp(res->vf, "vf") == 0)
7971                 && (strcmp(res->rate, "rate") == 0)
7972                 && (strcmp(res->q_msk, "queue_mask") == 0))
7973                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7974                                         res->rate_num, res->q_msk_val);
7975         if (ret < 0)
7976                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7977
7978 }
7979
7980 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7981         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7982                                 set, "set");
7983 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7984         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7985                                 port, "port");
7986 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7987         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7988                                 port_num, UINT16);
7989 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7990         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7991                                 vf, "vf");
7992 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7993         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7994                                 vf_num, UINT8);
7995 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7996         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7997                                 rate, "rate");
7998 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7999         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8000                                 rate_num, UINT16);
8001 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8002         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8003                                 q_msk, "queue_mask");
8004 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8005         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8006                                 q_msk_val, UINT64);
8007
8008 cmdline_parse_inst_t cmd_vf_rate_limit = {
8009         .f = cmd_vf_rate_limit_parsed,
8010         .data = (void *)0,
8011         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8012                 "queue_mask <queue_mask_value>: "
8013                 "Set rate limit for queues of VF on port_id",
8014         .tokens = {
8015                 (void *)&cmd_vf_rate_limit_set,
8016                 (void *)&cmd_vf_rate_limit_port,
8017                 (void *)&cmd_vf_rate_limit_portnum,
8018                 (void *)&cmd_vf_rate_limit_vf,
8019                 (void *)&cmd_vf_rate_limit_vfnum,
8020                 (void *)&cmd_vf_rate_limit_rate,
8021                 (void *)&cmd_vf_rate_limit_ratenum,
8022                 (void *)&cmd_vf_rate_limit_q_msk,
8023                 (void *)&cmd_vf_rate_limit_q_msk_val,
8024                 NULL,
8025         },
8026 };
8027
8028 /* *** ADD TUNNEL FILTER OF A PORT *** */
8029 struct cmd_tunnel_filter_result {
8030         cmdline_fixed_string_t cmd;
8031         cmdline_fixed_string_t what;
8032         portid_t port_id;
8033         struct ether_addr outer_mac;
8034         struct ether_addr inner_mac;
8035         cmdline_ipaddr_t ip_value;
8036         uint16_t inner_vlan;
8037         cmdline_fixed_string_t tunnel_type;
8038         cmdline_fixed_string_t filter_type;
8039         uint32_t tenant_id;
8040         uint16_t queue_num;
8041 };
8042
8043 static void
8044 cmd_tunnel_filter_parsed(void *parsed_result,
8045                           __attribute__((unused)) struct cmdline *cl,
8046                           __attribute__((unused)) void *data)
8047 {
8048         struct cmd_tunnel_filter_result *res = parsed_result;
8049         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8050         int ret = 0;
8051
8052         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8053
8054         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8055         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8056         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8057
8058         if (res->ip_value.family == AF_INET) {
8059                 tunnel_filter_conf.ip_addr.ipv4_addr =
8060                         res->ip_value.addr.ipv4.s_addr;
8061                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8062         } else {
8063                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8064                         &(res->ip_value.addr.ipv6),
8065                         sizeof(struct in6_addr));
8066                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8067         }
8068
8069         if (!strcmp(res->filter_type, "imac-ivlan"))
8070                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8071         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8072                 tunnel_filter_conf.filter_type =
8073                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8074         else if (!strcmp(res->filter_type, "imac-tenid"))
8075                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8076         else if (!strcmp(res->filter_type, "imac"))
8077                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8078         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8079                 tunnel_filter_conf.filter_type =
8080                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8081         else if (!strcmp(res->filter_type, "oip"))
8082                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8083         else if (!strcmp(res->filter_type, "iip"))
8084                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8085         else {
8086                 printf("The filter type is not supported");
8087                 return;
8088         }
8089
8090         if (!strcmp(res->tunnel_type, "vxlan"))
8091                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8092         else if (!strcmp(res->tunnel_type, "nvgre"))
8093                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8094         else if (!strcmp(res->tunnel_type, "ipingre"))
8095                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8096         else {
8097                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8098                 return;
8099         }
8100
8101         tunnel_filter_conf.tenant_id = res->tenant_id;
8102         tunnel_filter_conf.queue_id = res->queue_num;
8103         if (!strcmp(res->what, "add"))
8104                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8105                                         RTE_ETH_FILTER_TUNNEL,
8106                                         RTE_ETH_FILTER_ADD,
8107                                         &tunnel_filter_conf);
8108         else
8109                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8110                                         RTE_ETH_FILTER_TUNNEL,
8111                                         RTE_ETH_FILTER_DELETE,
8112                                         &tunnel_filter_conf);
8113         if (ret < 0)
8114                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8115                                 strerror(-ret));
8116
8117 }
8118 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8119         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8120         cmd, "tunnel_filter");
8121 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8122         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8123         what, "add#rm");
8124 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8125         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8126         port_id, UINT16);
8127 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8128         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8129         outer_mac);
8130 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8131         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8132         inner_mac);
8133 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8134         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8135         inner_vlan, UINT16);
8136 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8137         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8138         ip_value);
8139 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8140         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8141         tunnel_type, "vxlan#nvgre#ipingre");
8142
8143 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8144         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8145         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8146                 "imac#omac-imac-tenid");
8147 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8148         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8149         tenant_id, UINT32);
8150 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8151         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8152         queue_num, UINT16);
8153
8154 cmdline_parse_inst_t cmd_tunnel_filter = {
8155         .f = cmd_tunnel_filter_parsed,
8156         .data = (void *)0,
8157         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8158                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8159                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8160                 "<queue_id>: Add/Rm tunnel filter of a port",
8161         .tokens = {
8162                 (void *)&cmd_tunnel_filter_cmd,
8163                 (void *)&cmd_tunnel_filter_what,
8164                 (void *)&cmd_tunnel_filter_port_id,
8165                 (void *)&cmd_tunnel_filter_outer_mac,
8166                 (void *)&cmd_tunnel_filter_inner_mac,
8167                 (void *)&cmd_tunnel_filter_ip_value,
8168                 (void *)&cmd_tunnel_filter_innner_vlan,
8169                 (void *)&cmd_tunnel_filter_tunnel_type,
8170                 (void *)&cmd_tunnel_filter_filter_type,
8171                 (void *)&cmd_tunnel_filter_tenant_id,
8172                 (void *)&cmd_tunnel_filter_queue_num,
8173                 NULL,
8174         },
8175 };
8176
8177 /* *** CONFIGURE TUNNEL UDP PORT *** */
8178 struct cmd_tunnel_udp_config {
8179         cmdline_fixed_string_t cmd;
8180         cmdline_fixed_string_t what;
8181         uint16_t udp_port;
8182         portid_t port_id;
8183 };
8184
8185 static void
8186 cmd_tunnel_udp_config_parsed(void *parsed_result,
8187                           __attribute__((unused)) struct cmdline *cl,
8188                           __attribute__((unused)) void *data)
8189 {
8190         struct cmd_tunnel_udp_config *res = parsed_result;
8191         struct rte_eth_udp_tunnel tunnel_udp;
8192         int ret;
8193
8194         tunnel_udp.udp_port = res->udp_port;
8195
8196         if (!strcmp(res->cmd, "rx_vxlan_port"))
8197                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8198
8199         if (!strcmp(res->what, "add"))
8200                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8201                                                       &tunnel_udp);
8202         else
8203                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8204                                                          &tunnel_udp);
8205
8206         if (ret < 0)
8207                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8208 }
8209
8210 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8211         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8212                                 cmd, "rx_vxlan_port");
8213 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8214         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8215                                 what, "add#rm");
8216 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8217         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8218                                 udp_port, UINT16);
8219 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8220         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8221                                 port_id, UINT16);
8222
8223 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8224         .f = cmd_tunnel_udp_config_parsed,
8225         .data = (void *)0,
8226         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8227                 "Add/Remove a tunneling UDP port filter",
8228         .tokens = {
8229                 (void *)&cmd_tunnel_udp_config_cmd,
8230                 (void *)&cmd_tunnel_udp_config_what,
8231                 (void *)&cmd_tunnel_udp_config_udp_port,
8232                 (void *)&cmd_tunnel_udp_config_port_id,
8233                 NULL,
8234         },
8235 };
8236
8237 /* *** GLOBAL CONFIG *** */
8238 struct cmd_global_config_result {
8239         cmdline_fixed_string_t cmd;
8240         portid_t port_id;
8241         cmdline_fixed_string_t cfg_type;
8242         uint8_t len;
8243 };
8244
8245 static void
8246 cmd_global_config_parsed(void *parsed_result,
8247                          __attribute__((unused)) struct cmdline *cl,
8248                          __attribute__((unused)) void *data)
8249 {
8250         struct cmd_global_config_result *res = parsed_result;
8251         struct rte_eth_global_cfg conf;
8252         int ret;
8253
8254         memset(&conf, 0, sizeof(conf));
8255         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8256         conf.cfg.gre_key_len = res->len;
8257         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8258                                       RTE_ETH_FILTER_SET, &conf);
8259         if (ret != 0)
8260                 printf("Global config error\n");
8261 }
8262
8263 cmdline_parse_token_string_t cmd_global_config_cmd =
8264         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8265                 "global_config");
8266 cmdline_parse_token_num_t cmd_global_config_port_id =
8267         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8268                                UINT16);
8269 cmdline_parse_token_string_t cmd_global_config_type =
8270         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8271                 cfg_type, "gre-key-len");
8272 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8273         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8274                 len, UINT8);
8275
8276 cmdline_parse_inst_t cmd_global_config = {
8277         .f = cmd_global_config_parsed,
8278         .data = (void *)NULL,
8279         .help_str = "global_config <port_id> gre-key-len <key_len>",
8280         .tokens = {
8281                 (void *)&cmd_global_config_cmd,
8282                 (void *)&cmd_global_config_port_id,
8283                 (void *)&cmd_global_config_type,
8284                 (void *)&cmd_global_config_gre_key_len,
8285                 NULL,
8286         },
8287 };
8288
8289 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8290 struct cmd_set_mirror_mask_result {
8291         cmdline_fixed_string_t set;
8292         cmdline_fixed_string_t port;
8293         portid_t port_id;
8294         cmdline_fixed_string_t mirror;
8295         uint8_t rule_id;
8296         cmdline_fixed_string_t what;
8297         cmdline_fixed_string_t value;
8298         cmdline_fixed_string_t dstpool;
8299         uint8_t dstpool_id;
8300         cmdline_fixed_string_t on;
8301 };
8302
8303 cmdline_parse_token_string_t cmd_mirror_mask_set =
8304         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8305                                 set, "set");
8306 cmdline_parse_token_string_t cmd_mirror_mask_port =
8307         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8308                                 port, "port");
8309 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8310         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8311                                 port_id, UINT16);
8312 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8313         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8314                                 mirror, "mirror-rule");
8315 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8316         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8317                                 rule_id, UINT8);
8318 cmdline_parse_token_string_t cmd_mirror_mask_what =
8319         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8320                                 what, "pool-mirror-up#pool-mirror-down"
8321                                       "#vlan-mirror");
8322 cmdline_parse_token_string_t cmd_mirror_mask_value =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8324                                 value, NULL);
8325 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8326         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8327                                 dstpool, "dst-pool");
8328 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8329         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8330                                 dstpool_id, UINT8);
8331 cmdline_parse_token_string_t cmd_mirror_mask_on =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8333                                 on, "on#off");
8334
8335 static void
8336 cmd_set_mirror_mask_parsed(void *parsed_result,
8337                        __attribute__((unused)) struct cmdline *cl,
8338                        __attribute__((unused)) void *data)
8339 {
8340         int ret,nb_item,i;
8341         struct cmd_set_mirror_mask_result *res = parsed_result;
8342         struct rte_eth_mirror_conf mr_conf;
8343
8344         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8345
8346         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8347
8348         mr_conf.dst_pool = res->dstpool_id;
8349
8350         if (!strcmp(res->what, "pool-mirror-up")) {
8351                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8352                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8353         } else if (!strcmp(res->what, "pool-mirror-down")) {
8354                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8355                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8356         } else if (!strcmp(res->what, "vlan-mirror")) {
8357                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8358                 nb_item = parse_item_list(res->value, "vlan",
8359                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8360                 if (nb_item <= 0)
8361                         return;
8362
8363                 for (i = 0; i < nb_item; i++) {
8364                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8365                                 printf("Invalid vlan_id: must be < 4096\n");
8366                                 return;
8367                         }
8368
8369                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8370                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8371                 }
8372         }
8373
8374         if (!strcmp(res->on, "on"))
8375                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8376                                                 res->rule_id, 1);
8377         else
8378                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8379                                                 res->rule_id, 0);
8380         if (ret < 0)
8381                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8382 }
8383
8384 cmdline_parse_inst_t cmd_set_mirror_mask = {
8385                 .f = cmd_set_mirror_mask_parsed,
8386                 .data = NULL,
8387                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8388                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8389                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8390                 .tokens = {
8391                         (void *)&cmd_mirror_mask_set,
8392                         (void *)&cmd_mirror_mask_port,
8393                         (void *)&cmd_mirror_mask_portid,
8394                         (void *)&cmd_mirror_mask_mirror,
8395                         (void *)&cmd_mirror_mask_ruleid,
8396                         (void *)&cmd_mirror_mask_what,
8397                         (void *)&cmd_mirror_mask_value,
8398                         (void *)&cmd_mirror_mask_dstpool,
8399                         (void *)&cmd_mirror_mask_poolid,
8400                         (void *)&cmd_mirror_mask_on,
8401                         NULL,
8402                 },
8403 };
8404
8405 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8406 struct cmd_set_mirror_link_result {
8407         cmdline_fixed_string_t set;
8408         cmdline_fixed_string_t port;
8409         portid_t port_id;
8410         cmdline_fixed_string_t mirror;
8411         uint8_t rule_id;
8412         cmdline_fixed_string_t what;
8413         cmdline_fixed_string_t dstpool;
8414         uint8_t dstpool_id;
8415         cmdline_fixed_string_t on;
8416 };
8417
8418 cmdline_parse_token_string_t cmd_mirror_link_set =
8419         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8420                                  set, "set");
8421 cmdline_parse_token_string_t cmd_mirror_link_port =
8422         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8423                                 port, "port");
8424 cmdline_parse_token_num_t cmd_mirror_link_portid =
8425         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8426                                 port_id, UINT16);
8427 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8428         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8429                                 mirror, "mirror-rule");
8430 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8431         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8432                             rule_id, UINT8);
8433 cmdline_parse_token_string_t cmd_mirror_link_what =
8434         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8435                                 what, "uplink-mirror#downlink-mirror");
8436 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8437         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8438                                 dstpool, "dst-pool");
8439 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8440         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8441                                 dstpool_id, UINT8);
8442 cmdline_parse_token_string_t cmd_mirror_link_on =
8443         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8444                                 on, "on#off");
8445
8446 static void
8447 cmd_set_mirror_link_parsed(void *parsed_result,
8448                        __attribute__((unused)) struct cmdline *cl,
8449                        __attribute__((unused)) void *data)
8450 {
8451         int ret;
8452         struct cmd_set_mirror_link_result *res = parsed_result;
8453         struct rte_eth_mirror_conf mr_conf;
8454
8455         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8456         if (!strcmp(res->what, "uplink-mirror"))
8457                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8458         else
8459                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8460
8461         mr_conf.dst_pool = res->dstpool_id;
8462
8463         if (!strcmp(res->on, "on"))
8464                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8465                                                 res->rule_id, 1);
8466         else
8467                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8468                                                 res->rule_id, 0);
8469
8470         /* check the return value and print it if is < 0 */
8471         if (ret < 0)
8472                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8473
8474 }
8475
8476 cmdline_parse_inst_t cmd_set_mirror_link = {
8477                 .f = cmd_set_mirror_link_parsed,
8478                 .data = NULL,
8479                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8480                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8481                 .tokens = {
8482                         (void *)&cmd_mirror_link_set,
8483                         (void *)&cmd_mirror_link_port,
8484                         (void *)&cmd_mirror_link_portid,
8485                         (void *)&cmd_mirror_link_mirror,
8486                         (void *)&cmd_mirror_link_ruleid,
8487                         (void *)&cmd_mirror_link_what,
8488                         (void *)&cmd_mirror_link_dstpool,
8489                         (void *)&cmd_mirror_link_poolid,
8490                         (void *)&cmd_mirror_link_on,
8491                         NULL,
8492                 },
8493 };
8494
8495 /* *** RESET VM MIRROR RULE *** */
8496 struct cmd_rm_mirror_rule_result {
8497         cmdline_fixed_string_t reset;
8498         cmdline_fixed_string_t port;
8499         portid_t port_id;
8500         cmdline_fixed_string_t mirror;
8501         uint8_t rule_id;
8502 };
8503
8504 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8505         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8506                                  reset, "reset");
8507 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8508         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8509                                 port, "port");
8510 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8511         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8512                                 port_id, UINT16);
8513 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8514         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8515                                 mirror, "mirror-rule");
8516 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8517         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8518                                 rule_id, UINT8);
8519
8520 static void
8521 cmd_reset_mirror_rule_parsed(void *parsed_result,
8522                        __attribute__((unused)) struct cmdline *cl,
8523                        __attribute__((unused)) void *data)
8524 {
8525         int ret;
8526         struct cmd_set_mirror_link_result *res = parsed_result;
8527         /* check rule_id */
8528         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8529         if(ret < 0)
8530                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8531 }
8532
8533 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8534                 .f = cmd_reset_mirror_rule_parsed,
8535                 .data = NULL,
8536                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8537                 .tokens = {
8538                         (void *)&cmd_rm_mirror_rule_reset,
8539                         (void *)&cmd_rm_mirror_rule_port,
8540                         (void *)&cmd_rm_mirror_rule_portid,
8541                         (void *)&cmd_rm_mirror_rule_mirror,
8542                         (void *)&cmd_rm_mirror_rule_ruleid,
8543                         NULL,
8544                 },
8545 };
8546
8547 /* ******************************************************************************** */
8548
8549 struct cmd_dump_result {
8550         cmdline_fixed_string_t dump;
8551 };
8552
8553 static void
8554 dump_struct_sizes(void)
8555 {
8556 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8557         DUMP_SIZE(struct rte_mbuf);
8558         DUMP_SIZE(struct rte_mempool);
8559         DUMP_SIZE(struct rte_ring);
8560 #undef DUMP_SIZE
8561 }
8562
8563 static void cmd_dump_parsed(void *parsed_result,
8564                             __attribute__((unused)) struct cmdline *cl,
8565                             __attribute__((unused)) void *data)
8566 {
8567         struct cmd_dump_result *res = parsed_result;
8568
8569         if (!strcmp(res->dump, "dump_physmem"))
8570                 rte_dump_physmem_layout(stdout);
8571         else if (!strcmp(res->dump, "dump_memzone"))
8572                 rte_memzone_dump(stdout);
8573         else if (!strcmp(res->dump, "dump_struct_sizes"))
8574                 dump_struct_sizes();
8575         else if (!strcmp(res->dump, "dump_ring"))
8576                 rte_ring_list_dump(stdout);
8577         else if (!strcmp(res->dump, "dump_mempool"))
8578                 rte_mempool_list_dump(stdout);
8579         else if (!strcmp(res->dump, "dump_devargs"))
8580                 rte_eal_devargs_dump(stdout);
8581         else if (!strcmp(res->dump, "dump_log_types"))
8582                 rte_log_dump(stdout);
8583 }
8584
8585 cmdline_parse_token_string_t cmd_dump_dump =
8586         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8587                 "dump_physmem#"
8588                 "dump_memzone#"
8589                 "dump_struct_sizes#"
8590                 "dump_ring#"
8591                 "dump_mempool#"
8592                 "dump_devargs#"
8593                 "dump_log_types");
8594
8595 cmdline_parse_inst_t cmd_dump = {
8596         .f = cmd_dump_parsed,  /* function to call */
8597         .data = NULL,      /* 2nd arg of func */
8598         .help_str = "Dump status",
8599         .tokens = {        /* token list, NULL terminated */
8600                 (void *)&cmd_dump_dump,
8601                 NULL,
8602         },
8603 };
8604
8605 /* ******************************************************************************** */
8606
8607 struct cmd_dump_one_result {
8608         cmdline_fixed_string_t dump;
8609         cmdline_fixed_string_t name;
8610 };
8611
8612 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8613                                 __attribute__((unused)) void *data)
8614 {
8615         struct cmd_dump_one_result *res = parsed_result;
8616
8617         if (!strcmp(res->dump, "dump_ring")) {
8618                 struct rte_ring *r;
8619                 r = rte_ring_lookup(res->name);
8620                 if (r == NULL) {
8621                         cmdline_printf(cl, "Cannot find ring\n");
8622                         return;
8623                 }
8624                 rte_ring_dump(stdout, r);
8625         } else if (!strcmp(res->dump, "dump_mempool")) {
8626                 struct rte_mempool *mp;
8627                 mp = rte_mempool_lookup(res->name);
8628                 if (mp == NULL) {
8629                         cmdline_printf(cl, "Cannot find mempool\n");
8630                         return;
8631                 }
8632                 rte_mempool_dump(stdout, mp);
8633         }
8634 }
8635
8636 cmdline_parse_token_string_t cmd_dump_one_dump =
8637         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8638                                  "dump_ring#dump_mempool");
8639
8640 cmdline_parse_token_string_t cmd_dump_one_name =
8641         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8642
8643 cmdline_parse_inst_t cmd_dump_one = {
8644         .f = cmd_dump_one_parsed,  /* function to call */
8645         .data = NULL,      /* 2nd arg of func */
8646         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8647         .tokens = {        /* token list, NULL terminated */
8648                 (void *)&cmd_dump_one_dump,
8649                 (void *)&cmd_dump_one_name,
8650                 NULL,
8651         },
8652 };
8653
8654 /* *** Add/Del syn filter *** */
8655 struct cmd_syn_filter_result {
8656         cmdline_fixed_string_t filter;
8657         portid_t port_id;
8658         cmdline_fixed_string_t ops;
8659         cmdline_fixed_string_t priority;
8660         cmdline_fixed_string_t high;
8661         cmdline_fixed_string_t queue;
8662         uint16_t queue_id;
8663 };
8664
8665 static void
8666 cmd_syn_filter_parsed(void *parsed_result,
8667                         __attribute__((unused)) struct cmdline *cl,
8668                         __attribute__((unused)) void *data)
8669 {
8670         struct cmd_syn_filter_result *res = parsed_result;
8671         struct rte_eth_syn_filter syn_filter;
8672         int ret = 0;
8673
8674         ret = rte_eth_dev_filter_supported(res->port_id,
8675                                         RTE_ETH_FILTER_SYN);
8676         if (ret < 0) {
8677                 printf("syn filter is not supported on port %u.\n",
8678                                 res->port_id);
8679                 return;
8680         }
8681
8682         memset(&syn_filter, 0, sizeof(syn_filter));
8683
8684         if (!strcmp(res->ops, "add")) {
8685                 if (!strcmp(res->high, "high"))
8686                         syn_filter.hig_pri = 1;
8687                 else
8688                         syn_filter.hig_pri = 0;
8689
8690                 syn_filter.queue = res->queue_id;
8691                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8692                                                 RTE_ETH_FILTER_SYN,
8693                                                 RTE_ETH_FILTER_ADD,
8694                                                 &syn_filter);
8695         } else
8696                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8697                                                 RTE_ETH_FILTER_SYN,
8698                                                 RTE_ETH_FILTER_DELETE,
8699                                                 &syn_filter);
8700
8701         if (ret < 0)
8702                 printf("syn filter programming error: (%s)\n",
8703                                 strerror(-ret));
8704 }
8705
8706 cmdline_parse_token_string_t cmd_syn_filter_filter =
8707         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8708         filter, "syn_filter");
8709 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8710         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8711         port_id, UINT16);
8712 cmdline_parse_token_string_t cmd_syn_filter_ops =
8713         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8714         ops, "add#del");
8715 cmdline_parse_token_string_t cmd_syn_filter_priority =
8716         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8717                                 priority, "priority");
8718 cmdline_parse_token_string_t cmd_syn_filter_high =
8719         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8720                                 high, "high#low");
8721 cmdline_parse_token_string_t cmd_syn_filter_queue =
8722         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8723                                 queue, "queue");
8724 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8725         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8726                                 queue_id, UINT16);
8727
8728 cmdline_parse_inst_t cmd_syn_filter = {
8729         .f = cmd_syn_filter_parsed,
8730         .data = NULL,
8731         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8732                 "<queue_id>: Add/Delete syn filter",
8733         .tokens = {
8734                 (void *)&cmd_syn_filter_filter,
8735                 (void *)&cmd_syn_filter_port_id,
8736                 (void *)&cmd_syn_filter_ops,
8737                 (void *)&cmd_syn_filter_priority,
8738                 (void *)&cmd_syn_filter_high,
8739                 (void *)&cmd_syn_filter_queue,
8740                 (void *)&cmd_syn_filter_queue_id,
8741                 NULL,
8742         },
8743 };
8744
8745 /* *** queue region set *** */
8746 struct cmd_queue_region_result {
8747         cmdline_fixed_string_t set;
8748         cmdline_fixed_string_t port;
8749         portid_t port_id;
8750         cmdline_fixed_string_t cmd;
8751         cmdline_fixed_string_t region;
8752         uint8_t  region_id;
8753         cmdline_fixed_string_t queue_start_index;
8754         uint8_t  queue_id;
8755         cmdline_fixed_string_t queue_num;
8756         uint8_t  queue_num_value;
8757 };
8758
8759 static void
8760 cmd_queue_region_parsed(void *parsed_result,
8761                         __attribute__((unused)) struct cmdline *cl,
8762                         __attribute__((unused)) void *data)
8763 {
8764         struct cmd_queue_region_result *res = parsed_result;
8765         int ret = -ENOTSUP;
8766 #ifdef RTE_LIBRTE_I40E_PMD
8767         struct rte_pmd_i40e_queue_region_conf region_conf;
8768         enum rte_pmd_i40e_queue_region_op op_type;
8769 #endif
8770
8771         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8772                 return;
8773
8774 #ifdef RTE_LIBRTE_I40E_PMD
8775         memset(&region_conf, 0, sizeof(region_conf));
8776         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8777         region_conf.region_id = res->region_id;
8778         region_conf.queue_num = res->queue_num_value;
8779         region_conf.queue_start_index = res->queue_id;
8780
8781         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8782                                 op_type, &region_conf);
8783 #endif
8784
8785         switch (ret) {
8786         case 0:
8787                 break;
8788         case -ENOTSUP:
8789                 printf("function not implemented or supported\n");
8790                 break;
8791         default:
8792                 printf("queue region config error: (%s)\n", strerror(-ret));
8793         }
8794 }
8795
8796 cmdline_parse_token_string_t cmd_queue_region_set =
8797 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8798                 set, "set");
8799 cmdline_parse_token_string_t cmd_queue_region_port =
8800         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8801 cmdline_parse_token_num_t cmd_queue_region_port_id =
8802         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8803                                 port_id, UINT16);
8804 cmdline_parse_token_string_t cmd_queue_region_cmd =
8805         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8806                                  cmd, "queue-region");
8807 cmdline_parse_token_string_t cmd_queue_region_id =
8808         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8809                                 region, "region_id");
8810 cmdline_parse_token_num_t cmd_queue_region_index =
8811         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8812                                 region_id, UINT8);
8813 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8814         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8815                                 queue_start_index, "queue_start_index");
8816 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8817         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8818                                 queue_id, UINT8);
8819 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8820         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8821                                 queue_num, "queue_num");
8822 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8823         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8824                                 queue_num_value, UINT8);
8825
8826 cmdline_parse_inst_t cmd_queue_region = {
8827         .f = cmd_queue_region_parsed,
8828         .data = NULL,
8829         .help_str = "set port <port_id> queue-region region_id <value> "
8830                 "queue_start_index <value> queue_num <value>: Set a queue region",
8831         .tokens = {
8832                 (void *)&cmd_queue_region_set,
8833                 (void *)&cmd_queue_region_port,
8834                 (void *)&cmd_queue_region_port_id,
8835                 (void *)&cmd_queue_region_cmd,
8836                 (void *)&cmd_queue_region_id,
8837                 (void *)&cmd_queue_region_index,
8838                 (void *)&cmd_queue_region_queue_start_index,
8839                 (void *)&cmd_queue_region_queue_id,
8840                 (void *)&cmd_queue_region_queue_num,
8841                 (void *)&cmd_queue_region_queue_num_value,
8842                 NULL,
8843         },
8844 };
8845
8846 /* *** queue region and flowtype set *** */
8847 struct cmd_region_flowtype_result {
8848         cmdline_fixed_string_t set;
8849         cmdline_fixed_string_t port;
8850         portid_t port_id;
8851         cmdline_fixed_string_t cmd;
8852         cmdline_fixed_string_t region;
8853         uint8_t  region_id;
8854         cmdline_fixed_string_t flowtype;
8855         uint8_t  flowtype_id;
8856 };
8857
8858 static void
8859 cmd_region_flowtype_parsed(void *parsed_result,
8860                         __attribute__((unused)) struct cmdline *cl,
8861                         __attribute__((unused)) void *data)
8862 {
8863         struct cmd_region_flowtype_result *res = parsed_result;
8864         int ret = -ENOTSUP;
8865 #ifdef RTE_LIBRTE_I40E_PMD
8866         struct rte_pmd_i40e_queue_region_conf region_conf;
8867         enum rte_pmd_i40e_queue_region_op op_type;
8868 #endif
8869
8870         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8871                 return;
8872
8873 #ifdef RTE_LIBRTE_I40E_PMD
8874         memset(&region_conf, 0, sizeof(region_conf));
8875
8876         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8877         region_conf.region_id = res->region_id;
8878         region_conf.hw_flowtype = res->flowtype_id;
8879
8880         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8881                         op_type, &region_conf);
8882 #endif
8883
8884         switch (ret) {
8885         case 0:
8886                 break;
8887         case -ENOTSUP:
8888                 printf("function not implemented or supported\n");
8889                 break;
8890         default:
8891                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8892         }
8893 }
8894
8895 cmdline_parse_token_string_t cmd_region_flowtype_set =
8896 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8897                                 set, "set");
8898 cmdline_parse_token_string_t cmd_region_flowtype_port =
8899         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8900                                 port, "port");
8901 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8902         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8903                                 port_id, UINT16);
8904 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8905         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8906                                 cmd, "queue-region");
8907 cmdline_parse_token_string_t cmd_region_flowtype_index =
8908         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8909                                 region, "region_id");
8910 cmdline_parse_token_num_t cmd_region_flowtype_id =
8911         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8912                                 region_id, UINT8);
8913 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8914         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8915                                 flowtype, "flowtype");
8916 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8917         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8918                                 flowtype_id, UINT8);
8919 cmdline_parse_inst_t cmd_region_flowtype = {
8920         .f = cmd_region_flowtype_parsed,
8921         .data = NULL,
8922         .help_str = "set port <port_id> queue-region region_id <value> "
8923                 "flowtype <value>: Set a flowtype region index",
8924         .tokens = {
8925                 (void *)&cmd_region_flowtype_set,
8926                 (void *)&cmd_region_flowtype_port,
8927                 (void *)&cmd_region_flowtype_port_index,
8928                 (void *)&cmd_region_flowtype_cmd,
8929                 (void *)&cmd_region_flowtype_index,
8930                 (void *)&cmd_region_flowtype_id,
8931                 (void *)&cmd_region_flowtype_flow_index,
8932                 (void *)&cmd_region_flowtype_flow_id,
8933                 NULL,
8934         },
8935 };
8936
8937 /* *** User Priority (UP) to queue region (region_id) set *** */
8938 struct cmd_user_priority_region_result {
8939         cmdline_fixed_string_t set;
8940         cmdline_fixed_string_t port;
8941         portid_t port_id;
8942         cmdline_fixed_string_t cmd;
8943         cmdline_fixed_string_t user_priority;
8944         uint8_t  user_priority_id;
8945         cmdline_fixed_string_t region;
8946         uint8_t  region_id;
8947 };
8948
8949 static void
8950 cmd_user_priority_region_parsed(void *parsed_result,
8951                         __attribute__((unused)) struct cmdline *cl,
8952                         __attribute__((unused)) void *data)
8953 {
8954         struct cmd_user_priority_region_result *res = parsed_result;
8955         int ret = -ENOTSUP;
8956 #ifdef RTE_LIBRTE_I40E_PMD
8957         struct rte_pmd_i40e_queue_region_conf region_conf;
8958         enum rte_pmd_i40e_queue_region_op op_type;
8959 #endif
8960
8961         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8962                 return;
8963
8964 #ifdef RTE_LIBRTE_I40E_PMD
8965         memset(&region_conf, 0, sizeof(region_conf));
8966         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8967         region_conf.user_priority = res->user_priority_id;
8968         region_conf.region_id = res->region_id;
8969
8970         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8971                                 op_type, &region_conf);
8972 #endif
8973
8974         switch (ret) {
8975         case 0:
8976                 break;
8977         case -ENOTSUP:
8978                 printf("function not implemented or supported\n");
8979                 break;
8980         default:
8981                 printf("user_priority region config error: (%s)\n",
8982                                 strerror(-ret));
8983         }
8984 }
8985
8986 cmdline_parse_token_string_t cmd_user_priority_region_set =
8987         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8988                                 set, "set");
8989 cmdline_parse_token_string_t cmd_user_priority_region_port =
8990         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8991                                 port, "port");
8992 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8993         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8994                                 port_id, UINT16);
8995 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8996         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8997                                 cmd, "queue-region");
8998 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8999         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9000                                 user_priority, "UP");
9001 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9002         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9003                                 user_priority_id, UINT8);
9004 cmdline_parse_token_string_t cmd_user_priority_region_region =
9005         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9006                                 region, "region_id");
9007 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9008         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9009                                 region_id, UINT8);
9010
9011 cmdline_parse_inst_t cmd_user_priority_region = {
9012         .f = cmd_user_priority_region_parsed,
9013         .data = NULL,
9014         .help_str = "set port <port_id> queue-region UP <value> "
9015                 "region_id <value>: Set the mapping of User Priority (UP) "
9016                 "to queue region (region_id) ",
9017         .tokens = {
9018                 (void *)&cmd_user_priority_region_set,
9019                 (void *)&cmd_user_priority_region_port,
9020                 (void *)&cmd_user_priority_region_port_index,
9021                 (void *)&cmd_user_priority_region_cmd,
9022                 (void *)&cmd_user_priority_region_UP,
9023                 (void *)&cmd_user_priority_region_UP_id,
9024                 (void *)&cmd_user_priority_region_region,
9025                 (void *)&cmd_user_priority_region_region_id,
9026                 NULL,
9027         },
9028 };
9029
9030 /* *** flush all queue region related configuration *** */
9031 struct cmd_flush_queue_region_result {
9032         cmdline_fixed_string_t set;
9033         cmdline_fixed_string_t port;
9034         portid_t port_id;
9035         cmdline_fixed_string_t cmd;
9036         cmdline_fixed_string_t flush;
9037         cmdline_fixed_string_t what;
9038 };
9039
9040 static void
9041 cmd_flush_queue_region_parsed(void *parsed_result,
9042                         __attribute__((unused)) struct cmdline *cl,
9043                         __attribute__((unused)) void *data)
9044 {
9045         struct cmd_flush_queue_region_result *res = parsed_result;
9046         int ret = -ENOTSUP;
9047 #ifdef RTE_LIBRTE_I40E_PMD
9048         struct rte_pmd_i40e_queue_region_conf region_conf;
9049         enum rte_pmd_i40e_queue_region_op op_type;
9050 #endif
9051
9052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9053                 return;
9054
9055 #ifdef RTE_LIBRTE_I40E_PMD
9056         memset(&region_conf, 0, sizeof(region_conf));
9057
9058         if (strcmp(res->what, "on") == 0)
9059                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9060         else
9061                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9062
9063         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9064                                 op_type, &region_conf);
9065 #endif
9066
9067         switch (ret) {
9068         case 0:
9069                 break;
9070         case -ENOTSUP:
9071                 printf("function not implemented or supported\n");
9072                 break;
9073         default:
9074                 printf("queue region config flush error: (%s)\n",
9075                                 strerror(-ret));
9076         }
9077 }
9078
9079 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9080         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9081                                 set, "set");
9082 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9083         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9084                                 port, "port");
9085 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9086         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9087                                 port_id, UINT16);
9088 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9089         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9090                                 cmd, "queue-region");
9091 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9092         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9093                                 flush, "flush");
9094 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9095         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9096                                 what, "on#off");
9097
9098 cmdline_parse_inst_t cmd_flush_queue_region = {
9099         .f = cmd_flush_queue_region_parsed,
9100         .data = NULL,
9101         .help_str = "set port <port_id> queue-region flush on|off"
9102                 ": flush all queue region related configuration",
9103         .tokens = {
9104                 (void *)&cmd_flush_queue_region_set,
9105                 (void *)&cmd_flush_queue_region_port,
9106                 (void *)&cmd_flush_queue_region_port_index,
9107                 (void *)&cmd_flush_queue_region_cmd,
9108                 (void *)&cmd_flush_queue_region_flush,
9109                 (void *)&cmd_flush_queue_region_what,
9110                 NULL,
9111         },
9112 };
9113
9114 /* *** get all queue region related configuration info *** */
9115 struct cmd_show_queue_region_info {
9116         cmdline_fixed_string_t show;
9117         cmdline_fixed_string_t port;
9118         portid_t port_id;
9119         cmdline_fixed_string_t cmd;
9120 };
9121
9122 static void
9123 cmd_show_queue_region_info_parsed(void *parsed_result,
9124                         __attribute__((unused)) struct cmdline *cl,
9125                         __attribute__((unused)) void *data)
9126 {
9127         struct cmd_show_queue_region_info *res = parsed_result;
9128         int ret = -ENOTSUP;
9129 #ifdef RTE_LIBRTE_I40E_PMD
9130         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9131         enum rte_pmd_i40e_queue_region_op op_type;
9132 #endif
9133
9134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9135                 return;
9136
9137 #ifdef RTE_LIBRTE_I40E_PMD
9138         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9139
9140         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9141
9142         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9143                                         op_type, &rte_pmd_regions);
9144
9145         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9146 #endif
9147
9148         switch (ret) {
9149         case 0:
9150                 break;
9151         case -ENOTSUP:
9152                 printf("function not implemented or supported\n");
9153                 break;
9154         default:
9155                 printf("queue region config info show error: (%s)\n",
9156                                 strerror(-ret));
9157         }
9158 }
9159
9160 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9161 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9162                                 show, "show");
9163 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9164         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9165                                 port, "port");
9166 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9167         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9168                                 port_id, UINT16);
9169 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9170         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9171                                 cmd, "queue-region");
9172
9173 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9174         .f = cmd_show_queue_region_info_parsed,
9175         .data = NULL,
9176         .help_str = "show port <port_id> queue-region"
9177                 ": show all queue region related configuration info",
9178         .tokens = {
9179                 (void *)&cmd_show_queue_region_info_get,
9180                 (void *)&cmd_show_queue_region_info_port,
9181                 (void *)&cmd_show_queue_region_info_port_index,
9182                 (void *)&cmd_show_queue_region_info_cmd,
9183                 NULL,
9184         },
9185 };
9186
9187 /* *** ADD/REMOVE A 2tuple FILTER *** */
9188 struct cmd_2tuple_filter_result {
9189         cmdline_fixed_string_t filter;
9190         portid_t port_id;
9191         cmdline_fixed_string_t ops;
9192         cmdline_fixed_string_t dst_port;
9193         uint16_t dst_port_value;
9194         cmdline_fixed_string_t protocol;
9195         uint8_t protocol_value;
9196         cmdline_fixed_string_t mask;
9197         uint8_t  mask_value;
9198         cmdline_fixed_string_t tcp_flags;
9199         uint8_t tcp_flags_value;
9200         cmdline_fixed_string_t priority;
9201         uint8_t  priority_value;
9202         cmdline_fixed_string_t queue;
9203         uint16_t  queue_id;
9204 };
9205
9206 static void
9207 cmd_2tuple_filter_parsed(void *parsed_result,
9208                         __attribute__((unused)) struct cmdline *cl,
9209                         __attribute__((unused)) void *data)
9210 {
9211         struct rte_eth_ntuple_filter filter;
9212         struct cmd_2tuple_filter_result *res = parsed_result;
9213         int ret = 0;
9214
9215         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9216         if (ret < 0) {
9217                 printf("ntuple filter is not supported on port %u.\n",
9218                         res->port_id);
9219                 return;
9220         }
9221
9222         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9223
9224         filter.flags = RTE_2TUPLE_FLAGS;
9225         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9226         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9227         filter.proto = res->protocol_value;
9228         filter.priority = res->priority_value;
9229         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9230                 printf("nonzero tcp_flags is only meaningful"
9231                         " when protocol is TCP.\n");
9232                 return;
9233         }
9234         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9235                 printf("invalid TCP flags.\n");
9236                 return;
9237         }
9238
9239         if (res->tcp_flags_value != 0) {
9240                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9241                 filter.tcp_flags = res->tcp_flags_value;
9242         }
9243
9244         /* need convert to big endian. */
9245         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9246         filter.queue = res->queue_id;
9247
9248         if (!strcmp(res->ops, "add"))
9249                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9250                                 RTE_ETH_FILTER_NTUPLE,
9251                                 RTE_ETH_FILTER_ADD,
9252                                 &filter);
9253         else
9254                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9255                                 RTE_ETH_FILTER_NTUPLE,
9256                                 RTE_ETH_FILTER_DELETE,
9257                                 &filter);
9258         if (ret < 0)
9259                 printf("2tuple filter programming error: (%s)\n",
9260                         strerror(-ret));
9261
9262 }
9263
9264 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9265         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9266                                  filter, "2tuple_filter");
9267 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9268         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9269                                 port_id, UINT16);
9270 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9271         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9272                                  ops, "add#del");
9273 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9274         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9275                                 dst_port, "dst_port");
9276 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9277         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9278                                 dst_port_value, UINT16);
9279 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9280         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9281                                 protocol, "protocol");
9282 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9283         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9284                                 protocol_value, UINT8);
9285 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9286         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9287                                 mask, "mask");
9288 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9289         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9290                                 mask_value, INT8);
9291 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9292         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9293                                 tcp_flags, "tcp_flags");
9294 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9295         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9296                                 tcp_flags_value, UINT8);
9297 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9298         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9299                                 priority, "priority");
9300 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9301         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9302                                 priority_value, UINT8);
9303 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9304         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9305                                 queue, "queue");
9306 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9307         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9308                                 queue_id, UINT16);
9309
9310 cmdline_parse_inst_t cmd_2tuple_filter = {
9311         .f = cmd_2tuple_filter_parsed,
9312         .data = NULL,
9313         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9314                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9315                 "<queue_id>: Add a 2tuple filter",
9316         .tokens = {
9317                 (void *)&cmd_2tuple_filter_filter,
9318                 (void *)&cmd_2tuple_filter_port_id,
9319                 (void *)&cmd_2tuple_filter_ops,
9320                 (void *)&cmd_2tuple_filter_dst_port,
9321                 (void *)&cmd_2tuple_filter_dst_port_value,
9322                 (void *)&cmd_2tuple_filter_protocol,
9323                 (void *)&cmd_2tuple_filter_protocol_value,
9324                 (void *)&cmd_2tuple_filter_mask,
9325                 (void *)&cmd_2tuple_filter_mask_value,
9326                 (void *)&cmd_2tuple_filter_tcp_flags,
9327                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9328                 (void *)&cmd_2tuple_filter_priority,
9329                 (void *)&cmd_2tuple_filter_priority_value,
9330                 (void *)&cmd_2tuple_filter_queue,
9331                 (void *)&cmd_2tuple_filter_queue_id,
9332                 NULL,
9333         },
9334 };
9335
9336 /* *** ADD/REMOVE A 5tuple FILTER *** */
9337 struct cmd_5tuple_filter_result {
9338         cmdline_fixed_string_t filter;
9339         portid_t port_id;
9340         cmdline_fixed_string_t ops;
9341         cmdline_fixed_string_t dst_ip;
9342         cmdline_ipaddr_t dst_ip_value;
9343         cmdline_fixed_string_t src_ip;
9344         cmdline_ipaddr_t src_ip_value;
9345         cmdline_fixed_string_t dst_port;
9346         uint16_t dst_port_value;
9347         cmdline_fixed_string_t src_port;
9348         uint16_t src_port_value;
9349         cmdline_fixed_string_t protocol;
9350         uint8_t protocol_value;
9351         cmdline_fixed_string_t mask;
9352         uint8_t  mask_value;
9353         cmdline_fixed_string_t tcp_flags;
9354         uint8_t tcp_flags_value;
9355         cmdline_fixed_string_t priority;
9356         uint8_t  priority_value;
9357         cmdline_fixed_string_t queue;
9358         uint16_t  queue_id;
9359 };
9360
9361 static void
9362 cmd_5tuple_filter_parsed(void *parsed_result,
9363                         __attribute__((unused)) struct cmdline *cl,
9364                         __attribute__((unused)) void *data)
9365 {
9366         struct rte_eth_ntuple_filter filter;
9367         struct cmd_5tuple_filter_result *res = parsed_result;
9368         int ret = 0;
9369
9370         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9371         if (ret < 0) {
9372                 printf("ntuple filter is not supported on port %u.\n",
9373                         res->port_id);
9374                 return;
9375         }
9376
9377         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9378
9379         filter.flags = RTE_5TUPLE_FLAGS;
9380         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9381         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9382         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9383         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9384         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9385         filter.proto = res->protocol_value;
9386         filter.priority = res->priority_value;
9387         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9388                 printf("nonzero tcp_flags is only meaningful"
9389                         " when protocol is TCP.\n");
9390                 return;
9391         }
9392         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9393                 printf("invalid TCP flags.\n");
9394                 return;
9395         }
9396
9397         if (res->tcp_flags_value != 0) {
9398                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9399                 filter.tcp_flags = res->tcp_flags_value;
9400         }
9401
9402         if (res->dst_ip_value.family == AF_INET)
9403                 /* no need to convert, already big endian. */
9404                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9405         else {
9406                 if (filter.dst_ip_mask == 0) {
9407                         printf("can not support ipv6 involved compare.\n");
9408                         return;
9409                 }
9410                 filter.dst_ip = 0;
9411         }
9412
9413         if (res->src_ip_value.family == AF_INET)
9414                 /* no need to convert, already big endian. */
9415                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9416         else {
9417                 if (filter.src_ip_mask == 0) {
9418                         printf("can not support ipv6 involved compare.\n");
9419                         return;
9420                 }
9421                 filter.src_ip = 0;
9422         }
9423         /* need convert to big endian. */
9424         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9425         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9426         filter.queue = res->queue_id;
9427
9428         if (!strcmp(res->ops, "add"))
9429                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9430                                 RTE_ETH_FILTER_NTUPLE,
9431                                 RTE_ETH_FILTER_ADD,
9432                                 &filter);
9433         else
9434                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9435                                 RTE_ETH_FILTER_NTUPLE,
9436                                 RTE_ETH_FILTER_DELETE,
9437                                 &filter);
9438         if (ret < 0)
9439                 printf("5tuple filter programming error: (%s)\n",
9440                         strerror(-ret));
9441 }
9442
9443 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9444         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9445                                  filter, "5tuple_filter");
9446 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9447         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9448                                 port_id, UINT16);
9449 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9450         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9451                                  ops, "add#del");
9452 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9453         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9454                                 dst_ip, "dst_ip");
9455 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9456         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9457                                 dst_ip_value);
9458 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9459         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9460                                 src_ip, "src_ip");
9461 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9462         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9463                                 src_ip_value);
9464 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9465         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9466                                 dst_port, "dst_port");
9467 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9468         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9469                                 dst_port_value, UINT16);
9470 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9471         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9472                                 src_port, "src_port");
9473 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9474         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9475                                 src_port_value, UINT16);
9476 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9477         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9478                                 protocol, "protocol");
9479 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9480         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9481                                 protocol_value, UINT8);
9482 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9483         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9484                                 mask, "mask");
9485 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9486         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9487                                 mask_value, INT8);
9488 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9489         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9490                                 tcp_flags, "tcp_flags");
9491 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9492         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9493                                 tcp_flags_value, UINT8);
9494 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9495         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9496                                 priority, "priority");
9497 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9498         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9499                                 priority_value, UINT8);
9500 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9501         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9502                                 queue, "queue");
9503 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9504         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9505                                 queue_id, UINT16);
9506
9507 cmdline_parse_inst_t cmd_5tuple_filter = {
9508         .f = cmd_5tuple_filter_parsed,
9509         .data = NULL,
9510         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9511                 "src_ip <value> dst_port <value> src_port <value> "
9512                 "protocol <value>  mask <value> tcp_flags <value> "
9513                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9514         .tokens = {
9515                 (void *)&cmd_5tuple_filter_filter,
9516                 (void *)&cmd_5tuple_filter_port_id,
9517                 (void *)&cmd_5tuple_filter_ops,
9518                 (void *)&cmd_5tuple_filter_dst_ip,
9519                 (void *)&cmd_5tuple_filter_dst_ip_value,
9520                 (void *)&cmd_5tuple_filter_src_ip,
9521                 (void *)&cmd_5tuple_filter_src_ip_value,
9522                 (void *)&cmd_5tuple_filter_dst_port,
9523                 (void *)&cmd_5tuple_filter_dst_port_value,
9524                 (void *)&cmd_5tuple_filter_src_port,
9525                 (void *)&cmd_5tuple_filter_src_port_value,
9526                 (void *)&cmd_5tuple_filter_protocol,
9527                 (void *)&cmd_5tuple_filter_protocol_value,
9528                 (void *)&cmd_5tuple_filter_mask,
9529                 (void *)&cmd_5tuple_filter_mask_value,
9530                 (void *)&cmd_5tuple_filter_tcp_flags,
9531                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9532                 (void *)&cmd_5tuple_filter_priority,
9533                 (void *)&cmd_5tuple_filter_priority_value,
9534                 (void *)&cmd_5tuple_filter_queue,
9535                 (void *)&cmd_5tuple_filter_queue_id,
9536                 NULL,
9537         },
9538 };
9539
9540 /* *** ADD/REMOVE A flex FILTER *** */
9541 struct cmd_flex_filter_result {
9542         cmdline_fixed_string_t filter;
9543         cmdline_fixed_string_t ops;
9544         portid_t port_id;
9545         cmdline_fixed_string_t len;
9546         uint8_t len_value;
9547         cmdline_fixed_string_t bytes;
9548         cmdline_fixed_string_t bytes_value;
9549         cmdline_fixed_string_t mask;
9550         cmdline_fixed_string_t mask_value;
9551         cmdline_fixed_string_t priority;
9552         uint8_t priority_value;
9553         cmdline_fixed_string_t queue;
9554         uint16_t queue_id;
9555 };
9556
9557 static int xdigit2val(unsigned char c)
9558 {
9559         int val;
9560         if (isdigit(c))
9561                 val = c - '0';
9562         else if (isupper(c))
9563                 val = c - 'A' + 10;
9564         else
9565                 val = c - 'a' + 10;
9566         return val;
9567 }
9568
9569 static void
9570 cmd_flex_filter_parsed(void *parsed_result,
9571                           __attribute__((unused)) struct cmdline *cl,
9572                           __attribute__((unused)) void *data)
9573 {
9574         int ret = 0;
9575         struct rte_eth_flex_filter filter;
9576         struct cmd_flex_filter_result *res = parsed_result;
9577         char *bytes_ptr, *mask_ptr;
9578         uint16_t len, i, j = 0;
9579         char c;
9580         int val;
9581         uint8_t byte = 0;
9582
9583         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9584                 printf("the len exceed the max length 128\n");
9585                 return;
9586         }
9587         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9588         filter.len = res->len_value;
9589         filter.priority = res->priority_value;
9590         filter.queue = res->queue_id;
9591         bytes_ptr = res->bytes_value;
9592         mask_ptr = res->mask_value;
9593
9594          /* translate bytes string to array. */
9595         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9596                 (bytes_ptr[1] == 'X')))
9597                 bytes_ptr += 2;
9598         len = strnlen(bytes_ptr, res->len_value * 2);
9599         if (len == 0 || (len % 8 != 0)) {
9600                 printf("please check len and bytes input\n");
9601                 return;
9602         }
9603         for (i = 0; i < len; i++) {
9604                 c = bytes_ptr[i];
9605                 if (isxdigit(c) == 0) {
9606                         /* invalid characters. */
9607                         printf("invalid input\n");
9608                         return;
9609                 }
9610                 val = xdigit2val(c);
9611                 if (i % 2) {
9612                         byte |= val;
9613                         filter.bytes[j] = byte;
9614                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9615                         j++;
9616                         byte = 0;
9617                 } else
9618                         byte |= val << 4;
9619         }
9620         printf("\n");
9621          /* translate mask string to uint8_t array. */
9622         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9623                 (mask_ptr[1] == 'X')))
9624                 mask_ptr += 2;
9625         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9626         if (len == 0) {
9627                 printf("invalid input\n");
9628                 return;
9629         }
9630         j = 0;
9631         byte = 0;
9632         for (i = 0; i < len; i++) {
9633                 c = mask_ptr[i];
9634                 if (isxdigit(c) == 0) {
9635                         /* invalid characters. */
9636                         printf("invalid input\n");
9637                         return;
9638                 }
9639                 val = xdigit2val(c);
9640                 if (i % 2) {
9641                         byte |= val;
9642                         filter.mask[j] = byte;
9643                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9644                         j++;
9645                         byte = 0;
9646                 } else
9647                         byte |= val << 4;
9648         }
9649         printf("\n");
9650
9651         if (!strcmp(res->ops, "add"))
9652                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9653                                 RTE_ETH_FILTER_FLEXIBLE,
9654                                 RTE_ETH_FILTER_ADD,
9655                                 &filter);
9656         else
9657                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9658                                 RTE_ETH_FILTER_FLEXIBLE,
9659                                 RTE_ETH_FILTER_DELETE,
9660                                 &filter);
9661
9662         if (ret < 0)
9663                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9664 }
9665
9666 cmdline_parse_token_string_t cmd_flex_filter_filter =
9667         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9668                                 filter, "flex_filter");
9669 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9670         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9671                                 port_id, UINT16);
9672 cmdline_parse_token_string_t cmd_flex_filter_ops =
9673         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9674                                 ops, "add#del");
9675 cmdline_parse_token_string_t cmd_flex_filter_len =
9676         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9677                                 len, "len");
9678 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9679         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9680                                 len_value, UINT8);
9681 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9682         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9683                                 bytes, "bytes");
9684 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9685         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9686                                 bytes_value, NULL);
9687 cmdline_parse_token_string_t cmd_flex_filter_mask =
9688         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9689                                 mask, "mask");
9690 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9691         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9692                                 mask_value, NULL);
9693 cmdline_parse_token_string_t cmd_flex_filter_priority =
9694         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9695                                 priority, "priority");
9696 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9697         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9698                                 priority_value, UINT8);
9699 cmdline_parse_token_string_t cmd_flex_filter_queue =
9700         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9701                                 queue, "queue");
9702 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9703         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9704                                 queue_id, UINT16);
9705 cmdline_parse_inst_t cmd_flex_filter = {
9706         .f = cmd_flex_filter_parsed,
9707         .data = NULL,
9708         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9709                 "<value> mask <value> priority <value> queue <queue_id>: "
9710                 "Add/Del a flex filter",
9711         .tokens = {
9712                 (void *)&cmd_flex_filter_filter,
9713                 (void *)&cmd_flex_filter_port_id,
9714                 (void *)&cmd_flex_filter_ops,
9715                 (void *)&cmd_flex_filter_len,
9716                 (void *)&cmd_flex_filter_len_value,
9717                 (void *)&cmd_flex_filter_bytes,
9718                 (void *)&cmd_flex_filter_bytes_value,
9719                 (void *)&cmd_flex_filter_mask,
9720                 (void *)&cmd_flex_filter_mask_value,
9721                 (void *)&cmd_flex_filter_priority,
9722                 (void *)&cmd_flex_filter_priority_value,
9723                 (void *)&cmd_flex_filter_queue,
9724                 (void *)&cmd_flex_filter_queue_id,
9725                 NULL,
9726         },
9727 };
9728
9729 /* *** Filters Control *** */
9730
9731 /* *** deal with ethertype filter *** */
9732 struct cmd_ethertype_filter_result {
9733         cmdline_fixed_string_t filter;
9734         portid_t port_id;
9735         cmdline_fixed_string_t ops;
9736         cmdline_fixed_string_t mac;
9737         struct ether_addr mac_addr;
9738         cmdline_fixed_string_t ethertype;
9739         uint16_t ethertype_value;
9740         cmdline_fixed_string_t drop;
9741         cmdline_fixed_string_t queue;
9742         uint16_t  queue_id;
9743 };
9744
9745 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9746         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9747                                  filter, "ethertype_filter");
9748 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9749         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9750                               port_id, UINT16);
9751 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9752         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9753                                  ops, "add#del");
9754 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9755         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9756                                  mac, "mac_addr#mac_ignr");
9757 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9758         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9759                                      mac_addr);
9760 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9761         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9762                                  ethertype, "ethertype");
9763 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9764         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9765                               ethertype_value, UINT16);
9766 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9767         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9768                                  drop, "drop#fwd");
9769 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9770         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9771                                  queue, "queue");
9772 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9773         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9774                               queue_id, UINT16);
9775
9776 static void
9777 cmd_ethertype_filter_parsed(void *parsed_result,
9778                           __attribute__((unused)) struct cmdline *cl,
9779                           __attribute__((unused)) void *data)
9780 {
9781         struct cmd_ethertype_filter_result *res = parsed_result;
9782         struct rte_eth_ethertype_filter filter;
9783         int ret = 0;
9784
9785         ret = rte_eth_dev_filter_supported(res->port_id,
9786                         RTE_ETH_FILTER_ETHERTYPE);
9787         if (ret < 0) {
9788                 printf("ethertype filter is not supported on port %u.\n",
9789                         res->port_id);
9790                 return;
9791         }
9792
9793         memset(&filter, 0, sizeof(filter));
9794         if (!strcmp(res->mac, "mac_addr")) {
9795                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9796                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9797                         sizeof(struct ether_addr));
9798         }
9799         if (!strcmp(res->drop, "drop"))
9800                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9801         filter.ether_type = res->ethertype_value;
9802         filter.queue = res->queue_id;
9803
9804         if (!strcmp(res->ops, "add"))
9805                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9806                                 RTE_ETH_FILTER_ETHERTYPE,
9807                                 RTE_ETH_FILTER_ADD,
9808                                 &filter);
9809         else
9810                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9811                                 RTE_ETH_FILTER_ETHERTYPE,
9812                                 RTE_ETH_FILTER_DELETE,
9813                                 &filter);
9814         if (ret < 0)
9815                 printf("ethertype filter programming error: (%s)\n",
9816                         strerror(-ret));
9817 }
9818
9819 cmdline_parse_inst_t cmd_ethertype_filter = {
9820         .f = cmd_ethertype_filter_parsed,
9821         .data = NULL,
9822         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9823                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9824                 "Add or delete an ethertype filter entry",
9825         .tokens = {
9826                 (void *)&cmd_ethertype_filter_filter,
9827                 (void *)&cmd_ethertype_filter_port_id,
9828                 (void *)&cmd_ethertype_filter_ops,
9829                 (void *)&cmd_ethertype_filter_mac,
9830                 (void *)&cmd_ethertype_filter_mac_addr,
9831                 (void *)&cmd_ethertype_filter_ethertype,
9832                 (void *)&cmd_ethertype_filter_ethertype_value,
9833                 (void *)&cmd_ethertype_filter_drop,
9834                 (void *)&cmd_ethertype_filter_queue,
9835                 (void *)&cmd_ethertype_filter_queue_id,
9836                 NULL,
9837         },
9838 };
9839
9840 /* *** deal with flow director filter *** */
9841 struct cmd_flow_director_result {
9842         cmdline_fixed_string_t flow_director_filter;
9843         portid_t port_id;
9844         cmdline_fixed_string_t mode;
9845         cmdline_fixed_string_t mode_value;
9846         cmdline_fixed_string_t ops;
9847         cmdline_fixed_string_t flow;
9848         cmdline_fixed_string_t flow_type;
9849         cmdline_fixed_string_t ether;
9850         uint16_t ether_type;
9851         cmdline_fixed_string_t src;
9852         cmdline_ipaddr_t ip_src;
9853         uint16_t port_src;
9854         cmdline_fixed_string_t dst;
9855         cmdline_ipaddr_t ip_dst;
9856         uint16_t port_dst;
9857         cmdline_fixed_string_t verify_tag;
9858         uint32_t verify_tag_value;
9859         cmdline_ipaddr_t tos;
9860         uint8_t tos_value;
9861         cmdline_ipaddr_t proto;
9862         uint8_t proto_value;
9863         cmdline_ipaddr_t ttl;
9864         uint8_t ttl_value;
9865         cmdline_fixed_string_t vlan;
9866         uint16_t vlan_value;
9867         cmdline_fixed_string_t flexbytes;
9868         cmdline_fixed_string_t flexbytes_value;
9869         cmdline_fixed_string_t pf_vf;
9870         cmdline_fixed_string_t drop;
9871         cmdline_fixed_string_t queue;
9872         uint16_t  queue_id;
9873         cmdline_fixed_string_t fd_id;
9874         uint32_t  fd_id_value;
9875         cmdline_fixed_string_t mac;
9876         struct ether_addr mac_addr;
9877         cmdline_fixed_string_t tunnel;
9878         cmdline_fixed_string_t tunnel_type;
9879         cmdline_fixed_string_t tunnel_id;
9880         uint32_t tunnel_id_value;
9881 };
9882
9883 static inline int
9884 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9885 {
9886         char s[256];
9887         const char *p, *p0 = q_arg;
9888         char *end;
9889         unsigned long int_fld;
9890         char *str_fld[max_num];
9891         int i;
9892         unsigned size;
9893         int ret = -1;
9894
9895         p = strchr(p0, '(');
9896         if (p == NULL)
9897                 return -1;
9898         ++p;
9899         p0 = strchr(p, ')');
9900         if (p0 == NULL)
9901                 return -1;
9902
9903         size = p0 - p;
9904         if (size >= sizeof(s))
9905                 return -1;
9906
9907         snprintf(s, sizeof(s), "%.*s", size, p);
9908         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9909         if (ret < 0 || ret > max_num)
9910                 return -1;
9911         for (i = 0; i < ret; i++) {
9912                 errno = 0;
9913                 int_fld = strtoul(str_fld[i], &end, 0);
9914                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9915                         return -1;
9916                 flexbytes[i] = (uint8_t)int_fld;
9917         }
9918         return ret;
9919 }
9920
9921 static uint16_t
9922 str2flowtype(char *string)
9923 {
9924         uint8_t i = 0;
9925         static const struct {
9926                 char str[32];
9927                 uint16_t type;
9928         } flowtype_str[] = {
9929                 {"raw", RTE_ETH_FLOW_RAW},
9930                 {"ipv4", RTE_ETH_FLOW_IPV4},
9931                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9932                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9933                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9934                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9935                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9936                 {"ipv6", RTE_ETH_FLOW_IPV6},
9937                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9938                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9939                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9940                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9941                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9942                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9943         };
9944
9945         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9946                 if (!strcmp(flowtype_str[i].str, string))
9947                         return flowtype_str[i].type;
9948         }
9949
9950         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9951                 return (uint16_t)atoi(string);
9952
9953         return RTE_ETH_FLOW_UNKNOWN;
9954 }
9955
9956 static enum rte_eth_fdir_tunnel_type
9957 str2fdir_tunneltype(char *string)
9958 {
9959         uint8_t i = 0;
9960
9961         static const struct {
9962                 char str[32];
9963                 enum rte_eth_fdir_tunnel_type type;
9964         } tunneltype_str[] = {
9965                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9966                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9967         };
9968
9969         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9970                 if (!strcmp(tunneltype_str[i].str, string))
9971                         return tunneltype_str[i].type;
9972         }
9973         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9974 }
9975
9976 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9977 do { \
9978         if ((ip_addr).family == AF_INET) \
9979                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9980         else { \
9981                 printf("invalid parameter.\n"); \
9982                 return; \
9983         } \
9984 } while (0)
9985
9986 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9987 do { \
9988         if ((ip_addr).family == AF_INET6) \
9989                 rte_memcpy(&(ip), \
9990                                  &((ip_addr).addr.ipv6), \
9991                                  sizeof(struct in6_addr)); \
9992         else { \
9993                 printf("invalid parameter.\n"); \
9994                 return; \
9995         } \
9996 } while (0)
9997
9998 static void
9999 cmd_flow_director_filter_parsed(void *parsed_result,
10000                           __attribute__((unused)) struct cmdline *cl,
10001                           __attribute__((unused)) void *data)
10002 {
10003         struct cmd_flow_director_result *res = parsed_result;
10004         struct rte_eth_fdir_filter entry;
10005         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10006         char *end;
10007         unsigned long vf_id;
10008         int ret = 0;
10009
10010         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10011         if (ret < 0) {
10012                 printf("flow director is not supported on port %u.\n",
10013                         res->port_id);
10014                 return;
10015         }
10016         memset(flexbytes, 0, sizeof(flexbytes));
10017         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10018
10019         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10020                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10021                         printf("Please set mode to MAC-VLAN.\n");
10022                         return;
10023                 }
10024         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10025                 if (strcmp(res->mode_value, "Tunnel")) {
10026                         printf("Please set mode to Tunnel.\n");
10027                         return;
10028                 }
10029         } else {
10030                 if (strcmp(res->mode_value, "IP")) {
10031                         printf("Please set mode to IP.\n");
10032                         return;
10033                 }
10034                 entry.input.flow_type = str2flowtype(res->flow_type);
10035         }
10036
10037         ret = parse_flexbytes(res->flexbytes_value,
10038                                         flexbytes,
10039                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10040         if (ret < 0) {
10041                 printf("error: Cannot parse flexbytes input.\n");
10042                 return;
10043         }
10044
10045         switch (entry.input.flow_type) {
10046         case RTE_ETH_FLOW_FRAG_IPV4:
10047         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10048                 entry.input.flow.ip4_flow.proto = res->proto_value;
10049                 /* fall-through */
10050         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10051         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10052                 IPV4_ADDR_TO_UINT(res->ip_dst,
10053                         entry.input.flow.ip4_flow.dst_ip);
10054                 IPV4_ADDR_TO_UINT(res->ip_src,
10055                         entry.input.flow.ip4_flow.src_ip);
10056                 entry.input.flow.ip4_flow.tos = res->tos_value;
10057                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10058                 /* need convert to big endian. */
10059                 entry.input.flow.udp4_flow.dst_port =
10060                                 rte_cpu_to_be_16(res->port_dst);
10061                 entry.input.flow.udp4_flow.src_port =
10062                                 rte_cpu_to_be_16(res->port_src);
10063                 break;
10064         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10065                 IPV4_ADDR_TO_UINT(res->ip_dst,
10066                         entry.input.flow.sctp4_flow.ip.dst_ip);
10067                 IPV4_ADDR_TO_UINT(res->ip_src,
10068                         entry.input.flow.sctp4_flow.ip.src_ip);
10069                 entry.input.flow.ip4_flow.tos = res->tos_value;
10070                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10071                 /* need convert to big endian. */
10072                 entry.input.flow.sctp4_flow.dst_port =
10073                                 rte_cpu_to_be_16(res->port_dst);
10074                 entry.input.flow.sctp4_flow.src_port =
10075                                 rte_cpu_to_be_16(res->port_src);
10076                 entry.input.flow.sctp4_flow.verify_tag =
10077                                 rte_cpu_to_be_32(res->verify_tag_value);
10078                 break;
10079         case RTE_ETH_FLOW_FRAG_IPV6:
10080         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10081                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10082                 /* fall-through */
10083         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10084         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10085                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10086                         entry.input.flow.ipv6_flow.dst_ip);
10087                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10088                         entry.input.flow.ipv6_flow.src_ip);
10089                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10090                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10091                 /* need convert to big endian. */
10092                 entry.input.flow.udp6_flow.dst_port =
10093                                 rte_cpu_to_be_16(res->port_dst);
10094                 entry.input.flow.udp6_flow.src_port =
10095                                 rte_cpu_to_be_16(res->port_src);
10096                 break;
10097         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10098                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10099                         entry.input.flow.sctp6_flow.ip.dst_ip);
10100                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10101                         entry.input.flow.sctp6_flow.ip.src_ip);
10102                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10103                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10104                 /* need convert to big endian. */
10105                 entry.input.flow.sctp6_flow.dst_port =
10106                                 rte_cpu_to_be_16(res->port_dst);
10107                 entry.input.flow.sctp6_flow.src_port =
10108                                 rte_cpu_to_be_16(res->port_src);
10109                 entry.input.flow.sctp6_flow.verify_tag =
10110                                 rte_cpu_to_be_32(res->verify_tag_value);
10111                 break;
10112         case RTE_ETH_FLOW_L2_PAYLOAD:
10113                 entry.input.flow.l2_flow.ether_type =
10114                         rte_cpu_to_be_16(res->ether_type);
10115                 break;
10116         default:
10117                 break;
10118         }
10119
10120         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10121                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10122                                  &res->mac_addr,
10123                                  sizeof(struct ether_addr));
10124
10125         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10126                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10127                                  &res->mac_addr,
10128                                  sizeof(struct ether_addr));
10129                 entry.input.flow.tunnel_flow.tunnel_type =
10130                         str2fdir_tunneltype(res->tunnel_type);
10131                 entry.input.flow.tunnel_flow.tunnel_id =
10132                         rte_cpu_to_be_32(res->tunnel_id_value);
10133         }
10134
10135         rte_memcpy(entry.input.flow_ext.flexbytes,
10136                    flexbytes,
10137                    RTE_ETH_FDIR_MAX_FLEXLEN);
10138
10139         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10140
10141         entry.action.flex_off = 0;  /*use 0 by default */
10142         if (!strcmp(res->drop, "drop"))
10143                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10144         else
10145                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10146
10147         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10148             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10149                 if (!strcmp(res->pf_vf, "pf"))
10150                         entry.input.flow_ext.is_vf = 0;
10151                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10152                         struct rte_eth_dev_info dev_info;
10153
10154                         memset(&dev_info, 0, sizeof(dev_info));
10155                         rte_eth_dev_info_get(res->port_id, &dev_info);
10156                         errno = 0;
10157                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10158                         if (errno != 0 || *end != '\0' ||
10159                             vf_id >= dev_info.max_vfs) {
10160                                 printf("invalid parameter %s.\n", res->pf_vf);
10161                                 return;
10162                         }
10163                         entry.input.flow_ext.is_vf = 1;
10164                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10165                 } else {
10166                         printf("invalid parameter %s.\n", res->pf_vf);
10167                         return;
10168                 }
10169         }
10170
10171         /* set to report FD ID by default */
10172         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10173         entry.action.rx_queue = res->queue_id;
10174         entry.soft_id = res->fd_id_value;
10175         if (!strcmp(res->ops, "add"))
10176                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10177                                              RTE_ETH_FILTER_ADD, &entry);
10178         else if (!strcmp(res->ops, "del"))
10179                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10180                                              RTE_ETH_FILTER_DELETE, &entry);
10181         else
10182                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10183                                              RTE_ETH_FILTER_UPDATE, &entry);
10184         if (ret < 0)
10185                 printf("flow director programming error: (%s)\n",
10186                         strerror(-ret));
10187 }
10188
10189 cmdline_parse_token_string_t cmd_flow_director_filter =
10190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10191                                  flow_director_filter, "flow_director_filter");
10192 cmdline_parse_token_num_t cmd_flow_director_port_id =
10193         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10194                               port_id, UINT16);
10195 cmdline_parse_token_string_t cmd_flow_director_ops =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10197                                  ops, "add#del#update");
10198 cmdline_parse_token_string_t cmd_flow_director_flow =
10199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10200                                  flow, "flow");
10201 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10203                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10204                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10205 cmdline_parse_token_string_t cmd_flow_director_ether =
10206         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10207                                  ether, "ether");
10208 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10209         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10210                               ether_type, UINT16);
10211 cmdline_parse_token_string_t cmd_flow_director_src =
10212         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10213                                  src, "src");
10214 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10215         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10216                                  ip_src);
10217 cmdline_parse_token_num_t cmd_flow_director_port_src =
10218         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10219                               port_src, UINT16);
10220 cmdline_parse_token_string_t cmd_flow_director_dst =
10221         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10222                                  dst, "dst");
10223 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10224         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10225                                  ip_dst);
10226 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10227         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10228                               port_dst, UINT16);
10229 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10231                                   verify_tag, "verify_tag");
10232 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10233         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10234                               verify_tag_value, UINT32);
10235 cmdline_parse_token_string_t cmd_flow_director_tos =
10236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10237                                  tos, "tos");
10238 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10239         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10240                               tos_value, UINT8);
10241 cmdline_parse_token_string_t cmd_flow_director_proto =
10242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10243                                  proto, "proto");
10244 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10245         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10246                               proto_value, UINT8);
10247 cmdline_parse_token_string_t cmd_flow_director_ttl =
10248         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10249                                  ttl, "ttl");
10250 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10251         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10252                               ttl_value, UINT8);
10253 cmdline_parse_token_string_t cmd_flow_director_vlan =
10254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10255                                  vlan, "vlan");
10256 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10258                               vlan_value, UINT16);
10259 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10261                                  flexbytes, "flexbytes");
10262 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10264                               flexbytes_value, NULL);
10265 cmdline_parse_token_string_t cmd_flow_director_drop =
10266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10267                                  drop, "drop#fwd");
10268 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10270                               pf_vf, NULL);
10271 cmdline_parse_token_string_t cmd_flow_director_queue =
10272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10273                                  queue, "queue");
10274 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10275         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10276                               queue_id, UINT16);
10277 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10279                                  fd_id, "fd_id");
10280 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10282                               fd_id_value, UINT32);
10283
10284 cmdline_parse_token_string_t cmd_flow_director_mode =
10285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10286                                  mode, "mode");
10287 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10289                                  mode_value, "IP");
10290 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10292                                  mode_value, "MAC-VLAN");
10293 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10295                                  mode_value, "Tunnel");
10296 cmdline_parse_token_string_t cmd_flow_director_mac =
10297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10298                                  mac, "mac");
10299 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10300         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10301                                     mac_addr);
10302 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10304                                  tunnel, "tunnel");
10305 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10306         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10307                                  tunnel_type, "NVGRE#VxLAN");
10308 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10310                                  tunnel_id, "tunnel-id");
10311 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10312         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10313                               tunnel_id_value, UINT32);
10314
10315 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10316         .f = cmd_flow_director_filter_parsed,
10317         .data = NULL,
10318         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10319                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10320                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10321                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10322                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10323                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10324                 "fd_id <fd_id_value>: "
10325                 "Add or delete an ip flow director entry on NIC",
10326         .tokens = {
10327                 (void *)&cmd_flow_director_filter,
10328                 (void *)&cmd_flow_director_port_id,
10329                 (void *)&cmd_flow_director_mode,
10330                 (void *)&cmd_flow_director_mode_ip,
10331                 (void *)&cmd_flow_director_ops,
10332                 (void *)&cmd_flow_director_flow,
10333                 (void *)&cmd_flow_director_flow_type,
10334                 (void *)&cmd_flow_director_src,
10335                 (void *)&cmd_flow_director_ip_src,
10336                 (void *)&cmd_flow_director_dst,
10337                 (void *)&cmd_flow_director_ip_dst,
10338                 (void *)&cmd_flow_director_tos,
10339                 (void *)&cmd_flow_director_tos_value,
10340                 (void *)&cmd_flow_director_proto,
10341                 (void *)&cmd_flow_director_proto_value,
10342                 (void *)&cmd_flow_director_ttl,
10343                 (void *)&cmd_flow_director_ttl_value,
10344                 (void *)&cmd_flow_director_vlan,
10345                 (void *)&cmd_flow_director_vlan_value,
10346                 (void *)&cmd_flow_director_flexbytes,
10347                 (void *)&cmd_flow_director_flexbytes_value,
10348                 (void *)&cmd_flow_director_drop,
10349                 (void *)&cmd_flow_director_pf_vf,
10350                 (void *)&cmd_flow_director_queue,
10351                 (void *)&cmd_flow_director_queue_id,
10352                 (void *)&cmd_flow_director_fd_id,
10353                 (void *)&cmd_flow_director_fd_id_value,
10354                 NULL,
10355         },
10356 };
10357
10358 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10359         .f = cmd_flow_director_filter_parsed,
10360         .data = NULL,
10361         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10362                 "director entry on NIC",
10363         .tokens = {
10364                 (void *)&cmd_flow_director_filter,
10365                 (void *)&cmd_flow_director_port_id,
10366                 (void *)&cmd_flow_director_mode,
10367                 (void *)&cmd_flow_director_mode_ip,
10368                 (void *)&cmd_flow_director_ops,
10369                 (void *)&cmd_flow_director_flow,
10370                 (void *)&cmd_flow_director_flow_type,
10371                 (void *)&cmd_flow_director_src,
10372                 (void *)&cmd_flow_director_ip_src,
10373                 (void *)&cmd_flow_director_port_src,
10374                 (void *)&cmd_flow_director_dst,
10375                 (void *)&cmd_flow_director_ip_dst,
10376                 (void *)&cmd_flow_director_port_dst,
10377                 (void *)&cmd_flow_director_tos,
10378                 (void *)&cmd_flow_director_tos_value,
10379                 (void *)&cmd_flow_director_ttl,
10380                 (void *)&cmd_flow_director_ttl_value,
10381                 (void *)&cmd_flow_director_vlan,
10382                 (void *)&cmd_flow_director_vlan_value,
10383                 (void *)&cmd_flow_director_flexbytes,
10384                 (void *)&cmd_flow_director_flexbytes_value,
10385                 (void *)&cmd_flow_director_drop,
10386                 (void *)&cmd_flow_director_pf_vf,
10387                 (void *)&cmd_flow_director_queue,
10388                 (void *)&cmd_flow_director_queue_id,
10389                 (void *)&cmd_flow_director_fd_id,
10390                 (void *)&cmd_flow_director_fd_id_value,
10391                 NULL,
10392         },
10393 };
10394
10395 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10396         .f = cmd_flow_director_filter_parsed,
10397         .data = NULL,
10398         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10399                 "director entry on NIC",
10400         .tokens = {
10401                 (void *)&cmd_flow_director_filter,
10402                 (void *)&cmd_flow_director_port_id,
10403                 (void *)&cmd_flow_director_mode,
10404                 (void *)&cmd_flow_director_mode_ip,
10405                 (void *)&cmd_flow_director_ops,
10406                 (void *)&cmd_flow_director_flow,
10407                 (void *)&cmd_flow_director_flow_type,
10408                 (void *)&cmd_flow_director_src,
10409                 (void *)&cmd_flow_director_ip_src,
10410                 (void *)&cmd_flow_director_port_dst,
10411                 (void *)&cmd_flow_director_dst,
10412                 (void *)&cmd_flow_director_ip_dst,
10413                 (void *)&cmd_flow_director_port_dst,
10414                 (void *)&cmd_flow_director_verify_tag,
10415                 (void *)&cmd_flow_director_verify_tag_value,
10416                 (void *)&cmd_flow_director_tos,
10417                 (void *)&cmd_flow_director_tos_value,
10418                 (void *)&cmd_flow_director_ttl,
10419                 (void *)&cmd_flow_director_ttl_value,
10420                 (void *)&cmd_flow_director_vlan,
10421                 (void *)&cmd_flow_director_vlan_value,
10422                 (void *)&cmd_flow_director_flexbytes,
10423                 (void *)&cmd_flow_director_flexbytes_value,
10424                 (void *)&cmd_flow_director_drop,
10425                 (void *)&cmd_flow_director_pf_vf,
10426                 (void *)&cmd_flow_director_queue,
10427                 (void *)&cmd_flow_director_queue_id,
10428                 (void *)&cmd_flow_director_fd_id,
10429                 (void *)&cmd_flow_director_fd_id_value,
10430                 NULL,
10431         },
10432 };
10433
10434 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10435         .f = cmd_flow_director_filter_parsed,
10436         .data = NULL,
10437         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10438                 "director entry on NIC",
10439         .tokens = {
10440                 (void *)&cmd_flow_director_filter,
10441                 (void *)&cmd_flow_director_port_id,
10442                 (void *)&cmd_flow_director_mode,
10443                 (void *)&cmd_flow_director_mode_ip,
10444                 (void *)&cmd_flow_director_ops,
10445                 (void *)&cmd_flow_director_flow,
10446                 (void *)&cmd_flow_director_flow_type,
10447                 (void *)&cmd_flow_director_ether,
10448                 (void *)&cmd_flow_director_ether_type,
10449                 (void *)&cmd_flow_director_flexbytes,
10450                 (void *)&cmd_flow_director_flexbytes_value,
10451                 (void *)&cmd_flow_director_drop,
10452                 (void *)&cmd_flow_director_pf_vf,
10453                 (void *)&cmd_flow_director_queue,
10454                 (void *)&cmd_flow_director_queue_id,
10455                 (void *)&cmd_flow_director_fd_id,
10456                 (void *)&cmd_flow_director_fd_id_value,
10457                 NULL,
10458         },
10459 };
10460
10461 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10462         .f = cmd_flow_director_filter_parsed,
10463         .data = NULL,
10464         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10465                 "director entry on NIC",
10466         .tokens = {
10467                 (void *)&cmd_flow_director_filter,
10468                 (void *)&cmd_flow_director_port_id,
10469                 (void *)&cmd_flow_director_mode,
10470                 (void *)&cmd_flow_director_mode_mac_vlan,
10471                 (void *)&cmd_flow_director_ops,
10472                 (void *)&cmd_flow_director_mac,
10473                 (void *)&cmd_flow_director_mac_addr,
10474                 (void *)&cmd_flow_director_vlan,
10475                 (void *)&cmd_flow_director_vlan_value,
10476                 (void *)&cmd_flow_director_flexbytes,
10477                 (void *)&cmd_flow_director_flexbytes_value,
10478                 (void *)&cmd_flow_director_drop,
10479                 (void *)&cmd_flow_director_queue,
10480                 (void *)&cmd_flow_director_queue_id,
10481                 (void *)&cmd_flow_director_fd_id,
10482                 (void *)&cmd_flow_director_fd_id_value,
10483                 NULL,
10484         },
10485 };
10486
10487 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10488         .f = cmd_flow_director_filter_parsed,
10489         .data = NULL,
10490         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10491                 "director entry on NIC",
10492         .tokens = {
10493                 (void *)&cmd_flow_director_filter,
10494                 (void *)&cmd_flow_director_port_id,
10495                 (void *)&cmd_flow_director_mode,
10496                 (void *)&cmd_flow_director_mode_tunnel,
10497                 (void *)&cmd_flow_director_ops,
10498                 (void *)&cmd_flow_director_mac,
10499                 (void *)&cmd_flow_director_mac_addr,
10500                 (void *)&cmd_flow_director_vlan,
10501                 (void *)&cmd_flow_director_vlan_value,
10502                 (void *)&cmd_flow_director_tunnel,
10503                 (void *)&cmd_flow_director_tunnel_type,
10504                 (void *)&cmd_flow_director_tunnel_id,
10505                 (void *)&cmd_flow_director_tunnel_id_value,
10506                 (void *)&cmd_flow_director_flexbytes,
10507                 (void *)&cmd_flow_director_flexbytes_value,
10508                 (void *)&cmd_flow_director_drop,
10509                 (void *)&cmd_flow_director_queue,
10510                 (void *)&cmd_flow_director_queue_id,
10511                 (void *)&cmd_flow_director_fd_id,
10512                 (void *)&cmd_flow_director_fd_id_value,
10513                 NULL,
10514         },
10515 };
10516
10517 struct cmd_flush_flow_director_result {
10518         cmdline_fixed_string_t flush_flow_director;
10519         portid_t port_id;
10520 };
10521
10522 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10523         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10524                                  flush_flow_director, "flush_flow_director");
10525 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10526         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10527                               port_id, UINT16);
10528
10529 static void
10530 cmd_flush_flow_director_parsed(void *parsed_result,
10531                           __attribute__((unused)) struct cmdline *cl,
10532                           __attribute__((unused)) void *data)
10533 {
10534         struct cmd_flow_director_result *res = parsed_result;
10535         int ret = 0;
10536
10537         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10538         if (ret < 0) {
10539                 printf("flow director is not supported on port %u.\n",
10540                         res->port_id);
10541                 return;
10542         }
10543
10544         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10545                         RTE_ETH_FILTER_FLUSH, NULL);
10546         if (ret < 0)
10547                 printf("flow director table flushing error: (%s)\n",
10548                         strerror(-ret));
10549 }
10550
10551 cmdline_parse_inst_t cmd_flush_flow_director = {
10552         .f = cmd_flush_flow_director_parsed,
10553         .data = NULL,
10554         .help_str = "flush_flow_director <port_id>: "
10555                 "Flush all flow director entries of a device on NIC",
10556         .tokens = {
10557                 (void *)&cmd_flush_flow_director_flush,
10558                 (void *)&cmd_flush_flow_director_port_id,
10559                 NULL,
10560         },
10561 };
10562
10563 /* *** deal with flow director mask *** */
10564 struct cmd_flow_director_mask_result {
10565         cmdline_fixed_string_t flow_director_mask;
10566         portid_t port_id;
10567         cmdline_fixed_string_t mode;
10568         cmdline_fixed_string_t mode_value;
10569         cmdline_fixed_string_t vlan;
10570         uint16_t vlan_mask;
10571         cmdline_fixed_string_t src_mask;
10572         cmdline_ipaddr_t ipv4_src;
10573         cmdline_ipaddr_t ipv6_src;
10574         uint16_t port_src;
10575         cmdline_fixed_string_t dst_mask;
10576         cmdline_ipaddr_t ipv4_dst;
10577         cmdline_ipaddr_t ipv6_dst;
10578         uint16_t port_dst;
10579         cmdline_fixed_string_t mac;
10580         uint8_t mac_addr_byte_mask;
10581         cmdline_fixed_string_t tunnel_id;
10582         uint32_t tunnel_id_mask;
10583         cmdline_fixed_string_t tunnel_type;
10584         uint8_t tunnel_type_mask;
10585 };
10586
10587 static void
10588 cmd_flow_director_mask_parsed(void *parsed_result,
10589                           __attribute__((unused)) struct cmdline *cl,
10590                           __attribute__((unused)) void *data)
10591 {
10592         struct cmd_flow_director_mask_result *res = parsed_result;
10593         struct rte_eth_fdir_masks *mask;
10594         struct rte_port *port;
10595
10596         if (res->port_id > nb_ports) {
10597                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10598                 return;
10599         }
10600
10601         port = &ports[res->port_id];
10602         /** Check if the port is not started **/
10603         if (port->port_status != RTE_PORT_STOPPED) {
10604                 printf("Please stop port %d first\n", res->port_id);
10605                 return;
10606         }
10607
10608         mask = &port->dev_conf.fdir_conf.mask;
10609
10610         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10611                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10612                         printf("Please set mode to MAC-VLAN.\n");
10613                         return;
10614                 }
10615
10616                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10617         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10618                 if (strcmp(res->mode_value, "Tunnel")) {
10619                         printf("Please set mode to Tunnel.\n");
10620                         return;
10621                 }
10622
10623                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10624                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10625                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10626                 mask->tunnel_type_mask = res->tunnel_type_mask;
10627         } else {
10628                 if (strcmp(res->mode_value, "IP")) {
10629                         printf("Please set mode to IP.\n");
10630                         return;
10631                 }
10632
10633                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10634                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10635                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10636                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10637                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10638                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10639                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10640         }
10641
10642         cmd_reconfig_device_queue(res->port_id, 1, 1);
10643 }
10644
10645 cmdline_parse_token_string_t cmd_flow_director_mask =
10646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10647                                  flow_director_mask, "flow_director_mask");
10648 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10649         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10650                               port_id, UINT16);
10651 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10652         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10653                                  vlan, "vlan");
10654 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10655         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10656                               vlan_mask, UINT16);
10657 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10658         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10659                                  src_mask, "src_mask");
10660 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10661         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10662                                  ipv4_src);
10663 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10664         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10665                                  ipv6_src);
10666 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10667         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10668                               port_src, UINT16);
10669 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10671                                  dst_mask, "dst_mask");
10672 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10673         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10674                                  ipv4_dst);
10675 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10676         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10677                                  ipv6_dst);
10678 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10679         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10680                               port_dst, UINT16);
10681
10682 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10684                                  mode, "mode");
10685 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10686         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10687                                  mode_value, "IP");
10688 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10690                                  mode_value, "MAC-VLAN");
10691 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10692         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10693                                  mode_value, "Tunnel");
10694 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10696                                  mac, "mac");
10697 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10698         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10699                               mac_addr_byte_mask, UINT8);
10700 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10702                                  tunnel_type, "tunnel-type");
10703 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10704         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10705                               tunnel_type_mask, UINT8);
10706 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10707         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10708                                  tunnel_id, "tunnel-id");
10709 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10710         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10711                               tunnel_id_mask, UINT32);
10712
10713 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10714         .f = cmd_flow_director_mask_parsed,
10715         .data = NULL,
10716         .help_str = "flow_director_mask ... : "
10717                 "Set IP mode flow director's mask on NIC",
10718         .tokens = {
10719                 (void *)&cmd_flow_director_mask,
10720                 (void *)&cmd_flow_director_mask_port_id,
10721                 (void *)&cmd_flow_director_mask_mode,
10722                 (void *)&cmd_flow_director_mask_mode_ip,
10723                 (void *)&cmd_flow_director_mask_vlan,
10724                 (void *)&cmd_flow_director_mask_vlan_value,
10725                 (void *)&cmd_flow_director_mask_src,
10726                 (void *)&cmd_flow_director_mask_ipv4_src,
10727                 (void *)&cmd_flow_director_mask_ipv6_src,
10728                 (void *)&cmd_flow_director_mask_port_src,
10729                 (void *)&cmd_flow_director_mask_dst,
10730                 (void *)&cmd_flow_director_mask_ipv4_dst,
10731                 (void *)&cmd_flow_director_mask_ipv6_dst,
10732                 (void *)&cmd_flow_director_mask_port_dst,
10733                 NULL,
10734         },
10735 };
10736
10737 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10738         .f = cmd_flow_director_mask_parsed,
10739         .data = NULL,
10740         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10741                 "flow director's mask on NIC",
10742         .tokens = {
10743                 (void *)&cmd_flow_director_mask,
10744                 (void *)&cmd_flow_director_mask_port_id,
10745                 (void *)&cmd_flow_director_mask_mode,
10746                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10747                 (void *)&cmd_flow_director_mask_vlan,
10748                 (void *)&cmd_flow_director_mask_vlan_value,
10749                 NULL,
10750         },
10751 };
10752
10753 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10754         .f = cmd_flow_director_mask_parsed,
10755         .data = NULL,
10756         .help_str = "flow_director_mask ... : Set tunnel mode "
10757                 "flow director's mask on NIC",
10758         .tokens = {
10759                 (void *)&cmd_flow_director_mask,
10760                 (void *)&cmd_flow_director_mask_port_id,
10761                 (void *)&cmd_flow_director_mask_mode,
10762                 (void *)&cmd_flow_director_mask_mode_tunnel,
10763                 (void *)&cmd_flow_director_mask_vlan,
10764                 (void *)&cmd_flow_director_mask_vlan_value,
10765                 (void *)&cmd_flow_director_mask_mac,
10766                 (void *)&cmd_flow_director_mask_mac_value,
10767                 (void *)&cmd_flow_director_mask_tunnel_type,
10768                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10769                 (void *)&cmd_flow_director_mask_tunnel_id,
10770                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10771                 NULL,
10772         },
10773 };
10774
10775 /* *** deal with flow director mask on flexible payload *** */
10776 struct cmd_flow_director_flex_mask_result {
10777         cmdline_fixed_string_t flow_director_flexmask;
10778         portid_t port_id;
10779         cmdline_fixed_string_t flow;
10780         cmdline_fixed_string_t flow_type;
10781         cmdline_fixed_string_t mask;
10782 };
10783
10784 static void
10785 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10786                           __attribute__((unused)) struct cmdline *cl,
10787                           __attribute__((unused)) void *data)
10788 {
10789         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10790         struct rte_eth_fdir_info fdir_info;
10791         struct rte_eth_fdir_flex_mask flex_mask;
10792         struct rte_port *port;
10793         uint32_t flow_type_mask;
10794         uint16_t i;
10795         int ret;
10796
10797         if (res->port_id > nb_ports) {
10798                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10799                 return;
10800         }
10801
10802         port = &ports[res->port_id];
10803         /** Check if the port is not started **/
10804         if (port->port_status != RTE_PORT_STOPPED) {
10805                 printf("Please stop port %d first\n", res->port_id);
10806                 return;
10807         }
10808
10809         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10810         ret = parse_flexbytes(res->mask,
10811                         flex_mask.mask,
10812                         RTE_ETH_FDIR_MAX_FLEXLEN);
10813         if (ret < 0) {
10814                 printf("error: Cannot parse mask input.\n");
10815                 return;
10816         }
10817
10818         memset(&fdir_info, 0, sizeof(fdir_info));
10819         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10820                                 RTE_ETH_FILTER_INFO, &fdir_info);
10821         if (ret < 0) {
10822                 printf("Cannot get FDir filter info\n");
10823                 return;
10824         }
10825
10826         if (!strcmp(res->flow_type, "none")) {
10827                 /* means don't specify the flow type */
10828                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10829                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10830                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10831                                0, sizeof(struct rte_eth_fdir_flex_mask));
10832                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10833                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10834                                  &flex_mask,
10835                                  sizeof(struct rte_eth_fdir_flex_mask));
10836                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10837                 return;
10838         }
10839         flow_type_mask = fdir_info.flow_types_mask[0];
10840         if (!strcmp(res->flow_type, "all")) {
10841                 if (!flow_type_mask) {
10842                         printf("No flow type supported\n");
10843                         return;
10844                 }
10845                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10846                         if (flow_type_mask & (1 << i)) {
10847                                 flex_mask.flow_type = i;
10848                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10849                         }
10850                 }
10851                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10852                 return;
10853         }
10854         flex_mask.flow_type = str2flowtype(res->flow_type);
10855         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10856                 printf("Flow type %s not supported on port %d\n",
10857                                 res->flow_type, res->port_id);
10858                 return;
10859         }
10860         fdir_set_flex_mask(res->port_id, &flex_mask);
10861         cmd_reconfig_device_queue(res->port_id, 1, 1);
10862 }
10863
10864 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10866                                  flow_director_flexmask,
10867                                  "flow_director_flex_mask");
10868 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10869         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10870                               port_id, UINT16);
10871 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10872         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10873                                  flow, "flow");
10874 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10875         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10876                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10877                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10878 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10880                                  mask, NULL);
10881
10882 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10883         .f = cmd_flow_director_flex_mask_parsed,
10884         .data = NULL,
10885         .help_str = "flow_director_flex_mask ... : "
10886                 "Set flow director's flex mask on NIC",
10887         .tokens = {
10888                 (void *)&cmd_flow_director_flexmask,
10889                 (void *)&cmd_flow_director_flexmask_port_id,
10890                 (void *)&cmd_flow_director_flexmask_flow,
10891                 (void *)&cmd_flow_director_flexmask_flow_type,
10892                 (void *)&cmd_flow_director_flexmask_mask,
10893                 NULL,
10894         },
10895 };
10896
10897 /* *** deal with flow director flexible payload configuration *** */
10898 struct cmd_flow_director_flexpayload_result {
10899         cmdline_fixed_string_t flow_director_flexpayload;
10900         portid_t port_id;
10901         cmdline_fixed_string_t payload_layer;
10902         cmdline_fixed_string_t payload_cfg;
10903 };
10904
10905 static inline int
10906 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10907 {
10908         char s[256];
10909         const char *p, *p0 = q_arg;
10910         char *end;
10911         unsigned long int_fld;
10912         char *str_fld[max_num];
10913         int i;
10914         unsigned size;
10915         int ret = -1;
10916
10917         p = strchr(p0, '(');
10918         if (p == NULL)
10919                 return -1;
10920         ++p;
10921         p0 = strchr(p, ')');
10922         if (p0 == NULL)
10923                 return -1;
10924
10925         size = p0 - p;
10926         if (size >= sizeof(s))
10927                 return -1;
10928
10929         snprintf(s, sizeof(s), "%.*s", size, p);
10930         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10931         if (ret < 0 || ret > max_num)
10932                 return -1;
10933         for (i = 0; i < ret; i++) {
10934                 errno = 0;
10935                 int_fld = strtoul(str_fld[i], &end, 0);
10936                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10937                         return -1;
10938                 offsets[i] = (uint16_t)int_fld;
10939         }
10940         return ret;
10941 }
10942
10943 static void
10944 cmd_flow_director_flxpld_parsed(void *parsed_result,
10945                           __attribute__((unused)) struct cmdline *cl,
10946                           __attribute__((unused)) void *data)
10947 {
10948         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10949         struct rte_eth_flex_payload_cfg flex_cfg;
10950         struct rte_port *port;
10951         int ret = 0;
10952
10953         if (res->port_id > nb_ports) {
10954                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10955                 return;
10956         }
10957
10958         port = &ports[res->port_id];
10959         /** Check if the port is not started **/
10960         if (port->port_status != RTE_PORT_STOPPED) {
10961                 printf("Please stop port %d first\n", res->port_id);
10962                 return;
10963         }
10964
10965         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10966
10967         if (!strcmp(res->payload_layer, "raw"))
10968                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10969         else if (!strcmp(res->payload_layer, "l2"))
10970                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10971         else if (!strcmp(res->payload_layer, "l3"))
10972                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10973         else if (!strcmp(res->payload_layer, "l4"))
10974                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10975
10976         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10977                             RTE_ETH_FDIR_MAX_FLEXLEN);
10978         if (ret < 0) {
10979                 printf("error: Cannot parse flex payload input.\n");
10980                 return;
10981         }
10982
10983         fdir_set_flex_payload(res->port_id, &flex_cfg);
10984         cmd_reconfig_device_queue(res->port_id, 1, 1);
10985 }
10986
10987 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10988         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10989                                  flow_director_flexpayload,
10990                                  "flow_director_flex_payload");
10991 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10992         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10993                               port_id, UINT16);
10994 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10995         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10996                                  payload_layer, "raw#l2#l3#l4");
10997 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10998         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10999                                  payload_cfg, NULL);
11000
11001 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11002         .f = cmd_flow_director_flxpld_parsed,
11003         .data = NULL,
11004         .help_str = "flow_director_flexpayload ... : "
11005                 "Set flow director's flex payload on NIC",
11006         .tokens = {
11007                 (void *)&cmd_flow_director_flexpayload,
11008                 (void *)&cmd_flow_director_flexpayload_port_id,
11009                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11010                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11011                 NULL,
11012         },
11013 };
11014
11015 /* Generic flow interface command. */
11016 extern cmdline_parse_inst_t cmd_flow;
11017
11018 /* *** Classification Filters Control *** */
11019 /* *** Get symmetric hash enable per port *** */
11020 struct cmd_get_sym_hash_ena_per_port_result {
11021         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11022         portid_t port_id;
11023 };
11024
11025 static void
11026 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11027                                  __rte_unused struct cmdline *cl,
11028                                  __rte_unused void *data)
11029 {
11030         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11031         struct rte_eth_hash_filter_info info;
11032         int ret;
11033
11034         if (rte_eth_dev_filter_supported(res->port_id,
11035                                 RTE_ETH_FILTER_HASH) < 0) {
11036                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11037                                                         res->port_id);
11038                 return;
11039         }
11040
11041         memset(&info, 0, sizeof(info));
11042         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11043         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11044                                                 RTE_ETH_FILTER_GET, &info);
11045
11046         if (ret < 0) {
11047                 printf("Cannot get symmetric hash enable per port "
11048                                         "on port %u\n", res->port_id);
11049                 return;
11050         }
11051
11052         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11053                                 "enabled" : "disabled", res->port_id);
11054 }
11055
11056 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11057         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11058                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11059 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11060         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11061                 port_id, UINT16);
11062
11063 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11064         .f = cmd_get_sym_hash_per_port_parsed,
11065         .data = NULL,
11066         .help_str = "get_sym_hash_ena_per_port <port_id>",
11067         .tokens = {
11068                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11069                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11070                 NULL,
11071         },
11072 };
11073
11074 /* *** Set symmetric hash enable per port *** */
11075 struct cmd_set_sym_hash_ena_per_port_result {
11076         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11077         cmdline_fixed_string_t enable;
11078         portid_t port_id;
11079 };
11080
11081 static void
11082 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11083                                  __rte_unused struct cmdline *cl,
11084                                  __rte_unused void *data)
11085 {
11086         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11087         struct rte_eth_hash_filter_info info;
11088         int ret;
11089
11090         if (rte_eth_dev_filter_supported(res->port_id,
11091                                 RTE_ETH_FILTER_HASH) < 0) {
11092                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11093                                                         res->port_id);
11094                 return;
11095         }
11096
11097         memset(&info, 0, sizeof(info));
11098         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11099         if (!strcmp(res->enable, "enable"))
11100                 info.info.enable = 1;
11101         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11102                                         RTE_ETH_FILTER_SET, &info);
11103         if (ret < 0) {
11104                 printf("Cannot set symmetric hash enable per port on "
11105                                         "port %u\n", res->port_id);
11106                 return;
11107         }
11108         printf("Symmetric hash has been set to %s on port %u\n",
11109                                         res->enable, res->port_id);
11110 }
11111
11112 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11113         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11114                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11115 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11116         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11117                 port_id, UINT16);
11118 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11119         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11120                 enable, "enable#disable");
11121
11122 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11123         .f = cmd_set_sym_hash_per_port_parsed,
11124         .data = NULL,
11125         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11126         .tokens = {
11127                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11128                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11129                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11130                 NULL,
11131         },
11132 };
11133
11134 /* Get global config of hash function */
11135 struct cmd_get_hash_global_config_result {
11136         cmdline_fixed_string_t get_hash_global_config;
11137         portid_t port_id;
11138 };
11139
11140 static char *
11141 flowtype_to_str(uint16_t ftype)
11142 {
11143         uint16_t i;
11144         static struct {
11145                 char str[16];
11146                 uint16_t ftype;
11147         } ftype_table[] = {
11148                 {"ipv4", RTE_ETH_FLOW_IPV4},
11149                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11150                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11151                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11152                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11153                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11154                 {"ipv6", RTE_ETH_FLOW_IPV6},
11155                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11156                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11157                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11158                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11159                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11160                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11161                 {"port", RTE_ETH_FLOW_PORT},
11162                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11163                 {"geneve", RTE_ETH_FLOW_GENEVE},
11164                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11165         };
11166
11167         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11168                 if (ftype_table[i].ftype == ftype)
11169                         return ftype_table[i].str;
11170         }
11171
11172         return NULL;
11173 }
11174
11175 static void
11176 cmd_get_hash_global_config_parsed(void *parsed_result,
11177                                   __rte_unused struct cmdline *cl,
11178                                   __rte_unused void *data)
11179 {
11180         struct cmd_get_hash_global_config_result *res = parsed_result;
11181         struct rte_eth_hash_filter_info info;
11182         uint32_t idx, offset;
11183         uint16_t i;
11184         char *str;
11185         int ret;
11186
11187         if (rte_eth_dev_filter_supported(res->port_id,
11188                         RTE_ETH_FILTER_HASH) < 0) {
11189                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11190                                                         res->port_id);
11191                 return;
11192         }
11193
11194         memset(&info, 0, sizeof(info));
11195         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11196         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11197                                         RTE_ETH_FILTER_GET, &info);
11198         if (ret < 0) {
11199                 printf("Cannot get hash global configurations by port %d\n",
11200                                                         res->port_id);
11201                 return;
11202         }
11203
11204         switch (info.info.global_conf.hash_func) {
11205         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11206                 printf("Hash function is Toeplitz\n");
11207                 break;
11208         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11209                 printf("Hash function is Simple XOR\n");
11210                 break;
11211         default:
11212                 printf("Unknown hash function\n");
11213                 break;
11214         }
11215
11216         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11217                 idx = i / UINT32_BIT;
11218                 offset = i % UINT32_BIT;
11219                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11220                                                 (1UL << offset)))
11221                         continue;
11222                 str = flowtype_to_str(i);
11223                 if (!str)
11224                         continue;
11225                 printf("Symmetric hash is %s globally for flow type %s "
11226                                                         "by port %d\n",
11227                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11228                         (1UL << offset)) ? "enabled" : "disabled"), str,
11229                                                         res->port_id);
11230         }
11231 }
11232
11233 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11234         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11235                 get_hash_global_config, "get_hash_global_config");
11236 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11237         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11238                 port_id, UINT16);
11239
11240 cmdline_parse_inst_t cmd_get_hash_global_config = {
11241         .f = cmd_get_hash_global_config_parsed,
11242         .data = NULL,
11243         .help_str = "get_hash_global_config <port_id>",
11244         .tokens = {
11245                 (void *)&cmd_get_hash_global_config_all,
11246                 (void *)&cmd_get_hash_global_config_port_id,
11247                 NULL,
11248         },
11249 };
11250
11251 /* Set global config of hash function */
11252 struct cmd_set_hash_global_config_result {
11253         cmdline_fixed_string_t set_hash_global_config;
11254         portid_t port_id;
11255         cmdline_fixed_string_t hash_func;
11256         cmdline_fixed_string_t flow_type;
11257         cmdline_fixed_string_t enable;
11258 };
11259
11260 static void
11261 cmd_set_hash_global_config_parsed(void *parsed_result,
11262                                   __rte_unused struct cmdline *cl,
11263                                   __rte_unused void *data)
11264 {
11265         struct cmd_set_hash_global_config_result *res = parsed_result;
11266         struct rte_eth_hash_filter_info info;
11267         uint32_t ftype, idx, offset;
11268         int ret;
11269
11270         if (rte_eth_dev_filter_supported(res->port_id,
11271                                 RTE_ETH_FILTER_HASH) < 0) {
11272                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11273                                                         res->port_id);
11274                 return;
11275         }
11276         memset(&info, 0, sizeof(info));
11277         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11278         if (!strcmp(res->hash_func, "toeplitz"))
11279                 info.info.global_conf.hash_func =
11280                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11281         else if (!strcmp(res->hash_func, "simple_xor"))
11282                 info.info.global_conf.hash_func =
11283                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11284         else if (!strcmp(res->hash_func, "default"))
11285                 info.info.global_conf.hash_func =
11286                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11287
11288         ftype = str2flowtype(res->flow_type);
11289         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11290         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11291         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11292         if (!strcmp(res->enable, "enable"))
11293                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11294                                                 (1UL << offset);
11295         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11296                                         RTE_ETH_FILTER_SET, &info);
11297         if (ret < 0)
11298                 printf("Cannot set global hash configurations by port %d\n",
11299                                                         res->port_id);
11300         else
11301                 printf("Global hash configurations have been set "
11302                         "succcessfully by port %d\n", res->port_id);
11303 }
11304
11305 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11306         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11307                 set_hash_global_config, "set_hash_global_config");
11308 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11309         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11310                 port_id, UINT16);
11311 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11312         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11313                 hash_func, "toeplitz#simple_xor#default");
11314 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11315         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11316                 flow_type,
11317                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11318                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11319 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11320         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11321                 enable, "enable#disable");
11322
11323 cmdline_parse_inst_t cmd_set_hash_global_config = {
11324         .f = cmd_set_hash_global_config_parsed,
11325         .data = NULL,
11326         .help_str = "set_hash_global_config <port_id> "
11327                 "toeplitz|simple_xor|default "
11328                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11329                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11330                 "l2_payload enable|disable",
11331         .tokens = {
11332                 (void *)&cmd_set_hash_global_config_all,
11333                 (void *)&cmd_set_hash_global_config_port_id,
11334                 (void *)&cmd_set_hash_global_config_hash_func,
11335                 (void *)&cmd_set_hash_global_config_flow_type,
11336                 (void *)&cmd_set_hash_global_config_enable,
11337                 NULL,
11338         },
11339 };
11340
11341 /* Set hash input set */
11342 struct cmd_set_hash_input_set_result {
11343         cmdline_fixed_string_t set_hash_input_set;
11344         portid_t port_id;
11345         cmdline_fixed_string_t flow_type;
11346         cmdline_fixed_string_t inset_field;
11347         cmdline_fixed_string_t select;
11348 };
11349
11350 static enum rte_eth_input_set_field
11351 str2inset(char *string)
11352 {
11353         uint16_t i;
11354
11355         static const struct {
11356                 char str[32];
11357                 enum rte_eth_input_set_field inset;
11358         } inset_table[] = {
11359                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11360                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11361                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11362                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11363                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11364                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11365                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11366                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11367                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11368                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11369                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11370                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11371                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11372                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11373                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11374                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11375                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11376                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11377                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11378                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11379                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11380                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11381                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11382                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11383                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11384                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11385                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11386                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11387                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11388                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11389                 {"none", RTE_ETH_INPUT_SET_NONE},
11390         };
11391
11392         for (i = 0; i < RTE_DIM(inset_table); i++) {
11393                 if (!strcmp(string, inset_table[i].str))
11394                         return inset_table[i].inset;
11395         }
11396
11397         return RTE_ETH_INPUT_SET_UNKNOWN;
11398 }
11399
11400 static void
11401 cmd_set_hash_input_set_parsed(void *parsed_result,
11402                               __rte_unused struct cmdline *cl,
11403                               __rte_unused void *data)
11404 {
11405         struct cmd_set_hash_input_set_result *res = parsed_result;
11406         struct rte_eth_hash_filter_info info;
11407
11408         memset(&info, 0, sizeof(info));
11409         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11410         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11411         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11412         info.info.input_set_conf.inset_size = 1;
11413         if (!strcmp(res->select, "select"))
11414                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11415         else if (!strcmp(res->select, "add"))
11416                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11417         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11418                                 RTE_ETH_FILTER_SET, &info);
11419 }
11420
11421 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11422         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11423                 set_hash_input_set, "set_hash_input_set");
11424 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11425         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11426                 port_id, UINT16);
11427 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11428         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11429                 flow_type, NULL);
11430 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11431         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11432                 inset_field,
11433                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11434                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11435                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11436                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11437                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11438                 "fld-8th#none");
11439 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11440         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11441                 select, "select#add");
11442
11443 cmdline_parse_inst_t cmd_set_hash_input_set = {
11444         .f = cmd_set_hash_input_set_parsed,
11445         .data = NULL,
11446         .help_str = "set_hash_input_set <port_id> "
11447         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11448         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11449         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11450         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11451         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11452         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11453         "fld-7th|fld-8th|none select|add",
11454         .tokens = {
11455                 (void *)&cmd_set_hash_input_set_cmd,
11456                 (void *)&cmd_set_hash_input_set_port_id,
11457                 (void *)&cmd_set_hash_input_set_flow_type,
11458                 (void *)&cmd_set_hash_input_set_field,
11459                 (void *)&cmd_set_hash_input_set_select,
11460                 NULL,
11461         },
11462 };
11463
11464 /* Set flow director input set */
11465 struct cmd_set_fdir_input_set_result {
11466         cmdline_fixed_string_t set_fdir_input_set;
11467         portid_t port_id;
11468         cmdline_fixed_string_t flow_type;
11469         cmdline_fixed_string_t inset_field;
11470         cmdline_fixed_string_t select;
11471 };
11472
11473 static void
11474 cmd_set_fdir_input_set_parsed(void *parsed_result,
11475         __rte_unused struct cmdline *cl,
11476         __rte_unused void *data)
11477 {
11478         struct cmd_set_fdir_input_set_result *res = parsed_result;
11479         struct rte_eth_fdir_filter_info info;
11480
11481         memset(&info, 0, sizeof(info));
11482         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11483         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11484         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11485         info.info.input_set_conf.inset_size = 1;
11486         if (!strcmp(res->select, "select"))
11487                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11488         else if (!strcmp(res->select, "add"))
11489                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11490         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11491                 RTE_ETH_FILTER_SET, &info);
11492 }
11493
11494 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11495         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11496         set_fdir_input_set, "set_fdir_input_set");
11497 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11498         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11499         port_id, UINT16);
11500 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11501         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11502         flow_type,
11503         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11504         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11505 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11506         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11507         inset_field,
11508         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11509         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11510         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11511         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11512         "sctp-veri-tag#none");
11513 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11514         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11515         select, "select#add");
11516
11517 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11518         .f = cmd_set_fdir_input_set_parsed,
11519         .data = NULL,
11520         .help_str = "set_fdir_input_set <port_id> "
11521         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11522         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11523         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11524         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11525         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11526         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11527         "sctp-veri-tag|none select|add",
11528         .tokens = {
11529                 (void *)&cmd_set_fdir_input_set_cmd,
11530                 (void *)&cmd_set_fdir_input_set_port_id,
11531                 (void *)&cmd_set_fdir_input_set_flow_type,
11532                 (void *)&cmd_set_fdir_input_set_field,
11533                 (void *)&cmd_set_fdir_input_set_select,
11534                 NULL,
11535         },
11536 };
11537
11538 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11539 struct cmd_mcast_addr_result {
11540         cmdline_fixed_string_t mcast_addr_cmd;
11541         cmdline_fixed_string_t what;
11542         uint16_t port_num;
11543         struct ether_addr mc_addr;
11544 };
11545
11546 static void cmd_mcast_addr_parsed(void *parsed_result,
11547                 __attribute__((unused)) struct cmdline *cl,
11548                 __attribute__((unused)) void *data)
11549 {
11550         struct cmd_mcast_addr_result *res = parsed_result;
11551
11552         if (!is_multicast_ether_addr(&res->mc_addr)) {
11553                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11554                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11555                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11556                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11557                 return;
11558         }
11559         if (strcmp(res->what, "add") == 0)
11560                 mcast_addr_add(res->port_num, &res->mc_addr);
11561         else
11562                 mcast_addr_remove(res->port_num, &res->mc_addr);
11563 }
11564
11565 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11566         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11567                                  mcast_addr_cmd, "mcast_addr");
11568 cmdline_parse_token_string_t cmd_mcast_addr_what =
11569         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11570                                  "add#remove");
11571 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11572         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11573 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11574         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11575
11576 cmdline_parse_inst_t cmd_mcast_addr = {
11577         .f = cmd_mcast_addr_parsed,
11578         .data = (void *)0,
11579         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11580                 "Add/Remove multicast MAC address on port_id",
11581         .tokens = {
11582                 (void *)&cmd_mcast_addr_cmd,
11583                 (void *)&cmd_mcast_addr_what,
11584                 (void *)&cmd_mcast_addr_portnum,
11585                 (void *)&cmd_mcast_addr_addr,
11586                 NULL,
11587         },
11588 };
11589
11590 /* l2 tunnel config
11591  * only support E-tag now.
11592  */
11593
11594 /* Ether type config */
11595 struct cmd_config_l2_tunnel_eth_type_result {
11596         cmdline_fixed_string_t port;
11597         cmdline_fixed_string_t config;
11598         cmdline_fixed_string_t all;
11599         uint8_t id;
11600         cmdline_fixed_string_t l2_tunnel;
11601         cmdline_fixed_string_t l2_tunnel_type;
11602         cmdline_fixed_string_t eth_type;
11603         uint16_t eth_type_val;
11604 };
11605
11606 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11607         TOKEN_STRING_INITIALIZER
11608                 (struct cmd_config_l2_tunnel_eth_type_result,
11609                  port, "port");
11610 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11611         TOKEN_STRING_INITIALIZER
11612                 (struct cmd_config_l2_tunnel_eth_type_result,
11613                  config, "config");
11614 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11615         TOKEN_STRING_INITIALIZER
11616                 (struct cmd_config_l2_tunnel_eth_type_result,
11617                  all, "all");
11618 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11619         TOKEN_NUM_INITIALIZER
11620                 (struct cmd_config_l2_tunnel_eth_type_result,
11621                  id, UINT8);
11622 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11623         TOKEN_STRING_INITIALIZER
11624                 (struct cmd_config_l2_tunnel_eth_type_result,
11625                  l2_tunnel, "l2-tunnel");
11626 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11627         TOKEN_STRING_INITIALIZER
11628                 (struct cmd_config_l2_tunnel_eth_type_result,
11629                  l2_tunnel_type, "E-tag");
11630 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11631         TOKEN_STRING_INITIALIZER
11632                 (struct cmd_config_l2_tunnel_eth_type_result,
11633                  eth_type, "ether-type");
11634 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11635         TOKEN_NUM_INITIALIZER
11636                 (struct cmd_config_l2_tunnel_eth_type_result,
11637                  eth_type_val, UINT16);
11638
11639 static enum rte_eth_tunnel_type
11640 str2fdir_l2_tunnel_type(char *string)
11641 {
11642         uint32_t i = 0;
11643
11644         static const struct {
11645                 char str[32];
11646                 enum rte_eth_tunnel_type type;
11647         } l2_tunnel_type_str[] = {
11648                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11649         };
11650
11651         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11652                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11653                         return l2_tunnel_type_str[i].type;
11654         }
11655         return RTE_TUNNEL_TYPE_NONE;
11656 }
11657
11658 /* ether type config for all ports */
11659 static void
11660 cmd_config_l2_tunnel_eth_type_all_parsed
11661         (void *parsed_result,
11662          __attribute__((unused)) struct cmdline *cl,
11663          __attribute__((unused)) void *data)
11664 {
11665         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11666         struct rte_eth_l2_tunnel_conf entry;
11667         portid_t pid;
11668
11669         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11670         entry.ether_type = res->eth_type_val;
11671
11672         RTE_ETH_FOREACH_DEV(pid) {
11673                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11674         }
11675 }
11676
11677 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11678         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11679         .data = NULL,
11680         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11681         .tokens = {
11682                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11683                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11684                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11685                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11686                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11687                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11688                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11689                 NULL,
11690         },
11691 };
11692
11693 /* ether type config for a specific port */
11694 static void
11695 cmd_config_l2_tunnel_eth_type_specific_parsed(
11696         void *parsed_result,
11697         __attribute__((unused)) struct cmdline *cl,
11698         __attribute__((unused)) void *data)
11699 {
11700         struct cmd_config_l2_tunnel_eth_type_result *res =
11701                  parsed_result;
11702         struct rte_eth_l2_tunnel_conf entry;
11703
11704         if (port_id_is_invalid(res->id, ENABLED_WARN))
11705                 return;
11706
11707         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11708         entry.ether_type = res->eth_type_val;
11709
11710         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11711 }
11712
11713 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11714         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11715         .data = NULL,
11716         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11717         .tokens = {
11718                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11719                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11720                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11721                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11722                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11723                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11724                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11725                 NULL,
11726         },
11727 };
11728
11729 /* Enable/disable l2 tunnel */
11730 struct cmd_config_l2_tunnel_en_dis_result {
11731         cmdline_fixed_string_t port;
11732         cmdline_fixed_string_t config;
11733         cmdline_fixed_string_t all;
11734         uint8_t id;
11735         cmdline_fixed_string_t l2_tunnel;
11736         cmdline_fixed_string_t l2_tunnel_type;
11737         cmdline_fixed_string_t en_dis;
11738 };
11739
11740 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11741         TOKEN_STRING_INITIALIZER
11742                 (struct cmd_config_l2_tunnel_en_dis_result,
11743                  port, "port");
11744 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11745         TOKEN_STRING_INITIALIZER
11746                 (struct cmd_config_l2_tunnel_en_dis_result,
11747                  config, "config");
11748 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11749         TOKEN_STRING_INITIALIZER
11750                 (struct cmd_config_l2_tunnel_en_dis_result,
11751                  all, "all");
11752 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11753         TOKEN_NUM_INITIALIZER
11754                 (struct cmd_config_l2_tunnel_en_dis_result,
11755                  id, UINT8);
11756 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11757         TOKEN_STRING_INITIALIZER
11758                 (struct cmd_config_l2_tunnel_en_dis_result,
11759                  l2_tunnel, "l2-tunnel");
11760 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11761         TOKEN_STRING_INITIALIZER
11762                 (struct cmd_config_l2_tunnel_en_dis_result,
11763                  l2_tunnel_type, "E-tag");
11764 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11765         TOKEN_STRING_INITIALIZER
11766                 (struct cmd_config_l2_tunnel_en_dis_result,
11767                  en_dis, "enable#disable");
11768
11769 /* enable/disable l2 tunnel for all ports */
11770 static void
11771 cmd_config_l2_tunnel_en_dis_all_parsed(
11772         void *parsed_result,
11773         __attribute__((unused)) struct cmdline *cl,
11774         __attribute__((unused)) void *data)
11775 {
11776         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11777         struct rte_eth_l2_tunnel_conf entry;
11778         portid_t pid;
11779         uint8_t en;
11780
11781         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11782
11783         if (!strcmp("enable", res->en_dis))
11784                 en = 1;
11785         else
11786                 en = 0;
11787
11788         RTE_ETH_FOREACH_DEV(pid) {
11789                 rte_eth_dev_l2_tunnel_offload_set(pid,
11790                                                   &entry,
11791                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11792                                                   en);
11793         }
11794 }
11795
11796 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11797         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11798         .data = NULL,
11799         .help_str = "port config all l2-tunnel E-tag enable|disable",
11800         .tokens = {
11801                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11802                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11803                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11804                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11805                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11806                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11807                 NULL,
11808         },
11809 };
11810
11811 /* enable/disable l2 tunnel for a port */
11812 static void
11813 cmd_config_l2_tunnel_en_dis_specific_parsed(
11814         void *parsed_result,
11815         __attribute__((unused)) struct cmdline *cl,
11816         __attribute__((unused)) void *data)
11817 {
11818         struct cmd_config_l2_tunnel_en_dis_result *res =
11819                 parsed_result;
11820         struct rte_eth_l2_tunnel_conf entry;
11821
11822         if (port_id_is_invalid(res->id, ENABLED_WARN))
11823                 return;
11824
11825         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11826
11827         if (!strcmp("enable", res->en_dis))
11828                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11829                                                   &entry,
11830                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11831                                                   1);
11832         else
11833                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11834                                                   &entry,
11835                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11836                                                   0);
11837 }
11838
11839 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11840         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11841         .data = NULL,
11842         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11843         .tokens = {
11844                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11845                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11846                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11847                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11848                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11849                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11850                 NULL,
11851         },
11852 };
11853
11854 /* E-tag configuration */
11855
11856 /* Common result structure for all E-tag configuration */
11857 struct cmd_config_e_tag_result {
11858         cmdline_fixed_string_t e_tag;
11859         cmdline_fixed_string_t set;
11860         cmdline_fixed_string_t insertion;
11861         cmdline_fixed_string_t stripping;
11862         cmdline_fixed_string_t forwarding;
11863         cmdline_fixed_string_t filter;
11864         cmdline_fixed_string_t add;
11865         cmdline_fixed_string_t del;
11866         cmdline_fixed_string_t on;
11867         cmdline_fixed_string_t off;
11868         cmdline_fixed_string_t on_off;
11869         cmdline_fixed_string_t port_tag_id;
11870         uint32_t port_tag_id_val;
11871         cmdline_fixed_string_t e_tag_id;
11872         uint16_t e_tag_id_val;
11873         cmdline_fixed_string_t dst_pool;
11874         uint8_t dst_pool_val;
11875         cmdline_fixed_string_t port;
11876         portid_t port_id;
11877         cmdline_fixed_string_t vf;
11878         uint8_t vf_id;
11879 };
11880
11881 /* Common CLI fields for all E-tag configuration */
11882 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11883         TOKEN_STRING_INITIALIZER
11884                 (struct cmd_config_e_tag_result,
11885                  e_tag, "E-tag");
11886 cmdline_parse_token_string_t cmd_config_e_tag_set =
11887         TOKEN_STRING_INITIALIZER
11888                 (struct cmd_config_e_tag_result,
11889                  set, "set");
11890 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11891         TOKEN_STRING_INITIALIZER
11892                 (struct cmd_config_e_tag_result,
11893                  insertion, "insertion");
11894 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11895         TOKEN_STRING_INITIALIZER
11896                 (struct cmd_config_e_tag_result,
11897                  stripping, "stripping");
11898 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11899         TOKEN_STRING_INITIALIZER
11900                 (struct cmd_config_e_tag_result,
11901                  forwarding, "forwarding");
11902 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11903         TOKEN_STRING_INITIALIZER
11904                 (struct cmd_config_e_tag_result,
11905                  filter, "filter");
11906 cmdline_parse_token_string_t cmd_config_e_tag_add =
11907         TOKEN_STRING_INITIALIZER
11908                 (struct cmd_config_e_tag_result,
11909                  add, "add");
11910 cmdline_parse_token_string_t cmd_config_e_tag_del =
11911         TOKEN_STRING_INITIALIZER
11912                 (struct cmd_config_e_tag_result,
11913                  del, "del");
11914 cmdline_parse_token_string_t cmd_config_e_tag_on =
11915         TOKEN_STRING_INITIALIZER
11916                 (struct cmd_config_e_tag_result,
11917                  on, "on");
11918 cmdline_parse_token_string_t cmd_config_e_tag_off =
11919         TOKEN_STRING_INITIALIZER
11920                 (struct cmd_config_e_tag_result,
11921                  off, "off");
11922 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11923         TOKEN_STRING_INITIALIZER
11924                 (struct cmd_config_e_tag_result,
11925                  on_off, "on#off");
11926 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11927         TOKEN_STRING_INITIALIZER
11928                 (struct cmd_config_e_tag_result,
11929                  port_tag_id, "port-tag-id");
11930 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11931         TOKEN_NUM_INITIALIZER
11932                 (struct cmd_config_e_tag_result,
11933                  port_tag_id_val, UINT32);
11934 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11935         TOKEN_STRING_INITIALIZER
11936                 (struct cmd_config_e_tag_result,
11937                  e_tag_id, "e-tag-id");
11938 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11939         TOKEN_NUM_INITIALIZER
11940                 (struct cmd_config_e_tag_result,
11941                  e_tag_id_val, UINT16);
11942 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11943         TOKEN_STRING_INITIALIZER
11944                 (struct cmd_config_e_tag_result,
11945                  dst_pool, "dst-pool");
11946 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11947         TOKEN_NUM_INITIALIZER
11948                 (struct cmd_config_e_tag_result,
11949                  dst_pool_val, UINT8);
11950 cmdline_parse_token_string_t cmd_config_e_tag_port =
11951         TOKEN_STRING_INITIALIZER
11952                 (struct cmd_config_e_tag_result,
11953                  port, "port");
11954 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11955         TOKEN_NUM_INITIALIZER
11956                 (struct cmd_config_e_tag_result,
11957                  port_id, UINT16);
11958 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11959         TOKEN_STRING_INITIALIZER
11960                 (struct cmd_config_e_tag_result,
11961                  vf, "vf");
11962 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11963         TOKEN_NUM_INITIALIZER
11964                 (struct cmd_config_e_tag_result,
11965                  vf_id, UINT8);
11966
11967 /* E-tag insertion configuration */
11968 static void
11969 cmd_config_e_tag_insertion_en_parsed(
11970         void *parsed_result,
11971         __attribute__((unused)) struct cmdline *cl,
11972         __attribute__((unused)) void *data)
11973 {
11974         struct cmd_config_e_tag_result *res =
11975                 parsed_result;
11976         struct rte_eth_l2_tunnel_conf entry;
11977
11978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11979                 return;
11980
11981         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11982         entry.tunnel_id = res->port_tag_id_val;
11983         entry.vf_id = res->vf_id;
11984         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11985                                           &entry,
11986                                           ETH_L2_TUNNEL_INSERTION_MASK,
11987                                           1);
11988 }
11989
11990 static void
11991 cmd_config_e_tag_insertion_dis_parsed(
11992         void *parsed_result,
11993         __attribute__((unused)) struct cmdline *cl,
11994         __attribute__((unused)) void *data)
11995 {
11996         struct cmd_config_e_tag_result *res =
11997                 parsed_result;
11998         struct rte_eth_l2_tunnel_conf entry;
11999
12000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12001                 return;
12002
12003         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12004         entry.vf_id = res->vf_id;
12005
12006         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12007                                           &entry,
12008                                           ETH_L2_TUNNEL_INSERTION_MASK,
12009                                           0);
12010 }
12011
12012 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12013         .f = cmd_config_e_tag_insertion_en_parsed,
12014         .data = NULL,
12015         .help_str = "E-tag ... : E-tag insertion enable",
12016         .tokens = {
12017                 (void *)&cmd_config_e_tag_e_tag,
12018                 (void *)&cmd_config_e_tag_set,
12019                 (void *)&cmd_config_e_tag_insertion,
12020                 (void *)&cmd_config_e_tag_on,
12021                 (void *)&cmd_config_e_tag_port_tag_id,
12022                 (void *)&cmd_config_e_tag_port_tag_id_val,
12023                 (void *)&cmd_config_e_tag_port,
12024                 (void *)&cmd_config_e_tag_port_id,
12025                 (void *)&cmd_config_e_tag_vf,
12026                 (void *)&cmd_config_e_tag_vf_id,
12027                 NULL,
12028         },
12029 };
12030
12031 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12032         .f = cmd_config_e_tag_insertion_dis_parsed,
12033         .data = NULL,
12034         .help_str = "E-tag ... : E-tag insertion disable",
12035         .tokens = {
12036                 (void *)&cmd_config_e_tag_e_tag,
12037                 (void *)&cmd_config_e_tag_set,
12038                 (void *)&cmd_config_e_tag_insertion,
12039                 (void *)&cmd_config_e_tag_off,
12040                 (void *)&cmd_config_e_tag_port,
12041                 (void *)&cmd_config_e_tag_port_id,
12042                 (void *)&cmd_config_e_tag_vf,
12043                 (void *)&cmd_config_e_tag_vf_id,
12044                 NULL,
12045         },
12046 };
12047
12048 /* E-tag stripping configuration */
12049 static void
12050 cmd_config_e_tag_stripping_parsed(
12051         void *parsed_result,
12052         __attribute__((unused)) struct cmdline *cl,
12053         __attribute__((unused)) void *data)
12054 {
12055         struct cmd_config_e_tag_result *res =
12056                 parsed_result;
12057         struct rte_eth_l2_tunnel_conf entry;
12058
12059         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12060                 return;
12061
12062         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12063
12064         if (!strcmp(res->on_off, "on"))
12065                 rte_eth_dev_l2_tunnel_offload_set
12066                         (res->port_id,
12067                          &entry,
12068                          ETH_L2_TUNNEL_STRIPPING_MASK,
12069                          1);
12070         else
12071                 rte_eth_dev_l2_tunnel_offload_set
12072                         (res->port_id,
12073                          &entry,
12074                          ETH_L2_TUNNEL_STRIPPING_MASK,
12075                          0);
12076 }
12077
12078 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12079         .f = cmd_config_e_tag_stripping_parsed,
12080         .data = NULL,
12081         .help_str = "E-tag ... : E-tag stripping enable/disable",
12082         .tokens = {
12083                 (void *)&cmd_config_e_tag_e_tag,
12084                 (void *)&cmd_config_e_tag_set,
12085                 (void *)&cmd_config_e_tag_stripping,
12086                 (void *)&cmd_config_e_tag_on_off,
12087                 (void *)&cmd_config_e_tag_port,
12088                 (void *)&cmd_config_e_tag_port_id,
12089                 NULL,
12090         },
12091 };
12092
12093 /* E-tag forwarding configuration */
12094 static void
12095 cmd_config_e_tag_forwarding_parsed(
12096         void *parsed_result,
12097         __attribute__((unused)) struct cmdline *cl,
12098         __attribute__((unused)) void *data)
12099 {
12100         struct cmd_config_e_tag_result *res = parsed_result;
12101         struct rte_eth_l2_tunnel_conf entry;
12102
12103         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12104                 return;
12105
12106         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12107
12108         if (!strcmp(res->on_off, "on"))
12109                 rte_eth_dev_l2_tunnel_offload_set
12110                         (res->port_id,
12111                          &entry,
12112                          ETH_L2_TUNNEL_FORWARDING_MASK,
12113                          1);
12114         else
12115                 rte_eth_dev_l2_tunnel_offload_set
12116                         (res->port_id,
12117                          &entry,
12118                          ETH_L2_TUNNEL_FORWARDING_MASK,
12119                          0);
12120 }
12121
12122 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12123         .f = cmd_config_e_tag_forwarding_parsed,
12124         .data = NULL,
12125         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12126         .tokens = {
12127                 (void *)&cmd_config_e_tag_e_tag,
12128                 (void *)&cmd_config_e_tag_set,
12129                 (void *)&cmd_config_e_tag_forwarding,
12130                 (void *)&cmd_config_e_tag_on_off,
12131                 (void *)&cmd_config_e_tag_port,
12132                 (void *)&cmd_config_e_tag_port_id,
12133                 NULL,
12134         },
12135 };
12136
12137 /* E-tag filter configuration */
12138 static void
12139 cmd_config_e_tag_filter_add_parsed(
12140         void *parsed_result,
12141         __attribute__((unused)) struct cmdline *cl,
12142         __attribute__((unused)) void *data)
12143 {
12144         struct cmd_config_e_tag_result *res = parsed_result;
12145         struct rte_eth_l2_tunnel_conf entry;
12146         int ret = 0;
12147
12148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12149                 return;
12150
12151         if (res->e_tag_id_val > 0x3fff) {
12152                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12153                 return;
12154         }
12155
12156         ret = rte_eth_dev_filter_supported(res->port_id,
12157                                            RTE_ETH_FILTER_L2_TUNNEL);
12158         if (ret < 0) {
12159                 printf("E-tag filter is not supported on port %u.\n",
12160                        res->port_id);
12161                 return;
12162         }
12163
12164         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12165         entry.tunnel_id = res->e_tag_id_val;
12166         entry.pool = res->dst_pool_val;
12167
12168         ret = rte_eth_dev_filter_ctrl(res->port_id,
12169                                       RTE_ETH_FILTER_L2_TUNNEL,
12170                                       RTE_ETH_FILTER_ADD,
12171                                       &entry);
12172         if (ret < 0)
12173                 printf("E-tag filter programming error: (%s)\n",
12174                        strerror(-ret));
12175 }
12176
12177 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12178         .f = cmd_config_e_tag_filter_add_parsed,
12179         .data = NULL,
12180         .help_str = "E-tag ... : E-tag filter add",
12181         .tokens = {
12182                 (void *)&cmd_config_e_tag_e_tag,
12183                 (void *)&cmd_config_e_tag_set,
12184                 (void *)&cmd_config_e_tag_filter,
12185                 (void *)&cmd_config_e_tag_add,
12186                 (void *)&cmd_config_e_tag_e_tag_id,
12187                 (void *)&cmd_config_e_tag_e_tag_id_val,
12188                 (void *)&cmd_config_e_tag_dst_pool,
12189                 (void *)&cmd_config_e_tag_dst_pool_val,
12190                 (void *)&cmd_config_e_tag_port,
12191                 (void *)&cmd_config_e_tag_port_id,
12192                 NULL,
12193         },
12194 };
12195
12196 static void
12197 cmd_config_e_tag_filter_del_parsed(
12198         void *parsed_result,
12199         __attribute__((unused)) struct cmdline *cl,
12200         __attribute__((unused)) void *data)
12201 {
12202         struct cmd_config_e_tag_result *res = parsed_result;
12203         struct rte_eth_l2_tunnel_conf entry;
12204         int ret = 0;
12205
12206         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12207                 return;
12208
12209         if (res->e_tag_id_val > 0x3fff) {
12210                 printf("e-tag-id must be less than 0x3fff.\n");
12211                 return;
12212         }
12213
12214         ret = rte_eth_dev_filter_supported(res->port_id,
12215                                            RTE_ETH_FILTER_L2_TUNNEL);
12216         if (ret < 0) {
12217                 printf("E-tag filter is not supported on port %u.\n",
12218                        res->port_id);
12219                 return;
12220         }
12221
12222         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12223         entry.tunnel_id = res->e_tag_id_val;
12224
12225         ret = rte_eth_dev_filter_ctrl(res->port_id,
12226                                       RTE_ETH_FILTER_L2_TUNNEL,
12227                                       RTE_ETH_FILTER_DELETE,
12228                                       &entry);
12229         if (ret < 0)
12230                 printf("E-tag filter programming error: (%s)\n",
12231                        strerror(-ret));
12232 }
12233
12234 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12235         .f = cmd_config_e_tag_filter_del_parsed,
12236         .data = NULL,
12237         .help_str = "E-tag ... : E-tag filter delete",
12238         .tokens = {
12239                 (void *)&cmd_config_e_tag_e_tag,
12240                 (void *)&cmd_config_e_tag_set,
12241                 (void *)&cmd_config_e_tag_filter,
12242                 (void *)&cmd_config_e_tag_del,
12243                 (void *)&cmd_config_e_tag_e_tag_id,
12244                 (void *)&cmd_config_e_tag_e_tag_id_val,
12245                 (void *)&cmd_config_e_tag_port,
12246                 (void *)&cmd_config_e_tag_port_id,
12247                 NULL,
12248         },
12249 };
12250
12251 /* vf vlan anti spoof configuration */
12252
12253 /* Common result structure for vf vlan anti spoof */
12254 struct cmd_vf_vlan_anti_spoof_result {
12255         cmdline_fixed_string_t set;
12256         cmdline_fixed_string_t vf;
12257         cmdline_fixed_string_t vlan;
12258         cmdline_fixed_string_t antispoof;
12259         portid_t port_id;
12260         uint32_t vf_id;
12261         cmdline_fixed_string_t on_off;
12262 };
12263
12264 /* Common CLI fields for vf vlan anti spoof enable disable */
12265 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12266         TOKEN_STRING_INITIALIZER
12267                 (struct cmd_vf_vlan_anti_spoof_result,
12268                  set, "set");
12269 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12270         TOKEN_STRING_INITIALIZER
12271                 (struct cmd_vf_vlan_anti_spoof_result,
12272                  vf, "vf");
12273 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12274         TOKEN_STRING_INITIALIZER
12275                 (struct cmd_vf_vlan_anti_spoof_result,
12276                  vlan, "vlan");
12277 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12278         TOKEN_STRING_INITIALIZER
12279                 (struct cmd_vf_vlan_anti_spoof_result,
12280                  antispoof, "antispoof");
12281 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12282         TOKEN_NUM_INITIALIZER
12283                 (struct cmd_vf_vlan_anti_spoof_result,
12284                  port_id, UINT16);
12285 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12286         TOKEN_NUM_INITIALIZER
12287                 (struct cmd_vf_vlan_anti_spoof_result,
12288                  vf_id, UINT32);
12289 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12290         TOKEN_STRING_INITIALIZER
12291                 (struct cmd_vf_vlan_anti_spoof_result,
12292                  on_off, "on#off");
12293
12294 static void
12295 cmd_set_vf_vlan_anti_spoof_parsed(
12296         void *parsed_result,
12297         __attribute__((unused)) struct cmdline *cl,
12298         __attribute__((unused)) void *data)
12299 {
12300         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12301         int ret = -ENOTSUP;
12302
12303         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12304
12305         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12306                 return;
12307
12308 #ifdef RTE_LIBRTE_IXGBE_PMD
12309         if (ret == -ENOTSUP)
12310                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12311                                 res->vf_id, is_on);
12312 #endif
12313 #ifdef RTE_LIBRTE_I40E_PMD
12314         if (ret == -ENOTSUP)
12315                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12316                                 res->vf_id, is_on);
12317 #endif
12318 #ifdef RTE_LIBRTE_BNXT_PMD
12319         if (ret == -ENOTSUP)
12320                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12321                                 res->vf_id, is_on);
12322 #endif
12323
12324         switch (ret) {
12325         case 0:
12326                 break;
12327         case -EINVAL:
12328                 printf("invalid vf_id %d\n", res->vf_id);
12329                 break;
12330         case -ENODEV:
12331                 printf("invalid port_id %d\n", res->port_id);
12332                 break;
12333         case -ENOTSUP:
12334                 printf("function not implemented\n");
12335                 break;
12336         default:
12337                 printf("programming error: (%s)\n", strerror(-ret));
12338         }
12339 }
12340
12341 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12342         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12343         .data = NULL,
12344         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12345         .tokens = {
12346                 (void *)&cmd_vf_vlan_anti_spoof_set,
12347                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12348                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12349                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12350                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12351                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12352                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12353                 NULL,
12354         },
12355 };
12356
12357 /* vf mac anti spoof configuration */
12358
12359 /* Common result structure for vf mac anti spoof */
12360 struct cmd_vf_mac_anti_spoof_result {
12361         cmdline_fixed_string_t set;
12362         cmdline_fixed_string_t vf;
12363         cmdline_fixed_string_t mac;
12364         cmdline_fixed_string_t antispoof;
12365         portid_t port_id;
12366         uint32_t vf_id;
12367         cmdline_fixed_string_t on_off;
12368 };
12369
12370 /* Common CLI fields for vf mac anti spoof enable disable */
12371 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12372         TOKEN_STRING_INITIALIZER
12373                 (struct cmd_vf_mac_anti_spoof_result,
12374                  set, "set");
12375 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12376         TOKEN_STRING_INITIALIZER
12377                 (struct cmd_vf_mac_anti_spoof_result,
12378                  vf, "vf");
12379 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12380         TOKEN_STRING_INITIALIZER
12381                 (struct cmd_vf_mac_anti_spoof_result,
12382                  mac, "mac");
12383 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12384         TOKEN_STRING_INITIALIZER
12385                 (struct cmd_vf_mac_anti_spoof_result,
12386                  antispoof, "antispoof");
12387 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12388         TOKEN_NUM_INITIALIZER
12389                 (struct cmd_vf_mac_anti_spoof_result,
12390                  port_id, UINT16);
12391 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12392         TOKEN_NUM_INITIALIZER
12393                 (struct cmd_vf_mac_anti_spoof_result,
12394                  vf_id, UINT32);
12395 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12396         TOKEN_STRING_INITIALIZER
12397                 (struct cmd_vf_mac_anti_spoof_result,
12398                  on_off, "on#off");
12399
12400 static void
12401 cmd_set_vf_mac_anti_spoof_parsed(
12402         void *parsed_result,
12403         __attribute__((unused)) struct cmdline *cl,
12404         __attribute__((unused)) void *data)
12405 {
12406         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12407         int ret = -ENOTSUP;
12408
12409         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12410
12411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12412                 return;
12413
12414 #ifdef RTE_LIBRTE_IXGBE_PMD
12415         if (ret == -ENOTSUP)
12416                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12417                         res->vf_id, is_on);
12418 #endif
12419 #ifdef RTE_LIBRTE_I40E_PMD
12420         if (ret == -ENOTSUP)
12421                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12422                         res->vf_id, is_on);
12423 #endif
12424 #ifdef RTE_LIBRTE_BNXT_PMD
12425         if (ret == -ENOTSUP)
12426                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12427                         res->vf_id, is_on);
12428 #endif
12429
12430         switch (ret) {
12431         case 0:
12432                 break;
12433         case -EINVAL:
12434                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12435                 break;
12436         case -ENODEV:
12437                 printf("invalid port_id %d\n", res->port_id);
12438                 break;
12439         case -ENOTSUP:
12440                 printf("function not implemented\n");
12441                 break;
12442         default:
12443                 printf("programming error: (%s)\n", strerror(-ret));
12444         }
12445 }
12446
12447 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12448         .f = cmd_set_vf_mac_anti_spoof_parsed,
12449         .data = NULL,
12450         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12451         .tokens = {
12452                 (void *)&cmd_vf_mac_anti_spoof_set,
12453                 (void *)&cmd_vf_mac_anti_spoof_vf,
12454                 (void *)&cmd_vf_mac_anti_spoof_mac,
12455                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12456                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12457                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12458                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12459                 NULL,
12460         },
12461 };
12462
12463 /* vf vlan strip queue configuration */
12464
12465 /* Common result structure for vf mac anti spoof */
12466 struct cmd_vf_vlan_stripq_result {
12467         cmdline_fixed_string_t set;
12468         cmdline_fixed_string_t vf;
12469         cmdline_fixed_string_t vlan;
12470         cmdline_fixed_string_t stripq;
12471         portid_t port_id;
12472         uint16_t vf_id;
12473         cmdline_fixed_string_t on_off;
12474 };
12475
12476 /* Common CLI fields for vf vlan strip enable disable */
12477 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12478         TOKEN_STRING_INITIALIZER
12479                 (struct cmd_vf_vlan_stripq_result,
12480                  set, "set");
12481 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12482         TOKEN_STRING_INITIALIZER
12483                 (struct cmd_vf_vlan_stripq_result,
12484                  vf, "vf");
12485 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12486         TOKEN_STRING_INITIALIZER
12487                 (struct cmd_vf_vlan_stripq_result,
12488                  vlan, "vlan");
12489 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12490         TOKEN_STRING_INITIALIZER
12491                 (struct cmd_vf_vlan_stripq_result,
12492                  stripq, "stripq");
12493 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12494         TOKEN_NUM_INITIALIZER
12495                 (struct cmd_vf_vlan_stripq_result,
12496                  port_id, UINT16);
12497 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12498         TOKEN_NUM_INITIALIZER
12499                 (struct cmd_vf_vlan_stripq_result,
12500                  vf_id, UINT16);
12501 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12502         TOKEN_STRING_INITIALIZER
12503                 (struct cmd_vf_vlan_stripq_result,
12504                  on_off, "on#off");
12505
12506 static void
12507 cmd_set_vf_vlan_stripq_parsed(
12508         void *parsed_result,
12509         __attribute__((unused)) struct cmdline *cl,
12510         __attribute__((unused)) void *data)
12511 {
12512         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12513         int ret = -ENOTSUP;
12514
12515         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12516
12517         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12518                 return;
12519
12520 #ifdef RTE_LIBRTE_IXGBE_PMD
12521         if (ret == -ENOTSUP)
12522                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12523                         res->vf_id, is_on);
12524 #endif
12525 #ifdef RTE_LIBRTE_I40E_PMD
12526         if (ret == -ENOTSUP)
12527                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12528                         res->vf_id, is_on);
12529 #endif
12530 #ifdef RTE_LIBRTE_BNXT_PMD
12531         if (ret == -ENOTSUP)
12532                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12533                         res->vf_id, is_on);
12534 #endif
12535
12536         switch (ret) {
12537         case 0:
12538                 break;
12539         case -EINVAL:
12540                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12541                 break;
12542         case -ENODEV:
12543                 printf("invalid port_id %d\n", res->port_id);
12544                 break;
12545         case -ENOTSUP:
12546                 printf("function not implemented\n");
12547                 break;
12548         default:
12549                 printf("programming error: (%s)\n", strerror(-ret));
12550         }
12551 }
12552
12553 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12554         .f = cmd_set_vf_vlan_stripq_parsed,
12555         .data = NULL,
12556         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12557         .tokens = {
12558                 (void *)&cmd_vf_vlan_stripq_set,
12559                 (void *)&cmd_vf_vlan_stripq_vf,
12560                 (void *)&cmd_vf_vlan_stripq_vlan,
12561                 (void *)&cmd_vf_vlan_stripq_stripq,
12562                 (void *)&cmd_vf_vlan_stripq_port_id,
12563                 (void *)&cmd_vf_vlan_stripq_vf_id,
12564                 (void *)&cmd_vf_vlan_stripq_on_off,
12565                 NULL,
12566         },
12567 };
12568
12569 /* vf vlan insert configuration */
12570
12571 /* Common result structure for vf vlan insert */
12572 struct cmd_vf_vlan_insert_result {
12573         cmdline_fixed_string_t set;
12574         cmdline_fixed_string_t vf;
12575         cmdline_fixed_string_t vlan;
12576         cmdline_fixed_string_t insert;
12577         portid_t port_id;
12578         uint16_t vf_id;
12579         uint16_t vlan_id;
12580 };
12581
12582 /* Common CLI fields for vf vlan insert enable disable */
12583 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12584         TOKEN_STRING_INITIALIZER
12585                 (struct cmd_vf_vlan_insert_result,
12586                  set, "set");
12587 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12588         TOKEN_STRING_INITIALIZER
12589                 (struct cmd_vf_vlan_insert_result,
12590                  vf, "vf");
12591 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12592         TOKEN_STRING_INITIALIZER
12593                 (struct cmd_vf_vlan_insert_result,
12594                  vlan, "vlan");
12595 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12596         TOKEN_STRING_INITIALIZER
12597                 (struct cmd_vf_vlan_insert_result,
12598                  insert, "insert");
12599 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12600         TOKEN_NUM_INITIALIZER
12601                 (struct cmd_vf_vlan_insert_result,
12602                  port_id, UINT16);
12603 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12604         TOKEN_NUM_INITIALIZER
12605                 (struct cmd_vf_vlan_insert_result,
12606                  vf_id, UINT16);
12607 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12608         TOKEN_NUM_INITIALIZER
12609                 (struct cmd_vf_vlan_insert_result,
12610                  vlan_id, UINT16);
12611
12612 static void
12613 cmd_set_vf_vlan_insert_parsed(
12614         void *parsed_result,
12615         __attribute__((unused)) struct cmdline *cl,
12616         __attribute__((unused)) void *data)
12617 {
12618         struct cmd_vf_vlan_insert_result *res = parsed_result;
12619         int ret = -ENOTSUP;
12620
12621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12622                 return;
12623
12624 #ifdef RTE_LIBRTE_IXGBE_PMD
12625         if (ret == -ENOTSUP)
12626                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12627                         res->vlan_id);
12628 #endif
12629 #ifdef RTE_LIBRTE_I40E_PMD
12630         if (ret == -ENOTSUP)
12631                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12632                         res->vlan_id);
12633 #endif
12634 #ifdef RTE_LIBRTE_BNXT_PMD
12635         if (ret == -ENOTSUP)
12636                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12637                         res->vlan_id);
12638 #endif
12639
12640         switch (ret) {
12641         case 0:
12642                 break;
12643         case -EINVAL:
12644                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12645                 break;
12646         case -ENODEV:
12647                 printf("invalid port_id %d\n", res->port_id);
12648                 break;
12649         case -ENOTSUP:
12650                 printf("function not implemented\n");
12651                 break;
12652         default:
12653                 printf("programming error: (%s)\n", strerror(-ret));
12654         }
12655 }
12656
12657 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12658         .f = cmd_set_vf_vlan_insert_parsed,
12659         .data = NULL,
12660         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12661         .tokens = {
12662                 (void *)&cmd_vf_vlan_insert_set,
12663                 (void *)&cmd_vf_vlan_insert_vf,
12664                 (void *)&cmd_vf_vlan_insert_vlan,
12665                 (void *)&cmd_vf_vlan_insert_insert,
12666                 (void *)&cmd_vf_vlan_insert_port_id,
12667                 (void *)&cmd_vf_vlan_insert_vf_id,
12668                 (void *)&cmd_vf_vlan_insert_vlan_id,
12669                 NULL,
12670         },
12671 };
12672
12673 /* tx loopback configuration */
12674
12675 /* Common result structure for tx loopback */
12676 struct cmd_tx_loopback_result {
12677         cmdline_fixed_string_t set;
12678         cmdline_fixed_string_t tx;
12679         cmdline_fixed_string_t loopback;
12680         portid_t port_id;
12681         cmdline_fixed_string_t on_off;
12682 };
12683
12684 /* Common CLI fields for tx loopback enable disable */
12685 cmdline_parse_token_string_t cmd_tx_loopback_set =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_tx_loopback_result,
12688                  set, "set");
12689 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12690         TOKEN_STRING_INITIALIZER
12691                 (struct cmd_tx_loopback_result,
12692                  tx, "tx");
12693 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12694         TOKEN_STRING_INITIALIZER
12695                 (struct cmd_tx_loopback_result,
12696                  loopback, "loopback");
12697 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12698         TOKEN_NUM_INITIALIZER
12699                 (struct cmd_tx_loopback_result,
12700                  port_id, UINT16);
12701 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12702         TOKEN_STRING_INITIALIZER
12703                 (struct cmd_tx_loopback_result,
12704                  on_off, "on#off");
12705
12706 static void
12707 cmd_set_tx_loopback_parsed(
12708         void *parsed_result,
12709         __attribute__((unused)) struct cmdline *cl,
12710         __attribute__((unused)) void *data)
12711 {
12712         struct cmd_tx_loopback_result *res = parsed_result;
12713         int ret = -ENOTSUP;
12714
12715         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
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_tx_loopback(res->port_id, is_on);
12723 #endif
12724 #ifdef RTE_LIBRTE_I40E_PMD
12725         if (ret == -ENOTSUP)
12726                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12727 #endif
12728 #ifdef RTE_LIBRTE_BNXT_PMD
12729         if (ret == -ENOTSUP)
12730                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12731 #endif
12732
12733         switch (ret) {
12734         case 0:
12735                 break;
12736         case -EINVAL:
12737                 printf("invalid is_on %d\n", is_on);
12738                 break;
12739         case -ENODEV:
12740                 printf("invalid port_id %d\n", res->port_id);
12741                 break;
12742         case -ENOTSUP:
12743                 printf("function not implemented\n");
12744                 break;
12745         default:
12746                 printf("programming error: (%s)\n", strerror(-ret));
12747         }
12748 }
12749
12750 cmdline_parse_inst_t cmd_set_tx_loopback = {
12751         .f = cmd_set_tx_loopback_parsed,
12752         .data = NULL,
12753         .help_str = "set tx loopback <port_id> on|off",
12754         .tokens = {
12755                 (void *)&cmd_tx_loopback_set,
12756                 (void *)&cmd_tx_loopback_tx,
12757                 (void *)&cmd_tx_loopback_loopback,
12758                 (void *)&cmd_tx_loopback_port_id,
12759                 (void *)&cmd_tx_loopback_on_off,
12760                 NULL,
12761         },
12762 };
12763
12764 /* all queues drop enable configuration */
12765
12766 /* Common result structure for all queues drop enable */
12767 struct cmd_all_queues_drop_en_result {
12768         cmdline_fixed_string_t set;
12769         cmdline_fixed_string_t all;
12770         cmdline_fixed_string_t queues;
12771         cmdline_fixed_string_t drop;
12772         portid_t port_id;
12773         cmdline_fixed_string_t on_off;
12774 };
12775
12776 /* Common CLI fields for tx loopback enable disable */
12777 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12778         TOKEN_STRING_INITIALIZER
12779                 (struct cmd_all_queues_drop_en_result,
12780                  set, "set");
12781 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12782         TOKEN_STRING_INITIALIZER
12783                 (struct cmd_all_queues_drop_en_result,
12784                  all, "all");
12785 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12786         TOKEN_STRING_INITIALIZER
12787                 (struct cmd_all_queues_drop_en_result,
12788                  queues, "queues");
12789 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12790         TOKEN_STRING_INITIALIZER
12791                 (struct cmd_all_queues_drop_en_result,
12792                  drop, "drop");
12793 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12794         TOKEN_NUM_INITIALIZER
12795                 (struct cmd_all_queues_drop_en_result,
12796                  port_id, UINT16);
12797 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12798         TOKEN_STRING_INITIALIZER
12799                 (struct cmd_all_queues_drop_en_result,
12800                  on_off, "on#off");
12801
12802 static void
12803 cmd_set_all_queues_drop_en_parsed(
12804         void *parsed_result,
12805         __attribute__((unused)) struct cmdline *cl,
12806         __attribute__((unused)) void *data)
12807 {
12808         struct cmd_all_queues_drop_en_result *res = parsed_result;
12809         int ret = -ENOTSUP;
12810         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12811
12812         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12813                 return;
12814
12815 #ifdef RTE_LIBRTE_IXGBE_PMD
12816         if (ret == -ENOTSUP)
12817                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12818 #endif
12819 #ifdef RTE_LIBRTE_BNXT_PMD
12820         if (ret == -ENOTSUP)
12821                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12822 #endif
12823         switch (ret) {
12824         case 0:
12825                 break;
12826         case -EINVAL:
12827                 printf("invalid is_on %d\n", is_on);
12828                 break;
12829         case -ENODEV:
12830                 printf("invalid port_id %d\n", res->port_id);
12831                 break;
12832         case -ENOTSUP:
12833                 printf("function not implemented\n");
12834                 break;
12835         default:
12836                 printf("programming error: (%s)\n", strerror(-ret));
12837         }
12838 }
12839
12840 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12841         .f = cmd_set_all_queues_drop_en_parsed,
12842         .data = NULL,
12843         .help_str = "set all queues drop <port_id> on|off",
12844         .tokens = {
12845                 (void *)&cmd_all_queues_drop_en_set,
12846                 (void *)&cmd_all_queues_drop_en_all,
12847                 (void *)&cmd_all_queues_drop_en_queues,
12848                 (void *)&cmd_all_queues_drop_en_drop,
12849                 (void *)&cmd_all_queues_drop_en_port_id,
12850                 (void *)&cmd_all_queues_drop_en_on_off,
12851                 NULL,
12852         },
12853 };
12854
12855 /* vf split drop enable configuration */
12856
12857 /* Common result structure for vf split drop enable */
12858 struct cmd_vf_split_drop_en_result {
12859         cmdline_fixed_string_t set;
12860         cmdline_fixed_string_t vf;
12861         cmdline_fixed_string_t split;
12862         cmdline_fixed_string_t drop;
12863         portid_t port_id;
12864         uint16_t vf_id;
12865         cmdline_fixed_string_t on_off;
12866 };
12867
12868 /* Common CLI fields for vf split drop enable disable */
12869 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12870         TOKEN_STRING_INITIALIZER
12871                 (struct cmd_vf_split_drop_en_result,
12872                  set, "set");
12873 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12874         TOKEN_STRING_INITIALIZER
12875                 (struct cmd_vf_split_drop_en_result,
12876                  vf, "vf");
12877 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12878         TOKEN_STRING_INITIALIZER
12879                 (struct cmd_vf_split_drop_en_result,
12880                  split, "split");
12881 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_vf_split_drop_en_result,
12884                  drop, "drop");
12885 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12886         TOKEN_NUM_INITIALIZER
12887                 (struct cmd_vf_split_drop_en_result,
12888                  port_id, UINT16);
12889 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12890         TOKEN_NUM_INITIALIZER
12891                 (struct cmd_vf_split_drop_en_result,
12892                  vf_id, UINT16);
12893 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12894         TOKEN_STRING_INITIALIZER
12895                 (struct cmd_vf_split_drop_en_result,
12896                  on_off, "on#off");
12897
12898 static void
12899 cmd_set_vf_split_drop_en_parsed(
12900         void *parsed_result,
12901         __attribute__((unused)) struct cmdline *cl,
12902         __attribute__((unused)) void *data)
12903 {
12904         struct cmd_vf_split_drop_en_result *res = parsed_result;
12905         int ret = -ENOTSUP;
12906         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12907
12908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12909                 return;
12910
12911 #ifdef RTE_LIBRTE_IXGBE_PMD
12912         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12913                         is_on);
12914 #endif
12915         switch (ret) {
12916         case 0:
12917                 break;
12918         case -EINVAL:
12919                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12920                 break;
12921         case -ENODEV:
12922                 printf("invalid port_id %d\n", res->port_id);
12923                 break;
12924         case -ENOTSUP:
12925                 printf("not supported on port %d\n", res->port_id);
12926                 break;
12927         default:
12928                 printf("programming error: (%s)\n", strerror(-ret));
12929         }
12930 }
12931
12932 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12933         .f = cmd_set_vf_split_drop_en_parsed,
12934         .data = NULL,
12935         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12936         .tokens = {
12937                 (void *)&cmd_vf_split_drop_en_set,
12938                 (void *)&cmd_vf_split_drop_en_vf,
12939                 (void *)&cmd_vf_split_drop_en_split,
12940                 (void *)&cmd_vf_split_drop_en_drop,
12941                 (void *)&cmd_vf_split_drop_en_port_id,
12942                 (void *)&cmd_vf_split_drop_en_vf_id,
12943                 (void *)&cmd_vf_split_drop_en_on_off,
12944                 NULL,
12945         },
12946 };
12947
12948 /* vf mac address configuration */
12949
12950 /* Common result structure for vf mac address */
12951 struct cmd_set_vf_mac_addr_result {
12952         cmdline_fixed_string_t set;
12953         cmdline_fixed_string_t vf;
12954         cmdline_fixed_string_t mac;
12955         cmdline_fixed_string_t addr;
12956         portid_t port_id;
12957         uint16_t vf_id;
12958         struct ether_addr mac_addr;
12959
12960 };
12961
12962 /* Common CLI fields for vf split drop enable disable */
12963 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_set_vf_mac_addr_result,
12966                  set, "set");
12967 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_set_vf_mac_addr_result,
12970                  vf, "vf");
12971 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_set_vf_mac_addr_result,
12974                  mac, "mac");
12975 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_set_vf_mac_addr_result,
12978                  addr, "addr");
12979 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12980         TOKEN_NUM_INITIALIZER
12981                 (struct cmd_set_vf_mac_addr_result,
12982                  port_id, UINT16);
12983 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12984         TOKEN_NUM_INITIALIZER
12985                 (struct cmd_set_vf_mac_addr_result,
12986                  vf_id, UINT16);
12987 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12988         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12989                  mac_addr);
12990
12991 static void
12992 cmd_set_vf_mac_addr_parsed(
12993         void *parsed_result,
12994         __attribute__((unused)) struct cmdline *cl,
12995         __attribute__((unused)) void *data)
12996 {
12997         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12998         int ret = -ENOTSUP;
12999
13000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13001                 return;
13002
13003 #ifdef RTE_LIBRTE_IXGBE_PMD
13004         if (ret == -ENOTSUP)
13005                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13006                                 &res->mac_addr);
13007 #endif
13008 #ifdef RTE_LIBRTE_I40E_PMD
13009         if (ret == -ENOTSUP)
13010                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13011                                 &res->mac_addr);
13012 #endif
13013 #ifdef RTE_LIBRTE_BNXT_PMD
13014         if (ret == -ENOTSUP)
13015                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13016                                 &res->mac_addr);
13017 #endif
13018
13019         switch (ret) {
13020         case 0:
13021                 break;
13022         case -EINVAL:
13023                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13024                 break;
13025         case -ENODEV:
13026                 printf("invalid port_id %d\n", res->port_id);
13027                 break;
13028         case -ENOTSUP:
13029                 printf("function not implemented\n");
13030                 break;
13031         default:
13032                 printf("programming error: (%s)\n", strerror(-ret));
13033         }
13034 }
13035
13036 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13037         .f = cmd_set_vf_mac_addr_parsed,
13038         .data = NULL,
13039         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13040         .tokens = {
13041                 (void *)&cmd_set_vf_mac_addr_set,
13042                 (void *)&cmd_set_vf_mac_addr_vf,
13043                 (void *)&cmd_set_vf_mac_addr_mac,
13044                 (void *)&cmd_set_vf_mac_addr_addr,
13045                 (void *)&cmd_set_vf_mac_addr_port_id,
13046                 (void *)&cmd_set_vf_mac_addr_vf_id,
13047                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13048                 NULL,
13049         },
13050 };
13051
13052 /* MACsec configuration */
13053
13054 /* Common result structure for MACsec offload enable */
13055 struct cmd_macsec_offload_on_result {
13056         cmdline_fixed_string_t set;
13057         cmdline_fixed_string_t macsec;
13058         cmdline_fixed_string_t offload;
13059         portid_t port_id;
13060         cmdline_fixed_string_t on;
13061         cmdline_fixed_string_t encrypt;
13062         cmdline_fixed_string_t en_on_off;
13063         cmdline_fixed_string_t replay_protect;
13064         cmdline_fixed_string_t rp_on_off;
13065 };
13066
13067 /* Common CLI fields for MACsec offload disable */
13068 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13069         TOKEN_STRING_INITIALIZER
13070                 (struct cmd_macsec_offload_on_result,
13071                  set, "set");
13072 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13073         TOKEN_STRING_INITIALIZER
13074                 (struct cmd_macsec_offload_on_result,
13075                  macsec, "macsec");
13076 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13077         TOKEN_STRING_INITIALIZER
13078                 (struct cmd_macsec_offload_on_result,
13079                  offload, "offload");
13080 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13081         TOKEN_NUM_INITIALIZER
13082                 (struct cmd_macsec_offload_on_result,
13083                  port_id, UINT16);
13084 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_macsec_offload_on_result,
13087                  on, "on");
13088 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_macsec_offload_on_result,
13091                  encrypt, "encrypt");
13092 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_macsec_offload_on_result,
13095                  en_on_off, "on#off");
13096 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13097         TOKEN_STRING_INITIALIZER
13098                 (struct cmd_macsec_offload_on_result,
13099                  replay_protect, "replay-protect");
13100 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13101         TOKEN_STRING_INITIALIZER
13102                 (struct cmd_macsec_offload_on_result,
13103                  rp_on_off, "on#off");
13104
13105 static void
13106 cmd_set_macsec_offload_on_parsed(
13107         void *parsed_result,
13108         __attribute__((unused)) struct cmdline *cl,
13109         __attribute__((unused)) void *data)
13110 {
13111         struct cmd_macsec_offload_on_result *res = parsed_result;
13112         int ret = -ENOTSUP;
13113         portid_t port_id = res->port_id;
13114         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13115         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13116         struct rte_eth_dev_info dev_info;
13117
13118         if (port_id_is_invalid(port_id, ENABLED_WARN))
13119                 return;
13120         if (!port_is_stopped(port_id)) {
13121                 printf("Please stop port %d first\n", port_id);
13122                 return;
13123         }
13124
13125         rte_eth_dev_info_get(port_id, &dev_info);
13126         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13127 #ifdef RTE_LIBRTE_IXGBE_PMD
13128                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13129 #endif
13130         }
13131         RTE_SET_USED(en);
13132         RTE_SET_USED(rp);
13133
13134         switch (ret) {
13135         case 0:
13136                 ports[port_id].dev_conf.txmode.offloads |=
13137                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13138                 cmd_reconfig_device_queue(port_id, 1, 1);
13139                 break;
13140         case -ENODEV:
13141                 printf("invalid port_id %d\n", port_id);
13142                 break;
13143         case -ENOTSUP:
13144                 printf("not supported on port %d\n", port_id);
13145                 break;
13146         default:
13147                 printf("programming error: (%s)\n", strerror(-ret));
13148         }
13149 }
13150
13151 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13152         .f = cmd_set_macsec_offload_on_parsed,
13153         .data = NULL,
13154         .help_str = "set macsec offload <port_id> on "
13155                 "encrypt on|off replay-protect on|off",
13156         .tokens = {
13157                 (void *)&cmd_macsec_offload_on_set,
13158                 (void *)&cmd_macsec_offload_on_macsec,
13159                 (void *)&cmd_macsec_offload_on_offload,
13160                 (void *)&cmd_macsec_offload_on_port_id,
13161                 (void *)&cmd_macsec_offload_on_on,
13162                 (void *)&cmd_macsec_offload_on_encrypt,
13163                 (void *)&cmd_macsec_offload_on_en_on_off,
13164                 (void *)&cmd_macsec_offload_on_replay_protect,
13165                 (void *)&cmd_macsec_offload_on_rp_on_off,
13166                 NULL,
13167         },
13168 };
13169
13170 /* Common result structure for MACsec offload disable */
13171 struct cmd_macsec_offload_off_result {
13172         cmdline_fixed_string_t set;
13173         cmdline_fixed_string_t macsec;
13174         cmdline_fixed_string_t offload;
13175         portid_t port_id;
13176         cmdline_fixed_string_t off;
13177 };
13178
13179 /* Common CLI fields for MACsec offload disable */
13180 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13181         TOKEN_STRING_INITIALIZER
13182                 (struct cmd_macsec_offload_off_result,
13183                  set, "set");
13184 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13185         TOKEN_STRING_INITIALIZER
13186                 (struct cmd_macsec_offload_off_result,
13187                  macsec, "macsec");
13188 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13189         TOKEN_STRING_INITIALIZER
13190                 (struct cmd_macsec_offload_off_result,
13191                  offload, "offload");
13192 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13193         TOKEN_NUM_INITIALIZER
13194                 (struct cmd_macsec_offload_off_result,
13195                  port_id, UINT16);
13196 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13197         TOKEN_STRING_INITIALIZER
13198                 (struct cmd_macsec_offload_off_result,
13199                  off, "off");
13200
13201 static void
13202 cmd_set_macsec_offload_off_parsed(
13203         void *parsed_result,
13204         __attribute__((unused)) struct cmdline *cl,
13205         __attribute__((unused)) void *data)
13206 {
13207         struct cmd_macsec_offload_off_result *res = parsed_result;
13208         int ret = -ENOTSUP;
13209         struct rte_eth_dev_info dev_info;
13210         portid_t port_id = res->port_id;
13211
13212         if (port_id_is_invalid(port_id, ENABLED_WARN))
13213                 return;
13214         if (!port_is_stopped(port_id)) {
13215                 printf("Please stop port %d first\n", port_id);
13216                 return;
13217         }
13218
13219         rte_eth_dev_info_get(port_id, &dev_info);
13220         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13221 #ifdef RTE_LIBRTE_IXGBE_PMD
13222                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13223 #endif
13224         }
13225         switch (ret) {
13226         case 0:
13227                 ports[port_id].dev_conf.txmode.offloads &=
13228                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13229                 cmd_reconfig_device_queue(port_id, 1, 1);
13230                 break;
13231         case -ENODEV:
13232                 printf("invalid port_id %d\n", port_id);
13233                 break;
13234         case -ENOTSUP:
13235                 printf("not supported on port %d\n", port_id);
13236                 break;
13237         default:
13238                 printf("programming error: (%s)\n", strerror(-ret));
13239         }
13240 }
13241
13242 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13243         .f = cmd_set_macsec_offload_off_parsed,
13244         .data = NULL,
13245         .help_str = "set macsec offload <port_id> off",
13246         .tokens = {
13247                 (void *)&cmd_macsec_offload_off_set,
13248                 (void *)&cmd_macsec_offload_off_macsec,
13249                 (void *)&cmd_macsec_offload_off_offload,
13250                 (void *)&cmd_macsec_offload_off_port_id,
13251                 (void *)&cmd_macsec_offload_off_off,
13252                 NULL,
13253         },
13254 };
13255
13256 /* Common result structure for MACsec secure connection configure */
13257 struct cmd_macsec_sc_result {
13258         cmdline_fixed_string_t set;
13259         cmdline_fixed_string_t macsec;
13260         cmdline_fixed_string_t sc;
13261         cmdline_fixed_string_t tx_rx;
13262         portid_t port_id;
13263         struct ether_addr mac;
13264         uint16_t pi;
13265 };
13266
13267 /* Common CLI fields for MACsec secure connection configure */
13268 cmdline_parse_token_string_t cmd_macsec_sc_set =
13269         TOKEN_STRING_INITIALIZER
13270                 (struct cmd_macsec_sc_result,
13271                  set, "set");
13272 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13273         TOKEN_STRING_INITIALIZER
13274                 (struct cmd_macsec_sc_result,
13275                  macsec, "macsec");
13276 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13277         TOKEN_STRING_INITIALIZER
13278                 (struct cmd_macsec_sc_result,
13279                  sc, "sc");
13280 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13281         TOKEN_STRING_INITIALIZER
13282                 (struct cmd_macsec_sc_result,
13283                  tx_rx, "tx#rx");
13284 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13285         TOKEN_NUM_INITIALIZER
13286                 (struct cmd_macsec_sc_result,
13287                  port_id, UINT16);
13288 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13289         TOKEN_ETHERADDR_INITIALIZER
13290                 (struct cmd_macsec_sc_result,
13291                  mac);
13292 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13293         TOKEN_NUM_INITIALIZER
13294                 (struct cmd_macsec_sc_result,
13295                  pi, UINT16);
13296
13297 static void
13298 cmd_set_macsec_sc_parsed(
13299         void *parsed_result,
13300         __attribute__((unused)) struct cmdline *cl,
13301         __attribute__((unused)) void *data)
13302 {
13303         struct cmd_macsec_sc_result *res = parsed_result;
13304         int ret = -ENOTSUP;
13305         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13306
13307 #ifdef RTE_LIBRTE_IXGBE_PMD
13308         ret = is_tx ?
13309                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13310                                 res->mac.addr_bytes) :
13311                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13312                                 res->mac.addr_bytes, res->pi);
13313 #endif
13314         RTE_SET_USED(is_tx);
13315
13316         switch (ret) {
13317         case 0:
13318                 break;
13319         case -ENODEV:
13320                 printf("invalid port_id %d\n", res->port_id);
13321                 break;
13322         case -ENOTSUP:
13323                 printf("not supported on port %d\n", res->port_id);
13324                 break;
13325         default:
13326                 printf("programming error: (%s)\n", strerror(-ret));
13327         }
13328 }
13329
13330 cmdline_parse_inst_t cmd_set_macsec_sc = {
13331         .f = cmd_set_macsec_sc_parsed,
13332         .data = NULL,
13333         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13334         .tokens = {
13335                 (void *)&cmd_macsec_sc_set,
13336                 (void *)&cmd_macsec_sc_macsec,
13337                 (void *)&cmd_macsec_sc_sc,
13338                 (void *)&cmd_macsec_sc_tx_rx,
13339                 (void *)&cmd_macsec_sc_port_id,
13340                 (void *)&cmd_macsec_sc_mac,
13341                 (void *)&cmd_macsec_sc_pi,
13342                 NULL,
13343         },
13344 };
13345
13346 /* Common result structure for MACsec secure connection configure */
13347 struct cmd_macsec_sa_result {
13348         cmdline_fixed_string_t set;
13349         cmdline_fixed_string_t macsec;
13350         cmdline_fixed_string_t sa;
13351         cmdline_fixed_string_t tx_rx;
13352         portid_t port_id;
13353         uint8_t idx;
13354         uint8_t an;
13355         uint32_t pn;
13356         cmdline_fixed_string_t key;
13357 };
13358
13359 /* Common CLI fields for MACsec secure connection configure */
13360 cmdline_parse_token_string_t cmd_macsec_sa_set =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_macsec_sa_result,
13363                  set, "set");
13364 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_macsec_sa_result,
13367                  macsec, "macsec");
13368 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13369         TOKEN_STRING_INITIALIZER
13370                 (struct cmd_macsec_sa_result,
13371                  sa, "sa");
13372 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13373         TOKEN_STRING_INITIALIZER
13374                 (struct cmd_macsec_sa_result,
13375                  tx_rx, "tx#rx");
13376 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13377         TOKEN_NUM_INITIALIZER
13378                 (struct cmd_macsec_sa_result,
13379                  port_id, UINT16);
13380 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13381         TOKEN_NUM_INITIALIZER
13382                 (struct cmd_macsec_sa_result,
13383                  idx, UINT8);
13384 cmdline_parse_token_num_t cmd_macsec_sa_an =
13385         TOKEN_NUM_INITIALIZER
13386                 (struct cmd_macsec_sa_result,
13387                  an, UINT8);
13388 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13389         TOKEN_NUM_INITIALIZER
13390                 (struct cmd_macsec_sa_result,
13391                  pn, UINT32);
13392 cmdline_parse_token_string_t cmd_macsec_sa_key =
13393         TOKEN_STRING_INITIALIZER
13394                 (struct cmd_macsec_sa_result,
13395                  key, NULL);
13396
13397 static void
13398 cmd_set_macsec_sa_parsed(
13399         void *parsed_result,
13400         __attribute__((unused)) struct cmdline *cl,
13401         __attribute__((unused)) void *data)
13402 {
13403         struct cmd_macsec_sa_result *res = parsed_result;
13404         int ret = -ENOTSUP;
13405         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13406         uint8_t key[16] = { 0 };
13407         uint8_t xdgt0;
13408         uint8_t xdgt1;
13409         int key_len;
13410         int i;
13411
13412         key_len = strlen(res->key) / 2;
13413         if (key_len > 16)
13414                 key_len = 16;
13415
13416         for (i = 0; i < key_len; i++) {
13417                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13418                 if (xdgt0 == 0xFF)
13419                         return;
13420                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13421                 if (xdgt1 == 0xFF)
13422                         return;
13423                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13424         }
13425
13426 #ifdef RTE_LIBRTE_IXGBE_PMD
13427         ret = is_tx ?
13428                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13429                         res->idx, res->an, res->pn, key) :
13430                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13431                         res->idx, res->an, res->pn, key);
13432 #endif
13433         RTE_SET_USED(is_tx);
13434         RTE_SET_USED(key);
13435
13436         switch (ret) {
13437         case 0:
13438                 break;
13439         case -EINVAL:
13440                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13441                 break;
13442         case -ENODEV:
13443                 printf("invalid port_id %d\n", res->port_id);
13444                 break;
13445         case -ENOTSUP:
13446                 printf("not supported on port %d\n", res->port_id);
13447                 break;
13448         default:
13449                 printf("programming error: (%s)\n", strerror(-ret));
13450         }
13451 }
13452
13453 cmdline_parse_inst_t cmd_set_macsec_sa = {
13454         .f = cmd_set_macsec_sa_parsed,
13455         .data = NULL,
13456         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13457         .tokens = {
13458                 (void *)&cmd_macsec_sa_set,
13459                 (void *)&cmd_macsec_sa_macsec,
13460                 (void *)&cmd_macsec_sa_sa,
13461                 (void *)&cmd_macsec_sa_tx_rx,
13462                 (void *)&cmd_macsec_sa_port_id,
13463                 (void *)&cmd_macsec_sa_idx,
13464                 (void *)&cmd_macsec_sa_an,
13465                 (void *)&cmd_macsec_sa_pn,
13466                 (void *)&cmd_macsec_sa_key,
13467                 NULL,
13468         },
13469 };
13470
13471 /* VF unicast promiscuous mode configuration */
13472
13473 /* Common result structure for VF unicast promiscuous mode */
13474 struct cmd_vf_promisc_result {
13475         cmdline_fixed_string_t set;
13476         cmdline_fixed_string_t vf;
13477         cmdline_fixed_string_t promisc;
13478         portid_t port_id;
13479         uint32_t vf_id;
13480         cmdline_fixed_string_t on_off;
13481 };
13482
13483 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13484 cmdline_parse_token_string_t cmd_vf_promisc_set =
13485         TOKEN_STRING_INITIALIZER
13486                 (struct cmd_vf_promisc_result,
13487                  set, "set");
13488 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13489         TOKEN_STRING_INITIALIZER
13490                 (struct cmd_vf_promisc_result,
13491                  vf, "vf");
13492 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13493         TOKEN_STRING_INITIALIZER
13494                 (struct cmd_vf_promisc_result,
13495                  promisc, "promisc");
13496 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13497         TOKEN_NUM_INITIALIZER
13498                 (struct cmd_vf_promisc_result,
13499                  port_id, UINT16);
13500 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13501         TOKEN_NUM_INITIALIZER
13502                 (struct cmd_vf_promisc_result,
13503                  vf_id, UINT32);
13504 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13505         TOKEN_STRING_INITIALIZER
13506                 (struct cmd_vf_promisc_result,
13507                  on_off, "on#off");
13508
13509 static void
13510 cmd_set_vf_promisc_parsed(
13511         void *parsed_result,
13512         __attribute__((unused)) struct cmdline *cl,
13513         __attribute__((unused)) void *data)
13514 {
13515         struct cmd_vf_promisc_result *res = parsed_result;
13516         int ret = -ENOTSUP;
13517
13518         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13519
13520         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13521                 return;
13522
13523 #ifdef RTE_LIBRTE_I40E_PMD
13524         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13525                                                   res->vf_id, is_on);
13526 #endif
13527
13528         switch (ret) {
13529         case 0:
13530                 break;
13531         case -EINVAL:
13532                 printf("invalid vf_id %d\n", res->vf_id);
13533                 break;
13534         case -ENODEV:
13535                 printf("invalid port_id %d\n", res->port_id);
13536                 break;
13537         case -ENOTSUP:
13538                 printf("function not implemented\n");
13539                 break;
13540         default:
13541                 printf("programming error: (%s)\n", strerror(-ret));
13542         }
13543 }
13544
13545 cmdline_parse_inst_t cmd_set_vf_promisc = {
13546         .f = cmd_set_vf_promisc_parsed,
13547         .data = NULL,
13548         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13549                 "Set unicast promiscuous mode for a VF from the PF",
13550         .tokens = {
13551                 (void *)&cmd_vf_promisc_set,
13552                 (void *)&cmd_vf_promisc_vf,
13553                 (void *)&cmd_vf_promisc_promisc,
13554                 (void *)&cmd_vf_promisc_port_id,
13555                 (void *)&cmd_vf_promisc_vf_id,
13556                 (void *)&cmd_vf_promisc_on_off,
13557                 NULL,
13558         },
13559 };
13560
13561 /* VF multicast promiscuous mode configuration */
13562
13563 /* Common result structure for VF multicast promiscuous mode */
13564 struct cmd_vf_allmulti_result {
13565         cmdline_fixed_string_t set;
13566         cmdline_fixed_string_t vf;
13567         cmdline_fixed_string_t allmulti;
13568         portid_t port_id;
13569         uint32_t vf_id;
13570         cmdline_fixed_string_t on_off;
13571 };
13572
13573 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13574 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13575         TOKEN_STRING_INITIALIZER
13576                 (struct cmd_vf_allmulti_result,
13577                  set, "set");
13578 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_vf_allmulti_result,
13581                  vf, "vf");
13582 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_vf_allmulti_result,
13585                  allmulti, "allmulti");
13586 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13587         TOKEN_NUM_INITIALIZER
13588                 (struct cmd_vf_allmulti_result,
13589                  port_id, UINT16);
13590 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13591         TOKEN_NUM_INITIALIZER
13592                 (struct cmd_vf_allmulti_result,
13593                  vf_id, UINT32);
13594 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13595         TOKEN_STRING_INITIALIZER
13596                 (struct cmd_vf_allmulti_result,
13597                  on_off, "on#off");
13598
13599 static void
13600 cmd_set_vf_allmulti_parsed(
13601         void *parsed_result,
13602         __attribute__((unused)) struct cmdline *cl,
13603         __attribute__((unused)) void *data)
13604 {
13605         struct cmd_vf_allmulti_result *res = parsed_result;
13606         int ret = -ENOTSUP;
13607
13608         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13609
13610         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13611                 return;
13612
13613 #ifdef RTE_LIBRTE_I40E_PMD
13614         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13615                                                     res->vf_id, is_on);
13616 #endif
13617
13618         switch (ret) {
13619         case 0:
13620                 break;
13621         case -EINVAL:
13622                 printf("invalid vf_id %d\n", res->vf_id);
13623                 break;
13624         case -ENODEV:
13625                 printf("invalid port_id %d\n", res->port_id);
13626                 break;
13627         case -ENOTSUP:
13628                 printf("function not implemented\n");
13629                 break;
13630         default:
13631                 printf("programming error: (%s)\n", strerror(-ret));
13632         }
13633 }
13634
13635 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13636         .f = cmd_set_vf_allmulti_parsed,
13637         .data = NULL,
13638         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13639                 "Set multicast promiscuous mode for a VF from the PF",
13640         .tokens = {
13641                 (void *)&cmd_vf_allmulti_set,
13642                 (void *)&cmd_vf_allmulti_vf,
13643                 (void *)&cmd_vf_allmulti_allmulti,
13644                 (void *)&cmd_vf_allmulti_port_id,
13645                 (void *)&cmd_vf_allmulti_vf_id,
13646                 (void *)&cmd_vf_allmulti_on_off,
13647                 NULL,
13648         },
13649 };
13650
13651 /* vf broadcast mode configuration */
13652
13653 /* Common result structure for vf broadcast */
13654 struct cmd_set_vf_broadcast_result {
13655         cmdline_fixed_string_t set;
13656         cmdline_fixed_string_t vf;
13657         cmdline_fixed_string_t broadcast;
13658         portid_t port_id;
13659         uint16_t vf_id;
13660         cmdline_fixed_string_t on_off;
13661 };
13662
13663 /* Common CLI fields for vf broadcast enable disable */
13664 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_set_vf_broadcast_result,
13667                  set, "set");
13668 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_set_vf_broadcast_result,
13671                  vf, "vf");
13672 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_set_vf_broadcast_result,
13675                  broadcast, "broadcast");
13676 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13677         TOKEN_NUM_INITIALIZER
13678                 (struct cmd_set_vf_broadcast_result,
13679                  port_id, UINT16);
13680 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13681         TOKEN_NUM_INITIALIZER
13682                 (struct cmd_set_vf_broadcast_result,
13683                  vf_id, UINT16);
13684 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_set_vf_broadcast_result,
13687                  on_off, "on#off");
13688
13689 static void
13690 cmd_set_vf_broadcast_parsed(
13691         void *parsed_result,
13692         __attribute__((unused)) struct cmdline *cl,
13693         __attribute__((unused)) void *data)
13694 {
13695         struct cmd_set_vf_broadcast_result *res = parsed_result;
13696         int ret = -ENOTSUP;
13697
13698         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13699
13700         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13701                 return;
13702
13703 #ifdef RTE_LIBRTE_I40E_PMD
13704         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13705                                             res->vf_id, is_on);
13706 #endif
13707
13708         switch (ret) {
13709         case 0:
13710                 break;
13711         case -EINVAL:
13712                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13713                 break;
13714         case -ENODEV:
13715                 printf("invalid port_id %d\n", res->port_id);
13716                 break;
13717         case -ENOTSUP:
13718                 printf("function not implemented\n");
13719                 break;
13720         default:
13721                 printf("programming error: (%s)\n", strerror(-ret));
13722         }
13723 }
13724
13725 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13726         .f = cmd_set_vf_broadcast_parsed,
13727         .data = NULL,
13728         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13729         .tokens = {
13730                 (void *)&cmd_set_vf_broadcast_set,
13731                 (void *)&cmd_set_vf_broadcast_vf,
13732                 (void *)&cmd_set_vf_broadcast_broadcast,
13733                 (void *)&cmd_set_vf_broadcast_port_id,
13734                 (void *)&cmd_set_vf_broadcast_vf_id,
13735                 (void *)&cmd_set_vf_broadcast_on_off,
13736                 NULL,
13737         },
13738 };
13739
13740 /* vf vlan tag configuration */
13741
13742 /* Common result structure for vf vlan tag */
13743 struct cmd_set_vf_vlan_tag_result {
13744         cmdline_fixed_string_t set;
13745         cmdline_fixed_string_t vf;
13746         cmdline_fixed_string_t vlan;
13747         cmdline_fixed_string_t tag;
13748         portid_t port_id;
13749         uint16_t vf_id;
13750         cmdline_fixed_string_t on_off;
13751 };
13752
13753 /* Common CLI fields for vf vlan tag enable disable */
13754 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13755         TOKEN_STRING_INITIALIZER
13756                 (struct cmd_set_vf_vlan_tag_result,
13757                  set, "set");
13758 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13759         TOKEN_STRING_INITIALIZER
13760                 (struct cmd_set_vf_vlan_tag_result,
13761                  vf, "vf");
13762 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_set_vf_vlan_tag_result,
13765                  vlan, "vlan");
13766 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_set_vf_vlan_tag_result,
13769                  tag, "tag");
13770 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13771         TOKEN_NUM_INITIALIZER
13772                 (struct cmd_set_vf_vlan_tag_result,
13773                  port_id, UINT16);
13774 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13775         TOKEN_NUM_INITIALIZER
13776                 (struct cmd_set_vf_vlan_tag_result,
13777                  vf_id, UINT16);
13778 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13779         TOKEN_STRING_INITIALIZER
13780                 (struct cmd_set_vf_vlan_tag_result,
13781                  on_off, "on#off");
13782
13783 static void
13784 cmd_set_vf_vlan_tag_parsed(
13785         void *parsed_result,
13786         __attribute__((unused)) struct cmdline *cl,
13787         __attribute__((unused)) void *data)
13788 {
13789         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13790         int ret = -ENOTSUP;
13791
13792         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13793
13794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13795                 return;
13796
13797 #ifdef RTE_LIBRTE_I40E_PMD
13798         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13799                                            res->vf_id, is_on);
13800 #endif
13801
13802         switch (ret) {
13803         case 0:
13804                 break;
13805         case -EINVAL:
13806                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13807                 break;
13808         case -ENODEV:
13809                 printf("invalid port_id %d\n", res->port_id);
13810                 break;
13811         case -ENOTSUP:
13812                 printf("function not implemented\n");
13813                 break;
13814         default:
13815                 printf("programming error: (%s)\n", strerror(-ret));
13816         }
13817 }
13818
13819 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13820         .f = cmd_set_vf_vlan_tag_parsed,
13821         .data = NULL,
13822         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13823         .tokens = {
13824                 (void *)&cmd_set_vf_vlan_tag_set,
13825                 (void *)&cmd_set_vf_vlan_tag_vf,
13826                 (void *)&cmd_set_vf_vlan_tag_vlan,
13827                 (void *)&cmd_set_vf_vlan_tag_tag,
13828                 (void *)&cmd_set_vf_vlan_tag_port_id,
13829                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13830                 (void *)&cmd_set_vf_vlan_tag_on_off,
13831                 NULL,
13832         },
13833 };
13834
13835 /* Common definition of VF and TC TX bandwidth configuration */
13836 struct cmd_vf_tc_bw_result {
13837         cmdline_fixed_string_t set;
13838         cmdline_fixed_string_t vf;
13839         cmdline_fixed_string_t tc;
13840         cmdline_fixed_string_t tx;
13841         cmdline_fixed_string_t min_bw;
13842         cmdline_fixed_string_t max_bw;
13843         cmdline_fixed_string_t strict_link_prio;
13844         portid_t port_id;
13845         uint16_t vf_id;
13846         uint8_t tc_no;
13847         uint32_t bw;
13848         cmdline_fixed_string_t bw_list;
13849         uint8_t tc_map;
13850 };
13851
13852 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13853         TOKEN_STRING_INITIALIZER
13854                 (struct cmd_vf_tc_bw_result,
13855                  set, "set");
13856 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13857         TOKEN_STRING_INITIALIZER
13858                 (struct cmd_vf_tc_bw_result,
13859                  vf, "vf");
13860 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13861         TOKEN_STRING_INITIALIZER
13862                 (struct cmd_vf_tc_bw_result,
13863                  tc, "tc");
13864 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13865         TOKEN_STRING_INITIALIZER
13866                 (struct cmd_vf_tc_bw_result,
13867                  tx, "tx");
13868 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_vf_tc_bw_result,
13871                  strict_link_prio, "strict-link-priority");
13872 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_vf_tc_bw_result,
13875                  min_bw, "min-bandwidth");
13876 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_vf_tc_bw_result,
13879                  max_bw, "max-bandwidth");
13880 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13881         TOKEN_NUM_INITIALIZER
13882                 (struct cmd_vf_tc_bw_result,
13883                  port_id, UINT16);
13884 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13885         TOKEN_NUM_INITIALIZER
13886                 (struct cmd_vf_tc_bw_result,
13887                  vf_id, UINT16);
13888 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13889         TOKEN_NUM_INITIALIZER
13890                 (struct cmd_vf_tc_bw_result,
13891                  tc_no, UINT8);
13892 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13893         TOKEN_NUM_INITIALIZER
13894                 (struct cmd_vf_tc_bw_result,
13895                  bw, UINT32);
13896 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13897         TOKEN_STRING_INITIALIZER
13898                 (struct cmd_vf_tc_bw_result,
13899                  bw_list, NULL);
13900 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13901         TOKEN_NUM_INITIALIZER
13902                 (struct cmd_vf_tc_bw_result,
13903                  tc_map, UINT8);
13904
13905 /* VF max bandwidth setting */
13906 static void
13907 cmd_vf_max_bw_parsed(
13908         void *parsed_result,
13909         __attribute__((unused)) struct cmdline *cl,
13910         __attribute__((unused)) void *data)
13911 {
13912         struct cmd_vf_tc_bw_result *res = parsed_result;
13913         int ret = -ENOTSUP;
13914
13915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13916                 return;
13917
13918 #ifdef RTE_LIBRTE_I40E_PMD
13919         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13920                                          res->vf_id, res->bw);
13921 #endif
13922
13923         switch (ret) {
13924         case 0:
13925                 break;
13926         case -EINVAL:
13927                 printf("invalid vf_id %d or bandwidth %d\n",
13928                        res->vf_id, res->bw);
13929                 break;
13930         case -ENODEV:
13931                 printf("invalid port_id %d\n", res->port_id);
13932                 break;
13933         case -ENOTSUP:
13934                 printf("function not implemented\n");
13935                 break;
13936         default:
13937                 printf("programming error: (%s)\n", strerror(-ret));
13938         }
13939 }
13940
13941 cmdline_parse_inst_t cmd_vf_max_bw = {
13942         .f = cmd_vf_max_bw_parsed,
13943         .data = NULL,
13944         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13945         .tokens = {
13946                 (void *)&cmd_vf_tc_bw_set,
13947                 (void *)&cmd_vf_tc_bw_vf,
13948                 (void *)&cmd_vf_tc_bw_tx,
13949                 (void *)&cmd_vf_tc_bw_max_bw,
13950                 (void *)&cmd_vf_tc_bw_port_id,
13951                 (void *)&cmd_vf_tc_bw_vf_id,
13952                 (void *)&cmd_vf_tc_bw_bw,
13953                 NULL,
13954         },
13955 };
13956
13957 static int
13958 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13959                            uint8_t *tc_num,
13960                            char *str)
13961 {
13962         uint32_t size;
13963         const char *p, *p0 = str;
13964         char s[256];
13965         char *end;
13966         char *str_fld[16];
13967         uint16_t i;
13968         int ret;
13969
13970         p = strchr(p0, '(');
13971         if (p == NULL) {
13972                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13973                 return -1;
13974         }
13975         p++;
13976         p0 = strchr(p, ')');
13977         if (p0 == NULL) {
13978                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13979                 return -1;
13980         }
13981         size = p0 - p;
13982         if (size >= sizeof(s)) {
13983                 printf("The string size exceeds the internal buffer size\n");
13984                 return -1;
13985         }
13986         snprintf(s, sizeof(s), "%.*s", size, p);
13987         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13988         if (ret <= 0) {
13989                 printf("Failed to get the bandwidth list. ");
13990                 return -1;
13991         }
13992         *tc_num = ret;
13993         for (i = 0; i < ret; i++)
13994                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13995
13996         return 0;
13997 }
13998
13999 /* TC min bandwidth setting */
14000 static void
14001 cmd_vf_tc_min_bw_parsed(
14002         void *parsed_result,
14003         __attribute__((unused)) struct cmdline *cl,
14004         __attribute__((unused)) void *data)
14005 {
14006         struct cmd_vf_tc_bw_result *res = parsed_result;
14007         uint8_t tc_num;
14008         uint8_t bw[16];
14009         int ret = -ENOTSUP;
14010
14011         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14012                 return;
14013
14014         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14015         if (ret)
14016                 return;
14017
14018 #ifdef RTE_LIBRTE_I40E_PMD
14019         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14020                                               tc_num, bw);
14021 #endif
14022
14023         switch (ret) {
14024         case 0:
14025                 break;
14026         case -EINVAL:
14027                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14028                 break;
14029         case -ENODEV:
14030                 printf("invalid port_id %d\n", res->port_id);
14031                 break;
14032         case -ENOTSUP:
14033                 printf("function not implemented\n");
14034                 break;
14035         default:
14036                 printf("programming error: (%s)\n", strerror(-ret));
14037         }
14038 }
14039
14040 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14041         .f = cmd_vf_tc_min_bw_parsed,
14042         .data = NULL,
14043         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14044                     " <bw1, bw2, ...>",
14045         .tokens = {
14046                 (void *)&cmd_vf_tc_bw_set,
14047                 (void *)&cmd_vf_tc_bw_vf,
14048                 (void *)&cmd_vf_tc_bw_tc,
14049                 (void *)&cmd_vf_tc_bw_tx,
14050                 (void *)&cmd_vf_tc_bw_min_bw,
14051                 (void *)&cmd_vf_tc_bw_port_id,
14052                 (void *)&cmd_vf_tc_bw_vf_id,
14053                 (void *)&cmd_vf_tc_bw_bw_list,
14054                 NULL,
14055         },
14056 };
14057
14058 static void
14059 cmd_tc_min_bw_parsed(
14060         void *parsed_result,
14061         __attribute__((unused)) struct cmdline *cl,
14062         __attribute__((unused)) void *data)
14063 {
14064         struct cmd_vf_tc_bw_result *res = parsed_result;
14065         struct rte_port *port;
14066         uint8_t tc_num;
14067         uint8_t bw[16];
14068         int ret = -ENOTSUP;
14069
14070         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14071                 return;
14072
14073         port = &ports[res->port_id];
14074         /** Check if the port is not started **/
14075         if (port->port_status != RTE_PORT_STOPPED) {
14076                 printf("Please stop port %d first\n", res->port_id);
14077                 return;
14078         }
14079
14080         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14081         if (ret)
14082                 return;
14083
14084 #ifdef RTE_LIBRTE_IXGBE_PMD
14085         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14086 #endif
14087
14088         switch (ret) {
14089         case 0:
14090                 break;
14091         case -EINVAL:
14092                 printf("invalid bandwidth\n");
14093                 break;
14094         case -ENODEV:
14095                 printf("invalid port_id %d\n", res->port_id);
14096                 break;
14097         case -ENOTSUP:
14098                 printf("function not implemented\n");
14099                 break;
14100         default:
14101                 printf("programming error: (%s)\n", strerror(-ret));
14102         }
14103 }
14104
14105 cmdline_parse_inst_t cmd_tc_min_bw = {
14106         .f = cmd_tc_min_bw_parsed,
14107         .data = NULL,
14108         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14109         .tokens = {
14110                 (void *)&cmd_vf_tc_bw_set,
14111                 (void *)&cmd_vf_tc_bw_tc,
14112                 (void *)&cmd_vf_tc_bw_tx,
14113                 (void *)&cmd_vf_tc_bw_min_bw,
14114                 (void *)&cmd_vf_tc_bw_port_id,
14115                 (void *)&cmd_vf_tc_bw_bw_list,
14116                 NULL,
14117         },
14118 };
14119
14120 /* TC max bandwidth setting */
14121 static void
14122 cmd_vf_tc_max_bw_parsed(
14123         void *parsed_result,
14124         __attribute__((unused)) struct cmdline *cl,
14125         __attribute__((unused)) void *data)
14126 {
14127         struct cmd_vf_tc_bw_result *res = parsed_result;
14128         int ret = -ENOTSUP;
14129
14130         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14131                 return;
14132
14133 #ifdef RTE_LIBRTE_I40E_PMD
14134         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14135                                             res->tc_no, res->bw);
14136 #endif
14137
14138         switch (ret) {
14139         case 0:
14140                 break;
14141         case -EINVAL:
14142                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14143                        res->vf_id, res->tc_no, res->bw);
14144                 break;
14145         case -ENODEV:
14146                 printf("invalid port_id %d\n", res->port_id);
14147                 break;
14148         case -ENOTSUP:
14149                 printf("function not implemented\n");
14150                 break;
14151         default:
14152                 printf("programming error: (%s)\n", strerror(-ret));
14153         }
14154 }
14155
14156 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14157         .f = cmd_vf_tc_max_bw_parsed,
14158         .data = NULL,
14159         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14160                     " <bandwidth>",
14161         .tokens = {
14162                 (void *)&cmd_vf_tc_bw_set,
14163                 (void *)&cmd_vf_tc_bw_vf,
14164                 (void *)&cmd_vf_tc_bw_tc,
14165                 (void *)&cmd_vf_tc_bw_tx,
14166                 (void *)&cmd_vf_tc_bw_max_bw,
14167                 (void *)&cmd_vf_tc_bw_port_id,
14168                 (void *)&cmd_vf_tc_bw_vf_id,
14169                 (void *)&cmd_vf_tc_bw_tc_no,
14170                 (void *)&cmd_vf_tc_bw_bw,
14171                 NULL,
14172         },
14173 };
14174
14175
14176 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14177
14178 /* *** Set Port default Traffic Management Hierarchy *** */
14179 struct cmd_set_port_tm_hierarchy_default_result {
14180         cmdline_fixed_string_t set;
14181         cmdline_fixed_string_t port;
14182         cmdline_fixed_string_t tm;
14183         cmdline_fixed_string_t hierarchy;
14184         cmdline_fixed_string_t def;
14185         portid_t port_id;
14186 };
14187
14188 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14189         TOKEN_STRING_INITIALIZER(
14190                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14191 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14192         TOKEN_STRING_INITIALIZER(
14193                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14194 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14195         TOKEN_STRING_INITIALIZER(
14196                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14197 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14198         TOKEN_STRING_INITIALIZER(
14199                 struct cmd_set_port_tm_hierarchy_default_result,
14200                         hierarchy, "hierarchy");
14201 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14202         TOKEN_STRING_INITIALIZER(
14203                 struct cmd_set_port_tm_hierarchy_default_result,
14204                         def, "default");
14205 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14206         TOKEN_NUM_INITIALIZER(
14207                 struct cmd_set_port_tm_hierarchy_default_result,
14208                         port_id, UINT16);
14209
14210 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14211         __attribute__((unused)) struct cmdline *cl,
14212         __attribute__((unused)) void *data)
14213 {
14214         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14215         struct rte_port *p;
14216         portid_t port_id = res->port_id;
14217
14218         if (port_id_is_invalid(port_id, ENABLED_WARN))
14219                 return;
14220
14221         p = &ports[port_id];
14222
14223         /* Port tm flag */
14224         if (p->softport.tm_flag == 0) {
14225                 printf("  tm not enabled on port %u (error)\n", port_id);
14226                 return;
14227         }
14228
14229         /* Forward mode: tm */
14230         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14231                 printf("  tm mode not enabled(error)\n");
14232                 return;
14233         }
14234
14235         /* Set the default tm hierarchy */
14236         p->softport.tm.default_hierarchy_enable = 1;
14237 }
14238
14239 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14240         .f = cmd_set_port_tm_hierarchy_default_parsed,
14241         .data = NULL,
14242         .help_str = "set port tm hierarchy default <port_id>",
14243         .tokens = {
14244                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14245                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14246                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14247                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14248                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14249                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14250                 NULL,
14251         },
14252 };
14253 #endif
14254
14255 /* Strict link priority scheduling mode setting */
14256 static void
14257 cmd_strict_link_prio_parsed(
14258         void *parsed_result,
14259         __attribute__((unused)) struct cmdline *cl,
14260         __attribute__((unused)) void *data)
14261 {
14262         struct cmd_vf_tc_bw_result *res = parsed_result;
14263         int ret = -ENOTSUP;
14264
14265         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14266                 return;
14267
14268 #ifdef RTE_LIBRTE_I40E_PMD
14269         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14270 #endif
14271
14272         switch (ret) {
14273         case 0:
14274                 break;
14275         case -EINVAL:
14276                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14277                 break;
14278         case -ENODEV:
14279                 printf("invalid port_id %d\n", res->port_id);
14280                 break;
14281         case -ENOTSUP:
14282                 printf("function not implemented\n");
14283                 break;
14284         default:
14285                 printf("programming error: (%s)\n", strerror(-ret));
14286         }
14287 }
14288
14289 cmdline_parse_inst_t cmd_strict_link_prio = {
14290         .f = cmd_strict_link_prio_parsed,
14291         .data = NULL,
14292         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14293         .tokens = {
14294                 (void *)&cmd_vf_tc_bw_set,
14295                 (void *)&cmd_vf_tc_bw_tx,
14296                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14297                 (void *)&cmd_vf_tc_bw_port_id,
14298                 (void *)&cmd_vf_tc_bw_tc_map,
14299                 NULL,
14300         },
14301 };
14302
14303 /* Load dynamic device personalization*/
14304 struct cmd_ddp_add_result {
14305         cmdline_fixed_string_t ddp;
14306         cmdline_fixed_string_t add;
14307         portid_t port_id;
14308         char filepath[];
14309 };
14310
14311 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14312         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14313 cmdline_parse_token_string_t cmd_ddp_add_add =
14314         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14315 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14316         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14317 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14318         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14319
14320 static void
14321 cmd_ddp_add_parsed(
14322         void *parsed_result,
14323         __attribute__((unused)) struct cmdline *cl,
14324         __attribute__((unused)) void *data)
14325 {
14326         struct cmd_ddp_add_result *res = parsed_result;
14327         uint8_t *buff;
14328         uint32_t size;
14329         char *filepath;
14330         char *file_fld[2];
14331         int file_num;
14332         int ret = -ENOTSUP;
14333
14334         if (res->port_id > nb_ports) {
14335                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14336                 return;
14337         }
14338
14339         if (!all_ports_stopped()) {
14340                 printf("Please stop all ports first\n");
14341                 return;
14342         }
14343
14344         filepath = strdup(res->filepath);
14345         if (filepath == NULL) {
14346                 printf("Failed to allocate memory\n");
14347                 return;
14348         }
14349         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14350
14351         buff = open_ddp_package_file(file_fld[0], &size);
14352         if (!buff) {
14353                 free((void *)filepath);
14354                 return;
14355         }
14356
14357 #ifdef RTE_LIBRTE_I40E_PMD
14358         if (ret == -ENOTSUP)
14359                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14360                                                buff, size,
14361                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14362 #endif
14363
14364         if (ret == -EEXIST)
14365                 printf("Profile has already existed.\n");
14366         else if (ret < 0)
14367                 printf("Failed to load profile.\n");
14368         else if (file_num == 2)
14369                 save_ddp_package_file(file_fld[1], buff, size);
14370
14371         close_ddp_package_file(buff);
14372         free((void *)filepath);
14373 }
14374
14375 cmdline_parse_inst_t cmd_ddp_add = {
14376         .f = cmd_ddp_add_parsed,
14377         .data = NULL,
14378         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14379         .tokens = {
14380                 (void *)&cmd_ddp_add_ddp,
14381                 (void *)&cmd_ddp_add_add,
14382                 (void *)&cmd_ddp_add_port_id,
14383                 (void *)&cmd_ddp_add_filepath,
14384                 NULL,
14385         },
14386 };
14387
14388 /* Delete dynamic device personalization*/
14389 struct cmd_ddp_del_result {
14390         cmdline_fixed_string_t ddp;
14391         cmdline_fixed_string_t del;
14392         portid_t port_id;
14393         char filepath[];
14394 };
14395
14396 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14397         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14398 cmdline_parse_token_string_t cmd_ddp_del_del =
14399         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14400 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14401         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14402 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14403         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14404
14405 static void
14406 cmd_ddp_del_parsed(
14407         void *parsed_result,
14408         __attribute__((unused)) struct cmdline *cl,
14409         __attribute__((unused)) void *data)
14410 {
14411         struct cmd_ddp_del_result *res = parsed_result;
14412         uint8_t *buff;
14413         uint32_t size;
14414         int ret = -ENOTSUP;
14415
14416         if (res->port_id > nb_ports) {
14417                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14418                 return;
14419         }
14420
14421         if (!all_ports_stopped()) {
14422                 printf("Please stop all ports first\n");
14423                 return;
14424         }
14425
14426         buff = open_ddp_package_file(res->filepath, &size);
14427         if (!buff)
14428                 return;
14429
14430 #ifdef RTE_LIBRTE_I40E_PMD
14431         if (ret == -ENOTSUP)
14432                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14433                                                buff, size,
14434                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14435 #endif
14436
14437         if (ret == -EACCES)
14438                 printf("Profile does not exist.\n");
14439         else if (ret < 0)
14440                 printf("Failed to delete profile.\n");
14441
14442         close_ddp_package_file(buff);
14443 }
14444
14445 cmdline_parse_inst_t cmd_ddp_del = {
14446         .f = cmd_ddp_del_parsed,
14447         .data = NULL,
14448         .help_str = "ddp del <port_id> <profile_path>",
14449         .tokens = {
14450                 (void *)&cmd_ddp_del_ddp,
14451                 (void *)&cmd_ddp_del_del,
14452                 (void *)&cmd_ddp_del_port_id,
14453                 (void *)&cmd_ddp_del_filepath,
14454                 NULL,
14455         },
14456 };
14457
14458 /* Get dynamic device personalization profile info */
14459 struct cmd_ddp_info_result {
14460         cmdline_fixed_string_t ddp;
14461         cmdline_fixed_string_t get;
14462         cmdline_fixed_string_t info;
14463         char filepath[];
14464 };
14465
14466 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14467         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14468 cmdline_parse_token_string_t cmd_ddp_info_get =
14469         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14470 cmdline_parse_token_string_t cmd_ddp_info_info =
14471         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14472 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14473         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14474
14475 static void
14476 cmd_ddp_info_parsed(
14477         void *parsed_result,
14478         __attribute__((unused)) struct cmdline *cl,
14479         __attribute__((unused)) void *data)
14480 {
14481         struct cmd_ddp_info_result *res = parsed_result;
14482         uint8_t *pkg;
14483         uint32_t pkg_size;
14484         int ret = -ENOTSUP;
14485 #ifdef RTE_LIBRTE_I40E_PMD
14486         uint32_t i, j, n;
14487         uint8_t *buff;
14488         uint32_t buff_size = 0;
14489         struct rte_pmd_i40e_profile_info info;
14490         uint32_t dev_num = 0;
14491         struct rte_pmd_i40e_ddp_device_id *devs;
14492         uint32_t proto_num = 0;
14493         struct rte_pmd_i40e_proto_info *proto = NULL;
14494         uint32_t pctype_num = 0;
14495         struct rte_pmd_i40e_ptype_info *pctype;
14496         uint32_t ptype_num = 0;
14497         struct rte_pmd_i40e_ptype_info *ptype;
14498         uint8_t proto_id;
14499
14500 #endif
14501
14502         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14503         if (!pkg)
14504                 return;
14505
14506 #ifdef RTE_LIBRTE_I40E_PMD
14507         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14508                                 (uint8_t *)&info, sizeof(info),
14509                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14510         if (!ret) {
14511                 printf("Global Track id:       0x%x\n", info.track_id);
14512                 printf("Global Version:        %d.%d.%d.%d\n",
14513                         info.version.major,
14514                         info.version.minor,
14515                         info.version.update,
14516                         info.version.draft);
14517                 printf("Global Package name:   %s\n\n", info.name);
14518         }
14519
14520         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14521                                 (uint8_t *)&info, sizeof(info),
14522                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14523         if (!ret) {
14524                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14525                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14526                         info.version.major,
14527                         info.version.minor,
14528                         info.version.update,
14529                         info.version.draft);
14530                 printf("i40e Profile name:     %s\n\n", info.name);
14531         }
14532
14533         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14534                                 (uint8_t *)&buff_size, sizeof(buff_size),
14535                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14536         if (!ret && buff_size) {
14537                 buff = (uint8_t *)malloc(buff_size);
14538                 if (buff) {
14539                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14540                                                 buff, buff_size,
14541                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14542                         if (!ret)
14543                                 printf("Package Notes:\n%s\n\n", buff);
14544                         free(buff);
14545                 }
14546         }
14547
14548         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14549                                 (uint8_t *)&dev_num, sizeof(dev_num),
14550                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14551         if (!ret && dev_num) {
14552                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14553                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14554                 if (devs) {
14555                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14556                                                 (uint8_t *)devs, buff_size,
14557                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14558                         if (!ret) {
14559                                 printf("List of supported devices:\n");
14560                                 for (i = 0; i < dev_num; i++) {
14561                                         printf("  %04X:%04X %04X:%04X\n",
14562                                                 devs[i].vendor_dev_id >> 16,
14563                                                 devs[i].vendor_dev_id & 0xFFFF,
14564                                                 devs[i].sub_vendor_dev_id >> 16,
14565                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14566                                 }
14567                                 printf("\n");
14568                         }
14569                         free(devs);
14570                 }
14571         }
14572
14573         /* get information about protocols and packet types */
14574         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14575                 (uint8_t *)&proto_num, sizeof(proto_num),
14576                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14577         if (ret || !proto_num)
14578                 goto no_print_return;
14579
14580         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14581         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14582         if (!proto)
14583                 goto no_print_return;
14584
14585         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14586                                         buff_size,
14587                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14588         if (!ret) {
14589                 printf("List of used protocols:\n");
14590                 for (i = 0; i < proto_num; i++)
14591                         printf("  %2u: %s\n", proto[i].proto_id,
14592                                proto[i].name);
14593                 printf("\n");
14594         }
14595         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14596                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14597                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14598         if (ret || !pctype_num)
14599                 goto no_print_pctypes;
14600
14601         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14602         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14603         if (!pctype)
14604                 goto no_print_pctypes;
14605
14606         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14607                                         buff_size,
14608                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14609         if (ret) {
14610                 free(pctype);
14611                 goto no_print_pctypes;
14612         }
14613
14614         printf("List of defined packet classification types:\n");
14615         for (i = 0; i < pctype_num; i++) {
14616                 printf("  %2u:", pctype[i].ptype_id);
14617                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14618                         proto_id = pctype[i].protocols[j];
14619                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14620                                 for (n = 0; n < proto_num; n++) {
14621                                         if (proto[n].proto_id == proto_id) {
14622                                                 printf(" %s", proto[n].name);
14623                                                 break;
14624                                         }
14625                                 }
14626                         }
14627                 }
14628                 printf("\n");
14629         }
14630         printf("\n");
14631         free(pctype);
14632
14633 no_print_pctypes:
14634
14635         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14636                                         sizeof(ptype_num),
14637                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14638         if (ret || !ptype_num)
14639                 goto no_print_return;
14640
14641         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14642         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14643         if (!ptype)
14644                 goto no_print_return;
14645
14646         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14647                                         buff_size,
14648                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14649         if (ret) {
14650                 free(ptype);
14651                 goto no_print_return;
14652         }
14653         printf("List of defined packet types:\n");
14654         for (i = 0; i < ptype_num; i++) {
14655                 printf("  %2u:", ptype[i].ptype_id);
14656                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14657                         proto_id = ptype[i].protocols[j];
14658                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14659                                 for (n = 0; n < proto_num; n++) {
14660                                         if (proto[n].proto_id == proto_id) {
14661                                                 printf(" %s", proto[n].name);
14662                                                 break;
14663                                         }
14664                                 }
14665                         }
14666                 }
14667                 printf("\n");
14668         }
14669         free(ptype);
14670         printf("\n");
14671
14672         ret = 0;
14673 no_print_return:
14674         if (proto)
14675                 free(proto);
14676 #endif
14677         if (ret == -ENOTSUP)
14678                 printf("Function not supported in PMD driver\n");
14679         close_ddp_package_file(pkg);
14680 }
14681
14682 cmdline_parse_inst_t cmd_ddp_get_info = {
14683         .f = cmd_ddp_info_parsed,
14684         .data = NULL,
14685         .help_str = "ddp get info <profile_path>",
14686         .tokens = {
14687                 (void *)&cmd_ddp_info_ddp,
14688                 (void *)&cmd_ddp_info_get,
14689                 (void *)&cmd_ddp_info_info,
14690                 (void *)&cmd_ddp_info_filepath,
14691                 NULL,
14692         },
14693 };
14694
14695 /* Get dynamic device personalization profile info list*/
14696 #define PROFILE_INFO_SIZE 48
14697 #define MAX_PROFILE_NUM 16
14698
14699 struct cmd_ddp_get_list_result {
14700         cmdline_fixed_string_t ddp;
14701         cmdline_fixed_string_t get;
14702         cmdline_fixed_string_t list;
14703         portid_t port_id;
14704 };
14705
14706 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14707         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14708 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14709         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14710 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14711         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14712 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14713         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14714
14715 static void
14716 cmd_ddp_get_list_parsed(
14717         void *parsed_result,
14718         __attribute__((unused)) struct cmdline *cl,
14719         __attribute__((unused)) void *data)
14720 {
14721         struct cmd_ddp_get_list_result *res = parsed_result;
14722 #ifdef RTE_LIBRTE_I40E_PMD
14723         struct rte_pmd_i40e_profile_list *p_list;
14724         struct rte_pmd_i40e_profile_info *p_info;
14725         uint32_t p_num;
14726         uint32_t size;
14727         uint32_t i;
14728 #endif
14729         int ret = -ENOTSUP;
14730
14731         if (res->port_id > nb_ports) {
14732                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14733                 return;
14734         }
14735
14736 #ifdef RTE_LIBRTE_I40E_PMD
14737         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14738         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14739         if (!p_list)
14740                 printf("%s: Failed to malloc buffer\n", __func__);
14741
14742         if (ret == -ENOTSUP)
14743                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14744                                                 (uint8_t *)p_list, size);
14745
14746         if (!ret) {
14747                 p_num = p_list->p_count;
14748                 printf("Profile number is: %d\n\n", p_num);
14749
14750                 for (i = 0; i < p_num; i++) {
14751                         p_info = &p_list->p_info[i];
14752                         printf("Profile %d:\n", i);
14753                         printf("Track id:     0x%x\n", p_info->track_id);
14754                         printf("Version:      %d.%d.%d.%d\n",
14755                                p_info->version.major,
14756                                p_info->version.minor,
14757                                p_info->version.update,
14758                                p_info->version.draft);
14759                         printf("Profile name: %s\n\n", p_info->name);
14760                 }
14761         }
14762
14763         free(p_list);
14764 #endif
14765
14766         if (ret < 0)
14767                 printf("Failed to get ddp list\n");
14768 }
14769
14770 cmdline_parse_inst_t cmd_ddp_get_list = {
14771         .f = cmd_ddp_get_list_parsed,
14772         .data = NULL,
14773         .help_str = "ddp get list <port_id>",
14774         .tokens = {
14775                 (void *)&cmd_ddp_get_list_ddp,
14776                 (void *)&cmd_ddp_get_list_get,
14777                 (void *)&cmd_ddp_get_list_list,
14778                 (void *)&cmd_ddp_get_list_port_id,
14779                 NULL,
14780         },
14781 };
14782
14783 /* show vf stats */
14784
14785 /* Common result structure for show vf stats */
14786 struct cmd_show_vf_stats_result {
14787         cmdline_fixed_string_t show;
14788         cmdline_fixed_string_t vf;
14789         cmdline_fixed_string_t stats;
14790         portid_t port_id;
14791         uint16_t vf_id;
14792 };
14793
14794 /* Common CLI fields show vf stats*/
14795 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14796         TOKEN_STRING_INITIALIZER
14797                 (struct cmd_show_vf_stats_result,
14798                  show, "show");
14799 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14800         TOKEN_STRING_INITIALIZER
14801                 (struct cmd_show_vf_stats_result,
14802                  vf, "vf");
14803 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14804         TOKEN_STRING_INITIALIZER
14805                 (struct cmd_show_vf_stats_result,
14806                  stats, "stats");
14807 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14808         TOKEN_NUM_INITIALIZER
14809                 (struct cmd_show_vf_stats_result,
14810                  port_id, UINT16);
14811 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14812         TOKEN_NUM_INITIALIZER
14813                 (struct cmd_show_vf_stats_result,
14814                  vf_id, UINT16);
14815
14816 static void
14817 cmd_show_vf_stats_parsed(
14818         void *parsed_result,
14819         __attribute__((unused)) struct cmdline *cl,
14820         __attribute__((unused)) void *data)
14821 {
14822         struct cmd_show_vf_stats_result *res = parsed_result;
14823         struct rte_eth_stats stats;
14824         int ret = -ENOTSUP;
14825         static const char *nic_stats_border = "########################";
14826
14827         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14828                 return;
14829
14830         memset(&stats, 0, sizeof(stats));
14831
14832 #ifdef RTE_LIBRTE_I40E_PMD
14833         if (ret == -ENOTSUP)
14834                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14835                                                 res->vf_id,
14836                                                 &stats);
14837 #endif
14838 #ifdef RTE_LIBRTE_BNXT_PMD
14839         if (ret == -ENOTSUP)
14840                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14841                                                 res->vf_id,
14842                                                 &stats);
14843 #endif
14844
14845         switch (ret) {
14846         case 0:
14847                 break;
14848         case -EINVAL:
14849                 printf("invalid vf_id %d\n", res->vf_id);
14850                 break;
14851         case -ENODEV:
14852                 printf("invalid port_id %d\n", res->port_id);
14853                 break;
14854         case -ENOTSUP:
14855                 printf("function not implemented\n");
14856                 break;
14857         default:
14858                 printf("programming error: (%s)\n", strerror(-ret));
14859         }
14860
14861         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14862                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14863
14864         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14865                "%-"PRIu64"\n",
14866                stats.ipackets, stats.imissed, stats.ibytes);
14867         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14868         printf("  RX-nombuf:  %-10"PRIu64"\n",
14869                stats.rx_nombuf);
14870         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14871                "%-"PRIu64"\n",
14872                stats.opackets, stats.oerrors, stats.obytes);
14873
14874         printf("  %s############################%s\n",
14875                                nic_stats_border, nic_stats_border);
14876 }
14877
14878 cmdline_parse_inst_t cmd_show_vf_stats = {
14879         .f = cmd_show_vf_stats_parsed,
14880         .data = NULL,
14881         .help_str = "show vf stats <port_id> <vf_id>",
14882         .tokens = {
14883                 (void *)&cmd_show_vf_stats_show,
14884                 (void *)&cmd_show_vf_stats_vf,
14885                 (void *)&cmd_show_vf_stats_stats,
14886                 (void *)&cmd_show_vf_stats_port_id,
14887                 (void *)&cmd_show_vf_stats_vf_id,
14888                 NULL,
14889         },
14890 };
14891
14892 /* clear vf stats */
14893
14894 /* Common result structure for clear vf stats */
14895 struct cmd_clear_vf_stats_result {
14896         cmdline_fixed_string_t clear;
14897         cmdline_fixed_string_t vf;
14898         cmdline_fixed_string_t stats;
14899         portid_t port_id;
14900         uint16_t vf_id;
14901 };
14902
14903 /* Common CLI fields clear vf stats*/
14904 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14905         TOKEN_STRING_INITIALIZER
14906                 (struct cmd_clear_vf_stats_result,
14907                  clear, "clear");
14908 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14909         TOKEN_STRING_INITIALIZER
14910                 (struct cmd_clear_vf_stats_result,
14911                  vf, "vf");
14912 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14913         TOKEN_STRING_INITIALIZER
14914                 (struct cmd_clear_vf_stats_result,
14915                  stats, "stats");
14916 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14917         TOKEN_NUM_INITIALIZER
14918                 (struct cmd_clear_vf_stats_result,
14919                  port_id, UINT16);
14920 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14921         TOKEN_NUM_INITIALIZER
14922                 (struct cmd_clear_vf_stats_result,
14923                  vf_id, UINT16);
14924
14925 static void
14926 cmd_clear_vf_stats_parsed(
14927         void *parsed_result,
14928         __attribute__((unused)) struct cmdline *cl,
14929         __attribute__((unused)) void *data)
14930 {
14931         struct cmd_clear_vf_stats_result *res = parsed_result;
14932         int ret = -ENOTSUP;
14933
14934         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14935                 return;
14936
14937 #ifdef RTE_LIBRTE_I40E_PMD
14938         if (ret == -ENOTSUP)
14939                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14940                                                   res->vf_id);
14941 #endif
14942 #ifdef RTE_LIBRTE_BNXT_PMD
14943         if (ret == -ENOTSUP)
14944                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14945                                                   res->vf_id);
14946 #endif
14947
14948         switch (ret) {
14949         case 0:
14950                 break;
14951         case -EINVAL:
14952                 printf("invalid vf_id %d\n", res->vf_id);
14953                 break;
14954         case -ENODEV:
14955                 printf("invalid port_id %d\n", res->port_id);
14956                 break;
14957         case -ENOTSUP:
14958                 printf("function not implemented\n");
14959                 break;
14960         default:
14961                 printf("programming error: (%s)\n", strerror(-ret));
14962         }
14963 }
14964
14965 cmdline_parse_inst_t cmd_clear_vf_stats = {
14966         .f = cmd_clear_vf_stats_parsed,
14967         .data = NULL,
14968         .help_str = "clear vf stats <port_id> <vf_id>",
14969         .tokens = {
14970                 (void *)&cmd_clear_vf_stats_clear,
14971                 (void *)&cmd_clear_vf_stats_vf,
14972                 (void *)&cmd_clear_vf_stats_stats,
14973                 (void *)&cmd_clear_vf_stats_port_id,
14974                 (void *)&cmd_clear_vf_stats_vf_id,
14975                 NULL,
14976         },
14977 };
14978
14979 /* port config pctype mapping reset */
14980
14981 /* Common result structure for port config pctype mapping reset */
14982 struct cmd_pctype_mapping_reset_result {
14983         cmdline_fixed_string_t port;
14984         cmdline_fixed_string_t config;
14985         portid_t port_id;
14986         cmdline_fixed_string_t pctype;
14987         cmdline_fixed_string_t mapping;
14988         cmdline_fixed_string_t reset;
14989 };
14990
14991 /* Common CLI fields for port config pctype mapping reset*/
14992 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14993         TOKEN_STRING_INITIALIZER
14994                 (struct cmd_pctype_mapping_reset_result,
14995                  port, "port");
14996 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14997         TOKEN_STRING_INITIALIZER
14998                 (struct cmd_pctype_mapping_reset_result,
14999                  config, "config");
15000 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15001         TOKEN_NUM_INITIALIZER
15002                 (struct cmd_pctype_mapping_reset_result,
15003                  port_id, UINT16);
15004 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15005         TOKEN_STRING_INITIALIZER
15006                 (struct cmd_pctype_mapping_reset_result,
15007                  pctype, "pctype");
15008 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15009         TOKEN_STRING_INITIALIZER
15010                 (struct cmd_pctype_mapping_reset_result,
15011                  mapping, "mapping");
15012 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_pctype_mapping_reset_result,
15015                  reset, "reset");
15016
15017 static void
15018 cmd_pctype_mapping_reset_parsed(
15019         void *parsed_result,
15020         __attribute__((unused)) struct cmdline *cl,
15021         __attribute__((unused)) void *data)
15022 {
15023         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15024         int ret = -ENOTSUP;
15025
15026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15027                 return;
15028
15029 #ifdef RTE_LIBRTE_I40E_PMD
15030         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15031 #endif
15032
15033         switch (ret) {
15034         case 0:
15035                 break;
15036         case -ENODEV:
15037                 printf("invalid port_id %d\n", res->port_id);
15038                 break;
15039         case -ENOTSUP:
15040                 printf("function not implemented\n");
15041                 break;
15042         default:
15043                 printf("programming error: (%s)\n", strerror(-ret));
15044         }
15045 }
15046
15047 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15048         .f = cmd_pctype_mapping_reset_parsed,
15049         .data = NULL,
15050         .help_str = "port config <port_id> pctype mapping reset",
15051         .tokens = {
15052                 (void *)&cmd_pctype_mapping_reset_port,
15053                 (void *)&cmd_pctype_mapping_reset_config,
15054                 (void *)&cmd_pctype_mapping_reset_port_id,
15055                 (void *)&cmd_pctype_mapping_reset_pctype,
15056                 (void *)&cmd_pctype_mapping_reset_mapping,
15057                 (void *)&cmd_pctype_mapping_reset_reset,
15058                 NULL,
15059         },
15060 };
15061
15062 /* show port pctype mapping */
15063
15064 /* Common result structure for show port pctype mapping */
15065 struct cmd_pctype_mapping_get_result {
15066         cmdline_fixed_string_t show;
15067         cmdline_fixed_string_t port;
15068         portid_t port_id;
15069         cmdline_fixed_string_t pctype;
15070         cmdline_fixed_string_t mapping;
15071 };
15072
15073 /* Common CLI fields for pctype mapping get */
15074 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15075         TOKEN_STRING_INITIALIZER
15076                 (struct cmd_pctype_mapping_get_result,
15077                  show, "show");
15078 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15079         TOKEN_STRING_INITIALIZER
15080                 (struct cmd_pctype_mapping_get_result,
15081                  port, "port");
15082 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15083         TOKEN_NUM_INITIALIZER
15084                 (struct cmd_pctype_mapping_get_result,
15085                  port_id, UINT16);
15086 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15087         TOKEN_STRING_INITIALIZER
15088                 (struct cmd_pctype_mapping_get_result,
15089                  pctype, "pctype");
15090 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15091         TOKEN_STRING_INITIALIZER
15092                 (struct cmd_pctype_mapping_get_result,
15093                  mapping, "mapping");
15094
15095 static void
15096 cmd_pctype_mapping_get_parsed(
15097         void *parsed_result,
15098         __attribute__((unused)) struct cmdline *cl,
15099         __attribute__((unused)) void *data)
15100 {
15101         struct cmd_pctype_mapping_get_result *res = parsed_result;
15102         int ret = -ENOTSUP;
15103 #ifdef RTE_LIBRTE_I40E_PMD
15104         struct rte_pmd_i40e_flow_type_mapping
15105                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15106         int i, j, first_pctype;
15107 #endif
15108
15109         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15110                 return;
15111
15112 #ifdef RTE_LIBRTE_I40E_PMD
15113         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15114 #endif
15115
15116         switch (ret) {
15117         case 0:
15118                 break;
15119         case -ENODEV:
15120                 printf("invalid port_id %d\n", res->port_id);
15121                 return;
15122         case -ENOTSUP:
15123                 printf("function not implemented\n");
15124                 return;
15125         default:
15126                 printf("programming error: (%s)\n", strerror(-ret));
15127                 return;
15128         }
15129
15130 #ifdef RTE_LIBRTE_I40E_PMD
15131         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15132                 if (mapping[i].pctype != 0ULL) {
15133                         first_pctype = 1;
15134
15135                         printf("pctype: ");
15136                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15137                                 if (mapping[i].pctype & (1ULL << j)) {
15138                                         printf(first_pctype ?
15139                                                "%02d" : ",%02d", j);
15140                                         first_pctype = 0;
15141                                 }
15142                         }
15143                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15144                 }
15145         }
15146 #endif
15147 }
15148
15149 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15150         .f = cmd_pctype_mapping_get_parsed,
15151         .data = NULL,
15152         .help_str = "show port <port_id> pctype mapping",
15153         .tokens = {
15154                 (void *)&cmd_pctype_mapping_get_show,
15155                 (void *)&cmd_pctype_mapping_get_port,
15156                 (void *)&cmd_pctype_mapping_get_port_id,
15157                 (void *)&cmd_pctype_mapping_get_pctype,
15158                 (void *)&cmd_pctype_mapping_get_mapping,
15159                 NULL,
15160         },
15161 };
15162
15163 /* port config pctype mapping update */
15164
15165 /* Common result structure for port config pctype mapping update */
15166 struct cmd_pctype_mapping_update_result {
15167         cmdline_fixed_string_t port;
15168         cmdline_fixed_string_t config;
15169         portid_t port_id;
15170         cmdline_fixed_string_t pctype;
15171         cmdline_fixed_string_t mapping;
15172         cmdline_fixed_string_t update;
15173         cmdline_fixed_string_t pctype_list;
15174         uint16_t flow_type;
15175 };
15176
15177 /* Common CLI fields for pctype mapping update*/
15178 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15179         TOKEN_STRING_INITIALIZER
15180                 (struct cmd_pctype_mapping_update_result,
15181                  port, "port");
15182 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15183         TOKEN_STRING_INITIALIZER
15184                 (struct cmd_pctype_mapping_update_result,
15185                  config, "config");
15186 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15187         TOKEN_NUM_INITIALIZER
15188                 (struct cmd_pctype_mapping_update_result,
15189                  port_id, UINT16);
15190 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15191         TOKEN_STRING_INITIALIZER
15192                 (struct cmd_pctype_mapping_update_result,
15193                  pctype, "pctype");
15194 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15195         TOKEN_STRING_INITIALIZER
15196                 (struct cmd_pctype_mapping_update_result,
15197                  mapping, "mapping");
15198 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15199         TOKEN_STRING_INITIALIZER
15200                 (struct cmd_pctype_mapping_update_result,
15201                  update, "update");
15202 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15203         TOKEN_STRING_INITIALIZER
15204                 (struct cmd_pctype_mapping_update_result,
15205                  pctype_list, NULL);
15206 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15207         TOKEN_NUM_INITIALIZER
15208                 (struct cmd_pctype_mapping_update_result,
15209                  flow_type, UINT16);
15210
15211 static void
15212 cmd_pctype_mapping_update_parsed(
15213         void *parsed_result,
15214         __attribute__((unused)) struct cmdline *cl,
15215         __attribute__((unused)) void *data)
15216 {
15217         struct cmd_pctype_mapping_update_result *res = parsed_result;
15218         int ret = -ENOTSUP;
15219 #ifdef RTE_LIBRTE_I40E_PMD
15220         struct rte_pmd_i40e_flow_type_mapping mapping;
15221         unsigned int i;
15222         unsigned int nb_item;
15223         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15224 #endif
15225
15226         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15227                 return;
15228
15229 #ifdef RTE_LIBRTE_I40E_PMD
15230         nb_item = parse_item_list(res->pctype_list, "pctypes",
15231                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15232         mapping.flow_type = res->flow_type;
15233         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15234                 mapping.pctype |= (1ULL << pctype_list[i]);
15235         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15236                                                 &mapping,
15237                                                 1,
15238                                                 0);
15239 #endif
15240
15241         switch (ret) {
15242         case 0:
15243                 break;
15244         case -EINVAL:
15245                 printf("invalid pctype or flow type\n");
15246                 break;
15247         case -ENODEV:
15248                 printf("invalid port_id %d\n", res->port_id);
15249                 break;
15250         case -ENOTSUP:
15251                 printf("function not implemented\n");
15252                 break;
15253         default:
15254                 printf("programming error: (%s)\n", strerror(-ret));
15255         }
15256 }
15257
15258 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15259         .f = cmd_pctype_mapping_update_parsed,
15260         .data = NULL,
15261         .help_str = "port config <port_id> pctype mapping update"
15262         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15263         .tokens = {
15264                 (void *)&cmd_pctype_mapping_update_port,
15265                 (void *)&cmd_pctype_mapping_update_config,
15266                 (void *)&cmd_pctype_mapping_update_port_id,
15267                 (void *)&cmd_pctype_mapping_update_pctype,
15268                 (void *)&cmd_pctype_mapping_update_mapping,
15269                 (void *)&cmd_pctype_mapping_update_update,
15270                 (void *)&cmd_pctype_mapping_update_pc_type,
15271                 (void *)&cmd_pctype_mapping_update_flow_type,
15272                 NULL,
15273         },
15274 };
15275
15276 /* ptype mapping get */
15277
15278 /* Common result structure for ptype mapping get */
15279 struct cmd_ptype_mapping_get_result {
15280         cmdline_fixed_string_t ptype;
15281         cmdline_fixed_string_t mapping;
15282         cmdline_fixed_string_t get;
15283         portid_t port_id;
15284         uint8_t valid_only;
15285 };
15286
15287 /* Common CLI fields for ptype mapping get */
15288 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15289         TOKEN_STRING_INITIALIZER
15290                 (struct cmd_ptype_mapping_get_result,
15291                  ptype, "ptype");
15292 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15293         TOKEN_STRING_INITIALIZER
15294                 (struct cmd_ptype_mapping_get_result,
15295                  mapping, "mapping");
15296 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15297         TOKEN_STRING_INITIALIZER
15298                 (struct cmd_ptype_mapping_get_result,
15299                  get, "get");
15300 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15301         TOKEN_NUM_INITIALIZER
15302                 (struct cmd_ptype_mapping_get_result,
15303                  port_id, UINT16);
15304 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15305         TOKEN_NUM_INITIALIZER
15306                 (struct cmd_ptype_mapping_get_result,
15307                  valid_only, UINT8);
15308
15309 static void
15310 cmd_ptype_mapping_get_parsed(
15311         void *parsed_result,
15312         __attribute__((unused)) struct cmdline *cl,
15313         __attribute__((unused)) void *data)
15314 {
15315         struct cmd_ptype_mapping_get_result *res = parsed_result;
15316         int ret = -ENOTSUP;
15317 #ifdef RTE_LIBRTE_I40E_PMD
15318         int max_ptype_num = 256;
15319         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15320         uint16_t count;
15321         int i;
15322 #endif
15323
15324         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15325                 return;
15326
15327 #ifdef RTE_LIBRTE_I40E_PMD
15328         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15329                                         mapping,
15330                                         max_ptype_num,
15331                                         &count,
15332                                         res->valid_only);
15333 #endif
15334
15335         switch (ret) {
15336         case 0:
15337                 break;
15338         case -ENODEV:
15339                 printf("invalid port_id %d\n", res->port_id);
15340                 break;
15341         case -ENOTSUP:
15342                 printf("function not implemented\n");
15343                 break;
15344         default:
15345                 printf("programming error: (%s)\n", strerror(-ret));
15346         }
15347
15348 #ifdef RTE_LIBRTE_I40E_PMD
15349         if (!ret) {
15350                 for (i = 0; i < count; i++)
15351                         printf("%3d\t0x%08x\n",
15352                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15353         }
15354 #endif
15355 }
15356
15357 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15358         .f = cmd_ptype_mapping_get_parsed,
15359         .data = NULL,
15360         .help_str = "ptype mapping get <port_id> <valid_only>",
15361         .tokens = {
15362                 (void *)&cmd_ptype_mapping_get_ptype,
15363                 (void *)&cmd_ptype_mapping_get_mapping,
15364                 (void *)&cmd_ptype_mapping_get_get,
15365                 (void *)&cmd_ptype_mapping_get_port_id,
15366                 (void *)&cmd_ptype_mapping_get_valid_only,
15367                 NULL,
15368         },
15369 };
15370
15371 /* ptype mapping replace */
15372
15373 /* Common result structure for ptype mapping replace */
15374 struct cmd_ptype_mapping_replace_result {
15375         cmdline_fixed_string_t ptype;
15376         cmdline_fixed_string_t mapping;
15377         cmdline_fixed_string_t replace;
15378         portid_t port_id;
15379         uint32_t target;
15380         uint8_t mask;
15381         uint32_t pkt_type;
15382 };
15383
15384 /* Common CLI fields for ptype mapping replace */
15385 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15386         TOKEN_STRING_INITIALIZER
15387                 (struct cmd_ptype_mapping_replace_result,
15388                  ptype, "ptype");
15389 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15390         TOKEN_STRING_INITIALIZER
15391                 (struct cmd_ptype_mapping_replace_result,
15392                  mapping, "mapping");
15393 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15394         TOKEN_STRING_INITIALIZER
15395                 (struct cmd_ptype_mapping_replace_result,
15396                  replace, "replace");
15397 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15398         TOKEN_NUM_INITIALIZER
15399                 (struct cmd_ptype_mapping_replace_result,
15400                  port_id, UINT16);
15401 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15402         TOKEN_NUM_INITIALIZER
15403                 (struct cmd_ptype_mapping_replace_result,
15404                  target, UINT32);
15405 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15406         TOKEN_NUM_INITIALIZER
15407                 (struct cmd_ptype_mapping_replace_result,
15408                  mask, UINT8);
15409 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15410         TOKEN_NUM_INITIALIZER
15411                 (struct cmd_ptype_mapping_replace_result,
15412                  pkt_type, UINT32);
15413
15414 static void
15415 cmd_ptype_mapping_replace_parsed(
15416         void *parsed_result,
15417         __attribute__((unused)) struct cmdline *cl,
15418         __attribute__((unused)) void *data)
15419 {
15420         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15421         int ret = -ENOTSUP;
15422
15423         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15424                 return;
15425
15426 #ifdef RTE_LIBRTE_I40E_PMD
15427         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15428                                         res->target,
15429                                         res->mask,
15430                                         res->pkt_type);
15431 #endif
15432
15433         switch (ret) {
15434         case 0:
15435                 break;
15436         case -EINVAL:
15437                 printf("invalid ptype 0x%8x or 0x%8x\n",
15438                                 res->target, res->pkt_type);
15439                 break;
15440         case -ENODEV:
15441                 printf("invalid port_id %d\n", res->port_id);
15442                 break;
15443         case -ENOTSUP:
15444                 printf("function not implemented\n");
15445                 break;
15446         default:
15447                 printf("programming error: (%s)\n", strerror(-ret));
15448         }
15449 }
15450
15451 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15452         .f = cmd_ptype_mapping_replace_parsed,
15453         .data = NULL,
15454         .help_str =
15455                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15456         .tokens = {
15457                 (void *)&cmd_ptype_mapping_replace_ptype,
15458                 (void *)&cmd_ptype_mapping_replace_mapping,
15459                 (void *)&cmd_ptype_mapping_replace_replace,
15460                 (void *)&cmd_ptype_mapping_replace_port_id,
15461                 (void *)&cmd_ptype_mapping_replace_target,
15462                 (void *)&cmd_ptype_mapping_replace_mask,
15463                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15464                 NULL,
15465         },
15466 };
15467
15468 /* ptype mapping reset */
15469
15470 /* Common result structure for ptype mapping reset */
15471 struct cmd_ptype_mapping_reset_result {
15472         cmdline_fixed_string_t ptype;
15473         cmdline_fixed_string_t mapping;
15474         cmdline_fixed_string_t reset;
15475         portid_t port_id;
15476 };
15477
15478 /* Common CLI fields for ptype mapping reset*/
15479 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15480         TOKEN_STRING_INITIALIZER
15481                 (struct cmd_ptype_mapping_reset_result,
15482                  ptype, "ptype");
15483 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15484         TOKEN_STRING_INITIALIZER
15485                 (struct cmd_ptype_mapping_reset_result,
15486                  mapping, "mapping");
15487 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15488         TOKEN_STRING_INITIALIZER
15489                 (struct cmd_ptype_mapping_reset_result,
15490                  reset, "reset");
15491 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15492         TOKEN_NUM_INITIALIZER
15493                 (struct cmd_ptype_mapping_reset_result,
15494                  port_id, UINT16);
15495
15496 static void
15497 cmd_ptype_mapping_reset_parsed(
15498         void *parsed_result,
15499         __attribute__((unused)) struct cmdline *cl,
15500         __attribute__((unused)) void *data)
15501 {
15502         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15503         int ret = -ENOTSUP;
15504
15505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15506                 return;
15507
15508 #ifdef RTE_LIBRTE_I40E_PMD
15509         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15510 #endif
15511
15512         switch (ret) {
15513         case 0:
15514                 break;
15515         case -ENODEV:
15516                 printf("invalid port_id %d\n", res->port_id);
15517                 break;
15518         case -ENOTSUP:
15519                 printf("function not implemented\n");
15520                 break;
15521         default:
15522                 printf("programming error: (%s)\n", strerror(-ret));
15523         }
15524 }
15525
15526 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15527         .f = cmd_ptype_mapping_reset_parsed,
15528         .data = NULL,
15529         .help_str = "ptype mapping reset <port_id>",
15530         .tokens = {
15531                 (void *)&cmd_ptype_mapping_reset_ptype,
15532                 (void *)&cmd_ptype_mapping_reset_mapping,
15533                 (void *)&cmd_ptype_mapping_reset_reset,
15534                 (void *)&cmd_ptype_mapping_reset_port_id,
15535                 NULL,
15536         },
15537 };
15538
15539 /* ptype mapping update */
15540
15541 /* Common result structure for ptype mapping update */
15542 struct cmd_ptype_mapping_update_result {
15543         cmdline_fixed_string_t ptype;
15544         cmdline_fixed_string_t mapping;
15545         cmdline_fixed_string_t reset;
15546         portid_t port_id;
15547         uint8_t hw_ptype;
15548         uint32_t sw_ptype;
15549 };
15550
15551 /* Common CLI fields for ptype mapping update*/
15552 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15553         TOKEN_STRING_INITIALIZER
15554                 (struct cmd_ptype_mapping_update_result,
15555                  ptype, "ptype");
15556 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15557         TOKEN_STRING_INITIALIZER
15558                 (struct cmd_ptype_mapping_update_result,
15559                  mapping, "mapping");
15560 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15561         TOKEN_STRING_INITIALIZER
15562                 (struct cmd_ptype_mapping_update_result,
15563                  reset, "update");
15564 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15565         TOKEN_NUM_INITIALIZER
15566                 (struct cmd_ptype_mapping_update_result,
15567                  port_id, UINT16);
15568 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15569         TOKEN_NUM_INITIALIZER
15570                 (struct cmd_ptype_mapping_update_result,
15571                  hw_ptype, UINT8);
15572 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15573         TOKEN_NUM_INITIALIZER
15574                 (struct cmd_ptype_mapping_update_result,
15575                  sw_ptype, UINT32);
15576
15577 static void
15578 cmd_ptype_mapping_update_parsed(
15579         void *parsed_result,
15580         __attribute__((unused)) struct cmdline *cl,
15581         __attribute__((unused)) void *data)
15582 {
15583         struct cmd_ptype_mapping_update_result *res = parsed_result;
15584         int ret = -ENOTSUP;
15585 #ifdef RTE_LIBRTE_I40E_PMD
15586         struct rte_pmd_i40e_ptype_mapping mapping;
15587 #endif
15588         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15589                 return;
15590
15591 #ifdef RTE_LIBRTE_I40E_PMD
15592         mapping.hw_ptype = res->hw_ptype;
15593         mapping.sw_ptype = res->sw_ptype;
15594         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15595                                                 &mapping,
15596                                                 1,
15597                                                 0);
15598 #endif
15599
15600         switch (ret) {
15601         case 0:
15602                 break;
15603         case -EINVAL:
15604                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15605                 break;
15606         case -ENODEV:
15607                 printf("invalid port_id %d\n", res->port_id);
15608                 break;
15609         case -ENOTSUP:
15610                 printf("function not implemented\n");
15611                 break;
15612         default:
15613                 printf("programming error: (%s)\n", strerror(-ret));
15614         }
15615 }
15616
15617 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15618         .f = cmd_ptype_mapping_update_parsed,
15619         .data = NULL,
15620         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15621         .tokens = {
15622                 (void *)&cmd_ptype_mapping_update_ptype,
15623                 (void *)&cmd_ptype_mapping_update_mapping,
15624                 (void *)&cmd_ptype_mapping_update_update,
15625                 (void *)&cmd_ptype_mapping_update_port_id,
15626                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15627                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15628                 NULL,
15629         },
15630 };
15631
15632 /* Common result structure for file commands */
15633 struct cmd_cmdfile_result {
15634         cmdline_fixed_string_t load;
15635         cmdline_fixed_string_t filename;
15636 };
15637
15638 /* Common CLI fields for file commands */
15639 cmdline_parse_token_string_t cmd_load_cmdfile =
15640         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15641 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15642         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15643
15644 static void
15645 cmd_load_from_file_parsed(
15646         void *parsed_result,
15647         __attribute__((unused)) struct cmdline *cl,
15648         __attribute__((unused)) void *data)
15649 {
15650         struct cmd_cmdfile_result *res = parsed_result;
15651
15652         cmdline_read_from_file(res->filename);
15653 }
15654
15655 cmdline_parse_inst_t cmd_load_from_file = {
15656         .f = cmd_load_from_file_parsed,
15657         .data = NULL,
15658         .help_str = "load <filename>",
15659         .tokens = {
15660                 (void *)&cmd_load_cmdfile,
15661                 (void *)&cmd_load_cmdfile_filename,
15662                 NULL,
15663         },
15664 };
15665
15666 /* ******************************************************************************** */
15667
15668 /* list of instructions */
15669 cmdline_parse_ctx_t main_ctx[] = {
15670         (cmdline_parse_inst_t *)&cmd_help_brief,
15671         (cmdline_parse_inst_t *)&cmd_help_long,
15672         (cmdline_parse_inst_t *)&cmd_quit,
15673         (cmdline_parse_inst_t *)&cmd_load_from_file,
15674         (cmdline_parse_inst_t *)&cmd_showport,
15675         (cmdline_parse_inst_t *)&cmd_showqueue,
15676         (cmdline_parse_inst_t *)&cmd_showportall,
15677         (cmdline_parse_inst_t *)&cmd_showcfg,
15678         (cmdline_parse_inst_t *)&cmd_start,
15679         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15680         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15681         (cmdline_parse_inst_t *)&cmd_set_link_up,
15682         (cmdline_parse_inst_t *)&cmd_set_link_down,
15683         (cmdline_parse_inst_t *)&cmd_reset,
15684         (cmdline_parse_inst_t *)&cmd_set_numbers,
15685         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15686         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15687         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15688         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15689         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15690         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15691         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15692         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15693         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15694         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15695         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15696         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15697         (cmdline_parse_inst_t *)&cmd_set_link_check,
15698         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15699         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15700         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15701         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15702 #ifdef RTE_LIBRTE_PMD_BOND
15703         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15704         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15705         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15706         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15707         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15708         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15709         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15710         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15711         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15712         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15713         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15714 #endif
15715         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15716         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15717         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15718         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15719         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15720         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15721         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15722         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15723         (cmdline_parse_inst_t *)&cmd_csum_set,
15724         (cmdline_parse_inst_t *)&cmd_csum_show,
15725         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15726         (cmdline_parse_inst_t *)&cmd_tso_set,
15727         (cmdline_parse_inst_t *)&cmd_tso_show,
15728         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15729         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15730         (cmdline_parse_inst_t *)&cmd_gro_enable,
15731         (cmdline_parse_inst_t *)&cmd_gro_flush,
15732         (cmdline_parse_inst_t *)&cmd_gro_show,
15733         (cmdline_parse_inst_t *)&cmd_gso_enable,
15734         (cmdline_parse_inst_t *)&cmd_gso_size,
15735         (cmdline_parse_inst_t *)&cmd_gso_show,
15736         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15737         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15738         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15739         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15740         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15741         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15742         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15743         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15744         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15745         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15746         (cmdline_parse_inst_t *)&cmd_config_dcb,
15747         (cmdline_parse_inst_t *)&cmd_read_reg,
15748         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15749         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15750         (cmdline_parse_inst_t *)&cmd_write_reg,
15751         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15752         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15753         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15754         (cmdline_parse_inst_t *)&cmd_stop,
15755         (cmdline_parse_inst_t *)&cmd_mac_addr,
15756         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
15757         (cmdline_parse_inst_t *)&cmd_set_qmap,
15758         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15759         (cmdline_parse_inst_t *)&cmd_operate_port,
15760         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15761         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15762         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15763         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15764         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15765         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15766         (cmdline_parse_inst_t *)&cmd_config_mtu,
15767         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15768         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15769         (cmdline_parse_inst_t *)&cmd_config_rss,
15770         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15771         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15772         (cmdline_parse_inst_t *)&cmd_showport_reta,
15773         (cmdline_parse_inst_t *)&cmd_config_burst,
15774         (cmdline_parse_inst_t *)&cmd_config_thresh,
15775         (cmdline_parse_inst_t *)&cmd_config_threshold,
15776         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15777         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15778         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15779         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15780         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15781         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15782         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15783         (cmdline_parse_inst_t *)&cmd_global_config,
15784         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15785         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15786         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15787         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15788         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15789         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15790         (cmdline_parse_inst_t *)&cmd_dump,
15791         (cmdline_parse_inst_t *)&cmd_dump_one,
15792         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15793         (cmdline_parse_inst_t *)&cmd_syn_filter,
15794         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15795         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15796         (cmdline_parse_inst_t *)&cmd_flex_filter,
15797         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15798         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15799         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15800         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15801         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15802         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15803         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15804         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15805         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15806         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15807         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15808         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15809         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15810         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15811         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15812         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15813         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15814         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15815         (cmdline_parse_inst_t *)&cmd_flow,
15816         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15817         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15818         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15819         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15820         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15821         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15822         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15823         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15824         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15825         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15826         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15827         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15828         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15829         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15830         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15831         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15832         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15833         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15834         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15835         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15836         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15837         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15838         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15839         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15840         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15841         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15842         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15843         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15844         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15845         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15846         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15847         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15848         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15849         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15850         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15851         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15852         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15853         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15854         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15855         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15856         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15857         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15858         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15859         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15860         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15861         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15862         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15863         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15864         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15865 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15866         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15867 #endif
15868         (cmdline_parse_inst_t *)&cmd_ddp_add,
15869         (cmdline_parse_inst_t *)&cmd_ddp_del,
15870         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15871         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15872         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15873         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15874         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15875         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15876         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15877         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15878
15879         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15880         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15881         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15882         (cmdline_parse_inst_t *)&cmd_queue_region,
15883         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15884         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15885         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15886         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15887         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15888         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15889         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15890         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15891         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15892         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15893         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15894         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15895         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15896         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15897         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15898         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15899         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15900         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15901         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15902         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15903         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15904         NULL,
15905 };
15906
15907 /* read cmdline commands from file */
15908 void
15909 cmdline_read_from_file(const char *filename)
15910 {
15911         struct cmdline *cl;
15912
15913         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15914         if (cl == NULL) {
15915                 printf("Failed to create file based cmdline context: %s\n",
15916                        filename);
15917                 return;
15918         }
15919
15920         cmdline_interact(cl);
15921         cmdline_quit(cl);
15922
15923         cmdline_free(cl);
15924
15925         printf("Read CLI commands from %s\n", filename);
15926 }
15927
15928 /* prompt function, called from main on MASTER lcore */
15929 void
15930 prompt(void)
15931 {
15932         /* initialize non-constant commands */
15933         cmd_set_fwd_mode_init();
15934         cmd_set_fwd_retry_mode_init();
15935
15936         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15937         if (testpmd_cl == NULL)
15938                 return;
15939         cmdline_interact(testpmd_cl);
15940         cmdline_stdin_exit(testpmd_cl);
15941 }
15942
15943 void
15944 prompt_exit(void)
15945 {
15946         if (testpmd_cl != NULL)
15947                 cmdline_quit(testpmd_cl);
15948 }
15949
15950 static void
15951 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15952 {
15953         if (id == (portid_t)RTE_PORT_ALL) {
15954                 portid_t pid;
15955
15956                 RTE_ETH_FOREACH_DEV(pid) {
15957                         /* check if need_reconfig has been set to 1 */
15958                         if (ports[pid].need_reconfig == 0)
15959                                 ports[pid].need_reconfig = dev;
15960                         /* check if need_reconfig_queues has been set to 1 */
15961                         if (ports[pid].need_reconfig_queues == 0)
15962                                 ports[pid].need_reconfig_queues = queue;
15963                 }
15964         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15965                 /* check if need_reconfig has been set to 1 */
15966                 if (ports[id].need_reconfig == 0)
15967                         ports[id].need_reconfig = dev;
15968                 /* check if need_reconfig_queues has been set to 1 */
15969                 if (ports[id].need_reconfig_queues == 0)
15970                         ports[id].need_reconfig_queues = queue;
15971         }
15972 }