app/testpmd: add commands for TM capability and stats
[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                         , list_pkt_forwarding_modes()
728                 );
729         }
730
731         if (show_all || !strcmp(res->section, "ports")) {
732
733                 cmdline_printf(
734                         cl,
735                         "\n"
736                         "Port Operations:\n"
737                         "----------------\n\n"
738
739                         "port start (port_id|all)\n"
740                         "    Start all ports or port_id.\n\n"
741
742                         "port stop (port_id|all)\n"
743                         "    Stop all ports or port_id.\n\n"
744
745                         "port close (port_id|all)\n"
746                         "    Close all ports or port_id.\n\n"
747
748                         "port attach (ident)\n"
749                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
750
751                         "port detach (port_id)\n"
752                         "    Detach physical or virtual dev by port_id\n\n"
753
754                         "port config (port_id|all)"
755                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
756                         " duplex (half|full|auto)\n"
757                         "    Set speed and duplex for all ports or port_id\n\n"
758
759                         "port config all (rxq|txq|rxd|txd) (value)\n"
760                         "    Set number for rxq/txq/rxd/txd.\n\n"
761
762                         "port config all max-pkt-len (value)\n"
763                         "    Set the max packet length.\n\n"
764
765                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
766                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
767                         " (on|off)\n"
768                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
769                         " for ports.\n\n"
770
771                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
772                         "geneve|nvgre|none|<flowtype_id>)\n"
773                         "    Set the RSS mode.\n\n"
774
775                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
776                         "    Set the RSS redirection table.\n\n"
777
778                         "port config (port_id) dcb vt (on|off) (traffic_class)"
779                         " pfc (on|off)\n"
780                         "    Set the DCB mode.\n\n"
781
782                         "port config all burst (value)\n"
783                         "    Set the number of packets per burst.\n\n"
784
785                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
786                         " (value)\n"
787                         "    Set the ring prefetch/host/writeback threshold"
788                         " for tx/rx queue.\n\n"
789
790                         "port config all (txfreet|txrst|rxfreet) (value)\n"
791                         "    Set free threshold for rx/tx, or set"
792                         " tx rs bit threshold.\n\n"
793                         "port config mtu X value\n"
794                         "    Set the MTU of port X to a given value\n\n"
795
796                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
797                         "    Start/stop a rx/tx queue of port X. Only take effect"
798                         " when port X is started\n\n"
799
800                         "port config (port_id|all) l2-tunnel E-tag ether-type"
801                         " (value)\n"
802                         "    Set the value of E-tag ether-type.\n\n"
803
804                         "port config (port_id|all) l2-tunnel E-tag"
805                         " (enable|disable)\n"
806                         "    Enable/disable the E-tag support.\n\n"
807
808                         "port config (port_id) pctype mapping reset\n"
809                         "    Reset flow type to pctype mapping on a port\n\n"
810
811                         "port config (port_id) pctype mapping update"
812                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
813                         "    Update a flow type to pctype mapping item on a port\n\n"
814                 );
815         }
816
817         if (show_all || !strcmp(res->section, "registers")) {
818
819                 cmdline_printf(
820                         cl,
821                         "\n"
822                         "Registers:\n"
823                         "----------\n\n"
824
825                         "read reg (port_id) (address)\n"
826                         "    Display value of a port register.\n\n"
827
828                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
829                         "    Display a port register bit field.\n\n"
830
831                         "read regbit (port_id) (address) (bit_x)\n"
832                         "    Display a single port register bit.\n\n"
833
834                         "write reg (port_id) (address) (value)\n"
835                         "    Set value of a port register.\n\n"
836
837                         "write regfield (port_id) (address) (bit_x) (bit_y)"
838                         " (value)\n"
839                         "    Set bit field of a port register.\n\n"
840
841                         "write regbit (port_id) (address) (bit_x) (value)\n"
842                         "    Set single bit value of a port register.\n\n"
843                 );
844         }
845         if (show_all || !strcmp(res->section, "filters")) {
846
847                 cmdline_printf(
848                         cl,
849                         "\n"
850                         "filters:\n"
851                         "--------\n\n"
852
853                         "ethertype_filter (port_id) (add|del)"
854                         " (mac_addr|mac_ignr) (mac_address) ethertype"
855                         " (ether_type) (drop|fwd) queue (queue_id)\n"
856                         "    Add/Del an ethertype filter.\n\n"
857
858                         "2tuple_filter (port_id) (add|del)"
859                         " dst_port (dst_port_value) protocol (protocol_value)"
860                         " mask (mask_value) tcp_flags (tcp_flags_value)"
861                         " priority (prio_value) queue (queue_id)\n"
862                         "    Add/Del a 2tuple filter.\n\n"
863
864                         "5tuple_filter (port_id) (add|del)"
865                         " dst_ip (dst_address) src_ip (src_address)"
866                         " dst_port (dst_port_value) src_port (src_port_value)"
867                         " protocol (protocol_value)"
868                         " mask (mask_value) tcp_flags (tcp_flags_value)"
869                         " priority (prio_value) queue (queue_id)\n"
870                         "    Add/Del a 5tuple filter.\n\n"
871
872                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
873                         "    Add/Del syn filter.\n\n"
874
875                         "flex_filter (port_id) (add|del) len (len_value)"
876                         " bytes (bytes_value) mask (mask_value)"
877                         " priority (prio_value) queue (queue_id)\n"
878                         "    Add/Del a flex filter.\n\n"
879
880                         "flow_director_filter (port_id) mode IP (add|del|update)"
881                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
882                         " src (src_ip_address) dst (dst_ip_address)"
883                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
884                         " vlan (vlan_value) flexbytes (flexbytes_value)"
885                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
886                         " fd_id (fd_id_value)\n"
887                         "    Add/Del an IP type flow director filter.\n\n"
888
889                         "flow_director_filter (port_id) mode IP (add|del|update)"
890                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
891                         " src (src_ip_address) (src_port)"
892                         " dst (dst_ip_address) (dst_port)"
893                         " tos (tos_value) ttl (ttl_value)"
894                         " vlan (vlan_value) flexbytes (flexbytes_value)"
895                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
896                         " fd_id (fd_id_value)\n"
897                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
898
899                         "flow_director_filter (port_id) mode IP (add|del|update)"
900                         " flow (ipv4-sctp|ipv6-sctp)"
901                         " src (src_ip_address) (src_port)"
902                         " dst (dst_ip_address) (dst_port)"
903                         " tag (verification_tag) "
904                         " tos (tos_value) ttl (ttl_value)"
905                         " vlan (vlan_value)"
906                         " flexbytes (flexbytes_value) (drop|fwd)"
907                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
908                         "    Add/Del a SCTP type flow director filter.\n\n"
909
910                         "flow_director_filter (port_id) mode IP (add|del|update)"
911                         " flow l2_payload ether (ethertype)"
912                         " flexbytes (flexbytes_value) (drop|fwd)"
913                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
914                         "    Add/Del a l2 payload type flow director filter.\n\n"
915
916                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
917                         " mac (mac_address) vlan (vlan_value)"
918                         " flexbytes (flexbytes_value) (drop|fwd)"
919                         " queue (queue_id) fd_id (fd_id_value)\n"
920                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
921
922                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
923                         " mac (mac_address) vlan (vlan_value)"
924                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
925                         " flexbytes (flexbytes_value) (drop|fwd)"
926                         " queue (queue_id) fd_id (fd_id_value)\n"
927                         "    Add/Del a Tunnel flow director filter.\n\n"
928
929                         "flush_flow_director (port_id)\n"
930                         "    Flush all flow director entries of a device.\n\n"
931
932                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
933                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
934                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
935                         "    Set flow director IP mask.\n\n"
936
937                         "flow_director_mask (port_id) mode MAC-VLAN"
938                         " vlan (vlan_value)\n"
939                         "    Set flow director MAC-VLAN mask.\n\n"
940
941                         "flow_director_mask (port_id) mode Tunnel"
942                         " vlan (vlan_value) mac (mac_value)"
943                         " tunnel-type (tunnel_type_value)"
944                         " tunnel-id (tunnel_id_value)\n"
945                         "    Set flow director Tunnel mask.\n\n"
946
947                         "flow_director_flex_mask (port_id)"
948                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
949                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
950                         " (mask)\n"
951                         "    Configure mask of flex payload.\n\n"
952
953                         "flow_director_flex_payload (port_id)"
954                         " (raw|l2|l3|l4) (config)\n"
955                         "    Configure flex payload selection.\n\n"
956
957                         "get_sym_hash_ena_per_port (port_id)\n"
958                         "    get symmetric hash enable configuration per port.\n\n"
959
960                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
961                         "    set symmetric hash enable configuration per port"
962                         " to enable or disable.\n\n"
963
964                         "get_hash_global_config (port_id)\n"
965                         "    Get the global configurations of hash filters.\n\n"
966
967                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
968                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
969                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
970                         " (enable|disable)\n"
971                         "    Set the global configurations of hash filters.\n\n"
972
973                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
974                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
975                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
976                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
977                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
978                         "ipv6-next-header|udp-src-port|udp-dst-port|"
979                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
980                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
981                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
982                         "fld-8th|none) (select|add)\n"
983                         "    Set the input set for hash.\n\n"
984
985                         "set_fdir_input_set (port_id) "
986                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
987                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
988                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
989                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
990                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
991                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
992                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
993                         " (select|add)\n"
994                         "    Set the input set for FDir.\n\n"
995
996                         "flow validate {port_id}"
997                         " [group {group_id}] [priority {level}]"
998                         " [ingress] [egress]"
999                         " pattern {item} [/ {item} [...]] / end"
1000                         " actions {action} [/ {action} [...]] / end\n"
1001                         "    Check whether a flow rule can be created.\n\n"
1002
1003                         "flow create {port_id}"
1004                         " [group {group_id}] [priority {level}]"
1005                         " [ingress] [egress]"
1006                         " pattern {item} [/ {item} [...]] / end"
1007                         " actions {action} [/ {action} [...]] / end\n"
1008                         "    Create a flow rule.\n\n"
1009
1010                         "flow destroy {port_id} rule {rule_id} [...]\n"
1011                         "    Destroy specific flow rules.\n\n"
1012
1013                         "flow flush {port_id}\n"
1014                         "    Destroy all flow rules.\n\n"
1015
1016                         "flow query {port_id} {rule_id} {action}\n"
1017                         "    Query an existing flow rule.\n\n"
1018
1019                         "flow list {port_id} [group {group_id}] [...]\n"
1020                         "    List existing flow rules sorted by priority,"
1021                         " filtered by group identifiers.\n\n"
1022
1023                         "flow isolate {port_id} {boolean}\n"
1024                         "    Restrict ingress traffic to the defined"
1025                         " flow rules\n\n"
1026                 );
1027         }
1028 }
1029
1030 cmdline_parse_token_string_t cmd_help_long_help =
1031         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1032
1033 cmdline_parse_token_string_t cmd_help_long_section =
1034         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1035                         "all#control#display#config#"
1036                         "ports#registers#filters");
1037
1038 cmdline_parse_inst_t cmd_help_long = {
1039         .f = cmd_help_long_parsed,
1040         .data = NULL,
1041         .help_str = "help all|control|display|config|ports|register|filters: "
1042                 "Show help",
1043         .tokens = {
1044                 (void *)&cmd_help_long_help,
1045                 (void *)&cmd_help_long_section,
1046                 NULL,
1047         },
1048 };
1049
1050
1051 /* *** start/stop/close all ports *** */
1052 struct cmd_operate_port_result {
1053         cmdline_fixed_string_t keyword;
1054         cmdline_fixed_string_t name;
1055         cmdline_fixed_string_t value;
1056 };
1057
1058 static void cmd_operate_port_parsed(void *parsed_result,
1059                                 __attribute__((unused)) struct cmdline *cl,
1060                                 __attribute__((unused)) void *data)
1061 {
1062         struct cmd_operate_port_result *res = parsed_result;
1063
1064         if (!strcmp(res->name, "start"))
1065                 start_port(RTE_PORT_ALL);
1066         else if (!strcmp(res->name, "stop"))
1067                 stop_port(RTE_PORT_ALL);
1068         else if (!strcmp(res->name, "close"))
1069                 close_port(RTE_PORT_ALL);
1070         else if (!strcmp(res->name, "reset"))
1071                 reset_port(RTE_PORT_ALL);
1072         else
1073                 printf("Unknown parameter\n");
1074 }
1075
1076 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1077         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1078                                                                 "port");
1079 cmdline_parse_token_string_t cmd_operate_port_all_port =
1080         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1081                                                 "start#stop#close#reset");
1082 cmdline_parse_token_string_t cmd_operate_port_all_all =
1083         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1084
1085 cmdline_parse_inst_t cmd_operate_port = {
1086         .f = cmd_operate_port_parsed,
1087         .data = NULL,
1088         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1089         .tokens = {
1090                 (void *)&cmd_operate_port_all_cmd,
1091                 (void *)&cmd_operate_port_all_port,
1092                 (void *)&cmd_operate_port_all_all,
1093                 NULL,
1094         },
1095 };
1096
1097 /* *** start/stop/close specific port *** */
1098 struct cmd_operate_specific_port_result {
1099         cmdline_fixed_string_t keyword;
1100         cmdline_fixed_string_t name;
1101         uint8_t value;
1102 };
1103
1104 static void cmd_operate_specific_port_parsed(void *parsed_result,
1105                         __attribute__((unused)) struct cmdline *cl,
1106                                 __attribute__((unused)) void *data)
1107 {
1108         struct cmd_operate_specific_port_result *res = parsed_result;
1109
1110         if (!strcmp(res->name, "start"))
1111                 start_port(res->value);
1112         else if (!strcmp(res->name, "stop"))
1113                 stop_port(res->value);
1114         else if (!strcmp(res->name, "close"))
1115                 close_port(res->value);
1116         else if (!strcmp(res->name, "reset"))
1117                 reset_port(res->value);
1118         else
1119                 printf("Unknown parameter\n");
1120 }
1121
1122 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1123         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1124                                                         keyword, "port");
1125 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1126         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1127                                                 name, "start#stop#close#reset");
1128 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1129         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1130                                                         value, UINT8);
1131
1132 cmdline_parse_inst_t cmd_operate_specific_port = {
1133         .f = cmd_operate_specific_port_parsed,
1134         .data = NULL,
1135         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1136         .tokens = {
1137                 (void *)&cmd_operate_specific_port_cmd,
1138                 (void *)&cmd_operate_specific_port_port,
1139                 (void *)&cmd_operate_specific_port_id,
1140                 NULL,
1141         },
1142 };
1143
1144 /* *** attach a specified port *** */
1145 struct cmd_operate_attach_port_result {
1146         cmdline_fixed_string_t port;
1147         cmdline_fixed_string_t keyword;
1148         cmdline_fixed_string_t identifier;
1149 };
1150
1151 static void cmd_operate_attach_port_parsed(void *parsed_result,
1152                                 __attribute__((unused)) struct cmdline *cl,
1153                                 __attribute__((unused)) void *data)
1154 {
1155         struct cmd_operate_attach_port_result *res = parsed_result;
1156
1157         if (!strcmp(res->keyword, "attach"))
1158                 attach_port(res->identifier);
1159         else
1160                 printf("Unknown parameter\n");
1161 }
1162
1163 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1164         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1165                         port, "port");
1166 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1167         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1168                         keyword, "attach");
1169 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1170         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1171                         identifier, NULL);
1172
1173 cmdline_parse_inst_t cmd_operate_attach_port = {
1174         .f = cmd_operate_attach_port_parsed,
1175         .data = NULL,
1176         .help_str = "port attach <identifier>: "
1177                 "(identifier: pci address or virtual dev name)",
1178         .tokens = {
1179                 (void *)&cmd_operate_attach_port_port,
1180                 (void *)&cmd_operate_attach_port_keyword,
1181                 (void *)&cmd_operate_attach_port_identifier,
1182                 NULL,
1183         },
1184 };
1185
1186 /* *** detach a specified port *** */
1187 struct cmd_operate_detach_port_result {
1188         cmdline_fixed_string_t port;
1189         cmdline_fixed_string_t keyword;
1190         portid_t port_id;
1191 };
1192
1193 static void cmd_operate_detach_port_parsed(void *parsed_result,
1194                                 __attribute__((unused)) struct cmdline *cl,
1195                                 __attribute__((unused)) void *data)
1196 {
1197         struct cmd_operate_detach_port_result *res = parsed_result;
1198
1199         if (!strcmp(res->keyword, "detach"))
1200                 detach_port(res->port_id);
1201         else
1202                 printf("Unknown parameter\n");
1203 }
1204
1205 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1206         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1207                         port, "port");
1208 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1209         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1210                         keyword, "detach");
1211 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1212         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1213                         port_id, UINT16);
1214
1215 cmdline_parse_inst_t cmd_operate_detach_port = {
1216         .f = cmd_operate_detach_port_parsed,
1217         .data = NULL,
1218         .help_str = "port detach <port_id>",
1219         .tokens = {
1220                 (void *)&cmd_operate_detach_port_port,
1221                 (void *)&cmd_operate_detach_port_keyword,
1222                 (void *)&cmd_operate_detach_port_port_id,
1223                 NULL,
1224         },
1225 };
1226
1227 /* *** configure speed for all ports *** */
1228 struct cmd_config_speed_all {
1229         cmdline_fixed_string_t port;
1230         cmdline_fixed_string_t keyword;
1231         cmdline_fixed_string_t all;
1232         cmdline_fixed_string_t item1;
1233         cmdline_fixed_string_t item2;
1234         cmdline_fixed_string_t value1;
1235         cmdline_fixed_string_t value2;
1236 };
1237
1238 static int
1239 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1240 {
1241
1242         int duplex;
1243
1244         if (!strcmp(duplexstr, "half")) {
1245                 duplex = ETH_LINK_HALF_DUPLEX;
1246         } else if (!strcmp(duplexstr, "full")) {
1247                 duplex = ETH_LINK_FULL_DUPLEX;
1248         } else if (!strcmp(duplexstr, "auto")) {
1249                 duplex = ETH_LINK_FULL_DUPLEX;
1250         } else {
1251                 printf("Unknown duplex parameter\n");
1252                 return -1;
1253         }
1254
1255         if (!strcmp(speedstr, "10")) {
1256                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1257                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1258         } else if (!strcmp(speedstr, "100")) {
1259                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1260                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1261         } else {
1262                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1263                         printf("Invalid speed/duplex parameters\n");
1264                         return -1;
1265                 }
1266                 if (!strcmp(speedstr, "1000")) {
1267                         *speed = ETH_LINK_SPEED_1G;
1268                 } else if (!strcmp(speedstr, "10000")) {
1269                         *speed = ETH_LINK_SPEED_10G;
1270                 } else if (!strcmp(speedstr, "25000")) {
1271                         *speed = ETH_LINK_SPEED_25G;
1272                 } else if (!strcmp(speedstr, "40000")) {
1273                         *speed = ETH_LINK_SPEED_40G;
1274                 } else if (!strcmp(speedstr, "50000")) {
1275                         *speed = ETH_LINK_SPEED_50G;
1276                 } else if (!strcmp(speedstr, "100000")) {
1277                         *speed = ETH_LINK_SPEED_100G;
1278                 } else if (!strcmp(speedstr, "auto")) {
1279                         *speed = ETH_LINK_SPEED_AUTONEG;
1280                 } else {
1281                         printf("Unknown speed parameter\n");
1282                         return -1;
1283                 }
1284         }
1285
1286         return 0;
1287 }
1288
1289 static void
1290 cmd_config_speed_all_parsed(void *parsed_result,
1291                         __attribute__((unused)) struct cmdline *cl,
1292                         __attribute__((unused)) void *data)
1293 {
1294         struct cmd_config_speed_all *res = parsed_result;
1295         uint32_t link_speed;
1296         portid_t pid;
1297
1298         if (!all_ports_stopped()) {
1299                 printf("Please stop all ports first\n");
1300                 return;
1301         }
1302
1303         if (parse_and_check_speed_duplex(res->value1, res->value2,
1304                         &link_speed) < 0)
1305                 return;
1306
1307         RTE_ETH_FOREACH_DEV(pid) {
1308                 ports[pid].dev_conf.link_speeds = link_speed;
1309         }
1310
1311         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1312 }
1313
1314 cmdline_parse_token_string_t cmd_config_speed_all_port =
1315         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1316 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1317         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1318                                                         "config");
1319 cmdline_parse_token_string_t cmd_config_speed_all_all =
1320         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1321 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1322         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1323 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1324         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1325                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1326 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1327         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1328 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1329         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1330                                                 "half#full#auto");
1331
1332 cmdline_parse_inst_t cmd_config_speed_all = {
1333         .f = cmd_config_speed_all_parsed,
1334         .data = NULL,
1335         .help_str = "port config all speed "
1336                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1337                                                         "half|full|auto",
1338         .tokens = {
1339                 (void *)&cmd_config_speed_all_port,
1340                 (void *)&cmd_config_speed_all_keyword,
1341                 (void *)&cmd_config_speed_all_all,
1342                 (void *)&cmd_config_speed_all_item1,
1343                 (void *)&cmd_config_speed_all_value1,
1344                 (void *)&cmd_config_speed_all_item2,
1345                 (void *)&cmd_config_speed_all_value2,
1346                 NULL,
1347         },
1348 };
1349
1350 /* *** configure speed for specific port *** */
1351 struct cmd_config_speed_specific {
1352         cmdline_fixed_string_t port;
1353         cmdline_fixed_string_t keyword;
1354         uint8_t id;
1355         cmdline_fixed_string_t item1;
1356         cmdline_fixed_string_t item2;
1357         cmdline_fixed_string_t value1;
1358         cmdline_fixed_string_t value2;
1359 };
1360
1361 static void
1362 cmd_config_speed_specific_parsed(void *parsed_result,
1363                                 __attribute__((unused)) struct cmdline *cl,
1364                                 __attribute__((unused)) void *data)
1365 {
1366         struct cmd_config_speed_specific *res = parsed_result;
1367         uint32_t link_speed;
1368
1369         if (!all_ports_stopped()) {
1370                 printf("Please stop all ports first\n");
1371                 return;
1372         }
1373
1374         if (port_id_is_invalid(res->id, ENABLED_WARN))
1375                 return;
1376
1377         if (parse_and_check_speed_duplex(res->value1, res->value2,
1378                         &link_speed) < 0)
1379                 return;
1380
1381         ports[res->id].dev_conf.link_speeds = link_speed;
1382
1383         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1384 }
1385
1386
1387 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1388         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1389                                                                 "port");
1390 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1391         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1392                                                                 "config");
1393 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1394         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1395 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1397                                                                 "speed");
1398 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1400                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1401 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1403                                                                 "duplex");
1404 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1406                                                         "half#full#auto");
1407
1408 cmdline_parse_inst_t cmd_config_speed_specific = {
1409         .f = cmd_config_speed_specific_parsed,
1410         .data = NULL,
1411         .help_str = "port config <port_id> speed "
1412                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1413                                                         "half|full|auto",
1414         .tokens = {
1415                 (void *)&cmd_config_speed_specific_port,
1416                 (void *)&cmd_config_speed_specific_keyword,
1417                 (void *)&cmd_config_speed_specific_id,
1418                 (void *)&cmd_config_speed_specific_item1,
1419                 (void *)&cmd_config_speed_specific_value1,
1420                 (void *)&cmd_config_speed_specific_item2,
1421                 (void *)&cmd_config_speed_specific_value2,
1422                 NULL,
1423         },
1424 };
1425
1426 /* *** configure txq/rxq, txd/rxd *** */
1427 struct cmd_config_rx_tx {
1428         cmdline_fixed_string_t port;
1429         cmdline_fixed_string_t keyword;
1430         cmdline_fixed_string_t all;
1431         cmdline_fixed_string_t name;
1432         uint16_t value;
1433 };
1434
1435 static void
1436 cmd_config_rx_tx_parsed(void *parsed_result,
1437                         __attribute__((unused)) struct cmdline *cl,
1438                         __attribute__((unused)) void *data)
1439 {
1440         struct cmd_config_rx_tx *res = parsed_result;
1441
1442         if (!all_ports_stopped()) {
1443                 printf("Please stop all ports first\n");
1444                 return;
1445         }
1446         if (!strcmp(res->name, "rxq")) {
1447                 if (!res->value && !nb_txq) {
1448                         printf("Warning: Either rx or tx queues should be non zero\n");
1449                         return;
1450                 }
1451                 nb_rxq = res->value;
1452         }
1453         else if (!strcmp(res->name, "txq")) {
1454                 if (!res->value && !nb_rxq) {
1455                         printf("Warning: Either rx or tx queues should be non zero\n");
1456                         return;
1457                 }
1458                 nb_txq = res->value;
1459         }
1460         else if (!strcmp(res->name, "rxd")) {
1461                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1462                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1463                                         res->value, RTE_TEST_RX_DESC_MAX);
1464                         return;
1465                 }
1466                 nb_rxd = res->value;
1467         } else if (!strcmp(res->name, "txd")) {
1468                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1469                         printf("txd %d invalid - must be > 0 && <= %d\n",
1470                                         res->value, RTE_TEST_TX_DESC_MAX);
1471                         return;
1472                 }
1473                 nb_txd = res->value;
1474         } else {
1475                 printf("Unknown parameter\n");
1476                 return;
1477         }
1478
1479         fwd_config_setup();
1480
1481         init_port_config();
1482
1483         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1484 }
1485
1486 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1488 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1490 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1491         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1492 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1493         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1494                                                 "rxq#txq#rxd#txd");
1495 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1496         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1497
1498 cmdline_parse_inst_t cmd_config_rx_tx = {
1499         .f = cmd_config_rx_tx_parsed,
1500         .data = NULL,
1501         .help_str = "port config all rxq|txq|rxd|txd <value>",
1502         .tokens = {
1503                 (void *)&cmd_config_rx_tx_port,
1504                 (void *)&cmd_config_rx_tx_keyword,
1505                 (void *)&cmd_config_rx_tx_all,
1506                 (void *)&cmd_config_rx_tx_name,
1507                 (void *)&cmd_config_rx_tx_value,
1508                 NULL,
1509         },
1510 };
1511
1512 /* *** config max packet length *** */
1513 struct cmd_config_max_pkt_len_result {
1514         cmdline_fixed_string_t port;
1515         cmdline_fixed_string_t keyword;
1516         cmdline_fixed_string_t all;
1517         cmdline_fixed_string_t name;
1518         uint32_t value;
1519 };
1520
1521 static void
1522 cmd_config_max_pkt_len_parsed(void *parsed_result,
1523                                 __attribute__((unused)) struct cmdline *cl,
1524                                 __attribute__((unused)) void *data)
1525 {
1526         struct cmd_config_max_pkt_len_result *res = parsed_result;
1527
1528         if (!all_ports_stopped()) {
1529                 printf("Please stop all ports first\n");
1530                 return;
1531         }
1532
1533         if (!strcmp(res->name, "max-pkt-len")) {
1534                 if (res->value < ETHER_MIN_LEN) {
1535                         printf("max-pkt-len can not be less than %d\n",
1536                                                         ETHER_MIN_LEN);
1537                         return;
1538                 }
1539                 if (res->value == rx_mode.max_rx_pkt_len)
1540                         return;
1541
1542                 rx_mode.max_rx_pkt_len = res->value;
1543                 if (res->value > ETHER_MAX_LEN)
1544                         rx_mode.jumbo_frame = 1;
1545                 else
1546                         rx_mode.jumbo_frame = 0;
1547         } else {
1548                 printf("Unknown parameter\n");
1549                 return;
1550         }
1551
1552         init_port_config();
1553
1554         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1555 }
1556
1557 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1558         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1559                                                                 "port");
1560 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1562                                                                 "config");
1563 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1565                                                                 "all");
1566 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1568                                                                 "max-pkt-len");
1569 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1570         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1571                                                                 UINT32);
1572
1573 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1574         .f = cmd_config_max_pkt_len_parsed,
1575         .data = NULL,
1576         .help_str = "port config all max-pkt-len <value>",
1577         .tokens = {
1578                 (void *)&cmd_config_max_pkt_len_port,
1579                 (void *)&cmd_config_max_pkt_len_keyword,
1580                 (void *)&cmd_config_max_pkt_len_all,
1581                 (void *)&cmd_config_max_pkt_len_name,
1582                 (void *)&cmd_config_max_pkt_len_value,
1583                 NULL,
1584         },
1585 };
1586
1587 /* *** configure port MTU *** */
1588 struct cmd_config_mtu_result {
1589         cmdline_fixed_string_t port;
1590         cmdline_fixed_string_t keyword;
1591         cmdline_fixed_string_t mtu;
1592         portid_t port_id;
1593         uint16_t value;
1594 };
1595
1596 static void
1597 cmd_config_mtu_parsed(void *parsed_result,
1598                       __attribute__((unused)) struct cmdline *cl,
1599                       __attribute__((unused)) void *data)
1600 {
1601         struct cmd_config_mtu_result *res = parsed_result;
1602
1603         if (res->value < ETHER_MIN_LEN) {
1604                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1605                 return;
1606         }
1607         port_mtu_set(res->port_id, res->value);
1608 }
1609
1610 cmdline_parse_token_string_t cmd_config_mtu_port =
1611         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1612                                  "port");
1613 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1614         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1615                                  "config");
1616 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1617         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1618                                  "mtu");
1619 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1620         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1621 cmdline_parse_token_num_t cmd_config_mtu_value =
1622         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1623
1624 cmdline_parse_inst_t cmd_config_mtu = {
1625         .f = cmd_config_mtu_parsed,
1626         .data = NULL,
1627         .help_str = "port config mtu <port_id> <value>",
1628         .tokens = {
1629                 (void *)&cmd_config_mtu_port,
1630                 (void *)&cmd_config_mtu_keyword,
1631                 (void *)&cmd_config_mtu_mtu,
1632                 (void *)&cmd_config_mtu_port_id,
1633                 (void *)&cmd_config_mtu_value,
1634                 NULL,
1635         },
1636 };
1637
1638 /* *** configure rx mode *** */
1639 struct cmd_config_rx_mode_flag {
1640         cmdline_fixed_string_t port;
1641         cmdline_fixed_string_t keyword;
1642         cmdline_fixed_string_t all;
1643         cmdline_fixed_string_t name;
1644         cmdline_fixed_string_t value;
1645 };
1646
1647 static void
1648 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1649                                 __attribute__((unused)) struct cmdline *cl,
1650                                 __attribute__((unused)) void *data)
1651 {
1652         struct cmd_config_rx_mode_flag *res = parsed_result;
1653
1654         if (!all_ports_stopped()) {
1655                 printf("Please stop all ports first\n");
1656                 return;
1657         }
1658
1659         if (!strcmp(res->name, "crc-strip")) {
1660                 if (!strcmp(res->value, "on"))
1661                         rx_mode.hw_strip_crc = 1;
1662                 else if (!strcmp(res->value, "off"))
1663                         rx_mode.hw_strip_crc = 0;
1664                 else {
1665                         printf("Unknown parameter\n");
1666                         return;
1667                 }
1668         } else if (!strcmp(res->name, "scatter")) {
1669                 if (!strcmp(res->value, "on"))
1670                         rx_mode.enable_scatter = 1;
1671                 else if (!strcmp(res->value, "off"))
1672                         rx_mode.enable_scatter = 0;
1673                 else {
1674                         printf("Unknown parameter\n");
1675                         return;
1676                 }
1677         } else if (!strcmp(res->name, "rx-cksum")) {
1678                 if (!strcmp(res->value, "on"))
1679                         rx_mode.hw_ip_checksum = 1;
1680                 else if (!strcmp(res->value, "off"))
1681                         rx_mode.hw_ip_checksum = 0;
1682                 else {
1683                         printf("Unknown parameter\n");
1684                         return;
1685                 }
1686         } else if (!strcmp(res->name, "rx-timestamp")) {
1687                 if (!strcmp(res->value, "on"))
1688                         rx_mode.hw_timestamp = 1;
1689                 else if (!strcmp(res->value, "off"))
1690                         rx_mode.hw_timestamp = 0;
1691                 else {
1692                         printf("Unknown parameter\n");
1693                         return;
1694                 }
1695         } else if (!strcmp(res->name, "hw-vlan")) {
1696                 if (!strcmp(res->value, "on")) {
1697                         rx_mode.hw_vlan_filter = 1;
1698                         rx_mode.hw_vlan_strip  = 1;
1699                 }
1700                 else if (!strcmp(res->value, "off")) {
1701                         rx_mode.hw_vlan_filter = 0;
1702                         rx_mode.hw_vlan_strip  = 0;
1703                 }
1704                 else {
1705                         printf("Unknown parameter\n");
1706                         return;
1707                 }
1708         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1709                 if (!strcmp(res->value, "on"))
1710                         rx_mode.hw_vlan_filter = 1;
1711                 else if (!strcmp(res->value, "off"))
1712                         rx_mode.hw_vlan_filter = 0;
1713                 else {
1714                         printf("Unknown parameter\n");
1715                         return;
1716                 }
1717         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1718                 if (!strcmp(res->value, "on"))
1719                         rx_mode.hw_vlan_strip  = 1;
1720                 else if (!strcmp(res->value, "off"))
1721                         rx_mode.hw_vlan_strip  = 0;
1722                 else {
1723                         printf("Unknown parameter\n");
1724                         return;
1725                 }
1726         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1727                 if (!strcmp(res->value, "on"))
1728                         rx_mode.hw_vlan_extend = 1;
1729                 else if (!strcmp(res->value, "off"))
1730                         rx_mode.hw_vlan_extend = 0;
1731                 else {
1732                         printf("Unknown parameter\n");
1733                         return;
1734                 }
1735         } else if (!strcmp(res->name, "drop-en")) {
1736                 if (!strcmp(res->value, "on"))
1737                         rx_drop_en = 1;
1738                 else if (!strcmp(res->value, "off"))
1739                         rx_drop_en = 0;
1740                 else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         } else {
1745                 printf("Unknown parameter\n");
1746                 return;
1747         }
1748
1749         init_port_config();
1750
1751         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1752 }
1753
1754 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1756 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1757         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1758                                                                 "config");
1759 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1761 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1762         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1763                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1764                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1765 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1766         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1767                                                         "on#off");
1768
1769 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1770         .f = cmd_config_rx_mode_flag_parsed,
1771         .data = NULL,
1772         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1773                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1774         .tokens = {
1775                 (void *)&cmd_config_rx_mode_flag_port,
1776                 (void *)&cmd_config_rx_mode_flag_keyword,
1777                 (void *)&cmd_config_rx_mode_flag_all,
1778                 (void *)&cmd_config_rx_mode_flag_name,
1779                 (void *)&cmd_config_rx_mode_flag_value,
1780                 NULL,
1781         },
1782 };
1783
1784 /* *** configure rss *** */
1785 struct cmd_config_rss {
1786         cmdline_fixed_string_t port;
1787         cmdline_fixed_string_t keyword;
1788         cmdline_fixed_string_t all;
1789         cmdline_fixed_string_t name;
1790         cmdline_fixed_string_t value;
1791 };
1792
1793 static void
1794 cmd_config_rss_parsed(void *parsed_result,
1795                         __attribute__((unused)) struct cmdline *cl,
1796                         __attribute__((unused)) void *data)
1797 {
1798         struct cmd_config_rss *res = parsed_result;
1799         struct rte_eth_rss_conf rss_conf;
1800         int diag;
1801         uint8_t i;
1802
1803         if (!strcmp(res->value, "all"))
1804                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1805                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1806                                         ETH_RSS_L2_PAYLOAD;
1807         else if (!strcmp(res->value, "ip"))
1808                 rss_conf.rss_hf = ETH_RSS_IP;
1809         else if (!strcmp(res->value, "udp"))
1810                 rss_conf.rss_hf = ETH_RSS_UDP;
1811         else if (!strcmp(res->value, "tcp"))
1812                 rss_conf.rss_hf = ETH_RSS_TCP;
1813         else if (!strcmp(res->value, "sctp"))
1814                 rss_conf.rss_hf = ETH_RSS_SCTP;
1815         else if (!strcmp(res->value, "ether"))
1816                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1817         else if (!strcmp(res->value, "port"))
1818                 rss_conf.rss_hf = ETH_RSS_PORT;
1819         else if (!strcmp(res->value, "vxlan"))
1820                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1821         else if (!strcmp(res->value, "geneve"))
1822                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1823         else if (!strcmp(res->value, "nvgre"))
1824                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1825         else if (!strcmp(res->value, "none"))
1826                 rss_conf.rss_hf = 0;
1827         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1828                                                 atoi(res->value) < 64)
1829                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1830         else {
1831                 printf("Unknown parameter\n");
1832                 return;
1833         }
1834         rss_conf.rss_key = NULL;
1835         for (i = 0; i < rte_eth_dev_count(); i++) {
1836                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1837                 if (diag < 0)
1838                         printf("Configuration of RSS hash at ethernet port %d "
1839                                 "failed with error (%d): %s.\n",
1840                                 i, -diag, strerror(-diag));
1841         }
1842 }
1843
1844 cmdline_parse_token_string_t cmd_config_rss_port =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1846 cmdline_parse_token_string_t cmd_config_rss_keyword =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1848 cmdline_parse_token_string_t cmd_config_rss_all =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1850 cmdline_parse_token_string_t cmd_config_rss_name =
1851         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1852 cmdline_parse_token_string_t cmd_config_rss_value =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1854
1855 cmdline_parse_inst_t cmd_config_rss = {
1856         .f = cmd_config_rss_parsed,
1857         .data = NULL,
1858         .help_str = "port config all rss "
1859                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1860         .tokens = {
1861                 (void *)&cmd_config_rss_port,
1862                 (void *)&cmd_config_rss_keyword,
1863                 (void *)&cmd_config_rss_all,
1864                 (void *)&cmd_config_rss_name,
1865                 (void *)&cmd_config_rss_value,
1866                 NULL,
1867         },
1868 };
1869
1870 /* *** configure rss hash key *** */
1871 struct cmd_config_rss_hash_key {
1872         cmdline_fixed_string_t port;
1873         cmdline_fixed_string_t config;
1874         portid_t port_id;
1875         cmdline_fixed_string_t rss_hash_key;
1876         cmdline_fixed_string_t rss_type;
1877         cmdline_fixed_string_t key;
1878 };
1879
1880 static uint8_t
1881 hexa_digit_to_value(char hexa_digit)
1882 {
1883         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1884                 return (uint8_t) (hexa_digit - '0');
1885         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1886                 return (uint8_t) ((hexa_digit - 'a') + 10);
1887         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1888                 return (uint8_t) ((hexa_digit - 'A') + 10);
1889         /* Invalid hexa digit */
1890         return 0xFF;
1891 }
1892
1893 static uint8_t
1894 parse_and_check_key_hexa_digit(char *key, int idx)
1895 {
1896         uint8_t hexa_v;
1897
1898         hexa_v = hexa_digit_to_value(key[idx]);
1899         if (hexa_v == 0xFF)
1900                 printf("invalid key: character %c at position %d is not a "
1901                        "valid hexa digit\n", key[idx], idx);
1902         return hexa_v;
1903 }
1904
1905 static void
1906 cmd_config_rss_hash_key_parsed(void *parsed_result,
1907                                __attribute__((unused)) struct cmdline *cl,
1908                                __attribute__((unused)) void *data)
1909 {
1910         struct cmd_config_rss_hash_key *res = parsed_result;
1911         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1912         uint8_t xdgt0;
1913         uint8_t xdgt1;
1914         int i;
1915         struct rte_eth_dev_info dev_info;
1916         uint8_t hash_key_size;
1917         uint32_t key_len;
1918
1919         memset(&dev_info, 0, sizeof(dev_info));
1920         rte_eth_dev_info_get(res->port_id, &dev_info);
1921         if (dev_info.hash_key_size > 0 &&
1922                         dev_info.hash_key_size <= sizeof(hash_key))
1923                 hash_key_size = dev_info.hash_key_size;
1924         else {
1925                 printf("dev_info did not provide a valid hash key size\n");
1926                 return;
1927         }
1928         /* Check the length of the RSS hash key */
1929         key_len = strlen(res->key);
1930         if (key_len != (hash_key_size * 2)) {
1931                 printf("key length: %d invalid - key must be a string of %d"
1932                            " hexa-decimal numbers\n",
1933                            (int) key_len, hash_key_size * 2);
1934                 return;
1935         }
1936         /* Translate RSS hash key into binary representation */
1937         for (i = 0; i < hash_key_size; i++) {
1938                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1939                 if (xdgt0 == 0xFF)
1940                         return;
1941                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1942                 if (xdgt1 == 0xFF)
1943                         return;
1944                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1945         }
1946         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1947                         hash_key_size);
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1952 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1954                                  "config");
1955 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1956         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
1957 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1959                                  rss_hash_key, "rss-hash-key");
1960 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1962                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1963                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1964                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1965                                  "ipv6-tcp-ex#ipv6-udp-ex");
1966 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1968
1969 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1970         .f = cmd_config_rss_hash_key_parsed,
1971         .data = NULL,
1972         .help_str = "port config <port_id> rss-hash-key "
1973                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1974                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1975                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1976                 "<string of hex digits (variable length, NIC dependent)>",
1977         .tokens = {
1978                 (void *)&cmd_config_rss_hash_key_port,
1979                 (void *)&cmd_config_rss_hash_key_config,
1980                 (void *)&cmd_config_rss_hash_key_port_id,
1981                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1982                 (void *)&cmd_config_rss_hash_key_rss_type,
1983                 (void *)&cmd_config_rss_hash_key_value,
1984                 NULL,
1985         },
1986 };
1987
1988 /* *** configure port rxq/txq start/stop *** */
1989 struct cmd_config_rxtx_queue {
1990         cmdline_fixed_string_t port;
1991         portid_t portid;
1992         cmdline_fixed_string_t rxtxq;
1993         uint16_t qid;
1994         cmdline_fixed_string_t opname;
1995 };
1996
1997 static void
1998 cmd_config_rxtx_queue_parsed(void *parsed_result,
1999                         __attribute__((unused)) struct cmdline *cl,
2000                         __attribute__((unused)) void *data)
2001 {
2002         struct cmd_config_rxtx_queue *res = parsed_result;
2003         uint8_t isrx;
2004         uint8_t isstart;
2005         int ret = 0;
2006
2007         if (test_done == 0) {
2008                 printf("Please stop forwarding first\n");
2009                 return;
2010         }
2011
2012         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2013                 return;
2014
2015         if (port_is_started(res->portid) != 1) {
2016                 printf("Please start port %u first\n", res->portid);
2017                 return;
2018         }
2019
2020         if (!strcmp(res->rxtxq, "rxq"))
2021                 isrx = 1;
2022         else if (!strcmp(res->rxtxq, "txq"))
2023                 isrx = 0;
2024         else {
2025                 printf("Unknown parameter\n");
2026                 return;
2027         }
2028
2029         if (isrx && rx_queue_id_is_invalid(res->qid))
2030                 return;
2031         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2032                 return;
2033
2034         if (!strcmp(res->opname, "start"))
2035                 isstart = 1;
2036         else if (!strcmp(res->opname, "stop"))
2037                 isstart = 0;
2038         else {
2039                 printf("Unknown parameter\n");
2040                 return;
2041         }
2042
2043         if (isstart && isrx)
2044                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2045         else if (!isstart && isrx)
2046                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2047         else if (isstart && !isrx)
2048                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2049         else
2050                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2051
2052         if (ret == -ENOTSUP)
2053                 printf("Function not supported in PMD driver\n");
2054 }
2055
2056 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2058 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2059         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2060 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2062 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2063         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2064 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2066                                                 "start#stop");
2067
2068 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2069         .f = cmd_config_rxtx_queue_parsed,
2070         .data = NULL,
2071         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2072         .tokens = {
2073                 (void *)&cmd_config_speed_all_port,
2074                 (void *)&cmd_config_rxtx_queue_portid,
2075                 (void *)&cmd_config_rxtx_queue_rxtxq,
2076                 (void *)&cmd_config_rxtx_queue_qid,
2077                 (void *)&cmd_config_rxtx_queue_opname,
2078                 NULL,
2079         },
2080 };
2081
2082 /* *** Configure RSS RETA *** */
2083 struct cmd_config_rss_reta {
2084         cmdline_fixed_string_t port;
2085         cmdline_fixed_string_t keyword;
2086         portid_t port_id;
2087         cmdline_fixed_string_t name;
2088         cmdline_fixed_string_t list_name;
2089         cmdline_fixed_string_t list_of_items;
2090 };
2091
2092 static int
2093 parse_reta_config(const char *str,
2094                   struct rte_eth_rss_reta_entry64 *reta_conf,
2095                   uint16_t nb_entries)
2096 {
2097         int i;
2098         unsigned size;
2099         uint16_t hash_index, idx, shift;
2100         uint16_t nb_queue;
2101         char s[256];
2102         const char *p, *p0 = str;
2103         char *end;
2104         enum fieldnames {
2105                 FLD_HASH_INDEX = 0,
2106                 FLD_QUEUE,
2107                 _NUM_FLD
2108         };
2109         unsigned long int_fld[_NUM_FLD];
2110         char *str_fld[_NUM_FLD];
2111
2112         while ((p = strchr(p0,'(')) != NULL) {
2113                 ++p;
2114                 if((p0 = strchr(p,')')) == NULL)
2115                         return -1;
2116
2117                 size = p0 - p;
2118                 if(size >= sizeof(s))
2119                         return -1;
2120
2121                 snprintf(s, sizeof(s), "%.*s", size, p);
2122                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2123                         return -1;
2124                 for (i = 0; i < _NUM_FLD; i++) {
2125                         errno = 0;
2126                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2127                         if (errno != 0 || end == str_fld[i] ||
2128                                         int_fld[i] > 65535)
2129                                 return -1;
2130                 }
2131
2132                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2133                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2134
2135                 if (hash_index >= nb_entries) {
2136                         printf("Invalid RETA hash index=%d\n", hash_index);
2137                         return -1;
2138                 }
2139
2140                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2141                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2142                 reta_conf[idx].mask |= (1ULL << shift);
2143                 reta_conf[idx].reta[shift] = nb_queue;
2144         }
2145
2146         return 0;
2147 }
2148
2149 static void
2150 cmd_set_rss_reta_parsed(void *parsed_result,
2151                         __attribute__((unused)) struct cmdline *cl,
2152                         __attribute__((unused)) void *data)
2153 {
2154         int ret;
2155         struct rte_eth_dev_info dev_info;
2156         struct rte_eth_rss_reta_entry64 reta_conf[8];
2157         struct cmd_config_rss_reta *res = parsed_result;
2158
2159         memset(&dev_info, 0, sizeof(dev_info));
2160         rte_eth_dev_info_get(res->port_id, &dev_info);
2161         if (dev_info.reta_size == 0) {
2162                 printf("Redirection table size is 0 which is "
2163                                         "invalid for RSS\n");
2164                 return;
2165         } else
2166                 printf("The reta size of port %d is %u\n",
2167                         res->port_id, dev_info.reta_size);
2168         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2169                 printf("Currently do not support more than %u entries of "
2170                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2171                 return;
2172         }
2173
2174         memset(reta_conf, 0, sizeof(reta_conf));
2175         if (!strcmp(res->list_name, "reta")) {
2176                 if (parse_reta_config(res->list_of_items, reta_conf,
2177                                                 dev_info.reta_size)) {
2178                         printf("Invalid RSS Redirection Table "
2179                                         "config entered\n");
2180                         return;
2181                 }
2182                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2183                                 reta_conf, dev_info.reta_size);
2184                 if (ret != 0)
2185                         printf("Bad redirection table parameter, "
2186                                         "return code = %d \n", ret);
2187         }
2188 }
2189
2190 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2191         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2192 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2193         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2194 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2195         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2196 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2197         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2198 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2199         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2200 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2201         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2202                                  NULL);
2203 cmdline_parse_inst_t cmd_config_rss_reta = {
2204         .f = cmd_set_rss_reta_parsed,
2205         .data = NULL,
2206         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2207         .tokens = {
2208                 (void *)&cmd_config_rss_reta_port,
2209                 (void *)&cmd_config_rss_reta_keyword,
2210                 (void *)&cmd_config_rss_reta_port_id,
2211                 (void *)&cmd_config_rss_reta_name,
2212                 (void *)&cmd_config_rss_reta_list_name,
2213                 (void *)&cmd_config_rss_reta_list_of_items,
2214                 NULL,
2215         },
2216 };
2217
2218 /* *** SHOW PORT RETA INFO *** */
2219 struct cmd_showport_reta {
2220         cmdline_fixed_string_t show;
2221         cmdline_fixed_string_t port;
2222         portid_t port_id;
2223         cmdline_fixed_string_t rss;
2224         cmdline_fixed_string_t reta;
2225         uint16_t size;
2226         cmdline_fixed_string_t list_of_items;
2227 };
2228
2229 static int
2230 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2231                            uint16_t nb_entries,
2232                            char *str)
2233 {
2234         uint32_t size;
2235         const char *p, *p0 = str;
2236         char s[256];
2237         char *end;
2238         char *str_fld[8];
2239         uint16_t i;
2240         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2241                         RTE_RETA_GROUP_SIZE;
2242         int ret;
2243
2244         p = strchr(p0, '(');
2245         if (p == NULL)
2246                 return -1;
2247         p++;
2248         p0 = strchr(p, ')');
2249         if (p0 == NULL)
2250                 return -1;
2251         size = p0 - p;
2252         if (size >= sizeof(s)) {
2253                 printf("The string size exceeds the internal buffer size\n");
2254                 return -1;
2255         }
2256         snprintf(s, sizeof(s), "%.*s", size, p);
2257         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2258         if (ret <= 0 || ret != num) {
2259                 printf("The bits of masks do not match the number of "
2260                                         "reta entries: %u\n", num);
2261                 return -1;
2262         }
2263         for (i = 0; i < ret; i++)
2264                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2265
2266         return 0;
2267 }
2268
2269 static void
2270 cmd_showport_reta_parsed(void *parsed_result,
2271                          __attribute__((unused)) struct cmdline *cl,
2272                          __attribute__((unused)) void *data)
2273 {
2274         struct cmd_showport_reta *res = parsed_result;
2275         struct rte_eth_rss_reta_entry64 reta_conf[8];
2276         struct rte_eth_dev_info dev_info;
2277         uint16_t max_reta_size;
2278
2279         memset(&dev_info, 0, sizeof(dev_info));
2280         rte_eth_dev_info_get(res->port_id, &dev_info);
2281         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2282         if (res->size == 0 || res->size > max_reta_size) {
2283                 printf("Invalid redirection table size: %u (1-%u)\n",
2284                         res->size, max_reta_size);
2285                 return;
2286         }
2287
2288         memset(reta_conf, 0, sizeof(reta_conf));
2289         if (showport_parse_reta_config(reta_conf, res->size,
2290                                 res->list_of_items) < 0) {
2291                 printf("Invalid string: %s for reta masks\n",
2292                                         res->list_of_items);
2293                 return;
2294         }
2295         port_rss_reta_info(res->port_id, reta_conf, res->size);
2296 }
2297
2298 cmdline_parse_token_string_t cmd_showport_reta_show =
2299         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2300 cmdline_parse_token_string_t cmd_showport_reta_port =
2301         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2302 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2303         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2304 cmdline_parse_token_string_t cmd_showport_reta_rss =
2305         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2306 cmdline_parse_token_string_t cmd_showport_reta_reta =
2307         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2308 cmdline_parse_token_num_t cmd_showport_reta_size =
2309         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2310 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2311         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2312                                         list_of_items, NULL);
2313
2314 cmdline_parse_inst_t cmd_showport_reta = {
2315         .f = cmd_showport_reta_parsed,
2316         .data = NULL,
2317         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2318         .tokens = {
2319                 (void *)&cmd_showport_reta_show,
2320                 (void *)&cmd_showport_reta_port,
2321                 (void *)&cmd_showport_reta_port_id,
2322                 (void *)&cmd_showport_reta_rss,
2323                 (void *)&cmd_showport_reta_reta,
2324                 (void *)&cmd_showport_reta_size,
2325                 (void *)&cmd_showport_reta_list_of_items,
2326                 NULL,
2327         },
2328 };
2329
2330 /* *** Show RSS hash configuration *** */
2331 struct cmd_showport_rss_hash {
2332         cmdline_fixed_string_t show;
2333         cmdline_fixed_string_t port;
2334         portid_t port_id;
2335         cmdline_fixed_string_t rss_hash;
2336         cmdline_fixed_string_t rss_type;
2337         cmdline_fixed_string_t key; /* optional argument */
2338 };
2339
2340 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2341                                 __attribute__((unused)) struct cmdline *cl,
2342                                 void *show_rss_key)
2343 {
2344         struct cmd_showport_rss_hash *res = parsed_result;
2345
2346         port_rss_hash_conf_show(res->port_id, res->rss_type,
2347                                 show_rss_key != NULL);
2348 }
2349
2350 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2351         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2352 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2353         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2354 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2355         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2356 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2357         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2358                                  "rss-hash");
2359 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2360         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2361                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2362                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2363                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2364                                  "ipv6-tcp-ex#ipv6-udp-ex");
2365 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2366         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2367
2368 cmdline_parse_inst_t cmd_showport_rss_hash = {
2369         .f = cmd_showport_rss_hash_parsed,
2370         .data = NULL,
2371         .help_str = "show port <port_id> rss-hash "
2372                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2373                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2374                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2375         .tokens = {
2376                 (void *)&cmd_showport_rss_hash_show,
2377                 (void *)&cmd_showport_rss_hash_port,
2378                 (void *)&cmd_showport_rss_hash_port_id,
2379                 (void *)&cmd_showport_rss_hash_rss_hash,
2380                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2381                 NULL,
2382         },
2383 };
2384
2385 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2386         .f = cmd_showport_rss_hash_parsed,
2387         .data = (void *)1,
2388         .help_str = "show port <port_id> rss-hash "
2389                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2390                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2391                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2392         .tokens = {
2393                 (void *)&cmd_showport_rss_hash_show,
2394                 (void *)&cmd_showport_rss_hash_port,
2395                 (void *)&cmd_showport_rss_hash_port_id,
2396                 (void *)&cmd_showport_rss_hash_rss_hash,
2397                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2398                 (void *)&cmd_showport_rss_hash_rss_key,
2399                 NULL,
2400         },
2401 };
2402
2403 /* *** Configure DCB *** */
2404 struct cmd_config_dcb {
2405         cmdline_fixed_string_t port;
2406         cmdline_fixed_string_t config;
2407         portid_t port_id;
2408         cmdline_fixed_string_t dcb;
2409         cmdline_fixed_string_t vt;
2410         cmdline_fixed_string_t vt_en;
2411         uint8_t num_tcs;
2412         cmdline_fixed_string_t pfc;
2413         cmdline_fixed_string_t pfc_en;
2414 };
2415
2416 static void
2417 cmd_config_dcb_parsed(void *parsed_result,
2418                         __attribute__((unused)) struct cmdline *cl,
2419                         __attribute__((unused)) void *data)
2420 {
2421         struct cmd_config_dcb *res = parsed_result;
2422         portid_t port_id = res->port_id;
2423         struct rte_port *port;
2424         uint8_t pfc_en;
2425         int ret;
2426
2427         port = &ports[port_id];
2428         /** Check if the port is not started **/
2429         if (port->port_status != RTE_PORT_STOPPED) {
2430                 printf("Please stop port %d first\n", port_id);
2431                 return;
2432         }
2433
2434         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2435                 printf("The invalid number of traffic class,"
2436                         " only 4 or 8 allowed.\n");
2437                 return;
2438         }
2439
2440         if (nb_fwd_lcores < res->num_tcs) {
2441                 printf("nb_cores shouldn't be less than number of TCs.\n");
2442                 return;
2443         }
2444         if (!strncmp(res->pfc_en, "on", 2))
2445                 pfc_en = 1;
2446         else
2447                 pfc_en = 0;
2448
2449         /* DCB in VT mode */
2450         if (!strncmp(res->vt_en, "on", 2))
2451                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2452                                 (enum rte_eth_nb_tcs)res->num_tcs,
2453                                 pfc_en);
2454         else
2455                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2456                                 (enum rte_eth_nb_tcs)res->num_tcs,
2457                                 pfc_en);
2458
2459
2460         if (ret != 0) {
2461                 printf("Cannot initialize network ports.\n");
2462                 return;
2463         }
2464
2465         cmd_reconfig_device_queue(port_id, 1, 1);
2466 }
2467
2468 cmdline_parse_token_string_t cmd_config_dcb_port =
2469         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2470 cmdline_parse_token_string_t cmd_config_dcb_config =
2471         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2472 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2473         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2474 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2475         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2476 cmdline_parse_token_string_t cmd_config_dcb_vt =
2477         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2478 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2479         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2480 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2481         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2482 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2483         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2484 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2485         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2486
2487 cmdline_parse_inst_t cmd_config_dcb = {
2488         .f = cmd_config_dcb_parsed,
2489         .data = NULL,
2490         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2491         .tokens = {
2492                 (void *)&cmd_config_dcb_port,
2493                 (void *)&cmd_config_dcb_config,
2494                 (void *)&cmd_config_dcb_port_id,
2495                 (void *)&cmd_config_dcb_dcb,
2496                 (void *)&cmd_config_dcb_vt,
2497                 (void *)&cmd_config_dcb_vt_en,
2498                 (void *)&cmd_config_dcb_num_tcs,
2499                 (void *)&cmd_config_dcb_pfc,
2500                 (void *)&cmd_config_dcb_pfc_en,
2501                 NULL,
2502         },
2503 };
2504
2505 /* *** configure number of packets per burst *** */
2506 struct cmd_config_burst {
2507         cmdline_fixed_string_t port;
2508         cmdline_fixed_string_t keyword;
2509         cmdline_fixed_string_t all;
2510         cmdline_fixed_string_t name;
2511         uint16_t value;
2512 };
2513
2514 static void
2515 cmd_config_burst_parsed(void *parsed_result,
2516                         __attribute__((unused)) struct cmdline *cl,
2517                         __attribute__((unused)) void *data)
2518 {
2519         struct cmd_config_burst *res = parsed_result;
2520
2521         if (!all_ports_stopped()) {
2522                 printf("Please stop all ports first\n");
2523                 return;
2524         }
2525
2526         if (!strcmp(res->name, "burst")) {
2527                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2528                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2529                         return;
2530                 }
2531                 nb_pkt_per_burst = res->value;
2532         } else {
2533                 printf("Unknown parameter\n");
2534                 return;
2535         }
2536
2537         init_port_config();
2538
2539         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2540 }
2541
2542 cmdline_parse_token_string_t cmd_config_burst_port =
2543         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2544 cmdline_parse_token_string_t cmd_config_burst_keyword =
2545         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2546 cmdline_parse_token_string_t cmd_config_burst_all =
2547         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2548 cmdline_parse_token_string_t cmd_config_burst_name =
2549         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2550 cmdline_parse_token_num_t cmd_config_burst_value =
2551         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2552
2553 cmdline_parse_inst_t cmd_config_burst = {
2554         .f = cmd_config_burst_parsed,
2555         .data = NULL,
2556         .help_str = "port config all burst <value>",
2557         .tokens = {
2558                 (void *)&cmd_config_burst_port,
2559                 (void *)&cmd_config_burst_keyword,
2560                 (void *)&cmd_config_burst_all,
2561                 (void *)&cmd_config_burst_name,
2562                 (void *)&cmd_config_burst_value,
2563                 NULL,
2564         },
2565 };
2566
2567 /* *** configure rx/tx queues *** */
2568 struct cmd_config_thresh {
2569         cmdline_fixed_string_t port;
2570         cmdline_fixed_string_t keyword;
2571         cmdline_fixed_string_t all;
2572         cmdline_fixed_string_t name;
2573         uint8_t value;
2574 };
2575
2576 static void
2577 cmd_config_thresh_parsed(void *parsed_result,
2578                         __attribute__((unused)) struct cmdline *cl,
2579                         __attribute__((unused)) void *data)
2580 {
2581         struct cmd_config_thresh *res = parsed_result;
2582
2583         if (!all_ports_stopped()) {
2584                 printf("Please stop all ports first\n");
2585                 return;
2586         }
2587
2588         if (!strcmp(res->name, "txpt"))
2589                 tx_pthresh = res->value;
2590         else if(!strcmp(res->name, "txht"))
2591                 tx_hthresh = res->value;
2592         else if(!strcmp(res->name, "txwt"))
2593                 tx_wthresh = res->value;
2594         else if(!strcmp(res->name, "rxpt"))
2595                 rx_pthresh = res->value;
2596         else if(!strcmp(res->name, "rxht"))
2597                 rx_hthresh = res->value;
2598         else if(!strcmp(res->name, "rxwt"))
2599                 rx_wthresh = res->value;
2600         else {
2601                 printf("Unknown parameter\n");
2602                 return;
2603         }
2604
2605         init_port_config();
2606
2607         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2608 }
2609
2610 cmdline_parse_token_string_t cmd_config_thresh_port =
2611         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2612 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2613         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2614 cmdline_parse_token_string_t cmd_config_thresh_all =
2615         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2616 cmdline_parse_token_string_t cmd_config_thresh_name =
2617         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2618                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2619 cmdline_parse_token_num_t cmd_config_thresh_value =
2620         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2621
2622 cmdline_parse_inst_t cmd_config_thresh = {
2623         .f = cmd_config_thresh_parsed,
2624         .data = NULL,
2625         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2626         .tokens = {
2627                 (void *)&cmd_config_thresh_port,
2628                 (void *)&cmd_config_thresh_keyword,
2629                 (void *)&cmd_config_thresh_all,
2630                 (void *)&cmd_config_thresh_name,
2631                 (void *)&cmd_config_thresh_value,
2632                 NULL,
2633         },
2634 };
2635
2636 /* *** configure free/rs threshold *** */
2637 struct cmd_config_threshold {
2638         cmdline_fixed_string_t port;
2639         cmdline_fixed_string_t keyword;
2640         cmdline_fixed_string_t all;
2641         cmdline_fixed_string_t name;
2642         uint16_t value;
2643 };
2644
2645 static void
2646 cmd_config_threshold_parsed(void *parsed_result,
2647                         __attribute__((unused)) struct cmdline *cl,
2648                         __attribute__((unused)) void *data)
2649 {
2650         struct cmd_config_threshold *res = parsed_result;
2651
2652         if (!all_ports_stopped()) {
2653                 printf("Please stop all ports first\n");
2654                 return;
2655         }
2656
2657         if (!strcmp(res->name, "txfreet"))
2658                 tx_free_thresh = res->value;
2659         else if (!strcmp(res->name, "txrst"))
2660                 tx_rs_thresh = res->value;
2661         else if (!strcmp(res->name, "rxfreet"))
2662                 rx_free_thresh = res->value;
2663         else {
2664                 printf("Unknown parameter\n");
2665                 return;
2666         }
2667
2668         init_port_config();
2669
2670         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2671 }
2672
2673 cmdline_parse_token_string_t cmd_config_threshold_port =
2674         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2675 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2676         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2677                                                                 "config");
2678 cmdline_parse_token_string_t cmd_config_threshold_all =
2679         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2680 cmdline_parse_token_string_t cmd_config_threshold_name =
2681         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2682                                                 "txfreet#txrst#rxfreet");
2683 cmdline_parse_token_num_t cmd_config_threshold_value =
2684         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2685
2686 cmdline_parse_inst_t cmd_config_threshold = {
2687         .f = cmd_config_threshold_parsed,
2688         .data = NULL,
2689         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2690         .tokens = {
2691                 (void *)&cmd_config_threshold_port,
2692                 (void *)&cmd_config_threshold_keyword,
2693                 (void *)&cmd_config_threshold_all,
2694                 (void *)&cmd_config_threshold_name,
2695                 (void *)&cmd_config_threshold_value,
2696                 NULL,
2697         },
2698 };
2699
2700 /* *** stop *** */
2701 struct cmd_stop_result {
2702         cmdline_fixed_string_t stop;
2703 };
2704
2705 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2706                             __attribute__((unused)) struct cmdline *cl,
2707                             __attribute__((unused)) void *data)
2708 {
2709         stop_packet_forwarding();
2710 }
2711
2712 cmdline_parse_token_string_t cmd_stop_stop =
2713         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2714
2715 cmdline_parse_inst_t cmd_stop = {
2716         .f = cmd_stop_parsed,
2717         .data = NULL,
2718         .help_str = "stop: Stop packet forwarding",
2719         .tokens = {
2720                 (void *)&cmd_stop_stop,
2721                 NULL,
2722         },
2723 };
2724
2725 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2726
2727 unsigned int
2728 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2729                 unsigned int *parsed_items, int check_unique_values)
2730 {
2731         unsigned int nb_item;
2732         unsigned int value;
2733         unsigned int i;
2734         unsigned int j;
2735         int value_ok;
2736         char c;
2737
2738         /*
2739          * First parse all items in the list and store their value.
2740          */
2741         value = 0;
2742         nb_item = 0;
2743         value_ok = 0;
2744         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2745                 c = str[i];
2746                 if ((c >= '0') && (c <= '9')) {
2747                         value = (unsigned int) (value * 10 + (c - '0'));
2748                         value_ok = 1;
2749                         continue;
2750                 }
2751                 if (c != ',') {
2752                         printf("character %c is not a decimal digit\n", c);
2753                         return 0;
2754                 }
2755                 if (! value_ok) {
2756                         printf("No valid value before comma\n");
2757                         return 0;
2758                 }
2759                 if (nb_item < max_items) {
2760                         parsed_items[nb_item] = value;
2761                         value_ok = 0;
2762                         value = 0;
2763                 }
2764                 nb_item++;
2765         }
2766         if (nb_item >= max_items) {
2767                 printf("Number of %s = %u > %u (maximum items)\n",
2768                        item_name, nb_item + 1, max_items);
2769                 return 0;
2770         }
2771         parsed_items[nb_item++] = value;
2772         if (! check_unique_values)
2773                 return nb_item;
2774
2775         /*
2776          * Then, check that all values in the list are differents.
2777          * No optimization here...
2778          */
2779         for (i = 0; i < nb_item; i++) {
2780                 for (j = i + 1; j < nb_item; j++) {
2781                         if (parsed_items[j] == parsed_items[i]) {
2782                                 printf("duplicated %s %u at index %u and %u\n",
2783                                        item_name, parsed_items[i], i, j);
2784                                 return 0;
2785                         }
2786                 }
2787         }
2788         return nb_item;
2789 }
2790
2791 struct cmd_set_list_result {
2792         cmdline_fixed_string_t cmd_keyword;
2793         cmdline_fixed_string_t list_name;
2794         cmdline_fixed_string_t list_of_items;
2795 };
2796
2797 static void cmd_set_list_parsed(void *parsed_result,
2798                                 __attribute__((unused)) struct cmdline *cl,
2799                                 __attribute__((unused)) void *data)
2800 {
2801         struct cmd_set_list_result *res;
2802         union {
2803                 unsigned int lcorelist[RTE_MAX_LCORE];
2804                 unsigned int portlist[RTE_MAX_ETHPORTS];
2805         } parsed_items;
2806         unsigned int nb_item;
2807
2808         if (test_done == 0) {
2809                 printf("Please stop forwarding first\n");
2810                 return;
2811         }
2812
2813         res = parsed_result;
2814         if (!strcmp(res->list_name, "corelist")) {
2815                 nb_item = parse_item_list(res->list_of_items, "core",
2816                                           RTE_MAX_LCORE,
2817                                           parsed_items.lcorelist, 1);
2818                 if (nb_item > 0) {
2819                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2820                         fwd_config_setup();
2821                 }
2822                 return;
2823         }
2824         if (!strcmp(res->list_name, "portlist")) {
2825                 nb_item = parse_item_list(res->list_of_items, "port",
2826                                           RTE_MAX_ETHPORTS,
2827                                           parsed_items.portlist, 1);
2828                 if (nb_item > 0) {
2829                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2830                         fwd_config_setup();
2831                 }
2832         }
2833 }
2834
2835 cmdline_parse_token_string_t cmd_set_list_keyword =
2836         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2837                                  "set");
2838 cmdline_parse_token_string_t cmd_set_list_name =
2839         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2840                                  "corelist#portlist");
2841 cmdline_parse_token_string_t cmd_set_list_of_items =
2842         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2843                                  NULL);
2844
2845 cmdline_parse_inst_t cmd_set_fwd_list = {
2846         .f = cmd_set_list_parsed,
2847         .data = NULL,
2848         .help_str = "set corelist|portlist <list0[,list1]*>",
2849         .tokens = {
2850                 (void *)&cmd_set_list_keyword,
2851                 (void *)&cmd_set_list_name,
2852                 (void *)&cmd_set_list_of_items,
2853                 NULL,
2854         },
2855 };
2856
2857 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2858
2859 struct cmd_setmask_result {
2860         cmdline_fixed_string_t set;
2861         cmdline_fixed_string_t mask;
2862         uint64_t hexavalue;
2863 };
2864
2865 static void cmd_set_mask_parsed(void *parsed_result,
2866                                 __attribute__((unused)) struct cmdline *cl,
2867                                 __attribute__((unused)) void *data)
2868 {
2869         struct cmd_setmask_result *res = parsed_result;
2870
2871         if (test_done == 0) {
2872                 printf("Please stop forwarding first\n");
2873                 return;
2874         }
2875         if (!strcmp(res->mask, "coremask")) {
2876                 set_fwd_lcores_mask(res->hexavalue);
2877                 fwd_config_setup();
2878         } else if (!strcmp(res->mask, "portmask")) {
2879                 set_fwd_ports_mask(res->hexavalue);
2880                 fwd_config_setup();
2881         }
2882 }
2883
2884 cmdline_parse_token_string_t cmd_setmask_set =
2885         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2886 cmdline_parse_token_string_t cmd_setmask_mask =
2887         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2888                                  "coremask#portmask");
2889 cmdline_parse_token_num_t cmd_setmask_value =
2890         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2891
2892 cmdline_parse_inst_t cmd_set_fwd_mask = {
2893         .f = cmd_set_mask_parsed,
2894         .data = NULL,
2895         .help_str = "set coremask|portmask <hexadecimal value>",
2896         .tokens = {
2897                 (void *)&cmd_setmask_set,
2898                 (void *)&cmd_setmask_mask,
2899                 (void *)&cmd_setmask_value,
2900                 NULL,
2901         },
2902 };
2903
2904 /*
2905  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2906  */
2907 struct cmd_set_result {
2908         cmdline_fixed_string_t set;
2909         cmdline_fixed_string_t what;
2910         uint16_t value;
2911 };
2912
2913 static void cmd_set_parsed(void *parsed_result,
2914                            __attribute__((unused)) struct cmdline *cl,
2915                            __attribute__((unused)) void *data)
2916 {
2917         struct cmd_set_result *res = parsed_result;
2918         if (!strcmp(res->what, "nbport")) {
2919                 set_fwd_ports_number(res->value);
2920                 fwd_config_setup();
2921         } else if (!strcmp(res->what, "nbcore")) {
2922                 set_fwd_lcores_number(res->value);
2923                 fwd_config_setup();
2924         } else if (!strcmp(res->what, "burst"))
2925                 set_nb_pkt_per_burst(res->value);
2926         else if (!strcmp(res->what, "verbose"))
2927                 set_verbose_level(res->value);
2928 }
2929
2930 cmdline_parse_token_string_t cmd_set_set =
2931         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2932 cmdline_parse_token_string_t cmd_set_what =
2933         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2934                                  "nbport#nbcore#burst#verbose");
2935 cmdline_parse_token_num_t cmd_set_value =
2936         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2937
2938 cmdline_parse_inst_t cmd_set_numbers = {
2939         .f = cmd_set_parsed,
2940         .data = NULL,
2941         .help_str = "set nbport|nbcore|burst|verbose <value>",
2942         .tokens = {
2943                 (void *)&cmd_set_set,
2944                 (void *)&cmd_set_what,
2945                 (void *)&cmd_set_value,
2946                 NULL,
2947         },
2948 };
2949
2950 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2951
2952 struct cmd_set_txpkts_result {
2953         cmdline_fixed_string_t cmd_keyword;
2954         cmdline_fixed_string_t txpkts;
2955         cmdline_fixed_string_t seg_lengths;
2956 };
2957
2958 static void
2959 cmd_set_txpkts_parsed(void *parsed_result,
2960                       __attribute__((unused)) struct cmdline *cl,
2961                       __attribute__((unused)) void *data)
2962 {
2963         struct cmd_set_txpkts_result *res;
2964         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2965         unsigned int nb_segs;
2966
2967         res = parsed_result;
2968         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2969                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2970         if (nb_segs > 0)
2971                 set_tx_pkt_segments(seg_lengths, nb_segs);
2972 }
2973
2974 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2975         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2976                                  cmd_keyword, "set");
2977 cmdline_parse_token_string_t cmd_set_txpkts_name =
2978         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2979                                  txpkts, "txpkts");
2980 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2981         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2982                                  seg_lengths, NULL);
2983
2984 cmdline_parse_inst_t cmd_set_txpkts = {
2985         .f = cmd_set_txpkts_parsed,
2986         .data = NULL,
2987         .help_str = "set txpkts <len0[,len1]*>",
2988         .tokens = {
2989                 (void *)&cmd_set_txpkts_keyword,
2990                 (void *)&cmd_set_txpkts_name,
2991                 (void *)&cmd_set_txpkts_lengths,
2992                 NULL,
2993         },
2994 };
2995
2996 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2997
2998 struct cmd_set_txsplit_result {
2999         cmdline_fixed_string_t cmd_keyword;
3000         cmdline_fixed_string_t txsplit;
3001         cmdline_fixed_string_t mode;
3002 };
3003
3004 static void
3005 cmd_set_txsplit_parsed(void *parsed_result,
3006                       __attribute__((unused)) struct cmdline *cl,
3007                       __attribute__((unused)) void *data)
3008 {
3009         struct cmd_set_txsplit_result *res;
3010
3011         res = parsed_result;
3012         set_tx_pkt_split(res->mode);
3013 }
3014
3015 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3016         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3017                                  cmd_keyword, "set");
3018 cmdline_parse_token_string_t cmd_set_txsplit_name =
3019         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3020                                  txsplit, "txsplit");
3021 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3022         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3023                                  mode, NULL);
3024
3025 cmdline_parse_inst_t cmd_set_txsplit = {
3026         .f = cmd_set_txsplit_parsed,
3027         .data = NULL,
3028         .help_str = "set txsplit on|off|rand",
3029         .tokens = {
3030                 (void *)&cmd_set_txsplit_keyword,
3031                 (void *)&cmd_set_txsplit_name,
3032                 (void *)&cmd_set_txsplit_mode,
3033                 NULL,
3034         },
3035 };
3036
3037 /* *** CONFIG TX QUEUE FLAGS *** */
3038
3039 struct cmd_config_txqflags_result {
3040         cmdline_fixed_string_t port;
3041         cmdline_fixed_string_t config;
3042         cmdline_fixed_string_t all;
3043         cmdline_fixed_string_t what;
3044         int32_t hexvalue;
3045 };
3046
3047 static void cmd_config_txqflags_parsed(void *parsed_result,
3048                                 __attribute__((unused)) struct cmdline *cl,
3049                                 __attribute__((unused)) void *data)
3050 {
3051         struct cmd_config_txqflags_result *res = parsed_result;
3052
3053         if (!all_ports_stopped()) {
3054                 printf("Please stop all ports first\n");
3055                 return;
3056         }
3057
3058         if (strcmp(res->what, "txqflags")) {
3059                 printf("Unknown parameter\n");
3060                 return;
3061         }
3062
3063         if (res->hexvalue >= 0) {
3064                 txq_flags = res->hexvalue;
3065         } else {
3066                 printf("txqflags must be >= 0\n");
3067                 return;
3068         }
3069
3070         init_port_config();
3071
3072         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3073 }
3074
3075 cmdline_parse_token_string_t cmd_config_txqflags_port =
3076         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3077                                  "port");
3078 cmdline_parse_token_string_t cmd_config_txqflags_config =
3079         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3080                                  "config");
3081 cmdline_parse_token_string_t cmd_config_txqflags_all =
3082         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3083                                  "all");
3084 cmdline_parse_token_string_t cmd_config_txqflags_what =
3085         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3086                                  "txqflags");
3087 cmdline_parse_token_num_t cmd_config_txqflags_value =
3088         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3089                                 hexvalue, INT32);
3090
3091 cmdline_parse_inst_t cmd_config_txqflags = {
3092         .f = cmd_config_txqflags_parsed,
3093         .data = NULL,
3094         .help_str = "port config all txqflags <value>",
3095         .tokens = {
3096                 (void *)&cmd_config_txqflags_port,
3097                 (void *)&cmd_config_txqflags_config,
3098                 (void *)&cmd_config_txqflags_all,
3099                 (void *)&cmd_config_txqflags_what,
3100                 (void *)&cmd_config_txqflags_value,
3101                 NULL,
3102         },
3103 };
3104
3105 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3106 struct cmd_rx_vlan_filter_all_result {
3107         cmdline_fixed_string_t rx_vlan;
3108         cmdline_fixed_string_t what;
3109         cmdline_fixed_string_t all;
3110         portid_t port_id;
3111 };
3112
3113 static void
3114 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3115                               __attribute__((unused)) struct cmdline *cl,
3116                               __attribute__((unused)) void *data)
3117 {
3118         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3119
3120         if (!strcmp(res->what, "add"))
3121                 rx_vlan_all_filter_set(res->port_id, 1);
3122         else
3123                 rx_vlan_all_filter_set(res->port_id, 0);
3124 }
3125
3126 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3127         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3128                                  rx_vlan, "rx_vlan");
3129 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3130         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3131                                  what, "add#rm");
3132 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3133         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3134                                  all, "all");
3135 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3136         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3137                               port_id, UINT16);
3138
3139 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3140         .f = cmd_rx_vlan_filter_all_parsed,
3141         .data = NULL,
3142         .help_str = "rx_vlan add|rm all <port_id>: "
3143                 "Add/Remove all identifiers to/from the set of VLAN "
3144                 "identifiers filtered by a port",
3145         .tokens = {
3146                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3147                 (void *)&cmd_rx_vlan_filter_all_what,
3148                 (void *)&cmd_rx_vlan_filter_all_all,
3149                 (void *)&cmd_rx_vlan_filter_all_portid,
3150                 NULL,
3151         },
3152 };
3153
3154 /* *** VLAN OFFLOAD SET ON A PORT *** */
3155 struct cmd_vlan_offload_result {
3156         cmdline_fixed_string_t vlan;
3157         cmdline_fixed_string_t set;
3158         cmdline_fixed_string_t vlan_type;
3159         cmdline_fixed_string_t what;
3160         cmdline_fixed_string_t on;
3161         cmdline_fixed_string_t port_id;
3162 };
3163
3164 static void
3165 cmd_vlan_offload_parsed(void *parsed_result,
3166                           __attribute__((unused)) struct cmdline *cl,
3167                           __attribute__((unused)) void *data)
3168 {
3169         int on;
3170         struct cmd_vlan_offload_result *res = parsed_result;
3171         char *str;
3172         int i, len = 0;
3173         portid_t port_id = 0;
3174         unsigned int tmp;
3175
3176         str = res->port_id;
3177         len = strnlen(str, STR_TOKEN_SIZE);
3178         i = 0;
3179         /* Get port_id first */
3180         while(i < len){
3181                 if(str[i] == ',')
3182                         break;
3183
3184                 i++;
3185         }
3186         str[i]='\0';
3187         tmp = strtoul(str, NULL, 0);
3188         /* If port_id greater that what portid_t can represent, return */
3189         if(tmp >= RTE_MAX_ETHPORTS)
3190                 return;
3191         port_id = (portid_t)tmp;
3192
3193         if (!strcmp(res->on, "on"))
3194                 on = 1;
3195         else
3196                 on = 0;
3197
3198         if (!strcmp(res->what, "strip"))
3199                 rx_vlan_strip_set(port_id,  on);
3200         else if(!strcmp(res->what, "stripq")){
3201                 uint16_t queue_id = 0;
3202
3203                 /* No queue_id, return */
3204                 if(i + 1 >= len) {
3205                         printf("must specify (port,queue_id)\n");
3206                         return;
3207                 }
3208                 tmp = strtoul(str + i + 1, NULL, 0);
3209                 /* If queue_id greater that what 16-bits can represent, return */
3210                 if(tmp > 0xffff)
3211                         return;
3212
3213                 queue_id = (uint16_t)tmp;
3214                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3215         }
3216         else if (!strcmp(res->what, "filter"))
3217                 rx_vlan_filter_set(port_id, on);
3218         else
3219                 vlan_extend_set(port_id, on);
3220
3221         return;
3222 }
3223
3224 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3225         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3226                                  vlan, "vlan");
3227 cmdline_parse_token_string_t cmd_vlan_offload_set =
3228         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3229                                  set, "set");
3230 cmdline_parse_token_string_t cmd_vlan_offload_what =
3231         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3232                                  what, "strip#filter#qinq#stripq");
3233 cmdline_parse_token_string_t cmd_vlan_offload_on =
3234         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3235                               on, "on#off");
3236 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3237         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3238                               port_id, NULL);
3239
3240 cmdline_parse_inst_t cmd_vlan_offload = {
3241         .f = cmd_vlan_offload_parsed,
3242         .data = NULL,
3243         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3244                 "<port_id[,queue_id]>: "
3245                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3246         .tokens = {
3247                 (void *)&cmd_vlan_offload_vlan,
3248                 (void *)&cmd_vlan_offload_set,
3249                 (void *)&cmd_vlan_offload_what,
3250                 (void *)&cmd_vlan_offload_on,
3251                 (void *)&cmd_vlan_offload_portid,
3252                 NULL,
3253         },
3254 };
3255
3256 /* *** VLAN TPID SET ON A PORT *** */
3257 struct cmd_vlan_tpid_result {
3258         cmdline_fixed_string_t vlan;
3259         cmdline_fixed_string_t set;
3260         cmdline_fixed_string_t vlan_type;
3261         cmdline_fixed_string_t what;
3262         uint16_t tp_id;
3263         portid_t port_id;
3264 };
3265
3266 static void
3267 cmd_vlan_tpid_parsed(void *parsed_result,
3268                           __attribute__((unused)) struct cmdline *cl,
3269                           __attribute__((unused)) void *data)
3270 {
3271         struct cmd_vlan_tpid_result *res = parsed_result;
3272         enum rte_vlan_type vlan_type;
3273
3274         if (!strcmp(res->vlan_type, "inner"))
3275                 vlan_type = ETH_VLAN_TYPE_INNER;
3276         else if (!strcmp(res->vlan_type, "outer"))
3277                 vlan_type = ETH_VLAN_TYPE_OUTER;
3278         else {
3279                 printf("Unknown vlan type\n");
3280                 return;
3281         }
3282         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3283 }
3284
3285 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3286         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3287                                  vlan, "vlan");
3288 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3289         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3290                                  set, "set");
3291 cmdline_parse_token_string_t cmd_vlan_type =
3292         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3293                                  vlan_type, "inner#outer");
3294 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3295         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3296                                  what, "tpid");
3297 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3298         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3299                               tp_id, UINT16);
3300 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3301         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3302                               port_id, UINT8);
3303
3304 cmdline_parse_inst_t cmd_vlan_tpid = {
3305         .f = cmd_vlan_tpid_parsed,
3306         .data = NULL,
3307         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3308                 "Set the VLAN Ether type",
3309         .tokens = {
3310                 (void *)&cmd_vlan_tpid_vlan,
3311                 (void *)&cmd_vlan_tpid_set,
3312                 (void *)&cmd_vlan_type,
3313                 (void *)&cmd_vlan_tpid_what,
3314                 (void *)&cmd_vlan_tpid_tpid,
3315                 (void *)&cmd_vlan_tpid_portid,
3316                 NULL,
3317         },
3318 };
3319
3320 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3321 struct cmd_rx_vlan_filter_result {
3322         cmdline_fixed_string_t rx_vlan;
3323         cmdline_fixed_string_t what;
3324         uint16_t vlan_id;
3325         portid_t port_id;
3326 };
3327
3328 static void
3329 cmd_rx_vlan_filter_parsed(void *parsed_result,
3330                           __attribute__((unused)) struct cmdline *cl,
3331                           __attribute__((unused)) void *data)
3332 {
3333         struct cmd_rx_vlan_filter_result *res = parsed_result;
3334
3335         if (!strcmp(res->what, "add"))
3336                 rx_vft_set(res->port_id, res->vlan_id, 1);
3337         else
3338                 rx_vft_set(res->port_id, res->vlan_id, 0);
3339 }
3340
3341 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3342         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3343                                  rx_vlan, "rx_vlan");
3344 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3345         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3346                                  what, "add#rm");
3347 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3348         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3349                               vlan_id, UINT16);
3350 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3351         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3352                               port_id, UINT16);
3353
3354 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3355         .f = cmd_rx_vlan_filter_parsed,
3356         .data = NULL,
3357         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3358                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3359                 "identifiers filtered by a port",
3360         .tokens = {
3361                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3362                 (void *)&cmd_rx_vlan_filter_what,
3363                 (void *)&cmd_rx_vlan_filter_vlanid,
3364                 (void *)&cmd_rx_vlan_filter_portid,
3365                 NULL,
3366         },
3367 };
3368
3369 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3370 struct cmd_tx_vlan_set_result {
3371         cmdline_fixed_string_t tx_vlan;
3372         cmdline_fixed_string_t set;
3373         portid_t port_id;
3374         uint16_t vlan_id;
3375 };
3376
3377 static void
3378 cmd_tx_vlan_set_parsed(void *parsed_result,
3379                        __attribute__((unused)) struct cmdline *cl,
3380                        __attribute__((unused)) void *data)
3381 {
3382         struct cmd_tx_vlan_set_result *res = parsed_result;
3383
3384         tx_vlan_set(res->port_id, res->vlan_id);
3385 }
3386
3387 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3388         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3389                                  tx_vlan, "tx_vlan");
3390 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3391         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3392                                  set, "set");
3393 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3394         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3395                               port_id, UINT16);
3396 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3397         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3398                               vlan_id, UINT16);
3399
3400 cmdline_parse_inst_t cmd_tx_vlan_set = {
3401         .f = cmd_tx_vlan_set_parsed,
3402         .data = NULL,
3403         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3404                 "Enable hardware insertion of a single VLAN header "
3405                 "with a given TAG Identifier in packets sent on a port",
3406         .tokens = {
3407                 (void *)&cmd_tx_vlan_set_tx_vlan,
3408                 (void *)&cmd_tx_vlan_set_set,
3409                 (void *)&cmd_tx_vlan_set_portid,
3410                 (void *)&cmd_tx_vlan_set_vlanid,
3411                 NULL,
3412         },
3413 };
3414
3415 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3416 struct cmd_tx_vlan_set_qinq_result {
3417         cmdline_fixed_string_t tx_vlan;
3418         cmdline_fixed_string_t set;
3419         portid_t port_id;
3420         uint16_t vlan_id;
3421         uint16_t vlan_id_outer;
3422 };
3423
3424 static void
3425 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3426                             __attribute__((unused)) struct cmdline *cl,
3427                             __attribute__((unused)) void *data)
3428 {
3429         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3430
3431         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3432 }
3433
3434 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3435         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3436                 tx_vlan, "tx_vlan");
3437 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3438         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3439                 set, "set");
3440 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3441         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3442                 port_id, UINT16);
3443 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3444         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3445                 vlan_id, UINT16);
3446 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3447         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3448                 vlan_id_outer, UINT16);
3449
3450 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3451         .f = cmd_tx_vlan_set_qinq_parsed,
3452         .data = NULL,
3453         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3454                 "Enable hardware insertion of double VLAN header "
3455                 "with given TAG Identifiers in packets sent on a port",
3456         .tokens = {
3457                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3458                 (void *)&cmd_tx_vlan_set_qinq_set,
3459                 (void *)&cmd_tx_vlan_set_qinq_portid,
3460                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3461                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3462                 NULL,
3463         },
3464 };
3465
3466 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3467 struct cmd_tx_vlan_set_pvid_result {
3468         cmdline_fixed_string_t tx_vlan;
3469         cmdline_fixed_string_t set;
3470         cmdline_fixed_string_t pvid;
3471         portid_t port_id;
3472         uint16_t vlan_id;
3473         cmdline_fixed_string_t mode;
3474 };
3475
3476 static void
3477 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3478                             __attribute__((unused)) struct cmdline *cl,
3479                             __attribute__((unused)) void *data)
3480 {
3481         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3482
3483         if (strcmp(res->mode, "on") == 0)
3484                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3485         else
3486                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3487 }
3488
3489 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3490         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3491                                  tx_vlan, "tx_vlan");
3492 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3493         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3494                                  set, "set");
3495 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3496         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3497                                  pvid, "pvid");
3498 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3499         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3500                              port_id, UINT16);
3501 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3502         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3503                               vlan_id, UINT16);
3504 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3505         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3506                                  mode, "on#off");
3507
3508 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3509         .f = cmd_tx_vlan_set_pvid_parsed,
3510         .data = NULL,
3511         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3512         .tokens = {
3513                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3514                 (void *)&cmd_tx_vlan_set_pvid_set,
3515                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3516                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3517                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3518                 (void *)&cmd_tx_vlan_set_pvid_mode,
3519                 NULL,
3520         },
3521 };
3522
3523 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3524 struct cmd_tx_vlan_reset_result {
3525         cmdline_fixed_string_t tx_vlan;
3526         cmdline_fixed_string_t reset;
3527         portid_t port_id;
3528 };
3529
3530 static void
3531 cmd_tx_vlan_reset_parsed(void *parsed_result,
3532                          __attribute__((unused)) struct cmdline *cl,
3533                          __attribute__((unused)) void *data)
3534 {
3535         struct cmd_tx_vlan_reset_result *res = parsed_result;
3536
3537         tx_vlan_reset(res->port_id);
3538 }
3539
3540 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3541         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3542                                  tx_vlan, "tx_vlan");
3543 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3544         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3545                                  reset, "reset");
3546 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3547         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3548                               port_id, UINT16);
3549
3550 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3551         .f = cmd_tx_vlan_reset_parsed,
3552         .data = NULL,
3553         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3554                 "VLAN header in packets sent on a port",
3555         .tokens = {
3556                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3557                 (void *)&cmd_tx_vlan_reset_reset,
3558                 (void *)&cmd_tx_vlan_reset_portid,
3559                 NULL,
3560         },
3561 };
3562
3563
3564 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3565 struct cmd_csum_result {
3566         cmdline_fixed_string_t csum;
3567         cmdline_fixed_string_t mode;
3568         cmdline_fixed_string_t proto;
3569         cmdline_fixed_string_t hwsw;
3570         portid_t port_id;
3571 };
3572
3573 static void
3574 csum_show(int port_id)
3575 {
3576         struct rte_eth_dev_info dev_info;
3577         uint16_t ol_flags;
3578
3579         ol_flags = ports[port_id].tx_ol_flags;
3580         printf("Parse tunnel is %s\n",
3581                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3582         printf("IP checksum offload is %s\n",
3583                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3584         printf("UDP checksum offload is %s\n",
3585                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3586         printf("TCP checksum offload is %s\n",
3587                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3588         printf("SCTP checksum offload is %s\n",
3589                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3590         printf("Outer-Ip checksum offload is %s\n",
3591                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3592
3593         /* display warnings if configuration is not supported by the NIC */
3594         rte_eth_dev_info_get(port_id, &dev_info);
3595         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3596                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3597                 printf("Warning: hardware IP checksum enabled but not "
3598                         "supported by port %d\n", port_id);
3599         }
3600         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3601                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3602                 printf("Warning: hardware UDP checksum enabled but not "
3603                         "supported by port %d\n", port_id);
3604         }
3605         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3606                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3607                 printf("Warning: hardware TCP checksum enabled but not "
3608                         "supported by port %d\n", port_id);
3609         }
3610         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3611                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3612                 printf("Warning: hardware SCTP checksum enabled but not "
3613                         "supported by port %d\n", port_id);
3614         }
3615         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3616                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3617                 printf("Warning: hardware outer IP checksum enabled but not "
3618                         "supported by port %d\n", port_id);
3619         }
3620 }
3621
3622 static void
3623 cmd_csum_parsed(void *parsed_result,
3624                        __attribute__((unused)) struct cmdline *cl,
3625                        __attribute__((unused)) void *data)
3626 {
3627         struct cmd_csum_result *res = parsed_result;
3628         int hw = 0;
3629         uint16_t mask = 0;
3630
3631         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3632                 printf("invalid port %d\n", res->port_id);
3633                 return;
3634         }
3635
3636         if (!strcmp(res->mode, "set")) {
3637
3638                 if (!strcmp(res->hwsw, "hw"))
3639                         hw = 1;
3640
3641                 if (!strcmp(res->proto, "ip")) {
3642                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3643                 } else if (!strcmp(res->proto, "udp")) {
3644                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3645                 } else if (!strcmp(res->proto, "tcp")) {
3646                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3647                 } else if (!strcmp(res->proto, "sctp")) {
3648                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3649                 } else if (!strcmp(res->proto, "outer-ip")) {
3650                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3651                 }
3652
3653                 if (hw)
3654                         ports[res->port_id].tx_ol_flags |= mask;
3655                 else
3656                         ports[res->port_id].tx_ol_flags &= (~mask);
3657         }
3658         csum_show(res->port_id);
3659 }
3660
3661 cmdline_parse_token_string_t cmd_csum_csum =
3662         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3663                                 csum, "csum");
3664 cmdline_parse_token_string_t cmd_csum_mode =
3665         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3666                                 mode, "set");
3667 cmdline_parse_token_string_t cmd_csum_proto =
3668         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3669                                 proto, "ip#tcp#udp#sctp#outer-ip");
3670 cmdline_parse_token_string_t cmd_csum_hwsw =
3671         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3672                                 hwsw, "hw#sw");
3673 cmdline_parse_token_num_t cmd_csum_portid =
3674         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3675                                 port_id, UINT16);
3676
3677 cmdline_parse_inst_t cmd_csum_set = {
3678         .f = cmd_csum_parsed,
3679         .data = NULL,
3680         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3681                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3682                 "using csum forward engine",
3683         .tokens = {
3684                 (void *)&cmd_csum_csum,
3685                 (void *)&cmd_csum_mode,
3686                 (void *)&cmd_csum_proto,
3687                 (void *)&cmd_csum_hwsw,
3688                 (void *)&cmd_csum_portid,
3689                 NULL,
3690         },
3691 };
3692
3693 cmdline_parse_token_string_t cmd_csum_mode_show =
3694         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3695                                 mode, "show");
3696
3697 cmdline_parse_inst_t cmd_csum_show = {
3698         .f = cmd_csum_parsed,
3699         .data = NULL,
3700         .help_str = "csum show <port_id>: Show checksum offload configuration",
3701         .tokens = {
3702                 (void *)&cmd_csum_csum,
3703                 (void *)&cmd_csum_mode_show,
3704                 (void *)&cmd_csum_portid,
3705                 NULL,
3706         },
3707 };
3708
3709 /* Enable/disable tunnel parsing */
3710 struct cmd_csum_tunnel_result {
3711         cmdline_fixed_string_t csum;
3712         cmdline_fixed_string_t parse;
3713         cmdline_fixed_string_t onoff;
3714         portid_t port_id;
3715 };
3716
3717 static void
3718 cmd_csum_tunnel_parsed(void *parsed_result,
3719                        __attribute__((unused)) struct cmdline *cl,
3720                        __attribute__((unused)) void *data)
3721 {
3722         struct cmd_csum_tunnel_result *res = parsed_result;
3723
3724         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3725                 return;
3726
3727         if (!strcmp(res->onoff, "on"))
3728                 ports[res->port_id].tx_ol_flags |=
3729                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3730         else
3731                 ports[res->port_id].tx_ol_flags &=
3732                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3733
3734         csum_show(res->port_id);
3735 }
3736
3737 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3738         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3739                                 csum, "csum");
3740 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3741         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3742                                 parse, "parse_tunnel");
3743 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3744         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3745                                 onoff, "on#off");
3746 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3747         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3748                                 port_id, UINT16);
3749
3750 cmdline_parse_inst_t cmd_csum_tunnel = {
3751         .f = cmd_csum_tunnel_parsed,
3752         .data = NULL,
3753         .help_str = "csum parse_tunnel on|off <port_id>: "
3754                 "Enable/Disable parsing of tunnels for csum engine",
3755         .tokens = {
3756                 (void *)&cmd_csum_tunnel_csum,
3757                 (void *)&cmd_csum_tunnel_parse,
3758                 (void *)&cmd_csum_tunnel_onoff,
3759                 (void *)&cmd_csum_tunnel_portid,
3760                 NULL,
3761         },
3762 };
3763
3764 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3765 struct cmd_tso_set_result {
3766         cmdline_fixed_string_t tso;
3767         cmdline_fixed_string_t mode;
3768         uint16_t tso_segsz;
3769         portid_t port_id;
3770 };
3771
3772 static void
3773 cmd_tso_set_parsed(void *parsed_result,
3774                        __attribute__((unused)) struct cmdline *cl,
3775                        __attribute__((unused)) void *data)
3776 {
3777         struct cmd_tso_set_result *res = parsed_result;
3778         struct rte_eth_dev_info dev_info;
3779
3780         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3781                 return;
3782
3783         if (!strcmp(res->mode, "set"))
3784                 ports[res->port_id].tso_segsz = res->tso_segsz;
3785
3786         if (ports[res->port_id].tso_segsz == 0)
3787                 printf("TSO for non-tunneled packets is disabled\n");
3788         else
3789                 printf("TSO segment size for non-tunneled packets is %d\n",
3790                         ports[res->port_id].tso_segsz);
3791
3792         /* display warnings if configuration is not supported by the NIC */
3793         rte_eth_dev_info_get(res->port_id, &dev_info);
3794         if ((ports[res->port_id].tso_segsz != 0) &&
3795                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3796                 printf("Warning: TSO enabled but not "
3797                         "supported by port %d\n", res->port_id);
3798         }
3799 }
3800
3801 cmdline_parse_token_string_t cmd_tso_set_tso =
3802         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3803                                 tso, "tso");
3804 cmdline_parse_token_string_t cmd_tso_set_mode =
3805         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3806                                 mode, "set");
3807 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3808         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3809                                 tso_segsz, UINT16);
3810 cmdline_parse_token_num_t cmd_tso_set_portid =
3811         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3812                                 port_id, UINT16);
3813
3814 cmdline_parse_inst_t cmd_tso_set = {
3815         .f = cmd_tso_set_parsed,
3816         .data = NULL,
3817         .help_str = "tso set <tso_segsz> <port_id>: "
3818                 "Set TSO segment size of non-tunneled packets for csum engine "
3819                 "(0 to disable)",
3820         .tokens = {
3821                 (void *)&cmd_tso_set_tso,
3822                 (void *)&cmd_tso_set_mode,
3823                 (void *)&cmd_tso_set_tso_segsz,
3824                 (void *)&cmd_tso_set_portid,
3825                 NULL,
3826         },
3827 };
3828
3829 cmdline_parse_token_string_t cmd_tso_show_mode =
3830         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3831                                 mode, "show");
3832
3833
3834 cmdline_parse_inst_t cmd_tso_show = {
3835         .f = cmd_tso_set_parsed,
3836         .data = NULL,
3837         .help_str = "tso show <port_id>: "
3838                 "Show TSO segment size of non-tunneled packets for csum engine",
3839         .tokens = {
3840                 (void *)&cmd_tso_set_tso,
3841                 (void *)&cmd_tso_show_mode,
3842                 (void *)&cmd_tso_set_portid,
3843                 NULL,
3844         },
3845 };
3846
3847 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3848 struct cmd_tunnel_tso_set_result {
3849         cmdline_fixed_string_t tso;
3850         cmdline_fixed_string_t mode;
3851         uint16_t tso_segsz;
3852         portid_t port_id;
3853 };
3854
3855 static void
3856 check_tunnel_tso_nic_support(portid_t port_id)
3857 {
3858         struct rte_eth_dev_info dev_info;
3859
3860         rte_eth_dev_info_get(port_id, &dev_info);
3861         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3862                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3863                        "supported by port %d\n", port_id);
3864         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3865                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3866                         "supported by port %d\n", port_id);
3867         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3868                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3869                        "supported by port %d\n", port_id);
3870         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3871                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3872                        "supported by port %d\n", port_id);
3873 }
3874
3875 static void
3876 cmd_tunnel_tso_set_parsed(void *parsed_result,
3877                           __attribute__((unused)) struct cmdline *cl,
3878                           __attribute__((unused)) void *data)
3879 {
3880         struct cmd_tunnel_tso_set_result *res = parsed_result;
3881
3882         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3883                 return;
3884
3885         if (!strcmp(res->mode, "set"))
3886                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3887
3888         if (ports[res->port_id].tunnel_tso_segsz == 0)
3889                 printf("TSO for tunneled packets is disabled\n");
3890         else {
3891                 printf("TSO segment size for tunneled packets is %d\n",
3892                         ports[res->port_id].tunnel_tso_segsz);
3893
3894                 /* Below conditions are needed to make it work:
3895                  * (1) tunnel TSO is supported by the NIC;
3896                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3897                  * are recognized;
3898                  * (3) for tunneled pkts with outer L3 of IPv4,
3899                  * "csum set outer-ip" must be set to hw, because after tso,
3900                  * total_len of outer IP header is changed, and the checksum
3901                  * of outer IP header calculated by sw should be wrong; that
3902                  * is not necessary for IPv6 tunneled pkts because there's no
3903                  * checksum in IP header anymore.
3904                  */
3905                 check_tunnel_tso_nic_support(res->port_id);
3906
3907                 if (!(ports[res->port_id].tx_ol_flags &
3908                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3909                         printf("Warning: csum parse_tunnel must be set "
3910                                 "so that tunneled packets are recognized\n");
3911                 if (!(ports[res->port_id].tx_ol_flags &
3912                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3913                         printf("Warning: csum set outer-ip must be set to hw "
3914                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3915         }
3916 }
3917
3918 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3919         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3920                                 tso, "tunnel_tso");
3921 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3922         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3923                                 mode, "set");
3924 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3925         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3926                                 tso_segsz, UINT16);
3927 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3928         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3929                                 port_id, UINT16);
3930
3931 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3932         .f = cmd_tunnel_tso_set_parsed,
3933         .data = NULL,
3934         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3935                 "Set TSO segment size of tunneled packets for csum engine "
3936                 "(0 to disable)",
3937         .tokens = {
3938                 (void *)&cmd_tunnel_tso_set_tso,
3939                 (void *)&cmd_tunnel_tso_set_mode,
3940                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3941                 (void *)&cmd_tunnel_tso_set_portid,
3942                 NULL,
3943         },
3944 };
3945
3946 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3947         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3948                                 mode, "show");
3949
3950
3951 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3952         .f = cmd_tunnel_tso_set_parsed,
3953         .data = NULL,
3954         .help_str = "tunnel_tso show <port_id> "
3955                 "Show TSO segment size of tunneled packets for csum engine",
3956         .tokens = {
3957                 (void *)&cmd_tunnel_tso_set_tso,
3958                 (void *)&cmd_tunnel_tso_show_mode,
3959                 (void *)&cmd_tunnel_tso_set_portid,
3960                 NULL,
3961         },
3962 };
3963
3964 /* *** SET GRO FOR A PORT *** */
3965 struct cmd_gro_enable_result {
3966         cmdline_fixed_string_t cmd_set;
3967         cmdline_fixed_string_t cmd_port;
3968         cmdline_fixed_string_t cmd_keyword;
3969         cmdline_fixed_string_t cmd_onoff;
3970         portid_t cmd_pid;
3971 };
3972
3973 static void
3974 cmd_gro_enable_parsed(void *parsed_result,
3975                 __attribute__((unused)) struct cmdline *cl,
3976                 __attribute__((unused)) void *data)
3977 {
3978         struct cmd_gro_enable_result *res;
3979
3980         res = parsed_result;
3981         if (!strcmp(res->cmd_keyword, "gro"))
3982                 setup_gro(res->cmd_onoff, res->cmd_pid);
3983 }
3984
3985 cmdline_parse_token_string_t cmd_gro_enable_set =
3986         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3987                         cmd_set, "set");
3988 cmdline_parse_token_string_t cmd_gro_enable_port =
3989         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3990                         cmd_keyword, "port");
3991 cmdline_parse_token_num_t cmd_gro_enable_pid =
3992         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3993                         cmd_pid, UINT16);
3994 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3995         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3996                         cmd_keyword, "gro");
3997 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3998         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3999                         cmd_onoff, "on#off");
4000
4001 cmdline_parse_inst_t cmd_gro_enable = {
4002         .f = cmd_gro_enable_parsed,
4003         .data = NULL,
4004         .help_str = "set port <port_id> gro on|off",
4005         .tokens = {
4006                 (void *)&cmd_gro_enable_set,
4007                 (void *)&cmd_gro_enable_port,
4008                 (void *)&cmd_gro_enable_pid,
4009                 (void *)&cmd_gro_enable_keyword,
4010                 (void *)&cmd_gro_enable_onoff,
4011                 NULL,
4012         },
4013 };
4014
4015 /* *** DISPLAY GRO CONFIGURATION *** */
4016 struct cmd_gro_show_result {
4017         cmdline_fixed_string_t cmd_show;
4018         cmdline_fixed_string_t cmd_port;
4019         cmdline_fixed_string_t cmd_keyword;
4020         portid_t cmd_pid;
4021 };
4022
4023 static void
4024 cmd_gro_show_parsed(void *parsed_result,
4025                 __attribute__((unused)) struct cmdline *cl,
4026                 __attribute__((unused)) void *data)
4027 {
4028         struct cmd_gro_show_result *res;
4029
4030         res = parsed_result;
4031         if (!strcmp(res->cmd_keyword, "gro"))
4032                 show_gro(res->cmd_pid);
4033 }
4034
4035 cmdline_parse_token_string_t cmd_gro_show_show =
4036         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4037                         cmd_show, "show");
4038 cmdline_parse_token_string_t cmd_gro_show_port =
4039         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4040                         cmd_port, "port");
4041 cmdline_parse_token_num_t cmd_gro_show_pid =
4042         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4043                         cmd_pid, UINT16);
4044 cmdline_parse_token_string_t cmd_gro_show_keyword =
4045         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4046                         cmd_keyword, "gro");
4047
4048 cmdline_parse_inst_t cmd_gro_show = {
4049         .f = cmd_gro_show_parsed,
4050         .data = NULL,
4051         .help_str = "show port <port_id> gro",
4052         .tokens = {
4053                 (void *)&cmd_gro_show_show,
4054                 (void *)&cmd_gro_show_port,
4055                 (void *)&cmd_gro_show_pid,
4056                 (void *)&cmd_gro_show_keyword,
4057                 NULL,
4058         },
4059 };
4060
4061 /* *** SET FLUSH CYCLES FOR GRO *** */
4062 struct cmd_gro_flush_result {
4063         cmdline_fixed_string_t cmd_set;
4064         cmdline_fixed_string_t cmd_keyword;
4065         cmdline_fixed_string_t cmd_flush;
4066         uint8_t cmd_cycles;
4067 };
4068
4069 static void
4070 cmd_gro_flush_parsed(void *parsed_result,
4071                 __attribute__((unused)) struct cmdline *cl,
4072                 __attribute__((unused)) void *data)
4073 {
4074         struct cmd_gro_flush_result *res;
4075
4076         res = parsed_result;
4077         if ((!strcmp(res->cmd_keyword, "gro")) &&
4078                         (!strcmp(res->cmd_flush, "flush")))
4079                 setup_gro_flush_cycles(res->cmd_cycles);
4080 }
4081
4082 cmdline_parse_token_string_t cmd_gro_flush_set =
4083         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4084                         cmd_set, "set");
4085 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4086         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4087                         cmd_keyword, "gro");
4088 cmdline_parse_token_string_t cmd_gro_flush_flush =
4089         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4090                         cmd_flush, "flush");
4091 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4092         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4093                         cmd_cycles, UINT8);
4094
4095 cmdline_parse_inst_t cmd_gro_flush = {
4096         .f = cmd_gro_flush_parsed,
4097         .data = NULL,
4098         .help_str = "set gro flush <cycles>",
4099         .tokens = {
4100                 (void *)&cmd_gro_flush_set,
4101                 (void *)&cmd_gro_flush_keyword,
4102                 (void *)&cmd_gro_flush_flush,
4103                 (void *)&cmd_gro_flush_cycles,
4104                 NULL,
4105         },
4106 };
4107
4108 /* *** ENABLE/DISABLE GSO *** */
4109 struct cmd_gso_enable_result {
4110         cmdline_fixed_string_t cmd_set;
4111         cmdline_fixed_string_t cmd_port;
4112         cmdline_fixed_string_t cmd_keyword;
4113         cmdline_fixed_string_t cmd_mode;
4114         portid_t cmd_pid;
4115 };
4116
4117 static void
4118 cmd_gso_enable_parsed(void *parsed_result,
4119                 __attribute__((unused)) struct cmdline *cl,
4120                 __attribute__((unused)) void *data)
4121 {
4122         struct cmd_gso_enable_result *res;
4123
4124         res = parsed_result;
4125         if (!strcmp(res->cmd_keyword, "gso"))
4126                 setup_gso(res->cmd_mode, res->cmd_pid);
4127 }
4128
4129 cmdline_parse_token_string_t cmd_gso_enable_set =
4130         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4131                         cmd_set, "set");
4132 cmdline_parse_token_string_t cmd_gso_enable_port =
4133         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4134                         cmd_port, "port");
4135 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4136         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4137                         cmd_keyword, "gso");
4138 cmdline_parse_token_string_t cmd_gso_enable_mode =
4139         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4140                         cmd_mode, "on#off");
4141 cmdline_parse_token_num_t cmd_gso_enable_pid =
4142         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4143                         cmd_pid, UINT16);
4144
4145 cmdline_parse_inst_t cmd_gso_enable = {
4146         .f = cmd_gso_enable_parsed,
4147         .data = NULL,
4148         .help_str = "set port <port_id> gso on|off",
4149         .tokens = {
4150                 (void *)&cmd_gso_enable_set,
4151                 (void *)&cmd_gso_enable_port,
4152                 (void *)&cmd_gso_enable_pid,
4153                 (void *)&cmd_gso_enable_keyword,
4154                 (void *)&cmd_gso_enable_mode,
4155                 NULL,
4156         },
4157 };
4158
4159 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4160 struct cmd_gso_size_result {
4161         cmdline_fixed_string_t cmd_set;
4162         cmdline_fixed_string_t cmd_keyword;
4163         cmdline_fixed_string_t cmd_segsz;
4164         uint16_t cmd_size;
4165 };
4166
4167 static void
4168 cmd_gso_size_parsed(void *parsed_result,
4169                        __attribute__((unused)) struct cmdline *cl,
4170                        __attribute__((unused)) void *data)
4171 {
4172         struct cmd_gso_size_result *res = parsed_result;
4173
4174         if (test_done == 0) {
4175                 printf("Before setting GSO segsz, please first"
4176                                 " stop fowarding\n");
4177                 return;
4178         }
4179
4180         if (!strcmp(res->cmd_keyword, "gso") &&
4181                         !strcmp(res->cmd_segsz, "segsz")) {
4182                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4183                         printf("gso_size should be larger than %zu."
4184                                         " Please input a legal value\n",
4185                                         RTE_GSO_SEG_SIZE_MIN);
4186                 else
4187                         gso_max_segment_size = res->cmd_size;
4188         }
4189 }
4190
4191 cmdline_parse_token_string_t cmd_gso_size_set =
4192         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4193                                 cmd_set, "set");
4194 cmdline_parse_token_string_t cmd_gso_size_keyword =
4195         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4196                                 cmd_keyword, "gso");
4197 cmdline_parse_token_string_t cmd_gso_size_segsz =
4198         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4199                                 cmd_segsz, "segsz");
4200 cmdline_parse_token_num_t cmd_gso_size_size =
4201         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4202                                 cmd_size, UINT16);
4203
4204 cmdline_parse_inst_t cmd_gso_size = {
4205         .f = cmd_gso_size_parsed,
4206         .data = NULL,
4207         .help_str = "set gso segsz <length>",
4208         .tokens = {
4209                 (void *)&cmd_gso_size_set,
4210                 (void *)&cmd_gso_size_keyword,
4211                 (void *)&cmd_gso_size_segsz,
4212                 (void *)&cmd_gso_size_size,
4213                 NULL,
4214         },
4215 };
4216
4217 /* *** SHOW GSO CONFIGURATION *** */
4218 struct cmd_gso_show_result {
4219         cmdline_fixed_string_t cmd_show;
4220         cmdline_fixed_string_t cmd_port;
4221         cmdline_fixed_string_t cmd_keyword;
4222         portid_t cmd_pid;
4223 };
4224
4225 static void
4226 cmd_gso_show_parsed(void *parsed_result,
4227                        __attribute__((unused)) struct cmdline *cl,
4228                        __attribute__((unused)) void *data)
4229 {
4230         struct cmd_gso_show_result *res = parsed_result;
4231
4232         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4233                 printf("invalid port id %u\n", res->cmd_pid);
4234                 return;
4235         }
4236         if (!strcmp(res->cmd_keyword, "gso")) {
4237                 if (gso_ports[res->cmd_pid].enable) {
4238                         printf("Max GSO'd packet size: %uB\n"
4239                                         "Supported GSO types: TCP/IPv4, "
4240                                         "VxLAN with inner TCP/IPv4 packet, "
4241                                         "GRE with inner TCP/IPv4  packet\n",
4242                                         gso_max_segment_size);
4243                 } else
4244                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4245         }
4246 }
4247
4248 cmdline_parse_token_string_t cmd_gso_show_show =
4249 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4250                 cmd_show, "show");
4251 cmdline_parse_token_string_t cmd_gso_show_port =
4252 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4253                 cmd_port, "port");
4254 cmdline_parse_token_string_t cmd_gso_show_keyword =
4255         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4256                                 cmd_keyword, "gso");
4257 cmdline_parse_token_num_t cmd_gso_show_pid =
4258         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4259                                 cmd_pid, UINT16);
4260
4261 cmdline_parse_inst_t cmd_gso_show = {
4262         .f = cmd_gso_show_parsed,
4263         .data = NULL,
4264         .help_str = "show port <port_id> gso",
4265         .tokens = {
4266                 (void *)&cmd_gso_show_show,
4267                 (void *)&cmd_gso_show_port,
4268                 (void *)&cmd_gso_show_pid,
4269                 (void *)&cmd_gso_show_keyword,
4270                 NULL,
4271         },
4272 };
4273
4274 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4275 struct cmd_set_flush_rx {
4276         cmdline_fixed_string_t set;
4277         cmdline_fixed_string_t flush_rx;
4278         cmdline_fixed_string_t mode;
4279 };
4280
4281 static void
4282 cmd_set_flush_rx_parsed(void *parsed_result,
4283                 __attribute__((unused)) struct cmdline *cl,
4284                 __attribute__((unused)) void *data)
4285 {
4286         struct cmd_set_flush_rx *res = parsed_result;
4287         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4288 }
4289
4290 cmdline_parse_token_string_t cmd_setflushrx_set =
4291         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4292                         set, "set");
4293 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4294         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4295                         flush_rx, "flush_rx");
4296 cmdline_parse_token_string_t cmd_setflushrx_mode =
4297         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4298                         mode, "on#off");
4299
4300
4301 cmdline_parse_inst_t cmd_set_flush_rx = {
4302         .f = cmd_set_flush_rx_parsed,
4303         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4304         .data = NULL,
4305         .tokens = {
4306                 (void *)&cmd_setflushrx_set,
4307                 (void *)&cmd_setflushrx_flush_rx,
4308                 (void *)&cmd_setflushrx_mode,
4309                 NULL,
4310         },
4311 };
4312
4313 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4314 struct cmd_set_link_check {
4315         cmdline_fixed_string_t set;
4316         cmdline_fixed_string_t link_check;
4317         cmdline_fixed_string_t mode;
4318 };
4319
4320 static void
4321 cmd_set_link_check_parsed(void *parsed_result,
4322                 __attribute__((unused)) struct cmdline *cl,
4323                 __attribute__((unused)) void *data)
4324 {
4325         struct cmd_set_link_check *res = parsed_result;
4326         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4327 }
4328
4329 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4330         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4331                         set, "set");
4332 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4333         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4334                         link_check, "link_check");
4335 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4336         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4337                         mode, "on#off");
4338
4339
4340 cmdline_parse_inst_t cmd_set_link_check = {
4341         .f = cmd_set_link_check_parsed,
4342         .help_str = "set link_check on|off: Enable/Disable link status check "
4343                     "when starting/stopping a port",
4344         .data = NULL,
4345         .tokens = {
4346                 (void *)&cmd_setlinkcheck_set,
4347                 (void *)&cmd_setlinkcheck_link_check,
4348                 (void *)&cmd_setlinkcheck_mode,
4349                 NULL,
4350         },
4351 };
4352
4353 /* *** SET NIC BYPASS MODE *** */
4354 struct cmd_set_bypass_mode_result {
4355         cmdline_fixed_string_t set;
4356         cmdline_fixed_string_t bypass;
4357         cmdline_fixed_string_t mode;
4358         cmdline_fixed_string_t value;
4359         portid_t port_id;
4360 };
4361
4362 static void
4363 cmd_set_bypass_mode_parsed(void *parsed_result,
4364                 __attribute__((unused)) struct cmdline *cl,
4365                 __attribute__((unused)) void *data)
4366 {
4367         struct cmd_set_bypass_mode_result *res = parsed_result;
4368         portid_t port_id = res->port_id;
4369         int32_t rc = -EINVAL;
4370
4371 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4372         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4373
4374         if (!strcmp(res->value, "bypass"))
4375                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4376         else if (!strcmp(res->value, "isolate"))
4377                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4378         else
4379                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4380
4381         /* Set the bypass mode for the relevant port. */
4382         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4383 #endif
4384         if (rc != 0)
4385                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4386 }
4387
4388 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4389         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4390                         set, "set");
4391 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4392         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4393                         bypass, "bypass");
4394 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4395         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4396                         mode, "mode");
4397 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4398         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4399                         value, "normal#bypass#isolate");
4400 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4401         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4402                                 port_id, UINT16);
4403
4404 cmdline_parse_inst_t cmd_set_bypass_mode = {
4405         .f = cmd_set_bypass_mode_parsed,
4406         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4407                     "Set the NIC bypass mode for port_id",
4408         .data = NULL,
4409         .tokens = {
4410                 (void *)&cmd_setbypass_mode_set,
4411                 (void *)&cmd_setbypass_mode_bypass,
4412                 (void *)&cmd_setbypass_mode_mode,
4413                 (void *)&cmd_setbypass_mode_value,
4414                 (void *)&cmd_setbypass_mode_port,
4415                 NULL,
4416         },
4417 };
4418
4419 /* *** SET NIC BYPASS EVENT *** */
4420 struct cmd_set_bypass_event_result {
4421         cmdline_fixed_string_t set;
4422         cmdline_fixed_string_t bypass;
4423         cmdline_fixed_string_t event;
4424         cmdline_fixed_string_t event_value;
4425         cmdline_fixed_string_t mode;
4426         cmdline_fixed_string_t mode_value;
4427         portid_t port_id;
4428 };
4429
4430 static void
4431 cmd_set_bypass_event_parsed(void *parsed_result,
4432                 __attribute__((unused)) struct cmdline *cl,
4433                 __attribute__((unused)) void *data)
4434 {
4435         int32_t rc = -EINVAL;
4436         struct cmd_set_bypass_event_result *res = parsed_result;
4437         portid_t port_id = res->port_id;
4438
4439 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4440         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4441         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4442
4443         if (!strcmp(res->event_value, "timeout"))
4444                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4445         else if (!strcmp(res->event_value, "os_on"))
4446                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4447         else if (!strcmp(res->event_value, "os_off"))
4448                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4449         else if (!strcmp(res->event_value, "power_on"))
4450                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4451         else if (!strcmp(res->event_value, "power_off"))
4452                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4453         else
4454                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4455
4456         if (!strcmp(res->mode_value, "bypass"))
4457                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4458         else if (!strcmp(res->mode_value, "isolate"))
4459                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4460         else
4461                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4462
4463         /* Set the watchdog timeout. */
4464         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4465
4466                 rc = -EINVAL;
4467                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4468                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4469                                                            bypass_timeout);
4470                 }
4471                 if (rc != 0) {
4472                         printf("Failed to set timeout value %u "
4473                         "for port %d, errto code: %d.\n",
4474                         bypass_timeout, port_id, rc);
4475                 }
4476         }
4477
4478         /* Set the bypass event to transition to bypass mode. */
4479         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4480                                               bypass_mode);
4481 #endif
4482
4483         if (rc != 0)
4484                 printf("\t Failed to set bypass event for port = %d.\n",
4485                        port_id);
4486 }
4487
4488 cmdline_parse_token_string_t cmd_setbypass_event_set =
4489         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4490                         set, "set");
4491 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4492         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4493                         bypass, "bypass");
4494 cmdline_parse_token_string_t cmd_setbypass_event_event =
4495         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4496                         event, "event");
4497 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4498         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4499                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4500 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4501         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4502                         mode, "mode");
4503 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4504         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4505                         mode_value, "normal#bypass#isolate");
4506 cmdline_parse_token_num_t cmd_setbypass_event_port =
4507         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4508                                 port_id, UINT16);
4509
4510 cmdline_parse_inst_t cmd_set_bypass_event = {
4511         .f = cmd_set_bypass_event_parsed,
4512         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4513                 "power_off mode normal|bypass|isolate <port_id>: "
4514                 "Set the NIC bypass event mode for port_id",
4515         .data = NULL,
4516         .tokens = {
4517                 (void *)&cmd_setbypass_event_set,
4518                 (void *)&cmd_setbypass_event_bypass,
4519                 (void *)&cmd_setbypass_event_event,
4520                 (void *)&cmd_setbypass_event_event_value,
4521                 (void *)&cmd_setbypass_event_mode,
4522                 (void *)&cmd_setbypass_event_mode_value,
4523                 (void *)&cmd_setbypass_event_port,
4524                 NULL,
4525         },
4526 };
4527
4528
4529 /* *** SET NIC BYPASS TIMEOUT *** */
4530 struct cmd_set_bypass_timeout_result {
4531         cmdline_fixed_string_t set;
4532         cmdline_fixed_string_t bypass;
4533         cmdline_fixed_string_t timeout;
4534         cmdline_fixed_string_t value;
4535 };
4536
4537 static void
4538 cmd_set_bypass_timeout_parsed(void *parsed_result,
4539                 __attribute__((unused)) struct cmdline *cl,
4540                 __attribute__((unused)) void *data)
4541 {
4542         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4543
4544 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4545         if (!strcmp(res->value, "1.5"))
4546                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4547         else if (!strcmp(res->value, "2"))
4548                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4549         else if (!strcmp(res->value, "3"))
4550                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4551         else if (!strcmp(res->value, "4"))
4552                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4553         else if (!strcmp(res->value, "8"))
4554                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4555         else if (!strcmp(res->value, "16"))
4556                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4557         else if (!strcmp(res->value, "32"))
4558                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4559         else
4560                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4561 #endif
4562 }
4563
4564 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4566                         set, "set");
4567 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4569                         bypass, "bypass");
4570 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4572                         timeout, "timeout");
4573 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4574         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4575                         value, "0#1.5#2#3#4#8#16#32");
4576
4577 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4578         .f = cmd_set_bypass_timeout_parsed,
4579         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4580                 "Set the NIC bypass watchdog timeout in seconds",
4581         .data = NULL,
4582         .tokens = {
4583                 (void *)&cmd_setbypass_timeout_set,
4584                 (void *)&cmd_setbypass_timeout_bypass,
4585                 (void *)&cmd_setbypass_timeout_timeout,
4586                 (void *)&cmd_setbypass_timeout_value,
4587                 NULL,
4588         },
4589 };
4590
4591 /* *** SHOW NIC BYPASS MODE *** */
4592 struct cmd_show_bypass_config_result {
4593         cmdline_fixed_string_t show;
4594         cmdline_fixed_string_t bypass;
4595         cmdline_fixed_string_t config;
4596         portid_t port_id;
4597 };
4598
4599 static void
4600 cmd_show_bypass_config_parsed(void *parsed_result,
4601                 __attribute__((unused)) struct cmdline *cl,
4602                 __attribute__((unused)) void *data)
4603 {
4604         struct cmd_show_bypass_config_result *res = parsed_result;
4605         portid_t port_id = res->port_id;
4606         int rc = -EINVAL;
4607 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4608         uint32_t event_mode;
4609         uint32_t bypass_mode;
4610         uint32_t timeout = bypass_timeout;
4611         int i;
4612
4613         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4614                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4615         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4616                 {"UNKNOWN", "normal", "bypass", "isolate"};
4617         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4618                 "NONE",
4619                 "OS/board on",
4620                 "power supply on",
4621                 "OS/board off",
4622                 "power supply off",
4623                 "timeout"};
4624         int num_events = (sizeof events) / (sizeof events[0]);
4625
4626         /* Display the bypass mode.*/
4627         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4628                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4629                 return;
4630         }
4631         else {
4632                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4633                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4634
4635                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4636         }
4637
4638         /* Display the bypass timeout.*/
4639         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4640                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4641
4642         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4643
4644         /* Display the bypass events and associated modes. */
4645         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4646
4647                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4648                         printf("\tFailed to get bypass mode for event = %s\n",
4649                                 events[i]);
4650                 } else {
4651                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4652                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4653
4654                         printf("\tbypass event: %-16s = %s\n", events[i],
4655                                 modes[event_mode]);
4656                 }
4657         }
4658 #endif
4659         if (rc != 0)
4660                 printf("\tFailed to get bypass configuration for port = %d\n",
4661                        port_id);
4662 }
4663
4664 cmdline_parse_token_string_t cmd_showbypass_config_show =
4665         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4666                         show, "show");
4667 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4668         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4669                         bypass, "bypass");
4670 cmdline_parse_token_string_t cmd_showbypass_config_config =
4671         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4672                         config, "config");
4673 cmdline_parse_token_num_t cmd_showbypass_config_port =
4674         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4675                                 port_id, UINT16);
4676
4677 cmdline_parse_inst_t cmd_show_bypass_config = {
4678         .f = cmd_show_bypass_config_parsed,
4679         .help_str = "show bypass config <port_id>: "
4680                     "Show the NIC bypass config for port_id",
4681         .data = NULL,
4682         .tokens = {
4683                 (void *)&cmd_showbypass_config_show,
4684                 (void *)&cmd_showbypass_config_bypass,
4685                 (void *)&cmd_showbypass_config_config,
4686                 (void *)&cmd_showbypass_config_port,
4687                 NULL,
4688         },
4689 };
4690
4691 #ifdef RTE_LIBRTE_PMD_BOND
4692 /* *** SET BONDING MODE *** */
4693 struct cmd_set_bonding_mode_result {
4694         cmdline_fixed_string_t set;
4695         cmdline_fixed_string_t bonding;
4696         cmdline_fixed_string_t mode;
4697         uint8_t value;
4698         portid_t port_id;
4699 };
4700
4701 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4702                 __attribute__((unused))  struct cmdline *cl,
4703                 __attribute__((unused)) void *data)
4704 {
4705         struct cmd_set_bonding_mode_result *res = parsed_result;
4706         portid_t port_id = res->port_id;
4707
4708         /* Set the bonding mode for the relevant port. */
4709         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4710                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4711 }
4712
4713 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4714 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4715                 set, "set");
4716 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4717 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4718                 bonding, "bonding");
4719 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4720 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4721                 mode, "mode");
4722 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4723 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4724                 value, UINT8);
4725 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4726 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4727                 port_id, UINT16);
4728
4729 cmdline_parse_inst_t cmd_set_bonding_mode = {
4730                 .f = cmd_set_bonding_mode_parsed,
4731                 .help_str = "set bonding mode <mode_value> <port_id>: "
4732                         "Set the bonding mode for port_id",
4733                 .data = NULL,
4734                 .tokens = {
4735                                 (void *) &cmd_setbonding_mode_set,
4736                                 (void *) &cmd_setbonding_mode_bonding,
4737                                 (void *) &cmd_setbonding_mode_mode,
4738                                 (void *) &cmd_setbonding_mode_value,
4739                                 (void *) &cmd_setbonding_mode_port,
4740                                 NULL
4741                 }
4742 };
4743
4744 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4745 struct cmd_set_bonding_lacp_dedicated_queues_result {
4746         cmdline_fixed_string_t set;
4747         cmdline_fixed_string_t bonding;
4748         cmdline_fixed_string_t lacp;
4749         cmdline_fixed_string_t dedicated_queues;
4750         portid_t port_id;
4751         cmdline_fixed_string_t mode;
4752 };
4753
4754 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4755                 __attribute__((unused))  struct cmdline *cl,
4756                 __attribute__((unused)) void *data)
4757 {
4758         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4759         portid_t port_id = res->port_id;
4760         struct rte_port *port;
4761
4762         port = &ports[port_id];
4763
4764         /** Check if the port is not started **/
4765         if (port->port_status != RTE_PORT_STOPPED) {
4766                 printf("Please stop port %d first\n", port_id);
4767                 return;
4768         }
4769
4770         if (!strcmp(res->mode, "enable")) {
4771                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4772                         printf("Dedicate queues for LACP control packets"
4773                                         " enabled\n");
4774                 else
4775                         printf("Enabling dedicate queues for LACP control "
4776                                         "packets on port %d failed\n", port_id);
4777         } else if (!strcmp(res->mode, "disable")) {
4778                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4779                         printf("Dedicated queues for LACP control packets "
4780                                         "disabled\n");
4781                 else
4782                         printf("Disabling dedicated queues for LACP control "
4783                                         "traffic on port %d failed\n", port_id);
4784         }
4785 }
4786
4787 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4788 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4789                 set, "set");
4790 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4791 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4792                 bonding, "bonding");
4793 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4794 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4795                 lacp, "lacp");
4796 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4797 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4798                 dedicated_queues, "dedicated_queues");
4799 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4800 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4801                 port_id, UINT16);
4802 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4803 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4804                 mode, "enable#disable");
4805
4806 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4807                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4808                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4809                         "enable|disable: "
4810                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4811                 .data = NULL,
4812                 .tokens = {
4813                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4814                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4815                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4816                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4817                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4818                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4819                         NULL
4820                 }
4821 };
4822
4823 /* *** SET BALANCE XMIT POLICY *** */
4824 struct cmd_set_bonding_balance_xmit_policy_result {
4825         cmdline_fixed_string_t set;
4826         cmdline_fixed_string_t bonding;
4827         cmdline_fixed_string_t balance_xmit_policy;
4828         portid_t port_id;
4829         cmdline_fixed_string_t policy;
4830 };
4831
4832 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4833                 __attribute__((unused))  struct cmdline *cl,
4834                 __attribute__((unused)) void *data)
4835 {
4836         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4837         portid_t port_id = res->port_id;
4838         uint8_t policy;
4839
4840         if (!strcmp(res->policy, "l2")) {
4841                 policy = BALANCE_XMIT_POLICY_LAYER2;
4842         } else if (!strcmp(res->policy, "l23")) {
4843                 policy = BALANCE_XMIT_POLICY_LAYER23;
4844         } else if (!strcmp(res->policy, "l34")) {
4845                 policy = BALANCE_XMIT_POLICY_LAYER34;
4846         } else {
4847                 printf("\t Invalid xmit policy selection");
4848                 return;
4849         }
4850
4851         /* Set the bonding mode for the relevant port. */
4852         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4853                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4854                                 port_id);
4855         }
4856 }
4857
4858 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4859 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4860                 set, "set");
4861 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4862 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4863                 bonding, "bonding");
4864 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4865 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4866                 balance_xmit_policy, "balance_xmit_policy");
4867 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4868 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4869                 port_id, UINT16);
4870 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4871 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4872                 policy, "l2#l23#l34");
4873
4874 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4875                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4876                 .help_str = "set bonding balance_xmit_policy <port_id> "
4877                         "l2|l23|l34: "
4878                         "Set the bonding balance_xmit_policy for port_id",
4879                 .data = NULL,
4880                 .tokens = {
4881                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4882                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4883                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4884                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4885                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4886                                 NULL
4887                 }
4888 };
4889
4890 /* *** SHOW NIC BONDING CONFIGURATION *** */
4891 struct cmd_show_bonding_config_result {
4892         cmdline_fixed_string_t show;
4893         cmdline_fixed_string_t bonding;
4894         cmdline_fixed_string_t config;
4895         portid_t port_id;
4896 };
4897
4898 static void cmd_show_bonding_config_parsed(void *parsed_result,
4899                 __attribute__((unused))  struct cmdline *cl,
4900                 __attribute__((unused)) void *data)
4901 {
4902         struct cmd_show_bonding_config_result *res = parsed_result;
4903         int bonding_mode, agg_mode;
4904         portid_t slaves[RTE_MAX_ETHPORTS];
4905         int num_slaves, num_active_slaves;
4906         int primary_id;
4907         int i;
4908         portid_t port_id = res->port_id;
4909
4910         /* Display the bonding mode.*/
4911         bonding_mode = rte_eth_bond_mode_get(port_id);
4912         if (bonding_mode < 0) {
4913                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4914                 return;
4915         } else
4916                 printf("\tBonding mode: %d\n", bonding_mode);
4917
4918         if (bonding_mode == BONDING_MODE_BALANCE) {
4919                 int balance_xmit_policy;
4920
4921                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4922                 if (balance_xmit_policy < 0) {
4923                         printf("\tFailed to get balance xmit policy for port = %d\n",
4924                                         port_id);
4925                         return;
4926                 } else {
4927                         printf("\tBalance Xmit Policy: ");
4928
4929                         switch (balance_xmit_policy) {
4930                         case BALANCE_XMIT_POLICY_LAYER2:
4931                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4932                                 break;
4933                         case BALANCE_XMIT_POLICY_LAYER23:
4934                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4935                                 break;
4936                         case BALANCE_XMIT_POLICY_LAYER34:
4937                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4938                                 break;
4939                         }
4940                         printf("\n");
4941                 }
4942         }
4943
4944         if (bonding_mode == BONDING_MODE_8023AD) {
4945                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4946                 printf("\tIEEE802.3AD Aggregator Mode: ");
4947                 switch (agg_mode) {
4948                 case AGG_BANDWIDTH:
4949                         printf("bandwidth");
4950                         break;
4951                 case AGG_STABLE:
4952                         printf("stable");
4953                         break;
4954                 case AGG_COUNT:
4955                         printf("count");
4956                         break;
4957                 }
4958                 printf("\n");
4959         }
4960
4961         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4962
4963         if (num_slaves < 0) {
4964                 printf("\tFailed to get slave list for port = %d\n", port_id);
4965                 return;
4966         }
4967         if (num_slaves > 0) {
4968                 printf("\tSlaves (%d): [", num_slaves);
4969                 for (i = 0; i < num_slaves - 1; i++)
4970                         printf("%d ", slaves[i]);
4971
4972                 printf("%d]\n", slaves[num_slaves - 1]);
4973         } else {
4974                 printf("\tSlaves: []\n");
4975
4976         }
4977
4978         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4979                         RTE_MAX_ETHPORTS);
4980
4981         if (num_active_slaves < 0) {
4982                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4983                 return;
4984         }
4985         if (num_active_slaves > 0) {
4986                 printf("\tActive Slaves (%d): [", num_active_slaves);
4987                 for (i = 0; i < num_active_slaves - 1; i++)
4988                         printf("%d ", slaves[i]);
4989
4990                 printf("%d]\n", slaves[num_active_slaves - 1]);
4991
4992         } else {
4993                 printf("\tActive Slaves: []\n");
4994
4995         }
4996
4997         primary_id = rte_eth_bond_primary_get(port_id);
4998         if (primary_id < 0) {
4999                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5000                 return;
5001         } else
5002                 printf("\tPrimary: [%d]\n", primary_id);
5003
5004 }
5005
5006 cmdline_parse_token_string_t cmd_showbonding_config_show =
5007 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5008                 show, "show");
5009 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5010 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5011                 bonding, "bonding");
5012 cmdline_parse_token_string_t cmd_showbonding_config_config =
5013 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5014                 config, "config");
5015 cmdline_parse_token_num_t cmd_showbonding_config_port =
5016 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5017                 port_id, UINT16);
5018
5019 cmdline_parse_inst_t cmd_show_bonding_config = {
5020                 .f = cmd_show_bonding_config_parsed,
5021                 .help_str = "show bonding config <port_id>: "
5022                         "Show the bonding config for port_id",
5023                 .data = NULL,
5024                 .tokens = {
5025                                 (void *)&cmd_showbonding_config_show,
5026                                 (void *)&cmd_showbonding_config_bonding,
5027                                 (void *)&cmd_showbonding_config_config,
5028                                 (void *)&cmd_showbonding_config_port,
5029                                 NULL
5030                 }
5031 };
5032
5033 /* *** SET BONDING PRIMARY *** */
5034 struct cmd_set_bonding_primary_result {
5035         cmdline_fixed_string_t set;
5036         cmdline_fixed_string_t bonding;
5037         cmdline_fixed_string_t primary;
5038         portid_t slave_id;
5039         portid_t port_id;
5040 };
5041
5042 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5043                 __attribute__((unused))  struct cmdline *cl,
5044                 __attribute__((unused)) void *data)
5045 {
5046         struct cmd_set_bonding_primary_result *res = parsed_result;
5047         portid_t master_port_id = res->port_id;
5048         portid_t slave_port_id = res->slave_id;
5049
5050         /* Set the primary slave for a bonded device. */
5051         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5052                 printf("\t Failed to set primary slave for port = %d.\n",
5053                                 master_port_id);
5054                 return;
5055         }
5056         init_port_config();
5057 }
5058
5059 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5060 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5061                 set, "set");
5062 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5063 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5064                 bonding, "bonding");
5065 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5066 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5067                 primary, "primary");
5068 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5069 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5070                 slave_id, UINT16);
5071 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5072 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5073                 port_id, UINT16);
5074
5075 cmdline_parse_inst_t cmd_set_bonding_primary = {
5076                 .f = cmd_set_bonding_primary_parsed,
5077                 .help_str = "set bonding primary <slave_id> <port_id>: "
5078                         "Set the primary slave for port_id",
5079                 .data = NULL,
5080                 .tokens = {
5081                                 (void *)&cmd_setbonding_primary_set,
5082                                 (void *)&cmd_setbonding_primary_bonding,
5083                                 (void *)&cmd_setbonding_primary_primary,
5084                                 (void *)&cmd_setbonding_primary_slave,
5085                                 (void *)&cmd_setbonding_primary_port,
5086                                 NULL
5087                 }
5088 };
5089
5090 /* *** ADD SLAVE *** */
5091 struct cmd_add_bonding_slave_result {
5092         cmdline_fixed_string_t add;
5093         cmdline_fixed_string_t bonding;
5094         cmdline_fixed_string_t slave;
5095         portid_t slave_id;
5096         portid_t port_id;
5097 };
5098
5099 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5100                 __attribute__((unused))  struct cmdline *cl,
5101                 __attribute__((unused)) void *data)
5102 {
5103         struct cmd_add_bonding_slave_result *res = parsed_result;
5104         portid_t master_port_id = res->port_id;
5105         portid_t slave_port_id = res->slave_id;
5106
5107         /* add the slave for a bonded device. */
5108         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5109                 printf("\t Failed to add slave %d to master port = %d.\n",
5110                                 slave_port_id, master_port_id);
5111                 return;
5112         }
5113         init_port_config();
5114         set_port_slave_flag(slave_port_id);
5115 }
5116
5117 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5118 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5119                 add, "add");
5120 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5121 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5122                 bonding, "bonding");
5123 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5124 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5125                 slave, "slave");
5126 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5127 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5128                 slave_id, UINT16);
5129 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5130 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5131                 port_id, UINT16);
5132
5133 cmdline_parse_inst_t cmd_add_bonding_slave = {
5134                 .f = cmd_add_bonding_slave_parsed,
5135                 .help_str = "add bonding slave <slave_id> <port_id>: "
5136                         "Add a slave device to a bonded device",
5137                 .data = NULL,
5138                 .tokens = {
5139                                 (void *)&cmd_addbonding_slave_add,
5140                                 (void *)&cmd_addbonding_slave_bonding,
5141                                 (void *)&cmd_addbonding_slave_slave,
5142                                 (void *)&cmd_addbonding_slave_slaveid,
5143                                 (void *)&cmd_addbonding_slave_port,
5144                                 NULL
5145                 }
5146 };
5147
5148 /* *** REMOVE SLAVE *** */
5149 struct cmd_remove_bonding_slave_result {
5150         cmdline_fixed_string_t remove;
5151         cmdline_fixed_string_t bonding;
5152         cmdline_fixed_string_t slave;
5153         portid_t slave_id;
5154         portid_t port_id;
5155 };
5156
5157 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5158                 __attribute__((unused))  struct cmdline *cl,
5159                 __attribute__((unused)) void *data)
5160 {
5161         struct cmd_remove_bonding_slave_result *res = parsed_result;
5162         portid_t master_port_id = res->port_id;
5163         portid_t slave_port_id = res->slave_id;
5164
5165         /* remove the slave from a bonded device. */
5166         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5167                 printf("\t Failed to remove slave %d from master port = %d.\n",
5168                                 slave_port_id, master_port_id);
5169                 return;
5170         }
5171         init_port_config();
5172         clear_port_slave_flag(slave_port_id);
5173 }
5174
5175 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5176                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5177                                 remove, "remove");
5178 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5179                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5180                                 bonding, "bonding");
5181 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5182                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5183                                 slave, "slave");
5184 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5185                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5186                                 slave_id, UINT16);
5187 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5188                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5189                                 port_id, UINT16);
5190
5191 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5192                 .f = cmd_remove_bonding_slave_parsed,
5193                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5194                         "Remove a slave device from a bonded device",
5195                 .data = NULL,
5196                 .tokens = {
5197                                 (void *)&cmd_removebonding_slave_remove,
5198                                 (void *)&cmd_removebonding_slave_bonding,
5199                                 (void *)&cmd_removebonding_slave_slave,
5200                                 (void *)&cmd_removebonding_slave_slaveid,
5201                                 (void *)&cmd_removebonding_slave_port,
5202                                 NULL
5203                 }
5204 };
5205
5206 /* *** CREATE BONDED DEVICE *** */
5207 struct cmd_create_bonded_device_result {
5208         cmdline_fixed_string_t create;
5209         cmdline_fixed_string_t bonded;
5210         cmdline_fixed_string_t device;
5211         uint8_t mode;
5212         uint8_t socket;
5213 };
5214
5215 static int bond_dev_num = 0;
5216
5217 static void cmd_create_bonded_device_parsed(void *parsed_result,
5218                 __attribute__((unused))  struct cmdline *cl,
5219                 __attribute__((unused)) void *data)
5220 {
5221         struct cmd_create_bonded_device_result *res = parsed_result;
5222         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5223         int port_id;
5224
5225         if (test_done == 0) {
5226                 printf("Please stop forwarding first\n");
5227                 return;
5228         }
5229
5230         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5231                         bond_dev_num++);
5232
5233         /* Create a new bonded device. */
5234         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5235         if (port_id < 0) {
5236                 printf("\t Failed to create bonded device.\n");
5237                 return;
5238         } else {
5239                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5240                                 port_id);
5241
5242                 /* Update number of ports */
5243                 nb_ports = rte_eth_dev_count();
5244                 reconfig(port_id, res->socket);
5245                 rte_eth_promiscuous_enable(port_id);
5246         }
5247
5248 }
5249
5250 cmdline_parse_token_string_t cmd_createbonded_device_create =
5251                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5252                                 create, "create");
5253 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5254                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5255                                 bonded, "bonded");
5256 cmdline_parse_token_string_t cmd_createbonded_device_device =
5257                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5258                                 device, "device");
5259 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5260                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5261                                 mode, UINT8);
5262 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5263                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5264                                 socket, UINT8);
5265
5266 cmdline_parse_inst_t cmd_create_bonded_device = {
5267                 .f = cmd_create_bonded_device_parsed,
5268                 .help_str = "create bonded device <mode> <socket>: "
5269                         "Create a new bonded device with specific bonding mode and socket",
5270                 .data = NULL,
5271                 .tokens = {
5272                                 (void *)&cmd_createbonded_device_create,
5273                                 (void *)&cmd_createbonded_device_bonded,
5274                                 (void *)&cmd_createbonded_device_device,
5275                                 (void *)&cmd_createbonded_device_mode,
5276                                 (void *)&cmd_createbonded_device_socket,
5277                                 NULL
5278                 }
5279 };
5280
5281 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5282 struct cmd_set_bond_mac_addr_result {
5283         cmdline_fixed_string_t set;
5284         cmdline_fixed_string_t bonding;
5285         cmdline_fixed_string_t mac_addr;
5286         uint16_t port_num;
5287         struct ether_addr address;
5288 };
5289
5290 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5291                 __attribute__((unused))  struct cmdline *cl,
5292                 __attribute__((unused)) void *data)
5293 {
5294         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5295         int ret;
5296
5297         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5298                 return;
5299
5300         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5301
5302         /* check the return value and print it if is < 0 */
5303         if (ret < 0)
5304                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5305 }
5306
5307 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5308                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5309 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5310                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5311                                 "bonding");
5312 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5313                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5314                                 "mac_addr");
5315 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5316                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5317                                 port_num, UINT16);
5318 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5319                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5320
5321 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5322                 .f = cmd_set_bond_mac_addr_parsed,
5323                 .data = (void *) 0,
5324                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5325                 .tokens = {
5326                                 (void *)&cmd_set_bond_mac_addr_set,
5327                                 (void *)&cmd_set_bond_mac_addr_bonding,
5328                                 (void *)&cmd_set_bond_mac_addr_mac,
5329                                 (void *)&cmd_set_bond_mac_addr_portnum,
5330                                 (void *)&cmd_set_bond_mac_addr_addr,
5331                                 NULL
5332                 }
5333 };
5334
5335
5336 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5337 struct cmd_set_bond_mon_period_result {
5338         cmdline_fixed_string_t set;
5339         cmdline_fixed_string_t bonding;
5340         cmdline_fixed_string_t mon_period;
5341         uint16_t port_num;
5342         uint32_t period_ms;
5343 };
5344
5345 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5346                 __attribute__((unused))  struct cmdline *cl,
5347                 __attribute__((unused)) void *data)
5348 {
5349         struct cmd_set_bond_mon_period_result *res = parsed_result;
5350         int ret;
5351
5352         if (res->port_num >= nb_ports) {
5353                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5354                 return;
5355         }
5356
5357         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5358
5359         /* check the return value and print it if is < 0 */
5360         if (ret < 0)
5361                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5362 }
5363
5364 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5365                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5366                                 set, "set");
5367 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5368                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5369                                 bonding, "bonding");
5370 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5371                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5372                                 mon_period,     "mon_period");
5373 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5374                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5375                                 port_num, UINT16);
5376 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5377                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5378                                 period_ms, UINT32);
5379
5380 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5381                 .f = cmd_set_bond_mon_period_parsed,
5382                 .data = (void *) 0,
5383                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5384                 .tokens = {
5385                                 (void *)&cmd_set_bond_mon_period_set,
5386                                 (void *)&cmd_set_bond_mon_period_bonding,
5387                                 (void *)&cmd_set_bond_mon_period_mon_period,
5388                                 (void *)&cmd_set_bond_mon_period_portnum,
5389                                 (void *)&cmd_set_bond_mon_period_period_ms,
5390                                 NULL
5391                 }
5392 };
5393
5394
5395
5396 struct cmd_set_bonding_agg_mode_policy_result {
5397         cmdline_fixed_string_t set;
5398         cmdline_fixed_string_t bonding;
5399         cmdline_fixed_string_t agg_mode;
5400         uint16_t port_num;
5401         cmdline_fixed_string_t policy;
5402 };
5403
5404
5405 static void
5406 cmd_set_bonding_agg_mode(void *parsed_result,
5407                 __attribute__((unused)) struct cmdline *cl,
5408                 __attribute__((unused)) void *data)
5409 {
5410         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5411         uint8_t policy = AGG_BANDWIDTH;
5412
5413         if (res->port_num >= nb_ports) {
5414                 printf("Port id %d must be less than %d\n",
5415                                 res->port_num, nb_ports);
5416                 return;
5417         }
5418
5419         if (!strcmp(res->policy, "bandwidth"))
5420                 policy = AGG_BANDWIDTH;
5421         else if (!strcmp(res->policy, "stable"))
5422                 policy = AGG_STABLE;
5423         else if (!strcmp(res->policy, "count"))
5424                 policy = AGG_COUNT;
5425
5426         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5427 }
5428
5429
5430 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5431         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5432                                 set, "set");
5433 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5434         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5435                                 bonding, "bonding");
5436
5437 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5438         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5439                                 agg_mode, "agg_mode");
5440
5441 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5442         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5443                                 port_num, UINT16);
5444
5445 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5446         TOKEN_STRING_INITIALIZER(
5447                         struct cmd_set_bonding_balance_xmit_policy_result,
5448                 policy, "stable#bandwidth#count");
5449
5450 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5451         .f = cmd_set_bonding_agg_mode,
5452         .data = (void *) 0,
5453         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5454         .tokens = {
5455                         (void *)&cmd_set_bonding_agg_mode_set,
5456                         (void *)&cmd_set_bonding_agg_mode_bonding,
5457                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5458                         (void *)&cmd_set_bonding_agg_mode_portnum,
5459                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5460                         NULL
5461                 }
5462 };
5463
5464
5465 #endif /* RTE_LIBRTE_PMD_BOND */
5466
5467 /* *** SET FORWARDING MODE *** */
5468 struct cmd_set_fwd_mode_result {
5469         cmdline_fixed_string_t set;
5470         cmdline_fixed_string_t fwd;
5471         cmdline_fixed_string_t mode;
5472 };
5473
5474 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5475                                     __attribute__((unused)) struct cmdline *cl,
5476                                     __attribute__((unused)) void *data)
5477 {
5478         struct cmd_set_fwd_mode_result *res = parsed_result;
5479
5480         retry_enabled = 0;
5481         set_pkt_forwarding_mode(res->mode);
5482 }
5483
5484 cmdline_parse_token_string_t cmd_setfwd_set =
5485         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5486 cmdline_parse_token_string_t cmd_setfwd_fwd =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5488 cmdline_parse_token_string_t cmd_setfwd_mode =
5489         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5490                 "" /* defined at init */);
5491
5492 cmdline_parse_inst_t cmd_set_fwd_mode = {
5493         .f = cmd_set_fwd_mode_parsed,
5494         .data = NULL,
5495         .help_str = NULL, /* defined at init */
5496         .tokens = {
5497                 (void *)&cmd_setfwd_set,
5498                 (void *)&cmd_setfwd_fwd,
5499                 (void *)&cmd_setfwd_mode,
5500                 NULL,
5501         },
5502 };
5503
5504 static void cmd_set_fwd_mode_init(void)
5505 {
5506         char *modes, *c;
5507         static char token[128];
5508         static char help[256];
5509         cmdline_parse_token_string_t *token_struct;
5510
5511         modes = list_pkt_forwarding_modes();
5512         snprintf(help, sizeof(help), "set fwd %s: "
5513                 "Set packet forwarding mode", modes);
5514         cmd_set_fwd_mode.help_str = help;
5515
5516         /* string token separator is # */
5517         for (c = token; *modes != '\0'; modes++)
5518                 if (*modes == '|')
5519                         *c++ = '#';
5520                 else
5521                         *c++ = *modes;
5522         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5523         token_struct->string_data.str = token;
5524 }
5525
5526 /* *** SET RETRY FORWARDING MODE *** */
5527 struct cmd_set_fwd_retry_mode_result {
5528         cmdline_fixed_string_t set;
5529         cmdline_fixed_string_t fwd;
5530         cmdline_fixed_string_t mode;
5531         cmdline_fixed_string_t retry;
5532 };
5533
5534 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5535                             __attribute__((unused)) struct cmdline *cl,
5536                             __attribute__((unused)) void *data)
5537 {
5538         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5539
5540         retry_enabled = 1;
5541         set_pkt_forwarding_mode(res->mode);
5542 }
5543
5544 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5545         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5546                         set, "set");
5547 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5549                         fwd, "fwd");
5550 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5551         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5552                         mode,
5553                 "" /* defined at init */);
5554 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5556                         retry, "retry");
5557
5558 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5559         .f = cmd_set_fwd_retry_mode_parsed,
5560         .data = NULL,
5561         .help_str = NULL, /* defined at init */
5562         .tokens = {
5563                 (void *)&cmd_setfwd_retry_set,
5564                 (void *)&cmd_setfwd_retry_fwd,
5565                 (void *)&cmd_setfwd_retry_mode,
5566                 (void *)&cmd_setfwd_retry_retry,
5567                 NULL,
5568         },
5569 };
5570
5571 static void cmd_set_fwd_retry_mode_init(void)
5572 {
5573         char *modes, *c;
5574         static char token[128];
5575         static char help[256];
5576         cmdline_parse_token_string_t *token_struct;
5577
5578         modes = list_pkt_forwarding_retry_modes();
5579         snprintf(help, sizeof(help), "set fwd %s retry: "
5580                 "Set packet forwarding mode with retry", modes);
5581         cmd_set_fwd_retry_mode.help_str = help;
5582
5583         /* string token separator is # */
5584         for (c = token; *modes != '\0'; modes++)
5585                 if (*modes == '|')
5586                         *c++ = '#';
5587                 else
5588                         *c++ = *modes;
5589         token_struct = (cmdline_parse_token_string_t *)
5590                 cmd_set_fwd_retry_mode.tokens[2];
5591         token_struct->string_data.str = token;
5592 }
5593
5594 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5595 struct cmd_set_burst_tx_retry_result {
5596         cmdline_fixed_string_t set;
5597         cmdline_fixed_string_t burst;
5598         cmdline_fixed_string_t tx;
5599         cmdline_fixed_string_t delay;
5600         uint32_t time;
5601         cmdline_fixed_string_t retry;
5602         uint32_t retry_num;
5603 };
5604
5605 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5606                                         __attribute__((unused)) struct cmdline *cl,
5607                                         __attribute__((unused)) void *data)
5608 {
5609         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5610
5611         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5612                 && !strcmp(res->tx, "tx")) {
5613                 if (!strcmp(res->delay, "delay"))
5614                         burst_tx_delay_time = res->time;
5615                 if (!strcmp(res->retry, "retry"))
5616                         burst_tx_retry_num = res->retry_num;
5617         }
5618
5619 }
5620
5621 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5622         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5623 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5624         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5625                                  "burst");
5626 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5627         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5628 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5630 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5631         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5632 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5633         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5634 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5635         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5636
5637 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5638         .f = cmd_set_burst_tx_retry_parsed,
5639         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5640         .tokens = {
5641                 (void *)&cmd_set_burst_tx_retry_set,
5642                 (void *)&cmd_set_burst_tx_retry_burst,
5643                 (void *)&cmd_set_burst_tx_retry_tx,
5644                 (void *)&cmd_set_burst_tx_retry_delay,
5645                 (void *)&cmd_set_burst_tx_retry_time,
5646                 (void *)&cmd_set_burst_tx_retry_retry,
5647                 (void *)&cmd_set_burst_tx_retry_retry_num,
5648                 NULL,
5649         },
5650 };
5651
5652 /* *** SET PROMISC MODE *** */
5653 struct cmd_set_promisc_mode_result {
5654         cmdline_fixed_string_t set;
5655         cmdline_fixed_string_t promisc;
5656         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5657         uint16_t port_num;               /* valid if "allports" argument == 0 */
5658         cmdline_fixed_string_t mode;
5659 };
5660
5661 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5662                                         __attribute__((unused)) struct cmdline *cl,
5663                                         void *allports)
5664 {
5665         struct cmd_set_promisc_mode_result *res = parsed_result;
5666         int enable;
5667         portid_t i;
5668
5669         if (!strcmp(res->mode, "on"))
5670                 enable = 1;
5671         else
5672                 enable = 0;
5673
5674         /* all ports */
5675         if (allports) {
5676                 RTE_ETH_FOREACH_DEV(i) {
5677                         if (enable)
5678                                 rte_eth_promiscuous_enable(i);
5679                         else
5680                                 rte_eth_promiscuous_disable(i);
5681                 }
5682         }
5683         else {
5684                 if (enable)
5685                         rte_eth_promiscuous_enable(res->port_num);
5686                 else
5687                         rte_eth_promiscuous_disable(res->port_num);
5688         }
5689 }
5690
5691 cmdline_parse_token_string_t cmd_setpromisc_set =
5692         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5693 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5695                                  "promisc");
5696 cmdline_parse_token_string_t cmd_setpromisc_portall =
5697         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5698                                  "all");
5699 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5700         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5701                               UINT8);
5702 cmdline_parse_token_string_t cmd_setpromisc_mode =
5703         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5704                                  "on#off");
5705
5706 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5707         .f = cmd_set_promisc_mode_parsed,
5708         .data = (void *)1,
5709         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5710         .tokens = {
5711                 (void *)&cmd_setpromisc_set,
5712                 (void *)&cmd_setpromisc_promisc,
5713                 (void *)&cmd_setpromisc_portall,
5714                 (void *)&cmd_setpromisc_mode,
5715                 NULL,
5716         },
5717 };
5718
5719 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5720         .f = cmd_set_promisc_mode_parsed,
5721         .data = (void *)0,
5722         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5723         .tokens = {
5724                 (void *)&cmd_setpromisc_set,
5725                 (void *)&cmd_setpromisc_promisc,
5726                 (void *)&cmd_setpromisc_portnum,
5727                 (void *)&cmd_setpromisc_mode,
5728                 NULL,
5729         },
5730 };
5731
5732 /* *** SET ALLMULTI MODE *** */
5733 struct cmd_set_allmulti_mode_result {
5734         cmdline_fixed_string_t set;
5735         cmdline_fixed_string_t allmulti;
5736         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5737         uint16_t port_num;               /* valid if "allports" argument == 0 */
5738         cmdline_fixed_string_t mode;
5739 };
5740
5741 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5742                                         __attribute__((unused)) struct cmdline *cl,
5743                                         void *allports)
5744 {
5745         struct cmd_set_allmulti_mode_result *res = parsed_result;
5746         int enable;
5747         portid_t i;
5748
5749         if (!strcmp(res->mode, "on"))
5750                 enable = 1;
5751         else
5752                 enable = 0;
5753
5754         /* all ports */
5755         if (allports) {
5756                 RTE_ETH_FOREACH_DEV(i) {
5757                         if (enable)
5758                                 rte_eth_allmulticast_enable(i);
5759                         else
5760                                 rte_eth_allmulticast_disable(i);
5761                 }
5762         }
5763         else {
5764                 if (enable)
5765                         rte_eth_allmulticast_enable(res->port_num);
5766                 else
5767                         rte_eth_allmulticast_disable(res->port_num);
5768         }
5769 }
5770
5771 cmdline_parse_token_string_t cmd_setallmulti_set =
5772         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5773 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5774         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5775                                  "allmulti");
5776 cmdline_parse_token_string_t cmd_setallmulti_portall =
5777         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5778                                  "all");
5779 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5780         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5781                               UINT16);
5782 cmdline_parse_token_string_t cmd_setallmulti_mode =
5783         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5784                                  "on#off");
5785
5786 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5787         .f = cmd_set_allmulti_mode_parsed,
5788         .data = (void *)1,
5789         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5790         .tokens = {
5791                 (void *)&cmd_setallmulti_set,
5792                 (void *)&cmd_setallmulti_allmulti,
5793                 (void *)&cmd_setallmulti_portall,
5794                 (void *)&cmd_setallmulti_mode,
5795                 NULL,
5796         },
5797 };
5798
5799 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5800         .f = cmd_set_allmulti_mode_parsed,
5801         .data = (void *)0,
5802         .help_str = "set allmulti <port_id> on|off: "
5803                 "Set allmulti mode on port_id",
5804         .tokens = {
5805                 (void *)&cmd_setallmulti_set,
5806                 (void *)&cmd_setallmulti_allmulti,
5807                 (void *)&cmd_setallmulti_portnum,
5808                 (void *)&cmd_setallmulti_mode,
5809                 NULL,
5810         },
5811 };
5812
5813 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5814 struct cmd_link_flow_ctrl_set_result {
5815         cmdline_fixed_string_t set;
5816         cmdline_fixed_string_t flow_ctrl;
5817         cmdline_fixed_string_t rx;
5818         cmdline_fixed_string_t rx_lfc_mode;
5819         cmdline_fixed_string_t tx;
5820         cmdline_fixed_string_t tx_lfc_mode;
5821         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5822         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5823         cmdline_fixed_string_t autoneg_str;
5824         cmdline_fixed_string_t autoneg;
5825         cmdline_fixed_string_t hw_str;
5826         uint32_t high_water;
5827         cmdline_fixed_string_t lw_str;
5828         uint32_t low_water;
5829         cmdline_fixed_string_t pt_str;
5830         uint16_t pause_time;
5831         cmdline_fixed_string_t xon_str;
5832         uint16_t send_xon;
5833         portid_t port_id;
5834 };
5835
5836 cmdline_parse_token_string_t cmd_lfc_set_set =
5837         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5838                                 set, "set");
5839 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5840         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5841                                 flow_ctrl, "flow_ctrl");
5842 cmdline_parse_token_string_t cmd_lfc_set_rx =
5843         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5844                                 rx, "rx");
5845 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5846         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5847                                 rx_lfc_mode, "on#off");
5848 cmdline_parse_token_string_t cmd_lfc_set_tx =
5849         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5850                                 tx, "tx");
5851 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5852         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5853                                 tx_lfc_mode, "on#off");
5854 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5855         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5856                                 hw_str, "high_water");
5857 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5858         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5859                                 high_water, UINT32);
5860 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5861         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5862                                 lw_str, "low_water");
5863 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5864         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5865                                 low_water, UINT32);
5866 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5867         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5868                                 pt_str, "pause_time");
5869 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5870         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5871                                 pause_time, UINT16);
5872 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5873         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5874                                 xon_str, "send_xon");
5875 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5876         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5877                                 send_xon, UINT16);
5878 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5879         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5880                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5881 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5882         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5883                                 mac_ctrl_frame_fwd_mode, "on#off");
5884 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5885         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5886                                 autoneg_str, "autoneg");
5887 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5888         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5889                                 autoneg, "on#off");
5890 cmdline_parse_token_num_t cmd_lfc_set_portid =
5891         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5892                                 port_id, UINT16);
5893
5894 /* forward declaration */
5895 static void
5896 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5897                               void *data);
5898
5899 cmdline_parse_inst_t cmd_link_flow_control_set = {
5900         .f = cmd_link_flow_ctrl_set_parsed,
5901         .data = NULL,
5902         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5903                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5904                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5905         .tokens = {
5906                 (void *)&cmd_lfc_set_set,
5907                 (void *)&cmd_lfc_set_flow_ctrl,
5908                 (void *)&cmd_lfc_set_rx,
5909                 (void *)&cmd_lfc_set_rx_mode,
5910                 (void *)&cmd_lfc_set_tx,
5911                 (void *)&cmd_lfc_set_tx_mode,
5912                 (void *)&cmd_lfc_set_high_water,
5913                 (void *)&cmd_lfc_set_low_water,
5914                 (void *)&cmd_lfc_set_pause_time,
5915                 (void *)&cmd_lfc_set_send_xon,
5916                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5917                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5918                 (void *)&cmd_lfc_set_autoneg_str,
5919                 (void *)&cmd_lfc_set_autoneg,
5920                 (void *)&cmd_lfc_set_portid,
5921                 NULL,
5922         },
5923 };
5924
5925 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5926         .f = cmd_link_flow_ctrl_set_parsed,
5927         .data = (void *)&cmd_link_flow_control_set_rx,
5928         .help_str = "set flow_ctrl rx on|off <port_id>: "
5929                 "Change rx flow control parameter",
5930         .tokens = {
5931                 (void *)&cmd_lfc_set_set,
5932                 (void *)&cmd_lfc_set_flow_ctrl,
5933                 (void *)&cmd_lfc_set_rx,
5934                 (void *)&cmd_lfc_set_rx_mode,
5935                 (void *)&cmd_lfc_set_portid,
5936                 NULL,
5937         },
5938 };
5939
5940 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5941         .f = cmd_link_flow_ctrl_set_parsed,
5942         .data = (void *)&cmd_link_flow_control_set_tx,
5943         .help_str = "set flow_ctrl tx on|off <port_id>: "
5944                 "Change tx flow control parameter",
5945         .tokens = {
5946                 (void *)&cmd_lfc_set_set,
5947                 (void *)&cmd_lfc_set_flow_ctrl,
5948                 (void *)&cmd_lfc_set_tx,
5949                 (void *)&cmd_lfc_set_tx_mode,
5950                 (void *)&cmd_lfc_set_portid,
5951                 NULL,
5952         },
5953 };
5954
5955 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5956         .f = cmd_link_flow_ctrl_set_parsed,
5957         .data = (void *)&cmd_link_flow_control_set_hw,
5958         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5959                 "Change high water flow control parameter",
5960         .tokens = {
5961                 (void *)&cmd_lfc_set_set,
5962                 (void *)&cmd_lfc_set_flow_ctrl,
5963                 (void *)&cmd_lfc_set_high_water_str,
5964                 (void *)&cmd_lfc_set_high_water,
5965                 (void *)&cmd_lfc_set_portid,
5966                 NULL,
5967         },
5968 };
5969
5970 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5971         .f = cmd_link_flow_ctrl_set_parsed,
5972         .data = (void *)&cmd_link_flow_control_set_lw,
5973         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5974                 "Change low water flow control parameter",
5975         .tokens = {
5976                 (void *)&cmd_lfc_set_set,
5977                 (void *)&cmd_lfc_set_flow_ctrl,
5978                 (void *)&cmd_lfc_set_low_water_str,
5979                 (void *)&cmd_lfc_set_low_water,
5980                 (void *)&cmd_lfc_set_portid,
5981                 NULL,
5982         },
5983 };
5984
5985 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5986         .f = cmd_link_flow_ctrl_set_parsed,
5987         .data = (void *)&cmd_link_flow_control_set_pt,
5988         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5989                 "Change pause time flow control parameter",
5990         .tokens = {
5991                 (void *)&cmd_lfc_set_set,
5992                 (void *)&cmd_lfc_set_flow_ctrl,
5993                 (void *)&cmd_lfc_set_pause_time_str,
5994                 (void *)&cmd_lfc_set_pause_time,
5995                 (void *)&cmd_lfc_set_portid,
5996                 NULL,
5997         },
5998 };
5999
6000 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6001         .f = cmd_link_flow_ctrl_set_parsed,
6002         .data = (void *)&cmd_link_flow_control_set_xon,
6003         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6004                 "Change send_xon flow control parameter",
6005         .tokens = {
6006                 (void *)&cmd_lfc_set_set,
6007                 (void *)&cmd_lfc_set_flow_ctrl,
6008                 (void *)&cmd_lfc_set_send_xon_str,
6009                 (void *)&cmd_lfc_set_send_xon,
6010                 (void *)&cmd_lfc_set_portid,
6011                 NULL,
6012         },
6013 };
6014
6015 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6016         .f = cmd_link_flow_ctrl_set_parsed,
6017         .data = (void *)&cmd_link_flow_control_set_macfwd,
6018         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6019                 "Change mac ctrl fwd flow control parameter",
6020         .tokens = {
6021                 (void *)&cmd_lfc_set_set,
6022                 (void *)&cmd_lfc_set_flow_ctrl,
6023                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6024                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6025                 (void *)&cmd_lfc_set_portid,
6026                 NULL,
6027         },
6028 };
6029
6030 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6031         .f = cmd_link_flow_ctrl_set_parsed,
6032         .data = (void *)&cmd_link_flow_control_set_autoneg,
6033         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6034                 "Change autoneg flow control parameter",
6035         .tokens = {
6036                 (void *)&cmd_lfc_set_set,
6037                 (void *)&cmd_lfc_set_flow_ctrl,
6038                 (void *)&cmd_lfc_set_autoneg_str,
6039                 (void *)&cmd_lfc_set_autoneg,
6040                 (void *)&cmd_lfc_set_portid,
6041                 NULL,
6042         },
6043 };
6044
6045 static void
6046 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6047                               __attribute__((unused)) struct cmdline *cl,
6048                               void *data)
6049 {
6050         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6051         cmdline_parse_inst_t *cmd = data;
6052         struct rte_eth_fc_conf fc_conf;
6053         int rx_fc_en = 0;
6054         int tx_fc_en = 0;
6055         int ret;
6056
6057         /*
6058          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6059          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6060          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6061          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6062          */
6063         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6064                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6065         };
6066
6067         /* Partial command line, retrieve current configuration */
6068         if (cmd) {
6069                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6070                 if (ret != 0) {
6071                         printf("cannot get current flow ctrl parameters, return"
6072                                "code = %d\n", ret);
6073                         return;
6074                 }
6075
6076                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6077                     (fc_conf.mode == RTE_FC_FULL))
6078                         rx_fc_en = 1;
6079                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6080                     (fc_conf.mode == RTE_FC_FULL))
6081                         tx_fc_en = 1;
6082         }
6083
6084         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6085                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6086
6087         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6088                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6089
6090         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6091
6092         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6093                 fc_conf.high_water = res->high_water;
6094
6095         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6096                 fc_conf.low_water = res->low_water;
6097
6098         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6099                 fc_conf.pause_time = res->pause_time;
6100
6101         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6102                 fc_conf.send_xon = res->send_xon;
6103
6104         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6105                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6106                         fc_conf.mac_ctrl_frame_fwd = 1;
6107                 else
6108                         fc_conf.mac_ctrl_frame_fwd = 0;
6109         }
6110
6111         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6112                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6113
6114         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6115         if (ret != 0)
6116                 printf("bad flow contrl parameter, return code = %d \n", ret);
6117 }
6118
6119 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6120 struct cmd_priority_flow_ctrl_set_result {
6121         cmdline_fixed_string_t set;
6122         cmdline_fixed_string_t pfc_ctrl;
6123         cmdline_fixed_string_t rx;
6124         cmdline_fixed_string_t rx_pfc_mode;
6125         cmdline_fixed_string_t tx;
6126         cmdline_fixed_string_t tx_pfc_mode;
6127         uint32_t high_water;
6128         uint32_t low_water;
6129         uint16_t pause_time;
6130         uint8_t  priority;
6131         portid_t port_id;
6132 };
6133
6134 static void
6135 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6136                        __attribute__((unused)) struct cmdline *cl,
6137                        __attribute__((unused)) void *data)
6138 {
6139         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6140         struct rte_eth_pfc_conf pfc_conf;
6141         int rx_fc_enable, tx_fc_enable;
6142         int ret;
6143
6144         /*
6145          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6146          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6147          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6148          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6149          */
6150         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6151                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6152         };
6153
6154         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6155         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6156         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6157         pfc_conf.fc.high_water = res->high_water;
6158         pfc_conf.fc.low_water  = res->low_water;
6159         pfc_conf.fc.pause_time = res->pause_time;
6160         pfc_conf.priority      = res->priority;
6161
6162         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6163         if (ret != 0)
6164                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6165 }
6166
6167 cmdline_parse_token_string_t cmd_pfc_set_set =
6168         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6169                                 set, "set");
6170 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6171         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6172                                 pfc_ctrl, "pfc_ctrl");
6173 cmdline_parse_token_string_t cmd_pfc_set_rx =
6174         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6175                                 rx, "rx");
6176 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6177         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6178                                 rx_pfc_mode, "on#off");
6179 cmdline_parse_token_string_t cmd_pfc_set_tx =
6180         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6181                                 tx, "tx");
6182 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6183         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6184                                 tx_pfc_mode, "on#off");
6185 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6186         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6187                                 high_water, UINT32);
6188 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6189         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6190                                 low_water, UINT32);
6191 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6192         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6193                                 pause_time, UINT16);
6194 cmdline_parse_token_num_t cmd_pfc_set_priority =
6195         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6196                                 priority, UINT8);
6197 cmdline_parse_token_num_t cmd_pfc_set_portid =
6198         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6199                                 port_id, UINT16);
6200
6201 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6202         .f = cmd_priority_flow_ctrl_set_parsed,
6203         .data = NULL,
6204         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6205                 "<pause_time> <priority> <port_id>: "
6206                 "Configure the Ethernet priority flow control",
6207         .tokens = {
6208                 (void *)&cmd_pfc_set_set,
6209                 (void *)&cmd_pfc_set_flow_ctrl,
6210                 (void *)&cmd_pfc_set_rx,
6211                 (void *)&cmd_pfc_set_rx_mode,
6212                 (void *)&cmd_pfc_set_tx,
6213                 (void *)&cmd_pfc_set_tx_mode,
6214                 (void *)&cmd_pfc_set_high_water,
6215                 (void *)&cmd_pfc_set_low_water,
6216                 (void *)&cmd_pfc_set_pause_time,
6217                 (void *)&cmd_pfc_set_priority,
6218                 (void *)&cmd_pfc_set_portid,
6219                 NULL,
6220         },
6221 };
6222
6223 /* *** RESET CONFIGURATION *** */
6224 struct cmd_reset_result {
6225         cmdline_fixed_string_t reset;
6226         cmdline_fixed_string_t def;
6227 };
6228
6229 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6230                              struct cmdline *cl,
6231                              __attribute__((unused)) void *data)
6232 {
6233         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6234         set_def_fwd_config();
6235 }
6236
6237 cmdline_parse_token_string_t cmd_reset_set =
6238         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6239 cmdline_parse_token_string_t cmd_reset_def =
6240         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6241                                  "default");
6242
6243 cmdline_parse_inst_t cmd_reset = {
6244         .f = cmd_reset_parsed,
6245         .data = NULL,
6246         .help_str = "set default: Reset default forwarding configuration",
6247         .tokens = {
6248                 (void *)&cmd_reset_set,
6249                 (void *)&cmd_reset_def,
6250                 NULL,
6251         },
6252 };
6253
6254 /* *** START FORWARDING *** */
6255 struct cmd_start_result {
6256         cmdline_fixed_string_t start;
6257 };
6258
6259 cmdline_parse_token_string_t cmd_start_start =
6260         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6261
6262 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6263                              __attribute__((unused)) struct cmdline *cl,
6264                              __attribute__((unused)) void *data)
6265 {
6266         start_packet_forwarding(0);
6267 }
6268
6269 cmdline_parse_inst_t cmd_start = {
6270         .f = cmd_start_parsed,
6271         .data = NULL,
6272         .help_str = "start: Start packet forwarding",
6273         .tokens = {
6274                 (void *)&cmd_start_start,
6275                 NULL,
6276         },
6277 };
6278
6279 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6280 struct cmd_start_tx_first_result {
6281         cmdline_fixed_string_t start;
6282         cmdline_fixed_string_t tx_first;
6283 };
6284
6285 static void
6286 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6287                           __attribute__((unused)) struct cmdline *cl,
6288                           __attribute__((unused)) void *data)
6289 {
6290         start_packet_forwarding(1);
6291 }
6292
6293 cmdline_parse_token_string_t cmd_start_tx_first_start =
6294         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6295                                  "start");
6296 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6297         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6298                                  tx_first, "tx_first");
6299
6300 cmdline_parse_inst_t cmd_start_tx_first = {
6301         .f = cmd_start_tx_first_parsed,
6302         .data = NULL,
6303         .help_str = "start tx_first: Start packet forwarding, "
6304                 "after sending 1 burst of packets",
6305         .tokens = {
6306                 (void *)&cmd_start_tx_first_start,
6307                 (void *)&cmd_start_tx_first_tx_first,
6308                 NULL,
6309         },
6310 };
6311
6312 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6313 struct cmd_start_tx_first_n_result {
6314         cmdline_fixed_string_t start;
6315         cmdline_fixed_string_t tx_first;
6316         uint32_t tx_num;
6317 };
6318
6319 static void
6320 cmd_start_tx_first_n_parsed(void *parsed_result,
6321                           __attribute__((unused)) struct cmdline *cl,
6322                           __attribute__((unused)) void *data)
6323 {
6324         struct cmd_start_tx_first_n_result *res = parsed_result;
6325
6326         start_packet_forwarding(res->tx_num);
6327 }
6328
6329 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6330         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6331                         start, "start");
6332 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6333         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6334                         tx_first, "tx_first");
6335 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6336         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6337                         tx_num, UINT32);
6338
6339 cmdline_parse_inst_t cmd_start_tx_first_n = {
6340         .f = cmd_start_tx_first_n_parsed,
6341         .data = NULL,
6342         .help_str = "start tx_first <num>: "
6343                 "packet forwarding, after sending <num> bursts of packets",
6344         .tokens = {
6345                 (void *)&cmd_start_tx_first_n_start,
6346                 (void *)&cmd_start_tx_first_n_tx_first,
6347                 (void *)&cmd_start_tx_first_n_tx_num,
6348                 NULL,
6349         },
6350 };
6351
6352 /* *** SET LINK UP *** */
6353 struct cmd_set_link_up_result {
6354         cmdline_fixed_string_t set;
6355         cmdline_fixed_string_t link_up;
6356         cmdline_fixed_string_t port;
6357         portid_t port_id;
6358 };
6359
6360 cmdline_parse_token_string_t cmd_set_link_up_set =
6361         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6362 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6363         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6364                                 "link-up");
6365 cmdline_parse_token_string_t cmd_set_link_up_port =
6366         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6367 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6368         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6369
6370 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6371                              __attribute__((unused)) struct cmdline *cl,
6372                              __attribute__((unused)) void *data)
6373 {
6374         struct cmd_set_link_up_result *res = parsed_result;
6375         dev_set_link_up(res->port_id);
6376 }
6377
6378 cmdline_parse_inst_t cmd_set_link_up = {
6379         .f = cmd_set_link_up_parsed,
6380         .data = NULL,
6381         .help_str = "set link-up port <port id>",
6382         .tokens = {
6383                 (void *)&cmd_set_link_up_set,
6384                 (void *)&cmd_set_link_up_link_up,
6385                 (void *)&cmd_set_link_up_port,
6386                 (void *)&cmd_set_link_up_port_id,
6387                 NULL,
6388         },
6389 };
6390
6391 /* *** SET LINK DOWN *** */
6392 struct cmd_set_link_down_result {
6393         cmdline_fixed_string_t set;
6394         cmdline_fixed_string_t link_down;
6395         cmdline_fixed_string_t port;
6396         portid_t port_id;
6397 };
6398
6399 cmdline_parse_token_string_t cmd_set_link_down_set =
6400         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6401 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6402         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6403                                 "link-down");
6404 cmdline_parse_token_string_t cmd_set_link_down_port =
6405         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6406 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6407         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6408
6409 static void cmd_set_link_down_parsed(
6410                                 __attribute__((unused)) void *parsed_result,
6411                                 __attribute__((unused)) struct cmdline *cl,
6412                                 __attribute__((unused)) void *data)
6413 {
6414         struct cmd_set_link_down_result *res = parsed_result;
6415         dev_set_link_down(res->port_id);
6416 }
6417
6418 cmdline_parse_inst_t cmd_set_link_down = {
6419         .f = cmd_set_link_down_parsed,
6420         .data = NULL,
6421         .help_str = "set link-down port <port id>",
6422         .tokens = {
6423                 (void *)&cmd_set_link_down_set,
6424                 (void *)&cmd_set_link_down_link_down,
6425                 (void *)&cmd_set_link_down_port,
6426                 (void *)&cmd_set_link_down_port_id,
6427                 NULL,
6428         },
6429 };
6430
6431 /* *** SHOW CFG *** */
6432 struct cmd_showcfg_result {
6433         cmdline_fixed_string_t show;
6434         cmdline_fixed_string_t cfg;
6435         cmdline_fixed_string_t what;
6436 };
6437
6438 static void cmd_showcfg_parsed(void *parsed_result,
6439                                __attribute__((unused)) struct cmdline *cl,
6440                                __attribute__((unused)) void *data)
6441 {
6442         struct cmd_showcfg_result *res = parsed_result;
6443         if (!strcmp(res->what, "rxtx"))
6444                 rxtx_config_display();
6445         else if (!strcmp(res->what, "cores"))
6446                 fwd_lcores_config_display();
6447         else if (!strcmp(res->what, "fwd"))
6448                 pkt_fwd_config_display(&cur_fwd_config);
6449         else if (!strcmp(res->what, "txpkts"))
6450                 show_tx_pkt_segments();
6451 }
6452
6453 cmdline_parse_token_string_t cmd_showcfg_show =
6454         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6455 cmdline_parse_token_string_t cmd_showcfg_port =
6456         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6457 cmdline_parse_token_string_t cmd_showcfg_what =
6458         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6459                                  "rxtx#cores#fwd#txpkts");
6460
6461 cmdline_parse_inst_t cmd_showcfg = {
6462         .f = cmd_showcfg_parsed,
6463         .data = NULL,
6464         .help_str = "show config rxtx|cores|fwd|txpkts",
6465         .tokens = {
6466                 (void *)&cmd_showcfg_show,
6467                 (void *)&cmd_showcfg_port,
6468                 (void *)&cmd_showcfg_what,
6469                 NULL,
6470         },
6471 };
6472
6473 /* *** SHOW ALL PORT INFO *** */
6474 struct cmd_showportall_result {
6475         cmdline_fixed_string_t show;
6476         cmdline_fixed_string_t port;
6477         cmdline_fixed_string_t what;
6478         cmdline_fixed_string_t all;
6479 };
6480
6481 static void cmd_showportall_parsed(void *parsed_result,
6482                                 __attribute__((unused)) struct cmdline *cl,
6483                                 __attribute__((unused)) void *data)
6484 {
6485         portid_t i;
6486
6487         struct cmd_showportall_result *res = parsed_result;
6488         if (!strcmp(res->show, "clear")) {
6489                 if (!strcmp(res->what, "stats"))
6490                         RTE_ETH_FOREACH_DEV(i)
6491                                 nic_stats_clear(i);
6492                 else if (!strcmp(res->what, "xstats"))
6493                         RTE_ETH_FOREACH_DEV(i)
6494                                 nic_xstats_clear(i);
6495         } else if (!strcmp(res->what, "info"))
6496                 RTE_ETH_FOREACH_DEV(i)
6497                         port_infos_display(i);
6498         else if (!strcmp(res->what, "stats"))
6499                 RTE_ETH_FOREACH_DEV(i)
6500                         nic_stats_display(i);
6501         else if (!strcmp(res->what, "xstats"))
6502                 RTE_ETH_FOREACH_DEV(i)
6503                         nic_xstats_display(i);
6504         else if (!strcmp(res->what, "fdir"))
6505                 RTE_ETH_FOREACH_DEV(i)
6506                         fdir_get_infos(i);
6507         else if (!strcmp(res->what, "stat_qmap"))
6508                 RTE_ETH_FOREACH_DEV(i)
6509                         nic_stats_mapping_display(i);
6510         else if (!strcmp(res->what, "dcb_tc"))
6511                 RTE_ETH_FOREACH_DEV(i)
6512                         port_dcb_info_display(i);
6513         else if (!strcmp(res->what, "cap"))
6514                 RTE_ETH_FOREACH_DEV(i)
6515                         port_offload_cap_display(i);
6516 }
6517
6518 cmdline_parse_token_string_t cmd_showportall_show =
6519         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6520                                  "show#clear");
6521 cmdline_parse_token_string_t cmd_showportall_port =
6522         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6523 cmdline_parse_token_string_t cmd_showportall_what =
6524         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6525                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6526 cmdline_parse_token_string_t cmd_showportall_all =
6527         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6528 cmdline_parse_inst_t cmd_showportall = {
6529         .f = cmd_showportall_parsed,
6530         .data = NULL,
6531         .help_str = "show|clear port "
6532                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6533         .tokens = {
6534                 (void *)&cmd_showportall_show,
6535                 (void *)&cmd_showportall_port,
6536                 (void *)&cmd_showportall_what,
6537                 (void *)&cmd_showportall_all,
6538                 NULL,
6539         },
6540 };
6541
6542 /* *** SHOW PORT INFO *** */
6543 struct cmd_showport_result {
6544         cmdline_fixed_string_t show;
6545         cmdline_fixed_string_t port;
6546         cmdline_fixed_string_t what;
6547         uint16_t portnum;
6548 };
6549
6550 static void cmd_showport_parsed(void *parsed_result,
6551                                 __attribute__((unused)) struct cmdline *cl,
6552                                 __attribute__((unused)) void *data)
6553 {
6554         struct cmd_showport_result *res = parsed_result;
6555         if (!strcmp(res->show, "clear")) {
6556                 if (!strcmp(res->what, "stats"))
6557                         nic_stats_clear(res->portnum);
6558                 else if (!strcmp(res->what, "xstats"))
6559                         nic_xstats_clear(res->portnum);
6560         } else if (!strcmp(res->what, "info"))
6561                 port_infos_display(res->portnum);
6562         else if (!strcmp(res->what, "stats"))
6563                 nic_stats_display(res->portnum);
6564         else if (!strcmp(res->what, "xstats"))
6565                 nic_xstats_display(res->portnum);
6566         else if (!strcmp(res->what, "fdir"))
6567                  fdir_get_infos(res->portnum);
6568         else if (!strcmp(res->what, "stat_qmap"))
6569                 nic_stats_mapping_display(res->portnum);
6570         else if (!strcmp(res->what, "dcb_tc"))
6571                 port_dcb_info_display(res->portnum);
6572         else if (!strcmp(res->what, "cap"))
6573                 port_offload_cap_display(res->portnum);
6574 }
6575
6576 cmdline_parse_token_string_t cmd_showport_show =
6577         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6578                                  "show#clear");
6579 cmdline_parse_token_string_t cmd_showport_port =
6580         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6581 cmdline_parse_token_string_t cmd_showport_what =
6582         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6583                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6584 cmdline_parse_token_num_t cmd_showport_portnum =
6585         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6586
6587 cmdline_parse_inst_t cmd_showport = {
6588         .f = cmd_showport_parsed,
6589         .data = NULL,
6590         .help_str = "show|clear port "
6591                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6592                 "<port_id>",
6593         .tokens = {
6594                 (void *)&cmd_showport_show,
6595                 (void *)&cmd_showport_port,
6596                 (void *)&cmd_showport_what,
6597                 (void *)&cmd_showport_portnum,
6598                 NULL,
6599         },
6600 };
6601
6602 /* *** SHOW QUEUE INFO *** */
6603 struct cmd_showqueue_result {
6604         cmdline_fixed_string_t show;
6605         cmdline_fixed_string_t type;
6606         cmdline_fixed_string_t what;
6607         uint16_t portnum;
6608         uint16_t queuenum;
6609 };
6610
6611 static void
6612 cmd_showqueue_parsed(void *parsed_result,
6613         __attribute__((unused)) struct cmdline *cl,
6614         __attribute__((unused)) void *data)
6615 {
6616         struct cmd_showqueue_result *res = parsed_result;
6617
6618         if (!strcmp(res->type, "rxq"))
6619                 rx_queue_infos_display(res->portnum, res->queuenum);
6620         else if (!strcmp(res->type, "txq"))
6621                 tx_queue_infos_display(res->portnum, res->queuenum);
6622 }
6623
6624 cmdline_parse_token_string_t cmd_showqueue_show =
6625         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6626 cmdline_parse_token_string_t cmd_showqueue_type =
6627         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6628 cmdline_parse_token_string_t cmd_showqueue_what =
6629         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6630 cmdline_parse_token_num_t cmd_showqueue_portnum =
6631         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6632 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6633         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6634
6635 cmdline_parse_inst_t cmd_showqueue = {
6636         .f = cmd_showqueue_parsed,
6637         .data = NULL,
6638         .help_str = "show rxq|txq info <port_id> <queue_id>",
6639         .tokens = {
6640                 (void *)&cmd_showqueue_show,
6641                 (void *)&cmd_showqueue_type,
6642                 (void *)&cmd_showqueue_what,
6643                 (void *)&cmd_showqueue_portnum,
6644                 (void *)&cmd_showqueue_queuenum,
6645                 NULL,
6646         },
6647 };
6648
6649 /* *** READ PORT REGISTER *** */
6650 struct cmd_read_reg_result {
6651         cmdline_fixed_string_t read;
6652         cmdline_fixed_string_t reg;
6653         portid_t port_id;
6654         uint32_t reg_off;
6655 };
6656
6657 static void
6658 cmd_read_reg_parsed(void *parsed_result,
6659                     __attribute__((unused)) struct cmdline *cl,
6660                     __attribute__((unused)) void *data)
6661 {
6662         struct cmd_read_reg_result *res = parsed_result;
6663         port_reg_display(res->port_id, res->reg_off);
6664 }
6665
6666 cmdline_parse_token_string_t cmd_read_reg_read =
6667         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6668 cmdline_parse_token_string_t cmd_read_reg_reg =
6669         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6670 cmdline_parse_token_num_t cmd_read_reg_port_id =
6671         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6672 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6673         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6674
6675 cmdline_parse_inst_t cmd_read_reg = {
6676         .f = cmd_read_reg_parsed,
6677         .data = NULL,
6678         .help_str = "read reg <port_id> <reg_off>",
6679         .tokens = {
6680                 (void *)&cmd_read_reg_read,
6681                 (void *)&cmd_read_reg_reg,
6682                 (void *)&cmd_read_reg_port_id,
6683                 (void *)&cmd_read_reg_reg_off,
6684                 NULL,
6685         },
6686 };
6687
6688 /* *** READ PORT REGISTER BIT FIELD *** */
6689 struct cmd_read_reg_bit_field_result {
6690         cmdline_fixed_string_t read;
6691         cmdline_fixed_string_t regfield;
6692         portid_t port_id;
6693         uint32_t reg_off;
6694         uint8_t bit1_pos;
6695         uint8_t bit2_pos;
6696 };
6697
6698 static void
6699 cmd_read_reg_bit_field_parsed(void *parsed_result,
6700                               __attribute__((unused)) struct cmdline *cl,
6701                               __attribute__((unused)) void *data)
6702 {
6703         struct cmd_read_reg_bit_field_result *res = parsed_result;
6704         port_reg_bit_field_display(res->port_id, res->reg_off,
6705                                    res->bit1_pos, res->bit2_pos);
6706 }
6707
6708 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6709         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6710                                  "read");
6711 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6712         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6713                                  regfield, "regfield");
6714 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6715         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6716                               UINT16);
6717 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6718         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6719                               UINT32);
6720 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6721         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6722                               UINT8);
6723 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6724         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6725                               UINT8);
6726
6727 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6728         .f = cmd_read_reg_bit_field_parsed,
6729         .data = NULL,
6730         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6731         "Read register bit field between bit_x and bit_y included",
6732         .tokens = {
6733                 (void *)&cmd_read_reg_bit_field_read,
6734                 (void *)&cmd_read_reg_bit_field_regfield,
6735                 (void *)&cmd_read_reg_bit_field_port_id,
6736                 (void *)&cmd_read_reg_bit_field_reg_off,
6737                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6738                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6739                 NULL,
6740         },
6741 };
6742
6743 /* *** READ PORT REGISTER BIT *** */
6744 struct cmd_read_reg_bit_result {
6745         cmdline_fixed_string_t read;
6746         cmdline_fixed_string_t regbit;
6747         portid_t port_id;
6748         uint32_t reg_off;
6749         uint8_t bit_pos;
6750 };
6751
6752 static void
6753 cmd_read_reg_bit_parsed(void *parsed_result,
6754                         __attribute__((unused)) struct cmdline *cl,
6755                         __attribute__((unused)) void *data)
6756 {
6757         struct cmd_read_reg_bit_result *res = parsed_result;
6758         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6759 }
6760
6761 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6762         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6763 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6764         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6765                                  regbit, "regbit");
6766 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6767         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6768 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6769         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6770 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6771         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6772
6773 cmdline_parse_inst_t cmd_read_reg_bit = {
6774         .f = cmd_read_reg_bit_parsed,
6775         .data = NULL,
6776         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6777         .tokens = {
6778                 (void *)&cmd_read_reg_bit_read,
6779                 (void *)&cmd_read_reg_bit_regbit,
6780                 (void *)&cmd_read_reg_bit_port_id,
6781                 (void *)&cmd_read_reg_bit_reg_off,
6782                 (void *)&cmd_read_reg_bit_bit_pos,
6783                 NULL,
6784         },
6785 };
6786
6787 /* *** WRITE PORT REGISTER *** */
6788 struct cmd_write_reg_result {
6789         cmdline_fixed_string_t write;
6790         cmdline_fixed_string_t reg;
6791         portid_t port_id;
6792         uint32_t reg_off;
6793         uint32_t value;
6794 };
6795
6796 static void
6797 cmd_write_reg_parsed(void *parsed_result,
6798                      __attribute__((unused)) struct cmdline *cl,
6799                      __attribute__((unused)) void *data)
6800 {
6801         struct cmd_write_reg_result *res = parsed_result;
6802         port_reg_set(res->port_id, res->reg_off, res->value);
6803 }
6804
6805 cmdline_parse_token_string_t cmd_write_reg_write =
6806         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6807 cmdline_parse_token_string_t cmd_write_reg_reg =
6808         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6809 cmdline_parse_token_num_t cmd_write_reg_port_id =
6810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6811 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6812         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6813 cmdline_parse_token_num_t cmd_write_reg_value =
6814         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6815
6816 cmdline_parse_inst_t cmd_write_reg = {
6817         .f = cmd_write_reg_parsed,
6818         .data = NULL,
6819         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6820         .tokens = {
6821                 (void *)&cmd_write_reg_write,
6822                 (void *)&cmd_write_reg_reg,
6823                 (void *)&cmd_write_reg_port_id,
6824                 (void *)&cmd_write_reg_reg_off,
6825                 (void *)&cmd_write_reg_value,
6826                 NULL,
6827         },
6828 };
6829
6830 /* *** WRITE PORT REGISTER BIT FIELD *** */
6831 struct cmd_write_reg_bit_field_result {
6832         cmdline_fixed_string_t write;
6833         cmdline_fixed_string_t regfield;
6834         portid_t port_id;
6835         uint32_t reg_off;
6836         uint8_t bit1_pos;
6837         uint8_t bit2_pos;
6838         uint32_t value;
6839 };
6840
6841 static void
6842 cmd_write_reg_bit_field_parsed(void *parsed_result,
6843                                __attribute__((unused)) struct cmdline *cl,
6844                                __attribute__((unused)) void *data)
6845 {
6846         struct cmd_write_reg_bit_field_result *res = parsed_result;
6847         port_reg_bit_field_set(res->port_id, res->reg_off,
6848                           res->bit1_pos, res->bit2_pos, res->value);
6849 }
6850
6851 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6852         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6853                                  "write");
6854 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6855         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6856                                  regfield, "regfield");
6857 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6858         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6859                               UINT16);
6860 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6861         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6862                               UINT32);
6863 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6864         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6865                               UINT8);
6866 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6867         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6868                               UINT8);
6869 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6870         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6871                               UINT32);
6872
6873 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6874         .f = cmd_write_reg_bit_field_parsed,
6875         .data = NULL,
6876         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6877                 "<reg_value>: "
6878                 "Set register bit field between bit_x and bit_y included",
6879         .tokens = {
6880                 (void *)&cmd_write_reg_bit_field_write,
6881                 (void *)&cmd_write_reg_bit_field_regfield,
6882                 (void *)&cmd_write_reg_bit_field_port_id,
6883                 (void *)&cmd_write_reg_bit_field_reg_off,
6884                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6885                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6886                 (void *)&cmd_write_reg_bit_field_value,
6887                 NULL,
6888         },
6889 };
6890
6891 /* *** WRITE PORT REGISTER BIT *** */
6892 struct cmd_write_reg_bit_result {
6893         cmdline_fixed_string_t write;
6894         cmdline_fixed_string_t regbit;
6895         portid_t port_id;
6896         uint32_t reg_off;
6897         uint8_t bit_pos;
6898         uint8_t value;
6899 };
6900
6901 static void
6902 cmd_write_reg_bit_parsed(void *parsed_result,
6903                          __attribute__((unused)) struct cmdline *cl,
6904                          __attribute__((unused)) void *data)
6905 {
6906         struct cmd_write_reg_bit_result *res = parsed_result;
6907         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6908 }
6909
6910 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6911         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6912                                  "write");
6913 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6914         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6915                                  regbit, "regbit");
6916 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6917         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6918 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6919         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6920 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6921         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6922 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6923         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6924
6925 cmdline_parse_inst_t cmd_write_reg_bit = {
6926         .f = cmd_write_reg_bit_parsed,
6927         .data = NULL,
6928         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6929                 "0 <= bit_x <= 31",
6930         .tokens = {
6931                 (void *)&cmd_write_reg_bit_write,
6932                 (void *)&cmd_write_reg_bit_regbit,
6933                 (void *)&cmd_write_reg_bit_port_id,
6934                 (void *)&cmd_write_reg_bit_reg_off,
6935                 (void *)&cmd_write_reg_bit_bit_pos,
6936                 (void *)&cmd_write_reg_bit_value,
6937                 NULL,
6938         },
6939 };
6940
6941 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6942 struct cmd_read_rxd_txd_result {
6943         cmdline_fixed_string_t read;
6944         cmdline_fixed_string_t rxd_txd;
6945         portid_t port_id;
6946         uint16_t queue_id;
6947         uint16_t desc_id;
6948 };
6949
6950 static void
6951 cmd_read_rxd_txd_parsed(void *parsed_result,
6952                         __attribute__((unused)) struct cmdline *cl,
6953                         __attribute__((unused)) void *data)
6954 {
6955         struct cmd_read_rxd_txd_result *res = parsed_result;
6956
6957         if (!strcmp(res->rxd_txd, "rxd"))
6958                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6959         else if (!strcmp(res->rxd_txd, "txd"))
6960                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6961 }
6962
6963 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6964         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6965 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6966         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6967                                  "rxd#txd");
6968 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6969         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
6970 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6971         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6972 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6973         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6974
6975 cmdline_parse_inst_t cmd_read_rxd_txd = {
6976         .f = cmd_read_rxd_txd_parsed,
6977         .data = NULL,
6978         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6979         .tokens = {
6980                 (void *)&cmd_read_rxd_txd_read,
6981                 (void *)&cmd_read_rxd_txd_rxd_txd,
6982                 (void *)&cmd_read_rxd_txd_port_id,
6983                 (void *)&cmd_read_rxd_txd_queue_id,
6984                 (void *)&cmd_read_rxd_txd_desc_id,
6985                 NULL,
6986         },
6987 };
6988
6989 /* *** QUIT *** */
6990 struct cmd_quit_result {
6991         cmdline_fixed_string_t quit;
6992 };
6993
6994 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6995                             struct cmdline *cl,
6996                             __attribute__((unused)) void *data)
6997 {
6998         pmd_test_exit();
6999         cmdline_quit(cl);
7000 }
7001
7002 cmdline_parse_token_string_t cmd_quit_quit =
7003         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7004
7005 cmdline_parse_inst_t cmd_quit = {
7006         .f = cmd_quit_parsed,
7007         .data = NULL,
7008         .help_str = "quit: Exit application",
7009         .tokens = {
7010                 (void *)&cmd_quit_quit,
7011                 NULL,
7012         },
7013 };
7014
7015 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7016 struct cmd_mac_addr_result {
7017         cmdline_fixed_string_t mac_addr_cmd;
7018         cmdline_fixed_string_t what;
7019         uint16_t port_num;
7020         struct ether_addr address;
7021 };
7022
7023 static void cmd_mac_addr_parsed(void *parsed_result,
7024                 __attribute__((unused)) struct cmdline *cl,
7025                 __attribute__((unused)) void *data)
7026 {
7027         struct cmd_mac_addr_result *res = parsed_result;
7028         int ret;
7029
7030         if (strcmp(res->what, "add") == 0)
7031                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7032         else if (strcmp(res->what, "set") == 0)
7033                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7034                                                        &res->address);
7035         else
7036                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7037
7038         /* check the return value and print it if is < 0 */
7039         if(ret < 0)
7040                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7041
7042 }
7043
7044 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7045         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7046                                 "mac_addr");
7047 cmdline_parse_token_string_t cmd_mac_addr_what =
7048         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7049                                 "add#remove#set");
7050 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7051                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7052                                         UINT16);
7053 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7054                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7055
7056 cmdline_parse_inst_t cmd_mac_addr = {
7057         .f = cmd_mac_addr_parsed,
7058         .data = (void *)0,
7059         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7060                         "Add/Remove/Set MAC address on port_id",
7061         .tokens = {
7062                 (void *)&cmd_mac_addr_cmd,
7063                 (void *)&cmd_mac_addr_what,
7064                 (void *)&cmd_mac_addr_portnum,
7065                 (void *)&cmd_mac_addr_addr,
7066                 NULL,
7067         },
7068 };
7069
7070
7071 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7072 struct cmd_set_qmap_result {
7073         cmdline_fixed_string_t set;
7074         cmdline_fixed_string_t qmap;
7075         cmdline_fixed_string_t what;
7076         portid_t port_id;
7077         uint16_t queue_id;
7078         uint8_t map_value;
7079 };
7080
7081 static void
7082 cmd_set_qmap_parsed(void *parsed_result,
7083                        __attribute__((unused)) struct cmdline *cl,
7084                        __attribute__((unused)) void *data)
7085 {
7086         struct cmd_set_qmap_result *res = parsed_result;
7087         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7088
7089         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7090 }
7091
7092 cmdline_parse_token_string_t cmd_setqmap_set =
7093         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7094                                  set, "set");
7095 cmdline_parse_token_string_t cmd_setqmap_qmap =
7096         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7097                                  qmap, "stat_qmap");
7098 cmdline_parse_token_string_t cmd_setqmap_what =
7099         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7100                                  what, "tx#rx");
7101 cmdline_parse_token_num_t cmd_setqmap_portid =
7102         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7103                               port_id, UINT16);
7104 cmdline_parse_token_num_t cmd_setqmap_queueid =
7105         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7106                               queue_id, UINT16);
7107 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7108         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7109                               map_value, UINT8);
7110
7111 cmdline_parse_inst_t cmd_set_qmap = {
7112         .f = cmd_set_qmap_parsed,
7113         .data = NULL,
7114         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7115                 "Set statistics mapping value on tx|rx queue_id of port_id",
7116         .tokens = {
7117                 (void *)&cmd_setqmap_set,
7118                 (void *)&cmd_setqmap_qmap,
7119                 (void *)&cmd_setqmap_what,
7120                 (void *)&cmd_setqmap_portid,
7121                 (void *)&cmd_setqmap_queueid,
7122                 (void *)&cmd_setqmap_mapvalue,
7123                 NULL,
7124         },
7125 };
7126
7127 /* *** CONFIGURE UNICAST HASH TABLE *** */
7128 struct cmd_set_uc_hash_table {
7129         cmdline_fixed_string_t set;
7130         cmdline_fixed_string_t port;
7131         portid_t port_id;
7132         cmdline_fixed_string_t what;
7133         struct ether_addr address;
7134         cmdline_fixed_string_t mode;
7135 };
7136
7137 static void
7138 cmd_set_uc_hash_parsed(void *parsed_result,
7139                        __attribute__((unused)) struct cmdline *cl,
7140                        __attribute__((unused)) void *data)
7141 {
7142         int ret=0;
7143         struct cmd_set_uc_hash_table *res = parsed_result;
7144
7145         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7146
7147         if (strcmp(res->what, "uta") == 0)
7148                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7149                                                 &res->address,(uint8_t)is_on);
7150         if (ret < 0)
7151                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7152
7153 }
7154
7155 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7156         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7157                                  set, "set");
7158 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7159         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7160                                  port, "port");
7161 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7162         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7163                               port_id, UINT16);
7164 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7165         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7166                                  what, "uta");
7167 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7168         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7169                                 address);
7170 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7171         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7172                                  mode, "on#off");
7173
7174 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7175         .f = cmd_set_uc_hash_parsed,
7176         .data = NULL,
7177         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7178         .tokens = {
7179                 (void *)&cmd_set_uc_hash_set,
7180                 (void *)&cmd_set_uc_hash_port,
7181                 (void *)&cmd_set_uc_hash_portid,
7182                 (void *)&cmd_set_uc_hash_what,
7183                 (void *)&cmd_set_uc_hash_mac,
7184                 (void *)&cmd_set_uc_hash_mode,
7185                 NULL,
7186         },
7187 };
7188
7189 struct cmd_set_uc_all_hash_table {
7190         cmdline_fixed_string_t set;
7191         cmdline_fixed_string_t port;
7192         portid_t port_id;
7193         cmdline_fixed_string_t what;
7194         cmdline_fixed_string_t value;
7195         cmdline_fixed_string_t mode;
7196 };
7197
7198 static void
7199 cmd_set_uc_all_hash_parsed(void *parsed_result,
7200                        __attribute__((unused)) struct cmdline *cl,
7201                        __attribute__((unused)) void *data)
7202 {
7203         int ret=0;
7204         struct cmd_set_uc_all_hash_table *res = parsed_result;
7205
7206         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7207
7208         if ((strcmp(res->what, "uta") == 0) &&
7209                 (strcmp(res->value, "all") == 0))
7210                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7211         if (ret < 0)
7212                 printf("bad unicast hash table parameter,"
7213                         "return code = %d \n", ret);
7214 }
7215
7216 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7217         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7218                                  set, "set");
7219 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7221                                  port, "port");
7222 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7223         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7224                               port_id, UINT16);
7225 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7226         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7227                                  what, "uta");
7228 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7229         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7230                                 value,"all");
7231 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7232         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7233                                  mode, "on#off");
7234
7235 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7236         .f = cmd_set_uc_all_hash_parsed,
7237         .data = NULL,
7238         .help_str = "set port <port_id> uta all on|off",
7239         .tokens = {
7240                 (void *)&cmd_set_uc_all_hash_set,
7241                 (void *)&cmd_set_uc_all_hash_port,
7242                 (void *)&cmd_set_uc_all_hash_portid,
7243                 (void *)&cmd_set_uc_all_hash_what,
7244                 (void *)&cmd_set_uc_all_hash_value,
7245                 (void *)&cmd_set_uc_all_hash_mode,
7246                 NULL,
7247         },
7248 };
7249
7250 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7251 struct cmd_set_vf_macvlan_filter {
7252         cmdline_fixed_string_t set;
7253         cmdline_fixed_string_t port;
7254         portid_t port_id;
7255         cmdline_fixed_string_t vf;
7256         uint8_t vf_id;
7257         struct ether_addr address;
7258         cmdline_fixed_string_t filter_type;
7259         cmdline_fixed_string_t mode;
7260 };
7261
7262 static void
7263 cmd_set_vf_macvlan_parsed(void *parsed_result,
7264                        __attribute__((unused)) struct cmdline *cl,
7265                        __attribute__((unused)) void *data)
7266 {
7267         int is_on, ret = 0;
7268         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7269         struct rte_eth_mac_filter filter;
7270
7271         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7272
7273         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7274
7275         /* set VF MAC filter */
7276         filter.is_vf = 1;
7277
7278         /* set VF ID */
7279         filter.dst_id = res->vf_id;
7280
7281         if (!strcmp(res->filter_type, "exact-mac"))
7282                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7283         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7284                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7285         else if (!strcmp(res->filter_type, "hashmac"))
7286                 filter.filter_type = RTE_MAC_HASH_MATCH;
7287         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7288                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7289
7290         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7291
7292         if (is_on)
7293                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7294                                         RTE_ETH_FILTER_MACVLAN,
7295                                         RTE_ETH_FILTER_ADD,
7296                                          &filter);
7297         else
7298                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7299                                         RTE_ETH_FILTER_MACVLAN,
7300                                         RTE_ETH_FILTER_DELETE,
7301                                         &filter);
7302
7303         if (ret < 0)
7304                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7305
7306 }
7307
7308 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7309         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7310                                  set, "set");
7311 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7312         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7313                                  port, "port");
7314 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7315         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7316                               port_id, UINT16);
7317 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7318         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7319                                  vf, "vf");
7320 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7321         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7322                                 vf_id, UINT8);
7323 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7324         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7325                                 address);
7326 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7327         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7328                                 filter_type, "exact-mac#exact-mac-vlan"
7329                                 "#hashmac#hashmac-vlan");
7330 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7332                                  mode, "on#off");
7333
7334 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7335         .f = cmd_set_vf_macvlan_parsed,
7336         .data = NULL,
7337         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7338                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7339                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7340                 "hash match rule: hash match of MAC and exact match of VLAN",
7341         .tokens = {
7342                 (void *)&cmd_set_vf_macvlan_set,
7343                 (void *)&cmd_set_vf_macvlan_port,
7344                 (void *)&cmd_set_vf_macvlan_portid,
7345                 (void *)&cmd_set_vf_macvlan_vf,
7346                 (void *)&cmd_set_vf_macvlan_vf_id,
7347                 (void *)&cmd_set_vf_macvlan_mac,
7348                 (void *)&cmd_set_vf_macvlan_filter_type,
7349                 (void *)&cmd_set_vf_macvlan_mode,
7350                 NULL,
7351         },
7352 };
7353
7354 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7355 struct cmd_set_vf_traffic {
7356         cmdline_fixed_string_t set;
7357         cmdline_fixed_string_t port;
7358         portid_t port_id;
7359         cmdline_fixed_string_t vf;
7360         uint8_t vf_id;
7361         cmdline_fixed_string_t what;
7362         cmdline_fixed_string_t mode;
7363 };
7364
7365 static void
7366 cmd_set_vf_traffic_parsed(void *parsed_result,
7367                        __attribute__((unused)) struct cmdline *cl,
7368                        __attribute__((unused)) void *data)
7369 {
7370         struct cmd_set_vf_traffic *res = parsed_result;
7371         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7372         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7373
7374         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7375 }
7376
7377 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7378         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7379                                  set, "set");
7380 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7381         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7382                                  port, "port");
7383 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7384         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7385                               port_id, UINT16);
7386 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7387         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7388                                  vf, "vf");
7389 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7390         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7391                               vf_id, UINT8);
7392 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7393         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7394                                  what, "tx#rx");
7395 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7396         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7397                                  mode, "on#off");
7398
7399 cmdline_parse_inst_t cmd_set_vf_traffic = {
7400         .f = cmd_set_vf_traffic_parsed,
7401         .data = NULL,
7402         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7403         .tokens = {
7404                 (void *)&cmd_setvf_traffic_set,
7405                 (void *)&cmd_setvf_traffic_port,
7406                 (void *)&cmd_setvf_traffic_portid,
7407                 (void *)&cmd_setvf_traffic_vf,
7408                 (void *)&cmd_setvf_traffic_vfid,
7409                 (void *)&cmd_setvf_traffic_what,
7410                 (void *)&cmd_setvf_traffic_mode,
7411                 NULL,
7412         },
7413 };
7414
7415 /* *** CONFIGURE VF RECEIVE MODE *** */
7416 struct cmd_set_vf_rxmode {
7417         cmdline_fixed_string_t set;
7418         cmdline_fixed_string_t port;
7419         portid_t port_id;
7420         cmdline_fixed_string_t vf;
7421         uint8_t vf_id;
7422         cmdline_fixed_string_t what;
7423         cmdline_fixed_string_t mode;
7424         cmdline_fixed_string_t on;
7425 };
7426
7427 static void
7428 cmd_set_vf_rxmode_parsed(void *parsed_result,
7429                        __attribute__((unused)) struct cmdline *cl,
7430                        __attribute__((unused)) void *data)
7431 {
7432         int ret = -ENOTSUP;
7433         uint16_t rx_mode = 0;
7434         struct cmd_set_vf_rxmode *res = parsed_result;
7435
7436         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7437         if (!strcmp(res->what,"rxmode")) {
7438                 if (!strcmp(res->mode, "AUPE"))
7439                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7440                 else if (!strcmp(res->mode, "ROPE"))
7441                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7442                 else if (!strcmp(res->mode, "BAM"))
7443                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7444                 else if (!strncmp(res->mode, "MPE",3))
7445                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7446         }
7447
7448 #ifdef RTE_LIBRTE_IXGBE_PMD
7449         if (ret == -ENOTSUP)
7450                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7451                                                   rx_mode, (uint8_t)is_on);
7452 #endif
7453 #ifdef RTE_LIBRTE_BNXT_PMD
7454         if (ret == -ENOTSUP)
7455                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7456                                                  rx_mode, (uint8_t)is_on);
7457 #endif
7458         if (ret < 0)
7459                 printf("bad VF receive mode parameter, return code = %d \n",
7460                 ret);
7461 }
7462
7463 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7464         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7465                                  set, "set");
7466 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7467         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7468                                  port, "port");
7469 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7470         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7471                               port_id, UINT16);
7472 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7474                                  vf, "vf");
7475 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7476         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7477                               vf_id, UINT8);
7478 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7479         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7480                                  what, "rxmode");
7481 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7482         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7483                                  mode, "AUPE#ROPE#BAM#MPE");
7484 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7485         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7486                                  on, "on#off");
7487
7488 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7489         .f = cmd_set_vf_rxmode_parsed,
7490         .data = NULL,
7491         .help_str = "set port <port_id> vf <vf_id> rxmode "
7492                 "AUPE|ROPE|BAM|MPE on|off",
7493         .tokens = {
7494                 (void *)&cmd_set_vf_rxmode_set,
7495                 (void *)&cmd_set_vf_rxmode_port,
7496                 (void *)&cmd_set_vf_rxmode_portid,
7497                 (void *)&cmd_set_vf_rxmode_vf,
7498                 (void *)&cmd_set_vf_rxmode_vfid,
7499                 (void *)&cmd_set_vf_rxmode_what,
7500                 (void *)&cmd_set_vf_rxmode_mode,
7501                 (void *)&cmd_set_vf_rxmode_on,
7502                 NULL,
7503         },
7504 };
7505
7506 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7507 struct cmd_vf_mac_addr_result {
7508         cmdline_fixed_string_t mac_addr_cmd;
7509         cmdline_fixed_string_t what;
7510         cmdline_fixed_string_t port;
7511         uint16_t port_num;
7512         cmdline_fixed_string_t vf;
7513         uint8_t vf_num;
7514         struct ether_addr address;
7515 };
7516
7517 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7518                 __attribute__((unused)) struct cmdline *cl,
7519                 __attribute__((unused)) void *data)
7520 {
7521         struct cmd_vf_mac_addr_result *res = parsed_result;
7522         int ret = -ENOTSUP;
7523
7524         if (strcmp(res->what, "add") != 0)
7525                 return;
7526
7527 #ifdef RTE_LIBRTE_I40E_PMD
7528         if (ret == -ENOTSUP)
7529                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7530                                                    &res->address);
7531 #endif
7532 #ifdef RTE_LIBRTE_BNXT_PMD
7533         if (ret == -ENOTSUP)
7534                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7535                                                 res->vf_num);
7536 #endif
7537
7538         if(ret < 0)
7539                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7540
7541 }
7542
7543 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7544         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7545                                 mac_addr_cmd,"mac_addr");
7546 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7547         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7548                                 what,"add");
7549 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7550         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7551                                 port,"port");
7552 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7553         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7554                                 port_num, UINT16);
7555 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7556         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7557                                 vf,"vf");
7558 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7559         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7560                                 vf_num, UINT8);
7561 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7562         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7563                                 address);
7564
7565 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7566         .f = cmd_vf_mac_addr_parsed,
7567         .data = (void *)0,
7568         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7569                 "Add MAC address filtering for a VF on port_id",
7570         .tokens = {
7571                 (void *)&cmd_vf_mac_addr_cmd,
7572                 (void *)&cmd_vf_mac_addr_what,
7573                 (void *)&cmd_vf_mac_addr_port,
7574                 (void *)&cmd_vf_mac_addr_portnum,
7575                 (void *)&cmd_vf_mac_addr_vf,
7576                 (void *)&cmd_vf_mac_addr_vfnum,
7577                 (void *)&cmd_vf_mac_addr_addr,
7578                 NULL,
7579         },
7580 };
7581
7582 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7583 struct cmd_vf_rx_vlan_filter {
7584         cmdline_fixed_string_t rx_vlan;
7585         cmdline_fixed_string_t what;
7586         uint16_t vlan_id;
7587         cmdline_fixed_string_t port;
7588         portid_t port_id;
7589         cmdline_fixed_string_t vf;
7590         uint64_t vf_mask;
7591 };
7592
7593 static void
7594 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7595                           __attribute__((unused)) struct cmdline *cl,
7596                           __attribute__((unused)) void *data)
7597 {
7598         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7599         int ret = -ENOTSUP;
7600
7601         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7602
7603 #ifdef RTE_LIBRTE_IXGBE_PMD
7604         if (ret == -ENOTSUP)
7605                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7606                                 res->vlan_id, res->vf_mask, is_add);
7607 #endif
7608 #ifdef RTE_LIBRTE_I40E_PMD
7609         if (ret == -ENOTSUP)
7610                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7611                                 res->vlan_id, res->vf_mask, is_add);
7612 #endif
7613 #ifdef RTE_LIBRTE_BNXT_PMD
7614         if (ret == -ENOTSUP)
7615                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7616                                 res->vlan_id, res->vf_mask, is_add);
7617 #endif
7618
7619         switch (ret) {
7620         case 0:
7621                 break;
7622         case -EINVAL:
7623                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7624                                 res->vlan_id, res->vf_mask);
7625                 break;
7626         case -ENODEV:
7627                 printf("invalid port_id %d\n", res->port_id);
7628                 break;
7629         case -ENOTSUP:
7630                 printf("function not implemented or supported\n");
7631                 break;
7632         default:
7633                 printf("programming error: (%s)\n", strerror(-ret));
7634         }
7635 }
7636
7637 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7638         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7639                                  rx_vlan, "rx_vlan");
7640 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7641         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7642                                  what, "add#rm");
7643 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7644         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7645                               vlan_id, UINT16);
7646 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7647         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7648                                  port, "port");
7649 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7650         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7651                               port_id, UINT16);
7652 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7653         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7654                                  vf, "vf");
7655 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7656         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7657                               vf_mask, UINT64);
7658
7659 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7660         .f = cmd_vf_rx_vlan_filter_parsed,
7661         .data = NULL,
7662         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7663                 "(vf_mask = hexadecimal VF mask)",
7664         .tokens = {
7665                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7666                 (void *)&cmd_vf_rx_vlan_filter_what,
7667                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7668                 (void *)&cmd_vf_rx_vlan_filter_port,
7669                 (void *)&cmd_vf_rx_vlan_filter_portid,
7670                 (void *)&cmd_vf_rx_vlan_filter_vf,
7671                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7672                 NULL,
7673         },
7674 };
7675
7676 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7677 struct cmd_queue_rate_limit_result {
7678         cmdline_fixed_string_t set;
7679         cmdline_fixed_string_t port;
7680         uint16_t port_num;
7681         cmdline_fixed_string_t queue;
7682         uint8_t queue_num;
7683         cmdline_fixed_string_t rate;
7684         uint16_t rate_num;
7685 };
7686
7687 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7688                 __attribute__((unused)) struct cmdline *cl,
7689                 __attribute__((unused)) void *data)
7690 {
7691         struct cmd_queue_rate_limit_result *res = parsed_result;
7692         int ret = 0;
7693
7694         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7695                 && (strcmp(res->queue, "queue") == 0)
7696                 && (strcmp(res->rate, "rate") == 0))
7697                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7698                                         res->rate_num);
7699         if (ret < 0)
7700                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7701
7702 }
7703
7704 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7705         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7706                                 set, "set");
7707 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7708         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7709                                 port, "port");
7710 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7711         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7712                                 port_num, UINT16);
7713 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7714         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7715                                 queue, "queue");
7716 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7717         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7718                                 queue_num, UINT8);
7719 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7720         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7721                                 rate, "rate");
7722 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7723         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7724                                 rate_num, UINT16);
7725
7726 cmdline_parse_inst_t cmd_queue_rate_limit = {
7727         .f = cmd_queue_rate_limit_parsed,
7728         .data = (void *)0,
7729         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7730                 "Set rate limit for a queue on port_id",
7731         .tokens = {
7732                 (void *)&cmd_queue_rate_limit_set,
7733                 (void *)&cmd_queue_rate_limit_port,
7734                 (void *)&cmd_queue_rate_limit_portnum,
7735                 (void *)&cmd_queue_rate_limit_queue,
7736                 (void *)&cmd_queue_rate_limit_queuenum,
7737                 (void *)&cmd_queue_rate_limit_rate,
7738                 (void *)&cmd_queue_rate_limit_ratenum,
7739                 NULL,
7740         },
7741 };
7742
7743 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7744 struct cmd_vf_rate_limit_result {
7745         cmdline_fixed_string_t set;
7746         cmdline_fixed_string_t port;
7747         uint16_t port_num;
7748         cmdline_fixed_string_t vf;
7749         uint8_t vf_num;
7750         cmdline_fixed_string_t rate;
7751         uint16_t rate_num;
7752         cmdline_fixed_string_t q_msk;
7753         uint64_t q_msk_val;
7754 };
7755
7756 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7757                 __attribute__((unused)) struct cmdline *cl,
7758                 __attribute__((unused)) void *data)
7759 {
7760         struct cmd_vf_rate_limit_result *res = parsed_result;
7761         int ret = 0;
7762
7763         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7764                 && (strcmp(res->vf, "vf") == 0)
7765                 && (strcmp(res->rate, "rate") == 0)
7766                 && (strcmp(res->q_msk, "queue_mask") == 0))
7767                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7768                                         res->rate_num, res->q_msk_val);
7769         if (ret < 0)
7770                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7771
7772 }
7773
7774 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7775         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7776                                 set, "set");
7777 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7778         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7779                                 port, "port");
7780 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7781         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7782                                 port_num, UINT16);
7783 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7784         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7785                                 vf, "vf");
7786 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7787         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7788                                 vf_num, UINT8);
7789 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7790         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7791                                 rate, "rate");
7792 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7793         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7794                                 rate_num, UINT16);
7795 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7796         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7797                                 q_msk, "queue_mask");
7798 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7799         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7800                                 q_msk_val, UINT64);
7801
7802 cmdline_parse_inst_t cmd_vf_rate_limit = {
7803         .f = cmd_vf_rate_limit_parsed,
7804         .data = (void *)0,
7805         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7806                 "queue_mask <queue_mask_value>: "
7807                 "Set rate limit for queues of VF on port_id",
7808         .tokens = {
7809                 (void *)&cmd_vf_rate_limit_set,
7810                 (void *)&cmd_vf_rate_limit_port,
7811                 (void *)&cmd_vf_rate_limit_portnum,
7812                 (void *)&cmd_vf_rate_limit_vf,
7813                 (void *)&cmd_vf_rate_limit_vfnum,
7814                 (void *)&cmd_vf_rate_limit_rate,
7815                 (void *)&cmd_vf_rate_limit_ratenum,
7816                 (void *)&cmd_vf_rate_limit_q_msk,
7817                 (void *)&cmd_vf_rate_limit_q_msk_val,
7818                 NULL,
7819         },
7820 };
7821
7822 /* *** ADD TUNNEL FILTER OF A PORT *** */
7823 struct cmd_tunnel_filter_result {
7824         cmdline_fixed_string_t cmd;
7825         cmdline_fixed_string_t what;
7826         portid_t port_id;
7827         struct ether_addr outer_mac;
7828         struct ether_addr inner_mac;
7829         cmdline_ipaddr_t ip_value;
7830         uint16_t inner_vlan;
7831         cmdline_fixed_string_t tunnel_type;
7832         cmdline_fixed_string_t filter_type;
7833         uint32_t tenant_id;
7834         uint16_t queue_num;
7835 };
7836
7837 static void
7838 cmd_tunnel_filter_parsed(void *parsed_result,
7839                           __attribute__((unused)) struct cmdline *cl,
7840                           __attribute__((unused)) void *data)
7841 {
7842         struct cmd_tunnel_filter_result *res = parsed_result;
7843         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7844         int ret = 0;
7845
7846         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7847
7848         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7849         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7850         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7851
7852         if (res->ip_value.family == AF_INET) {
7853                 tunnel_filter_conf.ip_addr.ipv4_addr =
7854                         res->ip_value.addr.ipv4.s_addr;
7855                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7856         } else {
7857                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7858                         &(res->ip_value.addr.ipv6),
7859                         sizeof(struct in6_addr));
7860                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7861         }
7862
7863         if (!strcmp(res->filter_type, "imac-ivlan"))
7864                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7865         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7866                 tunnel_filter_conf.filter_type =
7867                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7868         else if (!strcmp(res->filter_type, "imac-tenid"))
7869                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7870         else if (!strcmp(res->filter_type, "imac"))
7871                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7872         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7873                 tunnel_filter_conf.filter_type =
7874                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7875         else if (!strcmp(res->filter_type, "oip"))
7876                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7877         else if (!strcmp(res->filter_type, "iip"))
7878                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7879         else {
7880                 printf("The filter type is not supported");
7881                 return;
7882         }
7883
7884         if (!strcmp(res->tunnel_type, "vxlan"))
7885                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7886         else if (!strcmp(res->tunnel_type, "nvgre"))
7887                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7888         else if (!strcmp(res->tunnel_type, "ipingre"))
7889                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7890         else {
7891                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7892                 return;
7893         }
7894
7895         tunnel_filter_conf.tenant_id = res->tenant_id;
7896         tunnel_filter_conf.queue_id = res->queue_num;
7897         if (!strcmp(res->what, "add"))
7898                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7899                                         RTE_ETH_FILTER_TUNNEL,
7900                                         RTE_ETH_FILTER_ADD,
7901                                         &tunnel_filter_conf);
7902         else
7903                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7904                                         RTE_ETH_FILTER_TUNNEL,
7905                                         RTE_ETH_FILTER_DELETE,
7906                                         &tunnel_filter_conf);
7907         if (ret < 0)
7908                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7909                                 strerror(-ret));
7910
7911 }
7912 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7913         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7914         cmd, "tunnel_filter");
7915 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7916         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7917         what, "add#rm");
7918 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7919         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7920         port_id, UINT16);
7921 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7922         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7923         outer_mac);
7924 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7925         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7926         inner_mac);
7927 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7928         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7929         inner_vlan, UINT16);
7930 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7931         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7932         ip_value);
7933 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7934         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7935         tunnel_type, "vxlan#nvgre#ipingre");
7936
7937 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7938         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7939         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7940                 "imac#omac-imac-tenid");
7941 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7942         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7943         tenant_id, UINT32);
7944 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7945         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7946         queue_num, UINT16);
7947
7948 cmdline_parse_inst_t cmd_tunnel_filter = {
7949         .f = cmd_tunnel_filter_parsed,
7950         .data = (void *)0,
7951         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7952                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7953                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7954                 "<queue_id>: Add/Rm tunnel filter of a port",
7955         .tokens = {
7956                 (void *)&cmd_tunnel_filter_cmd,
7957                 (void *)&cmd_tunnel_filter_what,
7958                 (void *)&cmd_tunnel_filter_port_id,
7959                 (void *)&cmd_tunnel_filter_outer_mac,
7960                 (void *)&cmd_tunnel_filter_inner_mac,
7961                 (void *)&cmd_tunnel_filter_ip_value,
7962                 (void *)&cmd_tunnel_filter_innner_vlan,
7963                 (void *)&cmd_tunnel_filter_tunnel_type,
7964                 (void *)&cmd_tunnel_filter_filter_type,
7965                 (void *)&cmd_tunnel_filter_tenant_id,
7966                 (void *)&cmd_tunnel_filter_queue_num,
7967                 NULL,
7968         },
7969 };
7970
7971 /* *** CONFIGURE TUNNEL UDP PORT *** */
7972 struct cmd_tunnel_udp_config {
7973         cmdline_fixed_string_t cmd;
7974         cmdline_fixed_string_t what;
7975         uint16_t udp_port;
7976         portid_t port_id;
7977 };
7978
7979 static void
7980 cmd_tunnel_udp_config_parsed(void *parsed_result,
7981                           __attribute__((unused)) struct cmdline *cl,
7982                           __attribute__((unused)) void *data)
7983 {
7984         struct cmd_tunnel_udp_config *res = parsed_result;
7985         struct rte_eth_udp_tunnel tunnel_udp;
7986         int ret;
7987
7988         tunnel_udp.udp_port = res->udp_port;
7989
7990         if (!strcmp(res->cmd, "rx_vxlan_port"))
7991                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7992
7993         if (!strcmp(res->what, "add"))
7994                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7995                                                       &tunnel_udp);
7996         else
7997                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7998                                                          &tunnel_udp);
7999
8000         if (ret < 0)
8001                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8002 }
8003
8004 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8005         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8006                                 cmd, "rx_vxlan_port");
8007 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8008         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8009                                 what, "add#rm");
8010 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8011         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8012                                 udp_port, UINT16);
8013 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8014         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8015                                 port_id, UINT16);
8016
8017 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8018         .f = cmd_tunnel_udp_config_parsed,
8019         .data = (void *)0,
8020         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8021                 "Add/Remove a tunneling UDP port filter",
8022         .tokens = {
8023                 (void *)&cmd_tunnel_udp_config_cmd,
8024                 (void *)&cmd_tunnel_udp_config_what,
8025                 (void *)&cmd_tunnel_udp_config_udp_port,
8026                 (void *)&cmd_tunnel_udp_config_port_id,
8027                 NULL,
8028         },
8029 };
8030
8031 /* *** GLOBAL CONFIG *** */
8032 struct cmd_global_config_result {
8033         cmdline_fixed_string_t cmd;
8034         portid_t port_id;
8035         cmdline_fixed_string_t cfg_type;
8036         uint8_t len;
8037 };
8038
8039 static void
8040 cmd_global_config_parsed(void *parsed_result,
8041                          __attribute__((unused)) struct cmdline *cl,
8042                          __attribute__((unused)) void *data)
8043 {
8044         struct cmd_global_config_result *res = parsed_result;
8045         struct rte_eth_global_cfg conf;
8046         int ret;
8047
8048         memset(&conf, 0, sizeof(conf));
8049         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8050         conf.cfg.gre_key_len = res->len;
8051         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8052                                       RTE_ETH_FILTER_SET, &conf);
8053         if (ret != 0)
8054                 printf("Global config error\n");
8055 }
8056
8057 cmdline_parse_token_string_t cmd_global_config_cmd =
8058         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8059                 "global_config");
8060 cmdline_parse_token_num_t cmd_global_config_port_id =
8061         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8062                                UINT16);
8063 cmdline_parse_token_string_t cmd_global_config_type =
8064         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8065                 cfg_type, "gre-key-len");
8066 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8067         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8068                 len, UINT8);
8069
8070 cmdline_parse_inst_t cmd_global_config = {
8071         .f = cmd_global_config_parsed,
8072         .data = (void *)NULL,
8073         .help_str = "global_config <port_id> gre-key-len <key_len>",
8074         .tokens = {
8075                 (void *)&cmd_global_config_cmd,
8076                 (void *)&cmd_global_config_port_id,
8077                 (void *)&cmd_global_config_type,
8078                 (void *)&cmd_global_config_gre_key_len,
8079                 NULL,
8080         },
8081 };
8082
8083 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8084 struct cmd_set_mirror_mask_result {
8085         cmdline_fixed_string_t set;
8086         cmdline_fixed_string_t port;
8087         portid_t port_id;
8088         cmdline_fixed_string_t mirror;
8089         uint8_t rule_id;
8090         cmdline_fixed_string_t what;
8091         cmdline_fixed_string_t value;
8092         cmdline_fixed_string_t dstpool;
8093         uint8_t dstpool_id;
8094         cmdline_fixed_string_t on;
8095 };
8096
8097 cmdline_parse_token_string_t cmd_mirror_mask_set =
8098         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8099                                 set, "set");
8100 cmdline_parse_token_string_t cmd_mirror_mask_port =
8101         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8102                                 port, "port");
8103 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8104         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8105                                 port_id, UINT16);
8106 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8107         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8108                                 mirror, "mirror-rule");
8109 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8110         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8111                                 rule_id, UINT8);
8112 cmdline_parse_token_string_t cmd_mirror_mask_what =
8113         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8114                                 what, "pool-mirror-up#pool-mirror-down"
8115                                       "#vlan-mirror");
8116 cmdline_parse_token_string_t cmd_mirror_mask_value =
8117         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8118                                 value, NULL);
8119 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8120         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8121                                 dstpool, "dst-pool");
8122 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8123         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8124                                 dstpool_id, UINT8);
8125 cmdline_parse_token_string_t cmd_mirror_mask_on =
8126         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8127                                 on, "on#off");
8128
8129 static void
8130 cmd_set_mirror_mask_parsed(void *parsed_result,
8131                        __attribute__((unused)) struct cmdline *cl,
8132                        __attribute__((unused)) void *data)
8133 {
8134         int ret,nb_item,i;
8135         struct cmd_set_mirror_mask_result *res = parsed_result;
8136         struct rte_eth_mirror_conf mr_conf;
8137
8138         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8139
8140         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8141
8142         mr_conf.dst_pool = res->dstpool_id;
8143
8144         if (!strcmp(res->what, "pool-mirror-up")) {
8145                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8146                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8147         } else if (!strcmp(res->what, "pool-mirror-down")) {
8148                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8149                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8150         } else if (!strcmp(res->what, "vlan-mirror")) {
8151                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8152                 nb_item = parse_item_list(res->value, "vlan",
8153                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8154                 if (nb_item <= 0)
8155                         return;
8156
8157                 for (i = 0; i < nb_item; i++) {
8158                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8159                                 printf("Invalid vlan_id: must be < 4096\n");
8160                                 return;
8161                         }
8162
8163                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8164                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8165                 }
8166         }
8167
8168         if (!strcmp(res->on, "on"))
8169                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8170                                                 res->rule_id, 1);
8171         else
8172                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8173                                                 res->rule_id, 0);
8174         if (ret < 0)
8175                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8176 }
8177
8178 cmdline_parse_inst_t cmd_set_mirror_mask = {
8179                 .f = cmd_set_mirror_mask_parsed,
8180                 .data = NULL,
8181                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8182                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8183                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8184                 .tokens = {
8185                         (void *)&cmd_mirror_mask_set,
8186                         (void *)&cmd_mirror_mask_port,
8187                         (void *)&cmd_mirror_mask_portid,
8188                         (void *)&cmd_mirror_mask_mirror,
8189                         (void *)&cmd_mirror_mask_ruleid,
8190                         (void *)&cmd_mirror_mask_what,
8191                         (void *)&cmd_mirror_mask_value,
8192                         (void *)&cmd_mirror_mask_dstpool,
8193                         (void *)&cmd_mirror_mask_poolid,
8194                         (void *)&cmd_mirror_mask_on,
8195                         NULL,
8196                 },
8197 };
8198
8199 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8200 struct cmd_set_mirror_link_result {
8201         cmdline_fixed_string_t set;
8202         cmdline_fixed_string_t port;
8203         portid_t port_id;
8204         cmdline_fixed_string_t mirror;
8205         uint8_t rule_id;
8206         cmdline_fixed_string_t what;
8207         cmdline_fixed_string_t dstpool;
8208         uint8_t dstpool_id;
8209         cmdline_fixed_string_t on;
8210 };
8211
8212 cmdline_parse_token_string_t cmd_mirror_link_set =
8213         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8214                                  set, "set");
8215 cmdline_parse_token_string_t cmd_mirror_link_port =
8216         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8217                                 port, "port");
8218 cmdline_parse_token_num_t cmd_mirror_link_portid =
8219         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8220                                 port_id, UINT16);
8221 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8222         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8223                                 mirror, "mirror-rule");
8224 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8225         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8226                             rule_id, UINT8);
8227 cmdline_parse_token_string_t cmd_mirror_link_what =
8228         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8229                                 what, "uplink-mirror#downlink-mirror");
8230 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8231         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8232                                 dstpool, "dst-pool");
8233 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8234         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8235                                 dstpool_id, UINT8);
8236 cmdline_parse_token_string_t cmd_mirror_link_on =
8237         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8238                                 on, "on#off");
8239
8240 static void
8241 cmd_set_mirror_link_parsed(void *parsed_result,
8242                        __attribute__((unused)) struct cmdline *cl,
8243                        __attribute__((unused)) void *data)
8244 {
8245         int ret;
8246         struct cmd_set_mirror_link_result *res = parsed_result;
8247         struct rte_eth_mirror_conf mr_conf;
8248
8249         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8250         if (!strcmp(res->what, "uplink-mirror"))
8251                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8252         else
8253                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8254
8255         mr_conf.dst_pool = res->dstpool_id;
8256
8257         if (!strcmp(res->on, "on"))
8258                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8259                                                 res->rule_id, 1);
8260         else
8261                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8262                                                 res->rule_id, 0);
8263
8264         /* check the return value and print it if is < 0 */
8265         if (ret < 0)
8266                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8267
8268 }
8269
8270 cmdline_parse_inst_t cmd_set_mirror_link = {
8271                 .f = cmd_set_mirror_link_parsed,
8272                 .data = NULL,
8273                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8274                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8275                 .tokens = {
8276                         (void *)&cmd_mirror_link_set,
8277                         (void *)&cmd_mirror_link_port,
8278                         (void *)&cmd_mirror_link_portid,
8279                         (void *)&cmd_mirror_link_mirror,
8280                         (void *)&cmd_mirror_link_ruleid,
8281                         (void *)&cmd_mirror_link_what,
8282                         (void *)&cmd_mirror_link_dstpool,
8283                         (void *)&cmd_mirror_link_poolid,
8284                         (void *)&cmd_mirror_link_on,
8285                         NULL,
8286                 },
8287 };
8288
8289 /* *** RESET VM MIRROR RULE *** */
8290 struct cmd_rm_mirror_rule_result {
8291         cmdline_fixed_string_t reset;
8292         cmdline_fixed_string_t port;
8293         portid_t port_id;
8294         cmdline_fixed_string_t mirror;
8295         uint8_t rule_id;
8296 };
8297
8298 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8299         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8300                                  reset, "reset");
8301 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8302         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8303                                 port, "port");
8304 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8305         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8306                                 port_id, UINT16);
8307 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8308         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8309                                 mirror, "mirror-rule");
8310 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8311         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8312                                 rule_id, UINT8);
8313
8314 static void
8315 cmd_reset_mirror_rule_parsed(void *parsed_result,
8316                        __attribute__((unused)) struct cmdline *cl,
8317                        __attribute__((unused)) void *data)
8318 {
8319         int ret;
8320         struct cmd_set_mirror_link_result *res = parsed_result;
8321         /* check rule_id */
8322         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8323         if(ret < 0)
8324                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8325 }
8326
8327 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8328                 .f = cmd_reset_mirror_rule_parsed,
8329                 .data = NULL,
8330                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8331                 .tokens = {
8332                         (void *)&cmd_rm_mirror_rule_reset,
8333                         (void *)&cmd_rm_mirror_rule_port,
8334                         (void *)&cmd_rm_mirror_rule_portid,
8335                         (void *)&cmd_rm_mirror_rule_mirror,
8336                         (void *)&cmd_rm_mirror_rule_ruleid,
8337                         NULL,
8338                 },
8339 };
8340
8341 /* ******************************************************************************** */
8342
8343 struct cmd_dump_result {
8344         cmdline_fixed_string_t dump;
8345 };
8346
8347 static void
8348 dump_struct_sizes(void)
8349 {
8350 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8351         DUMP_SIZE(struct rte_mbuf);
8352         DUMP_SIZE(struct rte_mempool);
8353         DUMP_SIZE(struct rte_ring);
8354 #undef DUMP_SIZE
8355 }
8356
8357 static void cmd_dump_parsed(void *parsed_result,
8358                             __attribute__((unused)) struct cmdline *cl,
8359                             __attribute__((unused)) void *data)
8360 {
8361         struct cmd_dump_result *res = parsed_result;
8362
8363         if (!strcmp(res->dump, "dump_physmem"))
8364                 rte_dump_physmem_layout(stdout);
8365         else if (!strcmp(res->dump, "dump_memzone"))
8366                 rte_memzone_dump(stdout);
8367         else if (!strcmp(res->dump, "dump_struct_sizes"))
8368                 dump_struct_sizes();
8369         else if (!strcmp(res->dump, "dump_ring"))
8370                 rte_ring_list_dump(stdout);
8371         else if (!strcmp(res->dump, "dump_mempool"))
8372                 rte_mempool_list_dump(stdout);
8373         else if (!strcmp(res->dump, "dump_devargs"))
8374                 rte_eal_devargs_dump(stdout);
8375         else if (!strcmp(res->dump, "dump_log_types"))
8376                 rte_log_dump(stdout);
8377 }
8378
8379 cmdline_parse_token_string_t cmd_dump_dump =
8380         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8381                 "dump_physmem#"
8382                 "dump_memzone#"
8383                 "dump_struct_sizes#"
8384                 "dump_ring#"
8385                 "dump_mempool#"
8386                 "dump_devargs#"
8387                 "dump_log_types");
8388
8389 cmdline_parse_inst_t cmd_dump = {
8390         .f = cmd_dump_parsed,  /* function to call */
8391         .data = NULL,      /* 2nd arg of func */
8392         .help_str = "Dump status",
8393         .tokens = {        /* token list, NULL terminated */
8394                 (void *)&cmd_dump_dump,
8395                 NULL,
8396         },
8397 };
8398
8399 /* ******************************************************************************** */
8400
8401 struct cmd_dump_one_result {
8402         cmdline_fixed_string_t dump;
8403         cmdline_fixed_string_t name;
8404 };
8405
8406 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8407                                 __attribute__((unused)) void *data)
8408 {
8409         struct cmd_dump_one_result *res = parsed_result;
8410
8411         if (!strcmp(res->dump, "dump_ring")) {
8412                 struct rte_ring *r;
8413                 r = rte_ring_lookup(res->name);
8414                 if (r == NULL) {
8415                         cmdline_printf(cl, "Cannot find ring\n");
8416                         return;
8417                 }
8418                 rte_ring_dump(stdout, r);
8419         } else if (!strcmp(res->dump, "dump_mempool")) {
8420                 struct rte_mempool *mp;
8421                 mp = rte_mempool_lookup(res->name);
8422                 if (mp == NULL) {
8423                         cmdline_printf(cl, "Cannot find mempool\n");
8424                         return;
8425                 }
8426                 rte_mempool_dump(stdout, mp);
8427         }
8428 }
8429
8430 cmdline_parse_token_string_t cmd_dump_one_dump =
8431         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8432                                  "dump_ring#dump_mempool");
8433
8434 cmdline_parse_token_string_t cmd_dump_one_name =
8435         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8436
8437 cmdline_parse_inst_t cmd_dump_one = {
8438         .f = cmd_dump_one_parsed,  /* function to call */
8439         .data = NULL,      /* 2nd arg of func */
8440         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8441         .tokens = {        /* token list, NULL terminated */
8442                 (void *)&cmd_dump_one_dump,
8443                 (void *)&cmd_dump_one_name,
8444                 NULL,
8445         },
8446 };
8447
8448 /* *** Add/Del syn filter *** */
8449 struct cmd_syn_filter_result {
8450         cmdline_fixed_string_t filter;
8451         portid_t port_id;
8452         cmdline_fixed_string_t ops;
8453         cmdline_fixed_string_t priority;
8454         cmdline_fixed_string_t high;
8455         cmdline_fixed_string_t queue;
8456         uint16_t queue_id;
8457 };
8458
8459 static void
8460 cmd_syn_filter_parsed(void *parsed_result,
8461                         __attribute__((unused)) struct cmdline *cl,
8462                         __attribute__((unused)) void *data)
8463 {
8464         struct cmd_syn_filter_result *res = parsed_result;
8465         struct rte_eth_syn_filter syn_filter;
8466         int ret = 0;
8467
8468         ret = rte_eth_dev_filter_supported(res->port_id,
8469                                         RTE_ETH_FILTER_SYN);
8470         if (ret < 0) {
8471                 printf("syn filter is not supported on port %u.\n",
8472                                 res->port_id);
8473                 return;
8474         }
8475
8476         memset(&syn_filter, 0, sizeof(syn_filter));
8477
8478         if (!strcmp(res->ops, "add")) {
8479                 if (!strcmp(res->high, "high"))
8480                         syn_filter.hig_pri = 1;
8481                 else
8482                         syn_filter.hig_pri = 0;
8483
8484                 syn_filter.queue = res->queue_id;
8485                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8486                                                 RTE_ETH_FILTER_SYN,
8487                                                 RTE_ETH_FILTER_ADD,
8488                                                 &syn_filter);
8489         } else
8490                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8491                                                 RTE_ETH_FILTER_SYN,
8492                                                 RTE_ETH_FILTER_DELETE,
8493                                                 &syn_filter);
8494
8495         if (ret < 0)
8496                 printf("syn filter programming error: (%s)\n",
8497                                 strerror(-ret));
8498 }
8499
8500 cmdline_parse_token_string_t cmd_syn_filter_filter =
8501         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8502         filter, "syn_filter");
8503 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8504         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8505         port_id, UINT16);
8506 cmdline_parse_token_string_t cmd_syn_filter_ops =
8507         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8508         ops, "add#del");
8509 cmdline_parse_token_string_t cmd_syn_filter_priority =
8510         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8511                                 priority, "priority");
8512 cmdline_parse_token_string_t cmd_syn_filter_high =
8513         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8514                                 high, "high#low");
8515 cmdline_parse_token_string_t cmd_syn_filter_queue =
8516         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8517                                 queue, "queue");
8518 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8519         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8520                                 queue_id, UINT16);
8521
8522 cmdline_parse_inst_t cmd_syn_filter = {
8523         .f = cmd_syn_filter_parsed,
8524         .data = NULL,
8525         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8526                 "<queue_id>: Add/Delete syn filter",
8527         .tokens = {
8528                 (void *)&cmd_syn_filter_filter,
8529                 (void *)&cmd_syn_filter_port_id,
8530                 (void *)&cmd_syn_filter_ops,
8531                 (void *)&cmd_syn_filter_priority,
8532                 (void *)&cmd_syn_filter_high,
8533                 (void *)&cmd_syn_filter_queue,
8534                 (void *)&cmd_syn_filter_queue_id,
8535                 NULL,
8536         },
8537 };
8538
8539 /* *** queue region set *** */
8540 struct cmd_queue_region_result {
8541         cmdline_fixed_string_t set;
8542         cmdline_fixed_string_t port;
8543         portid_t port_id;
8544         cmdline_fixed_string_t cmd;
8545         cmdline_fixed_string_t region;
8546         uint8_t  region_id;
8547         cmdline_fixed_string_t queue_start_index;
8548         uint8_t  queue_id;
8549         cmdline_fixed_string_t queue_num;
8550         uint8_t  queue_num_value;
8551 };
8552
8553 static void
8554 cmd_queue_region_parsed(void *parsed_result,
8555                         __attribute__((unused)) struct cmdline *cl,
8556                         __attribute__((unused)) void *data)
8557 {
8558         struct cmd_queue_region_result *res = parsed_result;
8559         int ret = -ENOTSUP;
8560 #ifdef RTE_LIBRTE_I40E_PMD
8561         struct rte_pmd_i40e_queue_region_conf region_conf;
8562         enum rte_pmd_i40e_queue_region_op op_type;
8563 #endif
8564
8565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8566                 return;
8567
8568 #ifdef RTE_LIBRTE_I40E_PMD
8569         memset(&region_conf, 0, sizeof(region_conf));
8570         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8571         region_conf.region_id = res->region_id;
8572         region_conf.queue_num = res->queue_num_value;
8573         region_conf.queue_start_index = res->queue_id;
8574
8575         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8576                                 op_type, &region_conf);
8577 #endif
8578
8579         switch (ret) {
8580         case 0:
8581                 break;
8582         case -ENOTSUP:
8583                 printf("function not implemented or supported\n");
8584                 break;
8585         default:
8586                 printf("queue region config error: (%s)\n", strerror(-ret));
8587         }
8588 }
8589
8590 cmdline_parse_token_string_t cmd_queue_region_set =
8591 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8592                 set, "set");
8593 cmdline_parse_token_string_t cmd_queue_region_port =
8594         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8595 cmdline_parse_token_num_t cmd_queue_region_port_id =
8596         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8597                                 port_id, UINT16);
8598 cmdline_parse_token_string_t cmd_queue_region_cmd =
8599         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8600                                  cmd, "queue-region");
8601 cmdline_parse_token_string_t cmd_queue_region_id =
8602         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8603                                 region, "region_id");
8604 cmdline_parse_token_num_t cmd_queue_region_index =
8605         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8606                                 region_id, UINT8);
8607 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8608         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8609                                 queue_start_index, "queue_start_index");
8610 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8611         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8612                                 queue_id, UINT8);
8613 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8614         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8615                                 queue_num, "queue_num");
8616 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8617         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8618                                 queue_num_value, UINT8);
8619
8620 cmdline_parse_inst_t cmd_queue_region = {
8621         .f = cmd_queue_region_parsed,
8622         .data = NULL,
8623         .help_str = "set port <port_id> queue-region region_id <value> "
8624                 "queue_start_index <value> queue_num <value>: Set a queue region",
8625         .tokens = {
8626                 (void *)&cmd_queue_region_set,
8627                 (void *)&cmd_queue_region_port,
8628                 (void *)&cmd_queue_region_port_id,
8629                 (void *)&cmd_queue_region_cmd,
8630                 (void *)&cmd_queue_region_id,
8631                 (void *)&cmd_queue_region_index,
8632                 (void *)&cmd_queue_region_queue_start_index,
8633                 (void *)&cmd_queue_region_queue_id,
8634                 (void *)&cmd_queue_region_queue_num,
8635                 (void *)&cmd_queue_region_queue_num_value,
8636                 NULL,
8637         },
8638 };
8639
8640 /* *** queue region and flowtype set *** */
8641 struct cmd_region_flowtype_result {
8642         cmdline_fixed_string_t set;
8643         cmdline_fixed_string_t port;
8644         portid_t port_id;
8645         cmdline_fixed_string_t cmd;
8646         cmdline_fixed_string_t region;
8647         uint8_t  region_id;
8648         cmdline_fixed_string_t flowtype;
8649         uint8_t  flowtype_id;
8650 };
8651
8652 static void
8653 cmd_region_flowtype_parsed(void *parsed_result,
8654                         __attribute__((unused)) struct cmdline *cl,
8655                         __attribute__((unused)) void *data)
8656 {
8657         struct cmd_region_flowtype_result *res = parsed_result;
8658         int ret = -ENOTSUP;
8659 #ifdef RTE_LIBRTE_I40E_PMD
8660         struct rte_pmd_i40e_queue_region_conf region_conf;
8661         enum rte_pmd_i40e_queue_region_op op_type;
8662 #endif
8663
8664         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8665                 return;
8666
8667 #ifdef RTE_LIBRTE_I40E_PMD
8668         memset(&region_conf, 0, sizeof(region_conf));
8669
8670         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8671         region_conf.region_id = res->region_id;
8672         region_conf.hw_flowtype = res->flowtype_id;
8673
8674         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8675                         op_type, &region_conf);
8676 #endif
8677
8678         switch (ret) {
8679         case 0:
8680                 break;
8681         case -ENOTSUP:
8682                 printf("function not implemented or supported\n");
8683                 break;
8684         default:
8685                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8686         }
8687 }
8688
8689 cmdline_parse_token_string_t cmd_region_flowtype_set =
8690 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8691                                 set, "set");
8692 cmdline_parse_token_string_t cmd_region_flowtype_port =
8693         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8694                                 port, "port");
8695 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8696         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8697                                 port_id, UINT16);
8698 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8699         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8700                                 cmd, "queue-region");
8701 cmdline_parse_token_string_t cmd_region_flowtype_index =
8702         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8703                                 region, "region_id");
8704 cmdline_parse_token_num_t cmd_region_flowtype_id =
8705         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8706                                 region_id, UINT8);
8707 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8708         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8709                                 flowtype, "flowtype");
8710 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8711         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8712                                 flowtype_id, UINT8);
8713 cmdline_parse_inst_t cmd_region_flowtype = {
8714         .f = cmd_region_flowtype_parsed,
8715         .data = NULL,
8716         .help_str = "set port <port_id> queue-region region_id <value> "
8717                 "flowtype <value>: Set a flowtype region index",
8718         .tokens = {
8719                 (void *)&cmd_region_flowtype_set,
8720                 (void *)&cmd_region_flowtype_port,
8721                 (void *)&cmd_region_flowtype_port_index,
8722                 (void *)&cmd_region_flowtype_cmd,
8723                 (void *)&cmd_region_flowtype_index,
8724                 (void *)&cmd_region_flowtype_id,
8725                 (void *)&cmd_region_flowtype_flow_index,
8726                 (void *)&cmd_region_flowtype_flow_id,
8727                 NULL,
8728         },
8729 };
8730
8731 /* *** User Priority (UP) to queue region (region_id) set *** */
8732 struct cmd_user_priority_region_result {
8733         cmdline_fixed_string_t set;
8734         cmdline_fixed_string_t port;
8735         portid_t port_id;
8736         cmdline_fixed_string_t cmd;
8737         cmdline_fixed_string_t user_priority;
8738         uint8_t  user_priority_id;
8739         cmdline_fixed_string_t region;
8740         uint8_t  region_id;
8741 };
8742
8743 static void
8744 cmd_user_priority_region_parsed(void *parsed_result,
8745                         __attribute__((unused)) struct cmdline *cl,
8746                         __attribute__((unused)) void *data)
8747 {
8748         struct cmd_user_priority_region_result *res = parsed_result;
8749         int ret = -ENOTSUP;
8750 #ifdef RTE_LIBRTE_I40E_PMD
8751         struct rte_pmd_i40e_queue_region_conf region_conf;
8752         enum rte_pmd_i40e_queue_region_op op_type;
8753 #endif
8754
8755         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8756                 return;
8757
8758 #ifdef RTE_LIBRTE_I40E_PMD
8759         memset(&region_conf, 0, sizeof(region_conf));
8760         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8761         region_conf.user_priority = res->user_priority_id;
8762         region_conf.region_id = res->region_id;
8763
8764         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8765                                 op_type, &region_conf);
8766 #endif
8767
8768         switch (ret) {
8769         case 0:
8770                 break;
8771         case -ENOTSUP:
8772                 printf("function not implemented or supported\n");
8773                 break;
8774         default:
8775                 printf("user_priority region config error: (%s)\n",
8776                                 strerror(-ret));
8777         }
8778 }
8779
8780 cmdline_parse_token_string_t cmd_user_priority_region_set =
8781         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8782                                 set, "set");
8783 cmdline_parse_token_string_t cmd_user_priority_region_port =
8784         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8785                                 port, "port");
8786 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8787         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8788                                 port_id, UINT16);
8789 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8790         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8791                                 cmd, "queue-region");
8792 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8793         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8794                                 user_priority, "UP");
8795 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8796         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8797                                 user_priority_id, UINT8);
8798 cmdline_parse_token_string_t cmd_user_priority_region_region =
8799         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8800                                 region, "region_id");
8801 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8802         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8803                                 region_id, UINT8);
8804
8805 cmdline_parse_inst_t cmd_user_priority_region = {
8806         .f = cmd_user_priority_region_parsed,
8807         .data = NULL,
8808         .help_str = "set port <port_id> queue-region UP <value> "
8809                 "region_id <value>: Set the mapping of User Priority (UP) "
8810                 "to queue region (region_id) ",
8811         .tokens = {
8812                 (void *)&cmd_user_priority_region_set,
8813                 (void *)&cmd_user_priority_region_port,
8814                 (void *)&cmd_user_priority_region_port_index,
8815                 (void *)&cmd_user_priority_region_cmd,
8816                 (void *)&cmd_user_priority_region_UP,
8817                 (void *)&cmd_user_priority_region_UP_id,
8818                 (void *)&cmd_user_priority_region_region,
8819                 (void *)&cmd_user_priority_region_region_id,
8820                 NULL,
8821         },
8822 };
8823
8824 /* *** flush all queue region related configuration *** */
8825 struct cmd_flush_queue_region_result {
8826         cmdline_fixed_string_t set;
8827         cmdline_fixed_string_t port;
8828         portid_t port_id;
8829         cmdline_fixed_string_t cmd;
8830         cmdline_fixed_string_t flush;
8831         cmdline_fixed_string_t what;
8832 };
8833
8834 static void
8835 cmd_flush_queue_region_parsed(void *parsed_result,
8836                         __attribute__((unused)) struct cmdline *cl,
8837                         __attribute__((unused)) void *data)
8838 {
8839         struct cmd_flush_queue_region_result *res = parsed_result;
8840         int ret = -ENOTSUP;
8841 #ifdef RTE_LIBRTE_I40E_PMD
8842         struct rte_pmd_i40e_queue_region_conf region_conf;
8843         enum rte_pmd_i40e_queue_region_op op_type;
8844 #endif
8845
8846         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8847                 return;
8848
8849 #ifdef RTE_LIBRTE_I40E_PMD
8850         memset(&region_conf, 0, sizeof(region_conf));
8851
8852         if (strcmp(res->what, "on") == 0)
8853                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8854         else
8855                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8856
8857         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8858                                 op_type, &region_conf);
8859 #endif
8860
8861         switch (ret) {
8862         case 0:
8863                 break;
8864         case -ENOTSUP:
8865                 printf("function not implemented or supported\n");
8866                 break;
8867         default:
8868                 printf("queue region config flush error: (%s)\n",
8869                                 strerror(-ret));
8870         }
8871 }
8872
8873 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8874         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8875                                 set, "set");
8876 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8877         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8878                                 port, "port");
8879 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8880         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8881                                 port_id, UINT16);
8882 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8883         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8884                                 cmd, "queue-region");
8885 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8886         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8887                                 flush, "flush");
8888 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8889         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8890                                 what, "on#off");
8891
8892 cmdline_parse_inst_t cmd_flush_queue_region = {
8893         .f = cmd_flush_queue_region_parsed,
8894         .data = NULL,
8895         .help_str = "set port <port_id> queue-region flush on|off"
8896                 ": flush all queue region related configuration",
8897         .tokens = {
8898                 (void *)&cmd_flush_queue_region_set,
8899                 (void *)&cmd_flush_queue_region_port,
8900                 (void *)&cmd_flush_queue_region_port_index,
8901                 (void *)&cmd_flush_queue_region_cmd,
8902                 (void *)&cmd_flush_queue_region_flush,
8903                 (void *)&cmd_flush_queue_region_what,
8904                 NULL,
8905         },
8906 };
8907
8908 /* *** get all queue region related configuration info *** */
8909 struct cmd_show_queue_region_info {
8910         cmdline_fixed_string_t show;
8911         cmdline_fixed_string_t port;
8912         portid_t port_id;
8913         cmdline_fixed_string_t cmd;
8914 };
8915
8916 static void
8917 cmd_show_queue_region_info_parsed(void *parsed_result,
8918                         __attribute__((unused)) struct cmdline *cl,
8919                         __attribute__((unused)) void *data)
8920 {
8921         struct cmd_show_queue_region_info *res = parsed_result;
8922         int ret = -ENOTSUP;
8923 #ifdef RTE_LIBRTE_I40E_PMD
8924         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
8925         enum rte_pmd_i40e_queue_region_op op_type;
8926 #endif
8927
8928         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8929                 return;
8930
8931 #ifdef RTE_LIBRTE_I40E_PMD
8932         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
8933
8934         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
8935
8936         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8937                                         op_type, &rte_pmd_regions);
8938
8939         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
8940 #endif
8941
8942         switch (ret) {
8943         case 0:
8944                 break;
8945         case -ENOTSUP:
8946                 printf("function not implemented or supported\n");
8947                 break;
8948         default:
8949                 printf("queue region config info show error: (%s)\n",
8950                                 strerror(-ret));
8951         }
8952 }
8953
8954 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
8955 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8956                                 show, "show");
8957 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
8958         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8959                                 port, "port");
8960 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
8961         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
8962                                 port_id, UINT16);
8963 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
8964         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8965                                 cmd, "queue-region");
8966
8967 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
8968         .f = cmd_show_queue_region_info_parsed,
8969         .data = NULL,
8970         .help_str = "show port <port_id> queue-region"
8971                 ": show all queue region related configuration info",
8972         .tokens = {
8973                 (void *)&cmd_show_queue_region_info_get,
8974                 (void *)&cmd_show_queue_region_info_port,
8975                 (void *)&cmd_show_queue_region_info_port_index,
8976                 (void *)&cmd_show_queue_region_info_cmd,
8977                 NULL,
8978         },
8979 };
8980
8981 /* *** ADD/REMOVE A 2tuple FILTER *** */
8982 struct cmd_2tuple_filter_result {
8983         cmdline_fixed_string_t filter;
8984         portid_t port_id;
8985         cmdline_fixed_string_t ops;
8986         cmdline_fixed_string_t dst_port;
8987         uint16_t dst_port_value;
8988         cmdline_fixed_string_t protocol;
8989         uint8_t protocol_value;
8990         cmdline_fixed_string_t mask;
8991         uint8_t  mask_value;
8992         cmdline_fixed_string_t tcp_flags;
8993         uint8_t tcp_flags_value;
8994         cmdline_fixed_string_t priority;
8995         uint8_t  priority_value;
8996         cmdline_fixed_string_t queue;
8997         uint16_t  queue_id;
8998 };
8999
9000 static void
9001 cmd_2tuple_filter_parsed(void *parsed_result,
9002                         __attribute__((unused)) struct cmdline *cl,
9003                         __attribute__((unused)) void *data)
9004 {
9005         struct rte_eth_ntuple_filter filter;
9006         struct cmd_2tuple_filter_result *res = parsed_result;
9007         int ret = 0;
9008
9009         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9010         if (ret < 0) {
9011                 printf("ntuple filter is not supported on port %u.\n",
9012                         res->port_id);
9013                 return;
9014         }
9015
9016         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9017
9018         filter.flags = RTE_2TUPLE_FLAGS;
9019         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9020         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9021         filter.proto = res->protocol_value;
9022         filter.priority = res->priority_value;
9023         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9024                 printf("nonzero tcp_flags is only meaningful"
9025                         " when protocol is TCP.\n");
9026                 return;
9027         }
9028         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9029                 printf("invalid TCP flags.\n");
9030                 return;
9031         }
9032
9033         if (res->tcp_flags_value != 0) {
9034                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9035                 filter.tcp_flags = res->tcp_flags_value;
9036         }
9037
9038         /* need convert to big endian. */
9039         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9040         filter.queue = res->queue_id;
9041
9042         if (!strcmp(res->ops, "add"))
9043                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9044                                 RTE_ETH_FILTER_NTUPLE,
9045                                 RTE_ETH_FILTER_ADD,
9046                                 &filter);
9047         else
9048                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9049                                 RTE_ETH_FILTER_NTUPLE,
9050                                 RTE_ETH_FILTER_DELETE,
9051                                 &filter);
9052         if (ret < 0)
9053                 printf("2tuple filter programming error: (%s)\n",
9054                         strerror(-ret));
9055
9056 }
9057
9058 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9059         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9060                                  filter, "2tuple_filter");
9061 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9062         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9063                                 port_id, UINT16);
9064 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9065         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9066                                  ops, "add#del");
9067 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9068         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9069                                 dst_port, "dst_port");
9070 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9071         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9072                                 dst_port_value, UINT16);
9073 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9074         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9075                                 protocol, "protocol");
9076 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9077         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9078                                 protocol_value, UINT8);
9079 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9080         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9081                                 mask, "mask");
9082 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9083         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9084                                 mask_value, INT8);
9085 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9086         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9087                                 tcp_flags, "tcp_flags");
9088 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9089         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9090                                 tcp_flags_value, UINT8);
9091 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9092         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9093                                 priority, "priority");
9094 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9095         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9096                                 priority_value, UINT8);
9097 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9098         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9099                                 queue, "queue");
9100 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9101         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9102                                 queue_id, UINT16);
9103
9104 cmdline_parse_inst_t cmd_2tuple_filter = {
9105         .f = cmd_2tuple_filter_parsed,
9106         .data = NULL,
9107         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9108                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9109                 "<queue_id>: Add a 2tuple filter",
9110         .tokens = {
9111                 (void *)&cmd_2tuple_filter_filter,
9112                 (void *)&cmd_2tuple_filter_port_id,
9113                 (void *)&cmd_2tuple_filter_ops,
9114                 (void *)&cmd_2tuple_filter_dst_port,
9115                 (void *)&cmd_2tuple_filter_dst_port_value,
9116                 (void *)&cmd_2tuple_filter_protocol,
9117                 (void *)&cmd_2tuple_filter_protocol_value,
9118                 (void *)&cmd_2tuple_filter_mask,
9119                 (void *)&cmd_2tuple_filter_mask_value,
9120                 (void *)&cmd_2tuple_filter_tcp_flags,
9121                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9122                 (void *)&cmd_2tuple_filter_priority,
9123                 (void *)&cmd_2tuple_filter_priority_value,
9124                 (void *)&cmd_2tuple_filter_queue,
9125                 (void *)&cmd_2tuple_filter_queue_id,
9126                 NULL,
9127         },
9128 };
9129
9130 /* *** ADD/REMOVE A 5tuple FILTER *** */
9131 struct cmd_5tuple_filter_result {
9132         cmdline_fixed_string_t filter;
9133         portid_t port_id;
9134         cmdline_fixed_string_t ops;
9135         cmdline_fixed_string_t dst_ip;
9136         cmdline_ipaddr_t dst_ip_value;
9137         cmdline_fixed_string_t src_ip;
9138         cmdline_ipaddr_t src_ip_value;
9139         cmdline_fixed_string_t dst_port;
9140         uint16_t dst_port_value;
9141         cmdline_fixed_string_t src_port;
9142         uint16_t src_port_value;
9143         cmdline_fixed_string_t protocol;
9144         uint8_t protocol_value;
9145         cmdline_fixed_string_t mask;
9146         uint8_t  mask_value;
9147         cmdline_fixed_string_t tcp_flags;
9148         uint8_t tcp_flags_value;
9149         cmdline_fixed_string_t priority;
9150         uint8_t  priority_value;
9151         cmdline_fixed_string_t queue;
9152         uint16_t  queue_id;
9153 };
9154
9155 static void
9156 cmd_5tuple_filter_parsed(void *parsed_result,
9157                         __attribute__((unused)) struct cmdline *cl,
9158                         __attribute__((unused)) void *data)
9159 {
9160         struct rte_eth_ntuple_filter filter;
9161         struct cmd_5tuple_filter_result *res = parsed_result;
9162         int ret = 0;
9163
9164         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9165         if (ret < 0) {
9166                 printf("ntuple filter is not supported on port %u.\n",
9167                         res->port_id);
9168                 return;
9169         }
9170
9171         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9172
9173         filter.flags = RTE_5TUPLE_FLAGS;
9174         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9175         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9176         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9177         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9178         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9179         filter.proto = res->protocol_value;
9180         filter.priority = res->priority_value;
9181         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9182                 printf("nonzero tcp_flags is only meaningful"
9183                         " when protocol is TCP.\n");
9184                 return;
9185         }
9186         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9187                 printf("invalid TCP flags.\n");
9188                 return;
9189         }
9190
9191         if (res->tcp_flags_value != 0) {
9192                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9193                 filter.tcp_flags = res->tcp_flags_value;
9194         }
9195
9196         if (res->dst_ip_value.family == AF_INET)
9197                 /* no need to convert, already big endian. */
9198                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9199         else {
9200                 if (filter.dst_ip_mask == 0) {
9201                         printf("can not support ipv6 involved compare.\n");
9202                         return;
9203                 }
9204                 filter.dst_ip = 0;
9205         }
9206
9207         if (res->src_ip_value.family == AF_INET)
9208                 /* no need to convert, already big endian. */
9209                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9210         else {
9211                 if (filter.src_ip_mask == 0) {
9212                         printf("can not support ipv6 involved compare.\n");
9213                         return;
9214                 }
9215                 filter.src_ip = 0;
9216         }
9217         /* need convert to big endian. */
9218         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9219         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9220         filter.queue = res->queue_id;
9221
9222         if (!strcmp(res->ops, "add"))
9223                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9224                                 RTE_ETH_FILTER_NTUPLE,
9225                                 RTE_ETH_FILTER_ADD,
9226                                 &filter);
9227         else
9228                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9229                                 RTE_ETH_FILTER_NTUPLE,
9230                                 RTE_ETH_FILTER_DELETE,
9231                                 &filter);
9232         if (ret < 0)
9233                 printf("5tuple filter programming error: (%s)\n",
9234                         strerror(-ret));
9235 }
9236
9237 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9238         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9239                                  filter, "5tuple_filter");
9240 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9241         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9242                                 port_id, UINT16);
9243 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9244         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9245                                  ops, "add#del");
9246 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9247         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9248                                 dst_ip, "dst_ip");
9249 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9250         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9251                                 dst_ip_value);
9252 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9253         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9254                                 src_ip, "src_ip");
9255 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9256         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9257                                 src_ip_value);
9258 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9259         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9260                                 dst_port, "dst_port");
9261 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9262         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9263                                 dst_port_value, UINT16);
9264 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9265         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9266                                 src_port, "src_port");
9267 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9268         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9269                                 src_port_value, UINT16);
9270 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9271         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9272                                 protocol, "protocol");
9273 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9274         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9275                                 protocol_value, UINT8);
9276 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9277         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9278                                 mask, "mask");
9279 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9280         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9281                                 mask_value, INT8);
9282 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9283         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9284                                 tcp_flags, "tcp_flags");
9285 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9286         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9287                                 tcp_flags_value, UINT8);
9288 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9289         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9290                                 priority, "priority");
9291 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9292         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9293                                 priority_value, UINT8);
9294 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9295         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9296                                 queue, "queue");
9297 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9298         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9299                                 queue_id, UINT16);
9300
9301 cmdline_parse_inst_t cmd_5tuple_filter = {
9302         .f = cmd_5tuple_filter_parsed,
9303         .data = NULL,
9304         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9305                 "src_ip <value> dst_port <value> src_port <value> "
9306                 "protocol <value>  mask <value> tcp_flags <value> "
9307                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9308         .tokens = {
9309                 (void *)&cmd_5tuple_filter_filter,
9310                 (void *)&cmd_5tuple_filter_port_id,
9311                 (void *)&cmd_5tuple_filter_ops,
9312                 (void *)&cmd_5tuple_filter_dst_ip,
9313                 (void *)&cmd_5tuple_filter_dst_ip_value,
9314                 (void *)&cmd_5tuple_filter_src_ip,
9315                 (void *)&cmd_5tuple_filter_src_ip_value,
9316                 (void *)&cmd_5tuple_filter_dst_port,
9317                 (void *)&cmd_5tuple_filter_dst_port_value,
9318                 (void *)&cmd_5tuple_filter_src_port,
9319                 (void *)&cmd_5tuple_filter_src_port_value,
9320                 (void *)&cmd_5tuple_filter_protocol,
9321                 (void *)&cmd_5tuple_filter_protocol_value,
9322                 (void *)&cmd_5tuple_filter_mask,
9323                 (void *)&cmd_5tuple_filter_mask_value,
9324                 (void *)&cmd_5tuple_filter_tcp_flags,
9325                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9326                 (void *)&cmd_5tuple_filter_priority,
9327                 (void *)&cmd_5tuple_filter_priority_value,
9328                 (void *)&cmd_5tuple_filter_queue,
9329                 (void *)&cmd_5tuple_filter_queue_id,
9330                 NULL,
9331         },
9332 };
9333
9334 /* *** ADD/REMOVE A flex FILTER *** */
9335 struct cmd_flex_filter_result {
9336         cmdline_fixed_string_t filter;
9337         cmdline_fixed_string_t ops;
9338         portid_t port_id;
9339         cmdline_fixed_string_t len;
9340         uint8_t len_value;
9341         cmdline_fixed_string_t bytes;
9342         cmdline_fixed_string_t bytes_value;
9343         cmdline_fixed_string_t mask;
9344         cmdline_fixed_string_t mask_value;
9345         cmdline_fixed_string_t priority;
9346         uint8_t priority_value;
9347         cmdline_fixed_string_t queue;
9348         uint16_t queue_id;
9349 };
9350
9351 static int xdigit2val(unsigned char c)
9352 {
9353         int val;
9354         if (isdigit(c))
9355                 val = c - '0';
9356         else if (isupper(c))
9357                 val = c - 'A' + 10;
9358         else
9359                 val = c - 'a' + 10;
9360         return val;
9361 }
9362
9363 static void
9364 cmd_flex_filter_parsed(void *parsed_result,
9365                           __attribute__((unused)) struct cmdline *cl,
9366                           __attribute__((unused)) void *data)
9367 {
9368         int ret = 0;
9369         struct rte_eth_flex_filter filter;
9370         struct cmd_flex_filter_result *res = parsed_result;
9371         char *bytes_ptr, *mask_ptr;
9372         uint16_t len, i, j = 0;
9373         char c;
9374         int val;
9375         uint8_t byte = 0;
9376
9377         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9378                 printf("the len exceed the max length 128\n");
9379                 return;
9380         }
9381         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9382         filter.len = res->len_value;
9383         filter.priority = res->priority_value;
9384         filter.queue = res->queue_id;
9385         bytes_ptr = res->bytes_value;
9386         mask_ptr = res->mask_value;
9387
9388          /* translate bytes string to array. */
9389         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9390                 (bytes_ptr[1] == 'X')))
9391                 bytes_ptr += 2;
9392         len = strnlen(bytes_ptr, res->len_value * 2);
9393         if (len == 0 || (len % 8 != 0)) {
9394                 printf("please check len and bytes input\n");
9395                 return;
9396         }
9397         for (i = 0; i < len; i++) {
9398                 c = bytes_ptr[i];
9399                 if (isxdigit(c) == 0) {
9400                         /* invalid characters. */
9401                         printf("invalid input\n");
9402                         return;
9403                 }
9404                 val = xdigit2val(c);
9405                 if (i % 2) {
9406                         byte |= val;
9407                         filter.bytes[j] = byte;
9408                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9409                         j++;
9410                         byte = 0;
9411                 } else
9412                         byte |= val << 4;
9413         }
9414         printf("\n");
9415          /* translate mask string to uint8_t array. */
9416         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9417                 (mask_ptr[1] == 'X')))
9418                 mask_ptr += 2;
9419         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9420         if (len == 0) {
9421                 printf("invalid input\n");
9422                 return;
9423         }
9424         j = 0;
9425         byte = 0;
9426         for (i = 0; i < len; i++) {
9427                 c = mask_ptr[i];
9428                 if (isxdigit(c) == 0) {
9429                         /* invalid characters. */
9430                         printf("invalid input\n");
9431                         return;
9432                 }
9433                 val = xdigit2val(c);
9434                 if (i % 2) {
9435                         byte |= val;
9436                         filter.mask[j] = byte;
9437                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9438                         j++;
9439                         byte = 0;
9440                 } else
9441                         byte |= val << 4;
9442         }
9443         printf("\n");
9444
9445         if (!strcmp(res->ops, "add"))
9446                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9447                                 RTE_ETH_FILTER_FLEXIBLE,
9448                                 RTE_ETH_FILTER_ADD,
9449                                 &filter);
9450         else
9451                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9452                                 RTE_ETH_FILTER_FLEXIBLE,
9453                                 RTE_ETH_FILTER_DELETE,
9454                                 &filter);
9455
9456         if (ret < 0)
9457                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9458 }
9459
9460 cmdline_parse_token_string_t cmd_flex_filter_filter =
9461         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9462                                 filter, "flex_filter");
9463 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9464         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9465                                 port_id, UINT16);
9466 cmdline_parse_token_string_t cmd_flex_filter_ops =
9467         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9468                                 ops, "add#del");
9469 cmdline_parse_token_string_t cmd_flex_filter_len =
9470         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9471                                 len, "len");
9472 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9473         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9474                                 len_value, UINT8);
9475 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9476         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9477                                 bytes, "bytes");
9478 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9479         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9480                                 bytes_value, NULL);
9481 cmdline_parse_token_string_t cmd_flex_filter_mask =
9482         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9483                                 mask, "mask");
9484 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9485         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9486                                 mask_value, NULL);
9487 cmdline_parse_token_string_t cmd_flex_filter_priority =
9488         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9489                                 priority, "priority");
9490 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9491         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9492                                 priority_value, UINT8);
9493 cmdline_parse_token_string_t cmd_flex_filter_queue =
9494         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9495                                 queue, "queue");
9496 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9497         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9498                                 queue_id, UINT16);
9499 cmdline_parse_inst_t cmd_flex_filter = {
9500         .f = cmd_flex_filter_parsed,
9501         .data = NULL,
9502         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9503                 "<value> mask <value> priority <value> queue <queue_id>: "
9504                 "Add/Del a flex filter",
9505         .tokens = {
9506                 (void *)&cmd_flex_filter_filter,
9507                 (void *)&cmd_flex_filter_port_id,
9508                 (void *)&cmd_flex_filter_ops,
9509                 (void *)&cmd_flex_filter_len,
9510                 (void *)&cmd_flex_filter_len_value,
9511                 (void *)&cmd_flex_filter_bytes,
9512                 (void *)&cmd_flex_filter_bytes_value,
9513                 (void *)&cmd_flex_filter_mask,
9514                 (void *)&cmd_flex_filter_mask_value,
9515                 (void *)&cmd_flex_filter_priority,
9516                 (void *)&cmd_flex_filter_priority_value,
9517                 (void *)&cmd_flex_filter_queue,
9518                 (void *)&cmd_flex_filter_queue_id,
9519                 NULL,
9520         },
9521 };
9522
9523 /* *** Filters Control *** */
9524
9525 /* *** deal with ethertype filter *** */
9526 struct cmd_ethertype_filter_result {
9527         cmdline_fixed_string_t filter;
9528         portid_t port_id;
9529         cmdline_fixed_string_t ops;
9530         cmdline_fixed_string_t mac;
9531         struct ether_addr mac_addr;
9532         cmdline_fixed_string_t ethertype;
9533         uint16_t ethertype_value;
9534         cmdline_fixed_string_t drop;
9535         cmdline_fixed_string_t queue;
9536         uint16_t  queue_id;
9537 };
9538
9539 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9540         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9541                                  filter, "ethertype_filter");
9542 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9543         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9544                               port_id, UINT16);
9545 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9546         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9547                                  ops, "add#del");
9548 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9549         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9550                                  mac, "mac_addr#mac_ignr");
9551 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9552         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9553                                      mac_addr);
9554 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9555         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9556                                  ethertype, "ethertype");
9557 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9558         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9559                               ethertype_value, UINT16);
9560 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9561         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9562                                  drop, "drop#fwd");
9563 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9564         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9565                                  queue, "queue");
9566 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9567         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9568                               queue_id, UINT16);
9569
9570 static void
9571 cmd_ethertype_filter_parsed(void *parsed_result,
9572                           __attribute__((unused)) struct cmdline *cl,
9573                           __attribute__((unused)) void *data)
9574 {
9575         struct cmd_ethertype_filter_result *res = parsed_result;
9576         struct rte_eth_ethertype_filter filter;
9577         int ret = 0;
9578
9579         ret = rte_eth_dev_filter_supported(res->port_id,
9580                         RTE_ETH_FILTER_ETHERTYPE);
9581         if (ret < 0) {
9582                 printf("ethertype filter is not supported on port %u.\n",
9583                         res->port_id);
9584                 return;
9585         }
9586
9587         memset(&filter, 0, sizeof(filter));
9588         if (!strcmp(res->mac, "mac_addr")) {
9589                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9590                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9591                         sizeof(struct ether_addr));
9592         }
9593         if (!strcmp(res->drop, "drop"))
9594                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9595         filter.ether_type = res->ethertype_value;
9596         filter.queue = res->queue_id;
9597
9598         if (!strcmp(res->ops, "add"))
9599                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9600                                 RTE_ETH_FILTER_ETHERTYPE,
9601                                 RTE_ETH_FILTER_ADD,
9602                                 &filter);
9603         else
9604                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9605                                 RTE_ETH_FILTER_ETHERTYPE,
9606                                 RTE_ETH_FILTER_DELETE,
9607                                 &filter);
9608         if (ret < 0)
9609                 printf("ethertype filter programming error: (%s)\n",
9610                         strerror(-ret));
9611 }
9612
9613 cmdline_parse_inst_t cmd_ethertype_filter = {
9614         .f = cmd_ethertype_filter_parsed,
9615         .data = NULL,
9616         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9617                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9618                 "Add or delete an ethertype filter entry",
9619         .tokens = {
9620                 (void *)&cmd_ethertype_filter_filter,
9621                 (void *)&cmd_ethertype_filter_port_id,
9622                 (void *)&cmd_ethertype_filter_ops,
9623                 (void *)&cmd_ethertype_filter_mac,
9624                 (void *)&cmd_ethertype_filter_mac_addr,
9625                 (void *)&cmd_ethertype_filter_ethertype,
9626                 (void *)&cmd_ethertype_filter_ethertype_value,
9627                 (void *)&cmd_ethertype_filter_drop,
9628                 (void *)&cmd_ethertype_filter_queue,
9629                 (void *)&cmd_ethertype_filter_queue_id,
9630                 NULL,
9631         },
9632 };
9633
9634 /* *** deal with flow director filter *** */
9635 struct cmd_flow_director_result {
9636         cmdline_fixed_string_t flow_director_filter;
9637         portid_t port_id;
9638         cmdline_fixed_string_t mode;
9639         cmdline_fixed_string_t mode_value;
9640         cmdline_fixed_string_t ops;
9641         cmdline_fixed_string_t flow;
9642         cmdline_fixed_string_t flow_type;
9643         cmdline_fixed_string_t ether;
9644         uint16_t ether_type;
9645         cmdline_fixed_string_t src;
9646         cmdline_ipaddr_t ip_src;
9647         uint16_t port_src;
9648         cmdline_fixed_string_t dst;
9649         cmdline_ipaddr_t ip_dst;
9650         uint16_t port_dst;
9651         cmdline_fixed_string_t verify_tag;
9652         uint32_t verify_tag_value;
9653         cmdline_ipaddr_t tos;
9654         uint8_t tos_value;
9655         cmdline_ipaddr_t proto;
9656         uint8_t proto_value;
9657         cmdline_ipaddr_t ttl;
9658         uint8_t ttl_value;
9659         cmdline_fixed_string_t vlan;
9660         uint16_t vlan_value;
9661         cmdline_fixed_string_t flexbytes;
9662         cmdline_fixed_string_t flexbytes_value;
9663         cmdline_fixed_string_t pf_vf;
9664         cmdline_fixed_string_t drop;
9665         cmdline_fixed_string_t queue;
9666         uint16_t  queue_id;
9667         cmdline_fixed_string_t fd_id;
9668         uint32_t  fd_id_value;
9669         cmdline_fixed_string_t mac;
9670         struct ether_addr mac_addr;
9671         cmdline_fixed_string_t tunnel;
9672         cmdline_fixed_string_t tunnel_type;
9673         cmdline_fixed_string_t tunnel_id;
9674         uint32_t tunnel_id_value;
9675 };
9676
9677 static inline int
9678 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9679 {
9680         char s[256];
9681         const char *p, *p0 = q_arg;
9682         char *end;
9683         unsigned long int_fld;
9684         char *str_fld[max_num];
9685         int i;
9686         unsigned size;
9687         int ret = -1;
9688
9689         p = strchr(p0, '(');
9690         if (p == NULL)
9691                 return -1;
9692         ++p;
9693         p0 = strchr(p, ')');
9694         if (p0 == NULL)
9695                 return -1;
9696
9697         size = p0 - p;
9698         if (size >= sizeof(s))
9699                 return -1;
9700
9701         snprintf(s, sizeof(s), "%.*s", size, p);
9702         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9703         if (ret < 0 || ret > max_num)
9704                 return -1;
9705         for (i = 0; i < ret; i++) {
9706                 errno = 0;
9707                 int_fld = strtoul(str_fld[i], &end, 0);
9708                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9709                         return -1;
9710                 flexbytes[i] = (uint8_t)int_fld;
9711         }
9712         return ret;
9713 }
9714
9715 static uint16_t
9716 str2flowtype(char *string)
9717 {
9718         uint8_t i = 0;
9719         static const struct {
9720                 char str[32];
9721                 uint16_t type;
9722         } flowtype_str[] = {
9723                 {"raw", RTE_ETH_FLOW_RAW},
9724                 {"ipv4", RTE_ETH_FLOW_IPV4},
9725                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9726                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9727                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9728                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9729                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9730                 {"ipv6", RTE_ETH_FLOW_IPV6},
9731                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9732                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9733                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9734                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9735                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9736                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9737         };
9738
9739         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9740                 if (!strcmp(flowtype_str[i].str, string))
9741                         return flowtype_str[i].type;
9742         }
9743
9744         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9745                 return (uint16_t)atoi(string);
9746
9747         return RTE_ETH_FLOW_UNKNOWN;
9748 }
9749
9750 static enum rte_eth_fdir_tunnel_type
9751 str2fdir_tunneltype(char *string)
9752 {
9753         uint8_t i = 0;
9754
9755         static const struct {
9756                 char str[32];
9757                 enum rte_eth_fdir_tunnel_type type;
9758         } tunneltype_str[] = {
9759                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9760                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9761         };
9762
9763         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9764                 if (!strcmp(tunneltype_str[i].str, string))
9765                         return tunneltype_str[i].type;
9766         }
9767         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9768 }
9769
9770 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9771 do { \
9772         if ((ip_addr).family == AF_INET) \
9773                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9774         else { \
9775                 printf("invalid parameter.\n"); \
9776                 return; \
9777         } \
9778 } while (0)
9779
9780 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9781 do { \
9782         if ((ip_addr).family == AF_INET6) \
9783                 rte_memcpy(&(ip), \
9784                                  &((ip_addr).addr.ipv6), \
9785                                  sizeof(struct in6_addr)); \
9786         else { \
9787                 printf("invalid parameter.\n"); \
9788                 return; \
9789         } \
9790 } while (0)
9791
9792 static void
9793 cmd_flow_director_filter_parsed(void *parsed_result,
9794                           __attribute__((unused)) struct cmdline *cl,
9795                           __attribute__((unused)) void *data)
9796 {
9797         struct cmd_flow_director_result *res = parsed_result;
9798         struct rte_eth_fdir_filter entry;
9799         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9800         char *end;
9801         unsigned long vf_id;
9802         int ret = 0;
9803
9804         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9805         if (ret < 0) {
9806                 printf("flow director is not supported on port %u.\n",
9807                         res->port_id);
9808                 return;
9809         }
9810         memset(flexbytes, 0, sizeof(flexbytes));
9811         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9812
9813         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9814                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9815                         printf("Please set mode to MAC-VLAN.\n");
9816                         return;
9817                 }
9818         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9819                 if (strcmp(res->mode_value, "Tunnel")) {
9820                         printf("Please set mode to Tunnel.\n");
9821                         return;
9822                 }
9823         } else {
9824                 if (strcmp(res->mode_value, "IP")) {
9825                         printf("Please set mode to IP.\n");
9826                         return;
9827                 }
9828                 entry.input.flow_type = str2flowtype(res->flow_type);
9829         }
9830
9831         ret = parse_flexbytes(res->flexbytes_value,
9832                                         flexbytes,
9833                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9834         if (ret < 0) {
9835                 printf("error: Cannot parse flexbytes input.\n");
9836                 return;
9837         }
9838
9839         switch (entry.input.flow_type) {
9840         case RTE_ETH_FLOW_FRAG_IPV4:
9841         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9842                 entry.input.flow.ip4_flow.proto = res->proto_value;
9843                 /* fall-through */
9844         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9845         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9846                 IPV4_ADDR_TO_UINT(res->ip_dst,
9847                         entry.input.flow.ip4_flow.dst_ip);
9848                 IPV4_ADDR_TO_UINT(res->ip_src,
9849                         entry.input.flow.ip4_flow.src_ip);
9850                 entry.input.flow.ip4_flow.tos = res->tos_value;
9851                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9852                 /* need convert to big endian. */
9853                 entry.input.flow.udp4_flow.dst_port =
9854                                 rte_cpu_to_be_16(res->port_dst);
9855                 entry.input.flow.udp4_flow.src_port =
9856                                 rte_cpu_to_be_16(res->port_src);
9857                 break;
9858         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9859                 IPV4_ADDR_TO_UINT(res->ip_dst,
9860                         entry.input.flow.sctp4_flow.ip.dst_ip);
9861                 IPV4_ADDR_TO_UINT(res->ip_src,
9862                         entry.input.flow.sctp4_flow.ip.src_ip);
9863                 entry.input.flow.ip4_flow.tos = res->tos_value;
9864                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9865                 /* need convert to big endian. */
9866                 entry.input.flow.sctp4_flow.dst_port =
9867                                 rte_cpu_to_be_16(res->port_dst);
9868                 entry.input.flow.sctp4_flow.src_port =
9869                                 rte_cpu_to_be_16(res->port_src);
9870                 entry.input.flow.sctp4_flow.verify_tag =
9871                                 rte_cpu_to_be_32(res->verify_tag_value);
9872                 break;
9873         case RTE_ETH_FLOW_FRAG_IPV6:
9874         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9875                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9876                 /* fall-through */
9877         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9878         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9879                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9880                         entry.input.flow.ipv6_flow.dst_ip);
9881                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9882                         entry.input.flow.ipv6_flow.src_ip);
9883                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9884                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9885                 /* need convert to big endian. */
9886                 entry.input.flow.udp6_flow.dst_port =
9887                                 rte_cpu_to_be_16(res->port_dst);
9888                 entry.input.flow.udp6_flow.src_port =
9889                                 rte_cpu_to_be_16(res->port_src);
9890                 break;
9891         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9892                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9893                         entry.input.flow.sctp6_flow.ip.dst_ip);
9894                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9895                         entry.input.flow.sctp6_flow.ip.src_ip);
9896                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9897                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9898                 /* need convert to big endian. */
9899                 entry.input.flow.sctp6_flow.dst_port =
9900                                 rte_cpu_to_be_16(res->port_dst);
9901                 entry.input.flow.sctp6_flow.src_port =
9902                                 rte_cpu_to_be_16(res->port_src);
9903                 entry.input.flow.sctp6_flow.verify_tag =
9904                                 rte_cpu_to_be_32(res->verify_tag_value);
9905                 break;
9906         case RTE_ETH_FLOW_L2_PAYLOAD:
9907                 entry.input.flow.l2_flow.ether_type =
9908                         rte_cpu_to_be_16(res->ether_type);
9909                 break;
9910         default:
9911                 break;
9912         }
9913
9914         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9915                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9916                                  &res->mac_addr,
9917                                  sizeof(struct ether_addr));
9918
9919         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9920                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9921                                  &res->mac_addr,
9922                                  sizeof(struct ether_addr));
9923                 entry.input.flow.tunnel_flow.tunnel_type =
9924                         str2fdir_tunneltype(res->tunnel_type);
9925                 entry.input.flow.tunnel_flow.tunnel_id =
9926                         rte_cpu_to_be_32(res->tunnel_id_value);
9927         }
9928
9929         rte_memcpy(entry.input.flow_ext.flexbytes,
9930                    flexbytes,
9931                    RTE_ETH_FDIR_MAX_FLEXLEN);
9932
9933         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9934
9935         entry.action.flex_off = 0;  /*use 0 by default */
9936         if (!strcmp(res->drop, "drop"))
9937                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9938         else
9939                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9940
9941         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9942             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9943                 if (!strcmp(res->pf_vf, "pf"))
9944                         entry.input.flow_ext.is_vf = 0;
9945                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9946                         struct rte_eth_dev_info dev_info;
9947
9948                         memset(&dev_info, 0, sizeof(dev_info));
9949                         rte_eth_dev_info_get(res->port_id, &dev_info);
9950                         errno = 0;
9951                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9952                         if (errno != 0 || *end != '\0' ||
9953                             vf_id >= dev_info.max_vfs) {
9954                                 printf("invalid parameter %s.\n", res->pf_vf);
9955                                 return;
9956                         }
9957                         entry.input.flow_ext.is_vf = 1;
9958                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9959                 } else {
9960                         printf("invalid parameter %s.\n", res->pf_vf);
9961                         return;
9962                 }
9963         }
9964
9965         /* set to report FD ID by default */
9966         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9967         entry.action.rx_queue = res->queue_id;
9968         entry.soft_id = res->fd_id_value;
9969         if (!strcmp(res->ops, "add"))
9970                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9971                                              RTE_ETH_FILTER_ADD, &entry);
9972         else if (!strcmp(res->ops, "del"))
9973                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9974                                              RTE_ETH_FILTER_DELETE, &entry);
9975         else
9976                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9977                                              RTE_ETH_FILTER_UPDATE, &entry);
9978         if (ret < 0)
9979                 printf("flow director programming error: (%s)\n",
9980                         strerror(-ret));
9981 }
9982
9983 cmdline_parse_token_string_t cmd_flow_director_filter =
9984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9985                                  flow_director_filter, "flow_director_filter");
9986 cmdline_parse_token_num_t cmd_flow_director_port_id =
9987         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9988                               port_id, UINT16);
9989 cmdline_parse_token_string_t cmd_flow_director_ops =
9990         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9991                                  ops, "add#del#update");
9992 cmdline_parse_token_string_t cmd_flow_director_flow =
9993         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9994                                  flow, "flow");
9995 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9996         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9997                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9998                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9999 cmdline_parse_token_string_t cmd_flow_director_ether =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10001                                  ether, "ether");
10002 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10003         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10004                               ether_type, UINT16);
10005 cmdline_parse_token_string_t cmd_flow_director_src =
10006         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10007                                  src, "src");
10008 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10009         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10010                                  ip_src);
10011 cmdline_parse_token_num_t cmd_flow_director_port_src =
10012         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10013                               port_src, UINT16);
10014 cmdline_parse_token_string_t cmd_flow_director_dst =
10015         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10016                                  dst, "dst");
10017 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10018         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10019                                  ip_dst);
10020 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10021         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10022                               port_dst, UINT16);
10023 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10024         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10025                                   verify_tag, "verify_tag");
10026 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10027         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10028                               verify_tag_value, UINT32);
10029 cmdline_parse_token_string_t cmd_flow_director_tos =
10030         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10031                                  tos, "tos");
10032 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10033         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10034                               tos_value, UINT8);
10035 cmdline_parse_token_string_t cmd_flow_director_proto =
10036         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10037                                  proto, "proto");
10038 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10039         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10040                               proto_value, UINT8);
10041 cmdline_parse_token_string_t cmd_flow_director_ttl =
10042         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10043                                  ttl, "ttl");
10044 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10045         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10046                               ttl_value, UINT8);
10047 cmdline_parse_token_string_t cmd_flow_director_vlan =
10048         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10049                                  vlan, "vlan");
10050 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10051         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10052                               vlan_value, UINT16);
10053 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10054         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10055                                  flexbytes, "flexbytes");
10056 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10057         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10058                               flexbytes_value, NULL);
10059 cmdline_parse_token_string_t cmd_flow_director_drop =
10060         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10061                                  drop, "drop#fwd");
10062 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10063         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10064                               pf_vf, NULL);
10065 cmdline_parse_token_string_t cmd_flow_director_queue =
10066         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10067                                  queue, "queue");
10068 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10069         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10070                               queue_id, UINT16);
10071 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10072         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10073                                  fd_id, "fd_id");
10074 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10075         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10076                               fd_id_value, UINT32);
10077
10078 cmdline_parse_token_string_t cmd_flow_director_mode =
10079         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10080                                  mode, "mode");
10081 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10082         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10083                                  mode_value, "IP");
10084 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10085         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10086                                  mode_value, "MAC-VLAN");
10087 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10088         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10089                                  mode_value, "Tunnel");
10090 cmdline_parse_token_string_t cmd_flow_director_mac =
10091         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10092                                  mac, "mac");
10093 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10094         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10095                                     mac_addr);
10096 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10098                                  tunnel, "tunnel");
10099 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10100         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10101                                  tunnel_type, "NVGRE#VxLAN");
10102 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10103         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10104                                  tunnel_id, "tunnel-id");
10105 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10106         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10107                               tunnel_id_value, UINT32);
10108
10109 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10110         .f = cmd_flow_director_filter_parsed,
10111         .data = NULL,
10112         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10113                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10114                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10115                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10116                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10117                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
10118                 "fd_id <fd_id_value>: "
10119                 "Add or delete an ip flow director entry on NIC",
10120         .tokens = {
10121                 (void *)&cmd_flow_director_filter,
10122                 (void *)&cmd_flow_director_port_id,
10123                 (void *)&cmd_flow_director_mode,
10124                 (void *)&cmd_flow_director_mode_ip,
10125                 (void *)&cmd_flow_director_ops,
10126                 (void *)&cmd_flow_director_flow,
10127                 (void *)&cmd_flow_director_flow_type,
10128                 (void *)&cmd_flow_director_src,
10129                 (void *)&cmd_flow_director_ip_src,
10130                 (void *)&cmd_flow_director_dst,
10131                 (void *)&cmd_flow_director_ip_dst,
10132                 (void *)&cmd_flow_director_tos,
10133                 (void *)&cmd_flow_director_tos_value,
10134                 (void *)&cmd_flow_director_proto,
10135                 (void *)&cmd_flow_director_proto_value,
10136                 (void *)&cmd_flow_director_ttl,
10137                 (void *)&cmd_flow_director_ttl_value,
10138                 (void *)&cmd_flow_director_vlan,
10139                 (void *)&cmd_flow_director_vlan_value,
10140                 (void *)&cmd_flow_director_flexbytes,
10141                 (void *)&cmd_flow_director_flexbytes_value,
10142                 (void *)&cmd_flow_director_drop,
10143                 (void *)&cmd_flow_director_pf_vf,
10144                 (void *)&cmd_flow_director_queue,
10145                 (void *)&cmd_flow_director_queue_id,
10146                 (void *)&cmd_flow_director_fd_id,
10147                 (void *)&cmd_flow_director_fd_id_value,
10148                 NULL,
10149         },
10150 };
10151
10152 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10153         .f = cmd_flow_director_filter_parsed,
10154         .data = NULL,
10155         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10156                 "director entry on NIC",
10157         .tokens = {
10158                 (void *)&cmd_flow_director_filter,
10159                 (void *)&cmd_flow_director_port_id,
10160                 (void *)&cmd_flow_director_mode,
10161                 (void *)&cmd_flow_director_mode_ip,
10162                 (void *)&cmd_flow_director_ops,
10163                 (void *)&cmd_flow_director_flow,
10164                 (void *)&cmd_flow_director_flow_type,
10165                 (void *)&cmd_flow_director_src,
10166                 (void *)&cmd_flow_director_ip_src,
10167                 (void *)&cmd_flow_director_port_src,
10168                 (void *)&cmd_flow_director_dst,
10169                 (void *)&cmd_flow_director_ip_dst,
10170                 (void *)&cmd_flow_director_port_dst,
10171                 (void *)&cmd_flow_director_tos,
10172                 (void *)&cmd_flow_director_tos_value,
10173                 (void *)&cmd_flow_director_ttl,
10174                 (void *)&cmd_flow_director_ttl_value,
10175                 (void *)&cmd_flow_director_vlan,
10176                 (void *)&cmd_flow_director_vlan_value,
10177                 (void *)&cmd_flow_director_flexbytes,
10178                 (void *)&cmd_flow_director_flexbytes_value,
10179                 (void *)&cmd_flow_director_drop,
10180                 (void *)&cmd_flow_director_pf_vf,
10181                 (void *)&cmd_flow_director_queue,
10182                 (void *)&cmd_flow_director_queue_id,
10183                 (void *)&cmd_flow_director_fd_id,
10184                 (void *)&cmd_flow_director_fd_id_value,
10185                 NULL,
10186         },
10187 };
10188
10189 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10190         .f = cmd_flow_director_filter_parsed,
10191         .data = NULL,
10192         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10193                 "director entry on NIC",
10194         .tokens = {
10195                 (void *)&cmd_flow_director_filter,
10196                 (void *)&cmd_flow_director_port_id,
10197                 (void *)&cmd_flow_director_mode,
10198                 (void *)&cmd_flow_director_mode_ip,
10199                 (void *)&cmd_flow_director_ops,
10200                 (void *)&cmd_flow_director_flow,
10201                 (void *)&cmd_flow_director_flow_type,
10202                 (void *)&cmd_flow_director_src,
10203                 (void *)&cmd_flow_director_ip_src,
10204                 (void *)&cmd_flow_director_port_dst,
10205                 (void *)&cmd_flow_director_dst,
10206                 (void *)&cmd_flow_director_ip_dst,
10207                 (void *)&cmd_flow_director_port_dst,
10208                 (void *)&cmd_flow_director_verify_tag,
10209                 (void *)&cmd_flow_director_verify_tag_value,
10210                 (void *)&cmd_flow_director_tos,
10211                 (void *)&cmd_flow_director_tos_value,
10212                 (void *)&cmd_flow_director_ttl,
10213                 (void *)&cmd_flow_director_ttl_value,
10214                 (void *)&cmd_flow_director_vlan,
10215                 (void *)&cmd_flow_director_vlan_value,
10216                 (void *)&cmd_flow_director_flexbytes,
10217                 (void *)&cmd_flow_director_flexbytes_value,
10218                 (void *)&cmd_flow_director_drop,
10219                 (void *)&cmd_flow_director_pf_vf,
10220                 (void *)&cmd_flow_director_queue,
10221                 (void *)&cmd_flow_director_queue_id,
10222                 (void *)&cmd_flow_director_fd_id,
10223                 (void *)&cmd_flow_director_fd_id_value,
10224                 NULL,
10225         },
10226 };
10227
10228 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10229         .f = cmd_flow_director_filter_parsed,
10230         .data = NULL,
10231         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10232                 "director entry on NIC",
10233         .tokens = {
10234                 (void *)&cmd_flow_director_filter,
10235                 (void *)&cmd_flow_director_port_id,
10236                 (void *)&cmd_flow_director_mode,
10237                 (void *)&cmd_flow_director_mode_ip,
10238                 (void *)&cmd_flow_director_ops,
10239                 (void *)&cmd_flow_director_flow,
10240                 (void *)&cmd_flow_director_flow_type,
10241                 (void *)&cmd_flow_director_ether,
10242                 (void *)&cmd_flow_director_ether_type,
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_mac_vlan_flow_director = {
10256         .f = cmd_flow_director_filter_parsed,
10257         .data = NULL,
10258         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN 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_mac_vlan,
10265                 (void *)&cmd_flow_director_ops,
10266                 (void *)&cmd_flow_director_mac,
10267                 (void *)&cmd_flow_director_mac_addr,
10268                 (void *)&cmd_flow_director_vlan,
10269                 (void *)&cmd_flow_director_vlan_value,
10270                 (void *)&cmd_flow_director_flexbytes,
10271                 (void *)&cmd_flow_director_flexbytes_value,
10272                 (void *)&cmd_flow_director_drop,
10273                 (void *)&cmd_flow_director_queue,
10274                 (void *)&cmd_flow_director_queue_id,
10275                 (void *)&cmd_flow_director_fd_id,
10276                 (void *)&cmd_flow_director_fd_id_value,
10277                 NULL,
10278         },
10279 };
10280
10281 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10282         .f = cmd_flow_director_filter_parsed,
10283         .data = NULL,
10284         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10285                 "director entry on NIC",
10286         .tokens = {
10287                 (void *)&cmd_flow_director_filter,
10288                 (void *)&cmd_flow_director_port_id,
10289                 (void *)&cmd_flow_director_mode,
10290                 (void *)&cmd_flow_director_mode_tunnel,
10291                 (void *)&cmd_flow_director_ops,
10292                 (void *)&cmd_flow_director_mac,
10293                 (void *)&cmd_flow_director_mac_addr,
10294                 (void *)&cmd_flow_director_vlan,
10295                 (void *)&cmd_flow_director_vlan_value,
10296                 (void *)&cmd_flow_director_tunnel,
10297                 (void *)&cmd_flow_director_tunnel_type,
10298                 (void *)&cmd_flow_director_tunnel_id,
10299                 (void *)&cmd_flow_director_tunnel_id_value,
10300                 (void *)&cmd_flow_director_flexbytes,
10301                 (void *)&cmd_flow_director_flexbytes_value,
10302                 (void *)&cmd_flow_director_drop,
10303                 (void *)&cmd_flow_director_queue,
10304                 (void *)&cmd_flow_director_queue_id,
10305                 (void *)&cmd_flow_director_fd_id,
10306                 (void *)&cmd_flow_director_fd_id_value,
10307                 NULL,
10308         },
10309 };
10310
10311 struct cmd_flush_flow_director_result {
10312         cmdline_fixed_string_t flush_flow_director;
10313         portid_t port_id;
10314 };
10315
10316 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10317         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10318                                  flush_flow_director, "flush_flow_director");
10319 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10320         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10321                               port_id, UINT16);
10322
10323 static void
10324 cmd_flush_flow_director_parsed(void *parsed_result,
10325                           __attribute__((unused)) struct cmdline *cl,
10326                           __attribute__((unused)) void *data)
10327 {
10328         struct cmd_flow_director_result *res = parsed_result;
10329         int ret = 0;
10330
10331         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10332         if (ret < 0) {
10333                 printf("flow director is not supported on port %u.\n",
10334                         res->port_id);
10335                 return;
10336         }
10337
10338         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10339                         RTE_ETH_FILTER_FLUSH, NULL);
10340         if (ret < 0)
10341                 printf("flow director table flushing error: (%s)\n",
10342                         strerror(-ret));
10343 }
10344
10345 cmdline_parse_inst_t cmd_flush_flow_director = {
10346         .f = cmd_flush_flow_director_parsed,
10347         .data = NULL,
10348         .help_str = "flush_flow_director <port_id>: "
10349                 "Flush all flow director entries of a device on NIC",
10350         .tokens = {
10351                 (void *)&cmd_flush_flow_director_flush,
10352                 (void *)&cmd_flush_flow_director_port_id,
10353                 NULL,
10354         },
10355 };
10356
10357 /* *** deal with flow director mask *** */
10358 struct cmd_flow_director_mask_result {
10359         cmdline_fixed_string_t flow_director_mask;
10360         portid_t port_id;
10361         cmdline_fixed_string_t mode;
10362         cmdline_fixed_string_t mode_value;
10363         cmdline_fixed_string_t vlan;
10364         uint16_t vlan_mask;
10365         cmdline_fixed_string_t src_mask;
10366         cmdline_ipaddr_t ipv4_src;
10367         cmdline_ipaddr_t ipv6_src;
10368         uint16_t port_src;
10369         cmdline_fixed_string_t dst_mask;
10370         cmdline_ipaddr_t ipv4_dst;
10371         cmdline_ipaddr_t ipv6_dst;
10372         uint16_t port_dst;
10373         cmdline_fixed_string_t mac;
10374         uint8_t mac_addr_byte_mask;
10375         cmdline_fixed_string_t tunnel_id;
10376         uint32_t tunnel_id_mask;
10377         cmdline_fixed_string_t tunnel_type;
10378         uint8_t tunnel_type_mask;
10379 };
10380
10381 static void
10382 cmd_flow_director_mask_parsed(void *parsed_result,
10383                           __attribute__((unused)) struct cmdline *cl,
10384                           __attribute__((unused)) void *data)
10385 {
10386         struct cmd_flow_director_mask_result *res = parsed_result;
10387         struct rte_eth_fdir_masks *mask;
10388         struct rte_port *port;
10389
10390         if (res->port_id > nb_ports) {
10391                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10392                 return;
10393         }
10394
10395         port = &ports[res->port_id];
10396         /** Check if the port is not started **/
10397         if (port->port_status != RTE_PORT_STOPPED) {
10398                 printf("Please stop port %d first\n", res->port_id);
10399                 return;
10400         }
10401
10402         mask = &port->dev_conf.fdir_conf.mask;
10403
10404         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10405                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10406                         printf("Please set mode to MAC-VLAN.\n");
10407                         return;
10408                 }
10409
10410                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10411         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10412                 if (strcmp(res->mode_value, "Tunnel")) {
10413                         printf("Please set mode to Tunnel.\n");
10414                         return;
10415                 }
10416
10417                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10418                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10419                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10420                 mask->tunnel_type_mask = res->tunnel_type_mask;
10421         } else {
10422                 if (strcmp(res->mode_value, "IP")) {
10423                         printf("Please set mode to IP.\n");
10424                         return;
10425                 }
10426
10427                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10428                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10429                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10430                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10431                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10432                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10433                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10434         }
10435
10436         cmd_reconfig_device_queue(res->port_id, 1, 1);
10437 }
10438
10439 cmdline_parse_token_string_t cmd_flow_director_mask =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10441                                  flow_director_mask, "flow_director_mask");
10442 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10444                               port_id, UINT16);
10445 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10447                                  vlan, "vlan");
10448 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10449         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10450                               vlan_mask, UINT16);
10451 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10452         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10453                                  src_mask, "src_mask");
10454 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10455         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10456                                  ipv4_src);
10457 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10458         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10459                                  ipv6_src);
10460 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10461         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10462                               port_src, UINT16);
10463 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10464         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10465                                  dst_mask, "dst_mask");
10466 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10467         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10468                                  ipv4_dst);
10469 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10470         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10471                                  ipv6_dst);
10472 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10473         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10474                               port_dst, UINT16);
10475
10476 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10478                                  mode, "mode");
10479 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10480         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10481                                  mode_value, "IP");
10482 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10483         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10484                                  mode_value, "MAC-VLAN");
10485 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10486         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10487                                  mode_value, "Tunnel");
10488 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10489         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10490                                  mac, "mac");
10491 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10492         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10493                               mac_addr_byte_mask, UINT8);
10494 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10495         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10496                                  tunnel_type, "tunnel-type");
10497 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10498         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10499                               tunnel_type_mask, UINT8);
10500 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10501         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10502                                  tunnel_id, "tunnel-id");
10503 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10504         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10505                               tunnel_id_mask, UINT32);
10506
10507 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10508         .f = cmd_flow_director_mask_parsed,
10509         .data = NULL,
10510         .help_str = "flow_director_mask ... : "
10511                 "Set IP mode flow director's mask on NIC",
10512         .tokens = {
10513                 (void *)&cmd_flow_director_mask,
10514                 (void *)&cmd_flow_director_mask_port_id,
10515                 (void *)&cmd_flow_director_mask_mode,
10516                 (void *)&cmd_flow_director_mask_mode_ip,
10517                 (void *)&cmd_flow_director_mask_vlan,
10518                 (void *)&cmd_flow_director_mask_vlan_value,
10519                 (void *)&cmd_flow_director_mask_src,
10520                 (void *)&cmd_flow_director_mask_ipv4_src,
10521                 (void *)&cmd_flow_director_mask_ipv6_src,
10522                 (void *)&cmd_flow_director_mask_port_src,
10523                 (void *)&cmd_flow_director_mask_dst,
10524                 (void *)&cmd_flow_director_mask_ipv4_dst,
10525                 (void *)&cmd_flow_director_mask_ipv6_dst,
10526                 (void *)&cmd_flow_director_mask_port_dst,
10527                 NULL,
10528         },
10529 };
10530
10531 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10532         .f = cmd_flow_director_mask_parsed,
10533         .data = NULL,
10534         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10535                 "flow director's mask on NIC",
10536         .tokens = {
10537                 (void *)&cmd_flow_director_mask,
10538                 (void *)&cmd_flow_director_mask_port_id,
10539                 (void *)&cmd_flow_director_mask_mode,
10540                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10541                 (void *)&cmd_flow_director_mask_vlan,
10542                 (void *)&cmd_flow_director_mask_vlan_value,
10543                 NULL,
10544         },
10545 };
10546
10547 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10548         .f = cmd_flow_director_mask_parsed,
10549         .data = NULL,
10550         .help_str = "flow_director_mask ... : Set tunnel mode "
10551                 "flow director's mask on NIC",
10552         .tokens = {
10553                 (void *)&cmd_flow_director_mask,
10554                 (void *)&cmd_flow_director_mask_port_id,
10555                 (void *)&cmd_flow_director_mask_mode,
10556                 (void *)&cmd_flow_director_mask_mode_tunnel,
10557                 (void *)&cmd_flow_director_mask_vlan,
10558                 (void *)&cmd_flow_director_mask_vlan_value,
10559                 (void *)&cmd_flow_director_mask_mac,
10560                 (void *)&cmd_flow_director_mask_mac_value,
10561                 (void *)&cmd_flow_director_mask_tunnel_type,
10562                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10563                 (void *)&cmd_flow_director_mask_tunnel_id,
10564                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10565                 NULL,
10566         },
10567 };
10568
10569 /* *** deal with flow director mask on flexible payload *** */
10570 struct cmd_flow_director_flex_mask_result {
10571         cmdline_fixed_string_t flow_director_flexmask;
10572         portid_t port_id;
10573         cmdline_fixed_string_t flow;
10574         cmdline_fixed_string_t flow_type;
10575         cmdline_fixed_string_t mask;
10576 };
10577
10578 static void
10579 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10580                           __attribute__((unused)) struct cmdline *cl,
10581                           __attribute__((unused)) void *data)
10582 {
10583         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10584         struct rte_eth_fdir_info fdir_info;
10585         struct rte_eth_fdir_flex_mask flex_mask;
10586         struct rte_port *port;
10587         uint32_t flow_type_mask;
10588         uint16_t i;
10589         int ret;
10590
10591         if (res->port_id > nb_ports) {
10592                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10593                 return;
10594         }
10595
10596         port = &ports[res->port_id];
10597         /** Check if the port is not started **/
10598         if (port->port_status != RTE_PORT_STOPPED) {
10599                 printf("Please stop port %d first\n", res->port_id);
10600                 return;
10601         }
10602
10603         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10604         ret = parse_flexbytes(res->mask,
10605                         flex_mask.mask,
10606                         RTE_ETH_FDIR_MAX_FLEXLEN);
10607         if (ret < 0) {
10608                 printf("error: Cannot parse mask input.\n");
10609                 return;
10610         }
10611
10612         memset(&fdir_info, 0, sizeof(fdir_info));
10613         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10614                                 RTE_ETH_FILTER_INFO, &fdir_info);
10615         if (ret < 0) {
10616                 printf("Cannot get FDir filter info\n");
10617                 return;
10618         }
10619
10620         if (!strcmp(res->flow_type, "none")) {
10621                 /* means don't specify the flow type */
10622                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10623                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10624                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10625                                0, sizeof(struct rte_eth_fdir_flex_mask));
10626                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10627                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10628                                  &flex_mask,
10629                                  sizeof(struct rte_eth_fdir_flex_mask));
10630                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10631                 return;
10632         }
10633         flow_type_mask = fdir_info.flow_types_mask[0];
10634         if (!strcmp(res->flow_type, "all")) {
10635                 if (!flow_type_mask) {
10636                         printf("No flow type supported\n");
10637                         return;
10638                 }
10639                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10640                         if (flow_type_mask & (1 << i)) {
10641                                 flex_mask.flow_type = i;
10642                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10643                         }
10644                 }
10645                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10646                 return;
10647         }
10648         flex_mask.flow_type = str2flowtype(res->flow_type);
10649         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10650                 printf("Flow type %s not supported on port %d\n",
10651                                 res->flow_type, res->port_id);
10652                 return;
10653         }
10654         fdir_set_flex_mask(res->port_id, &flex_mask);
10655         cmd_reconfig_device_queue(res->port_id, 1, 1);
10656 }
10657
10658 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10659         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10660                                  flow_director_flexmask,
10661                                  "flow_director_flex_mask");
10662 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10663         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10664                               port_id, UINT16);
10665 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10666         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10667                                  flow, "flow");
10668 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10669         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10670                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10671                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10672 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10673         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10674                                  mask, NULL);
10675
10676 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10677         .f = cmd_flow_director_flex_mask_parsed,
10678         .data = NULL,
10679         .help_str = "flow_director_flex_mask ... : "
10680                 "Set flow director's flex mask on NIC",
10681         .tokens = {
10682                 (void *)&cmd_flow_director_flexmask,
10683                 (void *)&cmd_flow_director_flexmask_port_id,
10684                 (void *)&cmd_flow_director_flexmask_flow,
10685                 (void *)&cmd_flow_director_flexmask_flow_type,
10686                 (void *)&cmd_flow_director_flexmask_mask,
10687                 NULL,
10688         },
10689 };
10690
10691 /* *** deal with flow director flexible payload configuration *** */
10692 struct cmd_flow_director_flexpayload_result {
10693         cmdline_fixed_string_t flow_director_flexpayload;
10694         portid_t port_id;
10695         cmdline_fixed_string_t payload_layer;
10696         cmdline_fixed_string_t payload_cfg;
10697 };
10698
10699 static inline int
10700 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10701 {
10702         char s[256];
10703         const char *p, *p0 = q_arg;
10704         char *end;
10705         unsigned long int_fld;
10706         char *str_fld[max_num];
10707         int i;
10708         unsigned size;
10709         int ret = -1;
10710
10711         p = strchr(p0, '(');
10712         if (p == NULL)
10713                 return -1;
10714         ++p;
10715         p0 = strchr(p, ')');
10716         if (p0 == NULL)
10717                 return -1;
10718
10719         size = p0 - p;
10720         if (size >= sizeof(s))
10721                 return -1;
10722
10723         snprintf(s, sizeof(s), "%.*s", size, p);
10724         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10725         if (ret < 0 || ret > max_num)
10726                 return -1;
10727         for (i = 0; i < ret; i++) {
10728                 errno = 0;
10729                 int_fld = strtoul(str_fld[i], &end, 0);
10730                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10731                         return -1;
10732                 offsets[i] = (uint16_t)int_fld;
10733         }
10734         return ret;
10735 }
10736
10737 static void
10738 cmd_flow_director_flxpld_parsed(void *parsed_result,
10739                           __attribute__((unused)) struct cmdline *cl,
10740                           __attribute__((unused)) void *data)
10741 {
10742         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10743         struct rte_eth_flex_payload_cfg flex_cfg;
10744         struct rte_port *port;
10745         int ret = 0;
10746
10747         if (res->port_id > nb_ports) {
10748                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10749                 return;
10750         }
10751
10752         port = &ports[res->port_id];
10753         /** Check if the port is not started **/
10754         if (port->port_status != RTE_PORT_STOPPED) {
10755                 printf("Please stop port %d first\n", res->port_id);
10756                 return;
10757         }
10758
10759         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10760
10761         if (!strcmp(res->payload_layer, "raw"))
10762                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10763         else if (!strcmp(res->payload_layer, "l2"))
10764                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10765         else if (!strcmp(res->payload_layer, "l3"))
10766                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10767         else if (!strcmp(res->payload_layer, "l4"))
10768                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10769
10770         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10771                             RTE_ETH_FDIR_MAX_FLEXLEN);
10772         if (ret < 0) {
10773                 printf("error: Cannot parse flex payload input.\n");
10774                 return;
10775         }
10776
10777         fdir_set_flex_payload(res->port_id, &flex_cfg);
10778         cmd_reconfig_device_queue(res->port_id, 1, 1);
10779 }
10780
10781 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10782         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10783                                  flow_director_flexpayload,
10784                                  "flow_director_flex_payload");
10785 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10786         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10787                               port_id, UINT16);
10788 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10789         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10790                                  payload_layer, "raw#l2#l3#l4");
10791 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10793                                  payload_cfg, NULL);
10794
10795 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10796         .f = cmd_flow_director_flxpld_parsed,
10797         .data = NULL,
10798         .help_str = "flow_director_flexpayload ... : "
10799                 "Set flow director's flex payload on NIC",
10800         .tokens = {
10801                 (void *)&cmd_flow_director_flexpayload,
10802                 (void *)&cmd_flow_director_flexpayload_port_id,
10803                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10804                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10805                 NULL,
10806         },
10807 };
10808
10809 /* Generic flow interface command. */
10810 extern cmdline_parse_inst_t cmd_flow;
10811
10812 /* *** Classification Filters Control *** */
10813 /* *** Get symmetric hash enable per port *** */
10814 struct cmd_get_sym_hash_ena_per_port_result {
10815         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10816         portid_t port_id;
10817 };
10818
10819 static void
10820 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10821                                  __rte_unused struct cmdline *cl,
10822                                  __rte_unused void *data)
10823 {
10824         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10825         struct rte_eth_hash_filter_info info;
10826         int ret;
10827
10828         if (rte_eth_dev_filter_supported(res->port_id,
10829                                 RTE_ETH_FILTER_HASH) < 0) {
10830                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10831                                                         res->port_id);
10832                 return;
10833         }
10834
10835         memset(&info, 0, sizeof(info));
10836         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10837         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10838                                                 RTE_ETH_FILTER_GET, &info);
10839
10840         if (ret < 0) {
10841                 printf("Cannot get symmetric hash enable per port "
10842                                         "on port %u\n", res->port_id);
10843                 return;
10844         }
10845
10846         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10847                                 "enabled" : "disabled", res->port_id);
10848 }
10849
10850 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10851         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10852                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10853 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10854         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10855                 port_id, UINT16);
10856
10857 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10858         .f = cmd_get_sym_hash_per_port_parsed,
10859         .data = NULL,
10860         .help_str = "get_sym_hash_ena_per_port <port_id>",
10861         .tokens = {
10862                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10863                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10864                 NULL,
10865         },
10866 };
10867
10868 /* *** Set symmetric hash enable per port *** */
10869 struct cmd_set_sym_hash_ena_per_port_result {
10870         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10871         cmdline_fixed_string_t enable;
10872         portid_t port_id;
10873 };
10874
10875 static void
10876 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10877                                  __rte_unused struct cmdline *cl,
10878                                  __rte_unused void *data)
10879 {
10880         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10881         struct rte_eth_hash_filter_info info;
10882         int ret;
10883
10884         if (rte_eth_dev_filter_supported(res->port_id,
10885                                 RTE_ETH_FILTER_HASH) < 0) {
10886                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10887                                                         res->port_id);
10888                 return;
10889         }
10890
10891         memset(&info, 0, sizeof(info));
10892         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10893         if (!strcmp(res->enable, "enable"))
10894                 info.info.enable = 1;
10895         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10896                                         RTE_ETH_FILTER_SET, &info);
10897         if (ret < 0) {
10898                 printf("Cannot set symmetric hash enable per port on "
10899                                         "port %u\n", res->port_id);
10900                 return;
10901         }
10902         printf("Symmetric hash has been set to %s on port %u\n",
10903                                         res->enable, res->port_id);
10904 }
10905
10906 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10907         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10908                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10909 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10910         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10911                 port_id, UINT16);
10912 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10913         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10914                 enable, "enable#disable");
10915
10916 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10917         .f = cmd_set_sym_hash_per_port_parsed,
10918         .data = NULL,
10919         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10920         .tokens = {
10921                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10922                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10923                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10924                 NULL,
10925         },
10926 };
10927
10928 /* Get global config of hash function */
10929 struct cmd_get_hash_global_config_result {
10930         cmdline_fixed_string_t get_hash_global_config;
10931         portid_t port_id;
10932 };
10933
10934 static char *
10935 flowtype_to_str(uint16_t ftype)
10936 {
10937         uint16_t i;
10938         static struct {
10939                 char str[16];
10940                 uint16_t ftype;
10941         } ftype_table[] = {
10942                 {"ipv4", RTE_ETH_FLOW_IPV4},
10943                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10944                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10945                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10946                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10947                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10948                 {"ipv6", RTE_ETH_FLOW_IPV6},
10949                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10950                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10951                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10952                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10953                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10954                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10955                 {"port", RTE_ETH_FLOW_PORT},
10956                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10957                 {"geneve", RTE_ETH_FLOW_GENEVE},
10958                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10959         };
10960
10961         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10962                 if (ftype_table[i].ftype == ftype)
10963                         return ftype_table[i].str;
10964         }
10965
10966         return NULL;
10967 }
10968
10969 static void
10970 cmd_get_hash_global_config_parsed(void *parsed_result,
10971                                   __rte_unused struct cmdline *cl,
10972                                   __rte_unused void *data)
10973 {
10974         struct cmd_get_hash_global_config_result *res = parsed_result;
10975         struct rte_eth_hash_filter_info info;
10976         uint32_t idx, offset;
10977         uint16_t i;
10978         char *str;
10979         int ret;
10980
10981         if (rte_eth_dev_filter_supported(res->port_id,
10982                         RTE_ETH_FILTER_HASH) < 0) {
10983                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10984                                                         res->port_id);
10985                 return;
10986         }
10987
10988         memset(&info, 0, sizeof(info));
10989         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10990         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10991                                         RTE_ETH_FILTER_GET, &info);
10992         if (ret < 0) {
10993                 printf("Cannot get hash global configurations by port %d\n",
10994                                                         res->port_id);
10995                 return;
10996         }
10997
10998         switch (info.info.global_conf.hash_func) {
10999         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11000                 printf("Hash function is Toeplitz\n");
11001                 break;
11002         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11003                 printf("Hash function is Simple XOR\n");
11004                 break;
11005         default:
11006                 printf("Unknown hash function\n");
11007                 break;
11008         }
11009
11010         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11011                 idx = i / UINT32_BIT;
11012                 offset = i % UINT32_BIT;
11013                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11014                                                 (1UL << offset)))
11015                         continue;
11016                 str = flowtype_to_str(i);
11017                 if (!str)
11018                         continue;
11019                 printf("Symmetric hash is %s globally for flow type %s "
11020                                                         "by port %d\n",
11021                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11022                         (1UL << offset)) ? "enabled" : "disabled"), str,
11023                                                         res->port_id);
11024         }
11025 }
11026
11027 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11028         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11029                 get_hash_global_config, "get_hash_global_config");
11030 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11031         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11032                 port_id, UINT16);
11033
11034 cmdline_parse_inst_t cmd_get_hash_global_config = {
11035         .f = cmd_get_hash_global_config_parsed,
11036         .data = NULL,
11037         .help_str = "get_hash_global_config <port_id>",
11038         .tokens = {
11039                 (void *)&cmd_get_hash_global_config_all,
11040                 (void *)&cmd_get_hash_global_config_port_id,
11041                 NULL,
11042         },
11043 };
11044
11045 /* Set global config of hash function */
11046 struct cmd_set_hash_global_config_result {
11047         cmdline_fixed_string_t set_hash_global_config;
11048         portid_t port_id;
11049         cmdline_fixed_string_t hash_func;
11050         cmdline_fixed_string_t flow_type;
11051         cmdline_fixed_string_t enable;
11052 };
11053
11054 static void
11055 cmd_set_hash_global_config_parsed(void *parsed_result,
11056                                   __rte_unused struct cmdline *cl,
11057                                   __rte_unused void *data)
11058 {
11059         struct cmd_set_hash_global_config_result *res = parsed_result;
11060         struct rte_eth_hash_filter_info info;
11061         uint32_t ftype, idx, offset;
11062         int ret;
11063
11064         if (rte_eth_dev_filter_supported(res->port_id,
11065                                 RTE_ETH_FILTER_HASH) < 0) {
11066                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11067                                                         res->port_id);
11068                 return;
11069         }
11070         memset(&info, 0, sizeof(info));
11071         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11072         if (!strcmp(res->hash_func, "toeplitz"))
11073                 info.info.global_conf.hash_func =
11074                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11075         else if (!strcmp(res->hash_func, "simple_xor"))
11076                 info.info.global_conf.hash_func =
11077                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11078         else if (!strcmp(res->hash_func, "default"))
11079                 info.info.global_conf.hash_func =
11080                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11081
11082         ftype = str2flowtype(res->flow_type);
11083         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11084         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11085         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11086         if (!strcmp(res->enable, "enable"))
11087                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11088                                                 (1UL << offset);
11089         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11090                                         RTE_ETH_FILTER_SET, &info);
11091         if (ret < 0)
11092                 printf("Cannot set global hash configurations by port %d\n",
11093                                                         res->port_id);
11094         else
11095                 printf("Global hash configurations have been set "
11096                         "succcessfully by port %d\n", res->port_id);
11097 }
11098
11099 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11100         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11101                 set_hash_global_config, "set_hash_global_config");
11102 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11103         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11104                 port_id, UINT16);
11105 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11106         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11107                 hash_func, "toeplitz#simple_xor#default");
11108 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11109         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11110                 flow_type,
11111                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11112                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11113 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11114         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11115                 enable, "enable#disable");
11116
11117 cmdline_parse_inst_t cmd_set_hash_global_config = {
11118         .f = cmd_set_hash_global_config_parsed,
11119         .data = NULL,
11120         .help_str = "set_hash_global_config <port_id> "
11121                 "toeplitz|simple_xor|default "
11122                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11123                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11124                 "l2_payload enable|disable",
11125         .tokens = {
11126                 (void *)&cmd_set_hash_global_config_all,
11127                 (void *)&cmd_set_hash_global_config_port_id,
11128                 (void *)&cmd_set_hash_global_config_hash_func,
11129                 (void *)&cmd_set_hash_global_config_flow_type,
11130                 (void *)&cmd_set_hash_global_config_enable,
11131                 NULL,
11132         },
11133 };
11134
11135 /* Set hash input set */
11136 struct cmd_set_hash_input_set_result {
11137         cmdline_fixed_string_t set_hash_input_set;
11138         portid_t port_id;
11139         cmdline_fixed_string_t flow_type;
11140         cmdline_fixed_string_t inset_field;
11141         cmdline_fixed_string_t select;
11142 };
11143
11144 static enum rte_eth_input_set_field
11145 str2inset(char *string)
11146 {
11147         uint16_t i;
11148
11149         static const struct {
11150                 char str[32];
11151                 enum rte_eth_input_set_field inset;
11152         } inset_table[] = {
11153                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11154                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11155                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11156                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11157                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11158                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11159                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11160                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11161                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11162                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11163                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11164                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11165                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11166                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11167                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11168                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11169                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11170                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11171                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11172                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11173                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11174                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11175                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11176                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11177                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11178                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11179                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11180                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11181                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11182                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11183                 {"none", RTE_ETH_INPUT_SET_NONE},
11184         };
11185
11186         for (i = 0; i < RTE_DIM(inset_table); i++) {
11187                 if (!strcmp(string, inset_table[i].str))
11188                         return inset_table[i].inset;
11189         }
11190
11191         return RTE_ETH_INPUT_SET_UNKNOWN;
11192 }
11193
11194 static void
11195 cmd_set_hash_input_set_parsed(void *parsed_result,
11196                               __rte_unused struct cmdline *cl,
11197                               __rte_unused void *data)
11198 {
11199         struct cmd_set_hash_input_set_result *res = parsed_result;
11200         struct rte_eth_hash_filter_info info;
11201
11202         memset(&info, 0, sizeof(info));
11203         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11204         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11205         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11206         info.info.input_set_conf.inset_size = 1;
11207         if (!strcmp(res->select, "select"))
11208                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11209         else if (!strcmp(res->select, "add"))
11210                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11211         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11212                                 RTE_ETH_FILTER_SET, &info);
11213 }
11214
11215 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11216         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11217                 set_hash_input_set, "set_hash_input_set");
11218 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11219         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11220                 port_id, UINT16);
11221 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11222         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11223                 flow_type, NULL);
11224 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11225         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11226                 inset_field,
11227                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11228                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11229                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11230                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11231                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11232                 "fld-8th#none");
11233 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11234         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11235                 select, "select#add");
11236
11237 cmdline_parse_inst_t cmd_set_hash_input_set = {
11238         .f = cmd_set_hash_input_set_parsed,
11239         .data = NULL,
11240         .help_str = "set_hash_input_set <port_id> "
11241         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11242         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11243         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11244         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11245         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11246         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11247         "fld-7th|fld-8th|none select|add",
11248         .tokens = {
11249                 (void *)&cmd_set_hash_input_set_cmd,
11250                 (void *)&cmd_set_hash_input_set_port_id,
11251                 (void *)&cmd_set_hash_input_set_flow_type,
11252                 (void *)&cmd_set_hash_input_set_field,
11253                 (void *)&cmd_set_hash_input_set_select,
11254                 NULL,
11255         },
11256 };
11257
11258 /* Set flow director input set */
11259 struct cmd_set_fdir_input_set_result {
11260         cmdline_fixed_string_t set_fdir_input_set;
11261         portid_t port_id;
11262         cmdline_fixed_string_t flow_type;
11263         cmdline_fixed_string_t inset_field;
11264         cmdline_fixed_string_t select;
11265 };
11266
11267 static void
11268 cmd_set_fdir_input_set_parsed(void *parsed_result,
11269         __rte_unused struct cmdline *cl,
11270         __rte_unused void *data)
11271 {
11272         struct cmd_set_fdir_input_set_result *res = parsed_result;
11273         struct rte_eth_fdir_filter_info info;
11274
11275         memset(&info, 0, sizeof(info));
11276         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11277         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11278         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11279         info.info.input_set_conf.inset_size = 1;
11280         if (!strcmp(res->select, "select"))
11281                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11282         else if (!strcmp(res->select, "add"))
11283                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11284         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11285                 RTE_ETH_FILTER_SET, &info);
11286 }
11287
11288 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11289         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11290         set_fdir_input_set, "set_fdir_input_set");
11291 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11292         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11293         port_id, UINT16);
11294 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11295         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11296         flow_type,
11297         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11298         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11299 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11300         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11301         inset_field,
11302         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11303         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11304         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11305         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11306         "sctp-veri-tag#none");
11307 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11308         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11309         select, "select#add");
11310
11311 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11312         .f = cmd_set_fdir_input_set_parsed,
11313         .data = NULL,
11314         .help_str = "set_fdir_input_set <port_id> "
11315         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11316         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11317         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11318         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11319         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11320         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11321         "sctp-veri-tag|none select|add",
11322         .tokens = {
11323                 (void *)&cmd_set_fdir_input_set_cmd,
11324                 (void *)&cmd_set_fdir_input_set_port_id,
11325                 (void *)&cmd_set_fdir_input_set_flow_type,
11326                 (void *)&cmd_set_fdir_input_set_field,
11327                 (void *)&cmd_set_fdir_input_set_select,
11328                 NULL,
11329         },
11330 };
11331
11332 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11333 struct cmd_mcast_addr_result {
11334         cmdline_fixed_string_t mcast_addr_cmd;
11335         cmdline_fixed_string_t what;
11336         uint16_t port_num;
11337         struct ether_addr mc_addr;
11338 };
11339
11340 static void cmd_mcast_addr_parsed(void *parsed_result,
11341                 __attribute__((unused)) struct cmdline *cl,
11342                 __attribute__((unused)) void *data)
11343 {
11344         struct cmd_mcast_addr_result *res = parsed_result;
11345
11346         if (!is_multicast_ether_addr(&res->mc_addr)) {
11347                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11348                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11349                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11350                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11351                 return;
11352         }
11353         if (strcmp(res->what, "add") == 0)
11354                 mcast_addr_add(res->port_num, &res->mc_addr);
11355         else
11356                 mcast_addr_remove(res->port_num, &res->mc_addr);
11357 }
11358
11359 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11360         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11361                                  mcast_addr_cmd, "mcast_addr");
11362 cmdline_parse_token_string_t cmd_mcast_addr_what =
11363         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11364                                  "add#remove");
11365 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11366         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11367 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11368         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11369
11370 cmdline_parse_inst_t cmd_mcast_addr = {
11371         .f = cmd_mcast_addr_parsed,
11372         .data = (void *)0,
11373         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11374                 "Add/Remove multicast MAC address on port_id",
11375         .tokens = {
11376                 (void *)&cmd_mcast_addr_cmd,
11377                 (void *)&cmd_mcast_addr_what,
11378                 (void *)&cmd_mcast_addr_portnum,
11379                 (void *)&cmd_mcast_addr_addr,
11380                 NULL,
11381         },
11382 };
11383
11384 /* l2 tunnel config
11385  * only support E-tag now.
11386  */
11387
11388 /* Ether type config */
11389 struct cmd_config_l2_tunnel_eth_type_result {
11390         cmdline_fixed_string_t port;
11391         cmdline_fixed_string_t config;
11392         cmdline_fixed_string_t all;
11393         uint8_t id;
11394         cmdline_fixed_string_t l2_tunnel;
11395         cmdline_fixed_string_t l2_tunnel_type;
11396         cmdline_fixed_string_t eth_type;
11397         uint16_t eth_type_val;
11398 };
11399
11400 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11401         TOKEN_STRING_INITIALIZER
11402                 (struct cmd_config_l2_tunnel_eth_type_result,
11403                  port, "port");
11404 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11405         TOKEN_STRING_INITIALIZER
11406                 (struct cmd_config_l2_tunnel_eth_type_result,
11407                  config, "config");
11408 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11409         TOKEN_STRING_INITIALIZER
11410                 (struct cmd_config_l2_tunnel_eth_type_result,
11411                  all, "all");
11412 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11413         TOKEN_NUM_INITIALIZER
11414                 (struct cmd_config_l2_tunnel_eth_type_result,
11415                  id, UINT8);
11416 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11417         TOKEN_STRING_INITIALIZER
11418                 (struct cmd_config_l2_tunnel_eth_type_result,
11419                  l2_tunnel, "l2-tunnel");
11420 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11421         TOKEN_STRING_INITIALIZER
11422                 (struct cmd_config_l2_tunnel_eth_type_result,
11423                  l2_tunnel_type, "E-tag");
11424 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11425         TOKEN_STRING_INITIALIZER
11426                 (struct cmd_config_l2_tunnel_eth_type_result,
11427                  eth_type, "ether-type");
11428 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11429         TOKEN_NUM_INITIALIZER
11430                 (struct cmd_config_l2_tunnel_eth_type_result,
11431                  eth_type_val, UINT16);
11432
11433 static enum rte_eth_tunnel_type
11434 str2fdir_l2_tunnel_type(char *string)
11435 {
11436         uint32_t i = 0;
11437
11438         static const struct {
11439                 char str[32];
11440                 enum rte_eth_tunnel_type type;
11441         } l2_tunnel_type_str[] = {
11442                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11443         };
11444
11445         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11446                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11447                         return l2_tunnel_type_str[i].type;
11448         }
11449         return RTE_TUNNEL_TYPE_NONE;
11450 }
11451
11452 /* ether type config for all ports */
11453 static void
11454 cmd_config_l2_tunnel_eth_type_all_parsed
11455         (void *parsed_result,
11456          __attribute__((unused)) struct cmdline *cl,
11457          __attribute__((unused)) void *data)
11458 {
11459         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11460         struct rte_eth_l2_tunnel_conf entry;
11461         portid_t pid;
11462
11463         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11464         entry.ether_type = res->eth_type_val;
11465
11466         RTE_ETH_FOREACH_DEV(pid) {
11467                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11468         }
11469 }
11470
11471 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11472         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11473         .data = NULL,
11474         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11475         .tokens = {
11476                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11477                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11478                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11479                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11480                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11481                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11482                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11483                 NULL,
11484         },
11485 };
11486
11487 /* ether type config for a specific port */
11488 static void
11489 cmd_config_l2_tunnel_eth_type_specific_parsed(
11490         void *parsed_result,
11491         __attribute__((unused)) struct cmdline *cl,
11492         __attribute__((unused)) void *data)
11493 {
11494         struct cmd_config_l2_tunnel_eth_type_result *res =
11495                  parsed_result;
11496         struct rte_eth_l2_tunnel_conf entry;
11497
11498         if (port_id_is_invalid(res->id, ENABLED_WARN))
11499                 return;
11500
11501         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11502         entry.ether_type = res->eth_type_val;
11503
11504         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11505 }
11506
11507 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11508         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11509         .data = NULL,
11510         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11511         .tokens = {
11512                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11513                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11514                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11515                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11516                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11517                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11518                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11519                 NULL,
11520         },
11521 };
11522
11523 /* Enable/disable l2 tunnel */
11524 struct cmd_config_l2_tunnel_en_dis_result {
11525         cmdline_fixed_string_t port;
11526         cmdline_fixed_string_t config;
11527         cmdline_fixed_string_t all;
11528         uint8_t id;
11529         cmdline_fixed_string_t l2_tunnel;
11530         cmdline_fixed_string_t l2_tunnel_type;
11531         cmdline_fixed_string_t en_dis;
11532 };
11533
11534 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11535         TOKEN_STRING_INITIALIZER
11536                 (struct cmd_config_l2_tunnel_en_dis_result,
11537                  port, "port");
11538 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11539         TOKEN_STRING_INITIALIZER
11540                 (struct cmd_config_l2_tunnel_en_dis_result,
11541                  config, "config");
11542 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11543         TOKEN_STRING_INITIALIZER
11544                 (struct cmd_config_l2_tunnel_en_dis_result,
11545                  all, "all");
11546 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11547         TOKEN_NUM_INITIALIZER
11548                 (struct cmd_config_l2_tunnel_en_dis_result,
11549                  id, UINT8);
11550 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11551         TOKEN_STRING_INITIALIZER
11552                 (struct cmd_config_l2_tunnel_en_dis_result,
11553                  l2_tunnel, "l2-tunnel");
11554 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11555         TOKEN_STRING_INITIALIZER
11556                 (struct cmd_config_l2_tunnel_en_dis_result,
11557                  l2_tunnel_type, "E-tag");
11558 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11559         TOKEN_STRING_INITIALIZER
11560                 (struct cmd_config_l2_tunnel_en_dis_result,
11561                  en_dis, "enable#disable");
11562
11563 /* enable/disable l2 tunnel for all ports */
11564 static void
11565 cmd_config_l2_tunnel_en_dis_all_parsed(
11566         void *parsed_result,
11567         __attribute__((unused)) struct cmdline *cl,
11568         __attribute__((unused)) void *data)
11569 {
11570         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11571         struct rte_eth_l2_tunnel_conf entry;
11572         portid_t pid;
11573         uint8_t en;
11574
11575         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11576
11577         if (!strcmp("enable", res->en_dis))
11578                 en = 1;
11579         else
11580                 en = 0;
11581
11582         RTE_ETH_FOREACH_DEV(pid) {
11583                 rte_eth_dev_l2_tunnel_offload_set(pid,
11584                                                   &entry,
11585                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11586                                                   en);
11587         }
11588 }
11589
11590 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11591         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11592         .data = NULL,
11593         .help_str = "port config all l2-tunnel E-tag enable|disable",
11594         .tokens = {
11595                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11596                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11597                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11598                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11599                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11600                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11601                 NULL,
11602         },
11603 };
11604
11605 /* enable/disable l2 tunnel for a port */
11606 static void
11607 cmd_config_l2_tunnel_en_dis_specific_parsed(
11608         void *parsed_result,
11609         __attribute__((unused)) struct cmdline *cl,
11610         __attribute__((unused)) void *data)
11611 {
11612         struct cmd_config_l2_tunnel_en_dis_result *res =
11613                 parsed_result;
11614         struct rte_eth_l2_tunnel_conf entry;
11615
11616         if (port_id_is_invalid(res->id, ENABLED_WARN))
11617                 return;
11618
11619         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11620
11621         if (!strcmp("enable", res->en_dis))
11622                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11623                                                   &entry,
11624                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11625                                                   1);
11626         else
11627                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11628                                                   &entry,
11629                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11630                                                   0);
11631 }
11632
11633 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11634         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11635         .data = NULL,
11636         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11637         .tokens = {
11638                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11639                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11640                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11641                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11642                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11643                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11644                 NULL,
11645         },
11646 };
11647
11648 /* E-tag configuration */
11649
11650 /* Common result structure for all E-tag configuration */
11651 struct cmd_config_e_tag_result {
11652         cmdline_fixed_string_t e_tag;
11653         cmdline_fixed_string_t set;
11654         cmdline_fixed_string_t insertion;
11655         cmdline_fixed_string_t stripping;
11656         cmdline_fixed_string_t forwarding;
11657         cmdline_fixed_string_t filter;
11658         cmdline_fixed_string_t add;
11659         cmdline_fixed_string_t del;
11660         cmdline_fixed_string_t on;
11661         cmdline_fixed_string_t off;
11662         cmdline_fixed_string_t on_off;
11663         cmdline_fixed_string_t port_tag_id;
11664         uint32_t port_tag_id_val;
11665         cmdline_fixed_string_t e_tag_id;
11666         uint16_t e_tag_id_val;
11667         cmdline_fixed_string_t dst_pool;
11668         uint8_t dst_pool_val;
11669         cmdline_fixed_string_t port;
11670         portid_t port_id;
11671         cmdline_fixed_string_t vf;
11672         uint8_t vf_id;
11673 };
11674
11675 /* Common CLI fields for all E-tag configuration */
11676 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11677         TOKEN_STRING_INITIALIZER
11678                 (struct cmd_config_e_tag_result,
11679                  e_tag, "E-tag");
11680 cmdline_parse_token_string_t cmd_config_e_tag_set =
11681         TOKEN_STRING_INITIALIZER
11682                 (struct cmd_config_e_tag_result,
11683                  set, "set");
11684 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11685         TOKEN_STRING_INITIALIZER
11686                 (struct cmd_config_e_tag_result,
11687                  insertion, "insertion");
11688 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11689         TOKEN_STRING_INITIALIZER
11690                 (struct cmd_config_e_tag_result,
11691                  stripping, "stripping");
11692 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11693         TOKEN_STRING_INITIALIZER
11694                 (struct cmd_config_e_tag_result,
11695                  forwarding, "forwarding");
11696 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11697         TOKEN_STRING_INITIALIZER
11698                 (struct cmd_config_e_tag_result,
11699                  filter, "filter");
11700 cmdline_parse_token_string_t cmd_config_e_tag_add =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_config_e_tag_result,
11703                  add, "add");
11704 cmdline_parse_token_string_t cmd_config_e_tag_del =
11705         TOKEN_STRING_INITIALIZER
11706                 (struct cmd_config_e_tag_result,
11707                  del, "del");
11708 cmdline_parse_token_string_t cmd_config_e_tag_on =
11709         TOKEN_STRING_INITIALIZER
11710                 (struct cmd_config_e_tag_result,
11711                  on, "on");
11712 cmdline_parse_token_string_t cmd_config_e_tag_off =
11713         TOKEN_STRING_INITIALIZER
11714                 (struct cmd_config_e_tag_result,
11715                  off, "off");
11716 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11717         TOKEN_STRING_INITIALIZER
11718                 (struct cmd_config_e_tag_result,
11719                  on_off, "on#off");
11720 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11721         TOKEN_STRING_INITIALIZER
11722                 (struct cmd_config_e_tag_result,
11723                  port_tag_id, "port-tag-id");
11724 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11725         TOKEN_NUM_INITIALIZER
11726                 (struct cmd_config_e_tag_result,
11727                  port_tag_id_val, UINT32);
11728 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11729         TOKEN_STRING_INITIALIZER
11730                 (struct cmd_config_e_tag_result,
11731                  e_tag_id, "e-tag-id");
11732 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11733         TOKEN_NUM_INITIALIZER
11734                 (struct cmd_config_e_tag_result,
11735                  e_tag_id_val, UINT16);
11736 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11737         TOKEN_STRING_INITIALIZER
11738                 (struct cmd_config_e_tag_result,
11739                  dst_pool, "dst-pool");
11740 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11741         TOKEN_NUM_INITIALIZER
11742                 (struct cmd_config_e_tag_result,
11743                  dst_pool_val, UINT8);
11744 cmdline_parse_token_string_t cmd_config_e_tag_port =
11745         TOKEN_STRING_INITIALIZER
11746                 (struct cmd_config_e_tag_result,
11747                  port, "port");
11748 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11749         TOKEN_NUM_INITIALIZER
11750                 (struct cmd_config_e_tag_result,
11751                  port_id, UINT16);
11752 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11753         TOKEN_STRING_INITIALIZER
11754                 (struct cmd_config_e_tag_result,
11755                  vf, "vf");
11756 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11757         TOKEN_NUM_INITIALIZER
11758                 (struct cmd_config_e_tag_result,
11759                  vf_id, UINT8);
11760
11761 /* E-tag insertion configuration */
11762 static void
11763 cmd_config_e_tag_insertion_en_parsed(
11764         void *parsed_result,
11765         __attribute__((unused)) struct cmdline *cl,
11766         __attribute__((unused)) void *data)
11767 {
11768         struct cmd_config_e_tag_result *res =
11769                 parsed_result;
11770         struct rte_eth_l2_tunnel_conf entry;
11771
11772         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11773                 return;
11774
11775         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11776         entry.tunnel_id = res->port_tag_id_val;
11777         entry.vf_id = res->vf_id;
11778         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11779                                           &entry,
11780                                           ETH_L2_TUNNEL_INSERTION_MASK,
11781                                           1);
11782 }
11783
11784 static void
11785 cmd_config_e_tag_insertion_dis_parsed(
11786         void *parsed_result,
11787         __attribute__((unused)) struct cmdline *cl,
11788         __attribute__((unused)) void *data)
11789 {
11790         struct cmd_config_e_tag_result *res =
11791                 parsed_result;
11792         struct rte_eth_l2_tunnel_conf entry;
11793
11794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11795                 return;
11796
11797         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11798         entry.vf_id = res->vf_id;
11799
11800         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11801                                           &entry,
11802                                           ETH_L2_TUNNEL_INSERTION_MASK,
11803                                           0);
11804 }
11805
11806 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11807         .f = cmd_config_e_tag_insertion_en_parsed,
11808         .data = NULL,
11809         .help_str = "E-tag ... : E-tag insertion enable",
11810         .tokens = {
11811                 (void *)&cmd_config_e_tag_e_tag,
11812                 (void *)&cmd_config_e_tag_set,
11813                 (void *)&cmd_config_e_tag_insertion,
11814                 (void *)&cmd_config_e_tag_on,
11815                 (void *)&cmd_config_e_tag_port_tag_id,
11816                 (void *)&cmd_config_e_tag_port_tag_id_val,
11817                 (void *)&cmd_config_e_tag_port,
11818                 (void *)&cmd_config_e_tag_port_id,
11819                 (void *)&cmd_config_e_tag_vf,
11820                 (void *)&cmd_config_e_tag_vf_id,
11821                 NULL,
11822         },
11823 };
11824
11825 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11826         .f = cmd_config_e_tag_insertion_dis_parsed,
11827         .data = NULL,
11828         .help_str = "E-tag ... : E-tag insertion disable",
11829         .tokens = {
11830                 (void *)&cmd_config_e_tag_e_tag,
11831                 (void *)&cmd_config_e_tag_set,
11832                 (void *)&cmd_config_e_tag_insertion,
11833                 (void *)&cmd_config_e_tag_off,
11834                 (void *)&cmd_config_e_tag_port,
11835                 (void *)&cmd_config_e_tag_port_id,
11836                 (void *)&cmd_config_e_tag_vf,
11837                 (void *)&cmd_config_e_tag_vf_id,
11838                 NULL,
11839         },
11840 };
11841
11842 /* E-tag stripping configuration */
11843 static void
11844 cmd_config_e_tag_stripping_parsed(
11845         void *parsed_result,
11846         __attribute__((unused)) struct cmdline *cl,
11847         __attribute__((unused)) void *data)
11848 {
11849         struct cmd_config_e_tag_result *res =
11850                 parsed_result;
11851         struct rte_eth_l2_tunnel_conf entry;
11852
11853         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11854                 return;
11855
11856         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11857
11858         if (!strcmp(res->on_off, "on"))
11859                 rte_eth_dev_l2_tunnel_offload_set
11860                         (res->port_id,
11861                          &entry,
11862                          ETH_L2_TUNNEL_STRIPPING_MASK,
11863                          1);
11864         else
11865                 rte_eth_dev_l2_tunnel_offload_set
11866                         (res->port_id,
11867                          &entry,
11868                          ETH_L2_TUNNEL_STRIPPING_MASK,
11869                          0);
11870 }
11871
11872 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11873         .f = cmd_config_e_tag_stripping_parsed,
11874         .data = NULL,
11875         .help_str = "E-tag ... : E-tag stripping enable/disable",
11876         .tokens = {
11877                 (void *)&cmd_config_e_tag_e_tag,
11878                 (void *)&cmd_config_e_tag_set,
11879                 (void *)&cmd_config_e_tag_stripping,
11880                 (void *)&cmd_config_e_tag_on_off,
11881                 (void *)&cmd_config_e_tag_port,
11882                 (void *)&cmd_config_e_tag_port_id,
11883                 NULL,
11884         },
11885 };
11886
11887 /* E-tag forwarding configuration */
11888 static void
11889 cmd_config_e_tag_forwarding_parsed(
11890         void *parsed_result,
11891         __attribute__((unused)) struct cmdline *cl,
11892         __attribute__((unused)) void *data)
11893 {
11894         struct cmd_config_e_tag_result *res = parsed_result;
11895         struct rte_eth_l2_tunnel_conf entry;
11896
11897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11898                 return;
11899
11900         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11901
11902         if (!strcmp(res->on_off, "on"))
11903                 rte_eth_dev_l2_tunnel_offload_set
11904                         (res->port_id,
11905                          &entry,
11906                          ETH_L2_TUNNEL_FORWARDING_MASK,
11907                          1);
11908         else
11909                 rte_eth_dev_l2_tunnel_offload_set
11910                         (res->port_id,
11911                          &entry,
11912                          ETH_L2_TUNNEL_FORWARDING_MASK,
11913                          0);
11914 }
11915
11916 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11917         .f = cmd_config_e_tag_forwarding_parsed,
11918         .data = NULL,
11919         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11920         .tokens = {
11921                 (void *)&cmd_config_e_tag_e_tag,
11922                 (void *)&cmd_config_e_tag_set,
11923                 (void *)&cmd_config_e_tag_forwarding,
11924                 (void *)&cmd_config_e_tag_on_off,
11925                 (void *)&cmd_config_e_tag_port,
11926                 (void *)&cmd_config_e_tag_port_id,
11927                 NULL,
11928         },
11929 };
11930
11931 /* E-tag filter configuration */
11932 static void
11933 cmd_config_e_tag_filter_add_parsed(
11934         void *parsed_result,
11935         __attribute__((unused)) struct cmdline *cl,
11936         __attribute__((unused)) void *data)
11937 {
11938         struct cmd_config_e_tag_result *res = parsed_result;
11939         struct rte_eth_l2_tunnel_conf entry;
11940         int ret = 0;
11941
11942         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11943                 return;
11944
11945         if (res->e_tag_id_val > 0x3fff) {
11946                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11947                 return;
11948         }
11949
11950         ret = rte_eth_dev_filter_supported(res->port_id,
11951                                            RTE_ETH_FILTER_L2_TUNNEL);
11952         if (ret < 0) {
11953                 printf("E-tag filter is not supported on port %u.\n",
11954                        res->port_id);
11955                 return;
11956         }
11957
11958         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11959         entry.tunnel_id = res->e_tag_id_val;
11960         entry.pool = res->dst_pool_val;
11961
11962         ret = rte_eth_dev_filter_ctrl(res->port_id,
11963                                       RTE_ETH_FILTER_L2_TUNNEL,
11964                                       RTE_ETH_FILTER_ADD,
11965                                       &entry);
11966         if (ret < 0)
11967                 printf("E-tag filter programming error: (%s)\n",
11968                        strerror(-ret));
11969 }
11970
11971 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11972         .f = cmd_config_e_tag_filter_add_parsed,
11973         .data = NULL,
11974         .help_str = "E-tag ... : E-tag filter add",
11975         .tokens = {
11976                 (void *)&cmd_config_e_tag_e_tag,
11977                 (void *)&cmd_config_e_tag_set,
11978                 (void *)&cmd_config_e_tag_filter,
11979                 (void *)&cmd_config_e_tag_add,
11980                 (void *)&cmd_config_e_tag_e_tag_id,
11981                 (void *)&cmd_config_e_tag_e_tag_id_val,
11982                 (void *)&cmd_config_e_tag_dst_pool,
11983                 (void *)&cmd_config_e_tag_dst_pool_val,
11984                 (void *)&cmd_config_e_tag_port,
11985                 (void *)&cmd_config_e_tag_port_id,
11986                 NULL,
11987         },
11988 };
11989
11990 static void
11991 cmd_config_e_tag_filter_del_parsed(
11992         void *parsed_result,
11993         __attribute__((unused)) struct cmdline *cl,
11994         __attribute__((unused)) void *data)
11995 {
11996         struct cmd_config_e_tag_result *res = parsed_result;
11997         struct rte_eth_l2_tunnel_conf entry;
11998         int ret = 0;
11999
12000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12001                 return;
12002
12003         if (res->e_tag_id_val > 0x3fff) {
12004                 printf("e-tag-id must be less than 0x3fff.\n");
12005                 return;
12006         }
12007
12008         ret = rte_eth_dev_filter_supported(res->port_id,
12009                                            RTE_ETH_FILTER_L2_TUNNEL);
12010         if (ret < 0) {
12011                 printf("E-tag filter is not supported on port %u.\n",
12012                        res->port_id);
12013                 return;
12014         }
12015
12016         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12017         entry.tunnel_id = res->e_tag_id_val;
12018
12019         ret = rte_eth_dev_filter_ctrl(res->port_id,
12020                                       RTE_ETH_FILTER_L2_TUNNEL,
12021                                       RTE_ETH_FILTER_DELETE,
12022                                       &entry);
12023         if (ret < 0)
12024                 printf("E-tag filter programming error: (%s)\n",
12025                        strerror(-ret));
12026 }
12027
12028 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12029         .f = cmd_config_e_tag_filter_del_parsed,
12030         .data = NULL,
12031         .help_str = "E-tag ... : E-tag filter delete",
12032         .tokens = {
12033                 (void *)&cmd_config_e_tag_e_tag,
12034                 (void *)&cmd_config_e_tag_set,
12035                 (void *)&cmd_config_e_tag_filter,
12036                 (void *)&cmd_config_e_tag_del,
12037                 (void *)&cmd_config_e_tag_e_tag_id,
12038                 (void *)&cmd_config_e_tag_e_tag_id_val,
12039                 (void *)&cmd_config_e_tag_port,
12040                 (void *)&cmd_config_e_tag_port_id,
12041                 NULL,
12042         },
12043 };
12044
12045 /* vf vlan anti spoof configuration */
12046
12047 /* Common result structure for vf vlan anti spoof */
12048 struct cmd_vf_vlan_anti_spoof_result {
12049         cmdline_fixed_string_t set;
12050         cmdline_fixed_string_t vf;
12051         cmdline_fixed_string_t vlan;
12052         cmdline_fixed_string_t antispoof;
12053         portid_t port_id;
12054         uint32_t vf_id;
12055         cmdline_fixed_string_t on_off;
12056 };
12057
12058 /* Common CLI fields for vf vlan anti spoof enable disable */
12059 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12060         TOKEN_STRING_INITIALIZER
12061                 (struct cmd_vf_vlan_anti_spoof_result,
12062                  set, "set");
12063 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12064         TOKEN_STRING_INITIALIZER
12065                 (struct cmd_vf_vlan_anti_spoof_result,
12066                  vf, "vf");
12067 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12068         TOKEN_STRING_INITIALIZER
12069                 (struct cmd_vf_vlan_anti_spoof_result,
12070                  vlan, "vlan");
12071 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12072         TOKEN_STRING_INITIALIZER
12073                 (struct cmd_vf_vlan_anti_spoof_result,
12074                  antispoof, "antispoof");
12075 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12076         TOKEN_NUM_INITIALIZER
12077                 (struct cmd_vf_vlan_anti_spoof_result,
12078                  port_id, UINT16);
12079 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12080         TOKEN_NUM_INITIALIZER
12081                 (struct cmd_vf_vlan_anti_spoof_result,
12082                  vf_id, UINT32);
12083 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12084         TOKEN_STRING_INITIALIZER
12085                 (struct cmd_vf_vlan_anti_spoof_result,
12086                  on_off, "on#off");
12087
12088 static void
12089 cmd_set_vf_vlan_anti_spoof_parsed(
12090         void *parsed_result,
12091         __attribute__((unused)) struct cmdline *cl,
12092         __attribute__((unused)) void *data)
12093 {
12094         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12095         int ret = -ENOTSUP;
12096
12097         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12098
12099         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12100                 return;
12101
12102 #ifdef RTE_LIBRTE_IXGBE_PMD
12103         if (ret == -ENOTSUP)
12104                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12105                                 res->vf_id, is_on);
12106 #endif
12107 #ifdef RTE_LIBRTE_I40E_PMD
12108         if (ret == -ENOTSUP)
12109                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12110                                 res->vf_id, is_on);
12111 #endif
12112 #ifdef RTE_LIBRTE_BNXT_PMD
12113         if (ret == -ENOTSUP)
12114                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12115                                 res->vf_id, is_on);
12116 #endif
12117
12118         switch (ret) {
12119         case 0:
12120                 break;
12121         case -EINVAL:
12122                 printf("invalid vf_id %d\n", res->vf_id);
12123                 break;
12124         case -ENODEV:
12125                 printf("invalid port_id %d\n", res->port_id);
12126                 break;
12127         case -ENOTSUP:
12128                 printf("function not implemented\n");
12129                 break;
12130         default:
12131                 printf("programming error: (%s)\n", strerror(-ret));
12132         }
12133 }
12134
12135 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12136         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12137         .data = NULL,
12138         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12139         .tokens = {
12140                 (void *)&cmd_vf_vlan_anti_spoof_set,
12141                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12142                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12143                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12144                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12145                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12146                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12147                 NULL,
12148         },
12149 };
12150
12151 /* vf mac anti spoof configuration */
12152
12153 /* Common result structure for vf mac anti spoof */
12154 struct cmd_vf_mac_anti_spoof_result {
12155         cmdline_fixed_string_t set;
12156         cmdline_fixed_string_t vf;
12157         cmdline_fixed_string_t mac;
12158         cmdline_fixed_string_t antispoof;
12159         portid_t port_id;
12160         uint32_t vf_id;
12161         cmdline_fixed_string_t on_off;
12162 };
12163
12164 /* Common CLI fields for vf mac anti spoof enable disable */
12165 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12166         TOKEN_STRING_INITIALIZER
12167                 (struct cmd_vf_mac_anti_spoof_result,
12168                  set, "set");
12169 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12170         TOKEN_STRING_INITIALIZER
12171                 (struct cmd_vf_mac_anti_spoof_result,
12172                  vf, "vf");
12173 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12174         TOKEN_STRING_INITIALIZER
12175                 (struct cmd_vf_mac_anti_spoof_result,
12176                  mac, "mac");
12177 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_vf_mac_anti_spoof_result,
12180                  antispoof, "antispoof");
12181 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12182         TOKEN_NUM_INITIALIZER
12183                 (struct cmd_vf_mac_anti_spoof_result,
12184                  port_id, UINT16);
12185 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12186         TOKEN_NUM_INITIALIZER
12187                 (struct cmd_vf_mac_anti_spoof_result,
12188                  vf_id, UINT32);
12189 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12190         TOKEN_STRING_INITIALIZER
12191                 (struct cmd_vf_mac_anti_spoof_result,
12192                  on_off, "on#off");
12193
12194 static void
12195 cmd_set_vf_mac_anti_spoof_parsed(
12196         void *parsed_result,
12197         __attribute__((unused)) struct cmdline *cl,
12198         __attribute__((unused)) void *data)
12199 {
12200         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12201         int ret = -ENOTSUP;
12202
12203         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12204
12205         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12206                 return;
12207
12208 #ifdef RTE_LIBRTE_IXGBE_PMD
12209         if (ret == -ENOTSUP)
12210                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12211                         res->vf_id, is_on);
12212 #endif
12213 #ifdef RTE_LIBRTE_I40E_PMD
12214         if (ret == -ENOTSUP)
12215                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12216                         res->vf_id, is_on);
12217 #endif
12218 #ifdef RTE_LIBRTE_BNXT_PMD
12219         if (ret == -ENOTSUP)
12220                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12221                         res->vf_id, is_on);
12222 #endif
12223
12224         switch (ret) {
12225         case 0:
12226                 break;
12227         case -EINVAL:
12228                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12229                 break;
12230         case -ENODEV:
12231                 printf("invalid port_id %d\n", res->port_id);
12232                 break;
12233         case -ENOTSUP:
12234                 printf("function not implemented\n");
12235                 break;
12236         default:
12237                 printf("programming error: (%s)\n", strerror(-ret));
12238         }
12239 }
12240
12241 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12242         .f = cmd_set_vf_mac_anti_spoof_parsed,
12243         .data = NULL,
12244         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12245         .tokens = {
12246                 (void *)&cmd_vf_mac_anti_spoof_set,
12247                 (void *)&cmd_vf_mac_anti_spoof_vf,
12248                 (void *)&cmd_vf_mac_anti_spoof_mac,
12249                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12250                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12251                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12252                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12253                 NULL,
12254         },
12255 };
12256
12257 /* vf vlan strip queue configuration */
12258
12259 /* Common result structure for vf mac anti spoof */
12260 struct cmd_vf_vlan_stripq_result {
12261         cmdline_fixed_string_t set;
12262         cmdline_fixed_string_t vf;
12263         cmdline_fixed_string_t vlan;
12264         cmdline_fixed_string_t stripq;
12265         portid_t port_id;
12266         uint16_t vf_id;
12267         cmdline_fixed_string_t on_off;
12268 };
12269
12270 /* Common CLI fields for vf vlan strip enable disable */
12271 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12272         TOKEN_STRING_INITIALIZER
12273                 (struct cmd_vf_vlan_stripq_result,
12274                  set, "set");
12275 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12276         TOKEN_STRING_INITIALIZER
12277                 (struct cmd_vf_vlan_stripq_result,
12278                  vf, "vf");
12279 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12280         TOKEN_STRING_INITIALIZER
12281                 (struct cmd_vf_vlan_stripq_result,
12282                  vlan, "vlan");
12283 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12284         TOKEN_STRING_INITIALIZER
12285                 (struct cmd_vf_vlan_stripq_result,
12286                  stripq, "stripq");
12287 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12288         TOKEN_NUM_INITIALIZER
12289                 (struct cmd_vf_vlan_stripq_result,
12290                  port_id, UINT16);
12291 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12292         TOKEN_NUM_INITIALIZER
12293                 (struct cmd_vf_vlan_stripq_result,
12294                  vf_id, UINT16);
12295 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12296         TOKEN_STRING_INITIALIZER
12297                 (struct cmd_vf_vlan_stripq_result,
12298                  on_off, "on#off");
12299
12300 static void
12301 cmd_set_vf_vlan_stripq_parsed(
12302         void *parsed_result,
12303         __attribute__((unused)) struct cmdline *cl,
12304         __attribute__((unused)) void *data)
12305 {
12306         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12307         int ret = -ENOTSUP;
12308
12309         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12310
12311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12312                 return;
12313
12314 #ifdef RTE_LIBRTE_IXGBE_PMD
12315         if (ret == -ENOTSUP)
12316                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12317                         res->vf_id, is_on);
12318 #endif
12319 #ifdef RTE_LIBRTE_I40E_PMD
12320         if (ret == -ENOTSUP)
12321                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12322                         res->vf_id, is_on);
12323 #endif
12324 #ifdef RTE_LIBRTE_BNXT_PMD
12325         if (ret == -ENOTSUP)
12326                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12327                         res->vf_id, is_on);
12328 #endif
12329
12330         switch (ret) {
12331         case 0:
12332                 break;
12333         case -EINVAL:
12334                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12335                 break;
12336         case -ENODEV:
12337                 printf("invalid port_id %d\n", res->port_id);
12338                 break;
12339         case -ENOTSUP:
12340                 printf("function not implemented\n");
12341                 break;
12342         default:
12343                 printf("programming error: (%s)\n", strerror(-ret));
12344         }
12345 }
12346
12347 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12348         .f = cmd_set_vf_vlan_stripq_parsed,
12349         .data = NULL,
12350         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12351         .tokens = {
12352                 (void *)&cmd_vf_vlan_stripq_set,
12353                 (void *)&cmd_vf_vlan_stripq_vf,
12354                 (void *)&cmd_vf_vlan_stripq_vlan,
12355                 (void *)&cmd_vf_vlan_stripq_stripq,
12356                 (void *)&cmd_vf_vlan_stripq_port_id,
12357                 (void *)&cmd_vf_vlan_stripq_vf_id,
12358                 (void *)&cmd_vf_vlan_stripq_on_off,
12359                 NULL,
12360         },
12361 };
12362
12363 /* vf vlan insert configuration */
12364
12365 /* Common result structure for vf vlan insert */
12366 struct cmd_vf_vlan_insert_result {
12367         cmdline_fixed_string_t set;
12368         cmdline_fixed_string_t vf;
12369         cmdline_fixed_string_t vlan;
12370         cmdline_fixed_string_t insert;
12371         portid_t port_id;
12372         uint16_t vf_id;
12373         uint16_t vlan_id;
12374 };
12375
12376 /* Common CLI fields for vf vlan insert enable disable */
12377 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12378         TOKEN_STRING_INITIALIZER
12379                 (struct cmd_vf_vlan_insert_result,
12380                  set, "set");
12381 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12382         TOKEN_STRING_INITIALIZER
12383                 (struct cmd_vf_vlan_insert_result,
12384                  vf, "vf");
12385 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12386         TOKEN_STRING_INITIALIZER
12387                 (struct cmd_vf_vlan_insert_result,
12388                  vlan, "vlan");
12389 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12390         TOKEN_STRING_INITIALIZER
12391                 (struct cmd_vf_vlan_insert_result,
12392                  insert, "insert");
12393 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12394         TOKEN_NUM_INITIALIZER
12395                 (struct cmd_vf_vlan_insert_result,
12396                  port_id, UINT16);
12397 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12398         TOKEN_NUM_INITIALIZER
12399                 (struct cmd_vf_vlan_insert_result,
12400                  vf_id, UINT16);
12401 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12402         TOKEN_NUM_INITIALIZER
12403                 (struct cmd_vf_vlan_insert_result,
12404                  vlan_id, UINT16);
12405
12406 static void
12407 cmd_set_vf_vlan_insert_parsed(
12408         void *parsed_result,
12409         __attribute__((unused)) struct cmdline *cl,
12410         __attribute__((unused)) void *data)
12411 {
12412         struct cmd_vf_vlan_insert_result *res = parsed_result;
12413         int ret = -ENOTSUP;
12414
12415         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12416                 return;
12417
12418 #ifdef RTE_LIBRTE_IXGBE_PMD
12419         if (ret == -ENOTSUP)
12420                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12421                         res->vlan_id);
12422 #endif
12423 #ifdef RTE_LIBRTE_I40E_PMD
12424         if (ret == -ENOTSUP)
12425                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12426                         res->vlan_id);
12427 #endif
12428 #ifdef RTE_LIBRTE_BNXT_PMD
12429         if (ret == -ENOTSUP)
12430                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12431                         res->vlan_id);
12432 #endif
12433
12434         switch (ret) {
12435         case 0:
12436                 break;
12437         case -EINVAL:
12438                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12439                 break;
12440         case -ENODEV:
12441                 printf("invalid port_id %d\n", res->port_id);
12442                 break;
12443         case -ENOTSUP:
12444                 printf("function not implemented\n");
12445                 break;
12446         default:
12447                 printf("programming error: (%s)\n", strerror(-ret));
12448         }
12449 }
12450
12451 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12452         .f = cmd_set_vf_vlan_insert_parsed,
12453         .data = NULL,
12454         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12455         .tokens = {
12456                 (void *)&cmd_vf_vlan_insert_set,
12457                 (void *)&cmd_vf_vlan_insert_vf,
12458                 (void *)&cmd_vf_vlan_insert_vlan,
12459                 (void *)&cmd_vf_vlan_insert_insert,
12460                 (void *)&cmd_vf_vlan_insert_port_id,
12461                 (void *)&cmd_vf_vlan_insert_vf_id,
12462                 (void *)&cmd_vf_vlan_insert_vlan_id,
12463                 NULL,
12464         },
12465 };
12466
12467 /* tx loopback configuration */
12468
12469 /* Common result structure for tx loopback */
12470 struct cmd_tx_loopback_result {
12471         cmdline_fixed_string_t set;
12472         cmdline_fixed_string_t tx;
12473         cmdline_fixed_string_t loopback;
12474         portid_t port_id;
12475         cmdline_fixed_string_t on_off;
12476 };
12477
12478 /* Common CLI fields for tx loopback enable disable */
12479 cmdline_parse_token_string_t cmd_tx_loopback_set =
12480         TOKEN_STRING_INITIALIZER
12481                 (struct cmd_tx_loopback_result,
12482                  set, "set");
12483 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12484         TOKEN_STRING_INITIALIZER
12485                 (struct cmd_tx_loopback_result,
12486                  tx, "tx");
12487 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12488         TOKEN_STRING_INITIALIZER
12489                 (struct cmd_tx_loopback_result,
12490                  loopback, "loopback");
12491 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12492         TOKEN_NUM_INITIALIZER
12493                 (struct cmd_tx_loopback_result,
12494                  port_id, UINT16);
12495 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12496         TOKEN_STRING_INITIALIZER
12497                 (struct cmd_tx_loopback_result,
12498                  on_off, "on#off");
12499
12500 static void
12501 cmd_set_tx_loopback_parsed(
12502         void *parsed_result,
12503         __attribute__((unused)) struct cmdline *cl,
12504         __attribute__((unused)) void *data)
12505 {
12506         struct cmd_tx_loopback_result *res = parsed_result;
12507         int ret = -ENOTSUP;
12508
12509         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12510
12511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12512                 return;
12513
12514 #ifdef RTE_LIBRTE_IXGBE_PMD
12515         if (ret == -ENOTSUP)
12516                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12517 #endif
12518 #ifdef RTE_LIBRTE_I40E_PMD
12519         if (ret == -ENOTSUP)
12520                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12521 #endif
12522 #ifdef RTE_LIBRTE_BNXT_PMD
12523         if (ret == -ENOTSUP)
12524                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12525 #endif
12526
12527         switch (ret) {
12528         case 0:
12529                 break;
12530         case -EINVAL:
12531                 printf("invalid is_on %d\n", is_on);
12532                 break;
12533         case -ENODEV:
12534                 printf("invalid port_id %d\n", res->port_id);
12535                 break;
12536         case -ENOTSUP:
12537                 printf("function not implemented\n");
12538                 break;
12539         default:
12540                 printf("programming error: (%s)\n", strerror(-ret));
12541         }
12542 }
12543
12544 cmdline_parse_inst_t cmd_set_tx_loopback = {
12545         .f = cmd_set_tx_loopback_parsed,
12546         .data = NULL,
12547         .help_str = "set tx loopback <port_id> on|off",
12548         .tokens = {
12549                 (void *)&cmd_tx_loopback_set,
12550                 (void *)&cmd_tx_loopback_tx,
12551                 (void *)&cmd_tx_loopback_loopback,
12552                 (void *)&cmd_tx_loopback_port_id,
12553                 (void *)&cmd_tx_loopback_on_off,
12554                 NULL,
12555         },
12556 };
12557
12558 /* all queues drop enable configuration */
12559
12560 /* Common result structure for all queues drop enable */
12561 struct cmd_all_queues_drop_en_result {
12562         cmdline_fixed_string_t set;
12563         cmdline_fixed_string_t all;
12564         cmdline_fixed_string_t queues;
12565         cmdline_fixed_string_t drop;
12566         portid_t port_id;
12567         cmdline_fixed_string_t on_off;
12568 };
12569
12570 /* Common CLI fields for tx loopback enable disable */
12571 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12572         TOKEN_STRING_INITIALIZER
12573                 (struct cmd_all_queues_drop_en_result,
12574                  set, "set");
12575 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12576         TOKEN_STRING_INITIALIZER
12577                 (struct cmd_all_queues_drop_en_result,
12578                  all, "all");
12579 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12580         TOKEN_STRING_INITIALIZER
12581                 (struct cmd_all_queues_drop_en_result,
12582                  queues, "queues");
12583 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12584         TOKEN_STRING_INITIALIZER
12585                 (struct cmd_all_queues_drop_en_result,
12586                  drop, "drop");
12587 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12588         TOKEN_NUM_INITIALIZER
12589                 (struct cmd_all_queues_drop_en_result,
12590                  port_id, UINT16);
12591 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12592         TOKEN_STRING_INITIALIZER
12593                 (struct cmd_all_queues_drop_en_result,
12594                  on_off, "on#off");
12595
12596 static void
12597 cmd_set_all_queues_drop_en_parsed(
12598         void *parsed_result,
12599         __attribute__((unused)) struct cmdline *cl,
12600         __attribute__((unused)) void *data)
12601 {
12602         struct cmd_all_queues_drop_en_result *res = parsed_result;
12603         int ret = -ENOTSUP;
12604         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12605
12606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12607                 return;
12608
12609 #ifdef RTE_LIBRTE_IXGBE_PMD
12610         if (ret == -ENOTSUP)
12611                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12612 #endif
12613 #ifdef RTE_LIBRTE_BNXT_PMD
12614         if (ret == -ENOTSUP)
12615                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12616 #endif
12617         switch (ret) {
12618         case 0:
12619                 break;
12620         case -EINVAL:
12621                 printf("invalid is_on %d\n", is_on);
12622                 break;
12623         case -ENODEV:
12624                 printf("invalid port_id %d\n", res->port_id);
12625                 break;
12626         case -ENOTSUP:
12627                 printf("function not implemented\n");
12628                 break;
12629         default:
12630                 printf("programming error: (%s)\n", strerror(-ret));
12631         }
12632 }
12633
12634 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12635         .f = cmd_set_all_queues_drop_en_parsed,
12636         .data = NULL,
12637         .help_str = "set all queues drop <port_id> on|off",
12638         .tokens = {
12639                 (void *)&cmd_all_queues_drop_en_set,
12640                 (void *)&cmd_all_queues_drop_en_all,
12641                 (void *)&cmd_all_queues_drop_en_queues,
12642                 (void *)&cmd_all_queues_drop_en_drop,
12643                 (void *)&cmd_all_queues_drop_en_port_id,
12644                 (void *)&cmd_all_queues_drop_en_on_off,
12645                 NULL,
12646         },
12647 };
12648
12649 /* vf split drop enable configuration */
12650
12651 /* Common result structure for vf split drop enable */
12652 struct cmd_vf_split_drop_en_result {
12653         cmdline_fixed_string_t set;
12654         cmdline_fixed_string_t vf;
12655         cmdline_fixed_string_t split;
12656         cmdline_fixed_string_t drop;
12657         portid_t port_id;
12658         uint16_t vf_id;
12659         cmdline_fixed_string_t on_off;
12660 };
12661
12662 /* Common CLI fields for vf split drop enable disable */
12663 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12664         TOKEN_STRING_INITIALIZER
12665                 (struct cmd_vf_split_drop_en_result,
12666                  set, "set");
12667 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12668         TOKEN_STRING_INITIALIZER
12669                 (struct cmd_vf_split_drop_en_result,
12670                  vf, "vf");
12671 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12672         TOKEN_STRING_INITIALIZER
12673                 (struct cmd_vf_split_drop_en_result,
12674                  split, "split");
12675 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12676         TOKEN_STRING_INITIALIZER
12677                 (struct cmd_vf_split_drop_en_result,
12678                  drop, "drop");
12679 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12680         TOKEN_NUM_INITIALIZER
12681                 (struct cmd_vf_split_drop_en_result,
12682                  port_id, UINT16);
12683 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12684         TOKEN_NUM_INITIALIZER
12685                 (struct cmd_vf_split_drop_en_result,
12686                  vf_id, UINT16);
12687 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12688         TOKEN_STRING_INITIALIZER
12689                 (struct cmd_vf_split_drop_en_result,
12690                  on_off, "on#off");
12691
12692 static void
12693 cmd_set_vf_split_drop_en_parsed(
12694         void *parsed_result,
12695         __attribute__((unused)) struct cmdline *cl,
12696         __attribute__((unused)) void *data)
12697 {
12698         struct cmd_vf_split_drop_en_result *res = parsed_result;
12699         int ret = -ENOTSUP;
12700         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12701
12702         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12703                 return;
12704
12705 #ifdef RTE_LIBRTE_IXGBE_PMD
12706         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12707                         is_on);
12708 #endif
12709         switch (ret) {
12710         case 0:
12711                 break;
12712         case -EINVAL:
12713                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12714                 break;
12715         case -ENODEV:
12716                 printf("invalid port_id %d\n", res->port_id);
12717                 break;
12718         case -ENOTSUP:
12719                 printf("not supported on port %d\n", res->port_id);
12720                 break;
12721         default:
12722                 printf("programming error: (%s)\n", strerror(-ret));
12723         }
12724 }
12725
12726 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12727         .f = cmd_set_vf_split_drop_en_parsed,
12728         .data = NULL,
12729         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12730         .tokens = {
12731                 (void *)&cmd_vf_split_drop_en_set,
12732                 (void *)&cmd_vf_split_drop_en_vf,
12733                 (void *)&cmd_vf_split_drop_en_split,
12734                 (void *)&cmd_vf_split_drop_en_drop,
12735                 (void *)&cmd_vf_split_drop_en_port_id,
12736                 (void *)&cmd_vf_split_drop_en_vf_id,
12737                 (void *)&cmd_vf_split_drop_en_on_off,
12738                 NULL,
12739         },
12740 };
12741
12742 /* vf mac address configuration */
12743
12744 /* Common result structure for vf mac address */
12745 struct cmd_set_vf_mac_addr_result {
12746         cmdline_fixed_string_t set;
12747         cmdline_fixed_string_t vf;
12748         cmdline_fixed_string_t mac;
12749         cmdline_fixed_string_t addr;
12750         portid_t port_id;
12751         uint16_t vf_id;
12752         struct ether_addr mac_addr;
12753
12754 };
12755
12756 /* Common CLI fields for vf split drop enable disable */
12757 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12758         TOKEN_STRING_INITIALIZER
12759                 (struct cmd_set_vf_mac_addr_result,
12760                  set, "set");
12761 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12762         TOKEN_STRING_INITIALIZER
12763                 (struct cmd_set_vf_mac_addr_result,
12764                  vf, "vf");
12765 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12766         TOKEN_STRING_INITIALIZER
12767                 (struct cmd_set_vf_mac_addr_result,
12768                  mac, "mac");
12769 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12770         TOKEN_STRING_INITIALIZER
12771                 (struct cmd_set_vf_mac_addr_result,
12772                  addr, "addr");
12773 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12774         TOKEN_NUM_INITIALIZER
12775                 (struct cmd_set_vf_mac_addr_result,
12776                  port_id, UINT16);
12777 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12778         TOKEN_NUM_INITIALIZER
12779                 (struct cmd_set_vf_mac_addr_result,
12780                  vf_id, UINT16);
12781 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12782         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12783                  mac_addr);
12784
12785 static void
12786 cmd_set_vf_mac_addr_parsed(
12787         void *parsed_result,
12788         __attribute__((unused)) struct cmdline *cl,
12789         __attribute__((unused)) void *data)
12790 {
12791         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12792         int ret = -ENOTSUP;
12793
12794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12795                 return;
12796
12797 #ifdef RTE_LIBRTE_IXGBE_PMD
12798         if (ret == -ENOTSUP)
12799                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12800                                 &res->mac_addr);
12801 #endif
12802 #ifdef RTE_LIBRTE_I40E_PMD
12803         if (ret == -ENOTSUP)
12804                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12805                                 &res->mac_addr);
12806 #endif
12807 #ifdef RTE_LIBRTE_BNXT_PMD
12808         if (ret == -ENOTSUP)
12809                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12810                                 &res->mac_addr);
12811 #endif
12812
12813         switch (ret) {
12814         case 0:
12815                 break;
12816         case -EINVAL:
12817                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12818                 break;
12819         case -ENODEV:
12820                 printf("invalid port_id %d\n", res->port_id);
12821                 break;
12822         case -ENOTSUP:
12823                 printf("function not implemented\n");
12824                 break;
12825         default:
12826                 printf("programming error: (%s)\n", strerror(-ret));
12827         }
12828 }
12829
12830 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12831         .f = cmd_set_vf_mac_addr_parsed,
12832         .data = NULL,
12833         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12834         .tokens = {
12835                 (void *)&cmd_set_vf_mac_addr_set,
12836                 (void *)&cmd_set_vf_mac_addr_vf,
12837                 (void *)&cmd_set_vf_mac_addr_mac,
12838                 (void *)&cmd_set_vf_mac_addr_addr,
12839                 (void *)&cmd_set_vf_mac_addr_port_id,
12840                 (void *)&cmd_set_vf_mac_addr_vf_id,
12841                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12842                 NULL,
12843         },
12844 };
12845
12846 /* MACsec configuration */
12847
12848 /* Common result structure for MACsec offload enable */
12849 struct cmd_macsec_offload_on_result {
12850         cmdline_fixed_string_t set;
12851         cmdline_fixed_string_t macsec;
12852         cmdline_fixed_string_t offload;
12853         portid_t port_id;
12854         cmdline_fixed_string_t on;
12855         cmdline_fixed_string_t encrypt;
12856         cmdline_fixed_string_t en_on_off;
12857         cmdline_fixed_string_t replay_protect;
12858         cmdline_fixed_string_t rp_on_off;
12859 };
12860
12861 /* Common CLI fields for MACsec offload disable */
12862 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_macsec_offload_on_result,
12865                  set, "set");
12866 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_macsec_offload_on_result,
12869                  macsec, "macsec");
12870 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_macsec_offload_on_result,
12873                  offload, "offload");
12874 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12875         TOKEN_NUM_INITIALIZER
12876                 (struct cmd_macsec_offload_on_result,
12877                  port_id, UINT16);
12878 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12879         TOKEN_STRING_INITIALIZER
12880                 (struct cmd_macsec_offload_on_result,
12881                  on, "on");
12882 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12883         TOKEN_STRING_INITIALIZER
12884                 (struct cmd_macsec_offload_on_result,
12885                  encrypt, "encrypt");
12886 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12887         TOKEN_STRING_INITIALIZER
12888                 (struct cmd_macsec_offload_on_result,
12889                  en_on_off, "on#off");
12890 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12891         TOKEN_STRING_INITIALIZER
12892                 (struct cmd_macsec_offload_on_result,
12893                  replay_protect, "replay-protect");
12894 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12895         TOKEN_STRING_INITIALIZER
12896                 (struct cmd_macsec_offload_on_result,
12897                  rp_on_off, "on#off");
12898
12899 static void
12900 cmd_set_macsec_offload_on_parsed(
12901         void *parsed_result,
12902         __attribute__((unused)) struct cmdline *cl,
12903         __attribute__((unused)) void *data)
12904 {
12905         struct cmd_macsec_offload_on_result *res = parsed_result;
12906         int ret = -ENOTSUP;
12907         portid_t port_id = res->port_id;
12908         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12909         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12910
12911         if (port_id_is_invalid(port_id, ENABLED_WARN))
12912                 return;
12913
12914         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12915 #ifdef RTE_LIBRTE_IXGBE_PMD
12916         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12917 #endif
12918         RTE_SET_USED(en);
12919         RTE_SET_USED(rp);
12920
12921         switch (ret) {
12922         case 0:
12923                 break;
12924         case -ENODEV:
12925                 printf("invalid port_id %d\n", port_id);
12926                 break;
12927         case -ENOTSUP:
12928                 printf("not supported on port %d\n", port_id);
12929                 break;
12930         default:
12931                 printf("programming error: (%s)\n", strerror(-ret));
12932         }
12933 }
12934
12935 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12936         .f = cmd_set_macsec_offload_on_parsed,
12937         .data = NULL,
12938         .help_str = "set macsec offload <port_id> on "
12939                 "encrypt on|off replay-protect on|off",
12940         .tokens = {
12941                 (void *)&cmd_macsec_offload_on_set,
12942                 (void *)&cmd_macsec_offload_on_macsec,
12943                 (void *)&cmd_macsec_offload_on_offload,
12944                 (void *)&cmd_macsec_offload_on_port_id,
12945                 (void *)&cmd_macsec_offload_on_on,
12946                 (void *)&cmd_macsec_offload_on_encrypt,
12947                 (void *)&cmd_macsec_offload_on_en_on_off,
12948                 (void *)&cmd_macsec_offload_on_replay_protect,
12949                 (void *)&cmd_macsec_offload_on_rp_on_off,
12950                 NULL,
12951         },
12952 };
12953
12954 /* Common result structure for MACsec offload disable */
12955 struct cmd_macsec_offload_off_result {
12956         cmdline_fixed_string_t set;
12957         cmdline_fixed_string_t macsec;
12958         cmdline_fixed_string_t offload;
12959         portid_t port_id;
12960         cmdline_fixed_string_t off;
12961 };
12962
12963 /* Common CLI fields for MACsec offload disable */
12964 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12965         TOKEN_STRING_INITIALIZER
12966                 (struct cmd_macsec_offload_off_result,
12967                  set, "set");
12968 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12969         TOKEN_STRING_INITIALIZER
12970                 (struct cmd_macsec_offload_off_result,
12971                  macsec, "macsec");
12972 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12973         TOKEN_STRING_INITIALIZER
12974                 (struct cmd_macsec_offload_off_result,
12975                  offload, "offload");
12976 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12977         TOKEN_NUM_INITIALIZER
12978                 (struct cmd_macsec_offload_off_result,
12979                  port_id, UINT16);
12980 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12981         TOKEN_STRING_INITIALIZER
12982                 (struct cmd_macsec_offload_off_result,
12983                  off, "off");
12984
12985 static void
12986 cmd_set_macsec_offload_off_parsed(
12987         void *parsed_result,
12988         __attribute__((unused)) struct cmdline *cl,
12989         __attribute__((unused)) void *data)
12990 {
12991         struct cmd_macsec_offload_off_result *res = parsed_result;
12992         int ret = -ENOTSUP;
12993         portid_t port_id = res->port_id;
12994
12995         if (port_id_is_invalid(port_id, ENABLED_WARN))
12996                 return;
12997
12998         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12999 #ifdef RTE_LIBRTE_IXGBE_PMD
13000         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13001 #endif
13002
13003         switch (ret) {
13004         case 0:
13005                 break;
13006         case -ENODEV:
13007                 printf("invalid port_id %d\n", port_id);
13008                 break;
13009         case -ENOTSUP:
13010                 printf("not supported on port %d\n", port_id);
13011                 break;
13012         default:
13013                 printf("programming error: (%s)\n", strerror(-ret));
13014         }
13015 }
13016
13017 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13018         .f = cmd_set_macsec_offload_off_parsed,
13019         .data = NULL,
13020         .help_str = "set macsec offload <port_id> off",
13021         .tokens = {
13022                 (void *)&cmd_macsec_offload_off_set,
13023                 (void *)&cmd_macsec_offload_off_macsec,
13024                 (void *)&cmd_macsec_offload_off_offload,
13025                 (void *)&cmd_macsec_offload_off_port_id,
13026                 (void *)&cmd_macsec_offload_off_off,
13027                 NULL,
13028         },
13029 };
13030
13031 /* Common result structure for MACsec secure connection configure */
13032 struct cmd_macsec_sc_result {
13033         cmdline_fixed_string_t set;
13034         cmdline_fixed_string_t macsec;
13035         cmdline_fixed_string_t sc;
13036         cmdline_fixed_string_t tx_rx;
13037         portid_t port_id;
13038         struct ether_addr mac;
13039         uint16_t pi;
13040 };
13041
13042 /* Common CLI fields for MACsec secure connection configure */
13043 cmdline_parse_token_string_t cmd_macsec_sc_set =
13044         TOKEN_STRING_INITIALIZER
13045                 (struct cmd_macsec_sc_result,
13046                  set, "set");
13047 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13048         TOKEN_STRING_INITIALIZER
13049                 (struct cmd_macsec_sc_result,
13050                  macsec, "macsec");
13051 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13052         TOKEN_STRING_INITIALIZER
13053                 (struct cmd_macsec_sc_result,
13054                  sc, "sc");
13055 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13056         TOKEN_STRING_INITIALIZER
13057                 (struct cmd_macsec_sc_result,
13058                  tx_rx, "tx#rx");
13059 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13060         TOKEN_NUM_INITIALIZER
13061                 (struct cmd_macsec_sc_result,
13062                  port_id, UINT16);
13063 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13064         TOKEN_ETHERADDR_INITIALIZER
13065                 (struct cmd_macsec_sc_result,
13066                  mac);
13067 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13068         TOKEN_NUM_INITIALIZER
13069                 (struct cmd_macsec_sc_result,
13070                  pi, UINT16);
13071
13072 static void
13073 cmd_set_macsec_sc_parsed(
13074         void *parsed_result,
13075         __attribute__((unused)) struct cmdline *cl,
13076         __attribute__((unused)) void *data)
13077 {
13078         struct cmd_macsec_sc_result *res = parsed_result;
13079         int ret = -ENOTSUP;
13080         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13081
13082 #ifdef RTE_LIBRTE_IXGBE_PMD
13083         ret = is_tx ?
13084                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13085                                 res->mac.addr_bytes) :
13086                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13087                                 res->mac.addr_bytes, res->pi);
13088 #endif
13089         RTE_SET_USED(is_tx);
13090
13091         switch (ret) {
13092         case 0:
13093                 break;
13094         case -ENODEV:
13095                 printf("invalid port_id %d\n", res->port_id);
13096                 break;
13097         case -ENOTSUP:
13098                 printf("not supported on port %d\n", res->port_id);
13099                 break;
13100         default:
13101                 printf("programming error: (%s)\n", strerror(-ret));
13102         }
13103 }
13104
13105 cmdline_parse_inst_t cmd_set_macsec_sc = {
13106         .f = cmd_set_macsec_sc_parsed,
13107         .data = NULL,
13108         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13109         .tokens = {
13110                 (void *)&cmd_macsec_sc_set,
13111                 (void *)&cmd_macsec_sc_macsec,
13112                 (void *)&cmd_macsec_sc_sc,
13113                 (void *)&cmd_macsec_sc_tx_rx,
13114                 (void *)&cmd_macsec_sc_port_id,
13115                 (void *)&cmd_macsec_sc_mac,
13116                 (void *)&cmd_macsec_sc_pi,
13117                 NULL,
13118         },
13119 };
13120
13121 /* Common result structure for MACsec secure connection configure */
13122 struct cmd_macsec_sa_result {
13123         cmdline_fixed_string_t set;
13124         cmdline_fixed_string_t macsec;
13125         cmdline_fixed_string_t sa;
13126         cmdline_fixed_string_t tx_rx;
13127         portid_t port_id;
13128         uint8_t idx;
13129         uint8_t an;
13130         uint32_t pn;
13131         cmdline_fixed_string_t key;
13132 };
13133
13134 /* Common CLI fields for MACsec secure connection configure */
13135 cmdline_parse_token_string_t cmd_macsec_sa_set =
13136         TOKEN_STRING_INITIALIZER
13137                 (struct cmd_macsec_sa_result,
13138                  set, "set");
13139 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13140         TOKEN_STRING_INITIALIZER
13141                 (struct cmd_macsec_sa_result,
13142                  macsec, "macsec");
13143 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13144         TOKEN_STRING_INITIALIZER
13145                 (struct cmd_macsec_sa_result,
13146                  sa, "sa");
13147 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13148         TOKEN_STRING_INITIALIZER
13149                 (struct cmd_macsec_sa_result,
13150                  tx_rx, "tx#rx");
13151 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13152         TOKEN_NUM_INITIALIZER
13153                 (struct cmd_macsec_sa_result,
13154                  port_id, UINT16);
13155 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13156         TOKEN_NUM_INITIALIZER
13157                 (struct cmd_macsec_sa_result,
13158                  idx, UINT8);
13159 cmdline_parse_token_num_t cmd_macsec_sa_an =
13160         TOKEN_NUM_INITIALIZER
13161                 (struct cmd_macsec_sa_result,
13162                  an, UINT8);
13163 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13164         TOKEN_NUM_INITIALIZER
13165                 (struct cmd_macsec_sa_result,
13166                  pn, UINT32);
13167 cmdline_parse_token_string_t cmd_macsec_sa_key =
13168         TOKEN_STRING_INITIALIZER
13169                 (struct cmd_macsec_sa_result,
13170                  key, NULL);
13171
13172 static void
13173 cmd_set_macsec_sa_parsed(
13174         void *parsed_result,
13175         __attribute__((unused)) struct cmdline *cl,
13176         __attribute__((unused)) void *data)
13177 {
13178         struct cmd_macsec_sa_result *res = parsed_result;
13179         int ret = -ENOTSUP;
13180         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13181         uint8_t key[16] = { 0 };
13182         uint8_t xdgt0;
13183         uint8_t xdgt1;
13184         int key_len;
13185         int i;
13186
13187         key_len = strlen(res->key) / 2;
13188         if (key_len > 16)
13189                 key_len = 16;
13190
13191         for (i = 0; i < key_len; i++) {
13192                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13193                 if (xdgt0 == 0xFF)
13194                         return;
13195                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13196                 if (xdgt1 == 0xFF)
13197                         return;
13198                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13199         }
13200
13201 #ifdef RTE_LIBRTE_IXGBE_PMD
13202         ret = is_tx ?
13203                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13204                         res->idx, res->an, res->pn, key) :
13205                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13206                         res->idx, res->an, res->pn, key);
13207 #endif
13208         RTE_SET_USED(is_tx);
13209         RTE_SET_USED(key);
13210
13211         switch (ret) {
13212         case 0:
13213                 break;
13214         case -EINVAL:
13215                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13216                 break;
13217         case -ENODEV:
13218                 printf("invalid port_id %d\n", res->port_id);
13219                 break;
13220         case -ENOTSUP:
13221                 printf("not supported on port %d\n", res->port_id);
13222                 break;
13223         default:
13224                 printf("programming error: (%s)\n", strerror(-ret));
13225         }
13226 }
13227
13228 cmdline_parse_inst_t cmd_set_macsec_sa = {
13229         .f = cmd_set_macsec_sa_parsed,
13230         .data = NULL,
13231         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13232         .tokens = {
13233                 (void *)&cmd_macsec_sa_set,
13234                 (void *)&cmd_macsec_sa_macsec,
13235                 (void *)&cmd_macsec_sa_sa,
13236                 (void *)&cmd_macsec_sa_tx_rx,
13237                 (void *)&cmd_macsec_sa_port_id,
13238                 (void *)&cmd_macsec_sa_idx,
13239                 (void *)&cmd_macsec_sa_an,
13240                 (void *)&cmd_macsec_sa_pn,
13241                 (void *)&cmd_macsec_sa_key,
13242                 NULL,
13243         },
13244 };
13245
13246 /* VF unicast promiscuous mode configuration */
13247
13248 /* Common result structure for VF unicast promiscuous mode */
13249 struct cmd_vf_promisc_result {
13250         cmdline_fixed_string_t set;
13251         cmdline_fixed_string_t vf;
13252         cmdline_fixed_string_t promisc;
13253         portid_t port_id;
13254         uint32_t vf_id;
13255         cmdline_fixed_string_t on_off;
13256 };
13257
13258 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13259 cmdline_parse_token_string_t cmd_vf_promisc_set =
13260         TOKEN_STRING_INITIALIZER
13261                 (struct cmd_vf_promisc_result,
13262                  set, "set");
13263 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13264         TOKEN_STRING_INITIALIZER
13265                 (struct cmd_vf_promisc_result,
13266                  vf, "vf");
13267 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13268         TOKEN_STRING_INITIALIZER
13269                 (struct cmd_vf_promisc_result,
13270                  promisc, "promisc");
13271 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13272         TOKEN_NUM_INITIALIZER
13273                 (struct cmd_vf_promisc_result,
13274                  port_id, UINT16);
13275 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13276         TOKEN_NUM_INITIALIZER
13277                 (struct cmd_vf_promisc_result,
13278                  vf_id, UINT32);
13279 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13280         TOKEN_STRING_INITIALIZER
13281                 (struct cmd_vf_promisc_result,
13282                  on_off, "on#off");
13283
13284 static void
13285 cmd_set_vf_promisc_parsed(
13286         void *parsed_result,
13287         __attribute__((unused)) struct cmdline *cl,
13288         __attribute__((unused)) void *data)
13289 {
13290         struct cmd_vf_promisc_result *res = parsed_result;
13291         int ret = -ENOTSUP;
13292
13293         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13294
13295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13296                 return;
13297
13298 #ifdef RTE_LIBRTE_I40E_PMD
13299         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13300                                                   res->vf_id, is_on);
13301 #endif
13302
13303         switch (ret) {
13304         case 0:
13305                 break;
13306         case -EINVAL:
13307                 printf("invalid vf_id %d\n", res->vf_id);
13308                 break;
13309         case -ENODEV:
13310                 printf("invalid port_id %d\n", res->port_id);
13311                 break;
13312         case -ENOTSUP:
13313                 printf("function not implemented\n");
13314                 break;
13315         default:
13316                 printf("programming error: (%s)\n", strerror(-ret));
13317         }
13318 }
13319
13320 cmdline_parse_inst_t cmd_set_vf_promisc = {
13321         .f = cmd_set_vf_promisc_parsed,
13322         .data = NULL,
13323         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13324                 "Set unicast promiscuous mode for a VF from the PF",
13325         .tokens = {
13326                 (void *)&cmd_vf_promisc_set,
13327                 (void *)&cmd_vf_promisc_vf,
13328                 (void *)&cmd_vf_promisc_promisc,
13329                 (void *)&cmd_vf_promisc_port_id,
13330                 (void *)&cmd_vf_promisc_vf_id,
13331                 (void *)&cmd_vf_promisc_on_off,
13332                 NULL,
13333         },
13334 };
13335
13336 /* VF multicast promiscuous mode configuration */
13337
13338 /* Common result structure for VF multicast promiscuous mode */
13339 struct cmd_vf_allmulti_result {
13340         cmdline_fixed_string_t set;
13341         cmdline_fixed_string_t vf;
13342         cmdline_fixed_string_t allmulti;
13343         portid_t port_id;
13344         uint32_t vf_id;
13345         cmdline_fixed_string_t on_off;
13346 };
13347
13348 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13349 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13350         TOKEN_STRING_INITIALIZER
13351                 (struct cmd_vf_allmulti_result,
13352                  set, "set");
13353 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13354         TOKEN_STRING_INITIALIZER
13355                 (struct cmd_vf_allmulti_result,
13356                  vf, "vf");
13357 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13358         TOKEN_STRING_INITIALIZER
13359                 (struct cmd_vf_allmulti_result,
13360                  allmulti, "allmulti");
13361 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13362         TOKEN_NUM_INITIALIZER
13363                 (struct cmd_vf_allmulti_result,
13364                  port_id, UINT16);
13365 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13366         TOKEN_NUM_INITIALIZER
13367                 (struct cmd_vf_allmulti_result,
13368                  vf_id, UINT32);
13369 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13370         TOKEN_STRING_INITIALIZER
13371                 (struct cmd_vf_allmulti_result,
13372                  on_off, "on#off");
13373
13374 static void
13375 cmd_set_vf_allmulti_parsed(
13376         void *parsed_result,
13377         __attribute__((unused)) struct cmdline *cl,
13378         __attribute__((unused)) void *data)
13379 {
13380         struct cmd_vf_allmulti_result *res = parsed_result;
13381         int ret = -ENOTSUP;
13382
13383         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13384
13385         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13386                 return;
13387
13388 #ifdef RTE_LIBRTE_I40E_PMD
13389         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13390                                                     res->vf_id, is_on);
13391 #endif
13392
13393         switch (ret) {
13394         case 0:
13395                 break;
13396         case -EINVAL:
13397                 printf("invalid vf_id %d\n", res->vf_id);
13398                 break;
13399         case -ENODEV:
13400                 printf("invalid port_id %d\n", res->port_id);
13401                 break;
13402         case -ENOTSUP:
13403                 printf("function not implemented\n");
13404                 break;
13405         default:
13406                 printf("programming error: (%s)\n", strerror(-ret));
13407         }
13408 }
13409
13410 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13411         .f = cmd_set_vf_allmulti_parsed,
13412         .data = NULL,
13413         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13414                 "Set multicast promiscuous mode for a VF from the PF",
13415         .tokens = {
13416                 (void *)&cmd_vf_allmulti_set,
13417                 (void *)&cmd_vf_allmulti_vf,
13418                 (void *)&cmd_vf_allmulti_allmulti,
13419                 (void *)&cmd_vf_allmulti_port_id,
13420                 (void *)&cmd_vf_allmulti_vf_id,
13421                 (void *)&cmd_vf_allmulti_on_off,
13422                 NULL,
13423         },
13424 };
13425
13426 /* vf broadcast mode configuration */
13427
13428 /* Common result structure for vf broadcast */
13429 struct cmd_set_vf_broadcast_result {
13430         cmdline_fixed_string_t set;
13431         cmdline_fixed_string_t vf;
13432         cmdline_fixed_string_t broadcast;
13433         portid_t port_id;
13434         uint16_t vf_id;
13435         cmdline_fixed_string_t on_off;
13436 };
13437
13438 /* Common CLI fields for vf broadcast enable disable */
13439 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13440         TOKEN_STRING_INITIALIZER
13441                 (struct cmd_set_vf_broadcast_result,
13442                  set, "set");
13443 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_set_vf_broadcast_result,
13446                  vf, "vf");
13447 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13448         TOKEN_STRING_INITIALIZER
13449                 (struct cmd_set_vf_broadcast_result,
13450                  broadcast, "broadcast");
13451 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13452         TOKEN_NUM_INITIALIZER
13453                 (struct cmd_set_vf_broadcast_result,
13454                  port_id, UINT16);
13455 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13456         TOKEN_NUM_INITIALIZER
13457                 (struct cmd_set_vf_broadcast_result,
13458                  vf_id, UINT16);
13459 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13460         TOKEN_STRING_INITIALIZER
13461                 (struct cmd_set_vf_broadcast_result,
13462                  on_off, "on#off");
13463
13464 static void
13465 cmd_set_vf_broadcast_parsed(
13466         void *parsed_result,
13467         __attribute__((unused)) struct cmdline *cl,
13468         __attribute__((unused)) void *data)
13469 {
13470         struct cmd_set_vf_broadcast_result *res = parsed_result;
13471         int ret = -ENOTSUP;
13472
13473         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13474
13475         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13476                 return;
13477
13478 #ifdef RTE_LIBRTE_I40E_PMD
13479         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13480                                             res->vf_id, is_on);
13481 #endif
13482
13483         switch (ret) {
13484         case 0:
13485                 break;
13486         case -EINVAL:
13487                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13488                 break;
13489         case -ENODEV:
13490                 printf("invalid port_id %d\n", res->port_id);
13491                 break;
13492         case -ENOTSUP:
13493                 printf("function not implemented\n");
13494                 break;
13495         default:
13496                 printf("programming error: (%s)\n", strerror(-ret));
13497         }
13498 }
13499
13500 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13501         .f = cmd_set_vf_broadcast_parsed,
13502         .data = NULL,
13503         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13504         .tokens = {
13505                 (void *)&cmd_set_vf_broadcast_set,
13506                 (void *)&cmd_set_vf_broadcast_vf,
13507                 (void *)&cmd_set_vf_broadcast_broadcast,
13508                 (void *)&cmd_set_vf_broadcast_port_id,
13509                 (void *)&cmd_set_vf_broadcast_vf_id,
13510                 (void *)&cmd_set_vf_broadcast_on_off,
13511                 NULL,
13512         },
13513 };
13514
13515 /* vf vlan tag configuration */
13516
13517 /* Common result structure for vf vlan tag */
13518 struct cmd_set_vf_vlan_tag_result {
13519         cmdline_fixed_string_t set;
13520         cmdline_fixed_string_t vf;
13521         cmdline_fixed_string_t vlan;
13522         cmdline_fixed_string_t tag;
13523         portid_t port_id;
13524         uint16_t vf_id;
13525         cmdline_fixed_string_t on_off;
13526 };
13527
13528 /* Common CLI fields for vf vlan tag enable disable */
13529 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13530         TOKEN_STRING_INITIALIZER
13531                 (struct cmd_set_vf_vlan_tag_result,
13532                  set, "set");
13533 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13534         TOKEN_STRING_INITIALIZER
13535                 (struct cmd_set_vf_vlan_tag_result,
13536                  vf, "vf");
13537 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_set_vf_vlan_tag_result,
13540                  vlan, "vlan");
13541 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13542         TOKEN_STRING_INITIALIZER
13543                 (struct cmd_set_vf_vlan_tag_result,
13544                  tag, "tag");
13545 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13546         TOKEN_NUM_INITIALIZER
13547                 (struct cmd_set_vf_vlan_tag_result,
13548                  port_id, UINT16);
13549 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13550         TOKEN_NUM_INITIALIZER
13551                 (struct cmd_set_vf_vlan_tag_result,
13552                  vf_id, UINT16);
13553 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13554         TOKEN_STRING_INITIALIZER
13555                 (struct cmd_set_vf_vlan_tag_result,
13556                  on_off, "on#off");
13557
13558 static void
13559 cmd_set_vf_vlan_tag_parsed(
13560         void *parsed_result,
13561         __attribute__((unused)) struct cmdline *cl,
13562         __attribute__((unused)) void *data)
13563 {
13564         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13565         int ret = -ENOTSUP;
13566
13567         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13568
13569         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13570                 return;
13571
13572 #ifdef RTE_LIBRTE_I40E_PMD
13573         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13574                                            res->vf_id, is_on);
13575 #endif
13576
13577         switch (ret) {
13578         case 0:
13579                 break;
13580         case -EINVAL:
13581                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13582                 break;
13583         case -ENODEV:
13584                 printf("invalid port_id %d\n", res->port_id);
13585                 break;
13586         case -ENOTSUP:
13587                 printf("function not implemented\n");
13588                 break;
13589         default:
13590                 printf("programming error: (%s)\n", strerror(-ret));
13591         }
13592 }
13593
13594 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13595         .f = cmd_set_vf_vlan_tag_parsed,
13596         .data = NULL,
13597         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13598         .tokens = {
13599                 (void *)&cmd_set_vf_vlan_tag_set,
13600                 (void *)&cmd_set_vf_vlan_tag_vf,
13601                 (void *)&cmd_set_vf_vlan_tag_vlan,
13602                 (void *)&cmd_set_vf_vlan_tag_tag,
13603                 (void *)&cmd_set_vf_vlan_tag_port_id,
13604                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13605                 (void *)&cmd_set_vf_vlan_tag_on_off,
13606                 NULL,
13607         },
13608 };
13609
13610 /* Common definition of VF and TC TX bandwidth configuration */
13611 struct cmd_vf_tc_bw_result {
13612         cmdline_fixed_string_t set;
13613         cmdline_fixed_string_t vf;
13614         cmdline_fixed_string_t tc;
13615         cmdline_fixed_string_t tx;
13616         cmdline_fixed_string_t min_bw;
13617         cmdline_fixed_string_t max_bw;
13618         cmdline_fixed_string_t strict_link_prio;
13619         portid_t port_id;
13620         uint16_t vf_id;
13621         uint8_t tc_no;
13622         uint32_t bw;
13623         cmdline_fixed_string_t bw_list;
13624         uint8_t tc_map;
13625 };
13626
13627 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13628         TOKEN_STRING_INITIALIZER
13629                 (struct cmd_vf_tc_bw_result,
13630                  set, "set");
13631 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13632         TOKEN_STRING_INITIALIZER
13633                 (struct cmd_vf_tc_bw_result,
13634                  vf, "vf");
13635 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13636         TOKEN_STRING_INITIALIZER
13637                 (struct cmd_vf_tc_bw_result,
13638                  tc, "tc");
13639 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13640         TOKEN_STRING_INITIALIZER
13641                 (struct cmd_vf_tc_bw_result,
13642                  tx, "tx");
13643 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_vf_tc_bw_result,
13646                  strict_link_prio, "strict-link-priority");
13647 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13648         TOKEN_STRING_INITIALIZER
13649                 (struct cmd_vf_tc_bw_result,
13650                  min_bw, "min-bandwidth");
13651 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13652         TOKEN_STRING_INITIALIZER
13653                 (struct cmd_vf_tc_bw_result,
13654                  max_bw, "max-bandwidth");
13655 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13656         TOKEN_NUM_INITIALIZER
13657                 (struct cmd_vf_tc_bw_result,
13658                  port_id, UINT16);
13659 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13660         TOKEN_NUM_INITIALIZER
13661                 (struct cmd_vf_tc_bw_result,
13662                  vf_id, UINT16);
13663 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13664         TOKEN_NUM_INITIALIZER
13665                 (struct cmd_vf_tc_bw_result,
13666                  tc_no, UINT8);
13667 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13668         TOKEN_NUM_INITIALIZER
13669                 (struct cmd_vf_tc_bw_result,
13670                  bw, UINT32);
13671 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13672         TOKEN_STRING_INITIALIZER
13673                 (struct cmd_vf_tc_bw_result,
13674                  bw_list, NULL);
13675 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13676         TOKEN_NUM_INITIALIZER
13677                 (struct cmd_vf_tc_bw_result,
13678                  tc_map, UINT8);
13679
13680 /* VF max bandwidth setting */
13681 static void
13682 cmd_vf_max_bw_parsed(
13683         void *parsed_result,
13684         __attribute__((unused)) struct cmdline *cl,
13685         __attribute__((unused)) void *data)
13686 {
13687         struct cmd_vf_tc_bw_result *res = parsed_result;
13688         int ret = -ENOTSUP;
13689
13690         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13691                 return;
13692
13693 #ifdef RTE_LIBRTE_I40E_PMD
13694         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13695                                          res->vf_id, res->bw);
13696 #endif
13697
13698         switch (ret) {
13699         case 0:
13700                 break;
13701         case -EINVAL:
13702                 printf("invalid vf_id %d or bandwidth %d\n",
13703                        res->vf_id, res->bw);
13704                 break;
13705         case -ENODEV:
13706                 printf("invalid port_id %d\n", res->port_id);
13707                 break;
13708         case -ENOTSUP:
13709                 printf("function not implemented\n");
13710                 break;
13711         default:
13712                 printf("programming error: (%s)\n", strerror(-ret));
13713         }
13714 }
13715
13716 cmdline_parse_inst_t cmd_vf_max_bw = {
13717         .f = cmd_vf_max_bw_parsed,
13718         .data = NULL,
13719         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13720         .tokens = {
13721                 (void *)&cmd_vf_tc_bw_set,
13722                 (void *)&cmd_vf_tc_bw_vf,
13723                 (void *)&cmd_vf_tc_bw_tx,
13724                 (void *)&cmd_vf_tc_bw_max_bw,
13725                 (void *)&cmd_vf_tc_bw_port_id,
13726                 (void *)&cmd_vf_tc_bw_vf_id,
13727                 (void *)&cmd_vf_tc_bw_bw,
13728                 NULL,
13729         },
13730 };
13731
13732 static int
13733 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13734                            uint8_t *tc_num,
13735                            char *str)
13736 {
13737         uint32_t size;
13738         const char *p, *p0 = str;
13739         char s[256];
13740         char *end;
13741         char *str_fld[16];
13742         uint16_t i;
13743         int ret;
13744
13745         p = strchr(p0, '(');
13746         if (p == NULL) {
13747                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13748                 return -1;
13749         }
13750         p++;
13751         p0 = strchr(p, ')');
13752         if (p0 == NULL) {
13753                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13754                 return -1;
13755         }
13756         size = p0 - p;
13757         if (size >= sizeof(s)) {
13758                 printf("The string size exceeds the internal buffer size\n");
13759                 return -1;
13760         }
13761         snprintf(s, sizeof(s), "%.*s", size, p);
13762         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13763         if (ret <= 0) {
13764                 printf("Failed to get the bandwidth list. ");
13765                 return -1;
13766         }
13767         *tc_num = ret;
13768         for (i = 0; i < ret; i++)
13769                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13770
13771         return 0;
13772 }
13773
13774 /* TC min bandwidth setting */
13775 static void
13776 cmd_vf_tc_min_bw_parsed(
13777         void *parsed_result,
13778         __attribute__((unused)) struct cmdline *cl,
13779         __attribute__((unused)) void *data)
13780 {
13781         struct cmd_vf_tc_bw_result *res = parsed_result;
13782         uint8_t tc_num;
13783         uint8_t bw[16];
13784         int ret = -ENOTSUP;
13785
13786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13787                 return;
13788
13789         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13790         if (ret)
13791                 return;
13792
13793 #ifdef RTE_LIBRTE_I40E_PMD
13794         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13795                                               tc_num, bw);
13796 #endif
13797
13798         switch (ret) {
13799         case 0:
13800                 break;
13801         case -EINVAL:
13802                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13803                 break;
13804         case -ENODEV:
13805                 printf("invalid port_id %d\n", res->port_id);
13806                 break;
13807         case -ENOTSUP:
13808                 printf("function not implemented\n");
13809                 break;
13810         default:
13811                 printf("programming error: (%s)\n", strerror(-ret));
13812         }
13813 }
13814
13815 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13816         .f = cmd_vf_tc_min_bw_parsed,
13817         .data = NULL,
13818         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13819                     " <bw1, bw2, ...>",
13820         .tokens = {
13821                 (void *)&cmd_vf_tc_bw_set,
13822                 (void *)&cmd_vf_tc_bw_vf,
13823                 (void *)&cmd_vf_tc_bw_tc,
13824                 (void *)&cmd_vf_tc_bw_tx,
13825                 (void *)&cmd_vf_tc_bw_min_bw,
13826                 (void *)&cmd_vf_tc_bw_port_id,
13827                 (void *)&cmd_vf_tc_bw_vf_id,
13828                 (void *)&cmd_vf_tc_bw_bw_list,
13829                 NULL,
13830         },
13831 };
13832
13833 static void
13834 cmd_tc_min_bw_parsed(
13835         void *parsed_result,
13836         __attribute__((unused)) struct cmdline *cl,
13837         __attribute__((unused)) void *data)
13838 {
13839         struct cmd_vf_tc_bw_result *res = parsed_result;
13840         struct rte_port *port;
13841         uint8_t tc_num;
13842         uint8_t bw[16];
13843         int ret = -ENOTSUP;
13844
13845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13846                 return;
13847
13848         port = &ports[res->port_id];
13849         /** Check if the port is not started **/
13850         if (port->port_status != RTE_PORT_STOPPED) {
13851                 printf("Please stop port %d first\n", res->port_id);
13852                 return;
13853         }
13854
13855         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13856         if (ret)
13857                 return;
13858
13859 #ifdef RTE_LIBRTE_IXGBE_PMD
13860         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13861 #endif
13862
13863         switch (ret) {
13864         case 0:
13865                 break;
13866         case -EINVAL:
13867                 printf("invalid bandwidth\n");
13868                 break;
13869         case -ENODEV:
13870                 printf("invalid port_id %d\n", res->port_id);
13871                 break;
13872         case -ENOTSUP:
13873                 printf("function not implemented\n");
13874                 break;
13875         default:
13876                 printf("programming error: (%s)\n", strerror(-ret));
13877         }
13878 }
13879
13880 cmdline_parse_inst_t cmd_tc_min_bw = {
13881         .f = cmd_tc_min_bw_parsed,
13882         .data = NULL,
13883         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13884         .tokens = {
13885                 (void *)&cmd_vf_tc_bw_set,
13886                 (void *)&cmd_vf_tc_bw_tc,
13887                 (void *)&cmd_vf_tc_bw_tx,
13888                 (void *)&cmd_vf_tc_bw_min_bw,
13889                 (void *)&cmd_vf_tc_bw_port_id,
13890                 (void *)&cmd_vf_tc_bw_bw_list,
13891                 NULL,
13892         },
13893 };
13894
13895 /* TC max bandwidth setting */
13896 static void
13897 cmd_vf_tc_max_bw_parsed(
13898         void *parsed_result,
13899         __attribute__((unused)) struct cmdline *cl,
13900         __attribute__((unused)) void *data)
13901 {
13902         struct cmd_vf_tc_bw_result *res = parsed_result;
13903         int ret = -ENOTSUP;
13904
13905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13906                 return;
13907
13908 #ifdef RTE_LIBRTE_I40E_PMD
13909         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13910                                             res->tc_no, res->bw);
13911 #endif
13912
13913         switch (ret) {
13914         case 0:
13915                 break;
13916         case -EINVAL:
13917                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13918                        res->vf_id, res->tc_no, res->bw);
13919                 break;
13920         case -ENODEV:
13921                 printf("invalid port_id %d\n", res->port_id);
13922                 break;
13923         case -ENOTSUP:
13924                 printf("function not implemented\n");
13925                 break;
13926         default:
13927                 printf("programming error: (%s)\n", strerror(-ret));
13928         }
13929 }
13930
13931 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13932         .f = cmd_vf_tc_max_bw_parsed,
13933         .data = NULL,
13934         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13935                     " <bandwidth>",
13936         .tokens = {
13937                 (void *)&cmd_vf_tc_bw_set,
13938                 (void *)&cmd_vf_tc_bw_vf,
13939                 (void *)&cmd_vf_tc_bw_tc,
13940                 (void *)&cmd_vf_tc_bw_tx,
13941                 (void *)&cmd_vf_tc_bw_max_bw,
13942                 (void *)&cmd_vf_tc_bw_port_id,
13943                 (void *)&cmd_vf_tc_bw_vf_id,
13944                 (void *)&cmd_vf_tc_bw_tc_no,
13945                 (void *)&cmd_vf_tc_bw_bw,
13946                 NULL,
13947         },
13948 };
13949
13950
13951 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
13952
13953 /* *** Set Port default Traffic Management Hierarchy *** */
13954 struct cmd_set_port_tm_hierarchy_default_result {
13955         cmdline_fixed_string_t set;
13956         cmdline_fixed_string_t port;
13957         cmdline_fixed_string_t tm;
13958         cmdline_fixed_string_t hierarchy;
13959         cmdline_fixed_string_t def;
13960         portid_t port_id;
13961 };
13962
13963 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
13964         TOKEN_STRING_INITIALIZER(
13965                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
13966 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
13967         TOKEN_STRING_INITIALIZER(
13968                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
13969 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
13970         TOKEN_STRING_INITIALIZER(
13971                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
13972 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
13973         TOKEN_STRING_INITIALIZER(
13974                 struct cmd_set_port_tm_hierarchy_default_result,
13975                         hierarchy, "hierarchy");
13976 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
13977         TOKEN_STRING_INITIALIZER(
13978                 struct cmd_set_port_tm_hierarchy_default_result,
13979                         def, "default");
13980 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
13981         TOKEN_NUM_INITIALIZER(
13982                 struct cmd_set_port_tm_hierarchy_default_result,
13983                         port_id, UINT16);
13984
13985 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
13986         __attribute__((unused)) struct cmdline *cl,
13987         __attribute__((unused)) void *data)
13988 {
13989         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
13990         struct rte_port *p;
13991         portid_t port_id = res->port_id;
13992
13993         if (port_id_is_invalid(port_id, ENABLED_WARN))
13994                 return;
13995
13996         p = &ports[port_id];
13997
13998         /* Port tm flag */
13999         if (p->softport.tm_flag == 0) {
14000                 printf("  tm not enabled on port %u (error)\n", port_id);
14001                 return;
14002         }
14003
14004         /* Forward mode: tm */
14005         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14006                 printf("  tm mode not enabled(error)\n");
14007                 return;
14008         }
14009
14010         /* Set the default tm hierarchy */
14011         p->softport.tm.default_hierarchy_enable = 1;
14012 }
14013
14014 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14015         .f = cmd_set_port_tm_hierarchy_default_parsed,
14016         .data = NULL,
14017         .help_str = "set port tm hierarchy default <port_id>",
14018         .tokens = {
14019                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14020                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14021                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14022                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14023                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14024                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14025                 NULL,
14026         },
14027 };
14028 #endif
14029
14030 /* Strict link priority scheduling mode setting */
14031 static void
14032 cmd_strict_link_prio_parsed(
14033         void *parsed_result,
14034         __attribute__((unused)) struct cmdline *cl,
14035         __attribute__((unused)) void *data)
14036 {
14037         struct cmd_vf_tc_bw_result *res = parsed_result;
14038         int ret = -ENOTSUP;
14039
14040         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14041                 return;
14042
14043 #ifdef RTE_LIBRTE_I40E_PMD
14044         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14045 #endif
14046
14047         switch (ret) {
14048         case 0:
14049                 break;
14050         case -EINVAL:
14051                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14052                 break;
14053         case -ENODEV:
14054                 printf("invalid port_id %d\n", res->port_id);
14055                 break;
14056         case -ENOTSUP:
14057                 printf("function not implemented\n");
14058                 break;
14059         default:
14060                 printf("programming error: (%s)\n", strerror(-ret));
14061         }
14062 }
14063
14064 cmdline_parse_inst_t cmd_strict_link_prio = {
14065         .f = cmd_strict_link_prio_parsed,
14066         .data = NULL,
14067         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14068         .tokens = {
14069                 (void *)&cmd_vf_tc_bw_set,
14070                 (void *)&cmd_vf_tc_bw_tx,
14071                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14072                 (void *)&cmd_vf_tc_bw_port_id,
14073                 (void *)&cmd_vf_tc_bw_tc_map,
14074                 NULL,
14075         },
14076 };
14077
14078 /* Load dynamic device personalization*/
14079 struct cmd_ddp_add_result {
14080         cmdline_fixed_string_t ddp;
14081         cmdline_fixed_string_t add;
14082         portid_t port_id;
14083         char filepath[];
14084 };
14085
14086 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14087         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14088 cmdline_parse_token_string_t cmd_ddp_add_add =
14089         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14090 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14091         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14092 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14093         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14094
14095 static void
14096 cmd_ddp_add_parsed(
14097         void *parsed_result,
14098         __attribute__((unused)) struct cmdline *cl,
14099         __attribute__((unused)) void *data)
14100 {
14101         struct cmd_ddp_add_result *res = parsed_result;
14102         uint8_t *buff;
14103         uint32_t size;
14104         char *filepath;
14105         char *file_fld[2];
14106         int file_num;
14107         int ret = -ENOTSUP;
14108
14109         if (res->port_id > nb_ports) {
14110                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14111                 return;
14112         }
14113
14114         if (!all_ports_stopped()) {
14115                 printf("Please stop all ports first\n");
14116                 return;
14117         }
14118
14119         filepath = strdup(res->filepath);
14120         if (filepath == NULL) {
14121                 printf("Failed to allocate memory\n");
14122                 return;
14123         }
14124         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14125
14126         buff = open_ddp_package_file(file_fld[0], &size);
14127         if (!buff) {
14128                 free((void *)filepath);
14129                 return;
14130         }
14131
14132 #ifdef RTE_LIBRTE_I40E_PMD
14133         if (ret == -ENOTSUP)
14134                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14135                                                buff, size,
14136                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14137 #endif
14138
14139         if (ret == -EEXIST)
14140                 printf("Profile has already existed.\n");
14141         else if (ret < 0)
14142                 printf("Failed to load profile.\n");
14143         else if (file_num == 2)
14144                 save_ddp_package_file(file_fld[1], buff, size);
14145
14146         close_ddp_package_file(buff);
14147         free((void *)filepath);
14148 }
14149
14150 cmdline_parse_inst_t cmd_ddp_add = {
14151         .f = cmd_ddp_add_parsed,
14152         .data = NULL,
14153         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14154         .tokens = {
14155                 (void *)&cmd_ddp_add_ddp,
14156                 (void *)&cmd_ddp_add_add,
14157                 (void *)&cmd_ddp_add_port_id,
14158                 (void *)&cmd_ddp_add_filepath,
14159                 NULL,
14160         },
14161 };
14162
14163 /* Delete dynamic device personalization*/
14164 struct cmd_ddp_del_result {
14165         cmdline_fixed_string_t ddp;
14166         cmdline_fixed_string_t del;
14167         portid_t port_id;
14168         char filepath[];
14169 };
14170
14171 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14172         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14173 cmdline_parse_token_string_t cmd_ddp_del_del =
14174         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14175 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14176         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14177 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14178         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14179
14180 static void
14181 cmd_ddp_del_parsed(
14182         void *parsed_result,
14183         __attribute__((unused)) struct cmdline *cl,
14184         __attribute__((unused)) void *data)
14185 {
14186         struct cmd_ddp_del_result *res = parsed_result;
14187         uint8_t *buff;
14188         uint32_t size;
14189         int ret = -ENOTSUP;
14190
14191         if (res->port_id > nb_ports) {
14192                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14193                 return;
14194         }
14195
14196         if (!all_ports_stopped()) {
14197                 printf("Please stop all ports first\n");
14198                 return;
14199         }
14200
14201         buff = open_ddp_package_file(res->filepath, &size);
14202         if (!buff)
14203                 return;
14204
14205 #ifdef RTE_LIBRTE_I40E_PMD
14206         if (ret == -ENOTSUP)
14207                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14208                                                buff, size,
14209                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14210 #endif
14211
14212         if (ret == -EACCES)
14213                 printf("Profile does not exist.\n");
14214         else if (ret < 0)
14215                 printf("Failed to delete profile.\n");
14216
14217         close_ddp_package_file(buff);
14218 }
14219
14220 cmdline_parse_inst_t cmd_ddp_del = {
14221         .f = cmd_ddp_del_parsed,
14222         .data = NULL,
14223         .help_str = "ddp del <port_id> <profile_path>",
14224         .tokens = {
14225                 (void *)&cmd_ddp_del_ddp,
14226                 (void *)&cmd_ddp_del_del,
14227                 (void *)&cmd_ddp_del_port_id,
14228                 (void *)&cmd_ddp_del_filepath,
14229                 NULL,
14230         },
14231 };
14232
14233 /* Get dynamic device personalization profile info */
14234 struct cmd_ddp_info_result {
14235         cmdline_fixed_string_t ddp;
14236         cmdline_fixed_string_t get;
14237         cmdline_fixed_string_t info;
14238         char filepath[];
14239 };
14240
14241 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14242         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14243 cmdline_parse_token_string_t cmd_ddp_info_get =
14244         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14245 cmdline_parse_token_string_t cmd_ddp_info_info =
14246         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14247 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14248         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14249
14250 static void
14251 cmd_ddp_info_parsed(
14252         void *parsed_result,
14253         __attribute__((unused)) struct cmdline *cl,
14254         __attribute__((unused)) void *data)
14255 {
14256         struct cmd_ddp_info_result *res = parsed_result;
14257         uint8_t *pkg;
14258         uint32_t pkg_size;
14259         int ret = -ENOTSUP;
14260 #ifdef RTE_LIBRTE_I40E_PMD
14261         uint32_t i, j, n;
14262         uint8_t *buff;
14263         uint32_t buff_size = 0;
14264         struct rte_pmd_i40e_profile_info info;
14265         uint32_t dev_num = 0;
14266         struct rte_pmd_i40e_ddp_device_id *devs;
14267         uint32_t proto_num = 0;
14268         struct rte_pmd_i40e_proto_info *proto;
14269         uint32_t pctype_num = 0;
14270         struct rte_pmd_i40e_ptype_info *pctype;
14271         uint32_t ptype_num = 0;
14272         struct rte_pmd_i40e_ptype_info *ptype;
14273         uint8_t proto_id;
14274
14275 #endif
14276
14277         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14278         if (!pkg)
14279                 return;
14280
14281 #ifdef RTE_LIBRTE_I40E_PMD
14282         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14283                                 (uint8_t *)&info, sizeof(info),
14284                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14285         if (!ret) {
14286                 printf("Global Track id:       0x%x\n", info.track_id);
14287                 printf("Global Version:        %d.%d.%d.%d\n",
14288                         info.version.major,
14289                         info.version.minor,
14290                         info.version.update,
14291                         info.version.draft);
14292                 printf("Global Package name:   %s\n\n", info.name);
14293         }
14294
14295         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14296                                 (uint8_t *)&info, sizeof(info),
14297                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14298         if (!ret) {
14299                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14300                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14301                         info.version.major,
14302                         info.version.minor,
14303                         info.version.update,
14304                         info.version.draft);
14305                 printf("i40e Profile name:     %s\n\n", info.name);
14306         }
14307
14308         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14309                                 (uint8_t *)&buff_size, sizeof(buff_size),
14310                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14311         if (!ret && buff_size) {
14312                 buff = (uint8_t *)malloc(buff_size);
14313                 if (buff) {
14314                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14315                                                 buff, buff_size,
14316                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14317                         if (!ret)
14318                                 printf("Package Notes:\n%s\n\n", buff);
14319                         free(buff);
14320                 }
14321         }
14322
14323         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14324                                 (uint8_t *)&dev_num, sizeof(dev_num),
14325                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14326         if (!ret && dev_num) {
14327                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14328                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14329                 if (devs) {
14330                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14331                                                 (uint8_t *)devs, buff_size,
14332                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14333                         if (!ret) {
14334                                 printf("List of supported devices:\n");
14335                                 for (i = 0; i < dev_num; i++) {
14336                                         printf("  %04X:%04X %04X:%04X\n",
14337                                                 devs[i].vendor_dev_id >> 16,
14338                                                 devs[i].vendor_dev_id & 0xFFFF,
14339                                                 devs[i].sub_vendor_dev_id >> 16,
14340                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14341                                 }
14342                                 printf("\n");
14343                         }
14344                         free(devs);
14345                 }
14346         }
14347
14348         /* get information about protocols and packet types */
14349         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14350                 (uint8_t *)&proto_num, sizeof(proto_num),
14351                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14352         if (ret || !proto_num)
14353                 goto no_print_return;
14354
14355         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14356         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14357         if (!proto)
14358                 goto no_print_return;
14359
14360         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14361                                         buff_size,
14362                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14363         if (!ret) {
14364                 printf("List of used protocols:\n");
14365                 for (i = 0; i < proto_num; i++)
14366                         printf("  %2u: %s\n", proto[i].proto_id,
14367                                proto[i].name);
14368                 printf("\n");
14369         }
14370         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14371                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14372                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14373         if (ret || !pctype_num)
14374                 goto no_print_pctypes;
14375
14376         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14377         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14378         if (!pctype)
14379                 goto no_print_pctypes;
14380
14381         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14382                                         buff_size,
14383                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14384         if (ret) {
14385                 free(pctype);
14386                 goto no_print_pctypes;
14387         }
14388
14389         printf("List of defined packet classification types:\n");
14390         for (i = 0; i < pctype_num; i++) {
14391                 printf("  %2u:", pctype[i].ptype_id);
14392                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14393                         proto_id = pctype[i].protocols[j];
14394                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14395                                 for (n = 0; n < proto_num; n++) {
14396                                         if (proto[n].proto_id == proto_id) {
14397                                                 printf(" %s", proto[n].name);
14398                                                 break;
14399                                         }
14400                                 }
14401                         }
14402                 }
14403                 printf("\n");
14404         }
14405         printf("\n");
14406         free(pctype);
14407
14408 no_print_pctypes:
14409
14410         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14411                                         sizeof(ptype_num),
14412                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14413         if (ret || !ptype_num)
14414                 goto no_print_return;
14415
14416         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14417         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14418         if (!ptype)
14419                 goto no_print_return;
14420
14421         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14422                                         buff_size,
14423                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14424         if (ret) {
14425                 free(ptype);
14426                 goto no_print_return;
14427         }
14428         printf("List of defined packet types:\n");
14429         for (i = 0; i < ptype_num; i++) {
14430                 printf("  %2u:", ptype[i].ptype_id);
14431                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14432                         proto_id = ptype[i].protocols[j];
14433                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14434                                 for (n = 0; n < proto_num; n++) {
14435                                         if (proto[n].proto_id == proto_id) {
14436                                                 printf(" %s", proto[n].name);
14437                                                 break;
14438                                         }
14439                                 }
14440                         }
14441                 }
14442                 printf("\n");
14443         }
14444         free(ptype);
14445         printf("\n");
14446
14447         free(proto);
14448         ret = 0;
14449 no_print_return:
14450 #endif
14451         if (ret == -ENOTSUP)
14452                 printf("Function not supported in PMD driver\n");
14453         close_ddp_package_file(pkg);
14454 }
14455
14456 cmdline_parse_inst_t cmd_ddp_get_info = {
14457         .f = cmd_ddp_info_parsed,
14458         .data = NULL,
14459         .help_str = "ddp get info <profile_path>",
14460         .tokens = {
14461                 (void *)&cmd_ddp_info_ddp,
14462                 (void *)&cmd_ddp_info_get,
14463                 (void *)&cmd_ddp_info_info,
14464                 (void *)&cmd_ddp_info_filepath,
14465                 NULL,
14466         },
14467 };
14468
14469 /* Get dynamic device personalization profile info list*/
14470 #define PROFILE_INFO_SIZE 48
14471 #define MAX_PROFILE_NUM 16
14472
14473 struct cmd_ddp_get_list_result {
14474         cmdline_fixed_string_t ddp;
14475         cmdline_fixed_string_t get;
14476         cmdline_fixed_string_t list;
14477         portid_t port_id;
14478 };
14479
14480 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14481         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14482 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14483         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14484 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14485         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14486 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14487         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14488
14489 static void
14490 cmd_ddp_get_list_parsed(
14491         void *parsed_result,
14492         __attribute__((unused)) struct cmdline *cl,
14493         __attribute__((unused)) void *data)
14494 {
14495         struct cmd_ddp_get_list_result *res = parsed_result;
14496 #ifdef RTE_LIBRTE_I40E_PMD
14497         struct rte_pmd_i40e_profile_list *p_list;
14498         struct rte_pmd_i40e_profile_info *p_info;
14499         uint32_t p_num;
14500         uint32_t size;
14501         uint32_t i;
14502 #endif
14503         int ret = -ENOTSUP;
14504
14505         if (res->port_id > nb_ports) {
14506                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14507                 return;
14508         }
14509
14510 #ifdef RTE_LIBRTE_I40E_PMD
14511         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14512         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14513         if (!p_list)
14514                 printf("%s: Failed to malloc buffer\n", __func__);
14515
14516         if (ret == -ENOTSUP)
14517                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14518                                                 (uint8_t *)p_list, size);
14519
14520         if (!ret) {
14521                 p_num = p_list->p_count;
14522                 printf("Profile number is: %d\n\n", p_num);
14523
14524                 for (i = 0; i < p_num; i++) {
14525                         p_info = &p_list->p_info[i];
14526                         printf("Profile %d:\n", i);
14527                         printf("Track id:     0x%x\n", p_info->track_id);
14528                         printf("Version:      %d.%d.%d.%d\n",
14529                                p_info->version.major,
14530                                p_info->version.minor,
14531                                p_info->version.update,
14532                                p_info->version.draft);
14533                         printf("Profile name: %s\n\n", p_info->name);
14534                 }
14535         }
14536
14537         free(p_list);
14538 #endif
14539
14540         if (ret < 0)
14541                 printf("Failed to get ddp list\n");
14542 }
14543
14544 cmdline_parse_inst_t cmd_ddp_get_list = {
14545         .f = cmd_ddp_get_list_parsed,
14546         .data = NULL,
14547         .help_str = "ddp get list <port_id>",
14548         .tokens = {
14549                 (void *)&cmd_ddp_get_list_ddp,
14550                 (void *)&cmd_ddp_get_list_get,
14551                 (void *)&cmd_ddp_get_list_list,
14552                 (void *)&cmd_ddp_get_list_port_id,
14553                 NULL,
14554         },
14555 };
14556
14557 /* show vf stats */
14558
14559 /* Common result structure for show vf stats */
14560 struct cmd_show_vf_stats_result {
14561         cmdline_fixed_string_t show;
14562         cmdline_fixed_string_t vf;
14563         cmdline_fixed_string_t stats;
14564         portid_t port_id;
14565         uint16_t vf_id;
14566 };
14567
14568 /* Common CLI fields show vf stats*/
14569 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14570         TOKEN_STRING_INITIALIZER
14571                 (struct cmd_show_vf_stats_result,
14572                  show, "show");
14573 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14574         TOKEN_STRING_INITIALIZER
14575                 (struct cmd_show_vf_stats_result,
14576                  vf, "vf");
14577 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14578         TOKEN_STRING_INITIALIZER
14579                 (struct cmd_show_vf_stats_result,
14580                  stats, "stats");
14581 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14582         TOKEN_NUM_INITIALIZER
14583                 (struct cmd_show_vf_stats_result,
14584                  port_id, UINT16);
14585 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14586         TOKEN_NUM_INITIALIZER
14587                 (struct cmd_show_vf_stats_result,
14588                  vf_id, UINT16);
14589
14590 static void
14591 cmd_show_vf_stats_parsed(
14592         void *parsed_result,
14593         __attribute__((unused)) struct cmdline *cl,
14594         __attribute__((unused)) void *data)
14595 {
14596         struct cmd_show_vf_stats_result *res = parsed_result;
14597         struct rte_eth_stats stats;
14598         int ret = -ENOTSUP;
14599         static const char *nic_stats_border = "########################";
14600
14601         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14602                 return;
14603
14604         memset(&stats, 0, sizeof(stats));
14605
14606 #ifdef RTE_LIBRTE_I40E_PMD
14607         if (ret == -ENOTSUP)
14608                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14609                                                 res->vf_id,
14610                                                 &stats);
14611 #endif
14612 #ifdef RTE_LIBRTE_BNXT_PMD
14613         if (ret == -ENOTSUP)
14614                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14615                                                 res->vf_id,
14616                                                 &stats);
14617 #endif
14618
14619         switch (ret) {
14620         case 0:
14621                 break;
14622         case -EINVAL:
14623                 printf("invalid vf_id %d\n", res->vf_id);
14624                 break;
14625         case -ENODEV:
14626                 printf("invalid port_id %d\n", res->port_id);
14627                 break;
14628         case -ENOTSUP:
14629                 printf("function not implemented\n");
14630                 break;
14631         default:
14632                 printf("programming error: (%s)\n", strerror(-ret));
14633         }
14634
14635         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14636                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14637
14638         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14639                "%-"PRIu64"\n",
14640                stats.ipackets, stats.imissed, stats.ibytes);
14641         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14642         printf("  RX-nombuf:  %-10"PRIu64"\n",
14643                stats.rx_nombuf);
14644         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14645                "%-"PRIu64"\n",
14646                stats.opackets, stats.oerrors, stats.obytes);
14647
14648         printf("  %s############################%s\n",
14649                                nic_stats_border, nic_stats_border);
14650 }
14651
14652 cmdline_parse_inst_t cmd_show_vf_stats = {
14653         .f = cmd_show_vf_stats_parsed,
14654         .data = NULL,
14655         .help_str = "show vf stats <port_id> <vf_id>",
14656         .tokens = {
14657                 (void *)&cmd_show_vf_stats_show,
14658                 (void *)&cmd_show_vf_stats_vf,
14659                 (void *)&cmd_show_vf_stats_stats,
14660                 (void *)&cmd_show_vf_stats_port_id,
14661                 (void *)&cmd_show_vf_stats_vf_id,
14662                 NULL,
14663         },
14664 };
14665
14666 /* clear vf stats */
14667
14668 /* Common result structure for clear vf stats */
14669 struct cmd_clear_vf_stats_result {
14670         cmdline_fixed_string_t clear;
14671         cmdline_fixed_string_t vf;
14672         cmdline_fixed_string_t stats;
14673         portid_t port_id;
14674         uint16_t vf_id;
14675 };
14676
14677 /* Common CLI fields clear vf stats*/
14678 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14679         TOKEN_STRING_INITIALIZER
14680                 (struct cmd_clear_vf_stats_result,
14681                  clear, "clear");
14682 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14683         TOKEN_STRING_INITIALIZER
14684                 (struct cmd_clear_vf_stats_result,
14685                  vf, "vf");
14686 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14687         TOKEN_STRING_INITIALIZER
14688                 (struct cmd_clear_vf_stats_result,
14689                  stats, "stats");
14690 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14691         TOKEN_NUM_INITIALIZER
14692                 (struct cmd_clear_vf_stats_result,
14693                  port_id, UINT16);
14694 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14695         TOKEN_NUM_INITIALIZER
14696                 (struct cmd_clear_vf_stats_result,
14697                  vf_id, UINT16);
14698
14699 static void
14700 cmd_clear_vf_stats_parsed(
14701         void *parsed_result,
14702         __attribute__((unused)) struct cmdline *cl,
14703         __attribute__((unused)) void *data)
14704 {
14705         struct cmd_clear_vf_stats_result *res = parsed_result;
14706         int ret = -ENOTSUP;
14707
14708         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14709                 return;
14710
14711 #ifdef RTE_LIBRTE_I40E_PMD
14712         if (ret == -ENOTSUP)
14713                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14714                                                   res->vf_id);
14715 #endif
14716 #ifdef RTE_LIBRTE_BNXT_PMD
14717         if (ret == -ENOTSUP)
14718                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14719                                                   res->vf_id);
14720 #endif
14721
14722         switch (ret) {
14723         case 0:
14724                 break;
14725         case -EINVAL:
14726                 printf("invalid vf_id %d\n", res->vf_id);
14727                 break;
14728         case -ENODEV:
14729                 printf("invalid port_id %d\n", res->port_id);
14730                 break;
14731         case -ENOTSUP:
14732                 printf("function not implemented\n");
14733                 break;
14734         default:
14735                 printf("programming error: (%s)\n", strerror(-ret));
14736         }
14737 }
14738
14739 cmdline_parse_inst_t cmd_clear_vf_stats = {
14740         .f = cmd_clear_vf_stats_parsed,
14741         .data = NULL,
14742         .help_str = "clear vf stats <port_id> <vf_id>",
14743         .tokens = {
14744                 (void *)&cmd_clear_vf_stats_clear,
14745                 (void *)&cmd_clear_vf_stats_vf,
14746                 (void *)&cmd_clear_vf_stats_stats,
14747                 (void *)&cmd_clear_vf_stats_port_id,
14748                 (void *)&cmd_clear_vf_stats_vf_id,
14749                 NULL,
14750         },
14751 };
14752
14753 /* port config pctype mapping reset */
14754
14755 /* Common result structure for port config pctype mapping reset */
14756 struct cmd_pctype_mapping_reset_result {
14757         cmdline_fixed_string_t port;
14758         cmdline_fixed_string_t config;
14759         portid_t port_id;
14760         cmdline_fixed_string_t pctype;
14761         cmdline_fixed_string_t mapping;
14762         cmdline_fixed_string_t reset;
14763 };
14764
14765 /* Common CLI fields for port config pctype mapping reset*/
14766 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14767         TOKEN_STRING_INITIALIZER
14768                 (struct cmd_pctype_mapping_reset_result,
14769                  port, "port");
14770 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14771         TOKEN_STRING_INITIALIZER
14772                 (struct cmd_pctype_mapping_reset_result,
14773                  config, "config");
14774 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14775         TOKEN_NUM_INITIALIZER
14776                 (struct cmd_pctype_mapping_reset_result,
14777                  port_id, UINT16);
14778 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14779         TOKEN_STRING_INITIALIZER
14780                 (struct cmd_pctype_mapping_reset_result,
14781                  pctype, "pctype");
14782 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14783         TOKEN_STRING_INITIALIZER
14784                 (struct cmd_pctype_mapping_reset_result,
14785                  mapping, "mapping");
14786 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14787         TOKEN_STRING_INITIALIZER
14788                 (struct cmd_pctype_mapping_reset_result,
14789                  reset, "reset");
14790
14791 static void
14792 cmd_pctype_mapping_reset_parsed(
14793         void *parsed_result,
14794         __attribute__((unused)) struct cmdline *cl,
14795         __attribute__((unused)) void *data)
14796 {
14797         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14798         int ret = -ENOTSUP;
14799
14800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14801                 return;
14802
14803 #ifdef RTE_LIBRTE_I40E_PMD
14804         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14805 #endif
14806
14807         switch (ret) {
14808         case 0:
14809                 break;
14810         case -ENODEV:
14811                 printf("invalid port_id %d\n", res->port_id);
14812                 break;
14813         case -ENOTSUP:
14814                 printf("function not implemented\n");
14815                 break;
14816         default:
14817                 printf("programming error: (%s)\n", strerror(-ret));
14818         }
14819 }
14820
14821 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14822         .f = cmd_pctype_mapping_reset_parsed,
14823         .data = NULL,
14824         .help_str = "port config <port_id> pctype mapping reset",
14825         .tokens = {
14826                 (void *)&cmd_pctype_mapping_reset_port,
14827                 (void *)&cmd_pctype_mapping_reset_config,
14828                 (void *)&cmd_pctype_mapping_reset_port_id,
14829                 (void *)&cmd_pctype_mapping_reset_pctype,
14830                 (void *)&cmd_pctype_mapping_reset_mapping,
14831                 (void *)&cmd_pctype_mapping_reset_reset,
14832                 NULL,
14833         },
14834 };
14835
14836 /* show port pctype mapping */
14837
14838 /* Common result structure for show port pctype mapping */
14839 struct cmd_pctype_mapping_get_result {
14840         cmdline_fixed_string_t show;
14841         cmdline_fixed_string_t port;
14842         portid_t port_id;
14843         cmdline_fixed_string_t pctype;
14844         cmdline_fixed_string_t mapping;
14845 };
14846
14847 /* Common CLI fields for pctype mapping get */
14848 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14849         TOKEN_STRING_INITIALIZER
14850                 (struct cmd_pctype_mapping_get_result,
14851                  show, "show");
14852 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14853         TOKEN_STRING_INITIALIZER
14854                 (struct cmd_pctype_mapping_get_result,
14855                  port, "port");
14856 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14857         TOKEN_NUM_INITIALIZER
14858                 (struct cmd_pctype_mapping_get_result,
14859                  port_id, UINT16);
14860 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14861         TOKEN_STRING_INITIALIZER
14862                 (struct cmd_pctype_mapping_get_result,
14863                  pctype, "pctype");
14864 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14865         TOKEN_STRING_INITIALIZER
14866                 (struct cmd_pctype_mapping_get_result,
14867                  mapping, "mapping");
14868
14869 static void
14870 cmd_pctype_mapping_get_parsed(
14871         void *parsed_result,
14872         __attribute__((unused)) struct cmdline *cl,
14873         __attribute__((unused)) void *data)
14874 {
14875         struct cmd_pctype_mapping_get_result *res = parsed_result;
14876         int ret = -ENOTSUP;
14877 #ifdef RTE_LIBRTE_I40E_PMD
14878         struct rte_pmd_i40e_flow_type_mapping
14879                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14880         int i, j, first_pctype;
14881 #endif
14882
14883         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14884                 return;
14885
14886 #ifdef RTE_LIBRTE_I40E_PMD
14887         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14888 #endif
14889
14890         switch (ret) {
14891         case 0:
14892                 break;
14893         case -ENODEV:
14894                 printf("invalid port_id %d\n", res->port_id);
14895                 return;
14896         case -ENOTSUP:
14897                 printf("function not implemented\n");
14898                 return;
14899         default:
14900                 printf("programming error: (%s)\n", strerror(-ret));
14901                 return;
14902         }
14903
14904 #ifdef RTE_LIBRTE_I40E_PMD
14905         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14906                 if (mapping[i].pctype != 0ULL) {
14907                         first_pctype = 1;
14908
14909                         printf("pctype: ");
14910                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14911                                 if (mapping[i].pctype & (1ULL << j)) {
14912                                         printf(first_pctype ?
14913                                                "%02d" : ",%02d", j);
14914                                         first_pctype = 0;
14915                                 }
14916                         }
14917                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14918                 }
14919         }
14920 #endif
14921 }
14922
14923 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14924         .f = cmd_pctype_mapping_get_parsed,
14925         .data = NULL,
14926         .help_str = "show port <port_id> pctype mapping",
14927         .tokens = {
14928                 (void *)&cmd_pctype_mapping_get_show,
14929                 (void *)&cmd_pctype_mapping_get_port,
14930                 (void *)&cmd_pctype_mapping_get_port_id,
14931                 (void *)&cmd_pctype_mapping_get_pctype,
14932                 (void *)&cmd_pctype_mapping_get_mapping,
14933                 NULL,
14934         },
14935 };
14936
14937 /* port config pctype mapping update */
14938
14939 /* Common result structure for port config pctype mapping update */
14940 struct cmd_pctype_mapping_update_result {
14941         cmdline_fixed_string_t port;
14942         cmdline_fixed_string_t config;
14943         portid_t port_id;
14944         cmdline_fixed_string_t pctype;
14945         cmdline_fixed_string_t mapping;
14946         cmdline_fixed_string_t update;
14947         cmdline_fixed_string_t pctype_list;
14948         uint16_t flow_type;
14949 };
14950
14951 /* Common CLI fields for pctype mapping update*/
14952 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14953         TOKEN_STRING_INITIALIZER
14954                 (struct cmd_pctype_mapping_update_result,
14955                  port, "port");
14956 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14957         TOKEN_STRING_INITIALIZER
14958                 (struct cmd_pctype_mapping_update_result,
14959                  config, "config");
14960 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14961         TOKEN_NUM_INITIALIZER
14962                 (struct cmd_pctype_mapping_update_result,
14963                  port_id, UINT16);
14964 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14965         TOKEN_STRING_INITIALIZER
14966                 (struct cmd_pctype_mapping_update_result,
14967                  pctype, "pctype");
14968 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14969         TOKEN_STRING_INITIALIZER
14970                 (struct cmd_pctype_mapping_update_result,
14971                  mapping, "mapping");
14972 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14973         TOKEN_STRING_INITIALIZER
14974                 (struct cmd_pctype_mapping_update_result,
14975                  update, "update");
14976 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14977         TOKEN_STRING_INITIALIZER
14978                 (struct cmd_pctype_mapping_update_result,
14979                  pctype_list, NULL);
14980 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14981         TOKEN_NUM_INITIALIZER
14982                 (struct cmd_pctype_mapping_update_result,
14983                  flow_type, UINT16);
14984
14985 static void
14986 cmd_pctype_mapping_update_parsed(
14987         void *parsed_result,
14988         __attribute__((unused)) struct cmdline *cl,
14989         __attribute__((unused)) void *data)
14990 {
14991         struct cmd_pctype_mapping_update_result *res = parsed_result;
14992         int ret = -ENOTSUP;
14993 #ifdef RTE_LIBRTE_I40E_PMD
14994         struct rte_pmd_i40e_flow_type_mapping mapping;
14995         unsigned int i;
14996         unsigned int nb_item;
14997         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14998 #endif
14999
15000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15001                 return;
15002
15003 #ifdef RTE_LIBRTE_I40E_PMD
15004         nb_item = parse_item_list(res->pctype_list, "pctypes",
15005                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15006         mapping.flow_type = res->flow_type;
15007         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15008                 mapping.pctype |= (1ULL << pctype_list[i]);
15009         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15010                                                 &mapping,
15011                                                 1,
15012                                                 0);
15013 #endif
15014
15015         switch (ret) {
15016         case 0:
15017                 break;
15018         case -EINVAL:
15019                 printf("invalid pctype or flow type\n");
15020                 break;
15021         case -ENODEV:
15022                 printf("invalid port_id %d\n", res->port_id);
15023                 break;
15024         case -ENOTSUP:
15025                 printf("function not implemented\n");
15026                 break;
15027         default:
15028                 printf("programming error: (%s)\n", strerror(-ret));
15029         }
15030 }
15031
15032 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15033         .f = cmd_pctype_mapping_update_parsed,
15034         .data = NULL,
15035         .help_str = "port config <port_id> pctype mapping update"
15036         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15037         .tokens = {
15038                 (void *)&cmd_pctype_mapping_update_port,
15039                 (void *)&cmd_pctype_mapping_update_config,
15040                 (void *)&cmd_pctype_mapping_update_port_id,
15041                 (void *)&cmd_pctype_mapping_update_pctype,
15042                 (void *)&cmd_pctype_mapping_update_mapping,
15043                 (void *)&cmd_pctype_mapping_update_update,
15044                 (void *)&cmd_pctype_mapping_update_pc_type,
15045                 (void *)&cmd_pctype_mapping_update_flow_type,
15046                 NULL,
15047         },
15048 };
15049
15050 /* ptype mapping get */
15051
15052 /* Common result structure for ptype mapping get */
15053 struct cmd_ptype_mapping_get_result {
15054         cmdline_fixed_string_t ptype;
15055         cmdline_fixed_string_t mapping;
15056         cmdline_fixed_string_t get;
15057         portid_t port_id;
15058         uint8_t valid_only;
15059 };
15060
15061 /* Common CLI fields for ptype mapping get */
15062 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15063         TOKEN_STRING_INITIALIZER
15064                 (struct cmd_ptype_mapping_get_result,
15065                  ptype, "ptype");
15066 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15067         TOKEN_STRING_INITIALIZER
15068                 (struct cmd_ptype_mapping_get_result,
15069                  mapping, "mapping");
15070 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15071         TOKEN_STRING_INITIALIZER
15072                 (struct cmd_ptype_mapping_get_result,
15073                  get, "get");
15074 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15075         TOKEN_NUM_INITIALIZER
15076                 (struct cmd_ptype_mapping_get_result,
15077                  port_id, UINT16);
15078 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15079         TOKEN_NUM_INITIALIZER
15080                 (struct cmd_ptype_mapping_get_result,
15081                  valid_only, UINT8);
15082
15083 static void
15084 cmd_ptype_mapping_get_parsed(
15085         void *parsed_result,
15086         __attribute__((unused)) struct cmdline *cl,
15087         __attribute__((unused)) void *data)
15088 {
15089         struct cmd_ptype_mapping_get_result *res = parsed_result;
15090         int ret = -ENOTSUP;
15091 #ifdef RTE_LIBRTE_I40E_PMD
15092         int max_ptype_num = 256;
15093         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15094         uint16_t count;
15095         int i;
15096 #endif
15097
15098         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15099                 return;
15100
15101 #ifdef RTE_LIBRTE_I40E_PMD
15102         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15103                                         mapping,
15104                                         max_ptype_num,
15105                                         &count,
15106                                         res->valid_only);
15107 #endif
15108
15109         switch (ret) {
15110         case 0:
15111                 break;
15112         case -ENODEV:
15113                 printf("invalid port_id %d\n", res->port_id);
15114                 break;
15115         case -ENOTSUP:
15116                 printf("function not implemented\n");
15117                 break;
15118         default:
15119                 printf("programming error: (%s)\n", strerror(-ret));
15120         }
15121
15122 #ifdef RTE_LIBRTE_I40E_PMD
15123         if (!ret) {
15124                 for (i = 0; i < count; i++)
15125                         printf("%3d\t0x%08x\n",
15126                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15127         }
15128 #endif
15129 }
15130
15131 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15132         .f = cmd_ptype_mapping_get_parsed,
15133         .data = NULL,
15134         .help_str = "ptype mapping get <port_id> <valid_only>",
15135         .tokens = {
15136                 (void *)&cmd_ptype_mapping_get_ptype,
15137                 (void *)&cmd_ptype_mapping_get_mapping,
15138                 (void *)&cmd_ptype_mapping_get_get,
15139                 (void *)&cmd_ptype_mapping_get_port_id,
15140                 (void *)&cmd_ptype_mapping_get_valid_only,
15141                 NULL,
15142         },
15143 };
15144
15145 /* ptype mapping replace */
15146
15147 /* Common result structure for ptype mapping replace */
15148 struct cmd_ptype_mapping_replace_result {
15149         cmdline_fixed_string_t ptype;
15150         cmdline_fixed_string_t mapping;
15151         cmdline_fixed_string_t replace;
15152         portid_t port_id;
15153         uint32_t target;
15154         uint8_t mask;
15155         uint32_t pkt_type;
15156 };
15157
15158 /* Common CLI fields for ptype mapping replace */
15159 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15160         TOKEN_STRING_INITIALIZER
15161                 (struct cmd_ptype_mapping_replace_result,
15162                  ptype, "ptype");
15163 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15164         TOKEN_STRING_INITIALIZER
15165                 (struct cmd_ptype_mapping_replace_result,
15166                  mapping, "mapping");
15167 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15168         TOKEN_STRING_INITIALIZER
15169                 (struct cmd_ptype_mapping_replace_result,
15170                  replace, "replace");
15171 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15172         TOKEN_NUM_INITIALIZER
15173                 (struct cmd_ptype_mapping_replace_result,
15174                  port_id, UINT16);
15175 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15176         TOKEN_NUM_INITIALIZER
15177                 (struct cmd_ptype_mapping_replace_result,
15178                  target, UINT32);
15179 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15180         TOKEN_NUM_INITIALIZER
15181                 (struct cmd_ptype_mapping_replace_result,
15182                  mask, UINT8);
15183 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15184         TOKEN_NUM_INITIALIZER
15185                 (struct cmd_ptype_mapping_replace_result,
15186                  pkt_type, UINT32);
15187
15188 static void
15189 cmd_ptype_mapping_replace_parsed(
15190         void *parsed_result,
15191         __attribute__((unused)) struct cmdline *cl,
15192         __attribute__((unused)) void *data)
15193 {
15194         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15195         int ret = -ENOTSUP;
15196
15197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15198                 return;
15199
15200 #ifdef RTE_LIBRTE_I40E_PMD
15201         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15202                                         res->target,
15203                                         res->mask,
15204                                         res->pkt_type);
15205 #endif
15206
15207         switch (ret) {
15208         case 0:
15209                 break;
15210         case -EINVAL:
15211                 printf("invalid ptype 0x%8x or 0x%8x\n",
15212                                 res->target, res->pkt_type);
15213                 break;
15214         case -ENODEV:
15215                 printf("invalid port_id %d\n", res->port_id);
15216                 break;
15217         case -ENOTSUP:
15218                 printf("function not implemented\n");
15219                 break;
15220         default:
15221                 printf("programming error: (%s)\n", strerror(-ret));
15222         }
15223 }
15224
15225 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15226         .f = cmd_ptype_mapping_replace_parsed,
15227         .data = NULL,
15228         .help_str =
15229                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15230         .tokens = {
15231                 (void *)&cmd_ptype_mapping_replace_ptype,
15232                 (void *)&cmd_ptype_mapping_replace_mapping,
15233                 (void *)&cmd_ptype_mapping_replace_replace,
15234                 (void *)&cmd_ptype_mapping_replace_port_id,
15235                 (void *)&cmd_ptype_mapping_replace_target,
15236                 (void *)&cmd_ptype_mapping_replace_mask,
15237                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15238                 NULL,
15239         },
15240 };
15241
15242 /* ptype mapping reset */
15243
15244 /* Common result structure for ptype mapping reset */
15245 struct cmd_ptype_mapping_reset_result {
15246         cmdline_fixed_string_t ptype;
15247         cmdline_fixed_string_t mapping;
15248         cmdline_fixed_string_t reset;
15249         portid_t port_id;
15250 };
15251
15252 /* Common CLI fields for ptype mapping reset*/
15253 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15254         TOKEN_STRING_INITIALIZER
15255                 (struct cmd_ptype_mapping_reset_result,
15256                  ptype, "ptype");
15257 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15258         TOKEN_STRING_INITIALIZER
15259                 (struct cmd_ptype_mapping_reset_result,
15260                  mapping, "mapping");
15261 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15262         TOKEN_STRING_INITIALIZER
15263                 (struct cmd_ptype_mapping_reset_result,
15264                  reset, "reset");
15265 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15266         TOKEN_NUM_INITIALIZER
15267                 (struct cmd_ptype_mapping_reset_result,
15268                  port_id, UINT16);
15269
15270 static void
15271 cmd_ptype_mapping_reset_parsed(
15272         void *parsed_result,
15273         __attribute__((unused)) struct cmdline *cl,
15274         __attribute__((unused)) void *data)
15275 {
15276         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15277         int ret = -ENOTSUP;
15278
15279         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15280                 return;
15281
15282 #ifdef RTE_LIBRTE_I40E_PMD
15283         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15284 #endif
15285
15286         switch (ret) {
15287         case 0:
15288                 break;
15289         case -ENODEV:
15290                 printf("invalid port_id %d\n", res->port_id);
15291                 break;
15292         case -ENOTSUP:
15293                 printf("function not implemented\n");
15294                 break;
15295         default:
15296                 printf("programming error: (%s)\n", strerror(-ret));
15297         }
15298 }
15299
15300 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15301         .f = cmd_ptype_mapping_reset_parsed,
15302         .data = NULL,
15303         .help_str = "ptype mapping reset <port_id>",
15304         .tokens = {
15305                 (void *)&cmd_ptype_mapping_reset_ptype,
15306                 (void *)&cmd_ptype_mapping_reset_mapping,
15307                 (void *)&cmd_ptype_mapping_reset_reset,
15308                 (void *)&cmd_ptype_mapping_reset_port_id,
15309                 NULL,
15310         },
15311 };
15312
15313 /* ptype mapping update */
15314
15315 /* Common result structure for ptype mapping update */
15316 struct cmd_ptype_mapping_update_result {
15317         cmdline_fixed_string_t ptype;
15318         cmdline_fixed_string_t mapping;
15319         cmdline_fixed_string_t reset;
15320         portid_t port_id;
15321         uint8_t hw_ptype;
15322         uint32_t sw_ptype;
15323 };
15324
15325 /* Common CLI fields for ptype mapping update*/
15326 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15327         TOKEN_STRING_INITIALIZER
15328                 (struct cmd_ptype_mapping_update_result,
15329                  ptype, "ptype");
15330 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15331         TOKEN_STRING_INITIALIZER
15332                 (struct cmd_ptype_mapping_update_result,
15333                  mapping, "mapping");
15334 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15335         TOKEN_STRING_INITIALIZER
15336                 (struct cmd_ptype_mapping_update_result,
15337                  reset, "update");
15338 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15339         TOKEN_NUM_INITIALIZER
15340                 (struct cmd_ptype_mapping_update_result,
15341                  port_id, UINT16);
15342 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15343         TOKEN_NUM_INITIALIZER
15344                 (struct cmd_ptype_mapping_update_result,
15345                  hw_ptype, UINT8);
15346 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15347         TOKEN_NUM_INITIALIZER
15348                 (struct cmd_ptype_mapping_update_result,
15349                  sw_ptype, UINT32);
15350
15351 static void
15352 cmd_ptype_mapping_update_parsed(
15353         void *parsed_result,
15354         __attribute__((unused)) struct cmdline *cl,
15355         __attribute__((unused)) void *data)
15356 {
15357         struct cmd_ptype_mapping_update_result *res = parsed_result;
15358         int ret = -ENOTSUP;
15359 #ifdef RTE_LIBRTE_I40E_PMD
15360         struct rte_pmd_i40e_ptype_mapping mapping;
15361 #endif
15362         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15363                 return;
15364
15365 #ifdef RTE_LIBRTE_I40E_PMD
15366         mapping.hw_ptype = res->hw_ptype;
15367         mapping.sw_ptype = res->sw_ptype;
15368         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15369                                                 &mapping,
15370                                                 1,
15371                                                 0);
15372 #endif
15373
15374         switch (ret) {
15375         case 0:
15376                 break;
15377         case -EINVAL:
15378                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15379                 break;
15380         case -ENODEV:
15381                 printf("invalid port_id %d\n", res->port_id);
15382                 break;
15383         case -ENOTSUP:
15384                 printf("function not implemented\n");
15385                 break;
15386         default:
15387                 printf("programming error: (%s)\n", strerror(-ret));
15388         }
15389 }
15390
15391 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15392         .f = cmd_ptype_mapping_update_parsed,
15393         .data = NULL,
15394         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15395         .tokens = {
15396                 (void *)&cmd_ptype_mapping_update_ptype,
15397                 (void *)&cmd_ptype_mapping_update_mapping,
15398                 (void *)&cmd_ptype_mapping_update_update,
15399                 (void *)&cmd_ptype_mapping_update_port_id,
15400                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15401                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15402                 NULL,
15403         },
15404 };
15405
15406 /* Common result structure for file commands */
15407 struct cmd_cmdfile_result {
15408         cmdline_fixed_string_t load;
15409         cmdline_fixed_string_t filename;
15410 };
15411
15412 /* Common CLI fields for file commands */
15413 cmdline_parse_token_string_t cmd_load_cmdfile =
15414         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15415 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15416         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15417
15418 static void
15419 cmd_load_from_file_parsed(
15420         void *parsed_result,
15421         __attribute__((unused)) struct cmdline *cl,
15422         __attribute__((unused)) void *data)
15423 {
15424         struct cmd_cmdfile_result *res = parsed_result;
15425
15426         cmdline_read_from_file(res->filename);
15427 }
15428
15429 cmdline_parse_inst_t cmd_load_from_file = {
15430         .f = cmd_load_from_file_parsed,
15431         .data = NULL,
15432         .help_str = "load <filename>",
15433         .tokens = {
15434                 (void *)&cmd_load_cmdfile,
15435                 (void *)&cmd_load_cmdfile_filename,
15436                 NULL,
15437         },
15438 };
15439
15440 /* ******************************************************************************** */
15441
15442 /* list of instructions */
15443 cmdline_parse_ctx_t main_ctx[] = {
15444         (cmdline_parse_inst_t *)&cmd_help_brief,
15445         (cmdline_parse_inst_t *)&cmd_help_long,
15446         (cmdline_parse_inst_t *)&cmd_quit,
15447         (cmdline_parse_inst_t *)&cmd_load_from_file,
15448         (cmdline_parse_inst_t *)&cmd_showport,
15449         (cmdline_parse_inst_t *)&cmd_showqueue,
15450         (cmdline_parse_inst_t *)&cmd_showportall,
15451         (cmdline_parse_inst_t *)&cmd_showcfg,
15452         (cmdline_parse_inst_t *)&cmd_start,
15453         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15454         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15455         (cmdline_parse_inst_t *)&cmd_set_link_up,
15456         (cmdline_parse_inst_t *)&cmd_set_link_down,
15457         (cmdline_parse_inst_t *)&cmd_reset,
15458         (cmdline_parse_inst_t *)&cmd_set_numbers,
15459         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15460         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15461         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15462         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15463         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15464         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15465         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15466         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15467         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15468         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15469         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15470         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15471         (cmdline_parse_inst_t *)&cmd_set_link_check,
15472         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15473         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15474         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15475         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15476 #ifdef RTE_LIBRTE_PMD_BOND
15477         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15478         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15479         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15480         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15481         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15482         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15483         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15484         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15485         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15486         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15487         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15488 #endif
15489         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15490         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15491         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15492         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15493         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15494         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15495         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15496         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15497         (cmdline_parse_inst_t *)&cmd_csum_set,
15498         (cmdline_parse_inst_t *)&cmd_csum_show,
15499         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15500         (cmdline_parse_inst_t *)&cmd_tso_set,
15501         (cmdline_parse_inst_t *)&cmd_tso_show,
15502         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15503         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15504         (cmdline_parse_inst_t *)&cmd_gro_enable,
15505         (cmdline_parse_inst_t *)&cmd_gro_flush,
15506         (cmdline_parse_inst_t *)&cmd_gro_show,
15507         (cmdline_parse_inst_t *)&cmd_gso_enable,
15508         (cmdline_parse_inst_t *)&cmd_gso_size,
15509         (cmdline_parse_inst_t *)&cmd_gso_show,
15510         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15511         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15512         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15513         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15514         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15515         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15516         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15517         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15518         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15519         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15520         (cmdline_parse_inst_t *)&cmd_config_dcb,
15521         (cmdline_parse_inst_t *)&cmd_read_reg,
15522         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15523         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15524         (cmdline_parse_inst_t *)&cmd_write_reg,
15525         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15526         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15527         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15528         (cmdline_parse_inst_t *)&cmd_stop,
15529         (cmdline_parse_inst_t *)&cmd_mac_addr,
15530         (cmdline_parse_inst_t *)&cmd_set_qmap,
15531         (cmdline_parse_inst_t *)&cmd_operate_port,
15532         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15533         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15534         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15535         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15536         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15537         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15538         (cmdline_parse_inst_t *)&cmd_config_mtu,
15539         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15540         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15541         (cmdline_parse_inst_t *)&cmd_config_rss,
15542         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15543         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15544         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15545         (cmdline_parse_inst_t *)&cmd_showport_reta,
15546         (cmdline_parse_inst_t *)&cmd_config_burst,
15547         (cmdline_parse_inst_t *)&cmd_config_thresh,
15548         (cmdline_parse_inst_t *)&cmd_config_threshold,
15549         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15550         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15551         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15552         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15553         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15554         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15555         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15556         (cmdline_parse_inst_t *)&cmd_global_config,
15557         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15558         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15559         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15560         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15561         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15562         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15563         (cmdline_parse_inst_t *)&cmd_dump,
15564         (cmdline_parse_inst_t *)&cmd_dump_one,
15565         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15566         (cmdline_parse_inst_t *)&cmd_syn_filter,
15567         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15568         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15569         (cmdline_parse_inst_t *)&cmd_flex_filter,
15570         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15571         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15572         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15573         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15574         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15575         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15576         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15577         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15578         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15579         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15580         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15581         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15582         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15583         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15584         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15585         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15586         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15587         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15588         (cmdline_parse_inst_t *)&cmd_flow,
15589         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15590         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15591         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15592         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15593         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15594         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15595         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15596         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15597         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15598         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15599         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15600         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15601         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15602         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15603         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15604         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15605         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15606         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15607         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15608         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15609         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15610         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15611         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15612         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15613         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15614         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15615         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15616         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15617         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15618         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15619         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15620         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15621         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15622         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15623         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15624         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15625         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15626         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15627         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15628         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15629         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15630         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15631         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15632         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15633         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15634 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15635         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15636 #endif
15637         (cmdline_parse_inst_t *)&cmd_ddp_add,
15638         (cmdline_parse_inst_t *)&cmd_ddp_del,
15639         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15640         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15641         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15642         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15643         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15644         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15645         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15646         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15647
15648         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15649         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15650         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15651         (cmdline_parse_inst_t *)&cmd_queue_region,
15652         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15653         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15654         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15655         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15656         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15657         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15658         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15659         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15660         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15661         NULL,
15662 };
15663
15664 /* read cmdline commands from file */
15665 void
15666 cmdline_read_from_file(const char *filename)
15667 {
15668         struct cmdline *cl;
15669
15670         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15671         if (cl == NULL) {
15672                 printf("Failed to create file based cmdline context: %s\n",
15673                        filename);
15674                 return;
15675         }
15676
15677         cmdline_interact(cl);
15678         cmdline_quit(cl);
15679
15680         cmdline_free(cl);
15681
15682         printf("Read CLI commands from %s\n", filename);
15683 }
15684
15685 /* prompt function, called from main on MASTER lcore */
15686 void
15687 prompt(void)
15688 {
15689         /* initialize non-constant commands */
15690         cmd_set_fwd_mode_init();
15691         cmd_set_fwd_retry_mode_init();
15692
15693         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15694         if (testpmd_cl == NULL)
15695                 return;
15696         cmdline_interact(testpmd_cl);
15697         cmdline_stdin_exit(testpmd_cl);
15698 }
15699
15700 void
15701 prompt_exit(void)
15702 {
15703         if (testpmd_cl != NULL)
15704                 cmdline_quit(testpmd_cl);
15705 }
15706
15707 static void
15708 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15709 {
15710         if (id == (portid_t)RTE_PORT_ALL) {
15711                 portid_t pid;
15712
15713                 RTE_ETH_FOREACH_DEV(pid) {
15714                         /* check if need_reconfig has been set to 1 */
15715                         if (ports[pid].need_reconfig == 0)
15716                                 ports[pid].need_reconfig = dev;
15717                         /* check if need_reconfig_queues has been set to 1 */
15718                         if (ports[pid].need_reconfig_queues == 0)
15719                                 ports[pid].need_reconfig_queues = queue;
15720                 }
15721         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15722                 /* check if need_reconfig has been set to 1 */
15723                 if (ports[id].need_reconfig == 0)
15724                         ports[id].need_reconfig = dev;
15725                 /* check if need_reconfig_queues has been set to 1 */
15726                 if (ports[id].need_reconfig_queues == 0)
15727                         ports[id].need_reconfig_queues = queue;
15728         }
15729 }