app/testpmd: add commands for shaper and wred profiles
[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 port (port_id) vf (vf_id) rx|tx on|off\n"
530                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
531
532                         "set port (port_id) vf (vf_id) (mac_addr)"
533                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
534                         "   Add/Remove unicast or multicast MAC addr filter"
535                         " for a VF.\n\n"
536
537                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
538                         "|MPE) (on|off)\n"
539                         "    AUPE:accepts untagged VLAN;"
540                         "ROPE:accept unicast hash\n\n"
541                         "    BAM:accepts broadcast packets;"
542                         "MPE:accepts all multicast packets\n\n"
543                         "    Enable/Disable a VF receive mode of a port\n\n"
544
545                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
546                         "    Set rate limit for a queue of a port\n\n"
547
548                         "set port (port_id) vf (vf_id) rate (rate_num) "
549                         "queue_mask (queue_mask_value)\n"
550                         "    Set rate limit for queues in VF of a port\n\n"
551
552                         "set port (port_id) mirror-rule (rule_id)"
553                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
554                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
555                         "   Set pool or vlan type mirror rule on a port.\n"
556                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
557                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
558                         " to pool 0.\n\n"
559
560                         "set port (port_id) mirror-rule (rule_id)"
561                         " (uplink-mirror|downlink-mirror) dst-pool"
562                         " (pool_id) (on|off)\n"
563                         "   Set uplink or downlink type mirror rule on a port.\n"
564                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
565                         " 0 on' enable mirror income traffic to pool 0.\n\n"
566
567                         "reset port (port_id) mirror-rule (rule_id)\n"
568                         "   Reset a mirror rule.\n\n"
569
570                         "set flush_rx (on|off)\n"
571                         "   Flush (default) or don't flush RX streams before"
572                         " forwarding. Mainly used with PCAP drivers.\n\n"
573
574                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
575                         "   Set the bypass mode for the lowest port on bypass enabled"
576                         " NIC.\n\n"
577
578                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
579                         "mode (normal|bypass|isolate) (port_id)\n"
580                         "   Set the event required to initiate specified bypass mode for"
581                         " the lowest port on a bypass enabled NIC where:\n"
582                         "       timeout   = enable bypass after watchdog timeout.\n"
583                         "       os_on     = enable bypass when OS/board is powered on.\n"
584                         "       os_off    = enable bypass when OS/board is powered off.\n"
585                         "       power_on  = enable bypass when power supply is turned on.\n"
586                         "       power_off = enable bypass when power supply is turned off."
587                         "\n\n"
588
589                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
590                         "   Set the bypass watchdog timeout to 'n' seconds"
591                         " where 0 = instant.\n\n"
592
593                         "show bypass config (port_id)\n"
594                         "   Show the bypass configuration for a bypass enabled NIC"
595                         " using the lowest port on the NIC.\n\n"
596
597 #ifdef RTE_LIBRTE_PMD_BOND
598                         "create bonded device (mode) (socket)\n"
599                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
600
601                         "add bonding slave (slave_id) (port_id)\n"
602                         "       Add a slave device to a bonded device.\n\n"
603
604                         "remove bonding slave (slave_id) (port_id)\n"
605                         "       Remove a slave device from a bonded device.\n\n"
606
607                         "set bonding mode (value) (port_id)\n"
608                         "       Set the bonding mode on a bonded device.\n\n"
609
610                         "set bonding primary (slave_id) (port_id)\n"
611                         "       Set the primary slave for a bonded device.\n\n"
612
613                         "show bonding config (port_id)\n"
614                         "       Show the bonding config for port_id.\n\n"
615
616                         "set bonding mac_addr (port_id) (address)\n"
617                         "       Set the MAC address of a bonded device.\n\n"
618
619                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
620                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
621
622                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
623                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
624
625                         "set bonding mon_period (port_id) (value)\n"
626                         "       Set the bonding link status monitoring polling period in ms.\n\n"
627
628                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
629                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
630
631 #endif
632                         "set link-up port (port_id)\n"
633                         "       Set link up for a port.\n\n"
634
635                         "set link-down port (port_id)\n"
636                         "       Set link down for a port.\n\n"
637
638                         "E-tag set insertion on port-tag-id (value)"
639                         " port (port_id) vf (vf_id)\n"
640                         "    Enable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
643                         "    Disable E-tag insertion for a VF on a port\n\n"
644
645                         "E-tag set stripping (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag stripping on a port\n\n"
647
648                         "E-tag set forwarding (on|off) port (port_id)\n"
649                         "    Enable/disable E-tag based forwarding"
650                         " on a port\n\n"
651
652                         "E-tag set filter add e-tag-id (value) dst-pool"
653                         " (pool_id) port (port_id)\n"
654                         "    Add an E-tag forwarding filter on a port\n\n"
655
656                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
657                         "    Delete an E-tag forwarding filter on a port\n\n"
658
659 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
660                         "set port tm hierarchy default (port_id)\n"
661                         "       Set default traffic Management hierarchy on a port\n\n"
662
663 #endif
664                         "ddp add (port_id) (profile_path[,output_path])\n"
665                         "    Load a profile package on a port\n\n"
666
667                         "ddp del (port_id) (profile_path)\n"
668                         "    Delete a profile package from a port\n\n"
669
670                         "ptype mapping get (port_id) (valid_only)\n"
671                         "    Get ptype mapping on a port\n\n"
672
673                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
674                         "    Replace target with the pkt_type in ptype mapping\n\n"
675
676                         "ptype mapping reset (port_id)\n"
677                         "    Reset ptype mapping on a port\n\n"
678
679                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
680                         "    Update a ptype mapping item on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "queue_start_index (value) queue_num (value)\n"
684                         "    Set a queue region on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "flowtype (value)\n"
688                         "    Set a flowtype region index on a port\n\n"
689
690                         "set port (port_id) queue-region UP (value) region_id (value)\n"
691                         "    Set the mapping of User Priority to "
692                         "queue region on a port\n\n"
693
694                         "set port (port_id) queue-region flush (on|off)\n"
695                         "    flush all queue region related configuration\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "    meter create\n\n"
711
712                         "del port meter (port_id) (mtr_id)\n"
713                         "    meter delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter policer action (port_id) (mtr_id) (color) (action)\n"
719                         "    meter update policer action\n\n"
720
721                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
722                         "    meter update stats\n\n"
723
724                         "show port (port_id) queue-region\n"
725                         "    show all queue region related configuration info\n\n"
726
727                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
728                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
729                         "       Add port tm node private shaper profile.\n\n"
730
731                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
732                         "       Delete port tm node private shaper profile.\n\n"
733
734                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
735                         " (shaper_profile_id)\n"
736                         "       Add/update port tm node shared shaper.\n\n"
737
738                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
739                         "       Delete port tm node shared shaper.\n\n"
740
741                         "set port tm node shaper profile (port_id) (node_id)"
742                         " (shaper_profile_id)\n"
743                         "       Set port tm node shaper profile.\n\n"
744
745                         "add port tm node wred profile (port_id) (wred_profile_id)"
746                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
747                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
748                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
749                         "       Add port tm node wred profile.\n\n"
750
751                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
752                         "       Delete port tm node wred profile.\n\n"
753
754                         , list_pkt_forwarding_modes()
755                 );
756         }
757
758         if (show_all || !strcmp(res->section, "ports")) {
759
760                 cmdline_printf(
761                         cl,
762                         "\n"
763                         "Port Operations:\n"
764                         "----------------\n\n"
765
766                         "port start (port_id|all)\n"
767                         "    Start all ports or port_id.\n\n"
768
769                         "port stop (port_id|all)\n"
770                         "    Stop all ports or port_id.\n\n"
771
772                         "port close (port_id|all)\n"
773                         "    Close all ports or port_id.\n\n"
774
775                         "port attach (ident)\n"
776                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
777
778                         "port detach (port_id)\n"
779                         "    Detach physical or virtual dev by port_id\n\n"
780
781                         "port config (port_id|all)"
782                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
783                         " duplex (half|full|auto)\n"
784                         "    Set speed and duplex for all ports or port_id\n\n"
785
786                         "port config all (rxq|txq|rxd|txd) (value)\n"
787                         "    Set number for rxq/txq/rxd/txd.\n\n"
788
789                         "port config all max-pkt-len (value)\n"
790                         "    Set the max packet length.\n\n"
791
792                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
793                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
794                         " (on|off)\n"
795                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
796                         " for ports.\n\n"
797
798                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
799                         "geneve|nvgre|none|<flowtype_id>)\n"
800                         "    Set the RSS mode.\n\n"
801
802                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
803                         "    Set the RSS redirection table.\n\n"
804
805                         "port config (port_id) dcb vt (on|off) (traffic_class)"
806                         " pfc (on|off)\n"
807                         "    Set the DCB mode.\n\n"
808
809                         "port config all burst (value)\n"
810                         "    Set the number of packets per burst.\n\n"
811
812                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
813                         " (value)\n"
814                         "    Set the ring prefetch/host/writeback threshold"
815                         " for tx/rx queue.\n\n"
816
817                         "port config all (txfreet|txrst|rxfreet) (value)\n"
818                         "    Set free threshold for rx/tx, or set"
819                         " tx rs bit threshold.\n\n"
820                         "port config mtu X value\n"
821                         "    Set the MTU of port X to a given value\n\n"
822
823                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
824                         "    Start/stop a rx/tx queue of port X. Only take effect"
825                         " when port X is started\n\n"
826
827                         "port config (port_id|all) l2-tunnel E-tag ether-type"
828                         " (value)\n"
829                         "    Set the value of E-tag ether-type.\n\n"
830
831                         "port config (port_id|all) l2-tunnel E-tag"
832                         " (enable|disable)\n"
833                         "    Enable/disable the E-tag support.\n\n"
834
835                         "port config (port_id) pctype mapping reset\n"
836                         "    Reset flow type to pctype mapping on a port\n\n"
837
838                         "port config (port_id) pctype mapping update"
839                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
840                         "    Update a flow type to pctype mapping item on a port\n\n"
841                 );
842         }
843
844         if (show_all || !strcmp(res->section, "registers")) {
845
846                 cmdline_printf(
847                         cl,
848                         "\n"
849                         "Registers:\n"
850                         "----------\n\n"
851
852                         "read reg (port_id) (address)\n"
853                         "    Display value of a port register.\n\n"
854
855                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
856                         "    Display a port register bit field.\n\n"
857
858                         "read regbit (port_id) (address) (bit_x)\n"
859                         "    Display a single port register bit.\n\n"
860
861                         "write reg (port_id) (address) (value)\n"
862                         "    Set value of a port register.\n\n"
863
864                         "write regfield (port_id) (address) (bit_x) (bit_y)"
865                         " (value)\n"
866                         "    Set bit field of a port register.\n\n"
867
868                         "write regbit (port_id) (address) (bit_x) (value)\n"
869                         "    Set single bit value of a port register.\n\n"
870                 );
871         }
872         if (show_all || !strcmp(res->section, "filters")) {
873
874                 cmdline_printf(
875                         cl,
876                         "\n"
877                         "filters:\n"
878                         "--------\n\n"
879
880                         "ethertype_filter (port_id) (add|del)"
881                         " (mac_addr|mac_ignr) (mac_address) ethertype"
882                         " (ether_type) (drop|fwd) queue (queue_id)\n"
883                         "    Add/Del an ethertype filter.\n\n"
884
885                         "2tuple_filter (port_id) (add|del)"
886                         " dst_port (dst_port_value) protocol (protocol_value)"
887                         " mask (mask_value) tcp_flags (tcp_flags_value)"
888                         " priority (prio_value) queue (queue_id)\n"
889                         "    Add/Del a 2tuple filter.\n\n"
890
891                         "5tuple_filter (port_id) (add|del)"
892                         " dst_ip (dst_address) src_ip (src_address)"
893                         " dst_port (dst_port_value) src_port (src_port_value)"
894                         " protocol (protocol_value)"
895                         " mask (mask_value) tcp_flags (tcp_flags_value)"
896                         " priority (prio_value) queue (queue_id)\n"
897                         "    Add/Del a 5tuple filter.\n\n"
898
899                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
900                         "    Add/Del syn filter.\n\n"
901
902                         "flex_filter (port_id) (add|del) len (len_value)"
903                         " bytes (bytes_value) mask (mask_value)"
904                         " priority (prio_value) queue (queue_id)\n"
905                         "    Add/Del a flex filter.\n\n"
906
907                         "flow_director_filter (port_id) mode IP (add|del|update)"
908                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
909                         " src (src_ip_address) dst (dst_ip_address)"
910                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
911                         " vlan (vlan_value) flexbytes (flexbytes_value)"
912                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
913                         " fd_id (fd_id_value)\n"
914                         "    Add/Del an IP type flow director filter.\n\n"
915
916                         "flow_director_filter (port_id) mode IP (add|del|update)"
917                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
918                         " src (src_ip_address) (src_port)"
919                         " dst (dst_ip_address) (dst_port)"
920                         " tos (tos_value) ttl (ttl_value)"
921                         " vlan (vlan_value) flexbytes (flexbytes_value)"
922                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
923                         " fd_id (fd_id_value)\n"
924                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
925
926                         "flow_director_filter (port_id) mode IP (add|del|update)"
927                         " flow (ipv4-sctp|ipv6-sctp)"
928                         " src (src_ip_address) (src_port)"
929                         " dst (dst_ip_address) (dst_port)"
930                         " tag (verification_tag) "
931                         " tos (tos_value) ttl (ttl_value)"
932                         " vlan (vlan_value)"
933                         " flexbytes (flexbytes_value) (drop|fwd)"
934                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
935                         "    Add/Del a SCTP type flow director filter.\n\n"
936
937                         "flow_director_filter (port_id) mode IP (add|del|update)"
938                         " flow l2_payload ether (ethertype)"
939                         " flexbytes (flexbytes_value) (drop|fwd)"
940                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
941                         "    Add/Del a l2 payload type flow director filter.\n\n"
942
943                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
944                         " mac (mac_address) vlan (vlan_value)"
945                         " flexbytes (flexbytes_value) (drop|fwd)"
946                         " queue (queue_id) fd_id (fd_id_value)\n"
947                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
948
949                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
950                         " mac (mac_address) vlan (vlan_value)"
951                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
952                         " flexbytes (flexbytes_value) (drop|fwd)"
953                         " queue (queue_id) fd_id (fd_id_value)\n"
954                         "    Add/Del a Tunnel flow director filter.\n\n"
955
956                         "flush_flow_director (port_id)\n"
957                         "    Flush all flow director entries of a device.\n\n"
958
959                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
960                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
961                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
962                         "    Set flow director IP mask.\n\n"
963
964                         "flow_director_mask (port_id) mode MAC-VLAN"
965                         " vlan (vlan_value)\n"
966                         "    Set flow director MAC-VLAN mask.\n\n"
967
968                         "flow_director_mask (port_id) mode Tunnel"
969                         " vlan (vlan_value) mac (mac_value)"
970                         " tunnel-type (tunnel_type_value)"
971                         " tunnel-id (tunnel_id_value)\n"
972                         "    Set flow director Tunnel mask.\n\n"
973
974                         "flow_director_flex_mask (port_id)"
975                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
976                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
977                         " (mask)\n"
978                         "    Configure mask of flex payload.\n\n"
979
980                         "flow_director_flex_payload (port_id)"
981                         " (raw|l2|l3|l4) (config)\n"
982                         "    Configure flex payload selection.\n\n"
983
984                         "get_sym_hash_ena_per_port (port_id)\n"
985                         "    get symmetric hash enable configuration per port.\n\n"
986
987                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
988                         "    set symmetric hash enable configuration per port"
989                         " to enable or disable.\n\n"
990
991                         "get_hash_global_config (port_id)\n"
992                         "    Get the global configurations of hash filters.\n\n"
993
994                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
995                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
996                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
997                         " (enable|disable)\n"
998                         "    Set the global configurations of hash filters.\n\n"
999
1000                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1001                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1002                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1003                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1004                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1005                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1006                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1007                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1008                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1009                         "fld-8th|none) (select|add)\n"
1010                         "    Set the input set for hash.\n\n"
1011
1012                         "set_fdir_input_set (port_id) "
1013                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1014                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1015                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1016                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1017                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1018                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1019                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1020                         " (select|add)\n"
1021                         "    Set the input set for FDir.\n\n"
1022
1023                         "flow validate {port_id}"
1024                         " [group {group_id}] [priority {level}]"
1025                         " [ingress] [egress]"
1026                         " pattern {item} [/ {item} [...]] / end"
1027                         " actions {action} [/ {action} [...]] / end\n"
1028                         "    Check whether a flow rule can be created.\n\n"
1029
1030                         "flow create {port_id}"
1031                         " [group {group_id}] [priority {level}]"
1032                         " [ingress] [egress]"
1033                         " pattern {item} [/ {item} [...]] / end"
1034                         " actions {action} [/ {action} [...]] / end\n"
1035                         "    Create a flow rule.\n\n"
1036
1037                         "flow destroy {port_id} rule {rule_id} [...]\n"
1038                         "    Destroy specific flow rules.\n\n"
1039
1040                         "flow flush {port_id}\n"
1041                         "    Destroy all flow rules.\n\n"
1042
1043                         "flow query {port_id} {rule_id} {action}\n"
1044                         "    Query an existing flow rule.\n\n"
1045
1046                         "flow list {port_id} [group {group_id}] [...]\n"
1047                         "    List existing flow rules sorted by priority,"
1048                         " filtered by group identifiers.\n\n"
1049
1050                         "flow isolate {port_id} {boolean}\n"
1051                         "    Restrict ingress traffic to the defined"
1052                         " flow rules\n\n"
1053                 );
1054         }
1055 }
1056
1057 cmdline_parse_token_string_t cmd_help_long_help =
1058         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1059
1060 cmdline_parse_token_string_t cmd_help_long_section =
1061         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1062                         "all#control#display#config#"
1063                         "ports#registers#filters");
1064
1065 cmdline_parse_inst_t cmd_help_long = {
1066         .f = cmd_help_long_parsed,
1067         .data = NULL,
1068         .help_str = "help all|control|display|config|ports|register|filters: "
1069                 "Show help",
1070         .tokens = {
1071                 (void *)&cmd_help_long_help,
1072                 (void *)&cmd_help_long_section,
1073                 NULL,
1074         },
1075 };
1076
1077
1078 /* *** start/stop/close all ports *** */
1079 struct cmd_operate_port_result {
1080         cmdline_fixed_string_t keyword;
1081         cmdline_fixed_string_t name;
1082         cmdline_fixed_string_t value;
1083 };
1084
1085 static void cmd_operate_port_parsed(void *parsed_result,
1086                                 __attribute__((unused)) struct cmdline *cl,
1087                                 __attribute__((unused)) void *data)
1088 {
1089         struct cmd_operate_port_result *res = parsed_result;
1090
1091         if (!strcmp(res->name, "start"))
1092                 start_port(RTE_PORT_ALL);
1093         else if (!strcmp(res->name, "stop"))
1094                 stop_port(RTE_PORT_ALL);
1095         else if (!strcmp(res->name, "close"))
1096                 close_port(RTE_PORT_ALL);
1097         else if (!strcmp(res->name, "reset"))
1098                 reset_port(RTE_PORT_ALL);
1099         else
1100                 printf("Unknown parameter\n");
1101 }
1102
1103 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1104         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1105                                                                 "port");
1106 cmdline_parse_token_string_t cmd_operate_port_all_port =
1107         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1108                                                 "start#stop#close#reset");
1109 cmdline_parse_token_string_t cmd_operate_port_all_all =
1110         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1111
1112 cmdline_parse_inst_t cmd_operate_port = {
1113         .f = cmd_operate_port_parsed,
1114         .data = NULL,
1115         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1116         .tokens = {
1117                 (void *)&cmd_operate_port_all_cmd,
1118                 (void *)&cmd_operate_port_all_port,
1119                 (void *)&cmd_operate_port_all_all,
1120                 NULL,
1121         },
1122 };
1123
1124 /* *** start/stop/close specific port *** */
1125 struct cmd_operate_specific_port_result {
1126         cmdline_fixed_string_t keyword;
1127         cmdline_fixed_string_t name;
1128         uint8_t value;
1129 };
1130
1131 static void cmd_operate_specific_port_parsed(void *parsed_result,
1132                         __attribute__((unused)) struct cmdline *cl,
1133                                 __attribute__((unused)) void *data)
1134 {
1135         struct cmd_operate_specific_port_result *res = parsed_result;
1136
1137         if (!strcmp(res->name, "start"))
1138                 start_port(res->value);
1139         else if (!strcmp(res->name, "stop"))
1140                 stop_port(res->value);
1141         else if (!strcmp(res->name, "close"))
1142                 close_port(res->value);
1143         else if (!strcmp(res->name, "reset"))
1144                 reset_port(res->value);
1145         else
1146                 printf("Unknown parameter\n");
1147 }
1148
1149 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1151                                                         keyword, "port");
1152 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1154                                                 name, "start#stop#close#reset");
1155 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1156         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1157                                                         value, UINT8);
1158
1159 cmdline_parse_inst_t cmd_operate_specific_port = {
1160         .f = cmd_operate_specific_port_parsed,
1161         .data = NULL,
1162         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1163         .tokens = {
1164                 (void *)&cmd_operate_specific_port_cmd,
1165                 (void *)&cmd_operate_specific_port_port,
1166                 (void *)&cmd_operate_specific_port_id,
1167                 NULL,
1168         },
1169 };
1170
1171 /* *** attach a specified port *** */
1172 struct cmd_operate_attach_port_result {
1173         cmdline_fixed_string_t port;
1174         cmdline_fixed_string_t keyword;
1175         cmdline_fixed_string_t identifier;
1176 };
1177
1178 static void cmd_operate_attach_port_parsed(void *parsed_result,
1179                                 __attribute__((unused)) struct cmdline *cl,
1180                                 __attribute__((unused)) void *data)
1181 {
1182         struct cmd_operate_attach_port_result *res = parsed_result;
1183
1184         if (!strcmp(res->keyword, "attach"))
1185                 attach_port(res->identifier);
1186         else
1187                 printf("Unknown parameter\n");
1188 }
1189
1190 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1191         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1192                         port, "port");
1193 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1194         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1195                         keyword, "attach");
1196 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1197         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1198                         identifier, NULL);
1199
1200 cmdline_parse_inst_t cmd_operate_attach_port = {
1201         .f = cmd_operate_attach_port_parsed,
1202         .data = NULL,
1203         .help_str = "port attach <identifier>: "
1204                 "(identifier: pci address or virtual dev name)",
1205         .tokens = {
1206                 (void *)&cmd_operate_attach_port_port,
1207                 (void *)&cmd_operate_attach_port_keyword,
1208                 (void *)&cmd_operate_attach_port_identifier,
1209                 NULL,
1210         },
1211 };
1212
1213 /* *** detach a specified port *** */
1214 struct cmd_operate_detach_port_result {
1215         cmdline_fixed_string_t port;
1216         cmdline_fixed_string_t keyword;
1217         portid_t port_id;
1218 };
1219
1220 static void cmd_operate_detach_port_parsed(void *parsed_result,
1221                                 __attribute__((unused)) struct cmdline *cl,
1222                                 __attribute__((unused)) void *data)
1223 {
1224         struct cmd_operate_detach_port_result *res = parsed_result;
1225
1226         if (!strcmp(res->keyword, "detach"))
1227                 detach_port(res->port_id);
1228         else
1229                 printf("Unknown parameter\n");
1230 }
1231
1232 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1233         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1234                         port, "port");
1235 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1236         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1237                         keyword, "detach");
1238 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1239         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1240                         port_id, UINT16);
1241
1242 cmdline_parse_inst_t cmd_operate_detach_port = {
1243         .f = cmd_operate_detach_port_parsed,
1244         .data = NULL,
1245         .help_str = "port detach <port_id>",
1246         .tokens = {
1247                 (void *)&cmd_operate_detach_port_port,
1248                 (void *)&cmd_operate_detach_port_keyword,
1249                 (void *)&cmd_operate_detach_port_port_id,
1250                 NULL,
1251         },
1252 };
1253
1254 /* *** configure speed for all ports *** */
1255 struct cmd_config_speed_all {
1256         cmdline_fixed_string_t port;
1257         cmdline_fixed_string_t keyword;
1258         cmdline_fixed_string_t all;
1259         cmdline_fixed_string_t item1;
1260         cmdline_fixed_string_t item2;
1261         cmdline_fixed_string_t value1;
1262         cmdline_fixed_string_t value2;
1263 };
1264
1265 static int
1266 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1267 {
1268
1269         int duplex;
1270
1271         if (!strcmp(duplexstr, "half")) {
1272                 duplex = ETH_LINK_HALF_DUPLEX;
1273         } else if (!strcmp(duplexstr, "full")) {
1274                 duplex = ETH_LINK_FULL_DUPLEX;
1275         } else if (!strcmp(duplexstr, "auto")) {
1276                 duplex = ETH_LINK_FULL_DUPLEX;
1277         } else {
1278                 printf("Unknown duplex parameter\n");
1279                 return -1;
1280         }
1281
1282         if (!strcmp(speedstr, "10")) {
1283                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1284                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1285         } else if (!strcmp(speedstr, "100")) {
1286                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1287                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1288         } else {
1289                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1290                         printf("Invalid speed/duplex parameters\n");
1291                         return -1;
1292                 }
1293                 if (!strcmp(speedstr, "1000")) {
1294                         *speed = ETH_LINK_SPEED_1G;
1295                 } else if (!strcmp(speedstr, "10000")) {
1296                         *speed = ETH_LINK_SPEED_10G;
1297                 } else if (!strcmp(speedstr, "25000")) {
1298                         *speed = ETH_LINK_SPEED_25G;
1299                 } else if (!strcmp(speedstr, "40000")) {
1300                         *speed = ETH_LINK_SPEED_40G;
1301                 } else if (!strcmp(speedstr, "50000")) {
1302                         *speed = ETH_LINK_SPEED_50G;
1303                 } else if (!strcmp(speedstr, "100000")) {
1304                         *speed = ETH_LINK_SPEED_100G;
1305                 } else if (!strcmp(speedstr, "auto")) {
1306                         *speed = ETH_LINK_SPEED_AUTONEG;
1307                 } else {
1308                         printf("Unknown speed parameter\n");
1309                         return -1;
1310                 }
1311         }
1312
1313         return 0;
1314 }
1315
1316 static void
1317 cmd_config_speed_all_parsed(void *parsed_result,
1318                         __attribute__((unused)) struct cmdline *cl,
1319                         __attribute__((unused)) void *data)
1320 {
1321         struct cmd_config_speed_all *res = parsed_result;
1322         uint32_t link_speed;
1323         portid_t pid;
1324
1325         if (!all_ports_stopped()) {
1326                 printf("Please stop all ports first\n");
1327                 return;
1328         }
1329
1330         if (parse_and_check_speed_duplex(res->value1, res->value2,
1331                         &link_speed) < 0)
1332                 return;
1333
1334         RTE_ETH_FOREACH_DEV(pid) {
1335                 ports[pid].dev_conf.link_speeds = link_speed;
1336         }
1337
1338         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1339 }
1340
1341 cmdline_parse_token_string_t cmd_config_speed_all_port =
1342         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1343 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1344         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1345                                                         "config");
1346 cmdline_parse_token_string_t cmd_config_speed_all_all =
1347         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1348 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1349         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1350 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1351         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1352                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1353 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1354         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1355 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1356         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1357                                                 "half#full#auto");
1358
1359 cmdline_parse_inst_t cmd_config_speed_all = {
1360         .f = cmd_config_speed_all_parsed,
1361         .data = NULL,
1362         .help_str = "port config all speed "
1363                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1364                                                         "half|full|auto",
1365         .tokens = {
1366                 (void *)&cmd_config_speed_all_port,
1367                 (void *)&cmd_config_speed_all_keyword,
1368                 (void *)&cmd_config_speed_all_all,
1369                 (void *)&cmd_config_speed_all_item1,
1370                 (void *)&cmd_config_speed_all_value1,
1371                 (void *)&cmd_config_speed_all_item2,
1372                 (void *)&cmd_config_speed_all_value2,
1373                 NULL,
1374         },
1375 };
1376
1377 /* *** configure speed for specific port *** */
1378 struct cmd_config_speed_specific {
1379         cmdline_fixed_string_t port;
1380         cmdline_fixed_string_t keyword;
1381         uint8_t id;
1382         cmdline_fixed_string_t item1;
1383         cmdline_fixed_string_t item2;
1384         cmdline_fixed_string_t value1;
1385         cmdline_fixed_string_t value2;
1386 };
1387
1388 static void
1389 cmd_config_speed_specific_parsed(void *parsed_result,
1390                                 __attribute__((unused)) struct cmdline *cl,
1391                                 __attribute__((unused)) void *data)
1392 {
1393         struct cmd_config_speed_specific *res = parsed_result;
1394         uint32_t link_speed;
1395
1396         if (!all_ports_stopped()) {
1397                 printf("Please stop all ports first\n");
1398                 return;
1399         }
1400
1401         if (port_id_is_invalid(res->id, ENABLED_WARN))
1402                 return;
1403
1404         if (parse_and_check_speed_duplex(res->value1, res->value2,
1405                         &link_speed) < 0)
1406                 return;
1407
1408         ports[res->id].dev_conf.link_speeds = link_speed;
1409
1410         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1411 }
1412
1413
1414 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1415         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1416                                                                 "port");
1417 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1418         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1419                                                                 "config");
1420 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1421         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1422 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1423         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1424                                                                 "speed");
1425 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1426         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1427                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1428 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1429         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1430                                                                 "duplex");
1431 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1432         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1433                                                         "half#full#auto");
1434
1435 cmdline_parse_inst_t cmd_config_speed_specific = {
1436         .f = cmd_config_speed_specific_parsed,
1437         .data = NULL,
1438         .help_str = "port config <port_id> speed "
1439                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1440                                                         "half|full|auto",
1441         .tokens = {
1442                 (void *)&cmd_config_speed_specific_port,
1443                 (void *)&cmd_config_speed_specific_keyword,
1444                 (void *)&cmd_config_speed_specific_id,
1445                 (void *)&cmd_config_speed_specific_item1,
1446                 (void *)&cmd_config_speed_specific_value1,
1447                 (void *)&cmd_config_speed_specific_item2,
1448                 (void *)&cmd_config_speed_specific_value2,
1449                 NULL,
1450         },
1451 };
1452
1453 /* *** configure txq/rxq, txd/rxd *** */
1454 struct cmd_config_rx_tx {
1455         cmdline_fixed_string_t port;
1456         cmdline_fixed_string_t keyword;
1457         cmdline_fixed_string_t all;
1458         cmdline_fixed_string_t name;
1459         uint16_t value;
1460 };
1461
1462 static void
1463 cmd_config_rx_tx_parsed(void *parsed_result,
1464                         __attribute__((unused)) struct cmdline *cl,
1465                         __attribute__((unused)) void *data)
1466 {
1467         struct cmd_config_rx_tx *res = parsed_result;
1468
1469         if (!all_ports_stopped()) {
1470                 printf("Please stop all ports first\n");
1471                 return;
1472         }
1473         if (!strcmp(res->name, "rxq")) {
1474                 if (!res->value && !nb_txq) {
1475                         printf("Warning: Either rx or tx queues should be non zero\n");
1476                         return;
1477                 }
1478                 nb_rxq = res->value;
1479         }
1480         else if (!strcmp(res->name, "txq")) {
1481                 if (!res->value && !nb_rxq) {
1482                         printf("Warning: Either rx or tx queues should be non zero\n");
1483                         return;
1484                 }
1485                 nb_txq = res->value;
1486         }
1487         else if (!strcmp(res->name, "rxd")) {
1488                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1489                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1490                                         res->value, RTE_TEST_RX_DESC_MAX);
1491                         return;
1492                 }
1493                 nb_rxd = res->value;
1494         } else if (!strcmp(res->name, "txd")) {
1495                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1496                         printf("txd %d invalid - must be > 0 && <= %d\n",
1497                                         res->value, RTE_TEST_TX_DESC_MAX);
1498                         return;
1499                 }
1500                 nb_txd = res->value;
1501         } else {
1502                 printf("Unknown parameter\n");
1503                 return;
1504         }
1505
1506         fwd_config_setup();
1507
1508         init_port_config();
1509
1510         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1511 }
1512
1513 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1514         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1515 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1516         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1517 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1518         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1519 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1520         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1521                                                 "rxq#txq#rxd#txd");
1522 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1523         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1524
1525 cmdline_parse_inst_t cmd_config_rx_tx = {
1526         .f = cmd_config_rx_tx_parsed,
1527         .data = NULL,
1528         .help_str = "port config all rxq|txq|rxd|txd <value>",
1529         .tokens = {
1530                 (void *)&cmd_config_rx_tx_port,
1531                 (void *)&cmd_config_rx_tx_keyword,
1532                 (void *)&cmd_config_rx_tx_all,
1533                 (void *)&cmd_config_rx_tx_name,
1534                 (void *)&cmd_config_rx_tx_value,
1535                 NULL,
1536         },
1537 };
1538
1539 /* *** config max packet length *** */
1540 struct cmd_config_max_pkt_len_result {
1541         cmdline_fixed_string_t port;
1542         cmdline_fixed_string_t keyword;
1543         cmdline_fixed_string_t all;
1544         cmdline_fixed_string_t name;
1545         uint32_t value;
1546 };
1547
1548 static void
1549 cmd_config_max_pkt_len_parsed(void *parsed_result,
1550                                 __attribute__((unused)) struct cmdline *cl,
1551                                 __attribute__((unused)) void *data)
1552 {
1553         struct cmd_config_max_pkt_len_result *res = parsed_result;
1554
1555         if (!all_ports_stopped()) {
1556                 printf("Please stop all ports first\n");
1557                 return;
1558         }
1559
1560         if (!strcmp(res->name, "max-pkt-len")) {
1561                 if (res->value < ETHER_MIN_LEN) {
1562                         printf("max-pkt-len can not be less than %d\n",
1563                                                         ETHER_MIN_LEN);
1564                         return;
1565                 }
1566                 if (res->value == rx_mode.max_rx_pkt_len)
1567                         return;
1568
1569                 rx_mode.max_rx_pkt_len = res->value;
1570                 if (res->value > ETHER_MAX_LEN)
1571                         rx_mode.jumbo_frame = 1;
1572                 else
1573                         rx_mode.jumbo_frame = 0;
1574         } else {
1575                 printf("Unknown parameter\n");
1576                 return;
1577         }
1578
1579         init_port_config();
1580
1581         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1582 }
1583
1584 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1585         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1586                                                                 "port");
1587 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1588         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1589                                                                 "config");
1590 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1592                                                                 "all");
1593 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1594         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1595                                                                 "max-pkt-len");
1596 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1597         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1598                                                                 UINT32);
1599
1600 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1601         .f = cmd_config_max_pkt_len_parsed,
1602         .data = NULL,
1603         .help_str = "port config all max-pkt-len <value>",
1604         .tokens = {
1605                 (void *)&cmd_config_max_pkt_len_port,
1606                 (void *)&cmd_config_max_pkt_len_keyword,
1607                 (void *)&cmd_config_max_pkt_len_all,
1608                 (void *)&cmd_config_max_pkt_len_name,
1609                 (void *)&cmd_config_max_pkt_len_value,
1610                 NULL,
1611         },
1612 };
1613
1614 /* *** configure port MTU *** */
1615 struct cmd_config_mtu_result {
1616         cmdline_fixed_string_t port;
1617         cmdline_fixed_string_t keyword;
1618         cmdline_fixed_string_t mtu;
1619         portid_t port_id;
1620         uint16_t value;
1621 };
1622
1623 static void
1624 cmd_config_mtu_parsed(void *parsed_result,
1625                       __attribute__((unused)) struct cmdline *cl,
1626                       __attribute__((unused)) void *data)
1627 {
1628         struct cmd_config_mtu_result *res = parsed_result;
1629
1630         if (res->value < ETHER_MIN_LEN) {
1631                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1632                 return;
1633         }
1634         port_mtu_set(res->port_id, res->value);
1635 }
1636
1637 cmdline_parse_token_string_t cmd_config_mtu_port =
1638         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1639                                  "port");
1640 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1642                                  "config");
1643 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1645                                  "mtu");
1646 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1647         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1648 cmdline_parse_token_num_t cmd_config_mtu_value =
1649         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1650
1651 cmdline_parse_inst_t cmd_config_mtu = {
1652         .f = cmd_config_mtu_parsed,
1653         .data = NULL,
1654         .help_str = "port config mtu <port_id> <value>",
1655         .tokens = {
1656                 (void *)&cmd_config_mtu_port,
1657                 (void *)&cmd_config_mtu_keyword,
1658                 (void *)&cmd_config_mtu_mtu,
1659                 (void *)&cmd_config_mtu_port_id,
1660                 (void *)&cmd_config_mtu_value,
1661                 NULL,
1662         },
1663 };
1664
1665 /* *** configure rx mode *** */
1666 struct cmd_config_rx_mode_flag {
1667         cmdline_fixed_string_t port;
1668         cmdline_fixed_string_t keyword;
1669         cmdline_fixed_string_t all;
1670         cmdline_fixed_string_t name;
1671         cmdline_fixed_string_t value;
1672 };
1673
1674 static void
1675 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1676                                 __attribute__((unused)) struct cmdline *cl,
1677                                 __attribute__((unused)) void *data)
1678 {
1679         struct cmd_config_rx_mode_flag *res = parsed_result;
1680
1681         if (!all_ports_stopped()) {
1682                 printf("Please stop all ports first\n");
1683                 return;
1684         }
1685
1686         if (!strcmp(res->name, "crc-strip")) {
1687                 if (!strcmp(res->value, "on"))
1688                         rx_mode.hw_strip_crc = 1;
1689                 else if (!strcmp(res->value, "off"))
1690                         rx_mode.hw_strip_crc = 0;
1691                 else {
1692                         printf("Unknown parameter\n");
1693                         return;
1694                 }
1695         } else if (!strcmp(res->name, "scatter")) {
1696                 if (!strcmp(res->value, "on"))
1697                         rx_mode.enable_scatter = 1;
1698                 else if (!strcmp(res->value, "off"))
1699                         rx_mode.enable_scatter = 0;
1700                 else {
1701                         printf("Unknown parameter\n");
1702                         return;
1703                 }
1704         } else if (!strcmp(res->name, "rx-cksum")) {
1705                 if (!strcmp(res->value, "on"))
1706                         rx_mode.hw_ip_checksum = 1;
1707                 else if (!strcmp(res->value, "off"))
1708                         rx_mode.hw_ip_checksum = 0;
1709                 else {
1710                         printf("Unknown parameter\n");
1711                         return;
1712                 }
1713         } else if (!strcmp(res->name, "rx-timestamp")) {
1714                 if (!strcmp(res->value, "on"))
1715                         rx_mode.hw_timestamp = 1;
1716                 else if (!strcmp(res->value, "off"))
1717                         rx_mode.hw_timestamp = 0;
1718                 else {
1719                         printf("Unknown parameter\n");
1720                         return;
1721                 }
1722         } else if (!strcmp(res->name, "hw-vlan")) {
1723                 if (!strcmp(res->value, "on")) {
1724                         rx_mode.hw_vlan_filter = 1;
1725                         rx_mode.hw_vlan_strip  = 1;
1726                 }
1727                 else if (!strcmp(res->value, "off")) {
1728                         rx_mode.hw_vlan_filter = 0;
1729                         rx_mode.hw_vlan_strip  = 0;
1730                 }
1731                 else {
1732                         printf("Unknown parameter\n");
1733                         return;
1734                 }
1735         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1736                 if (!strcmp(res->value, "on"))
1737                         rx_mode.hw_vlan_filter = 1;
1738                 else if (!strcmp(res->value, "off"))
1739                         rx_mode.hw_vlan_filter = 0;
1740                 else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1745                 if (!strcmp(res->value, "on"))
1746                         rx_mode.hw_vlan_strip  = 1;
1747                 else if (!strcmp(res->value, "off"))
1748                         rx_mode.hw_vlan_strip  = 0;
1749                 else {
1750                         printf("Unknown parameter\n");
1751                         return;
1752                 }
1753         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1754                 if (!strcmp(res->value, "on"))
1755                         rx_mode.hw_vlan_extend = 1;
1756                 else if (!strcmp(res->value, "off"))
1757                         rx_mode.hw_vlan_extend = 0;
1758                 else {
1759                         printf("Unknown parameter\n");
1760                         return;
1761                 }
1762         } else if (!strcmp(res->name, "drop-en")) {
1763                 if (!strcmp(res->value, "on"))
1764                         rx_drop_en = 1;
1765                 else if (!strcmp(res->value, "off"))
1766                         rx_drop_en = 0;
1767                 else {
1768                         printf("Unknown parameter\n");
1769                         return;
1770                 }
1771         } else {
1772                 printf("Unknown parameter\n");
1773                 return;
1774         }
1775
1776         init_port_config();
1777
1778         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1779 }
1780
1781 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1783 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1784         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1785                                                                 "config");
1786 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1788 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1790                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1791                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1792 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1794                                                         "on#off");
1795
1796 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1797         .f = cmd_config_rx_mode_flag_parsed,
1798         .data = NULL,
1799         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1800                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1801         .tokens = {
1802                 (void *)&cmd_config_rx_mode_flag_port,
1803                 (void *)&cmd_config_rx_mode_flag_keyword,
1804                 (void *)&cmd_config_rx_mode_flag_all,
1805                 (void *)&cmd_config_rx_mode_flag_name,
1806                 (void *)&cmd_config_rx_mode_flag_value,
1807                 NULL,
1808         },
1809 };
1810
1811 /* *** configure rss *** */
1812 struct cmd_config_rss {
1813         cmdline_fixed_string_t port;
1814         cmdline_fixed_string_t keyword;
1815         cmdline_fixed_string_t all;
1816         cmdline_fixed_string_t name;
1817         cmdline_fixed_string_t value;
1818 };
1819
1820 static void
1821 cmd_config_rss_parsed(void *parsed_result,
1822                         __attribute__((unused)) struct cmdline *cl,
1823                         __attribute__((unused)) void *data)
1824 {
1825         struct cmd_config_rss *res = parsed_result;
1826         struct rte_eth_rss_conf rss_conf;
1827         int diag;
1828         uint8_t i;
1829
1830         if (!strcmp(res->value, "all"))
1831                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1832                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1833                                         ETH_RSS_L2_PAYLOAD;
1834         else if (!strcmp(res->value, "ip"))
1835                 rss_conf.rss_hf = ETH_RSS_IP;
1836         else if (!strcmp(res->value, "udp"))
1837                 rss_conf.rss_hf = ETH_RSS_UDP;
1838         else if (!strcmp(res->value, "tcp"))
1839                 rss_conf.rss_hf = ETH_RSS_TCP;
1840         else if (!strcmp(res->value, "sctp"))
1841                 rss_conf.rss_hf = ETH_RSS_SCTP;
1842         else if (!strcmp(res->value, "ether"))
1843                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1844         else if (!strcmp(res->value, "port"))
1845                 rss_conf.rss_hf = ETH_RSS_PORT;
1846         else if (!strcmp(res->value, "vxlan"))
1847                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1848         else if (!strcmp(res->value, "geneve"))
1849                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1850         else if (!strcmp(res->value, "nvgre"))
1851                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1852         else if (!strcmp(res->value, "none"))
1853                 rss_conf.rss_hf = 0;
1854         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1855                                                 atoi(res->value) < 64)
1856                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1857         else {
1858                 printf("Unknown parameter\n");
1859                 return;
1860         }
1861         rss_conf.rss_key = NULL;
1862         for (i = 0; i < rte_eth_dev_count(); i++) {
1863                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1864                 if (diag < 0)
1865                         printf("Configuration of RSS hash at ethernet port %d "
1866                                 "failed with error (%d): %s.\n",
1867                                 i, -diag, strerror(-diag));
1868         }
1869 }
1870
1871 cmdline_parse_token_string_t cmd_config_rss_port =
1872         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1873 cmdline_parse_token_string_t cmd_config_rss_keyword =
1874         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1875 cmdline_parse_token_string_t cmd_config_rss_all =
1876         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1877 cmdline_parse_token_string_t cmd_config_rss_name =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1879 cmdline_parse_token_string_t cmd_config_rss_value =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1881
1882 cmdline_parse_inst_t cmd_config_rss = {
1883         .f = cmd_config_rss_parsed,
1884         .data = NULL,
1885         .help_str = "port config all rss "
1886                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1887         .tokens = {
1888                 (void *)&cmd_config_rss_port,
1889                 (void *)&cmd_config_rss_keyword,
1890                 (void *)&cmd_config_rss_all,
1891                 (void *)&cmd_config_rss_name,
1892                 (void *)&cmd_config_rss_value,
1893                 NULL,
1894         },
1895 };
1896
1897 /* *** configure rss hash key *** */
1898 struct cmd_config_rss_hash_key {
1899         cmdline_fixed_string_t port;
1900         cmdline_fixed_string_t config;
1901         portid_t port_id;
1902         cmdline_fixed_string_t rss_hash_key;
1903         cmdline_fixed_string_t rss_type;
1904         cmdline_fixed_string_t key;
1905 };
1906
1907 static uint8_t
1908 hexa_digit_to_value(char hexa_digit)
1909 {
1910         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1911                 return (uint8_t) (hexa_digit - '0');
1912         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1913                 return (uint8_t) ((hexa_digit - 'a') + 10);
1914         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1915                 return (uint8_t) ((hexa_digit - 'A') + 10);
1916         /* Invalid hexa digit */
1917         return 0xFF;
1918 }
1919
1920 static uint8_t
1921 parse_and_check_key_hexa_digit(char *key, int idx)
1922 {
1923         uint8_t hexa_v;
1924
1925         hexa_v = hexa_digit_to_value(key[idx]);
1926         if (hexa_v == 0xFF)
1927                 printf("invalid key: character %c at position %d is not a "
1928                        "valid hexa digit\n", key[idx], idx);
1929         return hexa_v;
1930 }
1931
1932 static void
1933 cmd_config_rss_hash_key_parsed(void *parsed_result,
1934                                __attribute__((unused)) struct cmdline *cl,
1935                                __attribute__((unused)) void *data)
1936 {
1937         struct cmd_config_rss_hash_key *res = parsed_result;
1938         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1939         uint8_t xdgt0;
1940         uint8_t xdgt1;
1941         int i;
1942         struct rte_eth_dev_info dev_info;
1943         uint8_t hash_key_size;
1944         uint32_t key_len;
1945
1946         memset(&dev_info, 0, sizeof(dev_info));
1947         rte_eth_dev_info_get(res->port_id, &dev_info);
1948         if (dev_info.hash_key_size > 0 &&
1949                         dev_info.hash_key_size <= sizeof(hash_key))
1950                 hash_key_size = dev_info.hash_key_size;
1951         else {
1952                 printf("dev_info did not provide a valid hash key size\n");
1953                 return;
1954         }
1955         /* Check the length of the RSS hash key */
1956         key_len = strlen(res->key);
1957         if (key_len != (hash_key_size * 2)) {
1958                 printf("key length: %d invalid - key must be a string of %d"
1959                            " hexa-decimal numbers\n",
1960                            (int) key_len, hash_key_size * 2);
1961                 return;
1962         }
1963         /* Translate RSS hash key into binary representation */
1964         for (i = 0; i < hash_key_size; i++) {
1965                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1966                 if (xdgt0 == 0xFF)
1967                         return;
1968                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1969                 if (xdgt1 == 0xFF)
1970                         return;
1971                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1972         }
1973         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1974                         hash_key_size);
1975 }
1976
1977 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1978         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1979 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1980         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1981                                  "config");
1982 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1983         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
1984 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1985         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1986                                  rss_hash_key, "rss-hash-key");
1987 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1988         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1989                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1990                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1991                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1992                                  "ipv6-tcp-ex#ipv6-udp-ex");
1993 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1994         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1995
1996 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1997         .f = cmd_config_rss_hash_key_parsed,
1998         .data = NULL,
1999         .help_str = "port config <port_id> rss-hash-key "
2000                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2001                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2002                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2003                 "<string of hex digits (variable length, NIC dependent)>",
2004         .tokens = {
2005                 (void *)&cmd_config_rss_hash_key_port,
2006                 (void *)&cmd_config_rss_hash_key_config,
2007                 (void *)&cmd_config_rss_hash_key_port_id,
2008                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2009                 (void *)&cmd_config_rss_hash_key_rss_type,
2010                 (void *)&cmd_config_rss_hash_key_value,
2011                 NULL,
2012         },
2013 };
2014
2015 /* *** configure port rxq/txq start/stop *** */
2016 struct cmd_config_rxtx_queue {
2017         cmdline_fixed_string_t port;
2018         portid_t portid;
2019         cmdline_fixed_string_t rxtxq;
2020         uint16_t qid;
2021         cmdline_fixed_string_t opname;
2022 };
2023
2024 static void
2025 cmd_config_rxtx_queue_parsed(void *parsed_result,
2026                         __attribute__((unused)) struct cmdline *cl,
2027                         __attribute__((unused)) void *data)
2028 {
2029         struct cmd_config_rxtx_queue *res = parsed_result;
2030         uint8_t isrx;
2031         uint8_t isstart;
2032         int ret = 0;
2033
2034         if (test_done == 0) {
2035                 printf("Please stop forwarding first\n");
2036                 return;
2037         }
2038
2039         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2040                 return;
2041
2042         if (port_is_started(res->portid) != 1) {
2043                 printf("Please start port %u first\n", res->portid);
2044                 return;
2045         }
2046
2047         if (!strcmp(res->rxtxq, "rxq"))
2048                 isrx = 1;
2049         else if (!strcmp(res->rxtxq, "txq"))
2050                 isrx = 0;
2051         else {
2052                 printf("Unknown parameter\n");
2053                 return;
2054         }
2055
2056         if (isrx && rx_queue_id_is_invalid(res->qid))
2057                 return;
2058         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2059                 return;
2060
2061         if (!strcmp(res->opname, "start"))
2062                 isstart = 1;
2063         else if (!strcmp(res->opname, "stop"))
2064                 isstart = 0;
2065         else {
2066                 printf("Unknown parameter\n");
2067                 return;
2068         }
2069
2070         if (isstart && isrx)
2071                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2072         else if (!isstart && isrx)
2073                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2074         else if (isstart && !isrx)
2075                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2076         else
2077                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2078
2079         if (ret == -ENOTSUP)
2080                 printf("Function not supported in PMD driver\n");
2081 }
2082
2083 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2084         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2085 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2086         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2087 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2088         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2089 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2090         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2091 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2092         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2093                                                 "start#stop");
2094
2095 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2096         .f = cmd_config_rxtx_queue_parsed,
2097         .data = NULL,
2098         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2099         .tokens = {
2100                 (void *)&cmd_config_speed_all_port,
2101                 (void *)&cmd_config_rxtx_queue_portid,
2102                 (void *)&cmd_config_rxtx_queue_rxtxq,
2103                 (void *)&cmd_config_rxtx_queue_qid,
2104                 (void *)&cmd_config_rxtx_queue_opname,
2105                 NULL,
2106         },
2107 };
2108
2109 /* *** Configure RSS RETA *** */
2110 struct cmd_config_rss_reta {
2111         cmdline_fixed_string_t port;
2112         cmdline_fixed_string_t keyword;
2113         portid_t port_id;
2114         cmdline_fixed_string_t name;
2115         cmdline_fixed_string_t list_name;
2116         cmdline_fixed_string_t list_of_items;
2117 };
2118
2119 static int
2120 parse_reta_config(const char *str,
2121                   struct rte_eth_rss_reta_entry64 *reta_conf,
2122                   uint16_t nb_entries)
2123 {
2124         int i;
2125         unsigned size;
2126         uint16_t hash_index, idx, shift;
2127         uint16_t nb_queue;
2128         char s[256];
2129         const char *p, *p0 = str;
2130         char *end;
2131         enum fieldnames {
2132                 FLD_HASH_INDEX = 0,
2133                 FLD_QUEUE,
2134                 _NUM_FLD
2135         };
2136         unsigned long int_fld[_NUM_FLD];
2137         char *str_fld[_NUM_FLD];
2138
2139         while ((p = strchr(p0,'(')) != NULL) {
2140                 ++p;
2141                 if((p0 = strchr(p,')')) == NULL)
2142                         return -1;
2143
2144                 size = p0 - p;
2145                 if(size >= sizeof(s))
2146                         return -1;
2147
2148                 snprintf(s, sizeof(s), "%.*s", size, p);
2149                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2150                         return -1;
2151                 for (i = 0; i < _NUM_FLD; i++) {
2152                         errno = 0;
2153                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2154                         if (errno != 0 || end == str_fld[i] ||
2155                                         int_fld[i] > 65535)
2156                                 return -1;
2157                 }
2158
2159                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2160                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2161
2162                 if (hash_index >= nb_entries) {
2163                         printf("Invalid RETA hash index=%d\n", hash_index);
2164                         return -1;
2165                 }
2166
2167                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2168                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2169                 reta_conf[idx].mask |= (1ULL << shift);
2170                 reta_conf[idx].reta[shift] = nb_queue;
2171         }
2172
2173         return 0;
2174 }
2175
2176 static void
2177 cmd_set_rss_reta_parsed(void *parsed_result,
2178                         __attribute__((unused)) struct cmdline *cl,
2179                         __attribute__((unused)) void *data)
2180 {
2181         int ret;
2182         struct rte_eth_dev_info dev_info;
2183         struct rte_eth_rss_reta_entry64 reta_conf[8];
2184         struct cmd_config_rss_reta *res = parsed_result;
2185
2186         memset(&dev_info, 0, sizeof(dev_info));
2187         rte_eth_dev_info_get(res->port_id, &dev_info);
2188         if (dev_info.reta_size == 0) {
2189                 printf("Redirection table size is 0 which is "
2190                                         "invalid for RSS\n");
2191                 return;
2192         } else
2193                 printf("The reta size of port %d is %u\n",
2194                         res->port_id, dev_info.reta_size);
2195         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2196                 printf("Currently do not support more than %u entries of "
2197                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2198                 return;
2199         }
2200
2201         memset(reta_conf, 0, sizeof(reta_conf));
2202         if (!strcmp(res->list_name, "reta")) {
2203                 if (parse_reta_config(res->list_of_items, reta_conf,
2204                                                 dev_info.reta_size)) {
2205                         printf("Invalid RSS Redirection Table "
2206                                         "config entered\n");
2207                         return;
2208                 }
2209                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2210                                 reta_conf, dev_info.reta_size);
2211                 if (ret != 0)
2212                         printf("Bad redirection table parameter, "
2213                                         "return code = %d \n", ret);
2214         }
2215 }
2216
2217 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2218         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2219 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2220         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2221 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2222         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2223 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2225 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2226         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2227 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2229                                  NULL);
2230 cmdline_parse_inst_t cmd_config_rss_reta = {
2231         .f = cmd_set_rss_reta_parsed,
2232         .data = NULL,
2233         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2234         .tokens = {
2235                 (void *)&cmd_config_rss_reta_port,
2236                 (void *)&cmd_config_rss_reta_keyword,
2237                 (void *)&cmd_config_rss_reta_port_id,
2238                 (void *)&cmd_config_rss_reta_name,
2239                 (void *)&cmd_config_rss_reta_list_name,
2240                 (void *)&cmd_config_rss_reta_list_of_items,
2241                 NULL,
2242         },
2243 };
2244
2245 /* *** SHOW PORT RETA INFO *** */
2246 struct cmd_showport_reta {
2247         cmdline_fixed_string_t show;
2248         cmdline_fixed_string_t port;
2249         portid_t port_id;
2250         cmdline_fixed_string_t rss;
2251         cmdline_fixed_string_t reta;
2252         uint16_t size;
2253         cmdline_fixed_string_t list_of_items;
2254 };
2255
2256 static int
2257 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2258                            uint16_t nb_entries,
2259                            char *str)
2260 {
2261         uint32_t size;
2262         const char *p, *p0 = str;
2263         char s[256];
2264         char *end;
2265         char *str_fld[8];
2266         uint16_t i;
2267         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2268                         RTE_RETA_GROUP_SIZE;
2269         int ret;
2270
2271         p = strchr(p0, '(');
2272         if (p == NULL)
2273                 return -1;
2274         p++;
2275         p0 = strchr(p, ')');
2276         if (p0 == NULL)
2277                 return -1;
2278         size = p0 - p;
2279         if (size >= sizeof(s)) {
2280                 printf("The string size exceeds the internal buffer size\n");
2281                 return -1;
2282         }
2283         snprintf(s, sizeof(s), "%.*s", size, p);
2284         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2285         if (ret <= 0 || ret != num) {
2286                 printf("The bits of masks do not match the number of "
2287                                         "reta entries: %u\n", num);
2288                 return -1;
2289         }
2290         for (i = 0; i < ret; i++)
2291                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2292
2293         return 0;
2294 }
2295
2296 static void
2297 cmd_showport_reta_parsed(void *parsed_result,
2298                          __attribute__((unused)) struct cmdline *cl,
2299                          __attribute__((unused)) void *data)
2300 {
2301         struct cmd_showport_reta *res = parsed_result;
2302         struct rte_eth_rss_reta_entry64 reta_conf[8];
2303         struct rte_eth_dev_info dev_info;
2304         uint16_t max_reta_size;
2305
2306         memset(&dev_info, 0, sizeof(dev_info));
2307         rte_eth_dev_info_get(res->port_id, &dev_info);
2308         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2309         if (res->size == 0 || res->size > max_reta_size) {
2310                 printf("Invalid redirection table size: %u (1-%u)\n",
2311                         res->size, max_reta_size);
2312                 return;
2313         }
2314
2315         memset(reta_conf, 0, sizeof(reta_conf));
2316         if (showport_parse_reta_config(reta_conf, res->size,
2317                                 res->list_of_items) < 0) {
2318                 printf("Invalid string: %s for reta masks\n",
2319                                         res->list_of_items);
2320                 return;
2321         }
2322         port_rss_reta_info(res->port_id, reta_conf, res->size);
2323 }
2324
2325 cmdline_parse_token_string_t cmd_showport_reta_show =
2326         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2327 cmdline_parse_token_string_t cmd_showport_reta_port =
2328         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2329 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2330         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2331 cmdline_parse_token_string_t cmd_showport_reta_rss =
2332         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2333 cmdline_parse_token_string_t cmd_showport_reta_reta =
2334         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2335 cmdline_parse_token_num_t cmd_showport_reta_size =
2336         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2337 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2338         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2339                                         list_of_items, NULL);
2340
2341 cmdline_parse_inst_t cmd_showport_reta = {
2342         .f = cmd_showport_reta_parsed,
2343         .data = NULL,
2344         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2345         .tokens = {
2346                 (void *)&cmd_showport_reta_show,
2347                 (void *)&cmd_showport_reta_port,
2348                 (void *)&cmd_showport_reta_port_id,
2349                 (void *)&cmd_showport_reta_rss,
2350                 (void *)&cmd_showport_reta_reta,
2351                 (void *)&cmd_showport_reta_size,
2352                 (void *)&cmd_showport_reta_list_of_items,
2353                 NULL,
2354         },
2355 };
2356
2357 /* *** Show RSS hash configuration *** */
2358 struct cmd_showport_rss_hash {
2359         cmdline_fixed_string_t show;
2360         cmdline_fixed_string_t port;
2361         portid_t port_id;
2362         cmdline_fixed_string_t rss_hash;
2363         cmdline_fixed_string_t rss_type;
2364         cmdline_fixed_string_t key; /* optional argument */
2365 };
2366
2367 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2368                                 __attribute__((unused)) struct cmdline *cl,
2369                                 void *show_rss_key)
2370 {
2371         struct cmd_showport_rss_hash *res = parsed_result;
2372
2373         port_rss_hash_conf_show(res->port_id, res->rss_type,
2374                                 show_rss_key != NULL);
2375 }
2376
2377 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2378         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2379 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2380         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2381 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2382         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2383 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2384         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2385                                  "rss-hash");
2386 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2387         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2388                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2389                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2390                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2391                                  "ipv6-tcp-ex#ipv6-udp-ex");
2392 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2393         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2394
2395 cmdline_parse_inst_t cmd_showport_rss_hash = {
2396         .f = cmd_showport_rss_hash_parsed,
2397         .data = NULL,
2398         .help_str = "show port <port_id> rss-hash "
2399                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2400                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2401                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2402         .tokens = {
2403                 (void *)&cmd_showport_rss_hash_show,
2404                 (void *)&cmd_showport_rss_hash_port,
2405                 (void *)&cmd_showport_rss_hash_port_id,
2406                 (void *)&cmd_showport_rss_hash_rss_hash,
2407                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2408                 NULL,
2409         },
2410 };
2411
2412 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2413         .f = cmd_showport_rss_hash_parsed,
2414         .data = (void *)1,
2415         .help_str = "show port <port_id> rss-hash "
2416                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2417                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2418                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2419         .tokens = {
2420                 (void *)&cmd_showport_rss_hash_show,
2421                 (void *)&cmd_showport_rss_hash_port,
2422                 (void *)&cmd_showport_rss_hash_port_id,
2423                 (void *)&cmd_showport_rss_hash_rss_hash,
2424                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2425                 (void *)&cmd_showport_rss_hash_rss_key,
2426                 NULL,
2427         },
2428 };
2429
2430 /* *** Configure DCB *** */
2431 struct cmd_config_dcb {
2432         cmdline_fixed_string_t port;
2433         cmdline_fixed_string_t config;
2434         portid_t port_id;
2435         cmdline_fixed_string_t dcb;
2436         cmdline_fixed_string_t vt;
2437         cmdline_fixed_string_t vt_en;
2438         uint8_t num_tcs;
2439         cmdline_fixed_string_t pfc;
2440         cmdline_fixed_string_t pfc_en;
2441 };
2442
2443 static void
2444 cmd_config_dcb_parsed(void *parsed_result,
2445                         __attribute__((unused)) struct cmdline *cl,
2446                         __attribute__((unused)) void *data)
2447 {
2448         struct cmd_config_dcb *res = parsed_result;
2449         portid_t port_id = res->port_id;
2450         struct rte_port *port;
2451         uint8_t pfc_en;
2452         int ret;
2453
2454         port = &ports[port_id];
2455         /** Check if the port is not started **/
2456         if (port->port_status != RTE_PORT_STOPPED) {
2457                 printf("Please stop port %d first\n", port_id);
2458                 return;
2459         }
2460
2461         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2462                 printf("The invalid number of traffic class,"
2463                         " only 4 or 8 allowed.\n");
2464                 return;
2465         }
2466
2467         if (nb_fwd_lcores < res->num_tcs) {
2468                 printf("nb_cores shouldn't be less than number of TCs.\n");
2469                 return;
2470         }
2471         if (!strncmp(res->pfc_en, "on", 2))
2472                 pfc_en = 1;
2473         else
2474                 pfc_en = 0;
2475
2476         /* DCB in VT mode */
2477         if (!strncmp(res->vt_en, "on", 2))
2478                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2479                                 (enum rte_eth_nb_tcs)res->num_tcs,
2480                                 pfc_en);
2481         else
2482                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2483                                 (enum rte_eth_nb_tcs)res->num_tcs,
2484                                 pfc_en);
2485
2486
2487         if (ret != 0) {
2488                 printf("Cannot initialize network ports.\n");
2489                 return;
2490         }
2491
2492         cmd_reconfig_device_queue(port_id, 1, 1);
2493 }
2494
2495 cmdline_parse_token_string_t cmd_config_dcb_port =
2496         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2497 cmdline_parse_token_string_t cmd_config_dcb_config =
2498         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2499 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2500         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2501 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2502         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2503 cmdline_parse_token_string_t cmd_config_dcb_vt =
2504         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2505 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2506         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2507 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2508         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2509 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2510         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2511 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2512         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2513
2514 cmdline_parse_inst_t cmd_config_dcb = {
2515         .f = cmd_config_dcb_parsed,
2516         .data = NULL,
2517         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2518         .tokens = {
2519                 (void *)&cmd_config_dcb_port,
2520                 (void *)&cmd_config_dcb_config,
2521                 (void *)&cmd_config_dcb_port_id,
2522                 (void *)&cmd_config_dcb_dcb,
2523                 (void *)&cmd_config_dcb_vt,
2524                 (void *)&cmd_config_dcb_vt_en,
2525                 (void *)&cmd_config_dcb_num_tcs,
2526                 (void *)&cmd_config_dcb_pfc,
2527                 (void *)&cmd_config_dcb_pfc_en,
2528                 NULL,
2529         },
2530 };
2531
2532 /* *** configure number of packets per burst *** */
2533 struct cmd_config_burst {
2534         cmdline_fixed_string_t port;
2535         cmdline_fixed_string_t keyword;
2536         cmdline_fixed_string_t all;
2537         cmdline_fixed_string_t name;
2538         uint16_t value;
2539 };
2540
2541 static void
2542 cmd_config_burst_parsed(void *parsed_result,
2543                         __attribute__((unused)) struct cmdline *cl,
2544                         __attribute__((unused)) void *data)
2545 {
2546         struct cmd_config_burst *res = parsed_result;
2547
2548         if (!all_ports_stopped()) {
2549                 printf("Please stop all ports first\n");
2550                 return;
2551         }
2552
2553         if (!strcmp(res->name, "burst")) {
2554                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2555                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2556                         return;
2557                 }
2558                 nb_pkt_per_burst = res->value;
2559         } else {
2560                 printf("Unknown parameter\n");
2561                 return;
2562         }
2563
2564         init_port_config();
2565
2566         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2567 }
2568
2569 cmdline_parse_token_string_t cmd_config_burst_port =
2570         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2571 cmdline_parse_token_string_t cmd_config_burst_keyword =
2572         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2573 cmdline_parse_token_string_t cmd_config_burst_all =
2574         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2575 cmdline_parse_token_string_t cmd_config_burst_name =
2576         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2577 cmdline_parse_token_num_t cmd_config_burst_value =
2578         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2579
2580 cmdline_parse_inst_t cmd_config_burst = {
2581         .f = cmd_config_burst_parsed,
2582         .data = NULL,
2583         .help_str = "port config all burst <value>",
2584         .tokens = {
2585                 (void *)&cmd_config_burst_port,
2586                 (void *)&cmd_config_burst_keyword,
2587                 (void *)&cmd_config_burst_all,
2588                 (void *)&cmd_config_burst_name,
2589                 (void *)&cmd_config_burst_value,
2590                 NULL,
2591         },
2592 };
2593
2594 /* *** configure rx/tx queues *** */
2595 struct cmd_config_thresh {
2596         cmdline_fixed_string_t port;
2597         cmdline_fixed_string_t keyword;
2598         cmdline_fixed_string_t all;
2599         cmdline_fixed_string_t name;
2600         uint8_t value;
2601 };
2602
2603 static void
2604 cmd_config_thresh_parsed(void *parsed_result,
2605                         __attribute__((unused)) struct cmdline *cl,
2606                         __attribute__((unused)) void *data)
2607 {
2608         struct cmd_config_thresh *res = parsed_result;
2609
2610         if (!all_ports_stopped()) {
2611                 printf("Please stop all ports first\n");
2612                 return;
2613         }
2614
2615         if (!strcmp(res->name, "txpt"))
2616                 tx_pthresh = res->value;
2617         else if(!strcmp(res->name, "txht"))
2618                 tx_hthresh = res->value;
2619         else if(!strcmp(res->name, "txwt"))
2620                 tx_wthresh = res->value;
2621         else if(!strcmp(res->name, "rxpt"))
2622                 rx_pthresh = res->value;
2623         else if(!strcmp(res->name, "rxht"))
2624                 rx_hthresh = res->value;
2625         else if(!strcmp(res->name, "rxwt"))
2626                 rx_wthresh = res->value;
2627         else {
2628                 printf("Unknown parameter\n");
2629                 return;
2630         }
2631
2632         init_port_config();
2633
2634         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2635 }
2636
2637 cmdline_parse_token_string_t cmd_config_thresh_port =
2638         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2639 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2640         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2641 cmdline_parse_token_string_t cmd_config_thresh_all =
2642         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2643 cmdline_parse_token_string_t cmd_config_thresh_name =
2644         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2645                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2646 cmdline_parse_token_num_t cmd_config_thresh_value =
2647         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2648
2649 cmdline_parse_inst_t cmd_config_thresh = {
2650         .f = cmd_config_thresh_parsed,
2651         .data = NULL,
2652         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2653         .tokens = {
2654                 (void *)&cmd_config_thresh_port,
2655                 (void *)&cmd_config_thresh_keyword,
2656                 (void *)&cmd_config_thresh_all,
2657                 (void *)&cmd_config_thresh_name,
2658                 (void *)&cmd_config_thresh_value,
2659                 NULL,
2660         },
2661 };
2662
2663 /* *** configure free/rs threshold *** */
2664 struct cmd_config_threshold {
2665         cmdline_fixed_string_t port;
2666         cmdline_fixed_string_t keyword;
2667         cmdline_fixed_string_t all;
2668         cmdline_fixed_string_t name;
2669         uint16_t value;
2670 };
2671
2672 static void
2673 cmd_config_threshold_parsed(void *parsed_result,
2674                         __attribute__((unused)) struct cmdline *cl,
2675                         __attribute__((unused)) void *data)
2676 {
2677         struct cmd_config_threshold *res = parsed_result;
2678
2679         if (!all_ports_stopped()) {
2680                 printf("Please stop all ports first\n");
2681                 return;
2682         }
2683
2684         if (!strcmp(res->name, "txfreet"))
2685                 tx_free_thresh = res->value;
2686         else if (!strcmp(res->name, "txrst"))
2687                 tx_rs_thresh = res->value;
2688         else if (!strcmp(res->name, "rxfreet"))
2689                 rx_free_thresh = res->value;
2690         else {
2691                 printf("Unknown parameter\n");
2692                 return;
2693         }
2694
2695         init_port_config();
2696
2697         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2698 }
2699
2700 cmdline_parse_token_string_t cmd_config_threshold_port =
2701         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2702 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2703         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2704                                                                 "config");
2705 cmdline_parse_token_string_t cmd_config_threshold_all =
2706         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2707 cmdline_parse_token_string_t cmd_config_threshold_name =
2708         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2709                                                 "txfreet#txrst#rxfreet");
2710 cmdline_parse_token_num_t cmd_config_threshold_value =
2711         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2712
2713 cmdline_parse_inst_t cmd_config_threshold = {
2714         .f = cmd_config_threshold_parsed,
2715         .data = NULL,
2716         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2717         .tokens = {
2718                 (void *)&cmd_config_threshold_port,
2719                 (void *)&cmd_config_threshold_keyword,
2720                 (void *)&cmd_config_threshold_all,
2721                 (void *)&cmd_config_threshold_name,
2722                 (void *)&cmd_config_threshold_value,
2723                 NULL,
2724         },
2725 };
2726
2727 /* *** stop *** */
2728 struct cmd_stop_result {
2729         cmdline_fixed_string_t stop;
2730 };
2731
2732 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2733                             __attribute__((unused)) struct cmdline *cl,
2734                             __attribute__((unused)) void *data)
2735 {
2736         stop_packet_forwarding();
2737 }
2738
2739 cmdline_parse_token_string_t cmd_stop_stop =
2740         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2741
2742 cmdline_parse_inst_t cmd_stop = {
2743         .f = cmd_stop_parsed,
2744         .data = NULL,
2745         .help_str = "stop: Stop packet forwarding",
2746         .tokens = {
2747                 (void *)&cmd_stop_stop,
2748                 NULL,
2749         },
2750 };
2751
2752 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2753
2754 unsigned int
2755 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2756                 unsigned int *parsed_items, int check_unique_values)
2757 {
2758         unsigned int nb_item;
2759         unsigned int value;
2760         unsigned int i;
2761         unsigned int j;
2762         int value_ok;
2763         char c;
2764
2765         /*
2766          * First parse all items in the list and store their value.
2767          */
2768         value = 0;
2769         nb_item = 0;
2770         value_ok = 0;
2771         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2772                 c = str[i];
2773                 if ((c >= '0') && (c <= '9')) {
2774                         value = (unsigned int) (value * 10 + (c - '0'));
2775                         value_ok = 1;
2776                         continue;
2777                 }
2778                 if (c != ',') {
2779                         printf("character %c is not a decimal digit\n", c);
2780                         return 0;
2781                 }
2782                 if (! value_ok) {
2783                         printf("No valid value before comma\n");
2784                         return 0;
2785                 }
2786                 if (nb_item < max_items) {
2787                         parsed_items[nb_item] = value;
2788                         value_ok = 0;
2789                         value = 0;
2790                 }
2791                 nb_item++;
2792         }
2793         if (nb_item >= max_items) {
2794                 printf("Number of %s = %u > %u (maximum items)\n",
2795                        item_name, nb_item + 1, max_items);
2796                 return 0;
2797         }
2798         parsed_items[nb_item++] = value;
2799         if (! check_unique_values)
2800                 return nb_item;
2801
2802         /*
2803          * Then, check that all values in the list are differents.
2804          * No optimization here...
2805          */
2806         for (i = 0; i < nb_item; i++) {
2807                 for (j = i + 1; j < nb_item; j++) {
2808                         if (parsed_items[j] == parsed_items[i]) {
2809                                 printf("duplicated %s %u at index %u and %u\n",
2810                                        item_name, parsed_items[i], i, j);
2811                                 return 0;
2812                         }
2813                 }
2814         }
2815         return nb_item;
2816 }
2817
2818 struct cmd_set_list_result {
2819         cmdline_fixed_string_t cmd_keyword;
2820         cmdline_fixed_string_t list_name;
2821         cmdline_fixed_string_t list_of_items;
2822 };
2823
2824 static void cmd_set_list_parsed(void *parsed_result,
2825                                 __attribute__((unused)) struct cmdline *cl,
2826                                 __attribute__((unused)) void *data)
2827 {
2828         struct cmd_set_list_result *res;
2829         union {
2830                 unsigned int lcorelist[RTE_MAX_LCORE];
2831                 unsigned int portlist[RTE_MAX_ETHPORTS];
2832         } parsed_items;
2833         unsigned int nb_item;
2834
2835         if (test_done == 0) {
2836                 printf("Please stop forwarding first\n");
2837                 return;
2838         }
2839
2840         res = parsed_result;
2841         if (!strcmp(res->list_name, "corelist")) {
2842                 nb_item = parse_item_list(res->list_of_items, "core",
2843                                           RTE_MAX_LCORE,
2844                                           parsed_items.lcorelist, 1);
2845                 if (nb_item > 0) {
2846                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2847                         fwd_config_setup();
2848                 }
2849                 return;
2850         }
2851         if (!strcmp(res->list_name, "portlist")) {
2852                 nb_item = parse_item_list(res->list_of_items, "port",
2853                                           RTE_MAX_ETHPORTS,
2854                                           parsed_items.portlist, 1);
2855                 if (nb_item > 0) {
2856                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2857                         fwd_config_setup();
2858                 }
2859         }
2860 }
2861
2862 cmdline_parse_token_string_t cmd_set_list_keyword =
2863         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2864                                  "set");
2865 cmdline_parse_token_string_t cmd_set_list_name =
2866         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2867                                  "corelist#portlist");
2868 cmdline_parse_token_string_t cmd_set_list_of_items =
2869         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2870                                  NULL);
2871
2872 cmdline_parse_inst_t cmd_set_fwd_list = {
2873         .f = cmd_set_list_parsed,
2874         .data = NULL,
2875         .help_str = "set corelist|portlist <list0[,list1]*>",
2876         .tokens = {
2877                 (void *)&cmd_set_list_keyword,
2878                 (void *)&cmd_set_list_name,
2879                 (void *)&cmd_set_list_of_items,
2880                 NULL,
2881         },
2882 };
2883
2884 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2885
2886 struct cmd_setmask_result {
2887         cmdline_fixed_string_t set;
2888         cmdline_fixed_string_t mask;
2889         uint64_t hexavalue;
2890 };
2891
2892 static void cmd_set_mask_parsed(void *parsed_result,
2893                                 __attribute__((unused)) struct cmdline *cl,
2894                                 __attribute__((unused)) void *data)
2895 {
2896         struct cmd_setmask_result *res = parsed_result;
2897
2898         if (test_done == 0) {
2899                 printf("Please stop forwarding first\n");
2900                 return;
2901         }
2902         if (!strcmp(res->mask, "coremask")) {
2903                 set_fwd_lcores_mask(res->hexavalue);
2904                 fwd_config_setup();
2905         } else if (!strcmp(res->mask, "portmask")) {
2906                 set_fwd_ports_mask(res->hexavalue);
2907                 fwd_config_setup();
2908         }
2909 }
2910
2911 cmdline_parse_token_string_t cmd_setmask_set =
2912         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2913 cmdline_parse_token_string_t cmd_setmask_mask =
2914         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2915                                  "coremask#portmask");
2916 cmdline_parse_token_num_t cmd_setmask_value =
2917         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2918
2919 cmdline_parse_inst_t cmd_set_fwd_mask = {
2920         .f = cmd_set_mask_parsed,
2921         .data = NULL,
2922         .help_str = "set coremask|portmask <hexadecimal value>",
2923         .tokens = {
2924                 (void *)&cmd_setmask_set,
2925                 (void *)&cmd_setmask_mask,
2926                 (void *)&cmd_setmask_value,
2927                 NULL,
2928         },
2929 };
2930
2931 /*
2932  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2933  */
2934 struct cmd_set_result {
2935         cmdline_fixed_string_t set;
2936         cmdline_fixed_string_t what;
2937         uint16_t value;
2938 };
2939
2940 static void cmd_set_parsed(void *parsed_result,
2941                            __attribute__((unused)) struct cmdline *cl,
2942                            __attribute__((unused)) void *data)
2943 {
2944         struct cmd_set_result *res = parsed_result;
2945         if (!strcmp(res->what, "nbport")) {
2946                 set_fwd_ports_number(res->value);
2947                 fwd_config_setup();
2948         } else if (!strcmp(res->what, "nbcore")) {
2949                 set_fwd_lcores_number(res->value);
2950                 fwd_config_setup();
2951         } else if (!strcmp(res->what, "burst"))
2952                 set_nb_pkt_per_burst(res->value);
2953         else if (!strcmp(res->what, "verbose"))
2954                 set_verbose_level(res->value);
2955 }
2956
2957 cmdline_parse_token_string_t cmd_set_set =
2958         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2959 cmdline_parse_token_string_t cmd_set_what =
2960         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2961                                  "nbport#nbcore#burst#verbose");
2962 cmdline_parse_token_num_t cmd_set_value =
2963         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2964
2965 cmdline_parse_inst_t cmd_set_numbers = {
2966         .f = cmd_set_parsed,
2967         .data = NULL,
2968         .help_str = "set nbport|nbcore|burst|verbose <value>",
2969         .tokens = {
2970                 (void *)&cmd_set_set,
2971                 (void *)&cmd_set_what,
2972                 (void *)&cmd_set_value,
2973                 NULL,
2974         },
2975 };
2976
2977 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2978
2979 struct cmd_set_txpkts_result {
2980         cmdline_fixed_string_t cmd_keyword;
2981         cmdline_fixed_string_t txpkts;
2982         cmdline_fixed_string_t seg_lengths;
2983 };
2984
2985 static void
2986 cmd_set_txpkts_parsed(void *parsed_result,
2987                       __attribute__((unused)) struct cmdline *cl,
2988                       __attribute__((unused)) void *data)
2989 {
2990         struct cmd_set_txpkts_result *res;
2991         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2992         unsigned int nb_segs;
2993
2994         res = parsed_result;
2995         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2996                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2997         if (nb_segs > 0)
2998                 set_tx_pkt_segments(seg_lengths, nb_segs);
2999 }
3000
3001 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3002         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3003                                  cmd_keyword, "set");
3004 cmdline_parse_token_string_t cmd_set_txpkts_name =
3005         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3006                                  txpkts, "txpkts");
3007 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3008         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3009                                  seg_lengths, NULL);
3010
3011 cmdline_parse_inst_t cmd_set_txpkts = {
3012         .f = cmd_set_txpkts_parsed,
3013         .data = NULL,
3014         .help_str = "set txpkts <len0[,len1]*>",
3015         .tokens = {
3016                 (void *)&cmd_set_txpkts_keyword,
3017                 (void *)&cmd_set_txpkts_name,
3018                 (void *)&cmd_set_txpkts_lengths,
3019                 NULL,
3020         },
3021 };
3022
3023 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3024
3025 struct cmd_set_txsplit_result {
3026         cmdline_fixed_string_t cmd_keyword;
3027         cmdline_fixed_string_t txsplit;
3028         cmdline_fixed_string_t mode;
3029 };
3030
3031 static void
3032 cmd_set_txsplit_parsed(void *parsed_result,
3033                       __attribute__((unused)) struct cmdline *cl,
3034                       __attribute__((unused)) void *data)
3035 {
3036         struct cmd_set_txsplit_result *res;
3037
3038         res = parsed_result;
3039         set_tx_pkt_split(res->mode);
3040 }
3041
3042 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3043         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3044                                  cmd_keyword, "set");
3045 cmdline_parse_token_string_t cmd_set_txsplit_name =
3046         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3047                                  txsplit, "txsplit");
3048 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3049         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3050                                  mode, NULL);
3051
3052 cmdline_parse_inst_t cmd_set_txsplit = {
3053         .f = cmd_set_txsplit_parsed,
3054         .data = NULL,
3055         .help_str = "set txsplit on|off|rand",
3056         .tokens = {
3057                 (void *)&cmd_set_txsplit_keyword,
3058                 (void *)&cmd_set_txsplit_name,
3059                 (void *)&cmd_set_txsplit_mode,
3060                 NULL,
3061         },
3062 };
3063
3064 /* *** CONFIG TX QUEUE FLAGS *** */
3065
3066 struct cmd_config_txqflags_result {
3067         cmdline_fixed_string_t port;
3068         cmdline_fixed_string_t config;
3069         cmdline_fixed_string_t all;
3070         cmdline_fixed_string_t what;
3071         int32_t hexvalue;
3072 };
3073
3074 static void cmd_config_txqflags_parsed(void *parsed_result,
3075                                 __attribute__((unused)) struct cmdline *cl,
3076                                 __attribute__((unused)) void *data)
3077 {
3078         struct cmd_config_txqflags_result *res = parsed_result;
3079
3080         if (!all_ports_stopped()) {
3081                 printf("Please stop all ports first\n");
3082                 return;
3083         }
3084
3085         if (strcmp(res->what, "txqflags")) {
3086                 printf("Unknown parameter\n");
3087                 return;
3088         }
3089
3090         if (res->hexvalue >= 0) {
3091                 txq_flags = res->hexvalue;
3092         } else {
3093                 printf("txqflags must be >= 0\n");
3094                 return;
3095         }
3096
3097         init_port_config();
3098
3099         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3100 }
3101
3102 cmdline_parse_token_string_t cmd_config_txqflags_port =
3103         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3104                                  "port");
3105 cmdline_parse_token_string_t cmd_config_txqflags_config =
3106         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3107                                  "config");
3108 cmdline_parse_token_string_t cmd_config_txqflags_all =
3109         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3110                                  "all");
3111 cmdline_parse_token_string_t cmd_config_txqflags_what =
3112         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3113                                  "txqflags");
3114 cmdline_parse_token_num_t cmd_config_txqflags_value =
3115         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3116                                 hexvalue, INT32);
3117
3118 cmdline_parse_inst_t cmd_config_txqflags = {
3119         .f = cmd_config_txqflags_parsed,
3120         .data = NULL,
3121         .help_str = "port config all txqflags <value>",
3122         .tokens = {
3123                 (void *)&cmd_config_txqflags_port,
3124                 (void *)&cmd_config_txqflags_config,
3125                 (void *)&cmd_config_txqflags_all,
3126                 (void *)&cmd_config_txqflags_what,
3127                 (void *)&cmd_config_txqflags_value,
3128                 NULL,
3129         },
3130 };
3131
3132 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3133 struct cmd_rx_vlan_filter_all_result {
3134         cmdline_fixed_string_t rx_vlan;
3135         cmdline_fixed_string_t what;
3136         cmdline_fixed_string_t all;
3137         portid_t port_id;
3138 };
3139
3140 static void
3141 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3142                               __attribute__((unused)) struct cmdline *cl,
3143                               __attribute__((unused)) void *data)
3144 {
3145         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3146
3147         if (!strcmp(res->what, "add"))
3148                 rx_vlan_all_filter_set(res->port_id, 1);
3149         else
3150                 rx_vlan_all_filter_set(res->port_id, 0);
3151 }
3152
3153 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3154         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3155                                  rx_vlan, "rx_vlan");
3156 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3157         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3158                                  what, "add#rm");
3159 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3160         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3161                                  all, "all");
3162 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3163         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3164                               port_id, UINT16);
3165
3166 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3167         .f = cmd_rx_vlan_filter_all_parsed,
3168         .data = NULL,
3169         .help_str = "rx_vlan add|rm all <port_id>: "
3170                 "Add/Remove all identifiers to/from the set of VLAN "
3171                 "identifiers filtered by a port",
3172         .tokens = {
3173                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3174                 (void *)&cmd_rx_vlan_filter_all_what,
3175                 (void *)&cmd_rx_vlan_filter_all_all,
3176                 (void *)&cmd_rx_vlan_filter_all_portid,
3177                 NULL,
3178         },
3179 };
3180
3181 /* *** VLAN OFFLOAD SET ON A PORT *** */
3182 struct cmd_vlan_offload_result {
3183         cmdline_fixed_string_t vlan;
3184         cmdline_fixed_string_t set;
3185         cmdline_fixed_string_t vlan_type;
3186         cmdline_fixed_string_t what;
3187         cmdline_fixed_string_t on;
3188         cmdline_fixed_string_t port_id;
3189 };
3190
3191 static void
3192 cmd_vlan_offload_parsed(void *parsed_result,
3193                           __attribute__((unused)) struct cmdline *cl,
3194                           __attribute__((unused)) void *data)
3195 {
3196         int on;
3197         struct cmd_vlan_offload_result *res = parsed_result;
3198         char *str;
3199         int i, len = 0;
3200         portid_t port_id = 0;
3201         unsigned int tmp;
3202
3203         str = res->port_id;
3204         len = strnlen(str, STR_TOKEN_SIZE);
3205         i = 0;
3206         /* Get port_id first */
3207         while(i < len){
3208                 if(str[i] == ',')
3209                         break;
3210
3211                 i++;
3212         }
3213         str[i]='\0';
3214         tmp = strtoul(str, NULL, 0);
3215         /* If port_id greater that what portid_t can represent, return */
3216         if(tmp >= RTE_MAX_ETHPORTS)
3217                 return;
3218         port_id = (portid_t)tmp;
3219
3220         if (!strcmp(res->on, "on"))
3221                 on = 1;
3222         else
3223                 on = 0;
3224
3225         if (!strcmp(res->what, "strip"))
3226                 rx_vlan_strip_set(port_id,  on);
3227         else if(!strcmp(res->what, "stripq")){
3228                 uint16_t queue_id = 0;
3229
3230                 /* No queue_id, return */
3231                 if(i + 1 >= len) {
3232                         printf("must specify (port,queue_id)\n");
3233                         return;
3234                 }
3235                 tmp = strtoul(str + i + 1, NULL, 0);
3236                 /* If queue_id greater that what 16-bits can represent, return */
3237                 if(tmp > 0xffff)
3238                         return;
3239
3240                 queue_id = (uint16_t)tmp;
3241                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3242         }
3243         else if (!strcmp(res->what, "filter"))
3244                 rx_vlan_filter_set(port_id, on);
3245         else
3246                 vlan_extend_set(port_id, on);
3247
3248         return;
3249 }
3250
3251 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3252         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3253                                  vlan, "vlan");
3254 cmdline_parse_token_string_t cmd_vlan_offload_set =
3255         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3256                                  set, "set");
3257 cmdline_parse_token_string_t cmd_vlan_offload_what =
3258         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3259                                  what, "strip#filter#qinq#stripq");
3260 cmdline_parse_token_string_t cmd_vlan_offload_on =
3261         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3262                               on, "on#off");
3263 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3264         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3265                               port_id, NULL);
3266
3267 cmdline_parse_inst_t cmd_vlan_offload = {
3268         .f = cmd_vlan_offload_parsed,
3269         .data = NULL,
3270         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3271                 "<port_id[,queue_id]>: "
3272                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3273         .tokens = {
3274                 (void *)&cmd_vlan_offload_vlan,
3275                 (void *)&cmd_vlan_offload_set,
3276                 (void *)&cmd_vlan_offload_what,
3277                 (void *)&cmd_vlan_offload_on,
3278                 (void *)&cmd_vlan_offload_portid,
3279                 NULL,
3280         },
3281 };
3282
3283 /* *** VLAN TPID SET ON A PORT *** */
3284 struct cmd_vlan_tpid_result {
3285         cmdline_fixed_string_t vlan;
3286         cmdline_fixed_string_t set;
3287         cmdline_fixed_string_t vlan_type;
3288         cmdline_fixed_string_t what;
3289         uint16_t tp_id;
3290         portid_t port_id;
3291 };
3292
3293 static void
3294 cmd_vlan_tpid_parsed(void *parsed_result,
3295                           __attribute__((unused)) struct cmdline *cl,
3296                           __attribute__((unused)) void *data)
3297 {
3298         struct cmd_vlan_tpid_result *res = parsed_result;
3299         enum rte_vlan_type vlan_type;
3300
3301         if (!strcmp(res->vlan_type, "inner"))
3302                 vlan_type = ETH_VLAN_TYPE_INNER;
3303         else if (!strcmp(res->vlan_type, "outer"))
3304                 vlan_type = ETH_VLAN_TYPE_OUTER;
3305         else {
3306                 printf("Unknown vlan type\n");
3307                 return;
3308         }
3309         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3310 }
3311
3312 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3313         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3314                                  vlan, "vlan");
3315 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3316         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3317                                  set, "set");
3318 cmdline_parse_token_string_t cmd_vlan_type =
3319         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3320                                  vlan_type, "inner#outer");
3321 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3322         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3323                                  what, "tpid");
3324 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3325         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3326                               tp_id, UINT16);
3327 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3328         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3329                               port_id, UINT8);
3330
3331 cmdline_parse_inst_t cmd_vlan_tpid = {
3332         .f = cmd_vlan_tpid_parsed,
3333         .data = NULL,
3334         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3335                 "Set the VLAN Ether type",
3336         .tokens = {
3337                 (void *)&cmd_vlan_tpid_vlan,
3338                 (void *)&cmd_vlan_tpid_set,
3339                 (void *)&cmd_vlan_type,
3340                 (void *)&cmd_vlan_tpid_what,
3341                 (void *)&cmd_vlan_tpid_tpid,
3342                 (void *)&cmd_vlan_tpid_portid,
3343                 NULL,
3344         },
3345 };
3346
3347 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3348 struct cmd_rx_vlan_filter_result {
3349         cmdline_fixed_string_t rx_vlan;
3350         cmdline_fixed_string_t what;
3351         uint16_t vlan_id;
3352         portid_t port_id;
3353 };
3354
3355 static void
3356 cmd_rx_vlan_filter_parsed(void *parsed_result,
3357                           __attribute__((unused)) struct cmdline *cl,
3358                           __attribute__((unused)) void *data)
3359 {
3360         struct cmd_rx_vlan_filter_result *res = parsed_result;
3361
3362         if (!strcmp(res->what, "add"))
3363                 rx_vft_set(res->port_id, res->vlan_id, 1);
3364         else
3365                 rx_vft_set(res->port_id, res->vlan_id, 0);
3366 }
3367
3368 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3369         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3370                                  rx_vlan, "rx_vlan");
3371 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3372         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3373                                  what, "add#rm");
3374 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3375         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3376                               vlan_id, UINT16);
3377 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3378         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3379                               port_id, UINT16);
3380
3381 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3382         .f = cmd_rx_vlan_filter_parsed,
3383         .data = NULL,
3384         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3385                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3386                 "identifiers filtered by a port",
3387         .tokens = {
3388                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3389                 (void *)&cmd_rx_vlan_filter_what,
3390                 (void *)&cmd_rx_vlan_filter_vlanid,
3391                 (void *)&cmd_rx_vlan_filter_portid,
3392                 NULL,
3393         },
3394 };
3395
3396 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3397 struct cmd_tx_vlan_set_result {
3398         cmdline_fixed_string_t tx_vlan;
3399         cmdline_fixed_string_t set;
3400         portid_t port_id;
3401         uint16_t vlan_id;
3402 };
3403
3404 static void
3405 cmd_tx_vlan_set_parsed(void *parsed_result,
3406                        __attribute__((unused)) struct cmdline *cl,
3407                        __attribute__((unused)) void *data)
3408 {
3409         struct cmd_tx_vlan_set_result *res = parsed_result;
3410
3411         tx_vlan_set(res->port_id, res->vlan_id);
3412 }
3413
3414 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3415         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3416                                  tx_vlan, "tx_vlan");
3417 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3418         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3419                                  set, "set");
3420 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3421         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3422                               port_id, UINT16);
3423 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3424         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3425                               vlan_id, UINT16);
3426
3427 cmdline_parse_inst_t cmd_tx_vlan_set = {
3428         .f = cmd_tx_vlan_set_parsed,
3429         .data = NULL,
3430         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3431                 "Enable hardware insertion of a single VLAN header "
3432                 "with a given TAG Identifier in packets sent on a port",
3433         .tokens = {
3434                 (void *)&cmd_tx_vlan_set_tx_vlan,
3435                 (void *)&cmd_tx_vlan_set_set,
3436                 (void *)&cmd_tx_vlan_set_portid,
3437                 (void *)&cmd_tx_vlan_set_vlanid,
3438                 NULL,
3439         },
3440 };
3441
3442 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3443 struct cmd_tx_vlan_set_qinq_result {
3444         cmdline_fixed_string_t tx_vlan;
3445         cmdline_fixed_string_t set;
3446         portid_t port_id;
3447         uint16_t vlan_id;
3448         uint16_t vlan_id_outer;
3449 };
3450
3451 static void
3452 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3453                             __attribute__((unused)) struct cmdline *cl,
3454                             __attribute__((unused)) void *data)
3455 {
3456         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3457
3458         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3459 }
3460
3461 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3462         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3463                 tx_vlan, "tx_vlan");
3464 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3465         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3466                 set, "set");
3467 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3468         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3469                 port_id, UINT16);
3470 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3471         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3472                 vlan_id, UINT16);
3473 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3474         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3475                 vlan_id_outer, UINT16);
3476
3477 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3478         .f = cmd_tx_vlan_set_qinq_parsed,
3479         .data = NULL,
3480         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3481                 "Enable hardware insertion of double VLAN header "
3482                 "with given TAG Identifiers in packets sent on a port",
3483         .tokens = {
3484                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3485                 (void *)&cmd_tx_vlan_set_qinq_set,
3486                 (void *)&cmd_tx_vlan_set_qinq_portid,
3487                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3488                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3489                 NULL,
3490         },
3491 };
3492
3493 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3494 struct cmd_tx_vlan_set_pvid_result {
3495         cmdline_fixed_string_t tx_vlan;
3496         cmdline_fixed_string_t set;
3497         cmdline_fixed_string_t pvid;
3498         portid_t port_id;
3499         uint16_t vlan_id;
3500         cmdline_fixed_string_t mode;
3501 };
3502
3503 static void
3504 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3505                             __attribute__((unused)) struct cmdline *cl,
3506                             __attribute__((unused)) void *data)
3507 {
3508         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3509
3510         if (strcmp(res->mode, "on") == 0)
3511                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3512         else
3513                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3514 }
3515
3516 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3517         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3518                                  tx_vlan, "tx_vlan");
3519 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3520         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3521                                  set, "set");
3522 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3523         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3524                                  pvid, "pvid");
3525 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3526         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3527                              port_id, UINT16);
3528 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3529         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3530                               vlan_id, UINT16);
3531 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3532         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3533                                  mode, "on#off");
3534
3535 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3536         .f = cmd_tx_vlan_set_pvid_parsed,
3537         .data = NULL,
3538         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3539         .tokens = {
3540                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3541                 (void *)&cmd_tx_vlan_set_pvid_set,
3542                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3543                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3544                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3545                 (void *)&cmd_tx_vlan_set_pvid_mode,
3546                 NULL,
3547         },
3548 };
3549
3550 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3551 struct cmd_tx_vlan_reset_result {
3552         cmdline_fixed_string_t tx_vlan;
3553         cmdline_fixed_string_t reset;
3554         portid_t port_id;
3555 };
3556
3557 static void
3558 cmd_tx_vlan_reset_parsed(void *parsed_result,
3559                          __attribute__((unused)) struct cmdline *cl,
3560                          __attribute__((unused)) void *data)
3561 {
3562         struct cmd_tx_vlan_reset_result *res = parsed_result;
3563
3564         tx_vlan_reset(res->port_id);
3565 }
3566
3567 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3568         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3569                                  tx_vlan, "tx_vlan");
3570 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3571         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3572                                  reset, "reset");
3573 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3574         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3575                               port_id, UINT16);
3576
3577 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3578         .f = cmd_tx_vlan_reset_parsed,
3579         .data = NULL,
3580         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3581                 "VLAN header in packets sent on a port",
3582         .tokens = {
3583                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3584                 (void *)&cmd_tx_vlan_reset_reset,
3585                 (void *)&cmd_tx_vlan_reset_portid,
3586                 NULL,
3587         },
3588 };
3589
3590
3591 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3592 struct cmd_csum_result {
3593         cmdline_fixed_string_t csum;
3594         cmdline_fixed_string_t mode;
3595         cmdline_fixed_string_t proto;
3596         cmdline_fixed_string_t hwsw;
3597         portid_t port_id;
3598 };
3599
3600 static void
3601 csum_show(int port_id)
3602 {
3603         struct rte_eth_dev_info dev_info;
3604         uint16_t ol_flags;
3605
3606         ol_flags = ports[port_id].tx_ol_flags;
3607         printf("Parse tunnel is %s\n",
3608                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3609         printf("IP checksum offload is %s\n",
3610                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3611         printf("UDP checksum offload is %s\n",
3612                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3613         printf("TCP checksum offload is %s\n",
3614                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3615         printf("SCTP checksum offload is %s\n",
3616                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3617         printf("Outer-Ip checksum offload is %s\n",
3618                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3619
3620         /* display warnings if configuration is not supported by the NIC */
3621         rte_eth_dev_info_get(port_id, &dev_info);
3622         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3623                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3624                 printf("Warning: hardware IP checksum enabled but not "
3625                         "supported by port %d\n", port_id);
3626         }
3627         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3628                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3629                 printf("Warning: hardware UDP checksum enabled but not "
3630                         "supported by port %d\n", port_id);
3631         }
3632         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3633                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3634                 printf("Warning: hardware TCP checksum enabled but not "
3635                         "supported by port %d\n", port_id);
3636         }
3637         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3638                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3639                 printf("Warning: hardware SCTP checksum enabled but not "
3640                         "supported by port %d\n", port_id);
3641         }
3642         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3643                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3644                 printf("Warning: hardware outer IP checksum enabled but not "
3645                         "supported by port %d\n", port_id);
3646         }
3647 }
3648
3649 static void
3650 cmd_csum_parsed(void *parsed_result,
3651                        __attribute__((unused)) struct cmdline *cl,
3652                        __attribute__((unused)) void *data)
3653 {
3654         struct cmd_csum_result *res = parsed_result;
3655         int hw = 0;
3656         uint16_t mask = 0;
3657
3658         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3659                 printf("invalid port %d\n", res->port_id);
3660                 return;
3661         }
3662
3663         if (!strcmp(res->mode, "set")) {
3664
3665                 if (!strcmp(res->hwsw, "hw"))
3666                         hw = 1;
3667
3668                 if (!strcmp(res->proto, "ip")) {
3669                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3670                 } else if (!strcmp(res->proto, "udp")) {
3671                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3672                 } else if (!strcmp(res->proto, "tcp")) {
3673                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3674                 } else if (!strcmp(res->proto, "sctp")) {
3675                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3676                 } else if (!strcmp(res->proto, "outer-ip")) {
3677                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3678                 }
3679
3680                 if (hw)
3681                         ports[res->port_id].tx_ol_flags |= mask;
3682                 else
3683                         ports[res->port_id].tx_ol_flags &= (~mask);
3684         }
3685         csum_show(res->port_id);
3686 }
3687
3688 cmdline_parse_token_string_t cmd_csum_csum =
3689         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3690                                 csum, "csum");
3691 cmdline_parse_token_string_t cmd_csum_mode =
3692         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3693                                 mode, "set");
3694 cmdline_parse_token_string_t cmd_csum_proto =
3695         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3696                                 proto, "ip#tcp#udp#sctp#outer-ip");
3697 cmdline_parse_token_string_t cmd_csum_hwsw =
3698         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3699                                 hwsw, "hw#sw");
3700 cmdline_parse_token_num_t cmd_csum_portid =
3701         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3702                                 port_id, UINT16);
3703
3704 cmdline_parse_inst_t cmd_csum_set = {
3705         .f = cmd_csum_parsed,
3706         .data = NULL,
3707         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3708                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3709                 "using csum forward engine",
3710         .tokens = {
3711                 (void *)&cmd_csum_csum,
3712                 (void *)&cmd_csum_mode,
3713                 (void *)&cmd_csum_proto,
3714                 (void *)&cmd_csum_hwsw,
3715                 (void *)&cmd_csum_portid,
3716                 NULL,
3717         },
3718 };
3719
3720 cmdline_parse_token_string_t cmd_csum_mode_show =
3721         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3722                                 mode, "show");
3723
3724 cmdline_parse_inst_t cmd_csum_show = {
3725         .f = cmd_csum_parsed,
3726         .data = NULL,
3727         .help_str = "csum show <port_id>: Show checksum offload configuration",
3728         .tokens = {
3729                 (void *)&cmd_csum_csum,
3730                 (void *)&cmd_csum_mode_show,
3731                 (void *)&cmd_csum_portid,
3732                 NULL,
3733         },
3734 };
3735
3736 /* Enable/disable tunnel parsing */
3737 struct cmd_csum_tunnel_result {
3738         cmdline_fixed_string_t csum;
3739         cmdline_fixed_string_t parse;
3740         cmdline_fixed_string_t onoff;
3741         portid_t port_id;
3742 };
3743
3744 static void
3745 cmd_csum_tunnel_parsed(void *parsed_result,
3746                        __attribute__((unused)) struct cmdline *cl,
3747                        __attribute__((unused)) void *data)
3748 {
3749         struct cmd_csum_tunnel_result *res = parsed_result;
3750
3751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3752                 return;
3753
3754         if (!strcmp(res->onoff, "on"))
3755                 ports[res->port_id].tx_ol_flags |=
3756                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3757         else
3758                 ports[res->port_id].tx_ol_flags &=
3759                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3760
3761         csum_show(res->port_id);
3762 }
3763
3764 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3765         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3766                                 csum, "csum");
3767 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3768         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3769                                 parse, "parse_tunnel");
3770 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3771         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3772                                 onoff, "on#off");
3773 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3774         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3775                                 port_id, UINT16);
3776
3777 cmdline_parse_inst_t cmd_csum_tunnel = {
3778         .f = cmd_csum_tunnel_parsed,
3779         .data = NULL,
3780         .help_str = "csum parse_tunnel on|off <port_id>: "
3781                 "Enable/Disable parsing of tunnels for csum engine",
3782         .tokens = {
3783                 (void *)&cmd_csum_tunnel_csum,
3784                 (void *)&cmd_csum_tunnel_parse,
3785                 (void *)&cmd_csum_tunnel_onoff,
3786                 (void *)&cmd_csum_tunnel_portid,
3787                 NULL,
3788         },
3789 };
3790
3791 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3792 struct cmd_tso_set_result {
3793         cmdline_fixed_string_t tso;
3794         cmdline_fixed_string_t mode;
3795         uint16_t tso_segsz;
3796         portid_t port_id;
3797 };
3798
3799 static void
3800 cmd_tso_set_parsed(void *parsed_result,
3801                        __attribute__((unused)) struct cmdline *cl,
3802                        __attribute__((unused)) void *data)
3803 {
3804         struct cmd_tso_set_result *res = parsed_result;
3805         struct rte_eth_dev_info dev_info;
3806
3807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3808                 return;
3809
3810         if (!strcmp(res->mode, "set"))
3811                 ports[res->port_id].tso_segsz = res->tso_segsz;
3812
3813         if (ports[res->port_id].tso_segsz == 0)
3814                 printf("TSO for non-tunneled packets is disabled\n");
3815         else
3816                 printf("TSO segment size for non-tunneled packets is %d\n",
3817                         ports[res->port_id].tso_segsz);
3818
3819         /* display warnings if configuration is not supported by the NIC */
3820         rte_eth_dev_info_get(res->port_id, &dev_info);
3821         if ((ports[res->port_id].tso_segsz != 0) &&
3822                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3823                 printf("Warning: TSO enabled but not "
3824                         "supported by port %d\n", res->port_id);
3825         }
3826 }
3827
3828 cmdline_parse_token_string_t cmd_tso_set_tso =
3829         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3830                                 tso, "tso");
3831 cmdline_parse_token_string_t cmd_tso_set_mode =
3832         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3833                                 mode, "set");
3834 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3835         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3836                                 tso_segsz, UINT16);
3837 cmdline_parse_token_num_t cmd_tso_set_portid =
3838         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3839                                 port_id, UINT16);
3840
3841 cmdline_parse_inst_t cmd_tso_set = {
3842         .f = cmd_tso_set_parsed,
3843         .data = NULL,
3844         .help_str = "tso set <tso_segsz> <port_id>: "
3845                 "Set TSO segment size of non-tunneled packets for csum engine "
3846                 "(0 to disable)",
3847         .tokens = {
3848                 (void *)&cmd_tso_set_tso,
3849                 (void *)&cmd_tso_set_mode,
3850                 (void *)&cmd_tso_set_tso_segsz,
3851                 (void *)&cmd_tso_set_portid,
3852                 NULL,
3853         },
3854 };
3855
3856 cmdline_parse_token_string_t cmd_tso_show_mode =
3857         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3858                                 mode, "show");
3859
3860
3861 cmdline_parse_inst_t cmd_tso_show = {
3862         .f = cmd_tso_set_parsed,
3863         .data = NULL,
3864         .help_str = "tso show <port_id>: "
3865                 "Show TSO segment size of non-tunneled packets for csum engine",
3866         .tokens = {
3867                 (void *)&cmd_tso_set_tso,
3868                 (void *)&cmd_tso_show_mode,
3869                 (void *)&cmd_tso_set_portid,
3870                 NULL,
3871         },
3872 };
3873
3874 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3875 struct cmd_tunnel_tso_set_result {
3876         cmdline_fixed_string_t tso;
3877         cmdline_fixed_string_t mode;
3878         uint16_t tso_segsz;
3879         portid_t port_id;
3880 };
3881
3882 static void
3883 check_tunnel_tso_nic_support(portid_t port_id)
3884 {
3885         struct rte_eth_dev_info dev_info;
3886
3887         rte_eth_dev_info_get(port_id, &dev_info);
3888         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3889                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3890                        "supported by port %d\n", port_id);
3891         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3892                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3893                         "supported by port %d\n", port_id);
3894         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3895                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3896                        "supported by port %d\n", port_id);
3897         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3898                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3899                        "supported by port %d\n", port_id);
3900 }
3901
3902 static void
3903 cmd_tunnel_tso_set_parsed(void *parsed_result,
3904                           __attribute__((unused)) struct cmdline *cl,
3905                           __attribute__((unused)) void *data)
3906 {
3907         struct cmd_tunnel_tso_set_result *res = parsed_result;
3908
3909         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3910                 return;
3911
3912         if (!strcmp(res->mode, "set"))
3913                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3914
3915         if (ports[res->port_id].tunnel_tso_segsz == 0)
3916                 printf("TSO for tunneled packets is disabled\n");
3917         else {
3918                 printf("TSO segment size for tunneled packets is %d\n",
3919                         ports[res->port_id].tunnel_tso_segsz);
3920
3921                 /* Below conditions are needed to make it work:
3922                  * (1) tunnel TSO is supported by the NIC;
3923                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3924                  * are recognized;
3925                  * (3) for tunneled pkts with outer L3 of IPv4,
3926                  * "csum set outer-ip" must be set to hw, because after tso,
3927                  * total_len of outer IP header is changed, and the checksum
3928                  * of outer IP header calculated by sw should be wrong; that
3929                  * is not necessary for IPv6 tunneled pkts because there's no
3930                  * checksum in IP header anymore.
3931                  */
3932                 check_tunnel_tso_nic_support(res->port_id);
3933
3934                 if (!(ports[res->port_id].tx_ol_flags &
3935                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3936                         printf("Warning: csum parse_tunnel must be set "
3937                                 "so that tunneled packets are recognized\n");
3938                 if (!(ports[res->port_id].tx_ol_flags &
3939                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3940                         printf("Warning: csum set outer-ip must be set to hw "
3941                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3942         }
3943 }
3944
3945 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3946         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3947                                 tso, "tunnel_tso");
3948 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3949         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3950                                 mode, "set");
3951 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3952         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3953                                 tso_segsz, UINT16);
3954 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3955         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3956                                 port_id, UINT16);
3957
3958 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3959         .f = cmd_tunnel_tso_set_parsed,
3960         .data = NULL,
3961         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3962                 "Set TSO segment size of tunneled packets for csum engine "
3963                 "(0 to disable)",
3964         .tokens = {
3965                 (void *)&cmd_tunnel_tso_set_tso,
3966                 (void *)&cmd_tunnel_tso_set_mode,
3967                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3968                 (void *)&cmd_tunnel_tso_set_portid,
3969                 NULL,
3970         },
3971 };
3972
3973 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3974         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3975                                 mode, "show");
3976
3977
3978 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3979         .f = cmd_tunnel_tso_set_parsed,
3980         .data = NULL,
3981         .help_str = "tunnel_tso show <port_id> "
3982                 "Show TSO segment size of tunneled packets for csum engine",
3983         .tokens = {
3984                 (void *)&cmd_tunnel_tso_set_tso,
3985                 (void *)&cmd_tunnel_tso_show_mode,
3986                 (void *)&cmd_tunnel_tso_set_portid,
3987                 NULL,
3988         },
3989 };
3990
3991 /* *** SET GRO FOR A PORT *** */
3992 struct cmd_gro_enable_result {
3993         cmdline_fixed_string_t cmd_set;
3994         cmdline_fixed_string_t cmd_port;
3995         cmdline_fixed_string_t cmd_keyword;
3996         cmdline_fixed_string_t cmd_onoff;
3997         portid_t cmd_pid;
3998 };
3999
4000 static void
4001 cmd_gro_enable_parsed(void *parsed_result,
4002                 __attribute__((unused)) struct cmdline *cl,
4003                 __attribute__((unused)) void *data)
4004 {
4005         struct cmd_gro_enable_result *res;
4006
4007         res = parsed_result;
4008         if (!strcmp(res->cmd_keyword, "gro"))
4009                 setup_gro(res->cmd_onoff, res->cmd_pid);
4010 }
4011
4012 cmdline_parse_token_string_t cmd_gro_enable_set =
4013         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4014                         cmd_set, "set");
4015 cmdline_parse_token_string_t cmd_gro_enable_port =
4016         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4017                         cmd_keyword, "port");
4018 cmdline_parse_token_num_t cmd_gro_enable_pid =
4019         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4020                         cmd_pid, UINT16);
4021 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4022         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4023                         cmd_keyword, "gro");
4024 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4025         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4026                         cmd_onoff, "on#off");
4027
4028 cmdline_parse_inst_t cmd_gro_enable = {
4029         .f = cmd_gro_enable_parsed,
4030         .data = NULL,
4031         .help_str = "set port <port_id> gro on|off",
4032         .tokens = {
4033                 (void *)&cmd_gro_enable_set,
4034                 (void *)&cmd_gro_enable_port,
4035                 (void *)&cmd_gro_enable_pid,
4036                 (void *)&cmd_gro_enable_keyword,
4037                 (void *)&cmd_gro_enable_onoff,
4038                 NULL,
4039         },
4040 };
4041
4042 /* *** DISPLAY GRO CONFIGURATION *** */
4043 struct cmd_gro_show_result {
4044         cmdline_fixed_string_t cmd_show;
4045         cmdline_fixed_string_t cmd_port;
4046         cmdline_fixed_string_t cmd_keyword;
4047         portid_t cmd_pid;
4048 };
4049
4050 static void
4051 cmd_gro_show_parsed(void *parsed_result,
4052                 __attribute__((unused)) struct cmdline *cl,
4053                 __attribute__((unused)) void *data)
4054 {
4055         struct cmd_gro_show_result *res;
4056
4057         res = parsed_result;
4058         if (!strcmp(res->cmd_keyword, "gro"))
4059                 show_gro(res->cmd_pid);
4060 }
4061
4062 cmdline_parse_token_string_t cmd_gro_show_show =
4063         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4064                         cmd_show, "show");
4065 cmdline_parse_token_string_t cmd_gro_show_port =
4066         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4067                         cmd_port, "port");
4068 cmdline_parse_token_num_t cmd_gro_show_pid =
4069         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4070                         cmd_pid, UINT16);
4071 cmdline_parse_token_string_t cmd_gro_show_keyword =
4072         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4073                         cmd_keyword, "gro");
4074
4075 cmdline_parse_inst_t cmd_gro_show = {
4076         .f = cmd_gro_show_parsed,
4077         .data = NULL,
4078         .help_str = "show port <port_id> gro",
4079         .tokens = {
4080                 (void *)&cmd_gro_show_show,
4081                 (void *)&cmd_gro_show_port,
4082                 (void *)&cmd_gro_show_pid,
4083                 (void *)&cmd_gro_show_keyword,
4084                 NULL,
4085         },
4086 };
4087
4088 /* *** SET FLUSH CYCLES FOR GRO *** */
4089 struct cmd_gro_flush_result {
4090         cmdline_fixed_string_t cmd_set;
4091         cmdline_fixed_string_t cmd_keyword;
4092         cmdline_fixed_string_t cmd_flush;
4093         uint8_t cmd_cycles;
4094 };
4095
4096 static void
4097 cmd_gro_flush_parsed(void *parsed_result,
4098                 __attribute__((unused)) struct cmdline *cl,
4099                 __attribute__((unused)) void *data)
4100 {
4101         struct cmd_gro_flush_result *res;
4102
4103         res = parsed_result;
4104         if ((!strcmp(res->cmd_keyword, "gro")) &&
4105                         (!strcmp(res->cmd_flush, "flush")))
4106                 setup_gro_flush_cycles(res->cmd_cycles);
4107 }
4108
4109 cmdline_parse_token_string_t cmd_gro_flush_set =
4110         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4111                         cmd_set, "set");
4112 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4113         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4114                         cmd_keyword, "gro");
4115 cmdline_parse_token_string_t cmd_gro_flush_flush =
4116         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4117                         cmd_flush, "flush");
4118 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4119         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4120                         cmd_cycles, UINT8);
4121
4122 cmdline_parse_inst_t cmd_gro_flush = {
4123         .f = cmd_gro_flush_parsed,
4124         .data = NULL,
4125         .help_str = "set gro flush <cycles>",
4126         .tokens = {
4127                 (void *)&cmd_gro_flush_set,
4128                 (void *)&cmd_gro_flush_keyword,
4129                 (void *)&cmd_gro_flush_flush,
4130                 (void *)&cmd_gro_flush_cycles,
4131                 NULL,
4132         },
4133 };
4134
4135 /* *** ENABLE/DISABLE GSO *** */
4136 struct cmd_gso_enable_result {
4137         cmdline_fixed_string_t cmd_set;
4138         cmdline_fixed_string_t cmd_port;
4139         cmdline_fixed_string_t cmd_keyword;
4140         cmdline_fixed_string_t cmd_mode;
4141         portid_t cmd_pid;
4142 };
4143
4144 static void
4145 cmd_gso_enable_parsed(void *parsed_result,
4146                 __attribute__((unused)) struct cmdline *cl,
4147                 __attribute__((unused)) void *data)
4148 {
4149         struct cmd_gso_enable_result *res;
4150
4151         res = parsed_result;
4152         if (!strcmp(res->cmd_keyword, "gso"))
4153                 setup_gso(res->cmd_mode, res->cmd_pid);
4154 }
4155
4156 cmdline_parse_token_string_t cmd_gso_enable_set =
4157         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4158                         cmd_set, "set");
4159 cmdline_parse_token_string_t cmd_gso_enable_port =
4160         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4161                         cmd_port, "port");
4162 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4163         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4164                         cmd_keyword, "gso");
4165 cmdline_parse_token_string_t cmd_gso_enable_mode =
4166         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4167                         cmd_mode, "on#off");
4168 cmdline_parse_token_num_t cmd_gso_enable_pid =
4169         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4170                         cmd_pid, UINT16);
4171
4172 cmdline_parse_inst_t cmd_gso_enable = {
4173         .f = cmd_gso_enable_parsed,
4174         .data = NULL,
4175         .help_str = "set port <port_id> gso on|off",
4176         .tokens = {
4177                 (void *)&cmd_gso_enable_set,
4178                 (void *)&cmd_gso_enable_port,
4179                 (void *)&cmd_gso_enable_pid,
4180                 (void *)&cmd_gso_enable_keyword,
4181                 (void *)&cmd_gso_enable_mode,
4182                 NULL,
4183         },
4184 };
4185
4186 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4187 struct cmd_gso_size_result {
4188         cmdline_fixed_string_t cmd_set;
4189         cmdline_fixed_string_t cmd_keyword;
4190         cmdline_fixed_string_t cmd_segsz;
4191         uint16_t cmd_size;
4192 };
4193
4194 static void
4195 cmd_gso_size_parsed(void *parsed_result,
4196                        __attribute__((unused)) struct cmdline *cl,
4197                        __attribute__((unused)) void *data)
4198 {
4199         struct cmd_gso_size_result *res = parsed_result;
4200
4201         if (test_done == 0) {
4202                 printf("Before setting GSO segsz, please first"
4203                                 " stop fowarding\n");
4204                 return;
4205         }
4206
4207         if (!strcmp(res->cmd_keyword, "gso") &&
4208                         !strcmp(res->cmd_segsz, "segsz")) {
4209                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4210                         printf("gso_size should be larger than %zu."
4211                                         " Please input a legal value\n",
4212                                         RTE_GSO_SEG_SIZE_MIN);
4213                 else
4214                         gso_max_segment_size = res->cmd_size;
4215         }
4216 }
4217
4218 cmdline_parse_token_string_t cmd_gso_size_set =
4219         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4220                                 cmd_set, "set");
4221 cmdline_parse_token_string_t cmd_gso_size_keyword =
4222         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4223                                 cmd_keyword, "gso");
4224 cmdline_parse_token_string_t cmd_gso_size_segsz =
4225         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4226                                 cmd_segsz, "segsz");
4227 cmdline_parse_token_num_t cmd_gso_size_size =
4228         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4229                                 cmd_size, UINT16);
4230
4231 cmdline_parse_inst_t cmd_gso_size = {
4232         .f = cmd_gso_size_parsed,
4233         .data = NULL,
4234         .help_str = "set gso segsz <length>",
4235         .tokens = {
4236                 (void *)&cmd_gso_size_set,
4237                 (void *)&cmd_gso_size_keyword,
4238                 (void *)&cmd_gso_size_segsz,
4239                 (void *)&cmd_gso_size_size,
4240                 NULL,
4241         },
4242 };
4243
4244 /* *** SHOW GSO CONFIGURATION *** */
4245 struct cmd_gso_show_result {
4246         cmdline_fixed_string_t cmd_show;
4247         cmdline_fixed_string_t cmd_port;
4248         cmdline_fixed_string_t cmd_keyword;
4249         portid_t cmd_pid;
4250 };
4251
4252 static void
4253 cmd_gso_show_parsed(void *parsed_result,
4254                        __attribute__((unused)) struct cmdline *cl,
4255                        __attribute__((unused)) void *data)
4256 {
4257         struct cmd_gso_show_result *res = parsed_result;
4258
4259         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4260                 printf("invalid port id %u\n", res->cmd_pid);
4261                 return;
4262         }
4263         if (!strcmp(res->cmd_keyword, "gso")) {
4264                 if (gso_ports[res->cmd_pid].enable) {
4265                         printf("Max GSO'd packet size: %uB\n"
4266                                         "Supported GSO types: TCP/IPv4, "
4267                                         "VxLAN with inner TCP/IPv4 packet, "
4268                                         "GRE with inner TCP/IPv4  packet\n",
4269                                         gso_max_segment_size);
4270                 } else
4271                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4272         }
4273 }
4274
4275 cmdline_parse_token_string_t cmd_gso_show_show =
4276 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4277                 cmd_show, "show");
4278 cmdline_parse_token_string_t cmd_gso_show_port =
4279 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4280                 cmd_port, "port");
4281 cmdline_parse_token_string_t cmd_gso_show_keyword =
4282         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4283                                 cmd_keyword, "gso");
4284 cmdline_parse_token_num_t cmd_gso_show_pid =
4285         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4286                                 cmd_pid, UINT16);
4287
4288 cmdline_parse_inst_t cmd_gso_show = {
4289         .f = cmd_gso_show_parsed,
4290         .data = NULL,
4291         .help_str = "show port <port_id> gso",
4292         .tokens = {
4293                 (void *)&cmd_gso_show_show,
4294                 (void *)&cmd_gso_show_port,
4295                 (void *)&cmd_gso_show_pid,
4296                 (void *)&cmd_gso_show_keyword,
4297                 NULL,
4298         },
4299 };
4300
4301 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4302 struct cmd_set_flush_rx {
4303         cmdline_fixed_string_t set;
4304         cmdline_fixed_string_t flush_rx;
4305         cmdline_fixed_string_t mode;
4306 };
4307
4308 static void
4309 cmd_set_flush_rx_parsed(void *parsed_result,
4310                 __attribute__((unused)) struct cmdline *cl,
4311                 __attribute__((unused)) void *data)
4312 {
4313         struct cmd_set_flush_rx *res = parsed_result;
4314         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4315 }
4316
4317 cmdline_parse_token_string_t cmd_setflushrx_set =
4318         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4319                         set, "set");
4320 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4321         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4322                         flush_rx, "flush_rx");
4323 cmdline_parse_token_string_t cmd_setflushrx_mode =
4324         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4325                         mode, "on#off");
4326
4327
4328 cmdline_parse_inst_t cmd_set_flush_rx = {
4329         .f = cmd_set_flush_rx_parsed,
4330         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4331         .data = NULL,
4332         .tokens = {
4333                 (void *)&cmd_setflushrx_set,
4334                 (void *)&cmd_setflushrx_flush_rx,
4335                 (void *)&cmd_setflushrx_mode,
4336                 NULL,
4337         },
4338 };
4339
4340 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4341 struct cmd_set_link_check {
4342         cmdline_fixed_string_t set;
4343         cmdline_fixed_string_t link_check;
4344         cmdline_fixed_string_t mode;
4345 };
4346
4347 static void
4348 cmd_set_link_check_parsed(void *parsed_result,
4349                 __attribute__((unused)) struct cmdline *cl,
4350                 __attribute__((unused)) void *data)
4351 {
4352         struct cmd_set_link_check *res = parsed_result;
4353         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4354 }
4355
4356 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4357         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4358                         set, "set");
4359 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4360         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4361                         link_check, "link_check");
4362 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4363         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4364                         mode, "on#off");
4365
4366
4367 cmdline_parse_inst_t cmd_set_link_check = {
4368         .f = cmd_set_link_check_parsed,
4369         .help_str = "set link_check on|off: Enable/Disable link status check "
4370                     "when starting/stopping a port",
4371         .data = NULL,
4372         .tokens = {
4373                 (void *)&cmd_setlinkcheck_set,
4374                 (void *)&cmd_setlinkcheck_link_check,
4375                 (void *)&cmd_setlinkcheck_mode,
4376                 NULL,
4377         },
4378 };
4379
4380 /* *** SET NIC BYPASS MODE *** */
4381 struct cmd_set_bypass_mode_result {
4382         cmdline_fixed_string_t set;
4383         cmdline_fixed_string_t bypass;
4384         cmdline_fixed_string_t mode;
4385         cmdline_fixed_string_t value;
4386         portid_t port_id;
4387 };
4388
4389 static void
4390 cmd_set_bypass_mode_parsed(void *parsed_result,
4391                 __attribute__((unused)) struct cmdline *cl,
4392                 __attribute__((unused)) void *data)
4393 {
4394         struct cmd_set_bypass_mode_result *res = parsed_result;
4395         portid_t port_id = res->port_id;
4396         int32_t rc = -EINVAL;
4397
4398 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4399         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4400
4401         if (!strcmp(res->value, "bypass"))
4402                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4403         else if (!strcmp(res->value, "isolate"))
4404                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4405         else
4406                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4407
4408         /* Set the bypass mode for the relevant port. */
4409         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4410 #endif
4411         if (rc != 0)
4412                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4413 }
4414
4415 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4416         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4417                         set, "set");
4418 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4419         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4420                         bypass, "bypass");
4421 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4422         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4423                         mode, "mode");
4424 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4425         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4426                         value, "normal#bypass#isolate");
4427 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4428         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4429                                 port_id, UINT16);
4430
4431 cmdline_parse_inst_t cmd_set_bypass_mode = {
4432         .f = cmd_set_bypass_mode_parsed,
4433         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4434                     "Set the NIC bypass mode for port_id",
4435         .data = NULL,
4436         .tokens = {
4437                 (void *)&cmd_setbypass_mode_set,
4438                 (void *)&cmd_setbypass_mode_bypass,
4439                 (void *)&cmd_setbypass_mode_mode,
4440                 (void *)&cmd_setbypass_mode_value,
4441                 (void *)&cmd_setbypass_mode_port,
4442                 NULL,
4443         },
4444 };
4445
4446 /* *** SET NIC BYPASS EVENT *** */
4447 struct cmd_set_bypass_event_result {
4448         cmdline_fixed_string_t set;
4449         cmdline_fixed_string_t bypass;
4450         cmdline_fixed_string_t event;
4451         cmdline_fixed_string_t event_value;
4452         cmdline_fixed_string_t mode;
4453         cmdline_fixed_string_t mode_value;
4454         portid_t port_id;
4455 };
4456
4457 static void
4458 cmd_set_bypass_event_parsed(void *parsed_result,
4459                 __attribute__((unused)) struct cmdline *cl,
4460                 __attribute__((unused)) void *data)
4461 {
4462         int32_t rc = -EINVAL;
4463         struct cmd_set_bypass_event_result *res = parsed_result;
4464         portid_t port_id = res->port_id;
4465
4466 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4467         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4468         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4469
4470         if (!strcmp(res->event_value, "timeout"))
4471                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4472         else if (!strcmp(res->event_value, "os_on"))
4473                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4474         else if (!strcmp(res->event_value, "os_off"))
4475                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4476         else if (!strcmp(res->event_value, "power_on"))
4477                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4478         else if (!strcmp(res->event_value, "power_off"))
4479                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4480         else
4481                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4482
4483         if (!strcmp(res->mode_value, "bypass"))
4484                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4485         else if (!strcmp(res->mode_value, "isolate"))
4486                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4487         else
4488                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4489
4490         /* Set the watchdog timeout. */
4491         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4492
4493                 rc = -EINVAL;
4494                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4495                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4496                                                            bypass_timeout);
4497                 }
4498                 if (rc != 0) {
4499                         printf("Failed to set timeout value %u "
4500                         "for port %d, errto code: %d.\n",
4501                         bypass_timeout, port_id, rc);
4502                 }
4503         }
4504
4505         /* Set the bypass event to transition to bypass mode. */
4506         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4507                                               bypass_mode);
4508 #endif
4509
4510         if (rc != 0)
4511                 printf("\t Failed to set bypass event for port = %d.\n",
4512                        port_id);
4513 }
4514
4515 cmdline_parse_token_string_t cmd_setbypass_event_set =
4516         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4517                         set, "set");
4518 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4519         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4520                         bypass, "bypass");
4521 cmdline_parse_token_string_t cmd_setbypass_event_event =
4522         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4523                         event, "event");
4524 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4525         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4526                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4527 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4528         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4529                         mode, "mode");
4530 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4531         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4532                         mode_value, "normal#bypass#isolate");
4533 cmdline_parse_token_num_t cmd_setbypass_event_port =
4534         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4535                                 port_id, UINT16);
4536
4537 cmdline_parse_inst_t cmd_set_bypass_event = {
4538         .f = cmd_set_bypass_event_parsed,
4539         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4540                 "power_off mode normal|bypass|isolate <port_id>: "
4541                 "Set the NIC bypass event mode for port_id",
4542         .data = NULL,
4543         .tokens = {
4544                 (void *)&cmd_setbypass_event_set,
4545                 (void *)&cmd_setbypass_event_bypass,
4546                 (void *)&cmd_setbypass_event_event,
4547                 (void *)&cmd_setbypass_event_event_value,
4548                 (void *)&cmd_setbypass_event_mode,
4549                 (void *)&cmd_setbypass_event_mode_value,
4550                 (void *)&cmd_setbypass_event_port,
4551                 NULL,
4552         },
4553 };
4554
4555
4556 /* *** SET NIC BYPASS TIMEOUT *** */
4557 struct cmd_set_bypass_timeout_result {
4558         cmdline_fixed_string_t set;
4559         cmdline_fixed_string_t bypass;
4560         cmdline_fixed_string_t timeout;
4561         cmdline_fixed_string_t value;
4562 };
4563
4564 static void
4565 cmd_set_bypass_timeout_parsed(void *parsed_result,
4566                 __attribute__((unused)) struct cmdline *cl,
4567                 __attribute__((unused)) void *data)
4568 {
4569         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4570
4571 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4572         if (!strcmp(res->value, "1.5"))
4573                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4574         else if (!strcmp(res->value, "2"))
4575                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4576         else if (!strcmp(res->value, "3"))
4577                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4578         else if (!strcmp(res->value, "4"))
4579                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4580         else if (!strcmp(res->value, "8"))
4581                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4582         else if (!strcmp(res->value, "16"))
4583                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4584         else if (!strcmp(res->value, "32"))
4585                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4586         else
4587                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4588 #endif
4589 }
4590
4591 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4592         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4593                         set, "set");
4594 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4595         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4596                         bypass, "bypass");
4597 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4598         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4599                         timeout, "timeout");
4600 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4601         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4602                         value, "0#1.5#2#3#4#8#16#32");
4603
4604 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4605         .f = cmd_set_bypass_timeout_parsed,
4606         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4607                 "Set the NIC bypass watchdog timeout in seconds",
4608         .data = NULL,
4609         .tokens = {
4610                 (void *)&cmd_setbypass_timeout_set,
4611                 (void *)&cmd_setbypass_timeout_bypass,
4612                 (void *)&cmd_setbypass_timeout_timeout,
4613                 (void *)&cmd_setbypass_timeout_value,
4614                 NULL,
4615         },
4616 };
4617
4618 /* *** SHOW NIC BYPASS MODE *** */
4619 struct cmd_show_bypass_config_result {
4620         cmdline_fixed_string_t show;
4621         cmdline_fixed_string_t bypass;
4622         cmdline_fixed_string_t config;
4623         portid_t port_id;
4624 };
4625
4626 static void
4627 cmd_show_bypass_config_parsed(void *parsed_result,
4628                 __attribute__((unused)) struct cmdline *cl,
4629                 __attribute__((unused)) void *data)
4630 {
4631         struct cmd_show_bypass_config_result *res = parsed_result;
4632         portid_t port_id = res->port_id;
4633         int rc = -EINVAL;
4634 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4635         uint32_t event_mode;
4636         uint32_t bypass_mode;
4637         uint32_t timeout = bypass_timeout;
4638         int i;
4639
4640         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4641                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4642         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4643                 {"UNKNOWN", "normal", "bypass", "isolate"};
4644         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4645                 "NONE",
4646                 "OS/board on",
4647                 "power supply on",
4648                 "OS/board off",
4649                 "power supply off",
4650                 "timeout"};
4651         int num_events = (sizeof events) / (sizeof events[0]);
4652
4653         /* Display the bypass mode.*/
4654         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4655                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4656                 return;
4657         }
4658         else {
4659                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4660                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4661
4662                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4663         }
4664
4665         /* Display the bypass timeout.*/
4666         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4667                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4668
4669         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4670
4671         /* Display the bypass events and associated modes. */
4672         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4673
4674                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4675                         printf("\tFailed to get bypass mode for event = %s\n",
4676                                 events[i]);
4677                 } else {
4678                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4679                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4680
4681                         printf("\tbypass event: %-16s = %s\n", events[i],
4682                                 modes[event_mode]);
4683                 }
4684         }
4685 #endif
4686         if (rc != 0)
4687                 printf("\tFailed to get bypass configuration for port = %d\n",
4688                        port_id);
4689 }
4690
4691 cmdline_parse_token_string_t cmd_showbypass_config_show =
4692         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4693                         show, "show");
4694 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4695         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4696                         bypass, "bypass");
4697 cmdline_parse_token_string_t cmd_showbypass_config_config =
4698         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4699                         config, "config");
4700 cmdline_parse_token_num_t cmd_showbypass_config_port =
4701         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4702                                 port_id, UINT16);
4703
4704 cmdline_parse_inst_t cmd_show_bypass_config = {
4705         .f = cmd_show_bypass_config_parsed,
4706         .help_str = "show bypass config <port_id>: "
4707                     "Show the NIC bypass config for port_id",
4708         .data = NULL,
4709         .tokens = {
4710                 (void *)&cmd_showbypass_config_show,
4711                 (void *)&cmd_showbypass_config_bypass,
4712                 (void *)&cmd_showbypass_config_config,
4713                 (void *)&cmd_showbypass_config_port,
4714                 NULL,
4715         },
4716 };
4717
4718 #ifdef RTE_LIBRTE_PMD_BOND
4719 /* *** SET BONDING MODE *** */
4720 struct cmd_set_bonding_mode_result {
4721         cmdline_fixed_string_t set;
4722         cmdline_fixed_string_t bonding;
4723         cmdline_fixed_string_t mode;
4724         uint8_t value;
4725         portid_t port_id;
4726 };
4727
4728 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4729                 __attribute__((unused))  struct cmdline *cl,
4730                 __attribute__((unused)) void *data)
4731 {
4732         struct cmd_set_bonding_mode_result *res = parsed_result;
4733         portid_t port_id = res->port_id;
4734
4735         /* Set the bonding mode for the relevant port. */
4736         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4737                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4738 }
4739
4740 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4741 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4742                 set, "set");
4743 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4744 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4745                 bonding, "bonding");
4746 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4747 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4748                 mode, "mode");
4749 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4750 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4751                 value, UINT8);
4752 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4753 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4754                 port_id, UINT16);
4755
4756 cmdline_parse_inst_t cmd_set_bonding_mode = {
4757                 .f = cmd_set_bonding_mode_parsed,
4758                 .help_str = "set bonding mode <mode_value> <port_id>: "
4759                         "Set the bonding mode for port_id",
4760                 .data = NULL,
4761                 .tokens = {
4762                                 (void *) &cmd_setbonding_mode_set,
4763                                 (void *) &cmd_setbonding_mode_bonding,
4764                                 (void *) &cmd_setbonding_mode_mode,
4765                                 (void *) &cmd_setbonding_mode_value,
4766                                 (void *) &cmd_setbonding_mode_port,
4767                                 NULL
4768                 }
4769 };
4770
4771 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4772 struct cmd_set_bonding_lacp_dedicated_queues_result {
4773         cmdline_fixed_string_t set;
4774         cmdline_fixed_string_t bonding;
4775         cmdline_fixed_string_t lacp;
4776         cmdline_fixed_string_t dedicated_queues;
4777         portid_t port_id;
4778         cmdline_fixed_string_t mode;
4779 };
4780
4781 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4782                 __attribute__((unused))  struct cmdline *cl,
4783                 __attribute__((unused)) void *data)
4784 {
4785         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4786         portid_t port_id = res->port_id;
4787         struct rte_port *port;
4788
4789         port = &ports[port_id];
4790
4791         /** Check if the port is not started **/
4792         if (port->port_status != RTE_PORT_STOPPED) {
4793                 printf("Please stop port %d first\n", port_id);
4794                 return;
4795         }
4796
4797         if (!strcmp(res->mode, "enable")) {
4798                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4799                         printf("Dedicate queues for LACP control packets"
4800                                         " enabled\n");
4801                 else
4802                         printf("Enabling dedicate queues for LACP control "
4803                                         "packets on port %d failed\n", port_id);
4804         } else if (!strcmp(res->mode, "disable")) {
4805                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4806                         printf("Dedicated queues for LACP control packets "
4807                                         "disabled\n");
4808                 else
4809                         printf("Disabling dedicated queues for LACP control "
4810                                         "traffic on port %d failed\n", port_id);
4811         }
4812 }
4813
4814 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4815 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4816                 set, "set");
4817 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4818 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4819                 bonding, "bonding");
4820 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4821 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4822                 lacp, "lacp");
4823 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4824 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4825                 dedicated_queues, "dedicated_queues");
4826 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4827 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4828                 port_id, UINT16);
4829 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4830 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4831                 mode, "enable#disable");
4832
4833 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4834                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4835                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4836                         "enable|disable: "
4837                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4838                 .data = NULL,
4839                 .tokens = {
4840                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4841                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4842                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4843                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4844                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4845                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4846                         NULL
4847                 }
4848 };
4849
4850 /* *** SET BALANCE XMIT POLICY *** */
4851 struct cmd_set_bonding_balance_xmit_policy_result {
4852         cmdline_fixed_string_t set;
4853         cmdline_fixed_string_t bonding;
4854         cmdline_fixed_string_t balance_xmit_policy;
4855         portid_t port_id;
4856         cmdline_fixed_string_t policy;
4857 };
4858
4859 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4860                 __attribute__((unused))  struct cmdline *cl,
4861                 __attribute__((unused)) void *data)
4862 {
4863         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4864         portid_t port_id = res->port_id;
4865         uint8_t policy;
4866
4867         if (!strcmp(res->policy, "l2")) {
4868                 policy = BALANCE_XMIT_POLICY_LAYER2;
4869         } else if (!strcmp(res->policy, "l23")) {
4870                 policy = BALANCE_XMIT_POLICY_LAYER23;
4871         } else if (!strcmp(res->policy, "l34")) {
4872                 policy = BALANCE_XMIT_POLICY_LAYER34;
4873         } else {
4874                 printf("\t Invalid xmit policy selection");
4875                 return;
4876         }
4877
4878         /* Set the bonding mode for the relevant port. */
4879         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4880                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4881                                 port_id);
4882         }
4883 }
4884
4885 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4886 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4887                 set, "set");
4888 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4889 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4890                 bonding, "bonding");
4891 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4892 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4893                 balance_xmit_policy, "balance_xmit_policy");
4894 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4895 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4896                 port_id, UINT16);
4897 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4898 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4899                 policy, "l2#l23#l34");
4900
4901 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4902                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4903                 .help_str = "set bonding balance_xmit_policy <port_id> "
4904                         "l2|l23|l34: "
4905                         "Set the bonding balance_xmit_policy for port_id",
4906                 .data = NULL,
4907                 .tokens = {
4908                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4909                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4910                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4911                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4912                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4913                                 NULL
4914                 }
4915 };
4916
4917 /* *** SHOW NIC BONDING CONFIGURATION *** */
4918 struct cmd_show_bonding_config_result {
4919         cmdline_fixed_string_t show;
4920         cmdline_fixed_string_t bonding;
4921         cmdline_fixed_string_t config;
4922         portid_t port_id;
4923 };
4924
4925 static void cmd_show_bonding_config_parsed(void *parsed_result,
4926                 __attribute__((unused))  struct cmdline *cl,
4927                 __attribute__((unused)) void *data)
4928 {
4929         struct cmd_show_bonding_config_result *res = parsed_result;
4930         int bonding_mode, agg_mode;
4931         portid_t slaves[RTE_MAX_ETHPORTS];
4932         int num_slaves, num_active_slaves;
4933         int primary_id;
4934         int i;
4935         portid_t port_id = res->port_id;
4936
4937         /* Display the bonding mode.*/
4938         bonding_mode = rte_eth_bond_mode_get(port_id);
4939         if (bonding_mode < 0) {
4940                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4941                 return;
4942         } else
4943                 printf("\tBonding mode: %d\n", bonding_mode);
4944
4945         if (bonding_mode == BONDING_MODE_BALANCE) {
4946                 int balance_xmit_policy;
4947
4948                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4949                 if (balance_xmit_policy < 0) {
4950                         printf("\tFailed to get balance xmit policy for port = %d\n",
4951                                         port_id);
4952                         return;
4953                 } else {
4954                         printf("\tBalance Xmit Policy: ");
4955
4956                         switch (balance_xmit_policy) {
4957                         case BALANCE_XMIT_POLICY_LAYER2:
4958                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4959                                 break;
4960                         case BALANCE_XMIT_POLICY_LAYER23:
4961                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4962                                 break;
4963                         case BALANCE_XMIT_POLICY_LAYER34:
4964                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4965                                 break;
4966                         }
4967                         printf("\n");
4968                 }
4969         }
4970
4971         if (bonding_mode == BONDING_MODE_8023AD) {
4972                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4973                 printf("\tIEEE802.3AD Aggregator Mode: ");
4974                 switch (agg_mode) {
4975                 case AGG_BANDWIDTH:
4976                         printf("bandwidth");
4977                         break;
4978                 case AGG_STABLE:
4979                         printf("stable");
4980                         break;
4981                 case AGG_COUNT:
4982                         printf("count");
4983                         break;
4984                 }
4985                 printf("\n");
4986         }
4987
4988         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4989
4990         if (num_slaves < 0) {
4991                 printf("\tFailed to get slave list for port = %d\n", port_id);
4992                 return;
4993         }
4994         if (num_slaves > 0) {
4995                 printf("\tSlaves (%d): [", num_slaves);
4996                 for (i = 0; i < num_slaves - 1; i++)
4997                         printf("%d ", slaves[i]);
4998
4999                 printf("%d]\n", slaves[num_slaves - 1]);
5000         } else {
5001                 printf("\tSlaves: []\n");
5002
5003         }
5004
5005         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5006                         RTE_MAX_ETHPORTS);
5007
5008         if (num_active_slaves < 0) {
5009                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5010                 return;
5011         }
5012         if (num_active_slaves > 0) {
5013                 printf("\tActive Slaves (%d): [", num_active_slaves);
5014                 for (i = 0; i < num_active_slaves - 1; i++)
5015                         printf("%d ", slaves[i]);
5016
5017                 printf("%d]\n", slaves[num_active_slaves - 1]);
5018
5019         } else {
5020                 printf("\tActive Slaves: []\n");
5021
5022         }
5023
5024         primary_id = rte_eth_bond_primary_get(port_id);
5025         if (primary_id < 0) {
5026                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5027                 return;
5028         } else
5029                 printf("\tPrimary: [%d]\n", primary_id);
5030
5031 }
5032
5033 cmdline_parse_token_string_t cmd_showbonding_config_show =
5034 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5035                 show, "show");
5036 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5037 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5038                 bonding, "bonding");
5039 cmdline_parse_token_string_t cmd_showbonding_config_config =
5040 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5041                 config, "config");
5042 cmdline_parse_token_num_t cmd_showbonding_config_port =
5043 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5044                 port_id, UINT16);
5045
5046 cmdline_parse_inst_t cmd_show_bonding_config = {
5047                 .f = cmd_show_bonding_config_parsed,
5048                 .help_str = "show bonding config <port_id>: "
5049                         "Show the bonding config for port_id",
5050                 .data = NULL,
5051                 .tokens = {
5052                                 (void *)&cmd_showbonding_config_show,
5053                                 (void *)&cmd_showbonding_config_bonding,
5054                                 (void *)&cmd_showbonding_config_config,
5055                                 (void *)&cmd_showbonding_config_port,
5056                                 NULL
5057                 }
5058 };
5059
5060 /* *** SET BONDING PRIMARY *** */
5061 struct cmd_set_bonding_primary_result {
5062         cmdline_fixed_string_t set;
5063         cmdline_fixed_string_t bonding;
5064         cmdline_fixed_string_t primary;
5065         portid_t slave_id;
5066         portid_t port_id;
5067 };
5068
5069 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5070                 __attribute__((unused))  struct cmdline *cl,
5071                 __attribute__((unused)) void *data)
5072 {
5073         struct cmd_set_bonding_primary_result *res = parsed_result;
5074         portid_t master_port_id = res->port_id;
5075         portid_t slave_port_id = res->slave_id;
5076
5077         /* Set the primary slave for a bonded device. */
5078         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5079                 printf("\t Failed to set primary slave for port = %d.\n",
5080                                 master_port_id);
5081                 return;
5082         }
5083         init_port_config();
5084 }
5085
5086 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5087 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5088                 set, "set");
5089 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5090 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5091                 bonding, "bonding");
5092 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5093 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5094                 primary, "primary");
5095 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5096 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5097                 slave_id, UINT16);
5098 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5099 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5100                 port_id, UINT16);
5101
5102 cmdline_parse_inst_t cmd_set_bonding_primary = {
5103                 .f = cmd_set_bonding_primary_parsed,
5104                 .help_str = "set bonding primary <slave_id> <port_id>: "
5105                         "Set the primary slave for port_id",
5106                 .data = NULL,
5107                 .tokens = {
5108                                 (void *)&cmd_setbonding_primary_set,
5109                                 (void *)&cmd_setbonding_primary_bonding,
5110                                 (void *)&cmd_setbonding_primary_primary,
5111                                 (void *)&cmd_setbonding_primary_slave,
5112                                 (void *)&cmd_setbonding_primary_port,
5113                                 NULL
5114                 }
5115 };
5116
5117 /* *** ADD SLAVE *** */
5118 struct cmd_add_bonding_slave_result {
5119         cmdline_fixed_string_t add;
5120         cmdline_fixed_string_t bonding;
5121         cmdline_fixed_string_t slave;
5122         portid_t slave_id;
5123         portid_t port_id;
5124 };
5125
5126 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5127                 __attribute__((unused))  struct cmdline *cl,
5128                 __attribute__((unused)) void *data)
5129 {
5130         struct cmd_add_bonding_slave_result *res = parsed_result;
5131         portid_t master_port_id = res->port_id;
5132         portid_t slave_port_id = res->slave_id;
5133
5134         /* add the slave for a bonded device. */
5135         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5136                 printf("\t Failed to add slave %d to master port = %d.\n",
5137                                 slave_port_id, master_port_id);
5138                 return;
5139         }
5140         init_port_config();
5141         set_port_slave_flag(slave_port_id);
5142 }
5143
5144 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5145 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5146                 add, "add");
5147 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5148 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5149                 bonding, "bonding");
5150 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5151 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5152                 slave, "slave");
5153 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5154 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5155                 slave_id, UINT16);
5156 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5157 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5158                 port_id, UINT16);
5159
5160 cmdline_parse_inst_t cmd_add_bonding_slave = {
5161                 .f = cmd_add_bonding_slave_parsed,
5162                 .help_str = "add bonding slave <slave_id> <port_id>: "
5163                         "Add a slave device to a bonded device",
5164                 .data = NULL,
5165                 .tokens = {
5166                                 (void *)&cmd_addbonding_slave_add,
5167                                 (void *)&cmd_addbonding_slave_bonding,
5168                                 (void *)&cmd_addbonding_slave_slave,
5169                                 (void *)&cmd_addbonding_slave_slaveid,
5170                                 (void *)&cmd_addbonding_slave_port,
5171                                 NULL
5172                 }
5173 };
5174
5175 /* *** REMOVE SLAVE *** */
5176 struct cmd_remove_bonding_slave_result {
5177         cmdline_fixed_string_t remove;
5178         cmdline_fixed_string_t bonding;
5179         cmdline_fixed_string_t slave;
5180         portid_t slave_id;
5181         portid_t port_id;
5182 };
5183
5184 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5185                 __attribute__((unused))  struct cmdline *cl,
5186                 __attribute__((unused)) void *data)
5187 {
5188         struct cmd_remove_bonding_slave_result *res = parsed_result;
5189         portid_t master_port_id = res->port_id;
5190         portid_t slave_port_id = res->slave_id;
5191
5192         /* remove the slave from a bonded device. */
5193         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5194                 printf("\t Failed to remove slave %d from master port = %d.\n",
5195                                 slave_port_id, master_port_id);
5196                 return;
5197         }
5198         init_port_config();
5199         clear_port_slave_flag(slave_port_id);
5200 }
5201
5202 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5203                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5204                                 remove, "remove");
5205 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5206                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5207                                 bonding, "bonding");
5208 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5209                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5210                                 slave, "slave");
5211 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5212                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5213                                 slave_id, UINT16);
5214 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5215                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5216                                 port_id, UINT16);
5217
5218 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5219                 .f = cmd_remove_bonding_slave_parsed,
5220                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5221                         "Remove a slave device from a bonded device",
5222                 .data = NULL,
5223                 .tokens = {
5224                                 (void *)&cmd_removebonding_slave_remove,
5225                                 (void *)&cmd_removebonding_slave_bonding,
5226                                 (void *)&cmd_removebonding_slave_slave,
5227                                 (void *)&cmd_removebonding_slave_slaveid,
5228                                 (void *)&cmd_removebonding_slave_port,
5229                                 NULL
5230                 }
5231 };
5232
5233 /* *** CREATE BONDED DEVICE *** */
5234 struct cmd_create_bonded_device_result {
5235         cmdline_fixed_string_t create;
5236         cmdline_fixed_string_t bonded;
5237         cmdline_fixed_string_t device;
5238         uint8_t mode;
5239         uint8_t socket;
5240 };
5241
5242 static int bond_dev_num = 0;
5243
5244 static void cmd_create_bonded_device_parsed(void *parsed_result,
5245                 __attribute__((unused))  struct cmdline *cl,
5246                 __attribute__((unused)) void *data)
5247 {
5248         struct cmd_create_bonded_device_result *res = parsed_result;
5249         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5250         int port_id;
5251
5252         if (test_done == 0) {
5253                 printf("Please stop forwarding first\n");
5254                 return;
5255         }
5256
5257         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5258                         bond_dev_num++);
5259
5260         /* Create a new bonded device. */
5261         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5262         if (port_id < 0) {
5263                 printf("\t Failed to create bonded device.\n");
5264                 return;
5265         } else {
5266                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5267                                 port_id);
5268
5269                 /* Update number of ports */
5270                 nb_ports = rte_eth_dev_count();
5271                 reconfig(port_id, res->socket);
5272                 rte_eth_promiscuous_enable(port_id);
5273         }
5274
5275 }
5276
5277 cmdline_parse_token_string_t cmd_createbonded_device_create =
5278                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5279                                 create, "create");
5280 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5281                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5282                                 bonded, "bonded");
5283 cmdline_parse_token_string_t cmd_createbonded_device_device =
5284                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5285                                 device, "device");
5286 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5287                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5288                                 mode, UINT8);
5289 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5290                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5291                                 socket, UINT8);
5292
5293 cmdline_parse_inst_t cmd_create_bonded_device = {
5294                 .f = cmd_create_bonded_device_parsed,
5295                 .help_str = "create bonded device <mode> <socket>: "
5296                         "Create a new bonded device with specific bonding mode and socket",
5297                 .data = NULL,
5298                 .tokens = {
5299                                 (void *)&cmd_createbonded_device_create,
5300                                 (void *)&cmd_createbonded_device_bonded,
5301                                 (void *)&cmd_createbonded_device_device,
5302                                 (void *)&cmd_createbonded_device_mode,
5303                                 (void *)&cmd_createbonded_device_socket,
5304                                 NULL
5305                 }
5306 };
5307
5308 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5309 struct cmd_set_bond_mac_addr_result {
5310         cmdline_fixed_string_t set;
5311         cmdline_fixed_string_t bonding;
5312         cmdline_fixed_string_t mac_addr;
5313         uint16_t port_num;
5314         struct ether_addr address;
5315 };
5316
5317 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5318                 __attribute__((unused))  struct cmdline *cl,
5319                 __attribute__((unused)) void *data)
5320 {
5321         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5322         int ret;
5323
5324         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5325                 return;
5326
5327         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5328
5329         /* check the return value and print it if is < 0 */
5330         if (ret < 0)
5331                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5332 }
5333
5334 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5335                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5336 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5337                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5338                                 "bonding");
5339 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5340                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5341                                 "mac_addr");
5342 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5343                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5344                                 port_num, UINT16);
5345 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5346                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5347
5348 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5349                 .f = cmd_set_bond_mac_addr_parsed,
5350                 .data = (void *) 0,
5351                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5352                 .tokens = {
5353                                 (void *)&cmd_set_bond_mac_addr_set,
5354                                 (void *)&cmd_set_bond_mac_addr_bonding,
5355                                 (void *)&cmd_set_bond_mac_addr_mac,
5356                                 (void *)&cmd_set_bond_mac_addr_portnum,
5357                                 (void *)&cmd_set_bond_mac_addr_addr,
5358                                 NULL
5359                 }
5360 };
5361
5362
5363 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5364 struct cmd_set_bond_mon_period_result {
5365         cmdline_fixed_string_t set;
5366         cmdline_fixed_string_t bonding;
5367         cmdline_fixed_string_t mon_period;
5368         uint16_t port_num;
5369         uint32_t period_ms;
5370 };
5371
5372 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5373                 __attribute__((unused))  struct cmdline *cl,
5374                 __attribute__((unused)) void *data)
5375 {
5376         struct cmd_set_bond_mon_period_result *res = parsed_result;
5377         int ret;
5378
5379         if (res->port_num >= nb_ports) {
5380                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5381                 return;
5382         }
5383
5384         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5385
5386         /* check the return value and print it if is < 0 */
5387         if (ret < 0)
5388                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5389 }
5390
5391 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5392                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5393                                 set, "set");
5394 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5395                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5396                                 bonding, "bonding");
5397 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5398                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5399                                 mon_period,     "mon_period");
5400 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5401                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5402                                 port_num, UINT16);
5403 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5404                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5405                                 period_ms, UINT32);
5406
5407 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5408                 .f = cmd_set_bond_mon_period_parsed,
5409                 .data = (void *) 0,
5410                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5411                 .tokens = {
5412                                 (void *)&cmd_set_bond_mon_period_set,
5413                                 (void *)&cmd_set_bond_mon_period_bonding,
5414                                 (void *)&cmd_set_bond_mon_period_mon_period,
5415                                 (void *)&cmd_set_bond_mon_period_portnum,
5416                                 (void *)&cmd_set_bond_mon_period_period_ms,
5417                                 NULL
5418                 }
5419 };
5420
5421
5422
5423 struct cmd_set_bonding_agg_mode_policy_result {
5424         cmdline_fixed_string_t set;
5425         cmdline_fixed_string_t bonding;
5426         cmdline_fixed_string_t agg_mode;
5427         uint16_t port_num;
5428         cmdline_fixed_string_t policy;
5429 };
5430
5431
5432 static void
5433 cmd_set_bonding_agg_mode(void *parsed_result,
5434                 __attribute__((unused)) struct cmdline *cl,
5435                 __attribute__((unused)) void *data)
5436 {
5437         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5438         uint8_t policy = AGG_BANDWIDTH;
5439
5440         if (res->port_num >= nb_ports) {
5441                 printf("Port id %d must be less than %d\n",
5442                                 res->port_num, nb_ports);
5443                 return;
5444         }
5445
5446         if (!strcmp(res->policy, "bandwidth"))
5447                 policy = AGG_BANDWIDTH;
5448         else if (!strcmp(res->policy, "stable"))
5449                 policy = AGG_STABLE;
5450         else if (!strcmp(res->policy, "count"))
5451                 policy = AGG_COUNT;
5452
5453         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5454 }
5455
5456
5457 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5458         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5459                                 set, "set");
5460 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5461         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5462                                 bonding, "bonding");
5463
5464 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5465         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5466                                 agg_mode, "agg_mode");
5467
5468 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5469         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5470                                 port_num, UINT16);
5471
5472 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5473         TOKEN_STRING_INITIALIZER(
5474                         struct cmd_set_bonding_balance_xmit_policy_result,
5475                 policy, "stable#bandwidth#count");
5476
5477 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5478         .f = cmd_set_bonding_agg_mode,
5479         .data = (void *) 0,
5480         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5481         .tokens = {
5482                         (void *)&cmd_set_bonding_agg_mode_set,
5483                         (void *)&cmd_set_bonding_agg_mode_bonding,
5484                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5485                         (void *)&cmd_set_bonding_agg_mode_portnum,
5486                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5487                         NULL
5488                 }
5489 };
5490
5491
5492 #endif /* RTE_LIBRTE_PMD_BOND */
5493
5494 /* *** SET FORWARDING MODE *** */
5495 struct cmd_set_fwd_mode_result {
5496         cmdline_fixed_string_t set;
5497         cmdline_fixed_string_t fwd;
5498         cmdline_fixed_string_t mode;
5499 };
5500
5501 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5502                                     __attribute__((unused)) struct cmdline *cl,
5503                                     __attribute__((unused)) void *data)
5504 {
5505         struct cmd_set_fwd_mode_result *res = parsed_result;
5506
5507         retry_enabled = 0;
5508         set_pkt_forwarding_mode(res->mode);
5509 }
5510
5511 cmdline_parse_token_string_t cmd_setfwd_set =
5512         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5513 cmdline_parse_token_string_t cmd_setfwd_fwd =
5514         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5515 cmdline_parse_token_string_t cmd_setfwd_mode =
5516         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5517                 "" /* defined at init */);
5518
5519 cmdline_parse_inst_t cmd_set_fwd_mode = {
5520         .f = cmd_set_fwd_mode_parsed,
5521         .data = NULL,
5522         .help_str = NULL, /* defined at init */
5523         .tokens = {
5524                 (void *)&cmd_setfwd_set,
5525                 (void *)&cmd_setfwd_fwd,
5526                 (void *)&cmd_setfwd_mode,
5527                 NULL,
5528         },
5529 };
5530
5531 static void cmd_set_fwd_mode_init(void)
5532 {
5533         char *modes, *c;
5534         static char token[128];
5535         static char help[256];
5536         cmdline_parse_token_string_t *token_struct;
5537
5538         modes = list_pkt_forwarding_modes();
5539         snprintf(help, sizeof(help), "set fwd %s: "
5540                 "Set packet forwarding mode", modes);
5541         cmd_set_fwd_mode.help_str = help;
5542
5543         /* string token separator is # */
5544         for (c = token; *modes != '\0'; modes++)
5545                 if (*modes == '|')
5546                         *c++ = '#';
5547                 else
5548                         *c++ = *modes;
5549         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5550         token_struct->string_data.str = token;
5551 }
5552
5553 /* *** SET RETRY FORWARDING MODE *** */
5554 struct cmd_set_fwd_retry_mode_result {
5555         cmdline_fixed_string_t set;
5556         cmdline_fixed_string_t fwd;
5557         cmdline_fixed_string_t mode;
5558         cmdline_fixed_string_t retry;
5559 };
5560
5561 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5562                             __attribute__((unused)) struct cmdline *cl,
5563                             __attribute__((unused)) void *data)
5564 {
5565         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5566
5567         retry_enabled = 1;
5568         set_pkt_forwarding_mode(res->mode);
5569 }
5570
5571 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5572         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5573                         set, "set");
5574 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5575         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5576                         fwd, "fwd");
5577 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5578         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5579                         mode,
5580                 "" /* defined at init */);
5581 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5582         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5583                         retry, "retry");
5584
5585 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5586         .f = cmd_set_fwd_retry_mode_parsed,
5587         .data = NULL,
5588         .help_str = NULL, /* defined at init */
5589         .tokens = {
5590                 (void *)&cmd_setfwd_retry_set,
5591                 (void *)&cmd_setfwd_retry_fwd,
5592                 (void *)&cmd_setfwd_retry_mode,
5593                 (void *)&cmd_setfwd_retry_retry,
5594                 NULL,
5595         },
5596 };
5597
5598 static void cmd_set_fwd_retry_mode_init(void)
5599 {
5600         char *modes, *c;
5601         static char token[128];
5602         static char help[256];
5603         cmdline_parse_token_string_t *token_struct;
5604
5605         modes = list_pkt_forwarding_retry_modes();
5606         snprintf(help, sizeof(help), "set fwd %s retry: "
5607                 "Set packet forwarding mode with retry", modes);
5608         cmd_set_fwd_retry_mode.help_str = help;
5609
5610         /* string token separator is # */
5611         for (c = token; *modes != '\0'; modes++)
5612                 if (*modes == '|')
5613                         *c++ = '#';
5614                 else
5615                         *c++ = *modes;
5616         token_struct = (cmdline_parse_token_string_t *)
5617                 cmd_set_fwd_retry_mode.tokens[2];
5618         token_struct->string_data.str = token;
5619 }
5620
5621 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5622 struct cmd_set_burst_tx_retry_result {
5623         cmdline_fixed_string_t set;
5624         cmdline_fixed_string_t burst;
5625         cmdline_fixed_string_t tx;
5626         cmdline_fixed_string_t delay;
5627         uint32_t time;
5628         cmdline_fixed_string_t retry;
5629         uint32_t retry_num;
5630 };
5631
5632 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5633                                         __attribute__((unused)) struct cmdline *cl,
5634                                         __attribute__((unused)) void *data)
5635 {
5636         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5637
5638         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5639                 && !strcmp(res->tx, "tx")) {
5640                 if (!strcmp(res->delay, "delay"))
5641                         burst_tx_delay_time = res->time;
5642                 if (!strcmp(res->retry, "retry"))
5643                         burst_tx_retry_num = res->retry_num;
5644         }
5645
5646 }
5647
5648 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5649         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5650 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5651         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5652                                  "burst");
5653 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5654         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5655 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5656         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5657 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5658         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5659 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5660         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5661 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5662         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5663
5664 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5665         .f = cmd_set_burst_tx_retry_parsed,
5666         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5667         .tokens = {
5668                 (void *)&cmd_set_burst_tx_retry_set,
5669                 (void *)&cmd_set_burst_tx_retry_burst,
5670                 (void *)&cmd_set_burst_tx_retry_tx,
5671                 (void *)&cmd_set_burst_tx_retry_delay,
5672                 (void *)&cmd_set_burst_tx_retry_time,
5673                 (void *)&cmd_set_burst_tx_retry_retry,
5674                 (void *)&cmd_set_burst_tx_retry_retry_num,
5675                 NULL,
5676         },
5677 };
5678
5679 /* *** SET PROMISC MODE *** */
5680 struct cmd_set_promisc_mode_result {
5681         cmdline_fixed_string_t set;
5682         cmdline_fixed_string_t promisc;
5683         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5684         uint16_t port_num;               /* valid if "allports" argument == 0 */
5685         cmdline_fixed_string_t mode;
5686 };
5687
5688 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5689                                         __attribute__((unused)) struct cmdline *cl,
5690                                         void *allports)
5691 {
5692         struct cmd_set_promisc_mode_result *res = parsed_result;
5693         int enable;
5694         portid_t i;
5695
5696         if (!strcmp(res->mode, "on"))
5697                 enable = 1;
5698         else
5699                 enable = 0;
5700
5701         /* all ports */
5702         if (allports) {
5703                 RTE_ETH_FOREACH_DEV(i) {
5704                         if (enable)
5705                                 rte_eth_promiscuous_enable(i);
5706                         else
5707                                 rte_eth_promiscuous_disable(i);
5708                 }
5709         }
5710         else {
5711                 if (enable)
5712                         rte_eth_promiscuous_enable(res->port_num);
5713                 else
5714                         rte_eth_promiscuous_disable(res->port_num);
5715         }
5716 }
5717
5718 cmdline_parse_token_string_t cmd_setpromisc_set =
5719         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5720 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5721         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5722                                  "promisc");
5723 cmdline_parse_token_string_t cmd_setpromisc_portall =
5724         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5725                                  "all");
5726 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5727         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5728                               UINT8);
5729 cmdline_parse_token_string_t cmd_setpromisc_mode =
5730         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5731                                  "on#off");
5732
5733 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5734         .f = cmd_set_promisc_mode_parsed,
5735         .data = (void *)1,
5736         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5737         .tokens = {
5738                 (void *)&cmd_setpromisc_set,
5739                 (void *)&cmd_setpromisc_promisc,
5740                 (void *)&cmd_setpromisc_portall,
5741                 (void *)&cmd_setpromisc_mode,
5742                 NULL,
5743         },
5744 };
5745
5746 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5747         .f = cmd_set_promisc_mode_parsed,
5748         .data = (void *)0,
5749         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5750         .tokens = {
5751                 (void *)&cmd_setpromisc_set,
5752                 (void *)&cmd_setpromisc_promisc,
5753                 (void *)&cmd_setpromisc_portnum,
5754                 (void *)&cmd_setpromisc_mode,
5755                 NULL,
5756         },
5757 };
5758
5759 /* *** SET ALLMULTI MODE *** */
5760 struct cmd_set_allmulti_mode_result {
5761         cmdline_fixed_string_t set;
5762         cmdline_fixed_string_t allmulti;
5763         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5764         uint16_t port_num;               /* valid if "allports" argument == 0 */
5765         cmdline_fixed_string_t mode;
5766 };
5767
5768 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5769                                         __attribute__((unused)) struct cmdline *cl,
5770                                         void *allports)
5771 {
5772         struct cmd_set_allmulti_mode_result *res = parsed_result;
5773         int enable;
5774         portid_t i;
5775
5776         if (!strcmp(res->mode, "on"))
5777                 enable = 1;
5778         else
5779                 enable = 0;
5780
5781         /* all ports */
5782         if (allports) {
5783                 RTE_ETH_FOREACH_DEV(i) {
5784                         if (enable)
5785                                 rte_eth_allmulticast_enable(i);
5786                         else
5787                                 rte_eth_allmulticast_disable(i);
5788                 }
5789         }
5790         else {
5791                 if (enable)
5792                         rte_eth_allmulticast_enable(res->port_num);
5793                 else
5794                         rte_eth_allmulticast_disable(res->port_num);
5795         }
5796 }
5797
5798 cmdline_parse_token_string_t cmd_setallmulti_set =
5799         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5800 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5801         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5802                                  "allmulti");
5803 cmdline_parse_token_string_t cmd_setallmulti_portall =
5804         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5805                                  "all");
5806 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5807         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5808                               UINT16);
5809 cmdline_parse_token_string_t cmd_setallmulti_mode =
5810         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5811                                  "on#off");
5812
5813 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5814         .f = cmd_set_allmulti_mode_parsed,
5815         .data = (void *)1,
5816         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5817         .tokens = {
5818                 (void *)&cmd_setallmulti_set,
5819                 (void *)&cmd_setallmulti_allmulti,
5820                 (void *)&cmd_setallmulti_portall,
5821                 (void *)&cmd_setallmulti_mode,
5822                 NULL,
5823         },
5824 };
5825
5826 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5827         .f = cmd_set_allmulti_mode_parsed,
5828         .data = (void *)0,
5829         .help_str = "set allmulti <port_id> on|off: "
5830                 "Set allmulti mode on port_id",
5831         .tokens = {
5832                 (void *)&cmd_setallmulti_set,
5833                 (void *)&cmd_setallmulti_allmulti,
5834                 (void *)&cmd_setallmulti_portnum,
5835                 (void *)&cmd_setallmulti_mode,
5836                 NULL,
5837         },
5838 };
5839
5840 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5841 struct cmd_link_flow_ctrl_set_result {
5842         cmdline_fixed_string_t set;
5843         cmdline_fixed_string_t flow_ctrl;
5844         cmdline_fixed_string_t rx;
5845         cmdline_fixed_string_t rx_lfc_mode;
5846         cmdline_fixed_string_t tx;
5847         cmdline_fixed_string_t tx_lfc_mode;
5848         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5849         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5850         cmdline_fixed_string_t autoneg_str;
5851         cmdline_fixed_string_t autoneg;
5852         cmdline_fixed_string_t hw_str;
5853         uint32_t high_water;
5854         cmdline_fixed_string_t lw_str;
5855         uint32_t low_water;
5856         cmdline_fixed_string_t pt_str;
5857         uint16_t pause_time;
5858         cmdline_fixed_string_t xon_str;
5859         uint16_t send_xon;
5860         portid_t port_id;
5861 };
5862
5863 cmdline_parse_token_string_t cmd_lfc_set_set =
5864         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5865                                 set, "set");
5866 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5867         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5868                                 flow_ctrl, "flow_ctrl");
5869 cmdline_parse_token_string_t cmd_lfc_set_rx =
5870         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5871                                 rx, "rx");
5872 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5873         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5874                                 rx_lfc_mode, "on#off");
5875 cmdline_parse_token_string_t cmd_lfc_set_tx =
5876         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5877                                 tx, "tx");
5878 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5879         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5880                                 tx_lfc_mode, "on#off");
5881 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5882         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5883                                 hw_str, "high_water");
5884 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5885         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5886                                 high_water, UINT32);
5887 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5888         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5889                                 lw_str, "low_water");
5890 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5891         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5892                                 low_water, UINT32);
5893 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5894         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5895                                 pt_str, "pause_time");
5896 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5897         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5898                                 pause_time, UINT16);
5899 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5900         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5901                                 xon_str, "send_xon");
5902 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5903         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5904                                 send_xon, UINT16);
5905 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5906         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5907                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5908 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5909         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5910                                 mac_ctrl_frame_fwd_mode, "on#off");
5911 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5912         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5913                                 autoneg_str, "autoneg");
5914 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5915         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5916                                 autoneg, "on#off");
5917 cmdline_parse_token_num_t cmd_lfc_set_portid =
5918         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5919                                 port_id, UINT16);
5920
5921 /* forward declaration */
5922 static void
5923 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5924                               void *data);
5925
5926 cmdline_parse_inst_t cmd_link_flow_control_set = {
5927         .f = cmd_link_flow_ctrl_set_parsed,
5928         .data = NULL,
5929         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5930                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5931                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5932         .tokens = {
5933                 (void *)&cmd_lfc_set_set,
5934                 (void *)&cmd_lfc_set_flow_ctrl,
5935                 (void *)&cmd_lfc_set_rx,
5936                 (void *)&cmd_lfc_set_rx_mode,
5937                 (void *)&cmd_lfc_set_tx,
5938                 (void *)&cmd_lfc_set_tx_mode,
5939                 (void *)&cmd_lfc_set_high_water,
5940                 (void *)&cmd_lfc_set_low_water,
5941                 (void *)&cmd_lfc_set_pause_time,
5942                 (void *)&cmd_lfc_set_send_xon,
5943                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5944                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5945                 (void *)&cmd_lfc_set_autoneg_str,
5946                 (void *)&cmd_lfc_set_autoneg,
5947                 (void *)&cmd_lfc_set_portid,
5948                 NULL,
5949         },
5950 };
5951
5952 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5953         .f = cmd_link_flow_ctrl_set_parsed,
5954         .data = (void *)&cmd_link_flow_control_set_rx,
5955         .help_str = "set flow_ctrl rx on|off <port_id>: "
5956                 "Change rx flow control parameter",
5957         .tokens = {
5958                 (void *)&cmd_lfc_set_set,
5959                 (void *)&cmd_lfc_set_flow_ctrl,
5960                 (void *)&cmd_lfc_set_rx,
5961                 (void *)&cmd_lfc_set_rx_mode,
5962                 (void *)&cmd_lfc_set_portid,
5963                 NULL,
5964         },
5965 };
5966
5967 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5968         .f = cmd_link_flow_ctrl_set_parsed,
5969         .data = (void *)&cmd_link_flow_control_set_tx,
5970         .help_str = "set flow_ctrl tx on|off <port_id>: "
5971                 "Change tx flow control parameter",
5972         .tokens = {
5973                 (void *)&cmd_lfc_set_set,
5974                 (void *)&cmd_lfc_set_flow_ctrl,
5975                 (void *)&cmd_lfc_set_tx,
5976                 (void *)&cmd_lfc_set_tx_mode,
5977                 (void *)&cmd_lfc_set_portid,
5978                 NULL,
5979         },
5980 };
5981
5982 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5983         .f = cmd_link_flow_ctrl_set_parsed,
5984         .data = (void *)&cmd_link_flow_control_set_hw,
5985         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5986                 "Change high water flow control parameter",
5987         .tokens = {
5988                 (void *)&cmd_lfc_set_set,
5989                 (void *)&cmd_lfc_set_flow_ctrl,
5990                 (void *)&cmd_lfc_set_high_water_str,
5991                 (void *)&cmd_lfc_set_high_water,
5992                 (void *)&cmd_lfc_set_portid,
5993                 NULL,
5994         },
5995 };
5996
5997 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5998         .f = cmd_link_flow_ctrl_set_parsed,
5999         .data = (void *)&cmd_link_flow_control_set_lw,
6000         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6001                 "Change low water flow control parameter",
6002         .tokens = {
6003                 (void *)&cmd_lfc_set_set,
6004                 (void *)&cmd_lfc_set_flow_ctrl,
6005                 (void *)&cmd_lfc_set_low_water_str,
6006                 (void *)&cmd_lfc_set_low_water,
6007                 (void *)&cmd_lfc_set_portid,
6008                 NULL,
6009         },
6010 };
6011
6012 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6013         .f = cmd_link_flow_ctrl_set_parsed,
6014         .data = (void *)&cmd_link_flow_control_set_pt,
6015         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6016                 "Change pause time flow control parameter",
6017         .tokens = {
6018                 (void *)&cmd_lfc_set_set,
6019                 (void *)&cmd_lfc_set_flow_ctrl,
6020                 (void *)&cmd_lfc_set_pause_time_str,
6021                 (void *)&cmd_lfc_set_pause_time,
6022                 (void *)&cmd_lfc_set_portid,
6023                 NULL,
6024         },
6025 };
6026
6027 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6028         .f = cmd_link_flow_ctrl_set_parsed,
6029         .data = (void *)&cmd_link_flow_control_set_xon,
6030         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6031                 "Change send_xon flow control parameter",
6032         .tokens = {
6033                 (void *)&cmd_lfc_set_set,
6034                 (void *)&cmd_lfc_set_flow_ctrl,
6035                 (void *)&cmd_lfc_set_send_xon_str,
6036                 (void *)&cmd_lfc_set_send_xon,
6037                 (void *)&cmd_lfc_set_portid,
6038                 NULL,
6039         },
6040 };
6041
6042 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6043         .f = cmd_link_flow_ctrl_set_parsed,
6044         .data = (void *)&cmd_link_flow_control_set_macfwd,
6045         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6046                 "Change mac ctrl fwd flow control parameter",
6047         .tokens = {
6048                 (void *)&cmd_lfc_set_set,
6049                 (void *)&cmd_lfc_set_flow_ctrl,
6050                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6051                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6052                 (void *)&cmd_lfc_set_portid,
6053                 NULL,
6054         },
6055 };
6056
6057 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6058         .f = cmd_link_flow_ctrl_set_parsed,
6059         .data = (void *)&cmd_link_flow_control_set_autoneg,
6060         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6061                 "Change autoneg flow control parameter",
6062         .tokens = {
6063                 (void *)&cmd_lfc_set_set,
6064                 (void *)&cmd_lfc_set_flow_ctrl,
6065                 (void *)&cmd_lfc_set_autoneg_str,
6066                 (void *)&cmd_lfc_set_autoneg,
6067                 (void *)&cmd_lfc_set_portid,
6068                 NULL,
6069         },
6070 };
6071
6072 static void
6073 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6074                               __attribute__((unused)) struct cmdline *cl,
6075                               void *data)
6076 {
6077         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6078         cmdline_parse_inst_t *cmd = data;
6079         struct rte_eth_fc_conf fc_conf;
6080         int rx_fc_en = 0;
6081         int tx_fc_en = 0;
6082         int ret;
6083
6084         /*
6085          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6086          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6087          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6088          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6089          */
6090         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6091                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6092         };
6093
6094         /* Partial command line, retrieve current configuration */
6095         if (cmd) {
6096                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6097                 if (ret != 0) {
6098                         printf("cannot get current flow ctrl parameters, return"
6099                                "code = %d\n", ret);
6100                         return;
6101                 }
6102
6103                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6104                     (fc_conf.mode == RTE_FC_FULL))
6105                         rx_fc_en = 1;
6106                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6107                     (fc_conf.mode == RTE_FC_FULL))
6108                         tx_fc_en = 1;
6109         }
6110
6111         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6112                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6113
6114         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6115                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6116
6117         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6118
6119         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6120                 fc_conf.high_water = res->high_water;
6121
6122         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6123                 fc_conf.low_water = res->low_water;
6124
6125         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6126                 fc_conf.pause_time = res->pause_time;
6127
6128         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6129                 fc_conf.send_xon = res->send_xon;
6130
6131         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6132                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6133                         fc_conf.mac_ctrl_frame_fwd = 1;
6134                 else
6135                         fc_conf.mac_ctrl_frame_fwd = 0;
6136         }
6137
6138         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6139                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6140
6141         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6142         if (ret != 0)
6143                 printf("bad flow contrl parameter, return code = %d \n", ret);
6144 }
6145
6146 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6147 struct cmd_priority_flow_ctrl_set_result {
6148         cmdline_fixed_string_t set;
6149         cmdline_fixed_string_t pfc_ctrl;
6150         cmdline_fixed_string_t rx;
6151         cmdline_fixed_string_t rx_pfc_mode;
6152         cmdline_fixed_string_t tx;
6153         cmdline_fixed_string_t tx_pfc_mode;
6154         uint32_t high_water;
6155         uint32_t low_water;
6156         uint16_t pause_time;
6157         uint8_t  priority;
6158         portid_t port_id;
6159 };
6160
6161 static void
6162 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6163                        __attribute__((unused)) struct cmdline *cl,
6164                        __attribute__((unused)) void *data)
6165 {
6166         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6167         struct rte_eth_pfc_conf pfc_conf;
6168         int rx_fc_enable, tx_fc_enable;
6169         int ret;
6170
6171         /*
6172          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6173          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6174          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6175          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6176          */
6177         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6178                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6179         };
6180
6181         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6182         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6183         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6184         pfc_conf.fc.high_water = res->high_water;
6185         pfc_conf.fc.low_water  = res->low_water;
6186         pfc_conf.fc.pause_time = res->pause_time;
6187         pfc_conf.priority      = res->priority;
6188
6189         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6190         if (ret != 0)
6191                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6192 }
6193
6194 cmdline_parse_token_string_t cmd_pfc_set_set =
6195         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6196                                 set, "set");
6197 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6198         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6199                                 pfc_ctrl, "pfc_ctrl");
6200 cmdline_parse_token_string_t cmd_pfc_set_rx =
6201         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6202                                 rx, "rx");
6203 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6204         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6205                                 rx_pfc_mode, "on#off");
6206 cmdline_parse_token_string_t cmd_pfc_set_tx =
6207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6208                                 tx, "tx");
6209 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6211                                 tx_pfc_mode, "on#off");
6212 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6213         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6214                                 high_water, UINT32);
6215 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6216         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6217                                 low_water, UINT32);
6218 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6219         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6220                                 pause_time, UINT16);
6221 cmdline_parse_token_num_t cmd_pfc_set_priority =
6222         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6223                                 priority, UINT8);
6224 cmdline_parse_token_num_t cmd_pfc_set_portid =
6225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6226                                 port_id, UINT16);
6227
6228 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6229         .f = cmd_priority_flow_ctrl_set_parsed,
6230         .data = NULL,
6231         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6232                 "<pause_time> <priority> <port_id>: "
6233                 "Configure the Ethernet priority flow control",
6234         .tokens = {
6235                 (void *)&cmd_pfc_set_set,
6236                 (void *)&cmd_pfc_set_flow_ctrl,
6237                 (void *)&cmd_pfc_set_rx,
6238                 (void *)&cmd_pfc_set_rx_mode,
6239                 (void *)&cmd_pfc_set_tx,
6240                 (void *)&cmd_pfc_set_tx_mode,
6241                 (void *)&cmd_pfc_set_high_water,
6242                 (void *)&cmd_pfc_set_low_water,
6243                 (void *)&cmd_pfc_set_pause_time,
6244                 (void *)&cmd_pfc_set_priority,
6245                 (void *)&cmd_pfc_set_portid,
6246                 NULL,
6247         },
6248 };
6249
6250 /* *** RESET CONFIGURATION *** */
6251 struct cmd_reset_result {
6252         cmdline_fixed_string_t reset;
6253         cmdline_fixed_string_t def;
6254 };
6255
6256 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6257                              struct cmdline *cl,
6258                              __attribute__((unused)) void *data)
6259 {
6260         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6261         set_def_fwd_config();
6262 }
6263
6264 cmdline_parse_token_string_t cmd_reset_set =
6265         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6266 cmdline_parse_token_string_t cmd_reset_def =
6267         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6268                                  "default");
6269
6270 cmdline_parse_inst_t cmd_reset = {
6271         .f = cmd_reset_parsed,
6272         .data = NULL,
6273         .help_str = "set default: Reset default forwarding configuration",
6274         .tokens = {
6275                 (void *)&cmd_reset_set,
6276                 (void *)&cmd_reset_def,
6277                 NULL,
6278         },
6279 };
6280
6281 /* *** START FORWARDING *** */
6282 struct cmd_start_result {
6283         cmdline_fixed_string_t start;
6284 };
6285
6286 cmdline_parse_token_string_t cmd_start_start =
6287         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6288
6289 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6290                              __attribute__((unused)) struct cmdline *cl,
6291                              __attribute__((unused)) void *data)
6292 {
6293         start_packet_forwarding(0);
6294 }
6295
6296 cmdline_parse_inst_t cmd_start = {
6297         .f = cmd_start_parsed,
6298         .data = NULL,
6299         .help_str = "start: Start packet forwarding",
6300         .tokens = {
6301                 (void *)&cmd_start_start,
6302                 NULL,
6303         },
6304 };
6305
6306 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6307 struct cmd_start_tx_first_result {
6308         cmdline_fixed_string_t start;
6309         cmdline_fixed_string_t tx_first;
6310 };
6311
6312 static void
6313 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6314                           __attribute__((unused)) struct cmdline *cl,
6315                           __attribute__((unused)) void *data)
6316 {
6317         start_packet_forwarding(1);
6318 }
6319
6320 cmdline_parse_token_string_t cmd_start_tx_first_start =
6321         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6322                                  "start");
6323 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6324         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6325                                  tx_first, "tx_first");
6326
6327 cmdline_parse_inst_t cmd_start_tx_first = {
6328         .f = cmd_start_tx_first_parsed,
6329         .data = NULL,
6330         .help_str = "start tx_first: Start packet forwarding, "
6331                 "after sending 1 burst of packets",
6332         .tokens = {
6333                 (void *)&cmd_start_tx_first_start,
6334                 (void *)&cmd_start_tx_first_tx_first,
6335                 NULL,
6336         },
6337 };
6338
6339 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6340 struct cmd_start_tx_first_n_result {
6341         cmdline_fixed_string_t start;
6342         cmdline_fixed_string_t tx_first;
6343         uint32_t tx_num;
6344 };
6345
6346 static void
6347 cmd_start_tx_first_n_parsed(void *parsed_result,
6348                           __attribute__((unused)) struct cmdline *cl,
6349                           __attribute__((unused)) void *data)
6350 {
6351         struct cmd_start_tx_first_n_result *res = parsed_result;
6352
6353         start_packet_forwarding(res->tx_num);
6354 }
6355
6356 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6357         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6358                         start, "start");
6359 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6360         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6361                         tx_first, "tx_first");
6362 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6363         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6364                         tx_num, UINT32);
6365
6366 cmdline_parse_inst_t cmd_start_tx_first_n = {
6367         .f = cmd_start_tx_first_n_parsed,
6368         .data = NULL,
6369         .help_str = "start tx_first <num>: "
6370                 "packet forwarding, after sending <num> bursts of packets",
6371         .tokens = {
6372                 (void *)&cmd_start_tx_first_n_start,
6373                 (void *)&cmd_start_tx_first_n_tx_first,
6374                 (void *)&cmd_start_tx_first_n_tx_num,
6375                 NULL,
6376         },
6377 };
6378
6379 /* *** SET LINK UP *** */
6380 struct cmd_set_link_up_result {
6381         cmdline_fixed_string_t set;
6382         cmdline_fixed_string_t link_up;
6383         cmdline_fixed_string_t port;
6384         portid_t port_id;
6385 };
6386
6387 cmdline_parse_token_string_t cmd_set_link_up_set =
6388         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6389 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6390         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6391                                 "link-up");
6392 cmdline_parse_token_string_t cmd_set_link_up_port =
6393         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6394 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6395         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6396
6397 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6398                              __attribute__((unused)) struct cmdline *cl,
6399                              __attribute__((unused)) void *data)
6400 {
6401         struct cmd_set_link_up_result *res = parsed_result;
6402         dev_set_link_up(res->port_id);
6403 }
6404
6405 cmdline_parse_inst_t cmd_set_link_up = {
6406         .f = cmd_set_link_up_parsed,
6407         .data = NULL,
6408         .help_str = "set link-up port <port id>",
6409         .tokens = {
6410                 (void *)&cmd_set_link_up_set,
6411                 (void *)&cmd_set_link_up_link_up,
6412                 (void *)&cmd_set_link_up_port,
6413                 (void *)&cmd_set_link_up_port_id,
6414                 NULL,
6415         },
6416 };
6417
6418 /* *** SET LINK DOWN *** */
6419 struct cmd_set_link_down_result {
6420         cmdline_fixed_string_t set;
6421         cmdline_fixed_string_t link_down;
6422         cmdline_fixed_string_t port;
6423         portid_t port_id;
6424 };
6425
6426 cmdline_parse_token_string_t cmd_set_link_down_set =
6427         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6428 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6429         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6430                                 "link-down");
6431 cmdline_parse_token_string_t cmd_set_link_down_port =
6432         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6433 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6434         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6435
6436 static void cmd_set_link_down_parsed(
6437                                 __attribute__((unused)) void *parsed_result,
6438                                 __attribute__((unused)) struct cmdline *cl,
6439                                 __attribute__((unused)) void *data)
6440 {
6441         struct cmd_set_link_down_result *res = parsed_result;
6442         dev_set_link_down(res->port_id);
6443 }
6444
6445 cmdline_parse_inst_t cmd_set_link_down = {
6446         .f = cmd_set_link_down_parsed,
6447         .data = NULL,
6448         .help_str = "set link-down port <port id>",
6449         .tokens = {
6450                 (void *)&cmd_set_link_down_set,
6451                 (void *)&cmd_set_link_down_link_down,
6452                 (void *)&cmd_set_link_down_port,
6453                 (void *)&cmd_set_link_down_port_id,
6454                 NULL,
6455         },
6456 };
6457
6458 /* *** SHOW CFG *** */
6459 struct cmd_showcfg_result {
6460         cmdline_fixed_string_t show;
6461         cmdline_fixed_string_t cfg;
6462         cmdline_fixed_string_t what;
6463 };
6464
6465 static void cmd_showcfg_parsed(void *parsed_result,
6466                                __attribute__((unused)) struct cmdline *cl,
6467                                __attribute__((unused)) void *data)
6468 {
6469         struct cmd_showcfg_result *res = parsed_result;
6470         if (!strcmp(res->what, "rxtx"))
6471                 rxtx_config_display();
6472         else if (!strcmp(res->what, "cores"))
6473                 fwd_lcores_config_display();
6474         else if (!strcmp(res->what, "fwd"))
6475                 pkt_fwd_config_display(&cur_fwd_config);
6476         else if (!strcmp(res->what, "txpkts"))
6477                 show_tx_pkt_segments();
6478 }
6479
6480 cmdline_parse_token_string_t cmd_showcfg_show =
6481         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6482 cmdline_parse_token_string_t cmd_showcfg_port =
6483         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6484 cmdline_parse_token_string_t cmd_showcfg_what =
6485         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6486                                  "rxtx#cores#fwd#txpkts");
6487
6488 cmdline_parse_inst_t cmd_showcfg = {
6489         .f = cmd_showcfg_parsed,
6490         .data = NULL,
6491         .help_str = "show config rxtx|cores|fwd|txpkts",
6492         .tokens = {
6493                 (void *)&cmd_showcfg_show,
6494                 (void *)&cmd_showcfg_port,
6495                 (void *)&cmd_showcfg_what,
6496                 NULL,
6497         },
6498 };
6499
6500 /* *** SHOW ALL PORT INFO *** */
6501 struct cmd_showportall_result {
6502         cmdline_fixed_string_t show;
6503         cmdline_fixed_string_t port;
6504         cmdline_fixed_string_t what;
6505         cmdline_fixed_string_t all;
6506 };
6507
6508 static void cmd_showportall_parsed(void *parsed_result,
6509                                 __attribute__((unused)) struct cmdline *cl,
6510                                 __attribute__((unused)) void *data)
6511 {
6512         portid_t i;
6513
6514         struct cmd_showportall_result *res = parsed_result;
6515         if (!strcmp(res->show, "clear")) {
6516                 if (!strcmp(res->what, "stats"))
6517                         RTE_ETH_FOREACH_DEV(i)
6518                                 nic_stats_clear(i);
6519                 else if (!strcmp(res->what, "xstats"))
6520                         RTE_ETH_FOREACH_DEV(i)
6521                                 nic_xstats_clear(i);
6522         } else if (!strcmp(res->what, "info"))
6523                 RTE_ETH_FOREACH_DEV(i)
6524                         port_infos_display(i);
6525         else if (!strcmp(res->what, "stats"))
6526                 RTE_ETH_FOREACH_DEV(i)
6527                         nic_stats_display(i);
6528         else if (!strcmp(res->what, "xstats"))
6529                 RTE_ETH_FOREACH_DEV(i)
6530                         nic_xstats_display(i);
6531         else if (!strcmp(res->what, "fdir"))
6532                 RTE_ETH_FOREACH_DEV(i)
6533                         fdir_get_infos(i);
6534         else if (!strcmp(res->what, "stat_qmap"))
6535                 RTE_ETH_FOREACH_DEV(i)
6536                         nic_stats_mapping_display(i);
6537         else if (!strcmp(res->what, "dcb_tc"))
6538                 RTE_ETH_FOREACH_DEV(i)
6539                         port_dcb_info_display(i);
6540         else if (!strcmp(res->what, "cap"))
6541                 RTE_ETH_FOREACH_DEV(i)
6542                         port_offload_cap_display(i);
6543 }
6544
6545 cmdline_parse_token_string_t cmd_showportall_show =
6546         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6547                                  "show#clear");
6548 cmdline_parse_token_string_t cmd_showportall_port =
6549         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6550 cmdline_parse_token_string_t cmd_showportall_what =
6551         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6552                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6553 cmdline_parse_token_string_t cmd_showportall_all =
6554         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6555 cmdline_parse_inst_t cmd_showportall = {
6556         .f = cmd_showportall_parsed,
6557         .data = NULL,
6558         .help_str = "show|clear port "
6559                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6560         .tokens = {
6561                 (void *)&cmd_showportall_show,
6562                 (void *)&cmd_showportall_port,
6563                 (void *)&cmd_showportall_what,
6564                 (void *)&cmd_showportall_all,
6565                 NULL,
6566         },
6567 };
6568
6569 /* *** SHOW PORT INFO *** */
6570 struct cmd_showport_result {
6571         cmdline_fixed_string_t show;
6572         cmdline_fixed_string_t port;
6573         cmdline_fixed_string_t what;
6574         uint16_t portnum;
6575 };
6576
6577 static void cmd_showport_parsed(void *parsed_result,
6578                                 __attribute__((unused)) struct cmdline *cl,
6579                                 __attribute__((unused)) void *data)
6580 {
6581         struct cmd_showport_result *res = parsed_result;
6582         if (!strcmp(res->show, "clear")) {
6583                 if (!strcmp(res->what, "stats"))
6584                         nic_stats_clear(res->portnum);
6585                 else if (!strcmp(res->what, "xstats"))
6586                         nic_xstats_clear(res->portnum);
6587         } else if (!strcmp(res->what, "info"))
6588                 port_infos_display(res->portnum);
6589         else if (!strcmp(res->what, "stats"))
6590                 nic_stats_display(res->portnum);
6591         else if (!strcmp(res->what, "xstats"))
6592                 nic_xstats_display(res->portnum);
6593         else if (!strcmp(res->what, "fdir"))
6594                  fdir_get_infos(res->portnum);
6595         else if (!strcmp(res->what, "stat_qmap"))
6596                 nic_stats_mapping_display(res->portnum);
6597         else if (!strcmp(res->what, "dcb_tc"))
6598                 port_dcb_info_display(res->portnum);
6599         else if (!strcmp(res->what, "cap"))
6600                 port_offload_cap_display(res->portnum);
6601 }
6602
6603 cmdline_parse_token_string_t cmd_showport_show =
6604         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6605                                  "show#clear");
6606 cmdline_parse_token_string_t cmd_showport_port =
6607         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6608 cmdline_parse_token_string_t cmd_showport_what =
6609         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6610                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6611 cmdline_parse_token_num_t cmd_showport_portnum =
6612         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6613
6614 cmdline_parse_inst_t cmd_showport = {
6615         .f = cmd_showport_parsed,
6616         .data = NULL,
6617         .help_str = "show|clear port "
6618                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6619                 "<port_id>",
6620         .tokens = {
6621                 (void *)&cmd_showport_show,
6622                 (void *)&cmd_showport_port,
6623                 (void *)&cmd_showport_what,
6624                 (void *)&cmd_showport_portnum,
6625                 NULL,
6626         },
6627 };
6628
6629 /* *** SHOW QUEUE INFO *** */
6630 struct cmd_showqueue_result {
6631         cmdline_fixed_string_t show;
6632         cmdline_fixed_string_t type;
6633         cmdline_fixed_string_t what;
6634         uint16_t portnum;
6635         uint16_t queuenum;
6636 };
6637
6638 static void
6639 cmd_showqueue_parsed(void *parsed_result,
6640         __attribute__((unused)) struct cmdline *cl,
6641         __attribute__((unused)) void *data)
6642 {
6643         struct cmd_showqueue_result *res = parsed_result;
6644
6645         if (!strcmp(res->type, "rxq"))
6646                 rx_queue_infos_display(res->portnum, res->queuenum);
6647         else if (!strcmp(res->type, "txq"))
6648                 tx_queue_infos_display(res->portnum, res->queuenum);
6649 }
6650
6651 cmdline_parse_token_string_t cmd_showqueue_show =
6652         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6653 cmdline_parse_token_string_t cmd_showqueue_type =
6654         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6655 cmdline_parse_token_string_t cmd_showqueue_what =
6656         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6657 cmdline_parse_token_num_t cmd_showqueue_portnum =
6658         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6659 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6660         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6661
6662 cmdline_parse_inst_t cmd_showqueue = {
6663         .f = cmd_showqueue_parsed,
6664         .data = NULL,
6665         .help_str = "show rxq|txq info <port_id> <queue_id>",
6666         .tokens = {
6667                 (void *)&cmd_showqueue_show,
6668                 (void *)&cmd_showqueue_type,
6669                 (void *)&cmd_showqueue_what,
6670                 (void *)&cmd_showqueue_portnum,
6671                 (void *)&cmd_showqueue_queuenum,
6672                 NULL,
6673         },
6674 };
6675
6676 /* *** READ PORT REGISTER *** */
6677 struct cmd_read_reg_result {
6678         cmdline_fixed_string_t read;
6679         cmdline_fixed_string_t reg;
6680         portid_t port_id;
6681         uint32_t reg_off;
6682 };
6683
6684 static void
6685 cmd_read_reg_parsed(void *parsed_result,
6686                     __attribute__((unused)) struct cmdline *cl,
6687                     __attribute__((unused)) void *data)
6688 {
6689         struct cmd_read_reg_result *res = parsed_result;
6690         port_reg_display(res->port_id, res->reg_off);
6691 }
6692
6693 cmdline_parse_token_string_t cmd_read_reg_read =
6694         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6695 cmdline_parse_token_string_t cmd_read_reg_reg =
6696         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6697 cmdline_parse_token_num_t cmd_read_reg_port_id =
6698         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6699 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6700         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6701
6702 cmdline_parse_inst_t cmd_read_reg = {
6703         .f = cmd_read_reg_parsed,
6704         .data = NULL,
6705         .help_str = "read reg <port_id> <reg_off>",
6706         .tokens = {
6707                 (void *)&cmd_read_reg_read,
6708                 (void *)&cmd_read_reg_reg,
6709                 (void *)&cmd_read_reg_port_id,
6710                 (void *)&cmd_read_reg_reg_off,
6711                 NULL,
6712         },
6713 };
6714
6715 /* *** READ PORT REGISTER BIT FIELD *** */
6716 struct cmd_read_reg_bit_field_result {
6717         cmdline_fixed_string_t read;
6718         cmdline_fixed_string_t regfield;
6719         portid_t port_id;
6720         uint32_t reg_off;
6721         uint8_t bit1_pos;
6722         uint8_t bit2_pos;
6723 };
6724
6725 static void
6726 cmd_read_reg_bit_field_parsed(void *parsed_result,
6727                               __attribute__((unused)) struct cmdline *cl,
6728                               __attribute__((unused)) void *data)
6729 {
6730         struct cmd_read_reg_bit_field_result *res = parsed_result;
6731         port_reg_bit_field_display(res->port_id, res->reg_off,
6732                                    res->bit1_pos, res->bit2_pos);
6733 }
6734
6735 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6736         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6737                                  "read");
6738 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6739         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6740                                  regfield, "regfield");
6741 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6742         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6743                               UINT16);
6744 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6745         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6746                               UINT32);
6747 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6748         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6749                               UINT8);
6750 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6751         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6752                               UINT8);
6753
6754 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6755         .f = cmd_read_reg_bit_field_parsed,
6756         .data = NULL,
6757         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6758         "Read register bit field between bit_x and bit_y included",
6759         .tokens = {
6760                 (void *)&cmd_read_reg_bit_field_read,
6761                 (void *)&cmd_read_reg_bit_field_regfield,
6762                 (void *)&cmd_read_reg_bit_field_port_id,
6763                 (void *)&cmd_read_reg_bit_field_reg_off,
6764                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6765                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6766                 NULL,
6767         },
6768 };
6769
6770 /* *** READ PORT REGISTER BIT *** */
6771 struct cmd_read_reg_bit_result {
6772         cmdline_fixed_string_t read;
6773         cmdline_fixed_string_t regbit;
6774         portid_t port_id;
6775         uint32_t reg_off;
6776         uint8_t bit_pos;
6777 };
6778
6779 static void
6780 cmd_read_reg_bit_parsed(void *parsed_result,
6781                         __attribute__((unused)) struct cmdline *cl,
6782                         __attribute__((unused)) void *data)
6783 {
6784         struct cmd_read_reg_bit_result *res = parsed_result;
6785         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6786 }
6787
6788 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6789         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6790 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6791         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6792                                  regbit, "regbit");
6793 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6794         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6795 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6796         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6797 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6798         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6799
6800 cmdline_parse_inst_t cmd_read_reg_bit = {
6801         .f = cmd_read_reg_bit_parsed,
6802         .data = NULL,
6803         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6804         .tokens = {
6805                 (void *)&cmd_read_reg_bit_read,
6806                 (void *)&cmd_read_reg_bit_regbit,
6807                 (void *)&cmd_read_reg_bit_port_id,
6808                 (void *)&cmd_read_reg_bit_reg_off,
6809                 (void *)&cmd_read_reg_bit_bit_pos,
6810                 NULL,
6811         },
6812 };
6813
6814 /* *** WRITE PORT REGISTER *** */
6815 struct cmd_write_reg_result {
6816         cmdline_fixed_string_t write;
6817         cmdline_fixed_string_t reg;
6818         portid_t port_id;
6819         uint32_t reg_off;
6820         uint32_t value;
6821 };
6822
6823 static void
6824 cmd_write_reg_parsed(void *parsed_result,
6825                      __attribute__((unused)) struct cmdline *cl,
6826                      __attribute__((unused)) void *data)
6827 {
6828         struct cmd_write_reg_result *res = parsed_result;
6829         port_reg_set(res->port_id, res->reg_off, res->value);
6830 }
6831
6832 cmdline_parse_token_string_t cmd_write_reg_write =
6833         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6834 cmdline_parse_token_string_t cmd_write_reg_reg =
6835         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6836 cmdline_parse_token_num_t cmd_write_reg_port_id =
6837         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6838 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6839         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6840 cmdline_parse_token_num_t cmd_write_reg_value =
6841         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6842
6843 cmdline_parse_inst_t cmd_write_reg = {
6844         .f = cmd_write_reg_parsed,
6845         .data = NULL,
6846         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6847         .tokens = {
6848                 (void *)&cmd_write_reg_write,
6849                 (void *)&cmd_write_reg_reg,
6850                 (void *)&cmd_write_reg_port_id,
6851                 (void *)&cmd_write_reg_reg_off,
6852                 (void *)&cmd_write_reg_value,
6853                 NULL,
6854         },
6855 };
6856
6857 /* *** WRITE PORT REGISTER BIT FIELD *** */
6858 struct cmd_write_reg_bit_field_result {
6859         cmdline_fixed_string_t write;
6860         cmdline_fixed_string_t regfield;
6861         portid_t port_id;
6862         uint32_t reg_off;
6863         uint8_t bit1_pos;
6864         uint8_t bit2_pos;
6865         uint32_t value;
6866 };
6867
6868 static void
6869 cmd_write_reg_bit_field_parsed(void *parsed_result,
6870                                __attribute__((unused)) struct cmdline *cl,
6871                                __attribute__((unused)) void *data)
6872 {
6873         struct cmd_write_reg_bit_field_result *res = parsed_result;
6874         port_reg_bit_field_set(res->port_id, res->reg_off,
6875                           res->bit1_pos, res->bit2_pos, res->value);
6876 }
6877
6878 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6879         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6880                                  "write");
6881 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6882         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6883                                  regfield, "regfield");
6884 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6885         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6886                               UINT16);
6887 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6888         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6889                               UINT32);
6890 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6891         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6892                               UINT8);
6893 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6894         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6895                               UINT8);
6896 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6897         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6898                               UINT32);
6899
6900 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6901         .f = cmd_write_reg_bit_field_parsed,
6902         .data = NULL,
6903         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6904                 "<reg_value>: "
6905                 "Set register bit field between bit_x and bit_y included",
6906         .tokens = {
6907                 (void *)&cmd_write_reg_bit_field_write,
6908                 (void *)&cmd_write_reg_bit_field_regfield,
6909                 (void *)&cmd_write_reg_bit_field_port_id,
6910                 (void *)&cmd_write_reg_bit_field_reg_off,
6911                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6912                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6913                 (void *)&cmd_write_reg_bit_field_value,
6914                 NULL,
6915         },
6916 };
6917
6918 /* *** WRITE PORT REGISTER BIT *** */
6919 struct cmd_write_reg_bit_result {
6920         cmdline_fixed_string_t write;
6921         cmdline_fixed_string_t regbit;
6922         portid_t port_id;
6923         uint32_t reg_off;
6924         uint8_t bit_pos;
6925         uint8_t value;
6926 };
6927
6928 static void
6929 cmd_write_reg_bit_parsed(void *parsed_result,
6930                          __attribute__((unused)) struct cmdline *cl,
6931                          __attribute__((unused)) void *data)
6932 {
6933         struct cmd_write_reg_bit_result *res = parsed_result;
6934         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6935 }
6936
6937 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6938         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6939                                  "write");
6940 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6941         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6942                                  regbit, "regbit");
6943 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6944         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6945 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6946         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6947 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6948         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6949 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6950         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6951
6952 cmdline_parse_inst_t cmd_write_reg_bit = {
6953         .f = cmd_write_reg_bit_parsed,
6954         .data = NULL,
6955         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6956                 "0 <= bit_x <= 31",
6957         .tokens = {
6958                 (void *)&cmd_write_reg_bit_write,
6959                 (void *)&cmd_write_reg_bit_regbit,
6960                 (void *)&cmd_write_reg_bit_port_id,
6961                 (void *)&cmd_write_reg_bit_reg_off,
6962                 (void *)&cmd_write_reg_bit_bit_pos,
6963                 (void *)&cmd_write_reg_bit_value,
6964                 NULL,
6965         },
6966 };
6967
6968 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6969 struct cmd_read_rxd_txd_result {
6970         cmdline_fixed_string_t read;
6971         cmdline_fixed_string_t rxd_txd;
6972         portid_t port_id;
6973         uint16_t queue_id;
6974         uint16_t desc_id;
6975 };
6976
6977 static void
6978 cmd_read_rxd_txd_parsed(void *parsed_result,
6979                         __attribute__((unused)) struct cmdline *cl,
6980                         __attribute__((unused)) void *data)
6981 {
6982         struct cmd_read_rxd_txd_result *res = parsed_result;
6983
6984         if (!strcmp(res->rxd_txd, "rxd"))
6985                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6986         else if (!strcmp(res->rxd_txd, "txd"))
6987                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6988 }
6989
6990 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6991         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6992 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6993         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6994                                  "rxd#txd");
6995 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6996         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
6997 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6998         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6999 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7000         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7001
7002 cmdline_parse_inst_t cmd_read_rxd_txd = {
7003         .f = cmd_read_rxd_txd_parsed,
7004         .data = NULL,
7005         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7006         .tokens = {
7007                 (void *)&cmd_read_rxd_txd_read,
7008                 (void *)&cmd_read_rxd_txd_rxd_txd,
7009                 (void *)&cmd_read_rxd_txd_port_id,
7010                 (void *)&cmd_read_rxd_txd_queue_id,
7011                 (void *)&cmd_read_rxd_txd_desc_id,
7012                 NULL,
7013         },
7014 };
7015
7016 /* *** QUIT *** */
7017 struct cmd_quit_result {
7018         cmdline_fixed_string_t quit;
7019 };
7020
7021 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7022                             struct cmdline *cl,
7023                             __attribute__((unused)) void *data)
7024 {
7025         pmd_test_exit();
7026         cmdline_quit(cl);
7027 }
7028
7029 cmdline_parse_token_string_t cmd_quit_quit =
7030         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7031
7032 cmdline_parse_inst_t cmd_quit = {
7033         .f = cmd_quit_parsed,
7034         .data = NULL,
7035         .help_str = "quit: Exit application",
7036         .tokens = {
7037                 (void *)&cmd_quit_quit,
7038                 NULL,
7039         },
7040 };
7041
7042 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7043 struct cmd_mac_addr_result {
7044         cmdline_fixed_string_t mac_addr_cmd;
7045         cmdline_fixed_string_t what;
7046         uint16_t port_num;
7047         struct ether_addr address;
7048 };
7049
7050 static void cmd_mac_addr_parsed(void *parsed_result,
7051                 __attribute__((unused)) struct cmdline *cl,
7052                 __attribute__((unused)) void *data)
7053 {
7054         struct cmd_mac_addr_result *res = parsed_result;
7055         int ret;
7056
7057         if (strcmp(res->what, "add") == 0)
7058                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7059         else if (strcmp(res->what, "set") == 0)
7060                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7061                                                        &res->address);
7062         else
7063                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7064
7065         /* check the return value and print it if is < 0 */
7066         if(ret < 0)
7067                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7068
7069 }
7070
7071 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7072         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7073                                 "mac_addr");
7074 cmdline_parse_token_string_t cmd_mac_addr_what =
7075         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7076                                 "add#remove#set");
7077 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7078                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7079                                         UINT16);
7080 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7081                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7082
7083 cmdline_parse_inst_t cmd_mac_addr = {
7084         .f = cmd_mac_addr_parsed,
7085         .data = (void *)0,
7086         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7087                         "Add/Remove/Set MAC address on port_id",
7088         .tokens = {
7089                 (void *)&cmd_mac_addr_cmd,
7090                 (void *)&cmd_mac_addr_what,
7091                 (void *)&cmd_mac_addr_portnum,
7092                 (void *)&cmd_mac_addr_addr,
7093                 NULL,
7094         },
7095 };
7096
7097
7098 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7099 struct cmd_set_qmap_result {
7100         cmdline_fixed_string_t set;
7101         cmdline_fixed_string_t qmap;
7102         cmdline_fixed_string_t what;
7103         portid_t port_id;
7104         uint16_t queue_id;
7105         uint8_t map_value;
7106 };
7107
7108 static void
7109 cmd_set_qmap_parsed(void *parsed_result,
7110                        __attribute__((unused)) struct cmdline *cl,
7111                        __attribute__((unused)) void *data)
7112 {
7113         struct cmd_set_qmap_result *res = parsed_result;
7114         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7115
7116         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7117 }
7118
7119 cmdline_parse_token_string_t cmd_setqmap_set =
7120         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7121                                  set, "set");
7122 cmdline_parse_token_string_t cmd_setqmap_qmap =
7123         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7124                                  qmap, "stat_qmap");
7125 cmdline_parse_token_string_t cmd_setqmap_what =
7126         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7127                                  what, "tx#rx");
7128 cmdline_parse_token_num_t cmd_setqmap_portid =
7129         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7130                               port_id, UINT16);
7131 cmdline_parse_token_num_t cmd_setqmap_queueid =
7132         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7133                               queue_id, UINT16);
7134 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7135         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7136                               map_value, UINT8);
7137
7138 cmdline_parse_inst_t cmd_set_qmap = {
7139         .f = cmd_set_qmap_parsed,
7140         .data = NULL,
7141         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7142                 "Set statistics mapping value on tx|rx queue_id of port_id",
7143         .tokens = {
7144                 (void *)&cmd_setqmap_set,
7145                 (void *)&cmd_setqmap_qmap,
7146                 (void *)&cmd_setqmap_what,
7147                 (void *)&cmd_setqmap_portid,
7148                 (void *)&cmd_setqmap_queueid,
7149                 (void *)&cmd_setqmap_mapvalue,
7150                 NULL,
7151         },
7152 };
7153
7154 /* *** CONFIGURE UNICAST HASH TABLE *** */
7155 struct cmd_set_uc_hash_table {
7156         cmdline_fixed_string_t set;
7157         cmdline_fixed_string_t port;
7158         portid_t port_id;
7159         cmdline_fixed_string_t what;
7160         struct ether_addr address;
7161         cmdline_fixed_string_t mode;
7162 };
7163
7164 static void
7165 cmd_set_uc_hash_parsed(void *parsed_result,
7166                        __attribute__((unused)) struct cmdline *cl,
7167                        __attribute__((unused)) void *data)
7168 {
7169         int ret=0;
7170         struct cmd_set_uc_hash_table *res = parsed_result;
7171
7172         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7173
7174         if (strcmp(res->what, "uta") == 0)
7175                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7176                                                 &res->address,(uint8_t)is_on);
7177         if (ret < 0)
7178                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7179
7180 }
7181
7182 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7183         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7184                                  set, "set");
7185 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7186         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7187                                  port, "port");
7188 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7189         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7190                               port_id, UINT16);
7191 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7192         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7193                                  what, "uta");
7194 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7195         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7196                                 address);
7197 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7198         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7199                                  mode, "on#off");
7200
7201 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7202         .f = cmd_set_uc_hash_parsed,
7203         .data = NULL,
7204         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7205         .tokens = {
7206                 (void *)&cmd_set_uc_hash_set,
7207                 (void *)&cmd_set_uc_hash_port,
7208                 (void *)&cmd_set_uc_hash_portid,
7209                 (void *)&cmd_set_uc_hash_what,
7210                 (void *)&cmd_set_uc_hash_mac,
7211                 (void *)&cmd_set_uc_hash_mode,
7212                 NULL,
7213         },
7214 };
7215
7216 struct cmd_set_uc_all_hash_table {
7217         cmdline_fixed_string_t set;
7218         cmdline_fixed_string_t port;
7219         portid_t port_id;
7220         cmdline_fixed_string_t what;
7221         cmdline_fixed_string_t value;
7222         cmdline_fixed_string_t mode;
7223 };
7224
7225 static void
7226 cmd_set_uc_all_hash_parsed(void *parsed_result,
7227                        __attribute__((unused)) struct cmdline *cl,
7228                        __attribute__((unused)) void *data)
7229 {
7230         int ret=0;
7231         struct cmd_set_uc_all_hash_table *res = parsed_result;
7232
7233         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7234
7235         if ((strcmp(res->what, "uta") == 0) &&
7236                 (strcmp(res->value, "all") == 0))
7237                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7238         if (ret < 0)
7239                 printf("bad unicast hash table parameter,"
7240                         "return code = %d \n", ret);
7241 }
7242
7243 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7244         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7245                                  set, "set");
7246 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7247         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7248                                  port, "port");
7249 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7250         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7251                               port_id, UINT16);
7252 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7253         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7254                                  what, "uta");
7255 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7256         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7257                                 value,"all");
7258 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7259         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7260                                  mode, "on#off");
7261
7262 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7263         .f = cmd_set_uc_all_hash_parsed,
7264         .data = NULL,
7265         .help_str = "set port <port_id> uta all on|off",
7266         .tokens = {
7267                 (void *)&cmd_set_uc_all_hash_set,
7268                 (void *)&cmd_set_uc_all_hash_port,
7269                 (void *)&cmd_set_uc_all_hash_portid,
7270                 (void *)&cmd_set_uc_all_hash_what,
7271                 (void *)&cmd_set_uc_all_hash_value,
7272                 (void *)&cmd_set_uc_all_hash_mode,
7273                 NULL,
7274         },
7275 };
7276
7277 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7278 struct cmd_set_vf_macvlan_filter {
7279         cmdline_fixed_string_t set;
7280         cmdline_fixed_string_t port;
7281         portid_t port_id;
7282         cmdline_fixed_string_t vf;
7283         uint8_t vf_id;
7284         struct ether_addr address;
7285         cmdline_fixed_string_t filter_type;
7286         cmdline_fixed_string_t mode;
7287 };
7288
7289 static void
7290 cmd_set_vf_macvlan_parsed(void *parsed_result,
7291                        __attribute__((unused)) struct cmdline *cl,
7292                        __attribute__((unused)) void *data)
7293 {
7294         int is_on, ret = 0;
7295         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7296         struct rte_eth_mac_filter filter;
7297
7298         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7299
7300         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7301
7302         /* set VF MAC filter */
7303         filter.is_vf = 1;
7304
7305         /* set VF ID */
7306         filter.dst_id = res->vf_id;
7307
7308         if (!strcmp(res->filter_type, "exact-mac"))
7309                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7310         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7311                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7312         else if (!strcmp(res->filter_type, "hashmac"))
7313                 filter.filter_type = RTE_MAC_HASH_MATCH;
7314         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7315                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7316
7317         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7318
7319         if (is_on)
7320                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7321                                         RTE_ETH_FILTER_MACVLAN,
7322                                         RTE_ETH_FILTER_ADD,
7323                                          &filter);
7324         else
7325                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7326                                         RTE_ETH_FILTER_MACVLAN,
7327                                         RTE_ETH_FILTER_DELETE,
7328                                         &filter);
7329
7330         if (ret < 0)
7331                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7332
7333 }
7334
7335 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7336         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7337                                  set, "set");
7338 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7339         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7340                                  port, "port");
7341 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7342         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7343                               port_id, UINT16);
7344 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7345         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7346                                  vf, "vf");
7347 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7348         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7349                                 vf_id, UINT8);
7350 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7351         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7352                                 address);
7353 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7354         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7355                                 filter_type, "exact-mac#exact-mac-vlan"
7356                                 "#hashmac#hashmac-vlan");
7357 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7358         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7359                                  mode, "on#off");
7360
7361 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7362         .f = cmd_set_vf_macvlan_parsed,
7363         .data = NULL,
7364         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7365                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7366                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7367                 "hash match rule: hash match of MAC and exact match of VLAN",
7368         .tokens = {
7369                 (void *)&cmd_set_vf_macvlan_set,
7370                 (void *)&cmd_set_vf_macvlan_port,
7371                 (void *)&cmd_set_vf_macvlan_portid,
7372                 (void *)&cmd_set_vf_macvlan_vf,
7373                 (void *)&cmd_set_vf_macvlan_vf_id,
7374                 (void *)&cmd_set_vf_macvlan_mac,
7375                 (void *)&cmd_set_vf_macvlan_filter_type,
7376                 (void *)&cmd_set_vf_macvlan_mode,
7377                 NULL,
7378         },
7379 };
7380
7381 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7382 struct cmd_set_vf_traffic {
7383         cmdline_fixed_string_t set;
7384         cmdline_fixed_string_t port;
7385         portid_t port_id;
7386         cmdline_fixed_string_t vf;
7387         uint8_t vf_id;
7388         cmdline_fixed_string_t what;
7389         cmdline_fixed_string_t mode;
7390 };
7391
7392 static void
7393 cmd_set_vf_traffic_parsed(void *parsed_result,
7394                        __attribute__((unused)) struct cmdline *cl,
7395                        __attribute__((unused)) void *data)
7396 {
7397         struct cmd_set_vf_traffic *res = parsed_result;
7398         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7399         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7400
7401         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7402 }
7403
7404 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7405         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7406                                  set, "set");
7407 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7408         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7409                                  port, "port");
7410 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7411         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7412                               port_id, UINT16);
7413 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7414         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7415                                  vf, "vf");
7416 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7417         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7418                               vf_id, UINT8);
7419 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7420         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7421                                  what, "tx#rx");
7422 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7423         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7424                                  mode, "on#off");
7425
7426 cmdline_parse_inst_t cmd_set_vf_traffic = {
7427         .f = cmd_set_vf_traffic_parsed,
7428         .data = NULL,
7429         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7430         .tokens = {
7431                 (void *)&cmd_setvf_traffic_set,
7432                 (void *)&cmd_setvf_traffic_port,
7433                 (void *)&cmd_setvf_traffic_portid,
7434                 (void *)&cmd_setvf_traffic_vf,
7435                 (void *)&cmd_setvf_traffic_vfid,
7436                 (void *)&cmd_setvf_traffic_what,
7437                 (void *)&cmd_setvf_traffic_mode,
7438                 NULL,
7439         },
7440 };
7441
7442 /* *** CONFIGURE VF RECEIVE MODE *** */
7443 struct cmd_set_vf_rxmode {
7444         cmdline_fixed_string_t set;
7445         cmdline_fixed_string_t port;
7446         portid_t port_id;
7447         cmdline_fixed_string_t vf;
7448         uint8_t vf_id;
7449         cmdline_fixed_string_t what;
7450         cmdline_fixed_string_t mode;
7451         cmdline_fixed_string_t on;
7452 };
7453
7454 static void
7455 cmd_set_vf_rxmode_parsed(void *parsed_result,
7456                        __attribute__((unused)) struct cmdline *cl,
7457                        __attribute__((unused)) void *data)
7458 {
7459         int ret = -ENOTSUP;
7460         uint16_t rx_mode = 0;
7461         struct cmd_set_vf_rxmode *res = parsed_result;
7462
7463         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7464         if (!strcmp(res->what,"rxmode")) {
7465                 if (!strcmp(res->mode, "AUPE"))
7466                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7467                 else if (!strcmp(res->mode, "ROPE"))
7468                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7469                 else if (!strcmp(res->mode, "BAM"))
7470                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7471                 else if (!strncmp(res->mode, "MPE",3))
7472                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7473         }
7474
7475 #ifdef RTE_LIBRTE_IXGBE_PMD
7476         if (ret == -ENOTSUP)
7477                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7478                                                   rx_mode, (uint8_t)is_on);
7479 #endif
7480 #ifdef RTE_LIBRTE_BNXT_PMD
7481         if (ret == -ENOTSUP)
7482                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7483                                                  rx_mode, (uint8_t)is_on);
7484 #endif
7485         if (ret < 0)
7486                 printf("bad VF receive mode parameter, return code = %d \n",
7487                 ret);
7488 }
7489
7490 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7491         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7492                                  set, "set");
7493 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7494         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7495                                  port, "port");
7496 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7497         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7498                               port_id, UINT16);
7499 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7500         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7501                                  vf, "vf");
7502 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7503         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7504                               vf_id, UINT8);
7505 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7506         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7507                                  what, "rxmode");
7508 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7509         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7510                                  mode, "AUPE#ROPE#BAM#MPE");
7511 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7512         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7513                                  on, "on#off");
7514
7515 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7516         .f = cmd_set_vf_rxmode_parsed,
7517         .data = NULL,
7518         .help_str = "set port <port_id> vf <vf_id> rxmode "
7519                 "AUPE|ROPE|BAM|MPE on|off",
7520         .tokens = {
7521                 (void *)&cmd_set_vf_rxmode_set,
7522                 (void *)&cmd_set_vf_rxmode_port,
7523                 (void *)&cmd_set_vf_rxmode_portid,
7524                 (void *)&cmd_set_vf_rxmode_vf,
7525                 (void *)&cmd_set_vf_rxmode_vfid,
7526                 (void *)&cmd_set_vf_rxmode_what,
7527                 (void *)&cmd_set_vf_rxmode_mode,
7528                 (void *)&cmd_set_vf_rxmode_on,
7529                 NULL,
7530         },
7531 };
7532
7533 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7534 struct cmd_vf_mac_addr_result {
7535         cmdline_fixed_string_t mac_addr_cmd;
7536         cmdline_fixed_string_t what;
7537         cmdline_fixed_string_t port;
7538         uint16_t port_num;
7539         cmdline_fixed_string_t vf;
7540         uint8_t vf_num;
7541         struct ether_addr address;
7542 };
7543
7544 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7545                 __attribute__((unused)) struct cmdline *cl,
7546                 __attribute__((unused)) void *data)
7547 {
7548         struct cmd_vf_mac_addr_result *res = parsed_result;
7549         int ret = -ENOTSUP;
7550
7551         if (strcmp(res->what, "add") != 0)
7552                 return;
7553
7554 #ifdef RTE_LIBRTE_I40E_PMD
7555         if (ret == -ENOTSUP)
7556                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7557                                                    &res->address);
7558 #endif
7559 #ifdef RTE_LIBRTE_BNXT_PMD
7560         if (ret == -ENOTSUP)
7561                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7562                                                 res->vf_num);
7563 #endif
7564
7565         if(ret < 0)
7566                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7567
7568 }
7569
7570 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7571         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7572                                 mac_addr_cmd,"mac_addr");
7573 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7574         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7575                                 what,"add");
7576 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7577         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7578                                 port,"port");
7579 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7580         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7581                                 port_num, UINT16);
7582 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7583         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7584                                 vf,"vf");
7585 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7586         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7587                                 vf_num, UINT8);
7588 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7589         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7590                                 address);
7591
7592 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7593         .f = cmd_vf_mac_addr_parsed,
7594         .data = (void *)0,
7595         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7596                 "Add MAC address filtering for a VF on port_id",
7597         .tokens = {
7598                 (void *)&cmd_vf_mac_addr_cmd,
7599                 (void *)&cmd_vf_mac_addr_what,
7600                 (void *)&cmd_vf_mac_addr_port,
7601                 (void *)&cmd_vf_mac_addr_portnum,
7602                 (void *)&cmd_vf_mac_addr_vf,
7603                 (void *)&cmd_vf_mac_addr_vfnum,
7604                 (void *)&cmd_vf_mac_addr_addr,
7605                 NULL,
7606         },
7607 };
7608
7609 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7610 struct cmd_vf_rx_vlan_filter {
7611         cmdline_fixed_string_t rx_vlan;
7612         cmdline_fixed_string_t what;
7613         uint16_t vlan_id;
7614         cmdline_fixed_string_t port;
7615         portid_t port_id;
7616         cmdline_fixed_string_t vf;
7617         uint64_t vf_mask;
7618 };
7619
7620 static void
7621 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7622                           __attribute__((unused)) struct cmdline *cl,
7623                           __attribute__((unused)) void *data)
7624 {
7625         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7626         int ret = -ENOTSUP;
7627
7628         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7629
7630 #ifdef RTE_LIBRTE_IXGBE_PMD
7631         if (ret == -ENOTSUP)
7632                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7633                                 res->vlan_id, res->vf_mask, is_add);
7634 #endif
7635 #ifdef RTE_LIBRTE_I40E_PMD
7636         if (ret == -ENOTSUP)
7637                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7638                                 res->vlan_id, res->vf_mask, is_add);
7639 #endif
7640 #ifdef RTE_LIBRTE_BNXT_PMD
7641         if (ret == -ENOTSUP)
7642                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7643                                 res->vlan_id, res->vf_mask, is_add);
7644 #endif
7645
7646         switch (ret) {
7647         case 0:
7648                 break;
7649         case -EINVAL:
7650                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7651                                 res->vlan_id, res->vf_mask);
7652                 break;
7653         case -ENODEV:
7654                 printf("invalid port_id %d\n", res->port_id);
7655                 break;
7656         case -ENOTSUP:
7657                 printf("function not implemented or supported\n");
7658                 break;
7659         default:
7660                 printf("programming error: (%s)\n", strerror(-ret));
7661         }
7662 }
7663
7664 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7665         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7666                                  rx_vlan, "rx_vlan");
7667 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7668         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7669                                  what, "add#rm");
7670 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7671         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7672                               vlan_id, UINT16);
7673 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7674         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7675                                  port, "port");
7676 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7677         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7678                               port_id, UINT16);
7679 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7680         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7681                                  vf, "vf");
7682 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7683         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7684                               vf_mask, UINT64);
7685
7686 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7687         .f = cmd_vf_rx_vlan_filter_parsed,
7688         .data = NULL,
7689         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7690                 "(vf_mask = hexadecimal VF mask)",
7691         .tokens = {
7692                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7693                 (void *)&cmd_vf_rx_vlan_filter_what,
7694                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7695                 (void *)&cmd_vf_rx_vlan_filter_port,
7696                 (void *)&cmd_vf_rx_vlan_filter_portid,
7697                 (void *)&cmd_vf_rx_vlan_filter_vf,
7698                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7699                 NULL,
7700         },
7701 };
7702
7703 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7704 struct cmd_queue_rate_limit_result {
7705         cmdline_fixed_string_t set;
7706         cmdline_fixed_string_t port;
7707         uint16_t port_num;
7708         cmdline_fixed_string_t queue;
7709         uint8_t queue_num;
7710         cmdline_fixed_string_t rate;
7711         uint16_t rate_num;
7712 };
7713
7714 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7715                 __attribute__((unused)) struct cmdline *cl,
7716                 __attribute__((unused)) void *data)
7717 {
7718         struct cmd_queue_rate_limit_result *res = parsed_result;
7719         int ret = 0;
7720
7721         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7722                 && (strcmp(res->queue, "queue") == 0)
7723                 && (strcmp(res->rate, "rate") == 0))
7724                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7725                                         res->rate_num);
7726         if (ret < 0)
7727                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7728
7729 }
7730
7731 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7732         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7733                                 set, "set");
7734 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7735         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7736                                 port, "port");
7737 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7738         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7739                                 port_num, UINT16);
7740 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7741         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7742                                 queue, "queue");
7743 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7744         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7745                                 queue_num, UINT8);
7746 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7747         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7748                                 rate, "rate");
7749 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7750         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7751                                 rate_num, UINT16);
7752
7753 cmdline_parse_inst_t cmd_queue_rate_limit = {
7754         .f = cmd_queue_rate_limit_parsed,
7755         .data = (void *)0,
7756         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7757                 "Set rate limit for a queue on port_id",
7758         .tokens = {
7759                 (void *)&cmd_queue_rate_limit_set,
7760                 (void *)&cmd_queue_rate_limit_port,
7761                 (void *)&cmd_queue_rate_limit_portnum,
7762                 (void *)&cmd_queue_rate_limit_queue,
7763                 (void *)&cmd_queue_rate_limit_queuenum,
7764                 (void *)&cmd_queue_rate_limit_rate,
7765                 (void *)&cmd_queue_rate_limit_ratenum,
7766                 NULL,
7767         },
7768 };
7769
7770 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7771 struct cmd_vf_rate_limit_result {
7772         cmdline_fixed_string_t set;
7773         cmdline_fixed_string_t port;
7774         uint16_t port_num;
7775         cmdline_fixed_string_t vf;
7776         uint8_t vf_num;
7777         cmdline_fixed_string_t rate;
7778         uint16_t rate_num;
7779         cmdline_fixed_string_t q_msk;
7780         uint64_t q_msk_val;
7781 };
7782
7783 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7784                 __attribute__((unused)) struct cmdline *cl,
7785                 __attribute__((unused)) void *data)
7786 {
7787         struct cmd_vf_rate_limit_result *res = parsed_result;
7788         int ret = 0;
7789
7790         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7791                 && (strcmp(res->vf, "vf") == 0)
7792                 && (strcmp(res->rate, "rate") == 0)
7793                 && (strcmp(res->q_msk, "queue_mask") == 0))
7794                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7795                                         res->rate_num, res->q_msk_val);
7796         if (ret < 0)
7797                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7798
7799 }
7800
7801 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7802         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7803                                 set, "set");
7804 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7805         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7806                                 port, "port");
7807 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7808         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7809                                 port_num, UINT16);
7810 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7811         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7812                                 vf, "vf");
7813 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7814         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7815                                 vf_num, UINT8);
7816 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7817         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7818                                 rate, "rate");
7819 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7820         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7821                                 rate_num, UINT16);
7822 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7823         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7824                                 q_msk, "queue_mask");
7825 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7826         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7827                                 q_msk_val, UINT64);
7828
7829 cmdline_parse_inst_t cmd_vf_rate_limit = {
7830         .f = cmd_vf_rate_limit_parsed,
7831         .data = (void *)0,
7832         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7833                 "queue_mask <queue_mask_value>: "
7834                 "Set rate limit for queues of VF on port_id",
7835         .tokens = {
7836                 (void *)&cmd_vf_rate_limit_set,
7837                 (void *)&cmd_vf_rate_limit_port,
7838                 (void *)&cmd_vf_rate_limit_portnum,
7839                 (void *)&cmd_vf_rate_limit_vf,
7840                 (void *)&cmd_vf_rate_limit_vfnum,
7841                 (void *)&cmd_vf_rate_limit_rate,
7842                 (void *)&cmd_vf_rate_limit_ratenum,
7843                 (void *)&cmd_vf_rate_limit_q_msk,
7844                 (void *)&cmd_vf_rate_limit_q_msk_val,
7845                 NULL,
7846         },
7847 };
7848
7849 /* *** ADD TUNNEL FILTER OF A PORT *** */
7850 struct cmd_tunnel_filter_result {
7851         cmdline_fixed_string_t cmd;
7852         cmdline_fixed_string_t what;
7853         portid_t port_id;
7854         struct ether_addr outer_mac;
7855         struct ether_addr inner_mac;
7856         cmdline_ipaddr_t ip_value;
7857         uint16_t inner_vlan;
7858         cmdline_fixed_string_t tunnel_type;
7859         cmdline_fixed_string_t filter_type;
7860         uint32_t tenant_id;
7861         uint16_t queue_num;
7862 };
7863
7864 static void
7865 cmd_tunnel_filter_parsed(void *parsed_result,
7866                           __attribute__((unused)) struct cmdline *cl,
7867                           __attribute__((unused)) void *data)
7868 {
7869         struct cmd_tunnel_filter_result *res = parsed_result;
7870         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7871         int ret = 0;
7872
7873         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7874
7875         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7876         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7877         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7878
7879         if (res->ip_value.family == AF_INET) {
7880                 tunnel_filter_conf.ip_addr.ipv4_addr =
7881                         res->ip_value.addr.ipv4.s_addr;
7882                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7883         } else {
7884                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7885                         &(res->ip_value.addr.ipv6),
7886                         sizeof(struct in6_addr));
7887                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7888         }
7889
7890         if (!strcmp(res->filter_type, "imac-ivlan"))
7891                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7892         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7893                 tunnel_filter_conf.filter_type =
7894                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7895         else if (!strcmp(res->filter_type, "imac-tenid"))
7896                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7897         else if (!strcmp(res->filter_type, "imac"))
7898                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7899         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7900                 tunnel_filter_conf.filter_type =
7901                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7902         else if (!strcmp(res->filter_type, "oip"))
7903                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7904         else if (!strcmp(res->filter_type, "iip"))
7905                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7906         else {
7907                 printf("The filter type is not supported");
7908                 return;
7909         }
7910
7911         if (!strcmp(res->tunnel_type, "vxlan"))
7912                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7913         else if (!strcmp(res->tunnel_type, "nvgre"))
7914                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7915         else if (!strcmp(res->tunnel_type, "ipingre"))
7916                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7917         else {
7918                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7919                 return;
7920         }
7921
7922         tunnel_filter_conf.tenant_id = res->tenant_id;
7923         tunnel_filter_conf.queue_id = res->queue_num;
7924         if (!strcmp(res->what, "add"))
7925                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7926                                         RTE_ETH_FILTER_TUNNEL,
7927                                         RTE_ETH_FILTER_ADD,
7928                                         &tunnel_filter_conf);
7929         else
7930                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7931                                         RTE_ETH_FILTER_TUNNEL,
7932                                         RTE_ETH_FILTER_DELETE,
7933                                         &tunnel_filter_conf);
7934         if (ret < 0)
7935                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7936                                 strerror(-ret));
7937
7938 }
7939 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7940         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7941         cmd, "tunnel_filter");
7942 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7943         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7944         what, "add#rm");
7945 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7946         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7947         port_id, UINT16);
7948 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7949         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7950         outer_mac);
7951 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7952         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7953         inner_mac);
7954 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7955         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7956         inner_vlan, UINT16);
7957 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7958         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7959         ip_value);
7960 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7961         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7962         tunnel_type, "vxlan#nvgre#ipingre");
7963
7964 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7965         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7966         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7967                 "imac#omac-imac-tenid");
7968 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7969         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7970         tenant_id, UINT32);
7971 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7972         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7973         queue_num, UINT16);
7974
7975 cmdline_parse_inst_t cmd_tunnel_filter = {
7976         .f = cmd_tunnel_filter_parsed,
7977         .data = (void *)0,
7978         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7979                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7980                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7981                 "<queue_id>: Add/Rm tunnel filter of a port",
7982         .tokens = {
7983                 (void *)&cmd_tunnel_filter_cmd,
7984                 (void *)&cmd_tunnel_filter_what,
7985                 (void *)&cmd_tunnel_filter_port_id,
7986                 (void *)&cmd_tunnel_filter_outer_mac,
7987                 (void *)&cmd_tunnel_filter_inner_mac,
7988                 (void *)&cmd_tunnel_filter_ip_value,
7989                 (void *)&cmd_tunnel_filter_innner_vlan,
7990                 (void *)&cmd_tunnel_filter_tunnel_type,
7991                 (void *)&cmd_tunnel_filter_filter_type,
7992                 (void *)&cmd_tunnel_filter_tenant_id,
7993                 (void *)&cmd_tunnel_filter_queue_num,
7994                 NULL,
7995         },
7996 };
7997
7998 /* *** CONFIGURE TUNNEL UDP PORT *** */
7999 struct cmd_tunnel_udp_config {
8000         cmdline_fixed_string_t cmd;
8001         cmdline_fixed_string_t what;
8002         uint16_t udp_port;
8003         portid_t port_id;
8004 };
8005
8006 static void
8007 cmd_tunnel_udp_config_parsed(void *parsed_result,
8008                           __attribute__((unused)) struct cmdline *cl,
8009                           __attribute__((unused)) void *data)
8010 {
8011         struct cmd_tunnel_udp_config *res = parsed_result;
8012         struct rte_eth_udp_tunnel tunnel_udp;
8013         int ret;
8014
8015         tunnel_udp.udp_port = res->udp_port;
8016
8017         if (!strcmp(res->cmd, "rx_vxlan_port"))
8018                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8019
8020         if (!strcmp(res->what, "add"))
8021                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8022                                                       &tunnel_udp);
8023         else
8024                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8025                                                          &tunnel_udp);
8026
8027         if (ret < 0)
8028                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8029 }
8030
8031 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8032         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8033                                 cmd, "rx_vxlan_port");
8034 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8035         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8036                                 what, "add#rm");
8037 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8038         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8039                                 udp_port, UINT16);
8040 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8041         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8042                                 port_id, UINT16);
8043
8044 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8045         .f = cmd_tunnel_udp_config_parsed,
8046         .data = (void *)0,
8047         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8048                 "Add/Remove a tunneling UDP port filter",
8049         .tokens = {
8050                 (void *)&cmd_tunnel_udp_config_cmd,
8051                 (void *)&cmd_tunnel_udp_config_what,
8052                 (void *)&cmd_tunnel_udp_config_udp_port,
8053                 (void *)&cmd_tunnel_udp_config_port_id,
8054                 NULL,
8055         },
8056 };
8057
8058 /* *** GLOBAL CONFIG *** */
8059 struct cmd_global_config_result {
8060         cmdline_fixed_string_t cmd;
8061         portid_t port_id;
8062         cmdline_fixed_string_t cfg_type;
8063         uint8_t len;
8064 };
8065
8066 static void
8067 cmd_global_config_parsed(void *parsed_result,
8068                          __attribute__((unused)) struct cmdline *cl,
8069                          __attribute__((unused)) void *data)
8070 {
8071         struct cmd_global_config_result *res = parsed_result;
8072         struct rte_eth_global_cfg conf;
8073         int ret;
8074
8075         memset(&conf, 0, sizeof(conf));
8076         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8077         conf.cfg.gre_key_len = res->len;
8078         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8079                                       RTE_ETH_FILTER_SET, &conf);
8080         if (ret != 0)
8081                 printf("Global config error\n");
8082 }
8083
8084 cmdline_parse_token_string_t cmd_global_config_cmd =
8085         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8086                 "global_config");
8087 cmdline_parse_token_num_t cmd_global_config_port_id =
8088         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8089                                UINT16);
8090 cmdline_parse_token_string_t cmd_global_config_type =
8091         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8092                 cfg_type, "gre-key-len");
8093 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8094         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8095                 len, UINT8);
8096
8097 cmdline_parse_inst_t cmd_global_config = {
8098         .f = cmd_global_config_parsed,
8099         .data = (void *)NULL,
8100         .help_str = "global_config <port_id> gre-key-len <key_len>",
8101         .tokens = {
8102                 (void *)&cmd_global_config_cmd,
8103                 (void *)&cmd_global_config_port_id,
8104                 (void *)&cmd_global_config_type,
8105                 (void *)&cmd_global_config_gre_key_len,
8106                 NULL,
8107         },
8108 };
8109
8110 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8111 struct cmd_set_mirror_mask_result {
8112         cmdline_fixed_string_t set;
8113         cmdline_fixed_string_t port;
8114         portid_t port_id;
8115         cmdline_fixed_string_t mirror;
8116         uint8_t rule_id;
8117         cmdline_fixed_string_t what;
8118         cmdline_fixed_string_t value;
8119         cmdline_fixed_string_t dstpool;
8120         uint8_t dstpool_id;
8121         cmdline_fixed_string_t on;
8122 };
8123
8124 cmdline_parse_token_string_t cmd_mirror_mask_set =
8125         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8126                                 set, "set");
8127 cmdline_parse_token_string_t cmd_mirror_mask_port =
8128         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8129                                 port, "port");
8130 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8131         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8132                                 port_id, UINT16);
8133 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8134         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8135                                 mirror, "mirror-rule");
8136 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8137         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8138                                 rule_id, UINT8);
8139 cmdline_parse_token_string_t cmd_mirror_mask_what =
8140         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8141                                 what, "pool-mirror-up#pool-mirror-down"
8142                                       "#vlan-mirror");
8143 cmdline_parse_token_string_t cmd_mirror_mask_value =
8144         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8145                                 value, NULL);
8146 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8147         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8148                                 dstpool, "dst-pool");
8149 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8150         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8151                                 dstpool_id, UINT8);
8152 cmdline_parse_token_string_t cmd_mirror_mask_on =
8153         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8154                                 on, "on#off");
8155
8156 static void
8157 cmd_set_mirror_mask_parsed(void *parsed_result,
8158                        __attribute__((unused)) struct cmdline *cl,
8159                        __attribute__((unused)) void *data)
8160 {
8161         int ret,nb_item,i;
8162         struct cmd_set_mirror_mask_result *res = parsed_result;
8163         struct rte_eth_mirror_conf mr_conf;
8164
8165         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8166
8167         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8168
8169         mr_conf.dst_pool = res->dstpool_id;
8170
8171         if (!strcmp(res->what, "pool-mirror-up")) {
8172                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8173                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8174         } else if (!strcmp(res->what, "pool-mirror-down")) {
8175                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8176                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8177         } else if (!strcmp(res->what, "vlan-mirror")) {
8178                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8179                 nb_item = parse_item_list(res->value, "vlan",
8180                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8181                 if (nb_item <= 0)
8182                         return;
8183
8184                 for (i = 0; i < nb_item; i++) {
8185                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8186                                 printf("Invalid vlan_id: must be < 4096\n");
8187                                 return;
8188                         }
8189
8190                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8191                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8192                 }
8193         }
8194
8195         if (!strcmp(res->on, "on"))
8196                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8197                                                 res->rule_id, 1);
8198         else
8199                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8200                                                 res->rule_id, 0);
8201         if (ret < 0)
8202                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8203 }
8204
8205 cmdline_parse_inst_t cmd_set_mirror_mask = {
8206                 .f = cmd_set_mirror_mask_parsed,
8207                 .data = NULL,
8208                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8209                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8210                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8211                 .tokens = {
8212                         (void *)&cmd_mirror_mask_set,
8213                         (void *)&cmd_mirror_mask_port,
8214                         (void *)&cmd_mirror_mask_portid,
8215                         (void *)&cmd_mirror_mask_mirror,
8216                         (void *)&cmd_mirror_mask_ruleid,
8217                         (void *)&cmd_mirror_mask_what,
8218                         (void *)&cmd_mirror_mask_value,
8219                         (void *)&cmd_mirror_mask_dstpool,
8220                         (void *)&cmd_mirror_mask_poolid,
8221                         (void *)&cmd_mirror_mask_on,
8222                         NULL,
8223                 },
8224 };
8225
8226 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8227 struct cmd_set_mirror_link_result {
8228         cmdline_fixed_string_t set;
8229         cmdline_fixed_string_t port;
8230         portid_t port_id;
8231         cmdline_fixed_string_t mirror;
8232         uint8_t rule_id;
8233         cmdline_fixed_string_t what;
8234         cmdline_fixed_string_t dstpool;
8235         uint8_t dstpool_id;
8236         cmdline_fixed_string_t on;
8237 };
8238
8239 cmdline_parse_token_string_t cmd_mirror_link_set =
8240         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8241                                  set, "set");
8242 cmdline_parse_token_string_t cmd_mirror_link_port =
8243         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8244                                 port, "port");
8245 cmdline_parse_token_num_t cmd_mirror_link_portid =
8246         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8247                                 port_id, UINT16);
8248 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8249         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8250                                 mirror, "mirror-rule");
8251 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8252         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8253                             rule_id, UINT8);
8254 cmdline_parse_token_string_t cmd_mirror_link_what =
8255         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8256                                 what, "uplink-mirror#downlink-mirror");
8257 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8258         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8259                                 dstpool, "dst-pool");
8260 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8261         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8262                                 dstpool_id, UINT8);
8263 cmdline_parse_token_string_t cmd_mirror_link_on =
8264         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8265                                 on, "on#off");
8266
8267 static void
8268 cmd_set_mirror_link_parsed(void *parsed_result,
8269                        __attribute__((unused)) struct cmdline *cl,
8270                        __attribute__((unused)) void *data)
8271 {
8272         int ret;
8273         struct cmd_set_mirror_link_result *res = parsed_result;
8274         struct rte_eth_mirror_conf mr_conf;
8275
8276         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8277         if (!strcmp(res->what, "uplink-mirror"))
8278                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8279         else
8280                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8281
8282         mr_conf.dst_pool = res->dstpool_id;
8283
8284         if (!strcmp(res->on, "on"))
8285                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8286                                                 res->rule_id, 1);
8287         else
8288                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8289                                                 res->rule_id, 0);
8290
8291         /* check the return value and print it if is < 0 */
8292         if (ret < 0)
8293                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8294
8295 }
8296
8297 cmdline_parse_inst_t cmd_set_mirror_link = {
8298                 .f = cmd_set_mirror_link_parsed,
8299                 .data = NULL,
8300                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8301                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8302                 .tokens = {
8303                         (void *)&cmd_mirror_link_set,
8304                         (void *)&cmd_mirror_link_port,
8305                         (void *)&cmd_mirror_link_portid,
8306                         (void *)&cmd_mirror_link_mirror,
8307                         (void *)&cmd_mirror_link_ruleid,
8308                         (void *)&cmd_mirror_link_what,
8309                         (void *)&cmd_mirror_link_dstpool,
8310                         (void *)&cmd_mirror_link_poolid,
8311                         (void *)&cmd_mirror_link_on,
8312                         NULL,
8313                 },
8314 };
8315
8316 /* *** RESET VM MIRROR RULE *** */
8317 struct cmd_rm_mirror_rule_result {
8318         cmdline_fixed_string_t reset;
8319         cmdline_fixed_string_t port;
8320         portid_t port_id;
8321         cmdline_fixed_string_t mirror;
8322         uint8_t rule_id;
8323 };
8324
8325 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8326         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8327                                  reset, "reset");
8328 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8329         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8330                                 port, "port");
8331 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8332         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8333                                 port_id, UINT16);
8334 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8335         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8336                                 mirror, "mirror-rule");
8337 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8338         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8339                                 rule_id, UINT8);
8340
8341 static void
8342 cmd_reset_mirror_rule_parsed(void *parsed_result,
8343                        __attribute__((unused)) struct cmdline *cl,
8344                        __attribute__((unused)) void *data)
8345 {
8346         int ret;
8347         struct cmd_set_mirror_link_result *res = parsed_result;
8348         /* check rule_id */
8349         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8350         if(ret < 0)
8351                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8352 }
8353
8354 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8355                 .f = cmd_reset_mirror_rule_parsed,
8356                 .data = NULL,
8357                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8358                 .tokens = {
8359                         (void *)&cmd_rm_mirror_rule_reset,
8360                         (void *)&cmd_rm_mirror_rule_port,
8361                         (void *)&cmd_rm_mirror_rule_portid,
8362                         (void *)&cmd_rm_mirror_rule_mirror,
8363                         (void *)&cmd_rm_mirror_rule_ruleid,
8364                         NULL,
8365                 },
8366 };
8367
8368 /* ******************************************************************************** */
8369
8370 struct cmd_dump_result {
8371         cmdline_fixed_string_t dump;
8372 };
8373
8374 static void
8375 dump_struct_sizes(void)
8376 {
8377 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8378         DUMP_SIZE(struct rte_mbuf);
8379         DUMP_SIZE(struct rte_mempool);
8380         DUMP_SIZE(struct rte_ring);
8381 #undef DUMP_SIZE
8382 }
8383
8384 static void cmd_dump_parsed(void *parsed_result,
8385                             __attribute__((unused)) struct cmdline *cl,
8386                             __attribute__((unused)) void *data)
8387 {
8388         struct cmd_dump_result *res = parsed_result;
8389
8390         if (!strcmp(res->dump, "dump_physmem"))
8391                 rte_dump_physmem_layout(stdout);
8392         else if (!strcmp(res->dump, "dump_memzone"))
8393                 rte_memzone_dump(stdout);
8394         else if (!strcmp(res->dump, "dump_struct_sizes"))
8395                 dump_struct_sizes();
8396         else if (!strcmp(res->dump, "dump_ring"))
8397                 rte_ring_list_dump(stdout);
8398         else if (!strcmp(res->dump, "dump_mempool"))
8399                 rte_mempool_list_dump(stdout);
8400         else if (!strcmp(res->dump, "dump_devargs"))
8401                 rte_eal_devargs_dump(stdout);
8402         else if (!strcmp(res->dump, "dump_log_types"))
8403                 rte_log_dump(stdout);
8404 }
8405
8406 cmdline_parse_token_string_t cmd_dump_dump =
8407         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8408                 "dump_physmem#"
8409                 "dump_memzone#"
8410                 "dump_struct_sizes#"
8411                 "dump_ring#"
8412                 "dump_mempool#"
8413                 "dump_devargs#"
8414                 "dump_log_types");
8415
8416 cmdline_parse_inst_t cmd_dump = {
8417         .f = cmd_dump_parsed,  /* function to call */
8418         .data = NULL,      /* 2nd arg of func */
8419         .help_str = "Dump status",
8420         .tokens = {        /* token list, NULL terminated */
8421                 (void *)&cmd_dump_dump,
8422                 NULL,
8423         },
8424 };
8425
8426 /* ******************************************************************************** */
8427
8428 struct cmd_dump_one_result {
8429         cmdline_fixed_string_t dump;
8430         cmdline_fixed_string_t name;
8431 };
8432
8433 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8434                                 __attribute__((unused)) void *data)
8435 {
8436         struct cmd_dump_one_result *res = parsed_result;
8437
8438         if (!strcmp(res->dump, "dump_ring")) {
8439                 struct rte_ring *r;
8440                 r = rte_ring_lookup(res->name);
8441                 if (r == NULL) {
8442                         cmdline_printf(cl, "Cannot find ring\n");
8443                         return;
8444                 }
8445                 rte_ring_dump(stdout, r);
8446         } else if (!strcmp(res->dump, "dump_mempool")) {
8447                 struct rte_mempool *mp;
8448                 mp = rte_mempool_lookup(res->name);
8449                 if (mp == NULL) {
8450                         cmdline_printf(cl, "Cannot find mempool\n");
8451                         return;
8452                 }
8453                 rte_mempool_dump(stdout, mp);
8454         }
8455 }
8456
8457 cmdline_parse_token_string_t cmd_dump_one_dump =
8458         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8459                                  "dump_ring#dump_mempool");
8460
8461 cmdline_parse_token_string_t cmd_dump_one_name =
8462         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8463
8464 cmdline_parse_inst_t cmd_dump_one = {
8465         .f = cmd_dump_one_parsed,  /* function to call */
8466         .data = NULL,      /* 2nd arg of func */
8467         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8468         .tokens = {        /* token list, NULL terminated */
8469                 (void *)&cmd_dump_one_dump,
8470                 (void *)&cmd_dump_one_name,
8471                 NULL,
8472         },
8473 };
8474
8475 /* *** Add/Del syn filter *** */
8476 struct cmd_syn_filter_result {
8477         cmdline_fixed_string_t filter;
8478         portid_t port_id;
8479         cmdline_fixed_string_t ops;
8480         cmdline_fixed_string_t priority;
8481         cmdline_fixed_string_t high;
8482         cmdline_fixed_string_t queue;
8483         uint16_t queue_id;
8484 };
8485
8486 static void
8487 cmd_syn_filter_parsed(void *parsed_result,
8488                         __attribute__((unused)) struct cmdline *cl,
8489                         __attribute__((unused)) void *data)
8490 {
8491         struct cmd_syn_filter_result *res = parsed_result;
8492         struct rte_eth_syn_filter syn_filter;
8493         int ret = 0;
8494
8495         ret = rte_eth_dev_filter_supported(res->port_id,
8496                                         RTE_ETH_FILTER_SYN);
8497         if (ret < 0) {
8498                 printf("syn filter is not supported on port %u.\n",
8499                                 res->port_id);
8500                 return;
8501         }
8502
8503         memset(&syn_filter, 0, sizeof(syn_filter));
8504
8505         if (!strcmp(res->ops, "add")) {
8506                 if (!strcmp(res->high, "high"))
8507                         syn_filter.hig_pri = 1;
8508                 else
8509                         syn_filter.hig_pri = 0;
8510
8511                 syn_filter.queue = res->queue_id;
8512                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8513                                                 RTE_ETH_FILTER_SYN,
8514                                                 RTE_ETH_FILTER_ADD,
8515                                                 &syn_filter);
8516         } else
8517                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8518                                                 RTE_ETH_FILTER_SYN,
8519                                                 RTE_ETH_FILTER_DELETE,
8520                                                 &syn_filter);
8521
8522         if (ret < 0)
8523                 printf("syn filter programming error: (%s)\n",
8524                                 strerror(-ret));
8525 }
8526
8527 cmdline_parse_token_string_t cmd_syn_filter_filter =
8528         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8529         filter, "syn_filter");
8530 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8531         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8532         port_id, UINT16);
8533 cmdline_parse_token_string_t cmd_syn_filter_ops =
8534         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8535         ops, "add#del");
8536 cmdline_parse_token_string_t cmd_syn_filter_priority =
8537         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8538                                 priority, "priority");
8539 cmdline_parse_token_string_t cmd_syn_filter_high =
8540         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8541                                 high, "high#low");
8542 cmdline_parse_token_string_t cmd_syn_filter_queue =
8543         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8544                                 queue, "queue");
8545 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8546         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8547                                 queue_id, UINT16);
8548
8549 cmdline_parse_inst_t cmd_syn_filter = {
8550         .f = cmd_syn_filter_parsed,
8551         .data = NULL,
8552         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8553                 "<queue_id>: Add/Delete syn filter",
8554         .tokens = {
8555                 (void *)&cmd_syn_filter_filter,
8556                 (void *)&cmd_syn_filter_port_id,
8557                 (void *)&cmd_syn_filter_ops,
8558                 (void *)&cmd_syn_filter_priority,
8559                 (void *)&cmd_syn_filter_high,
8560                 (void *)&cmd_syn_filter_queue,
8561                 (void *)&cmd_syn_filter_queue_id,
8562                 NULL,
8563         },
8564 };
8565
8566 /* *** queue region set *** */
8567 struct cmd_queue_region_result {
8568         cmdline_fixed_string_t set;
8569         cmdline_fixed_string_t port;
8570         portid_t port_id;
8571         cmdline_fixed_string_t cmd;
8572         cmdline_fixed_string_t region;
8573         uint8_t  region_id;
8574         cmdline_fixed_string_t queue_start_index;
8575         uint8_t  queue_id;
8576         cmdline_fixed_string_t queue_num;
8577         uint8_t  queue_num_value;
8578 };
8579
8580 static void
8581 cmd_queue_region_parsed(void *parsed_result,
8582                         __attribute__((unused)) struct cmdline *cl,
8583                         __attribute__((unused)) void *data)
8584 {
8585         struct cmd_queue_region_result *res = parsed_result;
8586         int ret = -ENOTSUP;
8587 #ifdef RTE_LIBRTE_I40E_PMD
8588         struct rte_pmd_i40e_queue_region_conf region_conf;
8589         enum rte_pmd_i40e_queue_region_op op_type;
8590 #endif
8591
8592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8593                 return;
8594
8595 #ifdef RTE_LIBRTE_I40E_PMD
8596         memset(&region_conf, 0, sizeof(region_conf));
8597         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8598         region_conf.region_id = res->region_id;
8599         region_conf.queue_num = res->queue_num_value;
8600         region_conf.queue_start_index = res->queue_id;
8601
8602         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8603                                 op_type, &region_conf);
8604 #endif
8605
8606         switch (ret) {
8607         case 0:
8608                 break;
8609         case -ENOTSUP:
8610                 printf("function not implemented or supported\n");
8611                 break;
8612         default:
8613                 printf("queue region config error: (%s)\n", strerror(-ret));
8614         }
8615 }
8616
8617 cmdline_parse_token_string_t cmd_queue_region_set =
8618 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8619                 set, "set");
8620 cmdline_parse_token_string_t cmd_queue_region_port =
8621         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8622 cmdline_parse_token_num_t cmd_queue_region_port_id =
8623         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8624                                 port_id, UINT16);
8625 cmdline_parse_token_string_t cmd_queue_region_cmd =
8626         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8627                                  cmd, "queue-region");
8628 cmdline_parse_token_string_t cmd_queue_region_id =
8629         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8630                                 region, "region_id");
8631 cmdline_parse_token_num_t cmd_queue_region_index =
8632         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8633                                 region_id, UINT8);
8634 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8635         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8636                                 queue_start_index, "queue_start_index");
8637 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8638         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8639                                 queue_id, UINT8);
8640 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8641         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8642                                 queue_num, "queue_num");
8643 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8644         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8645                                 queue_num_value, UINT8);
8646
8647 cmdline_parse_inst_t cmd_queue_region = {
8648         .f = cmd_queue_region_parsed,
8649         .data = NULL,
8650         .help_str = "set port <port_id> queue-region region_id <value> "
8651                 "queue_start_index <value> queue_num <value>: Set a queue region",
8652         .tokens = {
8653                 (void *)&cmd_queue_region_set,
8654                 (void *)&cmd_queue_region_port,
8655                 (void *)&cmd_queue_region_port_id,
8656                 (void *)&cmd_queue_region_cmd,
8657                 (void *)&cmd_queue_region_id,
8658                 (void *)&cmd_queue_region_index,
8659                 (void *)&cmd_queue_region_queue_start_index,
8660                 (void *)&cmd_queue_region_queue_id,
8661                 (void *)&cmd_queue_region_queue_num,
8662                 (void *)&cmd_queue_region_queue_num_value,
8663                 NULL,
8664         },
8665 };
8666
8667 /* *** queue region and flowtype set *** */
8668 struct cmd_region_flowtype_result {
8669         cmdline_fixed_string_t set;
8670         cmdline_fixed_string_t port;
8671         portid_t port_id;
8672         cmdline_fixed_string_t cmd;
8673         cmdline_fixed_string_t region;
8674         uint8_t  region_id;
8675         cmdline_fixed_string_t flowtype;
8676         uint8_t  flowtype_id;
8677 };
8678
8679 static void
8680 cmd_region_flowtype_parsed(void *parsed_result,
8681                         __attribute__((unused)) struct cmdline *cl,
8682                         __attribute__((unused)) void *data)
8683 {
8684         struct cmd_region_flowtype_result *res = parsed_result;
8685         int ret = -ENOTSUP;
8686 #ifdef RTE_LIBRTE_I40E_PMD
8687         struct rte_pmd_i40e_queue_region_conf region_conf;
8688         enum rte_pmd_i40e_queue_region_op op_type;
8689 #endif
8690
8691         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8692                 return;
8693
8694 #ifdef RTE_LIBRTE_I40E_PMD
8695         memset(&region_conf, 0, sizeof(region_conf));
8696
8697         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8698         region_conf.region_id = res->region_id;
8699         region_conf.hw_flowtype = res->flowtype_id;
8700
8701         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8702                         op_type, &region_conf);
8703 #endif
8704
8705         switch (ret) {
8706         case 0:
8707                 break;
8708         case -ENOTSUP:
8709                 printf("function not implemented or supported\n");
8710                 break;
8711         default:
8712                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8713         }
8714 }
8715
8716 cmdline_parse_token_string_t cmd_region_flowtype_set =
8717 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8718                                 set, "set");
8719 cmdline_parse_token_string_t cmd_region_flowtype_port =
8720         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8721                                 port, "port");
8722 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8723         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8724                                 port_id, UINT16);
8725 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8726         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8727                                 cmd, "queue-region");
8728 cmdline_parse_token_string_t cmd_region_flowtype_index =
8729         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8730                                 region, "region_id");
8731 cmdline_parse_token_num_t cmd_region_flowtype_id =
8732         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8733                                 region_id, UINT8);
8734 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8735         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8736                                 flowtype, "flowtype");
8737 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8738         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8739                                 flowtype_id, UINT8);
8740 cmdline_parse_inst_t cmd_region_flowtype = {
8741         .f = cmd_region_flowtype_parsed,
8742         .data = NULL,
8743         .help_str = "set port <port_id> queue-region region_id <value> "
8744                 "flowtype <value>: Set a flowtype region index",
8745         .tokens = {
8746                 (void *)&cmd_region_flowtype_set,
8747                 (void *)&cmd_region_flowtype_port,
8748                 (void *)&cmd_region_flowtype_port_index,
8749                 (void *)&cmd_region_flowtype_cmd,
8750                 (void *)&cmd_region_flowtype_index,
8751                 (void *)&cmd_region_flowtype_id,
8752                 (void *)&cmd_region_flowtype_flow_index,
8753                 (void *)&cmd_region_flowtype_flow_id,
8754                 NULL,
8755         },
8756 };
8757
8758 /* *** User Priority (UP) to queue region (region_id) set *** */
8759 struct cmd_user_priority_region_result {
8760         cmdline_fixed_string_t set;
8761         cmdline_fixed_string_t port;
8762         portid_t port_id;
8763         cmdline_fixed_string_t cmd;
8764         cmdline_fixed_string_t user_priority;
8765         uint8_t  user_priority_id;
8766         cmdline_fixed_string_t region;
8767         uint8_t  region_id;
8768 };
8769
8770 static void
8771 cmd_user_priority_region_parsed(void *parsed_result,
8772                         __attribute__((unused)) struct cmdline *cl,
8773                         __attribute__((unused)) void *data)
8774 {
8775         struct cmd_user_priority_region_result *res = parsed_result;
8776         int ret = -ENOTSUP;
8777 #ifdef RTE_LIBRTE_I40E_PMD
8778         struct rte_pmd_i40e_queue_region_conf region_conf;
8779         enum rte_pmd_i40e_queue_region_op op_type;
8780 #endif
8781
8782         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8783                 return;
8784
8785 #ifdef RTE_LIBRTE_I40E_PMD
8786         memset(&region_conf, 0, sizeof(region_conf));
8787         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8788         region_conf.user_priority = res->user_priority_id;
8789         region_conf.region_id = res->region_id;
8790
8791         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8792                                 op_type, &region_conf);
8793 #endif
8794
8795         switch (ret) {
8796         case 0:
8797                 break;
8798         case -ENOTSUP:
8799                 printf("function not implemented or supported\n");
8800                 break;
8801         default:
8802                 printf("user_priority region config error: (%s)\n",
8803                                 strerror(-ret));
8804         }
8805 }
8806
8807 cmdline_parse_token_string_t cmd_user_priority_region_set =
8808         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8809                                 set, "set");
8810 cmdline_parse_token_string_t cmd_user_priority_region_port =
8811         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8812                                 port, "port");
8813 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8814         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8815                                 port_id, UINT16);
8816 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8817         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8818                                 cmd, "queue-region");
8819 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8820         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8821                                 user_priority, "UP");
8822 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8823         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8824                                 user_priority_id, UINT8);
8825 cmdline_parse_token_string_t cmd_user_priority_region_region =
8826         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8827                                 region, "region_id");
8828 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8829         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8830                                 region_id, UINT8);
8831
8832 cmdline_parse_inst_t cmd_user_priority_region = {
8833         .f = cmd_user_priority_region_parsed,
8834         .data = NULL,
8835         .help_str = "set port <port_id> queue-region UP <value> "
8836                 "region_id <value>: Set the mapping of User Priority (UP) "
8837                 "to queue region (region_id) ",
8838         .tokens = {
8839                 (void *)&cmd_user_priority_region_set,
8840                 (void *)&cmd_user_priority_region_port,
8841                 (void *)&cmd_user_priority_region_port_index,
8842                 (void *)&cmd_user_priority_region_cmd,
8843                 (void *)&cmd_user_priority_region_UP,
8844                 (void *)&cmd_user_priority_region_UP_id,
8845                 (void *)&cmd_user_priority_region_region,
8846                 (void *)&cmd_user_priority_region_region_id,
8847                 NULL,
8848         },
8849 };
8850
8851 /* *** flush all queue region related configuration *** */
8852 struct cmd_flush_queue_region_result {
8853         cmdline_fixed_string_t set;
8854         cmdline_fixed_string_t port;
8855         portid_t port_id;
8856         cmdline_fixed_string_t cmd;
8857         cmdline_fixed_string_t flush;
8858         cmdline_fixed_string_t what;
8859 };
8860
8861 static void
8862 cmd_flush_queue_region_parsed(void *parsed_result,
8863                         __attribute__((unused)) struct cmdline *cl,
8864                         __attribute__((unused)) void *data)
8865 {
8866         struct cmd_flush_queue_region_result *res = parsed_result;
8867         int ret = -ENOTSUP;
8868 #ifdef RTE_LIBRTE_I40E_PMD
8869         struct rte_pmd_i40e_queue_region_conf region_conf;
8870         enum rte_pmd_i40e_queue_region_op op_type;
8871 #endif
8872
8873         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8874                 return;
8875
8876 #ifdef RTE_LIBRTE_I40E_PMD
8877         memset(&region_conf, 0, sizeof(region_conf));
8878
8879         if (strcmp(res->what, "on") == 0)
8880                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8881         else
8882                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8883
8884         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8885                                 op_type, &region_conf);
8886 #endif
8887
8888         switch (ret) {
8889         case 0:
8890                 break;
8891         case -ENOTSUP:
8892                 printf("function not implemented or supported\n");
8893                 break;
8894         default:
8895                 printf("queue region config flush error: (%s)\n",
8896                                 strerror(-ret));
8897         }
8898 }
8899
8900 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8901         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8902                                 set, "set");
8903 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8904         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8905                                 port, "port");
8906 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8907         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8908                                 port_id, UINT16);
8909 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8910         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8911                                 cmd, "queue-region");
8912 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8913         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8914                                 flush, "flush");
8915 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8916         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8917                                 what, "on#off");
8918
8919 cmdline_parse_inst_t cmd_flush_queue_region = {
8920         .f = cmd_flush_queue_region_parsed,
8921         .data = NULL,
8922         .help_str = "set port <port_id> queue-region flush on|off"
8923                 ": flush all queue region related configuration",
8924         .tokens = {
8925                 (void *)&cmd_flush_queue_region_set,
8926                 (void *)&cmd_flush_queue_region_port,
8927                 (void *)&cmd_flush_queue_region_port_index,
8928                 (void *)&cmd_flush_queue_region_cmd,
8929                 (void *)&cmd_flush_queue_region_flush,
8930                 (void *)&cmd_flush_queue_region_what,
8931                 NULL,
8932         },
8933 };
8934
8935 /* *** get all queue region related configuration info *** */
8936 struct cmd_show_queue_region_info {
8937         cmdline_fixed_string_t show;
8938         cmdline_fixed_string_t port;
8939         portid_t port_id;
8940         cmdline_fixed_string_t cmd;
8941 };
8942
8943 static void
8944 cmd_show_queue_region_info_parsed(void *parsed_result,
8945                         __attribute__((unused)) struct cmdline *cl,
8946                         __attribute__((unused)) void *data)
8947 {
8948         struct cmd_show_queue_region_info *res = parsed_result;
8949         int ret = -ENOTSUP;
8950 #ifdef RTE_LIBRTE_I40E_PMD
8951         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
8952         enum rte_pmd_i40e_queue_region_op op_type;
8953 #endif
8954
8955         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8956                 return;
8957
8958 #ifdef RTE_LIBRTE_I40E_PMD
8959         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
8960
8961         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
8962
8963         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8964                                         op_type, &rte_pmd_regions);
8965
8966         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
8967 #endif
8968
8969         switch (ret) {
8970         case 0:
8971                 break;
8972         case -ENOTSUP:
8973                 printf("function not implemented or supported\n");
8974                 break;
8975         default:
8976                 printf("queue region config info show error: (%s)\n",
8977                                 strerror(-ret));
8978         }
8979 }
8980
8981 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
8982 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8983                                 show, "show");
8984 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
8985         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8986                                 port, "port");
8987 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
8988         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
8989                                 port_id, UINT16);
8990 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
8991         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8992                                 cmd, "queue-region");
8993
8994 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
8995         .f = cmd_show_queue_region_info_parsed,
8996         .data = NULL,
8997         .help_str = "show port <port_id> queue-region"
8998                 ": show all queue region related configuration info",
8999         .tokens = {
9000                 (void *)&cmd_show_queue_region_info_get,
9001                 (void *)&cmd_show_queue_region_info_port,
9002                 (void *)&cmd_show_queue_region_info_port_index,
9003                 (void *)&cmd_show_queue_region_info_cmd,
9004                 NULL,
9005         },
9006 };
9007
9008 /* *** ADD/REMOVE A 2tuple FILTER *** */
9009 struct cmd_2tuple_filter_result {
9010         cmdline_fixed_string_t filter;
9011         portid_t port_id;
9012         cmdline_fixed_string_t ops;
9013         cmdline_fixed_string_t dst_port;
9014         uint16_t dst_port_value;
9015         cmdline_fixed_string_t protocol;
9016         uint8_t protocol_value;
9017         cmdline_fixed_string_t mask;
9018         uint8_t  mask_value;
9019         cmdline_fixed_string_t tcp_flags;
9020         uint8_t tcp_flags_value;
9021         cmdline_fixed_string_t priority;
9022         uint8_t  priority_value;
9023         cmdline_fixed_string_t queue;
9024         uint16_t  queue_id;
9025 };
9026
9027 static void
9028 cmd_2tuple_filter_parsed(void *parsed_result,
9029                         __attribute__((unused)) struct cmdline *cl,
9030                         __attribute__((unused)) void *data)
9031 {
9032         struct rte_eth_ntuple_filter filter;
9033         struct cmd_2tuple_filter_result *res = parsed_result;
9034         int ret = 0;
9035
9036         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9037         if (ret < 0) {
9038                 printf("ntuple filter is not supported on port %u.\n",
9039                         res->port_id);
9040                 return;
9041         }
9042
9043         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9044
9045         filter.flags = RTE_2TUPLE_FLAGS;
9046         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9047         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9048         filter.proto = res->protocol_value;
9049         filter.priority = res->priority_value;
9050         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9051                 printf("nonzero tcp_flags is only meaningful"
9052                         " when protocol is TCP.\n");
9053                 return;
9054         }
9055         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9056                 printf("invalid TCP flags.\n");
9057                 return;
9058         }
9059
9060         if (res->tcp_flags_value != 0) {
9061                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9062                 filter.tcp_flags = res->tcp_flags_value;
9063         }
9064
9065         /* need convert to big endian. */
9066         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9067         filter.queue = res->queue_id;
9068
9069         if (!strcmp(res->ops, "add"))
9070                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9071                                 RTE_ETH_FILTER_NTUPLE,
9072                                 RTE_ETH_FILTER_ADD,
9073                                 &filter);
9074         else
9075                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9076                                 RTE_ETH_FILTER_NTUPLE,
9077                                 RTE_ETH_FILTER_DELETE,
9078                                 &filter);
9079         if (ret < 0)
9080                 printf("2tuple filter programming error: (%s)\n",
9081                         strerror(-ret));
9082
9083 }
9084
9085 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9086         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9087                                  filter, "2tuple_filter");
9088 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9089         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9090                                 port_id, UINT16);
9091 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9092         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9093                                  ops, "add#del");
9094 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9095         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9096                                 dst_port, "dst_port");
9097 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9098         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9099                                 dst_port_value, UINT16);
9100 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9101         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9102                                 protocol, "protocol");
9103 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9104         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9105                                 protocol_value, UINT8);
9106 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9107         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9108                                 mask, "mask");
9109 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9110         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9111                                 mask_value, INT8);
9112 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9113         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9114                                 tcp_flags, "tcp_flags");
9115 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9116         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9117                                 tcp_flags_value, UINT8);
9118 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9119         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9120                                 priority, "priority");
9121 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9122         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9123                                 priority_value, UINT8);
9124 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9125         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9126                                 queue, "queue");
9127 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9128         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9129                                 queue_id, UINT16);
9130
9131 cmdline_parse_inst_t cmd_2tuple_filter = {
9132         .f = cmd_2tuple_filter_parsed,
9133         .data = NULL,
9134         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9135                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9136                 "<queue_id>: Add a 2tuple filter",
9137         .tokens = {
9138                 (void *)&cmd_2tuple_filter_filter,
9139                 (void *)&cmd_2tuple_filter_port_id,
9140                 (void *)&cmd_2tuple_filter_ops,
9141                 (void *)&cmd_2tuple_filter_dst_port,
9142                 (void *)&cmd_2tuple_filter_dst_port_value,
9143                 (void *)&cmd_2tuple_filter_protocol,
9144                 (void *)&cmd_2tuple_filter_protocol_value,
9145                 (void *)&cmd_2tuple_filter_mask,
9146                 (void *)&cmd_2tuple_filter_mask_value,
9147                 (void *)&cmd_2tuple_filter_tcp_flags,
9148                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9149                 (void *)&cmd_2tuple_filter_priority,
9150                 (void *)&cmd_2tuple_filter_priority_value,
9151                 (void *)&cmd_2tuple_filter_queue,
9152                 (void *)&cmd_2tuple_filter_queue_id,
9153                 NULL,
9154         },
9155 };
9156
9157 /* *** ADD/REMOVE A 5tuple FILTER *** */
9158 struct cmd_5tuple_filter_result {
9159         cmdline_fixed_string_t filter;
9160         portid_t port_id;
9161         cmdline_fixed_string_t ops;
9162         cmdline_fixed_string_t dst_ip;
9163         cmdline_ipaddr_t dst_ip_value;
9164         cmdline_fixed_string_t src_ip;
9165         cmdline_ipaddr_t src_ip_value;
9166         cmdline_fixed_string_t dst_port;
9167         uint16_t dst_port_value;
9168         cmdline_fixed_string_t src_port;
9169         uint16_t src_port_value;
9170         cmdline_fixed_string_t protocol;
9171         uint8_t protocol_value;
9172         cmdline_fixed_string_t mask;
9173         uint8_t  mask_value;
9174         cmdline_fixed_string_t tcp_flags;
9175         uint8_t tcp_flags_value;
9176         cmdline_fixed_string_t priority;
9177         uint8_t  priority_value;
9178         cmdline_fixed_string_t queue;
9179         uint16_t  queue_id;
9180 };
9181
9182 static void
9183 cmd_5tuple_filter_parsed(void *parsed_result,
9184                         __attribute__((unused)) struct cmdline *cl,
9185                         __attribute__((unused)) void *data)
9186 {
9187         struct rte_eth_ntuple_filter filter;
9188         struct cmd_5tuple_filter_result *res = parsed_result;
9189         int ret = 0;
9190
9191         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9192         if (ret < 0) {
9193                 printf("ntuple filter is not supported on port %u.\n",
9194                         res->port_id);
9195                 return;
9196         }
9197
9198         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9199
9200         filter.flags = RTE_5TUPLE_FLAGS;
9201         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9202         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9203         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9204         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9205         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9206         filter.proto = res->protocol_value;
9207         filter.priority = res->priority_value;
9208         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9209                 printf("nonzero tcp_flags is only meaningful"
9210                         " when protocol is TCP.\n");
9211                 return;
9212         }
9213         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9214                 printf("invalid TCP flags.\n");
9215                 return;
9216         }
9217
9218         if (res->tcp_flags_value != 0) {
9219                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9220                 filter.tcp_flags = res->tcp_flags_value;
9221         }
9222
9223         if (res->dst_ip_value.family == AF_INET)
9224                 /* no need to convert, already big endian. */
9225                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9226         else {
9227                 if (filter.dst_ip_mask == 0) {
9228                         printf("can not support ipv6 involved compare.\n");
9229                         return;
9230                 }
9231                 filter.dst_ip = 0;
9232         }
9233
9234         if (res->src_ip_value.family == AF_INET)
9235                 /* no need to convert, already big endian. */
9236                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9237         else {
9238                 if (filter.src_ip_mask == 0) {
9239                         printf("can not support ipv6 involved compare.\n");
9240                         return;
9241                 }
9242                 filter.src_ip = 0;
9243         }
9244         /* need convert to big endian. */
9245         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9246         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9247         filter.queue = res->queue_id;
9248
9249         if (!strcmp(res->ops, "add"))
9250                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9251                                 RTE_ETH_FILTER_NTUPLE,
9252                                 RTE_ETH_FILTER_ADD,
9253                                 &filter);
9254         else
9255                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9256                                 RTE_ETH_FILTER_NTUPLE,
9257                                 RTE_ETH_FILTER_DELETE,
9258                                 &filter);
9259         if (ret < 0)
9260                 printf("5tuple filter programming error: (%s)\n",
9261                         strerror(-ret));
9262 }
9263
9264 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9265         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9266                                  filter, "5tuple_filter");
9267 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9268         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9269                                 port_id, UINT16);
9270 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9271         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9272                                  ops, "add#del");
9273 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9274         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9275                                 dst_ip, "dst_ip");
9276 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9277         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9278                                 dst_ip_value);
9279 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9280         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9281                                 src_ip, "src_ip");
9282 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9283         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9284                                 src_ip_value);
9285 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9286         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9287                                 dst_port, "dst_port");
9288 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9289         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9290                                 dst_port_value, UINT16);
9291 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9292         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9293                                 src_port, "src_port");
9294 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9295         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9296                                 src_port_value, UINT16);
9297 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9298         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9299                                 protocol, "protocol");
9300 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9301         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9302                                 protocol_value, UINT8);
9303 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9304         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9305                                 mask, "mask");
9306 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9307         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9308                                 mask_value, INT8);
9309 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9310         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9311                                 tcp_flags, "tcp_flags");
9312 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9313         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9314                                 tcp_flags_value, UINT8);
9315 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9316         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9317                                 priority, "priority");
9318 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9319         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9320                                 priority_value, UINT8);
9321 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9322         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9323                                 queue, "queue");
9324 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9325         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9326                                 queue_id, UINT16);
9327
9328 cmdline_parse_inst_t cmd_5tuple_filter = {
9329         .f = cmd_5tuple_filter_parsed,
9330         .data = NULL,
9331         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9332                 "src_ip <value> dst_port <value> src_port <value> "
9333                 "protocol <value>  mask <value> tcp_flags <value> "
9334                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9335         .tokens = {
9336                 (void *)&cmd_5tuple_filter_filter,
9337                 (void *)&cmd_5tuple_filter_port_id,
9338                 (void *)&cmd_5tuple_filter_ops,
9339                 (void *)&cmd_5tuple_filter_dst_ip,
9340                 (void *)&cmd_5tuple_filter_dst_ip_value,
9341                 (void *)&cmd_5tuple_filter_src_ip,
9342                 (void *)&cmd_5tuple_filter_src_ip_value,
9343                 (void *)&cmd_5tuple_filter_dst_port,
9344                 (void *)&cmd_5tuple_filter_dst_port_value,
9345                 (void *)&cmd_5tuple_filter_src_port,
9346                 (void *)&cmd_5tuple_filter_src_port_value,
9347                 (void *)&cmd_5tuple_filter_protocol,
9348                 (void *)&cmd_5tuple_filter_protocol_value,
9349                 (void *)&cmd_5tuple_filter_mask,
9350                 (void *)&cmd_5tuple_filter_mask_value,
9351                 (void *)&cmd_5tuple_filter_tcp_flags,
9352                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9353                 (void *)&cmd_5tuple_filter_priority,
9354                 (void *)&cmd_5tuple_filter_priority_value,
9355                 (void *)&cmd_5tuple_filter_queue,
9356                 (void *)&cmd_5tuple_filter_queue_id,
9357                 NULL,
9358         },
9359 };
9360
9361 /* *** ADD/REMOVE A flex FILTER *** */
9362 struct cmd_flex_filter_result {
9363         cmdline_fixed_string_t filter;
9364         cmdline_fixed_string_t ops;
9365         portid_t port_id;
9366         cmdline_fixed_string_t len;
9367         uint8_t len_value;
9368         cmdline_fixed_string_t bytes;
9369         cmdline_fixed_string_t bytes_value;
9370         cmdline_fixed_string_t mask;
9371         cmdline_fixed_string_t mask_value;
9372         cmdline_fixed_string_t priority;
9373         uint8_t priority_value;
9374         cmdline_fixed_string_t queue;
9375         uint16_t queue_id;
9376 };
9377
9378 static int xdigit2val(unsigned char c)
9379 {
9380         int val;
9381         if (isdigit(c))
9382                 val = c - '0';
9383         else if (isupper(c))
9384                 val = c - 'A' + 10;
9385         else
9386                 val = c - 'a' + 10;
9387         return val;
9388 }
9389
9390 static void
9391 cmd_flex_filter_parsed(void *parsed_result,
9392                           __attribute__((unused)) struct cmdline *cl,
9393                           __attribute__((unused)) void *data)
9394 {
9395         int ret = 0;
9396         struct rte_eth_flex_filter filter;
9397         struct cmd_flex_filter_result *res = parsed_result;
9398         char *bytes_ptr, *mask_ptr;
9399         uint16_t len, i, j = 0;
9400         char c;
9401         int val;
9402         uint8_t byte = 0;
9403
9404         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9405                 printf("the len exceed the max length 128\n");
9406                 return;
9407         }
9408         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9409         filter.len = res->len_value;
9410         filter.priority = res->priority_value;
9411         filter.queue = res->queue_id;
9412         bytes_ptr = res->bytes_value;
9413         mask_ptr = res->mask_value;
9414
9415          /* translate bytes string to array. */
9416         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9417                 (bytes_ptr[1] == 'X')))
9418                 bytes_ptr += 2;
9419         len = strnlen(bytes_ptr, res->len_value * 2);
9420         if (len == 0 || (len % 8 != 0)) {
9421                 printf("please check len and bytes input\n");
9422                 return;
9423         }
9424         for (i = 0; i < len; i++) {
9425                 c = bytes_ptr[i];
9426                 if (isxdigit(c) == 0) {
9427                         /* invalid characters. */
9428                         printf("invalid input\n");
9429                         return;
9430                 }
9431                 val = xdigit2val(c);
9432                 if (i % 2) {
9433                         byte |= val;
9434                         filter.bytes[j] = byte;
9435                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9436                         j++;
9437                         byte = 0;
9438                 } else
9439                         byte |= val << 4;
9440         }
9441         printf("\n");
9442          /* translate mask string to uint8_t array. */
9443         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9444                 (mask_ptr[1] == 'X')))
9445                 mask_ptr += 2;
9446         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9447         if (len == 0) {
9448                 printf("invalid input\n");
9449                 return;
9450         }
9451         j = 0;
9452         byte = 0;
9453         for (i = 0; i < len; i++) {
9454                 c = mask_ptr[i];
9455                 if (isxdigit(c) == 0) {
9456                         /* invalid characters. */
9457                         printf("invalid input\n");
9458                         return;
9459                 }
9460                 val = xdigit2val(c);
9461                 if (i % 2) {
9462                         byte |= val;
9463                         filter.mask[j] = byte;
9464                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9465                         j++;
9466                         byte = 0;
9467                 } else
9468                         byte |= val << 4;
9469         }
9470         printf("\n");
9471
9472         if (!strcmp(res->ops, "add"))
9473                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9474                                 RTE_ETH_FILTER_FLEXIBLE,
9475                                 RTE_ETH_FILTER_ADD,
9476                                 &filter);
9477         else
9478                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9479                                 RTE_ETH_FILTER_FLEXIBLE,
9480                                 RTE_ETH_FILTER_DELETE,
9481                                 &filter);
9482
9483         if (ret < 0)
9484                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9485 }
9486
9487 cmdline_parse_token_string_t cmd_flex_filter_filter =
9488         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9489                                 filter, "flex_filter");
9490 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9491         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9492                                 port_id, UINT16);
9493 cmdline_parse_token_string_t cmd_flex_filter_ops =
9494         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9495                                 ops, "add#del");
9496 cmdline_parse_token_string_t cmd_flex_filter_len =
9497         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9498                                 len, "len");
9499 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9500         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9501                                 len_value, UINT8);
9502 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9503         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9504                                 bytes, "bytes");
9505 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9506         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9507                                 bytes_value, NULL);
9508 cmdline_parse_token_string_t cmd_flex_filter_mask =
9509         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9510                                 mask, "mask");
9511 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9512         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9513                                 mask_value, NULL);
9514 cmdline_parse_token_string_t cmd_flex_filter_priority =
9515         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9516                                 priority, "priority");
9517 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9518         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9519                                 priority_value, UINT8);
9520 cmdline_parse_token_string_t cmd_flex_filter_queue =
9521         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9522                                 queue, "queue");
9523 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9524         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9525                                 queue_id, UINT16);
9526 cmdline_parse_inst_t cmd_flex_filter = {
9527         .f = cmd_flex_filter_parsed,
9528         .data = NULL,
9529         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9530                 "<value> mask <value> priority <value> queue <queue_id>: "
9531                 "Add/Del a flex filter",
9532         .tokens = {
9533                 (void *)&cmd_flex_filter_filter,
9534                 (void *)&cmd_flex_filter_port_id,
9535                 (void *)&cmd_flex_filter_ops,
9536                 (void *)&cmd_flex_filter_len,
9537                 (void *)&cmd_flex_filter_len_value,
9538                 (void *)&cmd_flex_filter_bytes,
9539                 (void *)&cmd_flex_filter_bytes_value,
9540                 (void *)&cmd_flex_filter_mask,
9541                 (void *)&cmd_flex_filter_mask_value,
9542                 (void *)&cmd_flex_filter_priority,
9543                 (void *)&cmd_flex_filter_priority_value,
9544                 (void *)&cmd_flex_filter_queue,
9545                 (void *)&cmd_flex_filter_queue_id,
9546                 NULL,
9547         },
9548 };
9549
9550 /* *** Filters Control *** */
9551
9552 /* *** deal with ethertype filter *** */
9553 struct cmd_ethertype_filter_result {
9554         cmdline_fixed_string_t filter;
9555         portid_t port_id;
9556         cmdline_fixed_string_t ops;
9557         cmdline_fixed_string_t mac;
9558         struct ether_addr mac_addr;
9559         cmdline_fixed_string_t ethertype;
9560         uint16_t ethertype_value;
9561         cmdline_fixed_string_t drop;
9562         cmdline_fixed_string_t queue;
9563         uint16_t  queue_id;
9564 };
9565
9566 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9567         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9568                                  filter, "ethertype_filter");
9569 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9570         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9571                               port_id, UINT16);
9572 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9573         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9574                                  ops, "add#del");
9575 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9576         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9577                                  mac, "mac_addr#mac_ignr");
9578 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9579         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9580                                      mac_addr);
9581 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9582         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9583                                  ethertype, "ethertype");
9584 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9585         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9586                               ethertype_value, UINT16);
9587 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9588         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9589                                  drop, "drop#fwd");
9590 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9591         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9592                                  queue, "queue");
9593 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9594         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9595                               queue_id, UINT16);
9596
9597 static void
9598 cmd_ethertype_filter_parsed(void *parsed_result,
9599                           __attribute__((unused)) struct cmdline *cl,
9600                           __attribute__((unused)) void *data)
9601 {
9602         struct cmd_ethertype_filter_result *res = parsed_result;
9603         struct rte_eth_ethertype_filter filter;
9604         int ret = 0;
9605
9606         ret = rte_eth_dev_filter_supported(res->port_id,
9607                         RTE_ETH_FILTER_ETHERTYPE);
9608         if (ret < 0) {
9609                 printf("ethertype filter is not supported on port %u.\n",
9610                         res->port_id);
9611                 return;
9612         }
9613
9614         memset(&filter, 0, sizeof(filter));
9615         if (!strcmp(res->mac, "mac_addr")) {
9616                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9617                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9618                         sizeof(struct ether_addr));
9619         }
9620         if (!strcmp(res->drop, "drop"))
9621                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9622         filter.ether_type = res->ethertype_value;
9623         filter.queue = res->queue_id;
9624
9625         if (!strcmp(res->ops, "add"))
9626                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9627                                 RTE_ETH_FILTER_ETHERTYPE,
9628                                 RTE_ETH_FILTER_ADD,
9629                                 &filter);
9630         else
9631                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9632                                 RTE_ETH_FILTER_ETHERTYPE,
9633                                 RTE_ETH_FILTER_DELETE,
9634                                 &filter);
9635         if (ret < 0)
9636                 printf("ethertype filter programming error: (%s)\n",
9637                         strerror(-ret));
9638 }
9639
9640 cmdline_parse_inst_t cmd_ethertype_filter = {
9641         .f = cmd_ethertype_filter_parsed,
9642         .data = NULL,
9643         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9644                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9645                 "Add or delete an ethertype filter entry",
9646         .tokens = {
9647                 (void *)&cmd_ethertype_filter_filter,
9648                 (void *)&cmd_ethertype_filter_port_id,
9649                 (void *)&cmd_ethertype_filter_ops,
9650                 (void *)&cmd_ethertype_filter_mac,
9651                 (void *)&cmd_ethertype_filter_mac_addr,
9652                 (void *)&cmd_ethertype_filter_ethertype,
9653                 (void *)&cmd_ethertype_filter_ethertype_value,
9654                 (void *)&cmd_ethertype_filter_drop,
9655                 (void *)&cmd_ethertype_filter_queue,
9656                 (void *)&cmd_ethertype_filter_queue_id,
9657                 NULL,
9658         },
9659 };
9660
9661 /* *** deal with flow director filter *** */
9662 struct cmd_flow_director_result {
9663         cmdline_fixed_string_t flow_director_filter;
9664         portid_t port_id;
9665         cmdline_fixed_string_t mode;
9666         cmdline_fixed_string_t mode_value;
9667         cmdline_fixed_string_t ops;
9668         cmdline_fixed_string_t flow;
9669         cmdline_fixed_string_t flow_type;
9670         cmdline_fixed_string_t ether;
9671         uint16_t ether_type;
9672         cmdline_fixed_string_t src;
9673         cmdline_ipaddr_t ip_src;
9674         uint16_t port_src;
9675         cmdline_fixed_string_t dst;
9676         cmdline_ipaddr_t ip_dst;
9677         uint16_t port_dst;
9678         cmdline_fixed_string_t verify_tag;
9679         uint32_t verify_tag_value;
9680         cmdline_ipaddr_t tos;
9681         uint8_t tos_value;
9682         cmdline_ipaddr_t proto;
9683         uint8_t proto_value;
9684         cmdline_ipaddr_t ttl;
9685         uint8_t ttl_value;
9686         cmdline_fixed_string_t vlan;
9687         uint16_t vlan_value;
9688         cmdline_fixed_string_t flexbytes;
9689         cmdline_fixed_string_t flexbytes_value;
9690         cmdline_fixed_string_t pf_vf;
9691         cmdline_fixed_string_t drop;
9692         cmdline_fixed_string_t queue;
9693         uint16_t  queue_id;
9694         cmdline_fixed_string_t fd_id;
9695         uint32_t  fd_id_value;
9696         cmdline_fixed_string_t mac;
9697         struct ether_addr mac_addr;
9698         cmdline_fixed_string_t tunnel;
9699         cmdline_fixed_string_t tunnel_type;
9700         cmdline_fixed_string_t tunnel_id;
9701         uint32_t tunnel_id_value;
9702 };
9703
9704 static inline int
9705 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9706 {
9707         char s[256];
9708         const char *p, *p0 = q_arg;
9709         char *end;
9710         unsigned long int_fld;
9711         char *str_fld[max_num];
9712         int i;
9713         unsigned size;
9714         int ret = -1;
9715
9716         p = strchr(p0, '(');
9717         if (p == NULL)
9718                 return -1;
9719         ++p;
9720         p0 = strchr(p, ')');
9721         if (p0 == NULL)
9722                 return -1;
9723
9724         size = p0 - p;
9725         if (size >= sizeof(s))
9726                 return -1;
9727
9728         snprintf(s, sizeof(s), "%.*s", size, p);
9729         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9730         if (ret < 0 || ret > max_num)
9731                 return -1;
9732         for (i = 0; i < ret; i++) {
9733                 errno = 0;
9734                 int_fld = strtoul(str_fld[i], &end, 0);
9735                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9736                         return -1;
9737                 flexbytes[i] = (uint8_t)int_fld;
9738         }
9739         return ret;
9740 }
9741
9742 static uint16_t
9743 str2flowtype(char *string)
9744 {
9745         uint8_t i = 0;
9746         static const struct {
9747                 char str[32];
9748                 uint16_t type;
9749         } flowtype_str[] = {
9750                 {"raw", RTE_ETH_FLOW_RAW},
9751                 {"ipv4", RTE_ETH_FLOW_IPV4},
9752                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9753                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9754                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9755                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9756                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9757                 {"ipv6", RTE_ETH_FLOW_IPV6},
9758                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9759                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9760                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9761                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9762                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9763                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9764         };
9765
9766         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9767                 if (!strcmp(flowtype_str[i].str, string))
9768                         return flowtype_str[i].type;
9769         }
9770
9771         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9772                 return (uint16_t)atoi(string);
9773
9774         return RTE_ETH_FLOW_UNKNOWN;
9775 }
9776
9777 static enum rte_eth_fdir_tunnel_type
9778 str2fdir_tunneltype(char *string)
9779 {
9780         uint8_t i = 0;
9781
9782         static const struct {
9783                 char str[32];
9784                 enum rte_eth_fdir_tunnel_type type;
9785         } tunneltype_str[] = {
9786                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9787                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9788         };
9789
9790         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9791                 if (!strcmp(tunneltype_str[i].str, string))
9792                         return tunneltype_str[i].type;
9793         }
9794         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9795 }
9796
9797 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9798 do { \
9799         if ((ip_addr).family == AF_INET) \
9800                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9801         else { \
9802                 printf("invalid parameter.\n"); \
9803                 return; \
9804         } \
9805 } while (0)
9806
9807 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9808 do { \
9809         if ((ip_addr).family == AF_INET6) \
9810                 rte_memcpy(&(ip), \
9811                                  &((ip_addr).addr.ipv6), \
9812                                  sizeof(struct in6_addr)); \
9813         else { \
9814                 printf("invalid parameter.\n"); \
9815                 return; \
9816         } \
9817 } while (0)
9818
9819 static void
9820 cmd_flow_director_filter_parsed(void *parsed_result,
9821                           __attribute__((unused)) struct cmdline *cl,
9822                           __attribute__((unused)) void *data)
9823 {
9824         struct cmd_flow_director_result *res = parsed_result;
9825         struct rte_eth_fdir_filter entry;
9826         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9827         char *end;
9828         unsigned long vf_id;
9829         int ret = 0;
9830
9831         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9832         if (ret < 0) {
9833                 printf("flow director is not supported on port %u.\n",
9834                         res->port_id);
9835                 return;
9836         }
9837         memset(flexbytes, 0, sizeof(flexbytes));
9838         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9839
9840         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9841                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9842                         printf("Please set mode to MAC-VLAN.\n");
9843                         return;
9844                 }
9845         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9846                 if (strcmp(res->mode_value, "Tunnel")) {
9847                         printf("Please set mode to Tunnel.\n");
9848                         return;
9849                 }
9850         } else {
9851                 if (strcmp(res->mode_value, "IP")) {
9852                         printf("Please set mode to IP.\n");
9853                         return;
9854                 }
9855                 entry.input.flow_type = str2flowtype(res->flow_type);
9856         }
9857
9858         ret = parse_flexbytes(res->flexbytes_value,
9859                                         flexbytes,
9860                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9861         if (ret < 0) {
9862                 printf("error: Cannot parse flexbytes input.\n");
9863                 return;
9864         }
9865
9866         switch (entry.input.flow_type) {
9867         case RTE_ETH_FLOW_FRAG_IPV4:
9868         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9869                 entry.input.flow.ip4_flow.proto = res->proto_value;
9870                 /* fall-through */
9871         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9872         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9873                 IPV4_ADDR_TO_UINT(res->ip_dst,
9874                         entry.input.flow.ip4_flow.dst_ip);
9875                 IPV4_ADDR_TO_UINT(res->ip_src,
9876                         entry.input.flow.ip4_flow.src_ip);
9877                 entry.input.flow.ip4_flow.tos = res->tos_value;
9878                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9879                 /* need convert to big endian. */
9880                 entry.input.flow.udp4_flow.dst_port =
9881                                 rte_cpu_to_be_16(res->port_dst);
9882                 entry.input.flow.udp4_flow.src_port =
9883                                 rte_cpu_to_be_16(res->port_src);
9884                 break;
9885         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9886                 IPV4_ADDR_TO_UINT(res->ip_dst,
9887                         entry.input.flow.sctp4_flow.ip.dst_ip);
9888                 IPV4_ADDR_TO_UINT(res->ip_src,
9889                         entry.input.flow.sctp4_flow.ip.src_ip);
9890                 entry.input.flow.ip4_flow.tos = res->tos_value;
9891                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9892                 /* need convert to big endian. */
9893                 entry.input.flow.sctp4_flow.dst_port =
9894                                 rte_cpu_to_be_16(res->port_dst);
9895                 entry.input.flow.sctp4_flow.src_port =
9896                                 rte_cpu_to_be_16(res->port_src);
9897                 entry.input.flow.sctp4_flow.verify_tag =
9898                                 rte_cpu_to_be_32(res->verify_tag_value);
9899                 break;
9900         case RTE_ETH_FLOW_FRAG_IPV6:
9901         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9902                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9903                 /* fall-through */
9904         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9905         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9906                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9907                         entry.input.flow.ipv6_flow.dst_ip);
9908                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9909                         entry.input.flow.ipv6_flow.src_ip);
9910                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9911                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9912                 /* need convert to big endian. */
9913                 entry.input.flow.udp6_flow.dst_port =
9914                                 rte_cpu_to_be_16(res->port_dst);
9915                 entry.input.flow.udp6_flow.src_port =
9916                                 rte_cpu_to_be_16(res->port_src);
9917                 break;
9918         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9919                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9920                         entry.input.flow.sctp6_flow.ip.dst_ip);
9921                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9922                         entry.input.flow.sctp6_flow.ip.src_ip);
9923                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9924                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9925                 /* need convert to big endian. */
9926                 entry.input.flow.sctp6_flow.dst_port =
9927                                 rte_cpu_to_be_16(res->port_dst);
9928                 entry.input.flow.sctp6_flow.src_port =
9929                                 rte_cpu_to_be_16(res->port_src);
9930                 entry.input.flow.sctp6_flow.verify_tag =
9931                                 rte_cpu_to_be_32(res->verify_tag_value);
9932                 break;
9933         case RTE_ETH_FLOW_L2_PAYLOAD:
9934                 entry.input.flow.l2_flow.ether_type =
9935                         rte_cpu_to_be_16(res->ether_type);
9936                 break;
9937         default:
9938                 break;
9939         }
9940
9941         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9942                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9943                                  &res->mac_addr,
9944                                  sizeof(struct ether_addr));
9945
9946         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9947                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9948                                  &res->mac_addr,
9949                                  sizeof(struct ether_addr));
9950                 entry.input.flow.tunnel_flow.tunnel_type =
9951                         str2fdir_tunneltype(res->tunnel_type);
9952                 entry.input.flow.tunnel_flow.tunnel_id =
9953                         rte_cpu_to_be_32(res->tunnel_id_value);
9954         }
9955
9956         rte_memcpy(entry.input.flow_ext.flexbytes,
9957                    flexbytes,
9958                    RTE_ETH_FDIR_MAX_FLEXLEN);
9959
9960         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9961
9962         entry.action.flex_off = 0;  /*use 0 by default */
9963         if (!strcmp(res->drop, "drop"))
9964                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9965         else
9966                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9967
9968         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9969             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9970                 if (!strcmp(res->pf_vf, "pf"))
9971                         entry.input.flow_ext.is_vf = 0;
9972                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9973                         struct rte_eth_dev_info dev_info;
9974
9975                         memset(&dev_info, 0, sizeof(dev_info));
9976                         rte_eth_dev_info_get(res->port_id, &dev_info);
9977                         errno = 0;
9978                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9979                         if (errno != 0 || *end != '\0' ||
9980                             vf_id >= dev_info.max_vfs) {
9981                                 printf("invalid parameter %s.\n", res->pf_vf);
9982                                 return;
9983                         }
9984                         entry.input.flow_ext.is_vf = 1;
9985                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9986                 } else {
9987                         printf("invalid parameter %s.\n", res->pf_vf);
9988                         return;
9989                 }
9990         }
9991
9992         /* set to report FD ID by default */
9993         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9994         entry.action.rx_queue = res->queue_id;
9995         entry.soft_id = res->fd_id_value;
9996         if (!strcmp(res->ops, "add"))
9997                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9998                                              RTE_ETH_FILTER_ADD, &entry);
9999         else if (!strcmp(res->ops, "del"))
10000                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10001                                              RTE_ETH_FILTER_DELETE, &entry);
10002         else
10003                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10004                                              RTE_ETH_FILTER_UPDATE, &entry);
10005         if (ret < 0)
10006                 printf("flow director programming error: (%s)\n",
10007                         strerror(-ret));
10008 }
10009
10010 cmdline_parse_token_string_t cmd_flow_director_filter =
10011         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10012                                  flow_director_filter, "flow_director_filter");
10013 cmdline_parse_token_num_t cmd_flow_director_port_id =
10014         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10015                               port_id, UINT16);
10016 cmdline_parse_token_string_t cmd_flow_director_ops =
10017         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10018                                  ops, "add#del#update");
10019 cmdline_parse_token_string_t cmd_flow_director_flow =
10020         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10021                                  flow, "flow");
10022 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10023         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10024                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10025                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10026 cmdline_parse_token_string_t cmd_flow_director_ether =
10027         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10028                                  ether, "ether");
10029 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10030         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10031                               ether_type, UINT16);
10032 cmdline_parse_token_string_t cmd_flow_director_src =
10033         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10034                                  src, "src");
10035 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10036         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10037                                  ip_src);
10038 cmdline_parse_token_num_t cmd_flow_director_port_src =
10039         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10040                               port_src, UINT16);
10041 cmdline_parse_token_string_t cmd_flow_director_dst =
10042         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10043                                  dst, "dst");
10044 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10045         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10046                                  ip_dst);
10047 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10048         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10049                               port_dst, UINT16);
10050 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10051         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10052                                   verify_tag, "verify_tag");
10053 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10054         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10055                               verify_tag_value, UINT32);
10056 cmdline_parse_token_string_t cmd_flow_director_tos =
10057         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10058                                  tos, "tos");
10059 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10060         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10061                               tos_value, UINT8);
10062 cmdline_parse_token_string_t cmd_flow_director_proto =
10063         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10064                                  proto, "proto");
10065 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10066         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10067                               proto_value, UINT8);
10068 cmdline_parse_token_string_t cmd_flow_director_ttl =
10069         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10070                                  ttl, "ttl");
10071 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10072         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10073                               ttl_value, UINT8);
10074 cmdline_parse_token_string_t cmd_flow_director_vlan =
10075         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10076                                  vlan, "vlan");
10077 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10078         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10079                               vlan_value, UINT16);
10080 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10081         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10082                                  flexbytes, "flexbytes");
10083 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10084         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10085                               flexbytes_value, NULL);
10086 cmdline_parse_token_string_t cmd_flow_director_drop =
10087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10088                                  drop, "drop#fwd");
10089 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10090         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10091                               pf_vf, NULL);
10092 cmdline_parse_token_string_t cmd_flow_director_queue =
10093         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10094                                  queue, "queue");
10095 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10096         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10097                               queue_id, UINT16);
10098 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10099         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10100                                  fd_id, "fd_id");
10101 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10102         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10103                               fd_id_value, UINT32);
10104
10105 cmdline_parse_token_string_t cmd_flow_director_mode =
10106         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10107                                  mode, "mode");
10108 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10109         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10110                                  mode_value, "IP");
10111 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10112         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10113                                  mode_value, "MAC-VLAN");
10114 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10115         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10116                                  mode_value, "Tunnel");
10117 cmdline_parse_token_string_t cmd_flow_director_mac =
10118         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10119                                  mac, "mac");
10120 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10121         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10122                                     mac_addr);
10123 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10124         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10125                                  tunnel, "tunnel");
10126 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10127         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10128                                  tunnel_type, "NVGRE#VxLAN");
10129 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10130         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10131                                  tunnel_id, "tunnel-id");
10132 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10133         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10134                               tunnel_id_value, UINT32);
10135
10136 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10137         .f = cmd_flow_director_filter_parsed,
10138         .data = NULL,
10139         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10140                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10141                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10142                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10143                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10144                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
10145                 "fd_id <fd_id_value>: "
10146                 "Add or delete an ip flow director entry on NIC",
10147         .tokens = {
10148                 (void *)&cmd_flow_director_filter,
10149                 (void *)&cmd_flow_director_port_id,
10150                 (void *)&cmd_flow_director_mode,
10151                 (void *)&cmd_flow_director_mode_ip,
10152                 (void *)&cmd_flow_director_ops,
10153                 (void *)&cmd_flow_director_flow,
10154                 (void *)&cmd_flow_director_flow_type,
10155                 (void *)&cmd_flow_director_src,
10156                 (void *)&cmd_flow_director_ip_src,
10157                 (void *)&cmd_flow_director_dst,
10158                 (void *)&cmd_flow_director_ip_dst,
10159                 (void *)&cmd_flow_director_tos,
10160                 (void *)&cmd_flow_director_tos_value,
10161                 (void *)&cmd_flow_director_proto,
10162                 (void *)&cmd_flow_director_proto_value,
10163                 (void *)&cmd_flow_director_ttl,
10164                 (void *)&cmd_flow_director_ttl_value,
10165                 (void *)&cmd_flow_director_vlan,
10166                 (void *)&cmd_flow_director_vlan_value,
10167                 (void *)&cmd_flow_director_flexbytes,
10168                 (void *)&cmd_flow_director_flexbytes_value,
10169                 (void *)&cmd_flow_director_drop,
10170                 (void *)&cmd_flow_director_pf_vf,
10171                 (void *)&cmd_flow_director_queue,
10172                 (void *)&cmd_flow_director_queue_id,
10173                 (void *)&cmd_flow_director_fd_id,
10174                 (void *)&cmd_flow_director_fd_id_value,
10175                 NULL,
10176         },
10177 };
10178
10179 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10180         .f = cmd_flow_director_filter_parsed,
10181         .data = NULL,
10182         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10183                 "director entry on NIC",
10184         .tokens = {
10185                 (void *)&cmd_flow_director_filter,
10186                 (void *)&cmd_flow_director_port_id,
10187                 (void *)&cmd_flow_director_mode,
10188                 (void *)&cmd_flow_director_mode_ip,
10189                 (void *)&cmd_flow_director_ops,
10190                 (void *)&cmd_flow_director_flow,
10191                 (void *)&cmd_flow_director_flow_type,
10192                 (void *)&cmd_flow_director_src,
10193                 (void *)&cmd_flow_director_ip_src,
10194                 (void *)&cmd_flow_director_port_src,
10195                 (void *)&cmd_flow_director_dst,
10196                 (void *)&cmd_flow_director_ip_dst,
10197                 (void *)&cmd_flow_director_port_dst,
10198                 (void *)&cmd_flow_director_tos,
10199                 (void *)&cmd_flow_director_tos_value,
10200                 (void *)&cmd_flow_director_ttl,
10201                 (void *)&cmd_flow_director_ttl_value,
10202                 (void *)&cmd_flow_director_vlan,
10203                 (void *)&cmd_flow_director_vlan_value,
10204                 (void *)&cmd_flow_director_flexbytes,
10205                 (void *)&cmd_flow_director_flexbytes_value,
10206                 (void *)&cmd_flow_director_drop,
10207                 (void *)&cmd_flow_director_pf_vf,
10208                 (void *)&cmd_flow_director_queue,
10209                 (void *)&cmd_flow_director_queue_id,
10210                 (void *)&cmd_flow_director_fd_id,
10211                 (void *)&cmd_flow_director_fd_id_value,
10212                 NULL,
10213         },
10214 };
10215
10216 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10217         .f = cmd_flow_director_filter_parsed,
10218         .data = NULL,
10219         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10220                 "director entry on NIC",
10221         .tokens = {
10222                 (void *)&cmd_flow_director_filter,
10223                 (void *)&cmd_flow_director_port_id,
10224                 (void *)&cmd_flow_director_mode,
10225                 (void *)&cmd_flow_director_mode_ip,
10226                 (void *)&cmd_flow_director_ops,
10227                 (void *)&cmd_flow_director_flow,
10228                 (void *)&cmd_flow_director_flow_type,
10229                 (void *)&cmd_flow_director_src,
10230                 (void *)&cmd_flow_director_ip_src,
10231                 (void *)&cmd_flow_director_port_dst,
10232                 (void *)&cmd_flow_director_dst,
10233                 (void *)&cmd_flow_director_ip_dst,
10234                 (void *)&cmd_flow_director_port_dst,
10235                 (void *)&cmd_flow_director_verify_tag,
10236                 (void *)&cmd_flow_director_verify_tag_value,
10237                 (void *)&cmd_flow_director_tos,
10238                 (void *)&cmd_flow_director_tos_value,
10239                 (void *)&cmd_flow_director_ttl,
10240                 (void *)&cmd_flow_director_ttl_value,
10241                 (void *)&cmd_flow_director_vlan,
10242                 (void *)&cmd_flow_director_vlan_value,
10243                 (void *)&cmd_flow_director_flexbytes,
10244                 (void *)&cmd_flow_director_flexbytes_value,
10245                 (void *)&cmd_flow_director_drop,
10246                 (void *)&cmd_flow_director_pf_vf,
10247                 (void *)&cmd_flow_director_queue,
10248                 (void *)&cmd_flow_director_queue_id,
10249                 (void *)&cmd_flow_director_fd_id,
10250                 (void *)&cmd_flow_director_fd_id_value,
10251                 NULL,
10252         },
10253 };
10254
10255 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10256         .f = cmd_flow_director_filter_parsed,
10257         .data = NULL,
10258         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10259                 "director entry on NIC",
10260         .tokens = {
10261                 (void *)&cmd_flow_director_filter,
10262                 (void *)&cmd_flow_director_port_id,
10263                 (void *)&cmd_flow_director_mode,
10264                 (void *)&cmd_flow_director_mode_ip,
10265                 (void *)&cmd_flow_director_ops,
10266                 (void *)&cmd_flow_director_flow,
10267                 (void *)&cmd_flow_director_flow_type,
10268                 (void *)&cmd_flow_director_ether,
10269                 (void *)&cmd_flow_director_ether_type,
10270                 (void *)&cmd_flow_director_flexbytes,
10271                 (void *)&cmd_flow_director_flexbytes_value,
10272                 (void *)&cmd_flow_director_drop,
10273                 (void *)&cmd_flow_director_pf_vf,
10274                 (void *)&cmd_flow_director_queue,
10275                 (void *)&cmd_flow_director_queue_id,
10276                 (void *)&cmd_flow_director_fd_id,
10277                 (void *)&cmd_flow_director_fd_id_value,
10278                 NULL,
10279         },
10280 };
10281
10282 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10283         .f = cmd_flow_director_filter_parsed,
10284         .data = NULL,
10285         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10286                 "director entry on NIC",
10287         .tokens = {
10288                 (void *)&cmd_flow_director_filter,
10289                 (void *)&cmd_flow_director_port_id,
10290                 (void *)&cmd_flow_director_mode,
10291                 (void *)&cmd_flow_director_mode_mac_vlan,
10292                 (void *)&cmd_flow_director_ops,
10293                 (void *)&cmd_flow_director_mac,
10294                 (void *)&cmd_flow_director_mac_addr,
10295                 (void *)&cmd_flow_director_vlan,
10296                 (void *)&cmd_flow_director_vlan_value,
10297                 (void *)&cmd_flow_director_flexbytes,
10298                 (void *)&cmd_flow_director_flexbytes_value,
10299                 (void *)&cmd_flow_director_drop,
10300                 (void *)&cmd_flow_director_queue,
10301                 (void *)&cmd_flow_director_queue_id,
10302                 (void *)&cmd_flow_director_fd_id,
10303                 (void *)&cmd_flow_director_fd_id_value,
10304                 NULL,
10305         },
10306 };
10307
10308 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10309         .f = cmd_flow_director_filter_parsed,
10310         .data = NULL,
10311         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10312                 "director entry on NIC",
10313         .tokens = {
10314                 (void *)&cmd_flow_director_filter,
10315                 (void *)&cmd_flow_director_port_id,
10316                 (void *)&cmd_flow_director_mode,
10317                 (void *)&cmd_flow_director_mode_tunnel,
10318                 (void *)&cmd_flow_director_ops,
10319                 (void *)&cmd_flow_director_mac,
10320                 (void *)&cmd_flow_director_mac_addr,
10321                 (void *)&cmd_flow_director_vlan,
10322                 (void *)&cmd_flow_director_vlan_value,
10323                 (void *)&cmd_flow_director_tunnel,
10324                 (void *)&cmd_flow_director_tunnel_type,
10325                 (void *)&cmd_flow_director_tunnel_id,
10326                 (void *)&cmd_flow_director_tunnel_id_value,
10327                 (void *)&cmd_flow_director_flexbytes,
10328                 (void *)&cmd_flow_director_flexbytes_value,
10329                 (void *)&cmd_flow_director_drop,
10330                 (void *)&cmd_flow_director_queue,
10331                 (void *)&cmd_flow_director_queue_id,
10332                 (void *)&cmd_flow_director_fd_id,
10333                 (void *)&cmd_flow_director_fd_id_value,
10334                 NULL,
10335         },
10336 };
10337
10338 struct cmd_flush_flow_director_result {
10339         cmdline_fixed_string_t flush_flow_director;
10340         portid_t port_id;
10341 };
10342
10343 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10344         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10345                                  flush_flow_director, "flush_flow_director");
10346 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10347         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10348                               port_id, UINT16);
10349
10350 static void
10351 cmd_flush_flow_director_parsed(void *parsed_result,
10352                           __attribute__((unused)) struct cmdline *cl,
10353                           __attribute__((unused)) void *data)
10354 {
10355         struct cmd_flow_director_result *res = parsed_result;
10356         int ret = 0;
10357
10358         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10359         if (ret < 0) {
10360                 printf("flow director is not supported on port %u.\n",
10361                         res->port_id);
10362                 return;
10363         }
10364
10365         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10366                         RTE_ETH_FILTER_FLUSH, NULL);
10367         if (ret < 0)
10368                 printf("flow director table flushing error: (%s)\n",
10369                         strerror(-ret));
10370 }
10371
10372 cmdline_parse_inst_t cmd_flush_flow_director = {
10373         .f = cmd_flush_flow_director_parsed,
10374         .data = NULL,
10375         .help_str = "flush_flow_director <port_id>: "
10376                 "Flush all flow director entries of a device on NIC",
10377         .tokens = {
10378                 (void *)&cmd_flush_flow_director_flush,
10379                 (void *)&cmd_flush_flow_director_port_id,
10380                 NULL,
10381         },
10382 };
10383
10384 /* *** deal with flow director mask *** */
10385 struct cmd_flow_director_mask_result {
10386         cmdline_fixed_string_t flow_director_mask;
10387         portid_t port_id;
10388         cmdline_fixed_string_t mode;
10389         cmdline_fixed_string_t mode_value;
10390         cmdline_fixed_string_t vlan;
10391         uint16_t vlan_mask;
10392         cmdline_fixed_string_t src_mask;
10393         cmdline_ipaddr_t ipv4_src;
10394         cmdline_ipaddr_t ipv6_src;
10395         uint16_t port_src;
10396         cmdline_fixed_string_t dst_mask;
10397         cmdline_ipaddr_t ipv4_dst;
10398         cmdline_ipaddr_t ipv6_dst;
10399         uint16_t port_dst;
10400         cmdline_fixed_string_t mac;
10401         uint8_t mac_addr_byte_mask;
10402         cmdline_fixed_string_t tunnel_id;
10403         uint32_t tunnel_id_mask;
10404         cmdline_fixed_string_t tunnel_type;
10405         uint8_t tunnel_type_mask;
10406 };
10407
10408 static void
10409 cmd_flow_director_mask_parsed(void *parsed_result,
10410                           __attribute__((unused)) struct cmdline *cl,
10411                           __attribute__((unused)) void *data)
10412 {
10413         struct cmd_flow_director_mask_result *res = parsed_result;
10414         struct rte_eth_fdir_masks *mask;
10415         struct rte_port *port;
10416
10417         if (res->port_id > nb_ports) {
10418                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10419                 return;
10420         }
10421
10422         port = &ports[res->port_id];
10423         /** Check if the port is not started **/
10424         if (port->port_status != RTE_PORT_STOPPED) {
10425                 printf("Please stop port %d first\n", res->port_id);
10426                 return;
10427         }
10428
10429         mask = &port->dev_conf.fdir_conf.mask;
10430
10431         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10432                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10433                         printf("Please set mode to MAC-VLAN.\n");
10434                         return;
10435                 }
10436
10437                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10438         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10439                 if (strcmp(res->mode_value, "Tunnel")) {
10440                         printf("Please set mode to Tunnel.\n");
10441                         return;
10442                 }
10443
10444                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10445                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10446                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10447                 mask->tunnel_type_mask = res->tunnel_type_mask;
10448         } else {
10449                 if (strcmp(res->mode_value, "IP")) {
10450                         printf("Please set mode to IP.\n");
10451                         return;
10452                 }
10453
10454                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10455                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10456                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10457                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10458                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10459                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10460                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10461         }
10462
10463         cmd_reconfig_device_queue(res->port_id, 1, 1);
10464 }
10465
10466 cmdline_parse_token_string_t cmd_flow_director_mask =
10467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10468                                  flow_director_mask, "flow_director_mask");
10469 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10470         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10471                               port_id, UINT16);
10472 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10474                                  vlan, "vlan");
10475 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10476         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10477                               vlan_mask, UINT16);
10478 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10479         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10480                                  src_mask, "src_mask");
10481 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10482         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10483                                  ipv4_src);
10484 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10485         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10486                                  ipv6_src);
10487 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10488         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10489                               port_src, UINT16);
10490 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10492                                  dst_mask, "dst_mask");
10493 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10494         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10495                                  ipv4_dst);
10496 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10497         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10498                                  ipv6_dst);
10499 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10500         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10501                               port_dst, UINT16);
10502
10503 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10504         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10505                                  mode, "mode");
10506 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10507         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10508                                  mode_value, "IP");
10509 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10510         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10511                                  mode_value, "MAC-VLAN");
10512 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10513         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10514                                  mode_value, "Tunnel");
10515 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10516         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10517                                  mac, "mac");
10518 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10519         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10520                               mac_addr_byte_mask, UINT8);
10521 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10522         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10523                                  tunnel_type, "tunnel-type");
10524 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10525         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10526                               tunnel_type_mask, UINT8);
10527 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10528         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10529                                  tunnel_id, "tunnel-id");
10530 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10531         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10532                               tunnel_id_mask, UINT32);
10533
10534 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10535         .f = cmd_flow_director_mask_parsed,
10536         .data = NULL,
10537         .help_str = "flow_director_mask ... : "
10538                 "Set IP mode flow director's mask on NIC",
10539         .tokens = {
10540                 (void *)&cmd_flow_director_mask,
10541                 (void *)&cmd_flow_director_mask_port_id,
10542                 (void *)&cmd_flow_director_mask_mode,
10543                 (void *)&cmd_flow_director_mask_mode_ip,
10544                 (void *)&cmd_flow_director_mask_vlan,
10545                 (void *)&cmd_flow_director_mask_vlan_value,
10546                 (void *)&cmd_flow_director_mask_src,
10547                 (void *)&cmd_flow_director_mask_ipv4_src,
10548                 (void *)&cmd_flow_director_mask_ipv6_src,
10549                 (void *)&cmd_flow_director_mask_port_src,
10550                 (void *)&cmd_flow_director_mask_dst,
10551                 (void *)&cmd_flow_director_mask_ipv4_dst,
10552                 (void *)&cmd_flow_director_mask_ipv6_dst,
10553                 (void *)&cmd_flow_director_mask_port_dst,
10554                 NULL,
10555         },
10556 };
10557
10558 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10559         .f = cmd_flow_director_mask_parsed,
10560         .data = NULL,
10561         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10562                 "flow director's mask on NIC",
10563         .tokens = {
10564                 (void *)&cmd_flow_director_mask,
10565                 (void *)&cmd_flow_director_mask_port_id,
10566                 (void *)&cmd_flow_director_mask_mode,
10567                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10568                 (void *)&cmd_flow_director_mask_vlan,
10569                 (void *)&cmd_flow_director_mask_vlan_value,
10570                 NULL,
10571         },
10572 };
10573
10574 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10575         .f = cmd_flow_director_mask_parsed,
10576         .data = NULL,
10577         .help_str = "flow_director_mask ... : Set tunnel mode "
10578                 "flow director's mask on NIC",
10579         .tokens = {
10580                 (void *)&cmd_flow_director_mask,
10581                 (void *)&cmd_flow_director_mask_port_id,
10582                 (void *)&cmd_flow_director_mask_mode,
10583                 (void *)&cmd_flow_director_mask_mode_tunnel,
10584                 (void *)&cmd_flow_director_mask_vlan,
10585                 (void *)&cmd_flow_director_mask_vlan_value,
10586                 (void *)&cmd_flow_director_mask_mac,
10587                 (void *)&cmd_flow_director_mask_mac_value,
10588                 (void *)&cmd_flow_director_mask_tunnel_type,
10589                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10590                 (void *)&cmd_flow_director_mask_tunnel_id,
10591                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10592                 NULL,
10593         },
10594 };
10595
10596 /* *** deal with flow director mask on flexible payload *** */
10597 struct cmd_flow_director_flex_mask_result {
10598         cmdline_fixed_string_t flow_director_flexmask;
10599         portid_t port_id;
10600         cmdline_fixed_string_t flow;
10601         cmdline_fixed_string_t flow_type;
10602         cmdline_fixed_string_t mask;
10603 };
10604
10605 static void
10606 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10607                           __attribute__((unused)) struct cmdline *cl,
10608                           __attribute__((unused)) void *data)
10609 {
10610         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10611         struct rte_eth_fdir_info fdir_info;
10612         struct rte_eth_fdir_flex_mask flex_mask;
10613         struct rte_port *port;
10614         uint32_t flow_type_mask;
10615         uint16_t i;
10616         int ret;
10617
10618         if (res->port_id > nb_ports) {
10619                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10620                 return;
10621         }
10622
10623         port = &ports[res->port_id];
10624         /** Check if the port is not started **/
10625         if (port->port_status != RTE_PORT_STOPPED) {
10626                 printf("Please stop port %d first\n", res->port_id);
10627                 return;
10628         }
10629
10630         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10631         ret = parse_flexbytes(res->mask,
10632                         flex_mask.mask,
10633                         RTE_ETH_FDIR_MAX_FLEXLEN);
10634         if (ret < 0) {
10635                 printf("error: Cannot parse mask input.\n");
10636                 return;
10637         }
10638
10639         memset(&fdir_info, 0, sizeof(fdir_info));
10640         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10641                                 RTE_ETH_FILTER_INFO, &fdir_info);
10642         if (ret < 0) {
10643                 printf("Cannot get FDir filter info\n");
10644                 return;
10645         }
10646
10647         if (!strcmp(res->flow_type, "none")) {
10648                 /* means don't specify the flow type */
10649                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10650                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10651                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10652                                0, sizeof(struct rte_eth_fdir_flex_mask));
10653                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10654                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10655                                  &flex_mask,
10656                                  sizeof(struct rte_eth_fdir_flex_mask));
10657                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10658                 return;
10659         }
10660         flow_type_mask = fdir_info.flow_types_mask[0];
10661         if (!strcmp(res->flow_type, "all")) {
10662                 if (!flow_type_mask) {
10663                         printf("No flow type supported\n");
10664                         return;
10665                 }
10666                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10667                         if (flow_type_mask & (1 << i)) {
10668                                 flex_mask.flow_type = i;
10669                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10670                         }
10671                 }
10672                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10673                 return;
10674         }
10675         flex_mask.flow_type = str2flowtype(res->flow_type);
10676         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10677                 printf("Flow type %s not supported on port %d\n",
10678                                 res->flow_type, res->port_id);
10679                 return;
10680         }
10681         fdir_set_flex_mask(res->port_id, &flex_mask);
10682         cmd_reconfig_device_queue(res->port_id, 1, 1);
10683 }
10684
10685 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10686         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10687                                  flow_director_flexmask,
10688                                  "flow_director_flex_mask");
10689 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10690         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10691                               port_id, UINT16);
10692 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10693         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10694                                  flow, "flow");
10695 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10696         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10697                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10698                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10699 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10701                                  mask, NULL);
10702
10703 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10704         .f = cmd_flow_director_flex_mask_parsed,
10705         .data = NULL,
10706         .help_str = "flow_director_flex_mask ... : "
10707                 "Set flow director's flex mask on NIC",
10708         .tokens = {
10709                 (void *)&cmd_flow_director_flexmask,
10710                 (void *)&cmd_flow_director_flexmask_port_id,
10711                 (void *)&cmd_flow_director_flexmask_flow,
10712                 (void *)&cmd_flow_director_flexmask_flow_type,
10713                 (void *)&cmd_flow_director_flexmask_mask,
10714                 NULL,
10715         },
10716 };
10717
10718 /* *** deal with flow director flexible payload configuration *** */
10719 struct cmd_flow_director_flexpayload_result {
10720         cmdline_fixed_string_t flow_director_flexpayload;
10721         portid_t port_id;
10722         cmdline_fixed_string_t payload_layer;
10723         cmdline_fixed_string_t payload_cfg;
10724 };
10725
10726 static inline int
10727 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10728 {
10729         char s[256];
10730         const char *p, *p0 = q_arg;
10731         char *end;
10732         unsigned long int_fld;
10733         char *str_fld[max_num];
10734         int i;
10735         unsigned size;
10736         int ret = -1;
10737
10738         p = strchr(p0, '(');
10739         if (p == NULL)
10740                 return -1;
10741         ++p;
10742         p0 = strchr(p, ')');
10743         if (p0 == NULL)
10744                 return -1;
10745
10746         size = p0 - p;
10747         if (size >= sizeof(s))
10748                 return -1;
10749
10750         snprintf(s, sizeof(s), "%.*s", size, p);
10751         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10752         if (ret < 0 || ret > max_num)
10753                 return -1;
10754         for (i = 0; i < ret; i++) {
10755                 errno = 0;
10756                 int_fld = strtoul(str_fld[i], &end, 0);
10757                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10758                         return -1;
10759                 offsets[i] = (uint16_t)int_fld;
10760         }
10761         return ret;
10762 }
10763
10764 static void
10765 cmd_flow_director_flxpld_parsed(void *parsed_result,
10766                           __attribute__((unused)) struct cmdline *cl,
10767                           __attribute__((unused)) void *data)
10768 {
10769         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10770         struct rte_eth_flex_payload_cfg flex_cfg;
10771         struct rte_port *port;
10772         int ret = 0;
10773
10774         if (res->port_id > nb_ports) {
10775                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10776                 return;
10777         }
10778
10779         port = &ports[res->port_id];
10780         /** Check if the port is not started **/
10781         if (port->port_status != RTE_PORT_STOPPED) {
10782                 printf("Please stop port %d first\n", res->port_id);
10783                 return;
10784         }
10785
10786         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10787
10788         if (!strcmp(res->payload_layer, "raw"))
10789                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10790         else if (!strcmp(res->payload_layer, "l2"))
10791                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10792         else if (!strcmp(res->payload_layer, "l3"))
10793                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10794         else if (!strcmp(res->payload_layer, "l4"))
10795                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10796
10797         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10798                             RTE_ETH_FDIR_MAX_FLEXLEN);
10799         if (ret < 0) {
10800                 printf("error: Cannot parse flex payload input.\n");
10801                 return;
10802         }
10803
10804         fdir_set_flex_payload(res->port_id, &flex_cfg);
10805         cmd_reconfig_device_queue(res->port_id, 1, 1);
10806 }
10807
10808 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10809         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10810                                  flow_director_flexpayload,
10811                                  "flow_director_flex_payload");
10812 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10813         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10814                               port_id, UINT16);
10815 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10817                                  payload_layer, "raw#l2#l3#l4");
10818 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10819         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10820                                  payload_cfg, NULL);
10821
10822 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10823         .f = cmd_flow_director_flxpld_parsed,
10824         .data = NULL,
10825         .help_str = "flow_director_flexpayload ... : "
10826                 "Set flow director's flex payload on NIC",
10827         .tokens = {
10828                 (void *)&cmd_flow_director_flexpayload,
10829                 (void *)&cmd_flow_director_flexpayload_port_id,
10830                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10831                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10832                 NULL,
10833         },
10834 };
10835
10836 /* Generic flow interface command. */
10837 extern cmdline_parse_inst_t cmd_flow;
10838
10839 /* *** Classification Filters Control *** */
10840 /* *** Get symmetric hash enable per port *** */
10841 struct cmd_get_sym_hash_ena_per_port_result {
10842         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10843         portid_t port_id;
10844 };
10845
10846 static void
10847 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10848                                  __rte_unused struct cmdline *cl,
10849                                  __rte_unused void *data)
10850 {
10851         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10852         struct rte_eth_hash_filter_info info;
10853         int ret;
10854
10855         if (rte_eth_dev_filter_supported(res->port_id,
10856                                 RTE_ETH_FILTER_HASH) < 0) {
10857                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10858                                                         res->port_id);
10859                 return;
10860         }
10861
10862         memset(&info, 0, sizeof(info));
10863         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10864         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10865                                                 RTE_ETH_FILTER_GET, &info);
10866
10867         if (ret < 0) {
10868                 printf("Cannot get symmetric hash enable per port "
10869                                         "on port %u\n", res->port_id);
10870                 return;
10871         }
10872
10873         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10874                                 "enabled" : "disabled", res->port_id);
10875 }
10876
10877 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10878         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10879                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10880 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10881         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10882                 port_id, UINT16);
10883
10884 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10885         .f = cmd_get_sym_hash_per_port_parsed,
10886         .data = NULL,
10887         .help_str = "get_sym_hash_ena_per_port <port_id>",
10888         .tokens = {
10889                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10890                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10891                 NULL,
10892         },
10893 };
10894
10895 /* *** Set symmetric hash enable per port *** */
10896 struct cmd_set_sym_hash_ena_per_port_result {
10897         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10898         cmdline_fixed_string_t enable;
10899         portid_t port_id;
10900 };
10901
10902 static void
10903 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10904                                  __rte_unused struct cmdline *cl,
10905                                  __rte_unused void *data)
10906 {
10907         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10908         struct rte_eth_hash_filter_info info;
10909         int ret;
10910
10911         if (rte_eth_dev_filter_supported(res->port_id,
10912                                 RTE_ETH_FILTER_HASH) < 0) {
10913                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10914                                                         res->port_id);
10915                 return;
10916         }
10917
10918         memset(&info, 0, sizeof(info));
10919         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10920         if (!strcmp(res->enable, "enable"))
10921                 info.info.enable = 1;
10922         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10923                                         RTE_ETH_FILTER_SET, &info);
10924         if (ret < 0) {
10925                 printf("Cannot set symmetric hash enable per port on "
10926                                         "port %u\n", res->port_id);
10927                 return;
10928         }
10929         printf("Symmetric hash has been set to %s on port %u\n",
10930                                         res->enable, res->port_id);
10931 }
10932
10933 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10934         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10935                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10936 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10937         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10938                 port_id, UINT16);
10939 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10940         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10941                 enable, "enable#disable");
10942
10943 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10944         .f = cmd_set_sym_hash_per_port_parsed,
10945         .data = NULL,
10946         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10947         .tokens = {
10948                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10949                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10950                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10951                 NULL,
10952         },
10953 };
10954
10955 /* Get global config of hash function */
10956 struct cmd_get_hash_global_config_result {
10957         cmdline_fixed_string_t get_hash_global_config;
10958         portid_t port_id;
10959 };
10960
10961 static char *
10962 flowtype_to_str(uint16_t ftype)
10963 {
10964         uint16_t i;
10965         static struct {
10966                 char str[16];
10967                 uint16_t ftype;
10968         } ftype_table[] = {
10969                 {"ipv4", RTE_ETH_FLOW_IPV4},
10970                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10971                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10972                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10973                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10974                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10975                 {"ipv6", RTE_ETH_FLOW_IPV6},
10976                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10977                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10978                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10979                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10980                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10981                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10982                 {"port", RTE_ETH_FLOW_PORT},
10983                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10984                 {"geneve", RTE_ETH_FLOW_GENEVE},
10985                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10986         };
10987
10988         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10989                 if (ftype_table[i].ftype == ftype)
10990                         return ftype_table[i].str;
10991         }
10992
10993         return NULL;
10994 }
10995
10996 static void
10997 cmd_get_hash_global_config_parsed(void *parsed_result,
10998                                   __rte_unused struct cmdline *cl,
10999                                   __rte_unused void *data)
11000 {
11001         struct cmd_get_hash_global_config_result *res = parsed_result;
11002         struct rte_eth_hash_filter_info info;
11003         uint32_t idx, offset;
11004         uint16_t i;
11005         char *str;
11006         int ret;
11007
11008         if (rte_eth_dev_filter_supported(res->port_id,
11009                         RTE_ETH_FILTER_HASH) < 0) {
11010                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11011                                                         res->port_id);
11012                 return;
11013         }
11014
11015         memset(&info, 0, sizeof(info));
11016         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11017         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11018                                         RTE_ETH_FILTER_GET, &info);
11019         if (ret < 0) {
11020                 printf("Cannot get hash global configurations by port %d\n",
11021                                                         res->port_id);
11022                 return;
11023         }
11024
11025         switch (info.info.global_conf.hash_func) {
11026         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11027                 printf("Hash function is Toeplitz\n");
11028                 break;
11029         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11030                 printf("Hash function is Simple XOR\n");
11031                 break;
11032         default:
11033                 printf("Unknown hash function\n");
11034                 break;
11035         }
11036
11037         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11038                 idx = i / UINT32_BIT;
11039                 offset = i % UINT32_BIT;
11040                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11041                                                 (1UL << offset)))
11042                         continue;
11043                 str = flowtype_to_str(i);
11044                 if (!str)
11045                         continue;
11046                 printf("Symmetric hash is %s globally for flow type %s "
11047                                                         "by port %d\n",
11048                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11049                         (1UL << offset)) ? "enabled" : "disabled"), str,
11050                                                         res->port_id);
11051         }
11052 }
11053
11054 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11055         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11056                 get_hash_global_config, "get_hash_global_config");
11057 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11058         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11059                 port_id, UINT16);
11060
11061 cmdline_parse_inst_t cmd_get_hash_global_config = {
11062         .f = cmd_get_hash_global_config_parsed,
11063         .data = NULL,
11064         .help_str = "get_hash_global_config <port_id>",
11065         .tokens = {
11066                 (void *)&cmd_get_hash_global_config_all,
11067                 (void *)&cmd_get_hash_global_config_port_id,
11068                 NULL,
11069         },
11070 };
11071
11072 /* Set global config of hash function */
11073 struct cmd_set_hash_global_config_result {
11074         cmdline_fixed_string_t set_hash_global_config;
11075         portid_t port_id;
11076         cmdline_fixed_string_t hash_func;
11077         cmdline_fixed_string_t flow_type;
11078         cmdline_fixed_string_t enable;
11079 };
11080
11081 static void
11082 cmd_set_hash_global_config_parsed(void *parsed_result,
11083                                   __rte_unused struct cmdline *cl,
11084                                   __rte_unused void *data)
11085 {
11086         struct cmd_set_hash_global_config_result *res = parsed_result;
11087         struct rte_eth_hash_filter_info info;
11088         uint32_t ftype, idx, offset;
11089         int ret;
11090
11091         if (rte_eth_dev_filter_supported(res->port_id,
11092                                 RTE_ETH_FILTER_HASH) < 0) {
11093                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11094                                                         res->port_id);
11095                 return;
11096         }
11097         memset(&info, 0, sizeof(info));
11098         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11099         if (!strcmp(res->hash_func, "toeplitz"))
11100                 info.info.global_conf.hash_func =
11101                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11102         else if (!strcmp(res->hash_func, "simple_xor"))
11103                 info.info.global_conf.hash_func =
11104                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11105         else if (!strcmp(res->hash_func, "default"))
11106                 info.info.global_conf.hash_func =
11107                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11108
11109         ftype = str2flowtype(res->flow_type);
11110         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11111         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11112         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11113         if (!strcmp(res->enable, "enable"))
11114                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11115                                                 (1UL << offset);
11116         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11117                                         RTE_ETH_FILTER_SET, &info);
11118         if (ret < 0)
11119                 printf("Cannot set global hash configurations by port %d\n",
11120                                                         res->port_id);
11121         else
11122                 printf("Global hash configurations have been set "
11123                         "succcessfully by port %d\n", res->port_id);
11124 }
11125
11126 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11127         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11128                 set_hash_global_config, "set_hash_global_config");
11129 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11130         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11131                 port_id, UINT16);
11132 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11133         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11134                 hash_func, "toeplitz#simple_xor#default");
11135 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11136         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11137                 flow_type,
11138                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11139                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11140 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11141         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11142                 enable, "enable#disable");
11143
11144 cmdline_parse_inst_t cmd_set_hash_global_config = {
11145         .f = cmd_set_hash_global_config_parsed,
11146         .data = NULL,
11147         .help_str = "set_hash_global_config <port_id> "
11148                 "toeplitz|simple_xor|default "
11149                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11150                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11151                 "l2_payload enable|disable",
11152         .tokens = {
11153                 (void *)&cmd_set_hash_global_config_all,
11154                 (void *)&cmd_set_hash_global_config_port_id,
11155                 (void *)&cmd_set_hash_global_config_hash_func,
11156                 (void *)&cmd_set_hash_global_config_flow_type,
11157                 (void *)&cmd_set_hash_global_config_enable,
11158                 NULL,
11159         },
11160 };
11161
11162 /* Set hash input set */
11163 struct cmd_set_hash_input_set_result {
11164         cmdline_fixed_string_t set_hash_input_set;
11165         portid_t port_id;
11166         cmdline_fixed_string_t flow_type;
11167         cmdline_fixed_string_t inset_field;
11168         cmdline_fixed_string_t select;
11169 };
11170
11171 static enum rte_eth_input_set_field
11172 str2inset(char *string)
11173 {
11174         uint16_t i;
11175
11176         static const struct {
11177                 char str[32];
11178                 enum rte_eth_input_set_field inset;
11179         } inset_table[] = {
11180                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11181                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11182                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11183                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11184                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11185                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11186                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11187                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11188                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11189                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11190                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11191                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11192                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11193                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11194                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11195                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11196                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11197                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11198                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11199                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11200                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11201                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11202                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11203                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11204                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11205                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11206                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11207                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11208                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11209                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11210                 {"none", RTE_ETH_INPUT_SET_NONE},
11211         };
11212
11213         for (i = 0; i < RTE_DIM(inset_table); i++) {
11214                 if (!strcmp(string, inset_table[i].str))
11215                         return inset_table[i].inset;
11216         }
11217
11218         return RTE_ETH_INPUT_SET_UNKNOWN;
11219 }
11220
11221 static void
11222 cmd_set_hash_input_set_parsed(void *parsed_result,
11223                               __rte_unused struct cmdline *cl,
11224                               __rte_unused void *data)
11225 {
11226         struct cmd_set_hash_input_set_result *res = parsed_result;
11227         struct rte_eth_hash_filter_info info;
11228
11229         memset(&info, 0, sizeof(info));
11230         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11231         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11232         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11233         info.info.input_set_conf.inset_size = 1;
11234         if (!strcmp(res->select, "select"))
11235                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11236         else if (!strcmp(res->select, "add"))
11237                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11238         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11239                                 RTE_ETH_FILTER_SET, &info);
11240 }
11241
11242 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11243         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11244                 set_hash_input_set, "set_hash_input_set");
11245 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11246         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11247                 port_id, UINT16);
11248 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11249         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11250                 flow_type, NULL);
11251 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11252         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11253                 inset_field,
11254                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11255                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11256                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11257                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11258                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11259                 "fld-8th#none");
11260 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11261         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11262                 select, "select#add");
11263
11264 cmdline_parse_inst_t cmd_set_hash_input_set = {
11265         .f = cmd_set_hash_input_set_parsed,
11266         .data = NULL,
11267         .help_str = "set_hash_input_set <port_id> "
11268         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11269         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11270         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11271         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11272         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11273         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11274         "fld-7th|fld-8th|none select|add",
11275         .tokens = {
11276                 (void *)&cmd_set_hash_input_set_cmd,
11277                 (void *)&cmd_set_hash_input_set_port_id,
11278                 (void *)&cmd_set_hash_input_set_flow_type,
11279                 (void *)&cmd_set_hash_input_set_field,
11280                 (void *)&cmd_set_hash_input_set_select,
11281                 NULL,
11282         },
11283 };
11284
11285 /* Set flow director input set */
11286 struct cmd_set_fdir_input_set_result {
11287         cmdline_fixed_string_t set_fdir_input_set;
11288         portid_t port_id;
11289         cmdline_fixed_string_t flow_type;
11290         cmdline_fixed_string_t inset_field;
11291         cmdline_fixed_string_t select;
11292 };
11293
11294 static void
11295 cmd_set_fdir_input_set_parsed(void *parsed_result,
11296         __rte_unused struct cmdline *cl,
11297         __rte_unused void *data)
11298 {
11299         struct cmd_set_fdir_input_set_result *res = parsed_result;
11300         struct rte_eth_fdir_filter_info info;
11301
11302         memset(&info, 0, sizeof(info));
11303         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11304         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11305         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11306         info.info.input_set_conf.inset_size = 1;
11307         if (!strcmp(res->select, "select"))
11308                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11309         else if (!strcmp(res->select, "add"))
11310                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11311         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11312                 RTE_ETH_FILTER_SET, &info);
11313 }
11314
11315 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11316         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11317         set_fdir_input_set, "set_fdir_input_set");
11318 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11319         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11320         port_id, UINT16);
11321 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11322         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11323         flow_type,
11324         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11325         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11326 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11327         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11328         inset_field,
11329         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11330         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11331         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11332         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11333         "sctp-veri-tag#none");
11334 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11335         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11336         select, "select#add");
11337
11338 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11339         .f = cmd_set_fdir_input_set_parsed,
11340         .data = NULL,
11341         .help_str = "set_fdir_input_set <port_id> "
11342         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11343         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11344         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11345         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11346         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11347         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11348         "sctp-veri-tag|none select|add",
11349         .tokens = {
11350                 (void *)&cmd_set_fdir_input_set_cmd,
11351                 (void *)&cmd_set_fdir_input_set_port_id,
11352                 (void *)&cmd_set_fdir_input_set_flow_type,
11353                 (void *)&cmd_set_fdir_input_set_field,
11354                 (void *)&cmd_set_fdir_input_set_select,
11355                 NULL,
11356         },
11357 };
11358
11359 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11360 struct cmd_mcast_addr_result {
11361         cmdline_fixed_string_t mcast_addr_cmd;
11362         cmdline_fixed_string_t what;
11363         uint16_t port_num;
11364         struct ether_addr mc_addr;
11365 };
11366
11367 static void cmd_mcast_addr_parsed(void *parsed_result,
11368                 __attribute__((unused)) struct cmdline *cl,
11369                 __attribute__((unused)) void *data)
11370 {
11371         struct cmd_mcast_addr_result *res = parsed_result;
11372
11373         if (!is_multicast_ether_addr(&res->mc_addr)) {
11374                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11375                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11376                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11377                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11378                 return;
11379         }
11380         if (strcmp(res->what, "add") == 0)
11381                 mcast_addr_add(res->port_num, &res->mc_addr);
11382         else
11383                 mcast_addr_remove(res->port_num, &res->mc_addr);
11384 }
11385
11386 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11387         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11388                                  mcast_addr_cmd, "mcast_addr");
11389 cmdline_parse_token_string_t cmd_mcast_addr_what =
11390         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11391                                  "add#remove");
11392 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11393         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11394 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11395         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11396
11397 cmdline_parse_inst_t cmd_mcast_addr = {
11398         .f = cmd_mcast_addr_parsed,
11399         .data = (void *)0,
11400         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11401                 "Add/Remove multicast MAC address on port_id",
11402         .tokens = {
11403                 (void *)&cmd_mcast_addr_cmd,
11404                 (void *)&cmd_mcast_addr_what,
11405                 (void *)&cmd_mcast_addr_portnum,
11406                 (void *)&cmd_mcast_addr_addr,
11407                 NULL,
11408         },
11409 };
11410
11411 /* l2 tunnel config
11412  * only support E-tag now.
11413  */
11414
11415 /* Ether type config */
11416 struct cmd_config_l2_tunnel_eth_type_result {
11417         cmdline_fixed_string_t port;
11418         cmdline_fixed_string_t config;
11419         cmdline_fixed_string_t all;
11420         uint8_t id;
11421         cmdline_fixed_string_t l2_tunnel;
11422         cmdline_fixed_string_t l2_tunnel_type;
11423         cmdline_fixed_string_t eth_type;
11424         uint16_t eth_type_val;
11425 };
11426
11427 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11428         TOKEN_STRING_INITIALIZER
11429                 (struct cmd_config_l2_tunnel_eth_type_result,
11430                  port, "port");
11431 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11432         TOKEN_STRING_INITIALIZER
11433                 (struct cmd_config_l2_tunnel_eth_type_result,
11434                  config, "config");
11435 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11436         TOKEN_STRING_INITIALIZER
11437                 (struct cmd_config_l2_tunnel_eth_type_result,
11438                  all, "all");
11439 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11440         TOKEN_NUM_INITIALIZER
11441                 (struct cmd_config_l2_tunnel_eth_type_result,
11442                  id, UINT8);
11443 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11444         TOKEN_STRING_INITIALIZER
11445                 (struct cmd_config_l2_tunnel_eth_type_result,
11446                  l2_tunnel, "l2-tunnel");
11447 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11448         TOKEN_STRING_INITIALIZER
11449                 (struct cmd_config_l2_tunnel_eth_type_result,
11450                  l2_tunnel_type, "E-tag");
11451 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11452         TOKEN_STRING_INITIALIZER
11453                 (struct cmd_config_l2_tunnel_eth_type_result,
11454                  eth_type, "ether-type");
11455 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11456         TOKEN_NUM_INITIALIZER
11457                 (struct cmd_config_l2_tunnel_eth_type_result,
11458                  eth_type_val, UINT16);
11459
11460 static enum rte_eth_tunnel_type
11461 str2fdir_l2_tunnel_type(char *string)
11462 {
11463         uint32_t i = 0;
11464
11465         static const struct {
11466                 char str[32];
11467                 enum rte_eth_tunnel_type type;
11468         } l2_tunnel_type_str[] = {
11469                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11470         };
11471
11472         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11473                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11474                         return l2_tunnel_type_str[i].type;
11475         }
11476         return RTE_TUNNEL_TYPE_NONE;
11477 }
11478
11479 /* ether type config for all ports */
11480 static void
11481 cmd_config_l2_tunnel_eth_type_all_parsed
11482         (void *parsed_result,
11483          __attribute__((unused)) struct cmdline *cl,
11484          __attribute__((unused)) void *data)
11485 {
11486         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11487         struct rte_eth_l2_tunnel_conf entry;
11488         portid_t pid;
11489
11490         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11491         entry.ether_type = res->eth_type_val;
11492
11493         RTE_ETH_FOREACH_DEV(pid) {
11494                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11495         }
11496 }
11497
11498 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11499         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11500         .data = NULL,
11501         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11502         .tokens = {
11503                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11504                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11505                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11506                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11507                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11508                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11509                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11510                 NULL,
11511         },
11512 };
11513
11514 /* ether type config for a specific port */
11515 static void
11516 cmd_config_l2_tunnel_eth_type_specific_parsed(
11517         void *parsed_result,
11518         __attribute__((unused)) struct cmdline *cl,
11519         __attribute__((unused)) void *data)
11520 {
11521         struct cmd_config_l2_tunnel_eth_type_result *res =
11522                  parsed_result;
11523         struct rte_eth_l2_tunnel_conf entry;
11524
11525         if (port_id_is_invalid(res->id, ENABLED_WARN))
11526                 return;
11527
11528         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11529         entry.ether_type = res->eth_type_val;
11530
11531         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11532 }
11533
11534 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11535         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11536         .data = NULL,
11537         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11538         .tokens = {
11539                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11540                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11541                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11542                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11543                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11544                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11545                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11546                 NULL,
11547         },
11548 };
11549
11550 /* Enable/disable l2 tunnel */
11551 struct cmd_config_l2_tunnel_en_dis_result {
11552         cmdline_fixed_string_t port;
11553         cmdline_fixed_string_t config;
11554         cmdline_fixed_string_t all;
11555         uint8_t id;
11556         cmdline_fixed_string_t l2_tunnel;
11557         cmdline_fixed_string_t l2_tunnel_type;
11558         cmdline_fixed_string_t en_dis;
11559 };
11560
11561 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11562         TOKEN_STRING_INITIALIZER
11563                 (struct cmd_config_l2_tunnel_en_dis_result,
11564                  port, "port");
11565 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11566         TOKEN_STRING_INITIALIZER
11567                 (struct cmd_config_l2_tunnel_en_dis_result,
11568                  config, "config");
11569 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11570         TOKEN_STRING_INITIALIZER
11571                 (struct cmd_config_l2_tunnel_en_dis_result,
11572                  all, "all");
11573 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11574         TOKEN_NUM_INITIALIZER
11575                 (struct cmd_config_l2_tunnel_en_dis_result,
11576                  id, UINT8);
11577 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11578         TOKEN_STRING_INITIALIZER
11579                 (struct cmd_config_l2_tunnel_en_dis_result,
11580                  l2_tunnel, "l2-tunnel");
11581 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11582         TOKEN_STRING_INITIALIZER
11583                 (struct cmd_config_l2_tunnel_en_dis_result,
11584                  l2_tunnel_type, "E-tag");
11585 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11586         TOKEN_STRING_INITIALIZER
11587                 (struct cmd_config_l2_tunnel_en_dis_result,
11588                  en_dis, "enable#disable");
11589
11590 /* enable/disable l2 tunnel for all ports */
11591 static void
11592 cmd_config_l2_tunnel_en_dis_all_parsed(
11593         void *parsed_result,
11594         __attribute__((unused)) struct cmdline *cl,
11595         __attribute__((unused)) void *data)
11596 {
11597         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11598         struct rte_eth_l2_tunnel_conf entry;
11599         portid_t pid;
11600         uint8_t en;
11601
11602         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11603
11604         if (!strcmp("enable", res->en_dis))
11605                 en = 1;
11606         else
11607                 en = 0;
11608
11609         RTE_ETH_FOREACH_DEV(pid) {
11610                 rte_eth_dev_l2_tunnel_offload_set(pid,
11611                                                   &entry,
11612                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11613                                                   en);
11614         }
11615 }
11616
11617 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11618         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11619         .data = NULL,
11620         .help_str = "port config all l2-tunnel E-tag enable|disable",
11621         .tokens = {
11622                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11623                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11624                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11625                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11626                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11627                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11628                 NULL,
11629         },
11630 };
11631
11632 /* enable/disable l2 tunnel for a port */
11633 static void
11634 cmd_config_l2_tunnel_en_dis_specific_parsed(
11635         void *parsed_result,
11636         __attribute__((unused)) struct cmdline *cl,
11637         __attribute__((unused)) void *data)
11638 {
11639         struct cmd_config_l2_tunnel_en_dis_result *res =
11640                 parsed_result;
11641         struct rte_eth_l2_tunnel_conf entry;
11642
11643         if (port_id_is_invalid(res->id, ENABLED_WARN))
11644                 return;
11645
11646         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11647
11648         if (!strcmp("enable", res->en_dis))
11649                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11650                                                   &entry,
11651                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11652                                                   1);
11653         else
11654                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11655                                                   &entry,
11656                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11657                                                   0);
11658 }
11659
11660 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11661         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11662         .data = NULL,
11663         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11664         .tokens = {
11665                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11666                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11667                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11668                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11669                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11670                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11671                 NULL,
11672         },
11673 };
11674
11675 /* E-tag configuration */
11676
11677 /* Common result structure for all E-tag configuration */
11678 struct cmd_config_e_tag_result {
11679         cmdline_fixed_string_t e_tag;
11680         cmdline_fixed_string_t set;
11681         cmdline_fixed_string_t insertion;
11682         cmdline_fixed_string_t stripping;
11683         cmdline_fixed_string_t forwarding;
11684         cmdline_fixed_string_t filter;
11685         cmdline_fixed_string_t add;
11686         cmdline_fixed_string_t del;
11687         cmdline_fixed_string_t on;
11688         cmdline_fixed_string_t off;
11689         cmdline_fixed_string_t on_off;
11690         cmdline_fixed_string_t port_tag_id;
11691         uint32_t port_tag_id_val;
11692         cmdline_fixed_string_t e_tag_id;
11693         uint16_t e_tag_id_val;
11694         cmdline_fixed_string_t dst_pool;
11695         uint8_t dst_pool_val;
11696         cmdline_fixed_string_t port;
11697         portid_t port_id;
11698         cmdline_fixed_string_t vf;
11699         uint8_t vf_id;
11700 };
11701
11702 /* Common CLI fields for all E-tag configuration */
11703 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11704         TOKEN_STRING_INITIALIZER
11705                 (struct cmd_config_e_tag_result,
11706                  e_tag, "E-tag");
11707 cmdline_parse_token_string_t cmd_config_e_tag_set =
11708         TOKEN_STRING_INITIALIZER
11709                 (struct cmd_config_e_tag_result,
11710                  set, "set");
11711 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11712         TOKEN_STRING_INITIALIZER
11713                 (struct cmd_config_e_tag_result,
11714                  insertion, "insertion");
11715 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11716         TOKEN_STRING_INITIALIZER
11717                 (struct cmd_config_e_tag_result,
11718                  stripping, "stripping");
11719 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11720         TOKEN_STRING_INITIALIZER
11721                 (struct cmd_config_e_tag_result,
11722                  forwarding, "forwarding");
11723 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11724         TOKEN_STRING_INITIALIZER
11725                 (struct cmd_config_e_tag_result,
11726                  filter, "filter");
11727 cmdline_parse_token_string_t cmd_config_e_tag_add =
11728         TOKEN_STRING_INITIALIZER
11729                 (struct cmd_config_e_tag_result,
11730                  add, "add");
11731 cmdline_parse_token_string_t cmd_config_e_tag_del =
11732         TOKEN_STRING_INITIALIZER
11733                 (struct cmd_config_e_tag_result,
11734                  del, "del");
11735 cmdline_parse_token_string_t cmd_config_e_tag_on =
11736         TOKEN_STRING_INITIALIZER
11737                 (struct cmd_config_e_tag_result,
11738                  on, "on");
11739 cmdline_parse_token_string_t cmd_config_e_tag_off =
11740         TOKEN_STRING_INITIALIZER
11741                 (struct cmd_config_e_tag_result,
11742                  off, "off");
11743 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11744         TOKEN_STRING_INITIALIZER
11745                 (struct cmd_config_e_tag_result,
11746                  on_off, "on#off");
11747 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11748         TOKEN_STRING_INITIALIZER
11749                 (struct cmd_config_e_tag_result,
11750                  port_tag_id, "port-tag-id");
11751 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11752         TOKEN_NUM_INITIALIZER
11753                 (struct cmd_config_e_tag_result,
11754                  port_tag_id_val, UINT32);
11755 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11756         TOKEN_STRING_INITIALIZER
11757                 (struct cmd_config_e_tag_result,
11758                  e_tag_id, "e-tag-id");
11759 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11760         TOKEN_NUM_INITIALIZER
11761                 (struct cmd_config_e_tag_result,
11762                  e_tag_id_val, UINT16);
11763 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11764         TOKEN_STRING_INITIALIZER
11765                 (struct cmd_config_e_tag_result,
11766                  dst_pool, "dst-pool");
11767 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11768         TOKEN_NUM_INITIALIZER
11769                 (struct cmd_config_e_tag_result,
11770                  dst_pool_val, UINT8);
11771 cmdline_parse_token_string_t cmd_config_e_tag_port =
11772         TOKEN_STRING_INITIALIZER
11773                 (struct cmd_config_e_tag_result,
11774                  port, "port");
11775 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11776         TOKEN_NUM_INITIALIZER
11777                 (struct cmd_config_e_tag_result,
11778                  port_id, UINT16);
11779 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11780         TOKEN_STRING_INITIALIZER
11781                 (struct cmd_config_e_tag_result,
11782                  vf, "vf");
11783 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11784         TOKEN_NUM_INITIALIZER
11785                 (struct cmd_config_e_tag_result,
11786                  vf_id, UINT8);
11787
11788 /* E-tag insertion configuration */
11789 static void
11790 cmd_config_e_tag_insertion_en_parsed(
11791         void *parsed_result,
11792         __attribute__((unused)) struct cmdline *cl,
11793         __attribute__((unused)) void *data)
11794 {
11795         struct cmd_config_e_tag_result *res =
11796                 parsed_result;
11797         struct rte_eth_l2_tunnel_conf entry;
11798
11799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11800                 return;
11801
11802         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11803         entry.tunnel_id = res->port_tag_id_val;
11804         entry.vf_id = res->vf_id;
11805         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11806                                           &entry,
11807                                           ETH_L2_TUNNEL_INSERTION_MASK,
11808                                           1);
11809 }
11810
11811 static void
11812 cmd_config_e_tag_insertion_dis_parsed(
11813         void *parsed_result,
11814         __attribute__((unused)) struct cmdline *cl,
11815         __attribute__((unused)) void *data)
11816 {
11817         struct cmd_config_e_tag_result *res =
11818                 parsed_result;
11819         struct rte_eth_l2_tunnel_conf entry;
11820
11821         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11822                 return;
11823
11824         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11825         entry.vf_id = res->vf_id;
11826
11827         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11828                                           &entry,
11829                                           ETH_L2_TUNNEL_INSERTION_MASK,
11830                                           0);
11831 }
11832
11833 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11834         .f = cmd_config_e_tag_insertion_en_parsed,
11835         .data = NULL,
11836         .help_str = "E-tag ... : E-tag insertion enable",
11837         .tokens = {
11838                 (void *)&cmd_config_e_tag_e_tag,
11839                 (void *)&cmd_config_e_tag_set,
11840                 (void *)&cmd_config_e_tag_insertion,
11841                 (void *)&cmd_config_e_tag_on,
11842                 (void *)&cmd_config_e_tag_port_tag_id,
11843                 (void *)&cmd_config_e_tag_port_tag_id_val,
11844                 (void *)&cmd_config_e_tag_port,
11845                 (void *)&cmd_config_e_tag_port_id,
11846                 (void *)&cmd_config_e_tag_vf,
11847                 (void *)&cmd_config_e_tag_vf_id,
11848                 NULL,
11849         },
11850 };
11851
11852 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11853         .f = cmd_config_e_tag_insertion_dis_parsed,
11854         .data = NULL,
11855         .help_str = "E-tag ... : E-tag insertion disable",
11856         .tokens = {
11857                 (void *)&cmd_config_e_tag_e_tag,
11858                 (void *)&cmd_config_e_tag_set,
11859                 (void *)&cmd_config_e_tag_insertion,
11860                 (void *)&cmd_config_e_tag_off,
11861                 (void *)&cmd_config_e_tag_port,
11862                 (void *)&cmd_config_e_tag_port_id,
11863                 (void *)&cmd_config_e_tag_vf,
11864                 (void *)&cmd_config_e_tag_vf_id,
11865                 NULL,
11866         },
11867 };
11868
11869 /* E-tag stripping configuration */
11870 static void
11871 cmd_config_e_tag_stripping_parsed(
11872         void *parsed_result,
11873         __attribute__((unused)) struct cmdline *cl,
11874         __attribute__((unused)) void *data)
11875 {
11876         struct cmd_config_e_tag_result *res =
11877                 parsed_result;
11878         struct rte_eth_l2_tunnel_conf entry;
11879
11880         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11881                 return;
11882
11883         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11884
11885         if (!strcmp(res->on_off, "on"))
11886                 rte_eth_dev_l2_tunnel_offload_set
11887                         (res->port_id,
11888                          &entry,
11889                          ETH_L2_TUNNEL_STRIPPING_MASK,
11890                          1);
11891         else
11892                 rte_eth_dev_l2_tunnel_offload_set
11893                         (res->port_id,
11894                          &entry,
11895                          ETH_L2_TUNNEL_STRIPPING_MASK,
11896                          0);
11897 }
11898
11899 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11900         .f = cmd_config_e_tag_stripping_parsed,
11901         .data = NULL,
11902         .help_str = "E-tag ... : E-tag stripping enable/disable",
11903         .tokens = {
11904                 (void *)&cmd_config_e_tag_e_tag,
11905                 (void *)&cmd_config_e_tag_set,
11906                 (void *)&cmd_config_e_tag_stripping,
11907                 (void *)&cmd_config_e_tag_on_off,
11908                 (void *)&cmd_config_e_tag_port,
11909                 (void *)&cmd_config_e_tag_port_id,
11910                 NULL,
11911         },
11912 };
11913
11914 /* E-tag forwarding configuration */
11915 static void
11916 cmd_config_e_tag_forwarding_parsed(
11917         void *parsed_result,
11918         __attribute__((unused)) struct cmdline *cl,
11919         __attribute__((unused)) void *data)
11920 {
11921         struct cmd_config_e_tag_result *res = parsed_result;
11922         struct rte_eth_l2_tunnel_conf entry;
11923
11924         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11925                 return;
11926
11927         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11928
11929         if (!strcmp(res->on_off, "on"))
11930                 rte_eth_dev_l2_tunnel_offload_set
11931                         (res->port_id,
11932                          &entry,
11933                          ETH_L2_TUNNEL_FORWARDING_MASK,
11934                          1);
11935         else
11936                 rte_eth_dev_l2_tunnel_offload_set
11937                         (res->port_id,
11938                          &entry,
11939                          ETH_L2_TUNNEL_FORWARDING_MASK,
11940                          0);
11941 }
11942
11943 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11944         .f = cmd_config_e_tag_forwarding_parsed,
11945         .data = NULL,
11946         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11947         .tokens = {
11948                 (void *)&cmd_config_e_tag_e_tag,
11949                 (void *)&cmd_config_e_tag_set,
11950                 (void *)&cmd_config_e_tag_forwarding,
11951                 (void *)&cmd_config_e_tag_on_off,
11952                 (void *)&cmd_config_e_tag_port,
11953                 (void *)&cmd_config_e_tag_port_id,
11954                 NULL,
11955         },
11956 };
11957
11958 /* E-tag filter configuration */
11959 static void
11960 cmd_config_e_tag_filter_add_parsed(
11961         void *parsed_result,
11962         __attribute__((unused)) struct cmdline *cl,
11963         __attribute__((unused)) void *data)
11964 {
11965         struct cmd_config_e_tag_result *res = parsed_result;
11966         struct rte_eth_l2_tunnel_conf entry;
11967         int ret = 0;
11968
11969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11970                 return;
11971
11972         if (res->e_tag_id_val > 0x3fff) {
11973                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11974                 return;
11975         }
11976
11977         ret = rte_eth_dev_filter_supported(res->port_id,
11978                                            RTE_ETH_FILTER_L2_TUNNEL);
11979         if (ret < 0) {
11980                 printf("E-tag filter is not supported on port %u.\n",
11981                        res->port_id);
11982                 return;
11983         }
11984
11985         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11986         entry.tunnel_id = res->e_tag_id_val;
11987         entry.pool = res->dst_pool_val;
11988
11989         ret = rte_eth_dev_filter_ctrl(res->port_id,
11990                                       RTE_ETH_FILTER_L2_TUNNEL,
11991                                       RTE_ETH_FILTER_ADD,
11992                                       &entry);
11993         if (ret < 0)
11994                 printf("E-tag filter programming error: (%s)\n",
11995                        strerror(-ret));
11996 }
11997
11998 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11999         .f = cmd_config_e_tag_filter_add_parsed,
12000         .data = NULL,
12001         .help_str = "E-tag ... : E-tag filter add",
12002         .tokens = {
12003                 (void *)&cmd_config_e_tag_e_tag,
12004                 (void *)&cmd_config_e_tag_set,
12005                 (void *)&cmd_config_e_tag_filter,
12006                 (void *)&cmd_config_e_tag_add,
12007                 (void *)&cmd_config_e_tag_e_tag_id,
12008                 (void *)&cmd_config_e_tag_e_tag_id_val,
12009                 (void *)&cmd_config_e_tag_dst_pool,
12010                 (void *)&cmd_config_e_tag_dst_pool_val,
12011                 (void *)&cmd_config_e_tag_port,
12012                 (void *)&cmd_config_e_tag_port_id,
12013                 NULL,
12014         },
12015 };
12016
12017 static void
12018 cmd_config_e_tag_filter_del_parsed(
12019         void *parsed_result,
12020         __attribute__((unused)) struct cmdline *cl,
12021         __attribute__((unused)) void *data)
12022 {
12023         struct cmd_config_e_tag_result *res = parsed_result;
12024         struct rte_eth_l2_tunnel_conf entry;
12025         int ret = 0;
12026
12027         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12028                 return;
12029
12030         if (res->e_tag_id_val > 0x3fff) {
12031                 printf("e-tag-id must be less than 0x3fff.\n");
12032                 return;
12033         }
12034
12035         ret = rte_eth_dev_filter_supported(res->port_id,
12036                                            RTE_ETH_FILTER_L2_TUNNEL);
12037         if (ret < 0) {
12038                 printf("E-tag filter is not supported on port %u.\n",
12039                        res->port_id);
12040                 return;
12041         }
12042
12043         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12044         entry.tunnel_id = res->e_tag_id_val;
12045
12046         ret = rte_eth_dev_filter_ctrl(res->port_id,
12047                                       RTE_ETH_FILTER_L2_TUNNEL,
12048                                       RTE_ETH_FILTER_DELETE,
12049                                       &entry);
12050         if (ret < 0)
12051                 printf("E-tag filter programming error: (%s)\n",
12052                        strerror(-ret));
12053 }
12054
12055 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12056         .f = cmd_config_e_tag_filter_del_parsed,
12057         .data = NULL,
12058         .help_str = "E-tag ... : E-tag filter delete",
12059         .tokens = {
12060                 (void *)&cmd_config_e_tag_e_tag,
12061                 (void *)&cmd_config_e_tag_set,
12062                 (void *)&cmd_config_e_tag_filter,
12063                 (void *)&cmd_config_e_tag_del,
12064                 (void *)&cmd_config_e_tag_e_tag_id,
12065                 (void *)&cmd_config_e_tag_e_tag_id_val,
12066                 (void *)&cmd_config_e_tag_port,
12067                 (void *)&cmd_config_e_tag_port_id,
12068                 NULL,
12069         },
12070 };
12071
12072 /* vf vlan anti spoof configuration */
12073
12074 /* Common result structure for vf vlan anti spoof */
12075 struct cmd_vf_vlan_anti_spoof_result {
12076         cmdline_fixed_string_t set;
12077         cmdline_fixed_string_t vf;
12078         cmdline_fixed_string_t vlan;
12079         cmdline_fixed_string_t antispoof;
12080         portid_t port_id;
12081         uint32_t vf_id;
12082         cmdline_fixed_string_t on_off;
12083 };
12084
12085 /* Common CLI fields for vf vlan anti spoof enable disable */
12086 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12087         TOKEN_STRING_INITIALIZER
12088                 (struct cmd_vf_vlan_anti_spoof_result,
12089                  set, "set");
12090 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12091         TOKEN_STRING_INITIALIZER
12092                 (struct cmd_vf_vlan_anti_spoof_result,
12093                  vf, "vf");
12094 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12095         TOKEN_STRING_INITIALIZER
12096                 (struct cmd_vf_vlan_anti_spoof_result,
12097                  vlan, "vlan");
12098 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12099         TOKEN_STRING_INITIALIZER
12100                 (struct cmd_vf_vlan_anti_spoof_result,
12101                  antispoof, "antispoof");
12102 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12103         TOKEN_NUM_INITIALIZER
12104                 (struct cmd_vf_vlan_anti_spoof_result,
12105                  port_id, UINT16);
12106 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12107         TOKEN_NUM_INITIALIZER
12108                 (struct cmd_vf_vlan_anti_spoof_result,
12109                  vf_id, UINT32);
12110 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12111         TOKEN_STRING_INITIALIZER
12112                 (struct cmd_vf_vlan_anti_spoof_result,
12113                  on_off, "on#off");
12114
12115 static void
12116 cmd_set_vf_vlan_anti_spoof_parsed(
12117         void *parsed_result,
12118         __attribute__((unused)) struct cmdline *cl,
12119         __attribute__((unused)) void *data)
12120 {
12121         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12122         int ret = -ENOTSUP;
12123
12124         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12125
12126         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12127                 return;
12128
12129 #ifdef RTE_LIBRTE_IXGBE_PMD
12130         if (ret == -ENOTSUP)
12131                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12132                                 res->vf_id, is_on);
12133 #endif
12134 #ifdef RTE_LIBRTE_I40E_PMD
12135         if (ret == -ENOTSUP)
12136                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12137                                 res->vf_id, is_on);
12138 #endif
12139 #ifdef RTE_LIBRTE_BNXT_PMD
12140         if (ret == -ENOTSUP)
12141                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12142                                 res->vf_id, is_on);
12143 #endif
12144
12145         switch (ret) {
12146         case 0:
12147                 break;
12148         case -EINVAL:
12149                 printf("invalid vf_id %d\n", res->vf_id);
12150                 break;
12151         case -ENODEV:
12152                 printf("invalid port_id %d\n", res->port_id);
12153                 break;
12154         case -ENOTSUP:
12155                 printf("function not implemented\n");
12156                 break;
12157         default:
12158                 printf("programming error: (%s)\n", strerror(-ret));
12159         }
12160 }
12161
12162 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12163         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12164         .data = NULL,
12165         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12166         .tokens = {
12167                 (void *)&cmd_vf_vlan_anti_spoof_set,
12168                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12169                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12170                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12171                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12172                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12173                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12174                 NULL,
12175         },
12176 };
12177
12178 /* vf mac anti spoof configuration */
12179
12180 /* Common result structure for vf mac anti spoof */
12181 struct cmd_vf_mac_anti_spoof_result {
12182         cmdline_fixed_string_t set;
12183         cmdline_fixed_string_t vf;
12184         cmdline_fixed_string_t mac;
12185         cmdline_fixed_string_t antispoof;
12186         portid_t port_id;
12187         uint32_t vf_id;
12188         cmdline_fixed_string_t on_off;
12189 };
12190
12191 /* Common CLI fields for vf mac anti spoof enable disable */
12192 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12193         TOKEN_STRING_INITIALIZER
12194                 (struct cmd_vf_mac_anti_spoof_result,
12195                  set, "set");
12196 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12197         TOKEN_STRING_INITIALIZER
12198                 (struct cmd_vf_mac_anti_spoof_result,
12199                  vf, "vf");
12200 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12201         TOKEN_STRING_INITIALIZER
12202                 (struct cmd_vf_mac_anti_spoof_result,
12203                  mac, "mac");
12204 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12205         TOKEN_STRING_INITIALIZER
12206                 (struct cmd_vf_mac_anti_spoof_result,
12207                  antispoof, "antispoof");
12208 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12209         TOKEN_NUM_INITIALIZER
12210                 (struct cmd_vf_mac_anti_spoof_result,
12211                  port_id, UINT16);
12212 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12213         TOKEN_NUM_INITIALIZER
12214                 (struct cmd_vf_mac_anti_spoof_result,
12215                  vf_id, UINT32);
12216 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12217         TOKEN_STRING_INITIALIZER
12218                 (struct cmd_vf_mac_anti_spoof_result,
12219                  on_off, "on#off");
12220
12221 static void
12222 cmd_set_vf_mac_anti_spoof_parsed(
12223         void *parsed_result,
12224         __attribute__((unused)) struct cmdline *cl,
12225         __attribute__((unused)) void *data)
12226 {
12227         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12228         int ret = -ENOTSUP;
12229
12230         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12231
12232         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12233                 return;
12234
12235 #ifdef RTE_LIBRTE_IXGBE_PMD
12236         if (ret == -ENOTSUP)
12237                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12238                         res->vf_id, is_on);
12239 #endif
12240 #ifdef RTE_LIBRTE_I40E_PMD
12241         if (ret == -ENOTSUP)
12242                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12243                         res->vf_id, is_on);
12244 #endif
12245 #ifdef RTE_LIBRTE_BNXT_PMD
12246         if (ret == -ENOTSUP)
12247                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12248                         res->vf_id, is_on);
12249 #endif
12250
12251         switch (ret) {
12252         case 0:
12253                 break;
12254         case -EINVAL:
12255                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12256                 break;
12257         case -ENODEV:
12258                 printf("invalid port_id %d\n", res->port_id);
12259                 break;
12260         case -ENOTSUP:
12261                 printf("function not implemented\n");
12262                 break;
12263         default:
12264                 printf("programming error: (%s)\n", strerror(-ret));
12265         }
12266 }
12267
12268 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12269         .f = cmd_set_vf_mac_anti_spoof_parsed,
12270         .data = NULL,
12271         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12272         .tokens = {
12273                 (void *)&cmd_vf_mac_anti_spoof_set,
12274                 (void *)&cmd_vf_mac_anti_spoof_vf,
12275                 (void *)&cmd_vf_mac_anti_spoof_mac,
12276                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12277                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12278                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12279                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12280                 NULL,
12281         },
12282 };
12283
12284 /* vf vlan strip queue configuration */
12285
12286 /* Common result structure for vf mac anti spoof */
12287 struct cmd_vf_vlan_stripq_result {
12288         cmdline_fixed_string_t set;
12289         cmdline_fixed_string_t vf;
12290         cmdline_fixed_string_t vlan;
12291         cmdline_fixed_string_t stripq;
12292         portid_t port_id;
12293         uint16_t vf_id;
12294         cmdline_fixed_string_t on_off;
12295 };
12296
12297 /* Common CLI fields for vf vlan strip enable disable */
12298 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12299         TOKEN_STRING_INITIALIZER
12300                 (struct cmd_vf_vlan_stripq_result,
12301                  set, "set");
12302 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12303         TOKEN_STRING_INITIALIZER
12304                 (struct cmd_vf_vlan_stripq_result,
12305                  vf, "vf");
12306 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12307         TOKEN_STRING_INITIALIZER
12308                 (struct cmd_vf_vlan_stripq_result,
12309                  vlan, "vlan");
12310 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12311         TOKEN_STRING_INITIALIZER
12312                 (struct cmd_vf_vlan_stripq_result,
12313                  stripq, "stripq");
12314 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12315         TOKEN_NUM_INITIALIZER
12316                 (struct cmd_vf_vlan_stripq_result,
12317                  port_id, UINT16);
12318 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12319         TOKEN_NUM_INITIALIZER
12320                 (struct cmd_vf_vlan_stripq_result,
12321                  vf_id, UINT16);
12322 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12323         TOKEN_STRING_INITIALIZER
12324                 (struct cmd_vf_vlan_stripq_result,
12325                  on_off, "on#off");
12326
12327 static void
12328 cmd_set_vf_vlan_stripq_parsed(
12329         void *parsed_result,
12330         __attribute__((unused)) struct cmdline *cl,
12331         __attribute__((unused)) void *data)
12332 {
12333         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12334         int ret = -ENOTSUP;
12335
12336         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12337
12338         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12339                 return;
12340
12341 #ifdef RTE_LIBRTE_IXGBE_PMD
12342         if (ret == -ENOTSUP)
12343                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12344                         res->vf_id, is_on);
12345 #endif
12346 #ifdef RTE_LIBRTE_I40E_PMD
12347         if (ret == -ENOTSUP)
12348                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12349                         res->vf_id, is_on);
12350 #endif
12351 #ifdef RTE_LIBRTE_BNXT_PMD
12352         if (ret == -ENOTSUP)
12353                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12354                         res->vf_id, is_on);
12355 #endif
12356
12357         switch (ret) {
12358         case 0:
12359                 break;
12360         case -EINVAL:
12361                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12362                 break;
12363         case -ENODEV:
12364                 printf("invalid port_id %d\n", res->port_id);
12365                 break;
12366         case -ENOTSUP:
12367                 printf("function not implemented\n");
12368                 break;
12369         default:
12370                 printf("programming error: (%s)\n", strerror(-ret));
12371         }
12372 }
12373
12374 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12375         .f = cmd_set_vf_vlan_stripq_parsed,
12376         .data = NULL,
12377         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12378         .tokens = {
12379                 (void *)&cmd_vf_vlan_stripq_set,
12380                 (void *)&cmd_vf_vlan_stripq_vf,
12381                 (void *)&cmd_vf_vlan_stripq_vlan,
12382                 (void *)&cmd_vf_vlan_stripq_stripq,
12383                 (void *)&cmd_vf_vlan_stripq_port_id,
12384                 (void *)&cmd_vf_vlan_stripq_vf_id,
12385                 (void *)&cmd_vf_vlan_stripq_on_off,
12386                 NULL,
12387         },
12388 };
12389
12390 /* vf vlan insert configuration */
12391
12392 /* Common result structure for vf vlan insert */
12393 struct cmd_vf_vlan_insert_result {
12394         cmdline_fixed_string_t set;
12395         cmdline_fixed_string_t vf;
12396         cmdline_fixed_string_t vlan;
12397         cmdline_fixed_string_t insert;
12398         portid_t port_id;
12399         uint16_t vf_id;
12400         uint16_t vlan_id;
12401 };
12402
12403 /* Common CLI fields for vf vlan insert enable disable */
12404 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12405         TOKEN_STRING_INITIALIZER
12406                 (struct cmd_vf_vlan_insert_result,
12407                  set, "set");
12408 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12409         TOKEN_STRING_INITIALIZER
12410                 (struct cmd_vf_vlan_insert_result,
12411                  vf, "vf");
12412 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12413         TOKEN_STRING_INITIALIZER
12414                 (struct cmd_vf_vlan_insert_result,
12415                  vlan, "vlan");
12416 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12417         TOKEN_STRING_INITIALIZER
12418                 (struct cmd_vf_vlan_insert_result,
12419                  insert, "insert");
12420 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12421         TOKEN_NUM_INITIALIZER
12422                 (struct cmd_vf_vlan_insert_result,
12423                  port_id, UINT16);
12424 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12425         TOKEN_NUM_INITIALIZER
12426                 (struct cmd_vf_vlan_insert_result,
12427                  vf_id, UINT16);
12428 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12429         TOKEN_NUM_INITIALIZER
12430                 (struct cmd_vf_vlan_insert_result,
12431                  vlan_id, UINT16);
12432
12433 static void
12434 cmd_set_vf_vlan_insert_parsed(
12435         void *parsed_result,
12436         __attribute__((unused)) struct cmdline *cl,
12437         __attribute__((unused)) void *data)
12438 {
12439         struct cmd_vf_vlan_insert_result *res = parsed_result;
12440         int ret = -ENOTSUP;
12441
12442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12443                 return;
12444
12445 #ifdef RTE_LIBRTE_IXGBE_PMD
12446         if (ret == -ENOTSUP)
12447                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12448                         res->vlan_id);
12449 #endif
12450 #ifdef RTE_LIBRTE_I40E_PMD
12451         if (ret == -ENOTSUP)
12452                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12453                         res->vlan_id);
12454 #endif
12455 #ifdef RTE_LIBRTE_BNXT_PMD
12456         if (ret == -ENOTSUP)
12457                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12458                         res->vlan_id);
12459 #endif
12460
12461         switch (ret) {
12462         case 0:
12463                 break;
12464         case -EINVAL:
12465                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12466                 break;
12467         case -ENODEV:
12468                 printf("invalid port_id %d\n", res->port_id);
12469                 break;
12470         case -ENOTSUP:
12471                 printf("function not implemented\n");
12472                 break;
12473         default:
12474                 printf("programming error: (%s)\n", strerror(-ret));
12475         }
12476 }
12477
12478 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12479         .f = cmd_set_vf_vlan_insert_parsed,
12480         .data = NULL,
12481         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12482         .tokens = {
12483                 (void *)&cmd_vf_vlan_insert_set,
12484                 (void *)&cmd_vf_vlan_insert_vf,
12485                 (void *)&cmd_vf_vlan_insert_vlan,
12486                 (void *)&cmd_vf_vlan_insert_insert,
12487                 (void *)&cmd_vf_vlan_insert_port_id,
12488                 (void *)&cmd_vf_vlan_insert_vf_id,
12489                 (void *)&cmd_vf_vlan_insert_vlan_id,
12490                 NULL,
12491         },
12492 };
12493
12494 /* tx loopback configuration */
12495
12496 /* Common result structure for tx loopback */
12497 struct cmd_tx_loopback_result {
12498         cmdline_fixed_string_t set;
12499         cmdline_fixed_string_t tx;
12500         cmdline_fixed_string_t loopback;
12501         portid_t port_id;
12502         cmdline_fixed_string_t on_off;
12503 };
12504
12505 /* Common CLI fields for tx loopback enable disable */
12506 cmdline_parse_token_string_t cmd_tx_loopback_set =
12507         TOKEN_STRING_INITIALIZER
12508                 (struct cmd_tx_loopback_result,
12509                  set, "set");
12510 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12511         TOKEN_STRING_INITIALIZER
12512                 (struct cmd_tx_loopback_result,
12513                  tx, "tx");
12514 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12515         TOKEN_STRING_INITIALIZER
12516                 (struct cmd_tx_loopback_result,
12517                  loopback, "loopback");
12518 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12519         TOKEN_NUM_INITIALIZER
12520                 (struct cmd_tx_loopback_result,
12521                  port_id, UINT16);
12522 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12523         TOKEN_STRING_INITIALIZER
12524                 (struct cmd_tx_loopback_result,
12525                  on_off, "on#off");
12526
12527 static void
12528 cmd_set_tx_loopback_parsed(
12529         void *parsed_result,
12530         __attribute__((unused)) struct cmdline *cl,
12531         __attribute__((unused)) void *data)
12532 {
12533         struct cmd_tx_loopback_result *res = parsed_result;
12534         int ret = -ENOTSUP;
12535
12536         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12537
12538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12539                 return;
12540
12541 #ifdef RTE_LIBRTE_IXGBE_PMD
12542         if (ret == -ENOTSUP)
12543                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12544 #endif
12545 #ifdef RTE_LIBRTE_I40E_PMD
12546         if (ret == -ENOTSUP)
12547                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12548 #endif
12549 #ifdef RTE_LIBRTE_BNXT_PMD
12550         if (ret == -ENOTSUP)
12551                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12552 #endif
12553
12554         switch (ret) {
12555         case 0:
12556                 break;
12557         case -EINVAL:
12558                 printf("invalid is_on %d\n", is_on);
12559                 break;
12560         case -ENODEV:
12561                 printf("invalid port_id %d\n", res->port_id);
12562                 break;
12563         case -ENOTSUP:
12564                 printf("function not implemented\n");
12565                 break;
12566         default:
12567                 printf("programming error: (%s)\n", strerror(-ret));
12568         }
12569 }
12570
12571 cmdline_parse_inst_t cmd_set_tx_loopback = {
12572         .f = cmd_set_tx_loopback_parsed,
12573         .data = NULL,
12574         .help_str = "set tx loopback <port_id> on|off",
12575         .tokens = {
12576                 (void *)&cmd_tx_loopback_set,
12577                 (void *)&cmd_tx_loopback_tx,
12578                 (void *)&cmd_tx_loopback_loopback,
12579                 (void *)&cmd_tx_loopback_port_id,
12580                 (void *)&cmd_tx_loopback_on_off,
12581                 NULL,
12582         },
12583 };
12584
12585 /* all queues drop enable configuration */
12586
12587 /* Common result structure for all queues drop enable */
12588 struct cmd_all_queues_drop_en_result {
12589         cmdline_fixed_string_t set;
12590         cmdline_fixed_string_t all;
12591         cmdline_fixed_string_t queues;
12592         cmdline_fixed_string_t drop;
12593         portid_t port_id;
12594         cmdline_fixed_string_t on_off;
12595 };
12596
12597 /* Common CLI fields for tx loopback enable disable */
12598 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12599         TOKEN_STRING_INITIALIZER
12600                 (struct cmd_all_queues_drop_en_result,
12601                  set, "set");
12602 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12603         TOKEN_STRING_INITIALIZER
12604                 (struct cmd_all_queues_drop_en_result,
12605                  all, "all");
12606 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12607         TOKEN_STRING_INITIALIZER
12608                 (struct cmd_all_queues_drop_en_result,
12609                  queues, "queues");
12610 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12611         TOKEN_STRING_INITIALIZER
12612                 (struct cmd_all_queues_drop_en_result,
12613                  drop, "drop");
12614 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12615         TOKEN_NUM_INITIALIZER
12616                 (struct cmd_all_queues_drop_en_result,
12617                  port_id, UINT16);
12618 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12619         TOKEN_STRING_INITIALIZER
12620                 (struct cmd_all_queues_drop_en_result,
12621                  on_off, "on#off");
12622
12623 static void
12624 cmd_set_all_queues_drop_en_parsed(
12625         void *parsed_result,
12626         __attribute__((unused)) struct cmdline *cl,
12627         __attribute__((unused)) void *data)
12628 {
12629         struct cmd_all_queues_drop_en_result *res = parsed_result;
12630         int ret = -ENOTSUP;
12631         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12632
12633         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12634                 return;
12635
12636 #ifdef RTE_LIBRTE_IXGBE_PMD
12637         if (ret == -ENOTSUP)
12638                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12639 #endif
12640 #ifdef RTE_LIBRTE_BNXT_PMD
12641         if (ret == -ENOTSUP)
12642                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12643 #endif
12644         switch (ret) {
12645         case 0:
12646                 break;
12647         case -EINVAL:
12648                 printf("invalid is_on %d\n", is_on);
12649                 break;
12650         case -ENODEV:
12651                 printf("invalid port_id %d\n", res->port_id);
12652                 break;
12653         case -ENOTSUP:
12654                 printf("function not implemented\n");
12655                 break;
12656         default:
12657                 printf("programming error: (%s)\n", strerror(-ret));
12658         }
12659 }
12660
12661 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12662         .f = cmd_set_all_queues_drop_en_parsed,
12663         .data = NULL,
12664         .help_str = "set all queues drop <port_id> on|off",
12665         .tokens = {
12666                 (void *)&cmd_all_queues_drop_en_set,
12667                 (void *)&cmd_all_queues_drop_en_all,
12668                 (void *)&cmd_all_queues_drop_en_queues,
12669                 (void *)&cmd_all_queues_drop_en_drop,
12670                 (void *)&cmd_all_queues_drop_en_port_id,
12671                 (void *)&cmd_all_queues_drop_en_on_off,
12672                 NULL,
12673         },
12674 };
12675
12676 /* vf split drop enable configuration */
12677
12678 /* Common result structure for vf split drop enable */
12679 struct cmd_vf_split_drop_en_result {
12680         cmdline_fixed_string_t set;
12681         cmdline_fixed_string_t vf;
12682         cmdline_fixed_string_t split;
12683         cmdline_fixed_string_t drop;
12684         portid_t port_id;
12685         uint16_t vf_id;
12686         cmdline_fixed_string_t on_off;
12687 };
12688
12689 /* Common CLI fields for vf split drop enable disable */
12690 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12691         TOKEN_STRING_INITIALIZER
12692                 (struct cmd_vf_split_drop_en_result,
12693                  set, "set");
12694 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12695         TOKEN_STRING_INITIALIZER
12696                 (struct cmd_vf_split_drop_en_result,
12697                  vf, "vf");
12698 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12699         TOKEN_STRING_INITIALIZER
12700                 (struct cmd_vf_split_drop_en_result,
12701                  split, "split");
12702 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12703         TOKEN_STRING_INITIALIZER
12704                 (struct cmd_vf_split_drop_en_result,
12705                  drop, "drop");
12706 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12707         TOKEN_NUM_INITIALIZER
12708                 (struct cmd_vf_split_drop_en_result,
12709                  port_id, UINT16);
12710 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12711         TOKEN_NUM_INITIALIZER
12712                 (struct cmd_vf_split_drop_en_result,
12713                  vf_id, UINT16);
12714 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12715         TOKEN_STRING_INITIALIZER
12716                 (struct cmd_vf_split_drop_en_result,
12717                  on_off, "on#off");
12718
12719 static void
12720 cmd_set_vf_split_drop_en_parsed(
12721         void *parsed_result,
12722         __attribute__((unused)) struct cmdline *cl,
12723         __attribute__((unused)) void *data)
12724 {
12725         struct cmd_vf_split_drop_en_result *res = parsed_result;
12726         int ret = -ENOTSUP;
12727         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12728
12729         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12730                 return;
12731
12732 #ifdef RTE_LIBRTE_IXGBE_PMD
12733         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12734                         is_on);
12735 #endif
12736         switch (ret) {
12737         case 0:
12738                 break;
12739         case -EINVAL:
12740                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12741                 break;
12742         case -ENODEV:
12743                 printf("invalid port_id %d\n", res->port_id);
12744                 break;
12745         case -ENOTSUP:
12746                 printf("not supported on port %d\n", res->port_id);
12747                 break;
12748         default:
12749                 printf("programming error: (%s)\n", strerror(-ret));
12750         }
12751 }
12752
12753 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12754         .f = cmd_set_vf_split_drop_en_parsed,
12755         .data = NULL,
12756         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12757         .tokens = {
12758                 (void *)&cmd_vf_split_drop_en_set,
12759                 (void *)&cmd_vf_split_drop_en_vf,
12760                 (void *)&cmd_vf_split_drop_en_split,
12761                 (void *)&cmd_vf_split_drop_en_drop,
12762                 (void *)&cmd_vf_split_drop_en_port_id,
12763                 (void *)&cmd_vf_split_drop_en_vf_id,
12764                 (void *)&cmd_vf_split_drop_en_on_off,
12765                 NULL,
12766         },
12767 };
12768
12769 /* vf mac address configuration */
12770
12771 /* Common result structure for vf mac address */
12772 struct cmd_set_vf_mac_addr_result {
12773         cmdline_fixed_string_t set;
12774         cmdline_fixed_string_t vf;
12775         cmdline_fixed_string_t mac;
12776         cmdline_fixed_string_t addr;
12777         portid_t port_id;
12778         uint16_t vf_id;
12779         struct ether_addr mac_addr;
12780
12781 };
12782
12783 /* Common CLI fields for vf split drop enable disable */
12784 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12785         TOKEN_STRING_INITIALIZER
12786                 (struct cmd_set_vf_mac_addr_result,
12787                  set, "set");
12788 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_set_vf_mac_addr_result,
12791                  vf, "vf");
12792 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_set_vf_mac_addr_result,
12795                  mac, "mac");
12796 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12797         TOKEN_STRING_INITIALIZER
12798                 (struct cmd_set_vf_mac_addr_result,
12799                  addr, "addr");
12800 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12801         TOKEN_NUM_INITIALIZER
12802                 (struct cmd_set_vf_mac_addr_result,
12803                  port_id, UINT16);
12804 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12805         TOKEN_NUM_INITIALIZER
12806                 (struct cmd_set_vf_mac_addr_result,
12807                  vf_id, UINT16);
12808 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12809         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12810                  mac_addr);
12811
12812 static void
12813 cmd_set_vf_mac_addr_parsed(
12814         void *parsed_result,
12815         __attribute__((unused)) struct cmdline *cl,
12816         __attribute__((unused)) void *data)
12817 {
12818         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12819         int ret = -ENOTSUP;
12820
12821         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12822                 return;
12823
12824 #ifdef RTE_LIBRTE_IXGBE_PMD
12825         if (ret == -ENOTSUP)
12826                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12827                                 &res->mac_addr);
12828 #endif
12829 #ifdef RTE_LIBRTE_I40E_PMD
12830         if (ret == -ENOTSUP)
12831                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12832                                 &res->mac_addr);
12833 #endif
12834 #ifdef RTE_LIBRTE_BNXT_PMD
12835         if (ret == -ENOTSUP)
12836                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12837                                 &res->mac_addr);
12838 #endif
12839
12840         switch (ret) {
12841         case 0:
12842                 break;
12843         case -EINVAL:
12844                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12845                 break;
12846         case -ENODEV:
12847                 printf("invalid port_id %d\n", res->port_id);
12848                 break;
12849         case -ENOTSUP:
12850                 printf("function not implemented\n");
12851                 break;
12852         default:
12853                 printf("programming error: (%s)\n", strerror(-ret));
12854         }
12855 }
12856
12857 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12858         .f = cmd_set_vf_mac_addr_parsed,
12859         .data = NULL,
12860         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12861         .tokens = {
12862                 (void *)&cmd_set_vf_mac_addr_set,
12863                 (void *)&cmd_set_vf_mac_addr_vf,
12864                 (void *)&cmd_set_vf_mac_addr_mac,
12865                 (void *)&cmd_set_vf_mac_addr_addr,
12866                 (void *)&cmd_set_vf_mac_addr_port_id,
12867                 (void *)&cmd_set_vf_mac_addr_vf_id,
12868                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12869                 NULL,
12870         },
12871 };
12872
12873 /* MACsec configuration */
12874
12875 /* Common result structure for MACsec offload enable */
12876 struct cmd_macsec_offload_on_result {
12877         cmdline_fixed_string_t set;
12878         cmdline_fixed_string_t macsec;
12879         cmdline_fixed_string_t offload;
12880         portid_t port_id;
12881         cmdline_fixed_string_t on;
12882         cmdline_fixed_string_t encrypt;
12883         cmdline_fixed_string_t en_on_off;
12884         cmdline_fixed_string_t replay_protect;
12885         cmdline_fixed_string_t rp_on_off;
12886 };
12887
12888 /* Common CLI fields for MACsec offload disable */
12889 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12890         TOKEN_STRING_INITIALIZER
12891                 (struct cmd_macsec_offload_on_result,
12892                  set, "set");
12893 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12894         TOKEN_STRING_INITIALIZER
12895                 (struct cmd_macsec_offload_on_result,
12896                  macsec, "macsec");
12897 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12898         TOKEN_STRING_INITIALIZER
12899                 (struct cmd_macsec_offload_on_result,
12900                  offload, "offload");
12901 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12902         TOKEN_NUM_INITIALIZER
12903                 (struct cmd_macsec_offload_on_result,
12904                  port_id, UINT16);
12905 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12906         TOKEN_STRING_INITIALIZER
12907                 (struct cmd_macsec_offload_on_result,
12908                  on, "on");
12909 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12910         TOKEN_STRING_INITIALIZER
12911                 (struct cmd_macsec_offload_on_result,
12912                  encrypt, "encrypt");
12913 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12914         TOKEN_STRING_INITIALIZER
12915                 (struct cmd_macsec_offload_on_result,
12916                  en_on_off, "on#off");
12917 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12918         TOKEN_STRING_INITIALIZER
12919                 (struct cmd_macsec_offload_on_result,
12920                  replay_protect, "replay-protect");
12921 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12922         TOKEN_STRING_INITIALIZER
12923                 (struct cmd_macsec_offload_on_result,
12924                  rp_on_off, "on#off");
12925
12926 static void
12927 cmd_set_macsec_offload_on_parsed(
12928         void *parsed_result,
12929         __attribute__((unused)) struct cmdline *cl,
12930         __attribute__((unused)) void *data)
12931 {
12932         struct cmd_macsec_offload_on_result *res = parsed_result;
12933         int ret = -ENOTSUP;
12934         portid_t port_id = res->port_id;
12935         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12936         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12937
12938         if (port_id_is_invalid(port_id, ENABLED_WARN))
12939                 return;
12940
12941         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12942 #ifdef RTE_LIBRTE_IXGBE_PMD
12943         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12944 #endif
12945         RTE_SET_USED(en);
12946         RTE_SET_USED(rp);
12947
12948         switch (ret) {
12949         case 0:
12950                 break;
12951         case -ENODEV:
12952                 printf("invalid port_id %d\n", port_id);
12953                 break;
12954         case -ENOTSUP:
12955                 printf("not supported on port %d\n", port_id);
12956                 break;
12957         default:
12958                 printf("programming error: (%s)\n", strerror(-ret));
12959         }
12960 }
12961
12962 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12963         .f = cmd_set_macsec_offload_on_parsed,
12964         .data = NULL,
12965         .help_str = "set macsec offload <port_id> on "
12966                 "encrypt on|off replay-protect on|off",
12967         .tokens = {
12968                 (void *)&cmd_macsec_offload_on_set,
12969                 (void *)&cmd_macsec_offload_on_macsec,
12970                 (void *)&cmd_macsec_offload_on_offload,
12971                 (void *)&cmd_macsec_offload_on_port_id,
12972                 (void *)&cmd_macsec_offload_on_on,
12973                 (void *)&cmd_macsec_offload_on_encrypt,
12974                 (void *)&cmd_macsec_offload_on_en_on_off,
12975                 (void *)&cmd_macsec_offload_on_replay_protect,
12976                 (void *)&cmd_macsec_offload_on_rp_on_off,
12977                 NULL,
12978         },
12979 };
12980
12981 /* Common result structure for MACsec offload disable */
12982 struct cmd_macsec_offload_off_result {
12983         cmdline_fixed_string_t set;
12984         cmdline_fixed_string_t macsec;
12985         cmdline_fixed_string_t offload;
12986         portid_t port_id;
12987         cmdline_fixed_string_t off;
12988 };
12989
12990 /* Common CLI fields for MACsec offload disable */
12991 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_macsec_offload_off_result,
12994                  set, "set");
12995 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12996         TOKEN_STRING_INITIALIZER
12997                 (struct cmd_macsec_offload_off_result,
12998                  macsec, "macsec");
12999 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13000         TOKEN_STRING_INITIALIZER
13001                 (struct cmd_macsec_offload_off_result,
13002                  offload, "offload");
13003 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13004         TOKEN_NUM_INITIALIZER
13005                 (struct cmd_macsec_offload_off_result,
13006                  port_id, UINT16);
13007 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13008         TOKEN_STRING_INITIALIZER
13009                 (struct cmd_macsec_offload_off_result,
13010                  off, "off");
13011
13012 static void
13013 cmd_set_macsec_offload_off_parsed(
13014         void *parsed_result,
13015         __attribute__((unused)) struct cmdline *cl,
13016         __attribute__((unused)) void *data)
13017 {
13018         struct cmd_macsec_offload_off_result *res = parsed_result;
13019         int ret = -ENOTSUP;
13020         portid_t port_id = res->port_id;
13021
13022         if (port_id_is_invalid(port_id, ENABLED_WARN))
13023                 return;
13024
13025         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13026 #ifdef RTE_LIBRTE_IXGBE_PMD
13027         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13028 #endif
13029
13030         switch (ret) {
13031         case 0:
13032                 break;
13033         case -ENODEV:
13034                 printf("invalid port_id %d\n", port_id);
13035                 break;
13036         case -ENOTSUP:
13037                 printf("not supported on port %d\n", port_id);
13038                 break;
13039         default:
13040                 printf("programming error: (%s)\n", strerror(-ret));
13041         }
13042 }
13043
13044 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13045         .f = cmd_set_macsec_offload_off_parsed,
13046         .data = NULL,
13047         .help_str = "set macsec offload <port_id> off",
13048         .tokens = {
13049                 (void *)&cmd_macsec_offload_off_set,
13050                 (void *)&cmd_macsec_offload_off_macsec,
13051                 (void *)&cmd_macsec_offload_off_offload,
13052                 (void *)&cmd_macsec_offload_off_port_id,
13053                 (void *)&cmd_macsec_offload_off_off,
13054                 NULL,
13055         },
13056 };
13057
13058 /* Common result structure for MACsec secure connection configure */
13059 struct cmd_macsec_sc_result {
13060         cmdline_fixed_string_t set;
13061         cmdline_fixed_string_t macsec;
13062         cmdline_fixed_string_t sc;
13063         cmdline_fixed_string_t tx_rx;
13064         portid_t port_id;
13065         struct ether_addr mac;
13066         uint16_t pi;
13067 };
13068
13069 /* Common CLI fields for MACsec secure connection configure */
13070 cmdline_parse_token_string_t cmd_macsec_sc_set =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_macsec_sc_result,
13073                  set, "set");
13074 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_macsec_sc_result,
13077                  macsec, "macsec");
13078 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_macsec_sc_result,
13081                  sc, "sc");
13082 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13083         TOKEN_STRING_INITIALIZER
13084                 (struct cmd_macsec_sc_result,
13085                  tx_rx, "tx#rx");
13086 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13087         TOKEN_NUM_INITIALIZER
13088                 (struct cmd_macsec_sc_result,
13089                  port_id, UINT16);
13090 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13091         TOKEN_ETHERADDR_INITIALIZER
13092                 (struct cmd_macsec_sc_result,
13093                  mac);
13094 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13095         TOKEN_NUM_INITIALIZER
13096                 (struct cmd_macsec_sc_result,
13097                  pi, UINT16);
13098
13099 static void
13100 cmd_set_macsec_sc_parsed(
13101         void *parsed_result,
13102         __attribute__((unused)) struct cmdline *cl,
13103         __attribute__((unused)) void *data)
13104 {
13105         struct cmd_macsec_sc_result *res = parsed_result;
13106         int ret = -ENOTSUP;
13107         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13108
13109 #ifdef RTE_LIBRTE_IXGBE_PMD
13110         ret = is_tx ?
13111                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13112                                 res->mac.addr_bytes) :
13113                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13114                                 res->mac.addr_bytes, res->pi);
13115 #endif
13116         RTE_SET_USED(is_tx);
13117
13118         switch (ret) {
13119         case 0:
13120                 break;
13121         case -ENODEV:
13122                 printf("invalid port_id %d\n", res->port_id);
13123                 break;
13124         case -ENOTSUP:
13125                 printf("not supported on port %d\n", res->port_id);
13126                 break;
13127         default:
13128                 printf("programming error: (%s)\n", strerror(-ret));
13129         }
13130 }
13131
13132 cmdline_parse_inst_t cmd_set_macsec_sc = {
13133         .f = cmd_set_macsec_sc_parsed,
13134         .data = NULL,
13135         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13136         .tokens = {
13137                 (void *)&cmd_macsec_sc_set,
13138                 (void *)&cmd_macsec_sc_macsec,
13139                 (void *)&cmd_macsec_sc_sc,
13140                 (void *)&cmd_macsec_sc_tx_rx,
13141                 (void *)&cmd_macsec_sc_port_id,
13142                 (void *)&cmd_macsec_sc_mac,
13143                 (void *)&cmd_macsec_sc_pi,
13144                 NULL,
13145         },
13146 };
13147
13148 /* Common result structure for MACsec secure connection configure */
13149 struct cmd_macsec_sa_result {
13150         cmdline_fixed_string_t set;
13151         cmdline_fixed_string_t macsec;
13152         cmdline_fixed_string_t sa;
13153         cmdline_fixed_string_t tx_rx;
13154         portid_t port_id;
13155         uint8_t idx;
13156         uint8_t an;
13157         uint32_t pn;
13158         cmdline_fixed_string_t key;
13159 };
13160
13161 /* Common CLI fields for MACsec secure connection configure */
13162 cmdline_parse_token_string_t cmd_macsec_sa_set =
13163         TOKEN_STRING_INITIALIZER
13164                 (struct cmd_macsec_sa_result,
13165                  set, "set");
13166 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13167         TOKEN_STRING_INITIALIZER
13168                 (struct cmd_macsec_sa_result,
13169                  macsec, "macsec");
13170 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13171         TOKEN_STRING_INITIALIZER
13172                 (struct cmd_macsec_sa_result,
13173                  sa, "sa");
13174 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13175         TOKEN_STRING_INITIALIZER
13176                 (struct cmd_macsec_sa_result,
13177                  tx_rx, "tx#rx");
13178 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13179         TOKEN_NUM_INITIALIZER
13180                 (struct cmd_macsec_sa_result,
13181                  port_id, UINT16);
13182 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13183         TOKEN_NUM_INITIALIZER
13184                 (struct cmd_macsec_sa_result,
13185                  idx, UINT8);
13186 cmdline_parse_token_num_t cmd_macsec_sa_an =
13187         TOKEN_NUM_INITIALIZER
13188                 (struct cmd_macsec_sa_result,
13189                  an, UINT8);
13190 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13191         TOKEN_NUM_INITIALIZER
13192                 (struct cmd_macsec_sa_result,
13193                  pn, UINT32);
13194 cmdline_parse_token_string_t cmd_macsec_sa_key =
13195         TOKEN_STRING_INITIALIZER
13196                 (struct cmd_macsec_sa_result,
13197                  key, NULL);
13198
13199 static void
13200 cmd_set_macsec_sa_parsed(
13201         void *parsed_result,
13202         __attribute__((unused)) struct cmdline *cl,
13203         __attribute__((unused)) void *data)
13204 {
13205         struct cmd_macsec_sa_result *res = parsed_result;
13206         int ret = -ENOTSUP;
13207         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13208         uint8_t key[16] = { 0 };
13209         uint8_t xdgt0;
13210         uint8_t xdgt1;
13211         int key_len;
13212         int i;
13213
13214         key_len = strlen(res->key) / 2;
13215         if (key_len > 16)
13216                 key_len = 16;
13217
13218         for (i = 0; i < key_len; i++) {
13219                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13220                 if (xdgt0 == 0xFF)
13221                         return;
13222                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13223                 if (xdgt1 == 0xFF)
13224                         return;
13225                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13226         }
13227
13228 #ifdef RTE_LIBRTE_IXGBE_PMD
13229         ret = is_tx ?
13230                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13231                         res->idx, res->an, res->pn, key) :
13232                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13233                         res->idx, res->an, res->pn, key);
13234 #endif
13235         RTE_SET_USED(is_tx);
13236         RTE_SET_USED(key);
13237
13238         switch (ret) {
13239         case 0:
13240                 break;
13241         case -EINVAL:
13242                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13243                 break;
13244         case -ENODEV:
13245                 printf("invalid port_id %d\n", res->port_id);
13246                 break;
13247         case -ENOTSUP:
13248                 printf("not supported on port %d\n", res->port_id);
13249                 break;
13250         default:
13251                 printf("programming error: (%s)\n", strerror(-ret));
13252         }
13253 }
13254
13255 cmdline_parse_inst_t cmd_set_macsec_sa = {
13256         .f = cmd_set_macsec_sa_parsed,
13257         .data = NULL,
13258         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13259         .tokens = {
13260                 (void *)&cmd_macsec_sa_set,
13261                 (void *)&cmd_macsec_sa_macsec,
13262                 (void *)&cmd_macsec_sa_sa,
13263                 (void *)&cmd_macsec_sa_tx_rx,
13264                 (void *)&cmd_macsec_sa_port_id,
13265                 (void *)&cmd_macsec_sa_idx,
13266                 (void *)&cmd_macsec_sa_an,
13267                 (void *)&cmd_macsec_sa_pn,
13268                 (void *)&cmd_macsec_sa_key,
13269                 NULL,
13270         },
13271 };
13272
13273 /* VF unicast promiscuous mode configuration */
13274
13275 /* Common result structure for VF unicast promiscuous mode */
13276 struct cmd_vf_promisc_result {
13277         cmdline_fixed_string_t set;
13278         cmdline_fixed_string_t vf;
13279         cmdline_fixed_string_t promisc;
13280         portid_t port_id;
13281         uint32_t vf_id;
13282         cmdline_fixed_string_t on_off;
13283 };
13284
13285 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13286 cmdline_parse_token_string_t cmd_vf_promisc_set =
13287         TOKEN_STRING_INITIALIZER
13288                 (struct cmd_vf_promisc_result,
13289                  set, "set");
13290 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13291         TOKEN_STRING_INITIALIZER
13292                 (struct cmd_vf_promisc_result,
13293                  vf, "vf");
13294 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13295         TOKEN_STRING_INITIALIZER
13296                 (struct cmd_vf_promisc_result,
13297                  promisc, "promisc");
13298 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13299         TOKEN_NUM_INITIALIZER
13300                 (struct cmd_vf_promisc_result,
13301                  port_id, UINT16);
13302 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13303         TOKEN_NUM_INITIALIZER
13304                 (struct cmd_vf_promisc_result,
13305                  vf_id, UINT32);
13306 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13307         TOKEN_STRING_INITIALIZER
13308                 (struct cmd_vf_promisc_result,
13309                  on_off, "on#off");
13310
13311 static void
13312 cmd_set_vf_promisc_parsed(
13313         void *parsed_result,
13314         __attribute__((unused)) struct cmdline *cl,
13315         __attribute__((unused)) void *data)
13316 {
13317         struct cmd_vf_promisc_result *res = parsed_result;
13318         int ret = -ENOTSUP;
13319
13320         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13321
13322         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13323                 return;
13324
13325 #ifdef RTE_LIBRTE_I40E_PMD
13326         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13327                                                   res->vf_id, is_on);
13328 #endif
13329
13330         switch (ret) {
13331         case 0:
13332                 break;
13333         case -EINVAL:
13334                 printf("invalid vf_id %d\n", res->vf_id);
13335                 break;
13336         case -ENODEV:
13337                 printf("invalid port_id %d\n", res->port_id);
13338                 break;
13339         case -ENOTSUP:
13340                 printf("function not implemented\n");
13341                 break;
13342         default:
13343                 printf("programming error: (%s)\n", strerror(-ret));
13344         }
13345 }
13346
13347 cmdline_parse_inst_t cmd_set_vf_promisc = {
13348         .f = cmd_set_vf_promisc_parsed,
13349         .data = NULL,
13350         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13351                 "Set unicast promiscuous mode for a VF from the PF",
13352         .tokens = {
13353                 (void *)&cmd_vf_promisc_set,
13354                 (void *)&cmd_vf_promisc_vf,
13355                 (void *)&cmd_vf_promisc_promisc,
13356                 (void *)&cmd_vf_promisc_port_id,
13357                 (void *)&cmd_vf_promisc_vf_id,
13358                 (void *)&cmd_vf_promisc_on_off,
13359                 NULL,
13360         },
13361 };
13362
13363 /* VF multicast promiscuous mode configuration */
13364
13365 /* Common result structure for VF multicast promiscuous mode */
13366 struct cmd_vf_allmulti_result {
13367         cmdline_fixed_string_t set;
13368         cmdline_fixed_string_t vf;
13369         cmdline_fixed_string_t allmulti;
13370         portid_t port_id;
13371         uint32_t vf_id;
13372         cmdline_fixed_string_t on_off;
13373 };
13374
13375 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13376 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13377         TOKEN_STRING_INITIALIZER
13378                 (struct cmd_vf_allmulti_result,
13379                  set, "set");
13380 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13381         TOKEN_STRING_INITIALIZER
13382                 (struct cmd_vf_allmulti_result,
13383                  vf, "vf");
13384 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13385         TOKEN_STRING_INITIALIZER
13386                 (struct cmd_vf_allmulti_result,
13387                  allmulti, "allmulti");
13388 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13389         TOKEN_NUM_INITIALIZER
13390                 (struct cmd_vf_allmulti_result,
13391                  port_id, UINT16);
13392 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13393         TOKEN_NUM_INITIALIZER
13394                 (struct cmd_vf_allmulti_result,
13395                  vf_id, UINT32);
13396 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13397         TOKEN_STRING_INITIALIZER
13398                 (struct cmd_vf_allmulti_result,
13399                  on_off, "on#off");
13400
13401 static void
13402 cmd_set_vf_allmulti_parsed(
13403         void *parsed_result,
13404         __attribute__((unused)) struct cmdline *cl,
13405         __attribute__((unused)) void *data)
13406 {
13407         struct cmd_vf_allmulti_result *res = parsed_result;
13408         int ret = -ENOTSUP;
13409
13410         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13411
13412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13413                 return;
13414
13415 #ifdef RTE_LIBRTE_I40E_PMD
13416         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13417                                                     res->vf_id, is_on);
13418 #endif
13419
13420         switch (ret) {
13421         case 0:
13422                 break;
13423         case -EINVAL:
13424                 printf("invalid vf_id %d\n", res->vf_id);
13425                 break;
13426         case -ENODEV:
13427                 printf("invalid port_id %d\n", res->port_id);
13428                 break;
13429         case -ENOTSUP:
13430                 printf("function not implemented\n");
13431                 break;
13432         default:
13433                 printf("programming error: (%s)\n", strerror(-ret));
13434         }
13435 }
13436
13437 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13438         .f = cmd_set_vf_allmulti_parsed,
13439         .data = NULL,
13440         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13441                 "Set multicast promiscuous mode for a VF from the PF",
13442         .tokens = {
13443                 (void *)&cmd_vf_allmulti_set,
13444                 (void *)&cmd_vf_allmulti_vf,
13445                 (void *)&cmd_vf_allmulti_allmulti,
13446                 (void *)&cmd_vf_allmulti_port_id,
13447                 (void *)&cmd_vf_allmulti_vf_id,
13448                 (void *)&cmd_vf_allmulti_on_off,
13449                 NULL,
13450         },
13451 };
13452
13453 /* vf broadcast mode configuration */
13454
13455 /* Common result structure for vf broadcast */
13456 struct cmd_set_vf_broadcast_result {
13457         cmdline_fixed_string_t set;
13458         cmdline_fixed_string_t vf;
13459         cmdline_fixed_string_t broadcast;
13460         portid_t port_id;
13461         uint16_t vf_id;
13462         cmdline_fixed_string_t on_off;
13463 };
13464
13465 /* Common CLI fields for vf broadcast enable disable */
13466 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13467         TOKEN_STRING_INITIALIZER
13468                 (struct cmd_set_vf_broadcast_result,
13469                  set, "set");
13470 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13471         TOKEN_STRING_INITIALIZER
13472                 (struct cmd_set_vf_broadcast_result,
13473                  vf, "vf");
13474 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13475         TOKEN_STRING_INITIALIZER
13476                 (struct cmd_set_vf_broadcast_result,
13477                  broadcast, "broadcast");
13478 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13479         TOKEN_NUM_INITIALIZER
13480                 (struct cmd_set_vf_broadcast_result,
13481                  port_id, UINT16);
13482 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13483         TOKEN_NUM_INITIALIZER
13484                 (struct cmd_set_vf_broadcast_result,
13485                  vf_id, UINT16);
13486 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13487         TOKEN_STRING_INITIALIZER
13488                 (struct cmd_set_vf_broadcast_result,
13489                  on_off, "on#off");
13490
13491 static void
13492 cmd_set_vf_broadcast_parsed(
13493         void *parsed_result,
13494         __attribute__((unused)) struct cmdline *cl,
13495         __attribute__((unused)) void *data)
13496 {
13497         struct cmd_set_vf_broadcast_result *res = parsed_result;
13498         int ret = -ENOTSUP;
13499
13500         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13501
13502         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13503                 return;
13504
13505 #ifdef RTE_LIBRTE_I40E_PMD
13506         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13507                                             res->vf_id, is_on);
13508 #endif
13509
13510         switch (ret) {
13511         case 0:
13512                 break;
13513         case -EINVAL:
13514                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13515                 break;
13516         case -ENODEV:
13517                 printf("invalid port_id %d\n", res->port_id);
13518                 break;
13519         case -ENOTSUP:
13520                 printf("function not implemented\n");
13521                 break;
13522         default:
13523                 printf("programming error: (%s)\n", strerror(-ret));
13524         }
13525 }
13526
13527 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13528         .f = cmd_set_vf_broadcast_parsed,
13529         .data = NULL,
13530         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13531         .tokens = {
13532                 (void *)&cmd_set_vf_broadcast_set,
13533                 (void *)&cmd_set_vf_broadcast_vf,
13534                 (void *)&cmd_set_vf_broadcast_broadcast,
13535                 (void *)&cmd_set_vf_broadcast_port_id,
13536                 (void *)&cmd_set_vf_broadcast_vf_id,
13537                 (void *)&cmd_set_vf_broadcast_on_off,
13538                 NULL,
13539         },
13540 };
13541
13542 /* vf vlan tag configuration */
13543
13544 /* Common result structure for vf vlan tag */
13545 struct cmd_set_vf_vlan_tag_result {
13546         cmdline_fixed_string_t set;
13547         cmdline_fixed_string_t vf;
13548         cmdline_fixed_string_t vlan;
13549         cmdline_fixed_string_t tag;
13550         portid_t port_id;
13551         uint16_t vf_id;
13552         cmdline_fixed_string_t on_off;
13553 };
13554
13555 /* Common CLI fields for vf vlan tag enable disable */
13556 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13557         TOKEN_STRING_INITIALIZER
13558                 (struct cmd_set_vf_vlan_tag_result,
13559                  set, "set");
13560 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13561         TOKEN_STRING_INITIALIZER
13562                 (struct cmd_set_vf_vlan_tag_result,
13563                  vf, "vf");
13564 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13565         TOKEN_STRING_INITIALIZER
13566                 (struct cmd_set_vf_vlan_tag_result,
13567                  vlan, "vlan");
13568 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13569         TOKEN_STRING_INITIALIZER
13570                 (struct cmd_set_vf_vlan_tag_result,
13571                  tag, "tag");
13572 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13573         TOKEN_NUM_INITIALIZER
13574                 (struct cmd_set_vf_vlan_tag_result,
13575                  port_id, UINT16);
13576 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13577         TOKEN_NUM_INITIALIZER
13578                 (struct cmd_set_vf_vlan_tag_result,
13579                  vf_id, UINT16);
13580 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13581         TOKEN_STRING_INITIALIZER
13582                 (struct cmd_set_vf_vlan_tag_result,
13583                  on_off, "on#off");
13584
13585 static void
13586 cmd_set_vf_vlan_tag_parsed(
13587         void *parsed_result,
13588         __attribute__((unused)) struct cmdline *cl,
13589         __attribute__((unused)) void *data)
13590 {
13591         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13592         int ret = -ENOTSUP;
13593
13594         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13595
13596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13597                 return;
13598
13599 #ifdef RTE_LIBRTE_I40E_PMD
13600         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13601                                            res->vf_id, is_on);
13602 #endif
13603
13604         switch (ret) {
13605         case 0:
13606                 break;
13607         case -EINVAL:
13608                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13609                 break;
13610         case -ENODEV:
13611                 printf("invalid port_id %d\n", res->port_id);
13612                 break;
13613         case -ENOTSUP:
13614                 printf("function not implemented\n");
13615                 break;
13616         default:
13617                 printf("programming error: (%s)\n", strerror(-ret));
13618         }
13619 }
13620
13621 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13622         .f = cmd_set_vf_vlan_tag_parsed,
13623         .data = NULL,
13624         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13625         .tokens = {
13626                 (void *)&cmd_set_vf_vlan_tag_set,
13627                 (void *)&cmd_set_vf_vlan_tag_vf,
13628                 (void *)&cmd_set_vf_vlan_tag_vlan,
13629                 (void *)&cmd_set_vf_vlan_tag_tag,
13630                 (void *)&cmd_set_vf_vlan_tag_port_id,
13631                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13632                 (void *)&cmd_set_vf_vlan_tag_on_off,
13633                 NULL,
13634         },
13635 };
13636
13637 /* Common definition of VF and TC TX bandwidth configuration */
13638 struct cmd_vf_tc_bw_result {
13639         cmdline_fixed_string_t set;
13640         cmdline_fixed_string_t vf;
13641         cmdline_fixed_string_t tc;
13642         cmdline_fixed_string_t tx;
13643         cmdline_fixed_string_t min_bw;
13644         cmdline_fixed_string_t max_bw;
13645         cmdline_fixed_string_t strict_link_prio;
13646         portid_t port_id;
13647         uint16_t vf_id;
13648         uint8_t tc_no;
13649         uint32_t bw;
13650         cmdline_fixed_string_t bw_list;
13651         uint8_t tc_map;
13652 };
13653
13654 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13655         TOKEN_STRING_INITIALIZER
13656                 (struct cmd_vf_tc_bw_result,
13657                  set, "set");
13658 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13659         TOKEN_STRING_INITIALIZER
13660                 (struct cmd_vf_tc_bw_result,
13661                  vf, "vf");
13662 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13663         TOKEN_STRING_INITIALIZER
13664                 (struct cmd_vf_tc_bw_result,
13665                  tc, "tc");
13666 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13667         TOKEN_STRING_INITIALIZER
13668                 (struct cmd_vf_tc_bw_result,
13669                  tx, "tx");
13670 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13671         TOKEN_STRING_INITIALIZER
13672                 (struct cmd_vf_tc_bw_result,
13673                  strict_link_prio, "strict-link-priority");
13674 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_vf_tc_bw_result,
13677                  min_bw, "min-bandwidth");
13678 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_vf_tc_bw_result,
13681                  max_bw, "max-bandwidth");
13682 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13683         TOKEN_NUM_INITIALIZER
13684                 (struct cmd_vf_tc_bw_result,
13685                  port_id, UINT16);
13686 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13687         TOKEN_NUM_INITIALIZER
13688                 (struct cmd_vf_tc_bw_result,
13689                  vf_id, UINT16);
13690 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13691         TOKEN_NUM_INITIALIZER
13692                 (struct cmd_vf_tc_bw_result,
13693                  tc_no, UINT8);
13694 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13695         TOKEN_NUM_INITIALIZER
13696                 (struct cmd_vf_tc_bw_result,
13697                  bw, UINT32);
13698 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13699         TOKEN_STRING_INITIALIZER
13700                 (struct cmd_vf_tc_bw_result,
13701                  bw_list, NULL);
13702 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13703         TOKEN_NUM_INITIALIZER
13704                 (struct cmd_vf_tc_bw_result,
13705                  tc_map, UINT8);
13706
13707 /* VF max bandwidth setting */
13708 static void
13709 cmd_vf_max_bw_parsed(
13710         void *parsed_result,
13711         __attribute__((unused)) struct cmdline *cl,
13712         __attribute__((unused)) void *data)
13713 {
13714         struct cmd_vf_tc_bw_result *res = parsed_result;
13715         int ret = -ENOTSUP;
13716
13717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13718                 return;
13719
13720 #ifdef RTE_LIBRTE_I40E_PMD
13721         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13722                                          res->vf_id, res->bw);
13723 #endif
13724
13725         switch (ret) {
13726         case 0:
13727                 break;
13728         case -EINVAL:
13729                 printf("invalid vf_id %d or bandwidth %d\n",
13730                        res->vf_id, res->bw);
13731                 break;
13732         case -ENODEV:
13733                 printf("invalid port_id %d\n", res->port_id);
13734                 break;
13735         case -ENOTSUP:
13736                 printf("function not implemented\n");
13737                 break;
13738         default:
13739                 printf("programming error: (%s)\n", strerror(-ret));
13740         }
13741 }
13742
13743 cmdline_parse_inst_t cmd_vf_max_bw = {
13744         .f = cmd_vf_max_bw_parsed,
13745         .data = NULL,
13746         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13747         .tokens = {
13748                 (void *)&cmd_vf_tc_bw_set,
13749                 (void *)&cmd_vf_tc_bw_vf,
13750                 (void *)&cmd_vf_tc_bw_tx,
13751                 (void *)&cmd_vf_tc_bw_max_bw,
13752                 (void *)&cmd_vf_tc_bw_port_id,
13753                 (void *)&cmd_vf_tc_bw_vf_id,
13754                 (void *)&cmd_vf_tc_bw_bw,
13755                 NULL,
13756         },
13757 };
13758
13759 static int
13760 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13761                            uint8_t *tc_num,
13762                            char *str)
13763 {
13764         uint32_t size;
13765         const char *p, *p0 = str;
13766         char s[256];
13767         char *end;
13768         char *str_fld[16];
13769         uint16_t i;
13770         int ret;
13771
13772         p = strchr(p0, '(');
13773         if (p == NULL) {
13774                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13775                 return -1;
13776         }
13777         p++;
13778         p0 = strchr(p, ')');
13779         if (p0 == NULL) {
13780                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13781                 return -1;
13782         }
13783         size = p0 - p;
13784         if (size >= sizeof(s)) {
13785                 printf("The string size exceeds the internal buffer size\n");
13786                 return -1;
13787         }
13788         snprintf(s, sizeof(s), "%.*s", size, p);
13789         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13790         if (ret <= 0) {
13791                 printf("Failed to get the bandwidth list. ");
13792                 return -1;
13793         }
13794         *tc_num = ret;
13795         for (i = 0; i < ret; i++)
13796                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13797
13798         return 0;
13799 }
13800
13801 /* TC min bandwidth setting */
13802 static void
13803 cmd_vf_tc_min_bw_parsed(
13804         void *parsed_result,
13805         __attribute__((unused)) struct cmdline *cl,
13806         __attribute__((unused)) void *data)
13807 {
13808         struct cmd_vf_tc_bw_result *res = parsed_result;
13809         uint8_t tc_num;
13810         uint8_t bw[16];
13811         int ret = -ENOTSUP;
13812
13813         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13814                 return;
13815
13816         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13817         if (ret)
13818                 return;
13819
13820 #ifdef RTE_LIBRTE_I40E_PMD
13821         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13822                                               tc_num, bw);
13823 #endif
13824
13825         switch (ret) {
13826         case 0:
13827                 break;
13828         case -EINVAL:
13829                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13830                 break;
13831         case -ENODEV:
13832                 printf("invalid port_id %d\n", res->port_id);
13833                 break;
13834         case -ENOTSUP:
13835                 printf("function not implemented\n");
13836                 break;
13837         default:
13838                 printf("programming error: (%s)\n", strerror(-ret));
13839         }
13840 }
13841
13842 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13843         .f = cmd_vf_tc_min_bw_parsed,
13844         .data = NULL,
13845         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13846                     " <bw1, bw2, ...>",
13847         .tokens = {
13848                 (void *)&cmd_vf_tc_bw_set,
13849                 (void *)&cmd_vf_tc_bw_vf,
13850                 (void *)&cmd_vf_tc_bw_tc,
13851                 (void *)&cmd_vf_tc_bw_tx,
13852                 (void *)&cmd_vf_tc_bw_min_bw,
13853                 (void *)&cmd_vf_tc_bw_port_id,
13854                 (void *)&cmd_vf_tc_bw_vf_id,
13855                 (void *)&cmd_vf_tc_bw_bw_list,
13856                 NULL,
13857         },
13858 };
13859
13860 static void
13861 cmd_tc_min_bw_parsed(
13862         void *parsed_result,
13863         __attribute__((unused)) struct cmdline *cl,
13864         __attribute__((unused)) void *data)
13865 {
13866         struct cmd_vf_tc_bw_result *res = parsed_result;
13867         struct rte_port *port;
13868         uint8_t tc_num;
13869         uint8_t bw[16];
13870         int ret = -ENOTSUP;
13871
13872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13873                 return;
13874
13875         port = &ports[res->port_id];
13876         /** Check if the port is not started **/
13877         if (port->port_status != RTE_PORT_STOPPED) {
13878                 printf("Please stop port %d first\n", res->port_id);
13879                 return;
13880         }
13881
13882         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13883         if (ret)
13884                 return;
13885
13886 #ifdef RTE_LIBRTE_IXGBE_PMD
13887         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13888 #endif
13889
13890         switch (ret) {
13891         case 0:
13892                 break;
13893         case -EINVAL:
13894                 printf("invalid bandwidth\n");
13895                 break;
13896         case -ENODEV:
13897                 printf("invalid port_id %d\n", res->port_id);
13898                 break;
13899         case -ENOTSUP:
13900                 printf("function not implemented\n");
13901                 break;
13902         default:
13903                 printf("programming error: (%s)\n", strerror(-ret));
13904         }
13905 }
13906
13907 cmdline_parse_inst_t cmd_tc_min_bw = {
13908         .f = cmd_tc_min_bw_parsed,
13909         .data = NULL,
13910         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13911         .tokens = {
13912                 (void *)&cmd_vf_tc_bw_set,
13913                 (void *)&cmd_vf_tc_bw_tc,
13914                 (void *)&cmd_vf_tc_bw_tx,
13915                 (void *)&cmd_vf_tc_bw_min_bw,
13916                 (void *)&cmd_vf_tc_bw_port_id,
13917                 (void *)&cmd_vf_tc_bw_bw_list,
13918                 NULL,
13919         },
13920 };
13921
13922 /* TC max bandwidth setting */
13923 static void
13924 cmd_vf_tc_max_bw_parsed(
13925         void *parsed_result,
13926         __attribute__((unused)) struct cmdline *cl,
13927         __attribute__((unused)) void *data)
13928 {
13929         struct cmd_vf_tc_bw_result *res = parsed_result;
13930         int ret = -ENOTSUP;
13931
13932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13933                 return;
13934
13935 #ifdef RTE_LIBRTE_I40E_PMD
13936         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13937                                             res->tc_no, res->bw);
13938 #endif
13939
13940         switch (ret) {
13941         case 0:
13942                 break;
13943         case -EINVAL:
13944                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13945                        res->vf_id, res->tc_no, res->bw);
13946                 break;
13947         case -ENODEV:
13948                 printf("invalid port_id %d\n", res->port_id);
13949                 break;
13950         case -ENOTSUP:
13951                 printf("function not implemented\n");
13952                 break;
13953         default:
13954                 printf("programming error: (%s)\n", strerror(-ret));
13955         }
13956 }
13957
13958 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13959         .f = cmd_vf_tc_max_bw_parsed,
13960         .data = NULL,
13961         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13962                     " <bandwidth>",
13963         .tokens = {
13964                 (void *)&cmd_vf_tc_bw_set,
13965                 (void *)&cmd_vf_tc_bw_vf,
13966                 (void *)&cmd_vf_tc_bw_tc,
13967                 (void *)&cmd_vf_tc_bw_tx,
13968                 (void *)&cmd_vf_tc_bw_max_bw,
13969                 (void *)&cmd_vf_tc_bw_port_id,
13970                 (void *)&cmd_vf_tc_bw_vf_id,
13971                 (void *)&cmd_vf_tc_bw_tc_no,
13972                 (void *)&cmd_vf_tc_bw_bw,
13973                 NULL,
13974         },
13975 };
13976
13977
13978 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
13979
13980 /* *** Set Port default Traffic Management Hierarchy *** */
13981 struct cmd_set_port_tm_hierarchy_default_result {
13982         cmdline_fixed_string_t set;
13983         cmdline_fixed_string_t port;
13984         cmdline_fixed_string_t tm;
13985         cmdline_fixed_string_t hierarchy;
13986         cmdline_fixed_string_t def;
13987         portid_t port_id;
13988 };
13989
13990 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
13991         TOKEN_STRING_INITIALIZER(
13992                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
13993 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
13994         TOKEN_STRING_INITIALIZER(
13995                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
13996 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
13997         TOKEN_STRING_INITIALIZER(
13998                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
13999 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14000         TOKEN_STRING_INITIALIZER(
14001                 struct cmd_set_port_tm_hierarchy_default_result,
14002                         hierarchy, "hierarchy");
14003 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14004         TOKEN_STRING_INITIALIZER(
14005                 struct cmd_set_port_tm_hierarchy_default_result,
14006                         def, "default");
14007 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14008         TOKEN_NUM_INITIALIZER(
14009                 struct cmd_set_port_tm_hierarchy_default_result,
14010                         port_id, UINT16);
14011
14012 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14013         __attribute__((unused)) struct cmdline *cl,
14014         __attribute__((unused)) void *data)
14015 {
14016         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14017         struct rte_port *p;
14018         portid_t port_id = res->port_id;
14019
14020         if (port_id_is_invalid(port_id, ENABLED_WARN))
14021                 return;
14022
14023         p = &ports[port_id];
14024
14025         /* Port tm flag */
14026         if (p->softport.tm_flag == 0) {
14027                 printf("  tm not enabled on port %u (error)\n", port_id);
14028                 return;
14029         }
14030
14031         /* Forward mode: tm */
14032         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14033                 printf("  tm mode not enabled(error)\n");
14034                 return;
14035         }
14036
14037         /* Set the default tm hierarchy */
14038         p->softport.tm.default_hierarchy_enable = 1;
14039 }
14040
14041 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14042         .f = cmd_set_port_tm_hierarchy_default_parsed,
14043         .data = NULL,
14044         .help_str = "set port tm hierarchy default <port_id>",
14045         .tokens = {
14046                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14047                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14048                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14049                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14050                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14051                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14052                 NULL,
14053         },
14054 };
14055 #endif
14056
14057 /* Strict link priority scheduling mode setting */
14058 static void
14059 cmd_strict_link_prio_parsed(
14060         void *parsed_result,
14061         __attribute__((unused)) struct cmdline *cl,
14062         __attribute__((unused)) void *data)
14063 {
14064         struct cmd_vf_tc_bw_result *res = parsed_result;
14065         int ret = -ENOTSUP;
14066
14067         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14068                 return;
14069
14070 #ifdef RTE_LIBRTE_I40E_PMD
14071         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14072 #endif
14073
14074         switch (ret) {
14075         case 0:
14076                 break;
14077         case -EINVAL:
14078                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14079                 break;
14080         case -ENODEV:
14081                 printf("invalid port_id %d\n", res->port_id);
14082                 break;
14083         case -ENOTSUP:
14084                 printf("function not implemented\n");
14085                 break;
14086         default:
14087                 printf("programming error: (%s)\n", strerror(-ret));
14088         }
14089 }
14090
14091 cmdline_parse_inst_t cmd_strict_link_prio = {
14092         .f = cmd_strict_link_prio_parsed,
14093         .data = NULL,
14094         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14095         .tokens = {
14096                 (void *)&cmd_vf_tc_bw_set,
14097                 (void *)&cmd_vf_tc_bw_tx,
14098                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14099                 (void *)&cmd_vf_tc_bw_port_id,
14100                 (void *)&cmd_vf_tc_bw_tc_map,
14101                 NULL,
14102         },
14103 };
14104
14105 /* Load dynamic device personalization*/
14106 struct cmd_ddp_add_result {
14107         cmdline_fixed_string_t ddp;
14108         cmdline_fixed_string_t add;
14109         portid_t port_id;
14110         char filepath[];
14111 };
14112
14113 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14114         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14115 cmdline_parse_token_string_t cmd_ddp_add_add =
14116         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14117 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14118         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14119 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14120         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14121
14122 static void
14123 cmd_ddp_add_parsed(
14124         void *parsed_result,
14125         __attribute__((unused)) struct cmdline *cl,
14126         __attribute__((unused)) void *data)
14127 {
14128         struct cmd_ddp_add_result *res = parsed_result;
14129         uint8_t *buff;
14130         uint32_t size;
14131         char *filepath;
14132         char *file_fld[2];
14133         int file_num;
14134         int ret = -ENOTSUP;
14135
14136         if (res->port_id > nb_ports) {
14137                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14138                 return;
14139         }
14140
14141         if (!all_ports_stopped()) {
14142                 printf("Please stop all ports first\n");
14143                 return;
14144         }
14145
14146         filepath = strdup(res->filepath);
14147         if (filepath == NULL) {
14148                 printf("Failed to allocate memory\n");
14149                 return;
14150         }
14151         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14152
14153         buff = open_ddp_package_file(file_fld[0], &size);
14154         if (!buff) {
14155                 free((void *)filepath);
14156                 return;
14157         }
14158
14159 #ifdef RTE_LIBRTE_I40E_PMD
14160         if (ret == -ENOTSUP)
14161                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14162                                                buff, size,
14163                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14164 #endif
14165
14166         if (ret == -EEXIST)
14167                 printf("Profile has already existed.\n");
14168         else if (ret < 0)
14169                 printf("Failed to load profile.\n");
14170         else if (file_num == 2)
14171                 save_ddp_package_file(file_fld[1], buff, size);
14172
14173         close_ddp_package_file(buff);
14174         free((void *)filepath);
14175 }
14176
14177 cmdline_parse_inst_t cmd_ddp_add = {
14178         .f = cmd_ddp_add_parsed,
14179         .data = NULL,
14180         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14181         .tokens = {
14182                 (void *)&cmd_ddp_add_ddp,
14183                 (void *)&cmd_ddp_add_add,
14184                 (void *)&cmd_ddp_add_port_id,
14185                 (void *)&cmd_ddp_add_filepath,
14186                 NULL,
14187         },
14188 };
14189
14190 /* Delete dynamic device personalization*/
14191 struct cmd_ddp_del_result {
14192         cmdline_fixed_string_t ddp;
14193         cmdline_fixed_string_t del;
14194         portid_t port_id;
14195         char filepath[];
14196 };
14197
14198 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14199         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14200 cmdline_parse_token_string_t cmd_ddp_del_del =
14201         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14202 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14203         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14204 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14205         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14206
14207 static void
14208 cmd_ddp_del_parsed(
14209         void *parsed_result,
14210         __attribute__((unused)) struct cmdline *cl,
14211         __attribute__((unused)) void *data)
14212 {
14213         struct cmd_ddp_del_result *res = parsed_result;
14214         uint8_t *buff;
14215         uint32_t size;
14216         int ret = -ENOTSUP;
14217
14218         if (res->port_id > nb_ports) {
14219                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14220                 return;
14221         }
14222
14223         if (!all_ports_stopped()) {
14224                 printf("Please stop all ports first\n");
14225                 return;
14226         }
14227
14228         buff = open_ddp_package_file(res->filepath, &size);
14229         if (!buff)
14230                 return;
14231
14232 #ifdef RTE_LIBRTE_I40E_PMD
14233         if (ret == -ENOTSUP)
14234                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14235                                                buff, size,
14236                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14237 #endif
14238
14239         if (ret == -EACCES)
14240                 printf("Profile does not exist.\n");
14241         else if (ret < 0)
14242                 printf("Failed to delete profile.\n");
14243
14244         close_ddp_package_file(buff);
14245 }
14246
14247 cmdline_parse_inst_t cmd_ddp_del = {
14248         .f = cmd_ddp_del_parsed,
14249         .data = NULL,
14250         .help_str = "ddp del <port_id> <profile_path>",
14251         .tokens = {
14252                 (void *)&cmd_ddp_del_ddp,
14253                 (void *)&cmd_ddp_del_del,
14254                 (void *)&cmd_ddp_del_port_id,
14255                 (void *)&cmd_ddp_del_filepath,
14256                 NULL,
14257         },
14258 };
14259
14260 /* Get dynamic device personalization profile info */
14261 struct cmd_ddp_info_result {
14262         cmdline_fixed_string_t ddp;
14263         cmdline_fixed_string_t get;
14264         cmdline_fixed_string_t info;
14265         char filepath[];
14266 };
14267
14268 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14269         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14270 cmdline_parse_token_string_t cmd_ddp_info_get =
14271         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14272 cmdline_parse_token_string_t cmd_ddp_info_info =
14273         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14274 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14275         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14276
14277 static void
14278 cmd_ddp_info_parsed(
14279         void *parsed_result,
14280         __attribute__((unused)) struct cmdline *cl,
14281         __attribute__((unused)) void *data)
14282 {
14283         struct cmd_ddp_info_result *res = parsed_result;
14284         uint8_t *pkg;
14285         uint32_t pkg_size;
14286         int ret = -ENOTSUP;
14287 #ifdef RTE_LIBRTE_I40E_PMD
14288         uint32_t i, j, n;
14289         uint8_t *buff;
14290         uint32_t buff_size = 0;
14291         struct rte_pmd_i40e_profile_info info;
14292         uint32_t dev_num = 0;
14293         struct rte_pmd_i40e_ddp_device_id *devs;
14294         uint32_t proto_num = 0;
14295         struct rte_pmd_i40e_proto_info *proto;
14296         uint32_t pctype_num = 0;
14297         struct rte_pmd_i40e_ptype_info *pctype;
14298         uint32_t ptype_num = 0;
14299         struct rte_pmd_i40e_ptype_info *ptype;
14300         uint8_t proto_id;
14301
14302 #endif
14303
14304         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14305         if (!pkg)
14306                 return;
14307
14308 #ifdef RTE_LIBRTE_I40E_PMD
14309         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14310                                 (uint8_t *)&info, sizeof(info),
14311                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14312         if (!ret) {
14313                 printf("Global Track id:       0x%x\n", info.track_id);
14314                 printf("Global Version:        %d.%d.%d.%d\n",
14315                         info.version.major,
14316                         info.version.minor,
14317                         info.version.update,
14318                         info.version.draft);
14319                 printf("Global Package name:   %s\n\n", info.name);
14320         }
14321
14322         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14323                                 (uint8_t *)&info, sizeof(info),
14324                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14325         if (!ret) {
14326                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14327                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14328                         info.version.major,
14329                         info.version.minor,
14330                         info.version.update,
14331                         info.version.draft);
14332                 printf("i40e Profile name:     %s\n\n", info.name);
14333         }
14334
14335         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14336                                 (uint8_t *)&buff_size, sizeof(buff_size),
14337                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14338         if (!ret && buff_size) {
14339                 buff = (uint8_t *)malloc(buff_size);
14340                 if (buff) {
14341                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14342                                                 buff, buff_size,
14343                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14344                         if (!ret)
14345                                 printf("Package Notes:\n%s\n\n", buff);
14346                         free(buff);
14347                 }
14348         }
14349
14350         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14351                                 (uint8_t *)&dev_num, sizeof(dev_num),
14352                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14353         if (!ret && dev_num) {
14354                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14355                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14356                 if (devs) {
14357                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14358                                                 (uint8_t *)devs, buff_size,
14359                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14360                         if (!ret) {
14361                                 printf("List of supported devices:\n");
14362                                 for (i = 0; i < dev_num; i++) {
14363                                         printf("  %04X:%04X %04X:%04X\n",
14364                                                 devs[i].vendor_dev_id >> 16,
14365                                                 devs[i].vendor_dev_id & 0xFFFF,
14366                                                 devs[i].sub_vendor_dev_id >> 16,
14367                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14368                                 }
14369                                 printf("\n");
14370                         }
14371                         free(devs);
14372                 }
14373         }
14374
14375         /* get information about protocols and packet types */
14376         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14377                 (uint8_t *)&proto_num, sizeof(proto_num),
14378                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14379         if (ret || !proto_num)
14380                 goto no_print_return;
14381
14382         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14383         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14384         if (!proto)
14385                 goto no_print_return;
14386
14387         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14388                                         buff_size,
14389                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14390         if (!ret) {
14391                 printf("List of used protocols:\n");
14392                 for (i = 0; i < proto_num; i++)
14393                         printf("  %2u: %s\n", proto[i].proto_id,
14394                                proto[i].name);
14395                 printf("\n");
14396         }
14397         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14398                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14399                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14400         if (ret || !pctype_num)
14401                 goto no_print_pctypes;
14402
14403         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14404         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14405         if (!pctype)
14406                 goto no_print_pctypes;
14407
14408         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14409                                         buff_size,
14410                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14411         if (ret) {
14412                 free(pctype);
14413                 goto no_print_pctypes;
14414         }
14415
14416         printf("List of defined packet classification types:\n");
14417         for (i = 0; i < pctype_num; i++) {
14418                 printf("  %2u:", pctype[i].ptype_id);
14419                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14420                         proto_id = pctype[i].protocols[j];
14421                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14422                                 for (n = 0; n < proto_num; n++) {
14423                                         if (proto[n].proto_id == proto_id) {
14424                                                 printf(" %s", proto[n].name);
14425                                                 break;
14426                                         }
14427                                 }
14428                         }
14429                 }
14430                 printf("\n");
14431         }
14432         printf("\n");
14433         free(pctype);
14434
14435 no_print_pctypes:
14436
14437         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14438                                         sizeof(ptype_num),
14439                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14440         if (ret || !ptype_num)
14441                 goto no_print_return;
14442
14443         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14444         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14445         if (!ptype)
14446                 goto no_print_return;
14447
14448         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14449                                         buff_size,
14450                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14451         if (ret) {
14452                 free(ptype);
14453                 goto no_print_return;
14454         }
14455         printf("List of defined packet types:\n");
14456         for (i = 0; i < ptype_num; i++) {
14457                 printf("  %2u:", ptype[i].ptype_id);
14458                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14459                         proto_id = ptype[i].protocols[j];
14460                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14461                                 for (n = 0; n < proto_num; n++) {
14462                                         if (proto[n].proto_id == proto_id) {
14463                                                 printf(" %s", proto[n].name);
14464                                                 break;
14465                                         }
14466                                 }
14467                         }
14468                 }
14469                 printf("\n");
14470         }
14471         free(ptype);
14472         printf("\n");
14473
14474         free(proto);
14475         ret = 0;
14476 no_print_return:
14477 #endif
14478         if (ret == -ENOTSUP)
14479                 printf("Function not supported in PMD driver\n");
14480         close_ddp_package_file(pkg);
14481 }
14482
14483 cmdline_parse_inst_t cmd_ddp_get_info = {
14484         .f = cmd_ddp_info_parsed,
14485         .data = NULL,
14486         .help_str = "ddp get info <profile_path>",
14487         .tokens = {
14488                 (void *)&cmd_ddp_info_ddp,
14489                 (void *)&cmd_ddp_info_get,
14490                 (void *)&cmd_ddp_info_info,
14491                 (void *)&cmd_ddp_info_filepath,
14492                 NULL,
14493         },
14494 };
14495
14496 /* Get dynamic device personalization profile info list*/
14497 #define PROFILE_INFO_SIZE 48
14498 #define MAX_PROFILE_NUM 16
14499
14500 struct cmd_ddp_get_list_result {
14501         cmdline_fixed_string_t ddp;
14502         cmdline_fixed_string_t get;
14503         cmdline_fixed_string_t list;
14504         portid_t port_id;
14505 };
14506
14507 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14508         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14509 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14510         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14511 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14512         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14513 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14514         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14515
14516 static void
14517 cmd_ddp_get_list_parsed(
14518         void *parsed_result,
14519         __attribute__((unused)) struct cmdline *cl,
14520         __attribute__((unused)) void *data)
14521 {
14522         struct cmd_ddp_get_list_result *res = parsed_result;
14523 #ifdef RTE_LIBRTE_I40E_PMD
14524         struct rte_pmd_i40e_profile_list *p_list;
14525         struct rte_pmd_i40e_profile_info *p_info;
14526         uint32_t p_num;
14527         uint32_t size;
14528         uint32_t i;
14529 #endif
14530         int ret = -ENOTSUP;
14531
14532         if (res->port_id > nb_ports) {
14533                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14534                 return;
14535         }
14536
14537 #ifdef RTE_LIBRTE_I40E_PMD
14538         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14539         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14540         if (!p_list)
14541                 printf("%s: Failed to malloc buffer\n", __func__);
14542
14543         if (ret == -ENOTSUP)
14544                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14545                                                 (uint8_t *)p_list, size);
14546
14547         if (!ret) {
14548                 p_num = p_list->p_count;
14549                 printf("Profile number is: %d\n\n", p_num);
14550
14551                 for (i = 0; i < p_num; i++) {
14552                         p_info = &p_list->p_info[i];
14553                         printf("Profile %d:\n", i);
14554                         printf("Track id:     0x%x\n", p_info->track_id);
14555                         printf("Version:      %d.%d.%d.%d\n",
14556                                p_info->version.major,
14557                                p_info->version.minor,
14558                                p_info->version.update,
14559                                p_info->version.draft);
14560                         printf("Profile name: %s\n\n", p_info->name);
14561                 }
14562         }
14563
14564         free(p_list);
14565 #endif
14566
14567         if (ret < 0)
14568                 printf("Failed to get ddp list\n");
14569 }
14570
14571 cmdline_parse_inst_t cmd_ddp_get_list = {
14572         .f = cmd_ddp_get_list_parsed,
14573         .data = NULL,
14574         .help_str = "ddp get list <port_id>",
14575         .tokens = {
14576                 (void *)&cmd_ddp_get_list_ddp,
14577                 (void *)&cmd_ddp_get_list_get,
14578                 (void *)&cmd_ddp_get_list_list,
14579                 (void *)&cmd_ddp_get_list_port_id,
14580                 NULL,
14581         },
14582 };
14583
14584 /* show vf stats */
14585
14586 /* Common result structure for show vf stats */
14587 struct cmd_show_vf_stats_result {
14588         cmdline_fixed_string_t show;
14589         cmdline_fixed_string_t vf;
14590         cmdline_fixed_string_t stats;
14591         portid_t port_id;
14592         uint16_t vf_id;
14593 };
14594
14595 /* Common CLI fields show vf stats*/
14596 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14597         TOKEN_STRING_INITIALIZER
14598                 (struct cmd_show_vf_stats_result,
14599                  show, "show");
14600 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14601         TOKEN_STRING_INITIALIZER
14602                 (struct cmd_show_vf_stats_result,
14603                  vf, "vf");
14604 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14605         TOKEN_STRING_INITIALIZER
14606                 (struct cmd_show_vf_stats_result,
14607                  stats, "stats");
14608 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14609         TOKEN_NUM_INITIALIZER
14610                 (struct cmd_show_vf_stats_result,
14611                  port_id, UINT16);
14612 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14613         TOKEN_NUM_INITIALIZER
14614                 (struct cmd_show_vf_stats_result,
14615                  vf_id, UINT16);
14616
14617 static void
14618 cmd_show_vf_stats_parsed(
14619         void *parsed_result,
14620         __attribute__((unused)) struct cmdline *cl,
14621         __attribute__((unused)) void *data)
14622 {
14623         struct cmd_show_vf_stats_result *res = parsed_result;
14624         struct rte_eth_stats stats;
14625         int ret = -ENOTSUP;
14626         static const char *nic_stats_border = "########################";
14627
14628         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14629                 return;
14630
14631         memset(&stats, 0, sizeof(stats));
14632
14633 #ifdef RTE_LIBRTE_I40E_PMD
14634         if (ret == -ENOTSUP)
14635                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14636                                                 res->vf_id,
14637                                                 &stats);
14638 #endif
14639 #ifdef RTE_LIBRTE_BNXT_PMD
14640         if (ret == -ENOTSUP)
14641                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14642                                                 res->vf_id,
14643                                                 &stats);
14644 #endif
14645
14646         switch (ret) {
14647         case 0:
14648                 break;
14649         case -EINVAL:
14650                 printf("invalid vf_id %d\n", res->vf_id);
14651                 break;
14652         case -ENODEV:
14653                 printf("invalid port_id %d\n", res->port_id);
14654                 break;
14655         case -ENOTSUP:
14656                 printf("function not implemented\n");
14657                 break;
14658         default:
14659                 printf("programming error: (%s)\n", strerror(-ret));
14660         }
14661
14662         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14663                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14664
14665         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14666                "%-"PRIu64"\n",
14667                stats.ipackets, stats.imissed, stats.ibytes);
14668         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14669         printf("  RX-nombuf:  %-10"PRIu64"\n",
14670                stats.rx_nombuf);
14671         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14672                "%-"PRIu64"\n",
14673                stats.opackets, stats.oerrors, stats.obytes);
14674
14675         printf("  %s############################%s\n",
14676                                nic_stats_border, nic_stats_border);
14677 }
14678
14679 cmdline_parse_inst_t cmd_show_vf_stats = {
14680         .f = cmd_show_vf_stats_parsed,
14681         .data = NULL,
14682         .help_str = "show vf stats <port_id> <vf_id>",
14683         .tokens = {
14684                 (void *)&cmd_show_vf_stats_show,
14685                 (void *)&cmd_show_vf_stats_vf,
14686                 (void *)&cmd_show_vf_stats_stats,
14687                 (void *)&cmd_show_vf_stats_port_id,
14688                 (void *)&cmd_show_vf_stats_vf_id,
14689                 NULL,
14690         },
14691 };
14692
14693 /* clear vf stats */
14694
14695 /* Common result structure for clear vf stats */
14696 struct cmd_clear_vf_stats_result {
14697         cmdline_fixed_string_t clear;
14698         cmdline_fixed_string_t vf;
14699         cmdline_fixed_string_t stats;
14700         portid_t port_id;
14701         uint16_t vf_id;
14702 };
14703
14704 /* Common CLI fields clear vf stats*/
14705 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14706         TOKEN_STRING_INITIALIZER
14707                 (struct cmd_clear_vf_stats_result,
14708                  clear, "clear");
14709 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14710         TOKEN_STRING_INITIALIZER
14711                 (struct cmd_clear_vf_stats_result,
14712                  vf, "vf");
14713 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14714         TOKEN_STRING_INITIALIZER
14715                 (struct cmd_clear_vf_stats_result,
14716                  stats, "stats");
14717 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14718         TOKEN_NUM_INITIALIZER
14719                 (struct cmd_clear_vf_stats_result,
14720                  port_id, UINT16);
14721 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14722         TOKEN_NUM_INITIALIZER
14723                 (struct cmd_clear_vf_stats_result,
14724                  vf_id, UINT16);
14725
14726 static void
14727 cmd_clear_vf_stats_parsed(
14728         void *parsed_result,
14729         __attribute__((unused)) struct cmdline *cl,
14730         __attribute__((unused)) void *data)
14731 {
14732         struct cmd_clear_vf_stats_result *res = parsed_result;
14733         int ret = -ENOTSUP;
14734
14735         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14736                 return;
14737
14738 #ifdef RTE_LIBRTE_I40E_PMD
14739         if (ret == -ENOTSUP)
14740                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14741                                                   res->vf_id);
14742 #endif
14743 #ifdef RTE_LIBRTE_BNXT_PMD
14744         if (ret == -ENOTSUP)
14745                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14746                                                   res->vf_id);
14747 #endif
14748
14749         switch (ret) {
14750         case 0:
14751                 break;
14752         case -EINVAL:
14753                 printf("invalid vf_id %d\n", res->vf_id);
14754                 break;
14755         case -ENODEV:
14756                 printf("invalid port_id %d\n", res->port_id);
14757                 break;
14758         case -ENOTSUP:
14759                 printf("function not implemented\n");
14760                 break;
14761         default:
14762                 printf("programming error: (%s)\n", strerror(-ret));
14763         }
14764 }
14765
14766 cmdline_parse_inst_t cmd_clear_vf_stats = {
14767         .f = cmd_clear_vf_stats_parsed,
14768         .data = NULL,
14769         .help_str = "clear vf stats <port_id> <vf_id>",
14770         .tokens = {
14771                 (void *)&cmd_clear_vf_stats_clear,
14772                 (void *)&cmd_clear_vf_stats_vf,
14773                 (void *)&cmd_clear_vf_stats_stats,
14774                 (void *)&cmd_clear_vf_stats_port_id,
14775                 (void *)&cmd_clear_vf_stats_vf_id,
14776                 NULL,
14777         },
14778 };
14779
14780 /* port config pctype mapping reset */
14781
14782 /* Common result structure for port config pctype mapping reset */
14783 struct cmd_pctype_mapping_reset_result {
14784         cmdline_fixed_string_t port;
14785         cmdline_fixed_string_t config;
14786         portid_t port_id;
14787         cmdline_fixed_string_t pctype;
14788         cmdline_fixed_string_t mapping;
14789         cmdline_fixed_string_t reset;
14790 };
14791
14792 /* Common CLI fields for port config pctype mapping reset*/
14793 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14794         TOKEN_STRING_INITIALIZER
14795                 (struct cmd_pctype_mapping_reset_result,
14796                  port, "port");
14797 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14798         TOKEN_STRING_INITIALIZER
14799                 (struct cmd_pctype_mapping_reset_result,
14800                  config, "config");
14801 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14802         TOKEN_NUM_INITIALIZER
14803                 (struct cmd_pctype_mapping_reset_result,
14804                  port_id, UINT16);
14805 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14806         TOKEN_STRING_INITIALIZER
14807                 (struct cmd_pctype_mapping_reset_result,
14808                  pctype, "pctype");
14809 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14810         TOKEN_STRING_INITIALIZER
14811                 (struct cmd_pctype_mapping_reset_result,
14812                  mapping, "mapping");
14813 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14814         TOKEN_STRING_INITIALIZER
14815                 (struct cmd_pctype_mapping_reset_result,
14816                  reset, "reset");
14817
14818 static void
14819 cmd_pctype_mapping_reset_parsed(
14820         void *parsed_result,
14821         __attribute__((unused)) struct cmdline *cl,
14822         __attribute__((unused)) void *data)
14823 {
14824         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14825         int ret = -ENOTSUP;
14826
14827         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14828                 return;
14829
14830 #ifdef RTE_LIBRTE_I40E_PMD
14831         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14832 #endif
14833
14834         switch (ret) {
14835         case 0:
14836                 break;
14837         case -ENODEV:
14838                 printf("invalid port_id %d\n", res->port_id);
14839                 break;
14840         case -ENOTSUP:
14841                 printf("function not implemented\n");
14842                 break;
14843         default:
14844                 printf("programming error: (%s)\n", strerror(-ret));
14845         }
14846 }
14847
14848 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14849         .f = cmd_pctype_mapping_reset_parsed,
14850         .data = NULL,
14851         .help_str = "port config <port_id> pctype mapping reset",
14852         .tokens = {
14853                 (void *)&cmd_pctype_mapping_reset_port,
14854                 (void *)&cmd_pctype_mapping_reset_config,
14855                 (void *)&cmd_pctype_mapping_reset_port_id,
14856                 (void *)&cmd_pctype_mapping_reset_pctype,
14857                 (void *)&cmd_pctype_mapping_reset_mapping,
14858                 (void *)&cmd_pctype_mapping_reset_reset,
14859                 NULL,
14860         },
14861 };
14862
14863 /* show port pctype mapping */
14864
14865 /* Common result structure for show port pctype mapping */
14866 struct cmd_pctype_mapping_get_result {
14867         cmdline_fixed_string_t show;
14868         cmdline_fixed_string_t port;
14869         portid_t port_id;
14870         cmdline_fixed_string_t pctype;
14871         cmdline_fixed_string_t mapping;
14872 };
14873
14874 /* Common CLI fields for pctype mapping get */
14875 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14876         TOKEN_STRING_INITIALIZER
14877                 (struct cmd_pctype_mapping_get_result,
14878                  show, "show");
14879 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14880         TOKEN_STRING_INITIALIZER
14881                 (struct cmd_pctype_mapping_get_result,
14882                  port, "port");
14883 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14884         TOKEN_NUM_INITIALIZER
14885                 (struct cmd_pctype_mapping_get_result,
14886                  port_id, UINT16);
14887 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14888         TOKEN_STRING_INITIALIZER
14889                 (struct cmd_pctype_mapping_get_result,
14890                  pctype, "pctype");
14891 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14892         TOKEN_STRING_INITIALIZER
14893                 (struct cmd_pctype_mapping_get_result,
14894                  mapping, "mapping");
14895
14896 static void
14897 cmd_pctype_mapping_get_parsed(
14898         void *parsed_result,
14899         __attribute__((unused)) struct cmdline *cl,
14900         __attribute__((unused)) void *data)
14901 {
14902         struct cmd_pctype_mapping_get_result *res = parsed_result;
14903         int ret = -ENOTSUP;
14904 #ifdef RTE_LIBRTE_I40E_PMD
14905         struct rte_pmd_i40e_flow_type_mapping
14906                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14907         int i, j, first_pctype;
14908 #endif
14909
14910         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14911                 return;
14912
14913 #ifdef RTE_LIBRTE_I40E_PMD
14914         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14915 #endif
14916
14917         switch (ret) {
14918         case 0:
14919                 break;
14920         case -ENODEV:
14921                 printf("invalid port_id %d\n", res->port_id);
14922                 return;
14923         case -ENOTSUP:
14924                 printf("function not implemented\n");
14925                 return;
14926         default:
14927                 printf("programming error: (%s)\n", strerror(-ret));
14928                 return;
14929         }
14930
14931 #ifdef RTE_LIBRTE_I40E_PMD
14932         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14933                 if (mapping[i].pctype != 0ULL) {
14934                         first_pctype = 1;
14935
14936                         printf("pctype: ");
14937                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14938                                 if (mapping[i].pctype & (1ULL << j)) {
14939                                         printf(first_pctype ?
14940                                                "%02d" : ",%02d", j);
14941                                         first_pctype = 0;
14942                                 }
14943                         }
14944                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14945                 }
14946         }
14947 #endif
14948 }
14949
14950 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14951         .f = cmd_pctype_mapping_get_parsed,
14952         .data = NULL,
14953         .help_str = "show port <port_id> pctype mapping",
14954         .tokens = {
14955                 (void *)&cmd_pctype_mapping_get_show,
14956                 (void *)&cmd_pctype_mapping_get_port,
14957                 (void *)&cmd_pctype_mapping_get_port_id,
14958                 (void *)&cmd_pctype_mapping_get_pctype,
14959                 (void *)&cmd_pctype_mapping_get_mapping,
14960                 NULL,
14961         },
14962 };
14963
14964 /* port config pctype mapping update */
14965
14966 /* Common result structure for port config pctype mapping update */
14967 struct cmd_pctype_mapping_update_result {
14968         cmdline_fixed_string_t port;
14969         cmdline_fixed_string_t config;
14970         portid_t port_id;
14971         cmdline_fixed_string_t pctype;
14972         cmdline_fixed_string_t mapping;
14973         cmdline_fixed_string_t update;
14974         cmdline_fixed_string_t pctype_list;
14975         uint16_t flow_type;
14976 };
14977
14978 /* Common CLI fields for pctype mapping update*/
14979 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14980         TOKEN_STRING_INITIALIZER
14981                 (struct cmd_pctype_mapping_update_result,
14982                  port, "port");
14983 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14984         TOKEN_STRING_INITIALIZER
14985                 (struct cmd_pctype_mapping_update_result,
14986                  config, "config");
14987 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14988         TOKEN_NUM_INITIALIZER
14989                 (struct cmd_pctype_mapping_update_result,
14990                  port_id, UINT16);
14991 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14992         TOKEN_STRING_INITIALIZER
14993                 (struct cmd_pctype_mapping_update_result,
14994                  pctype, "pctype");
14995 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14996         TOKEN_STRING_INITIALIZER
14997                 (struct cmd_pctype_mapping_update_result,
14998                  mapping, "mapping");
14999 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15000         TOKEN_STRING_INITIALIZER
15001                 (struct cmd_pctype_mapping_update_result,
15002                  update, "update");
15003 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15004         TOKEN_STRING_INITIALIZER
15005                 (struct cmd_pctype_mapping_update_result,
15006                  pctype_list, NULL);
15007 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15008         TOKEN_NUM_INITIALIZER
15009                 (struct cmd_pctype_mapping_update_result,
15010                  flow_type, UINT16);
15011
15012 static void
15013 cmd_pctype_mapping_update_parsed(
15014         void *parsed_result,
15015         __attribute__((unused)) struct cmdline *cl,
15016         __attribute__((unused)) void *data)
15017 {
15018         struct cmd_pctype_mapping_update_result *res = parsed_result;
15019         int ret = -ENOTSUP;
15020 #ifdef RTE_LIBRTE_I40E_PMD
15021         struct rte_pmd_i40e_flow_type_mapping mapping;
15022         unsigned int i;
15023         unsigned int nb_item;
15024         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15025 #endif
15026
15027         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15028                 return;
15029
15030 #ifdef RTE_LIBRTE_I40E_PMD
15031         nb_item = parse_item_list(res->pctype_list, "pctypes",
15032                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15033         mapping.flow_type = res->flow_type;
15034         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15035                 mapping.pctype |= (1ULL << pctype_list[i]);
15036         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15037                                                 &mapping,
15038                                                 1,
15039                                                 0);
15040 #endif
15041
15042         switch (ret) {
15043         case 0:
15044                 break;
15045         case -EINVAL:
15046                 printf("invalid pctype or flow type\n");
15047                 break;
15048         case -ENODEV:
15049                 printf("invalid port_id %d\n", res->port_id);
15050                 break;
15051         case -ENOTSUP:
15052                 printf("function not implemented\n");
15053                 break;
15054         default:
15055                 printf("programming error: (%s)\n", strerror(-ret));
15056         }
15057 }
15058
15059 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15060         .f = cmd_pctype_mapping_update_parsed,
15061         .data = NULL,
15062         .help_str = "port config <port_id> pctype mapping update"
15063         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15064         .tokens = {
15065                 (void *)&cmd_pctype_mapping_update_port,
15066                 (void *)&cmd_pctype_mapping_update_config,
15067                 (void *)&cmd_pctype_mapping_update_port_id,
15068                 (void *)&cmd_pctype_mapping_update_pctype,
15069                 (void *)&cmd_pctype_mapping_update_mapping,
15070                 (void *)&cmd_pctype_mapping_update_update,
15071                 (void *)&cmd_pctype_mapping_update_pc_type,
15072                 (void *)&cmd_pctype_mapping_update_flow_type,
15073                 NULL,
15074         },
15075 };
15076
15077 /* ptype mapping get */
15078
15079 /* Common result structure for ptype mapping get */
15080 struct cmd_ptype_mapping_get_result {
15081         cmdline_fixed_string_t ptype;
15082         cmdline_fixed_string_t mapping;
15083         cmdline_fixed_string_t get;
15084         portid_t port_id;
15085         uint8_t valid_only;
15086 };
15087
15088 /* Common CLI fields for ptype mapping get */
15089 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15090         TOKEN_STRING_INITIALIZER
15091                 (struct cmd_ptype_mapping_get_result,
15092                  ptype, "ptype");
15093 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15094         TOKEN_STRING_INITIALIZER
15095                 (struct cmd_ptype_mapping_get_result,
15096                  mapping, "mapping");
15097 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15098         TOKEN_STRING_INITIALIZER
15099                 (struct cmd_ptype_mapping_get_result,
15100                  get, "get");
15101 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15102         TOKEN_NUM_INITIALIZER
15103                 (struct cmd_ptype_mapping_get_result,
15104                  port_id, UINT16);
15105 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15106         TOKEN_NUM_INITIALIZER
15107                 (struct cmd_ptype_mapping_get_result,
15108                  valid_only, UINT8);
15109
15110 static void
15111 cmd_ptype_mapping_get_parsed(
15112         void *parsed_result,
15113         __attribute__((unused)) struct cmdline *cl,
15114         __attribute__((unused)) void *data)
15115 {
15116         struct cmd_ptype_mapping_get_result *res = parsed_result;
15117         int ret = -ENOTSUP;
15118 #ifdef RTE_LIBRTE_I40E_PMD
15119         int max_ptype_num = 256;
15120         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15121         uint16_t count;
15122         int i;
15123 #endif
15124
15125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15126                 return;
15127
15128 #ifdef RTE_LIBRTE_I40E_PMD
15129         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15130                                         mapping,
15131                                         max_ptype_num,
15132                                         &count,
15133                                         res->valid_only);
15134 #endif
15135
15136         switch (ret) {
15137         case 0:
15138                 break;
15139         case -ENODEV:
15140                 printf("invalid port_id %d\n", res->port_id);
15141                 break;
15142         case -ENOTSUP:
15143                 printf("function not implemented\n");
15144                 break;
15145         default:
15146                 printf("programming error: (%s)\n", strerror(-ret));
15147         }
15148
15149 #ifdef RTE_LIBRTE_I40E_PMD
15150         if (!ret) {
15151                 for (i = 0; i < count; i++)
15152                         printf("%3d\t0x%08x\n",
15153                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15154         }
15155 #endif
15156 }
15157
15158 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15159         .f = cmd_ptype_mapping_get_parsed,
15160         .data = NULL,
15161         .help_str = "ptype mapping get <port_id> <valid_only>",
15162         .tokens = {
15163                 (void *)&cmd_ptype_mapping_get_ptype,
15164                 (void *)&cmd_ptype_mapping_get_mapping,
15165                 (void *)&cmd_ptype_mapping_get_get,
15166                 (void *)&cmd_ptype_mapping_get_port_id,
15167                 (void *)&cmd_ptype_mapping_get_valid_only,
15168                 NULL,
15169         },
15170 };
15171
15172 /* ptype mapping replace */
15173
15174 /* Common result structure for ptype mapping replace */
15175 struct cmd_ptype_mapping_replace_result {
15176         cmdline_fixed_string_t ptype;
15177         cmdline_fixed_string_t mapping;
15178         cmdline_fixed_string_t replace;
15179         portid_t port_id;
15180         uint32_t target;
15181         uint8_t mask;
15182         uint32_t pkt_type;
15183 };
15184
15185 /* Common CLI fields for ptype mapping replace */
15186 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15187         TOKEN_STRING_INITIALIZER
15188                 (struct cmd_ptype_mapping_replace_result,
15189                  ptype, "ptype");
15190 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15191         TOKEN_STRING_INITIALIZER
15192                 (struct cmd_ptype_mapping_replace_result,
15193                  mapping, "mapping");
15194 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15195         TOKEN_STRING_INITIALIZER
15196                 (struct cmd_ptype_mapping_replace_result,
15197                  replace, "replace");
15198 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15199         TOKEN_NUM_INITIALIZER
15200                 (struct cmd_ptype_mapping_replace_result,
15201                  port_id, UINT16);
15202 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15203         TOKEN_NUM_INITIALIZER
15204                 (struct cmd_ptype_mapping_replace_result,
15205                  target, UINT32);
15206 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15207         TOKEN_NUM_INITIALIZER
15208                 (struct cmd_ptype_mapping_replace_result,
15209                  mask, UINT8);
15210 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15211         TOKEN_NUM_INITIALIZER
15212                 (struct cmd_ptype_mapping_replace_result,
15213                  pkt_type, UINT32);
15214
15215 static void
15216 cmd_ptype_mapping_replace_parsed(
15217         void *parsed_result,
15218         __attribute__((unused)) struct cmdline *cl,
15219         __attribute__((unused)) void *data)
15220 {
15221         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15222         int ret = -ENOTSUP;
15223
15224         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15225                 return;
15226
15227 #ifdef RTE_LIBRTE_I40E_PMD
15228         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15229                                         res->target,
15230                                         res->mask,
15231                                         res->pkt_type);
15232 #endif
15233
15234         switch (ret) {
15235         case 0:
15236                 break;
15237         case -EINVAL:
15238                 printf("invalid ptype 0x%8x or 0x%8x\n",
15239                                 res->target, res->pkt_type);
15240                 break;
15241         case -ENODEV:
15242                 printf("invalid port_id %d\n", res->port_id);
15243                 break;
15244         case -ENOTSUP:
15245                 printf("function not implemented\n");
15246                 break;
15247         default:
15248                 printf("programming error: (%s)\n", strerror(-ret));
15249         }
15250 }
15251
15252 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15253         .f = cmd_ptype_mapping_replace_parsed,
15254         .data = NULL,
15255         .help_str =
15256                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15257         .tokens = {
15258                 (void *)&cmd_ptype_mapping_replace_ptype,
15259                 (void *)&cmd_ptype_mapping_replace_mapping,
15260                 (void *)&cmd_ptype_mapping_replace_replace,
15261                 (void *)&cmd_ptype_mapping_replace_port_id,
15262                 (void *)&cmd_ptype_mapping_replace_target,
15263                 (void *)&cmd_ptype_mapping_replace_mask,
15264                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15265                 NULL,
15266         },
15267 };
15268
15269 /* ptype mapping reset */
15270
15271 /* Common result structure for ptype mapping reset */
15272 struct cmd_ptype_mapping_reset_result {
15273         cmdline_fixed_string_t ptype;
15274         cmdline_fixed_string_t mapping;
15275         cmdline_fixed_string_t reset;
15276         portid_t port_id;
15277 };
15278
15279 /* Common CLI fields for ptype mapping reset*/
15280 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15281         TOKEN_STRING_INITIALIZER
15282                 (struct cmd_ptype_mapping_reset_result,
15283                  ptype, "ptype");
15284 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15285         TOKEN_STRING_INITIALIZER
15286                 (struct cmd_ptype_mapping_reset_result,
15287                  mapping, "mapping");
15288 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15289         TOKEN_STRING_INITIALIZER
15290                 (struct cmd_ptype_mapping_reset_result,
15291                  reset, "reset");
15292 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15293         TOKEN_NUM_INITIALIZER
15294                 (struct cmd_ptype_mapping_reset_result,
15295                  port_id, UINT16);
15296
15297 static void
15298 cmd_ptype_mapping_reset_parsed(
15299         void *parsed_result,
15300         __attribute__((unused)) struct cmdline *cl,
15301         __attribute__((unused)) void *data)
15302 {
15303         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15304         int ret = -ENOTSUP;
15305
15306         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15307                 return;
15308
15309 #ifdef RTE_LIBRTE_I40E_PMD
15310         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15311 #endif
15312
15313         switch (ret) {
15314         case 0:
15315                 break;
15316         case -ENODEV:
15317                 printf("invalid port_id %d\n", res->port_id);
15318                 break;
15319         case -ENOTSUP:
15320                 printf("function not implemented\n");
15321                 break;
15322         default:
15323                 printf("programming error: (%s)\n", strerror(-ret));
15324         }
15325 }
15326
15327 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15328         .f = cmd_ptype_mapping_reset_parsed,
15329         .data = NULL,
15330         .help_str = "ptype mapping reset <port_id>",
15331         .tokens = {
15332                 (void *)&cmd_ptype_mapping_reset_ptype,
15333                 (void *)&cmd_ptype_mapping_reset_mapping,
15334                 (void *)&cmd_ptype_mapping_reset_reset,
15335                 (void *)&cmd_ptype_mapping_reset_port_id,
15336                 NULL,
15337         },
15338 };
15339
15340 /* ptype mapping update */
15341
15342 /* Common result structure for ptype mapping update */
15343 struct cmd_ptype_mapping_update_result {
15344         cmdline_fixed_string_t ptype;
15345         cmdline_fixed_string_t mapping;
15346         cmdline_fixed_string_t reset;
15347         portid_t port_id;
15348         uint8_t hw_ptype;
15349         uint32_t sw_ptype;
15350 };
15351
15352 /* Common CLI fields for ptype mapping update*/
15353 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15354         TOKEN_STRING_INITIALIZER
15355                 (struct cmd_ptype_mapping_update_result,
15356                  ptype, "ptype");
15357 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15358         TOKEN_STRING_INITIALIZER
15359                 (struct cmd_ptype_mapping_update_result,
15360                  mapping, "mapping");
15361 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15362         TOKEN_STRING_INITIALIZER
15363                 (struct cmd_ptype_mapping_update_result,
15364                  reset, "update");
15365 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15366         TOKEN_NUM_INITIALIZER
15367                 (struct cmd_ptype_mapping_update_result,
15368                  port_id, UINT16);
15369 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15370         TOKEN_NUM_INITIALIZER
15371                 (struct cmd_ptype_mapping_update_result,
15372                  hw_ptype, UINT8);
15373 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15374         TOKEN_NUM_INITIALIZER
15375                 (struct cmd_ptype_mapping_update_result,
15376                  sw_ptype, UINT32);
15377
15378 static void
15379 cmd_ptype_mapping_update_parsed(
15380         void *parsed_result,
15381         __attribute__((unused)) struct cmdline *cl,
15382         __attribute__((unused)) void *data)
15383 {
15384         struct cmd_ptype_mapping_update_result *res = parsed_result;
15385         int ret = -ENOTSUP;
15386 #ifdef RTE_LIBRTE_I40E_PMD
15387         struct rte_pmd_i40e_ptype_mapping mapping;
15388 #endif
15389         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15390                 return;
15391
15392 #ifdef RTE_LIBRTE_I40E_PMD
15393         mapping.hw_ptype = res->hw_ptype;
15394         mapping.sw_ptype = res->sw_ptype;
15395         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15396                                                 &mapping,
15397                                                 1,
15398                                                 0);
15399 #endif
15400
15401         switch (ret) {
15402         case 0:
15403                 break;
15404         case -EINVAL:
15405                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15406                 break;
15407         case -ENODEV:
15408                 printf("invalid port_id %d\n", res->port_id);
15409                 break;
15410         case -ENOTSUP:
15411                 printf("function not implemented\n");
15412                 break;
15413         default:
15414                 printf("programming error: (%s)\n", strerror(-ret));
15415         }
15416 }
15417
15418 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15419         .f = cmd_ptype_mapping_update_parsed,
15420         .data = NULL,
15421         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15422         .tokens = {
15423                 (void *)&cmd_ptype_mapping_update_ptype,
15424                 (void *)&cmd_ptype_mapping_update_mapping,
15425                 (void *)&cmd_ptype_mapping_update_update,
15426                 (void *)&cmd_ptype_mapping_update_port_id,
15427                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15428                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15429                 NULL,
15430         },
15431 };
15432
15433 /* Common result structure for file commands */
15434 struct cmd_cmdfile_result {
15435         cmdline_fixed_string_t load;
15436         cmdline_fixed_string_t filename;
15437 };
15438
15439 /* Common CLI fields for file commands */
15440 cmdline_parse_token_string_t cmd_load_cmdfile =
15441         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15442 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15443         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15444
15445 static void
15446 cmd_load_from_file_parsed(
15447         void *parsed_result,
15448         __attribute__((unused)) struct cmdline *cl,
15449         __attribute__((unused)) void *data)
15450 {
15451         struct cmd_cmdfile_result *res = parsed_result;
15452
15453         cmdline_read_from_file(res->filename);
15454 }
15455
15456 cmdline_parse_inst_t cmd_load_from_file = {
15457         .f = cmd_load_from_file_parsed,
15458         .data = NULL,
15459         .help_str = "load <filename>",
15460         .tokens = {
15461                 (void *)&cmd_load_cmdfile,
15462                 (void *)&cmd_load_cmdfile_filename,
15463                 NULL,
15464         },
15465 };
15466
15467 /* ******************************************************************************** */
15468
15469 /* list of instructions */
15470 cmdline_parse_ctx_t main_ctx[] = {
15471         (cmdline_parse_inst_t *)&cmd_help_brief,
15472         (cmdline_parse_inst_t *)&cmd_help_long,
15473         (cmdline_parse_inst_t *)&cmd_quit,
15474         (cmdline_parse_inst_t *)&cmd_load_from_file,
15475         (cmdline_parse_inst_t *)&cmd_showport,
15476         (cmdline_parse_inst_t *)&cmd_showqueue,
15477         (cmdline_parse_inst_t *)&cmd_showportall,
15478         (cmdline_parse_inst_t *)&cmd_showcfg,
15479         (cmdline_parse_inst_t *)&cmd_start,
15480         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15481         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15482         (cmdline_parse_inst_t *)&cmd_set_link_up,
15483         (cmdline_parse_inst_t *)&cmd_set_link_down,
15484         (cmdline_parse_inst_t *)&cmd_reset,
15485         (cmdline_parse_inst_t *)&cmd_set_numbers,
15486         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15487         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15488         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15489         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15490         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15491         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15492         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15493         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15494         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15495         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15496         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15497         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15498         (cmdline_parse_inst_t *)&cmd_set_link_check,
15499         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15500         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15501         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15502         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15503 #ifdef RTE_LIBRTE_PMD_BOND
15504         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15505         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15506         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15507         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15508         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15509         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15510         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15511         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15512         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15513         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15514         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15515 #endif
15516         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15517         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15518         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15519         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15520         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15521         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15522         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15523         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15524         (cmdline_parse_inst_t *)&cmd_csum_set,
15525         (cmdline_parse_inst_t *)&cmd_csum_show,
15526         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15527         (cmdline_parse_inst_t *)&cmd_tso_set,
15528         (cmdline_parse_inst_t *)&cmd_tso_show,
15529         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15530         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15531         (cmdline_parse_inst_t *)&cmd_gro_enable,
15532         (cmdline_parse_inst_t *)&cmd_gro_flush,
15533         (cmdline_parse_inst_t *)&cmd_gro_show,
15534         (cmdline_parse_inst_t *)&cmd_gso_enable,
15535         (cmdline_parse_inst_t *)&cmd_gso_size,
15536         (cmdline_parse_inst_t *)&cmd_gso_show,
15537         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15538         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15539         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15540         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15541         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15542         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15543         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15544         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15545         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15546         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15547         (cmdline_parse_inst_t *)&cmd_config_dcb,
15548         (cmdline_parse_inst_t *)&cmd_read_reg,
15549         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15550         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15551         (cmdline_parse_inst_t *)&cmd_write_reg,
15552         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15553         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15554         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15555         (cmdline_parse_inst_t *)&cmd_stop,
15556         (cmdline_parse_inst_t *)&cmd_mac_addr,
15557         (cmdline_parse_inst_t *)&cmd_set_qmap,
15558         (cmdline_parse_inst_t *)&cmd_operate_port,
15559         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15560         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15561         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15562         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15563         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15564         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15565         (cmdline_parse_inst_t *)&cmd_config_mtu,
15566         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15567         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15568         (cmdline_parse_inst_t *)&cmd_config_rss,
15569         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15570         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15571         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15572         (cmdline_parse_inst_t *)&cmd_showport_reta,
15573         (cmdline_parse_inst_t *)&cmd_config_burst,
15574         (cmdline_parse_inst_t *)&cmd_config_thresh,
15575         (cmdline_parse_inst_t *)&cmd_config_threshold,
15576         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15577         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15578         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15579         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15580         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15581         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15582         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15583         (cmdline_parse_inst_t *)&cmd_global_config,
15584         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15585         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15586         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15587         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15588         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15589         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15590         (cmdline_parse_inst_t *)&cmd_dump,
15591         (cmdline_parse_inst_t *)&cmd_dump_one,
15592         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15593         (cmdline_parse_inst_t *)&cmd_syn_filter,
15594         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15595         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15596         (cmdline_parse_inst_t *)&cmd_flex_filter,
15597         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15598         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15599         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15600         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15601         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15602         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15603         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15604         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15605         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15606         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15607         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15608         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15609         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15610         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15611         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15612         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15613         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15614         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15615         (cmdline_parse_inst_t *)&cmd_flow,
15616         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15617         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15618         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15619         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15620         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15621         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15622         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15623         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15624         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15625         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15626         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15627         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15628         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15629         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15630         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15631         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15632         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15633         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15634         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15635         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15636         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15637         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15638         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15639         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15640         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15641         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15642         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15643         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15644         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15645         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15646         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15647         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15648         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15649         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15650         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15651         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15652         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15653         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15654         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15655         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15656         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15657         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15658         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15659         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15660         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15661 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15662         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15663 #endif
15664         (cmdline_parse_inst_t *)&cmd_ddp_add,
15665         (cmdline_parse_inst_t *)&cmd_ddp_del,
15666         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15667         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15668         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15669         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15670         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15671         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15672         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15673         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15674
15675         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15676         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15677         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15678         (cmdline_parse_inst_t *)&cmd_queue_region,
15679         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15680         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15681         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15682         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15683         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15684         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15685         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15686         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15687         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15688         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15689         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15690         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15691         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15692         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15693         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15694         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15695         NULL,
15696 };
15697
15698 /* read cmdline commands from file */
15699 void
15700 cmdline_read_from_file(const char *filename)
15701 {
15702         struct cmdline *cl;
15703
15704         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15705         if (cl == NULL) {
15706                 printf("Failed to create file based cmdline context: %s\n",
15707                        filename);
15708                 return;
15709         }
15710
15711         cmdline_interact(cl);
15712         cmdline_quit(cl);
15713
15714         cmdline_free(cl);
15715
15716         printf("Read CLI commands from %s\n", filename);
15717 }
15718
15719 /* prompt function, called from main on MASTER lcore */
15720 void
15721 prompt(void)
15722 {
15723         /* initialize non-constant commands */
15724         cmd_set_fwd_mode_init();
15725         cmd_set_fwd_retry_mode_init();
15726
15727         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15728         if (testpmd_cl == NULL)
15729                 return;
15730         cmdline_interact(testpmd_cl);
15731         cmdline_stdin_exit(testpmd_cl);
15732 }
15733
15734 void
15735 prompt_exit(void)
15736 {
15737         if (testpmd_cl != NULL)
15738                 cmdline_quit(testpmd_cl);
15739 }
15740
15741 static void
15742 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15743 {
15744         if (id == (portid_t)RTE_PORT_ALL) {
15745                 portid_t pid;
15746
15747                 RTE_ETH_FOREACH_DEV(pid) {
15748                         /* check if need_reconfig has been set to 1 */
15749                         if (ports[pid].need_reconfig == 0)
15750                                 ports[pid].need_reconfig = dev;
15751                         /* check if need_reconfig_queues has been set to 1 */
15752                         if (ports[pid].need_reconfig_queues == 0)
15753                                 ports[pid].need_reconfig_queues = queue;
15754                 }
15755         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15756                 /* check if need_reconfig has been set to 1 */
15757                 if (ports[id].need_reconfig == 0)
15758                         ports[id].need_reconfig = dev;
15759                 /* check if need_reconfig_queues has been set to 1 */
15760                 if (ports[id].need_reconfig_queues == 0)
15761                         ports[id].need_reconfig_queues = queue;
15762         }
15763 }