app/testpmd: enable fast free Tx offload by default
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set xstats-hide-zero on|off\n"
530                         "    Set the option to hide the zero values"
531                         " for xstats display.\n"
532
533                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
534                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
535
536                         "set port (port_id) vf (vf_id) (mac_addr)"
537                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
538                         "   Add/Remove unicast or multicast MAC addr filter"
539                         " for a VF.\n\n"
540
541                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
542                         "|MPE) (on|off)\n"
543                         "    AUPE:accepts untagged VLAN;"
544                         "ROPE:accept unicast hash\n\n"
545                         "    BAM:accepts broadcast packets;"
546                         "MPE:accepts all multicast packets\n\n"
547                         "    Enable/Disable a VF receive mode of a port\n\n"
548
549                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
550                         "    Set rate limit for a queue of a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rate (rate_num) "
553                         "queue_mask (queue_mask_value)\n"
554                         "    Set rate limit for queues in VF of a port\n\n"
555
556                         "set port (port_id) mirror-rule (rule_id)"
557                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
558                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
559                         "   Set pool or vlan type mirror rule on a port.\n"
560                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
561                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
562                         " to pool 0.\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (uplink-mirror|downlink-mirror) dst-pool"
566                         " (pool_id) (on|off)\n"
567                         "   Set uplink or downlink type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
569                         " 0 on' enable mirror income traffic to pool 0.\n\n"
570
571                         "reset port (port_id) mirror-rule (rule_id)\n"
572                         "   Reset a mirror rule.\n\n"
573
574                         "set flush_rx (on|off)\n"
575                         "   Flush (default) or don't flush RX streams before"
576                         " forwarding. Mainly used with PCAP drivers.\n\n"
577
578                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the bypass mode for the lowest port on bypass enabled"
580                         " NIC.\n\n"
581
582                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
583                         "mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the event required to initiate specified bypass mode for"
585                         " the lowest port on a bypass enabled NIC where:\n"
586                         "       timeout   = enable bypass after watchdog timeout.\n"
587                         "       os_on     = enable bypass when OS/board is powered on.\n"
588                         "       os_off    = enable bypass when OS/board is powered off.\n"
589                         "       power_on  = enable bypass when power supply is turned on.\n"
590                         "       power_off = enable bypass when power supply is turned off."
591                         "\n\n"
592
593                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
594                         "   Set the bypass watchdog timeout to 'n' seconds"
595                         " where 0 = instant.\n\n"
596
597                         "show bypass config (port_id)\n"
598                         "   Show the bypass configuration for a bypass enabled NIC"
599                         " using the lowest port on the NIC.\n\n"
600
601 #ifdef RTE_LIBRTE_PMD_BOND
602                         "create bonded device (mode) (socket)\n"
603                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
604
605                         "add bonding slave (slave_id) (port_id)\n"
606                         "       Add a slave device to a bonded device.\n\n"
607
608                         "remove bonding slave (slave_id) (port_id)\n"
609                         "       Remove a slave device from a bonded device.\n\n"
610
611                         "set bonding mode (value) (port_id)\n"
612                         "       Set the bonding mode on a bonded device.\n\n"
613
614                         "set bonding primary (slave_id) (port_id)\n"
615                         "       Set the primary slave for a bonded device.\n\n"
616
617                         "show bonding config (port_id)\n"
618                         "       Show the bonding config for port_id.\n\n"
619
620                         "set bonding mac_addr (port_id) (address)\n"
621                         "       Set the MAC address of a bonded device.\n\n"
622
623                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
624                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
625
626                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
627                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
628
629                         "set bonding mon_period (port_id) (value)\n"
630                         "       Set the bonding link status monitoring polling period in ms.\n\n"
631
632                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
633                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
634
635 #endif
636                         "set link-up port (port_id)\n"
637                         "       Set link up for a port.\n\n"
638
639                         "set link-down port (port_id)\n"
640                         "       Set link down for a port.\n\n"
641
642                         "E-tag set insertion on port-tag-id (value)"
643                         " port (port_id) vf (vf_id)\n"
644                         "    Enable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
647                         "    Disable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set stripping (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag stripping on a port\n\n"
651
652                         "E-tag set forwarding (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag based forwarding"
654                         " on a port\n\n"
655
656                         "E-tag set filter add e-tag-id (value) dst-pool"
657                         " (pool_id) port (port_id)\n"
658                         "    Add an E-tag forwarding filter on a port\n\n"
659
660                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
661                         "    Delete an E-tag forwarding filter on a port\n\n"
662
663 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
664                         "set port tm hierarchy default (port_id)\n"
665                         "       Set default traffic Management hierarchy on a port\n\n"
666
667 #endif
668                         "ddp add (port_id) (profile_path[,output_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "queue_start_index (value) queue_num (value)\n"
688                         "    Set a queue region on a port\n\n"
689
690                         "set port (port_id) queue-region region_id (value) "
691                         "flowtype (value)\n"
692                         "    Set a flowtype region index on a port\n\n"
693
694                         "set port (port_id) queue-region UP (value) region_id (value)\n"
695                         "    Set the mapping of User Priority to "
696                         "queue region on a port\n\n"
697
698                         "set port (port_id) queue-region flush (on|off)\n"
699                         "    flush all queue region related configuration\n\n"
700
701                         "show port meter cap (port_id)\n"
702                         "    Show port meter capability information\n\n"
703
704                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
705                         "    meter profile add - srtcm rfc 2697\n\n"
706
707                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
708                         "    meter profile add - trtcm rfc 2698\n\n"
709
710                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
711                         "    meter profile add - trtcm rfc 4115\n\n"
712
713                         "del port meter profile (port_id) (profile_id)\n"
714                         "    meter profile delete\n\n"
715
716                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
717                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
718                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
719                         "(dscp_tbl_entry63)]\n"
720                         "    meter create\n\n"
721
722                         "enable port meter (port_id) (mtr_id)\n"
723                         "    meter enable\n\n"
724
725                         "disable port meter (port_id) (mtr_id)\n"
726                         "    meter disable\n\n"
727
728                         "del port meter (port_id) (mtr_id)\n"
729                         "    meter delete\n\n"
730
731                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
732                         "    meter update meter profile\n\n"
733
734                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
735                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
736                         "    update meter dscp table entries\n\n"
737
738                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
739                         "(action0) [(action1) (action2)]\n"
740                         "    meter update policer action\n\n"
741
742                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
743                         "    meter update stats\n\n"
744
745                         "show port (port_id) queue-region\n"
746                         "    show all queue region related configuration info\n\n"
747
748                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
749                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
750                         "       Add port tm node private shaper profile.\n\n"
751
752                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
753                         "       Delete port tm node private shaper profile.\n\n"
754
755                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
756                         " (shaper_profile_id)\n"
757                         "       Add/update port tm node shared shaper.\n\n"
758
759                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
760                         "       Delete port tm node shared shaper.\n\n"
761
762                         "set port tm node shaper profile (port_id) (node_id)"
763                         " (shaper_profile_id)\n"
764                         "       Set port tm node shaper profile.\n\n"
765
766                         "add port tm node wred profile (port_id) (wred_profile_id)"
767                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
768                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
769                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
770                         "       Add port tm node wred profile.\n\n"
771
772                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
773                         "       Delete port tm node wred profile.\n\n"
774
775                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
776                         " (priority) (weight) (level_id) (shaper_profile_id)"
777                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
778                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
779                         "       Add port tm nonleaf node.\n\n"
780
781                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm leaf node.\n\n"
786
787                         "del port tm node (port_id) (node_id)\n"
788                         "       Delete port tm node.\n\n"
789
790                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
791                         " (priority) (weight)\n"
792                         "       Set port tm node parent.\n\n"
793
794                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
795                         "       Commit tm hierarchy.\n\n"
796
797                         , list_pkt_forwarding_modes()
798                 );
799         }
800
801         if (show_all || !strcmp(res->section, "ports")) {
802
803                 cmdline_printf(
804                         cl,
805                         "\n"
806                         "Port Operations:\n"
807                         "----------------\n\n"
808
809                         "port start (port_id|all)\n"
810                         "    Start all ports or port_id.\n\n"
811
812                         "port stop (port_id|all)\n"
813                         "    Stop all ports or port_id.\n\n"
814
815                         "port close (port_id|all)\n"
816                         "    Close all ports or port_id.\n\n"
817
818                         "port attach (ident)\n"
819                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
820
821                         "port detach (port_id)\n"
822                         "    Detach physical or virtual dev by port_id\n\n"
823
824                         "port config (port_id|all)"
825                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
826                         " duplex (half|full|auto)\n"
827                         "    Set speed and duplex for all ports or port_id\n\n"
828
829                         "port config all (rxq|txq|rxd|txd) (value)\n"
830                         "    Set number for rxq/txq/rxd/txd.\n\n"
831
832                         "port config all max-pkt-len (value)\n"
833                         "    Set the max packet length.\n\n"
834
835                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
836                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
837                         " (on|off)\n"
838                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
839                         " for ports.\n\n"
840
841                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
842                         "geneve|nvgre|none|<flowtype_id>)\n"
843                         "    Set the RSS mode.\n\n"
844
845                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
846                         "    Set the RSS redirection table.\n\n"
847
848                         "port config (port_id) dcb vt (on|off) (traffic_class)"
849                         " pfc (on|off)\n"
850                         "    Set the DCB mode.\n\n"
851
852                         "port config all burst (value)\n"
853                         "    Set the number of packets per burst.\n\n"
854
855                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
856                         " (value)\n"
857                         "    Set the ring prefetch/host/writeback threshold"
858                         " for tx/rx queue.\n\n"
859
860                         "port config all (txfreet|txrst|rxfreet) (value)\n"
861                         "    Set free threshold for rx/tx, or set"
862                         " tx rs bit threshold.\n\n"
863                         "port config mtu X value\n"
864                         "    Set the MTU of port X to a given value\n\n"
865
866                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
867                         "    Start/stop a rx/tx queue of port X. Only take effect"
868                         " when port X is started\n\n"
869
870                         "port config (port_id|all) l2-tunnel E-tag ether-type"
871                         " (value)\n"
872                         "    Set the value of E-tag ether-type.\n\n"
873
874                         "port config (port_id|all) l2-tunnel E-tag"
875                         " (enable|disable)\n"
876                         "    Enable/disable the E-tag support.\n\n"
877
878                         "port config (port_id) pctype mapping reset\n"
879                         "    Reset flow type to pctype mapping on a port\n\n"
880
881                         "port config (port_id) pctype mapping update"
882                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
883                         "    Update a flow type to pctype mapping item on a port\n\n"
884                 );
885         }
886
887         if (show_all || !strcmp(res->section, "registers")) {
888
889                 cmdline_printf(
890                         cl,
891                         "\n"
892                         "Registers:\n"
893                         "----------\n\n"
894
895                         "read reg (port_id) (address)\n"
896                         "    Display value of a port register.\n\n"
897
898                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
899                         "    Display a port register bit field.\n\n"
900
901                         "read regbit (port_id) (address) (bit_x)\n"
902                         "    Display a single port register bit.\n\n"
903
904                         "write reg (port_id) (address) (value)\n"
905                         "    Set value of a port register.\n\n"
906
907                         "write regfield (port_id) (address) (bit_x) (bit_y)"
908                         " (value)\n"
909                         "    Set bit field of a port register.\n\n"
910
911                         "write regbit (port_id) (address) (bit_x) (value)\n"
912                         "    Set single bit value of a port register.\n\n"
913                 );
914         }
915         if (show_all || !strcmp(res->section, "filters")) {
916
917                 cmdline_printf(
918                         cl,
919                         "\n"
920                         "filters:\n"
921                         "--------\n\n"
922
923                         "ethertype_filter (port_id) (add|del)"
924                         " (mac_addr|mac_ignr) (mac_address) ethertype"
925                         " (ether_type) (drop|fwd) queue (queue_id)\n"
926                         "    Add/Del an ethertype filter.\n\n"
927
928                         "2tuple_filter (port_id) (add|del)"
929                         " dst_port (dst_port_value) protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 2tuple filter.\n\n"
933
934                         "5tuple_filter (port_id) (add|del)"
935                         " dst_ip (dst_address) src_ip (src_address)"
936                         " dst_port (dst_port_value) src_port (src_port_value)"
937                         " protocol (protocol_value)"
938                         " mask (mask_value) tcp_flags (tcp_flags_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a 5tuple filter.\n\n"
941
942                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
943                         "    Add/Del syn filter.\n\n"
944
945                         "flex_filter (port_id) (add|del) len (len_value)"
946                         " bytes (bytes_value) mask (mask_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a flex filter.\n\n"
949
950                         "flow_director_filter (port_id) mode IP (add|del|update)"
951                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
952                         " src (src_ip_address) dst (dst_ip_address)"
953                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
954                         " vlan (vlan_value) flexbytes (flexbytes_value)"
955                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
956                         " fd_id (fd_id_value)\n"
957                         "    Add/Del an IP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
961                         " src (src_ip_address) (src_port)"
962                         " dst (dst_ip_address) (dst_port)"
963                         " tos (tos_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-sctp|ipv6-sctp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tag (verification_tag) "
974                         " tos (tos_value) ttl (ttl_value)"
975                         " vlan (vlan_value)"
976                         " flexbytes (flexbytes_value) (drop|fwd)"
977                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
978                         "    Add/Del a SCTP type flow director filter.\n\n"
979
980                         "flow_director_filter (port_id) mode IP (add|del|update)"
981                         " flow l2_payload ether (ethertype)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a l2 payload type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
987                         " mac (mac_address) vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a Tunnel flow director filter.\n\n"
998
999                         "flush_flow_director (port_id)\n"
1000                         "    Flush all flow director entries of a device.\n\n"
1001
1002                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1003                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1004                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1005                         "    Set flow director IP mask.\n\n"
1006
1007                         "flow_director_mask (port_id) mode MAC-VLAN"
1008                         " vlan (vlan_value)\n"
1009                         "    Set flow director MAC-VLAN mask.\n\n"
1010
1011                         "flow_director_mask (port_id) mode Tunnel"
1012                         " vlan (vlan_value) mac (mac_value)"
1013                         " tunnel-type (tunnel_type_value)"
1014                         " tunnel-id (tunnel_id_value)\n"
1015                         "    Set flow director Tunnel mask.\n\n"
1016
1017                         "flow_director_flex_mask (port_id)"
1018                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1019                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1020                         " (mask)\n"
1021                         "    Configure mask of flex payload.\n\n"
1022
1023                         "flow_director_flex_payload (port_id)"
1024                         " (raw|l2|l3|l4) (config)\n"
1025                         "    Configure flex payload selection.\n\n"
1026
1027                         "get_sym_hash_ena_per_port (port_id)\n"
1028                         "    get symmetric hash enable configuration per port.\n\n"
1029
1030                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1031                         "    set symmetric hash enable configuration per port"
1032                         " to enable or disable.\n\n"
1033
1034                         "get_hash_global_config (port_id)\n"
1035                         "    Get the global configurations of hash filters.\n\n"
1036
1037                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1038                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1039                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1040                         " (enable|disable)\n"
1041                         "    Set the global configurations of hash filters.\n\n"
1042
1043                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1044                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1045                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1046                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1047                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1048                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1049                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1050                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1051                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1052                         "fld-8th|none) (select|add)\n"
1053                         "    Set the input set for hash.\n\n"
1054
1055                         "set_fdir_input_set (port_id) "
1056                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1058                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1059                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1060                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1061                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1062                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1063                         " (select|add)\n"
1064                         "    Set the input set for FDir.\n\n"
1065
1066                         "flow validate {port_id}"
1067                         " [group {group_id}] [priority {level}]"
1068                         " [ingress] [egress]"
1069                         " pattern {item} [/ {item} [...]] / end"
1070                         " actions {action} [/ {action} [...]] / end\n"
1071                         "    Check whether a flow rule can be created.\n\n"
1072
1073                         "flow create {port_id}"
1074                         " [group {group_id}] [priority {level}]"
1075                         " [ingress] [egress]"
1076                         " pattern {item} [/ {item} [...]] / end"
1077                         " actions {action} [/ {action} [...]] / end\n"
1078                         "    Create a flow rule.\n\n"
1079
1080                         "flow destroy {port_id} rule {rule_id} [...]\n"
1081                         "    Destroy specific flow rules.\n\n"
1082
1083                         "flow flush {port_id}\n"
1084                         "    Destroy all flow rules.\n\n"
1085
1086                         "flow query {port_id} {rule_id} {action}\n"
1087                         "    Query an existing flow rule.\n\n"
1088
1089                         "flow list {port_id} [group {group_id}] [...]\n"
1090                         "    List existing flow rules sorted by priority,"
1091                         " filtered by group identifiers.\n\n"
1092
1093                         "flow isolate {port_id} {boolean}\n"
1094                         "    Restrict ingress traffic to the defined"
1095                         " flow rules\n\n"
1096                 );
1097         }
1098 }
1099
1100 cmdline_parse_token_string_t cmd_help_long_help =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1102
1103 cmdline_parse_token_string_t cmd_help_long_section =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1105                         "all#control#display#config#"
1106                         "ports#registers#filters");
1107
1108 cmdline_parse_inst_t cmd_help_long = {
1109         .f = cmd_help_long_parsed,
1110         .data = NULL,
1111         .help_str = "help all|control|display|config|ports|register|filters: "
1112                 "Show help",
1113         .tokens = {
1114                 (void *)&cmd_help_long_help,
1115                 (void *)&cmd_help_long_section,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 /* *** start/stop/close all ports *** */
1122 struct cmd_operate_port_result {
1123         cmdline_fixed_string_t keyword;
1124         cmdline_fixed_string_t name;
1125         cmdline_fixed_string_t value;
1126 };
1127
1128 static void cmd_operate_port_parsed(void *parsed_result,
1129                                 __attribute__((unused)) struct cmdline *cl,
1130                                 __attribute__((unused)) void *data)
1131 {
1132         struct cmd_operate_port_result *res = parsed_result;
1133
1134         if (!strcmp(res->name, "start"))
1135                 start_port(RTE_PORT_ALL);
1136         else if (!strcmp(res->name, "stop"))
1137                 stop_port(RTE_PORT_ALL);
1138         else if (!strcmp(res->name, "close"))
1139                 close_port(RTE_PORT_ALL);
1140         else if (!strcmp(res->name, "reset"))
1141                 reset_port(RTE_PORT_ALL);
1142         else
1143                 printf("Unknown parameter\n");
1144 }
1145
1146 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1148                                                                 "port");
1149 cmdline_parse_token_string_t cmd_operate_port_all_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1151                                                 "start#stop#close#reset");
1152 cmdline_parse_token_string_t cmd_operate_port_all_all =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1154
1155 cmdline_parse_inst_t cmd_operate_port = {
1156         .f = cmd_operate_port_parsed,
1157         .data = NULL,
1158         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1159         .tokens = {
1160                 (void *)&cmd_operate_port_all_cmd,
1161                 (void *)&cmd_operate_port_all_port,
1162                 (void *)&cmd_operate_port_all_all,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** start/stop/close specific port *** */
1168 struct cmd_operate_specific_port_result {
1169         cmdline_fixed_string_t keyword;
1170         cmdline_fixed_string_t name;
1171         uint8_t value;
1172 };
1173
1174 static void cmd_operate_specific_port_parsed(void *parsed_result,
1175                         __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_operate_specific_port_result *res = parsed_result;
1179
1180         if (!strcmp(res->name, "start"))
1181                 start_port(res->value);
1182         else if (!strcmp(res->name, "stop"))
1183                 stop_port(res->value);
1184         else if (!strcmp(res->name, "close"))
1185                 close_port(res->value);
1186         else if (!strcmp(res->name, "reset"))
1187                 reset_port(res->value);
1188         else
1189                 printf("Unknown parameter\n");
1190 }
1191
1192 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                         keyword, "port");
1195 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                 name, "start#stop#close#reset");
1198 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1199         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                         value, UINT8);
1201
1202 cmdline_parse_inst_t cmd_operate_specific_port = {
1203         .f = cmd_operate_specific_port_parsed,
1204         .data = NULL,
1205         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1206         .tokens = {
1207                 (void *)&cmd_operate_specific_port_cmd,
1208                 (void *)&cmd_operate_specific_port_port,
1209                 (void *)&cmd_operate_specific_port_id,
1210                 NULL,
1211         },
1212 };
1213
1214 /* *** attach a specified port *** */
1215 struct cmd_operate_attach_port_result {
1216         cmdline_fixed_string_t port;
1217         cmdline_fixed_string_t keyword;
1218         cmdline_fixed_string_t identifier;
1219 };
1220
1221 static void cmd_operate_attach_port_parsed(void *parsed_result,
1222                                 __attribute__((unused)) struct cmdline *cl,
1223                                 __attribute__((unused)) void *data)
1224 {
1225         struct cmd_operate_attach_port_result *res = parsed_result;
1226
1227         if (!strcmp(res->keyword, "attach"))
1228                 attach_port(res->identifier);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         port, "port");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         keyword, "attach");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         identifier, NULL);
1242
1243 cmdline_parse_inst_t cmd_operate_attach_port = {
1244         .f = cmd_operate_attach_port_parsed,
1245         .data = NULL,
1246         .help_str = "port attach <identifier>: "
1247                 "(identifier: pci address or virtual dev name)",
1248         .tokens = {
1249                 (void *)&cmd_operate_attach_port_port,
1250                 (void *)&cmd_operate_attach_port_keyword,
1251                 (void *)&cmd_operate_attach_port_identifier,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** detach a specified port *** */
1257 struct cmd_operate_detach_port_result {
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t keyword;
1260         portid_t port_id;
1261 };
1262
1263 static void cmd_operate_detach_port_parsed(void *parsed_result,
1264                                 __attribute__((unused)) struct cmdline *cl,
1265                                 __attribute__((unused)) void *data)
1266 {
1267         struct cmd_operate_detach_port_result *res = parsed_result;
1268
1269         if (!strcmp(res->keyword, "detach"))
1270                 detach_port(res->port_id);
1271         else
1272                 printf("Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         port, "port");
1278 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         keyword, "detach");
1281 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         port_id, UINT16);
1284
1285 cmdline_parse_inst_t cmd_operate_detach_port = {
1286         .f = cmd_operate_detach_port_parsed,
1287         .data = NULL,
1288         .help_str = "port detach <port_id>",
1289         .tokens = {
1290                 (void *)&cmd_operate_detach_port_port,
1291                 (void *)&cmd_operate_detach_port_keyword,
1292                 (void *)&cmd_operate_detach_port_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** configure speed for all ports *** */
1298 struct cmd_config_speed_all {
1299         cmdline_fixed_string_t port;
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t all;
1302         cmdline_fixed_string_t item1;
1303         cmdline_fixed_string_t item2;
1304         cmdline_fixed_string_t value1;
1305         cmdline_fixed_string_t value2;
1306 };
1307
1308 static int
1309 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1310 {
1311
1312         int duplex;
1313
1314         if (!strcmp(duplexstr, "half")) {
1315                 duplex = ETH_LINK_HALF_DUPLEX;
1316         } else if (!strcmp(duplexstr, "full")) {
1317                 duplex = ETH_LINK_FULL_DUPLEX;
1318         } else if (!strcmp(duplexstr, "auto")) {
1319                 duplex = ETH_LINK_FULL_DUPLEX;
1320         } else {
1321                 printf("Unknown duplex parameter\n");
1322                 return -1;
1323         }
1324
1325         if (!strcmp(speedstr, "10")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1328         } else if (!strcmp(speedstr, "100")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1331         } else {
1332                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1333                         printf("Invalid speed/duplex parameters\n");
1334                         return -1;
1335                 }
1336                 if (!strcmp(speedstr, "1000")) {
1337                         *speed = ETH_LINK_SPEED_1G;
1338                 } else if (!strcmp(speedstr, "10000")) {
1339                         *speed = ETH_LINK_SPEED_10G;
1340                 } else if (!strcmp(speedstr, "25000")) {
1341                         *speed = ETH_LINK_SPEED_25G;
1342                 } else if (!strcmp(speedstr, "40000")) {
1343                         *speed = ETH_LINK_SPEED_40G;
1344                 } else if (!strcmp(speedstr, "50000")) {
1345                         *speed = ETH_LINK_SPEED_50G;
1346                 } else if (!strcmp(speedstr, "100000")) {
1347                         *speed = ETH_LINK_SPEED_100G;
1348                 } else if (!strcmp(speedstr, "auto")) {
1349                         *speed = ETH_LINK_SPEED_AUTONEG;
1350                 } else {
1351                         printf("Unknown speed parameter\n");
1352                         return -1;
1353                 }
1354         }
1355
1356         return 0;
1357 }
1358
1359 static void
1360 cmd_config_speed_all_parsed(void *parsed_result,
1361                         __attribute__((unused)) struct cmdline *cl,
1362                         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_config_speed_all *res = parsed_result;
1365         uint32_t link_speed;
1366         portid_t pid;
1367
1368         if (!all_ports_stopped()) {
1369                 printf("Please stop all ports first\n");
1370                 return;
1371         }
1372
1373         if (parse_and_check_speed_duplex(res->value1, res->value2,
1374                         &link_speed) < 0)
1375                 return;
1376
1377         RTE_ETH_FOREACH_DEV(pid) {
1378                 ports[pid].dev_conf.link_speeds = link_speed;
1379         }
1380
1381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1382 }
1383
1384 cmdline_parse_token_string_t cmd_config_speed_all_port =
1385         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1386 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1388                                                         "config");
1389 cmdline_parse_token_string_t cmd_config_speed_all_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1391 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1393 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1395                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1400                                                 "half#full#auto");
1401
1402 cmdline_parse_inst_t cmd_config_speed_all = {
1403         .f = cmd_config_speed_all_parsed,
1404         .data = NULL,
1405         .help_str = "port config all speed "
1406                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1407                                                         "half|full|auto",
1408         .tokens = {
1409                 (void *)&cmd_config_speed_all_port,
1410                 (void *)&cmd_config_speed_all_keyword,
1411                 (void *)&cmd_config_speed_all_all,
1412                 (void *)&cmd_config_speed_all_item1,
1413                 (void *)&cmd_config_speed_all_value1,
1414                 (void *)&cmd_config_speed_all_item2,
1415                 (void *)&cmd_config_speed_all_value2,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** configure speed for specific port *** */
1421 struct cmd_config_speed_specific {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         uint8_t id;
1425         cmdline_fixed_string_t item1;
1426         cmdline_fixed_string_t item2;
1427         cmdline_fixed_string_t value1;
1428         cmdline_fixed_string_t value2;
1429 };
1430
1431 static void
1432 cmd_config_speed_specific_parsed(void *parsed_result,
1433                                 __attribute__((unused)) struct cmdline *cl,
1434                                 __attribute__((unused)) void *data)
1435 {
1436         struct cmd_config_speed_specific *res = parsed_result;
1437         uint32_t link_speed;
1438
1439         if (!all_ports_stopped()) {
1440                 printf("Please stop all ports first\n");
1441                 return;
1442         }
1443
1444         if (port_id_is_invalid(res->id, ENABLED_WARN))
1445                 return;
1446
1447         if (parse_and_check_speed_duplex(res->value1, res->value2,
1448                         &link_speed) < 0)
1449                 return;
1450
1451         ports[res->id].dev_conf.link_speeds = link_speed;
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456
1457 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1459                                                                 "port");
1460 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1462                                                                 "config");
1463 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1464         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1465 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1467                                                                 "speed");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1470                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1473                                                                 "duplex");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1476                                                         "half#full#auto");
1477
1478 cmdline_parse_inst_t cmd_config_speed_specific = {
1479         .f = cmd_config_speed_specific_parsed,
1480         .data = NULL,
1481         .help_str = "port config <port_id> speed "
1482                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1483                                                         "half|full|auto",
1484         .tokens = {
1485                 (void *)&cmd_config_speed_specific_port,
1486                 (void *)&cmd_config_speed_specific_keyword,
1487                 (void *)&cmd_config_speed_specific_id,
1488                 (void *)&cmd_config_speed_specific_item1,
1489                 (void *)&cmd_config_speed_specific_value1,
1490                 (void *)&cmd_config_speed_specific_item2,
1491                 (void *)&cmd_config_speed_specific_value2,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure txq/rxq, txd/rxd *** */
1497 struct cmd_config_rx_tx {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t name;
1502         uint16_t value;
1503 };
1504
1505 static void
1506 cmd_config_rx_tx_parsed(void *parsed_result,
1507                         __attribute__((unused)) struct cmdline *cl,
1508                         __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_rx_tx *res = parsed_result;
1511
1512         if (!all_ports_stopped()) {
1513                 printf("Please stop all ports first\n");
1514                 return;
1515         }
1516         if (!strcmp(res->name, "rxq")) {
1517                 if (!res->value && !nb_txq) {
1518                         printf("Warning: Either rx or tx queues should be non zero\n");
1519                         return;
1520                 }
1521                 nb_rxq = res->value;
1522         }
1523         else if (!strcmp(res->name, "txq")) {
1524                 if (!res->value && !nb_rxq) {
1525                         printf("Warning: Either rx or tx queues should be non zero\n");
1526                         return;
1527                 }
1528                 nb_txq = res->value;
1529         }
1530         else if (!strcmp(res->name, "rxd")) {
1531                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1532                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1533                                         res->value, RTE_TEST_RX_DESC_MAX);
1534                         return;
1535                 }
1536                 nb_rxd = res->value;
1537         } else if (!strcmp(res->name, "txd")) {
1538                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1539                         printf("txd %d invalid - must be > 0 && <= %d\n",
1540                                         res->value, RTE_TEST_TX_DESC_MAX);
1541                         return;
1542                 }
1543                 nb_txd = res->value;
1544         } else {
1545                 printf("Unknown parameter\n");
1546                 return;
1547         }
1548
1549         fwd_config_setup();
1550
1551         init_port_config();
1552
1553         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1558 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1560 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1562 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1564                                                 "rxq#txq#rxd#txd");
1565 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1566         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1567
1568 cmdline_parse_inst_t cmd_config_rx_tx = {
1569         .f = cmd_config_rx_tx_parsed,
1570         .data = NULL,
1571         .help_str = "port config all rxq|txq|rxd|txd <value>",
1572         .tokens = {
1573                 (void *)&cmd_config_rx_tx_port,
1574                 (void *)&cmd_config_rx_tx_keyword,
1575                 (void *)&cmd_config_rx_tx_all,
1576                 (void *)&cmd_config_rx_tx_name,
1577                 (void *)&cmd_config_rx_tx_value,
1578                 NULL,
1579         },
1580 };
1581
1582 /* *** config max packet length *** */
1583 struct cmd_config_max_pkt_len_result {
1584         cmdline_fixed_string_t port;
1585         cmdline_fixed_string_t keyword;
1586         cmdline_fixed_string_t all;
1587         cmdline_fixed_string_t name;
1588         uint32_t value;
1589 };
1590
1591 static void
1592 cmd_config_max_pkt_len_parsed(void *parsed_result,
1593                                 __attribute__((unused)) struct cmdline *cl,
1594                                 __attribute__((unused)) void *data)
1595 {
1596         struct cmd_config_max_pkt_len_result *res = parsed_result;
1597         portid_t pid;
1598
1599         if (!all_ports_stopped()) {
1600                 printf("Please stop all ports first\n");
1601                 return;
1602         }
1603
1604         RTE_ETH_FOREACH_DEV(pid) {
1605                 struct rte_port *port = &ports[pid];
1606                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1607
1608                 if (!strcmp(res->name, "max-pkt-len")) {
1609                         if (res->value < ETHER_MIN_LEN) {
1610                                 printf("max-pkt-len can not be less than %d\n",
1611                                                 ETHER_MIN_LEN);
1612                                 return;
1613                         }
1614                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1615                                 return;
1616
1617                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1618                         if (res->value > ETHER_MAX_LEN)
1619                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1620                         else
1621                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1622                         port->dev_conf.rxmode.offloads = rx_offloads;
1623                 } else {
1624                         printf("Unknown parameter\n");
1625                         return;
1626                 }
1627         }
1628
1629         init_port_config();
1630
1631         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1632 }
1633
1634 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1635         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1636                                                                 "port");
1637 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1638         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1639                                                                 "config");
1640 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1642                                                                 "all");
1643 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1645                                                                 "max-pkt-len");
1646 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1647         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1648                                                                 UINT32);
1649
1650 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1651         .f = cmd_config_max_pkt_len_parsed,
1652         .data = NULL,
1653         .help_str = "port config all max-pkt-len <value>",
1654         .tokens = {
1655                 (void *)&cmd_config_max_pkt_len_port,
1656                 (void *)&cmd_config_max_pkt_len_keyword,
1657                 (void *)&cmd_config_max_pkt_len_all,
1658                 (void *)&cmd_config_max_pkt_len_name,
1659                 (void *)&cmd_config_max_pkt_len_value,
1660                 NULL,
1661         },
1662 };
1663
1664 /* *** configure port MTU *** */
1665 struct cmd_config_mtu_result {
1666         cmdline_fixed_string_t port;
1667         cmdline_fixed_string_t keyword;
1668         cmdline_fixed_string_t mtu;
1669         portid_t port_id;
1670         uint16_t value;
1671 };
1672
1673 static void
1674 cmd_config_mtu_parsed(void *parsed_result,
1675                       __attribute__((unused)) struct cmdline *cl,
1676                       __attribute__((unused)) void *data)
1677 {
1678         struct cmd_config_mtu_result *res = parsed_result;
1679
1680         if (res->value < ETHER_MIN_LEN) {
1681                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1682                 return;
1683         }
1684         port_mtu_set(res->port_id, res->value);
1685 }
1686
1687 cmdline_parse_token_string_t cmd_config_mtu_port =
1688         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1689                                  "port");
1690 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1691         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1692                                  "config");
1693 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1695                                  "mtu");
1696 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1697         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1698 cmdline_parse_token_num_t cmd_config_mtu_value =
1699         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1700
1701 cmdline_parse_inst_t cmd_config_mtu = {
1702         .f = cmd_config_mtu_parsed,
1703         .data = NULL,
1704         .help_str = "port config mtu <port_id> <value>",
1705         .tokens = {
1706                 (void *)&cmd_config_mtu_port,
1707                 (void *)&cmd_config_mtu_keyword,
1708                 (void *)&cmd_config_mtu_mtu,
1709                 (void *)&cmd_config_mtu_port_id,
1710                 (void *)&cmd_config_mtu_value,
1711                 NULL,
1712         },
1713 };
1714
1715 /* *** configure rx mode *** */
1716 struct cmd_config_rx_mode_flag {
1717         cmdline_fixed_string_t port;
1718         cmdline_fixed_string_t keyword;
1719         cmdline_fixed_string_t all;
1720         cmdline_fixed_string_t name;
1721         cmdline_fixed_string_t value;
1722 };
1723
1724 static void
1725 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1726                                 __attribute__((unused)) struct cmdline *cl,
1727                                 __attribute__((unused)) void *data)
1728 {
1729         struct cmd_config_rx_mode_flag *res = parsed_result;
1730         portid_t pid;
1731
1732         if (!all_ports_stopped()) {
1733                 printf("Please stop all ports first\n");
1734                 return;
1735         }
1736
1737         RTE_ETH_FOREACH_DEV(pid) {
1738                 struct rte_port *port;
1739                 uint64_t rx_offloads;
1740
1741                 port = &ports[pid];
1742                 rx_offloads = port->dev_conf.rxmode.offloads;
1743                 if (!strcmp(res->name, "crc-strip")) {
1744                         if (!strcmp(res->value, "on"))
1745                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1746                         else if (!strcmp(res->value, "off"))
1747                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1748                         else {
1749                                 printf("Unknown parameter\n");
1750                                 return;
1751                         }
1752                 } else if (!strcmp(res->name, "scatter")) {
1753                         if (!strcmp(res->value, "on")) {
1754                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1755                         } else if (!strcmp(res->value, "off")) {
1756                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1757                         } else {
1758                                 printf("Unknown parameter\n");
1759                                 return;
1760                         }
1761                 } else if (!strcmp(res->name, "rx-cksum")) {
1762                         if (!strcmp(res->value, "on"))
1763                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1764                         else if (!strcmp(res->value, "off"))
1765                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1766                         else {
1767                                 printf("Unknown parameter\n");
1768                                 return;
1769                         }
1770                 } else if (!strcmp(res->name, "rx-timestamp")) {
1771                         if (!strcmp(res->value, "on"))
1772                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1773                         else if (!strcmp(res->value, "off"))
1774                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1775                         else {
1776                                 printf("Unknown parameter\n");
1777                                 return;
1778                         }
1779                 } else if (!strcmp(res->name, "hw-vlan")) {
1780                         if (!strcmp(res->value, "on")) {
1781                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1782                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1783                         } else if (!strcmp(res->value, "off")) {
1784                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1785                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1786                         } else {
1787                                 printf("Unknown parameter\n");
1788                                 return;
1789                         }
1790                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1791                         if (!strcmp(res->value, "on"))
1792                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1793                         else if (!strcmp(res->value, "off"))
1794                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1795                         else {
1796                                 printf("Unknown parameter\n");
1797                                 return;
1798                         }
1799                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1800                         if (!strcmp(res->value, "on"))
1801                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1802                         else if (!strcmp(res->value, "off"))
1803                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1804                         else {
1805                                 printf("Unknown parameter\n");
1806                                 return;
1807                         }
1808                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1809                         if (!strcmp(res->value, "on"))
1810                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1811                         else if (!strcmp(res->value, "off"))
1812                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1813                         else {
1814                                 printf("Unknown parameter\n");
1815                                 return;
1816                         }
1817                 } else if (!strcmp(res->name, "drop-en")) {
1818                         if (!strcmp(res->value, "on"))
1819                                 rx_drop_en = 1;
1820                         else if (!strcmp(res->value, "off"))
1821                                 rx_drop_en = 0;
1822                         else {
1823                                 printf("Unknown parameter\n");
1824                                 return;
1825                         }
1826                 } else {
1827                         printf("Unknown parameter\n");
1828                         return;
1829                 }
1830                 port->dev_conf.rxmode.offloads = rx_offloads;
1831         }
1832
1833         init_port_config();
1834
1835         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1836 }
1837
1838 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1839         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1840 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1841         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1842                                                                 "config");
1843 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1845 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1847                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1848                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1849 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1851                                                         "on#off");
1852
1853 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1854         .f = cmd_config_rx_mode_flag_parsed,
1855         .data = NULL,
1856         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1857                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1858         .tokens = {
1859                 (void *)&cmd_config_rx_mode_flag_port,
1860                 (void *)&cmd_config_rx_mode_flag_keyword,
1861                 (void *)&cmd_config_rx_mode_flag_all,
1862                 (void *)&cmd_config_rx_mode_flag_name,
1863                 (void *)&cmd_config_rx_mode_flag_value,
1864                 NULL,
1865         },
1866 };
1867
1868 /* *** configure rss *** */
1869 struct cmd_config_rss {
1870         cmdline_fixed_string_t port;
1871         cmdline_fixed_string_t keyword;
1872         cmdline_fixed_string_t all;
1873         cmdline_fixed_string_t name;
1874         cmdline_fixed_string_t value;
1875 };
1876
1877 static void
1878 cmd_config_rss_parsed(void *parsed_result,
1879                         __attribute__((unused)) struct cmdline *cl,
1880                         __attribute__((unused)) void *data)
1881 {
1882         struct cmd_config_rss *res = parsed_result;
1883         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1884         int diag;
1885         uint8_t i;
1886
1887         if (!strcmp(res->value, "all"))
1888                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1889                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1890                                         ETH_RSS_L2_PAYLOAD;
1891         else if (!strcmp(res->value, "ip"))
1892                 rss_conf.rss_hf = ETH_RSS_IP;
1893         else if (!strcmp(res->value, "udp"))
1894                 rss_conf.rss_hf = ETH_RSS_UDP;
1895         else if (!strcmp(res->value, "tcp"))
1896                 rss_conf.rss_hf = ETH_RSS_TCP;
1897         else if (!strcmp(res->value, "sctp"))
1898                 rss_conf.rss_hf = ETH_RSS_SCTP;
1899         else if (!strcmp(res->value, "ether"))
1900                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1901         else if (!strcmp(res->value, "port"))
1902                 rss_conf.rss_hf = ETH_RSS_PORT;
1903         else if (!strcmp(res->value, "vxlan"))
1904                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1905         else if (!strcmp(res->value, "geneve"))
1906                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1907         else if (!strcmp(res->value, "nvgre"))
1908                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1909         else if (!strcmp(res->value, "none"))
1910                 rss_conf.rss_hf = 0;
1911         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1912                                                 atoi(res->value) < 64)
1913                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1914         else {
1915                 printf("Unknown parameter\n");
1916                 return;
1917         }
1918         rss_conf.rss_key = NULL;
1919         for (i = 0; i < rte_eth_dev_count(); i++) {
1920                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1921                 if (diag < 0)
1922                         printf("Configuration of RSS hash at ethernet port %d "
1923                                 "failed with error (%d): %s.\n",
1924                                 i, -diag, strerror(-diag));
1925         }
1926 }
1927
1928 cmdline_parse_token_string_t cmd_config_rss_port =
1929         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1930 cmdline_parse_token_string_t cmd_config_rss_keyword =
1931         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1932 cmdline_parse_token_string_t cmd_config_rss_all =
1933         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1934 cmdline_parse_token_string_t cmd_config_rss_name =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1936 cmdline_parse_token_string_t cmd_config_rss_value =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1938
1939 cmdline_parse_inst_t cmd_config_rss = {
1940         .f = cmd_config_rss_parsed,
1941         .data = NULL,
1942         .help_str = "port config all rss "
1943                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1944         .tokens = {
1945                 (void *)&cmd_config_rss_port,
1946                 (void *)&cmd_config_rss_keyword,
1947                 (void *)&cmd_config_rss_all,
1948                 (void *)&cmd_config_rss_name,
1949                 (void *)&cmd_config_rss_value,
1950                 NULL,
1951         },
1952 };
1953
1954 /* *** configure rss hash key *** */
1955 struct cmd_config_rss_hash_key {
1956         cmdline_fixed_string_t port;
1957         cmdline_fixed_string_t config;
1958         portid_t port_id;
1959         cmdline_fixed_string_t rss_hash_key;
1960         cmdline_fixed_string_t rss_type;
1961         cmdline_fixed_string_t key;
1962 };
1963
1964 static uint8_t
1965 hexa_digit_to_value(char hexa_digit)
1966 {
1967         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1968                 return (uint8_t) (hexa_digit - '0');
1969         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1970                 return (uint8_t) ((hexa_digit - 'a') + 10);
1971         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1972                 return (uint8_t) ((hexa_digit - 'A') + 10);
1973         /* Invalid hexa digit */
1974         return 0xFF;
1975 }
1976
1977 static uint8_t
1978 parse_and_check_key_hexa_digit(char *key, int idx)
1979 {
1980         uint8_t hexa_v;
1981
1982         hexa_v = hexa_digit_to_value(key[idx]);
1983         if (hexa_v == 0xFF)
1984                 printf("invalid key: character %c at position %d is not a "
1985                        "valid hexa digit\n", key[idx], idx);
1986         return hexa_v;
1987 }
1988
1989 static void
1990 cmd_config_rss_hash_key_parsed(void *parsed_result,
1991                                __attribute__((unused)) struct cmdline *cl,
1992                                __attribute__((unused)) void *data)
1993 {
1994         struct cmd_config_rss_hash_key *res = parsed_result;
1995         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1996         uint8_t xdgt0;
1997         uint8_t xdgt1;
1998         int i;
1999         struct rte_eth_dev_info dev_info;
2000         uint8_t hash_key_size;
2001         uint32_t key_len;
2002
2003         memset(&dev_info, 0, sizeof(dev_info));
2004         rte_eth_dev_info_get(res->port_id, &dev_info);
2005         if (dev_info.hash_key_size > 0 &&
2006                         dev_info.hash_key_size <= sizeof(hash_key))
2007                 hash_key_size = dev_info.hash_key_size;
2008         else {
2009                 printf("dev_info did not provide a valid hash key size\n");
2010                 return;
2011         }
2012         /* Check the length of the RSS hash key */
2013         key_len = strlen(res->key);
2014         if (key_len != (hash_key_size * 2)) {
2015                 printf("key length: %d invalid - key must be a string of %d"
2016                            " hexa-decimal numbers\n",
2017                            (int) key_len, hash_key_size * 2);
2018                 return;
2019         }
2020         /* Translate RSS hash key into binary representation */
2021         for (i = 0; i < hash_key_size; i++) {
2022                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2023                 if (xdgt0 == 0xFF)
2024                         return;
2025                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2026                 if (xdgt1 == 0xFF)
2027                         return;
2028                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2029         }
2030         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2031                         hash_key_size);
2032 }
2033
2034 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2035         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2036 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2037         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2038                                  "config");
2039 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2040         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2041 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2042         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2043                                  rss_hash_key, "rss-hash-key");
2044 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2045         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2046                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2047                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2048                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2049                                  "ipv6-tcp-ex#ipv6-udp-ex");
2050 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2051         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2052
2053 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2054         .f = cmd_config_rss_hash_key_parsed,
2055         .data = NULL,
2056         .help_str = "port config <port_id> rss-hash-key "
2057                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2058                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2059                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2060                 "<string of hex digits (variable length, NIC dependent)>",
2061         .tokens = {
2062                 (void *)&cmd_config_rss_hash_key_port,
2063                 (void *)&cmd_config_rss_hash_key_config,
2064                 (void *)&cmd_config_rss_hash_key_port_id,
2065                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2066                 (void *)&cmd_config_rss_hash_key_rss_type,
2067                 (void *)&cmd_config_rss_hash_key_value,
2068                 NULL,
2069         },
2070 };
2071
2072 /* *** configure port rxq/txq start/stop *** */
2073 struct cmd_config_rxtx_queue {
2074         cmdline_fixed_string_t port;
2075         portid_t portid;
2076         cmdline_fixed_string_t rxtxq;
2077         uint16_t qid;
2078         cmdline_fixed_string_t opname;
2079 };
2080
2081 static void
2082 cmd_config_rxtx_queue_parsed(void *parsed_result,
2083                         __attribute__((unused)) struct cmdline *cl,
2084                         __attribute__((unused)) void *data)
2085 {
2086         struct cmd_config_rxtx_queue *res = parsed_result;
2087         uint8_t isrx;
2088         uint8_t isstart;
2089         int ret = 0;
2090
2091         if (test_done == 0) {
2092                 printf("Please stop forwarding first\n");
2093                 return;
2094         }
2095
2096         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2097                 return;
2098
2099         if (port_is_started(res->portid) != 1) {
2100                 printf("Please start port %u first\n", res->portid);
2101                 return;
2102         }
2103
2104         if (!strcmp(res->rxtxq, "rxq"))
2105                 isrx = 1;
2106         else if (!strcmp(res->rxtxq, "txq"))
2107                 isrx = 0;
2108         else {
2109                 printf("Unknown parameter\n");
2110                 return;
2111         }
2112
2113         if (isrx && rx_queue_id_is_invalid(res->qid))
2114                 return;
2115         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2116                 return;
2117
2118         if (!strcmp(res->opname, "start"))
2119                 isstart = 1;
2120         else if (!strcmp(res->opname, "stop"))
2121                 isstart = 0;
2122         else {
2123                 printf("Unknown parameter\n");
2124                 return;
2125         }
2126
2127         if (isstart && isrx)
2128                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2129         else if (!isstart && isrx)
2130                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2131         else if (isstart && !isrx)
2132                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2133         else
2134                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2135
2136         if (ret == -ENOTSUP)
2137                 printf("Function not supported in PMD driver\n");
2138 }
2139
2140 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2142 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2143         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2144 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2146 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2147         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2148 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2150                                                 "start#stop");
2151
2152 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2153         .f = cmd_config_rxtx_queue_parsed,
2154         .data = NULL,
2155         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2156         .tokens = {
2157                 (void *)&cmd_config_speed_all_port,
2158                 (void *)&cmd_config_rxtx_queue_portid,
2159                 (void *)&cmd_config_rxtx_queue_rxtxq,
2160                 (void *)&cmd_config_rxtx_queue_qid,
2161                 (void *)&cmd_config_rxtx_queue_opname,
2162                 NULL,
2163         },
2164 };
2165
2166 /* *** Configure RSS RETA *** */
2167 struct cmd_config_rss_reta {
2168         cmdline_fixed_string_t port;
2169         cmdline_fixed_string_t keyword;
2170         portid_t port_id;
2171         cmdline_fixed_string_t name;
2172         cmdline_fixed_string_t list_name;
2173         cmdline_fixed_string_t list_of_items;
2174 };
2175
2176 static int
2177 parse_reta_config(const char *str,
2178                   struct rte_eth_rss_reta_entry64 *reta_conf,
2179                   uint16_t nb_entries)
2180 {
2181         int i;
2182         unsigned size;
2183         uint16_t hash_index, idx, shift;
2184         uint16_t nb_queue;
2185         char s[256];
2186         const char *p, *p0 = str;
2187         char *end;
2188         enum fieldnames {
2189                 FLD_HASH_INDEX = 0,
2190                 FLD_QUEUE,
2191                 _NUM_FLD
2192         };
2193         unsigned long int_fld[_NUM_FLD];
2194         char *str_fld[_NUM_FLD];
2195
2196         while ((p = strchr(p0,'(')) != NULL) {
2197                 ++p;
2198                 if((p0 = strchr(p,')')) == NULL)
2199                         return -1;
2200
2201                 size = p0 - p;
2202                 if(size >= sizeof(s))
2203                         return -1;
2204
2205                 snprintf(s, sizeof(s), "%.*s", size, p);
2206                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2207                         return -1;
2208                 for (i = 0; i < _NUM_FLD; i++) {
2209                         errno = 0;
2210                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2211                         if (errno != 0 || end == str_fld[i] ||
2212                                         int_fld[i] > 65535)
2213                                 return -1;
2214                 }
2215
2216                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2217                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2218
2219                 if (hash_index >= nb_entries) {
2220                         printf("Invalid RETA hash index=%d\n", hash_index);
2221                         return -1;
2222                 }
2223
2224                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2225                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2226                 reta_conf[idx].mask |= (1ULL << shift);
2227                 reta_conf[idx].reta[shift] = nb_queue;
2228         }
2229
2230         return 0;
2231 }
2232
2233 static void
2234 cmd_set_rss_reta_parsed(void *parsed_result,
2235                         __attribute__((unused)) struct cmdline *cl,
2236                         __attribute__((unused)) void *data)
2237 {
2238         int ret;
2239         struct rte_eth_dev_info dev_info;
2240         struct rte_eth_rss_reta_entry64 reta_conf[8];
2241         struct cmd_config_rss_reta *res = parsed_result;
2242
2243         memset(&dev_info, 0, sizeof(dev_info));
2244         rte_eth_dev_info_get(res->port_id, &dev_info);
2245         if (dev_info.reta_size == 0) {
2246                 printf("Redirection table size is 0 which is "
2247                                         "invalid for RSS\n");
2248                 return;
2249         } else
2250                 printf("The reta size of port %d is %u\n",
2251                         res->port_id, dev_info.reta_size);
2252         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2253                 printf("Currently do not support more than %u entries of "
2254                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2255                 return;
2256         }
2257
2258         memset(reta_conf, 0, sizeof(reta_conf));
2259         if (!strcmp(res->list_name, "reta")) {
2260                 if (parse_reta_config(res->list_of_items, reta_conf,
2261                                                 dev_info.reta_size)) {
2262                         printf("Invalid RSS Redirection Table "
2263                                         "config entered\n");
2264                         return;
2265                 }
2266                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2267                                 reta_conf, dev_info.reta_size);
2268                 if (ret != 0)
2269                         printf("Bad redirection table parameter, "
2270                                         "return code = %d \n", ret);
2271         }
2272 }
2273
2274 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2275         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2276 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2277         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2278 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2279         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2280 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2282 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2284 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2286                                  NULL);
2287 cmdline_parse_inst_t cmd_config_rss_reta = {
2288         .f = cmd_set_rss_reta_parsed,
2289         .data = NULL,
2290         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2291         .tokens = {
2292                 (void *)&cmd_config_rss_reta_port,
2293                 (void *)&cmd_config_rss_reta_keyword,
2294                 (void *)&cmd_config_rss_reta_port_id,
2295                 (void *)&cmd_config_rss_reta_name,
2296                 (void *)&cmd_config_rss_reta_list_name,
2297                 (void *)&cmd_config_rss_reta_list_of_items,
2298                 NULL,
2299         },
2300 };
2301
2302 /* *** SHOW PORT RETA INFO *** */
2303 struct cmd_showport_reta {
2304         cmdline_fixed_string_t show;
2305         cmdline_fixed_string_t port;
2306         portid_t port_id;
2307         cmdline_fixed_string_t rss;
2308         cmdline_fixed_string_t reta;
2309         uint16_t size;
2310         cmdline_fixed_string_t list_of_items;
2311 };
2312
2313 static int
2314 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2315                            uint16_t nb_entries,
2316                            char *str)
2317 {
2318         uint32_t size;
2319         const char *p, *p0 = str;
2320         char s[256];
2321         char *end;
2322         char *str_fld[8];
2323         uint16_t i;
2324         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2325                         RTE_RETA_GROUP_SIZE;
2326         int ret;
2327
2328         p = strchr(p0, '(');
2329         if (p == NULL)
2330                 return -1;
2331         p++;
2332         p0 = strchr(p, ')');
2333         if (p0 == NULL)
2334                 return -1;
2335         size = p0 - p;
2336         if (size >= sizeof(s)) {
2337                 printf("The string size exceeds the internal buffer size\n");
2338                 return -1;
2339         }
2340         snprintf(s, sizeof(s), "%.*s", size, p);
2341         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2342         if (ret <= 0 || ret != num) {
2343                 printf("The bits of masks do not match the number of "
2344                                         "reta entries: %u\n", num);
2345                 return -1;
2346         }
2347         for (i = 0; i < ret; i++)
2348                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2349
2350         return 0;
2351 }
2352
2353 static void
2354 cmd_showport_reta_parsed(void *parsed_result,
2355                          __attribute__((unused)) struct cmdline *cl,
2356                          __attribute__((unused)) void *data)
2357 {
2358         struct cmd_showport_reta *res = parsed_result;
2359         struct rte_eth_rss_reta_entry64 reta_conf[8];
2360         struct rte_eth_dev_info dev_info;
2361         uint16_t max_reta_size;
2362
2363         memset(&dev_info, 0, sizeof(dev_info));
2364         rte_eth_dev_info_get(res->port_id, &dev_info);
2365         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2366         if (res->size == 0 || res->size > max_reta_size) {
2367                 printf("Invalid redirection table size: %u (1-%u)\n",
2368                         res->size, max_reta_size);
2369                 return;
2370         }
2371
2372         memset(reta_conf, 0, sizeof(reta_conf));
2373         if (showport_parse_reta_config(reta_conf, res->size,
2374                                 res->list_of_items) < 0) {
2375                 printf("Invalid string: %s for reta masks\n",
2376                                         res->list_of_items);
2377                 return;
2378         }
2379         port_rss_reta_info(res->port_id, reta_conf, res->size);
2380 }
2381
2382 cmdline_parse_token_string_t cmd_showport_reta_show =
2383         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2384 cmdline_parse_token_string_t cmd_showport_reta_port =
2385         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2386 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2387         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2388 cmdline_parse_token_string_t cmd_showport_reta_rss =
2389         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2390 cmdline_parse_token_string_t cmd_showport_reta_reta =
2391         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2392 cmdline_parse_token_num_t cmd_showport_reta_size =
2393         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2394 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2395         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2396                                         list_of_items, NULL);
2397
2398 cmdline_parse_inst_t cmd_showport_reta = {
2399         .f = cmd_showport_reta_parsed,
2400         .data = NULL,
2401         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2402         .tokens = {
2403                 (void *)&cmd_showport_reta_show,
2404                 (void *)&cmd_showport_reta_port,
2405                 (void *)&cmd_showport_reta_port_id,
2406                 (void *)&cmd_showport_reta_rss,
2407                 (void *)&cmd_showport_reta_reta,
2408                 (void *)&cmd_showport_reta_size,
2409                 (void *)&cmd_showport_reta_list_of_items,
2410                 NULL,
2411         },
2412 };
2413
2414 /* *** Show RSS hash configuration *** */
2415 struct cmd_showport_rss_hash {
2416         cmdline_fixed_string_t show;
2417         cmdline_fixed_string_t port;
2418         portid_t port_id;
2419         cmdline_fixed_string_t rss_hash;
2420         cmdline_fixed_string_t rss_type;
2421         cmdline_fixed_string_t key; /* optional argument */
2422 };
2423
2424 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2425                                 __attribute__((unused)) struct cmdline *cl,
2426                                 void *show_rss_key)
2427 {
2428         struct cmd_showport_rss_hash *res = parsed_result;
2429
2430         port_rss_hash_conf_show(res->port_id, res->rss_type,
2431                                 show_rss_key != NULL);
2432 }
2433
2434 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2435         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2436 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2437         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2438 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2439         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2440 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2441         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2442                                  "rss-hash");
2443 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2444         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2445                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2446                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2447                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2448                                  "ipv6-tcp-ex#ipv6-udp-ex");
2449 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2450         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2451
2452 cmdline_parse_inst_t cmd_showport_rss_hash = {
2453         .f = cmd_showport_rss_hash_parsed,
2454         .data = NULL,
2455         .help_str = "show port <port_id> rss-hash "
2456                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2457                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2458                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2459         .tokens = {
2460                 (void *)&cmd_showport_rss_hash_show,
2461                 (void *)&cmd_showport_rss_hash_port,
2462                 (void *)&cmd_showport_rss_hash_port_id,
2463                 (void *)&cmd_showport_rss_hash_rss_hash,
2464                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2465                 NULL,
2466         },
2467 };
2468
2469 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2470         .f = cmd_showport_rss_hash_parsed,
2471         .data = (void *)1,
2472         .help_str = "show port <port_id> rss-hash "
2473                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2474                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2475                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2476         .tokens = {
2477                 (void *)&cmd_showport_rss_hash_show,
2478                 (void *)&cmd_showport_rss_hash_port,
2479                 (void *)&cmd_showport_rss_hash_port_id,
2480                 (void *)&cmd_showport_rss_hash_rss_hash,
2481                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2482                 (void *)&cmd_showport_rss_hash_rss_key,
2483                 NULL,
2484         },
2485 };
2486
2487 /* *** Configure DCB *** */
2488 struct cmd_config_dcb {
2489         cmdline_fixed_string_t port;
2490         cmdline_fixed_string_t config;
2491         portid_t port_id;
2492         cmdline_fixed_string_t dcb;
2493         cmdline_fixed_string_t vt;
2494         cmdline_fixed_string_t vt_en;
2495         uint8_t num_tcs;
2496         cmdline_fixed_string_t pfc;
2497         cmdline_fixed_string_t pfc_en;
2498 };
2499
2500 static void
2501 cmd_config_dcb_parsed(void *parsed_result,
2502                         __attribute__((unused)) struct cmdline *cl,
2503                         __attribute__((unused)) void *data)
2504 {
2505         struct cmd_config_dcb *res = parsed_result;
2506         portid_t port_id = res->port_id;
2507         struct rte_port *port;
2508         uint8_t pfc_en;
2509         int ret;
2510
2511         port = &ports[port_id];
2512         /** Check if the port is not started **/
2513         if (port->port_status != RTE_PORT_STOPPED) {
2514                 printf("Please stop port %d first\n", port_id);
2515                 return;
2516         }
2517
2518         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2519                 printf("The invalid number of traffic class,"
2520                         " only 4 or 8 allowed.\n");
2521                 return;
2522         }
2523
2524         if (nb_fwd_lcores < res->num_tcs) {
2525                 printf("nb_cores shouldn't be less than number of TCs.\n");
2526                 return;
2527         }
2528         if (!strncmp(res->pfc_en, "on", 2))
2529                 pfc_en = 1;
2530         else
2531                 pfc_en = 0;
2532
2533         /* DCB in VT mode */
2534         if (!strncmp(res->vt_en, "on", 2))
2535                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2536                                 (enum rte_eth_nb_tcs)res->num_tcs,
2537                                 pfc_en);
2538         else
2539                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2540                                 (enum rte_eth_nb_tcs)res->num_tcs,
2541                                 pfc_en);
2542
2543
2544         if (ret != 0) {
2545                 printf("Cannot initialize network ports.\n");
2546                 return;
2547         }
2548
2549         cmd_reconfig_device_queue(port_id, 1, 1);
2550 }
2551
2552 cmdline_parse_token_string_t cmd_config_dcb_port =
2553         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2554 cmdline_parse_token_string_t cmd_config_dcb_config =
2555         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2556 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2557         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2558 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2559         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2560 cmdline_parse_token_string_t cmd_config_dcb_vt =
2561         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2562 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2564 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2565         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2566 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2567         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2568 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2569         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2570
2571 cmdline_parse_inst_t cmd_config_dcb = {
2572         .f = cmd_config_dcb_parsed,
2573         .data = NULL,
2574         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2575         .tokens = {
2576                 (void *)&cmd_config_dcb_port,
2577                 (void *)&cmd_config_dcb_config,
2578                 (void *)&cmd_config_dcb_port_id,
2579                 (void *)&cmd_config_dcb_dcb,
2580                 (void *)&cmd_config_dcb_vt,
2581                 (void *)&cmd_config_dcb_vt_en,
2582                 (void *)&cmd_config_dcb_num_tcs,
2583                 (void *)&cmd_config_dcb_pfc,
2584                 (void *)&cmd_config_dcb_pfc_en,
2585                 NULL,
2586         },
2587 };
2588
2589 /* *** configure number of packets per burst *** */
2590 struct cmd_config_burst {
2591         cmdline_fixed_string_t port;
2592         cmdline_fixed_string_t keyword;
2593         cmdline_fixed_string_t all;
2594         cmdline_fixed_string_t name;
2595         uint16_t value;
2596 };
2597
2598 static void
2599 cmd_config_burst_parsed(void *parsed_result,
2600                         __attribute__((unused)) struct cmdline *cl,
2601                         __attribute__((unused)) void *data)
2602 {
2603         struct cmd_config_burst *res = parsed_result;
2604
2605         if (!all_ports_stopped()) {
2606                 printf("Please stop all ports first\n");
2607                 return;
2608         }
2609
2610         if (!strcmp(res->name, "burst")) {
2611                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2612                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2613                         return;
2614                 }
2615                 nb_pkt_per_burst = res->value;
2616         } else {
2617                 printf("Unknown parameter\n");
2618                 return;
2619         }
2620
2621         init_port_config();
2622
2623         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2624 }
2625
2626 cmdline_parse_token_string_t cmd_config_burst_port =
2627         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2628 cmdline_parse_token_string_t cmd_config_burst_keyword =
2629         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2630 cmdline_parse_token_string_t cmd_config_burst_all =
2631         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2632 cmdline_parse_token_string_t cmd_config_burst_name =
2633         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2634 cmdline_parse_token_num_t cmd_config_burst_value =
2635         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2636
2637 cmdline_parse_inst_t cmd_config_burst = {
2638         .f = cmd_config_burst_parsed,
2639         .data = NULL,
2640         .help_str = "port config all burst <value>",
2641         .tokens = {
2642                 (void *)&cmd_config_burst_port,
2643                 (void *)&cmd_config_burst_keyword,
2644                 (void *)&cmd_config_burst_all,
2645                 (void *)&cmd_config_burst_name,
2646                 (void *)&cmd_config_burst_value,
2647                 NULL,
2648         },
2649 };
2650
2651 /* *** configure rx/tx queues *** */
2652 struct cmd_config_thresh {
2653         cmdline_fixed_string_t port;
2654         cmdline_fixed_string_t keyword;
2655         cmdline_fixed_string_t all;
2656         cmdline_fixed_string_t name;
2657         uint8_t value;
2658 };
2659
2660 static void
2661 cmd_config_thresh_parsed(void *parsed_result,
2662                         __attribute__((unused)) struct cmdline *cl,
2663                         __attribute__((unused)) void *data)
2664 {
2665         struct cmd_config_thresh *res = parsed_result;
2666
2667         if (!all_ports_stopped()) {
2668                 printf("Please stop all ports first\n");
2669                 return;
2670         }
2671
2672         if (!strcmp(res->name, "txpt"))
2673                 tx_pthresh = res->value;
2674         else if(!strcmp(res->name, "txht"))
2675                 tx_hthresh = res->value;
2676         else if(!strcmp(res->name, "txwt"))
2677                 tx_wthresh = res->value;
2678         else if(!strcmp(res->name, "rxpt"))
2679                 rx_pthresh = res->value;
2680         else if(!strcmp(res->name, "rxht"))
2681                 rx_hthresh = res->value;
2682         else if(!strcmp(res->name, "rxwt"))
2683                 rx_wthresh = res->value;
2684         else {
2685                 printf("Unknown parameter\n");
2686                 return;
2687         }
2688
2689         init_port_config();
2690
2691         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2692 }
2693
2694 cmdline_parse_token_string_t cmd_config_thresh_port =
2695         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2696 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2697         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2698 cmdline_parse_token_string_t cmd_config_thresh_all =
2699         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2700 cmdline_parse_token_string_t cmd_config_thresh_name =
2701         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2702                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2703 cmdline_parse_token_num_t cmd_config_thresh_value =
2704         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2705
2706 cmdline_parse_inst_t cmd_config_thresh = {
2707         .f = cmd_config_thresh_parsed,
2708         .data = NULL,
2709         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2710         .tokens = {
2711                 (void *)&cmd_config_thresh_port,
2712                 (void *)&cmd_config_thresh_keyword,
2713                 (void *)&cmd_config_thresh_all,
2714                 (void *)&cmd_config_thresh_name,
2715                 (void *)&cmd_config_thresh_value,
2716                 NULL,
2717         },
2718 };
2719
2720 /* *** configure free/rs threshold *** */
2721 struct cmd_config_threshold {
2722         cmdline_fixed_string_t port;
2723         cmdline_fixed_string_t keyword;
2724         cmdline_fixed_string_t all;
2725         cmdline_fixed_string_t name;
2726         uint16_t value;
2727 };
2728
2729 static void
2730 cmd_config_threshold_parsed(void *parsed_result,
2731                         __attribute__((unused)) struct cmdline *cl,
2732                         __attribute__((unused)) void *data)
2733 {
2734         struct cmd_config_threshold *res = parsed_result;
2735
2736         if (!all_ports_stopped()) {
2737                 printf("Please stop all ports first\n");
2738                 return;
2739         }
2740
2741         if (!strcmp(res->name, "txfreet"))
2742                 tx_free_thresh = res->value;
2743         else if (!strcmp(res->name, "txrst"))
2744                 tx_rs_thresh = res->value;
2745         else if (!strcmp(res->name, "rxfreet"))
2746                 rx_free_thresh = res->value;
2747         else {
2748                 printf("Unknown parameter\n");
2749                 return;
2750         }
2751
2752         init_port_config();
2753
2754         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2755 }
2756
2757 cmdline_parse_token_string_t cmd_config_threshold_port =
2758         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2759 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2760         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2761                                                                 "config");
2762 cmdline_parse_token_string_t cmd_config_threshold_all =
2763         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2764 cmdline_parse_token_string_t cmd_config_threshold_name =
2765         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2766                                                 "txfreet#txrst#rxfreet");
2767 cmdline_parse_token_num_t cmd_config_threshold_value =
2768         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2769
2770 cmdline_parse_inst_t cmd_config_threshold = {
2771         .f = cmd_config_threshold_parsed,
2772         .data = NULL,
2773         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2774         .tokens = {
2775                 (void *)&cmd_config_threshold_port,
2776                 (void *)&cmd_config_threshold_keyword,
2777                 (void *)&cmd_config_threshold_all,
2778                 (void *)&cmd_config_threshold_name,
2779                 (void *)&cmd_config_threshold_value,
2780                 NULL,
2781         },
2782 };
2783
2784 /* *** stop *** */
2785 struct cmd_stop_result {
2786         cmdline_fixed_string_t stop;
2787 };
2788
2789 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2790                             __attribute__((unused)) struct cmdline *cl,
2791                             __attribute__((unused)) void *data)
2792 {
2793         stop_packet_forwarding();
2794 }
2795
2796 cmdline_parse_token_string_t cmd_stop_stop =
2797         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2798
2799 cmdline_parse_inst_t cmd_stop = {
2800         .f = cmd_stop_parsed,
2801         .data = NULL,
2802         .help_str = "stop: Stop packet forwarding",
2803         .tokens = {
2804                 (void *)&cmd_stop_stop,
2805                 NULL,
2806         },
2807 };
2808
2809 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2810
2811 unsigned int
2812 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2813                 unsigned int *parsed_items, int check_unique_values)
2814 {
2815         unsigned int nb_item;
2816         unsigned int value;
2817         unsigned int i;
2818         unsigned int j;
2819         int value_ok;
2820         char c;
2821
2822         /*
2823          * First parse all items in the list and store their value.
2824          */
2825         value = 0;
2826         nb_item = 0;
2827         value_ok = 0;
2828         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2829                 c = str[i];
2830                 if ((c >= '0') && (c <= '9')) {
2831                         value = (unsigned int) (value * 10 + (c - '0'));
2832                         value_ok = 1;
2833                         continue;
2834                 }
2835                 if (c != ',') {
2836                         printf("character %c is not a decimal digit\n", c);
2837                         return 0;
2838                 }
2839                 if (! value_ok) {
2840                         printf("No valid value before comma\n");
2841                         return 0;
2842                 }
2843                 if (nb_item < max_items) {
2844                         parsed_items[nb_item] = value;
2845                         value_ok = 0;
2846                         value = 0;
2847                 }
2848                 nb_item++;
2849         }
2850         if (nb_item >= max_items) {
2851                 printf("Number of %s = %u > %u (maximum items)\n",
2852                        item_name, nb_item + 1, max_items);
2853                 return 0;
2854         }
2855         parsed_items[nb_item++] = value;
2856         if (! check_unique_values)
2857                 return nb_item;
2858
2859         /*
2860          * Then, check that all values in the list are differents.
2861          * No optimization here...
2862          */
2863         for (i = 0; i < nb_item; i++) {
2864                 for (j = i + 1; j < nb_item; j++) {
2865                         if (parsed_items[j] == parsed_items[i]) {
2866                                 printf("duplicated %s %u at index %u and %u\n",
2867                                        item_name, parsed_items[i], i, j);
2868                                 return 0;
2869                         }
2870                 }
2871         }
2872         return nb_item;
2873 }
2874
2875 struct cmd_set_list_result {
2876         cmdline_fixed_string_t cmd_keyword;
2877         cmdline_fixed_string_t list_name;
2878         cmdline_fixed_string_t list_of_items;
2879 };
2880
2881 static void cmd_set_list_parsed(void *parsed_result,
2882                                 __attribute__((unused)) struct cmdline *cl,
2883                                 __attribute__((unused)) void *data)
2884 {
2885         struct cmd_set_list_result *res;
2886         union {
2887                 unsigned int lcorelist[RTE_MAX_LCORE];
2888                 unsigned int portlist[RTE_MAX_ETHPORTS];
2889         } parsed_items;
2890         unsigned int nb_item;
2891
2892         if (test_done == 0) {
2893                 printf("Please stop forwarding first\n");
2894                 return;
2895         }
2896
2897         res = parsed_result;
2898         if (!strcmp(res->list_name, "corelist")) {
2899                 nb_item = parse_item_list(res->list_of_items, "core",
2900                                           RTE_MAX_LCORE,
2901                                           parsed_items.lcorelist, 1);
2902                 if (nb_item > 0) {
2903                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2904                         fwd_config_setup();
2905                 }
2906                 return;
2907         }
2908         if (!strcmp(res->list_name, "portlist")) {
2909                 nb_item = parse_item_list(res->list_of_items, "port",
2910                                           RTE_MAX_ETHPORTS,
2911                                           parsed_items.portlist, 1);
2912                 if (nb_item > 0) {
2913                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2914                         fwd_config_setup();
2915                 }
2916         }
2917 }
2918
2919 cmdline_parse_token_string_t cmd_set_list_keyword =
2920         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2921                                  "set");
2922 cmdline_parse_token_string_t cmd_set_list_name =
2923         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2924                                  "corelist#portlist");
2925 cmdline_parse_token_string_t cmd_set_list_of_items =
2926         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2927                                  NULL);
2928
2929 cmdline_parse_inst_t cmd_set_fwd_list = {
2930         .f = cmd_set_list_parsed,
2931         .data = NULL,
2932         .help_str = "set corelist|portlist <list0[,list1]*>",
2933         .tokens = {
2934                 (void *)&cmd_set_list_keyword,
2935                 (void *)&cmd_set_list_name,
2936                 (void *)&cmd_set_list_of_items,
2937                 NULL,
2938         },
2939 };
2940
2941 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2942
2943 struct cmd_setmask_result {
2944         cmdline_fixed_string_t set;
2945         cmdline_fixed_string_t mask;
2946         uint64_t hexavalue;
2947 };
2948
2949 static void cmd_set_mask_parsed(void *parsed_result,
2950                                 __attribute__((unused)) struct cmdline *cl,
2951                                 __attribute__((unused)) void *data)
2952 {
2953         struct cmd_setmask_result *res = parsed_result;
2954
2955         if (test_done == 0) {
2956                 printf("Please stop forwarding first\n");
2957                 return;
2958         }
2959         if (!strcmp(res->mask, "coremask")) {
2960                 set_fwd_lcores_mask(res->hexavalue);
2961                 fwd_config_setup();
2962         } else if (!strcmp(res->mask, "portmask")) {
2963                 set_fwd_ports_mask(res->hexavalue);
2964                 fwd_config_setup();
2965         }
2966 }
2967
2968 cmdline_parse_token_string_t cmd_setmask_set =
2969         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2970 cmdline_parse_token_string_t cmd_setmask_mask =
2971         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2972                                  "coremask#portmask");
2973 cmdline_parse_token_num_t cmd_setmask_value =
2974         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2975
2976 cmdline_parse_inst_t cmd_set_fwd_mask = {
2977         .f = cmd_set_mask_parsed,
2978         .data = NULL,
2979         .help_str = "set coremask|portmask <hexadecimal value>",
2980         .tokens = {
2981                 (void *)&cmd_setmask_set,
2982                 (void *)&cmd_setmask_mask,
2983                 (void *)&cmd_setmask_value,
2984                 NULL,
2985         },
2986 };
2987
2988 /*
2989  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2990  */
2991 struct cmd_set_result {
2992         cmdline_fixed_string_t set;
2993         cmdline_fixed_string_t what;
2994         uint16_t value;
2995 };
2996
2997 static void cmd_set_parsed(void *parsed_result,
2998                            __attribute__((unused)) struct cmdline *cl,
2999                            __attribute__((unused)) void *data)
3000 {
3001         struct cmd_set_result *res = parsed_result;
3002         if (!strcmp(res->what, "nbport")) {
3003                 set_fwd_ports_number(res->value);
3004                 fwd_config_setup();
3005         } else if (!strcmp(res->what, "nbcore")) {
3006                 set_fwd_lcores_number(res->value);
3007                 fwd_config_setup();
3008         } else if (!strcmp(res->what, "burst"))
3009                 set_nb_pkt_per_burst(res->value);
3010         else if (!strcmp(res->what, "verbose"))
3011                 set_verbose_level(res->value);
3012 }
3013
3014 cmdline_parse_token_string_t cmd_set_set =
3015         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3016 cmdline_parse_token_string_t cmd_set_what =
3017         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3018                                  "nbport#nbcore#burst#verbose");
3019 cmdline_parse_token_num_t cmd_set_value =
3020         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3021
3022 cmdline_parse_inst_t cmd_set_numbers = {
3023         .f = cmd_set_parsed,
3024         .data = NULL,
3025         .help_str = "set nbport|nbcore|burst|verbose <value>",
3026         .tokens = {
3027                 (void *)&cmd_set_set,
3028                 (void *)&cmd_set_what,
3029                 (void *)&cmd_set_value,
3030                 NULL,
3031         },
3032 };
3033
3034 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3035
3036 struct cmd_set_txpkts_result {
3037         cmdline_fixed_string_t cmd_keyword;
3038         cmdline_fixed_string_t txpkts;
3039         cmdline_fixed_string_t seg_lengths;
3040 };
3041
3042 static void
3043 cmd_set_txpkts_parsed(void *parsed_result,
3044                       __attribute__((unused)) struct cmdline *cl,
3045                       __attribute__((unused)) void *data)
3046 {
3047         struct cmd_set_txpkts_result *res;
3048         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3049         unsigned int nb_segs;
3050
3051         res = parsed_result;
3052         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3053                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3054         if (nb_segs > 0)
3055                 set_tx_pkt_segments(seg_lengths, nb_segs);
3056 }
3057
3058 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3059         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3060                                  cmd_keyword, "set");
3061 cmdline_parse_token_string_t cmd_set_txpkts_name =
3062         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3063                                  txpkts, "txpkts");
3064 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3065         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3066                                  seg_lengths, NULL);
3067
3068 cmdline_parse_inst_t cmd_set_txpkts = {
3069         .f = cmd_set_txpkts_parsed,
3070         .data = NULL,
3071         .help_str = "set txpkts <len0[,len1]*>",
3072         .tokens = {
3073                 (void *)&cmd_set_txpkts_keyword,
3074                 (void *)&cmd_set_txpkts_name,
3075                 (void *)&cmd_set_txpkts_lengths,
3076                 NULL,
3077         },
3078 };
3079
3080 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3081
3082 struct cmd_set_txsplit_result {
3083         cmdline_fixed_string_t cmd_keyword;
3084         cmdline_fixed_string_t txsplit;
3085         cmdline_fixed_string_t mode;
3086 };
3087
3088 static void
3089 cmd_set_txsplit_parsed(void *parsed_result,
3090                       __attribute__((unused)) struct cmdline *cl,
3091                       __attribute__((unused)) void *data)
3092 {
3093         struct cmd_set_txsplit_result *res;
3094
3095         res = parsed_result;
3096         set_tx_pkt_split(res->mode);
3097 }
3098
3099 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3100         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3101                                  cmd_keyword, "set");
3102 cmdline_parse_token_string_t cmd_set_txsplit_name =
3103         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3104                                  txsplit, "txsplit");
3105 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3106         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3107                                  mode, NULL);
3108
3109 cmdline_parse_inst_t cmd_set_txsplit = {
3110         .f = cmd_set_txsplit_parsed,
3111         .data = NULL,
3112         .help_str = "set txsplit on|off|rand",
3113         .tokens = {
3114                 (void *)&cmd_set_txsplit_keyword,
3115                 (void *)&cmd_set_txsplit_name,
3116                 (void *)&cmd_set_txsplit_mode,
3117                 NULL,
3118         },
3119 };
3120
3121 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3122 struct cmd_rx_vlan_filter_all_result {
3123         cmdline_fixed_string_t rx_vlan;
3124         cmdline_fixed_string_t what;
3125         cmdline_fixed_string_t all;
3126         portid_t port_id;
3127 };
3128
3129 static void
3130 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3131                               __attribute__((unused)) struct cmdline *cl,
3132                               __attribute__((unused)) void *data)
3133 {
3134         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3135
3136         if (!strcmp(res->what, "add"))
3137                 rx_vlan_all_filter_set(res->port_id, 1);
3138         else
3139                 rx_vlan_all_filter_set(res->port_id, 0);
3140 }
3141
3142 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3143         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3144                                  rx_vlan, "rx_vlan");
3145 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3146         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3147                                  what, "add#rm");
3148 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3149         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3150                                  all, "all");
3151 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3152         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3153                               port_id, UINT16);
3154
3155 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3156         .f = cmd_rx_vlan_filter_all_parsed,
3157         .data = NULL,
3158         .help_str = "rx_vlan add|rm all <port_id>: "
3159                 "Add/Remove all identifiers to/from the set of VLAN "
3160                 "identifiers filtered by a port",
3161         .tokens = {
3162                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3163                 (void *)&cmd_rx_vlan_filter_all_what,
3164                 (void *)&cmd_rx_vlan_filter_all_all,
3165                 (void *)&cmd_rx_vlan_filter_all_portid,
3166                 NULL,
3167         },
3168 };
3169
3170 /* *** VLAN OFFLOAD SET ON A PORT *** */
3171 struct cmd_vlan_offload_result {
3172         cmdline_fixed_string_t vlan;
3173         cmdline_fixed_string_t set;
3174         cmdline_fixed_string_t vlan_type;
3175         cmdline_fixed_string_t what;
3176         cmdline_fixed_string_t on;
3177         cmdline_fixed_string_t port_id;
3178 };
3179
3180 static void
3181 cmd_vlan_offload_parsed(void *parsed_result,
3182                           __attribute__((unused)) struct cmdline *cl,
3183                           __attribute__((unused)) void *data)
3184 {
3185         int on;
3186         struct cmd_vlan_offload_result *res = parsed_result;
3187         char *str;
3188         int i, len = 0;
3189         portid_t port_id = 0;
3190         unsigned int tmp;
3191
3192         str = res->port_id;
3193         len = strnlen(str, STR_TOKEN_SIZE);
3194         i = 0;
3195         /* Get port_id first */
3196         while(i < len){
3197                 if(str[i] == ',')
3198                         break;
3199
3200                 i++;
3201         }
3202         str[i]='\0';
3203         tmp = strtoul(str, NULL, 0);
3204         /* If port_id greater that what portid_t can represent, return */
3205         if(tmp >= RTE_MAX_ETHPORTS)
3206                 return;
3207         port_id = (portid_t)tmp;
3208
3209         if (!strcmp(res->on, "on"))
3210                 on = 1;
3211         else
3212                 on = 0;
3213
3214         if (!strcmp(res->what, "strip"))
3215                 rx_vlan_strip_set(port_id,  on);
3216         else if(!strcmp(res->what, "stripq")){
3217                 uint16_t queue_id = 0;
3218
3219                 /* No queue_id, return */
3220                 if(i + 1 >= len) {
3221                         printf("must specify (port,queue_id)\n");
3222                         return;
3223                 }
3224                 tmp = strtoul(str + i + 1, NULL, 0);
3225                 /* If queue_id greater that what 16-bits can represent, return */
3226                 if(tmp > 0xffff)
3227                         return;
3228
3229                 queue_id = (uint16_t)tmp;
3230                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3231         }
3232         else if (!strcmp(res->what, "filter"))
3233                 rx_vlan_filter_set(port_id, on);
3234         else
3235                 vlan_extend_set(port_id, on);
3236
3237         return;
3238 }
3239
3240 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3241         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3242                                  vlan, "vlan");
3243 cmdline_parse_token_string_t cmd_vlan_offload_set =
3244         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3245                                  set, "set");
3246 cmdline_parse_token_string_t cmd_vlan_offload_what =
3247         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3248                                  what, "strip#filter#qinq#stripq");
3249 cmdline_parse_token_string_t cmd_vlan_offload_on =
3250         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3251                               on, "on#off");
3252 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3253         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3254                               port_id, NULL);
3255
3256 cmdline_parse_inst_t cmd_vlan_offload = {
3257         .f = cmd_vlan_offload_parsed,
3258         .data = NULL,
3259         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3260                 "<port_id[,queue_id]>: "
3261                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3262         .tokens = {
3263                 (void *)&cmd_vlan_offload_vlan,
3264                 (void *)&cmd_vlan_offload_set,
3265                 (void *)&cmd_vlan_offload_what,
3266                 (void *)&cmd_vlan_offload_on,
3267                 (void *)&cmd_vlan_offload_portid,
3268                 NULL,
3269         },
3270 };
3271
3272 /* *** VLAN TPID SET ON A PORT *** */
3273 struct cmd_vlan_tpid_result {
3274         cmdline_fixed_string_t vlan;
3275         cmdline_fixed_string_t set;
3276         cmdline_fixed_string_t vlan_type;
3277         cmdline_fixed_string_t what;
3278         uint16_t tp_id;
3279         portid_t port_id;
3280 };
3281
3282 static void
3283 cmd_vlan_tpid_parsed(void *parsed_result,
3284                           __attribute__((unused)) struct cmdline *cl,
3285                           __attribute__((unused)) void *data)
3286 {
3287         struct cmd_vlan_tpid_result *res = parsed_result;
3288         enum rte_vlan_type vlan_type;
3289
3290         if (!strcmp(res->vlan_type, "inner"))
3291                 vlan_type = ETH_VLAN_TYPE_INNER;
3292         else if (!strcmp(res->vlan_type, "outer"))
3293                 vlan_type = ETH_VLAN_TYPE_OUTER;
3294         else {
3295                 printf("Unknown vlan type\n");
3296                 return;
3297         }
3298         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3299 }
3300
3301 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3302         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3303                                  vlan, "vlan");
3304 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3305         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3306                                  set, "set");
3307 cmdline_parse_token_string_t cmd_vlan_type =
3308         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3309                                  vlan_type, "inner#outer");
3310 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3311         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3312                                  what, "tpid");
3313 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3314         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3315                               tp_id, UINT16);
3316 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3317         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3318                               port_id, UINT16);
3319
3320 cmdline_parse_inst_t cmd_vlan_tpid = {
3321         .f = cmd_vlan_tpid_parsed,
3322         .data = NULL,
3323         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3324                 "Set the VLAN Ether type",
3325         .tokens = {
3326                 (void *)&cmd_vlan_tpid_vlan,
3327                 (void *)&cmd_vlan_tpid_set,
3328                 (void *)&cmd_vlan_type,
3329                 (void *)&cmd_vlan_tpid_what,
3330                 (void *)&cmd_vlan_tpid_tpid,
3331                 (void *)&cmd_vlan_tpid_portid,
3332                 NULL,
3333         },
3334 };
3335
3336 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3337 struct cmd_rx_vlan_filter_result {
3338         cmdline_fixed_string_t rx_vlan;
3339         cmdline_fixed_string_t what;
3340         uint16_t vlan_id;
3341         portid_t port_id;
3342 };
3343
3344 static void
3345 cmd_rx_vlan_filter_parsed(void *parsed_result,
3346                           __attribute__((unused)) struct cmdline *cl,
3347                           __attribute__((unused)) void *data)
3348 {
3349         struct cmd_rx_vlan_filter_result *res = parsed_result;
3350
3351         if (!strcmp(res->what, "add"))
3352                 rx_vft_set(res->port_id, res->vlan_id, 1);
3353         else
3354                 rx_vft_set(res->port_id, res->vlan_id, 0);
3355 }
3356
3357 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3358         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3359                                  rx_vlan, "rx_vlan");
3360 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3361         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3362                                  what, "add#rm");
3363 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3364         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3365                               vlan_id, UINT16);
3366 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3367         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3368                               port_id, UINT16);
3369
3370 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3371         .f = cmd_rx_vlan_filter_parsed,
3372         .data = NULL,
3373         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3374                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3375                 "identifiers filtered by a port",
3376         .tokens = {
3377                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3378                 (void *)&cmd_rx_vlan_filter_what,
3379                 (void *)&cmd_rx_vlan_filter_vlanid,
3380                 (void *)&cmd_rx_vlan_filter_portid,
3381                 NULL,
3382         },
3383 };
3384
3385 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3386 struct cmd_tx_vlan_set_result {
3387         cmdline_fixed_string_t tx_vlan;
3388         cmdline_fixed_string_t set;
3389         portid_t port_id;
3390         uint16_t vlan_id;
3391 };
3392
3393 static void
3394 cmd_tx_vlan_set_parsed(void *parsed_result,
3395                        __attribute__((unused)) struct cmdline *cl,
3396                        __attribute__((unused)) void *data)
3397 {
3398         struct cmd_tx_vlan_set_result *res = parsed_result;
3399
3400         if (!port_is_stopped(res->port_id)) {
3401                 printf("Please stop port %d first\n", res->port_id);
3402                 return;
3403         }
3404
3405         tx_vlan_set(res->port_id, res->vlan_id);
3406
3407         cmd_reconfig_device_queue(res->port_id, 1, 1);
3408 }
3409
3410 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3411         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3412                                  tx_vlan, "tx_vlan");
3413 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3414         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3415                                  set, "set");
3416 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3417         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3418                               port_id, UINT16);
3419 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3420         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3421                               vlan_id, UINT16);
3422
3423 cmdline_parse_inst_t cmd_tx_vlan_set = {
3424         .f = cmd_tx_vlan_set_parsed,
3425         .data = NULL,
3426         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3427                 "Enable hardware insertion of a single VLAN header "
3428                 "with a given TAG Identifier in packets sent on a port",
3429         .tokens = {
3430                 (void *)&cmd_tx_vlan_set_tx_vlan,
3431                 (void *)&cmd_tx_vlan_set_set,
3432                 (void *)&cmd_tx_vlan_set_portid,
3433                 (void *)&cmd_tx_vlan_set_vlanid,
3434                 NULL,
3435         },
3436 };
3437
3438 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3439 struct cmd_tx_vlan_set_qinq_result {
3440         cmdline_fixed_string_t tx_vlan;
3441         cmdline_fixed_string_t set;
3442         portid_t port_id;
3443         uint16_t vlan_id;
3444         uint16_t vlan_id_outer;
3445 };
3446
3447 static void
3448 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3449                             __attribute__((unused)) struct cmdline *cl,
3450                             __attribute__((unused)) void *data)
3451 {
3452         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3453
3454         if (!port_is_stopped(res->port_id)) {
3455                 printf("Please stop port %d first\n", res->port_id);
3456                 return;
3457         }
3458
3459         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3460
3461         cmd_reconfig_device_queue(res->port_id, 1, 1);
3462 }
3463
3464 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3465         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3466                 tx_vlan, "tx_vlan");
3467 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3468         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3469                 set, "set");
3470 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3471         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3472                 port_id, UINT16);
3473 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3474         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3475                 vlan_id, UINT16);
3476 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3477         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3478                 vlan_id_outer, UINT16);
3479
3480 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3481         .f = cmd_tx_vlan_set_qinq_parsed,
3482         .data = NULL,
3483         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3484                 "Enable hardware insertion of double VLAN header "
3485                 "with given TAG Identifiers in packets sent on a port",
3486         .tokens = {
3487                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3488                 (void *)&cmd_tx_vlan_set_qinq_set,
3489                 (void *)&cmd_tx_vlan_set_qinq_portid,
3490                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3491                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3492                 NULL,
3493         },
3494 };
3495
3496 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3497 struct cmd_tx_vlan_set_pvid_result {
3498         cmdline_fixed_string_t tx_vlan;
3499         cmdline_fixed_string_t set;
3500         cmdline_fixed_string_t pvid;
3501         portid_t port_id;
3502         uint16_t vlan_id;
3503         cmdline_fixed_string_t mode;
3504 };
3505
3506 static void
3507 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3508                             __attribute__((unused)) struct cmdline *cl,
3509                             __attribute__((unused)) void *data)
3510 {
3511         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3512
3513         if (strcmp(res->mode, "on") == 0)
3514                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3515         else
3516                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3517 }
3518
3519 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3520         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3521                                  tx_vlan, "tx_vlan");
3522 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3523         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3524                                  set, "set");
3525 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3526         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3527                                  pvid, "pvid");
3528 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3529         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3530                              port_id, UINT16);
3531 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3532         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3533                               vlan_id, UINT16);
3534 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3535         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3536                                  mode, "on#off");
3537
3538 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3539         .f = cmd_tx_vlan_set_pvid_parsed,
3540         .data = NULL,
3541         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3542         .tokens = {
3543                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3544                 (void *)&cmd_tx_vlan_set_pvid_set,
3545                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3546                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3547                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3548                 (void *)&cmd_tx_vlan_set_pvid_mode,
3549                 NULL,
3550         },
3551 };
3552
3553 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3554 struct cmd_tx_vlan_reset_result {
3555         cmdline_fixed_string_t tx_vlan;
3556         cmdline_fixed_string_t reset;
3557         portid_t port_id;
3558 };
3559
3560 static void
3561 cmd_tx_vlan_reset_parsed(void *parsed_result,
3562                          __attribute__((unused)) struct cmdline *cl,
3563                          __attribute__((unused)) void *data)
3564 {
3565         struct cmd_tx_vlan_reset_result *res = parsed_result;
3566
3567         if (!port_is_stopped(res->port_id)) {
3568                 printf("Please stop port %d first\n", res->port_id);
3569                 return;
3570         }
3571
3572         tx_vlan_reset(res->port_id);
3573
3574         cmd_reconfig_device_queue(res->port_id, 1, 1);
3575 }
3576
3577 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3578         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3579                                  tx_vlan, "tx_vlan");
3580 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3581         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3582                                  reset, "reset");
3583 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3584         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3585                               port_id, UINT16);
3586
3587 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3588         .f = cmd_tx_vlan_reset_parsed,
3589         .data = NULL,
3590         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3591                 "VLAN header in packets sent on a port",
3592         .tokens = {
3593                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3594                 (void *)&cmd_tx_vlan_reset_reset,
3595                 (void *)&cmd_tx_vlan_reset_portid,
3596                 NULL,
3597         },
3598 };
3599
3600
3601 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3602 struct cmd_csum_result {
3603         cmdline_fixed_string_t csum;
3604         cmdline_fixed_string_t mode;
3605         cmdline_fixed_string_t proto;
3606         cmdline_fixed_string_t hwsw;
3607         portid_t port_id;
3608 };
3609
3610 static void
3611 csum_show(int port_id)
3612 {
3613         struct rte_eth_dev_info dev_info;
3614         uint64_t tx_offloads;
3615
3616         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3617         printf("Parse tunnel is %s\n",
3618                 (ports[port_id].parse_tunnel) ? "on" : "off");
3619         printf("IP checksum offload is %s\n",
3620                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3621         printf("UDP checksum offload is %s\n",
3622                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3623         printf("TCP checksum offload is %s\n",
3624                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3625         printf("SCTP checksum offload is %s\n",
3626                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3627         printf("Outer-Ip checksum offload is %s\n",
3628                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3629
3630         /* display warnings if configuration is not supported by the NIC */
3631         rte_eth_dev_info_get(port_id, &dev_info);
3632         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3633                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3634                 printf("Warning: hardware IP checksum enabled but not "
3635                         "supported by port %d\n", port_id);
3636         }
3637         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3638                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3639                 printf("Warning: hardware UDP checksum enabled but not "
3640                         "supported by port %d\n", port_id);
3641         }
3642         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3643                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3644                 printf("Warning: hardware TCP checksum enabled but not "
3645                         "supported by port %d\n", port_id);
3646         }
3647         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3648                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3649                 printf("Warning: hardware SCTP checksum enabled but not "
3650                         "supported by port %d\n", port_id);
3651         }
3652         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3653                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3654                 printf("Warning: hardware outer IP checksum enabled but not "
3655                         "supported by port %d\n", port_id);
3656         }
3657 }
3658
3659 static void
3660 cmd_csum_parsed(void *parsed_result,
3661                        __attribute__((unused)) struct cmdline *cl,
3662                        __attribute__((unused)) void *data)
3663 {
3664         struct cmd_csum_result *res = parsed_result;
3665         int hw = 0;
3666         uint64_t csum_offloads = 0;
3667         struct rte_eth_dev_info dev_info;
3668
3669         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3670                 printf("invalid port %d\n", res->port_id);
3671                 return;
3672         }
3673         if (!port_is_stopped(res->port_id)) {
3674                 printf("Please stop port %d first\n", res->port_id);
3675                 return;
3676         }
3677
3678         rte_eth_dev_info_get(res->port_id, &dev_info);
3679         if (!strcmp(res->mode, "set")) {
3680
3681                 if (!strcmp(res->hwsw, "hw"))
3682                         hw = 1;
3683
3684                 if (!strcmp(res->proto, "ip")) {
3685                         if (dev_info.tx_offload_capa &
3686                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3687                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3688                         } else {
3689                                 printf("IP checksum offload is not supported "
3690                                        "by port %u\n", res->port_id);
3691                         }
3692                 } else if (!strcmp(res->proto, "udp")) {
3693                         if (dev_info.tx_offload_capa &
3694                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3695                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3696                         } else {
3697                                 printf("UDP checksum offload is not supported "
3698                                        "by port %u\n", res->port_id);
3699                         }
3700                 } else if (!strcmp(res->proto, "tcp")) {
3701                         if (dev_info.tx_offload_capa &
3702                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3703                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3704                         } else {
3705                                 printf("TCP checksum offload is not supported "
3706                                        "by port %u\n", res->port_id);
3707                         }
3708                 } else if (!strcmp(res->proto, "sctp")) {
3709                         if (dev_info.tx_offload_capa &
3710                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3711                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3712                         } else {
3713                                 printf("SCTP checksum offload is not supported "
3714                                        "by port %u\n", res->port_id);
3715                         }
3716                 } else if (!strcmp(res->proto, "outer-ip")) {
3717                         if (dev_info.tx_offload_capa &
3718                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3719                                 csum_offloads |=
3720                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3721                         } else {
3722                                 printf("Outer IP checksum offload is not "
3723                                        "supported by port %u\n", res->port_id);
3724                         }
3725                 }
3726
3727                 if (hw) {
3728                         ports[res->port_id].dev_conf.txmode.offloads |=
3729                                                         csum_offloads;
3730                 } else {
3731                         ports[res->port_id].dev_conf.txmode.offloads &=
3732                                                         (~csum_offloads);
3733                 }
3734         }
3735         csum_show(res->port_id);
3736
3737         cmd_reconfig_device_queue(res->port_id, 1, 1);
3738 }
3739
3740 cmdline_parse_token_string_t cmd_csum_csum =
3741         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3742                                 csum, "csum");
3743 cmdline_parse_token_string_t cmd_csum_mode =
3744         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3745                                 mode, "set");
3746 cmdline_parse_token_string_t cmd_csum_proto =
3747         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3748                                 proto, "ip#tcp#udp#sctp#outer-ip");
3749 cmdline_parse_token_string_t cmd_csum_hwsw =
3750         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3751                                 hwsw, "hw#sw");
3752 cmdline_parse_token_num_t cmd_csum_portid =
3753         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3754                                 port_id, UINT16);
3755
3756 cmdline_parse_inst_t cmd_csum_set = {
3757         .f = cmd_csum_parsed,
3758         .data = NULL,
3759         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3760                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3761                 "using csum forward engine",
3762         .tokens = {
3763                 (void *)&cmd_csum_csum,
3764                 (void *)&cmd_csum_mode,
3765                 (void *)&cmd_csum_proto,
3766                 (void *)&cmd_csum_hwsw,
3767                 (void *)&cmd_csum_portid,
3768                 NULL,
3769         },
3770 };
3771
3772 cmdline_parse_token_string_t cmd_csum_mode_show =
3773         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3774                                 mode, "show");
3775
3776 cmdline_parse_inst_t cmd_csum_show = {
3777         .f = cmd_csum_parsed,
3778         .data = NULL,
3779         .help_str = "csum show <port_id>: Show checksum offload configuration",
3780         .tokens = {
3781                 (void *)&cmd_csum_csum,
3782                 (void *)&cmd_csum_mode_show,
3783                 (void *)&cmd_csum_portid,
3784                 NULL,
3785         },
3786 };
3787
3788 /* Enable/disable tunnel parsing */
3789 struct cmd_csum_tunnel_result {
3790         cmdline_fixed_string_t csum;
3791         cmdline_fixed_string_t parse;
3792         cmdline_fixed_string_t onoff;
3793         portid_t port_id;
3794 };
3795
3796 static void
3797 cmd_csum_tunnel_parsed(void *parsed_result,
3798                        __attribute__((unused)) struct cmdline *cl,
3799                        __attribute__((unused)) void *data)
3800 {
3801         struct cmd_csum_tunnel_result *res = parsed_result;
3802
3803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3804                 return;
3805
3806         if (!strcmp(res->onoff, "on"))
3807                 ports[res->port_id].parse_tunnel = 1;
3808         else
3809                 ports[res->port_id].parse_tunnel = 0;
3810
3811         csum_show(res->port_id);
3812 }
3813
3814 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3815         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3816                                 csum, "csum");
3817 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3818         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3819                                 parse, "parse_tunnel");
3820 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3821         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3822                                 onoff, "on#off");
3823 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3824         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3825                                 port_id, UINT16);
3826
3827 cmdline_parse_inst_t cmd_csum_tunnel = {
3828         .f = cmd_csum_tunnel_parsed,
3829         .data = NULL,
3830         .help_str = "csum parse_tunnel on|off <port_id>: "
3831                 "Enable/Disable parsing of tunnels for csum engine",
3832         .tokens = {
3833                 (void *)&cmd_csum_tunnel_csum,
3834                 (void *)&cmd_csum_tunnel_parse,
3835                 (void *)&cmd_csum_tunnel_onoff,
3836                 (void *)&cmd_csum_tunnel_portid,
3837                 NULL,
3838         },
3839 };
3840
3841 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3842 struct cmd_tso_set_result {
3843         cmdline_fixed_string_t tso;
3844         cmdline_fixed_string_t mode;
3845         uint16_t tso_segsz;
3846         portid_t port_id;
3847 };
3848
3849 static void
3850 cmd_tso_set_parsed(void *parsed_result,
3851                        __attribute__((unused)) struct cmdline *cl,
3852                        __attribute__((unused)) void *data)
3853 {
3854         struct cmd_tso_set_result *res = parsed_result;
3855         struct rte_eth_dev_info dev_info;
3856
3857         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3858                 return;
3859         if (!port_is_stopped(res->port_id)) {
3860                 printf("Please stop port %d first\n", res->port_id);
3861                 return;
3862         }
3863
3864         if (!strcmp(res->mode, "set"))
3865                 ports[res->port_id].tso_segsz = res->tso_segsz;
3866
3867         rte_eth_dev_info_get(res->port_id, &dev_info);
3868         if ((ports[res->port_id].tso_segsz != 0) &&
3869                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3870                 printf("Error: TSO is not supported by port %d\n",
3871                        res->port_id);
3872                 return;
3873         }
3874
3875         if (ports[res->port_id].tso_segsz == 0) {
3876                 ports[res->port_id].dev_conf.txmode.offloads &=
3877                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3878                 printf("TSO for non-tunneled packets is disabled\n");
3879         } else {
3880                 ports[res->port_id].dev_conf.txmode.offloads |=
3881                                                 DEV_TX_OFFLOAD_TCP_TSO;
3882                 printf("TSO segment size for non-tunneled packets is %d\n",
3883                         ports[res->port_id].tso_segsz);
3884         }
3885
3886         /* display warnings if configuration is not supported by the NIC */
3887         rte_eth_dev_info_get(res->port_id, &dev_info);
3888         if ((ports[res->port_id].tso_segsz != 0) &&
3889                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3890                 printf("Warning: TSO enabled but not "
3891                         "supported by port %d\n", res->port_id);
3892         }
3893
3894         cmd_reconfig_device_queue(res->port_id, 1, 1);
3895 }
3896
3897 cmdline_parse_token_string_t cmd_tso_set_tso =
3898         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3899                                 tso, "tso");
3900 cmdline_parse_token_string_t cmd_tso_set_mode =
3901         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3902                                 mode, "set");
3903 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3904         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3905                                 tso_segsz, UINT16);
3906 cmdline_parse_token_num_t cmd_tso_set_portid =
3907         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3908                                 port_id, UINT16);
3909
3910 cmdline_parse_inst_t cmd_tso_set = {
3911         .f = cmd_tso_set_parsed,
3912         .data = NULL,
3913         .help_str = "tso set <tso_segsz> <port_id>: "
3914                 "Set TSO segment size of non-tunneled packets for csum engine "
3915                 "(0 to disable)",
3916         .tokens = {
3917                 (void *)&cmd_tso_set_tso,
3918                 (void *)&cmd_tso_set_mode,
3919                 (void *)&cmd_tso_set_tso_segsz,
3920                 (void *)&cmd_tso_set_portid,
3921                 NULL,
3922         },
3923 };
3924
3925 cmdline_parse_token_string_t cmd_tso_show_mode =
3926         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3927                                 mode, "show");
3928
3929
3930 cmdline_parse_inst_t cmd_tso_show = {
3931         .f = cmd_tso_set_parsed,
3932         .data = NULL,
3933         .help_str = "tso show <port_id>: "
3934                 "Show TSO segment size of non-tunneled packets for csum engine",
3935         .tokens = {
3936                 (void *)&cmd_tso_set_tso,
3937                 (void *)&cmd_tso_show_mode,
3938                 (void *)&cmd_tso_set_portid,
3939                 NULL,
3940         },
3941 };
3942
3943 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3944 struct cmd_tunnel_tso_set_result {
3945         cmdline_fixed_string_t tso;
3946         cmdline_fixed_string_t mode;
3947         uint16_t tso_segsz;
3948         portid_t port_id;
3949 };
3950
3951 static struct rte_eth_dev_info
3952 check_tunnel_tso_nic_support(portid_t port_id)
3953 {
3954         struct rte_eth_dev_info dev_info;
3955
3956         rte_eth_dev_info_get(port_id, &dev_info);
3957         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3958                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3959                        "not enabled for port %d\n", port_id);
3960         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3961                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3962                        "not enabled for port %d\n", port_id);
3963         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3964                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3965                        "not enabled for port %d\n", port_id);
3966         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3967                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3968                        "not enabled for port %d\n", port_id);
3969         return dev_info;
3970 }
3971
3972 static void
3973 cmd_tunnel_tso_set_parsed(void *parsed_result,
3974                           __attribute__((unused)) struct cmdline *cl,
3975                           __attribute__((unused)) void *data)
3976 {
3977         struct cmd_tunnel_tso_set_result *res = parsed_result;
3978         struct rte_eth_dev_info dev_info;
3979
3980         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3981                 return;
3982         if (!port_is_stopped(res->port_id)) {
3983                 printf("Please stop port %d first\n", res->port_id);
3984                 return;
3985         }
3986
3987         if (!strcmp(res->mode, "set"))
3988                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3989
3990         dev_info = check_tunnel_tso_nic_support(res->port_id);
3991         if (ports[res->port_id].tunnel_tso_segsz == 0) {
3992                 ports[res->port_id].dev_conf.txmode.offloads &=
3993                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3994                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
3995                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3996                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
3997                 printf("TSO for tunneled packets is disabled\n");
3998         } else {
3999                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4000                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4001                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4002                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4003
4004                 ports[res->port_id].dev_conf.txmode.offloads |=
4005                         (tso_offloads & dev_info.tx_offload_capa);
4006                 printf("TSO segment size for tunneled packets is %d\n",
4007                         ports[res->port_id].tunnel_tso_segsz);
4008
4009                 /* Below conditions are needed to make it work:
4010                  * (1) tunnel TSO is supported by the NIC;
4011                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4012                  * are recognized;
4013                  * (3) for tunneled pkts with outer L3 of IPv4,
4014                  * "csum set outer-ip" must be set to hw, because after tso,
4015                  * total_len of outer IP header is changed, and the checksum
4016                  * of outer IP header calculated by sw should be wrong; that
4017                  * is not necessary for IPv6 tunneled pkts because there's no
4018                  * checksum in IP header anymore.
4019                  */
4020
4021                 if (!ports[res->port_id].parse_tunnel)
4022                         printf("Warning: csum parse_tunnel must be set "
4023                                 "so that tunneled packets are recognized\n");
4024                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4025                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4026                         printf("Warning: csum set outer-ip must be set to hw "
4027                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4028         }
4029
4030         cmd_reconfig_device_queue(res->port_id, 1, 1);
4031 }
4032
4033 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4034         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4035                                 tso, "tunnel_tso");
4036 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4037         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4038                                 mode, "set");
4039 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4040         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4041                                 tso_segsz, UINT16);
4042 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4043         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4044                                 port_id, UINT16);
4045
4046 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4047         .f = cmd_tunnel_tso_set_parsed,
4048         .data = NULL,
4049         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4050                 "Set TSO segment size of tunneled packets for csum engine "
4051                 "(0 to disable)",
4052         .tokens = {
4053                 (void *)&cmd_tunnel_tso_set_tso,
4054                 (void *)&cmd_tunnel_tso_set_mode,
4055                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4056                 (void *)&cmd_tunnel_tso_set_portid,
4057                 NULL,
4058         },
4059 };
4060
4061 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4062         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4063                                 mode, "show");
4064
4065
4066 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4067         .f = cmd_tunnel_tso_set_parsed,
4068         .data = NULL,
4069         .help_str = "tunnel_tso show <port_id> "
4070                 "Show TSO segment size of tunneled packets for csum engine",
4071         .tokens = {
4072                 (void *)&cmd_tunnel_tso_set_tso,
4073                 (void *)&cmd_tunnel_tso_show_mode,
4074                 (void *)&cmd_tunnel_tso_set_portid,
4075                 NULL,
4076         },
4077 };
4078
4079 /* *** SET GRO FOR A PORT *** */
4080 struct cmd_gro_enable_result {
4081         cmdline_fixed_string_t cmd_set;
4082         cmdline_fixed_string_t cmd_port;
4083         cmdline_fixed_string_t cmd_keyword;
4084         cmdline_fixed_string_t cmd_onoff;
4085         portid_t cmd_pid;
4086 };
4087
4088 static void
4089 cmd_gro_enable_parsed(void *parsed_result,
4090                 __attribute__((unused)) struct cmdline *cl,
4091                 __attribute__((unused)) void *data)
4092 {
4093         struct cmd_gro_enable_result *res;
4094
4095         res = parsed_result;
4096         if (!strcmp(res->cmd_keyword, "gro"))
4097                 setup_gro(res->cmd_onoff, res->cmd_pid);
4098 }
4099
4100 cmdline_parse_token_string_t cmd_gro_enable_set =
4101         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4102                         cmd_set, "set");
4103 cmdline_parse_token_string_t cmd_gro_enable_port =
4104         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4105                         cmd_keyword, "port");
4106 cmdline_parse_token_num_t cmd_gro_enable_pid =
4107         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4108                         cmd_pid, UINT16);
4109 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4110         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4111                         cmd_keyword, "gro");
4112 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4113         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4114                         cmd_onoff, "on#off");
4115
4116 cmdline_parse_inst_t cmd_gro_enable = {
4117         .f = cmd_gro_enable_parsed,
4118         .data = NULL,
4119         .help_str = "set port <port_id> gro on|off",
4120         .tokens = {
4121                 (void *)&cmd_gro_enable_set,
4122                 (void *)&cmd_gro_enable_port,
4123                 (void *)&cmd_gro_enable_pid,
4124                 (void *)&cmd_gro_enable_keyword,
4125                 (void *)&cmd_gro_enable_onoff,
4126                 NULL,
4127         },
4128 };
4129
4130 /* *** DISPLAY GRO CONFIGURATION *** */
4131 struct cmd_gro_show_result {
4132         cmdline_fixed_string_t cmd_show;
4133         cmdline_fixed_string_t cmd_port;
4134         cmdline_fixed_string_t cmd_keyword;
4135         portid_t cmd_pid;
4136 };
4137
4138 static void
4139 cmd_gro_show_parsed(void *parsed_result,
4140                 __attribute__((unused)) struct cmdline *cl,
4141                 __attribute__((unused)) void *data)
4142 {
4143         struct cmd_gro_show_result *res;
4144
4145         res = parsed_result;
4146         if (!strcmp(res->cmd_keyword, "gro"))
4147                 show_gro(res->cmd_pid);
4148 }
4149
4150 cmdline_parse_token_string_t cmd_gro_show_show =
4151         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4152                         cmd_show, "show");
4153 cmdline_parse_token_string_t cmd_gro_show_port =
4154         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4155                         cmd_port, "port");
4156 cmdline_parse_token_num_t cmd_gro_show_pid =
4157         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4158                         cmd_pid, UINT16);
4159 cmdline_parse_token_string_t cmd_gro_show_keyword =
4160         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4161                         cmd_keyword, "gro");
4162
4163 cmdline_parse_inst_t cmd_gro_show = {
4164         .f = cmd_gro_show_parsed,
4165         .data = NULL,
4166         .help_str = "show port <port_id> gro",
4167         .tokens = {
4168                 (void *)&cmd_gro_show_show,
4169                 (void *)&cmd_gro_show_port,
4170                 (void *)&cmd_gro_show_pid,
4171                 (void *)&cmd_gro_show_keyword,
4172                 NULL,
4173         },
4174 };
4175
4176 /* *** SET FLUSH CYCLES FOR GRO *** */
4177 struct cmd_gro_flush_result {
4178         cmdline_fixed_string_t cmd_set;
4179         cmdline_fixed_string_t cmd_keyword;
4180         cmdline_fixed_string_t cmd_flush;
4181         uint8_t cmd_cycles;
4182 };
4183
4184 static void
4185 cmd_gro_flush_parsed(void *parsed_result,
4186                 __attribute__((unused)) struct cmdline *cl,
4187                 __attribute__((unused)) void *data)
4188 {
4189         struct cmd_gro_flush_result *res;
4190
4191         res = parsed_result;
4192         if ((!strcmp(res->cmd_keyword, "gro")) &&
4193                         (!strcmp(res->cmd_flush, "flush")))
4194                 setup_gro_flush_cycles(res->cmd_cycles);
4195 }
4196
4197 cmdline_parse_token_string_t cmd_gro_flush_set =
4198         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4199                         cmd_set, "set");
4200 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4201         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4202                         cmd_keyword, "gro");
4203 cmdline_parse_token_string_t cmd_gro_flush_flush =
4204         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4205                         cmd_flush, "flush");
4206 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4207         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4208                         cmd_cycles, UINT8);
4209
4210 cmdline_parse_inst_t cmd_gro_flush = {
4211         .f = cmd_gro_flush_parsed,
4212         .data = NULL,
4213         .help_str = "set gro flush <cycles>",
4214         .tokens = {
4215                 (void *)&cmd_gro_flush_set,
4216                 (void *)&cmd_gro_flush_keyword,
4217                 (void *)&cmd_gro_flush_flush,
4218                 (void *)&cmd_gro_flush_cycles,
4219                 NULL,
4220         },
4221 };
4222
4223 /* *** ENABLE/DISABLE GSO *** */
4224 struct cmd_gso_enable_result {
4225         cmdline_fixed_string_t cmd_set;
4226         cmdline_fixed_string_t cmd_port;
4227         cmdline_fixed_string_t cmd_keyword;
4228         cmdline_fixed_string_t cmd_mode;
4229         portid_t cmd_pid;
4230 };
4231
4232 static void
4233 cmd_gso_enable_parsed(void *parsed_result,
4234                 __attribute__((unused)) struct cmdline *cl,
4235                 __attribute__((unused)) void *data)
4236 {
4237         struct cmd_gso_enable_result *res;
4238
4239         res = parsed_result;
4240         if (!strcmp(res->cmd_keyword, "gso"))
4241                 setup_gso(res->cmd_mode, res->cmd_pid);
4242 }
4243
4244 cmdline_parse_token_string_t cmd_gso_enable_set =
4245         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4246                         cmd_set, "set");
4247 cmdline_parse_token_string_t cmd_gso_enable_port =
4248         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4249                         cmd_port, "port");
4250 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4251         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4252                         cmd_keyword, "gso");
4253 cmdline_parse_token_string_t cmd_gso_enable_mode =
4254         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4255                         cmd_mode, "on#off");
4256 cmdline_parse_token_num_t cmd_gso_enable_pid =
4257         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4258                         cmd_pid, UINT16);
4259
4260 cmdline_parse_inst_t cmd_gso_enable = {
4261         .f = cmd_gso_enable_parsed,
4262         .data = NULL,
4263         .help_str = "set port <port_id> gso on|off",
4264         .tokens = {
4265                 (void *)&cmd_gso_enable_set,
4266                 (void *)&cmd_gso_enable_port,
4267                 (void *)&cmd_gso_enable_pid,
4268                 (void *)&cmd_gso_enable_keyword,
4269                 (void *)&cmd_gso_enable_mode,
4270                 NULL,
4271         },
4272 };
4273
4274 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4275 struct cmd_gso_size_result {
4276         cmdline_fixed_string_t cmd_set;
4277         cmdline_fixed_string_t cmd_keyword;
4278         cmdline_fixed_string_t cmd_segsz;
4279         uint16_t cmd_size;
4280 };
4281
4282 static void
4283 cmd_gso_size_parsed(void *parsed_result,
4284                        __attribute__((unused)) struct cmdline *cl,
4285                        __attribute__((unused)) void *data)
4286 {
4287         struct cmd_gso_size_result *res = parsed_result;
4288
4289         if (test_done == 0) {
4290                 printf("Before setting GSO segsz, please first"
4291                                 " stop fowarding\n");
4292                 return;
4293         }
4294
4295         if (!strcmp(res->cmd_keyword, "gso") &&
4296                         !strcmp(res->cmd_segsz, "segsz")) {
4297                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4298                         printf("gso_size should be larger than %zu."
4299                                         " Please input a legal value\n",
4300                                         RTE_GSO_SEG_SIZE_MIN);
4301                 else
4302                         gso_max_segment_size = res->cmd_size;
4303         }
4304 }
4305
4306 cmdline_parse_token_string_t cmd_gso_size_set =
4307         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4308                                 cmd_set, "set");
4309 cmdline_parse_token_string_t cmd_gso_size_keyword =
4310         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4311                                 cmd_keyword, "gso");
4312 cmdline_parse_token_string_t cmd_gso_size_segsz =
4313         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4314                                 cmd_segsz, "segsz");
4315 cmdline_parse_token_num_t cmd_gso_size_size =
4316         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4317                                 cmd_size, UINT16);
4318
4319 cmdline_parse_inst_t cmd_gso_size = {
4320         .f = cmd_gso_size_parsed,
4321         .data = NULL,
4322         .help_str = "set gso segsz <length>",
4323         .tokens = {
4324                 (void *)&cmd_gso_size_set,
4325                 (void *)&cmd_gso_size_keyword,
4326                 (void *)&cmd_gso_size_segsz,
4327                 (void *)&cmd_gso_size_size,
4328                 NULL,
4329         },
4330 };
4331
4332 /* *** SHOW GSO CONFIGURATION *** */
4333 struct cmd_gso_show_result {
4334         cmdline_fixed_string_t cmd_show;
4335         cmdline_fixed_string_t cmd_port;
4336         cmdline_fixed_string_t cmd_keyword;
4337         portid_t cmd_pid;
4338 };
4339
4340 static void
4341 cmd_gso_show_parsed(void *parsed_result,
4342                        __attribute__((unused)) struct cmdline *cl,
4343                        __attribute__((unused)) void *data)
4344 {
4345         struct cmd_gso_show_result *res = parsed_result;
4346
4347         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4348                 printf("invalid port id %u\n", res->cmd_pid);
4349                 return;
4350         }
4351         if (!strcmp(res->cmd_keyword, "gso")) {
4352                 if (gso_ports[res->cmd_pid].enable) {
4353                         printf("Max GSO'd packet size: %uB\n"
4354                                         "Supported GSO types: TCP/IPv4, "
4355                                         "VxLAN with inner TCP/IPv4 packet, "
4356                                         "GRE with inner TCP/IPv4  packet\n",
4357                                         gso_max_segment_size);
4358                 } else
4359                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4360         }
4361 }
4362
4363 cmdline_parse_token_string_t cmd_gso_show_show =
4364 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4365                 cmd_show, "show");
4366 cmdline_parse_token_string_t cmd_gso_show_port =
4367 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4368                 cmd_port, "port");
4369 cmdline_parse_token_string_t cmd_gso_show_keyword =
4370         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4371                                 cmd_keyword, "gso");
4372 cmdline_parse_token_num_t cmd_gso_show_pid =
4373         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4374                                 cmd_pid, UINT16);
4375
4376 cmdline_parse_inst_t cmd_gso_show = {
4377         .f = cmd_gso_show_parsed,
4378         .data = NULL,
4379         .help_str = "show port <port_id> gso",
4380         .tokens = {
4381                 (void *)&cmd_gso_show_show,
4382                 (void *)&cmd_gso_show_port,
4383                 (void *)&cmd_gso_show_pid,
4384                 (void *)&cmd_gso_show_keyword,
4385                 NULL,
4386         },
4387 };
4388
4389 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4390 struct cmd_set_flush_rx {
4391         cmdline_fixed_string_t set;
4392         cmdline_fixed_string_t flush_rx;
4393         cmdline_fixed_string_t mode;
4394 };
4395
4396 static void
4397 cmd_set_flush_rx_parsed(void *parsed_result,
4398                 __attribute__((unused)) struct cmdline *cl,
4399                 __attribute__((unused)) void *data)
4400 {
4401         struct cmd_set_flush_rx *res = parsed_result;
4402         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4403 }
4404
4405 cmdline_parse_token_string_t cmd_setflushrx_set =
4406         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4407                         set, "set");
4408 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4409         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4410                         flush_rx, "flush_rx");
4411 cmdline_parse_token_string_t cmd_setflushrx_mode =
4412         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4413                         mode, "on#off");
4414
4415
4416 cmdline_parse_inst_t cmd_set_flush_rx = {
4417         .f = cmd_set_flush_rx_parsed,
4418         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4419         .data = NULL,
4420         .tokens = {
4421                 (void *)&cmd_setflushrx_set,
4422                 (void *)&cmd_setflushrx_flush_rx,
4423                 (void *)&cmd_setflushrx_mode,
4424                 NULL,
4425         },
4426 };
4427
4428 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4429 struct cmd_set_link_check {
4430         cmdline_fixed_string_t set;
4431         cmdline_fixed_string_t link_check;
4432         cmdline_fixed_string_t mode;
4433 };
4434
4435 static void
4436 cmd_set_link_check_parsed(void *parsed_result,
4437                 __attribute__((unused)) struct cmdline *cl,
4438                 __attribute__((unused)) void *data)
4439 {
4440         struct cmd_set_link_check *res = parsed_result;
4441         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4442 }
4443
4444 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4445         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4446                         set, "set");
4447 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4448         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4449                         link_check, "link_check");
4450 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4451         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4452                         mode, "on#off");
4453
4454
4455 cmdline_parse_inst_t cmd_set_link_check = {
4456         .f = cmd_set_link_check_parsed,
4457         .help_str = "set link_check on|off: Enable/Disable link status check "
4458                     "when starting/stopping a port",
4459         .data = NULL,
4460         .tokens = {
4461                 (void *)&cmd_setlinkcheck_set,
4462                 (void *)&cmd_setlinkcheck_link_check,
4463                 (void *)&cmd_setlinkcheck_mode,
4464                 NULL,
4465         },
4466 };
4467
4468 /* *** SET NIC BYPASS MODE *** */
4469 struct cmd_set_bypass_mode_result {
4470         cmdline_fixed_string_t set;
4471         cmdline_fixed_string_t bypass;
4472         cmdline_fixed_string_t mode;
4473         cmdline_fixed_string_t value;
4474         portid_t port_id;
4475 };
4476
4477 static void
4478 cmd_set_bypass_mode_parsed(void *parsed_result,
4479                 __attribute__((unused)) struct cmdline *cl,
4480                 __attribute__((unused)) void *data)
4481 {
4482         struct cmd_set_bypass_mode_result *res = parsed_result;
4483         portid_t port_id = res->port_id;
4484         int32_t rc = -EINVAL;
4485
4486 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4487         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4488
4489         if (!strcmp(res->value, "bypass"))
4490                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4491         else if (!strcmp(res->value, "isolate"))
4492                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4493         else
4494                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4495
4496         /* Set the bypass mode for the relevant port. */
4497         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4498 #endif
4499         if (rc != 0)
4500                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4501 }
4502
4503 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4504         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4505                         set, "set");
4506 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4507         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4508                         bypass, "bypass");
4509 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4510         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4511                         mode, "mode");
4512 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4513         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4514                         value, "normal#bypass#isolate");
4515 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4516         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4517                                 port_id, UINT16);
4518
4519 cmdline_parse_inst_t cmd_set_bypass_mode = {
4520         .f = cmd_set_bypass_mode_parsed,
4521         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4522                     "Set the NIC bypass mode for port_id",
4523         .data = NULL,
4524         .tokens = {
4525                 (void *)&cmd_setbypass_mode_set,
4526                 (void *)&cmd_setbypass_mode_bypass,
4527                 (void *)&cmd_setbypass_mode_mode,
4528                 (void *)&cmd_setbypass_mode_value,
4529                 (void *)&cmd_setbypass_mode_port,
4530                 NULL,
4531         },
4532 };
4533
4534 /* *** SET NIC BYPASS EVENT *** */
4535 struct cmd_set_bypass_event_result {
4536         cmdline_fixed_string_t set;
4537         cmdline_fixed_string_t bypass;
4538         cmdline_fixed_string_t event;
4539         cmdline_fixed_string_t event_value;
4540         cmdline_fixed_string_t mode;
4541         cmdline_fixed_string_t mode_value;
4542         portid_t port_id;
4543 };
4544
4545 static void
4546 cmd_set_bypass_event_parsed(void *parsed_result,
4547                 __attribute__((unused)) struct cmdline *cl,
4548                 __attribute__((unused)) void *data)
4549 {
4550         int32_t rc = -EINVAL;
4551         struct cmd_set_bypass_event_result *res = parsed_result;
4552         portid_t port_id = res->port_id;
4553
4554 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4555         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4556         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4557
4558         if (!strcmp(res->event_value, "timeout"))
4559                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4560         else if (!strcmp(res->event_value, "os_on"))
4561                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4562         else if (!strcmp(res->event_value, "os_off"))
4563                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4564         else if (!strcmp(res->event_value, "power_on"))
4565                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4566         else if (!strcmp(res->event_value, "power_off"))
4567                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4568         else
4569                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4570
4571         if (!strcmp(res->mode_value, "bypass"))
4572                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4573         else if (!strcmp(res->mode_value, "isolate"))
4574                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4575         else
4576                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4577
4578         /* Set the watchdog timeout. */
4579         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4580
4581                 rc = -EINVAL;
4582                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4583                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4584                                                            bypass_timeout);
4585                 }
4586                 if (rc != 0) {
4587                         printf("Failed to set timeout value %u "
4588                         "for port %d, errto code: %d.\n",
4589                         bypass_timeout, port_id, rc);
4590                 }
4591         }
4592
4593         /* Set the bypass event to transition to bypass mode. */
4594         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4595                                               bypass_mode);
4596 #endif
4597
4598         if (rc != 0)
4599                 printf("\t Failed to set bypass event for port = %d.\n",
4600                        port_id);
4601 }
4602
4603 cmdline_parse_token_string_t cmd_setbypass_event_set =
4604         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4605                         set, "set");
4606 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4607         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4608                         bypass, "bypass");
4609 cmdline_parse_token_string_t cmd_setbypass_event_event =
4610         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4611                         event, "event");
4612 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4613         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4614                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4615 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4616         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4617                         mode, "mode");
4618 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4619         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4620                         mode_value, "normal#bypass#isolate");
4621 cmdline_parse_token_num_t cmd_setbypass_event_port =
4622         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4623                                 port_id, UINT16);
4624
4625 cmdline_parse_inst_t cmd_set_bypass_event = {
4626         .f = cmd_set_bypass_event_parsed,
4627         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4628                 "power_off mode normal|bypass|isolate <port_id>: "
4629                 "Set the NIC bypass event mode for port_id",
4630         .data = NULL,
4631         .tokens = {
4632                 (void *)&cmd_setbypass_event_set,
4633                 (void *)&cmd_setbypass_event_bypass,
4634                 (void *)&cmd_setbypass_event_event,
4635                 (void *)&cmd_setbypass_event_event_value,
4636                 (void *)&cmd_setbypass_event_mode,
4637                 (void *)&cmd_setbypass_event_mode_value,
4638                 (void *)&cmd_setbypass_event_port,
4639                 NULL,
4640         },
4641 };
4642
4643
4644 /* *** SET NIC BYPASS TIMEOUT *** */
4645 struct cmd_set_bypass_timeout_result {
4646         cmdline_fixed_string_t set;
4647         cmdline_fixed_string_t bypass;
4648         cmdline_fixed_string_t timeout;
4649         cmdline_fixed_string_t value;
4650 };
4651
4652 static void
4653 cmd_set_bypass_timeout_parsed(void *parsed_result,
4654                 __attribute__((unused)) struct cmdline *cl,
4655                 __attribute__((unused)) void *data)
4656 {
4657         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4658
4659 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4660         if (!strcmp(res->value, "1.5"))
4661                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4662         else if (!strcmp(res->value, "2"))
4663                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4664         else if (!strcmp(res->value, "3"))
4665                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4666         else if (!strcmp(res->value, "4"))
4667                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4668         else if (!strcmp(res->value, "8"))
4669                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4670         else if (!strcmp(res->value, "16"))
4671                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4672         else if (!strcmp(res->value, "32"))
4673                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4674         else
4675                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4676 #endif
4677 }
4678
4679 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4680         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4681                         set, "set");
4682 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4683         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4684                         bypass, "bypass");
4685 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4686         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4687                         timeout, "timeout");
4688 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4689         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4690                         value, "0#1.5#2#3#4#8#16#32");
4691
4692 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4693         .f = cmd_set_bypass_timeout_parsed,
4694         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4695                 "Set the NIC bypass watchdog timeout in seconds",
4696         .data = NULL,
4697         .tokens = {
4698                 (void *)&cmd_setbypass_timeout_set,
4699                 (void *)&cmd_setbypass_timeout_bypass,
4700                 (void *)&cmd_setbypass_timeout_timeout,
4701                 (void *)&cmd_setbypass_timeout_value,
4702                 NULL,
4703         },
4704 };
4705
4706 /* *** SHOW NIC BYPASS MODE *** */
4707 struct cmd_show_bypass_config_result {
4708         cmdline_fixed_string_t show;
4709         cmdline_fixed_string_t bypass;
4710         cmdline_fixed_string_t config;
4711         portid_t port_id;
4712 };
4713
4714 static void
4715 cmd_show_bypass_config_parsed(void *parsed_result,
4716                 __attribute__((unused)) struct cmdline *cl,
4717                 __attribute__((unused)) void *data)
4718 {
4719         struct cmd_show_bypass_config_result *res = parsed_result;
4720         portid_t port_id = res->port_id;
4721         int rc = -EINVAL;
4722 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4723         uint32_t event_mode;
4724         uint32_t bypass_mode;
4725         uint32_t timeout = bypass_timeout;
4726         int i;
4727
4728         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4729                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4730         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4731                 {"UNKNOWN", "normal", "bypass", "isolate"};
4732         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4733                 "NONE",
4734                 "OS/board on",
4735                 "power supply on",
4736                 "OS/board off",
4737                 "power supply off",
4738                 "timeout"};
4739         int num_events = (sizeof events) / (sizeof events[0]);
4740
4741         /* Display the bypass mode.*/
4742         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4743                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4744                 return;
4745         }
4746         else {
4747                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4748                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4749
4750                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4751         }
4752
4753         /* Display the bypass timeout.*/
4754         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4755                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4756
4757         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4758
4759         /* Display the bypass events and associated modes. */
4760         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4761
4762                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4763                         printf("\tFailed to get bypass mode for event = %s\n",
4764                                 events[i]);
4765                 } else {
4766                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4767                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4768
4769                         printf("\tbypass event: %-16s = %s\n", events[i],
4770                                 modes[event_mode]);
4771                 }
4772         }
4773 #endif
4774         if (rc != 0)
4775                 printf("\tFailed to get bypass configuration for port = %d\n",
4776                        port_id);
4777 }
4778
4779 cmdline_parse_token_string_t cmd_showbypass_config_show =
4780         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4781                         show, "show");
4782 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4783         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4784                         bypass, "bypass");
4785 cmdline_parse_token_string_t cmd_showbypass_config_config =
4786         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4787                         config, "config");
4788 cmdline_parse_token_num_t cmd_showbypass_config_port =
4789         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4790                                 port_id, UINT16);
4791
4792 cmdline_parse_inst_t cmd_show_bypass_config = {
4793         .f = cmd_show_bypass_config_parsed,
4794         .help_str = "show bypass config <port_id>: "
4795                     "Show the NIC bypass config for port_id",
4796         .data = NULL,
4797         .tokens = {
4798                 (void *)&cmd_showbypass_config_show,
4799                 (void *)&cmd_showbypass_config_bypass,
4800                 (void *)&cmd_showbypass_config_config,
4801                 (void *)&cmd_showbypass_config_port,
4802                 NULL,
4803         },
4804 };
4805
4806 #ifdef RTE_LIBRTE_PMD_BOND
4807 /* *** SET BONDING MODE *** */
4808 struct cmd_set_bonding_mode_result {
4809         cmdline_fixed_string_t set;
4810         cmdline_fixed_string_t bonding;
4811         cmdline_fixed_string_t mode;
4812         uint8_t value;
4813         portid_t port_id;
4814 };
4815
4816 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4817                 __attribute__((unused))  struct cmdline *cl,
4818                 __attribute__((unused)) void *data)
4819 {
4820         struct cmd_set_bonding_mode_result *res = parsed_result;
4821         portid_t port_id = res->port_id;
4822
4823         /* Set the bonding mode for the relevant port. */
4824         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4825                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4826 }
4827
4828 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4829 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4830                 set, "set");
4831 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4832 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4833                 bonding, "bonding");
4834 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4835 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4836                 mode, "mode");
4837 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4838 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4839                 value, UINT8);
4840 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4841 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4842                 port_id, UINT16);
4843
4844 cmdline_parse_inst_t cmd_set_bonding_mode = {
4845                 .f = cmd_set_bonding_mode_parsed,
4846                 .help_str = "set bonding mode <mode_value> <port_id>: "
4847                         "Set the bonding mode for port_id",
4848                 .data = NULL,
4849                 .tokens = {
4850                                 (void *) &cmd_setbonding_mode_set,
4851                                 (void *) &cmd_setbonding_mode_bonding,
4852                                 (void *) &cmd_setbonding_mode_mode,
4853                                 (void *) &cmd_setbonding_mode_value,
4854                                 (void *) &cmd_setbonding_mode_port,
4855                                 NULL
4856                 }
4857 };
4858
4859 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4860 struct cmd_set_bonding_lacp_dedicated_queues_result {
4861         cmdline_fixed_string_t set;
4862         cmdline_fixed_string_t bonding;
4863         cmdline_fixed_string_t lacp;
4864         cmdline_fixed_string_t dedicated_queues;
4865         portid_t port_id;
4866         cmdline_fixed_string_t mode;
4867 };
4868
4869 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4870                 __attribute__((unused))  struct cmdline *cl,
4871                 __attribute__((unused)) void *data)
4872 {
4873         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4874         portid_t port_id = res->port_id;
4875         struct rte_port *port;
4876
4877         port = &ports[port_id];
4878
4879         /** Check if the port is not started **/
4880         if (port->port_status != RTE_PORT_STOPPED) {
4881                 printf("Please stop port %d first\n", port_id);
4882                 return;
4883         }
4884
4885         if (!strcmp(res->mode, "enable")) {
4886                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4887                         printf("Dedicate queues for LACP control packets"
4888                                         " enabled\n");
4889                 else
4890                         printf("Enabling dedicate queues for LACP control "
4891                                         "packets on port %d failed\n", port_id);
4892         } else if (!strcmp(res->mode, "disable")) {
4893                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4894                         printf("Dedicated queues for LACP control packets "
4895                                         "disabled\n");
4896                 else
4897                         printf("Disabling dedicated queues for LACP control "
4898                                         "traffic on port %d failed\n", port_id);
4899         }
4900 }
4901
4902 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4903 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4904                 set, "set");
4905 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4906 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4907                 bonding, "bonding");
4908 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4910                 lacp, "lacp");
4911 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4912 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4913                 dedicated_queues, "dedicated_queues");
4914 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4915 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4916                 port_id, UINT16);
4917 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4918 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4919                 mode, "enable#disable");
4920
4921 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4922                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4923                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4924                         "enable|disable: "
4925                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4926                 .data = NULL,
4927                 .tokens = {
4928                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4929                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4930                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4931                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4932                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4933                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4934                         NULL
4935                 }
4936 };
4937
4938 /* *** SET BALANCE XMIT POLICY *** */
4939 struct cmd_set_bonding_balance_xmit_policy_result {
4940         cmdline_fixed_string_t set;
4941         cmdline_fixed_string_t bonding;
4942         cmdline_fixed_string_t balance_xmit_policy;
4943         portid_t port_id;
4944         cmdline_fixed_string_t policy;
4945 };
4946
4947 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4948                 __attribute__((unused))  struct cmdline *cl,
4949                 __attribute__((unused)) void *data)
4950 {
4951         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4952         portid_t port_id = res->port_id;
4953         uint8_t policy;
4954
4955         if (!strcmp(res->policy, "l2")) {
4956                 policy = BALANCE_XMIT_POLICY_LAYER2;
4957         } else if (!strcmp(res->policy, "l23")) {
4958                 policy = BALANCE_XMIT_POLICY_LAYER23;
4959         } else if (!strcmp(res->policy, "l34")) {
4960                 policy = BALANCE_XMIT_POLICY_LAYER34;
4961         } else {
4962                 printf("\t Invalid xmit policy selection");
4963                 return;
4964         }
4965
4966         /* Set the bonding mode for the relevant port. */
4967         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4968                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4969                                 port_id);
4970         }
4971 }
4972
4973 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4974 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4975                 set, "set");
4976 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4977 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4978                 bonding, "bonding");
4979 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4980 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4981                 balance_xmit_policy, "balance_xmit_policy");
4982 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4983 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4984                 port_id, UINT16);
4985 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4986 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4987                 policy, "l2#l23#l34");
4988
4989 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4990                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4991                 .help_str = "set bonding balance_xmit_policy <port_id> "
4992                         "l2|l23|l34: "
4993                         "Set the bonding balance_xmit_policy for port_id",
4994                 .data = NULL,
4995                 .tokens = {
4996                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4997                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4998                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4999                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5000                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5001                                 NULL
5002                 }
5003 };
5004
5005 /* *** SHOW NIC BONDING CONFIGURATION *** */
5006 struct cmd_show_bonding_config_result {
5007         cmdline_fixed_string_t show;
5008         cmdline_fixed_string_t bonding;
5009         cmdline_fixed_string_t config;
5010         portid_t port_id;
5011 };
5012
5013 static void cmd_show_bonding_config_parsed(void *parsed_result,
5014                 __attribute__((unused))  struct cmdline *cl,
5015                 __attribute__((unused)) void *data)
5016 {
5017         struct cmd_show_bonding_config_result *res = parsed_result;
5018         int bonding_mode, agg_mode;
5019         portid_t slaves[RTE_MAX_ETHPORTS];
5020         int num_slaves, num_active_slaves;
5021         int primary_id;
5022         int i;
5023         portid_t port_id = res->port_id;
5024
5025         /* Display the bonding mode.*/
5026         bonding_mode = rte_eth_bond_mode_get(port_id);
5027         if (bonding_mode < 0) {
5028                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5029                 return;
5030         } else
5031                 printf("\tBonding mode: %d\n", bonding_mode);
5032
5033         if (bonding_mode == BONDING_MODE_BALANCE) {
5034                 int balance_xmit_policy;
5035
5036                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5037                 if (balance_xmit_policy < 0) {
5038                         printf("\tFailed to get balance xmit policy for port = %d\n",
5039                                         port_id);
5040                         return;
5041                 } else {
5042                         printf("\tBalance Xmit Policy: ");
5043
5044                         switch (balance_xmit_policy) {
5045                         case BALANCE_XMIT_POLICY_LAYER2:
5046                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5047                                 break;
5048                         case BALANCE_XMIT_POLICY_LAYER23:
5049                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5050                                 break;
5051                         case BALANCE_XMIT_POLICY_LAYER34:
5052                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5053                                 break;
5054                         }
5055                         printf("\n");
5056                 }
5057         }
5058
5059         if (bonding_mode == BONDING_MODE_8023AD) {
5060                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5061                 printf("\tIEEE802.3AD Aggregator Mode: ");
5062                 switch (agg_mode) {
5063                 case AGG_BANDWIDTH:
5064                         printf("bandwidth");
5065                         break;
5066                 case AGG_STABLE:
5067                         printf("stable");
5068                         break;
5069                 case AGG_COUNT:
5070                         printf("count");
5071                         break;
5072                 }
5073                 printf("\n");
5074         }
5075
5076         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5077
5078         if (num_slaves < 0) {
5079                 printf("\tFailed to get slave list for port = %d\n", port_id);
5080                 return;
5081         }
5082         if (num_slaves > 0) {
5083                 printf("\tSlaves (%d): [", num_slaves);
5084                 for (i = 0; i < num_slaves - 1; i++)
5085                         printf("%d ", slaves[i]);
5086
5087                 printf("%d]\n", slaves[num_slaves - 1]);
5088         } else {
5089                 printf("\tSlaves: []\n");
5090
5091         }
5092
5093         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5094                         RTE_MAX_ETHPORTS);
5095
5096         if (num_active_slaves < 0) {
5097                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5098                 return;
5099         }
5100         if (num_active_slaves > 0) {
5101                 printf("\tActive Slaves (%d): [", num_active_slaves);
5102                 for (i = 0; i < num_active_slaves - 1; i++)
5103                         printf("%d ", slaves[i]);
5104
5105                 printf("%d]\n", slaves[num_active_slaves - 1]);
5106
5107         } else {
5108                 printf("\tActive Slaves: []\n");
5109
5110         }
5111
5112         primary_id = rte_eth_bond_primary_get(port_id);
5113         if (primary_id < 0) {
5114                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5115                 return;
5116         } else
5117                 printf("\tPrimary: [%d]\n", primary_id);
5118
5119 }
5120
5121 cmdline_parse_token_string_t cmd_showbonding_config_show =
5122 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5123                 show, "show");
5124 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5125 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5126                 bonding, "bonding");
5127 cmdline_parse_token_string_t cmd_showbonding_config_config =
5128 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5129                 config, "config");
5130 cmdline_parse_token_num_t cmd_showbonding_config_port =
5131 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5132                 port_id, UINT16);
5133
5134 cmdline_parse_inst_t cmd_show_bonding_config = {
5135                 .f = cmd_show_bonding_config_parsed,
5136                 .help_str = "show bonding config <port_id>: "
5137                         "Show the bonding config for port_id",
5138                 .data = NULL,
5139                 .tokens = {
5140                                 (void *)&cmd_showbonding_config_show,
5141                                 (void *)&cmd_showbonding_config_bonding,
5142                                 (void *)&cmd_showbonding_config_config,
5143                                 (void *)&cmd_showbonding_config_port,
5144                                 NULL
5145                 }
5146 };
5147
5148 /* *** SET BONDING PRIMARY *** */
5149 struct cmd_set_bonding_primary_result {
5150         cmdline_fixed_string_t set;
5151         cmdline_fixed_string_t bonding;
5152         cmdline_fixed_string_t primary;
5153         portid_t slave_id;
5154         portid_t port_id;
5155 };
5156
5157 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5158                 __attribute__((unused))  struct cmdline *cl,
5159                 __attribute__((unused)) void *data)
5160 {
5161         struct cmd_set_bonding_primary_result *res = parsed_result;
5162         portid_t master_port_id = res->port_id;
5163         portid_t slave_port_id = res->slave_id;
5164
5165         /* Set the primary slave for a bonded device. */
5166         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5167                 printf("\t Failed to set primary slave for port = %d.\n",
5168                                 master_port_id);
5169                 return;
5170         }
5171         init_port_config();
5172 }
5173
5174 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5175 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5176                 set, "set");
5177 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5178 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5179                 bonding, "bonding");
5180 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5181 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5182                 primary, "primary");
5183 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5184 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5185                 slave_id, UINT16);
5186 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5187 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5188                 port_id, UINT16);
5189
5190 cmdline_parse_inst_t cmd_set_bonding_primary = {
5191                 .f = cmd_set_bonding_primary_parsed,
5192                 .help_str = "set bonding primary <slave_id> <port_id>: "
5193                         "Set the primary slave for port_id",
5194                 .data = NULL,
5195                 .tokens = {
5196                                 (void *)&cmd_setbonding_primary_set,
5197                                 (void *)&cmd_setbonding_primary_bonding,
5198                                 (void *)&cmd_setbonding_primary_primary,
5199                                 (void *)&cmd_setbonding_primary_slave,
5200                                 (void *)&cmd_setbonding_primary_port,
5201                                 NULL
5202                 }
5203 };
5204
5205 /* *** ADD SLAVE *** */
5206 struct cmd_add_bonding_slave_result {
5207         cmdline_fixed_string_t add;
5208         cmdline_fixed_string_t bonding;
5209         cmdline_fixed_string_t slave;
5210         portid_t slave_id;
5211         portid_t port_id;
5212 };
5213
5214 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5215                 __attribute__((unused))  struct cmdline *cl,
5216                 __attribute__((unused)) void *data)
5217 {
5218         struct cmd_add_bonding_slave_result *res = parsed_result;
5219         portid_t master_port_id = res->port_id;
5220         portid_t slave_port_id = res->slave_id;
5221
5222         /* add the slave for a bonded device. */
5223         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5224                 printf("\t Failed to add slave %d to master port = %d.\n",
5225                                 slave_port_id, master_port_id);
5226                 return;
5227         }
5228         init_port_config();
5229         set_port_slave_flag(slave_port_id);
5230 }
5231
5232 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5233 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5234                 add, "add");
5235 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5236 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5237                 bonding, "bonding");
5238 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5239 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5240                 slave, "slave");
5241 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5242 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5243                 slave_id, UINT16);
5244 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5245 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5246                 port_id, UINT16);
5247
5248 cmdline_parse_inst_t cmd_add_bonding_slave = {
5249                 .f = cmd_add_bonding_slave_parsed,
5250                 .help_str = "add bonding slave <slave_id> <port_id>: "
5251                         "Add a slave device to a bonded device",
5252                 .data = NULL,
5253                 .tokens = {
5254                                 (void *)&cmd_addbonding_slave_add,
5255                                 (void *)&cmd_addbonding_slave_bonding,
5256                                 (void *)&cmd_addbonding_slave_slave,
5257                                 (void *)&cmd_addbonding_slave_slaveid,
5258                                 (void *)&cmd_addbonding_slave_port,
5259                                 NULL
5260                 }
5261 };
5262
5263 /* *** REMOVE SLAVE *** */
5264 struct cmd_remove_bonding_slave_result {
5265         cmdline_fixed_string_t remove;
5266         cmdline_fixed_string_t bonding;
5267         cmdline_fixed_string_t slave;
5268         portid_t slave_id;
5269         portid_t port_id;
5270 };
5271
5272 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5273                 __attribute__((unused))  struct cmdline *cl,
5274                 __attribute__((unused)) void *data)
5275 {
5276         struct cmd_remove_bonding_slave_result *res = parsed_result;
5277         portid_t master_port_id = res->port_id;
5278         portid_t slave_port_id = res->slave_id;
5279
5280         /* remove the slave from a bonded device. */
5281         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5282                 printf("\t Failed to remove slave %d from master port = %d.\n",
5283                                 slave_port_id, master_port_id);
5284                 return;
5285         }
5286         init_port_config();
5287         clear_port_slave_flag(slave_port_id);
5288 }
5289
5290 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5291                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5292                                 remove, "remove");
5293 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5294                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5295                                 bonding, "bonding");
5296 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5297                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5298                                 slave, "slave");
5299 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5300                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5301                                 slave_id, UINT16);
5302 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5303                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5304                                 port_id, UINT16);
5305
5306 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5307                 .f = cmd_remove_bonding_slave_parsed,
5308                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5309                         "Remove a slave device from a bonded device",
5310                 .data = NULL,
5311                 .tokens = {
5312                                 (void *)&cmd_removebonding_slave_remove,
5313                                 (void *)&cmd_removebonding_slave_bonding,
5314                                 (void *)&cmd_removebonding_slave_slave,
5315                                 (void *)&cmd_removebonding_slave_slaveid,
5316                                 (void *)&cmd_removebonding_slave_port,
5317                                 NULL
5318                 }
5319 };
5320
5321 /* *** CREATE BONDED DEVICE *** */
5322 struct cmd_create_bonded_device_result {
5323         cmdline_fixed_string_t create;
5324         cmdline_fixed_string_t bonded;
5325         cmdline_fixed_string_t device;
5326         uint8_t mode;
5327         uint8_t socket;
5328 };
5329
5330 static int bond_dev_num = 0;
5331
5332 static void cmd_create_bonded_device_parsed(void *parsed_result,
5333                 __attribute__((unused))  struct cmdline *cl,
5334                 __attribute__((unused)) void *data)
5335 {
5336         struct cmd_create_bonded_device_result *res = parsed_result;
5337         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5338         int port_id;
5339
5340         if (test_done == 0) {
5341                 printf("Please stop forwarding first\n");
5342                 return;
5343         }
5344
5345         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5346                         bond_dev_num++);
5347
5348         /* Create a new bonded device. */
5349         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5350         if (port_id < 0) {
5351                 printf("\t Failed to create bonded device.\n");
5352                 return;
5353         } else {
5354                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5355                                 port_id);
5356
5357                 /* Update number of ports */
5358                 nb_ports = rte_eth_dev_count();
5359                 reconfig(port_id, res->socket);
5360                 rte_eth_promiscuous_enable(port_id);
5361         }
5362
5363 }
5364
5365 cmdline_parse_token_string_t cmd_createbonded_device_create =
5366                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5367                                 create, "create");
5368 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5369                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5370                                 bonded, "bonded");
5371 cmdline_parse_token_string_t cmd_createbonded_device_device =
5372                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5373                                 device, "device");
5374 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5375                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5376                                 mode, UINT8);
5377 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5378                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5379                                 socket, UINT8);
5380
5381 cmdline_parse_inst_t cmd_create_bonded_device = {
5382                 .f = cmd_create_bonded_device_parsed,
5383                 .help_str = "create bonded device <mode> <socket>: "
5384                         "Create a new bonded device with specific bonding mode and socket",
5385                 .data = NULL,
5386                 .tokens = {
5387                                 (void *)&cmd_createbonded_device_create,
5388                                 (void *)&cmd_createbonded_device_bonded,
5389                                 (void *)&cmd_createbonded_device_device,
5390                                 (void *)&cmd_createbonded_device_mode,
5391                                 (void *)&cmd_createbonded_device_socket,
5392                                 NULL
5393                 }
5394 };
5395
5396 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5397 struct cmd_set_bond_mac_addr_result {
5398         cmdline_fixed_string_t set;
5399         cmdline_fixed_string_t bonding;
5400         cmdline_fixed_string_t mac_addr;
5401         uint16_t port_num;
5402         struct ether_addr address;
5403 };
5404
5405 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5406                 __attribute__((unused))  struct cmdline *cl,
5407                 __attribute__((unused)) void *data)
5408 {
5409         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5410         int ret;
5411
5412         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5413                 return;
5414
5415         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5416
5417         /* check the return value and print it if is < 0 */
5418         if (ret < 0)
5419                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5420 }
5421
5422 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5423                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5424 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5425                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5426                                 "bonding");
5427 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5428                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5429                                 "mac_addr");
5430 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5431                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5432                                 port_num, UINT16);
5433 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5434                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5435
5436 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5437                 .f = cmd_set_bond_mac_addr_parsed,
5438                 .data = (void *) 0,
5439                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5440                 .tokens = {
5441                                 (void *)&cmd_set_bond_mac_addr_set,
5442                                 (void *)&cmd_set_bond_mac_addr_bonding,
5443                                 (void *)&cmd_set_bond_mac_addr_mac,
5444                                 (void *)&cmd_set_bond_mac_addr_portnum,
5445                                 (void *)&cmd_set_bond_mac_addr_addr,
5446                                 NULL
5447                 }
5448 };
5449
5450
5451 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5452 struct cmd_set_bond_mon_period_result {
5453         cmdline_fixed_string_t set;
5454         cmdline_fixed_string_t bonding;
5455         cmdline_fixed_string_t mon_period;
5456         uint16_t port_num;
5457         uint32_t period_ms;
5458 };
5459
5460 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5461                 __attribute__((unused))  struct cmdline *cl,
5462                 __attribute__((unused)) void *data)
5463 {
5464         struct cmd_set_bond_mon_period_result *res = parsed_result;
5465         int ret;
5466
5467         if (res->port_num >= nb_ports) {
5468                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5469                 return;
5470         }
5471
5472         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5473
5474         /* check the return value and print it if is < 0 */
5475         if (ret < 0)
5476                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5477 }
5478
5479 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5480                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5481                                 set, "set");
5482 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5483                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5484                                 bonding, "bonding");
5485 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5486                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5487                                 mon_period,     "mon_period");
5488 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5489                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5490                                 port_num, UINT16);
5491 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5492                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5493                                 period_ms, UINT32);
5494
5495 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5496                 .f = cmd_set_bond_mon_period_parsed,
5497                 .data = (void *) 0,
5498                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5499                 .tokens = {
5500                                 (void *)&cmd_set_bond_mon_period_set,
5501                                 (void *)&cmd_set_bond_mon_period_bonding,
5502                                 (void *)&cmd_set_bond_mon_period_mon_period,
5503                                 (void *)&cmd_set_bond_mon_period_portnum,
5504                                 (void *)&cmd_set_bond_mon_period_period_ms,
5505                                 NULL
5506                 }
5507 };
5508
5509
5510
5511 struct cmd_set_bonding_agg_mode_policy_result {
5512         cmdline_fixed_string_t set;
5513         cmdline_fixed_string_t bonding;
5514         cmdline_fixed_string_t agg_mode;
5515         uint16_t port_num;
5516         cmdline_fixed_string_t policy;
5517 };
5518
5519
5520 static void
5521 cmd_set_bonding_agg_mode(void *parsed_result,
5522                 __attribute__((unused)) struct cmdline *cl,
5523                 __attribute__((unused)) void *data)
5524 {
5525         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5526         uint8_t policy = AGG_BANDWIDTH;
5527
5528         if (res->port_num >= nb_ports) {
5529                 printf("Port id %d must be less than %d\n",
5530                                 res->port_num, nb_ports);
5531                 return;
5532         }
5533
5534         if (!strcmp(res->policy, "bandwidth"))
5535                 policy = AGG_BANDWIDTH;
5536         else if (!strcmp(res->policy, "stable"))
5537                 policy = AGG_STABLE;
5538         else if (!strcmp(res->policy, "count"))
5539                 policy = AGG_COUNT;
5540
5541         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5542 }
5543
5544
5545 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5547                                 set, "set");
5548 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5550                                 bonding, "bonding");
5551
5552 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5554                                 agg_mode, "agg_mode");
5555
5556 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5557         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5558                                 port_num, UINT16);
5559
5560 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5561         TOKEN_STRING_INITIALIZER(
5562                         struct cmd_set_bonding_balance_xmit_policy_result,
5563                 policy, "stable#bandwidth#count");
5564
5565 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5566         .f = cmd_set_bonding_agg_mode,
5567         .data = (void *) 0,
5568         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5569         .tokens = {
5570                         (void *)&cmd_set_bonding_agg_mode_set,
5571                         (void *)&cmd_set_bonding_agg_mode_bonding,
5572                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5573                         (void *)&cmd_set_bonding_agg_mode_portnum,
5574                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5575                         NULL
5576                 }
5577 };
5578
5579
5580 #endif /* RTE_LIBRTE_PMD_BOND */
5581
5582 /* *** SET FORWARDING MODE *** */
5583 struct cmd_set_fwd_mode_result {
5584         cmdline_fixed_string_t set;
5585         cmdline_fixed_string_t fwd;
5586         cmdline_fixed_string_t mode;
5587 };
5588
5589 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5590                                     __attribute__((unused)) struct cmdline *cl,
5591                                     __attribute__((unused)) void *data)
5592 {
5593         struct cmd_set_fwd_mode_result *res = parsed_result;
5594
5595         retry_enabled = 0;
5596         set_pkt_forwarding_mode(res->mode);
5597 }
5598
5599 cmdline_parse_token_string_t cmd_setfwd_set =
5600         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5601 cmdline_parse_token_string_t cmd_setfwd_fwd =
5602         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5603 cmdline_parse_token_string_t cmd_setfwd_mode =
5604         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5605                 "" /* defined at init */);
5606
5607 cmdline_parse_inst_t cmd_set_fwd_mode = {
5608         .f = cmd_set_fwd_mode_parsed,
5609         .data = NULL,
5610         .help_str = NULL, /* defined at init */
5611         .tokens = {
5612                 (void *)&cmd_setfwd_set,
5613                 (void *)&cmd_setfwd_fwd,
5614                 (void *)&cmd_setfwd_mode,
5615                 NULL,
5616         },
5617 };
5618
5619 static void cmd_set_fwd_mode_init(void)
5620 {
5621         char *modes, *c;
5622         static char token[128];
5623         static char help[256];
5624         cmdline_parse_token_string_t *token_struct;
5625
5626         modes = list_pkt_forwarding_modes();
5627         snprintf(help, sizeof(help), "set fwd %s: "
5628                 "Set packet forwarding mode", modes);
5629         cmd_set_fwd_mode.help_str = help;
5630
5631         /* string token separator is # */
5632         for (c = token; *modes != '\0'; modes++)
5633                 if (*modes == '|')
5634                         *c++ = '#';
5635                 else
5636                         *c++ = *modes;
5637         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5638         token_struct->string_data.str = token;
5639 }
5640
5641 /* *** SET RETRY FORWARDING MODE *** */
5642 struct cmd_set_fwd_retry_mode_result {
5643         cmdline_fixed_string_t set;
5644         cmdline_fixed_string_t fwd;
5645         cmdline_fixed_string_t mode;
5646         cmdline_fixed_string_t retry;
5647 };
5648
5649 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5650                             __attribute__((unused)) struct cmdline *cl,
5651                             __attribute__((unused)) void *data)
5652 {
5653         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5654
5655         retry_enabled = 1;
5656         set_pkt_forwarding_mode(res->mode);
5657 }
5658
5659 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5660         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5661                         set, "set");
5662 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5663         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5664                         fwd, "fwd");
5665 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5666         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5667                         mode,
5668                 "" /* defined at init */);
5669 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5670         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5671                         retry, "retry");
5672
5673 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5674         .f = cmd_set_fwd_retry_mode_parsed,
5675         .data = NULL,
5676         .help_str = NULL, /* defined at init */
5677         .tokens = {
5678                 (void *)&cmd_setfwd_retry_set,
5679                 (void *)&cmd_setfwd_retry_fwd,
5680                 (void *)&cmd_setfwd_retry_mode,
5681                 (void *)&cmd_setfwd_retry_retry,
5682                 NULL,
5683         },
5684 };
5685
5686 static void cmd_set_fwd_retry_mode_init(void)
5687 {
5688         char *modes, *c;
5689         static char token[128];
5690         static char help[256];
5691         cmdline_parse_token_string_t *token_struct;
5692
5693         modes = list_pkt_forwarding_retry_modes();
5694         snprintf(help, sizeof(help), "set fwd %s retry: "
5695                 "Set packet forwarding mode with retry", modes);
5696         cmd_set_fwd_retry_mode.help_str = help;
5697
5698         /* string token separator is # */
5699         for (c = token; *modes != '\0'; modes++)
5700                 if (*modes == '|')
5701                         *c++ = '#';
5702                 else
5703                         *c++ = *modes;
5704         token_struct = (cmdline_parse_token_string_t *)
5705                 cmd_set_fwd_retry_mode.tokens[2];
5706         token_struct->string_data.str = token;
5707 }
5708
5709 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5710 struct cmd_set_burst_tx_retry_result {
5711         cmdline_fixed_string_t set;
5712         cmdline_fixed_string_t burst;
5713         cmdline_fixed_string_t tx;
5714         cmdline_fixed_string_t delay;
5715         uint32_t time;
5716         cmdline_fixed_string_t retry;
5717         uint32_t retry_num;
5718 };
5719
5720 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5721                                         __attribute__((unused)) struct cmdline *cl,
5722                                         __attribute__((unused)) void *data)
5723 {
5724         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5725
5726         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5727                 && !strcmp(res->tx, "tx")) {
5728                 if (!strcmp(res->delay, "delay"))
5729                         burst_tx_delay_time = res->time;
5730                 if (!strcmp(res->retry, "retry"))
5731                         burst_tx_retry_num = res->retry_num;
5732         }
5733
5734 }
5735
5736 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5737         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5738 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5739         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5740                                  "burst");
5741 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5742         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5743 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5744         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5745 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5746         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5747 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5748         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5749 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5750         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5751
5752 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5753         .f = cmd_set_burst_tx_retry_parsed,
5754         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5755         .tokens = {
5756                 (void *)&cmd_set_burst_tx_retry_set,
5757                 (void *)&cmd_set_burst_tx_retry_burst,
5758                 (void *)&cmd_set_burst_tx_retry_tx,
5759                 (void *)&cmd_set_burst_tx_retry_delay,
5760                 (void *)&cmd_set_burst_tx_retry_time,
5761                 (void *)&cmd_set_burst_tx_retry_retry,
5762                 (void *)&cmd_set_burst_tx_retry_retry_num,
5763                 NULL,
5764         },
5765 };
5766
5767 /* *** SET PROMISC MODE *** */
5768 struct cmd_set_promisc_mode_result {
5769         cmdline_fixed_string_t set;
5770         cmdline_fixed_string_t promisc;
5771         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5772         uint16_t port_num;               /* valid if "allports" argument == 0 */
5773         cmdline_fixed_string_t mode;
5774 };
5775
5776 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5777                                         __attribute__((unused)) struct cmdline *cl,
5778                                         void *allports)
5779 {
5780         struct cmd_set_promisc_mode_result *res = parsed_result;
5781         int enable;
5782         portid_t i;
5783
5784         if (!strcmp(res->mode, "on"))
5785                 enable = 1;
5786         else
5787                 enable = 0;
5788
5789         /* all ports */
5790         if (allports) {
5791                 RTE_ETH_FOREACH_DEV(i) {
5792                         if (enable)
5793                                 rte_eth_promiscuous_enable(i);
5794                         else
5795                                 rte_eth_promiscuous_disable(i);
5796                 }
5797         }
5798         else {
5799                 if (enable)
5800                         rte_eth_promiscuous_enable(res->port_num);
5801                 else
5802                         rte_eth_promiscuous_disable(res->port_num);
5803         }
5804 }
5805
5806 cmdline_parse_token_string_t cmd_setpromisc_set =
5807         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5808 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5809         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5810                                  "promisc");
5811 cmdline_parse_token_string_t cmd_setpromisc_portall =
5812         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5813                                  "all");
5814 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5815         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5816                               UINT8);
5817 cmdline_parse_token_string_t cmd_setpromisc_mode =
5818         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5819                                  "on#off");
5820
5821 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5822         .f = cmd_set_promisc_mode_parsed,
5823         .data = (void *)1,
5824         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5825         .tokens = {
5826                 (void *)&cmd_setpromisc_set,
5827                 (void *)&cmd_setpromisc_promisc,
5828                 (void *)&cmd_setpromisc_portall,
5829                 (void *)&cmd_setpromisc_mode,
5830                 NULL,
5831         },
5832 };
5833
5834 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5835         .f = cmd_set_promisc_mode_parsed,
5836         .data = (void *)0,
5837         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5838         .tokens = {
5839                 (void *)&cmd_setpromisc_set,
5840                 (void *)&cmd_setpromisc_promisc,
5841                 (void *)&cmd_setpromisc_portnum,
5842                 (void *)&cmd_setpromisc_mode,
5843                 NULL,
5844         },
5845 };
5846
5847 /* *** SET ALLMULTI MODE *** */
5848 struct cmd_set_allmulti_mode_result {
5849         cmdline_fixed_string_t set;
5850         cmdline_fixed_string_t allmulti;
5851         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5852         uint16_t port_num;               /* valid if "allports" argument == 0 */
5853         cmdline_fixed_string_t mode;
5854 };
5855
5856 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5857                                         __attribute__((unused)) struct cmdline *cl,
5858                                         void *allports)
5859 {
5860         struct cmd_set_allmulti_mode_result *res = parsed_result;
5861         int enable;
5862         portid_t i;
5863
5864         if (!strcmp(res->mode, "on"))
5865                 enable = 1;
5866         else
5867                 enable = 0;
5868
5869         /* all ports */
5870         if (allports) {
5871                 RTE_ETH_FOREACH_DEV(i) {
5872                         if (enable)
5873                                 rte_eth_allmulticast_enable(i);
5874                         else
5875                                 rte_eth_allmulticast_disable(i);
5876                 }
5877         }
5878         else {
5879                 if (enable)
5880                         rte_eth_allmulticast_enable(res->port_num);
5881                 else
5882                         rte_eth_allmulticast_disable(res->port_num);
5883         }
5884 }
5885
5886 cmdline_parse_token_string_t cmd_setallmulti_set =
5887         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5888 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5889         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5890                                  "allmulti");
5891 cmdline_parse_token_string_t cmd_setallmulti_portall =
5892         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5893                                  "all");
5894 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5895         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5896                               UINT16);
5897 cmdline_parse_token_string_t cmd_setallmulti_mode =
5898         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5899                                  "on#off");
5900
5901 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5902         .f = cmd_set_allmulti_mode_parsed,
5903         .data = (void *)1,
5904         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5905         .tokens = {
5906                 (void *)&cmd_setallmulti_set,
5907                 (void *)&cmd_setallmulti_allmulti,
5908                 (void *)&cmd_setallmulti_portall,
5909                 (void *)&cmd_setallmulti_mode,
5910                 NULL,
5911         },
5912 };
5913
5914 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5915         .f = cmd_set_allmulti_mode_parsed,
5916         .data = (void *)0,
5917         .help_str = "set allmulti <port_id> on|off: "
5918                 "Set allmulti mode on port_id",
5919         .tokens = {
5920                 (void *)&cmd_setallmulti_set,
5921                 (void *)&cmd_setallmulti_allmulti,
5922                 (void *)&cmd_setallmulti_portnum,
5923                 (void *)&cmd_setallmulti_mode,
5924                 NULL,
5925         },
5926 };
5927
5928 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5929 struct cmd_link_flow_ctrl_set_result {
5930         cmdline_fixed_string_t set;
5931         cmdline_fixed_string_t flow_ctrl;
5932         cmdline_fixed_string_t rx;
5933         cmdline_fixed_string_t rx_lfc_mode;
5934         cmdline_fixed_string_t tx;
5935         cmdline_fixed_string_t tx_lfc_mode;
5936         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5937         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5938         cmdline_fixed_string_t autoneg_str;
5939         cmdline_fixed_string_t autoneg;
5940         cmdline_fixed_string_t hw_str;
5941         uint32_t high_water;
5942         cmdline_fixed_string_t lw_str;
5943         uint32_t low_water;
5944         cmdline_fixed_string_t pt_str;
5945         uint16_t pause_time;
5946         cmdline_fixed_string_t xon_str;
5947         uint16_t send_xon;
5948         portid_t port_id;
5949 };
5950
5951 cmdline_parse_token_string_t cmd_lfc_set_set =
5952         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5953                                 set, "set");
5954 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5955         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5956                                 flow_ctrl, "flow_ctrl");
5957 cmdline_parse_token_string_t cmd_lfc_set_rx =
5958         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5959                                 rx, "rx");
5960 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5961         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5962                                 rx_lfc_mode, "on#off");
5963 cmdline_parse_token_string_t cmd_lfc_set_tx =
5964         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5965                                 tx, "tx");
5966 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5967         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5968                                 tx_lfc_mode, "on#off");
5969 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5970         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5971                                 hw_str, "high_water");
5972 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5973         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5974                                 high_water, UINT32);
5975 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5976         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5977                                 lw_str, "low_water");
5978 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5979         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5980                                 low_water, UINT32);
5981 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5982         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5983                                 pt_str, "pause_time");
5984 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5985         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5986                                 pause_time, UINT16);
5987 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5988         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5989                                 xon_str, "send_xon");
5990 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5991         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5992                                 send_xon, UINT16);
5993 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5994         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5995                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5996 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5997         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5998                                 mac_ctrl_frame_fwd_mode, "on#off");
5999 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6000         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6001                                 autoneg_str, "autoneg");
6002 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6003         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6004                                 autoneg, "on#off");
6005 cmdline_parse_token_num_t cmd_lfc_set_portid =
6006         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6007                                 port_id, UINT16);
6008
6009 /* forward declaration */
6010 static void
6011 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6012                               void *data);
6013
6014 cmdline_parse_inst_t cmd_link_flow_control_set = {
6015         .f = cmd_link_flow_ctrl_set_parsed,
6016         .data = NULL,
6017         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6018                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6019                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6020         .tokens = {
6021                 (void *)&cmd_lfc_set_set,
6022                 (void *)&cmd_lfc_set_flow_ctrl,
6023                 (void *)&cmd_lfc_set_rx,
6024                 (void *)&cmd_lfc_set_rx_mode,
6025                 (void *)&cmd_lfc_set_tx,
6026                 (void *)&cmd_lfc_set_tx_mode,
6027                 (void *)&cmd_lfc_set_high_water,
6028                 (void *)&cmd_lfc_set_low_water,
6029                 (void *)&cmd_lfc_set_pause_time,
6030                 (void *)&cmd_lfc_set_send_xon,
6031                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6032                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6033                 (void *)&cmd_lfc_set_autoneg_str,
6034                 (void *)&cmd_lfc_set_autoneg,
6035                 (void *)&cmd_lfc_set_portid,
6036                 NULL,
6037         },
6038 };
6039
6040 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6041         .f = cmd_link_flow_ctrl_set_parsed,
6042         .data = (void *)&cmd_link_flow_control_set_rx,
6043         .help_str = "set flow_ctrl rx on|off <port_id>: "
6044                 "Change rx flow control parameter",
6045         .tokens = {
6046                 (void *)&cmd_lfc_set_set,
6047                 (void *)&cmd_lfc_set_flow_ctrl,
6048                 (void *)&cmd_lfc_set_rx,
6049                 (void *)&cmd_lfc_set_rx_mode,
6050                 (void *)&cmd_lfc_set_portid,
6051                 NULL,
6052         },
6053 };
6054
6055 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6056         .f = cmd_link_flow_ctrl_set_parsed,
6057         .data = (void *)&cmd_link_flow_control_set_tx,
6058         .help_str = "set flow_ctrl tx on|off <port_id>: "
6059                 "Change tx flow control parameter",
6060         .tokens = {
6061                 (void *)&cmd_lfc_set_set,
6062                 (void *)&cmd_lfc_set_flow_ctrl,
6063                 (void *)&cmd_lfc_set_tx,
6064                 (void *)&cmd_lfc_set_tx_mode,
6065                 (void *)&cmd_lfc_set_portid,
6066                 NULL,
6067         },
6068 };
6069
6070 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6071         .f = cmd_link_flow_ctrl_set_parsed,
6072         .data = (void *)&cmd_link_flow_control_set_hw,
6073         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6074                 "Change high water flow control parameter",
6075         .tokens = {
6076                 (void *)&cmd_lfc_set_set,
6077                 (void *)&cmd_lfc_set_flow_ctrl,
6078                 (void *)&cmd_lfc_set_high_water_str,
6079                 (void *)&cmd_lfc_set_high_water,
6080                 (void *)&cmd_lfc_set_portid,
6081                 NULL,
6082         },
6083 };
6084
6085 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6086         .f = cmd_link_flow_ctrl_set_parsed,
6087         .data = (void *)&cmd_link_flow_control_set_lw,
6088         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6089                 "Change low water flow control parameter",
6090         .tokens = {
6091                 (void *)&cmd_lfc_set_set,
6092                 (void *)&cmd_lfc_set_flow_ctrl,
6093                 (void *)&cmd_lfc_set_low_water_str,
6094                 (void *)&cmd_lfc_set_low_water,
6095                 (void *)&cmd_lfc_set_portid,
6096                 NULL,
6097         },
6098 };
6099
6100 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6101         .f = cmd_link_flow_ctrl_set_parsed,
6102         .data = (void *)&cmd_link_flow_control_set_pt,
6103         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6104                 "Change pause time flow control parameter",
6105         .tokens = {
6106                 (void *)&cmd_lfc_set_set,
6107                 (void *)&cmd_lfc_set_flow_ctrl,
6108                 (void *)&cmd_lfc_set_pause_time_str,
6109                 (void *)&cmd_lfc_set_pause_time,
6110                 (void *)&cmd_lfc_set_portid,
6111                 NULL,
6112         },
6113 };
6114
6115 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6116         .f = cmd_link_flow_ctrl_set_parsed,
6117         .data = (void *)&cmd_link_flow_control_set_xon,
6118         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6119                 "Change send_xon flow control parameter",
6120         .tokens = {
6121                 (void *)&cmd_lfc_set_set,
6122                 (void *)&cmd_lfc_set_flow_ctrl,
6123                 (void *)&cmd_lfc_set_send_xon_str,
6124                 (void *)&cmd_lfc_set_send_xon,
6125                 (void *)&cmd_lfc_set_portid,
6126                 NULL,
6127         },
6128 };
6129
6130 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6131         .f = cmd_link_flow_ctrl_set_parsed,
6132         .data = (void *)&cmd_link_flow_control_set_macfwd,
6133         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6134                 "Change mac ctrl fwd flow control parameter",
6135         .tokens = {
6136                 (void *)&cmd_lfc_set_set,
6137                 (void *)&cmd_lfc_set_flow_ctrl,
6138                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6139                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6140                 (void *)&cmd_lfc_set_portid,
6141                 NULL,
6142         },
6143 };
6144
6145 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6146         .f = cmd_link_flow_ctrl_set_parsed,
6147         .data = (void *)&cmd_link_flow_control_set_autoneg,
6148         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6149                 "Change autoneg flow control parameter",
6150         .tokens = {
6151                 (void *)&cmd_lfc_set_set,
6152                 (void *)&cmd_lfc_set_flow_ctrl,
6153                 (void *)&cmd_lfc_set_autoneg_str,
6154                 (void *)&cmd_lfc_set_autoneg,
6155                 (void *)&cmd_lfc_set_portid,
6156                 NULL,
6157         },
6158 };
6159
6160 static void
6161 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6162                               __attribute__((unused)) struct cmdline *cl,
6163                               void *data)
6164 {
6165         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6166         cmdline_parse_inst_t *cmd = data;
6167         struct rte_eth_fc_conf fc_conf;
6168         int rx_fc_en = 0;
6169         int tx_fc_en = 0;
6170         int ret;
6171
6172         /*
6173          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6174          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6175          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6176          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6177          */
6178         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6179                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6180         };
6181
6182         /* Partial command line, retrieve current configuration */
6183         if (cmd) {
6184                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6185                 if (ret != 0) {
6186                         printf("cannot get current flow ctrl parameters, return"
6187                                "code = %d\n", ret);
6188                         return;
6189                 }
6190
6191                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6192                     (fc_conf.mode == RTE_FC_FULL))
6193                         rx_fc_en = 1;
6194                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6195                     (fc_conf.mode == RTE_FC_FULL))
6196                         tx_fc_en = 1;
6197         }
6198
6199         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6200                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6201
6202         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6203                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6204
6205         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6206
6207         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6208                 fc_conf.high_water = res->high_water;
6209
6210         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6211                 fc_conf.low_water = res->low_water;
6212
6213         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6214                 fc_conf.pause_time = res->pause_time;
6215
6216         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6217                 fc_conf.send_xon = res->send_xon;
6218
6219         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6220                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6221                         fc_conf.mac_ctrl_frame_fwd = 1;
6222                 else
6223                         fc_conf.mac_ctrl_frame_fwd = 0;
6224         }
6225
6226         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6227                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6228
6229         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6230         if (ret != 0)
6231                 printf("bad flow contrl parameter, return code = %d \n", ret);
6232 }
6233
6234 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6235 struct cmd_priority_flow_ctrl_set_result {
6236         cmdline_fixed_string_t set;
6237         cmdline_fixed_string_t pfc_ctrl;
6238         cmdline_fixed_string_t rx;
6239         cmdline_fixed_string_t rx_pfc_mode;
6240         cmdline_fixed_string_t tx;
6241         cmdline_fixed_string_t tx_pfc_mode;
6242         uint32_t high_water;
6243         uint32_t low_water;
6244         uint16_t pause_time;
6245         uint8_t  priority;
6246         portid_t port_id;
6247 };
6248
6249 static void
6250 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6251                        __attribute__((unused)) struct cmdline *cl,
6252                        __attribute__((unused)) void *data)
6253 {
6254         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6255         struct rte_eth_pfc_conf pfc_conf;
6256         int rx_fc_enable, tx_fc_enable;
6257         int ret;
6258
6259         /*
6260          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6261          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6262          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6263          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6264          */
6265         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6266                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6267         };
6268
6269         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6270         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6271         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6272         pfc_conf.fc.high_water = res->high_water;
6273         pfc_conf.fc.low_water  = res->low_water;
6274         pfc_conf.fc.pause_time = res->pause_time;
6275         pfc_conf.priority      = res->priority;
6276
6277         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6278         if (ret != 0)
6279                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6280 }
6281
6282 cmdline_parse_token_string_t cmd_pfc_set_set =
6283         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6284                                 set, "set");
6285 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6286         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6287                                 pfc_ctrl, "pfc_ctrl");
6288 cmdline_parse_token_string_t cmd_pfc_set_rx =
6289         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6290                                 rx, "rx");
6291 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6292         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6293                                 rx_pfc_mode, "on#off");
6294 cmdline_parse_token_string_t cmd_pfc_set_tx =
6295         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6296                                 tx, "tx");
6297 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6298         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6299                                 tx_pfc_mode, "on#off");
6300 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6301         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6302                                 high_water, UINT32);
6303 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6304         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6305                                 low_water, UINT32);
6306 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6307         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6308                                 pause_time, UINT16);
6309 cmdline_parse_token_num_t cmd_pfc_set_priority =
6310         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6311                                 priority, UINT8);
6312 cmdline_parse_token_num_t cmd_pfc_set_portid =
6313         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6314                                 port_id, UINT16);
6315
6316 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6317         .f = cmd_priority_flow_ctrl_set_parsed,
6318         .data = NULL,
6319         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6320                 "<pause_time> <priority> <port_id>: "
6321                 "Configure the Ethernet priority flow control",
6322         .tokens = {
6323                 (void *)&cmd_pfc_set_set,
6324                 (void *)&cmd_pfc_set_flow_ctrl,
6325                 (void *)&cmd_pfc_set_rx,
6326                 (void *)&cmd_pfc_set_rx_mode,
6327                 (void *)&cmd_pfc_set_tx,
6328                 (void *)&cmd_pfc_set_tx_mode,
6329                 (void *)&cmd_pfc_set_high_water,
6330                 (void *)&cmd_pfc_set_low_water,
6331                 (void *)&cmd_pfc_set_pause_time,
6332                 (void *)&cmd_pfc_set_priority,
6333                 (void *)&cmd_pfc_set_portid,
6334                 NULL,
6335         },
6336 };
6337
6338 /* *** RESET CONFIGURATION *** */
6339 struct cmd_reset_result {
6340         cmdline_fixed_string_t reset;
6341         cmdline_fixed_string_t def;
6342 };
6343
6344 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6345                              struct cmdline *cl,
6346                              __attribute__((unused)) void *data)
6347 {
6348         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6349         set_def_fwd_config();
6350 }
6351
6352 cmdline_parse_token_string_t cmd_reset_set =
6353         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6354 cmdline_parse_token_string_t cmd_reset_def =
6355         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6356                                  "default");
6357
6358 cmdline_parse_inst_t cmd_reset = {
6359         .f = cmd_reset_parsed,
6360         .data = NULL,
6361         .help_str = "set default: Reset default forwarding configuration",
6362         .tokens = {
6363                 (void *)&cmd_reset_set,
6364                 (void *)&cmd_reset_def,
6365                 NULL,
6366         },
6367 };
6368
6369 /* *** START FORWARDING *** */
6370 struct cmd_start_result {
6371         cmdline_fixed_string_t start;
6372 };
6373
6374 cmdline_parse_token_string_t cmd_start_start =
6375         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6376
6377 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6378                              __attribute__((unused)) struct cmdline *cl,
6379                              __attribute__((unused)) void *data)
6380 {
6381         start_packet_forwarding(0);
6382 }
6383
6384 cmdline_parse_inst_t cmd_start = {
6385         .f = cmd_start_parsed,
6386         .data = NULL,
6387         .help_str = "start: Start packet forwarding",
6388         .tokens = {
6389                 (void *)&cmd_start_start,
6390                 NULL,
6391         },
6392 };
6393
6394 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6395 struct cmd_start_tx_first_result {
6396         cmdline_fixed_string_t start;
6397         cmdline_fixed_string_t tx_first;
6398 };
6399
6400 static void
6401 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6402                           __attribute__((unused)) struct cmdline *cl,
6403                           __attribute__((unused)) void *data)
6404 {
6405         start_packet_forwarding(1);
6406 }
6407
6408 cmdline_parse_token_string_t cmd_start_tx_first_start =
6409         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6410                                  "start");
6411 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6412         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6413                                  tx_first, "tx_first");
6414
6415 cmdline_parse_inst_t cmd_start_tx_first = {
6416         .f = cmd_start_tx_first_parsed,
6417         .data = NULL,
6418         .help_str = "start tx_first: Start packet forwarding, "
6419                 "after sending 1 burst of packets",
6420         .tokens = {
6421                 (void *)&cmd_start_tx_first_start,
6422                 (void *)&cmd_start_tx_first_tx_first,
6423                 NULL,
6424         },
6425 };
6426
6427 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6428 struct cmd_start_tx_first_n_result {
6429         cmdline_fixed_string_t start;
6430         cmdline_fixed_string_t tx_first;
6431         uint32_t tx_num;
6432 };
6433
6434 static void
6435 cmd_start_tx_first_n_parsed(void *parsed_result,
6436                           __attribute__((unused)) struct cmdline *cl,
6437                           __attribute__((unused)) void *data)
6438 {
6439         struct cmd_start_tx_first_n_result *res = parsed_result;
6440
6441         start_packet_forwarding(res->tx_num);
6442 }
6443
6444 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6445         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6446                         start, "start");
6447 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6448         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6449                         tx_first, "tx_first");
6450 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6451         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6452                         tx_num, UINT32);
6453
6454 cmdline_parse_inst_t cmd_start_tx_first_n = {
6455         .f = cmd_start_tx_first_n_parsed,
6456         .data = NULL,
6457         .help_str = "start tx_first <num>: "
6458                 "packet forwarding, after sending <num> bursts of packets",
6459         .tokens = {
6460                 (void *)&cmd_start_tx_first_n_start,
6461                 (void *)&cmd_start_tx_first_n_tx_first,
6462                 (void *)&cmd_start_tx_first_n_tx_num,
6463                 NULL,
6464         },
6465 };
6466
6467 /* *** SET LINK UP *** */
6468 struct cmd_set_link_up_result {
6469         cmdline_fixed_string_t set;
6470         cmdline_fixed_string_t link_up;
6471         cmdline_fixed_string_t port;
6472         portid_t port_id;
6473 };
6474
6475 cmdline_parse_token_string_t cmd_set_link_up_set =
6476         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6477 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6478         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6479                                 "link-up");
6480 cmdline_parse_token_string_t cmd_set_link_up_port =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6482 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6483         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6484
6485 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6486                              __attribute__((unused)) struct cmdline *cl,
6487                              __attribute__((unused)) void *data)
6488 {
6489         struct cmd_set_link_up_result *res = parsed_result;
6490         dev_set_link_up(res->port_id);
6491 }
6492
6493 cmdline_parse_inst_t cmd_set_link_up = {
6494         .f = cmd_set_link_up_parsed,
6495         .data = NULL,
6496         .help_str = "set link-up port <port id>",
6497         .tokens = {
6498                 (void *)&cmd_set_link_up_set,
6499                 (void *)&cmd_set_link_up_link_up,
6500                 (void *)&cmd_set_link_up_port,
6501                 (void *)&cmd_set_link_up_port_id,
6502                 NULL,
6503         },
6504 };
6505
6506 /* *** SET LINK DOWN *** */
6507 struct cmd_set_link_down_result {
6508         cmdline_fixed_string_t set;
6509         cmdline_fixed_string_t link_down;
6510         cmdline_fixed_string_t port;
6511         portid_t port_id;
6512 };
6513
6514 cmdline_parse_token_string_t cmd_set_link_down_set =
6515         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6516 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6517         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6518                                 "link-down");
6519 cmdline_parse_token_string_t cmd_set_link_down_port =
6520         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6521 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6522         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6523
6524 static void cmd_set_link_down_parsed(
6525                                 __attribute__((unused)) void *parsed_result,
6526                                 __attribute__((unused)) struct cmdline *cl,
6527                                 __attribute__((unused)) void *data)
6528 {
6529         struct cmd_set_link_down_result *res = parsed_result;
6530         dev_set_link_down(res->port_id);
6531 }
6532
6533 cmdline_parse_inst_t cmd_set_link_down = {
6534         .f = cmd_set_link_down_parsed,
6535         .data = NULL,
6536         .help_str = "set link-down port <port id>",
6537         .tokens = {
6538                 (void *)&cmd_set_link_down_set,
6539                 (void *)&cmd_set_link_down_link_down,
6540                 (void *)&cmd_set_link_down_port,
6541                 (void *)&cmd_set_link_down_port_id,
6542                 NULL,
6543         },
6544 };
6545
6546 /* *** SHOW CFG *** */
6547 struct cmd_showcfg_result {
6548         cmdline_fixed_string_t show;
6549         cmdline_fixed_string_t cfg;
6550         cmdline_fixed_string_t what;
6551 };
6552
6553 static void cmd_showcfg_parsed(void *parsed_result,
6554                                __attribute__((unused)) struct cmdline *cl,
6555                                __attribute__((unused)) void *data)
6556 {
6557         struct cmd_showcfg_result *res = parsed_result;
6558         if (!strcmp(res->what, "rxtx"))
6559                 rxtx_config_display();
6560         else if (!strcmp(res->what, "cores"))
6561                 fwd_lcores_config_display();
6562         else if (!strcmp(res->what, "fwd"))
6563                 pkt_fwd_config_display(&cur_fwd_config);
6564         else if (!strcmp(res->what, "txpkts"))
6565                 show_tx_pkt_segments();
6566 }
6567
6568 cmdline_parse_token_string_t cmd_showcfg_show =
6569         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6570 cmdline_parse_token_string_t cmd_showcfg_port =
6571         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6572 cmdline_parse_token_string_t cmd_showcfg_what =
6573         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6574                                  "rxtx#cores#fwd#txpkts");
6575
6576 cmdline_parse_inst_t cmd_showcfg = {
6577         .f = cmd_showcfg_parsed,
6578         .data = NULL,
6579         .help_str = "show config rxtx|cores|fwd|txpkts",
6580         .tokens = {
6581                 (void *)&cmd_showcfg_show,
6582                 (void *)&cmd_showcfg_port,
6583                 (void *)&cmd_showcfg_what,
6584                 NULL,
6585         },
6586 };
6587
6588 /* *** SHOW ALL PORT INFO *** */
6589 struct cmd_showportall_result {
6590         cmdline_fixed_string_t show;
6591         cmdline_fixed_string_t port;
6592         cmdline_fixed_string_t what;
6593         cmdline_fixed_string_t all;
6594 };
6595
6596 static void cmd_showportall_parsed(void *parsed_result,
6597                                 __attribute__((unused)) struct cmdline *cl,
6598                                 __attribute__((unused)) void *data)
6599 {
6600         portid_t i;
6601
6602         struct cmd_showportall_result *res = parsed_result;
6603         if (!strcmp(res->show, "clear")) {
6604                 if (!strcmp(res->what, "stats"))
6605                         RTE_ETH_FOREACH_DEV(i)
6606                                 nic_stats_clear(i);
6607                 else if (!strcmp(res->what, "xstats"))
6608                         RTE_ETH_FOREACH_DEV(i)
6609                                 nic_xstats_clear(i);
6610         } else if (!strcmp(res->what, "info"))
6611                 RTE_ETH_FOREACH_DEV(i)
6612                         port_infos_display(i);
6613         else if (!strcmp(res->what, "stats"))
6614                 RTE_ETH_FOREACH_DEV(i)
6615                         nic_stats_display(i);
6616         else if (!strcmp(res->what, "xstats"))
6617                 RTE_ETH_FOREACH_DEV(i)
6618                         nic_xstats_display(i);
6619         else if (!strcmp(res->what, "fdir"))
6620                 RTE_ETH_FOREACH_DEV(i)
6621                         fdir_get_infos(i);
6622         else if (!strcmp(res->what, "stat_qmap"))
6623                 RTE_ETH_FOREACH_DEV(i)
6624                         nic_stats_mapping_display(i);
6625         else if (!strcmp(res->what, "dcb_tc"))
6626                 RTE_ETH_FOREACH_DEV(i)
6627                         port_dcb_info_display(i);
6628         else if (!strcmp(res->what, "cap"))
6629                 RTE_ETH_FOREACH_DEV(i)
6630                         port_offload_cap_display(i);
6631 }
6632
6633 cmdline_parse_token_string_t cmd_showportall_show =
6634         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6635                                  "show#clear");
6636 cmdline_parse_token_string_t cmd_showportall_port =
6637         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6638 cmdline_parse_token_string_t cmd_showportall_what =
6639         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6640                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6641 cmdline_parse_token_string_t cmd_showportall_all =
6642         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6643 cmdline_parse_inst_t cmd_showportall = {
6644         .f = cmd_showportall_parsed,
6645         .data = NULL,
6646         .help_str = "show|clear port "
6647                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6648         .tokens = {
6649                 (void *)&cmd_showportall_show,
6650                 (void *)&cmd_showportall_port,
6651                 (void *)&cmd_showportall_what,
6652                 (void *)&cmd_showportall_all,
6653                 NULL,
6654         },
6655 };
6656
6657 /* *** SHOW PORT INFO *** */
6658 struct cmd_showport_result {
6659         cmdline_fixed_string_t show;
6660         cmdline_fixed_string_t port;
6661         cmdline_fixed_string_t what;
6662         uint16_t portnum;
6663 };
6664
6665 static void cmd_showport_parsed(void *parsed_result,
6666                                 __attribute__((unused)) struct cmdline *cl,
6667                                 __attribute__((unused)) void *data)
6668 {
6669         struct cmd_showport_result *res = parsed_result;
6670         if (!strcmp(res->show, "clear")) {
6671                 if (!strcmp(res->what, "stats"))
6672                         nic_stats_clear(res->portnum);
6673                 else if (!strcmp(res->what, "xstats"))
6674                         nic_xstats_clear(res->portnum);
6675         } else if (!strcmp(res->what, "info"))
6676                 port_infos_display(res->portnum);
6677         else if (!strcmp(res->what, "stats"))
6678                 nic_stats_display(res->portnum);
6679         else if (!strcmp(res->what, "xstats"))
6680                 nic_xstats_display(res->portnum);
6681         else if (!strcmp(res->what, "fdir"))
6682                  fdir_get_infos(res->portnum);
6683         else if (!strcmp(res->what, "stat_qmap"))
6684                 nic_stats_mapping_display(res->portnum);
6685         else if (!strcmp(res->what, "dcb_tc"))
6686                 port_dcb_info_display(res->portnum);
6687         else if (!strcmp(res->what, "cap"))
6688                 port_offload_cap_display(res->portnum);
6689 }
6690
6691 cmdline_parse_token_string_t cmd_showport_show =
6692         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6693                                  "show#clear");
6694 cmdline_parse_token_string_t cmd_showport_port =
6695         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6696 cmdline_parse_token_string_t cmd_showport_what =
6697         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6698                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6699 cmdline_parse_token_num_t cmd_showport_portnum =
6700         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6701
6702 cmdline_parse_inst_t cmd_showport = {
6703         .f = cmd_showport_parsed,
6704         .data = NULL,
6705         .help_str = "show|clear port "
6706                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6707                 "<port_id>",
6708         .tokens = {
6709                 (void *)&cmd_showport_show,
6710                 (void *)&cmd_showport_port,
6711                 (void *)&cmd_showport_what,
6712                 (void *)&cmd_showport_portnum,
6713                 NULL,
6714         },
6715 };
6716
6717 /* *** SHOW QUEUE INFO *** */
6718 struct cmd_showqueue_result {
6719         cmdline_fixed_string_t show;
6720         cmdline_fixed_string_t type;
6721         cmdline_fixed_string_t what;
6722         uint16_t portnum;
6723         uint16_t queuenum;
6724 };
6725
6726 static void
6727 cmd_showqueue_parsed(void *parsed_result,
6728         __attribute__((unused)) struct cmdline *cl,
6729         __attribute__((unused)) void *data)
6730 {
6731         struct cmd_showqueue_result *res = parsed_result;
6732
6733         if (!strcmp(res->type, "rxq"))
6734                 rx_queue_infos_display(res->portnum, res->queuenum);
6735         else if (!strcmp(res->type, "txq"))
6736                 tx_queue_infos_display(res->portnum, res->queuenum);
6737 }
6738
6739 cmdline_parse_token_string_t cmd_showqueue_show =
6740         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6741 cmdline_parse_token_string_t cmd_showqueue_type =
6742         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6743 cmdline_parse_token_string_t cmd_showqueue_what =
6744         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6745 cmdline_parse_token_num_t cmd_showqueue_portnum =
6746         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6747 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6748         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6749
6750 cmdline_parse_inst_t cmd_showqueue = {
6751         .f = cmd_showqueue_parsed,
6752         .data = NULL,
6753         .help_str = "show rxq|txq info <port_id> <queue_id>",
6754         .tokens = {
6755                 (void *)&cmd_showqueue_show,
6756                 (void *)&cmd_showqueue_type,
6757                 (void *)&cmd_showqueue_what,
6758                 (void *)&cmd_showqueue_portnum,
6759                 (void *)&cmd_showqueue_queuenum,
6760                 NULL,
6761         },
6762 };
6763
6764 /* *** READ PORT REGISTER *** */
6765 struct cmd_read_reg_result {
6766         cmdline_fixed_string_t read;
6767         cmdline_fixed_string_t reg;
6768         portid_t port_id;
6769         uint32_t reg_off;
6770 };
6771
6772 static void
6773 cmd_read_reg_parsed(void *parsed_result,
6774                     __attribute__((unused)) struct cmdline *cl,
6775                     __attribute__((unused)) void *data)
6776 {
6777         struct cmd_read_reg_result *res = parsed_result;
6778         port_reg_display(res->port_id, res->reg_off);
6779 }
6780
6781 cmdline_parse_token_string_t cmd_read_reg_read =
6782         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6783 cmdline_parse_token_string_t cmd_read_reg_reg =
6784         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6785 cmdline_parse_token_num_t cmd_read_reg_port_id =
6786         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6787 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6788         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6789
6790 cmdline_parse_inst_t cmd_read_reg = {
6791         .f = cmd_read_reg_parsed,
6792         .data = NULL,
6793         .help_str = "read reg <port_id> <reg_off>",
6794         .tokens = {
6795                 (void *)&cmd_read_reg_read,
6796                 (void *)&cmd_read_reg_reg,
6797                 (void *)&cmd_read_reg_port_id,
6798                 (void *)&cmd_read_reg_reg_off,
6799                 NULL,
6800         },
6801 };
6802
6803 /* *** READ PORT REGISTER BIT FIELD *** */
6804 struct cmd_read_reg_bit_field_result {
6805         cmdline_fixed_string_t read;
6806         cmdline_fixed_string_t regfield;
6807         portid_t port_id;
6808         uint32_t reg_off;
6809         uint8_t bit1_pos;
6810         uint8_t bit2_pos;
6811 };
6812
6813 static void
6814 cmd_read_reg_bit_field_parsed(void *parsed_result,
6815                               __attribute__((unused)) struct cmdline *cl,
6816                               __attribute__((unused)) void *data)
6817 {
6818         struct cmd_read_reg_bit_field_result *res = parsed_result;
6819         port_reg_bit_field_display(res->port_id, res->reg_off,
6820                                    res->bit1_pos, res->bit2_pos);
6821 }
6822
6823 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6824         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6825                                  "read");
6826 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6827         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6828                                  regfield, "regfield");
6829 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6830         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6831                               UINT16);
6832 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6833         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6834                               UINT32);
6835 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6836         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6837                               UINT8);
6838 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6839         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6840                               UINT8);
6841
6842 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6843         .f = cmd_read_reg_bit_field_parsed,
6844         .data = NULL,
6845         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6846         "Read register bit field between bit_x and bit_y included",
6847         .tokens = {
6848                 (void *)&cmd_read_reg_bit_field_read,
6849                 (void *)&cmd_read_reg_bit_field_regfield,
6850                 (void *)&cmd_read_reg_bit_field_port_id,
6851                 (void *)&cmd_read_reg_bit_field_reg_off,
6852                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6853                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6854                 NULL,
6855         },
6856 };
6857
6858 /* *** READ PORT REGISTER BIT *** */
6859 struct cmd_read_reg_bit_result {
6860         cmdline_fixed_string_t read;
6861         cmdline_fixed_string_t regbit;
6862         portid_t port_id;
6863         uint32_t reg_off;
6864         uint8_t bit_pos;
6865 };
6866
6867 static void
6868 cmd_read_reg_bit_parsed(void *parsed_result,
6869                         __attribute__((unused)) struct cmdline *cl,
6870                         __attribute__((unused)) void *data)
6871 {
6872         struct cmd_read_reg_bit_result *res = parsed_result;
6873         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6874 }
6875
6876 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6877         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6878 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6879         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6880                                  regbit, "regbit");
6881 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6882         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6883 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6884         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6885 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6886         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6887
6888 cmdline_parse_inst_t cmd_read_reg_bit = {
6889         .f = cmd_read_reg_bit_parsed,
6890         .data = NULL,
6891         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6892         .tokens = {
6893                 (void *)&cmd_read_reg_bit_read,
6894                 (void *)&cmd_read_reg_bit_regbit,
6895                 (void *)&cmd_read_reg_bit_port_id,
6896                 (void *)&cmd_read_reg_bit_reg_off,
6897                 (void *)&cmd_read_reg_bit_bit_pos,
6898                 NULL,
6899         },
6900 };
6901
6902 /* *** WRITE PORT REGISTER *** */
6903 struct cmd_write_reg_result {
6904         cmdline_fixed_string_t write;
6905         cmdline_fixed_string_t reg;
6906         portid_t port_id;
6907         uint32_t reg_off;
6908         uint32_t value;
6909 };
6910
6911 static void
6912 cmd_write_reg_parsed(void *parsed_result,
6913                      __attribute__((unused)) struct cmdline *cl,
6914                      __attribute__((unused)) void *data)
6915 {
6916         struct cmd_write_reg_result *res = parsed_result;
6917         port_reg_set(res->port_id, res->reg_off, res->value);
6918 }
6919
6920 cmdline_parse_token_string_t cmd_write_reg_write =
6921         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6922 cmdline_parse_token_string_t cmd_write_reg_reg =
6923         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6924 cmdline_parse_token_num_t cmd_write_reg_port_id =
6925         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6926 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6927         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6928 cmdline_parse_token_num_t cmd_write_reg_value =
6929         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6930
6931 cmdline_parse_inst_t cmd_write_reg = {
6932         .f = cmd_write_reg_parsed,
6933         .data = NULL,
6934         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6935         .tokens = {
6936                 (void *)&cmd_write_reg_write,
6937                 (void *)&cmd_write_reg_reg,
6938                 (void *)&cmd_write_reg_port_id,
6939                 (void *)&cmd_write_reg_reg_off,
6940                 (void *)&cmd_write_reg_value,
6941                 NULL,
6942         },
6943 };
6944
6945 /* *** WRITE PORT REGISTER BIT FIELD *** */
6946 struct cmd_write_reg_bit_field_result {
6947         cmdline_fixed_string_t write;
6948         cmdline_fixed_string_t regfield;
6949         portid_t port_id;
6950         uint32_t reg_off;
6951         uint8_t bit1_pos;
6952         uint8_t bit2_pos;
6953         uint32_t value;
6954 };
6955
6956 static void
6957 cmd_write_reg_bit_field_parsed(void *parsed_result,
6958                                __attribute__((unused)) struct cmdline *cl,
6959                                __attribute__((unused)) void *data)
6960 {
6961         struct cmd_write_reg_bit_field_result *res = parsed_result;
6962         port_reg_bit_field_set(res->port_id, res->reg_off,
6963                           res->bit1_pos, res->bit2_pos, res->value);
6964 }
6965
6966 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6967         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6968                                  "write");
6969 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6970         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6971                                  regfield, "regfield");
6972 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6973         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6974                               UINT16);
6975 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6977                               UINT32);
6978 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6979         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6980                               UINT8);
6981 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6982         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6983                               UINT8);
6984 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6985         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6986                               UINT32);
6987
6988 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6989         .f = cmd_write_reg_bit_field_parsed,
6990         .data = NULL,
6991         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6992                 "<reg_value>: "
6993                 "Set register bit field between bit_x and bit_y included",
6994         .tokens = {
6995                 (void *)&cmd_write_reg_bit_field_write,
6996                 (void *)&cmd_write_reg_bit_field_regfield,
6997                 (void *)&cmd_write_reg_bit_field_port_id,
6998                 (void *)&cmd_write_reg_bit_field_reg_off,
6999                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7000                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7001                 (void *)&cmd_write_reg_bit_field_value,
7002                 NULL,
7003         },
7004 };
7005
7006 /* *** WRITE PORT REGISTER BIT *** */
7007 struct cmd_write_reg_bit_result {
7008         cmdline_fixed_string_t write;
7009         cmdline_fixed_string_t regbit;
7010         portid_t port_id;
7011         uint32_t reg_off;
7012         uint8_t bit_pos;
7013         uint8_t value;
7014 };
7015
7016 static void
7017 cmd_write_reg_bit_parsed(void *parsed_result,
7018                          __attribute__((unused)) struct cmdline *cl,
7019                          __attribute__((unused)) void *data)
7020 {
7021         struct cmd_write_reg_bit_result *res = parsed_result;
7022         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7023 }
7024
7025 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7026         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7027                                  "write");
7028 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7029         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7030                                  regbit, "regbit");
7031 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7032         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7033 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7034         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7035 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7036         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7037 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7038         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7039
7040 cmdline_parse_inst_t cmd_write_reg_bit = {
7041         .f = cmd_write_reg_bit_parsed,
7042         .data = NULL,
7043         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7044                 "0 <= bit_x <= 31",
7045         .tokens = {
7046                 (void *)&cmd_write_reg_bit_write,
7047                 (void *)&cmd_write_reg_bit_regbit,
7048                 (void *)&cmd_write_reg_bit_port_id,
7049                 (void *)&cmd_write_reg_bit_reg_off,
7050                 (void *)&cmd_write_reg_bit_bit_pos,
7051                 (void *)&cmd_write_reg_bit_value,
7052                 NULL,
7053         },
7054 };
7055
7056 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7057 struct cmd_read_rxd_txd_result {
7058         cmdline_fixed_string_t read;
7059         cmdline_fixed_string_t rxd_txd;
7060         portid_t port_id;
7061         uint16_t queue_id;
7062         uint16_t desc_id;
7063 };
7064
7065 static void
7066 cmd_read_rxd_txd_parsed(void *parsed_result,
7067                         __attribute__((unused)) struct cmdline *cl,
7068                         __attribute__((unused)) void *data)
7069 {
7070         struct cmd_read_rxd_txd_result *res = parsed_result;
7071
7072         if (!strcmp(res->rxd_txd, "rxd"))
7073                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7074         else if (!strcmp(res->rxd_txd, "txd"))
7075                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7076 }
7077
7078 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7079         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7080 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7081         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7082                                  "rxd#txd");
7083 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7084         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7085 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7086         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7087 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7088         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7089
7090 cmdline_parse_inst_t cmd_read_rxd_txd = {
7091         .f = cmd_read_rxd_txd_parsed,
7092         .data = NULL,
7093         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7094         .tokens = {
7095                 (void *)&cmd_read_rxd_txd_read,
7096                 (void *)&cmd_read_rxd_txd_rxd_txd,
7097                 (void *)&cmd_read_rxd_txd_port_id,
7098                 (void *)&cmd_read_rxd_txd_queue_id,
7099                 (void *)&cmd_read_rxd_txd_desc_id,
7100                 NULL,
7101         },
7102 };
7103
7104 /* *** QUIT *** */
7105 struct cmd_quit_result {
7106         cmdline_fixed_string_t quit;
7107 };
7108
7109 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7110                             struct cmdline *cl,
7111                             __attribute__((unused)) void *data)
7112 {
7113         pmd_test_exit();
7114         cmdline_quit(cl);
7115 }
7116
7117 cmdline_parse_token_string_t cmd_quit_quit =
7118         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7119
7120 cmdline_parse_inst_t cmd_quit = {
7121         .f = cmd_quit_parsed,
7122         .data = NULL,
7123         .help_str = "quit: Exit application",
7124         .tokens = {
7125                 (void *)&cmd_quit_quit,
7126                 NULL,
7127         },
7128 };
7129
7130 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7131 struct cmd_mac_addr_result {
7132         cmdline_fixed_string_t mac_addr_cmd;
7133         cmdline_fixed_string_t what;
7134         uint16_t port_num;
7135         struct ether_addr address;
7136 };
7137
7138 static void cmd_mac_addr_parsed(void *parsed_result,
7139                 __attribute__((unused)) struct cmdline *cl,
7140                 __attribute__((unused)) void *data)
7141 {
7142         struct cmd_mac_addr_result *res = parsed_result;
7143         int ret;
7144
7145         if (strcmp(res->what, "add") == 0)
7146                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7147         else if (strcmp(res->what, "set") == 0)
7148                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7149                                                        &res->address);
7150         else
7151                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7152
7153         /* check the return value and print it if is < 0 */
7154         if(ret < 0)
7155                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7156
7157 }
7158
7159 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7160         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7161                                 "mac_addr");
7162 cmdline_parse_token_string_t cmd_mac_addr_what =
7163         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7164                                 "add#remove#set");
7165 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7166                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7167                                         UINT16);
7168 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7169                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7170
7171 cmdline_parse_inst_t cmd_mac_addr = {
7172         .f = cmd_mac_addr_parsed,
7173         .data = (void *)0,
7174         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7175                         "Add/Remove/Set MAC address on port_id",
7176         .tokens = {
7177                 (void *)&cmd_mac_addr_cmd,
7178                 (void *)&cmd_mac_addr_what,
7179                 (void *)&cmd_mac_addr_portnum,
7180                 (void *)&cmd_mac_addr_addr,
7181                 NULL,
7182         },
7183 };
7184
7185
7186 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7187 struct cmd_set_qmap_result {
7188         cmdline_fixed_string_t set;
7189         cmdline_fixed_string_t qmap;
7190         cmdline_fixed_string_t what;
7191         portid_t port_id;
7192         uint16_t queue_id;
7193         uint8_t map_value;
7194 };
7195
7196 static void
7197 cmd_set_qmap_parsed(void *parsed_result,
7198                        __attribute__((unused)) struct cmdline *cl,
7199                        __attribute__((unused)) void *data)
7200 {
7201         struct cmd_set_qmap_result *res = parsed_result;
7202         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7203
7204         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7205 }
7206
7207 cmdline_parse_token_string_t cmd_setqmap_set =
7208         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7209                                  set, "set");
7210 cmdline_parse_token_string_t cmd_setqmap_qmap =
7211         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7212                                  qmap, "stat_qmap");
7213 cmdline_parse_token_string_t cmd_setqmap_what =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7215                                  what, "tx#rx");
7216 cmdline_parse_token_num_t cmd_setqmap_portid =
7217         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7218                               port_id, UINT16);
7219 cmdline_parse_token_num_t cmd_setqmap_queueid =
7220         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7221                               queue_id, UINT16);
7222 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7223         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7224                               map_value, UINT8);
7225
7226 cmdline_parse_inst_t cmd_set_qmap = {
7227         .f = cmd_set_qmap_parsed,
7228         .data = NULL,
7229         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7230                 "Set statistics mapping value on tx|rx queue_id of port_id",
7231         .tokens = {
7232                 (void *)&cmd_setqmap_set,
7233                 (void *)&cmd_setqmap_qmap,
7234                 (void *)&cmd_setqmap_what,
7235                 (void *)&cmd_setqmap_portid,
7236                 (void *)&cmd_setqmap_queueid,
7237                 (void *)&cmd_setqmap_mapvalue,
7238                 NULL,
7239         },
7240 };
7241
7242 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7243 struct cmd_set_xstats_hide_zero_result {
7244         cmdline_fixed_string_t keyword;
7245         cmdline_fixed_string_t name;
7246         cmdline_fixed_string_t on_off;
7247 };
7248
7249 static void
7250 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7251                         __attribute__((unused)) struct cmdline *cl,
7252                         __attribute__((unused)) void *data)
7253 {
7254         struct cmd_set_xstats_hide_zero_result *res;
7255         uint16_t on_off = 0;
7256
7257         res = parsed_result;
7258         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7259         set_xstats_hide_zero(on_off);
7260 }
7261
7262 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7263         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7264                                  keyword, "set");
7265 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7266         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7267                                  name, "xstats-hide-zero");
7268 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7269         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7270                                  on_off, "on#off");
7271
7272 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7273         .f = cmd_set_xstats_hide_zero_parsed,
7274         .data = NULL,
7275         .help_str = "set xstats-hide-zero on|off",
7276         .tokens = {
7277                 (void *)&cmd_set_xstats_hide_zero_keyword,
7278                 (void *)&cmd_set_xstats_hide_zero_name,
7279                 (void *)&cmd_set_xstats_hide_zero_on_off,
7280                 NULL,
7281         },
7282 };
7283
7284 /* *** CONFIGURE UNICAST HASH TABLE *** */
7285 struct cmd_set_uc_hash_table {
7286         cmdline_fixed_string_t set;
7287         cmdline_fixed_string_t port;
7288         portid_t port_id;
7289         cmdline_fixed_string_t what;
7290         struct ether_addr address;
7291         cmdline_fixed_string_t mode;
7292 };
7293
7294 static void
7295 cmd_set_uc_hash_parsed(void *parsed_result,
7296                        __attribute__((unused)) struct cmdline *cl,
7297                        __attribute__((unused)) void *data)
7298 {
7299         int ret=0;
7300         struct cmd_set_uc_hash_table *res = parsed_result;
7301
7302         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7303
7304         if (strcmp(res->what, "uta") == 0)
7305                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7306                                                 &res->address,(uint8_t)is_on);
7307         if (ret < 0)
7308                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7309
7310 }
7311
7312 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7313         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7314                                  set, "set");
7315 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7316         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7317                                  port, "port");
7318 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7319         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7320                               port_id, UINT16);
7321 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7322         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7323                                  what, "uta");
7324 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7325         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7326                                 address);
7327 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7328         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7329                                  mode, "on#off");
7330
7331 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7332         .f = cmd_set_uc_hash_parsed,
7333         .data = NULL,
7334         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7335         .tokens = {
7336                 (void *)&cmd_set_uc_hash_set,
7337                 (void *)&cmd_set_uc_hash_port,
7338                 (void *)&cmd_set_uc_hash_portid,
7339                 (void *)&cmd_set_uc_hash_what,
7340                 (void *)&cmd_set_uc_hash_mac,
7341                 (void *)&cmd_set_uc_hash_mode,
7342                 NULL,
7343         },
7344 };
7345
7346 struct cmd_set_uc_all_hash_table {
7347         cmdline_fixed_string_t set;
7348         cmdline_fixed_string_t port;
7349         portid_t port_id;
7350         cmdline_fixed_string_t what;
7351         cmdline_fixed_string_t value;
7352         cmdline_fixed_string_t mode;
7353 };
7354
7355 static void
7356 cmd_set_uc_all_hash_parsed(void *parsed_result,
7357                        __attribute__((unused)) struct cmdline *cl,
7358                        __attribute__((unused)) void *data)
7359 {
7360         int ret=0;
7361         struct cmd_set_uc_all_hash_table *res = parsed_result;
7362
7363         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7364
7365         if ((strcmp(res->what, "uta") == 0) &&
7366                 (strcmp(res->value, "all") == 0))
7367                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7368         if (ret < 0)
7369                 printf("bad unicast hash table parameter,"
7370                         "return code = %d \n", ret);
7371 }
7372
7373 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7374         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7375                                  set, "set");
7376 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7377         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7378                                  port, "port");
7379 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7380         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7381                               port_id, UINT16);
7382 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7383         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7384                                  what, "uta");
7385 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7386         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7387                                 value,"all");
7388 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7389         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7390                                  mode, "on#off");
7391
7392 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7393         .f = cmd_set_uc_all_hash_parsed,
7394         .data = NULL,
7395         .help_str = "set port <port_id> uta all on|off",
7396         .tokens = {
7397                 (void *)&cmd_set_uc_all_hash_set,
7398                 (void *)&cmd_set_uc_all_hash_port,
7399                 (void *)&cmd_set_uc_all_hash_portid,
7400                 (void *)&cmd_set_uc_all_hash_what,
7401                 (void *)&cmd_set_uc_all_hash_value,
7402                 (void *)&cmd_set_uc_all_hash_mode,
7403                 NULL,
7404         },
7405 };
7406
7407 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7408 struct cmd_set_vf_macvlan_filter {
7409         cmdline_fixed_string_t set;
7410         cmdline_fixed_string_t port;
7411         portid_t port_id;
7412         cmdline_fixed_string_t vf;
7413         uint8_t vf_id;
7414         struct ether_addr address;
7415         cmdline_fixed_string_t filter_type;
7416         cmdline_fixed_string_t mode;
7417 };
7418
7419 static void
7420 cmd_set_vf_macvlan_parsed(void *parsed_result,
7421                        __attribute__((unused)) struct cmdline *cl,
7422                        __attribute__((unused)) void *data)
7423 {
7424         int is_on, ret = 0;
7425         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7426         struct rte_eth_mac_filter filter;
7427
7428         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7429
7430         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7431
7432         /* set VF MAC filter */
7433         filter.is_vf = 1;
7434
7435         /* set VF ID */
7436         filter.dst_id = res->vf_id;
7437
7438         if (!strcmp(res->filter_type, "exact-mac"))
7439                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7440         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7441                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7442         else if (!strcmp(res->filter_type, "hashmac"))
7443                 filter.filter_type = RTE_MAC_HASH_MATCH;
7444         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7445                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7446
7447         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7448
7449         if (is_on)
7450                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7451                                         RTE_ETH_FILTER_MACVLAN,
7452                                         RTE_ETH_FILTER_ADD,
7453                                          &filter);
7454         else
7455                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7456                                         RTE_ETH_FILTER_MACVLAN,
7457                                         RTE_ETH_FILTER_DELETE,
7458                                         &filter);
7459
7460         if (ret < 0)
7461                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7462
7463 }
7464
7465 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7466         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7467                                  set, "set");
7468 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7469         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7470                                  port, "port");
7471 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7472         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7473                               port_id, UINT16);
7474 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7475         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7476                                  vf, "vf");
7477 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7478         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7479                                 vf_id, UINT8);
7480 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7481         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7482                                 address);
7483 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7484         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7485                                 filter_type, "exact-mac#exact-mac-vlan"
7486                                 "#hashmac#hashmac-vlan");
7487 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7488         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7489                                  mode, "on#off");
7490
7491 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7492         .f = cmd_set_vf_macvlan_parsed,
7493         .data = NULL,
7494         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7495                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7496                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7497                 "hash match rule: hash match of MAC and exact match of VLAN",
7498         .tokens = {
7499                 (void *)&cmd_set_vf_macvlan_set,
7500                 (void *)&cmd_set_vf_macvlan_port,
7501                 (void *)&cmd_set_vf_macvlan_portid,
7502                 (void *)&cmd_set_vf_macvlan_vf,
7503                 (void *)&cmd_set_vf_macvlan_vf_id,
7504                 (void *)&cmd_set_vf_macvlan_mac,
7505                 (void *)&cmd_set_vf_macvlan_filter_type,
7506                 (void *)&cmd_set_vf_macvlan_mode,
7507                 NULL,
7508         },
7509 };
7510
7511 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7512 struct cmd_set_vf_traffic {
7513         cmdline_fixed_string_t set;
7514         cmdline_fixed_string_t port;
7515         portid_t port_id;
7516         cmdline_fixed_string_t vf;
7517         uint8_t vf_id;
7518         cmdline_fixed_string_t what;
7519         cmdline_fixed_string_t mode;
7520 };
7521
7522 static void
7523 cmd_set_vf_traffic_parsed(void *parsed_result,
7524                        __attribute__((unused)) struct cmdline *cl,
7525                        __attribute__((unused)) void *data)
7526 {
7527         struct cmd_set_vf_traffic *res = parsed_result;
7528         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7529         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7530
7531         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7532 }
7533
7534 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7535         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7536                                  set, "set");
7537 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7538         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7539                                  port, "port");
7540 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7541         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7542                               port_id, UINT16);
7543 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7544         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7545                                  vf, "vf");
7546 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7547         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7548                               vf_id, UINT8);
7549 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7550         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7551                                  what, "tx#rx");
7552 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7553         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7554                                  mode, "on#off");
7555
7556 cmdline_parse_inst_t cmd_set_vf_traffic = {
7557         .f = cmd_set_vf_traffic_parsed,
7558         .data = NULL,
7559         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7560         .tokens = {
7561                 (void *)&cmd_setvf_traffic_set,
7562                 (void *)&cmd_setvf_traffic_port,
7563                 (void *)&cmd_setvf_traffic_portid,
7564                 (void *)&cmd_setvf_traffic_vf,
7565                 (void *)&cmd_setvf_traffic_vfid,
7566                 (void *)&cmd_setvf_traffic_what,
7567                 (void *)&cmd_setvf_traffic_mode,
7568                 NULL,
7569         },
7570 };
7571
7572 /* *** CONFIGURE VF RECEIVE MODE *** */
7573 struct cmd_set_vf_rxmode {
7574         cmdline_fixed_string_t set;
7575         cmdline_fixed_string_t port;
7576         portid_t port_id;
7577         cmdline_fixed_string_t vf;
7578         uint8_t vf_id;
7579         cmdline_fixed_string_t what;
7580         cmdline_fixed_string_t mode;
7581         cmdline_fixed_string_t on;
7582 };
7583
7584 static void
7585 cmd_set_vf_rxmode_parsed(void *parsed_result,
7586                        __attribute__((unused)) struct cmdline *cl,
7587                        __attribute__((unused)) void *data)
7588 {
7589         int ret = -ENOTSUP;
7590         uint16_t rx_mode = 0;
7591         struct cmd_set_vf_rxmode *res = parsed_result;
7592
7593         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7594         if (!strcmp(res->what,"rxmode")) {
7595                 if (!strcmp(res->mode, "AUPE"))
7596                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7597                 else if (!strcmp(res->mode, "ROPE"))
7598                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7599                 else if (!strcmp(res->mode, "BAM"))
7600                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7601                 else if (!strncmp(res->mode, "MPE",3))
7602                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7603         }
7604
7605         RTE_SET_USED(is_on);
7606
7607 #ifdef RTE_LIBRTE_IXGBE_PMD
7608         if (ret == -ENOTSUP)
7609                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7610                                                   rx_mode, (uint8_t)is_on);
7611 #endif
7612 #ifdef RTE_LIBRTE_BNXT_PMD
7613         if (ret == -ENOTSUP)
7614                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7615                                                  rx_mode, (uint8_t)is_on);
7616 #endif
7617         if (ret < 0)
7618                 printf("bad VF receive mode parameter, return code = %d \n",
7619                 ret);
7620 }
7621
7622 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7623         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7624                                  set, "set");
7625 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7626         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7627                                  port, "port");
7628 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7629         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7630                               port_id, UINT16);
7631 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7632         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7633                                  vf, "vf");
7634 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7635         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7636                               vf_id, UINT8);
7637 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7638         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7639                                  what, "rxmode");
7640 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7641         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7642                                  mode, "AUPE#ROPE#BAM#MPE");
7643 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7644         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7645                                  on, "on#off");
7646
7647 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7648         .f = cmd_set_vf_rxmode_parsed,
7649         .data = NULL,
7650         .help_str = "set port <port_id> vf <vf_id> rxmode "
7651                 "AUPE|ROPE|BAM|MPE on|off",
7652         .tokens = {
7653                 (void *)&cmd_set_vf_rxmode_set,
7654                 (void *)&cmd_set_vf_rxmode_port,
7655                 (void *)&cmd_set_vf_rxmode_portid,
7656                 (void *)&cmd_set_vf_rxmode_vf,
7657                 (void *)&cmd_set_vf_rxmode_vfid,
7658                 (void *)&cmd_set_vf_rxmode_what,
7659                 (void *)&cmd_set_vf_rxmode_mode,
7660                 (void *)&cmd_set_vf_rxmode_on,
7661                 NULL,
7662         },
7663 };
7664
7665 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7666 struct cmd_vf_mac_addr_result {
7667         cmdline_fixed_string_t mac_addr_cmd;
7668         cmdline_fixed_string_t what;
7669         cmdline_fixed_string_t port;
7670         uint16_t port_num;
7671         cmdline_fixed_string_t vf;
7672         uint8_t vf_num;
7673         struct ether_addr address;
7674 };
7675
7676 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7677                 __attribute__((unused)) struct cmdline *cl,
7678                 __attribute__((unused)) void *data)
7679 {
7680         struct cmd_vf_mac_addr_result *res = parsed_result;
7681         int ret = -ENOTSUP;
7682
7683         if (strcmp(res->what, "add") != 0)
7684                 return;
7685
7686 #ifdef RTE_LIBRTE_I40E_PMD
7687         if (ret == -ENOTSUP)
7688                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7689                                                    &res->address);
7690 #endif
7691 #ifdef RTE_LIBRTE_BNXT_PMD
7692         if (ret == -ENOTSUP)
7693                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7694                                                 res->vf_num);
7695 #endif
7696
7697         if(ret < 0)
7698                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7699
7700 }
7701
7702 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7703         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7704                                 mac_addr_cmd,"mac_addr");
7705 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7706         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7707                                 what,"add");
7708 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7709         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7710                                 port,"port");
7711 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7712         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7713                                 port_num, UINT16);
7714 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7715         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7716                                 vf,"vf");
7717 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7718         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7719                                 vf_num, UINT8);
7720 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7721         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7722                                 address);
7723
7724 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7725         .f = cmd_vf_mac_addr_parsed,
7726         .data = (void *)0,
7727         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7728                 "Add MAC address filtering for a VF on port_id",
7729         .tokens = {
7730                 (void *)&cmd_vf_mac_addr_cmd,
7731                 (void *)&cmd_vf_mac_addr_what,
7732                 (void *)&cmd_vf_mac_addr_port,
7733                 (void *)&cmd_vf_mac_addr_portnum,
7734                 (void *)&cmd_vf_mac_addr_vf,
7735                 (void *)&cmd_vf_mac_addr_vfnum,
7736                 (void *)&cmd_vf_mac_addr_addr,
7737                 NULL,
7738         },
7739 };
7740
7741 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7742 struct cmd_vf_rx_vlan_filter {
7743         cmdline_fixed_string_t rx_vlan;
7744         cmdline_fixed_string_t what;
7745         uint16_t vlan_id;
7746         cmdline_fixed_string_t port;
7747         portid_t port_id;
7748         cmdline_fixed_string_t vf;
7749         uint64_t vf_mask;
7750 };
7751
7752 static void
7753 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7754                           __attribute__((unused)) struct cmdline *cl,
7755                           __attribute__((unused)) void *data)
7756 {
7757         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7758         int ret = -ENOTSUP;
7759
7760         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7761
7762 #ifdef RTE_LIBRTE_IXGBE_PMD
7763         if (ret == -ENOTSUP)
7764                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7765                                 res->vlan_id, res->vf_mask, is_add);
7766 #endif
7767 #ifdef RTE_LIBRTE_I40E_PMD
7768         if (ret == -ENOTSUP)
7769                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7770                                 res->vlan_id, res->vf_mask, is_add);
7771 #endif
7772 #ifdef RTE_LIBRTE_BNXT_PMD
7773         if (ret == -ENOTSUP)
7774                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7775                                 res->vlan_id, res->vf_mask, is_add);
7776 #endif
7777
7778         switch (ret) {
7779         case 0:
7780                 break;
7781         case -EINVAL:
7782                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7783                                 res->vlan_id, res->vf_mask);
7784                 break;
7785         case -ENODEV:
7786                 printf("invalid port_id %d\n", res->port_id);
7787                 break;
7788         case -ENOTSUP:
7789                 printf("function not implemented or supported\n");
7790                 break;
7791         default:
7792                 printf("programming error: (%s)\n", strerror(-ret));
7793         }
7794 }
7795
7796 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7797         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7798                                  rx_vlan, "rx_vlan");
7799 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7800         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7801                                  what, "add#rm");
7802 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7803         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7804                               vlan_id, UINT16);
7805 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7806         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7807                                  port, "port");
7808 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7809         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7810                               port_id, UINT16);
7811 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7812         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7813                                  vf, "vf");
7814 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7815         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7816                               vf_mask, UINT64);
7817
7818 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7819         .f = cmd_vf_rx_vlan_filter_parsed,
7820         .data = NULL,
7821         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7822                 "(vf_mask = hexadecimal VF mask)",
7823         .tokens = {
7824                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7825                 (void *)&cmd_vf_rx_vlan_filter_what,
7826                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7827                 (void *)&cmd_vf_rx_vlan_filter_port,
7828                 (void *)&cmd_vf_rx_vlan_filter_portid,
7829                 (void *)&cmd_vf_rx_vlan_filter_vf,
7830                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7831                 NULL,
7832         },
7833 };
7834
7835 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7836 struct cmd_queue_rate_limit_result {
7837         cmdline_fixed_string_t set;
7838         cmdline_fixed_string_t port;
7839         uint16_t port_num;
7840         cmdline_fixed_string_t queue;
7841         uint8_t queue_num;
7842         cmdline_fixed_string_t rate;
7843         uint16_t rate_num;
7844 };
7845
7846 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7847                 __attribute__((unused)) struct cmdline *cl,
7848                 __attribute__((unused)) void *data)
7849 {
7850         struct cmd_queue_rate_limit_result *res = parsed_result;
7851         int ret = 0;
7852
7853         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7854                 && (strcmp(res->queue, "queue") == 0)
7855                 && (strcmp(res->rate, "rate") == 0))
7856                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7857                                         res->rate_num);
7858         if (ret < 0)
7859                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7860
7861 }
7862
7863 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7864         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7865                                 set, "set");
7866 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7867         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7868                                 port, "port");
7869 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7870         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7871                                 port_num, UINT16);
7872 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7873         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7874                                 queue, "queue");
7875 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7876         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7877                                 queue_num, UINT8);
7878 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7879         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7880                                 rate, "rate");
7881 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7882         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7883                                 rate_num, UINT16);
7884
7885 cmdline_parse_inst_t cmd_queue_rate_limit = {
7886         .f = cmd_queue_rate_limit_parsed,
7887         .data = (void *)0,
7888         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7889                 "Set rate limit for a queue on port_id",
7890         .tokens = {
7891                 (void *)&cmd_queue_rate_limit_set,
7892                 (void *)&cmd_queue_rate_limit_port,
7893                 (void *)&cmd_queue_rate_limit_portnum,
7894                 (void *)&cmd_queue_rate_limit_queue,
7895                 (void *)&cmd_queue_rate_limit_queuenum,
7896                 (void *)&cmd_queue_rate_limit_rate,
7897                 (void *)&cmd_queue_rate_limit_ratenum,
7898                 NULL,
7899         },
7900 };
7901
7902 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7903 struct cmd_vf_rate_limit_result {
7904         cmdline_fixed_string_t set;
7905         cmdline_fixed_string_t port;
7906         uint16_t port_num;
7907         cmdline_fixed_string_t vf;
7908         uint8_t vf_num;
7909         cmdline_fixed_string_t rate;
7910         uint16_t rate_num;
7911         cmdline_fixed_string_t q_msk;
7912         uint64_t q_msk_val;
7913 };
7914
7915 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7916                 __attribute__((unused)) struct cmdline *cl,
7917                 __attribute__((unused)) void *data)
7918 {
7919         struct cmd_vf_rate_limit_result *res = parsed_result;
7920         int ret = 0;
7921
7922         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7923                 && (strcmp(res->vf, "vf") == 0)
7924                 && (strcmp(res->rate, "rate") == 0)
7925                 && (strcmp(res->q_msk, "queue_mask") == 0))
7926                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7927                                         res->rate_num, res->q_msk_val);
7928         if (ret < 0)
7929                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7930
7931 }
7932
7933 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7934         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7935                                 set, "set");
7936 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7937         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7938                                 port, "port");
7939 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7940         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7941                                 port_num, UINT16);
7942 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7943         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7944                                 vf, "vf");
7945 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7946         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7947                                 vf_num, UINT8);
7948 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7949         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7950                                 rate, "rate");
7951 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7952         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7953                                 rate_num, UINT16);
7954 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7955         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7956                                 q_msk, "queue_mask");
7957 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7958         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7959                                 q_msk_val, UINT64);
7960
7961 cmdline_parse_inst_t cmd_vf_rate_limit = {
7962         .f = cmd_vf_rate_limit_parsed,
7963         .data = (void *)0,
7964         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7965                 "queue_mask <queue_mask_value>: "
7966                 "Set rate limit for queues of VF on port_id",
7967         .tokens = {
7968                 (void *)&cmd_vf_rate_limit_set,
7969                 (void *)&cmd_vf_rate_limit_port,
7970                 (void *)&cmd_vf_rate_limit_portnum,
7971                 (void *)&cmd_vf_rate_limit_vf,
7972                 (void *)&cmd_vf_rate_limit_vfnum,
7973                 (void *)&cmd_vf_rate_limit_rate,
7974                 (void *)&cmd_vf_rate_limit_ratenum,
7975                 (void *)&cmd_vf_rate_limit_q_msk,
7976                 (void *)&cmd_vf_rate_limit_q_msk_val,
7977                 NULL,
7978         },
7979 };
7980
7981 /* *** ADD TUNNEL FILTER OF A PORT *** */
7982 struct cmd_tunnel_filter_result {
7983         cmdline_fixed_string_t cmd;
7984         cmdline_fixed_string_t what;
7985         portid_t port_id;
7986         struct ether_addr outer_mac;
7987         struct ether_addr inner_mac;
7988         cmdline_ipaddr_t ip_value;
7989         uint16_t inner_vlan;
7990         cmdline_fixed_string_t tunnel_type;
7991         cmdline_fixed_string_t filter_type;
7992         uint32_t tenant_id;
7993         uint16_t queue_num;
7994 };
7995
7996 static void
7997 cmd_tunnel_filter_parsed(void *parsed_result,
7998                           __attribute__((unused)) struct cmdline *cl,
7999                           __attribute__((unused)) void *data)
8000 {
8001         struct cmd_tunnel_filter_result *res = parsed_result;
8002         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8003         int ret = 0;
8004
8005         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8006
8007         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8008         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8009         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8010
8011         if (res->ip_value.family == AF_INET) {
8012                 tunnel_filter_conf.ip_addr.ipv4_addr =
8013                         res->ip_value.addr.ipv4.s_addr;
8014                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8015         } else {
8016                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8017                         &(res->ip_value.addr.ipv6),
8018                         sizeof(struct in6_addr));
8019                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8020         }
8021
8022         if (!strcmp(res->filter_type, "imac-ivlan"))
8023                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8024         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8025                 tunnel_filter_conf.filter_type =
8026                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8027         else if (!strcmp(res->filter_type, "imac-tenid"))
8028                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8029         else if (!strcmp(res->filter_type, "imac"))
8030                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8031         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8032                 tunnel_filter_conf.filter_type =
8033                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8034         else if (!strcmp(res->filter_type, "oip"))
8035                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8036         else if (!strcmp(res->filter_type, "iip"))
8037                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8038         else {
8039                 printf("The filter type is not supported");
8040                 return;
8041         }
8042
8043         if (!strcmp(res->tunnel_type, "vxlan"))
8044                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8045         else if (!strcmp(res->tunnel_type, "nvgre"))
8046                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8047         else if (!strcmp(res->tunnel_type, "ipingre"))
8048                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8049         else {
8050                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8051                 return;
8052         }
8053
8054         tunnel_filter_conf.tenant_id = res->tenant_id;
8055         tunnel_filter_conf.queue_id = res->queue_num;
8056         if (!strcmp(res->what, "add"))
8057                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8058                                         RTE_ETH_FILTER_TUNNEL,
8059                                         RTE_ETH_FILTER_ADD,
8060                                         &tunnel_filter_conf);
8061         else
8062                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8063                                         RTE_ETH_FILTER_TUNNEL,
8064                                         RTE_ETH_FILTER_DELETE,
8065                                         &tunnel_filter_conf);
8066         if (ret < 0)
8067                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8068                                 strerror(-ret));
8069
8070 }
8071 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8072         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8073         cmd, "tunnel_filter");
8074 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8075         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8076         what, "add#rm");
8077 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8078         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8079         port_id, UINT16);
8080 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8081         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8082         outer_mac);
8083 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8084         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8085         inner_mac);
8086 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8087         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8088         inner_vlan, UINT16);
8089 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8090         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8091         ip_value);
8092 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8093         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8094         tunnel_type, "vxlan#nvgre#ipingre");
8095
8096 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8097         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8098         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8099                 "imac#omac-imac-tenid");
8100 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8101         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8102         tenant_id, UINT32);
8103 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8104         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8105         queue_num, UINT16);
8106
8107 cmdline_parse_inst_t cmd_tunnel_filter = {
8108         .f = cmd_tunnel_filter_parsed,
8109         .data = (void *)0,
8110         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8111                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8112                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8113                 "<queue_id>: Add/Rm tunnel filter of a port",
8114         .tokens = {
8115                 (void *)&cmd_tunnel_filter_cmd,
8116                 (void *)&cmd_tunnel_filter_what,
8117                 (void *)&cmd_tunnel_filter_port_id,
8118                 (void *)&cmd_tunnel_filter_outer_mac,
8119                 (void *)&cmd_tunnel_filter_inner_mac,
8120                 (void *)&cmd_tunnel_filter_ip_value,
8121                 (void *)&cmd_tunnel_filter_innner_vlan,
8122                 (void *)&cmd_tunnel_filter_tunnel_type,
8123                 (void *)&cmd_tunnel_filter_filter_type,
8124                 (void *)&cmd_tunnel_filter_tenant_id,
8125                 (void *)&cmd_tunnel_filter_queue_num,
8126                 NULL,
8127         },
8128 };
8129
8130 /* *** CONFIGURE TUNNEL UDP PORT *** */
8131 struct cmd_tunnel_udp_config {
8132         cmdline_fixed_string_t cmd;
8133         cmdline_fixed_string_t what;
8134         uint16_t udp_port;
8135         portid_t port_id;
8136 };
8137
8138 static void
8139 cmd_tunnel_udp_config_parsed(void *parsed_result,
8140                           __attribute__((unused)) struct cmdline *cl,
8141                           __attribute__((unused)) void *data)
8142 {
8143         struct cmd_tunnel_udp_config *res = parsed_result;
8144         struct rte_eth_udp_tunnel tunnel_udp;
8145         int ret;
8146
8147         tunnel_udp.udp_port = res->udp_port;
8148
8149         if (!strcmp(res->cmd, "rx_vxlan_port"))
8150                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8151
8152         if (!strcmp(res->what, "add"))
8153                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8154                                                       &tunnel_udp);
8155         else
8156                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8157                                                          &tunnel_udp);
8158
8159         if (ret < 0)
8160                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8161 }
8162
8163 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8164         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8165                                 cmd, "rx_vxlan_port");
8166 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8167         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8168                                 what, "add#rm");
8169 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8170         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8171                                 udp_port, UINT16);
8172 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8173         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8174                                 port_id, UINT16);
8175
8176 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8177         .f = cmd_tunnel_udp_config_parsed,
8178         .data = (void *)0,
8179         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8180                 "Add/Remove a tunneling UDP port filter",
8181         .tokens = {
8182                 (void *)&cmd_tunnel_udp_config_cmd,
8183                 (void *)&cmd_tunnel_udp_config_what,
8184                 (void *)&cmd_tunnel_udp_config_udp_port,
8185                 (void *)&cmd_tunnel_udp_config_port_id,
8186                 NULL,
8187         },
8188 };
8189
8190 /* *** GLOBAL CONFIG *** */
8191 struct cmd_global_config_result {
8192         cmdline_fixed_string_t cmd;
8193         portid_t port_id;
8194         cmdline_fixed_string_t cfg_type;
8195         uint8_t len;
8196 };
8197
8198 static void
8199 cmd_global_config_parsed(void *parsed_result,
8200                          __attribute__((unused)) struct cmdline *cl,
8201                          __attribute__((unused)) void *data)
8202 {
8203         struct cmd_global_config_result *res = parsed_result;
8204         struct rte_eth_global_cfg conf;
8205         int ret;
8206
8207         memset(&conf, 0, sizeof(conf));
8208         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8209         conf.cfg.gre_key_len = res->len;
8210         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8211                                       RTE_ETH_FILTER_SET, &conf);
8212         if (ret != 0)
8213                 printf("Global config error\n");
8214 }
8215
8216 cmdline_parse_token_string_t cmd_global_config_cmd =
8217         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8218                 "global_config");
8219 cmdline_parse_token_num_t cmd_global_config_port_id =
8220         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8221                                UINT16);
8222 cmdline_parse_token_string_t cmd_global_config_type =
8223         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8224                 cfg_type, "gre-key-len");
8225 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8226         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8227                 len, UINT8);
8228
8229 cmdline_parse_inst_t cmd_global_config = {
8230         .f = cmd_global_config_parsed,
8231         .data = (void *)NULL,
8232         .help_str = "global_config <port_id> gre-key-len <key_len>",
8233         .tokens = {
8234                 (void *)&cmd_global_config_cmd,
8235                 (void *)&cmd_global_config_port_id,
8236                 (void *)&cmd_global_config_type,
8237                 (void *)&cmd_global_config_gre_key_len,
8238                 NULL,
8239         },
8240 };
8241
8242 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8243 struct cmd_set_mirror_mask_result {
8244         cmdline_fixed_string_t set;
8245         cmdline_fixed_string_t port;
8246         portid_t port_id;
8247         cmdline_fixed_string_t mirror;
8248         uint8_t rule_id;
8249         cmdline_fixed_string_t what;
8250         cmdline_fixed_string_t value;
8251         cmdline_fixed_string_t dstpool;
8252         uint8_t dstpool_id;
8253         cmdline_fixed_string_t on;
8254 };
8255
8256 cmdline_parse_token_string_t cmd_mirror_mask_set =
8257         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8258                                 set, "set");
8259 cmdline_parse_token_string_t cmd_mirror_mask_port =
8260         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8261                                 port, "port");
8262 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8263         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8264                                 port_id, UINT16);
8265 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8266         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8267                                 mirror, "mirror-rule");
8268 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8269         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8270                                 rule_id, UINT8);
8271 cmdline_parse_token_string_t cmd_mirror_mask_what =
8272         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8273                                 what, "pool-mirror-up#pool-mirror-down"
8274                                       "#vlan-mirror");
8275 cmdline_parse_token_string_t cmd_mirror_mask_value =
8276         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8277                                 value, NULL);
8278 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8279         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8280                                 dstpool, "dst-pool");
8281 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8282         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8283                                 dstpool_id, UINT8);
8284 cmdline_parse_token_string_t cmd_mirror_mask_on =
8285         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8286                                 on, "on#off");
8287
8288 static void
8289 cmd_set_mirror_mask_parsed(void *parsed_result,
8290                        __attribute__((unused)) struct cmdline *cl,
8291                        __attribute__((unused)) void *data)
8292 {
8293         int ret,nb_item,i;
8294         struct cmd_set_mirror_mask_result *res = parsed_result;
8295         struct rte_eth_mirror_conf mr_conf;
8296
8297         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8298
8299         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8300
8301         mr_conf.dst_pool = res->dstpool_id;
8302
8303         if (!strcmp(res->what, "pool-mirror-up")) {
8304                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8305                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8306         } else if (!strcmp(res->what, "pool-mirror-down")) {
8307                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8308                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8309         } else if (!strcmp(res->what, "vlan-mirror")) {
8310                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8311                 nb_item = parse_item_list(res->value, "vlan",
8312                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8313                 if (nb_item <= 0)
8314                         return;
8315
8316                 for (i = 0; i < nb_item; i++) {
8317                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8318                                 printf("Invalid vlan_id: must be < 4096\n");
8319                                 return;
8320                         }
8321
8322                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8323                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8324                 }
8325         }
8326
8327         if (!strcmp(res->on, "on"))
8328                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8329                                                 res->rule_id, 1);
8330         else
8331                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8332                                                 res->rule_id, 0);
8333         if (ret < 0)
8334                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8335 }
8336
8337 cmdline_parse_inst_t cmd_set_mirror_mask = {
8338                 .f = cmd_set_mirror_mask_parsed,
8339                 .data = NULL,
8340                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8341                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8342                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8343                 .tokens = {
8344                         (void *)&cmd_mirror_mask_set,
8345                         (void *)&cmd_mirror_mask_port,
8346                         (void *)&cmd_mirror_mask_portid,
8347                         (void *)&cmd_mirror_mask_mirror,
8348                         (void *)&cmd_mirror_mask_ruleid,
8349                         (void *)&cmd_mirror_mask_what,
8350                         (void *)&cmd_mirror_mask_value,
8351                         (void *)&cmd_mirror_mask_dstpool,
8352                         (void *)&cmd_mirror_mask_poolid,
8353                         (void *)&cmd_mirror_mask_on,
8354                         NULL,
8355                 },
8356 };
8357
8358 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8359 struct cmd_set_mirror_link_result {
8360         cmdline_fixed_string_t set;
8361         cmdline_fixed_string_t port;
8362         portid_t port_id;
8363         cmdline_fixed_string_t mirror;
8364         uint8_t rule_id;
8365         cmdline_fixed_string_t what;
8366         cmdline_fixed_string_t dstpool;
8367         uint8_t dstpool_id;
8368         cmdline_fixed_string_t on;
8369 };
8370
8371 cmdline_parse_token_string_t cmd_mirror_link_set =
8372         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8373                                  set, "set");
8374 cmdline_parse_token_string_t cmd_mirror_link_port =
8375         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8376                                 port, "port");
8377 cmdline_parse_token_num_t cmd_mirror_link_portid =
8378         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8379                                 port_id, UINT16);
8380 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8381         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8382                                 mirror, "mirror-rule");
8383 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8384         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8385                             rule_id, UINT8);
8386 cmdline_parse_token_string_t cmd_mirror_link_what =
8387         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8388                                 what, "uplink-mirror#downlink-mirror");
8389 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8390         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8391                                 dstpool, "dst-pool");
8392 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8393         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8394                                 dstpool_id, UINT8);
8395 cmdline_parse_token_string_t cmd_mirror_link_on =
8396         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8397                                 on, "on#off");
8398
8399 static void
8400 cmd_set_mirror_link_parsed(void *parsed_result,
8401                        __attribute__((unused)) struct cmdline *cl,
8402                        __attribute__((unused)) void *data)
8403 {
8404         int ret;
8405         struct cmd_set_mirror_link_result *res = parsed_result;
8406         struct rte_eth_mirror_conf mr_conf;
8407
8408         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8409         if (!strcmp(res->what, "uplink-mirror"))
8410                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8411         else
8412                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8413
8414         mr_conf.dst_pool = res->dstpool_id;
8415
8416         if (!strcmp(res->on, "on"))
8417                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8418                                                 res->rule_id, 1);
8419         else
8420                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8421                                                 res->rule_id, 0);
8422
8423         /* check the return value and print it if is < 0 */
8424         if (ret < 0)
8425                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8426
8427 }
8428
8429 cmdline_parse_inst_t cmd_set_mirror_link = {
8430                 .f = cmd_set_mirror_link_parsed,
8431                 .data = NULL,
8432                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8433                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8434                 .tokens = {
8435                         (void *)&cmd_mirror_link_set,
8436                         (void *)&cmd_mirror_link_port,
8437                         (void *)&cmd_mirror_link_portid,
8438                         (void *)&cmd_mirror_link_mirror,
8439                         (void *)&cmd_mirror_link_ruleid,
8440                         (void *)&cmd_mirror_link_what,
8441                         (void *)&cmd_mirror_link_dstpool,
8442                         (void *)&cmd_mirror_link_poolid,
8443                         (void *)&cmd_mirror_link_on,
8444                         NULL,
8445                 },
8446 };
8447
8448 /* *** RESET VM MIRROR RULE *** */
8449 struct cmd_rm_mirror_rule_result {
8450         cmdline_fixed_string_t reset;
8451         cmdline_fixed_string_t port;
8452         portid_t port_id;
8453         cmdline_fixed_string_t mirror;
8454         uint8_t rule_id;
8455 };
8456
8457 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8458         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8459                                  reset, "reset");
8460 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8461         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8462                                 port, "port");
8463 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8464         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8465                                 port_id, UINT16);
8466 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8467         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8468                                 mirror, "mirror-rule");
8469 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8470         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8471                                 rule_id, UINT8);
8472
8473 static void
8474 cmd_reset_mirror_rule_parsed(void *parsed_result,
8475                        __attribute__((unused)) struct cmdline *cl,
8476                        __attribute__((unused)) void *data)
8477 {
8478         int ret;
8479         struct cmd_set_mirror_link_result *res = parsed_result;
8480         /* check rule_id */
8481         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8482         if(ret < 0)
8483                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8484 }
8485
8486 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8487                 .f = cmd_reset_mirror_rule_parsed,
8488                 .data = NULL,
8489                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8490                 .tokens = {
8491                         (void *)&cmd_rm_mirror_rule_reset,
8492                         (void *)&cmd_rm_mirror_rule_port,
8493                         (void *)&cmd_rm_mirror_rule_portid,
8494                         (void *)&cmd_rm_mirror_rule_mirror,
8495                         (void *)&cmd_rm_mirror_rule_ruleid,
8496                         NULL,
8497                 },
8498 };
8499
8500 /* ******************************************************************************** */
8501
8502 struct cmd_dump_result {
8503         cmdline_fixed_string_t dump;
8504 };
8505
8506 static void
8507 dump_struct_sizes(void)
8508 {
8509 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8510         DUMP_SIZE(struct rte_mbuf);
8511         DUMP_SIZE(struct rte_mempool);
8512         DUMP_SIZE(struct rte_ring);
8513 #undef DUMP_SIZE
8514 }
8515
8516 static void cmd_dump_parsed(void *parsed_result,
8517                             __attribute__((unused)) struct cmdline *cl,
8518                             __attribute__((unused)) void *data)
8519 {
8520         struct cmd_dump_result *res = parsed_result;
8521
8522         if (!strcmp(res->dump, "dump_physmem"))
8523                 rte_dump_physmem_layout(stdout);
8524         else if (!strcmp(res->dump, "dump_memzone"))
8525                 rte_memzone_dump(stdout);
8526         else if (!strcmp(res->dump, "dump_struct_sizes"))
8527                 dump_struct_sizes();
8528         else if (!strcmp(res->dump, "dump_ring"))
8529                 rte_ring_list_dump(stdout);
8530         else if (!strcmp(res->dump, "dump_mempool"))
8531                 rte_mempool_list_dump(stdout);
8532         else if (!strcmp(res->dump, "dump_devargs"))
8533                 rte_eal_devargs_dump(stdout);
8534         else if (!strcmp(res->dump, "dump_log_types"))
8535                 rte_log_dump(stdout);
8536 }
8537
8538 cmdline_parse_token_string_t cmd_dump_dump =
8539         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8540                 "dump_physmem#"
8541                 "dump_memzone#"
8542                 "dump_struct_sizes#"
8543                 "dump_ring#"
8544                 "dump_mempool#"
8545                 "dump_devargs#"
8546                 "dump_log_types");
8547
8548 cmdline_parse_inst_t cmd_dump = {
8549         .f = cmd_dump_parsed,  /* function to call */
8550         .data = NULL,      /* 2nd arg of func */
8551         .help_str = "Dump status",
8552         .tokens = {        /* token list, NULL terminated */
8553                 (void *)&cmd_dump_dump,
8554                 NULL,
8555         },
8556 };
8557
8558 /* ******************************************************************************** */
8559
8560 struct cmd_dump_one_result {
8561         cmdline_fixed_string_t dump;
8562         cmdline_fixed_string_t name;
8563 };
8564
8565 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8566                                 __attribute__((unused)) void *data)
8567 {
8568         struct cmd_dump_one_result *res = parsed_result;
8569
8570         if (!strcmp(res->dump, "dump_ring")) {
8571                 struct rte_ring *r;
8572                 r = rte_ring_lookup(res->name);
8573                 if (r == NULL) {
8574                         cmdline_printf(cl, "Cannot find ring\n");
8575                         return;
8576                 }
8577                 rte_ring_dump(stdout, r);
8578         } else if (!strcmp(res->dump, "dump_mempool")) {
8579                 struct rte_mempool *mp;
8580                 mp = rte_mempool_lookup(res->name);
8581                 if (mp == NULL) {
8582                         cmdline_printf(cl, "Cannot find mempool\n");
8583                         return;
8584                 }
8585                 rte_mempool_dump(stdout, mp);
8586         }
8587 }
8588
8589 cmdline_parse_token_string_t cmd_dump_one_dump =
8590         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8591                                  "dump_ring#dump_mempool");
8592
8593 cmdline_parse_token_string_t cmd_dump_one_name =
8594         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8595
8596 cmdline_parse_inst_t cmd_dump_one = {
8597         .f = cmd_dump_one_parsed,  /* function to call */
8598         .data = NULL,      /* 2nd arg of func */
8599         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8600         .tokens = {        /* token list, NULL terminated */
8601                 (void *)&cmd_dump_one_dump,
8602                 (void *)&cmd_dump_one_name,
8603                 NULL,
8604         },
8605 };
8606
8607 /* *** Add/Del syn filter *** */
8608 struct cmd_syn_filter_result {
8609         cmdline_fixed_string_t filter;
8610         portid_t port_id;
8611         cmdline_fixed_string_t ops;
8612         cmdline_fixed_string_t priority;
8613         cmdline_fixed_string_t high;
8614         cmdline_fixed_string_t queue;
8615         uint16_t queue_id;
8616 };
8617
8618 static void
8619 cmd_syn_filter_parsed(void *parsed_result,
8620                         __attribute__((unused)) struct cmdline *cl,
8621                         __attribute__((unused)) void *data)
8622 {
8623         struct cmd_syn_filter_result *res = parsed_result;
8624         struct rte_eth_syn_filter syn_filter;
8625         int ret = 0;
8626
8627         ret = rte_eth_dev_filter_supported(res->port_id,
8628                                         RTE_ETH_FILTER_SYN);
8629         if (ret < 0) {
8630                 printf("syn filter is not supported on port %u.\n",
8631                                 res->port_id);
8632                 return;
8633         }
8634
8635         memset(&syn_filter, 0, sizeof(syn_filter));
8636
8637         if (!strcmp(res->ops, "add")) {
8638                 if (!strcmp(res->high, "high"))
8639                         syn_filter.hig_pri = 1;
8640                 else
8641                         syn_filter.hig_pri = 0;
8642
8643                 syn_filter.queue = res->queue_id;
8644                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8645                                                 RTE_ETH_FILTER_SYN,
8646                                                 RTE_ETH_FILTER_ADD,
8647                                                 &syn_filter);
8648         } else
8649                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8650                                                 RTE_ETH_FILTER_SYN,
8651                                                 RTE_ETH_FILTER_DELETE,
8652                                                 &syn_filter);
8653
8654         if (ret < 0)
8655                 printf("syn filter programming error: (%s)\n",
8656                                 strerror(-ret));
8657 }
8658
8659 cmdline_parse_token_string_t cmd_syn_filter_filter =
8660         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8661         filter, "syn_filter");
8662 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8663         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8664         port_id, UINT16);
8665 cmdline_parse_token_string_t cmd_syn_filter_ops =
8666         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8667         ops, "add#del");
8668 cmdline_parse_token_string_t cmd_syn_filter_priority =
8669         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8670                                 priority, "priority");
8671 cmdline_parse_token_string_t cmd_syn_filter_high =
8672         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8673                                 high, "high#low");
8674 cmdline_parse_token_string_t cmd_syn_filter_queue =
8675         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8676                                 queue, "queue");
8677 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8678         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8679                                 queue_id, UINT16);
8680
8681 cmdline_parse_inst_t cmd_syn_filter = {
8682         .f = cmd_syn_filter_parsed,
8683         .data = NULL,
8684         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8685                 "<queue_id>: Add/Delete syn filter",
8686         .tokens = {
8687                 (void *)&cmd_syn_filter_filter,
8688                 (void *)&cmd_syn_filter_port_id,
8689                 (void *)&cmd_syn_filter_ops,
8690                 (void *)&cmd_syn_filter_priority,
8691                 (void *)&cmd_syn_filter_high,
8692                 (void *)&cmd_syn_filter_queue,
8693                 (void *)&cmd_syn_filter_queue_id,
8694                 NULL,
8695         },
8696 };
8697
8698 /* *** queue region set *** */
8699 struct cmd_queue_region_result {
8700         cmdline_fixed_string_t set;
8701         cmdline_fixed_string_t port;
8702         portid_t port_id;
8703         cmdline_fixed_string_t cmd;
8704         cmdline_fixed_string_t region;
8705         uint8_t  region_id;
8706         cmdline_fixed_string_t queue_start_index;
8707         uint8_t  queue_id;
8708         cmdline_fixed_string_t queue_num;
8709         uint8_t  queue_num_value;
8710 };
8711
8712 static void
8713 cmd_queue_region_parsed(void *parsed_result,
8714                         __attribute__((unused)) struct cmdline *cl,
8715                         __attribute__((unused)) void *data)
8716 {
8717         struct cmd_queue_region_result *res = parsed_result;
8718         int ret = -ENOTSUP;
8719 #ifdef RTE_LIBRTE_I40E_PMD
8720         struct rte_pmd_i40e_queue_region_conf region_conf;
8721         enum rte_pmd_i40e_queue_region_op op_type;
8722 #endif
8723
8724         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8725                 return;
8726
8727 #ifdef RTE_LIBRTE_I40E_PMD
8728         memset(&region_conf, 0, sizeof(region_conf));
8729         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8730         region_conf.region_id = res->region_id;
8731         region_conf.queue_num = res->queue_num_value;
8732         region_conf.queue_start_index = res->queue_id;
8733
8734         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8735                                 op_type, &region_conf);
8736 #endif
8737
8738         switch (ret) {
8739         case 0:
8740                 break;
8741         case -ENOTSUP:
8742                 printf("function not implemented or supported\n");
8743                 break;
8744         default:
8745                 printf("queue region config error: (%s)\n", strerror(-ret));
8746         }
8747 }
8748
8749 cmdline_parse_token_string_t cmd_queue_region_set =
8750 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8751                 set, "set");
8752 cmdline_parse_token_string_t cmd_queue_region_port =
8753         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8754 cmdline_parse_token_num_t cmd_queue_region_port_id =
8755         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8756                                 port_id, UINT16);
8757 cmdline_parse_token_string_t cmd_queue_region_cmd =
8758         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8759                                  cmd, "queue-region");
8760 cmdline_parse_token_string_t cmd_queue_region_id =
8761         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8762                                 region, "region_id");
8763 cmdline_parse_token_num_t cmd_queue_region_index =
8764         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8765                                 region_id, UINT8);
8766 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8767         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8768                                 queue_start_index, "queue_start_index");
8769 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8770         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8771                                 queue_id, UINT8);
8772 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8773         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8774                                 queue_num, "queue_num");
8775 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8776         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8777                                 queue_num_value, UINT8);
8778
8779 cmdline_parse_inst_t cmd_queue_region = {
8780         .f = cmd_queue_region_parsed,
8781         .data = NULL,
8782         .help_str = "set port <port_id> queue-region region_id <value> "
8783                 "queue_start_index <value> queue_num <value>: Set a queue region",
8784         .tokens = {
8785                 (void *)&cmd_queue_region_set,
8786                 (void *)&cmd_queue_region_port,
8787                 (void *)&cmd_queue_region_port_id,
8788                 (void *)&cmd_queue_region_cmd,
8789                 (void *)&cmd_queue_region_id,
8790                 (void *)&cmd_queue_region_index,
8791                 (void *)&cmd_queue_region_queue_start_index,
8792                 (void *)&cmd_queue_region_queue_id,
8793                 (void *)&cmd_queue_region_queue_num,
8794                 (void *)&cmd_queue_region_queue_num_value,
8795                 NULL,
8796         },
8797 };
8798
8799 /* *** queue region and flowtype set *** */
8800 struct cmd_region_flowtype_result {
8801         cmdline_fixed_string_t set;
8802         cmdline_fixed_string_t port;
8803         portid_t port_id;
8804         cmdline_fixed_string_t cmd;
8805         cmdline_fixed_string_t region;
8806         uint8_t  region_id;
8807         cmdline_fixed_string_t flowtype;
8808         uint8_t  flowtype_id;
8809 };
8810
8811 static void
8812 cmd_region_flowtype_parsed(void *parsed_result,
8813                         __attribute__((unused)) struct cmdline *cl,
8814                         __attribute__((unused)) void *data)
8815 {
8816         struct cmd_region_flowtype_result *res = parsed_result;
8817         int ret = -ENOTSUP;
8818 #ifdef RTE_LIBRTE_I40E_PMD
8819         struct rte_pmd_i40e_queue_region_conf region_conf;
8820         enum rte_pmd_i40e_queue_region_op op_type;
8821 #endif
8822
8823         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8824                 return;
8825
8826 #ifdef RTE_LIBRTE_I40E_PMD
8827         memset(&region_conf, 0, sizeof(region_conf));
8828
8829         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8830         region_conf.region_id = res->region_id;
8831         region_conf.hw_flowtype = res->flowtype_id;
8832
8833         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8834                         op_type, &region_conf);
8835 #endif
8836
8837         switch (ret) {
8838         case 0:
8839                 break;
8840         case -ENOTSUP:
8841                 printf("function not implemented or supported\n");
8842                 break;
8843         default:
8844                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8845         }
8846 }
8847
8848 cmdline_parse_token_string_t cmd_region_flowtype_set =
8849 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8850                                 set, "set");
8851 cmdline_parse_token_string_t cmd_region_flowtype_port =
8852         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8853                                 port, "port");
8854 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8855         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8856                                 port_id, UINT16);
8857 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8858         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8859                                 cmd, "queue-region");
8860 cmdline_parse_token_string_t cmd_region_flowtype_index =
8861         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8862                                 region, "region_id");
8863 cmdline_parse_token_num_t cmd_region_flowtype_id =
8864         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8865                                 region_id, UINT8);
8866 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8867         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8868                                 flowtype, "flowtype");
8869 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8870         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8871                                 flowtype_id, UINT8);
8872 cmdline_parse_inst_t cmd_region_flowtype = {
8873         .f = cmd_region_flowtype_parsed,
8874         .data = NULL,
8875         .help_str = "set port <port_id> queue-region region_id <value> "
8876                 "flowtype <value>: Set a flowtype region index",
8877         .tokens = {
8878                 (void *)&cmd_region_flowtype_set,
8879                 (void *)&cmd_region_flowtype_port,
8880                 (void *)&cmd_region_flowtype_port_index,
8881                 (void *)&cmd_region_flowtype_cmd,
8882                 (void *)&cmd_region_flowtype_index,
8883                 (void *)&cmd_region_flowtype_id,
8884                 (void *)&cmd_region_flowtype_flow_index,
8885                 (void *)&cmd_region_flowtype_flow_id,
8886                 NULL,
8887         },
8888 };
8889
8890 /* *** User Priority (UP) to queue region (region_id) set *** */
8891 struct cmd_user_priority_region_result {
8892         cmdline_fixed_string_t set;
8893         cmdline_fixed_string_t port;
8894         portid_t port_id;
8895         cmdline_fixed_string_t cmd;
8896         cmdline_fixed_string_t user_priority;
8897         uint8_t  user_priority_id;
8898         cmdline_fixed_string_t region;
8899         uint8_t  region_id;
8900 };
8901
8902 static void
8903 cmd_user_priority_region_parsed(void *parsed_result,
8904                         __attribute__((unused)) struct cmdline *cl,
8905                         __attribute__((unused)) void *data)
8906 {
8907         struct cmd_user_priority_region_result *res = parsed_result;
8908         int ret = -ENOTSUP;
8909 #ifdef RTE_LIBRTE_I40E_PMD
8910         struct rte_pmd_i40e_queue_region_conf region_conf;
8911         enum rte_pmd_i40e_queue_region_op op_type;
8912 #endif
8913
8914         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8915                 return;
8916
8917 #ifdef RTE_LIBRTE_I40E_PMD
8918         memset(&region_conf, 0, sizeof(region_conf));
8919         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8920         region_conf.user_priority = res->user_priority_id;
8921         region_conf.region_id = res->region_id;
8922
8923         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8924                                 op_type, &region_conf);
8925 #endif
8926
8927         switch (ret) {
8928         case 0:
8929                 break;
8930         case -ENOTSUP:
8931                 printf("function not implemented or supported\n");
8932                 break;
8933         default:
8934                 printf("user_priority region config error: (%s)\n",
8935                                 strerror(-ret));
8936         }
8937 }
8938
8939 cmdline_parse_token_string_t cmd_user_priority_region_set =
8940         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8941                                 set, "set");
8942 cmdline_parse_token_string_t cmd_user_priority_region_port =
8943         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8944                                 port, "port");
8945 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8946         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8947                                 port_id, UINT16);
8948 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8949         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8950                                 cmd, "queue-region");
8951 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8952         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8953                                 user_priority, "UP");
8954 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8955         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8956                                 user_priority_id, UINT8);
8957 cmdline_parse_token_string_t cmd_user_priority_region_region =
8958         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8959                                 region, "region_id");
8960 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8961         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8962                                 region_id, UINT8);
8963
8964 cmdline_parse_inst_t cmd_user_priority_region = {
8965         .f = cmd_user_priority_region_parsed,
8966         .data = NULL,
8967         .help_str = "set port <port_id> queue-region UP <value> "
8968                 "region_id <value>: Set the mapping of User Priority (UP) "
8969                 "to queue region (region_id) ",
8970         .tokens = {
8971                 (void *)&cmd_user_priority_region_set,
8972                 (void *)&cmd_user_priority_region_port,
8973                 (void *)&cmd_user_priority_region_port_index,
8974                 (void *)&cmd_user_priority_region_cmd,
8975                 (void *)&cmd_user_priority_region_UP,
8976                 (void *)&cmd_user_priority_region_UP_id,
8977                 (void *)&cmd_user_priority_region_region,
8978                 (void *)&cmd_user_priority_region_region_id,
8979                 NULL,
8980         },
8981 };
8982
8983 /* *** flush all queue region related configuration *** */
8984 struct cmd_flush_queue_region_result {
8985         cmdline_fixed_string_t set;
8986         cmdline_fixed_string_t port;
8987         portid_t port_id;
8988         cmdline_fixed_string_t cmd;
8989         cmdline_fixed_string_t flush;
8990         cmdline_fixed_string_t what;
8991 };
8992
8993 static void
8994 cmd_flush_queue_region_parsed(void *parsed_result,
8995                         __attribute__((unused)) struct cmdline *cl,
8996                         __attribute__((unused)) void *data)
8997 {
8998         struct cmd_flush_queue_region_result *res = parsed_result;
8999         int ret = -ENOTSUP;
9000 #ifdef RTE_LIBRTE_I40E_PMD
9001         struct rte_pmd_i40e_queue_region_conf region_conf;
9002         enum rte_pmd_i40e_queue_region_op op_type;
9003 #endif
9004
9005         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9006                 return;
9007
9008 #ifdef RTE_LIBRTE_I40E_PMD
9009         memset(&region_conf, 0, sizeof(region_conf));
9010
9011         if (strcmp(res->what, "on") == 0)
9012                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9013         else
9014                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9015
9016         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9017                                 op_type, &region_conf);
9018 #endif
9019
9020         switch (ret) {
9021         case 0:
9022                 break;
9023         case -ENOTSUP:
9024                 printf("function not implemented or supported\n");
9025                 break;
9026         default:
9027                 printf("queue region config flush error: (%s)\n",
9028                                 strerror(-ret));
9029         }
9030 }
9031
9032 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9033         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9034                                 set, "set");
9035 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9036         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9037                                 port, "port");
9038 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9039         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9040                                 port_id, UINT16);
9041 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9042         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9043                                 cmd, "queue-region");
9044 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9045         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9046                                 flush, "flush");
9047 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9048         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9049                                 what, "on#off");
9050
9051 cmdline_parse_inst_t cmd_flush_queue_region = {
9052         .f = cmd_flush_queue_region_parsed,
9053         .data = NULL,
9054         .help_str = "set port <port_id> queue-region flush on|off"
9055                 ": flush all queue region related configuration",
9056         .tokens = {
9057                 (void *)&cmd_flush_queue_region_set,
9058                 (void *)&cmd_flush_queue_region_port,
9059                 (void *)&cmd_flush_queue_region_port_index,
9060                 (void *)&cmd_flush_queue_region_cmd,
9061                 (void *)&cmd_flush_queue_region_flush,
9062                 (void *)&cmd_flush_queue_region_what,
9063                 NULL,
9064         },
9065 };
9066
9067 /* *** get all queue region related configuration info *** */
9068 struct cmd_show_queue_region_info {
9069         cmdline_fixed_string_t show;
9070         cmdline_fixed_string_t port;
9071         portid_t port_id;
9072         cmdline_fixed_string_t cmd;
9073 };
9074
9075 static void
9076 cmd_show_queue_region_info_parsed(void *parsed_result,
9077                         __attribute__((unused)) struct cmdline *cl,
9078                         __attribute__((unused)) void *data)
9079 {
9080         struct cmd_show_queue_region_info *res = parsed_result;
9081         int ret = -ENOTSUP;
9082 #ifdef RTE_LIBRTE_I40E_PMD
9083         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9084         enum rte_pmd_i40e_queue_region_op op_type;
9085 #endif
9086
9087         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9088                 return;
9089
9090 #ifdef RTE_LIBRTE_I40E_PMD
9091         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9092
9093         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9094
9095         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9096                                         op_type, &rte_pmd_regions);
9097
9098         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9099 #endif
9100
9101         switch (ret) {
9102         case 0:
9103                 break;
9104         case -ENOTSUP:
9105                 printf("function not implemented or supported\n");
9106                 break;
9107         default:
9108                 printf("queue region config info show error: (%s)\n",
9109                                 strerror(-ret));
9110         }
9111 }
9112
9113 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9114 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9115                                 show, "show");
9116 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9117         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9118                                 port, "port");
9119 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9120         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9121                                 port_id, UINT16);
9122 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9123         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9124                                 cmd, "queue-region");
9125
9126 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9127         .f = cmd_show_queue_region_info_parsed,
9128         .data = NULL,
9129         .help_str = "show port <port_id> queue-region"
9130                 ": show all queue region related configuration info",
9131         .tokens = {
9132                 (void *)&cmd_show_queue_region_info_get,
9133                 (void *)&cmd_show_queue_region_info_port,
9134                 (void *)&cmd_show_queue_region_info_port_index,
9135                 (void *)&cmd_show_queue_region_info_cmd,
9136                 NULL,
9137         },
9138 };
9139
9140 /* *** ADD/REMOVE A 2tuple FILTER *** */
9141 struct cmd_2tuple_filter_result {
9142         cmdline_fixed_string_t filter;
9143         portid_t port_id;
9144         cmdline_fixed_string_t ops;
9145         cmdline_fixed_string_t dst_port;
9146         uint16_t dst_port_value;
9147         cmdline_fixed_string_t protocol;
9148         uint8_t protocol_value;
9149         cmdline_fixed_string_t mask;
9150         uint8_t  mask_value;
9151         cmdline_fixed_string_t tcp_flags;
9152         uint8_t tcp_flags_value;
9153         cmdline_fixed_string_t priority;
9154         uint8_t  priority_value;
9155         cmdline_fixed_string_t queue;
9156         uint16_t  queue_id;
9157 };
9158
9159 static void
9160 cmd_2tuple_filter_parsed(void *parsed_result,
9161                         __attribute__((unused)) struct cmdline *cl,
9162                         __attribute__((unused)) void *data)
9163 {
9164         struct rte_eth_ntuple_filter filter;
9165         struct cmd_2tuple_filter_result *res = parsed_result;
9166         int ret = 0;
9167
9168         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9169         if (ret < 0) {
9170                 printf("ntuple filter is not supported on port %u.\n",
9171                         res->port_id);
9172                 return;
9173         }
9174
9175         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9176
9177         filter.flags = RTE_2TUPLE_FLAGS;
9178         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9179         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9180         filter.proto = res->protocol_value;
9181         filter.priority = res->priority_value;
9182         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9183                 printf("nonzero tcp_flags is only meaningful"
9184                         " when protocol is TCP.\n");
9185                 return;
9186         }
9187         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9188                 printf("invalid TCP flags.\n");
9189                 return;
9190         }
9191
9192         if (res->tcp_flags_value != 0) {
9193                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9194                 filter.tcp_flags = res->tcp_flags_value;
9195         }
9196
9197         /* need convert to big endian. */
9198         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9199         filter.queue = res->queue_id;
9200
9201         if (!strcmp(res->ops, "add"))
9202                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9203                                 RTE_ETH_FILTER_NTUPLE,
9204                                 RTE_ETH_FILTER_ADD,
9205                                 &filter);
9206         else
9207                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9208                                 RTE_ETH_FILTER_NTUPLE,
9209                                 RTE_ETH_FILTER_DELETE,
9210                                 &filter);
9211         if (ret < 0)
9212                 printf("2tuple filter programming error: (%s)\n",
9213                         strerror(-ret));
9214
9215 }
9216
9217 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9218         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9219                                  filter, "2tuple_filter");
9220 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9221         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9222                                 port_id, UINT16);
9223 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9224         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9225                                  ops, "add#del");
9226 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9227         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9228                                 dst_port, "dst_port");
9229 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9230         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9231                                 dst_port_value, UINT16);
9232 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9233         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9234                                 protocol, "protocol");
9235 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9236         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9237                                 protocol_value, UINT8);
9238 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9239         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9240                                 mask, "mask");
9241 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9242         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9243                                 mask_value, INT8);
9244 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9245         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9246                                 tcp_flags, "tcp_flags");
9247 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9248         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9249                                 tcp_flags_value, UINT8);
9250 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9251         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9252                                 priority, "priority");
9253 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9254         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9255                                 priority_value, UINT8);
9256 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9257         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9258                                 queue, "queue");
9259 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9260         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9261                                 queue_id, UINT16);
9262
9263 cmdline_parse_inst_t cmd_2tuple_filter = {
9264         .f = cmd_2tuple_filter_parsed,
9265         .data = NULL,
9266         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9267                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9268                 "<queue_id>: Add a 2tuple filter",
9269         .tokens = {
9270                 (void *)&cmd_2tuple_filter_filter,
9271                 (void *)&cmd_2tuple_filter_port_id,
9272                 (void *)&cmd_2tuple_filter_ops,
9273                 (void *)&cmd_2tuple_filter_dst_port,
9274                 (void *)&cmd_2tuple_filter_dst_port_value,
9275                 (void *)&cmd_2tuple_filter_protocol,
9276                 (void *)&cmd_2tuple_filter_protocol_value,
9277                 (void *)&cmd_2tuple_filter_mask,
9278                 (void *)&cmd_2tuple_filter_mask_value,
9279                 (void *)&cmd_2tuple_filter_tcp_flags,
9280                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9281                 (void *)&cmd_2tuple_filter_priority,
9282                 (void *)&cmd_2tuple_filter_priority_value,
9283                 (void *)&cmd_2tuple_filter_queue,
9284                 (void *)&cmd_2tuple_filter_queue_id,
9285                 NULL,
9286         },
9287 };
9288
9289 /* *** ADD/REMOVE A 5tuple FILTER *** */
9290 struct cmd_5tuple_filter_result {
9291         cmdline_fixed_string_t filter;
9292         portid_t port_id;
9293         cmdline_fixed_string_t ops;
9294         cmdline_fixed_string_t dst_ip;
9295         cmdline_ipaddr_t dst_ip_value;
9296         cmdline_fixed_string_t src_ip;
9297         cmdline_ipaddr_t src_ip_value;
9298         cmdline_fixed_string_t dst_port;
9299         uint16_t dst_port_value;
9300         cmdline_fixed_string_t src_port;
9301         uint16_t src_port_value;
9302         cmdline_fixed_string_t protocol;
9303         uint8_t protocol_value;
9304         cmdline_fixed_string_t mask;
9305         uint8_t  mask_value;
9306         cmdline_fixed_string_t tcp_flags;
9307         uint8_t tcp_flags_value;
9308         cmdline_fixed_string_t priority;
9309         uint8_t  priority_value;
9310         cmdline_fixed_string_t queue;
9311         uint16_t  queue_id;
9312 };
9313
9314 static void
9315 cmd_5tuple_filter_parsed(void *parsed_result,
9316                         __attribute__((unused)) struct cmdline *cl,
9317                         __attribute__((unused)) void *data)
9318 {
9319         struct rte_eth_ntuple_filter filter;
9320         struct cmd_5tuple_filter_result *res = parsed_result;
9321         int ret = 0;
9322
9323         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9324         if (ret < 0) {
9325                 printf("ntuple filter is not supported on port %u.\n",
9326                         res->port_id);
9327                 return;
9328         }
9329
9330         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9331
9332         filter.flags = RTE_5TUPLE_FLAGS;
9333         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9334         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9335         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9336         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9337         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9338         filter.proto = res->protocol_value;
9339         filter.priority = res->priority_value;
9340         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9341                 printf("nonzero tcp_flags is only meaningful"
9342                         " when protocol is TCP.\n");
9343                 return;
9344         }
9345         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9346                 printf("invalid TCP flags.\n");
9347                 return;
9348         }
9349
9350         if (res->tcp_flags_value != 0) {
9351                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9352                 filter.tcp_flags = res->tcp_flags_value;
9353         }
9354
9355         if (res->dst_ip_value.family == AF_INET)
9356                 /* no need to convert, already big endian. */
9357                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9358         else {
9359                 if (filter.dst_ip_mask == 0) {
9360                         printf("can not support ipv6 involved compare.\n");
9361                         return;
9362                 }
9363                 filter.dst_ip = 0;
9364         }
9365
9366         if (res->src_ip_value.family == AF_INET)
9367                 /* no need to convert, already big endian. */
9368                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9369         else {
9370                 if (filter.src_ip_mask == 0) {
9371                         printf("can not support ipv6 involved compare.\n");
9372                         return;
9373                 }
9374                 filter.src_ip = 0;
9375         }
9376         /* need convert to big endian. */
9377         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9378         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9379         filter.queue = res->queue_id;
9380
9381         if (!strcmp(res->ops, "add"))
9382                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9383                                 RTE_ETH_FILTER_NTUPLE,
9384                                 RTE_ETH_FILTER_ADD,
9385                                 &filter);
9386         else
9387                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9388                                 RTE_ETH_FILTER_NTUPLE,
9389                                 RTE_ETH_FILTER_DELETE,
9390                                 &filter);
9391         if (ret < 0)
9392                 printf("5tuple filter programming error: (%s)\n",
9393                         strerror(-ret));
9394 }
9395
9396 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9397         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9398                                  filter, "5tuple_filter");
9399 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9400         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9401                                 port_id, UINT16);
9402 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9403         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9404                                  ops, "add#del");
9405 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9406         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9407                                 dst_ip, "dst_ip");
9408 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9409         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9410                                 dst_ip_value);
9411 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9412         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9413                                 src_ip, "src_ip");
9414 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9415         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9416                                 src_ip_value);
9417 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9418         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9419                                 dst_port, "dst_port");
9420 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9421         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9422                                 dst_port_value, UINT16);
9423 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9424         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9425                                 src_port, "src_port");
9426 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9427         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9428                                 src_port_value, UINT16);
9429 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9430         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9431                                 protocol, "protocol");
9432 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9433         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9434                                 protocol_value, UINT8);
9435 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9436         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9437                                 mask, "mask");
9438 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9439         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9440                                 mask_value, INT8);
9441 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9442         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9443                                 tcp_flags, "tcp_flags");
9444 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9445         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9446                                 tcp_flags_value, UINT8);
9447 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9448         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9449                                 priority, "priority");
9450 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9451         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9452                                 priority_value, UINT8);
9453 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9454         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9455                                 queue, "queue");
9456 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9457         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9458                                 queue_id, UINT16);
9459
9460 cmdline_parse_inst_t cmd_5tuple_filter = {
9461         .f = cmd_5tuple_filter_parsed,
9462         .data = NULL,
9463         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9464                 "src_ip <value> dst_port <value> src_port <value> "
9465                 "protocol <value>  mask <value> tcp_flags <value> "
9466                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9467         .tokens = {
9468                 (void *)&cmd_5tuple_filter_filter,
9469                 (void *)&cmd_5tuple_filter_port_id,
9470                 (void *)&cmd_5tuple_filter_ops,
9471                 (void *)&cmd_5tuple_filter_dst_ip,
9472                 (void *)&cmd_5tuple_filter_dst_ip_value,
9473                 (void *)&cmd_5tuple_filter_src_ip,
9474                 (void *)&cmd_5tuple_filter_src_ip_value,
9475                 (void *)&cmd_5tuple_filter_dst_port,
9476                 (void *)&cmd_5tuple_filter_dst_port_value,
9477                 (void *)&cmd_5tuple_filter_src_port,
9478                 (void *)&cmd_5tuple_filter_src_port_value,
9479                 (void *)&cmd_5tuple_filter_protocol,
9480                 (void *)&cmd_5tuple_filter_protocol_value,
9481                 (void *)&cmd_5tuple_filter_mask,
9482                 (void *)&cmd_5tuple_filter_mask_value,
9483                 (void *)&cmd_5tuple_filter_tcp_flags,
9484                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9485                 (void *)&cmd_5tuple_filter_priority,
9486                 (void *)&cmd_5tuple_filter_priority_value,
9487                 (void *)&cmd_5tuple_filter_queue,
9488                 (void *)&cmd_5tuple_filter_queue_id,
9489                 NULL,
9490         },
9491 };
9492
9493 /* *** ADD/REMOVE A flex FILTER *** */
9494 struct cmd_flex_filter_result {
9495         cmdline_fixed_string_t filter;
9496         cmdline_fixed_string_t ops;
9497         portid_t port_id;
9498         cmdline_fixed_string_t len;
9499         uint8_t len_value;
9500         cmdline_fixed_string_t bytes;
9501         cmdline_fixed_string_t bytes_value;
9502         cmdline_fixed_string_t mask;
9503         cmdline_fixed_string_t mask_value;
9504         cmdline_fixed_string_t priority;
9505         uint8_t priority_value;
9506         cmdline_fixed_string_t queue;
9507         uint16_t queue_id;
9508 };
9509
9510 static int xdigit2val(unsigned char c)
9511 {
9512         int val;
9513         if (isdigit(c))
9514                 val = c - '0';
9515         else if (isupper(c))
9516                 val = c - 'A' + 10;
9517         else
9518                 val = c - 'a' + 10;
9519         return val;
9520 }
9521
9522 static void
9523 cmd_flex_filter_parsed(void *parsed_result,
9524                           __attribute__((unused)) struct cmdline *cl,
9525                           __attribute__((unused)) void *data)
9526 {
9527         int ret = 0;
9528         struct rte_eth_flex_filter filter;
9529         struct cmd_flex_filter_result *res = parsed_result;
9530         char *bytes_ptr, *mask_ptr;
9531         uint16_t len, i, j = 0;
9532         char c;
9533         int val;
9534         uint8_t byte = 0;
9535
9536         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9537                 printf("the len exceed the max length 128\n");
9538                 return;
9539         }
9540         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9541         filter.len = res->len_value;
9542         filter.priority = res->priority_value;
9543         filter.queue = res->queue_id;
9544         bytes_ptr = res->bytes_value;
9545         mask_ptr = res->mask_value;
9546
9547          /* translate bytes string to array. */
9548         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9549                 (bytes_ptr[1] == 'X')))
9550                 bytes_ptr += 2;
9551         len = strnlen(bytes_ptr, res->len_value * 2);
9552         if (len == 0 || (len % 8 != 0)) {
9553                 printf("please check len and bytes input\n");
9554                 return;
9555         }
9556         for (i = 0; i < len; i++) {
9557                 c = bytes_ptr[i];
9558                 if (isxdigit(c) == 0) {
9559                         /* invalid characters. */
9560                         printf("invalid input\n");
9561                         return;
9562                 }
9563                 val = xdigit2val(c);
9564                 if (i % 2) {
9565                         byte |= val;
9566                         filter.bytes[j] = byte;
9567                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9568                         j++;
9569                         byte = 0;
9570                 } else
9571                         byte |= val << 4;
9572         }
9573         printf("\n");
9574          /* translate mask string to uint8_t array. */
9575         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9576                 (mask_ptr[1] == 'X')))
9577                 mask_ptr += 2;
9578         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9579         if (len == 0) {
9580                 printf("invalid input\n");
9581                 return;
9582         }
9583         j = 0;
9584         byte = 0;
9585         for (i = 0; i < len; i++) {
9586                 c = mask_ptr[i];
9587                 if (isxdigit(c) == 0) {
9588                         /* invalid characters. */
9589                         printf("invalid input\n");
9590                         return;
9591                 }
9592                 val = xdigit2val(c);
9593                 if (i % 2) {
9594                         byte |= val;
9595                         filter.mask[j] = byte;
9596                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9597                         j++;
9598                         byte = 0;
9599                 } else
9600                         byte |= val << 4;
9601         }
9602         printf("\n");
9603
9604         if (!strcmp(res->ops, "add"))
9605                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9606                                 RTE_ETH_FILTER_FLEXIBLE,
9607                                 RTE_ETH_FILTER_ADD,
9608                                 &filter);
9609         else
9610                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9611                                 RTE_ETH_FILTER_FLEXIBLE,
9612                                 RTE_ETH_FILTER_DELETE,
9613                                 &filter);
9614
9615         if (ret < 0)
9616                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9617 }
9618
9619 cmdline_parse_token_string_t cmd_flex_filter_filter =
9620         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9621                                 filter, "flex_filter");
9622 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9623         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9624                                 port_id, UINT16);
9625 cmdline_parse_token_string_t cmd_flex_filter_ops =
9626         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9627                                 ops, "add#del");
9628 cmdline_parse_token_string_t cmd_flex_filter_len =
9629         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9630                                 len, "len");
9631 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9632         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9633                                 len_value, UINT8);
9634 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9635         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9636                                 bytes, "bytes");
9637 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9638         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9639                                 bytes_value, NULL);
9640 cmdline_parse_token_string_t cmd_flex_filter_mask =
9641         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9642                                 mask, "mask");
9643 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9644         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9645                                 mask_value, NULL);
9646 cmdline_parse_token_string_t cmd_flex_filter_priority =
9647         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9648                                 priority, "priority");
9649 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9650         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9651                                 priority_value, UINT8);
9652 cmdline_parse_token_string_t cmd_flex_filter_queue =
9653         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9654                                 queue, "queue");
9655 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9656         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9657                                 queue_id, UINT16);
9658 cmdline_parse_inst_t cmd_flex_filter = {
9659         .f = cmd_flex_filter_parsed,
9660         .data = NULL,
9661         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9662                 "<value> mask <value> priority <value> queue <queue_id>: "
9663                 "Add/Del a flex filter",
9664         .tokens = {
9665                 (void *)&cmd_flex_filter_filter,
9666                 (void *)&cmd_flex_filter_port_id,
9667                 (void *)&cmd_flex_filter_ops,
9668                 (void *)&cmd_flex_filter_len,
9669                 (void *)&cmd_flex_filter_len_value,
9670                 (void *)&cmd_flex_filter_bytes,
9671                 (void *)&cmd_flex_filter_bytes_value,
9672                 (void *)&cmd_flex_filter_mask,
9673                 (void *)&cmd_flex_filter_mask_value,
9674                 (void *)&cmd_flex_filter_priority,
9675                 (void *)&cmd_flex_filter_priority_value,
9676                 (void *)&cmd_flex_filter_queue,
9677                 (void *)&cmd_flex_filter_queue_id,
9678                 NULL,
9679         },
9680 };
9681
9682 /* *** Filters Control *** */
9683
9684 /* *** deal with ethertype filter *** */
9685 struct cmd_ethertype_filter_result {
9686         cmdline_fixed_string_t filter;
9687         portid_t port_id;
9688         cmdline_fixed_string_t ops;
9689         cmdline_fixed_string_t mac;
9690         struct ether_addr mac_addr;
9691         cmdline_fixed_string_t ethertype;
9692         uint16_t ethertype_value;
9693         cmdline_fixed_string_t drop;
9694         cmdline_fixed_string_t queue;
9695         uint16_t  queue_id;
9696 };
9697
9698 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9699         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9700                                  filter, "ethertype_filter");
9701 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9702         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9703                               port_id, UINT16);
9704 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9705         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9706                                  ops, "add#del");
9707 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9708         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9709                                  mac, "mac_addr#mac_ignr");
9710 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9711         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9712                                      mac_addr);
9713 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9714         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9715                                  ethertype, "ethertype");
9716 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9717         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9718                               ethertype_value, UINT16);
9719 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9720         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9721                                  drop, "drop#fwd");
9722 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9723         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9724                                  queue, "queue");
9725 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9726         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9727                               queue_id, UINT16);
9728
9729 static void
9730 cmd_ethertype_filter_parsed(void *parsed_result,
9731                           __attribute__((unused)) struct cmdline *cl,
9732                           __attribute__((unused)) void *data)
9733 {
9734         struct cmd_ethertype_filter_result *res = parsed_result;
9735         struct rte_eth_ethertype_filter filter;
9736         int ret = 0;
9737
9738         ret = rte_eth_dev_filter_supported(res->port_id,
9739                         RTE_ETH_FILTER_ETHERTYPE);
9740         if (ret < 0) {
9741                 printf("ethertype filter is not supported on port %u.\n",
9742                         res->port_id);
9743                 return;
9744         }
9745
9746         memset(&filter, 0, sizeof(filter));
9747         if (!strcmp(res->mac, "mac_addr")) {
9748                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9749                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9750                         sizeof(struct ether_addr));
9751         }
9752         if (!strcmp(res->drop, "drop"))
9753                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9754         filter.ether_type = res->ethertype_value;
9755         filter.queue = res->queue_id;
9756
9757         if (!strcmp(res->ops, "add"))
9758                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9759                                 RTE_ETH_FILTER_ETHERTYPE,
9760                                 RTE_ETH_FILTER_ADD,
9761                                 &filter);
9762         else
9763                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9764                                 RTE_ETH_FILTER_ETHERTYPE,
9765                                 RTE_ETH_FILTER_DELETE,
9766                                 &filter);
9767         if (ret < 0)
9768                 printf("ethertype filter programming error: (%s)\n",
9769                         strerror(-ret));
9770 }
9771
9772 cmdline_parse_inst_t cmd_ethertype_filter = {
9773         .f = cmd_ethertype_filter_parsed,
9774         .data = NULL,
9775         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9776                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9777                 "Add or delete an ethertype filter entry",
9778         .tokens = {
9779                 (void *)&cmd_ethertype_filter_filter,
9780                 (void *)&cmd_ethertype_filter_port_id,
9781                 (void *)&cmd_ethertype_filter_ops,
9782                 (void *)&cmd_ethertype_filter_mac,
9783                 (void *)&cmd_ethertype_filter_mac_addr,
9784                 (void *)&cmd_ethertype_filter_ethertype,
9785                 (void *)&cmd_ethertype_filter_ethertype_value,
9786                 (void *)&cmd_ethertype_filter_drop,
9787                 (void *)&cmd_ethertype_filter_queue,
9788                 (void *)&cmd_ethertype_filter_queue_id,
9789                 NULL,
9790         },
9791 };
9792
9793 /* *** deal with flow director filter *** */
9794 struct cmd_flow_director_result {
9795         cmdline_fixed_string_t flow_director_filter;
9796         portid_t port_id;
9797         cmdline_fixed_string_t mode;
9798         cmdline_fixed_string_t mode_value;
9799         cmdline_fixed_string_t ops;
9800         cmdline_fixed_string_t flow;
9801         cmdline_fixed_string_t flow_type;
9802         cmdline_fixed_string_t ether;
9803         uint16_t ether_type;
9804         cmdline_fixed_string_t src;
9805         cmdline_ipaddr_t ip_src;
9806         uint16_t port_src;
9807         cmdline_fixed_string_t dst;
9808         cmdline_ipaddr_t ip_dst;
9809         uint16_t port_dst;
9810         cmdline_fixed_string_t verify_tag;
9811         uint32_t verify_tag_value;
9812         cmdline_ipaddr_t tos;
9813         uint8_t tos_value;
9814         cmdline_ipaddr_t proto;
9815         uint8_t proto_value;
9816         cmdline_ipaddr_t ttl;
9817         uint8_t ttl_value;
9818         cmdline_fixed_string_t vlan;
9819         uint16_t vlan_value;
9820         cmdline_fixed_string_t flexbytes;
9821         cmdline_fixed_string_t flexbytes_value;
9822         cmdline_fixed_string_t pf_vf;
9823         cmdline_fixed_string_t drop;
9824         cmdline_fixed_string_t queue;
9825         uint16_t  queue_id;
9826         cmdline_fixed_string_t fd_id;
9827         uint32_t  fd_id_value;
9828         cmdline_fixed_string_t mac;
9829         struct ether_addr mac_addr;
9830         cmdline_fixed_string_t tunnel;
9831         cmdline_fixed_string_t tunnel_type;
9832         cmdline_fixed_string_t tunnel_id;
9833         uint32_t tunnel_id_value;
9834 };
9835
9836 static inline int
9837 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9838 {
9839         char s[256];
9840         const char *p, *p0 = q_arg;
9841         char *end;
9842         unsigned long int_fld;
9843         char *str_fld[max_num];
9844         int i;
9845         unsigned size;
9846         int ret = -1;
9847
9848         p = strchr(p0, '(');
9849         if (p == NULL)
9850                 return -1;
9851         ++p;
9852         p0 = strchr(p, ')');
9853         if (p0 == NULL)
9854                 return -1;
9855
9856         size = p0 - p;
9857         if (size >= sizeof(s))
9858                 return -1;
9859
9860         snprintf(s, sizeof(s), "%.*s", size, p);
9861         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9862         if (ret < 0 || ret > max_num)
9863                 return -1;
9864         for (i = 0; i < ret; i++) {
9865                 errno = 0;
9866                 int_fld = strtoul(str_fld[i], &end, 0);
9867                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9868                         return -1;
9869                 flexbytes[i] = (uint8_t)int_fld;
9870         }
9871         return ret;
9872 }
9873
9874 static uint16_t
9875 str2flowtype(char *string)
9876 {
9877         uint8_t i = 0;
9878         static const struct {
9879                 char str[32];
9880                 uint16_t type;
9881         } flowtype_str[] = {
9882                 {"raw", RTE_ETH_FLOW_RAW},
9883                 {"ipv4", RTE_ETH_FLOW_IPV4},
9884                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9885                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9886                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9887                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9888                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9889                 {"ipv6", RTE_ETH_FLOW_IPV6},
9890                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9891                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9892                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9893                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9894                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9895                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9896         };
9897
9898         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9899                 if (!strcmp(flowtype_str[i].str, string))
9900                         return flowtype_str[i].type;
9901         }
9902
9903         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9904                 return (uint16_t)atoi(string);
9905
9906         return RTE_ETH_FLOW_UNKNOWN;
9907 }
9908
9909 static enum rte_eth_fdir_tunnel_type
9910 str2fdir_tunneltype(char *string)
9911 {
9912         uint8_t i = 0;
9913
9914         static const struct {
9915                 char str[32];
9916                 enum rte_eth_fdir_tunnel_type type;
9917         } tunneltype_str[] = {
9918                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9919                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9920         };
9921
9922         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9923                 if (!strcmp(tunneltype_str[i].str, string))
9924                         return tunneltype_str[i].type;
9925         }
9926         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9927 }
9928
9929 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9930 do { \
9931         if ((ip_addr).family == AF_INET) \
9932                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9933         else { \
9934                 printf("invalid parameter.\n"); \
9935                 return; \
9936         } \
9937 } while (0)
9938
9939 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9940 do { \
9941         if ((ip_addr).family == AF_INET6) \
9942                 rte_memcpy(&(ip), \
9943                                  &((ip_addr).addr.ipv6), \
9944                                  sizeof(struct in6_addr)); \
9945         else { \
9946                 printf("invalid parameter.\n"); \
9947                 return; \
9948         } \
9949 } while (0)
9950
9951 static void
9952 cmd_flow_director_filter_parsed(void *parsed_result,
9953                           __attribute__((unused)) struct cmdline *cl,
9954                           __attribute__((unused)) void *data)
9955 {
9956         struct cmd_flow_director_result *res = parsed_result;
9957         struct rte_eth_fdir_filter entry;
9958         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9959         char *end;
9960         unsigned long vf_id;
9961         int ret = 0;
9962
9963         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9964         if (ret < 0) {
9965                 printf("flow director is not supported on port %u.\n",
9966                         res->port_id);
9967                 return;
9968         }
9969         memset(flexbytes, 0, sizeof(flexbytes));
9970         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9971
9972         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9973                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9974                         printf("Please set mode to MAC-VLAN.\n");
9975                         return;
9976                 }
9977         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9978                 if (strcmp(res->mode_value, "Tunnel")) {
9979                         printf("Please set mode to Tunnel.\n");
9980                         return;
9981                 }
9982         } else {
9983                 if (strcmp(res->mode_value, "IP")) {
9984                         printf("Please set mode to IP.\n");
9985                         return;
9986                 }
9987                 entry.input.flow_type = str2flowtype(res->flow_type);
9988         }
9989
9990         ret = parse_flexbytes(res->flexbytes_value,
9991                                         flexbytes,
9992                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9993         if (ret < 0) {
9994                 printf("error: Cannot parse flexbytes input.\n");
9995                 return;
9996         }
9997
9998         switch (entry.input.flow_type) {
9999         case RTE_ETH_FLOW_FRAG_IPV4:
10000         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10001                 entry.input.flow.ip4_flow.proto = res->proto_value;
10002                 /* fall-through */
10003         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10004         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10005                 IPV4_ADDR_TO_UINT(res->ip_dst,
10006                         entry.input.flow.ip4_flow.dst_ip);
10007                 IPV4_ADDR_TO_UINT(res->ip_src,
10008                         entry.input.flow.ip4_flow.src_ip);
10009                 entry.input.flow.ip4_flow.tos = res->tos_value;
10010                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10011                 /* need convert to big endian. */
10012                 entry.input.flow.udp4_flow.dst_port =
10013                                 rte_cpu_to_be_16(res->port_dst);
10014                 entry.input.flow.udp4_flow.src_port =
10015                                 rte_cpu_to_be_16(res->port_src);
10016                 break;
10017         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10018                 IPV4_ADDR_TO_UINT(res->ip_dst,
10019                         entry.input.flow.sctp4_flow.ip.dst_ip);
10020                 IPV4_ADDR_TO_UINT(res->ip_src,
10021                         entry.input.flow.sctp4_flow.ip.src_ip);
10022                 entry.input.flow.ip4_flow.tos = res->tos_value;
10023                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10024                 /* need convert to big endian. */
10025                 entry.input.flow.sctp4_flow.dst_port =
10026                                 rte_cpu_to_be_16(res->port_dst);
10027                 entry.input.flow.sctp4_flow.src_port =
10028                                 rte_cpu_to_be_16(res->port_src);
10029                 entry.input.flow.sctp4_flow.verify_tag =
10030                                 rte_cpu_to_be_32(res->verify_tag_value);
10031                 break;
10032         case RTE_ETH_FLOW_FRAG_IPV6:
10033         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10034                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10035                 /* fall-through */
10036         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10037         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10038                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10039                         entry.input.flow.ipv6_flow.dst_ip);
10040                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10041                         entry.input.flow.ipv6_flow.src_ip);
10042                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10043                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10044                 /* need convert to big endian. */
10045                 entry.input.flow.udp6_flow.dst_port =
10046                                 rte_cpu_to_be_16(res->port_dst);
10047                 entry.input.flow.udp6_flow.src_port =
10048                                 rte_cpu_to_be_16(res->port_src);
10049                 break;
10050         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10051                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10052                         entry.input.flow.sctp6_flow.ip.dst_ip);
10053                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10054                         entry.input.flow.sctp6_flow.ip.src_ip);
10055                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10056                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10057                 /* need convert to big endian. */
10058                 entry.input.flow.sctp6_flow.dst_port =
10059                                 rte_cpu_to_be_16(res->port_dst);
10060                 entry.input.flow.sctp6_flow.src_port =
10061                                 rte_cpu_to_be_16(res->port_src);
10062                 entry.input.flow.sctp6_flow.verify_tag =
10063                                 rte_cpu_to_be_32(res->verify_tag_value);
10064                 break;
10065         case RTE_ETH_FLOW_L2_PAYLOAD:
10066                 entry.input.flow.l2_flow.ether_type =
10067                         rte_cpu_to_be_16(res->ether_type);
10068                 break;
10069         default:
10070                 break;
10071         }
10072
10073         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10074                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10075                                  &res->mac_addr,
10076                                  sizeof(struct ether_addr));
10077
10078         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10079                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10080                                  &res->mac_addr,
10081                                  sizeof(struct ether_addr));
10082                 entry.input.flow.tunnel_flow.tunnel_type =
10083                         str2fdir_tunneltype(res->tunnel_type);
10084                 entry.input.flow.tunnel_flow.tunnel_id =
10085                         rte_cpu_to_be_32(res->tunnel_id_value);
10086         }
10087
10088         rte_memcpy(entry.input.flow_ext.flexbytes,
10089                    flexbytes,
10090                    RTE_ETH_FDIR_MAX_FLEXLEN);
10091
10092         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10093
10094         entry.action.flex_off = 0;  /*use 0 by default */
10095         if (!strcmp(res->drop, "drop"))
10096                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10097         else
10098                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10099
10100         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10101             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10102                 if (!strcmp(res->pf_vf, "pf"))
10103                         entry.input.flow_ext.is_vf = 0;
10104                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10105                         struct rte_eth_dev_info dev_info;
10106
10107                         memset(&dev_info, 0, sizeof(dev_info));
10108                         rte_eth_dev_info_get(res->port_id, &dev_info);
10109                         errno = 0;
10110                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10111                         if (errno != 0 || *end != '\0' ||
10112                             vf_id >= dev_info.max_vfs) {
10113                                 printf("invalid parameter %s.\n", res->pf_vf);
10114                                 return;
10115                         }
10116                         entry.input.flow_ext.is_vf = 1;
10117                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10118                 } else {
10119                         printf("invalid parameter %s.\n", res->pf_vf);
10120                         return;
10121                 }
10122         }
10123
10124         /* set to report FD ID by default */
10125         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10126         entry.action.rx_queue = res->queue_id;
10127         entry.soft_id = res->fd_id_value;
10128         if (!strcmp(res->ops, "add"))
10129                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10130                                              RTE_ETH_FILTER_ADD, &entry);
10131         else if (!strcmp(res->ops, "del"))
10132                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10133                                              RTE_ETH_FILTER_DELETE, &entry);
10134         else
10135                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10136                                              RTE_ETH_FILTER_UPDATE, &entry);
10137         if (ret < 0)
10138                 printf("flow director programming error: (%s)\n",
10139                         strerror(-ret));
10140 }
10141
10142 cmdline_parse_token_string_t cmd_flow_director_filter =
10143         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10144                                  flow_director_filter, "flow_director_filter");
10145 cmdline_parse_token_num_t cmd_flow_director_port_id =
10146         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10147                               port_id, UINT16);
10148 cmdline_parse_token_string_t cmd_flow_director_ops =
10149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10150                                  ops, "add#del#update");
10151 cmdline_parse_token_string_t cmd_flow_director_flow =
10152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10153                                  flow, "flow");
10154 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10156                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10157                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10158 cmdline_parse_token_string_t cmd_flow_director_ether =
10159         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10160                                  ether, "ether");
10161 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10162         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10163                               ether_type, UINT16);
10164 cmdline_parse_token_string_t cmd_flow_director_src =
10165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10166                                  src, "src");
10167 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10168         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10169                                  ip_src);
10170 cmdline_parse_token_num_t cmd_flow_director_port_src =
10171         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10172                               port_src, UINT16);
10173 cmdline_parse_token_string_t cmd_flow_director_dst =
10174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10175                                  dst, "dst");
10176 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10177         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10178                                  ip_dst);
10179 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10180         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10181                               port_dst, UINT16);
10182 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10184                                   verify_tag, "verify_tag");
10185 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10186         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10187                               verify_tag_value, UINT32);
10188 cmdline_parse_token_string_t cmd_flow_director_tos =
10189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10190                                  tos, "tos");
10191 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10192         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10193                               tos_value, UINT8);
10194 cmdline_parse_token_string_t cmd_flow_director_proto =
10195         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10196                                  proto, "proto");
10197 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10198         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10199                               proto_value, UINT8);
10200 cmdline_parse_token_string_t cmd_flow_director_ttl =
10201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10202                                  ttl, "ttl");
10203 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10204         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10205                               ttl_value, UINT8);
10206 cmdline_parse_token_string_t cmd_flow_director_vlan =
10207         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10208                                  vlan, "vlan");
10209 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10210         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10211                               vlan_value, UINT16);
10212 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10213         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10214                                  flexbytes, "flexbytes");
10215 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10216         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10217                               flexbytes_value, NULL);
10218 cmdline_parse_token_string_t cmd_flow_director_drop =
10219         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10220                                  drop, "drop#fwd");
10221 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10223                               pf_vf, NULL);
10224 cmdline_parse_token_string_t cmd_flow_director_queue =
10225         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10226                                  queue, "queue");
10227 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10228         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10229                               queue_id, UINT16);
10230 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10231         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10232                                  fd_id, "fd_id");
10233 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10234         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10235                               fd_id_value, UINT32);
10236
10237 cmdline_parse_token_string_t cmd_flow_director_mode =
10238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10239                                  mode, "mode");
10240 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10242                                  mode_value, "IP");
10243 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10245                                  mode_value, "MAC-VLAN");
10246 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10248                                  mode_value, "Tunnel");
10249 cmdline_parse_token_string_t cmd_flow_director_mac =
10250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10251                                  mac, "mac");
10252 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10253         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10254                                     mac_addr);
10255 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10256         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10257                                  tunnel, "tunnel");
10258 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10260                                  tunnel_type, "NVGRE#VxLAN");
10261 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10263                                  tunnel_id, "tunnel-id");
10264 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10265         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10266                               tunnel_id_value, UINT32);
10267
10268 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10269         .f = cmd_flow_director_filter_parsed,
10270         .data = NULL,
10271         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10272                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10273                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10274                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10275                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10276                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10277                 "fd_id <fd_id_value>: "
10278                 "Add or delete an ip flow director entry on NIC",
10279         .tokens = {
10280                 (void *)&cmd_flow_director_filter,
10281                 (void *)&cmd_flow_director_port_id,
10282                 (void *)&cmd_flow_director_mode,
10283                 (void *)&cmd_flow_director_mode_ip,
10284                 (void *)&cmd_flow_director_ops,
10285                 (void *)&cmd_flow_director_flow,
10286                 (void *)&cmd_flow_director_flow_type,
10287                 (void *)&cmd_flow_director_src,
10288                 (void *)&cmd_flow_director_ip_src,
10289                 (void *)&cmd_flow_director_dst,
10290                 (void *)&cmd_flow_director_ip_dst,
10291                 (void *)&cmd_flow_director_tos,
10292                 (void *)&cmd_flow_director_tos_value,
10293                 (void *)&cmd_flow_director_proto,
10294                 (void *)&cmd_flow_director_proto_value,
10295                 (void *)&cmd_flow_director_ttl,
10296                 (void *)&cmd_flow_director_ttl_value,
10297                 (void *)&cmd_flow_director_vlan,
10298                 (void *)&cmd_flow_director_vlan_value,
10299                 (void *)&cmd_flow_director_flexbytes,
10300                 (void *)&cmd_flow_director_flexbytes_value,
10301                 (void *)&cmd_flow_director_drop,
10302                 (void *)&cmd_flow_director_pf_vf,
10303                 (void *)&cmd_flow_director_queue,
10304                 (void *)&cmd_flow_director_queue_id,
10305                 (void *)&cmd_flow_director_fd_id,
10306                 (void *)&cmd_flow_director_fd_id_value,
10307                 NULL,
10308         },
10309 };
10310
10311 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10312         .f = cmd_flow_director_filter_parsed,
10313         .data = NULL,
10314         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10315                 "director entry on NIC",
10316         .tokens = {
10317                 (void *)&cmd_flow_director_filter,
10318                 (void *)&cmd_flow_director_port_id,
10319                 (void *)&cmd_flow_director_mode,
10320                 (void *)&cmd_flow_director_mode_ip,
10321                 (void *)&cmd_flow_director_ops,
10322                 (void *)&cmd_flow_director_flow,
10323                 (void *)&cmd_flow_director_flow_type,
10324                 (void *)&cmd_flow_director_src,
10325                 (void *)&cmd_flow_director_ip_src,
10326                 (void *)&cmd_flow_director_port_src,
10327                 (void *)&cmd_flow_director_dst,
10328                 (void *)&cmd_flow_director_ip_dst,
10329                 (void *)&cmd_flow_director_port_dst,
10330                 (void *)&cmd_flow_director_tos,
10331                 (void *)&cmd_flow_director_tos_value,
10332                 (void *)&cmd_flow_director_ttl,
10333                 (void *)&cmd_flow_director_ttl_value,
10334                 (void *)&cmd_flow_director_vlan,
10335                 (void *)&cmd_flow_director_vlan_value,
10336                 (void *)&cmd_flow_director_flexbytes,
10337                 (void *)&cmd_flow_director_flexbytes_value,
10338                 (void *)&cmd_flow_director_drop,
10339                 (void *)&cmd_flow_director_pf_vf,
10340                 (void *)&cmd_flow_director_queue,
10341                 (void *)&cmd_flow_director_queue_id,
10342                 (void *)&cmd_flow_director_fd_id,
10343                 (void *)&cmd_flow_director_fd_id_value,
10344                 NULL,
10345         },
10346 };
10347
10348 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10349         .f = cmd_flow_director_filter_parsed,
10350         .data = NULL,
10351         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10352                 "director entry on NIC",
10353         .tokens = {
10354                 (void *)&cmd_flow_director_filter,
10355                 (void *)&cmd_flow_director_port_id,
10356                 (void *)&cmd_flow_director_mode,
10357                 (void *)&cmd_flow_director_mode_ip,
10358                 (void *)&cmd_flow_director_ops,
10359                 (void *)&cmd_flow_director_flow,
10360                 (void *)&cmd_flow_director_flow_type,
10361                 (void *)&cmd_flow_director_src,
10362                 (void *)&cmd_flow_director_ip_src,
10363                 (void *)&cmd_flow_director_port_dst,
10364                 (void *)&cmd_flow_director_dst,
10365                 (void *)&cmd_flow_director_ip_dst,
10366                 (void *)&cmd_flow_director_port_dst,
10367                 (void *)&cmd_flow_director_verify_tag,
10368                 (void *)&cmd_flow_director_verify_tag_value,
10369                 (void *)&cmd_flow_director_tos,
10370                 (void *)&cmd_flow_director_tos_value,
10371                 (void *)&cmd_flow_director_ttl,
10372                 (void *)&cmd_flow_director_ttl_value,
10373                 (void *)&cmd_flow_director_vlan,
10374                 (void *)&cmd_flow_director_vlan_value,
10375                 (void *)&cmd_flow_director_flexbytes,
10376                 (void *)&cmd_flow_director_flexbytes_value,
10377                 (void *)&cmd_flow_director_drop,
10378                 (void *)&cmd_flow_director_pf_vf,
10379                 (void *)&cmd_flow_director_queue,
10380                 (void *)&cmd_flow_director_queue_id,
10381                 (void *)&cmd_flow_director_fd_id,
10382                 (void *)&cmd_flow_director_fd_id_value,
10383                 NULL,
10384         },
10385 };
10386
10387 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10388         .f = cmd_flow_director_filter_parsed,
10389         .data = NULL,
10390         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10391                 "director entry on NIC",
10392         .tokens = {
10393                 (void *)&cmd_flow_director_filter,
10394                 (void *)&cmd_flow_director_port_id,
10395                 (void *)&cmd_flow_director_mode,
10396                 (void *)&cmd_flow_director_mode_ip,
10397                 (void *)&cmd_flow_director_ops,
10398                 (void *)&cmd_flow_director_flow,
10399                 (void *)&cmd_flow_director_flow_type,
10400                 (void *)&cmd_flow_director_ether,
10401                 (void *)&cmd_flow_director_ether_type,
10402                 (void *)&cmd_flow_director_flexbytes,
10403                 (void *)&cmd_flow_director_flexbytes_value,
10404                 (void *)&cmd_flow_director_drop,
10405                 (void *)&cmd_flow_director_pf_vf,
10406                 (void *)&cmd_flow_director_queue,
10407                 (void *)&cmd_flow_director_queue_id,
10408                 (void *)&cmd_flow_director_fd_id,
10409                 (void *)&cmd_flow_director_fd_id_value,
10410                 NULL,
10411         },
10412 };
10413
10414 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10415         .f = cmd_flow_director_filter_parsed,
10416         .data = NULL,
10417         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10418                 "director entry on NIC",
10419         .tokens = {
10420                 (void *)&cmd_flow_director_filter,
10421                 (void *)&cmd_flow_director_port_id,
10422                 (void *)&cmd_flow_director_mode,
10423                 (void *)&cmd_flow_director_mode_mac_vlan,
10424                 (void *)&cmd_flow_director_ops,
10425                 (void *)&cmd_flow_director_mac,
10426                 (void *)&cmd_flow_director_mac_addr,
10427                 (void *)&cmd_flow_director_vlan,
10428                 (void *)&cmd_flow_director_vlan_value,
10429                 (void *)&cmd_flow_director_flexbytes,
10430                 (void *)&cmd_flow_director_flexbytes_value,
10431                 (void *)&cmd_flow_director_drop,
10432                 (void *)&cmd_flow_director_queue,
10433                 (void *)&cmd_flow_director_queue_id,
10434                 (void *)&cmd_flow_director_fd_id,
10435                 (void *)&cmd_flow_director_fd_id_value,
10436                 NULL,
10437         },
10438 };
10439
10440 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10441         .f = cmd_flow_director_filter_parsed,
10442         .data = NULL,
10443         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10444                 "director entry on NIC",
10445         .tokens = {
10446                 (void *)&cmd_flow_director_filter,
10447                 (void *)&cmd_flow_director_port_id,
10448                 (void *)&cmd_flow_director_mode,
10449                 (void *)&cmd_flow_director_mode_tunnel,
10450                 (void *)&cmd_flow_director_ops,
10451                 (void *)&cmd_flow_director_mac,
10452                 (void *)&cmd_flow_director_mac_addr,
10453                 (void *)&cmd_flow_director_vlan,
10454                 (void *)&cmd_flow_director_vlan_value,
10455                 (void *)&cmd_flow_director_tunnel,
10456                 (void *)&cmd_flow_director_tunnel_type,
10457                 (void *)&cmd_flow_director_tunnel_id,
10458                 (void *)&cmd_flow_director_tunnel_id_value,
10459                 (void *)&cmd_flow_director_flexbytes,
10460                 (void *)&cmd_flow_director_flexbytes_value,
10461                 (void *)&cmd_flow_director_drop,
10462                 (void *)&cmd_flow_director_queue,
10463                 (void *)&cmd_flow_director_queue_id,
10464                 (void *)&cmd_flow_director_fd_id,
10465                 (void *)&cmd_flow_director_fd_id_value,
10466                 NULL,
10467         },
10468 };
10469
10470 struct cmd_flush_flow_director_result {
10471         cmdline_fixed_string_t flush_flow_director;
10472         portid_t port_id;
10473 };
10474
10475 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10476         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10477                                  flush_flow_director, "flush_flow_director");
10478 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10479         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10480                               port_id, UINT16);
10481
10482 static void
10483 cmd_flush_flow_director_parsed(void *parsed_result,
10484                           __attribute__((unused)) struct cmdline *cl,
10485                           __attribute__((unused)) void *data)
10486 {
10487         struct cmd_flow_director_result *res = parsed_result;
10488         int ret = 0;
10489
10490         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10491         if (ret < 0) {
10492                 printf("flow director is not supported on port %u.\n",
10493                         res->port_id);
10494                 return;
10495         }
10496
10497         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10498                         RTE_ETH_FILTER_FLUSH, NULL);
10499         if (ret < 0)
10500                 printf("flow director table flushing error: (%s)\n",
10501                         strerror(-ret));
10502 }
10503
10504 cmdline_parse_inst_t cmd_flush_flow_director = {
10505         .f = cmd_flush_flow_director_parsed,
10506         .data = NULL,
10507         .help_str = "flush_flow_director <port_id>: "
10508                 "Flush all flow director entries of a device on NIC",
10509         .tokens = {
10510                 (void *)&cmd_flush_flow_director_flush,
10511                 (void *)&cmd_flush_flow_director_port_id,
10512                 NULL,
10513         },
10514 };
10515
10516 /* *** deal with flow director mask *** */
10517 struct cmd_flow_director_mask_result {
10518         cmdline_fixed_string_t flow_director_mask;
10519         portid_t port_id;
10520         cmdline_fixed_string_t mode;
10521         cmdline_fixed_string_t mode_value;
10522         cmdline_fixed_string_t vlan;
10523         uint16_t vlan_mask;
10524         cmdline_fixed_string_t src_mask;
10525         cmdline_ipaddr_t ipv4_src;
10526         cmdline_ipaddr_t ipv6_src;
10527         uint16_t port_src;
10528         cmdline_fixed_string_t dst_mask;
10529         cmdline_ipaddr_t ipv4_dst;
10530         cmdline_ipaddr_t ipv6_dst;
10531         uint16_t port_dst;
10532         cmdline_fixed_string_t mac;
10533         uint8_t mac_addr_byte_mask;
10534         cmdline_fixed_string_t tunnel_id;
10535         uint32_t tunnel_id_mask;
10536         cmdline_fixed_string_t tunnel_type;
10537         uint8_t tunnel_type_mask;
10538 };
10539
10540 static void
10541 cmd_flow_director_mask_parsed(void *parsed_result,
10542                           __attribute__((unused)) struct cmdline *cl,
10543                           __attribute__((unused)) void *data)
10544 {
10545         struct cmd_flow_director_mask_result *res = parsed_result;
10546         struct rte_eth_fdir_masks *mask;
10547         struct rte_port *port;
10548
10549         if (res->port_id > nb_ports) {
10550                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10551                 return;
10552         }
10553
10554         port = &ports[res->port_id];
10555         /** Check if the port is not started **/
10556         if (port->port_status != RTE_PORT_STOPPED) {
10557                 printf("Please stop port %d first\n", res->port_id);
10558                 return;
10559         }
10560
10561         mask = &port->dev_conf.fdir_conf.mask;
10562
10563         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10564                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10565                         printf("Please set mode to MAC-VLAN.\n");
10566                         return;
10567                 }
10568
10569                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10570         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10571                 if (strcmp(res->mode_value, "Tunnel")) {
10572                         printf("Please set mode to Tunnel.\n");
10573                         return;
10574                 }
10575
10576                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10577                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10578                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10579                 mask->tunnel_type_mask = res->tunnel_type_mask;
10580         } else {
10581                 if (strcmp(res->mode_value, "IP")) {
10582                         printf("Please set mode to IP.\n");
10583                         return;
10584                 }
10585
10586                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10587                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10588                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10589                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10590                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10591                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10592                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10593         }
10594
10595         cmd_reconfig_device_queue(res->port_id, 1, 1);
10596 }
10597
10598 cmdline_parse_token_string_t cmd_flow_director_mask =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10600                                  flow_director_mask, "flow_director_mask");
10601 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10602         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10603                               port_id, UINT16);
10604 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10606                                  vlan, "vlan");
10607 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10608         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10609                               vlan_mask, UINT16);
10610 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10611         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10612                                  src_mask, "src_mask");
10613 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10614         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10615                                  ipv4_src);
10616 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10617         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10618                                  ipv6_src);
10619 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10620         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10621                               port_src, UINT16);
10622 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10623         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10624                                  dst_mask, "dst_mask");
10625 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10626         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10627                                  ipv4_dst);
10628 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10629         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10630                                  ipv6_dst);
10631 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10632         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10633                               port_dst, UINT16);
10634
10635 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10636         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10637                                  mode, "mode");
10638 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10639         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10640                                  mode_value, "IP");
10641 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10642         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10643                                  mode_value, "MAC-VLAN");
10644 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10645         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10646                                  mode_value, "Tunnel");
10647 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10649                                  mac, "mac");
10650 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10651         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10652                               mac_addr_byte_mask, UINT8);
10653 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10654         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10655                                  tunnel_type, "tunnel-type");
10656 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10657         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10658                               tunnel_type_mask, UINT8);
10659 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10661                                  tunnel_id, "tunnel-id");
10662 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10663         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10664                               tunnel_id_mask, UINT32);
10665
10666 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10667         .f = cmd_flow_director_mask_parsed,
10668         .data = NULL,
10669         .help_str = "flow_director_mask ... : "
10670                 "Set IP mode flow director's mask on NIC",
10671         .tokens = {
10672                 (void *)&cmd_flow_director_mask,
10673                 (void *)&cmd_flow_director_mask_port_id,
10674                 (void *)&cmd_flow_director_mask_mode,
10675                 (void *)&cmd_flow_director_mask_mode_ip,
10676                 (void *)&cmd_flow_director_mask_vlan,
10677                 (void *)&cmd_flow_director_mask_vlan_value,
10678                 (void *)&cmd_flow_director_mask_src,
10679                 (void *)&cmd_flow_director_mask_ipv4_src,
10680                 (void *)&cmd_flow_director_mask_ipv6_src,
10681                 (void *)&cmd_flow_director_mask_port_src,
10682                 (void *)&cmd_flow_director_mask_dst,
10683                 (void *)&cmd_flow_director_mask_ipv4_dst,
10684                 (void *)&cmd_flow_director_mask_ipv6_dst,
10685                 (void *)&cmd_flow_director_mask_port_dst,
10686                 NULL,
10687         },
10688 };
10689
10690 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10691         .f = cmd_flow_director_mask_parsed,
10692         .data = NULL,
10693         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10694                 "flow director's mask on NIC",
10695         .tokens = {
10696                 (void *)&cmd_flow_director_mask,
10697                 (void *)&cmd_flow_director_mask_port_id,
10698                 (void *)&cmd_flow_director_mask_mode,
10699                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10700                 (void *)&cmd_flow_director_mask_vlan,
10701                 (void *)&cmd_flow_director_mask_vlan_value,
10702                 NULL,
10703         },
10704 };
10705
10706 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10707         .f = cmd_flow_director_mask_parsed,
10708         .data = NULL,
10709         .help_str = "flow_director_mask ... : Set tunnel mode "
10710                 "flow director's mask on NIC",
10711         .tokens = {
10712                 (void *)&cmd_flow_director_mask,
10713                 (void *)&cmd_flow_director_mask_port_id,
10714                 (void *)&cmd_flow_director_mask_mode,
10715                 (void *)&cmd_flow_director_mask_mode_tunnel,
10716                 (void *)&cmd_flow_director_mask_vlan,
10717                 (void *)&cmd_flow_director_mask_vlan_value,
10718                 (void *)&cmd_flow_director_mask_mac,
10719                 (void *)&cmd_flow_director_mask_mac_value,
10720                 (void *)&cmd_flow_director_mask_tunnel_type,
10721                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10722                 (void *)&cmd_flow_director_mask_tunnel_id,
10723                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10724                 NULL,
10725         },
10726 };
10727
10728 /* *** deal with flow director mask on flexible payload *** */
10729 struct cmd_flow_director_flex_mask_result {
10730         cmdline_fixed_string_t flow_director_flexmask;
10731         portid_t port_id;
10732         cmdline_fixed_string_t flow;
10733         cmdline_fixed_string_t flow_type;
10734         cmdline_fixed_string_t mask;
10735 };
10736
10737 static void
10738 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10739                           __attribute__((unused)) struct cmdline *cl,
10740                           __attribute__((unused)) void *data)
10741 {
10742         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10743         struct rte_eth_fdir_info fdir_info;
10744         struct rte_eth_fdir_flex_mask flex_mask;
10745         struct rte_port *port;
10746         uint32_t flow_type_mask;
10747         uint16_t i;
10748         int ret;
10749
10750         if (res->port_id > nb_ports) {
10751                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10752                 return;
10753         }
10754
10755         port = &ports[res->port_id];
10756         /** Check if the port is not started **/
10757         if (port->port_status != RTE_PORT_STOPPED) {
10758                 printf("Please stop port %d first\n", res->port_id);
10759                 return;
10760         }
10761
10762         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10763         ret = parse_flexbytes(res->mask,
10764                         flex_mask.mask,
10765                         RTE_ETH_FDIR_MAX_FLEXLEN);
10766         if (ret < 0) {
10767                 printf("error: Cannot parse mask input.\n");
10768                 return;
10769         }
10770
10771         memset(&fdir_info, 0, sizeof(fdir_info));
10772         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10773                                 RTE_ETH_FILTER_INFO, &fdir_info);
10774         if (ret < 0) {
10775                 printf("Cannot get FDir filter info\n");
10776                 return;
10777         }
10778
10779         if (!strcmp(res->flow_type, "none")) {
10780                 /* means don't specify the flow type */
10781                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10782                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10783                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10784                                0, sizeof(struct rte_eth_fdir_flex_mask));
10785                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10786                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10787                                  &flex_mask,
10788                                  sizeof(struct rte_eth_fdir_flex_mask));
10789                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10790                 return;
10791         }
10792         flow_type_mask = fdir_info.flow_types_mask[0];
10793         if (!strcmp(res->flow_type, "all")) {
10794                 if (!flow_type_mask) {
10795                         printf("No flow type supported\n");
10796                         return;
10797                 }
10798                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10799                         if (flow_type_mask & (1 << i)) {
10800                                 flex_mask.flow_type = i;
10801                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10802                         }
10803                 }
10804                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10805                 return;
10806         }
10807         flex_mask.flow_type = str2flowtype(res->flow_type);
10808         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10809                 printf("Flow type %s not supported on port %d\n",
10810                                 res->flow_type, res->port_id);
10811                 return;
10812         }
10813         fdir_set_flex_mask(res->port_id, &flex_mask);
10814         cmd_reconfig_device_queue(res->port_id, 1, 1);
10815 }
10816
10817 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10818         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10819                                  flow_director_flexmask,
10820                                  "flow_director_flex_mask");
10821 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10822         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10823                               port_id, UINT16);
10824 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10825         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10826                                  flow, "flow");
10827 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10828         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10829                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10830                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10831 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10832         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10833                                  mask, NULL);
10834
10835 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10836         .f = cmd_flow_director_flex_mask_parsed,
10837         .data = NULL,
10838         .help_str = "flow_director_flex_mask ... : "
10839                 "Set flow director's flex mask on NIC",
10840         .tokens = {
10841                 (void *)&cmd_flow_director_flexmask,
10842                 (void *)&cmd_flow_director_flexmask_port_id,
10843                 (void *)&cmd_flow_director_flexmask_flow,
10844                 (void *)&cmd_flow_director_flexmask_flow_type,
10845                 (void *)&cmd_flow_director_flexmask_mask,
10846                 NULL,
10847         },
10848 };
10849
10850 /* *** deal with flow director flexible payload configuration *** */
10851 struct cmd_flow_director_flexpayload_result {
10852         cmdline_fixed_string_t flow_director_flexpayload;
10853         portid_t port_id;
10854         cmdline_fixed_string_t payload_layer;
10855         cmdline_fixed_string_t payload_cfg;
10856 };
10857
10858 static inline int
10859 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10860 {
10861         char s[256];
10862         const char *p, *p0 = q_arg;
10863         char *end;
10864         unsigned long int_fld;
10865         char *str_fld[max_num];
10866         int i;
10867         unsigned size;
10868         int ret = -1;
10869
10870         p = strchr(p0, '(');
10871         if (p == NULL)
10872                 return -1;
10873         ++p;
10874         p0 = strchr(p, ')');
10875         if (p0 == NULL)
10876                 return -1;
10877
10878         size = p0 - p;
10879         if (size >= sizeof(s))
10880                 return -1;
10881
10882         snprintf(s, sizeof(s), "%.*s", size, p);
10883         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10884         if (ret < 0 || ret > max_num)
10885                 return -1;
10886         for (i = 0; i < ret; i++) {
10887                 errno = 0;
10888                 int_fld = strtoul(str_fld[i], &end, 0);
10889                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10890                         return -1;
10891                 offsets[i] = (uint16_t)int_fld;
10892         }
10893         return ret;
10894 }
10895
10896 static void
10897 cmd_flow_director_flxpld_parsed(void *parsed_result,
10898                           __attribute__((unused)) struct cmdline *cl,
10899                           __attribute__((unused)) void *data)
10900 {
10901         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10902         struct rte_eth_flex_payload_cfg flex_cfg;
10903         struct rte_port *port;
10904         int ret = 0;
10905
10906         if (res->port_id > nb_ports) {
10907                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10908                 return;
10909         }
10910
10911         port = &ports[res->port_id];
10912         /** Check if the port is not started **/
10913         if (port->port_status != RTE_PORT_STOPPED) {
10914                 printf("Please stop port %d first\n", res->port_id);
10915                 return;
10916         }
10917
10918         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10919
10920         if (!strcmp(res->payload_layer, "raw"))
10921                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10922         else if (!strcmp(res->payload_layer, "l2"))
10923                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10924         else if (!strcmp(res->payload_layer, "l3"))
10925                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10926         else if (!strcmp(res->payload_layer, "l4"))
10927                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10928
10929         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10930                             RTE_ETH_FDIR_MAX_FLEXLEN);
10931         if (ret < 0) {
10932                 printf("error: Cannot parse flex payload input.\n");
10933                 return;
10934         }
10935
10936         fdir_set_flex_payload(res->port_id, &flex_cfg);
10937         cmd_reconfig_device_queue(res->port_id, 1, 1);
10938 }
10939
10940 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10942                                  flow_director_flexpayload,
10943                                  "flow_director_flex_payload");
10944 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10945         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10946                               port_id, UINT16);
10947 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10948         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10949                                  payload_layer, "raw#l2#l3#l4");
10950 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10951         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10952                                  payload_cfg, NULL);
10953
10954 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10955         .f = cmd_flow_director_flxpld_parsed,
10956         .data = NULL,
10957         .help_str = "flow_director_flexpayload ... : "
10958                 "Set flow director's flex payload on NIC",
10959         .tokens = {
10960                 (void *)&cmd_flow_director_flexpayload,
10961                 (void *)&cmd_flow_director_flexpayload_port_id,
10962                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10963                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10964                 NULL,
10965         },
10966 };
10967
10968 /* Generic flow interface command. */
10969 extern cmdline_parse_inst_t cmd_flow;
10970
10971 /* *** Classification Filters Control *** */
10972 /* *** Get symmetric hash enable per port *** */
10973 struct cmd_get_sym_hash_ena_per_port_result {
10974         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10975         portid_t port_id;
10976 };
10977
10978 static void
10979 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10980                                  __rte_unused struct cmdline *cl,
10981                                  __rte_unused void *data)
10982 {
10983         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10984         struct rte_eth_hash_filter_info info;
10985         int ret;
10986
10987         if (rte_eth_dev_filter_supported(res->port_id,
10988                                 RTE_ETH_FILTER_HASH) < 0) {
10989                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10990                                                         res->port_id);
10991                 return;
10992         }
10993
10994         memset(&info, 0, sizeof(info));
10995         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10996         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10997                                                 RTE_ETH_FILTER_GET, &info);
10998
10999         if (ret < 0) {
11000                 printf("Cannot get symmetric hash enable per port "
11001                                         "on port %u\n", res->port_id);
11002                 return;
11003         }
11004
11005         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11006                                 "enabled" : "disabled", res->port_id);
11007 }
11008
11009 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11010         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11011                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11012 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11013         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11014                 port_id, UINT16);
11015
11016 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11017         .f = cmd_get_sym_hash_per_port_parsed,
11018         .data = NULL,
11019         .help_str = "get_sym_hash_ena_per_port <port_id>",
11020         .tokens = {
11021                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11022                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11023                 NULL,
11024         },
11025 };
11026
11027 /* *** Set symmetric hash enable per port *** */
11028 struct cmd_set_sym_hash_ena_per_port_result {
11029         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11030         cmdline_fixed_string_t enable;
11031         portid_t port_id;
11032 };
11033
11034 static void
11035 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11036                                  __rte_unused struct cmdline *cl,
11037                                  __rte_unused void *data)
11038 {
11039         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11040         struct rte_eth_hash_filter_info info;
11041         int ret;
11042
11043         if (rte_eth_dev_filter_supported(res->port_id,
11044                                 RTE_ETH_FILTER_HASH) < 0) {
11045                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11046                                                         res->port_id);
11047                 return;
11048         }
11049
11050         memset(&info, 0, sizeof(info));
11051         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11052         if (!strcmp(res->enable, "enable"))
11053                 info.info.enable = 1;
11054         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11055                                         RTE_ETH_FILTER_SET, &info);
11056         if (ret < 0) {
11057                 printf("Cannot set symmetric hash enable per port on "
11058                                         "port %u\n", res->port_id);
11059                 return;
11060         }
11061         printf("Symmetric hash has been set to %s on port %u\n",
11062                                         res->enable, res->port_id);
11063 }
11064
11065 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11066         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11067                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11068 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11069         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11070                 port_id, UINT16);
11071 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11072         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11073                 enable, "enable#disable");
11074
11075 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11076         .f = cmd_set_sym_hash_per_port_parsed,
11077         .data = NULL,
11078         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11079         .tokens = {
11080                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11081                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11082                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11083                 NULL,
11084         },
11085 };
11086
11087 /* Get global config of hash function */
11088 struct cmd_get_hash_global_config_result {
11089         cmdline_fixed_string_t get_hash_global_config;
11090         portid_t port_id;
11091 };
11092
11093 static char *
11094 flowtype_to_str(uint16_t ftype)
11095 {
11096         uint16_t i;
11097         static struct {
11098                 char str[16];
11099                 uint16_t ftype;
11100         } ftype_table[] = {
11101                 {"ipv4", RTE_ETH_FLOW_IPV4},
11102                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11103                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11104                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11105                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11106                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11107                 {"ipv6", RTE_ETH_FLOW_IPV6},
11108                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11109                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11110                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11111                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11112                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11113                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11114                 {"port", RTE_ETH_FLOW_PORT},
11115                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11116                 {"geneve", RTE_ETH_FLOW_GENEVE},
11117                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11118         };
11119
11120         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11121                 if (ftype_table[i].ftype == ftype)
11122                         return ftype_table[i].str;
11123         }
11124
11125         return NULL;
11126 }
11127
11128 static void
11129 cmd_get_hash_global_config_parsed(void *parsed_result,
11130                                   __rte_unused struct cmdline *cl,
11131                                   __rte_unused void *data)
11132 {
11133         struct cmd_get_hash_global_config_result *res = parsed_result;
11134         struct rte_eth_hash_filter_info info;
11135         uint32_t idx, offset;
11136         uint16_t i;
11137         char *str;
11138         int ret;
11139
11140         if (rte_eth_dev_filter_supported(res->port_id,
11141                         RTE_ETH_FILTER_HASH) < 0) {
11142                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11143                                                         res->port_id);
11144                 return;
11145         }
11146
11147         memset(&info, 0, sizeof(info));
11148         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11149         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11150                                         RTE_ETH_FILTER_GET, &info);
11151         if (ret < 0) {
11152                 printf("Cannot get hash global configurations by port %d\n",
11153                                                         res->port_id);
11154                 return;
11155         }
11156
11157         switch (info.info.global_conf.hash_func) {
11158         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11159                 printf("Hash function is Toeplitz\n");
11160                 break;
11161         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11162                 printf("Hash function is Simple XOR\n");
11163                 break;
11164         default:
11165                 printf("Unknown hash function\n");
11166                 break;
11167         }
11168
11169         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11170                 idx = i / UINT32_BIT;
11171                 offset = i % UINT32_BIT;
11172                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11173                                                 (1UL << offset)))
11174                         continue;
11175                 str = flowtype_to_str(i);
11176                 if (!str)
11177                         continue;
11178                 printf("Symmetric hash is %s globally for flow type %s "
11179                                                         "by port %d\n",
11180                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11181                         (1UL << offset)) ? "enabled" : "disabled"), str,
11182                                                         res->port_id);
11183         }
11184 }
11185
11186 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11187         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11188                 get_hash_global_config, "get_hash_global_config");
11189 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11190         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11191                 port_id, UINT16);
11192
11193 cmdline_parse_inst_t cmd_get_hash_global_config = {
11194         .f = cmd_get_hash_global_config_parsed,
11195         .data = NULL,
11196         .help_str = "get_hash_global_config <port_id>",
11197         .tokens = {
11198                 (void *)&cmd_get_hash_global_config_all,
11199                 (void *)&cmd_get_hash_global_config_port_id,
11200                 NULL,
11201         },
11202 };
11203
11204 /* Set global config of hash function */
11205 struct cmd_set_hash_global_config_result {
11206         cmdline_fixed_string_t set_hash_global_config;
11207         portid_t port_id;
11208         cmdline_fixed_string_t hash_func;
11209         cmdline_fixed_string_t flow_type;
11210         cmdline_fixed_string_t enable;
11211 };
11212
11213 static void
11214 cmd_set_hash_global_config_parsed(void *parsed_result,
11215                                   __rte_unused struct cmdline *cl,
11216                                   __rte_unused void *data)
11217 {
11218         struct cmd_set_hash_global_config_result *res = parsed_result;
11219         struct rte_eth_hash_filter_info info;
11220         uint32_t ftype, idx, offset;
11221         int ret;
11222
11223         if (rte_eth_dev_filter_supported(res->port_id,
11224                                 RTE_ETH_FILTER_HASH) < 0) {
11225                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11226                                                         res->port_id);
11227                 return;
11228         }
11229         memset(&info, 0, sizeof(info));
11230         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11231         if (!strcmp(res->hash_func, "toeplitz"))
11232                 info.info.global_conf.hash_func =
11233                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11234         else if (!strcmp(res->hash_func, "simple_xor"))
11235                 info.info.global_conf.hash_func =
11236                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11237         else if (!strcmp(res->hash_func, "default"))
11238                 info.info.global_conf.hash_func =
11239                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11240
11241         ftype = str2flowtype(res->flow_type);
11242         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11243         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11244         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11245         if (!strcmp(res->enable, "enable"))
11246                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11247                                                 (1UL << offset);
11248         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11249                                         RTE_ETH_FILTER_SET, &info);
11250         if (ret < 0)
11251                 printf("Cannot set global hash configurations by port %d\n",
11252                                                         res->port_id);
11253         else
11254                 printf("Global hash configurations have been set "
11255                         "succcessfully by port %d\n", res->port_id);
11256 }
11257
11258 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11259         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11260                 set_hash_global_config, "set_hash_global_config");
11261 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11262         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11263                 port_id, UINT16);
11264 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11265         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11266                 hash_func, "toeplitz#simple_xor#default");
11267 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11268         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11269                 flow_type,
11270                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11271                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11272 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11273         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11274                 enable, "enable#disable");
11275
11276 cmdline_parse_inst_t cmd_set_hash_global_config = {
11277         .f = cmd_set_hash_global_config_parsed,
11278         .data = NULL,
11279         .help_str = "set_hash_global_config <port_id> "
11280                 "toeplitz|simple_xor|default "
11281                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11282                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11283                 "l2_payload enable|disable",
11284         .tokens = {
11285                 (void *)&cmd_set_hash_global_config_all,
11286                 (void *)&cmd_set_hash_global_config_port_id,
11287                 (void *)&cmd_set_hash_global_config_hash_func,
11288                 (void *)&cmd_set_hash_global_config_flow_type,
11289                 (void *)&cmd_set_hash_global_config_enable,
11290                 NULL,
11291         },
11292 };
11293
11294 /* Set hash input set */
11295 struct cmd_set_hash_input_set_result {
11296         cmdline_fixed_string_t set_hash_input_set;
11297         portid_t port_id;
11298         cmdline_fixed_string_t flow_type;
11299         cmdline_fixed_string_t inset_field;
11300         cmdline_fixed_string_t select;
11301 };
11302
11303 static enum rte_eth_input_set_field
11304 str2inset(char *string)
11305 {
11306         uint16_t i;
11307
11308         static const struct {
11309                 char str[32];
11310                 enum rte_eth_input_set_field inset;
11311         } inset_table[] = {
11312                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11313                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11314                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11315                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11316                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11317                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11318                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11319                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11320                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11321                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11322                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11323                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11324                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11325                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11326                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11327                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11328                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11329                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11330                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11331                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11332                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11333                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11334                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11335                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11336                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11337                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11338                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11339                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11340                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11341                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11342                 {"none", RTE_ETH_INPUT_SET_NONE},
11343         };
11344
11345         for (i = 0; i < RTE_DIM(inset_table); i++) {
11346                 if (!strcmp(string, inset_table[i].str))
11347                         return inset_table[i].inset;
11348         }
11349
11350         return RTE_ETH_INPUT_SET_UNKNOWN;
11351 }
11352
11353 static void
11354 cmd_set_hash_input_set_parsed(void *parsed_result,
11355                               __rte_unused struct cmdline *cl,
11356                               __rte_unused void *data)
11357 {
11358         struct cmd_set_hash_input_set_result *res = parsed_result;
11359         struct rte_eth_hash_filter_info info;
11360
11361         memset(&info, 0, sizeof(info));
11362         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11363         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11364         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11365         info.info.input_set_conf.inset_size = 1;
11366         if (!strcmp(res->select, "select"))
11367                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11368         else if (!strcmp(res->select, "add"))
11369                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11370         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11371                                 RTE_ETH_FILTER_SET, &info);
11372 }
11373
11374 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11375         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11376                 set_hash_input_set, "set_hash_input_set");
11377 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11378         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11379                 port_id, UINT16);
11380 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11381         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11382                 flow_type, NULL);
11383 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11384         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11385                 inset_field,
11386                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11387                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11388                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11389                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11390                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11391                 "fld-8th#none");
11392 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11393         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11394                 select, "select#add");
11395
11396 cmdline_parse_inst_t cmd_set_hash_input_set = {
11397         .f = cmd_set_hash_input_set_parsed,
11398         .data = NULL,
11399         .help_str = "set_hash_input_set <port_id> "
11400         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11401         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11402         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11403         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11404         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11405         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11406         "fld-7th|fld-8th|none select|add",
11407         .tokens = {
11408                 (void *)&cmd_set_hash_input_set_cmd,
11409                 (void *)&cmd_set_hash_input_set_port_id,
11410                 (void *)&cmd_set_hash_input_set_flow_type,
11411                 (void *)&cmd_set_hash_input_set_field,
11412                 (void *)&cmd_set_hash_input_set_select,
11413                 NULL,
11414         },
11415 };
11416
11417 /* Set flow director input set */
11418 struct cmd_set_fdir_input_set_result {
11419         cmdline_fixed_string_t set_fdir_input_set;
11420         portid_t port_id;
11421         cmdline_fixed_string_t flow_type;
11422         cmdline_fixed_string_t inset_field;
11423         cmdline_fixed_string_t select;
11424 };
11425
11426 static void
11427 cmd_set_fdir_input_set_parsed(void *parsed_result,
11428         __rte_unused struct cmdline *cl,
11429         __rte_unused void *data)
11430 {
11431         struct cmd_set_fdir_input_set_result *res = parsed_result;
11432         struct rte_eth_fdir_filter_info info;
11433
11434         memset(&info, 0, sizeof(info));
11435         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11436         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11437         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11438         info.info.input_set_conf.inset_size = 1;
11439         if (!strcmp(res->select, "select"))
11440                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11441         else if (!strcmp(res->select, "add"))
11442                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11443         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11444                 RTE_ETH_FILTER_SET, &info);
11445 }
11446
11447 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11448         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11449         set_fdir_input_set, "set_fdir_input_set");
11450 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11451         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11452         port_id, UINT16);
11453 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11454         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11455         flow_type,
11456         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11457         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11458 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11459         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11460         inset_field,
11461         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11462         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11463         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11464         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11465         "sctp-veri-tag#none");
11466 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11467         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11468         select, "select#add");
11469
11470 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11471         .f = cmd_set_fdir_input_set_parsed,
11472         .data = NULL,
11473         .help_str = "set_fdir_input_set <port_id> "
11474         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11475         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11476         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11477         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11478         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11479         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11480         "sctp-veri-tag|none select|add",
11481         .tokens = {
11482                 (void *)&cmd_set_fdir_input_set_cmd,
11483                 (void *)&cmd_set_fdir_input_set_port_id,
11484                 (void *)&cmd_set_fdir_input_set_flow_type,
11485                 (void *)&cmd_set_fdir_input_set_field,
11486                 (void *)&cmd_set_fdir_input_set_select,
11487                 NULL,
11488         },
11489 };
11490
11491 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11492 struct cmd_mcast_addr_result {
11493         cmdline_fixed_string_t mcast_addr_cmd;
11494         cmdline_fixed_string_t what;
11495         uint16_t port_num;
11496         struct ether_addr mc_addr;
11497 };
11498
11499 static void cmd_mcast_addr_parsed(void *parsed_result,
11500                 __attribute__((unused)) struct cmdline *cl,
11501                 __attribute__((unused)) void *data)
11502 {
11503         struct cmd_mcast_addr_result *res = parsed_result;
11504
11505         if (!is_multicast_ether_addr(&res->mc_addr)) {
11506                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11507                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11508                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11509                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11510                 return;
11511         }
11512         if (strcmp(res->what, "add") == 0)
11513                 mcast_addr_add(res->port_num, &res->mc_addr);
11514         else
11515                 mcast_addr_remove(res->port_num, &res->mc_addr);
11516 }
11517
11518 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11519         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11520                                  mcast_addr_cmd, "mcast_addr");
11521 cmdline_parse_token_string_t cmd_mcast_addr_what =
11522         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11523                                  "add#remove");
11524 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11525         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11526 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11527         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11528
11529 cmdline_parse_inst_t cmd_mcast_addr = {
11530         .f = cmd_mcast_addr_parsed,
11531         .data = (void *)0,
11532         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11533                 "Add/Remove multicast MAC address on port_id",
11534         .tokens = {
11535                 (void *)&cmd_mcast_addr_cmd,
11536                 (void *)&cmd_mcast_addr_what,
11537                 (void *)&cmd_mcast_addr_portnum,
11538                 (void *)&cmd_mcast_addr_addr,
11539                 NULL,
11540         },
11541 };
11542
11543 /* l2 tunnel config
11544  * only support E-tag now.
11545  */
11546
11547 /* Ether type config */
11548 struct cmd_config_l2_tunnel_eth_type_result {
11549         cmdline_fixed_string_t port;
11550         cmdline_fixed_string_t config;
11551         cmdline_fixed_string_t all;
11552         uint8_t id;
11553         cmdline_fixed_string_t l2_tunnel;
11554         cmdline_fixed_string_t l2_tunnel_type;
11555         cmdline_fixed_string_t eth_type;
11556         uint16_t eth_type_val;
11557 };
11558
11559 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11560         TOKEN_STRING_INITIALIZER
11561                 (struct cmd_config_l2_tunnel_eth_type_result,
11562                  port, "port");
11563 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11564         TOKEN_STRING_INITIALIZER
11565                 (struct cmd_config_l2_tunnel_eth_type_result,
11566                  config, "config");
11567 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11568         TOKEN_STRING_INITIALIZER
11569                 (struct cmd_config_l2_tunnel_eth_type_result,
11570                  all, "all");
11571 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11572         TOKEN_NUM_INITIALIZER
11573                 (struct cmd_config_l2_tunnel_eth_type_result,
11574                  id, UINT8);
11575 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11576         TOKEN_STRING_INITIALIZER
11577                 (struct cmd_config_l2_tunnel_eth_type_result,
11578                  l2_tunnel, "l2-tunnel");
11579 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11580         TOKEN_STRING_INITIALIZER
11581                 (struct cmd_config_l2_tunnel_eth_type_result,
11582                  l2_tunnel_type, "E-tag");
11583 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11584         TOKEN_STRING_INITIALIZER
11585                 (struct cmd_config_l2_tunnel_eth_type_result,
11586                  eth_type, "ether-type");
11587 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11588         TOKEN_NUM_INITIALIZER
11589                 (struct cmd_config_l2_tunnel_eth_type_result,
11590                  eth_type_val, UINT16);
11591
11592 static enum rte_eth_tunnel_type
11593 str2fdir_l2_tunnel_type(char *string)
11594 {
11595         uint32_t i = 0;
11596
11597         static const struct {
11598                 char str[32];
11599                 enum rte_eth_tunnel_type type;
11600         } l2_tunnel_type_str[] = {
11601                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11602         };
11603
11604         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11605                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11606                         return l2_tunnel_type_str[i].type;
11607         }
11608         return RTE_TUNNEL_TYPE_NONE;
11609 }
11610
11611 /* ether type config for all ports */
11612 static void
11613 cmd_config_l2_tunnel_eth_type_all_parsed
11614         (void *parsed_result,
11615          __attribute__((unused)) struct cmdline *cl,
11616          __attribute__((unused)) void *data)
11617 {
11618         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11619         struct rte_eth_l2_tunnel_conf entry;
11620         portid_t pid;
11621
11622         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11623         entry.ether_type = res->eth_type_val;
11624
11625         RTE_ETH_FOREACH_DEV(pid) {
11626                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11627         }
11628 }
11629
11630 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11631         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11632         .data = NULL,
11633         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11634         .tokens = {
11635                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11636                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11637                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11638                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11639                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11640                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11641                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11642                 NULL,
11643         },
11644 };
11645
11646 /* ether type config for a specific port */
11647 static void
11648 cmd_config_l2_tunnel_eth_type_specific_parsed(
11649         void *parsed_result,
11650         __attribute__((unused)) struct cmdline *cl,
11651         __attribute__((unused)) void *data)
11652 {
11653         struct cmd_config_l2_tunnel_eth_type_result *res =
11654                  parsed_result;
11655         struct rte_eth_l2_tunnel_conf entry;
11656
11657         if (port_id_is_invalid(res->id, ENABLED_WARN))
11658                 return;
11659
11660         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11661         entry.ether_type = res->eth_type_val;
11662
11663         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11664 }
11665
11666 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11667         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11668         .data = NULL,
11669         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11670         .tokens = {
11671                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11672                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11673                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11674                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11675                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11676                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11677                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11678                 NULL,
11679         },
11680 };
11681
11682 /* Enable/disable l2 tunnel */
11683 struct cmd_config_l2_tunnel_en_dis_result {
11684         cmdline_fixed_string_t port;
11685         cmdline_fixed_string_t config;
11686         cmdline_fixed_string_t all;
11687         uint8_t id;
11688         cmdline_fixed_string_t l2_tunnel;
11689         cmdline_fixed_string_t l2_tunnel_type;
11690         cmdline_fixed_string_t en_dis;
11691 };
11692
11693 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11694         TOKEN_STRING_INITIALIZER
11695                 (struct cmd_config_l2_tunnel_en_dis_result,
11696                  port, "port");
11697 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11698         TOKEN_STRING_INITIALIZER
11699                 (struct cmd_config_l2_tunnel_en_dis_result,
11700                  config, "config");
11701 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11702         TOKEN_STRING_INITIALIZER
11703                 (struct cmd_config_l2_tunnel_en_dis_result,
11704                  all, "all");
11705 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11706         TOKEN_NUM_INITIALIZER
11707                 (struct cmd_config_l2_tunnel_en_dis_result,
11708                  id, UINT8);
11709 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11710         TOKEN_STRING_INITIALIZER
11711                 (struct cmd_config_l2_tunnel_en_dis_result,
11712                  l2_tunnel, "l2-tunnel");
11713 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11714         TOKEN_STRING_INITIALIZER
11715                 (struct cmd_config_l2_tunnel_en_dis_result,
11716                  l2_tunnel_type, "E-tag");
11717 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11718         TOKEN_STRING_INITIALIZER
11719                 (struct cmd_config_l2_tunnel_en_dis_result,
11720                  en_dis, "enable#disable");
11721
11722 /* enable/disable l2 tunnel for all ports */
11723 static void
11724 cmd_config_l2_tunnel_en_dis_all_parsed(
11725         void *parsed_result,
11726         __attribute__((unused)) struct cmdline *cl,
11727         __attribute__((unused)) void *data)
11728 {
11729         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11730         struct rte_eth_l2_tunnel_conf entry;
11731         portid_t pid;
11732         uint8_t en;
11733
11734         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11735
11736         if (!strcmp("enable", res->en_dis))
11737                 en = 1;
11738         else
11739                 en = 0;
11740
11741         RTE_ETH_FOREACH_DEV(pid) {
11742                 rte_eth_dev_l2_tunnel_offload_set(pid,
11743                                                   &entry,
11744                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11745                                                   en);
11746         }
11747 }
11748
11749 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11750         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11751         .data = NULL,
11752         .help_str = "port config all l2-tunnel E-tag enable|disable",
11753         .tokens = {
11754                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11755                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11756                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11757                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11758                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11759                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11760                 NULL,
11761         },
11762 };
11763
11764 /* enable/disable l2 tunnel for a port */
11765 static void
11766 cmd_config_l2_tunnel_en_dis_specific_parsed(
11767         void *parsed_result,
11768         __attribute__((unused)) struct cmdline *cl,
11769         __attribute__((unused)) void *data)
11770 {
11771         struct cmd_config_l2_tunnel_en_dis_result *res =
11772                 parsed_result;
11773         struct rte_eth_l2_tunnel_conf entry;
11774
11775         if (port_id_is_invalid(res->id, ENABLED_WARN))
11776                 return;
11777
11778         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11779
11780         if (!strcmp("enable", res->en_dis))
11781                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11782                                                   &entry,
11783                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11784                                                   1);
11785         else
11786                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11787                                                   &entry,
11788                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11789                                                   0);
11790 }
11791
11792 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11793         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11794         .data = NULL,
11795         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11796         .tokens = {
11797                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11798                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11799                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11800                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11801                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11802                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11803                 NULL,
11804         },
11805 };
11806
11807 /* E-tag configuration */
11808
11809 /* Common result structure for all E-tag configuration */
11810 struct cmd_config_e_tag_result {
11811         cmdline_fixed_string_t e_tag;
11812         cmdline_fixed_string_t set;
11813         cmdline_fixed_string_t insertion;
11814         cmdline_fixed_string_t stripping;
11815         cmdline_fixed_string_t forwarding;
11816         cmdline_fixed_string_t filter;
11817         cmdline_fixed_string_t add;
11818         cmdline_fixed_string_t del;
11819         cmdline_fixed_string_t on;
11820         cmdline_fixed_string_t off;
11821         cmdline_fixed_string_t on_off;
11822         cmdline_fixed_string_t port_tag_id;
11823         uint32_t port_tag_id_val;
11824         cmdline_fixed_string_t e_tag_id;
11825         uint16_t e_tag_id_val;
11826         cmdline_fixed_string_t dst_pool;
11827         uint8_t dst_pool_val;
11828         cmdline_fixed_string_t port;
11829         portid_t port_id;
11830         cmdline_fixed_string_t vf;
11831         uint8_t vf_id;
11832 };
11833
11834 /* Common CLI fields for all E-tag configuration */
11835 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11836         TOKEN_STRING_INITIALIZER
11837                 (struct cmd_config_e_tag_result,
11838                  e_tag, "E-tag");
11839 cmdline_parse_token_string_t cmd_config_e_tag_set =
11840         TOKEN_STRING_INITIALIZER
11841                 (struct cmd_config_e_tag_result,
11842                  set, "set");
11843 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11844         TOKEN_STRING_INITIALIZER
11845                 (struct cmd_config_e_tag_result,
11846                  insertion, "insertion");
11847 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11848         TOKEN_STRING_INITIALIZER
11849                 (struct cmd_config_e_tag_result,
11850                  stripping, "stripping");
11851 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11852         TOKEN_STRING_INITIALIZER
11853                 (struct cmd_config_e_tag_result,
11854                  forwarding, "forwarding");
11855 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11856         TOKEN_STRING_INITIALIZER
11857                 (struct cmd_config_e_tag_result,
11858                  filter, "filter");
11859 cmdline_parse_token_string_t cmd_config_e_tag_add =
11860         TOKEN_STRING_INITIALIZER
11861                 (struct cmd_config_e_tag_result,
11862                  add, "add");
11863 cmdline_parse_token_string_t cmd_config_e_tag_del =
11864         TOKEN_STRING_INITIALIZER
11865                 (struct cmd_config_e_tag_result,
11866                  del, "del");
11867 cmdline_parse_token_string_t cmd_config_e_tag_on =
11868         TOKEN_STRING_INITIALIZER
11869                 (struct cmd_config_e_tag_result,
11870                  on, "on");
11871 cmdline_parse_token_string_t cmd_config_e_tag_off =
11872         TOKEN_STRING_INITIALIZER
11873                 (struct cmd_config_e_tag_result,
11874                  off, "off");
11875 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11876         TOKEN_STRING_INITIALIZER
11877                 (struct cmd_config_e_tag_result,
11878                  on_off, "on#off");
11879 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11880         TOKEN_STRING_INITIALIZER
11881                 (struct cmd_config_e_tag_result,
11882                  port_tag_id, "port-tag-id");
11883 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11884         TOKEN_NUM_INITIALIZER
11885                 (struct cmd_config_e_tag_result,
11886                  port_tag_id_val, UINT32);
11887 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11888         TOKEN_STRING_INITIALIZER
11889                 (struct cmd_config_e_tag_result,
11890                  e_tag_id, "e-tag-id");
11891 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11892         TOKEN_NUM_INITIALIZER
11893                 (struct cmd_config_e_tag_result,
11894                  e_tag_id_val, UINT16);
11895 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11896         TOKEN_STRING_INITIALIZER
11897                 (struct cmd_config_e_tag_result,
11898                  dst_pool, "dst-pool");
11899 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11900         TOKEN_NUM_INITIALIZER
11901                 (struct cmd_config_e_tag_result,
11902                  dst_pool_val, UINT8);
11903 cmdline_parse_token_string_t cmd_config_e_tag_port =
11904         TOKEN_STRING_INITIALIZER
11905                 (struct cmd_config_e_tag_result,
11906                  port, "port");
11907 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11908         TOKEN_NUM_INITIALIZER
11909                 (struct cmd_config_e_tag_result,
11910                  port_id, UINT16);
11911 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11912         TOKEN_STRING_INITIALIZER
11913                 (struct cmd_config_e_tag_result,
11914                  vf, "vf");
11915 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11916         TOKEN_NUM_INITIALIZER
11917                 (struct cmd_config_e_tag_result,
11918                  vf_id, UINT8);
11919
11920 /* E-tag insertion configuration */
11921 static void
11922 cmd_config_e_tag_insertion_en_parsed(
11923         void *parsed_result,
11924         __attribute__((unused)) struct cmdline *cl,
11925         __attribute__((unused)) void *data)
11926 {
11927         struct cmd_config_e_tag_result *res =
11928                 parsed_result;
11929         struct rte_eth_l2_tunnel_conf entry;
11930
11931         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11932                 return;
11933
11934         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11935         entry.tunnel_id = res->port_tag_id_val;
11936         entry.vf_id = res->vf_id;
11937         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11938                                           &entry,
11939                                           ETH_L2_TUNNEL_INSERTION_MASK,
11940                                           1);
11941 }
11942
11943 static void
11944 cmd_config_e_tag_insertion_dis_parsed(
11945         void *parsed_result,
11946         __attribute__((unused)) struct cmdline *cl,
11947         __attribute__((unused)) void *data)
11948 {
11949         struct cmd_config_e_tag_result *res =
11950                 parsed_result;
11951         struct rte_eth_l2_tunnel_conf entry;
11952
11953         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11954                 return;
11955
11956         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11957         entry.vf_id = res->vf_id;
11958
11959         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11960                                           &entry,
11961                                           ETH_L2_TUNNEL_INSERTION_MASK,
11962                                           0);
11963 }
11964
11965 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11966         .f = cmd_config_e_tag_insertion_en_parsed,
11967         .data = NULL,
11968         .help_str = "E-tag ... : E-tag insertion enable",
11969         .tokens = {
11970                 (void *)&cmd_config_e_tag_e_tag,
11971                 (void *)&cmd_config_e_tag_set,
11972                 (void *)&cmd_config_e_tag_insertion,
11973                 (void *)&cmd_config_e_tag_on,
11974                 (void *)&cmd_config_e_tag_port_tag_id,
11975                 (void *)&cmd_config_e_tag_port_tag_id_val,
11976                 (void *)&cmd_config_e_tag_port,
11977                 (void *)&cmd_config_e_tag_port_id,
11978                 (void *)&cmd_config_e_tag_vf,
11979                 (void *)&cmd_config_e_tag_vf_id,
11980                 NULL,
11981         },
11982 };
11983
11984 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11985         .f = cmd_config_e_tag_insertion_dis_parsed,
11986         .data = NULL,
11987         .help_str = "E-tag ... : E-tag insertion disable",
11988         .tokens = {
11989                 (void *)&cmd_config_e_tag_e_tag,
11990                 (void *)&cmd_config_e_tag_set,
11991                 (void *)&cmd_config_e_tag_insertion,
11992                 (void *)&cmd_config_e_tag_off,
11993                 (void *)&cmd_config_e_tag_port,
11994                 (void *)&cmd_config_e_tag_port_id,
11995                 (void *)&cmd_config_e_tag_vf,
11996                 (void *)&cmd_config_e_tag_vf_id,
11997                 NULL,
11998         },
11999 };
12000
12001 /* E-tag stripping configuration */
12002 static void
12003 cmd_config_e_tag_stripping_parsed(
12004         void *parsed_result,
12005         __attribute__((unused)) struct cmdline *cl,
12006         __attribute__((unused)) void *data)
12007 {
12008         struct cmd_config_e_tag_result *res =
12009                 parsed_result;
12010         struct rte_eth_l2_tunnel_conf entry;
12011
12012         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12013                 return;
12014
12015         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12016
12017         if (!strcmp(res->on_off, "on"))
12018                 rte_eth_dev_l2_tunnel_offload_set
12019                         (res->port_id,
12020                          &entry,
12021                          ETH_L2_TUNNEL_STRIPPING_MASK,
12022                          1);
12023         else
12024                 rte_eth_dev_l2_tunnel_offload_set
12025                         (res->port_id,
12026                          &entry,
12027                          ETH_L2_TUNNEL_STRIPPING_MASK,
12028                          0);
12029 }
12030
12031 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12032         .f = cmd_config_e_tag_stripping_parsed,
12033         .data = NULL,
12034         .help_str = "E-tag ... : E-tag stripping enable/disable",
12035         .tokens = {
12036                 (void *)&cmd_config_e_tag_e_tag,
12037                 (void *)&cmd_config_e_tag_set,
12038                 (void *)&cmd_config_e_tag_stripping,
12039                 (void *)&cmd_config_e_tag_on_off,
12040                 (void *)&cmd_config_e_tag_port,
12041                 (void *)&cmd_config_e_tag_port_id,
12042                 NULL,
12043         },
12044 };
12045
12046 /* E-tag forwarding configuration */
12047 static void
12048 cmd_config_e_tag_forwarding_parsed(
12049         void *parsed_result,
12050         __attribute__((unused)) struct cmdline *cl,
12051         __attribute__((unused)) void *data)
12052 {
12053         struct cmd_config_e_tag_result *res = parsed_result;
12054         struct rte_eth_l2_tunnel_conf entry;
12055
12056         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12057                 return;
12058
12059         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12060
12061         if (!strcmp(res->on_off, "on"))
12062                 rte_eth_dev_l2_tunnel_offload_set
12063                         (res->port_id,
12064                          &entry,
12065                          ETH_L2_TUNNEL_FORWARDING_MASK,
12066                          1);
12067         else
12068                 rte_eth_dev_l2_tunnel_offload_set
12069                         (res->port_id,
12070                          &entry,
12071                          ETH_L2_TUNNEL_FORWARDING_MASK,
12072                          0);
12073 }
12074
12075 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12076         .f = cmd_config_e_tag_forwarding_parsed,
12077         .data = NULL,
12078         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12079         .tokens = {
12080                 (void *)&cmd_config_e_tag_e_tag,
12081                 (void *)&cmd_config_e_tag_set,
12082                 (void *)&cmd_config_e_tag_forwarding,
12083                 (void *)&cmd_config_e_tag_on_off,
12084                 (void *)&cmd_config_e_tag_port,
12085                 (void *)&cmd_config_e_tag_port_id,
12086                 NULL,
12087         },
12088 };
12089
12090 /* E-tag filter configuration */
12091 static void
12092 cmd_config_e_tag_filter_add_parsed(
12093         void *parsed_result,
12094         __attribute__((unused)) struct cmdline *cl,
12095         __attribute__((unused)) void *data)
12096 {
12097         struct cmd_config_e_tag_result *res = parsed_result;
12098         struct rte_eth_l2_tunnel_conf entry;
12099         int ret = 0;
12100
12101         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12102                 return;
12103
12104         if (res->e_tag_id_val > 0x3fff) {
12105                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12106                 return;
12107         }
12108
12109         ret = rte_eth_dev_filter_supported(res->port_id,
12110                                            RTE_ETH_FILTER_L2_TUNNEL);
12111         if (ret < 0) {
12112                 printf("E-tag filter is not supported on port %u.\n",
12113                        res->port_id);
12114                 return;
12115         }
12116
12117         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12118         entry.tunnel_id = res->e_tag_id_val;
12119         entry.pool = res->dst_pool_val;
12120
12121         ret = rte_eth_dev_filter_ctrl(res->port_id,
12122                                       RTE_ETH_FILTER_L2_TUNNEL,
12123                                       RTE_ETH_FILTER_ADD,
12124                                       &entry);
12125         if (ret < 0)
12126                 printf("E-tag filter programming error: (%s)\n",
12127                        strerror(-ret));
12128 }
12129
12130 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12131         .f = cmd_config_e_tag_filter_add_parsed,
12132         .data = NULL,
12133         .help_str = "E-tag ... : E-tag filter add",
12134         .tokens = {
12135                 (void *)&cmd_config_e_tag_e_tag,
12136                 (void *)&cmd_config_e_tag_set,
12137                 (void *)&cmd_config_e_tag_filter,
12138                 (void *)&cmd_config_e_tag_add,
12139                 (void *)&cmd_config_e_tag_e_tag_id,
12140                 (void *)&cmd_config_e_tag_e_tag_id_val,
12141                 (void *)&cmd_config_e_tag_dst_pool,
12142                 (void *)&cmd_config_e_tag_dst_pool_val,
12143                 (void *)&cmd_config_e_tag_port,
12144                 (void *)&cmd_config_e_tag_port_id,
12145                 NULL,
12146         },
12147 };
12148
12149 static void
12150 cmd_config_e_tag_filter_del_parsed(
12151         void *parsed_result,
12152         __attribute__((unused)) struct cmdline *cl,
12153         __attribute__((unused)) void *data)
12154 {
12155         struct cmd_config_e_tag_result *res = parsed_result;
12156         struct rte_eth_l2_tunnel_conf entry;
12157         int ret = 0;
12158
12159         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12160                 return;
12161
12162         if (res->e_tag_id_val > 0x3fff) {
12163                 printf("e-tag-id must be less than 0x3fff.\n");
12164                 return;
12165         }
12166
12167         ret = rte_eth_dev_filter_supported(res->port_id,
12168                                            RTE_ETH_FILTER_L2_TUNNEL);
12169         if (ret < 0) {
12170                 printf("E-tag filter is not supported on port %u.\n",
12171                        res->port_id);
12172                 return;
12173         }
12174
12175         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12176         entry.tunnel_id = res->e_tag_id_val;
12177
12178         ret = rte_eth_dev_filter_ctrl(res->port_id,
12179                                       RTE_ETH_FILTER_L2_TUNNEL,
12180                                       RTE_ETH_FILTER_DELETE,
12181                                       &entry);
12182         if (ret < 0)
12183                 printf("E-tag filter programming error: (%s)\n",
12184                        strerror(-ret));
12185 }
12186
12187 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12188         .f = cmd_config_e_tag_filter_del_parsed,
12189         .data = NULL,
12190         .help_str = "E-tag ... : E-tag filter delete",
12191         .tokens = {
12192                 (void *)&cmd_config_e_tag_e_tag,
12193                 (void *)&cmd_config_e_tag_set,
12194                 (void *)&cmd_config_e_tag_filter,
12195                 (void *)&cmd_config_e_tag_del,
12196                 (void *)&cmd_config_e_tag_e_tag_id,
12197                 (void *)&cmd_config_e_tag_e_tag_id_val,
12198                 (void *)&cmd_config_e_tag_port,
12199                 (void *)&cmd_config_e_tag_port_id,
12200                 NULL,
12201         },
12202 };
12203
12204 /* vf vlan anti spoof configuration */
12205
12206 /* Common result structure for vf vlan anti spoof */
12207 struct cmd_vf_vlan_anti_spoof_result {
12208         cmdline_fixed_string_t set;
12209         cmdline_fixed_string_t vf;
12210         cmdline_fixed_string_t vlan;
12211         cmdline_fixed_string_t antispoof;
12212         portid_t port_id;
12213         uint32_t vf_id;
12214         cmdline_fixed_string_t on_off;
12215 };
12216
12217 /* Common CLI fields for vf vlan anti spoof enable disable */
12218 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12219         TOKEN_STRING_INITIALIZER
12220                 (struct cmd_vf_vlan_anti_spoof_result,
12221                  set, "set");
12222 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12223         TOKEN_STRING_INITIALIZER
12224                 (struct cmd_vf_vlan_anti_spoof_result,
12225                  vf, "vf");
12226 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12227         TOKEN_STRING_INITIALIZER
12228                 (struct cmd_vf_vlan_anti_spoof_result,
12229                  vlan, "vlan");
12230 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12231         TOKEN_STRING_INITIALIZER
12232                 (struct cmd_vf_vlan_anti_spoof_result,
12233                  antispoof, "antispoof");
12234 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12235         TOKEN_NUM_INITIALIZER
12236                 (struct cmd_vf_vlan_anti_spoof_result,
12237                  port_id, UINT16);
12238 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12239         TOKEN_NUM_INITIALIZER
12240                 (struct cmd_vf_vlan_anti_spoof_result,
12241                  vf_id, UINT32);
12242 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12243         TOKEN_STRING_INITIALIZER
12244                 (struct cmd_vf_vlan_anti_spoof_result,
12245                  on_off, "on#off");
12246
12247 static void
12248 cmd_set_vf_vlan_anti_spoof_parsed(
12249         void *parsed_result,
12250         __attribute__((unused)) struct cmdline *cl,
12251         __attribute__((unused)) void *data)
12252 {
12253         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12254         int ret = -ENOTSUP;
12255
12256         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12257
12258         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12259                 return;
12260
12261 #ifdef RTE_LIBRTE_IXGBE_PMD
12262         if (ret == -ENOTSUP)
12263                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12264                                 res->vf_id, is_on);
12265 #endif
12266 #ifdef RTE_LIBRTE_I40E_PMD
12267         if (ret == -ENOTSUP)
12268                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12269                                 res->vf_id, is_on);
12270 #endif
12271 #ifdef RTE_LIBRTE_BNXT_PMD
12272         if (ret == -ENOTSUP)
12273                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12274                                 res->vf_id, is_on);
12275 #endif
12276
12277         switch (ret) {
12278         case 0:
12279                 break;
12280         case -EINVAL:
12281                 printf("invalid vf_id %d\n", res->vf_id);
12282                 break;
12283         case -ENODEV:
12284                 printf("invalid port_id %d\n", res->port_id);
12285                 break;
12286         case -ENOTSUP:
12287                 printf("function not implemented\n");
12288                 break;
12289         default:
12290                 printf("programming error: (%s)\n", strerror(-ret));
12291         }
12292 }
12293
12294 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12295         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12296         .data = NULL,
12297         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12298         .tokens = {
12299                 (void *)&cmd_vf_vlan_anti_spoof_set,
12300                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12301                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12302                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12303                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12304                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12305                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12306                 NULL,
12307         },
12308 };
12309
12310 /* vf mac anti spoof configuration */
12311
12312 /* Common result structure for vf mac anti spoof */
12313 struct cmd_vf_mac_anti_spoof_result {
12314         cmdline_fixed_string_t set;
12315         cmdline_fixed_string_t vf;
12316         cmdline_fixed_string_t mac;
12317         cmdline_fixed_string_t antispoof;
12318         portid_t port_id;
12319         uint32_t vf_id;
12320         cmdline_fixed_string_t on_off;
12321 };
12322
12323 /* Common CLI fields for vf mac anti spoof enable disable */
12324 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12325         TOKEN_STRING_INITIALIZER
12326                 (struct cmd_vf_mac_anti_spoof_result,
12327                  set, "set");
12328 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12329         TOKEN_STRING_INITIALIZER
12330                 (struct cmd_vf_mac_anti_spoof_result,
12331                  vf, "vf");
12332 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12333         TOKEN_STRING_INITIALIZER
12334                 (struct cmd_vf_mac_anti_spoof_result,
12335                  mac, "mac");
12336 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12337         TOKEN_STRING_INITIALIZER
12338                 (struct cmd_vf_mac_anti_spoof_result,
12339                  antispoof, "antispoof");
12340 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12341         TOKEN_NUM_INITIALIZER
12342                 (struct cmd_vf_mac_anti_spoof_result,
12343                  port_id, UINT16);
12344 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12345         TOKEN_NUM_INITIALIZER
12346                 (struct cmd_vf_mac_anti_spoof_result,
12347                  vf_id, UINT32);
12348 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12349         TOKEN_STRING_INITIALIZER
12350                 (struct cmd_vf_mac_anti_spoof_result,
12351                  on_off, "on#off");
12352
12353 static void
12354 cmd_set_vf_mac_anti_spoof_parsed(
12355         void *parsed_result,
12356         __attribute__((unused)) struct cmdline *cl,
12357         __attribute__((unused)) void *data)
12358 {
12359         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12360         int ret = -ENOTSUP;
12361
12362         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12363
12364         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12365                 return;
12366
12367 #ifdef RTE_LIBRTE_IXGBE_PMD
12368         if (ret == -ENOTSUP)
12369                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12370                         res->vf_id, is_on);
12371 #endif
12372 #ifdef RTE_LIBRTE_I40E_PMD
12373         if (ret == -ENOTSUP)
12374                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12375                         res->vf_id, is_on);
12376 #endif
12377 #ifdef RTE_LIBRTE_BNXT_PMD
12378         if (ret == -ENOTSUP)
12379                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12380                         res->vf_id, is_on);
12381 #endif
12382
12383         switch (ret) {
12384         case 0:
12385                 break;
12386         case -EINVAL:
12387                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12388                 break;
12389         case -ENODEV:
12390                 printf("invalid port_id %d\n", res->port_id);
12391                 break;
12392         case -ENOTSUP:
12393                 printf("function not implemented\n");
12394                 break;
12395         default:
12396                 printf("programming error: (%s)\n", strerror(-ret));
12397         }
12398 }
12399
12400 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12401         .f = cmd_set_vf_mac_anti_spoof_parsed,
12402         .data = NULL,
12403         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12404         .tokens = {
12405                 (void *)&cmd_vf_mac_anti_spoof_set,
12406                 (void *)&cmd_vf_mac_anti_spoof_vf,
12407                 (void *)&cmd_vf_mac_anti_spoof_mac,
12408                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12409                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12410                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12411                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12412                 NULL,
12413         },
12414 };
12415
12416 /* vf vlan strip queue configuration */
12417
12418 /* Common result structure for vf mac anti spoof */
12419 struct cmd_vf_vlan_stripq_result {
12420         cmdline_fixed_string_t set;
12421         cmdline_fixed_string_t vf;
12422         cmdline_fixed_string_t vlan;
12423         cmdline_fixed_string_t stripq;
12424         portid_t port_id;
12425         uint16_t vf_id;
12426         cmdline_fixed_string_t on_off;
12427 };
12428
12429 /* Common CLI fields for vf vlan strip enable disable */
12430 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12431         TOKEN_STRING_INITIALIZER
12432                 (struct cmd_vf_vlan_stripq_result,
12433                  set, "set");
12434 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12435         TOKEN_STRING_INITIALIZER
12436                 (struct cmd_vf_vlan_stripq_result,
12437                  vf, "vf");
12438 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12439         TOKEN_STRING_INITIALIZER
12440                 (struct cmd_vf_vlan_stripq_result,
12441                  vlan, "vlan");
12442 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12443         TOKEN_STRING_INITIALIZER
12444                 (struct cmd_vf_vlan_stripq_result,
12445                  stripq, "stripq");
12446 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12447         TOKEN_NUM_INITIALIZER
12448                 (struct cmd_vf_vlan_stripq_result,
12449                  port_id, UINT16);
12450 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12451         TOKEN_NUM_INITIALIZER
12452                 (struct cmd_vf_vlan_stripq_result,
12453                  vf_id, UINT16);
12454 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12455         TOKEN_STRING_INITIALIZER
12456                 (struct cmd_vf_vlan_stripq_result,
12457                  on_off, "on#off");
12458
12459 static void
12460 cmd_set_vf_vlan_stripq_parsed(
12461         void *parsed_result,
12462         __attribute__((unused)) struct cmdline *cl,
12463         __attribute__((unused)) void *data)
12464 {
12465         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12466         int ret = -ENOTSUP;
12467
12468         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12469
12470         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12471                 return;
12472
12473 #ifdef RTE_LIBRTE_IXGBE_PMD
12474         if (ret == -ENOTSUP)
12475                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12476                         res->vf_id, is_on);
12477 #endif
12478 #ifdef RTE_LIBRTE_I40E_PMD
12479         if (ret == -ENOTSUP)
12480                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12481                         res->vf_id, is_on);
12482 #endif
12483 #ifdef RTE_LIBRTE_BNXT_PMD
12484         if (ret == -ENOTSUP)
12485                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12486                         res->vf_id, is_on);
12487 #endif
12488
12489         switch (ret) {
12490         case 0:
12491                 break;
12492         case -EINVAL:
12493                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12494                 break;
12495         case -ENODEV:
12496                 printf("invalid port_id %d\n", res->port_id);
12497                 break;
12498         case -ENOTSUP:
12499                 printf("function not implemented\n");
12500                 break;
12501         default:
12502                 printf("programming error: (%s)\n", strerror(-ret));
12503         }
12504 }
12505
12506 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12507         .f = cmd_set_vf_vlan_stripq_parsed,
12508         .data = NULL,
12509         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12510         .tokens = {
12511                 (void *)&cmd_vf_vlan_stripq_set,
12512                 (void *)&cmd_vf_vlan_stripq_vf,
12513                 (void *)&cmd_vf_vlan_stripq_vlan,
12514                 (void *)&cmd_vf_vlan_stripq_stripq,
12515                 (void *)&cmd_vf_vlan_stripq_port_id,
12516                 (void *)&cmd_vf_vlan_stripq_vf_id,
12517                 (void *)&cmd_vf_vlan_stripq_on_off,
12518                 NULL,
12519         },
12520 };
12521
12522 /* vf vlan insert configuration */
12523
12524 /* Common result structure for vf vlan insert */
12525 struct cmd_vf_vlan_insert_result {
12526         cmdline_fixed_string_t set;
12527         cmdline_fixed_string_t vf;
12528         cmdline_fixed_string_t vlan;
12529         cmdline_fixed_string_t insert;
12530         portid_t port_id;
12531         uint16_t vf_id;
12532         uint16_t vlan_id;
12533 };
12534
12535 /* Common CLI fields for vf vlan insert enable disable */
12536 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_vf_vlan_insert_result,
12539                  set, "set");
12540 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12541         TOKEN_STRING_INITIALIZER
12542                 (struct cmd_vf_vlan_insert_result,
12543                  vf, "vf");
12544 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12545         TOKEN_STRING_INITIALIZER
12546                 (struct cmd_vf_vlan_insert_result,
12547                  vlan, "vlan");
12548 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12549         TOKEN_STRING_INITIALIZER
12550                 (struct cmd_vf_vlan_insert_result,
12551                  insert, "insert");
12552 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12553         TOKEN_NUM_INITIALIZER
12554                 (struct cmd_vf_vlan_insert_result,
12555                  port_id, UINT16);
12556 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12557         TOKEN_NUM_INITIALIZER
12558                 (struct cmd_vf_vlan_insert_result,
12559                  vf_id, UINT16);
12560 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12561         TOKEN_NUM_INITIALIZER
12562                 (struct cmd_vf_vlan_insert_result,
12563                  vlan_id, UINT16);
12564
12565 static void
12566 cmd_set_vf_vlan_insert_parsed(
12567         void *parsed_result,
12568         __attribute__((unused)) struct cmdline *cl,
12569         __attribute__((unused)) void *data)
12570 {
12571         struct cmd_vf_vlan_insert_result *res = parsed_result;
12572         int ret = -ENOTSUP;
12573
12574         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12575                 return;
12576
12577 #ifdef RTE_LIBRTE_IXGBE_PMD
12578         if (ret == -ENOTSUP)
12579                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12580                         res->vlan_id);
12581 #endif
12582 #ifdef RTE_LIBRTE_I40E_PMD
12583         if (ret == -ENOTSUP)
12584                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12585                         res->vlan_id);
12586 #endif
12587 #ifdef RTE_LIBRTE_BNXT_PMD
12588         if (ret == -ENOTSUP)
12589                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12590                         res->vlan_id);
12591 #endif
12592
12593         switch (ret) {
12594         case 0:
12595                 break;
12596         case -EINVAL:
12597                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12598                 break;
12599         case -ENODEV:
12600                 printf("invalid port_id %d\n", res->port_id);
12601                 break;
12602         case -ENOTSUP:
12603                 printf("function not implemented\n");
12604                 break;
12605         default:
12606                 printf("programming error: (%s)\n", strerror(-ret));
12607         }
12608 }
12609
12610 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12611         .f = cmd_set_vf_vlan_insert_parsed,
12612         .data = NULL,
12613         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12614         .tokens = {
12615                 (void *)&cmd_vf_vlan_insert_set,
12616                 (void *)&cmd_vf_vlan_insert_vf,
12617                 (void *)&cmd_vf_vlan_insert_vlan,
12618                 (void *)&cmd_vf_vlan_insert_insert,
12619                 (void *)&cmd_vf_vlan_insert_port_id,
12620                 (void *)&cmd_vf_vlan_insert_vf_id,
12621                 (void *)&cmd_vf_vlan_insert_vlan_id,
12622                 NULL,
12623         },
12624 };
12625
12626 /* tx loopback configuration */
12627
12628 /* Common result structure for tx loopback */
12629 struct cmd_tx_loopback_result {
12630         cmdline_fixed_string_t set;
12631         cmdline_fixed_string_t tx;
12632         cmdline_fixed_string_t loopback;
12633         portid_t port_id;
12634         cmdline_fixed_string_t on_off;
12635 };
12636
12637 /* Common CLI fields for tx loopback enable disable */
12638 cmdline_parse_token_string_t cmd_tx_loopback_set =
12639         TOKEN_STRING_INITIALIZER
12640                 (struct cmd_tx_loopback_result,
12641                  set, "set");
12642 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12643         TOKEN_STRING_INITIALIZER
12644                 (struct cmd_tx_loopback_result,
12645                  tx, "tx");
12646 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12647         TOKEN_STRING_INITIALIZER
12648                 (struct cmd_tx_loopback_result,
12649                  loopback, "loopback");
12650 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12651         TOKEN_NUM_INITIALIZER
12652                 (struct cmd_tx_loopback_result,
12653                  port_id, UINT16);
12654 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12655         TOKEN_STRING_INITIALIZER
12656                 (struct cmd_tx_loopback_result,
12657                  on_off, "on#off");
12658
12659 static void
12660 cmd_set_tx_loopback_parsed(
12661         void *parsed_result,
12662         __attribute__((unused)) struct cmdline *cl,
12663         __attribute__((unused)) void *data)
12664 {
12665         struct cmd_tx_loopback_result *res = parsed_result;
12666         int ret = -ENOTSUP;
12667
12668         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12669
12670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12671                 return;
12672
12673 #ifdef RTE_LIBRTE_IXGBE_PMD
12674         if (ret == -ENOTSUP)
12675                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12676 #endif
12677 #ifdef RTE_LIBRTE_I40E_PMD
12678         if (ret == -ENOTSUP)
12679                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12680 #endif
12681 #ifdef RTE_LIBRTE_BNXT_PMD
12682         if (ret == -ENOTSUP)
12683                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12684 #endif
12685
12686         switch (ret) {
12687         case 0:
12688                 break;
12689         case -EINVAL:
12690                 printf("invalid is_on %d\n", is_on);
12691                 break;
12692         case -ENODEV:
12693                 printf("invalid port_id %d\n", res->port_id);
12694                 break;
12695         case -ENOTSUP:
12696                 printf("function not implemented\n");
12697                 break;
12698         default:
12699                 printf("programming error: (%s)\n", strerror(-ret));
12700         }
12701 }
12702
12703 cmdline_parse_inst_t cmd_set_tx_loopback = {
12704         .f = cmd_set_tx_loopback_parsed,
12705         .data = NULL,
12706         .help_str = "set tx loopback <port_id> on|off",
12707         .tokens = {
12708                 (void *)&cmd_tx_loopback_set,
12709                 (void *)&cmd_tx_loopback_tx,
12710                 (void *)&cmd_tx_loopback_loopback,
12711                 (void *)&cmd_tx_loopback_port_id,
12712                 (void *)&cmd_tx_loopback_on_off,
12713                 NULL,
12714         },
12715 };
12716
12717 /* all queues drop enable configuration */
12718
12719 /* Common result structure for all queues drop enable */
12720 struct cmd_all_queues_drop_en_result {
12721         cmdline_fixed_string_t set;
12722         cmdline_fixed_string_t all;
12723         cmdline_fixed_string_t queues;
12724         cmdline_fixed_string_t drop;
12725         portid_t port_id;
12726         cmdline_fixed_string_t on_off;
12727 };
12728
12729 /* Common CLI fields for tx loopback enable disable */
12730 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12731         TOKEN_STRING_INITIALIZER
12732                 (struct cmd_all_queues_drop_en_result,
12733                  set, "set");
12734 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12735         TOKEN_STRING_INITIALIZER
12736                 (struct cmd_all_queues_drop_en_result,
12737                  all, "all");
12738 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12739         TOKEN_STRING_INITIALIZER
12740                 (struct cmd_all_queues_drop_en_result,
12741                  queues, "queues");
12742 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12743         TOKEN_STRING_INITIALIZER
12744                 (struct cmd_all_queues_drop_en_result,
12745                  drop, "drop");
12746 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12747         TOKEN_NUM_INITIALIZER
12748                 (struct cmd_all_queues_drop_en_result,
12749                  port_id, UINT16);
12750 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12751         TOKEN_STRING_INITIALIZER
12752                 (struct cmd_all_queues_drop_en_result,
12753                  on_off, "on#off");
12754
12755 static void
12756 cmd_set_all_queues_drop_en_parsed(
12757         void *parsed_result,
12758         __attribute__((unused)) struct cmdline *cl,
12759         __attribute__((unused)) void *data)
12760 {
12761         struct cmd_all_queues_drop_en_result *res = parsed_result;
12762         int ret = -ENOTSUP;
12763         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12764
12765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12766                 return;
12767
12768 #ifdef RTE_LIBRTE_IXGBE_PMD
12769         if (ret == -ENOTSUP)
12770                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12771 #endif
12772 #ifdef RTE_LIBRTE_BNXT_PMD
12773         if (ret == -ENOTSUP)
12774                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12775 #endif
12776         switch (ret) {
12777         case 0:
12778                 break;
12779         case -EINVAL:
12780                 printf("invalid is_on %d\n", is_on);
12781                 break;
12782         case -ENODEV:
12783                 printf("invalid port_id %d\n", res->port_id);
12784                 break;
12785         case -ENOTSUP:
12786                 printf("function not implemented\n");
12787                 break;
12788         default:
12789                 printf("programming error: (%s)\n", strerror(-ret));
12790         }
12791 }
12792
12793 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12794         .f = cmd_set_all_queues_drop_en_parsed,
12795         .data = NULL,
12796         .help_str = "set all queues drop <port_id> on|off",
12797         .tokens = {
12798                 (void *)&cmd_all_queues_drop_en_set,
12799                 (void *)&cmd_all_queues_drop_en_all,
12800                 (void *)&cmd_all_queues_drop_en_queues,
12801                 (void *)&cmd_all_queues_drop_en_drop,
12802                 (void *)&cmd_all_queues_drop_en_port_id,
12803                 (void *)&cmd_all_queues_drop_en_on_off,
12804                 NULL,
12805         },
12806 };
12807
12808 /* vf split drop enable configuration */
12809
12810 /* Common result structure for vf split drop enable */
12811 struct cmd_vf_split_drop_en_result {
12812         cmdline_fixed_string_t set;
12813         cmdline_fixed_string_t vf;
12814         cmdline_fixed_string_t split;
12815         cmdline_fixed_string_t drop;
12816         portid_t port_id;
12817         uint16_t vf_id;
12818         cmdline_fixed_string_t on_off;
12819 };
12820
12821 /* Common CLI fields for vf split drop enable disable */
12822 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12823         TOKEN_STRING_INITIALIZER
12824                 (struct cmd_vf_split_drop_en_result,
12825                  set, "set");
12826 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12827         TOKEN_STRING_INITIALIZER
12828                 (struct cmd_vf_split_drop_en_result,
12829                  vf, "vf");
12830 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12831         TOKEN_STRING_INITIALIZER
12832                 (struct cmd_vf_split_drop_en_result,
12833                  split, "split");
12834 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12835         TOKEN_STRING_INITIALIZER
12836                 (struct cmd_vf_split_drop_en_result,
12837                  drop, "drop");
12838 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12839         TOKEN_NUM_INITIALIZER
12840                 (struct cmd_vf_split_drop_en_result,
12841                  port_id, UINT16);
12842 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12843         TOKEN_NUM_INITIALIZER
12844                 (struct cmd_vf_split_drop_en_result,
12845                  vf_id, UINT16);
12846 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12847         TOKEN_STRING_INITIALIZER
12848                 (struct cmd_vf_split_drop_en_result,
12849                  on_off, "on#off");
12850
12851 static void
12852 cmd_set_vf_split_drop_en_parsed(
12853         void *parsed_result,
12854         __attribute__((unused)) struct cmdline *cl,
12855         __attribute__((unused)) void *data)
12856 {
12857         struct cmd_vf_split_drop_en_result *res = parsed_result;
12858         int ret = -ENOTSUP;
12859         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12860
12861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12862                 return;
12863
12864 #ifdef RTE_LIBRTE_IXGBE_PMD
12865         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12866                         is_on);
12867 #endif
12868         switch (ret) {
12869         case 0:
12870                 break;
12871         case -EINVAL:
12872                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12873                 break;
12874         case -ENODEV:
12875                 printf("invalid port_id %d\n", res->port_id);
12876                 break;
12877         case -ENOTSUP:
12878                 printf("not supported on port %d\n", res->port_id);
12879                 break;
12880         default:
12881                 printf("programming error: (%s)\n", strerror(-ret));
12882         }
12883 }
12884
12885 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12886         .f = cmd_set_vf_split_drop_en_parsed,
12887         .data = NULL,
12888         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12889         .tokens = {
12890                 (void *)&cmd_vf_split_drop_en_set,
12891                 (void *)&cmd_vf_split_drop_en_vf,
12892                 (void *)&cmd_vf_split_drop_en_split,
12893                 (void *)&cmd_vf_split_drop_en_drop,
12894                 (void *)&cmd_vf_split_drop_en_port_id,
12895                 (void *)&cmd_vf_split_drop_en_vf_id,
12896                 (void *)&cmd_vf_split_drop_en_on_off,
12897                 NULL,
12898         },
12899 };
12900
12901 /* vf mac address configuration */
12902
12903 /* Common result structure for vf mac address */
12904 struct cmd_set_vf_mac_addr_result {
12905         cmdline_fixed_string_t set;
12906         cmdline_fixed_string_t vf;
12907         cmdline_fixed_string_t mac;
12908         cmdline_fixed_string_t addr;
12909         portid_t port_id;
12910         uint16_t vf_id;
12911         struct ether_addr mac_addr;
12912
12913 };
12914
12915 /* Common CLI fields for vf split drop enable disable */
12916 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12917         TOKEN_STRING_INITIALIZER
12918                 (struct cmd_set_vf_mac_addr_result,
12919                  set, "set");
12920 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12921         TOKEN_STRING_INITIALIZER
12922                 (struct cmd_set_vf_mac_addr_result,
12923                  vf, "vf");
12924 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12925         TOKEN_STRING_INITIALIZER
12926                 (struct cmd_set_vf_mac_addr_result,
12927                  mac, "mac");
12928 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12929         TOKEN_STRING_INITIALIZER
12930                 (struct cmd_set_vf_mac_addr_result,
12931                  addr, "addr");
12932 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12933         TOKEN_NUM_INITIALIZER
12934                 (struct cmd_set_vf_mac_addr_result,
12935                  port_id, UINT16);
12936 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12937         TOKEN_NUM_INITIALIZER
12938                 (struct cmd_set_vf_mac_addr_result,
12939                  vf_id, UINT16);
12940 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12941         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12942                  mac_addr);
12943
12944 static void
12945 cmd_set_vf_mac_addr_parsed(
12946         void *parsed_result,
12947         __attribute__((unused)) struct cmdline *cl,
12948         __attribute__((unused)) void *data)
12949 {
12950         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12951         int ret = -ENOTSUP;
12952
12953         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12954                 return;
12955
12956 #ifdef RTE_LIBRTE_IXGBE_PMD
12957         if (ret == -ENOTSUP)
12958                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12959                                 &res->mac_addr);
12960 #endif
12961 #ifdef RTE_LIBRTE_I40E_PMD
12962         if (ret == -ENOTSUP)
12963                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12964                                 &res->mac_addr);
12965 #endif
12966 #ifdef RTE_LIBRTE_BNXT_PMD
12967         if (ret == -ENOTSUP)
12968                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12969                                 &res->mac_addr);
12970 #endif
12971
12972         switch (ret) {
12973         case 0:
12974                 break;
12975         case -EINVAL:
12976                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12977                 break;
12978         case -ENODEV:
12979                 printf("invalid port_id %d\n", res->port_id);
12980                 break;
12981         case -ENOTSUP:
12982                 printf("function not implemented\n");
12983                 break;
12984         default:
12985                 printf("programming error: (%s)\n", strerror(-ret));
12986         }
12987 }
12988
12989 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12990         .f = cmd_set_vf_mac_addr_parsed,
12991         .data = NULL,
12992         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12993         .tokens = {
12994                 (void *)&cmd_set_vf_mac_addr_set,
12995                 (void *)&cmd_set_vf_mac_addr_vf,
12996                 (void *)&cmd_set_vf_mac_addr_mac,
12997                 (void *)&cmd_set_vf_mac_addr_addr,
12998                 (void *)&cmd_set_vf_mac_addr_port_id,
12999                 (void *)&cmd_set_vf_mac_addr_vf_id,
13000                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13001                 NULL,
13002         },
13003 };
13004
13005 /* MACsec configuration */
13006
13007 /* Common result structure for MACsec offload enable */
13008 struct cmd_macsec_offload_on_result {
13009         cmdline_fixed_string_t set;
13010         cmdline_fixed_string_t macsec;
13011         cmdline_fixed_string_t offload;
13012         portid_t port_id;
13013         cmdline_fixed_string_t on;
13014         cmdline_fixed_string_t encrypt;
13015         cmdline_fixed_string_t en_on_off;
13016         cmdline_fixed_string_t replay_protect;
13017         cmdline_fixed_string_t rp_on_off;
13018 };
13019
13020 /* Common CLI fields for MACsec offload disable */
13021 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13022         TOKEN_STRING_INITIALIZER
13023                 (struct cmd_macsec_offload_on_result,
13024                  set, "set");
13025 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13026         TOKEN_STRING_INITIALIZER
13027                 (struct cmd_macsec_offload_on_result,
13028                  macsec, "macsec");
13029 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13030         TOKEN_STRING_INITIALIZER
13031                 (struct cmd_macsec_offload_on_result,
13032                  offload, "offload");
13033 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13034         TOKEN_NUM_INITIALIZER
13035                 (struct cmd_macsec_offload_on_result,
13036                  port_id, UINT16);
13037 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13038         TOKEN_STRING_INITIALIZER
13039                 (struct cmd_macsec_offload_on_result,
13040                  on, "on");
13041 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13042         TOKEN_STRING_INITIALIZER
13043                 (struct cmd_macsec_offload_on_result,
13044                  encrypt, "encrypt");
13045 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13046         TOKEN_STRING_INITIALIZER
13047                 (struct cmd_macsec_offload_on_result,
13048                  en_on_off, "on#off");
13049 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13050         TOKEN_STRING_INITIALIZER
13051                 (struct cmd_macsec_offload_on_result,
13052                  replay_protect, "replay-protect");
13053 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13054         TOKEN_STRING_INITIALIZER
13055                 (struct cmd_macsec_offload_on_result,
13056                  rp_on_off, "on#off");
13057
13058 static void
13059 cmd_set_macsec_offload_on_parsed(
13060         void *parsed_result,
13061         __attribute__((unused)) struct cmdline *cl,
13062         __attribute__((unused)) void *data)
13063 {
13064         struct cmd_macsec_offload_on_result *res = parsed_result;
13065         int ret = -ENOTSUP;
13066         portid_t port_id = res->port_id;
13067         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13068         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13069         struct rte_eth_dev_info dev_info;
13070
13071         if (port_id_is_invalid(port_id, ENABLED_WARN))
13072                 return;
13073         if (!port_is_stopped(port_id)) {
13074                 printf("Please stop port %d first\n", port_id);
13075                 return;
13076         }
13077
13078         rte_eth_dev_info_get(port_id, &dev_info);
13079         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13080 #ifdef RTE_LIBRTE_IXGBE_PMD
13081                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13082 #endif
13083         }
13084         RTE_SET_USED(en);
13085         RTE_SET_USED(rp);
13086
13087         switch (ret) {
13088         case 0:
13089                 ports[port_id].dev_conf.txmode.offloads |=
13090                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13091                 cmd_reconfig_device_queue(port_id, 1, 1);
13092                 break;
13093         case -ENODEV:
13094                 printf("invalid port_id %d\n", port_id);
13095                 break;
13096         case -ENOTSUP:
13097                 printf("not supported on port %d\n", port_id);
13098                 break;
13099         default:
13100                 printf("programming error: (%s)\n", strerror(-ret));
13101         }
13102 }
13103
13104 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13105         .f = cmd_set_macsec_offload_on_parsed,
13106         .data = NULL,
13107         .help_str = "set macsec offload <port_id> on "
13108                 "encrypt on|off replay-protect on|off",
13109         .tokens = {
13110                 (void *)&cmd_macsec_offload_on_set,
13111                 (void *)&cmd_macsec_offload_on_macsec,
13112                 (void *)&cmd_macsec_offload_on_offload,
13113                 (void *)&cmd_macsec_offload_on_port_id,
13114                 (void *)&cmd_macsec_offload_on_on,
13115                 (void *)&cmd_macsec_offload_on_encrypt,
13116                 (void *)&cmd_macsec_offload_on_en_on_off,
13117                 (void *)&cmd_macsec_offload_on_replay_protect,
13118                 (void *)&cmd_macsec_offload_on_rp_on_off,
13119                 NULL,
13120         },
13121 };
13122
13123 /* Common result structure for MACsec offload disable */
13124 struct cmd_macsec_offload_off_result {
13125         cmdline_fixed_string_t set;
13126         cmdline_fixed_string_t macsec;
13127         cmdline_fixed_string_t offload;
13128         portid_t port_id;
13129         cmdline_fixed_string_t off;
13130 };
13131
13132 /* Common CLI fields for MACsec offload disable */
13133 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13134         TOKEN_STRING_INITIALIZER
13135                 (struct cmd_macsec_offload_off_result,
13136                  set, "set");
13137 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13138         TOKEN_STRING_INITIALIZER
13139                 (struct cmd_macsec_offload_off_result,
13140                  macsec, "macsec");
13141 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13142         TOKEN_STRING_INITIALIZER
13143                 (struct cmd_macsec_offload_off_result,
13144                  offload, "offload");
13145 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13146         TOKEN_NUM_INITIALIZER
13147                 (struct cmd_macsec_offload_off_result,
13148                  port_id, UINT16);
13149 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13150         TOKEN_STRING_INITIALIZER
13151                 (struct cmd_macsec_offload_off_result,
13152                  off, "off");
13153
13154 static void
13155 cmd_set_macsec_offload_off_parsed(
13156         void *parsed_result,
13157         __attribute__((unused)) struct cmdline *cl,
13158         __attribute__((unused)) void *data)
13159 {
13160         struct cmd_macsec_offload_off_result *res = parsed_result;
13161         int ret = -ENOTSUP;
13162         struct rte_eth_dev_info dev_info;
13163         portid_t port_id = res->port_id;
13164
13165         if (port_id_is_invalid(port_id, ENABLED_WARN))
13166                 return;
13167         if (!port_is_stopped(port_id)) {
13168                 printf("Please stop port %d first\n", port_id);
13169                 return;
13170         }
13171
13172         rte_eth_dev_info_get(port_id, &dev_info);
13173         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13174 #ifdef RTE_LIBRTE_IXGBE_PMD
13175                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13176 #endif
13177         }
13178         switch (ret) {
13179         case 0:
13180                 ports[port_id].dev_conf.txmode.offloads &=
13181                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13182                 cmd_reconfig_device_queue(port_id, 1, 1);
13183                 break;
13184         case -ENODEV:
13185                 printf("invalid port_id %d\n", port_id);
13186                 break;
13187         case -ENOTSUP:
13188                 printf("not supported on port %d\n", port_id);
13189                 break;
13190         default:
13191                 printf("programming error: (%s)\n", strerror(-ret));
13192         }
13193 }
13194
13195 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13196         .f = cmd_set_macsec_offload_off_parsed,
13197         .data = NULL,
13198         .help_str = "set macsec offload <port_id> off",
13199         .tokens = {
13200                 (void *)&cmd_macsec_offload_off_set,
13201                 (void *)&cmd_macsec_offload_off_macsec,
13202                 (void *)&cmd_macsec_offload_off_offload,
13203                 (void *)&cmd_macsec_offload_off_port_id,
13204                 (void *)&cmd_macsec_offload_off_off,
13205                 NULL,
13206         },
13207 };
13208
13209 /* Common result structure for MACsec secure connection configure */
13210 struct cmd_macsec_sc_result {
13211         cmdline_fixed_string_t set;
13212         cmdline_fixed_string_t macsec;
13213         cmdline_fixed_string_t sc;
13214         cmdline_fixed_string_t tx_rx;
13215         portid_t port_id;
13216         struct ether_addr mac;
13217         uint16_t pi;
13218 };
13219
13220 /* Common CLI fields for MACsec secure connection configure */
13221 cmdline_parse_token_string_t cmd_macsec_sc_set =
13222         TOKEN_STRING_INITIALIZER
13223                 (struct cmd_macsec_sc_result,
13224                  set, "set");
13225 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13226         TOKEN_STRING_INITIALIZER
13227                 (struct cmd_macsec_sc_result,
13228                  macsec, "macsec");
13229 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13230         TOKEN_STRING_INITIALIZER
13231                 (struct cmd_macsec_sc_result,
13232                  sc, "sc");
13233 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13234         TOKEN_STRING_INITIALIZER
13235                 (struct cmd_macsec_sc_result,
13236                  tx_rx, "tx#rx");
13237 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13238         TOKEN_NUM_INITIALIZER
13239                 (struct cmd_macsec_sc_result,
13240                  port_id, UINT16);
13241 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13242         TOKEN_ETHERADDR_INITIALIZER
13243                 (struct cmd_macsec_sc_result,
13244                  mac);
13245 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13246         TOKEN_NUM_INITIALIZER
13247                 (struct cmd_macsec_sc_result,
13248                  pi, UINT16);
13249
13250 static void
13251 cmd_set_macsec_sc_parsed(
13252         void *parsed_result,
13253         __attribute__((unused)) struct cmdline *cl,
13254         __attribute__((unused)) void *data)
13255 {
13256         struct cmd_macsec_sc_result *res = parsed_result;
13257         int ret = -ENOTSUP;
13258         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13259
13260 #ifdef RTE_LIBRTE_IXGBE_PMD
13261         ret = is_tx ?
13262                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13263                                 res->mac.addr_bytes) :
13264                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13265                                 res->mac.addr_bytes, res->pi);
13266 #endif
13267         RTE_SET_USED(is_tx);
13268
13269         switch (ret) {
13270         case 0:
13271                 break;
13272         case -ENODEV:
13273                 printf("invalid port_id %d\n", res->port_id);
13274                 break;
13275         case -ENOTSUP:
13276                 printf("not supported on port %d\n", res->port_id);
13277                 break;
13278         default:
13279                 printf("programming error: (%s)\n", strerror(-ret));
13280         }
13281 }
13282
13283 cmdline_parse_inst_t cmd_set_macsec_sc = {
13284         .f = cmd_set_macsec_sc_parsed,
13285         .data = NULL,
13286         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13287         .tokens = {
13288                 (void *)&cmd_macsec_sc_set,
13289                 (void *)&cmd_macsec_sc_macsec,
13290                 (void *)&cmd_macsec_sc_sc,
13291                 (void *)&cmd_macsec_sc_tx_rx,
13292                 (void *)&cmd_macsec_sc_port_id,
13293                 (void *)&cmd_macsec_sc_mac,
13294                 (void *)&cmd_macsec_sc_pi,
13295                 NULL,
13296         },
13297 };
13298
13299 /* Common result structure for MACsec secure connection configure */
13300 struct cmd_macsec_sa_result {
13301         cmdline_fixed_string_t set;
13302         cmdline_fixed_string_t macsec;
13303         cmdline_fixed_string_t sa;
13304         cmdline_fixed_string_t tx_rx;
13305         portid_t port_id;
13306         uint8_t idx;
13307         uint8_t an;
13308         uint32_t pn;
13309         cmdline_fixed_string_t key;
13310 };
13311
13312 /* Common CLI fields for MACsec secure connection configure */
13313 cmdline_parse_token_string_t cmd_macsec_sa_set =
13314         TOKEN_STRING_INITIALIZER
13315                 (struct cmd_macsec_sa_result,
13316                  set, "set");
13317 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13318         TOKEN_STRING_INITIALIZER
13319                 (struct cmd_macsec_sa_result,
13320                  macsec, "macsec");
13321 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13322         TOKEN_STRING_INITIALIZER
13323                 (struct cmd_macsec_sa_result,
13324                  sa, "sa");
13325 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13326         TOKEN_STRING_INITIALIZER
13327                 (struct cmd_macsec_sa_result,
13328                  tx_rx, "tx#rx");
13329 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13330         TOKEN_NUM_INITIALIZER
13331                 (struct cmd_macsec_sa_result,
13332                  port_id, UINT16);
13333 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13334         TOKEN_NUM_INITIALIZER
13335                 (struct cmd_macsec_sa_result,
13336                  idx, UINT8);
13337 cmdline_parse_token_num_t cmd_macsec_sa_an =
13338         TOKEN_NUM_INITIALIZER
13339                 (struct cmd_macsec_sa_result,
13340                  an, UINT8);
13341 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13342         TOKEN_NUM_INITIALIZER
13343                 (struct cmd_macsec_sa_result,
13344                  pn, UINT32);
13345 cmdline_parse_token_string_t cmd_macsec_sa_key =
13346         TOKEN_STRING_INITIALIZER
13347                 (struct cmd_macsec_sa_result,
13348                  key, NULL);
13349
13350 static void
13351 cmd_set_macsec_sa_parsed(
13352         void *parsed_result,
13353         __attribute__((unused)) struct cmdline *cl,
13354         __attribute__((unused)) void *data)
13355 {
13356         struct cmd_macsec_sa_result *res = parsed_result;
13357         int ret = -ENOTSUP;
13358         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13359         uint8_t key[16] = { 0 };
13360         uint8_t xdgt0;
13361         uint8_t xdgt1;
13362         int key_len;
13363         int i;
13364
13365         key_len = strlen(res->key) / 2;
13366         if (key_len > 16)
13367                 key_len = 16;
13368
13369         for (i = 0; i < key_len; i++) {
13370                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13371                 if (xdgt0 == 0xFF)
13372                         return;
13373                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13374                 if (xdgt1 == 0xFF)
13375                         return;
13376                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13377         }
13378
13379 #ifdef RTE_LIBRTE_IXGBE_PMD
13380         ret = is_tx ?
13381                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13382                         res->idx, res->an, res->pn, key) :
13383                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13384                         res->idx, res->an, res->pn, key);
13385 #endif
13386         RTE_SET_USED(is_tx);
13387         RTE_SET_USED(key);
13388
13389         switch (ret) {
13390         case 0:
13391                 break;
13392         case -EINVAL:
13393                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13394                 break;
13395         case -ENODEV:
13396                 printf("invalid port_id %d\n", res->port_id);
13397                 break;
13398         case -ENOTSUP:
13399                 printf("not supported on port %d\n", res->port_id);
13400                 break;
13401         default:
13402                 printf("programming error: (%s)\n", strerror(-ret));
13403         }
13404 }
13405
13406 cmdline_parse_inst_t cmd_set_macsec_sa = {
13407         .f = cmd_set_macsec_sa_parsed,
13408         .data = NULL,
13409         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13410         .tokens = {
13411                 (void *)&cmd_macsec_sa_set,
13412                 (void *)&cmd_macsec_sa_macsec,
13413                 (void *)&cmd_macsec_sa_sa,
13414                 (void *)&cmd_macsec_sa_tx_rx,
13415                 (void *)&cmd_macsec_sa_port_id,
13416                 (void *)&cmd_macsec_sa_idx,
13417                 (void *)&cmd_macsec_sa_an,
13418                 (void *)&cmd_macsec_sa_pn,
13419                 (void *)&cmd_macsec_sa_key,
13420                 NULL,
13421         },
13422 };
13423
13424 /* VF unicast promiscuous mode configuration */
13425
13426 /* Common result structure for VF unicast promiscuous mode */
13427 struct cmd_vf_promisc_result {
13428         cmdline_fixed_string_t set;
13429         cmdline_fixed_string_t vf;
13430         cmdline_fixed_string_t promisc;
13431         portid_t port_id;
13432         uint32_t vf_id;
13433         cmdline_fixed_string_t on_off;
13434 };
13435
13436 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13437 cmdline_parse_token_string_t cmd_vf_promisc_set =
13438         TOKEN_STRING_INITIALIZER
13439                 (struct cmd_vf_promisc_result,
13440                  set, "set");
13441 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13442         TOKEN_STRING_INITIALIZER
13443                 (struct cmd_vf_promisc_result,
13444                  vf, "vf");
13445 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13446         TOKEN_STRING_INITIALIZER
13447                 (struct cmd_vf_promisc_result,
13448                  promisc, "promisc");
13449 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13450         TOKEN_NUM_INITIALIZER
13451                 (struct cmd_vf_promisc_result,
13452                  port_id, UINT16);
13453 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13454         TOKEN_NUM_INITIALIZER
13455                 (struct cmd_vf_promisc_result,
13456                  vf_id, UINT32);
13457 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13458         TOKEN_STRING_INITIALIZER
13459                 (struct cmd_vf_promisc_result,
13460                  on_off, "on#off");
13461
13462 static void
13463 cmd_set_vf_promisc_parsed(
13464         void *parsed_result,
13465         __attribute__((unused)) struct cmdline *cl,
13466         __attribute__((unused)) void *data)
13467 {
13468         struct cmd_vf_promisc_result *res = parsed_result;
13469         int ret = -ENOTSUP;
13470
13471         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13472
13473         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13474                 return;
13475
13476 #ifdef RTE_LIBRTE_I40E_PMD
13477         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13478                                                   res->vf_id, is_on);
13479 #endif
13480
13481         switch (ret) {
13482         case 0:
13483                 break;
13484         case -EINVAL:
13485                 printf("invalid vf_id %d\n", res->vf_id);
13486                 break;
13487         case -ENODEV:
13488                 printf("invalid port_id %d\n", res->port_id);
13489                 break;
13490         case -ENOTSUP:
13491                 printf("function not implemented\n");
13492                 break;
13493         default:
13494                 printf("programming error: (%s)\n", strerror(-ret));
13495         }
13496 }
13497
13498 cmdline_parse_inst_t cmd_set_vf_promisc = {
13499         .f = cmd_set_vf_promisc_parsed,
13500         .data = NULL,
13501         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13502                 "Set unicast promiscuous mode for a VF from the PF",
13503         .tokens = {
13504                 (void *)&cmd_vf_promisc_set,
13505                 (void *)&cmd_vf_promisc_vf,
13506                 (void *)&cmd_vf_promisc_promisc,
13507                 (void *)&cmd_vf_promisc_port_id,
13508                 (void *)&cmd_vf_promisc_vf_id,
13509                 (void *)&cmd_vf_promisc_on_off,
13510                 NULL,
13511         },
13512 };
13513
13514 /* VF multicast promiscuous mode configuration */
13515
13516 /* Common result structure for VF multicast promiscuous mode */
13517 struct cmd_vf_allmulti_result {
13518         cmdline_fixed_string_t set;
13519         cmdline_fixed_string_t vf;
13520         cmdline_fixed_string_t allmulti;
13521         portid_t port_id;
13522         uint32_t vf_id;
13523         cmdline_fixed_string_t on_off;
13524 };
13525
13526 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13527 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13528         TOKEN_STRING_INITIALIZER
13529                 (struct cmd_vf_allmulti_result,
13530                  set, "set");
13531 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13532         TOKEN_STRING_INITIALIZER
13533                 (struct cmd_vf_allmulti_result,
13534                  vf, "vf");
13535 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13536         TOKEN_STRING_INITIALIZER
13537                 (struct cmd_vf_allmulti_result,
13538                  allmulti, "allmulti");
13539 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13540         TOKEN_NUM_INITIALIZER
13541                 (struct cmd_vf_allmulti_result,
13542                  port_id, UINT16);
13543 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13544         TOKEN_NUM_INITIALIZER
13545                 (struct cmd_vf_allmulti_result,
13546                  vf_id, UINT32);
13547 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13548         TOKEN_STRING_INITIALIZER
13549                 (struct cmd_vf_allmulti_result,
13550                  on_off, "on#off");
13551
13552 static void
13553 cmd_set_vf_allmulti_parsed(
13554         void *parsed_result,
13555         __attribute__((unused)) struct cmdline *cl,
13556         __attribute__((unused)) void *data)
13557 {
13558         struct cmd_vf_allmulti_result *res = parsed_result;
13559         int ret = -ENOTSUP;
13560
13561         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13562
13563         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13564                 return;
13565
13566 #ifdef RTE_LIBRTE_I40E_PMD
13567         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13568                                                     res->vf_id, is_on);
13569 #endif
13570
13571         switch (ret) {
13572         case 0:
13573                 break;
13574         case -EINVAL:
13575                 printf("invalid vf_id %d\n", res->vf_id);
13576                 break;
13577         case -ENODEV:
13578                 printf("invalid port_id %d\n", res->port_id);
13579                 break;
13580         case -ENOTSUP:
13581                 printf("function not implemented\n");
13582                 break;
13583         default:
13584                 printf("programming error: (%s)\n", strerror(-ret));
13585         }
13586 }
13587
13588 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13589         .f = cmd_set_vf_allmulti_parsed,
13590         .data = NULL,
13591         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13592                 "Set multicast promiscuous mode for a VF from the PF",
13593         .tokens = {
13594                 (void *)&cmd_vf_allmulti_set,
13595                 (void *)&cmd_vf_allmulti_vf,
13596                 (void *)&cmd_vf_allmulti_allmulti,
13597                 (void *)&cmd_vf_allmulti_port_id,
13598                 (void *)&cmd_vf_allmulti_vf_id,
13599                 (void *)&cmd_vf_allmulti_on_off,
13600                 NULL,
13601         },
13602 };
13603
13604 /* vf broadcast mode configuration */
13605
13606 /* Common result structure for vf broadcast */
13607 struct cmd_set_vf_broadcast_result {
13608         cmdline_fixed_string_t set;
13609         cmdline_fixed_string_t vf;
13610         cmdline_fixed_string_t broadcast;
13611         portid_t port_id;
13612         uint16_t vf_id;
13613         cmdline_fixed_string_t on_off;
13614 };
13615
13616 /* Common CLI fields for vf broadcast enable disable */
13617 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13618         TOKEN_STRING_INITIALIZER
13619                 (struct cmd_set_vf_broadcast_result,
13620                  set, "set");
13621 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13622         TOKEN_STRING_INITIALIZER
13623                 (struct cmd_set_vf_broadcast_result,
13624                  vf, "vf");
13625 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13626         TOKEN_STRING_INITIALIZER
13627                 (struct cmd_set_vf_broadcast_result,
13628                  broadcast, "broadcast");
13629 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13630         TOKEN_NUM_INITIALIZER
13631                 (struct cmd_set_vf_broadcast_result,
13632                  port_id, UINT16);
13633 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13634         TOKEN_NUM_INITIALIZER
13635                 (struct cmd_set_vf_broadcast_result,
13636                  vf_id, UINT16);
13637 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13638         TOKEN_STRING_INITIALIZER
13639                 (struct cmd_set_vf_broadcast_result,
13640                  on_off, "on#off");
13641
13642 static void
13643 cmd_set_vf_broadcast_parsed(
13644         void *parsed_result,
13645         __attribute__((unused)) struct cmdline *cl,
13646         __attribute__((unused)) void *data)
13647 {
13648         struct cmd_set_vf_broadcast_result *res = parsed_result;
13649         int ret = -ENOTSUP;
13650
13651         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13652
13653         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13654                 return;
13655
13656 #ifdef RTE_LIBRTE_I40E_PMD
13657         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13658                                             res->vf_id, is_on);
13659 #endif
13660
13661         switch (ret) {
13662         case 0:
13663                 break;
13664         case -EINVAL:
13665                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13666                 break;
13667         case -ENODEV:
13668                 printf("invalid port_id %d\n", res->port_id);
13669                 break;
13670         case -ENOTSUP:
13671                 printf("function not implemented\n");
13672                 break;
13673         default:
13674                 printf("programming error: (%s)\n", strerror(-ret));
13675         }
13676 }
13677
13678 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13679         .f = cmd_set_vf_broadcast_parsed,
13680         .data = NULL,
13681         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13682         .tokens = {
13683                 (void *)&cmd_set_vf_broadcast_set,
13684                 (void *)&cmd_set_vf_broadcast_vf,
13685                 (void *)&cmd_set_vf_broadcast_broadcast,
13686                 (void *)&cmd_set_vf_broadcast_port_id,
13687                 (void *)&cmd_set_vf_broadcast_vf_id,
13688                 (void *)&cmd_set_vf_broadcast_on_off,
13689                 NULL,
13690         },
13691 };
13692
13693 /* vf vlan tag configuration */
13694
13695 /* Common result structure for vf vlan tag */
13696 struct cmd_set_vf_vlan_tag_result {
13697         cmdline_fixed_string_t set;
13698         cmdline_fixed_string_t vf;
13699         cmdline_fixed_string_t vlan;
13700         cmdline_fixed_string_t tag;
13701         portid_t port_id;
13702         uint16_t vf_id;
13703         cmdline_fixed_string_t on_off;
13704 };
13705
13706 /* Common CLI fields for vf vlan tag enable disable */
13707 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_set_vf_vlan_tag_result,
13710                  set, "set");
13711 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13712         TOKEN_STRING_INITIALIZER
13713                 (struct cmd_set_vf_vlan_tag_result,
13714                  vf, "vf");
13715 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13716         TOKEN_STRING_INITIALIZER
13717                 (struct cmd_set_vf_vlan_tag_result,
13718                  vlan, "vlan");
13719 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13720         TOKEN_STRING_INITIALIZER
13721                 (struct cmd_set_vf_vlan_tag_result,
13722                  tag, "tag");
13723 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13724         TOKEN_NUM_INITIALIZER
13725                 (struct cmd_set_vf_vlan_tag_result,
13726                  port_id, UINT16);
13727 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13728         TOKEN_NUM_INITIALIZER
13729                 (struct cmd_set_vf_vlan_tag_result,
13730                  vf_id, UINT16);
13731 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13732         TOKEN_STRING_INITIALIZER
13733                 (struct cmd_set_vf_vlan_tag_result,
13734                  on_off, "on#off");
13735
13736 static void
13737 cmd_set_vf_vlan_tag_parsed(
13738         void *parsed_result,
13739         __attribute__((unused)) struct cmdline *cl,
13740         __attribute__((unused)) void *data)
13741 {
13742         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13743         int ret = -ENOTSUP;
13744
13745         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13746
13747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13748                 return;
13749
13750 #ifdef RTE_LIBRTE_I40E_PMD
13751         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13752                                            res->vf_id, is_on);
13753 #endif
13754
13755         switch (ret) {
13756         case 0:
13757                 break;
13758         case -EINVAL:
13759                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13760                 break;
13761         case -ENODEV:
13762                 printf("invalid port_id %d\n", res->port_id);
13763                 break;
13764         case -ENOTSUP:
13765                 printf("function not implemented\n");
13766                 break;
13767         default:
13768                 printf("programming error: (%s)\n", strerror(-ret));
13769         }
13770 }
13771
13772 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13773         .f = cmd_set_vf_vlan_tag_parsed,
13774         .data = NULL,
13775         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13776         .tokens = {
13777                 (void *)&cmd_set_vf_vlan_tag_set,
13778                 (void *)&cmd_set_vf_vlan_tag_vf,
13779                 (void *)&cmd_set_vf_vlan_tag_vlan,
13780                 (void *)&cmd_set_vf_vlan_tag_tag,
13781                 (void *)&cmd_set_vf_vlan_tag_port_id,
13782                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13783                 (void *)&cmd_set_vf_vlan_tag_on_off,
13784                 NULL,
13785         },
13786 };
13787
13788 /* Common definition of VF and TC TX bandwidth configuration */
13789 struct cmd_vf_tc_bw_result {
13790         cmdline_fixed_string_t set;
13791         cmdline_fixed_string_t vf;
13792         cmdline_fixed_string_t tc;
13793         cmdline_fixed_string_t tx;
13794         cmdline_fixed_string_t min_bw;
13795         cmdline_fixed_string_t max_bw;
13796         cmdline_fixed_string_t strict_link_prio;
13797         portid_t port_id;
13798         uint16_t vf_id;
13799         uint8_t tc_no;
13800         uint32_t bw;
13801         cmdline_fixed_string_t bw_list;
13802         uint8_t tc_map;
13803 };
13804
13805 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13806         TOKEN_STRING_INITIALIZER
13807                 (struct cmd_vf_tc_bw_result,
13808                  set, "set");
13809 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13810         TOKEN_STRING_INITIALIZER
13811                 (struct cmd_vf_tc_bw_result,
13812                  vf, "vf");
13813 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13814         TOKEN_STRING_INITIALIZER
13815                 (struct cmd_vf_tc_bw_result,
13816                  tc, "tc");
13817 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13818         TOKEN_STRING_INITIALIZER
13819                 (struct cmd_vf_tc_bw_result,
13820                  tx, "tx");
13821 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13822         TOKEN_STRING_INITIALIZER
13823                 (struct cmd_vf_tc_bw_result,
13824                  strict_link_prio, "strict-link-priority");
13825 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13826         TOKEN_STRING_INITIALIZER
13827                 (struct cmd_vf_tc_bw_result,
13828                  min_bw, "min-bandwidth");
13829 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13830         TOKEN_STRING_INITIALIZER
13831                 (struct cmd_vf_tc_bw_result,
13832                  max_bw, "max-bandwidth");
13833 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13834         TOKEN_NUM_INITIALIZER
13835                 (struct cmd_vf_tc_bw_result,
13836                  port_id, UINT16);
13837 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13838         TOKEN_NUM_INITIALIZER
13839                 (struct cmd_vf_tc_bw_result,
13840                  vf_id, UINT16);
13841 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13842         TOKEN_NUM_INITIALIZER
13843                 (struct cmd_vf_tc_bw_result,
13844                  tc_no, UINT8);
13845 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13846         TOKEN_NUM_INITIALIZER
13847                 (struct cmd_vf_tc_bw_result,
13848                  bw, UINT32);
13849 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13850         TOKEN_STRING_INITIALIZER
13851                 (struct cmd_vf_tc_bw_result,
13852                  bw_list, NULL);
13853 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13854         TOKEN_NUM_INITIALIZER
13855                 (struct cmd_vf_tc_bw_result,
13856                  tc_map, UINT8);
13857
13858 /* VF max bandwidth setting */
13859 static void
13860 cmd_vf_max_bw_parsed(
13861         void *parsed_result,
13862         __attribute__((unused)) struct cmdline *cl,
13863         __attribute__((unused)) void *data)
13864 {
13865         struct cmd_vf_tc_bw_result *res = parsed_result;
13866         int ret = -ENOTSUP;
13867
13868         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13869                 return;
13870
13871 #ifdef RTE_LIBRTE_I40E_PMD
13872         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13873                                          res->vf_id, res->bw);
13874 #endif
13875
13876         switch (ret) {
13877         case 0:
13878                 break;
13879         case -EINVAL:
13880                 printf("invalid vf_id %d or bandwidth %d\n",
13881                        res->vf_id, res->bw);
13882                 break;
13883         case -ENODEV:
13884                 printf("invalid port_id %d\n", res->port_id);
13885                 break;
13886         case -ENOTSUP:
13887                 printf("function not implemented\n");
13888                 break;
13889         default:
13890                 printf("programming error: (%s)\n", strerror(-ret));
13891         }
13892 }
13893
13894 cmdline_parse_inst_t cmd_vf_max_bw = {
13895         .f = cmd_vf_max_bw_parsed,
13896         .data = NULL,
13897         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13898         .tokens = {
13899                 (void *)&cmd_vf_tc_bw_set,
13900                 (void *)&cmd_vf_tc_bw_vf,
13901                 (void *)&cmd_vf_tc_bw_tx,
13902                 (void *)&cmd_vf_tc_bw_max_bw,
13903                 (void *)&cmd_vf_tc_bw_port_id,
13904                 (void *)&cmd_vf_tc_bw_vf_id,
13905                 (void *)&cmd_vf_tc_bw_bw,
13906                 NULL,
13907         },
13908 };
13909
13910 static int
13911 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13912                            uint8_t *tc_num,
13913                            char *str)
13914 {
13915         uint32_t size;
13916         const char *p, *p0 = str;
13917         char s[256];
13918         char *end;
13919         char *str_fld[16];
13920         uint16_t i;
13921         int ret;
13922
13923         p = strchr(p0, '(');
13924         if (p == NULL) {
13925                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13926                 return -1;
13927         }
13928         p++;
13929         p0 = strchr(p, ')');
13930         if (p0 == NULL) {
13931                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13932                 return -1;
13933         }
13934         size = p0 - p;
13935         if (size >= sizeof(s)) {
13936                 printf("The string size exceeds the internal buffer size\n");
13937                 return -1;
13938         }
13939         snprintf(s, sizeof(s), "%.*s", size, p);
13940         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13941         if (ret <= 0) {
13942                 printf("Failed to get the bandwidth list. ");
13943                 return -1;
13944         }
13945         *tc_num = ret;
13946         for (i = 0; i < ret; i++)
13947                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13948
13949         return 0;
13950 }
13951
13952 /* TC min bandwidth setting */
13953 static void
13954 cmd_vf_tc_min_bw_parsed(
13955         void *parsed_result,
13956         __attribute__((unused)) struct cmdline *cl,
13957         __attribute__((unused)) void *data)
13958 {
13959         struct cmd_vf_tc_bw_result *res = parsed_result;
13960         uint8_t tc_num;
13961         uint8_t bw[16];
13962         int ret = -ENOTSUP;
13963
13964         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13965                 return;
13966
13967         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13968         if (ret)
13969                 return;
13970
13971 #ifdef RTE_LIBRTE_I40E_PMD
13972         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13973                                               tc_num, bw);
13974 #endif
13975
13976         switch (ret) {
13977         case 0:
13978                 break;
13979         case -EINVAL:
13980                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13981                 break;
13982         case -ENODEV:
13983                 printf("invalid port_id %d\n", res->port_id);
13984                 break;
13985         case -ENOTSUP:
13986                 printf("function not implemented\n");
13987                 break;
13988         default:
13989                 printf("programming error: (%s)\n", strerror(-ret));
13990         }
13991 }
13992
13993 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13994         .f = cmd_vf_tc_min_bw_parsed,
13995         .data = NULL,
13996         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13997                     " <bw1, bw2, ...>",
13998         .tokens = {
13999                 (void *)&cmd_vf_tc_bw_set,
14000                 (void *)&cmd_vf_tc_bw_vf,
14001                 (void *)&cmd_vf_tc_bw_tc,
14002                 (void *)&cmd_vf_tc_bw_tx,
14003                 (void *)&cmd_vf_tc_bw_min_bw,
14004                 (void *)&cmd_vf_tc_bw_port_id,
14005                 (void *)&cmd_vf_tc_bw_vf_id,
14006                 (void *)&cmd_vf_tc_bw_bw_list,
14007                 NULL,
14008         },
14009 };
14010
14011 static void
14012 cmd_tc_min_bw_parsed(
14013         void *parsed_result,
14014         __attribute__((unused)) struct cmdline *cl,
14015         __attribute__((unused)) void *data)
14016 {
14017         struct cmd_vf_tc_bw_result *res = parsed_result;
14018         struct rte_port *port;
14019         uint8_t tc_num;
14020         uint8_t bw[16];
14021         int ret = -ENOTSUP;
14022
14023         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14024                 return;
14025
14026         port = &ports[res->port_id];
14027         /** Check if the port is not started **/
14028         if (port->port_status != RTE_PORT_STOPPED) {
14029                 printf("Please stop port %d first\n", res->port_id);
14030                 return;
14031         }
14032
14033         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14034         if (ret)
14035                 return;
14036
14037 #ifdef RTE_LIBRTE_IXGBE_PMD
14038         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14039 #endif
14040
14041         switch (ret) {
14042         case 0:
14043                 break;
14044         case -EINVAL:
14045                 printf("invalid bandwidth\n");
14046                 break;
14047         case -ENODEV:
14048                 printf("invalid port_id %d\n", res->port_id);
14049                 break;
14050         case -ENOTSUP:
14051                 printf("function not implemented\n");
14052                 break;
14053         default:
14054                 printf("programming error: (%s)\n", strerror(-ret));
14055         }
14056 }
14057
14058 cmdline_parse_inst_t cmd_tc_min_bw = {
14059         .f = cmd_tc_min_bw_parsed,
14060         .data = NULL,
14061         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14062         .tokens = {
14063                 (void *)&cmd_vf_tc_bw_set,
14064                 (void *)&cmd_vf_tc_bw_tc,
14065                 (void *)&cmd_vf_tc_bw_tx,
14066                 (void *)&cmd_vf_tc_bw_min_bw,
14067                 (void *)&cmd_vf_tc_bw_port_id,
14068                 (void *)&cmd_vf_tc_bw_bw_list,
14069                 NULL,
14070         },
14071 };
14072
14073 /* TC max bandwidth setting */
14074 static void
14075 cmd_vf_tc_max_bw_parsed(
14076         void *parsed_result,
14077         __attribute__((unused)) struct cmdline *cl,
14078         __attribute__((unused)) void *data)
14079 {
14080         struct cmd_vf_tc_bw_result *res = parsed_result;
14081         int ret = -ENOTSUP;
14082
14083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14084                 return;
14085
14086 #ifdef RTE_LIBRTE_I40E_PMD
14087         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14088                                             res->tc_no, res->bw);
14089 #endif
14090
14091         switch (ret) {
14092         case 0:
14093                 break;
14094         case -EINVAL:
14095                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14096                        res->vf_id, res->tc_no, res->bw);
14097                 break;
14098         case -ENODEV:
14099                 printf("invalid port_id %d\n", res->port_id);
14100                 break;
14101         case -ENOTSUP:
14102                 printf("function not implemented\n");
14103                 break;
14104         default:
14105                 printf("programming error: (%s)\n", strerror(-ret));
14106         }
14107 }
14108
14109 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14110         .f = cmd_vf_tc_max_bw_parsed,
14111         .data = NULL,
14112         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14113                     " <bandwidth>",
14114         .tokens = {
14115                 (void *)&cmd_vf_tc_bw_set,
14116                 (void *)&cmd_vf_tc_bw_vf,
14117                 (void *)&cmd_vf_tc_bw_tc,
14118                 (void *)&cmd_vf_tc_bw_tx,
14119                 (void *)&cmd_vf_tc_bw_max_bw,
14120                 (void *)&cmd_vf_tc_bw_port_id,
14121                 (void *)&cmd_vf_tc_bw_vf_id,
14122                 (void *)&cmd_vf_tc_bw_tc_no,
14123                 (void *)&cmd_vf_tc_bw_bw,
14124                 NULL,
14125         },
14126 };
14127
14128
14129 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14130
14131 /* *** Set Port default Traffic Management Hierarchy *** */
14132 struct cmd_set_port_tm_hierarchy_default_result {
14133         cmdline_fixed_string_t set;
14134         cmdline_fixed_string_t port;
14135         cmdline_fixed_string_t tm;
14136         cmdline_fixed_string_t hierarchy;
14137         cmdline_fixed_string_t def;
14138         portid_t port_id;
14139 };
14140
14141 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14142         TOKEN_STRING_INITIALIZER(
14143                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14144 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14145         TOKEN_STRING_INITIALIZER(
14146                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14147 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14148         TOKEN_STRING_INITIALIZER(
14149                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14150 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14151         TOKEN_STRING_INITIALIZER(
14152                 struct cmd_set_port_tm_hierarchy_default_result,
14153                         hierarchy, "hierarchy");
14154 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14155         TOKEN_STRING_INITIALIZER(
14156                 struct cmd_set_port_tm_hierarchy_default_result,
14157                         def, "default");
14158 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14159         TOKEN_NUM_INITIALIZER(
14160                 struct cmd_set_port_tm_hierarchy_default_result,
14161                         port_id, UINT16);
14162
14163 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14164         __attribute__((unused)) struct cmdline *cl,
14165         __attribute__((unused)) void *data)
14166 {
14167         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14168         struct rte_port *p;
14169         portid_t port_id = res->port_id;
14170
14171         if (port_id_is_invalid(port_id, ENABLED_WARN))
14172                 return;
14173
14174         p = &ports[port_id];
14175
14176         /* Port tm flag */
14177         if (p->softport.tm_flag == 0) {
14178                 printf("  tm not enabled on port %u (error)\n", port_id);
14179                 return;
14180         }
14181
14182         /* Forward mode: tm */
14183         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14184                 printf("  tm mode not enabled(error)\n");
14185                 return;
14186         }
14187
14188         /* Set the default tm hierarchy */
14189         p->softport.tm.default_hierarchy_enable = 1;
14190 }
14191
14192 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14193         .f = cmd_set_port_tm_hierarchy_default_parsed,
14194         .data = NULL,
14195         .help_str = "set port tm hierarchy default <port_id>",
14196         .tokens = {
14197                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14198                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14199                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14200                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14201                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14202                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14203                 NULL,
14204         },
14205 };
14206 #endif
14207
14208 /* Strict link priority scheduling mode setting */
14209 static void
14210 cmd_strict_link_prio_parsed(
14211         void *parsed_result,
14212         __attribute__((unused)) struct cmdline *cl,
14213         __attribute__((unused)) void *data)
14214 {
14215         struct cmd_vf_tc_bw_result *res = parsed_result;
14216         int ret = -ENOTSUP;
14217
14218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14219                 return;
14220
14221 #ifdef RTE_LIBRTE_I40E_PMD
14222         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14223 #endif
14224
14225         switch (ret) {
14226         case 0:
14227                 break;
14228         case -EINVAL:
14229                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14230                 break;
14231         case -ENODEV:
14232                 printf("invalid port_id %d\n", res->port_id);
14233                 break;
14234         case -ENOTSUP:
14235                 printf("function not implemented\n");
14236                 break;
14237         default:
14238                 printf("programming error: (%s)\n", strerror(-ret));
14239         }
14240 }
14241
14242 cmdline_parse_inst_t cmd_strict_link_prio = {
14243         .f = cmd_strict_link_prio_parsed,
14244         .data = NULL,
14245         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14246         .tokens = {
14247                 (void *)&cmd_vf_tc_bw_set,
14248                 (void *)&cmd_vf_tc_bw_tx,
14249                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14250                 (void *)&cmd_vf_tc_bw_port_id,
14251                 (void *)&cmd_vf_tc_bw_tc_map,
14252                 NULL,
14253         },
14254 };
14255
14256 /* Load dynamic device personalization*/
14257 struct cmd_ddp_add_result {
14258         cmdline_fixed_string_t ddp;
14259         cmdline_fixed_string_t add;
14260         portid_t port_id;
14261         char filepath[];
14262 };
14263
14264 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14265         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14266 cmdline_parse_token_string_t cmd_ddp_add_add =
14267         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14268 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14269         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14270 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14271         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14272
14273 static void
14274 cmd_ddp_add_parsed(
14275         void *parsed_result,
14276         __attribute__((unused)) struct cmdline *cl,
14277         __attribute__((unused)) void *data)
14278 {
14279         struct cmd_ddp_add_result *res = parsed_result;
14280         uint8_t *buff;
14281         uint32_t size;
14282         char *filepath;
14283         char *file_fld[2];
14284         int file_num;
14285         int ret = -ENOTSUP;
14286
14287         if (res->port_id > nb_ports) {
14288                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14289                 return;
14290         }
14291
14292         if (!all_ports_stopped()) {
14293                 printf("Please stop all ports first\n");
14294                 return;
14295         }
14296
14297         filepath = strdup(res->filepath);
14298         if (filepath == NULL) {
14299                 printf("Failed to allocate memory\n");
14300                 return;
14301         }
14302         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14303
14304         buff = open_ddp_package_file(file_fld[0], &size);
14305         if (!buff) {
14306                 free((void *)filepath);
14307                 return;
14308         }
14309
14310 #ifdef RTE_LIBRTE_I40E_PMD
14311         if (ret == -ENOTSUP)
14312                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14313                                                buff, size,
14314                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14315 #endif
14316
14317         if (ret == -EEXIST)
14318                 printf("Profile has already existed.\n");
14319         else if (ret < 0)
14320                 printf("Failed to load profile.\n");
14321         else if (file_num == 2)
14322                 save_ddp_package_file(file_fld[1], buff, size);
14323
14324         close_ddp_package_file(buff);
14325         free((void *)filepath);
14326 }
14327
14328 cmdline_parse_inst_t cmd_ddp_add = {
14329         .f = cmd_ddp_add_parsed,
14330         .data = NULL,
14331         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14332         .tokens = {
14333                 (void *)&cmd_ddp_add_ddp,
14334                 (void *)&cmd_ddp_add_add,
14335                 (void *)&cmd_ddp_add_port_id,
14336                 (void *)&cmd_ddp_add_filepath,
14337                 NULL,
14338         },
14339 };
14340
14341 /* Delete dynamic device personalization*/
14342 struct cmd_ddp_del_result {
14343         cmdline_fixed_string_t ddp;
14344         cmdline_fixed_string_t del;
14345         portid_t port_id;
14346         char filepath[];
14347 };
14348
14349 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14350         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14351 cmdline_parse_token_string_t cmd_ddp_del_del =
14352         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14353 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14354         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14355 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14356         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14357
14358 static void
14359 cmd_ddp_del_parsed(
14360         void *parsed_result,
14361         __attribute__((unused)) struct cmdline *cl,
14362         __attribute__((unused)) void *data)
14363 {
14364         struct cmd_ddp_del_result *res = parsed_result;
14365         uint8_t *buff;
14366         uint32_t size;
14367         int ret = -ENOTSUP;
14368
14369         if (res->port_id > nb_ports) {
14370                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14371                 return;
14372         }
14373
14374         if (!all_ports_stopped()) {
14375                 printf("Please stop all ports first\n");
14376                 return;
14377         }
14378
14379         buff = open_ddp_package_file(res->filepath, &size);
14380         if (!buff)
14381                 return;
14382
14383 #ifdef RTE_LIBRTE_I40E_PMD
14384         if (ret == -ENOTSUP)
14385                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14386                                                buff, size,
14387                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14388 #endif
14389
14390         if (ret == -EACCES)
14391                 printf("Profile does not exist.\n");
14392         else if (ret < 0)
14393                 printf("Failed to delete profile.\n");
14394
14395         close_ddp_package_file(buff);
14396 }
14397
14398 cmdline_parse_inst_t cmd_ddp_del = {
14399         .f = cmd_ddp_del_parsed,
14400         .data = NULL,
14401         .help_str = "ddp del <port_id> <profile_path>",
14402         .tokens = {
14403                 (void *)&cmd_ddp_del_ddp,
14404                 (void *)&cmd_ddp_del_del,
14405                 (void *)&cmd_ddp_del_port_id,
14406                 (void *)&cmd_ddp_del_filepath,
14407                 NULL,
14408         },
14409 };
14410
14411 /* Get dynamic device personalization profile info */
14412 struct cmd_ddp_info_result {
14413         cmdline_fixed_string_t ddp;
14414         cmdline_fixed_string_t get;
14415         cmdline_fixed_string_t info;
14416         char filepath[];
14417 };
14418
14419 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14420         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14421 cmdline_parse_token_string_t cmd_ddp_info_get =
14422         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14423 cmdline_parse_token_string_t cmd_ddp_info_info =
14424         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14425 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14426         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14427
14428 static void
14429 cmd_ddp_info_parsed(
14430         void *parsed_result,
14431         __attribute__((unused)) struct cmdline *cl,
14432         __attribute__((unused)) void *data)
14433 {
14434         struct cmd_ddp_info_result *res = parsed_result;
14435         uint8_t *pkg;
14436         uint32_t pkg_size;
14437         int ret = -ENOTSUP;
14438 #ifdef RTE_LIBRTE_I40E_PMD
14439         uint32_t i, j, n;
14440         uint8_t *buff;
14441         uint32_t buff_size = 0;
14442         struct rte_pmd_i40e_profile_info info;
14443         uint32_t dev_num = 0;
14444         struct rte_pmd_i40e_ddp_device_id *devs;
14445         uint32_t proto_num = 0;
14446         struct rte_pmd_i40e_proto_info *proto = NULL;
14447         uint32_t pctype_num = 0;
14448         struct rte_pmd_i40e_ptype_info *pctype;
14449         uint32_t ptype_num = 0;
14450         struct rte_pmd_i40e_ptype_info *ptype;
14451         uint8_t proto_id;
14452
14453 #endif
14454
14455         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14456         if (!pkg)
14457                 return;
14458
14459 #ifdef RTE_LIBRTE_I40E_PMD
14460         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14461                                 (uint8_t *)&info, sizeof(info),
14462                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14463         if (!ret) {
14464                 printf("Global Track id:       0x%x\n", info.track_id);
14465                 printf("Global Version:        %d.%d.%d.%d\n",
14466                         info.version.major,
14467                         info.version.minor,
14468                         info.version.update,
14469                         info.version.draft);
14470                 printf("Global Package name:   %s\n\n", info.name);
14471         }
14472
14473         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14474                                 (uint8_t *)&info, sizeof(info),
14475                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14476         if (!ret) {
14477                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14478                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14479                         info.version.major,
14480                         info.version.minor,
14481                         info.version.update,
14482                         info.version.draft);
14483                 printf("i40e Profile name:     %s\n\n", info.name);
14484         }
14485
14486         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14487                                 (uint8_t *)&buff_size, sizeof(buff_size),
14488                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14489         if (!ret && buff_size) {
14490                 buff = (uint8_t *)malloc(buff_size);
14491                 if (buff) {
14492                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14493                                                 buff, buff_size,
14494                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14495                         if (!ret)
14496                                 printf("Package Notes:\n%s\n\n", buff);
14497                         free(buff);
14498                 }
14499         }
14500
14501         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14502                                 (uint8_t *)&dev_num, sizeof(dev_num),
14503                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14504         if (!ret && dev_num) {
14505                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14506                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14507                 if (devs) {
14508                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14509                                                 (uint8_t *)devs, buff_size,
14510                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14511                         if (!ret) {
14512                                 printf("List of supported devices:\n");
14513                                 for (i = 0; i < dev_num; i++) {
14514                                         printf("  %04X:%04X %04X:%04X\n",
14515                                                 devs[i].vendor_dev_id >> 16,
14516                                                 devs[i].vendor_dev_id & 0xFFFF,
14517                                                 devs[i].sub_vendor_dev_id >> 16,
14518                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14519                                 }
14520                                 printf("\n");
14521                         }
14522                         free(devs);
14523                 }
14524         }
14525
14526         /* get information about protocols and packet types */
14527         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14528                 (uint8_t *)&proto_num, sizeof(proto_num),
14529                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14530         if (ret || !proto_num)
14531                 goto no_print_return;
14532
14533         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14534         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14535         if (!proto)
14536                 goto no_print_return;
14537
14538         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14539                                         buff_size,
14540                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14541         if (!ret) {
14542                 printf("List of used protocols:\n");
14543                 for (i = 0; i < proto_num; i++)
14544                         printf("  %2u: %s\n", proto[i].proto_id,
14545                                proto[i].name);
14546                 printf("\n");
14547         }
14548         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14549                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14550                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14551         if (ret || !pctype_num)
14552                 goto no_print_pctypes;
14553
14554         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14555         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14556         if (!pctype)
14557                 goto no_print_pctypes;
14558
14559         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14560                                         buff_size,
14561                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14562         if (ret) {
14563                 free(pctype);
14564                 goto no_print_pctypes;
14565         }
14566
14567         printf("List of defined packet classification types:\n");
14568         for (i = 0; i < pctype_num; i++) {
14569                 printf("  %2u:", pctype[i].ptype_id);
14570                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14571                         proto_id = pctype[i].protocols[j];
14572                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14573                                 for (n = 0; n < proto_num; n++) {
14574                                         if (proto[n].proto_id == proto_id) {
14575                                                 printf(" %s", proto[n].name);
14576                                                 break;
14577                                         }
14578                                 }
14579                         }
14580                 }
14581                 printf("\n");
14582         }
14583         printf("\n");
14584         free(pctype);
14585
14586 no_print_pctypes:
14587
14588         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14589                                         sizeof(ptype_num),
14590                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14591         if (ret || !ptype_num)
14592                 goto no_print_return;
14593
14594         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14595         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14596         if (!ptype)
14597                 goto no_print_return;
14598
14599         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14600                                         buff_size,
14601                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14602         if (ret) {
14603                 free(ptype);
14604                 goto no_print_return;
14605         }
14606         printf("List of defined packet types:\n");
14607         for (i = 0; i < ptype_num; i++) {
14608                 printf("  %2u:", ptype[i].ptype_id);
14609                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14610                         proto_id = ptype[i].protocols[j];
14611                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14612                                 for (n = 0; n < proto_num; n++) {
14613                                         if (proto[n].proto_id == proto_id) {
14614                                                 printf(" %s", proto[n].name);
14615                                                 break;
14616                                         }
14617                                 }
14618                         }
14619                 }
14620                 printf("\n");
14621         }
14622         free(ptype);
14623         printf("\n");
14624
14625         ret = 0;
14626 no_print_return:
14627         if (proto)
14628                 free(proto);
14629 #endif
14630         if (ret == -ENOTSUP)
14631                 printf("Function not supported in PMD driver\n");
14632         close_ddp_package_file(pkg);
14633 }
14634
14635 cmdline_parse_inst_t cmd_ddp_get_info = {
14636         .f = cmd_ddp_info_parsed,
14637         .data = NULL,
14638         .help_str = "ddp get info <profile_path>",
14639         .tokens = {
14640                 (void *)&cmd_ddp_info_ddp,
14641                 (void *)&cmd_ddp_info_get,
14642                 (void *)&cmd_ddp_info_info,
14643                 (void *)&cmd_ddp_info_filepath,
14644                 NULL,
14645         },
14646 };
14647
14648 /* Get dynamic device personalization profile info list*/
14649 #define PROFILE_INFO_SIZE 48
14650 #define MAX_PROFILE_NUM 16
14651
14652 struct cmd_ddp_get_list_result {
14653         cmdline_fixed_string_t ddp;
14654         cmdline_fixed_string_t get;
14655         cmdline_fixed_string_t list;
14656         portid_t port_id;
14657 };
14658
14659 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14660         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14661 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14662         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14663 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14664         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14665 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14666         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14667
14668 static void
14669 cmd_ddp_get_list_parsed(
14670         void *parsed_result,
14671         __attribute__((unused)) struct cmdline *cl,
14672         __attribute__((unused)) void *data)
14673 {
14674         struct cmd_ddp_get_list_result *res = parsed_result;
14675 #ifdef RTE_LIBRTE_I40E_PMD
14676         struct rte_pmd_i40e_profile_list *p_list;
14677         struct rte_pmd_i40e_profile_info *p_info;
14678         uint32_t p_num;
14679         uint32_t size;
14680         uint32_t i;
14681 #endif
14682         int ret = -ENOTSUP;
14683
14684         if (res->port_id > nb_ports) {
14685                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14686                 return;
14687         }
14688
14689 #ifdef RTE_LIBRTE_I40E_PMD
14690         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14691         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14692         if (!p_list)
14693                 printf("%s: Failed to malloc buffer\n", __func__);
14694
14695         if (ret == -ENOTSUP)
14696                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14697                                                 (uint8_t *)p_list, size);
14698
14699         if (!ret) {
14700                 p_num = p_list->p_count;
14701                 printf("Profile number is: %d\n\n", p_num);
14702
14703                 for (i = 0; i < p_num; i++) {
14704                         p_info = &p_list->p_info[i];
14705                         printf("Profile %d:\n", i);
14706                         printf("Track id:     0x%x\n", p_info->track_id);
14707                         printf("Version:      %d.%d.%d.%d\n",
14708                                p_info->version.major,
14709                                p_info->version.minor,
14710                                p_info->version.update,
14711                                p_info->version.draft);
14712                         printf("Profile name: %s\n\n", p_info->name);
14713                 }
14714         }
14715
14716         free(p_list);
14717 #endif
14718
14719         if (ret < 0)
14720                 printf("Failed to get ddp list\n");
14721 }
14722
14723 cmdline_parse_inst_t cmd_ddp_get_list = {
14724         .f = cmd_ddp_get_list_parsed,
14725         .data = NULL,
14726         .help_str = "ddp get list <port_id>",
14727         .tokens = {
14728                 (void *)&cmd_ddp_get_list_ddp,
14729                 (void *)&cmd_ddp_get_list_get,
14730                 (void *)&cmd_ddp_get_list_list,
14731                 (void *)&cmd_ddp_get_list_port_id,
14732                 NULL,
14733         },
14734 };
14735
14736 /* show vf stats */
14737
14738 /* Common result structure for show vf stats */
14739 struct cmd_show_vf_stats_result {
14740         cmdline_fixed_string_t show;
14741         cmdline_fixed_string_t vf;
14742         cmdline_fixed_string_t stats;
14743         portid_t port_id;
14744         uint16_t vf_id;
14745 };
14746
14747 /* Common CLI fields show vf stats*/
14748 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14749         TOKEN_STRING_INITIALIZER
14750                 (struct cmd_show_vf_stats_result,
14751                  show, "show");
14752 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14753         TOKEN_STRING_INITIALIZER
14754                 (struct cmd_show_vf_stats_result,
14755                  vf, "vf");
14756 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14757         TOKEN_STRING_INITIALIZER
14758                 (struct cmd_show_vf_stats_result,
14759                  stats, "stats");
14760 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14761         TOKEN_NUM_INITIALIZER
14762                 (struct cmd_show_vf_stats_result,
14763                  port_id, UINT16);
14764 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14765         TOKEN_NUM_INITIALIZER
14766                 (struct cmd_show_vf_stats_result,
14767                  vf_id, UINT16);
14768
14769 static void
14770 cmd_show_vf_stats_parsed(
14771         void *parsed_result,
14772         __attribute__((unused)) struct cmdline *cl,
14773         __attribute__((unused)) void *data)
14774 {
14775         struct cmd_show_vf_stats_result *res = parsed_result;
14776         struct rte_eth_stats stats;
14777         int ret = -ENOTSUP;
14778         static const char *nic_stats_border = "########################";
14779
14780         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14781                 return;
14782
14783         memset(&stats, 0, sizeof(stats));
14784
14785 #ifdef RTE_LIBRTE_I40E_PMD
14786         if (ret == -ENOTSUP)
14787                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14788                                                 res->vf_id,
14789                                                 &stats);
14790 #endif
14791 #ifdef RTE_LIBRTE_BNXT_PMD
14792         if (ret == -ENOTSUP)
14793                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14794                                                 res->vf_id,
14795                                                 &stats);
14796 #endif
14797
14798         switch (ret) {
14799         case 0:
14800                 break;
14801         case -EINVAL:
14802                 printf("invalid vf_id %d\n", res->vf_id);
14803                 break;
14804         case -ENODEV:
14805                 printf("invalid port_id %d\n", res->port_id);
14806                 break;
14807         case -ENOTSUP:
14808                 printf("function not implemented\n");
14809                 break;
14810         default:
14811                 printf("programming error: (%s)\n", strerror(-ret));
14812         }
14813
14814         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14815                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14816
14817         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14818                "%-"PRIu64"\n",
14819                stats.ipackets, stats.imissed, stats.ibytes);
14820         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14821         printf("  RX-nombuf:  %-10"PRIu64"\n",
14822                stats.rx_nombuf);
14823         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14824                "%-"PRIu64"\n",
14825                stats.opackets, stats.oerrors, stats.obytes);
14826
14827         printf("  %s############################%s\n",
14828                                nic_stats_border, nic_stats_border);
14829 }
14830
14831 cmdline_parse_inst_t cmd_show_vf_stats = {
14832         .f = cmd_show_vf_stats_parsed,
14833         .data = NULL,
14834         .help_str = "show vf stats <port_id> <vf_id>",
14835         .tokens = {
14836                 (void *)&cmd_show_vf_stats_show,
14837                 (void *)&cmd_show_vf_stats_vf,
14838                 (void *)&cmd_show_vf_stats_stats,
14839                 (void *)&cmd_show_vf_stats_port_id,
14840                 (void *)&cmd_show_vf_stats_vf_id,
14841                 NULL,
14842         },
14843 };
14844
14845 /* clear vf stats */
14846
14847 /* Common result structure for clear vf stats */
14848 struct cmd_clear_vf_stats_result {
14849         cmdline_fixed_string_t clear;
14850         cmdline_fixed_string_t vf;
14851         cmdline_fixed_string_t stats;
14852         portid_t port_id;
14853         uint16_t vf_id;
14854 };
14855
14856 /* Common CLI fields clear vf stats*/
14857 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14858         TOKEN_STRING_INITIALIZER
14859                 (struct cmd_clear_vf_stats_result,
14860                  clear, "clear");
14861 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_clear_vf_stats_result,
14864                  vf, "vf");
14865 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14866         TOKEN_STRING_INITIALIZER
14867                 (struct cmd_clear_vf_stats_result,
14868                  stats, "stats");
14869 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14870         TOKEN_NUM_INITIALIZER
14871                 (struct cmd_clear_vf_stats_result,
14872                  port_id, UINT16);
14873 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14874         TOKEN_NUM_INITIALIZER
14875                 (struct cmd_clear_vf_stats_result,
14876                  vf_id, UINT16);
14877
14878 static void
14879 cmd_clear_vf_stats_parsed(
14880         void *parsed_result,
14881         __attribute__((unused)) struct cmdline *cl,
14882         __attribute__((unused)) void *data)
14883 {
14884         struct cmd_clear_vf_stats_result *res = parsed_result;
14885         int ret = -ENOTSUP;
14886
14887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14888                 return;
14889
14890 #ifdef RTE_LIBRTE_I40E_PMD
14891         if (ret == -ENOTSUP)
14892                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14893                                                   res->vf_id);
14894 #endif
14895 #ifdef RTE_LIBRTE_BNXT_PMD
14896         if (ret == -ENOTSUP)
14897                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14898                                                   res->vf_id);
14899 #endif
14900
14901         switch (ret) {
14902         case 0:
14903                 break;
14904         case -EINVAL:
14905                 printf("invalid vf_id %d\n", res->vf_id);
14906                 break;
14907         case -ENODEV:
14908                 printf("invalid port_id %d\n", res->port_id);
14909                 break;
14910         case -ENOTSUP:
14911                 printf("function not implemented\n");
14912                 break;
14913         default:
14914                 printf("programming error: (%s)\n", strerror(-ret));
14915         }
14916 }
14917
14918 cmdline_parse_inst_t cmd_clear_vf_stats = {
14919         .f = cmd_clear_vf_stats_parsed,
14920         .data = NULL,
14921         .help_str = "clear vf stats <port_id> <vf_id>",
14922         .tokens = {
14923                 (void *)&cmd_clear_vf_stats_clear,
14924                 (void *)&cmd_clear_vf_stats_vf,
14925                 (void *)&cmd_clear_vf_stats_stats,
14926                 (void *)&cmd_clear_vf_stats_port_id,
14927                 (void *)&cmd_clear_vf_stats_vf_id,
14928                 NULL,
14929         },
14930 };
14931
14932 /* port config pctype mapping reset */
14933
14934 /* Common result structure for port config pctype mapping reset */
14935 struct cmd_pctype_mapping_reset_result {
14936         cmdline_fixed_string_t port;
14937         cmdline_fixed_string_t config;
14938         portid_t port_id;
14939         cmdline_fixed_string_t pctype;
14940         cmdline_fixed_string_t mapping;
14941         cmdline_fixed_string_t reset;
14942 };
14943
14944 /* Common CLI fields for port config pctype mapping reset*/
14945 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14946         TOKEN_STRING_INITIALIZER
14947                 (struct cmd_pctype_mapping_reset_result,
14948                  port, "port");
14949 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14950         TOKEN_STRING_INITIALIZER
14951                 (struct cmd_pctype_mapping_reset_result,
14952                  config, "config");
14953 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14954         TOKEN_NUM_INITIALIZER
14955                 (struct cmd_pctype_mapping_reset_result,
14956                  port_id, UINT16);
14957 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14958         TOKEN_STRING_INITIALIZER
14959                 (struct cmd_pctype_mapping_reset_result,
14960                  pctype, "pctype");
14961 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14962         TOKEN_STRING_INITIALIZER
14963                 (struct cmd_pctype_mapping_reset_result,
14964                  mapping, "mapping");
14965 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14966         TOKEN_STRING_INITIALIZER
14967                 (struct cmd_pctype_mapping_reset_result,
14968                  reset, "reset");
14969
14970 static void
14971 cmd_pctype_mapping_reset_parsed(
14972         void *parsed_result,
14973         __attribute__((unused)) struct cmdline *cl,
14974         __attribute__((unused)) void *data)
14975 {
14976         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14977         int ret = -ENOTSUP;
14978
14979         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14980                 return;
14981
14982 #ifdef RTE_LIBRTE_I40E_PMD
14983         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14984 #endif
14985
14986         switch (ret) {
14987         case 0:
14988                 break;
14989         case -ENODEV:
14990                 printf("invalid port_id %d\n", res->port_id);
14991                 break;
14992         case -ENOTSUP:
14993                 printf("function not implemented\n");
14994                 break;
14995         default:
14996                 printf("programming error: (%s)\n", strerror(-ret));
14997         }
14998 }
14999
15000 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15001         .f = cmd_pctype_mapping_reset_parsed,
15002         .data = NULL,
15003         .help_str = "port config <port_id> pctype mapping reset",
15004         .tokens = {
15005                 (void *)&cmd_pctype_mapping_reset_port,
15006                 (void *)&cmd_pctype_mapping_reset_config,
15007                 (void *)&cmd_pctype_mapping_reset_port_id,
15008                 (void *)&cmd_pctype_mapping_reset_pctype,
15009                 (void *)&cmd_pctype_mapping_reset_mapping,
15010                 (void *)&cmd_pctype_mapping_reset_reset,
15011                 NULL,
15012         },
15013 };
15014
15015 /* show port pctype mapping */
15016
15017 /* Common result structure for show port pctype mapping */
15018 struct cmd_pctype_mapping_get_result {
15019         cmdline_fixed_string_t show;
15020         cmdline_fixed_string_t port;
15021         portid_t port_id;
15022         cmdline_fixed_string_t pctype;
15023         cmdline_fixed_string_t mapping;
15024 };
15025
15026 /* Common CLI fields for pctype mapping get */
15027 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15028         TOKEN_STRING_INITIALIZER
15029                 (struct cmd_pctype_mapping_get_result,
15030                  show, "show");
15031 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15032         TOKEN_STRING_INITIALIZER
15033                 (struct cmd_pctype_mapping_get_result,
15034                  port, "port");
15035 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15036         TOKEN_NUM_INITIALIZER
15037                 (struct cmd_pctype_mapping_get_result,
15038                  port_id, UINT16);
15039 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15040         TOKEN_STRING_INITIALIZER
15041                 (struct cmd_pctype_mapping_get_result,
15042                  pctype, "pctype");
15043 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15044         TOKEN_STRING_INITIALIZER
15045                 (struct cmd_pctype_mapping_get_result,
15046                  mapping, "mapping");
15047
15048 static void
15049 cmd_pctype_mapping_get_parsed(
15050         void *parsed_result,
15051         __attribute__((unused)) struct cmdline *cl,
15052         __attribute__((unused)) void *data)
15053 {
15054         struct cmd_pctype_mapping_get_result *res = parsed_result;
15055         int ret = -ENOTSUP;
15056 #ifdef RTE_LIBRTE_I40E_PMD
15057         struct rte_pmd_i40e_flow_type_mapping
15058                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15059         int i, j, first_pctype;
15060 #endif
15061
15062         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15063                 return;
15064
15065 #ifdef RTE_LIBRTE_I40E_PMD
15066         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15067 #endif
15068
15069         switch (ret) {
15070         case 0:
15071                 break;
15072         case -ENODEV:
15073                 printf("invalid port_id %d\n", res->port_id);
15074                 return;
15075         case -ENOTSUP:
15076                 printf("function not implemented\n");
15077                 return;
15078         default:
15079                 printf("programming error: (%s)\n", strerror(-ret));
15080                 return;
15081         }
15082
15083 #ifdef RTE_LIBRTE_I40E_PMD
15084         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15085                 if (mapping[i].pctype != 0ULL) {
15086                         first_pctype = 1;
15087
15088                         printf("pctype: ");
15089                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15090                                 if (mapping[i].pctype & (1ULL << j)) {
15091                                         printf(first_pctype ?
15092                                                "%02d" : ",%02d", j);
15093                                         first_pctype = 0;
15094                                 }
15095                         }
15096                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15097                 }
15098         }
15099 #endif
15100 }
15101
15102 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15103         .f = cmd_pctype_mapping_get_parsed,
15104         .data = NULL,
15105         .help_str = "show port <port_id> pctype mapping",
15106         .tokens = {
15107                 (void *)&cmd_pctype_mapping_get_show,
15108                 (void *)&cmd_pctype_mapping_get_port,
15109                 (void *)&cmd_pctype_mapping_get_port_id,
15110                 (void *)&cmd_pctype_mapping_get_pctype,
15111                 (void *)&cmd_pctype_mapping_get_mapping,
15112                 NULL,
15113         },
15114 };
15115
15116 /* port config pctype mapping update */
15117
15118 /* Common result structure for port config pctype mapping update */
15119 struct cmd_pctype_mapping_update_result {
15120         cmdline_fixed_string_t port;
15121         cmdline_fixed_string_t config;
15122         portid_t port_id;
15123         cmdline_fixed_string_t pctype;
15124         cmdline_fixed_string_t mapping;
15125         cmdline_fixed_string_t update;
15126         cmdline_fixed_string_t pctype_list;
15127         uint16_t flow_type;
15128 };
15129
15130 /* Common CLI fields for pctype mapping update*/
15131 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15132         TOKEN_STRING_INITIALIZER
15133                 (struct cmd_pctype_mapping_update_result,
15134                  port, "port");
15135 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15136         TOKEN_STRING_INITIALIZER
15137                 (struct cmd_pctype_mapping_update_result,
15138                  config, "config");
15139 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15140         TOKEN_NUM_INITIALIZER
15141                 (struct cmd_pctype_mapping_update_result,
15142                  port_id, UINT16);
15143 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15144         TOKEN_STRING_INITIALIZER
15145                 (struct cmd_pctype_mapping_update_result,
15146                  pctype, "pctype");
15147 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15148         TOKEN_STRING_INITIALIZER
15149                 (struct cmd_pctype_mapping_update_result,
15150                  mapping, "mapping");
15151 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15152         TOKEN_STRING_INITIALIZER
15153                 (struct cmd_pctype_mapping_update_result,
15154                  update, "update");
15155 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15156         TOKEN_STRING_INITIALIZER
15157                 (struct cmd_pctype_mapping_update_result,
15158                  pctype_list, NULL);
15159 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15160         TOKEN_NUM_INITIALIZER
15161                 (struct cmd_pctype_mapping_update_result,
15162                  flow_type, UINT16);
15163
15164 static void
15165 cmd_pctype_mapping_update_parsed(
15166         void *parsed_result,
15167         __attribute__((unused)) struct cmdline *cl,
15168         __attribute__((unused)) void *data)
15169 {
15170         struct cmd_pctype_mapping_update_result *res = parsed_result;
15171         int ret = -ENOTSUP;
15172 #ifdef RTE_LIBRTE_I40E_PMD
15173         struct rte_pmd_i40e_flow_type_mapping mapping;
15174         unsigned int i;
15175         unsigned int nb_item;
15176         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15177 #endif
15178
15179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15180                 return;
15181
15182 #ifdef RTE_LIBRTE_I40E_PMD
15183         nb_item = parse_item_list(res->pctype_list, "pctypes",
15184                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15185         mapping.flow_type = res->flow_type;
15186         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15187                 mapping.pctype |= (1ULL << pctype_list[i]);
15188         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15189                                                 &mapping,
15190                                                 1,
15191                                                 0);
15192 #endif
15193
15194         switch (ret) {
15195         case 0:
15196                 break;
15197         case -EINVAL:
15198                 printf("invalid pctype or flow type\n");
15199                 break;
15200         case -ENODEV:
15201                 printf("invalid port_id %d\n", res->port_id);
15202                 break;
15203         case -ENOTSUP:
15204                 printf("function not implemented\n");
15205                 break;
15206         default:
15207                 printf("programming error: (%s)\n", strerror(-ret));
15208         }
15209 }
15210
15211 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15212         .f = cmd_pctype_mapping_update_parsed,
15213         .data = NULL,
15214         .help_str = "port config <port_id> pctype mapping update"
15215         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15216         .tokens = {
15217                 (void *)&cmd_pctype_mapping_update_port,
15218                 (void *)&cmd_pctype_mapping_update_config,
15219                 (void *)&cmd_pctype_mapping_update_port_id,
15220                 (void *)&cmd_pctype_mapping_update_pctype,
15221                 (void *)&cmd_pctype_mapping_update_mapping,
15222                 (void *)&cmd_pctype_mapping_update_update,
15223                 (void *)&cmd_pctype_mapping_update_pc_type,
15224                 (void *)&cmd_pctype_mapping_update_flow_type,
15225                 NULL,
15226         },
15227 };
15228
15229 /* ptype mapping get */
15230
15231 /* Common result structure for ptype mapping get */
15232 struct cmd_ptype_mapping_get_result {
15233         cmdline_fixed_string_t ptype;
15234         cmdline_fixed_string_t mapping;
15235         cmdline_fixed_string_t get;
15236         portid_t port_id;
15237         uint8_t valid_only;
15238 };
15239
15240 /* Common CLI fields for ptype mapping get */
15241 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15242         TOKEN_STRING_INITIALIZER
15243                 (struct cmd_ptype_mapping_get_result,
15244                  ptype, "ptype");
15245 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15246         TOKEN_STRING_INITIALIZER
15247                 (struct cmd_ptype_mapping_get_result,
15248                  mapping, "mapping");
15249 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15250         TOKEN_STRING_INITIALIZER
15251                 (struct cmd_ptype_mapping_get_result,
15252                  get, "get");
15253 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15254         TOKEN_NUM_INITIALIZER
15255                 (struct cmd_ptype_mapping_get_result,
15256                  port_id, UINT16);
15257 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15258         TOKEN_NUM_INITIALIZER
15259                 (struct cmd_ptype_mapping_get_result,
15260                  valid_only, UINT8);
15261
15262 static void
15263 cmd_ptype_mapping_get_parsed(
15264         void *parsed_result,
15265         __attribute__((unused)) struct cmdline *cl,
15266         __attribute__((unused)) void *data)
15267 {
15268         struct cmd_ptype_mapping_get_result *res = parsed_result;
15269         int ret = -ENOTSUP;
15270 #ifdef RTE_LIBRTE_I40E_PMD
15271         int max_ptype_num = 256;
15272         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15273         uint16_t count;
15274         int i;
15275 #endif
15276
15277         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15278                 return;
15279
15280 #ifdef RTE_LIBRTE_I40E_PMD
15281         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15282                                         mapping,
15283                                         max_ptype_num,
15284                                         &count,
15285                                         res->valid_only);
15286 #endif
15287
15288         switch (ret) {
15289         case 0:
15290                 break;
15291         case -ENODEV:
15292                 printf("invalid port_id %d\n", res->port_id);
15293                 break;
15294         case -ENOTSUP:
15295                 printf("function not implemented\n");
15296                 break;
15297         default:
15298                 printf("programming error: (%s)\n", strerror(-ret));
15299         }
15300
15301 #ifdef RTE_LIBRTE_I40E_PMD
15302         if (!ret) {
15303                 for (i = 0; i < count; i++)
15304                         printf("%3d\t0x%08x\n",
15305                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15306         }
15307 #endif
15308 }
15309
15310 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15311         .f = cmd_ptype_mapping_get_parsed,
15312         .data = NULL,
15313         .help_str = "ptype mapping get <port_id> <valid_only>",
15314         .tokens = {
15315                 (void *)&cmd_ptype_mapping_get_ptype,
15316                 (void *)&cmd_ptype_mapping_get_mapping,
15317                 (void *)&cmd_ptype_mapping_get_get,
15318                 (void *)&cmd_ptype_mapping_get_port_id,
15319                 (void *)&cmd_ptype_mapping_get_valid_only,
15320                 NULL,
15321         },
15322 };
15323
15324 /* ptype mapping replace */
15325
15326 /* Common result structure for ptype mapping replace */
15327 struct cmd_ptype_mapping_replace_result {
15328         cmdline_fixed_string_t ptype;
15329         cmdline_fixed_string_t mapping;
15330         cmdline_fixed_string_t replace;
15331         portid_t port_id;
15332         uint32_t target;
15333         uint8_t mask;
15334         uint32_t pkt_type;
15335 };
15336
15337 /* Common CLI fields for ptype mapping replace */
15338 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15339         TOKEN_STRING_INITIALIZER
15340                 (struct cmd_ptype_mapping_replace_result,
15341                  ptype, "ptype");
15342 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15343         TOKEN_STRING_INITIALIZER
15344                 (struct cmd_ptype_mapping_replace_result,
15345                  mapping, "mapping");
15346 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15347         TOKEN_STRING_INITIALIZER
15348                 (struct cmd_ptype_mapping_replace_result,
15349                  replace, "replace");
15350 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15351         TOKEN_NUM_INITIALIZER
15352                 (struct cmd_ptype_mapping_replace_result,
15353                  port_id, UINT16);
15354 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15355         TOKEN_NUM_INITIALIZER
15356                 (struct cmd_ptype_mapping_replace_result,
15357                  target, UINT32);
15358 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15359         TOKEN_NUM_INITIALIZER
15360                 (struct cmd_ptype_mapping_replace_result,
15361                  mask, UINT8);
15362 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15363         TOKEN_NUM_INITIALIZER
15364                 (struct cmd_ptype_mapping_replace_result,
15365                  pkt_type, UINT32);
15366
15367 static void
15368 cmd_ptype_mapping_replace_parsed(
15369         void *parsed_result,
15370         __attribute__((unused)) struct cmdline *cl,
15371         __attribute__((unused)) void *data)
15372 {
15373         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15374         int ret = -ENOTSUP;
15375
15376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15377                 return;
15378
15379 #ifdef RTE_LIBRTE_I40E_PMD
15380         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15381                                         res->target,
15382                                         res->mask,
15383                                         res->pkt_type);
15384 #endif
15385
15386         switch (ret) {
15387         case 0:
15388                 break;
15389         case -EINVAL:
15390                 printf("invalid ptype 0x%8x or 0x%8x\n",
15391                                 res->target, res->pkt_type);
15392                 break;
15393         case -ENODEV:
15394                 printf("invalid port_id %d\n", res->port_id);
15395                 break;
15396         case -ENOTSUP:
15397                 printf("function not implemented\n");
15398                 break;
15399         default:
15400                 printf("programming error: (%s)\n", strerror(-ret));
15401         }
15402 }
15403
15404 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15405         .f = cmd_ptype_mapping_replace_parsed,
15406         .data = NULL,
15407         .help_str =
15408                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15409         .tokens = {
15410                 (void *)&cmd_ptype_mapping_replace_ptype,
15411                 (void *)&cmd_ptype_mapping_replace_mapping,
15412                 (void *)&cmd_ptype_mapping_replace_replace,
15413                 (void *)&cmd_ptype_mapping_replace_port_id,
15414                 (void *)&cmd_ptype_mapping_replace_target,
15415                 (void *)&cmd_ptype_mapping_replace_mask,
15416                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15417                 NULL,
15418         },
15419 };
15420
15421 /* ptype mapping reset */
15422
15423 /* Common result structure for ptype mapping reset */
15424 struct cmd_ptype_mapping_reset_result {
15425         cmdline_fixed_string_t ptype;
15426         cmdline_fixed_string_t mapping;
15427         cmdline_fixed_string_t reset;
15428         portid_t port_id;
15429 };
15430
15431 /* Common CLI fields for ptype mapping reset*/
15432 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15433         TOKEN_STRING_INITIALIZER
15434                 (struct cmd_ptype_mapping_reset_result,
15435                  ptype, "ptype");
15436 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15437         TOKEN_STRING_INITIALIZER
15438                 (struct cmd_ptype_mapping_reset_result,
15439                  mapping, "mapping");
15440 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15441         TOKEN_STRING_INITIALIZER
15442                 (struct cmd_ptype_mapping_reset_result,
15443                  reset, "reset");
15444 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15445         TOKEN_NUM_INITIALIZER
15446                 (struct cmd_ptype_mapping_reset_result,
15447                  port_id, UINT16);
15448
15449 static void
15450 cmd_ptype_mapping_reset_parsed(
15451         void *parsed_result,
15452         __attribute__((unused)) struct cmdline *cl,
15453         __attribute__((unused)) void *data)
15454 {
15455         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15456         int ret = -ENOTSUP;
15457
15458         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15459                 return;
15460
15461 #ifdef RTE_LIBRTE_I40E_PMD
15462         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15463 #endif
15464
15465         switch (ret) {
15466         case 0:
15467                 break;
15468         case -ENODEV:
15469                 printf("invalid port_id %d\n", res->port_id);
15470                 break;
15471         case -ENOTSUP:
15472                 printf("function not implemented\n");
15473                 break;
15474         default:
15475                 printf("programming error: (%s)\n", strerror(-ret));
15476         }
15477 }
15478
15479 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15480         .f = cmd_ptype_mapping_reset_parsed,
15481         .data = NULL,
15482         .help_str = "ptype mapping reset <port_id>",
15483         .tokens = {
15484                 (void *)&cmd_ptype_mapping_reset_ptype,
15485                 (void *)&cmd_ptype_mapping_reset_mapping,
15486                 (void *)&cmd_ptype_mapping_reset_reset,
15487                 (void *)&cmd_ptype_mapping_reset_port_id,
15488                 NULL,
15489         },
15490 };
15491
15492 /* ptype mapping update */
15493
15494 /* Common result structure for ptype mapping update */
15495 struct cmd_ptype_mapping_update_result {
15496         cmdline_fixed_string_t ptype;
15497         cmdline_fixed_string_t mapping;
15498         cmdline_fixed_string_t reset;
15499         portid_t port_id;
15500         uint8_t hw_ptype;
15501         uint32_t sw_ptype;
15502 };
15503
15504 /* Common CLI fields for ptype mapping update*/
15505 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15506         TOKEN_STRING_INITIALIZER
15507                 (struct cmd_ptype_mapping_update_result,
15508                  ptype, "ptype");
15509 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15510         TOKEN_STRING_INITIALIZER
15511                 (struct cmd_ptype_mapping_update_result,
15512                  mapping, "mapping");
15513 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15514         TOKEN_STRING_INITIALIZER
15515                 (struct cmd_ptype_mapping_update_result,
15516                  reset, "update");
15517 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15518         TOKEN_NUM_INITIALIZER
15519                 (struct cmd_ptype_mapping_update_result,
15520                  port_id, UINT16);
15521 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15522         TOKEN_NUM_INITIALIZER
15523                 (struct cmd_ptype_mapping_update_result,
15524                  hw_ptype, UINT8);
15525 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15526         TOKEN_NUM_INITIALIZER
15527                 (struct cmd_ptype_mapping_update_result,
15528                  sw_ptype, UINT32);
15529
15530 static void
15531 cmd_ptype_mapping_update_parsed(
15532         void *parsed_result,
15533         __attribute__((unused)) struct cmdline *cl,
15534         __attribute__((unused)) void *data)
15535 {
15536         struct cmd_ptype_mapping_update_result *res = parsed_result;
15537         int ret = -ENOTSUP;
15538 #ifdef RTE_LIBRTE_I40E_PMD
15539         struct rte_pmd_i40e_ptype_mapping mapping;
15540 #endif
15541         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15542                 return;
15543
15544 #ifdef RTE_LIBRTE_I40E_PMD
15545         mapping.hw_ptype = res->hw_ptype;
15546         mapping.sw_ptype = res->sw_ptype;
15547         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15548                                                 &mapping,
15549                                                 1,
15550                                                 0);
15551 #endif
15552
15553         switch (ret) {
15554         case 0:
15555                 break;
15556         case -EINVAL:
15557                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15558                 break;
15559         case -ENODEV:
15560                 printf("invalid port_id %d\n", res->port_id);
15561                 break;
15562         case -ENOTSUP:
15563                 printf("function not implemented\n");
15564                 break;
15565         default:
15566                 printf("programming error: (%s)\n", strerror(-ret));
15567         }
15568 }
15569
15570 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15571         .f = cmd_ptype_mapping_update_parsed,
15572         .data = NULL,
15573         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15574         .tokens = {
15575                 (void *)&cmd_ptype_mapping_update_ptype,
15576                 (void *)&cmd_ptype_mapping_update_mapping,
15577                 (void *)&cmd_ptype_mapping_update_update,
15578                 (void *)&cmd_ptype_mapping_update_port_id,
15579                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15580                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15581                 NULL,
15582         },
15583 };
15584
15585 /* Common result structure for file commands */
15586 struct cmd_cmdfile_result {
15587         cmdline_fixed_string_t load;
15588         cmdline_fixed_string_t filename;
15589 };
15590
15591 /* Common CLI fields for file commands */
15592 cmdline_parse_token_string_t cmd_load_cmdfile =
15593         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15594 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15595         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15596
15597 static void
15598 cmd_load_from_file_parsed(
15599         void *parsed_result,
15600         __attribute__((unused)) struct cmdline *cl,
15601         __attribute__((unused)) void *data)
15602 {
15603         struct cmd_cmdfile_result *res = parsed_result;
15604
15605         cmdline_read_from_file(res->filename);
15606 }
15607
15608 cmdline_parse_inst_t cmd_load_from_file = {
15609         .f = cmd_load_from_file_parsed,
15610         .data = NULL,
15611         .help_str = "load <filename>",
15612         .tokens = {
15613                 (void *)&cmd_load_cmdfile,
15614                 (void *)&cmd_load_cmdfile_filename,
15615                 NULL,
15616         },
15617 };
15618
15619 /* ******************************************************************************** */
15620
15621 /* list of instructions */
15622 cmdline_parse_ctx_t main_ctx[] = {
15623         (cmdline_parse_inst_t *)&cmd_help_brief,
15624         (cmdline_parse_inst_t *)&cmd_help_long,
15625         (cmdline_parse_inst_t *)&cmd_quit,
15626         (cmdline_parse_inst_t *)&cmd_load_from_file,
15627         (cmdline_parse_inst_t *)&cmd_showport,
15628         (cmdline_parse_inst_t *)&cmd_showqueue,
15629         (cmdline_parse_inst_t *)&cmd_showportall,
15630         (cmdline_parse_inst_t *)&cmd_showcfg,
15631         (cmdline_parse_inst_t *)&cmd_start,
15632         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15633         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15634         (cmdline_parse_inst_t *)&cmd_set_link_up,
15635         (cmdline_parse_inst_t *)&cmd_set_link_down,
15636         (cmdline_parse_inst_t *)&cmd_reset,
15637         (cmdline_parse_inst_t *)&cmd_set_numbers,
15638         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15639         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15640         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15641         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15642         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15643         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15644         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15645         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15646         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15647         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15648         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15649         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15650         (cmdline_parse_inst_t *)&cmd_set_link_check,
15651         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15652         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15653         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15654         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15655 #ifdef RTE_LIBRTE_PMD_BOND
15656         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15657         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15658         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15659         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15660         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15661         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15662         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15663         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15664         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15665         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15666         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15667 #endif
15668         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15669         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15670         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15671         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15672         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15673         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15674         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15675         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15676         (cmdline_parse_inst_t *)&cmd_csum_set,
15677         (cmdline_parse_inst_t *)&cmd_csum_show,
15678         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15679         (cmdline_parse_inst_t *)&cmd_tso_set,
15680         (cmdline_parse_inst_t *)&cmd_tso_show,
15681         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15682         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15683         (cmdline_parse_inst_t *)&cmd_gro_enable,
15684         (cmdline_parse_inst_t *)&cmd_gro_flush,
15685         (cmdline_parse_inst_t *)&cmd_gro_show,
15686         (cmdline_parse_inst_t *)&cmd_gso_enable,
15687         (cmdline_parse_inst_t *)&cmd_gso_size,
15688         (cmdline_parse_inst_t *)&cmd_gso_show,
15689         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15690         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15691         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15692         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15693         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15694         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15695         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15696         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15697         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15698         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15699         (cmdline_parse_inst_t *)&cmd_config_dcb,
15700         (cmdline_parse_inst_t *)&cmd_read_reg,
15701         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15702         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15703         (cmdline_parse_inst_t *)&cmd_write_reg,
15704         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15705         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15706         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15707         (cmdline_parse_inst_t *)&cmd_stop,
15708         (cmdline_parse_inst_t *)&cmd_mac_addr,
15709         (cmdline_parse_inst_t *)&cmd_set_qmap,
15710         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15711         (cmdline_parse_inst_t *)&cmd_operate_port,
15712         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15713         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15714         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15715         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15716         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15717         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15718         (cmdline_parse_inst_t *)&cmd_config_mtu,
15719         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15720         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15721         (cmdline_parse_inst_t *)&cmd_config_rss,
15722         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15723         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15724         (cmdline_parse_inst_t *)&cmd_showport_reta,
15725         (cmdline_parse_inst_t *)&cmd_config_burst,
15726         (cmdline_parse_inst_t *)&cmd_config_thresh,
15727         (cmdline_parse_inst_t *)&cmd_config_threshold,
15728         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15729         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15730         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15731         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15732         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15733         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15734         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15735         (cmdline_parse_inst_t *)&cmd_global_config,
15736         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15737         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15738         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15739         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15740         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15741         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15742         (cmdline_parse_inst_t *)&cmd_dump,
15743         (cmdline_parse_inst_t *)&cmd_dump_one,
15744         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15745         (cmdline_parse_inst_t *)&cmd_syn_filter,
15746         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15747         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15748         (cmdline_parse_inst_t *)&cmd_flex_filter,
15749         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15750         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15751         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15752         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15753         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15754         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15755         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15756         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15757         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15758         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15759         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15760         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15761         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15762         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15763         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15764         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15765         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15766         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15767         (cmdline_parse_inst_t *)&cmd_flow,
15768         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15769         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15770         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15771         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15772         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15773         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15774         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15775         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15776         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15777         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15778         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15779         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15780         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15781         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15782         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15783         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15784         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15785         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15786         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15787         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15788         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15789         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15790         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15791         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15792         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15793         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15794         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15795         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15796         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15797         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15798         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15799         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15800         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15801         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15802         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15803         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15804         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15805         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15806         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15807         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15808         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15809         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15810         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15811         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15812         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15813         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15814         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15815         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15816         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15817 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15818         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15819 #endif
15820         (cmdline_parse_inst_t *)&cmd_ddp_add,
15821         (cmdline_parse_inst_t *)&cmd_ddp_del,
15822         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15823         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15824         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15825         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15826         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15827         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15828         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15829         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15830
15831         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15832         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15833         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15834         (cmdline_parse_inst_t *)&cmd_queue_region,
15835         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15836         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15837         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15838         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15839         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15840         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15841         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15842         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15843         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15844         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15845         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15846         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15847         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15848         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15849         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15850         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15851         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15852         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15853         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15854         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15855         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15856         NULL,
15857 };
15858
15859 /* read cmdline commands from file */
15860 void
15861 cmdline_read_from_file(const char *filename)
15862 {
15863         struct cmdline *cl;
15864
15865         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15866         if (cl == NULL) {
15867                 printf("Failed to create file based cmdline context: %s\n",
15868                        filename);
15869                 return;
15870         }
15871
15872         cmdline_interact(cl);
15873         cmdline_quit(cl);
15874
15875         cmdline_free(cl);
15876
15877         printf("Read CLI commands from %s\n", filename);
15878 }
15879
15880 /* prompt function, called from main on MASTER lcore */
15881 void
15882 prompt(void)
15883 {
15884         /* initialize non-constant commands */
15885         cmd_set_fwd_mode_init();
15886         cmd_set_fwd_retry_mode_init();
15887
15888         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15889         if (testpmd_cl == NULL)
15890                 return;
15891         cmdline_interact(testpmd_cl);
15892         cmdline_stdin_exit(testpmd_cl);
15893 }
15894
15895 void
15896 prompt_exit(void)
15897 {
15898         if (testpmd_cl != NULL)
15899                 cmdline_quit(testpmd_cl);
15900 }
15901
15902 static void
15903 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15904 {
15905         if (id == (portid_t)RTE_PORT_ALL) {
15906                 portid_t pid;
15907
15908                 RTE_ETH_FOREACH_DEV(pid) {
15909                         /* check if need_reconfig has been set to 1 */
15910                         if (ports[pid].need_reconfig == 0)
15911                                 ports[pid].need_reconfig = dev;
15912                         /* check if need_reconfig_queues has been set to 1 */
15913                         if (ports[pid].need_reconfig_queues == 0)
15914                                 ports[pid].need_reconfig_queues = queue;
15915                 }
15916         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15917                 /* check if need_reconfig has been set to 1 */
15918                 if (ports[id].need_reconfig == 0)
15919                         ports[id].need_reconfig = dev;
15920                 /* check if need_reconfig_queues has been set to 1 */
15921                 if (ports[id].need_reconfig_queues == 0)
15922                         ports[id].need_reconfig_queues = queue;
15923         }
15924 }