b3a56baab54623bbb5107cabb51870784e151982
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
530                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
531
532                         "set port (port_id) vf (vf_id) (mac_addr)"
533                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
534                         "   Add/Remove unicast or multicast MAC addr filter"
535                         " for a VF.\n\n"
536
537                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
538                         "|MPE) (on|off)\n"
539                         "    AUPE:accepts untagged VLAN;"
540                         "ROPE:accept unicast hash\n\n"
541                         "    BAM:accepts broadcast packets;"
542                         "MPE:accepts all multicast packets\n\n"
543                         "    Enable/Disable a VF receive mode of a port\n\n"
544
545                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
546                         "    Set rate limit for a queue of a port\n\n"
547
548                         "set port (port_id) vf (vf_id) rate (rate_num) "
549                         "queue_mask (queue_mask_value)\n"
550                         "    Set rate limit for queues in VF of a port\n\n"
551
552                         "set port (port_id) mirror-rule (rule_id)"
553                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
554                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
555                         "   Set pool or vlan type mirror rule on a port.\n"
556                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
557                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
558                         " to pool 0.\n\n"
559
560                         "set port (port_id) mirror-rule (rule_id)"
561                         " (uplink-mirror|downlink-mirror) dst-pool"
562                         " (pool_id) (on|off)\n"
563                         "   Set uplink or downlink type mirror rule on a port.\n"
564                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
565                         " 0 on' enable mirror income traffic to pool 0.\n\n"
566
567                         "reset port (port_id) mirror-rule (rule_id)\n"
568                         "   Reset a mirror rule.\n\n"
569
570                         "set flush_rx (on|off)\n"
571                         "   Flush (default) or don't flush RX streams before"
572                         " forwarding. Mainly used with PCAP drivers.\n\n"
573
574                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
575                         "   Set the bypass mode for the lowest port on bypass enabled"
576                         " NIC.\n\n"
577
578                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
579                         "mode (normal|bypass|isolate) (port_id)\n"
580                         "   Set the event required to initiate specified bypass mode for"
581                         " the lowest port on a bypass enabled NIC where:\n"
582                         "       timeout   = enable bypass after watchdog timeout.\n"
583                         "       os_on     = enable bypass when OS/board is powered on.\n"
584                         "       os_off    = enable bypass when OS/board is powered off.\n"
585                         "       power_on  = enable bypass when power supply is turned on.\n"
586                         "       power_off = enable bypass when power supply is turned off."
587                         "\n\n"
588
589                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
590                         "   Set the bypass watchdog timeout to 'n' seconds"
591                         " where 0 = instant.\n\n"
592
593                         "show bypass config (port_id)\n"
594                         "   Show the bypass configuration for a bypass enabled NIC"
595                         " using the lowest port on the NIC.\n\n"
596
597 #ifdef RTE_LIBRTE_PMD_BOND
598                         "create bonded device (mode) (socket)\n"
599                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
600
601                         "add bonding slave (slave_id) (port_id)\n"
602                         "       Add a slave device to a bonded device.\n\n"
603
604                         "remove bonding slave (slave_id) (port_id)\n"
605                         "       Remove a slave device from a bonded device.\n\n"
606
607                         "set bonding mode (value) (port_id)\n"
608                         "       Set the bonding mode on a bonded device.\n\n"
609
610                         "set bonding primary (slave_id) (port_id)\n"
611                         "       Set the primary slave for a bonded device.\n\n"
612
613                         "show bonding config (port_id)\n"
614                         "       Show the bonding config for port_id.\n\n"
615
616                         "set bonding mac_addr (port_id) (address)\n"
617                         "       Set the MAC address of a bonded device.\n\n"
618
619                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
620                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
621
622                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
623                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
624
625                         "set bonding mon_period (port_id) (value)\n"
626                         "       Set the bonding link status monitoring polling period in ms.\n\n"
627
628                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
629                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
630
631 #endif
632                         "set link-up port (port_id)\n"
633                         "       Set link up for a port.\n\n"
634
635                         "set link-down port (port_id)\n"
636                         "       Set link down for a port.\n\n"
637
638                         "E-tag set insertion on port-tag-id (value)"
639                         " port (port_id) vf (vf_id)\n"
640                         "    Enable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
643                         "    Disable E-tag insertion for a VF on a port\n\n"
644
645                         "E-tag set stripping (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag stripping on a port\n\n"
647
648                         "E-tag set forwarding (on|off) port (port_id)\n"
649                         "    Enable/disable E-tag based forwarding"
650                         " on a port\n\n"
651
652                         "E-tag set filter add e-tag-id (value) dst-pool"
653                         " (pool_id) port (port_id)\n"
654                         "    Add an E-tag forwarding filter on a port\n\n"
655
656                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
657                         "    Delete an E-tag forwarding filter on a port\n\n"
658
659 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
660                         "set port tm hierarchy default (port_id)\n"
661                         "       Set default traffic Management hierarchy on a port\n\n"
662
663 #endif
664                         "ddp add (port_id) (profile_path[,output_path])\n"
665                         "    Load a profile package on a port\n\n"
666
667                         "ddp del (port_id) (profile_path)\n"
668                         "    Delete a profile package from a port\n\n"
669
670                         "ptype mapping get (port_id) (valid_only)\n"
671                         "    Get ptype mapping on a port\n\n"
672
673                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
674                         "    Replace target with the pkt_type in ptype mapping\n\n"
675
676                         "ptype mapping reset (port_id)\n"
677                         "    Reset ptype mapping on a port\n\n"
678
679                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
680                         "    Update a ptype mapping item on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "queue_start_index (value) queue_num (value)\n"
684                         "    Set a queue region on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "flowtype (value)\n"
688                         "    Set a flowtype region index on a port\n\n"
689
690                         "set port (port_id) queue-region UP (value) region_id (value)\n"
691                         "    Set the mapping of User Priority to "
692                         "queue region on a port\n\n"
693
694                         "set port (port_id) queue-region flush (on|off)\n"
695                         "    flush all queue region related configuration\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "    meter create\n\n"
711
712                         "del port meter (port_id) (mtr_id)\n"
713                         "    meter delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter policer action (port_id) (mtr_id) (color) (action)\n"
719                         "    meter update policer action\n\n"
720
721                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
722                         "    meter update stats\n\n"
723
724                         "show port (port_id) queue-region\n"
725                         "    show all queue region related configuration info\n\n"
726
727                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
728                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
729                         "       Add port tm node private shaper profile.\n\n"
730
731                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
732                         "       Delete port tm node private shaper profile.\n\n"
733
734                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
735                         " (shaper_profile_id)\n"
736                         "       Add/update port tm node shared shaper.\n\n"
737
738                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
739                         "       Delete port tm node shared shaper.\n\n"
740
741                         "set port tm node shaper profile (port_id) (node_id)"
742                         " (shaper_profile_id)\n"
743                         "       Set port tm node shaper profile.\n\n"
744
745                         "add port tm node wred profile (port_id) (wred_profile_id)"
746                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
747                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
748                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
749                         "       Add port tm node wred profile.\n\n"
750
751                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
752                         "       Delete port tm node wred profile.\n\n"
753
754                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
755                         " (priority) (weight) (level_id) (shaper_profile_id)"
756                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
757                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
758                         "       Add port tm nonleaf node.\n\n"
759
760                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
761                         " (priority) (weight) (level_id) (shaper_profile_id)"
762                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
763                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
764                         "       Add port tm leaf node.\n\n"
765
766                         "del port tm node (port_id) (node_id)\n"
767                         "       Delete port tm node.\n\n"
768
769                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
770                         " (priority) (weight)\n"
771                         "       Set port tm node parent.\n\n"
772
773                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
774                         "       Commit tm hierarchy.\n\n"
775
776                         , list_pkt_forwarding_modes()
777                 );
778         }
779
780         if (show_all || !strcmp(res->section, "ports")) {
781
782                 cmdline_printf(
783                         cl,
784                         "\n"
785                         "Port Operations:\n"
786                         "----------------\n\n"
787
788                         "port start (port_id|all)\n"
789                         "    Start all ports or port_id.\n\n"
790
791                         "port stop (port_id|all)\n"
792                         "    Stop all ports or port_id.\n\n"
793
794                         "port close (port_id|all)\n"
795                         "    Close all ports or port_id.\n\n"
796
797                         "port attach (ident)\n"
798                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
799
800                         "port detach (port_id)\n"
801                         "    Detach physical or virtual dev by port_id\n\n"
802
803                         "port config (port_id|all)"
804                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
805                         " duplex (half|full|auto)\n"
806                         "    Set speed and duplex for all ports or port_id\n\n"
807
808                         "port config all (rxq|txq|rxd|txd) (value)\n"
809                         "    Set number for rxq/txq/rxd/txd.\n\n"
810
811                         "port config all max-pkt-len (value)\n"
812                         "    Set the max packet length.\n\n"
813
814                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
815                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
816                         " (on|off)\n"
817                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
818                         " for ports.\n\n"
819
820                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
821                         "geneve|nvgre|none|<flowtype_id>)\n"
822                         "    Set the RSS mode.\n\n"
823
824                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
825                         "    Set the RSS redirection table.\n\n"
826
827                         "port config (port_id) dcb vt (on|off) (traffic_class)"
828                         " pfc (on|off)\n"
829                         "    Set the DCB mode.\n\n"
830
831                         "port config all burst (value)\n"
832                         "    Set the number of packets per burst.\n\n"
833
834                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
835                         " (value)\n"
836                         "    Set the ring prefetch/host/writeback threshold"
837                         " for tx/rx queue.\n\n"
838
839                         "port config all (txfreet|txrst|rxfreet) (value)\n"
840                         "    Set free threshold for rx/tx, or set"
841                         " tx rs bit threshold.\n\n"
842                         "port config mtu X value\n"
843                         "    Set the MTU of port X to a given value\n\n"
844
845                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
846                         "    Start/stop a rx/tx queue of port X. Only take effect"
847                         " when port X is started\n\n"
848
849                         "port config (port_id|all) l2-tunnel E-tag ether-type"
850                         " (value)\n"
851                         "    Set the value of E-tag ether-type.\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag"
854                         " (enable|disable)\n"
855                         "    Enable/disable the E-tag support.\n\n"
856
857                         "port config (port_id) pctype mapping reset\n"
858                         "    Reset flow type to pctype mapping on a port\n\n"
859
860                         "port config (port_id) pctype mapping update"
861                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
862                         "    Update a flow type to pctype mapping item on a port\n\n"
863                 );
864         }
865
866         if (show_all || !strcmp(res->section, "registers")) {
867
868                 cmdline_printf(
869                         cl,
870                         "\n"
871                         "Registers:\n"
872                         "----------\n\n"
873
874                         "read reg (port_id) (address)\n"
875                         "    Display value of a port register.\n\n"
876
877                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
878                         "    Display a port register bit field.\n\n"
879
880                         "read regbit (port_id) (address) (bit_x)\n"
881                         "    Display a single port register bit.\n\n"
882
883                         "write reg (port_id) (address) (value)\n"
884                         "    Set value of a port register.\n\n"
885
886                         "write regfield (port_id) (address) (bit_x) (bit_y)"
887                         " (value)\n"
888                         "    Set bit field of a port register.\n\n"
889
890                         "write regbit (port_id) (address) (bit_x) (value)\n"
891                         "    Set single bit value of a port register.\n\n"
892                 );
893         }
894         if (show_all || !strcmp(res->section, "filters")) {
895
896                 cmdline_printf(
897                         cl,
898                         "\n"
899                         "filters:\n"
900                         "--------\n\n"
901
902                         "ethertype_filter (port_id) (add|del)"
903                         " (mac_addr|mac_ignr) (mac_address) ethertype"
904                         " (ether_type) (drop|fwd) queue (queue_id)\n"
905                         "    Add/Del an ethertype filter.\n\n"
906
907                         "2tuple_filter (port_id) (add|del)"
908                         " dst_port (dst_port_value) protocol (protocol_value)"
909                         " mask (mask_value) tcp_flags (tcp_flags_value)"
910                         " priority (prio_value) queue (queue_id)\n"
911                         "    Add/Del a 2tuple filter.\n\n"
912
913                         "5tuple_filter (port_id) (add|del)"
914                         " dst_ip (dst_address) src_ip (src_address)"
915                         " dst_port (dst_port_value) src_port (src_port_value)"
916                         " protocol (protocol_value)"
917                         " mask (mask_value) tcp_flags (tcp_flags_value)"
918                         " priority (prio_value) queue (queue_id)\n"
919                         "    Add/Del a 5tuple filter.\n\n"
920
921                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
922                         "    Add/Del syn filter.\n\n"
923
924                         "flex_filter (port_id) (add|del) len (len_value)"
925                         " bytes (bytes_value) mask (mask_value)"
926                         " priority (prio_value) queue (queue_id)\n"
927                         "    Add/Del a flex filter.\n\n"
928
929                         "flow_director_filter (port_id) mode IP (add|del|update)"
930                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
931                         " src (src_ip_address) dst (dst_ip_address)"
932                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
933                         " vlan (vlan_value) flexbytes (flexbytes_value)"
934                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
935                         " fd_id (fd_id_value)\n"
936                         "    Add/Del an IP type flow director filter.\n\n"
937
938                         "flow_director_filter (port_id) mode IP (add|del|update)"
939                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
940                         " src (src_ip_address) (src_port)"
941                         " dst (dst_ip_address) (dst_port)"
942                         " tos (tos_value) ttl (ttl_value)"
943                         " vlan (vlan_value) flexbytes (flexbytes_value)"
944                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
945                         " fd_id (fd_id_value)\n"
946                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
947
948                         "flow_director_filter (port_id) mode IP (add|del|update)"
949                         " flow (ipv4-sctp|ipv6-sctp)"
950                         " src (src_ip_address) (src_port)"
951                         " dst (dst_ip_address) (dst_port)"
952                         " tag (verification_tag) "
953                         " tos (tos_value) ttl (ttl_value)"
954                         " vlan (vlan_value)"
955                         " flexbytes (flexbytes_value) (drop|fwd)"
956                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
957                         "    Add/Del a SCTP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow l2_payload ether (ethertype)"
961                         " flexbytes (flexbytes_value) (drop|fwd)"
962                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
963                         "    Add/Del a l2 payload type flow director filter.\n\n"
964
965                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
966                         " mac (mac_address) vlan (vlan_value)"
967                         " flexbytes (flexbytes_value) (drop|fwd)"
968                         " queue (queue_id) fd_id (fd_id_value)\n"
969                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
970
971                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
972                         " mac (mac_address) vlan (vlan_value)"
973                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
974                         " flexbytes (flexbytes_value) (drop|fwd)"
975                         " queue (queue_id) fd_id (fd_id_value)\n"
976                         "    Add/Del a Tunnel flow director filter.\n\n"
977
978                         "flush_flow_director (port_id)\n"
979                         "    Flush all flow director entries of a device.\n\n"
980
981                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
982                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
983                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
984                         "    Set flow director IP mask.\n\n"
985
986                         "flow_director_mask (port_id) mode MAC-VLAN"
987                         " vlan (vlan_value)\n"
988                         "    Set flow director MAC-VLAN mask.\n\n"
989
990                         "flow_director_mask (port_id) mode Tunnel"
991                         " vlan (vlan_value) mac (mac_value)"
992                         " tunnel-type (tunnel_type_value)"
993                         " tunnel-id (tunnel_id_value)\n"
994                         "    Set flow director Tunnel mask.\n\n"
995
996                         "flow_director_flex_mask (port_id)"
997                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
998                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
999                         " (mask)\n"
1000                         "    Configure mask of flex payload.\n\n"
1001
1002                         "flow_director_flex_payload (port_id)"
1003                         " (raw|l2|l3|l4) (config)\n"
1004                         "    Configure flex payload selection.\n\n"
1005
1006                         "get_sym_hash_ena_per_port (port_id)\n"
1007                         "    get symmetric hash enable configuration per port.\n\n"
1008
1009                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1010                         "    set symmetric hash enable configuration per port"
1011                         " to enable or disable.\n\n"
1012
1013                         "get_hash_global_config (port_id)\n"
1014                         "    Get the global configurations of hash filters.\n\n"
1015
1016                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1017                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1018                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1019                         " (enable|disable)\n"
1020                         "    Set the global configurations of hash filters.\n\n"
1021
1022                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1023                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1024                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1025                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1026                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1027                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1028                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1029                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1030                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1031                         "fld-8th|none) (select|add)\n"
1032                         "    Set the input set for hash.\n\n"
1033
1034                         "set_fdir_input_set (port_id) "
1035                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1036                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1037                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1038                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1039                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1040                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1041                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1042                         " (select|add)\n"
1043                         "    Set the input set for FDir.\n\n"
1044
1045                         "flow validate {port_id}"
1046                         " [group {group_id}] [priority {level}]"
1047                         " [ingress] [egress]"
1048                         " pattern {item} [/ {item} [...]] / end"
1049                         " actions {action} [/ {action} [...]] / end\n"
1050                         "    Check whether a flow rule can be created.\n\n"
1051
1052                         "flow create {port_id}"
1053                         " [group {group_id}] [priority {level}]"
1054                         " [ingress] [egress]"
1055                         " pattern {item} [/ {item} [...]] / end"
1056                         " actions {action} [/ {action} [...]] / end\n"
1057                         "    Create a flow rule.\n\n"
1058
1059                         "flow destroy {port_id} rule {rule_id} [...]\n"
1060                         "    Destroy specific flow rules.\n\n"
1061
1062                         "flow flush {port_id}\n"
1063                         "    Destroy all flow rules.\n\n"
1064
1065                         "flow query {port_id} {rule_id} {action}\n"
1066                         "    Query an existing flow rule.\n\n"
1067
1068                         "flow list {port_id} [group {group_id}] [...]\n"
1069                         "    List existing flow rules sorted by priority,"
1070                         " filtered by group identifiers.\n\n"
1071
1072                         "flow isolate {port_id} {boolean}\n"
1073                         "    Restrict ingress traffic to the defined"
1074                         " flow rules\n\n"
1075                 );
1076         }
1077 }
1078
1079 cmdline_parse_token_string_t cmd_help_long_help =
1080         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1081
1082 cmdline_parse_token_string_t cmd_help_long_section =
1083         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1084                         "all#control#display#config#"
1085                         "ports#registers#filters");
1086
1087 cmdline_parse_inst_t cmd_help_long = {
1088         .f = cmd_help_long_parsed,
1089         .data = NULL,
1090         .help_str = "help all|control|display|config|ports|register|filters: "
1091                 "Show help",
1092         .tokens = {
1093                 (void *)&cmd_help_long_help,
1094                 (void *)&cmd_help_long_section,
1095                 NULL,
1096         },
1097 };
1098
1099
1100 /* *** start/stop/close all ports *** */
1101 struct cmd_operate_port_result {
1102         cmdline_fixed_string_t keyword;
1103         cmdline_fixed_string_t name;
1104         cmdline_fixed_string_t value;
1105 };
1106
1107 static void cmd_operate_port_parsed(void *parsed_result,
1108                                 __attribute__((unused)) struct cmdline *cl,
1109                                 __attribute__((unused)) void *data)
1110 {
1111         struct cmd_operate_port_result *res = parsed_result;
1112
1113         if (!strcmp(res->name, "start"))
1114                 start_port(RTE_PORT_ALL);
1115         else if (!strcmp(res->name, "stop"))
1116                 stop_port(RTE_PORT_ALL);
1117         else if (!strcmp(res->name, "close"))
1118                 close_port(RTE_PORT_ALL);
1119         else if (!strcmp(res->name, "reset"))
1120                 reset_port(RTE_PORT_ALL);
1121         else
1122                 printf("Unknown parameter\n");
1123 }
1124
1125 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1126         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1127                                                                 "port");
1128 cmdline_parse_token_string_t cmd_operate_port_all_port =
1129         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1130                                                 "start#stop#close#reset");
1131 cmdline_parse_token_string_t cmd_operate_port_all_all =
1132         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1133
1134 cmdline_parse_inst_t cmd_operate_port = {
1135         .f = cmd_operate_port_parsed,
1136         .data = NULL,
1137         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1138         .tokens = {
1139                 (void *)&cmd_operate_port_all_cmd,
1140                 (void *)&cmd_operate_port_all_port,
1141                 (void *)&cmd_operate_port_all_all,
1142                 NULL,
1143         },
1144 };
1145
1146 /* *** start/stop/close specific port *** */
1147 struct cmd_operate_specific_port_result {
1148         cmdline_fixed_string_t keyword;
1149         cmdline_fixed_string_t name;
1150         uint8_t value;
1151 };
1152
1153 static void cmd_operate_specific_port_parsed(void *parsed_result,
1154                         __attribute__((unused)) struct cmdline *cl,
1155                                 __attribute__((unused)) void *data)
1156 {
1157         struct cmd_operate_specific_port_result *res = parsed_result;
1158
1159         if (!strcmp(res->name, "start"))
1160                 start_port(res->value);
1161         else if (!strcmp(res->name, "stop"))
1162                 stop_port(res->value);
1163         else if (!strcmp(res->name, "close"))
1164                 close_port(res->value);
1165         else if (!strcmp(res->name, "reset"))
1166                 reset_port(res->value);
1167         else
1168                 printf("Unknown parameter\n");
1169 }
1170
1171 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1172         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1173                                                         keyword, "port");
1174 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1175         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1176                                                 name, "start#stop#close#reset");
1177 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1178         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1179                                                         value, UINT8);
1180
1181 cmdline_parse_inst_t cmd_operate_specific_port = {
1182         .f = cmd_operate_specific_port_parsed,
1183         .data = NULL,
1184         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1185         .tokens = {
1186                 (void *)&cmd_operate_specific_port_cmd,
1187                 (void *)&cmd_operate_specific_port_port,
1188                 (void *)&cmd_operate_specific_port_id,
1189                 NULL,
1190         },
1191 };
1192
1193 /* *** attach a specified port *** */
1194 struct cmd_operate_attach_port_result {
1195         cmdline_fixed_string_t port;
1196         cmdline_fixed_string_t keyword;
1197         cmdline_fixed_string_t identifier;
1198 };
1199
1200 static void cmd_operate_attach_port_parsed(void *parsed_result,
1201                                 __attribute__((unused)) struct cmdline *cl,
1202                                 __attribute__((unused)) void *data)
1203 {
1204         struct cmd_operate_attach_port_result *res = parsed_result;
1205
1206         if (!strcmp(res->keyword, "attach"))
1207                 attach_port(res->identifier);
1208         else
1209                 printf("Unknown parameter\n");
1210 }
1211
1212 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1213         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1214                         port, "port");
1215 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1216         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1217                         keyword, "attach");
1218 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1219         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1220                         identifier, NULL);
1221
1222 cmdline_parse_inst_t cmd_operate_attach_port = {
1223         .f = cmd_operate_attach_port_parsed,
1224         .data = NULL,
1225         .help_str = "port attach <identifier>: "
1226                 "(identifier: pci address or virtual dev name)",
1227         .tokens = {
1228                 (void *)&cmd_operate_attach_port_port,
1229                 (void *)&cmd_operate_attach_port_keyword,
1230                 (void *)&cmd_operate_attach_port_identifier,
1231                 NULL,
1232         },
1233 };
1234
1235 /* *** detach a specified port *** */
1236 struct cmd_operate_detach_port_result {
1237         cmdline_fixed_string_t port;
1238         cmdline_fixed_string_t keyword;
1239         portid_t port_id;
1240 };
1241
1242 static void cmd_operate_detach_port_parsed(void *parsed_result,
1243                                 __attribute__((unused)) struct cmdline *cl,
1244                                 __attribute__((unused)) void *data)
1245 {
1246         struct cmd_operate_detach_port_result *res = parsed_result;
1247
1248         if (!strcmp(res->keyword, "detach"))
1249                 detach_port(res->port_id);
1250         else
1251                 printf("Unknown parameter\n");
1252 }
1253
1254 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1256                         port, "port");
1257 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1258         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1259                         keyword, "detach");
1260 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1261         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1262                         port_id, UINT16);
1263
1264 cmdline_parse_inst_t cmd_operate_detach_port = {
1265         .f = cmd_operate_detach_port_parsed,
1266         .data = NULL,
1267         .help_str = "port detach <port_id>",
1268         .tokens = {
1269                 (void *)&cmd_operate_detach_port_port,
1270                 (void *)&cmd_operate_detach_port_keyword,
1271                 (void *)&cmd_operate_detach_port_port_id,
1272                 NULL,
1273         },
1274 };
1275
1276 /* *** configure speed for all ports *** */
1277 struct cmd_config_speed_all {
1278         cmdline_fixed_string_t port;
1279         cmdline_fixed_string_t keyword;
1280         cmdline_fixed_string_t all;
1281         cmdline_fixed_string_t item1;
1282         cmdline_fixed_string_t item2;
1283         cmdline_fixed_string_t value1;
1284         cmdline_fixed_string_t value2;
1285 };
1286
1287 static int
1288 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1289 {
1290
1291         int duplex;
1292
1293         if (!strcmp(duplexstr, "half")) {
1294                 duplex = ETH_LINK_HALF_DUPLEX;
1295         } else if (!strcmp(duplexstr, "full")) {
1296                 duplex = ETH_LINK_FULL_DUPLEX;
1297         } else if (!strcmp(duplexstr, "auto")) {
1298                 duplex = ETH_LINK_FULL_DUPLEX;
1299         } else {
1300                 printf("Unknown duplex parameter\n");
1301                 return -1;
1302         }
1303
1304         if (!strcmp(speedstr, "10")) {
1305                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1306                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1307         } else if (!strcmp(speedstr, "100")) {
1308                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1309                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1310         } else {
1311                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1312                         printf("Invalid speed/duplex parameters\n");
1313                         return -1;
1314                 }
1315                 if (!strcmp(speedstr, "1000")) {
1316                         *speed = ETH_LINK_SPEED_1G;
1317                 } else if (!strcmp(speedstr, "10000")) {
1318                         *speed = ETH_LINK_SPEED_10G;
1319                 } else if (!strcmp(speedstr, "25000")) {
1320                         *speed = ETH_LINK_SPEED_25G;
1321                 } else if (!strcmp(speedstr, "40000")) {
1322                         *speed = ETH_LINK_SPEED_40G;
1323                 } else if (!strcmp(speedstr, "50000")) {
1324                         *speed = ETH_LINK_SPEED_50G;
1325                 } else if (!strcmp(speedstr, "100000")) {
1326                         *speed = ETH_LINK_SPEED_100G;
1327                 } else if (!strcmp(speedstr, "auto")) {
1328                         *speed = ETH_LINK_SPEED_AUTONEG;
1329                 } else {
1330                         printf("Unknown speed parameter\n");
1331                         return -1;
1332                 }
1333         }
1334
1335         return 0;
1336 }
1337
1338 static void
1339 cmd_config_speed_all_parsed(void *parsed_result,
1340                         __attribute__((unused)) struct cmdline *cl,
1341                         __attribute__((unused)) void *data)
1342 {
1343         struct cmd_config_speed_all *res = parsed_result;
1344         uint32_t link_speed;
1345         portid_t pid;
1346
1347         if (!all_ports_stopped()) {
1348                 printf("Please stop all ports first\n");
1349                 return;
1350         }
1351
1352         if (parse_and_check_speed_duplex(res->value1, res->value2,
1353                         &link_speed) < 0)
1354                 return;
1355
1356         RTE_ETH_FOREACH_DEV(pid) {
1357                 ports[pid].dev_conf.link_speeds = link_speed;
1358         }
1359
1360         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1361 }
1362
1363 cmdline_parse_token_string_t cmd_config_speed_all_port =
1364         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1365 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1366         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1367                                                         "config");
1368 cmdline_parse_token_string_t cmd_config_speed_all_all =
1369         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1370 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1371         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1372 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1373         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1374                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1375 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1376         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1377 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1378         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1379                                                 "half#full#auto");
1380
1381 cmdline_parse_inst_t cmd_config_speed_all = {
1382         .f = cmd_config_speed_all_parsed,
1383         .data = NULL,
1384         .help_str = "port config all speed "
1385                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1386                                                         "half|full|auto",
1387         .tokens = {
1388                 (void *)&cmd_config_speed_all_port,
1389                 (void *)&cmd_config_speed_all_keyword,
1390                 (void *)&cmd_config_speed_all_all,
1391                 (void *)&cmd_config_speed_all_item1,
1392                 (void *)&cmd_config_speed_all_value1,
1393                 (void *)&cmd_config_speed_all_item2,
1394                 (void *)&cmd_config_speed_all_value2,
1395                 NULL,
1396         },
1397 };
1398
1399 /* *** configure speed for specific port *** */
1400 struct cmd_config_speed_specific {
1401         cmdline_fixed_string_t port;
1402         cmdline_fixed_string_t keyword;
1403         uint8_t id;
1404         cmdline_fixed_string_t item1;
1405         cmdline_fixed_string_t item2;
1406         cmdline_fixed_string_t value1;
1407         cmdline_fixed_string_t value2;
1408 };
1409
1410 static void
1411 cmd_config_speed_specific_parsed(void *parsed_result,
1412                                 __attribute__((unused)) struct cmdline *cl,
1413                                 __attribute__((unused)) void *data)
1414 {
1415         struct cmd_config_speed_specific *res = parsed_result;
1416         uint32_t link_speed;
1417
1418         if (!all_ports_stopped()) {
1419                 printf("Please stop all ports first\n");
1420                 return;
1421         }
1422
1423         if (port_id_is_invalid(res->id, ENABLED_WARN))
1424                 return;
1425
1426         if (parse_and_check_speed_duplex(res->value1, res->value2,
1427                         &link_speed) < 0)
1428                 return;
1429
1430         ports[res->id].dev_conf.link_speeds = link_speed;
1431
1432         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1433 }
1434
1435
1436 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1437         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1438                                                                 "port");
1439 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1440         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1441                                                                 "config");
1442 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1443         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1444 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1445         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1446                                                                 "speed");
1447 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1448         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1449                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1450 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1451         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1452                                                                 "duplex");
1453 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1454         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1455                                                         "half#full#auto");
1456
1457 cmdline_parse_inst_t cmd_config_speed_specific = {
1458         .f = cmd_config_speed_specific_parsed,
1459         .data = NULL,
1460         .help_str = "port config <port_id> speed "
1461                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1462                                                         "half|full|auto",
1463         .tokens = {
1464                 (void *)&cmd_config_speed_specific_port,
1465                 (void *)&cmd_config_speed_specific_keyword,
1466                 (void *)&cmd_config_speed_specific_id,
1467                 (void *)&cmd_config_speed_specific_item1,
1468                 (void *)&cmd_config_speed_specific_value1,
1469                 (void *)&cmd_config_speed_specific_item2,
1470                 (void *)&cmd_config_speed_specific_value2,
1471                 NULL,
1472         },
1473 };
1474
1475 /* *** configure txq/rxq, txd/rxd *** */
1476 struct cmd_config_rx_tx {
1477         cmdline_fixed_string_t port;
1478         cmdline_fixed_string_t keyword;
1479         cmdline_fixed_string_t all;
1480         cmdline_fixed_string_t name;
1481         uint16_t value;
1482 };
1483
1484 static void
1485 cmd_config_rx_tx_parsed(void *parsed_result,
1486                         __attribute__((unused)) struct cmdline *cl,
1487                         __attribute__((unused)) void *data)
1488 {
1489         struct cmd_config_rx_tx *res = parsed_result;
1490
1491         if (!all_ports_stopped()) {
1492                 printf("Please stop all ports first\n");
1493                 return;
1494         }
1495         if (!strcmp(res->name, "rxq")) {
1496                 if (!res->value && !nb_txq) {
1497                         printf("Warning: Either rx or tx queues should be non zero\n");
1498                         return;
1499                 }
1500                 nb_rxq = res->value;
1501         }
1502         else if (!strcmp(res->name, "txq")) {
1503                 if (!res->value && !nb_rxq) {
1504                         printf("Warning: Either rx or tx queues should be non zero\n");
1505                         return;
1506                 }
1507                 nb_txq = res->value;
1508         }
1509         else if (!strcmp(res->name, "rxd")) {
1510                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1511                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1512                                         res->value, RTE_TEST_RX_DESC_MAX);
1513                         return;
1514                 }
1515                 nb_rxd = res->value;
1516         } else if (!strcmp(res->name, "txd")) {
1517                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1518                         printf("txd %d invalid - must be > 0 && <= %d\n",
1519                                         res->value, RTE_TEST_TX_DESC_MAX);
1520                         return;
1521                 }
1522                 nb_txd = res->value;
1523         } else {
1524                 printf("Unknown parameter\n");
1525                 return;
1526         }
1527
1528         fwd_config_setup();
1529
1530         init_port_config();
1531
1532         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1533 }
1534
1535 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1536         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1537 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1538         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1539 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1540         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1541 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1542         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1543                                                 "rxq#txq#rxd#txd");
1544 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1545         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1546
1547 cmdline_parse_inst_t cmd_config_rx_tx = {
1548         .f = cmd_config_rx_tx_parsed,
1549         .data = NULL,
1550         .help_str = "port config all rxq|txq|rxd|txd <value>",
1551         .tokens = {
1552                 (void *)&cmd_config_rx_tx_port,
1553                 (void *)&cmd_config_rx_tx_keyword,
1554                 (void *)&cmd_config_rx_tx_all,
1555                 (void *)&cmd_config_rx_tx_name,
1556                 (void *)&cmd_config_rx_tx_value,
1557                 NULL,
1558         },
1559 };
1560
1561 /* *** config max packet length *** */
1562 struct cmd_config_max_pkt_len_result {
1563         cmdline_fixed_string_t port;
1564         cmdline_fixed_string_t keyword;
1565         cmdline_fixed_string_t all;
1566         cmdline_fixed_string_t name;
1567         uint32_t value;
1568 };
1569
1570 static void
1571 cmd_config_max_pkt_len_parsed(void *parsed_result,
1572                                 __attribute__((unused)) struct cmdline *cl,
1573                                 __attribute__((unused)) void *data)
1574 {
1575         struct cmd_config_max_pkt_len_result *res = parsed_result;
1576
1577         if (!all_ports_stopped()) {
1578                 printf("Please stop all ports first\n");
1579                 return;
1580         }
1581
1582         if (!strcmp(res->name, "max-pkt-len")) {
1583                 if (res->value < ETHER_MIN_LEN) {
1584                         printf("max-pkt-len can not be less than %d\n",
1585                                                         ETHER_MIN_LEN);
1586                         return;
1587                 }
1588                 if (res->value == rx_mode.max_rx_pkt_len)
1589                         return;
1590
1591                 rx_mode.max_rx_pkt_len = res->value;
1592                 if (res->value > ETHER_MAX_LEN)
1593                         rx_mode.jumbo_frame = 1;
1594                 else
1595                         rx_mode.jumbo_frame = 0;
1596         } else {
1597                 printf("Unknown parameter\n");
1598                 return;
1599         }
1600
1601         init_port_config();
1602
1603         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1604 }
1605
1606 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1607         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1608                                                                 "port");
1609 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1610         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1611                                                                 "config");
1612 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1613         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1614                                                                 "all");
1615 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1616         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1617                                                                 "max-pkt-len");
1618 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1619         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1620                                                                 UINT32);
1621
1622 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1623         .f = cmd_config_max_pkt_len_parsed,
1624         .data = NULL,
1625         .help_str = "port config all max-pkt-len <value>",
1626         .tokens = {
1627                 (void *)&cmd_config_max_pkt_len_port,
1628                 (void *)&cmd_config_max_pkt_len_keyword,
1629                 (void *)&cmd_config_max_pkt_len_all,
1630                 (void *)&cmd_config_max_pkt_len_name,
1631                 (void *)&cmd_config_max_pkt_len_value,
1632                 NULL,
1633         },
1634 };
1635
1636 /* *** configure port MTU *** */
1637 struct cmd_config_mtu_result {
1638         cmdline_fixed_string_t port;
1639         cmdline_fixed_string_t keyword;
1640         cmdline_fixed_string_t mtu;
1641         portid_t port_id;
1642         uint16_t value;
1643 };
1644
1645 static void
1646 cmd_config_mtu_parsed(void *parsed_result,
1647                       __attribute__((unused)) struct cmdline *cl,
1648                       __attribute__((unused)) void *data)
1649 {
1650         struct cmd_config_mtu_result *res = parsed_result;
1651
1652         if (res->value < ETHER_MIN_LEN) {
1653                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1654                 return;
1655         }
1656         port_mtu_set(res->port_id, res->value);
1657 }
1658
1659 cmdline_parse_token_string_t cmd_config_mtu_port =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1661                                  "port");
1662 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1663         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1664                                  "config");
1665 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1667                                  "mtu");
1668 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1669         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1670 cmdline_parse_token_num_t cmd_config_mtu_value =
1671         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1672
1673 cmdline_parse_inst_t cmd_config_mtu = {
1674         .f = cmd_config_mtu_parsed,
1675         .data = NULL,
1676         .help_str = "port config mtu <port_id> <value>",
1677         .tokens = {
1678                 (void *)&cmd_config_mtu_port,
1679                 (void *)&cmd_config_mtu_keyword,
1680                 (void *)&cmd_config_mtu_mtu,
1681                 (void *)&cmd_config_mtu_port_id,
1682                 (void *)&cmd_config_mtu_value,
1683                 NULL,
1684         },
1685 };
1686
1687 /* *** configure rx mode *** */
1688 struct cmd_config_rx_mode_flag {
1689         cmdline_fixed_string_t port;
1690         cmdline_fixed_string_t keyword;
1691         cmdline_fixed_string_t all;
1692         cmdline_fixed_string_t name;
1693         cmdline_fixed_string_t value;
1694 };
1695
1696 static void
1697 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1698                                 __attribute__((unused)) struct cmdline *cl,
1699                                 __attribute__((unused)) void *data)
1700 {
1701         struct cmd_config_rx_mode_flag *res = parsed_result;
1702
1703         if (!all_ports_stopped()) {
1704                 printf("Please stop all ports first\n");
1705                 return;
1706         }
1707
1708         if (!strcmp(res->name, "crc-strip")) {
1709                 if (!strcmp(res->value, "on"))
1710                         rx_mode.hw_strip_crc = 1;
1711                 else if (!strcmp(res->value, "off"))
1712                         rx_mode.hw_strip_crc = 0;
1713                 else {
1714                         printf("Unknown parameter\n");
1715                         return;
1716                 }
1717         } else if (!strcmp(res->name, "scatter")) {
1718                 if (!strcmp(res->value, "on"))
1719                         rx_mode.enable_scatter = 1;
1720                 else if (!strcmp(res->value, "off"))
1721                         rx_mode.enable_scatter = 0;
1722                 else {
1723                         printf("Unknown parameter\n");
1724                         return;
1725                 }
1726         } else if (!strcmp(res->name, "rx-cksum")) {
1727                 if (!strcmp(res->value, "on"))
1728                         rx_mode.hw_ip_checksum = 1;
1729                 else if (!strcmp(res->value, "off"))
1730                         rx_mode.hw_ip_checksum = 0;
1731                 else {
1732                         printf("Unknown parameter\n");
1733                         return;
1734                 }
1735         } else if (!strcmp(res->name, "rx-timestamp")) {
1736                 if (!strcmp(res->value, "on"))
1737                         rx_mode.hw_timestamp = 1;
1738                 else if (!strcmp(res->value, "off"))
1739                         rx_mode.hw_timestamp = 0;
1740                 else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         } else if (!strcmp(res->name, "hw-vlan")) {
1745                 if (!strcmp(res->value, "on")) {
1746                         rx_mode.hw_vlan_filter = 1;
1747                         rx_mode.hw_vlan_strip  = 1;
1748                 }
1749                 else if (!strcmp(res->value, "off")) {
1750                         rx_mode.hw_vlan_filter = 0;
1751                         rx_mode.hw_vlan_strip  = 0;
1752                 }
1753                 else {
1754                         printf("Unknown parameter\n");
1755                         return;
1756                 }
1757         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1758                 if (!strcmp(res->value, "on"))
1759                         rx_mode.hw_vlan_filter = 1;
1760                 else if (!strcmp(res->value, "off"))
1761                         rx_mode.hw_vlan_filter = 0;
1762                 else {
1763                         printf("Unknown parameter\n");
1764                         return;
1765                 }
1766         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1767                 if (!strcmp(res->value, "on"))
1768                         rx_mode.hw_vlan_strip  = 1;
1769                 else if (!strcmp(res->value, "off"))
1770                         rx_mode.hw_vlan_strip  = 0;
1771                 else {
1772                         printf("Unknown parameter\n");
1773                         return;
1774                 }
1775         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1776                 if (!strcmp(res->value, "on"))
1777                         rx_mode.hw_vlan_extend = 1;
1778                 else if (!strcmp(res->value, "off"))
1779                         rx_mode.hw_vlan_extend = 0;
1780                 else {
1781                         printf("Unknown parameter\n");
1782                         return;
1783                 }
1784         } else if (!strcmp(res->name, "drop-en")) {
1785                 if (!strcmp(res->value, "on"))
1786                         rx_drop_en = 1;
1787                 else if (!strcmp(res->value, "off"))
1788                         rx_drop_en = 0;
1789                 else {
1790                         printf("Unknown parameter\n");
1791                         return;
1792                 }
1793         } else {
1794                 printf("Unknown parameter\n");
1795                 return;
1796         }
1797
1798         init_port_config();
1799
1800         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1801 }
1802
1803 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1804         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1805 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1807                                                                 "config");
1808 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1809         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1810 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1812                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1813                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1814 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1815         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1816                                                         "on#off");
1817
1818 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1819         .f = cmd_config_rx_mode_flag_parsed,
1820         .data = NULL,
1821         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1822                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1823         .tokens = {
1824                 (void *)&cmd_config_rx_mode_flag_port,
1825                 (void *)&cmd_config_rx_mode_flag_keyword,
1826                 (void *)&cmd_config_rx_mode_flag_all,
1827                 (void *)&cmd_config_rx_mode_flag_name,
1828                 (void *)&cmd_config_rx_mode_flag_value,
1829                 NULL,
1830         },
1831 };
1832
1833 /* *** configure rss *** */
1834 struct cmd_config_rss {
1835         cmdline_fixed_string_t port;
1836         cmdline_fixed_string_t keyword;
1837         cmdline_fixed_string_t all;
1838         cmdline_fixed_string_t name;
1839         cmdline_fixed_string_t value;
1840 };
1841
1842 static void
1843 cmd_config_rss_parsed(void *parsed_result,
1844                         __attribute__((unused)) struct cmdline *cl,
1845                         __attribute__((unused)) void *data)
1846 {
1847         struct cmd_config_rss *res = parsed_result;
1848         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1849         int diag;
1850         uint8_t i;
1851
1852         if (!strcmp(res->value, "all"))
1853                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1854                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1855                                         ETH_RSS_L2_PAYLOAD;
1856         else if (!strcmp(res->value, "ip"))
1857                 rss_conf.rss_hf = ETH_RSS_IP;
1858         else if (!strcmp(res->value, "udp"))
1859                 rss_conf.rss_hf = ETH_RSS_UDP;
1860         else if (!strcmp(res->value, "tcp"))
1861                 rss_conf.rss_hf = ETH_RSS_TCP;
1862         else if (!strcmp(res->value, "sctp"))
1863                 rss_conf.rss_hf = ETH_RSS_SCTP;
1864         else if (!strcmp(res->value, "ether"))
1865                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1866         else if (!strcmp(res->value, "port"))
1867                 rss_conf.rss_hf = ETH_RSS_PORT;
1868         else if (!strcmp(res->value, "vxlan"))
1869                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1870         else if (!strcmp(res->value, "geneve"))
1871                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1872         else if (!strcmp(res->value, "nvgre"))
1873                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1874         else if (!strcmp(res->value, "none"))
1875                 rss_conf.rss_hf = 0;
1876         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1877                                                 atoi(res->value) < 64)
1878                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1879         else {
1880                 printf("Unknown parameter\n");
1881                 return;
1882         }
1883         rss_conf.rss_key = NULL;
1884         for (i = 0; i < rte_eth_dev_count(); i++) {
1885                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1886                 if (diag < 0)
1887                         printf("Configuration of RSS hash at ethernet port %d "
1888                                 "failed with error (%d): %s.\n",
1889                                 i, -diag, strerror(-diag));
1890         }
1891 }
1892
1893 cmdline_parse_token_string_t cmd_config_rss_port =
1894         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1895 cmdline_parse_token_string_t cmd_config_rss_keyword =
1896         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1897 cmdline_parse_token_string_t cmd_config_rss_all =
1898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1899 cmdline_parse_token_string_t cmd_config_rss_name =
1900         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1901 cmdline_parse_token_string_t cmd_config_rss_value =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1903
1904 cmdline_parse_inst_t cmd_config_rss = {
1905         .f = cmd_config_rss_parsed,
1906         .data = NULL,
1907         .help_str = "port config all rss "
1908                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1909         .tokens = {
1910                 (void *)&cmd_config_rss_port,
1911                 (void *)&cmd_config_rss_keyword,
1912                 (void *)&cmd_config_rss_all,
1913                 (void *)&cmd_config_rss_name,
1914                 (void *)&cmd_config_rss_value,
1915                 NULL,
1916         },
1917 };
1918
1919 /* *** configure rss hash key *** */
1920 struct cmd_config_rss_hash_key {
1921         cmdline_fixed_string_t port;
1922         cmdline_fixed_string_t config;
1923         portid_t port_id;
1924         cmdline_fixed_string_t rss_hash_key;
1925         cmdline_fixed_string_t rss_type;
1926         cmdline_fixed_string_t key;
1927 };
1928
1929 static uint8_t
1930 hexa_digit_to_value(char hexa_digit)
1931 {
1932         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1933                 return (uint8_t) (hexa_digit - '0');
1934         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1935                 return (uint8_t) ((hexa_digit - 'a') + 10);
1936         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1937                 return (uint8_t) ((hexa_digit - 'A') + 10);
1938         /* Invalid hexa digit */
1939         return 0xFF;
1940 }
1941
1942 static uint8_t
1943 parse_and_check_key_hexa_digit(char *key, int idx)
1944 {
1945         uint8_t hexa_v;
1946
1947         hexa_v = hexa_digit_to_value(key[idx]);
1948         if (hexa_v == 0xFF)
1949                 printf("invalid key: character %c at position %d is not a "
1950                        "valid hexa digit\n", key[idx], idx);
1951         return hexa_v;
1952 }
1953
1954 static void
1955 cmd_config_rss_hash_key_parsed(void *parsed_result,
1956                                __attribute__((unused)) struct cmdline *cl,
1957                                __attribute__((unused)) void *data)
1958 {
1959         struct cmd_config_rss_hash_key *res = parsed_result;
1960         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1961         uint8_t xdgt0;
1962         uint8_t xdgt1;
1963         int i;
1964         struct rte_eth_dev_info dev_info;
1965         uint8_t hash_key_size;
1966         uint32_t key_len;
1967
1968         memset(&dev_info, 0, sizeof(dev_info));
1969         rte_eth_dev_info_get(res->port_id, &dev_info);
1970         if (dev_info.hash_key_size > 0 &&
1971                         dev_info.hash_key_size <= sizeof(hash_key))
1972                 hash_key_size = dev_info.hash_key_size;
1973         else {
1974                 printf("dev_info did not provide a valid hash key size\n");
1975                 return;
1976         }
1977         /* Check the length of the RSS hash key */
1978         key_len = strlen(res->key);
1979         if (key_len != (hash_key_size * 2)) {
1980                 printf("key length: %d invalid - key must be a string of %d"
1981                            " hexa-decimal numbers\n",
1982                            (int) key_len, hash_key_size * 2);
1983                 return;
1984         }
1985         /* Translate RSS hash key into binary representation */
1986         for (i = 0; i < hash_key_size; i++) {
1987                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1988                 if (xdgt0 == 0xFF)
1989                         return;
1990                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1991                 if (xdgt1 == 0xFF)
1992                         return;
1993                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1994         }
1995         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1996                         hash_key_size);
1997 }
1998
1999 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2001 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2003                                  "config");
2004 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2005         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2006 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2008                                  rss_hash_key, "rss-hash-key");
2009 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2011                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2012                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2013                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2014                                  "ipv6-tcp-ex#ipv6-udp-ex");
2015 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2016         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2017
2018 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2019         .f = cmd_config_rss_hash_key_parsed,
2020         .data = NULL,
2021         .help_str = "port config <port_id> rss-hash-key "
2022                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2023                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2024                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2025                 "<string of hex digits (variable length, NIC dependent)>",
2026         .tokens = {
2027                 (void *)&cmd_config_rss_hash_key_port,
2028                 (void *)&cmd_config_rss_hash_key_config,
2029                 (void *)&cmd_config_rss_hash_key_port_id,
2030                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2031                 (void *)&cmd_config_rss_hash_key_rss_type,
2032                 (void *)&cmd_config_rss_hash_key_value,
2033                 NULL,
2034         },
2035 };
2036
2037 /* *** configure port rxq/txq start/stop *** */
2038 struct cmd_config_rxtx_queue {
2039         cmdline_fixed_string_t port;
2040         portid_t portid;
2041         cmdline_fixed_string_t rxtxq;
2042         uint16_t qid;
2043         cmdline_fixed_string_t opname;
2044 };
2045
2046 static void
2047 cmd_config_rxtx_queue_parsed(void *parsed_result,
2048                         __attribute__((unused)) struct cmdline *cl,
2049                         __attribute__((unused)) void *data)
2050 {
2051         struct cmd_config_rxtx_queue *res = parsed_result;
2052         uint8_t isrx;
2053         uint8_t isstart;
2054         int ret = 0;
2055
2056         if (test_done == 0) {
2057                 printf("Please stop forwarding first\n");
2058                 return;
2059         }
2060
2061         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2062                 return;
2063
2064         if (port_is_started(res->portid) != 1) {
2065                 printf("Please start port %u first\n", res->portid);
2066                 return;
2067         }
2068
2069         if (!strcmp(res->rxtxq, "rxq"))
2070                 isrx = 1;
2071         else if (!strcmp(res->rxtxq, "txq"))
2072                 isrx = 0;
2073         else {
2074                 printf("Unknown parameter\n");
2075                 return;
2076         }
2077
2078         if (isrx && rx_queue_id_is_invalid(res->qid))
2079                 return;
2080         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2081                 return;
2082
2083         if (!strcmp(res->opname, "start"))
2084                 isstart = 1;
2085         else if (!strcmp(res->opname, "stop"))
2086                 isstart = 0;
2087         else {
2088                 printf("Unknown parameter\n");
2089                 return;
2090         }
2091
2092         if (isstart && isrx)
2093                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2094         else if (!isstart && isrx)
2095                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2096         else if (isstart && !isrx)
2097                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2098         else
2099                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2100
2101         if (ret == -ENOTSUP)
2102                 printf("Function not supported in PMD driver\n");
2103 }
2104
2105 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2106         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2107 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2108         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2109 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2111 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2112         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2113 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2114         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2115                                                 "start#stop");
2116
2117 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2118         .f = cmd_config_rxtx_queue_parsed,
2119         .data = NULL,
2120         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2121         .tokens = {
2122                 (void *)&cmd_config_speed_all_port,
2123                 (void *)&cmd_config_rxtx_queue_portid,
2124                 (void *)&cmd_config_rxtx_queue_rxtxq,
2125                 (void *)&cmd_config_rxtx_queue_qid,
2126                 (void *)&cmd_config_rxtx_queue_opname,
2127                 NULL,
2128         },
2129 };
2130
2131 /* *** Configure RSS RETA *** */
2132 struct cmd_config_rss_reta {
2133         cmdline_fixed_string_t port;
2134         cmdline_fixed_string_t keyword;
2135         portid_t port_id;
2136         cmdline_fixed_string_t name;
2137         cmdline_fixed_string_t list_name;
2138         cmdline_fixed_string_t list_of_items;
2139 };
2140
2141 static int
2142 parse_reta_config(const char *str,
2143                   struct rte_eth_rss_reta_entry64 *reta_conf,
2144                   uint16_t nb_entries)
2145 {
2146         int i;
2147         unsigned size;
2148         uint16_t hash_index, idx, shift;
2149         uint16_t nb_queue;
2150         char s[256];
2151         const char *p, *p0 = str;
2152         char *end;
2153         enum fieldnames {
2154                 FLD_HASH_INDEX = 0,
2155                 FLD_QUEUE,
2156                 _NUM_FLD
2157         };
2158         unsigned long int_fld[_NUM_FLD];
2159         char *str_fld[_NUM_FLD];
2160
2161         while ((p = strchr(p0,'(')) != NULL) {
2162                 ++p;
2163                 if((p0 = strchr(p,')')) == NULL)
2164                         return -1;
2165
2166                 size = p0 - p;
2167                 if(size >= sizeof(s))
2168                         return -1;
2169
2170                 snprintf(s, sizeof(s), "%.*s", size, p);
2171                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2172                         return -1;
2173                 for (i = 0; i < _NUM_FLD; i++) {
2174                         errno = 0;
2175                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2176                         if (errno != 0 || end == str_fld[i] ||
2177                                         int_fld[i] > 65535)
2178                                 return -1;
2179                 }
2180
2181                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2182                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2183
2184                 if (hash_index >= nb_entries) {
2185                         printf("Invalid RETA hash index=%d\n", hash_index);
2186                         return -1;
2187                 }
2188
2189                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2190                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2191                 reta_conf[idx].mask |= (1ULL << shift);
2192                 reta_conf[idx].reta[shift] = nb_queue;
2193         }
2194
2195         return 0;
2196 }
2197
2198 static void
2199 cmd_set_rss_reta_parsed(void *parsed_result,
2200                         __attribute__((unused)) struct cmdline *cl,
2201                         __attribute__((unused)) void *data)
2202 {
2203         int ret;
2204         struct rte_eth_dev_info dev_info;
2205         struct rte_eth_rss_reta_entry64 reta_conf[8];
2206         struct cmd_config_rss_reta *res = parsed_result;
2207
2208         memset(&dev_info, 0, sizeof(dev_info));
2209         rte_eth_dev_info_get(res->port_id, &dev_info);
2210         if (dev_info.reta_size == 0) {
2211                 printf("Redirection table size is 0 which is "
2212                                         "invalid for RSS\n");
2213                 return;
2214         } else
2215                 printf("The reta size of port %d is %u\n",
2216                         res->port_id, dev_info.reta_size);
2217         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2218                 printf("Currently do not support more than %u entries of "
2219                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2220                 return;
2221         }
2222
2223         memset(reta_conf, 0, sizeof(reta_conf));
2224         if (!strcmp(res->list_name, "reta")) {
2225                 if (parse_reta_config(res->list_of_items, reta_conf,
2226                                                 dev_info.reta_size)) {
2227                         printf("Invalid RSS Redirection Table "
2228                                         "config entered\n");
2229                         return;
2230                 }
2231                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2232                                 reta_conf, dev_info.reta_size);
2233                 if (ret != 0)
2234                         printf("Bad redirection table parameter, "
2235                                         "return code = %d \n", ret);
2236         }
2237 }
2238
2239 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2240         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2241 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2242         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2243 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2244         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2245 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2246         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2247 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2249 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2251                                  NULL);
2252 cmdline_parse_inst_t cmd_config_rss_reta = {
2253         .f = cmd_set_rss_reta_parsed,
2254         .data = NULL,
2255         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2256         .tokens = {
2257                 (void *)&cmd_config_rss_reta_port,
2258                 (void *)&cmd_config_rss_reta_keyword,
2259                 (void *)&cmd_config_rss_reta_port_id,
2260                 (void *)&cmd_config_rss_reta_name,
2261                 (void *)&cmd_config_rss_reta_list_name,
2262                 (void *)&cmd_config_rss_reta_list_of_items,
2263                 NULL,
2264         },
2265 };
2266
2267 /* *** SHOW PORT RETA INFO *** */
2268 struct cmd_showport_reta {
2269         cmdline_fixed_string_t show;
2270         cmdline_fixed_string_t port;
2271         portid_t port_id;
2272         cmdline_fixed_string_t rss;
2273         cmdline_fixed_string_t reta;
2274         uint16_t size;
2275         cmdline_fixed_string_t list_of_items;
2276 };
2277
2278 static int
2279 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2280                            uint16_t nb_entries,
2281                            char *str)
2282 {
2283         uint32_t size;
2284         const char *p, *p0 = str;
2285         char s[256];
2286         char *end;
2287         char *str_fld[8];
2288         uint16_t i;
2289         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2290                         RTE_RETA_GROUP_SIZE;
2291         int ret;
2292
2293         p = strchr(p0, '(');
2294         if (p == NULL)
2295                 return -1;
2296         p++;
2297         p0 = strchr(p, ')');
2298         if (p0 == NULL)
2299                 return -1;
2300         size = p0 - p;
2301         if (size >= sizeof(s)) {
2302                 printf("The string size exceeds the internal buffer size\n");
2303                 return -1;
2304         }
2305         snprintf(s, sizeof(s), "%.*s", size, p);
2306         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2307         if (ret <= 0 || ret != num) {
2308                 printf("The bits of masks do not match the number of "
2309                                         "reta entries: %u\n", num);
2310                 return -1;
2311         }
2312         for (i = 0; i < ret; i++)
2313                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2314
2315         return 0;
2316 }
2317
2318 static void
2319 cmd_showport_reta_parsed(void *parsed_result,
2320                          __attribute__((unused)) struct cmdline *cl,
2321                          __attribute__((unused)) void *data)
2322 {
2323         struct cmd_showport_reta *res = parsed_result;
2324         struct rte_eth_rss_reta_entry64 reta_conf[8];
2325         struct rte_eth_dev_info dev_info;
2326         uint16_t max_reta_size;
2327
2328         memset(&dev_info, 0, sizeof(dev_info));
2329         rte_eth_dev_info_get(res->port_id, &dev_info);
2330         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2331         if (res->size == 0 || res->size > max_reta_size) {
2332                 printf("Invalid redirection table size: %u (1-%u)\n",
2333                         res->size, max_reta_size);
2334                 return;
2335         }
2336
2337         memset(reta_conf, 0, sizeof(reta_conf));
2338         if (showport_parse_reta_config(reta_conf, res->size,
2339                                 res->list_of_items) < 0) {
2340                 printf("Invalid string: %s for reta masks\n",
2341                                         res->list_of_items);
2342                 return;
2343         }
2344         port_rss_reta_info(res->port_id, reta_conf, res->size);
2345 }
2346
2347 cmdline_parse_token_string_t cmd_showport_reta_show =
2348         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2349 cmdline_parse_token_string_t cmd_showport_reta_port =
2350         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2351 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2352         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2353 cmdline_parse_token_string_t cmd_showport_reta_rss =
2354         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2355 cmdline_parse_token_string_t cmd_showport_reta_reta =
2356         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2357 cmdline_parse_token_num_t cmd_showport_reta_size =
2358         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2359 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2360         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2361                                         list_of_items, NULL);
2362
2363 cmdline_parse_inst_t cmd_showport_reta = {
2364         .f = cmd_showport_reta_parsed,
2365         .data = NULL,
2366         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2367         .tokens = {
2368                 (void *)&cmd_showport_reta_show,
2369                 (void *)&cmd_showport_reta_port,
2370                 (void *)&cmd_showport_reta_port_id,
2371                 (void *)&cmd_showport_reta_rss,
2372                 (void *)&cmd_showport_reta_reta,
2373                 (void *)&cmd_showport_reta_size,
2374                 (void *)&cmd_showport_reta_list_of_items,
2375                 NULL,
2376         },
2377 };
2378
2379 /* *** Show RSS hash configuration *** */
2380 struct cmd_showport_rss_hash {
2381         cmdline_fixed_string_t show;
2382         cmdline_fixed_string_t port;
2383         portid_t port_id;
2384         cmdline_fixed_string_t rss_hash;
2385         cmdline_fixed_string_t rss_type;
2386         cmdline_fixed_string_t key; /* optional argument */
2387 };
2388
2389 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2390                                 __attribute__((unused)) struct cmdline *cl,
2391                                 void *show_rss_key)
2392 {
2393         struct cmd_showport_rss_hash *res = parsed_result;
2394
2395         port_rss_hash_conf_show(res->port_id, res->rss_type,
2396                                 show_rss_key != NULL);
2397 }
2398
2399 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2400         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2401 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2402         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2403 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2404         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2405 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2406         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2407                                  "rss-hash");
2408 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2409         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2410                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2411                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2412                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2413                                  "ipv6-tcp-ex#ipv6-udp-ex");
2414 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2415         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2416
2417 cmdline_parse_inst_t cmd_showport_rss_hash = {
2418         .f = cmd_showport_rss_hash_parsed,
2419         .data = NULL,
2420         .help_str = "show port <port_id> rss-hash "
2421                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2422                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2423                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2424         .tokens = {
2425                 (void *)&cmd_showport_rss_hash_show,
2426                 (void *)&cmd_showport_rss_hash_port,
2427                 (void *)&cmd_showport_rss_hash_port_id,
2428                 (void *)&cmd_showport_rss_hash_rss_hash,
2429                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2430                 NULL,
2431         },
2432 };
2433
2434 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2435         .f = cmd_showport_rss_hash_parsed,
2436         .data = (void *)1,
2437         .help_str = "show port <port_id> rss-hash "
2438                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2439                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2440                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2441         .tokens = {
2442                 (void *)&cmd_showport_rss_hash_show,
2443                 (void *)&cmd_showport_rss_hash_port,
2444                 (void *)&cmd_showport_rss_hash_port_id,
2445                 (void *)&cmd_showport_rss_hash_rss_hash,
2446                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2447                 (void *)&cmd_showport_rss_hash_rss_key,
2448                 NULL,
2449         },
2450 };
2451
2452 /* *** Configure DCB *** */
2453 struct cmd_config_dcb {
2454         cmdline_fixed_string_t port;
2455         cmdline_fixed_string_t config;
2456         portid_t port_id;
2457         cmdline_fixed_string_t dcb;
2458         cmdline_fixed_string_t vt;
2459         cmdline_fixed_string_t vt_en;
2460         uint8_t num_tcs;
2461         cmdline_fixed_string_t pfc;
2462         cmdline_fixed_string_t pfc_en;
2463 };
2464
2465 static void
2466 cmd_config_dcb_parsed(void *parsed_result,
2467                         __attribute__((unused)) struct cmdline *cl,
2468                         __attribute__((unused)) void *data)
2469 {
2470         struct cmd_config_dcb *res = parsed_result;
2471         portid_t port_id = res->port_id;
2472         struct rte_port *port;
2473         uint8_t pfc_en;
2474         int ret;
2475
2476         port = &ports[port_id];
2477         /** Check if the port is not started **/
2478         if (port->port_status != RTE_PORT_STOPPED) {
2479                 printf("Please stop port %d first\n", port_id);
2480                 return;
2481         }
2482
2483         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2484                 printf("The invalid number of traffic class,"
2485                         " only 4 or 8 allowed.\n");
2486                 return;
2487         }
2488
2489         if (nb_fwd_lcores < res->num_tcs) {
2490                 printf("nb_cores shouldn't be less than number of TCs.\n");
2491                 return;
2492         }
2493         if (!strncmp(res->pfc_en, "on", 2))
2494                 pfc_en = 1;
2495         else
2496                 pfc_en = 0;
2497
2498         /* DCB in VT mode */
2499         if (!strncmp(res->vt_en, "on", 2))
2500                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2501                                 (enum rte_eth_nb_tcs)res->num_tcs,
2502                                 pfc_en);
2503         else
2504                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2505                                 (enum rte_eth_nb_tcs)res->num_tcs,
2506                                 pfc_en);
2507
2508
2509         if (ret != 0) {
2510                 printf("Cannot initialize network ports.\n");
2511                 return;
2512         }
2513
2514         cmd_reconfig_device_queue(port_id, 1, 1);
2515 }
2516
2517 cmdline_parse_token_string_t cmd_config_dcb_port =
2518         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2519 cmdline_parse_token_string_t cmd_config_dcb_config =
2520         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2521 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2522         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2523 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2524         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2525 cmdline_parse_token_string_t cmd_config_dcb_vt =
2526         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2527 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2528         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2529 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2530         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2531 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2532         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2533 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2534         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2535
2536 cmdline_parse_inst_t cmd_config_dcb = {
2537         .f = cmd_config_dcb_parsed,
2538         .data = NULL,
2539         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2540         .tokens = {
2541                 (void *)&cmd_config_dcb_port,
2542                 (void *)&cmd_config_dcb_config,
2543                 (void *)&cmd_config_dcb_port_id,
2544                 (void *)&cmd_config_dcb_dcb,
2545                 (void *)&cmd_config_dcb_vt,
2546                 (void *)&cmd_config_dcb_vt_en,
2547                 (void *)&cmd_config_dcb_num_tcs,
2548                 (void *)&cmd_config_dcb_pfc,
2549                 (void *)&cmd_config_dcb_pfc_en,
2550                 NULL,
2551         },
2552 };
2553
2554 /* *** configure number of packets per burst *** */
2555 struct cmd_config_burst {
2556         cmdline_fixed_string_t port;
2557         cmdline_fixed_string_t keyword;
2558         cmdline_fixed_string_t all;
2559         cmdline_fixed_string_t name;
2560         uint16_t value;
2561 };
2562
2563 static void
2564 cmd_config_burst_parsed(void *parsed_result,
2565                         __attribute__((unused)) struct cmdline *cl,
2566                         __attribute__((unused)) void *data)
2567 {
2568         struct cmd_config_burst *res = parsed_result;
2569
2570         if (!all_ports_stopped()) {
2571                 printf("Please stop all ports first\n");
2572                 return;
2573         }
2574
2575         if (!strcmp(res->name, "burst")) {
2576                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2577                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2578                         return;
2579                 }
2580                 nb_pkt_per_burst = res->value;
2581         } else {
2582                 printf("Unknown parameter\n");
2583                 return;
2584         }
2585
2586         init_port_config();
2587
2588         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2589 }
2590
2591 cmdline_parse_token_string_t cmd_config_burst_port =
2592         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2593 cmdline_parse_token_string_t cmd_config_burst_keyword =
2594         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2595 cmdline_parse_token_string_t cmd_config_burst_all =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2597 cmdline_parse_token_string_t cmd_config_burst_name =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2599 cmdline_parse_token_num_t cmd_config_burst_value =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2601
2602 cmdline_parse_inst_t cmd_config_burst = {
2603         .f = cmd_config_burst_parsed,
2604         .data = NULL,
2605         .help_str = "port config all burst <value>",
2606         .tokens = {
2607                 (void *)&cmd_config_burst_port,
2608                 (void *)&cmd_config_burst_keyword,
2609                 (void *)&cmd_config_burst_all,
2610                 (void *)&cmd_config_burst_name,
2611                 (void *)&cmd_config_burst_value,
2612                 NULL,
2613         },
2614 };
2615
2616 /* *** configure rx/tx queues *** */
2617 struct cmd_config_thresh {
2618         cmdline_fixed_string_t port;
2619         cmdline_fixed_string_t keyword;
2620         cmdline_fixed_string_t all;
2621         cmdline_fixed_string_t name;
2622         uint8_t value;
2623 };
2624
2625 static void
2626 cmd_config_thresh_parsed(void *parsed_result,
2627                         __attribute__((unused)) struct cmdline *cl,
2628                         __attribute__((unused)) void *data)
2629 {
2630         struct cmd_config_thresh *res = parsed_result;
2631
2632         if (!all_ports_stopped()) {
2633                 printf("Please stop all ports first\n");
2634                 return;
2635         }
2636
2637         if (!strcmp(res->name, "txpt"))
2638                 tx_pthresh = res->value;
2639         else if(!strcmp(res->name, "txht"))
2640                 tx_hthresh = res->value;
2641         else if(!strcmp(res->name, "txwt"))
2642                 tx_wthresh = res->value;
2643         else if(!strcmp(res->name, "rxpt"))
2644                 rx_pthresh = res->value;
2645         else if(!strcmp(res->name, "rxht"))
2646                 rx_hthresh = res->value;
2647         else if(!strcmp(res->name, "rxwt"))
2648                 rx_wthresh = res->value;
2649         else {
2650                 printf("Unknown parameter\n");
2651                 return;
2652         }
2653
2654         init_port_config();
2655
2656         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2657 }
2658
2659 cmdline_parse_token_string_t cmd_config_thresh_port =
2660         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2661 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2662         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2663 cmdline_parse_token_string_t cmd_config_thresh_all =
2664         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2665 cmdline_parse_token_string_t cmd_config_thresh_name =
2666         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2667                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2668 cmdline_parse_token_num_t cmd_config_thresh_value =
2669         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2670
2671 cmdline_parse_inst_t cmd_config_thresh = {
2672         .f = cmd_config_thresh_parsed,
2673         .data = NULL,
2674         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2675         .tokens = {
2676                 (void *)&cmd_config_thresh_port,
2677                 (void *)&cmd_config_thresh_keyword,
2678                 (void *)&cmd_config_thresh_all,
2679                 (void *)&cmd_config_thresh_name,
2680                 (void *)&cmd_config_thresh_value,
2681                 NULL,
2682         },
2683 };
2684
2685 /* *** configure free/rs threshold *** */
2686 struct cmd_config_threshold {
2687         cmdline_fixed_string_t port;
2688         cmdline_fixed_string_t keyword;
2689         cmdline_fixed_string_t all;
2690         cmdline_fixed_string_t name;
2691         uint16_t value;
2692 };
2693
2694 static void
2695 cmd_config_threshold_parsed(void *parsed_result,
2696                         __attribute__((unused)) struct cmdline *cl,
2697                         __attribute__((unused)) void *data)
2698 {
2699         struct cmd_config_threshold *res = parsed_result;
2700
2701         if (!all_ports_stopped()) {
2702                 printf("Please stop all ports first\n");
2703                 return;
2704         }
2705
2706         if (!strcmp(res->name, "txfreet"))
2707                 tx_free_thresh = res->value;
2708         else if (!strcmp(res->name, "txrst"))
2709                 tx_rs_thresh = res->value;
2710         else if (!strcmp(res->name, "rxfreet"))
2711                 rx_free_thresh = res->value;
2712         else {
2713                 printf("Unknown parameter\n");
2714                 return;
2715         }
2716
2717         init_port_config();
2718
2719         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2720 }
2721
2722 cmdline_parse_token_string_t cmd_config_threshold_port =
2723         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2724 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2725         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2726                                                                 "config");
2727 cmdline_parse_token_string_t cmd_config_threshold_all =
2728         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2729 cmdline_parse_token_string_t cmd_config_threshold_name =
2730         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2731                                                 "txfreet#txrst#rxfreet");
2732 cmdline_parse_token_num_t cmd_config_threshold_value =
2733         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2734
2735 cmdline_parse_inst_t cmd_config_threshold = {
2736         .f = cmd_config_threshold_parsed,
2737         .data = NULL,
2738         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2739         .tokens = {
2740                 (void *)&cmd_config_threshold_port,
2741                 (void *)&cmd_config_threshold_keyword,
2742                 (void *)&cmd_config_threshold_all,
2743                 (void *)&cmd_config_threshold_name,
2744                 (void *)&cmd_config_threshold_value,
2745                 NULL,
2746         },
2747 };
2748
2749 /* *** stop *** */
2750 struct cmd_stop_result {
2751         cmdline_fixed_string_t stop;
2752 };
2753
2754 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2755                             __attribute__((unused)) struct cmdline *cl,
2756                             __attribute__((unused)) void *data)
2757 {
2758         stop_packet_forwarding();
2759 }
2760
2761 cmdline_parse_token_string_t cmd_stop_stop =
2762         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2763
2764 cmdline_parse_inst_t cmd_stop = {
2765         .f = cmd_stop_parsed,
2766         .data = NULL,
2767         .help_str = "stop: Stop packet forwarding",
2768         .tokens = {
2769                 (void *)&cmd_stop_stop,
2770                 NULL,
2771         },
2772 };
2773
2774 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2775
2776 unsigned int
2777 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2778                 unsigned int *parsed_items, int check_unique_values)
2779 {
2780         unsigned int nb_item;
2781         unsigned int value;
2782         unsigned int i;
2783         unsigned int j;
2784         int value_ok;
2785         char c;
2786
2787         /*
2788          * First parse all items in the list and store their value.
2789          */
2790         value = 0;
2791         nb_item = 0;
2792         value_ok = 0;
2793         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2794                 c = str[i];
2795                 if ((c >= '0') && (c <= '9')) {
2796                         value = (unsigned int) (value * 10 + (c - '0'));
2797                         value_ok = 1;
2798                         continue;
2799                 }
2800                 if (c != ',') {
2801                         printf("character %c is not a decimal digit\n", c);
2802                         return 0;
2803                 }
2804                 if (! value_ok) {
2805                         printf("No valid value before comma\n");
2806                         return 0;
2807                 }
2808                 if (nb_item < max_items) {
2809                         parsed_items[nb_item] = value;
2810                         value_ok = 0;
2811                         value = 0;
2812                 }
2813                 nb_item++;
2814         }
2815         if (nb_item >= max_items) {
2816                 printf("Number of %s = %u > %u (maximum items)\n",
2817                        item_name, nb_item + 1, max_items);
2818                 return 0;
2819         }
2820         parsed_items[nb_item++] = value;
2821         if (! check_unique_values)
2822                 return nb_item;
2823
2824         /*
2825          * Then, check that all values in the list are differents.
2826          * No optimization here...
2827          */
2828         for (i = 0; i < nb_item; i++) {
2829                 for (j = i + 1; j < nb_item; j++) {
2830                         if (parsed_items[j] == parsed_items[i]) {
2831                                 printf("duplicated %s %u at index %u and %u\n",
2832                                        item_name, parsed_items[i], i, j);
2833                                 return 0;
2834                         }
2835                 }
2836         }
2837         return nb_item;
2838 }
2839
2840 struct cmd_set_list_result {
2841         cmdline_fixed_string_t cmd_keyword;
2842         cmdline_fixed_string_t list_name;
2843         cmdline_fixed_string_t list_of_items;
2844 };
2845
2846 static void cmd_set_list_parsed(void *parsed_result,
2847                                 __attribute__((unused)) struct cmdline *cl,
2848                                 __attribute__((unused)) void *data)
2849 {
2850         struct cmd_set_list_result *res;
2851         union {
2852                 unsigned int lcorelist[RTE_MAX_LCORE];
2853                 unsigned int portlist[RTE_MAX_ETHPORTS];
2854         } parsed_items;
2855         unsigned int nb_item;
2856
2857         if (test_done == 0) {
2858                 printf("Please stop forwarding first\n");
2859                 return;
2860         }
2861
2862         res = parsed_result;
2863         if (!strcmp(res->list_name, "corelist")) {
2864                 nb_item = parse_item_list(res->list_of_items, "core",
2865                                           RTE_MAX_LCORE,
2866                                           parsed_items.lcorelist, 1);
2867                 if (nb_item > 0) {
2868                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2869                         fwd_config_setup();
2870                 }
2871                 return;
2872         }
2873         if (!strcmp(res->list_name, "portlist")) {
2874                 nb_item = parse_item_list(res->list_of_items, "port",
2875                                           RTE_MAX_ETHPORTS,
2876                                           parsed_items.portlist, 1);
2877                 if (nb_item > 0) {
2878                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2879                         fwd_config_setup();
2880                 }
2881         }
2882 }
2883
2884 cmdline_parse_token_string_t cmd_set_list_keyword =
2885         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2886                                  "set");
2887 cmdline_parse_token_string_t cmd_set_list_name =
2888         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2889                                  "corelist#portlist");
2890 cmdline_parse_token_string_t cmd_set_list_of_items =
2891         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2892                                  NULL);
2893
2894 cmdline_parse_inst_t cmd_set_fwd_list = {
2895         .f = cmd_set_list_parsed,
2896         .data = NULL,
2897         .help_str = "set corelist|portlist <list0[,list1]*>",
2898         .tokens = {
2899                 (void *)&cmd_set_list_keyword,
2900                 (void *)&cmd_set_list_name,
2901                 (void *)&cmd_set_list_of_items,
2902                 NULL,
2903         },
2904 };
2905
2906 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2907
2908 struct cmd_setmask_result {
2909         cmdline_fixed_string_t set;
2910         cmdline_fixed_string_t mask;
2911         uint64_t hexavalue;
2912 };
2913
2914 static void cmd_set_mask_parsed(void *parsed_result,
2915                                 __attribute__((unused)) struct cmdline *cl,
2916                                 __attribute__((unused)) void *data)
2917 {
2918         struct cmd_setmask_result *res = parsed_result;
2919
2920         if (test_done == 0) {
2921                 printf("Please stop forwarding first\n");
2922                 return;
2923         }
2924         if (!strcmp(res->mask, "coremask")) {
2925                 set_fwd_lcores_mask(res->hexavalue);
2926                 fwd_config_setup();
2927         } else if (!strcmp(res->mask, "portmask")) {
2928                 set_fwd_ports_mask(res->hexavalue);
2929                 fwd_config_setup();
2930         }
2931 }
2932
2933 cmdline_parse_token_string_t cmd_setmask_set =
2934         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2935 cmdline_parse_token_string_t cmd_setmask_mask =
2936         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2937                                  "coremask#portmask");
2938 cmdline_parse_token_num_t cmd_setmask_value =
2939         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2940
2941 cmdline_parse_inst_t cmd_set_fwd_mask = {
2942         .f = cmd_set_mask_parsed,
2943         .data = NULL,
2944         .help_str = "set coremask|portmask <hexadecimal value>",
2945         .tokens = {
2946                 (void *)&cmd_setmask_set,
2947                 (void *)&cmd_setmask_mask,
2948                 (void *)&cmd_setmask_value,
2949                 NULL,
2950         },
2951 };
2952
2953 /*
2954  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2955  */
2956 struct cmd_set_result {
2957         cmdline_fixed_string_t set;
2958         cmdline_fixed_string_t what;
2959         uint16_t value;
2960 };
2961
2962 static void cmd_set_parsed(void *parsed_result,
2963                            __attribute__((unused)) struct cmdline *cl,
2964                            __attribute__((unused)) void *data)
2965 {
2966         struct cmd_set_result *res = parsed_result;
2967         if (!strcmp(res->what, "nbport")) {
2968                 set_fwd_ports_number(res->value);
2969                 fwd_config_setup();
2970         } else if (!strcmp(res->what, "nbcore")) {
2971                 set_fwd_lcores_number(res->value);
2972                 fwd_config_setup();
2973         } else if (!strcmp(res->what, "burst"))
2974                 set_nb_pkt_per_burst(res->value);
2975         else if (!strcmp(res->what, "verbose"))
2976                 set_verbose_level(res->value);
2977 }
2978
2979 cmdline_parse_token_string_t cmd_set_set =
2980         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2981 cmdline_parse_token_string_t cmd_set_what =
2982         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2983                                  "nbport#nbcore#burst#verbose");
2984 cmdline_parse_token_num_t cmd_set_value =
2985         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2986
2987 cmdline_parse_inst_t cmd_set_numbers = {
2988         .f = cmd_set_parsed,
2989         .data = NULL,
2990         .help_str = "set nbport|nbcore|burst|verbose <value>",
2991         .tokens = {
2992                 (void *)&cmd_set_set,
2993                 (void *)&cmd_set_what,
2994                 (void *)&cmd_set_value,
2995                 NULL,
2996         },
2997 };
2998
2999 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3000
3001 struct cmd_set_txpkts_result {
3002         cmdline_fixed_string_t cmd_keyword;
3003         cmdline_fixed_string_t txpkts;
3004         cmdline_fixed_string_t seg_lengths;
3005 };
3006
3007 static void
3008 cmd_set_txpkts_parsed(void *parsed_result,
3009                       __attribute__((unused)) struct cmdline *cl,
3010                       __attribute__((unused)) void *data)
3011 {
3012         struct cmd_set_txpkts_result *res;
3013         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3014         unsigned int nb_segs;
3015
3016         res = parsed_result;
3017         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3018                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3019         if (nb_segs > 0)
3020                 set_tx_pkt_segments(seg_lengths, nb_segs);
3021 }
3022
3023 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3024         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3025                                  cmd_keyword, "set");
3026 cmdline_parse_token_string_t cmd_set_txpkts_name =
3027         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3028                                  txpkts, "txpkts");
3029 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3030         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3031                                  seg_lengths, NULL);
3032
3033 cmdline_parse_inst_t cmd_set_txpkts = {
3034         .f = cmd_set_txpkts_parsed,
3035         .data = NULL,
3036         .help_str = "set txpkts <len0[,len1]*>",
3037         .tokens = {
3038                 (void *)&cmd_set_txpkts_keyword,
3039                 (void *)&cmd_set_txpkts_name,
3040                 (void *)&cmd_set_txpkts_lengths,
3041                 NULL,
3042         },
3043 };
3044
3045 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3046
3047 struct cmd_set_txsplit_result {
3048         cmdline_fixed_string_t cmd_keyword;
3049         cmdline_fixed_string_t txsplit;
3050         cmdline_fixed_string_t mode;
3051 };
3052
3053 static void
3054 cmd_set_txsplit_parsed(void *parsed_result,
3055                       __attribute__((unused)) struct cmdline *cl,
3056                       __attribute__((unused)) void *data)
3057 {
3058         struct cmd_set_txsplit_result *res;
3059
3060         res = parsed_result;
3061         set_tx_pkt_split(res->mode);
3062 }
3063
3064 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3065         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3066                                  cmd_keyword, "set");
3067 cmdline_parse_token_string_t cmd_set_txsplit_name =
3068         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3069                                  txsplit, "txsplit");
3070 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3071         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3072                                  mode, NULL);
3073
3074 cmdline_parse_inst_t cmd_set_txsplit = {
3075         .f = cmd_set_txsplit_parsed,
3076         .data = NULL,
3077         .help_str = "set txsplit on|off|rand",
3078         .tokens = {
3079                 (void *)&cmd_set_txsplit_keyword,
3080                 (void *)&cmd_set_txsplit_name,
3081                 (void *)&cmd_set_txsplit_mode,
3082                 NULL,
3083         },
3084 };
3085
3086 /* *** CONFIG TX QUEUE FLAGS *** */
3087
3088 struct cmd_config_txqflags_result {
3089         cmdline_fixed_string_t port;
3090         cmdline_fixed_string_t config;
3091         cmdline_fixed_string_t all;
3092         cmdline_fixed_string_t what;
3093         int32_t hexvalue;
3094 };
3095
3096 static void cmd_config_txqflags_parsed(void *parsed_result,
3097                                 __attribute__((unused)) struct cmdline *cl,
3098                                 __attribute__((unused)) void *data)
3099 {
3100         struct cmd_config_txqflags_result *res = parsed_result;
3101
3102         if (!all_ports_stopped()) {
3103                 printf("Please stop all ports first\n");
3104                 return;
3105         }
3106
3107         if (strcmp(res->what, "txqflags")) {
3108                 printf("Unknown parameter\n");
3109                 return;
3110         }
3111
3112         if (res->hexvalue >= 0) {
3113                 txq_flags = res->hexvalue;
3114         } else {
3115                 printf("txqflags must be >= 0\n");
3116                 return;
3117         }
3118
3119         init_port_config();
3120
3121         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3122 }
3123
3124 cmdline_parse_token_string_t cmd_config_txqflags_port =
3125         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3126                                  "port");
3127 cmdline_parse_token_string_t cmd_config_txqflags_config =
3128         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3129                                  "config");
3130 cmdline_parse_token_string_t cmd_config_txqflags_all =
3131         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3132                                  "all");
3133 cmdline_parse_token_string_t cmd_config_txqflags_what =
3134         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3135                                  "txqflags");
3136 cmdline_parse_token_num_t cmd_config_txqflags_value =
3137         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3138                                 hexvalue, INT32);
3139
3140 cmdline_parse_inst_t cmd_config_txqflags = {
3141         .f = cmd_config_txqflags_parsed,
3142         .data = NULL,
3143         .help_str = "port config all txqflags <value>",
3144         .tokens = {
3145                 (void *)&cmd_config_txqflags_port,
3146                 (void *)&cmd_config_txqflags_config,
3147                 (void *)&cmd_config_txqflags_all,
3148                 (void *)&cmd_config_txqflags_what,
3149                 (void *)&cmd_config_txqflags_value,
3150                 NULL,
3151         },
3152 };
3153
3154 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3155 struct cmd_rx_vlan_filter_all_result {
3156         cmdline_fixed_string_t rx_vlan;
3157         cmdline_fixed_string_t what;
3158         cmdline_fixed_string_t all;
3159         portid_t port_id;
3160 };
3161
3162 static void
3163 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3164                               __attribute__((unused)) struct cmdline *cl,
3165                               __attribute__((unused)) void *data)
3166 {
3167         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3168
3169         if (!strcmp(res->what, "add"))
3170                 rx_vlan_all_filter_set(res->port_id, 1);
3171         else
3172                 rx_vlan_all_filter_set(res->port_id, 0);
3173 }
3174
3175 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3176         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3177                                  rx_vlan, "rx_vlan");
3178 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3179         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3180                                  what, "add#rm");
3181 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3182         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3183                                  all, "all");
3184 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3185         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3186                               port_id, UINT16);
3187
3188 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3189         .f = cmd_rx_vlan_filter_all_parsed,
3190         .data = NULL,
3191         .help_str = "rx_vlan add|rm all <port_id>: "
3192                 "Add/Remove all identifiers to/from the set of VLAN "
3193                 "identifiers filtered by a port",
3194         .tokens = {
3195                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3196                 (void *)&cmd_rx_vlan_filter_all_what,
3197                 (void *)&cmd_rx_vlan_filter_all_all,
3198                 (void *)&cmd_rx_vlan_filter_all_portid,
3199                 NULL,
3200         },
3201 };
3202
3203 /* *** VLAN OFFLOAD SET ON A PORT *** */
3204 struct cmd_vlan_offload_result {
3205         cmdline_fixed_string_t vlan;
3206         cmdline_fixed_string_t set;
3207         cmdline_fixed_string_t vlan_type;
3208         cmdline_fixed_string_t what;
3209         cmdline_fixed_string_t on;
3210         cmdline_fixed_string_t port_id;
3211 };
3212
3213 static void
3214 cmd_vlan_offload_parsed(void *parsed_result,
3215                           __attribute__((unused)) struct cmdline *cl,
3216                           __attribute__((unused)) void *data)
3217 {
3218         int on;
3219         struct cmd_vlan_offload_result *res = parsed_result;
3220         char *str;
3221         int i, len = 0;
3222         portid_t port_id = 0;
3223         unsigned int tmp;
3224
3225         str = res->port_id;
3226         len = strnlen(str, STR_TOKEN_SIZE);
3227         i = 0;
3228         /* Get port_id first */
3229         while(i < len){
3230                 if(str[i] == ',')
3231                         break;
3232
3233                 i++;
3234         }
3235         str[i]='\0';
3236         tmp = strtoul(str, NULL, 0);
3237         /* If port_id greater that what portid_t can represent, return */
3238         if(tmp >= RTE_MAX_ETHPORTS)
3239                 return;
3240         port_id = (portid_t)tmp;
3241
3242         if (!strcmp(res->on, "on"))
3243                 on = 1;
3244         else
3245                 on = 0;
3246
3247         if (!strcmp(res->what, "strip"))
3248                 rx_vlan_strip_set(port_id,  on);
3249         else if(!strcmp(res->what, "stripq")){
3250                 uint16_t queue_id = 0;
3251
3252                 /* No queue_id, return */
3253                 if(i + 1 >= len) {
3254                         printf("must specify (port,queue_id)\n");
3255                         return;
3256                 }
3257                 tmp = strtoul(str + i + 1, NULL, 0);
3258                 /* If queue_id greater that what 16-bits can represent, return */
3259                 if(tmp > 0xffff)
3260                         return;
3261
3262                 queue_id = (uint16_t)tmp;
3263                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3264         }
3265         else if (!strcmp(res->what, "filter"))
3266                 rx_vlan_filter_set(port_id, on);
3267         else
3268                 vlan_extend_set(port_id, on);
3269
3270         return;
3271 }
3272
3273 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3274         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3275                                  vlan, "vlan");
3276 cmdline_parse_token_string_t cmd_vlan_offload_set =
3277         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3278                                  set, "set");
3279 cmdline_parse_token_string_t cmd_vlan_offload_what =
3280         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3281                                  what, "strip#filter#qinq#stripq");
3282 cmdline_parse_token_string_t cmd_vlan_offload_on =
3283         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3284                               on, "on#off");
3285 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3286         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3287                               port_id, NULL);
3288
3289 cmdline_parse_inst_t cmd_vlan_offload = {
3290         .f = cmd_vlan_offload_parsed,
3291         .data = NULL,
3292         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3293                 "<port_id[,queue_id]>: "
3294                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3295         .tokens = {
3296                 (void *)&cmd_vlan_offload_vlan,
3297                 (void *)&cmd_vlan_offload_set,
3298                 (void *)&cmd_vlan_offload_what,
3299                 (void *)&cmd_vlan_offload_on,
3300                 (void *)&cmd_vlan_offload_portid,
3301                 NULL,
3302         },
3303 };
3304
3305 /* *** VLAN TPID SET ON A PORT *** */
3306 struct cmd_vlan_tpid_result {
3307         cmdline_fixed_string_t vlan;
3308         cmdline_fixed_string_t set;
3309         cmdline_fixed_string_t vlan_type;
3310         cmdline_fixed_string_t what;
3311         uint16_t tp_id;
3312         portid_t port_id;
3313 };
3314
3315 static void
3316 cmd_vlan_tpid_parsed(void *parsed_result,
3317                           __attribute__((unused)) struct cmdline *cl,
3318                           __attribute__((unused)) void *data)
3319 {
3320         struct cmd_vlan_tpid_result *res = parsed_result;
3321         enum rte_vlan_type vlan_type;
3322
3323         if (!strcmp(res->vlan_type, "inner"))
3324                 vlan_type = ETH_VLAN_TYPE_INNER;
3325         else if (!strcmp(res->vlan_type, "outer"))
3326                 vlan_type = ETH_VLAN_TYPE_OUTER;
3327         else {
3328                 printf("Unknown vlan type\n");
3329                 return;
3330         }
3331         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3332 }
3333
3334 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3335         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3336                                  vlan, "vlan");
3337 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3338         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3339                                  set, "set");
3340 cmdline_parse_token_string_t cmd_vlan_type =
3341         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3342                                  vlan_type, "inner#outer");
3343 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3344         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3345                                  what, "tpid");
3346 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3347         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3348                               tp_id, UINT16);
3349 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3350         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3351                               port_id, UINT8);
3352
3353 cmdline_parse_inst_t cmd_vlan_tpid = {
3354         .f = cmd_vlan_tpid_parsed,
3355         .data = NULL,
3356         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3357                 "Set the VLAN Ether type",
3358         .tokens = {
3359                 (void *)&cmd_vlan_tpid_vlan,
3360                 (void *)&cmd_vlan_tpid_set,
3361                 (void *)&cmd_vlan_type,
3362                 (void *)&cmd_vlan_tpid_what,
3363                 (void *)&cmd_vlan_tpid_tpid,
3364                 (void *)&cmd_vlan_tpid_portid,
3365                 NULL,
3366         },
3367 };
3368
3369 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3370 struct cmd_rx_vlan_filter_result {
3371         cmdline_fixed_string_t rx_vlan;
3372         cmdline_fixed_string_t what;
3373         uint16_t vlan_id;
3374         portid_t port_id;
3375 };
3376
3377 static void
3378 cmd_rx_vlan_filter_parsed(void *parsed_result,
3379                           __attribute__((unused)) struct cmdline *cl,
3380                           __attribute__((unused)) void *data)
3381 {
3382         struct cmd_rx_vlan_filter_result *res = parsed_result;
3383
3384         if (!strcmp(res->what, "add"))
3385                 rx_vft_set(res->port_id, res->vlan_id, 1);
3386         else
3387                 rx_vft_set(res->port_id, res->vlan_id, 0);
3388 }
3389
3390 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3391         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3392                                  rx_vlan, "rx_vlan");
3393 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3394         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3395                                  what, "add#rm");
3396 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3397         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3398                               vlan_id, UINT16);
3399 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3400         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3401                               port_id, UINT16);
3402
3403 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3404         .f = cmd_rx_vlan_filter_parsed,
3405         .data = NULL,
3406         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3407                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3408                 "identifiers filtered by a port",
3409         .tokens = {
3410                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3411                 (void *)&cmd_rx_vlan_filter_what,
3412                 (void *)&cmd_rx_vlan_filter_vlanid,
3413                 (void *)&cmd_rx_vlan_filter_portid,
3414                 NULL,
3415         },
3416 };
3417
3418 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3419 struct cmd_tx_vlan_set_result {
3420         cmdline_fixed_string_t tx_vlan;
3421         cmdline_fixed_string_t set;
3422         portid_t port_id;
3423         uint16_t vlan_id;
3424 };
3425
3426 static void
3427 cmd_tx_vlan_set_parsed(void *parsed_result,
3428                        __attribute__((unused)) struct cmdline *cl,
3429                        __attribute__((unused)) void *data)
3430 {
3431         struct cmd_tx_vlan_set_result *res = parsed_result;
3432
3433         tx_vlan_set(res->port_id, res->vlan_id);
3434 }
3435
3436 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3437         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3438                                  tx_vlan, "tx_vlan");
3439 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3440         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3441                                  set, "set");
3442 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3443         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3444                               port_id, UINT16);
3445 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3446         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3447                               vlan_id, UINT16);
3448
3449 cmdline_parse_inst_t cmd_tx_vlan_set = {
3450         .f = cmd_tx_vlan_set_parsed,
3451         .data = NULL,
3452         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3453                 "Enable hardware insertion of a single VLAN header "
3454                 "with a given TAG Identifier in packets sent on a port",
3455         .tokens = {
3456                 (void *)&cmd_tx_vlan_set_tx_vlan,
3457                 (void *)&cmd_tx_vlan_set_set,
3458                 (void *)&cmd_tx_vlan_set_portid,
3459                 (void *)&cmd_tx_vlan_set_vlanid,
3460                 NULL,
3461         },
3462 };
3463
3464 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3465 struct cmd_tx_vlan_set_qinq_result {
3466         cmdline_fixed_string_t tx_vlan;
3467         cmdline_fixed_string_t set;
3468         portid_t port_id;
3469         uint16_t vlan_id;
3470         uint16_t vlan_id_outer;
3471 };
3472
3473 static void
3474 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3475                             __attribute__((unused)) struct cmdline *cl,
3476                             __attribute__((unused)) void *data)
3477 {
3478         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3479
3480         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3481 }
3482
3483 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3484         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3485                 tx_vlan, "tx_vlan");
3486 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3488                 set, "set");
3489 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3490         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3491                 port_id, UINT16);
3492 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3494                 vlan_id, UINT16);
3495 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3496         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3497                 vlan_id_outer, UINT16);
3498
3499 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3500         .f = cmd_tx_vlan_set_qinq_parsed,
3501         .data = NULL,
3502         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3503                 "Enable hardware insertion of double VLAN header "
3504                 "with given TAG Identifiers in packets sent on a port",
3505         .tokens = {
3506                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3507                 (void *)&cmd_tx_vlan_set_qinq_set,
3508                 (void *)&cmd_tx_vlan_set_qinq_portid,
3509                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3510                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3511                 NULL,
3512         },
3513 };
3514
3515 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3516 struct cmd_tx_vlan_set_pvid_result {
3517         cmdline_fixed_string_t tx_vlan;
3518         cmdline_fixed_string_t set;
3519         cmdline_fixed_string_t pvid;
3520         portid_t port_id;
3521         uint16_t vlan_id;
3522         cmdline_fixed_string_t mode;
3523 };
3524
3525 static void
3526 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3527                             __attribute__((unused)) struct cmdline *cl,
3528                             __attribute__((unused)) void *data)
3529 {
3530         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3531
3532         if (strcmp(res->mode, "on") == 0)
3533                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3534         else
3535                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3536 }
3537
3538 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3539         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3540                                  tx_vlan, "tx_vlan");
3541 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3542         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3543                                  set, "set");
3544 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3545         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3546                                  pvid, "pvid");
3547 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3548         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3549                              port_id, UINT16);
3550 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3551         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3552                               vlan_id, UINT16);
3553 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3554         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3555                                  mode, "on#off");
3556
3557 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3558         .f = cmd_tx_vlan_set_pvid_parsed,
3559         .data = NULL,
3560         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3561         .tokens = {
3562                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3563                 (void *)&cmd_tx_vlan_set_pvid_set,
3564                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3565                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3566                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3567                 (void *)&cmd_tx_vlan_set_pvid_mode,
3568                 NULL,
3569         },
3570 };
3571
3572 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3573 struct cmd_tx_vlan_reset_result {
3574         cmdline_fixed_string_t tx_vlan;
3575         cmdline_fixed_string_t reset;
3576         portid_t port_id;
3577 };
3578
3579 static void
3580 cmd_tx_vlan_reset_parsed(void *parsed_result,
3581                          __attribute__((unused)) struct cmdline *cl,
3582                          __attribute__((unused)) void *data)
3583 {
3584         struct cmd_tx_vlan_reset_result *res = parsed_result;
3585
3586         tx_vlan_reset(res->port_id);
3587 }
3588
3589 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3590         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3591                                  tx_vlan, "tx_vlan");
3592 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3593         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3594                                  reset, "reset");
3595 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3596         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3597                               port_id, UINT16);
3598
3599 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3600         .f = cmd_tx_vlan_reset_parsed,
3601         .data = NULL,
3602         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3603                 "VLAN header in packets sent on a port",
3604         .tokens = {
3605                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3606                 (void *)&cmd_tx_vlan_reset_reset,
3607                 (void *)&cmd_tx_vlan_reset_portid,
3608                 NULL,
3609         },
3610 };
3611
3612
3613 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3614 struct cmd_csum_result {
3615         cmdline_fixed_string_t csum;
3616         cmdline_fixed_string_t mode;
3617         cmdline_fixed_string_t proto;
3618         cmdline_fixed_string_t hwsw;
3619         portid_t port_id;
3620 };
3621
3622 static void
3623 csum_show(int port_id)
3624 {
3625         struct rte_eth_dev_info dev_info;
3626         uint16_t ol_flags;
3627
3628         ol_flags = ports[port_id].tx_ol_flags;
3629         printf("Parse tunnel is %s\n",
3630                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3631         printf("IP checksum offload is %s\n",
3632                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3633         printf("UDP checksum offload is %s\n",
3634                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3635         printf("TCP checksum offload is %s\n",
3636                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3637         printf("SCTP checksum offload is %s\n",
3638                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3639         printf("Outer-Ip checksum offload is %s\n",
3640                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3641
3642         /* display warnings if configuration is not supported by the NIC */
3643         rte_eth_dev_info_get(port_id, &dev_info);
3644         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3645                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3646                 printf("Warning: hardware IP checksum enabled but not "
3647                         "supported by port %d\n", port_id);
3648         }
3649         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3650                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3651                 printf("Warning: hardware UDP checksum enabled but not "
3652                         "supported by port %d\n", port_id);
3653         }
3654         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3655                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3656                 printf("Warning: hardware TCP checksum enabled but not "
3657                         "supported by port %d\n", port_id);
3658         }
3659         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3660                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3661                 printf("Warning: hardware SCTP checksum enabled but not "
3662                         "supported by port %d\n", port_id);
3663         }
3664         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3665                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3666                 printf("Warning: hardware outer IP checksum enabled but not "
3667                         "supported by port %d\n", port_id);
3668         }
3669 }
3670
3671 static void
3672 cmd_csum_parsed(void *parsed_result,
3673                        __attribute__((unused)) struct cmdline *cl,
3674                        __attribute__((unused)) void *data)
3675 {
3676         struct cmd_csum_result *res = parsed_result;
3677         int hw = 0;
3678         uint16_t mask = 0;
3679
3680         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3681                 printf("invalid port %d\n", res->port_id);
3682                 return;
3683         }
3684
3685         if (!strcmp(res->mode, "set")) {
3686
3687                 if (!strcmp(res->hwsw, "hw"))
3688                         hw = 1;
3689
3690                 if (!strcmp(res->proto, "ip")) {
3691                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3692                 } else if (!strcmp(res->proto, "udp")) {
3693                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3694                 } else if (!strcmp(res->proto, "tcp")) {
3695                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3696                 } else if (!strcmp(res->proto, "sctp")) {
3697                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3698                 } else if (!strcmp(res->proto, "outer-ip")) {
3699                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3700                 }
3701
3702                 if (hw)
3703                         ports[res->port_id].tx_ol_flags |= mask;
3704                 else
3705                         ports[res->port_id].tx_ol_flags &= (~mask);
3706         }
3707         csum_show(res->port_id);
3708 }
3709
3710 cmdline_parse_token_string_t cmd_csum_csum =
3711         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3712                                 csum, "csum");
3713 cmdline_parse_token_string_t cmd_csum_mode =
3714         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3715                                 mode, "set");
3716 cmdline_parse_token_string_t cmd_csum_proto =
3717         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3718                                 proto, "ip#tcp#udp#sctp#outer-ip");
3719 cmdline_parse_token_string_t cmd_csum_hwsw =
3720         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3721                                 hwsw, "hw#sw");
3722 cmdline_parse_token_num_t cmd_csum_portid =
3723         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3724                                 port_id, UINT16);
3725
3726 cmdline_parse_inst_t cmd_csum_set = {
3727         .f = cmd_csum_parsed,
3728         .data = NULL,
3729         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3730                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3731                 "using csum forward engine",
3732         .tokens = {
3733                 (void *)&cmd_csum_csum,
3734                 (void *)&cmd_csum_mode,
3735                 (void *)&cmd_csum_proto,
3736                 (void *)&cmd_csum_hwsw,
3737                 (void *)&cmd_csum_portid,
3738                 NULL,
3739         },
3740 };
3741
3742 cmdline_parse_token_string_t cmd_csum_mode_show =
3743         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3744                                 mode, "show");
3745
3746 cmdline_parse_inst_t cmd_csum_show = {
3747         .f = cmd_csum_parsed,
3748         .data = NULL,
3749         .help_str = "csum show <port_id>: Show checksum offload configuration",
3750         .tokens = {
3751                 (void *)&cmd_csum_csum,
3752                 (void *)&cmd_csum_mode_show,
3753                 (void *)&cmd_csum_portid,
3754                 NULL,
3755         },
3756 };
3757
3758 /* Enable/disable tunnel parsing */
3759 struct cmd_csum_tunnel_result {
3760         cmdline_fixed_string_t csum;
3761         cmdline_fixed_string_t parse;
3762         cmdline_fixed_string_t onoff;
3763         portid_t port_id;
3764 };
3765
3766 static void
3767 cmd_csum_tunnel_parsed(void *parsed_result,
3768                        __attribute__((unused)) struct cmdline *cl,
3769                        __attribute__((unused)) void *data)
3770 {
3771         struct cmd_csum_tunnel_result *res = parsed_result;
3772
3773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3774                 return;
3775
3776         if (!strcmp(res->onoff, "on"))
3777                 ports[res->port_id].tx_ol_flags |=
3778                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3779         else
3780                 ports[res->port_id].tx_ol_flags &=
3781                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3782
3783         csum_show(res->port_id);
3784 }
3785
3786 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3787         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3788                                 csum, "csum");
3789 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3790         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3791                                 parse, "parse_tunnel");
3792 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3793         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3794                                 onoff, "on#off");
3795 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3796         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3797                                 port_id, UINT16);
3798
3799 cmdline_parse_inst_t cmd_csum_tunnel = {
3800         .f = cmd_csum_tunnel_parsed,
3801         .data = NULL,
3802         .help_str = "csum parse_tunnel on|off <port_id>: "
3803                 "Enable/Disable parsing of tunnels for csum engine",
3804         .tokens = {
3805                 (void *)&cmd_csum_tunnel_csum,
3806                 (void *)&cmd_csum_tunnel_parse,
3807                 (void *)&cmd_csum_tunnel_onoff,
3808                 (void *)&cmd_csum_tunnel_portid,
3809                 NULL,
3810         },
3811 };
3812
3813 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3814 struct cmd_tso_set_result {
3815         cmdline_fixed_string_t tso;
3816         cmdline_fixed_string_t mode;
3817         uint16_t tso_segsz;
3818         portid_t port_id;
3819 };
3820
3821 static void
3822 cmd_tso_set_parsed(void *parsed_result,
3823                        __attribute__((unused)) struct cmdline *cl,
3824                        __attribute__((unused)) void *data)
3825 {
3826         struct cmd_tso_set_result *res = parsed_result;
3827         struct rte_eth_dev_info dev_info;
3828
3829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3830                 return;
3831
3832         if (!strcmp(res->mode, "set"))
3833                 ports[res->port_id].tso_segsz = res->tso_segsz;
3834
3835         if (ports[res->port_id].tso_segsz == 0)
3836                 printf("TSO for non-tunneled packets is disabled\n");
3837         else
3838                 printf("TSO segment size for non-tunneled packets is %d\n",
3839                         ports[res->port_id].tso_segsz);
3840
3841         /* display warnings if configuration is not supported by the NIC */
3842         rte_eth_dev_info_get(res->port_id, &dev_info);
3843         if ((ports[res->port_id].tso_segsz != 0) &&
3844                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3845                 printf("Warning: TSO enabled but not "
3846                         "supported by port %d\n", res->port_id);
3847         }
3848 }
3849
3850 cmdline_parse_token_string_t cmd_tso_set_tso =
3851         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3852                                 tso, "tso");
3853 cmdline_parse_token_string_t cmd_tso_set_mode =
3854         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3855                                 mode, "set");
3856 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3857         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3858                                 tso_segsz, UINT16);
3859 cmdline_parse_token_num_t cmd_tso_set_portid =
3860         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3861                                 port_id, UINT16);
3862
3863 cmdline_parse_inst_t cmd_tso_set = {
3864         .f = cmd_tso_set_parsed,
3865         .data = NULL,
3866         .help_str = "tso set <tso_segsz> <port_id>: "
3867                 "Set TSO segment size of non-tunneled packets for csum engine "
3868                 "(0 to disable)",
3869         .tokens = {
3870                 (void *)&cmd_tso_set_tso,
3871                 (void *)&cmd_tso_set_mode,
3872                 (void *)&cmd_tso_set_tso_segsz,
3873                 (void *)&cmd_tso_set_portid,
3874                 NULL,
3875         },
3876 };
3877
3878 cmdline_parse_token_string_t cmd_tso_show_mode =
3879         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3880                                 mode, "show");
3881
3882
3883 cmdline_parse_inst_t cmd_tso_show = {
3884         .f = cmd_tso_set_parsed,
3885         .data = NULL,
3886         .help_str = "tso show <port_id>: "
3887                 "Show TSO segment size of non-tunneled packets for csum engine",
3888         .tokens = {
3889                 (void *)&cmd_tso_set_tso,
3890                 (void *)&cmd_tso_show_mode,
3891                 (void *)&cmd_tso_set_portid,
3892                 NULL,
3893         },
3894 };
3895
3896 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3897 struct cmd_tunnel_tso_set_result {
3898         cmdline_fixed_string_t tso;
3899         cmdline_fixed_string_t mode;
3900         uint16_t tso_segsz;
3901         portid_t port_id;
3902 };
3903
3904 static void
3905 check_tunnel_tso_nic_support(portid_t port_id)
3906 {
3907         struct rte_eth_dev_info dev_info;
3908
3909         rte_eth_dev_info_get(port_id, &dev_info);
3910         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3911                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3912                        "supported by port %d\n", port_id);
3913         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3914                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3915                         "supported by port %d\n", port_id);
3916         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3917                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3918                        "supported by port %d\n", port_id);
3919         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3920                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3921                        "supported by port %d\n", port_id);
3922 }
3923
3924 static void
3925 cmd_tunnel_tso_set_parsed(void *parsed_result,
3926                           __attribute__((unused)) struct cmdline *cl,
3927                           __attribute__((unused)) void *data)
3928 {
3929         struct cmd_tunnel_tso_set_result *res = parsed_result;
3930
3931         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3932                 return;
3933
3934         if (!strcmp(res->mode, "set"))
3935                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3936
3937         if (ports[res->port_id].tunnel_tso_segsz == 0)
3938                 printf("TSO for tunneled packets is disabled\n");
3939         else {
3940                 printf("TSO segment size for tunneled packets is %d\n",
3941                         ports[res->port_id].tunnel_tso_segsz);
3942
3943                 /* Below conditions are needed to make it work:
3944                  * (1) tunnel TSO is supported by the NIC;
3945                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3946                  * are recognized;
3947                  * (3) for tunneled pkts with outer L3 of IPv4,
3948                  * "csum set outer-ip" must be set to hw, because after tso,
3949                  * total_len of outer IP header is changed, and the checksum
3950                  * of outer IP header calculated by sw should be wrong; that
3951                  * is not necessary for IPv6 tunneled pkts because there's no
3952                  * checksum in IP header anymore.
3953                  */
3954                 check_tunnel_tso_nic_support(res->port_id);
3955
3956                 if (!(ports[res->port_id].tx_ol_flags &
3957                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3958                         printf("Warning: csum parse_tunnel must be set "
3959                                 "so that tunneled packets are recognized\n");
3960                 if (!(ports[res->port_id].tx_ol_flags &
3961                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3962                         printf("Warning: csum set outer-ip must be set to hw "
3963                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3964         }
3965 }
3966
3967 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3968         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3969                                 tso, "tunnel_tso");
3970 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3971         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3972                                 mode, "set");
3973 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3974         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3975                                 tso_segsz, UINT16);
3976 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3977         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3978                                 port_id, UINT16);
3979
3980 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3981         .f = cmd_tunnel_tso_set_parsed,
3982         .data = NULL,
3983         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3984                 "Set TSO segment size of tunneled packets for csum engine "
3985                 "(0 to disable)",
3986         .tokens = {
3987                 (void *)&cmd_tunnel_tso_set_tso,
3988                 (void *)&cmd_tunnel_tso_set_mode,
3989                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3990                 (void *)&cmd_tunnel_tso_set_portid,
3991                 NULL,
3992         },
3993 };
3994
3995 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3996         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3997                                 mode, "show");
3998
3999
4000 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4001         .f = cmd_tunnel_tso_set_parsed,
4002         .data = NULL,
4003         .help_str = "tunnel_tso show <port_id> "
4004                 "Show TSO segment size of tunneled packets for csum engine",
4005         .tokens = {
4006                 (void *)&cmd_tunnel_tso_set_tso,
4007                 (void *)&cmd_tunnel_tso_show_mode,
4008                 (void *)&cmd_tunnel_tso_set_portid,
4009                 NULL,
4010         },
4011 };
4012
4013 /* *** SET GRO FOR A PORT *** */
4014 struct cmd_gro_enable_result {
4015         cmdline_fixed_string_t cmd_set;
4016         cmdline_fixed_string_t cmd_port;
4017         cmdline_fixed_string_t cmd_keyword;
4018         cmdline_fixed_string_t cmd_onoff;
4019         portid_t cmd_pid;
4020 };
4021
4022 static void
4023 cmd_gro_enable_parsed(void *parsed_result,
4024                 __attribute__((unused)) struct cmdline *cl,
4025                 __attribute__((unused)) void *data)
4026 {
4027         struct cmd_gro_enable_result *res;
4028
4029         res = parsed_result;
4030         if (!strcmp(res->cmd_keyword, "gro"))
4031                 setup_gro(res->cmd_onoff, res->cmd_pid);
4032 }
4033
4034 cmdline_parse_token_string_t cmd_gro_enable_set =
4035         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4036                         cmd_set, "set");
4037 cmdline_parse_token_string_t cmd_gro_enable_port =
4038         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4039                         cmd_keyword, "port");
4040 cmdline_parse_token_num_t cmd_gro_enable_pid =
4041         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4042                         cmd_pid, UINT16);
4043 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4044         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4045                         cmd_keyword, "gro");
4046 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4047         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4048                         cmd_onoff, "on#off");
4049
4050 cmdline_parse_inst_t cmd_gro_enable = {
4051         .f = cmd_gro_enable_parsed,
4052         .data = NULL,
4053         .help_str = "set port <port_id> gro on|off",
4054         .tokens = {
4055                 (void *)&cmd_gro_enable_set,
4056                 (void *)&cmd_gro_enable_port,
4057                 (void *)&cmd_gro_enable_pid,
4058                 (void *)&cmd_gro_enable_keyword,
4059                 (void *)&cmd_gro_enable_onoff,
4060                 NULL,
4061         },
4062 };
4063
4064 /* *** DISPLAY GRO CONFIGURATION *** */
4065 struct cmd_gro_show_result {
4066         cmdline_fixed_string_t cmd_show;
4067         cmdline_fixed_string_t cmd_port;
4068         cmdline_fixed_string_t cmd_keyword;
4069         portid_t cmd_pid;
4070 };
4071
4072 static void
4073 cmd_gro_show_parsed(void *parsed_result,
4074                 __attribute__((unused)) struct cmdline *cl,
4075                 __attribute__((unused)) void *data)
4076 {
4077         struct cmd_gro_show_result *res;
4078
4079         res = parsed_result;
4080         if (!strcmp(res->cmd_keyword, "gro"))
4081                 show_gro(res->cmd_pid);
4082 }
4083
4084 cmdline_parse_token_string_t cmd_gro_show_show =
4085         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4086                         cmd_show, "show");
4087 cmdline_parse_token_string_t cmd_gro_show_port =
4088         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4089                         cmd_port, "port");
4090 cmdline_parse_token_num_t cmd_gro_show_pid =
4091         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4092                         cmd_pid, UINT16);
4093 cmdline_parse_token_string_t cmd_gro_show_keyword =
4094         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4095                         cmd_keyword, "gro");
4096
4097 cmdline_parse_inst_t cmd_gro_show = {
4098         .f = cmd_gro_show_parsed,
4099         .data = NULL,
4100         .help_str = "show port <port_id> gro",
4101         .tokens = {
4102                 (void *)&cmd_gro_show_show,
4103                 (void *)&cmd_gro_show_port,
4104                 (void *)&cmd_gro_show_pid,
4105                 (void *)&cmd_gro_show_keyword,
4106                 NULL,
4107         },
4108 };
4109
4110 /* *** SET FLUSH CYCLES FOR GRO *** */
4111 struct cmd_gro_flush_result {
4112         cmdline_fixed_string_t cmd_set;
4113         cmdline_fixed_string_t cmd_keyword;
4114         cmdline_fixed_string_t cmd_flush;
4115         uint8_t cmd_cycles;
4116 };
4117
4118 static void
4119 cmd_gro_flush_parsed(void *parsed_result,
4120                 __attribute__((unused)) struct cmdline *cl,
4121                 __attribute__((unused)) void *data)
4122 {
4123         struct cmd_gro_flush_result *res;
4124
4125         res = parsed_result;
4126         if ((!strcmp(res->cmd_keyword, "gro")) &&
4127                         (!strcmp(res->cmd_flush, "flush")))
4128                 setup_gro_flush_cycles(res->cmd_cycles);
4129 }
4130
4131 cmdline_parse_token_string_t cmd_gro_flush_set =
4132         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4133                         cmd_set, "set");
4134 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4135         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4136                         cmd_keyword, "gro");
4137 cmdline_parse_token_string_t cmd_gro_flush_flush =
4138         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4139                         cmd_flush, "flush");
4140 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4141         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4142                         cmd_cycles, UINT8);
4143
4144 cmdline_parse_inst_t cmd_gro_flush = {
4145         .f = cmd_gro_flush_parsed,
4146         .data = NULL,
4147         .help_str = "set gro flush <cycles>",
4148         .tokens = {
4149                 (void *)&cmd_gro_flush_set,
4150                 (void *)&cmd_gro_flush_keyword,
4151                 (void *)&cmd_gro_flush_flush,
4152                 (void *)&cmd_gro_flush_cycles,
4153                 NULL,
4154         },
4155 };
4156
4157 /* *** ENABLE/DISABLE GSO *** */
4158 struct cmd_gso_enable_result {
4159         cmdline_fixed_string_t cmd_set;
4160         cmdline_fixed_string_t cmd_port;
4161         cmdline_fixed_string_t cmd_keyword;
4162         cmdline_fixed_string_t cmd_mode;
4163         portid_t cmd_pid;
4164 };
4165
4166 static void
4167 cmd_gso_enable_parsed(void *parsed_result,
4168                 __attribute__((unused)) struct cmdline *cl,
4169                 __attribute__((unused)) void *data)
4170 {
4171         struct cmd_gso_enable_result *res;
4172
4173         res = parsed_result;
4174         if (!strcmp(res->cmd_keyword, "gso"))
4175                 setup_gso(res->cmd_mode, res->cmd_pid);
4176 }
4177
4178 cmdline_parse_token_string_t cmd_gso_enable_set =
4179         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4180                         cmd_set, "set");
4181 cmdline_parse_token_string_t cmd_gso_enable_port =
4182         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4183                         cmd_port, "port");
4184 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4185         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4186                         cmd_keyword, "gso");
4187 cmdline_parse_token_string_t cmd_gso_enable_mode =
4188         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4189                         cmd_mode, "on#off");
4190 cmdline_parse_token_num_t cmd_gso_enable_pid =
4191         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4192                         cmd_pid, UINT16);
4193
4194 cmdline_parse_inst_t cmd_gso_enable = {
4195         .f = cmd_gso_enable_parsed,
4196         .data = NULL,
4197         .help_str = "set port <port_id> gso on|off",
4198         .tokens = {
4199                 (void *)&cmd_gso_enable_set,
4200                 (void *)&cmd_gso_enable_port,
4201                 (void *)&cmd_gso_enable_pid,
4202                 (void *)&cmd_gso_enable_keyword,
4203                 (void *)&cmd_gso_enable_mode,
4204                 NULL,
4205         },
4206 };
4207
4208 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4209 struct cmd_gso_size_result {
4210         cmdline_fixed_string_t cmd_set;
4211         cmdline_fixed_string_t cmd_keyword;
4212         cmdline_fixed_string_t cmd_segsz;
4213         uint16_t cmd_size;
4214 };
4215
4216 static void
4217 cmd_gso_size_parsed(void *parsed_result,
4218                        __attribute__((unused)) struct cmdline *cl,
4219                        __attribute__((unused)) void *data)
4220 {
4221         struct cmd_gso_size_result *res = parsed_result;
4222
4223         if (test_done == 0) {
4224                 printf("Before setting GSO segsz, please first"
4225                                 " stop fowarding\n");
4226                 return;
4227         }
4228
4229         if (!strcmp(res->cmd_keyword, "gso") &&
4230                         !strcmp(res->cmd_segsz, "segsz")) {
4231                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4232                         printf("gso_size should be larger than %zu."
4233                                         " Please input a legal value\n",
4234                                         RTE_GSO_SEG_SIZE_MIN);
4235                 else
4236                         gso_max_segment_size = res->cmd_size;
4237         }
4238 }
4239
4240 cmdline_parse_token_string_t cmd_gso_size_set =
4241         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4242                                 cmd_set, "set");
4243 cmdline_parse_token_string_t cmd_gso_size_keyword =
4244         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4245                                 cmd_keyword, "gso");
4246 cmdline_parse_token_string_t cmd_gso_size_segsz =
4247         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4248                                 cmd_segsz, "segsz");
4249 cmdline_parse_token_num_t cmd_gso_size_size =
4250         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4251                                 cmd_size, UINT16);
4252
4253 cmdline_parse_inst_t cmd_gso_size = {
4254         .f = cmd_gso_size_parsed,
4255         .data = NULL,
4256         .help_str = "set gso segsz <length>",
4257         .tokens = {
4258                 (void *)&cmd_gso_size_set,
4259                 (void *)&cmd_gso_size_keyword,
4260                 (void *)&cmd_gso_size_segsz,
4261                 (void *)&cmd_gso_size_size,
4262                 NULL,
4263         },
4264 };
4265
4266 /* *** SHOW GSO CONFIGURATION *** */
4267 struct cmd_gso_show_result {
4268         cmdline_fixed_string_t cmd_show;
4269         cmdline_fixed_string_t cmd_port;
4270         cmdline_fixed_string_t cmd_keyword;
4271         portid_t cmd_pid;
4272 };
4273
4274 static void
4275 cmd_gso_show_parsed(void *parsed_result,
4276                        __attribute__((unused)) struct cmdline *cl,
4277                        __attribute__((unused)) void *data)
4278 {
4279         struct cmd_gso_show_result *res = parsed_result;
4280
4281         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4282                 printf("invalid port id %u\n", res->cmd_pid);
4283                 return;
4284         }
4285         if (!strcmp(res->cmd_keyword, "gso")) {
4286                 if (gso_ports[res->cmd_pid].enable) {
4287                         printf("Max GSO'd packet size: %uB\n"
4288                                         "Supported GSO types: TCP/IPv4, "
4289                                         "VxLAN with inner TCP/IPv4 packet, "
4290                                         "GRE with inner TCP/IPv4  packet\n",
4291                                         gso_max_segment_size);
4292                 } else
4293                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4294         }
4295 }
4296
4297 cmdline_parse_token_string_t cmd_gso_show_show =
4298 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4299                 cmd_show, "show");
4300 cmdline_parse_token_string_t cmd_gso_show_port =
4301 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4302                 cmd_port, "port");
4303 cmdline_parse_token_string_t cmd_gso_show_keyword =
4304         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4305                                 cmd_keyword, "gso");
4306 cmdline_parse_token_num_t cmd_gso_show_pid =
4307         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4308                                 cmd_pid, UINT16);
4309
4310 cmdline_parse_inst_t cmd_gso_show = {
4311         .f = cmd_gso_show_parsed,
4312         .data = NULL,
4313         .help_str = "show port <port_id> gso",
4314         .tokens = {
4315                 (void *)&cmd_gso_show_show,
4316                 (void *)&cmd_gso_show_port,
4317                 (void *)&cmd_gso_show_pid,
4318                 (void *)&cmd_gso_show_keyword,
4319                 NULL,
4320         },
4321 };
4322
4323 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4324 struct cmd_set_flush_rx {
4325         cmdline_fixed_string_t set;
4326         cmdline_fixed_string_t flush_rx;
4327         cmdline_fixed_string_t mode;
4328 };
4329
4330 static void
4331 cmd_set_flush_rx_parsed(void *parsed_result,
4332                 __attribute__((unused)) struct cmdline *cl,
4333                 __attribute__((unused)) void *data)
4334 {
4335         struct cmd_set_flush_rx *res = parsed_result;
4336         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4337 }
4338
4339 cmdline_parse_token_string_t cmd_setflushrx_set =
4340         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4341                         set, "set");
4342 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4343         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4344                         flush_rx, "flush_rx");
4345 cmdline_parse_token_string_t cmd_setflushrx_mode =
4346         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4347                         mode, "on#off");
4348
4349
4350 cmdline_parse_inst_t cmd_set_flush_rx = {
4351         .f = cmd_set_flush_rx_parsed,
4352         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4353         .data = NULL,
4354         .tokens = {
4355                 (void *)&cmd_setflushrx_set,
4356                 (void *)&cmd_setflushrx_flush_rx,
4357                 (void *)&cmd_setflushrx_mode,
4358                 NULL,
4359         },
4360 };
4361
4362 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4363 struct cmd_set_link_check {
4364         cmdline_fixed_string_t set;
4365         cmdline_fixed_string_t link_check;
4366         cmdline_fixed_string_t mode;
4367 };
4368
4369 static void
4370 cmd_set_link_check_parsed(void *parsed_result,
4371                 __attribute__((unused)) struct cmdline *cl,
4372                 __attribute__((unused)) void *data)
4373 {
4374         struct cmd_set_link_check *res = parsed_result;
4375         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4376 }
4377
4378 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4379         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4380                         set, "set");
4381 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4383                         link_check, "link_check");
4384 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4385         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4386                         mode, "on#off");
4387
4388
4389 cmdline_parse_inst_t cmd_set_link_check = {
4390         .f = cmd_set_link_check_parsed,
4391         .help_str = "set link_check on|off: Enable/Disable link status check "
4392                     "when starting/stopping a port",
4393         .data = NULL,
4394         .tokens = {
4395                 (void *)&cmd_setlinkcheck_set,
4396                 (void *)&cmd_setlinkcheck_link_check,
4397                 (void *)&cmd_setlinkcheck_mode,
4398                 NULL,
4399         },
4400 };
4401
4402 /* *** SET NIC BYPASS MODE *** */
4403 struct cmd_set_bypass_mode_result {
4404         cmdline_fixed_string_t set;
4405         cmdline_fixed_string_t bypass;
4406         cmdline_fixed_string_t mode;
4407         cmdline_fixed_string_t value;
4408         portid_t port_id;
4409 };
4410
4411 static void
4412 cmd_set_bypass_mode_parsed(void *parsed_result,
4413                 __attribute__((unused)) struct cmdline *cl,
4414                 __attribute__((unused)) void *data)
4415 {
4416         struct cmd_set_bypass_mode_result *res = parsed_result;
4417         portid_t port_id = res->port_id;
4418         int32_t rc = -EINVAL;
4419
4420 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4421         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4422
4423         if (!strcmp(res->value, "bypass"))
4424                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4425         else if (!strcmp(res->value, "isolate"))
4426                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4427         else
4428                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4429
4430         /* Set the bypass mode for the relevant port. */
4431         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4432 #endif
4433         if (rc != 0)
4434                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4435 }
4436
4437 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4438         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4439                         set, "set");
4440 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4441         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4442                         bypass, "bypass");
4443 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4444         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4445                         mode, "mode");
4446 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4447         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4448                         value, "normal#bypass#isolate");
4449 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4450         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4451                                 port_id, UINT16);
4452
4453 cmdline_parse_inst_t cmd_set_bypass_mode = {
4454         .f = cmd_set_bypass_mode_parsed,
4455         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4456                     "Set the NIC bypass mode for port_id",
4457         .data = NULL,
4458         .tokens = {
4459                 (void *)&cmd_setbypass_mode_set,
4460                 (void *)&cmd_setbypass_mode_bypass,
4461                 (void *)&cmd_setbypass_mode_mode,
4462                 (void *)&cmd_setbypass_mode_value,
4463                 (void *)&cmd_setbypass_mode_port,
4464                 NULL,
4465         },
4466 };
4467
4468 /* *** SET NIC BYPASS EVENT *** */
4469 struct cmd_set_bypass_event_result {
4470         cmdline_fixed_string_t set;
4471         cmdline_fixed_string_t bypass;
4472         cmdline_fixed_string_t event;
4473         cmdline_fixed_string_t event_value;
4474         cmdline_fixed_string_t mode;
4475         cmdline_fixed_string_t mode_value;
4476         portid_t port_id;
4477 };
4478
4479 static void
4480 cmd_set_bypass_event_parsed(void *parsed_result,
4481                 __attribute__((unused)) struct cmdline *cl,
4482                 __attribute__((unused)) void *data)
4483 {
4484         int32_t rc = -EINVAL;
4485         struct cmd_set_bypass_event_result *res = parsed_result;
4486         portid_t port_id = res->port_id;
4487
4488 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4489         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4490         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4491
4492         if (!strcmp(res->event_value, "timeout"))
4493                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4494         else if (!strcmp(res->event_value, "os_on"))
4495                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4496         else if (!strcmp(res->event_value, "os_off"))
4497                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4498         else if (!strcmp(res->event_value, "power_on"))
4499                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4500         else if (!strcmp(res->event_value, "power_off"))
4501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4502         else
4503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4504
4505         if (!strcmp(res->mode_value, "bypass"))
4506                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4507         else if (!strcmp(res->mode_value, "isolate"))
4508                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4509         else
4510                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4511
4512         /* Set the watchdog timeout. */
4513         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4514
4515                 rc = -EINVAL;
4516                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4517                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4518                                                            bypass_timeout);
4519                 }
4520                 if (rc != 0) {
4521                         printf("Failed to set timeout value %u "
4522                         "for port %d, errto code: %d.\n",
4523                         bypass_timeout, port_id, rc);
4524                 }
4525         }
4526
4527         /* Set the bypass event to transition to bypass mode. */
4528         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4529                                               bypass_mode);
4530 #endif
4531
4532         if (rc != 0)
4533                 printf("\t Failed to set bypass event for port = %d.\n",
4534                        port_id);
4535 }
4536
4537 cmdline_parse_token_string_t cmd_setbypass_event_set =
4538         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4539                         set, "set");
4540 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4542                         bypass, "bypass");
4543 cmdline_parse_token_string_t cmd_setbypass_event_event =
4544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4545                         event, "event");
4546 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4548                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4549 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4551                         mode, "mode");
4552 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4554                         mode_value, "normal#bypass#isolate");
4555 cmdline_parse_token_num_t cmd_setbypass_event_port =
4556         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4557                                 port_id, UINT16);
4558
4559 cmdline_parse_inst_t cmd_set_bypass_event = {
4560         .f = cmd_set_bypass_event_parsed,
4561         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4562                 "power_off mode normal|bypass|isolate <port_id>: "
4563                 "Set the NIC bypass event mode for port_id",
4564         .data = NULL,
4565         .tokens = {
4566                 (void *)&cmd_setbypass_event_set,
4567                 (void *)&cmd_setbypass_event_bypass,
4568                 (void *)&cmd_setbypass_event_event,
4569                 (void *)&cmd_setbypass_event_event_value,
4570                 (void *)&cmd_setbypass_event_mode,
4571                 (void *)&cmd_setbypass_event_mode_value,
4572                 (void *)&cmd_setbypass_event_port,
4573                 NULL,
4574         },
4575 };
4576
4577
4578 /* *** SET NIC BYPASS TIMEOUT *** */
4579 struct cmd_set_bypass_timeout_result {
4580         cmdline_fixed_string_t set;
4581         cmdline_fixed_string_t bypass;
4582         cmdline_fixed_string_t timeout;
4583         cmdline_fixed_string_t value;
4584 };
4585
4586 static void
4587 cmd_set_bypass_timeout_parsed(void *parsed_result,
4588                 __attribute__((unused)) struct cmdline *cl,
4589                 __attribute__((unused)) void *data)
4590 {
4591         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4592
4593 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4594         if (!strcmp(res->value, "1.5"))
4595                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4596         else if (!strcmp(res->value, "2"))
4597                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4598         else if (!strcmp(res->value, "3"))
4599                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4600         else if (!strcmp(res->value, "4"))
4601                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4602         else if (!strcmp(res->value, "8"))
4603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4604         else if (!strcmp(res->value, "16"))
4605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4606         else if (!strcmp(res->value, "32"))
4607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4608         else
4609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4610 #endif
4611 }
4612
4613 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4614         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4615                         set, "set");
4616 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4617         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4618                         bypass, "bypass");
4619 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4620         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4621                         timeout, "timeout");
4622 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4623         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4624                         value, "0#1.5#2#3#4#8#16#32");
4625
4626 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4627         .f = cmd_set_bypass_timeout_parsed,
4628         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4629                 "Set the NIC bypass watchdog timeout in seconds",
4630         .data = NULL,
4631         .tokens = {
4632                 (void *)&cmd_setbypass_timeout_set,
4633                 (void *)&cmd_setbypass_timeout_bypass,
4634                 (void *)&cmd_setbypass_timeout_timeout,
4635                 (void *)&cmd_setbypass_timeout_value,
4636                 NULL,
4637         },
4638 };
4639
4640 /* *** SHOW NIC BYPASS MODE *** */
4641 struct cmd_show_bypass_config_result {
4642         cmdline_fixed_string_t show;
4643         cmdline_fixed_string_t bypass;
4644         cmdline_fixed_string_t config;
4645         portid_t port_id;
4646 };
4647
4648 static void
4649 cmd_show_bypass_config_parsed(void *parsed_result,
4650                 __attribute__((unused)) struct cmdline *cl,
4651                 __attribute__((unused)) void *data)
4652 {
4653         struct cmd_show_bypass_config_result *res = parsed_result;
4654         portid_t port_id = res->port_id;
4655         int rc = -EINVAL;
4656 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4657         uint32_t event_mode;
4658         uint32_t bypass_mode;
4659         uint32_t timeout = bypass_timeout;
4660         int i;
4661
4662         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4663                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4664         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4665                 {"UNKNOWN", "normal", "bypass", "isolate"};
4666         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4667                 "NONE",
4668                 "OS/board on",
4669                 "power supply on",
4670                 "OS/board off",
4671                 "power supply off",
4672                 "timeout"};
4673         int num_events = (sizeof events) / (sizeof events[0]);
4674
4675         /* Display the bypass mode.*/
4676         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4677                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4678                 return;
4679         }
4680         else {
4681                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4682                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4683
4684                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4685         }
4686
4687         /* Display the bypass timeout.*/
4688         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4689                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4690
4691         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4692
4693         /* Display the bypass events and associated modes. */
4694         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4695
4696                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4697                         printf("\tFailed to get bypass mode for event = %s\n",
4698                                 events[i]);
4699                 } else {
4700                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4701                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4702
4703                         printf("\tbypass event: %-16s = %s\n", events[i],
4704                                 modes[event_mode]);
4705                 }
4706         }
4707 #endif
4708         if (rc != 0)
4709                 printf("\tFailed to get bypass configuration for port = %d\n",
4710                        port_id);
4711 }
4712
4713 cmdline_parse_token_string_t cmd_showbypass_config_show =
4714         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4715                         show, "show");
4716 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4717         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4718                         bypass, "bypass");
4719 cmdline_parse_token_string_t cmd_showbypass_config_config =
4720         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4721                         config, "config");
4722 cmdline_parse_token_num_t cmd_showbypass_config_port =
4723         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4724                                 port_id, UINT16);
4725
4726 cmdline_parse_inst_t cmd_show_bypass_config = {
4727         .f = cmd_show_bypass_config_parsed,
4728         .help_str = "show bypass config <port_id>: "
4729                     "Show the NIC bypass config for port_id",
4730         .data = NULL,
4731         .tokens = {
4732                 (void *)&cmd_showbypass_config_show,
4733                 (void *)&cmd_showbypass_config_bypass,
4734                 (void *)&cmd_showbypass_config_config,
4735                 (void *)&cmd_showbypass_config_port,
4736                 NULL,
4737         },
4738 };
4739
4740 #ifdef RTE_LIBRTE_PMD_BOND
4741 /* *** SET BONDING MODE *** */
4742 struct cmd_set_bonding_mode_result {
4743         cmdline_fixed_string_t set;
4744         cmdline_fixed_string_t bonding;
4745         cmdline_fixed_string_t mode;
4746         uint8_t value;
4747         portid_t port_id;
4748 };
4749
4750 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4751                 __attribute__((unused))  struct cmdline *cl,
4752                 __attribute__((unused)) void *data)
4753 {
4754         struct cmd_set_bonding_mode_result *res = parsed_result;
4755         portid_t port_id = res->port_id;
4756
4757         /* Set the bonding mode for the relevant port. */
4758         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4759                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4760 }
4761
4762 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4763 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4764                 set, "set");
4765 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4766 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4767                 bonding, "bonding");
4768 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4769 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4770                 mode, "mode");
4771 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4772 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4773                 value, UINT8);
4774 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4775 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4776                 port_id, UINT16);
4777
4778 cmdline_parse_inst_t cmd_set_bonding_mode = {
4779                 .f = cmd_set_bonding_mode_parsed,
4780                 .help_str = "set bonding mode <mode_value> <port_id>: "
4781                         "Set the bonding mode for port_id",
4782                 .data = NULL,
4783                 .tokens = {
4784                                 (void *) &cmd_setbonding_mode_set,
4785                                 (void *) &cmd_setbonding_mode_bonding,
4786                                 (void *) &cmd_setbonding_mode_mode,
4787                                 (void *) &cmd_setbonding_mode_value,
4788                                 (void *) &cmd_setbonding_mode_port,
4789                                 NULL
4790                 }
4791 };
4792
4793 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4794 struct cmd_set_bonding_lacp_dedicated_queues_result {
4795         cmdline_fixed_string_t set;
4796         cmdline_fixed_string_t bonding;
4797         cmdline_fixed_string_t lacp;
4798         cmdline_fixed_string_t dedicated_queues;
4799         portid_t port_id;
4800         cmdline_fixed_string_t mode;
4801 };
4802
4803 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4804                 __attribute__((unused))  struct cmdline *cl,
4805                 __attribute__((unused)) void *data)
4806 {
4807         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4808         portid_t port_id = res->port_id;
4809         struct rte_port *port;
4810
4811         port = &ports[port_id];
4812
4813         /** Check if the port is not started **/
4814         if (port->port_status != RTE_PORT_STOPPED) {
4815                 printf("Please stop port %d first\n", port_id);
4816                 return;
4817         }
4818
4819         if (!strcmp(res->mode, "enable")) {
4820                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4821                         printf("Dedicate queues for LACP control packets"
4822                                         " enabled\n");
4823                 else
4824                         printf("Enabling dedicate queues for LACP control "
4825                                         "packets on port %d failed\n", port_id);
4826         } else if (!strcmp(res->mode, "disable")) {
4827                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4828                         printf("Dedicated queues for LACP control packets "
4829                                         "disabled\n");
4830                 else
4831                         printf("Disabling dedicated queues for LACP control "
4832                                         "traffic on port %d failed\n", port_id);
4833         }
4834 }
4835
4836 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4837 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4838                 set, "set");
4839 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4840 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4841                 bonding, "bonding");
4842 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4843 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4844                 lacp, "lacp");
4845 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4846 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4847                 dedicated_queues, "dedicated_queues");
4848 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4849 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4850                 port_id, UINT16);
4851 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4852 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4853                 mode, "enable#disable");
4854
4855 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4856                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4857                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4858                         "enable|disable: "
4859                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4860                 .data = NULL,
4861                 .tokens = {
4862                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4863                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4864                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4865                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4866                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4867                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4868                         NULL
4869                 }
4870 };
4871
4872 /* *** SET BALANCE XMIT POLICY *** */
4873 struct cmd_set_bonding_balance_xmit_policy_result {
4874         cmdline_fixed_string_t set;
4875         cmdline_fixed_string_t bonding;
4876         cmdline_fixed_string_t balance_xmit_policy;
4877         portid_t port_id;
4878         cmdline_fixed_string_t policy;
4879 };
4880
4881 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4882                 __attribute__((unused))  struct cmdline *cl,
4883                 __attribute__((unused)) void *data)
4884 {
4885         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4886         portid_t port_id = res->port_id;
4887         uint8_t policy;
4888
4889         if (!strcmp(res->policy, "l2")) {
4890                 policy = BALANCE_XMIT_POLICY_LAYER2;
4891         } else if (!strcmp(res->policy, "l23")) {
4892                 policy = BALANCE_XMIT_POLICY_LAYER23;
4893         } else if (!strcmp(res->policy, "l34")) {
4894                 policy = BALANCE_XMIT_POLICY_LAYER34;
4895         } else {
4896                 printf("\t Invalid xmit policy selection");
4897                 return;
4898         }
4899
4900         /* Set the bonding mode for the relevant port. */
4901         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4902                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4903                                 port_id);
4904         }
4905 }
4906
4907 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4908 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4909                 set, "set");
4910 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4911 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4912                 bonding, "bonding");
4913 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4914 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4915                 balance_xmit_policy, "balance_xmit_policy");
4916 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4917 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4918                 port_id, UINT16);
4919 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4921                 policy, "l2#l23#l34");
4922
4923 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4924                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4925                 .help_str = "set bonding balance_xmit_policy <port_id> "
4926                         "l2|l23|l34: "
4927                         "Set the bonding balance_xmit_policy for port_id",
4928                 .data = NULL,
4929                 .tokens = {
4930                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4931                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4932                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4933                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4934                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4935                                 NULL
4936                 }
4937 };
4938
4939 /* *** SHOW NIC BONDING CONFIGURATION *** */
4940 struct cmd_show_bonding_config_result {
4941         cmdline_fixed_string_t show;
4942         cmdline_fixed_string_t bonding;
4943         cmdline_fixed_string_t config;
4944         portid_t port_id;
4945 };
4946
4947 static void cmd_show_bonding_config_parsed(void *parsed_result,
4948                 __attribute__((unused))  struct cmdline *cl,
4949                 __attribute__((unused)) void *data)
4950 {
4951         struct cmd_show_bonding_config_result *res = parsed_result;
4952         int bonding_mode, agg_mode;
4953         portid_t slaves[RTE_MAX_ETHPORTS];
4954         int num_slaves, num_active_slaves;
4955         int primary_id;
4956         int i;
4957         portid_t port_id = res->port_id;
4958
4959         /* Display the bonding mode.*/
4960         bonding_mode = rte_eth_bond_mode_get(port_id);
4961         if (bonding_mode < 0) {
4962                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4963                 return;
4964         } else
4965                 printf("\tBonding mode: %d\n", bonding_mode);
4966
4967         if (bonding_mode == BONDING_MODE_BALANCE) {
4968                 int balance_xmit_policy;
4969
4970                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4971                 if (balance_xmit_policy < 0) {
4972                         printf("\tFailed to get balance xmit policy for port = %d\n",
4973                                         port_id);
4974                         return;
4975                 } else {
4976                         printf("\tBalance Xmit Policy: ");
4977
4978                         switch (balance_xmit_policy) {
4979                         case BALANCE_XMIT_POLICY_LAYER2:
4980                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4981                                 break;
4982                         case BALANCE_XMIT_POLICY_LAYER23:
4983                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4984                                 break;
4985                         case BALANCE_XMIT_POLICY_LAYER34:
4986                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4987                                 break;
4988                         }
4989                         printf("\n");
4990                 }
4991         }
4992
4993         if (bonding_mode == BONDING_MODE_8023AD) {
4994                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4995                 printf("\tIEEE802.3AD Aggregator Mode: ");
4996                 switch (agg_mode) {
4997                 case AGG_BANDWIDTH:
4998                         printf("bandwidth");
4999                         break;
5000                 case AGG_STABLE:
5001                         printf("stable");
5002                         break;
5003                 case AGG_COUNT:
5004                         printf("count");
5005                         break;
5006                 }
5007                 printf("\n");
5008         }
5009
5010         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5011
5012         if (num_slaves < 0) {
5013                 printf("\tFailed to get slave list for port = %d\n", port_id);
5014                 return;
5015         }
5016         if (num_slaves > 0) {
5017                 printf("\tSlaves (%d): [", num_slaves);
5018                 for (i = 0; i < num_slaves - 1; i++)
5019                         printf("%d ", slaves[i]);
5020
5021                 printf("%d]\n", slaves[num_slaves - 1]);
5022         } else {
5023                 printf("\tSlaves: []\n");
5024
5025         }
5026
5027         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5028                         RTE_MAX_ETHPORTS);
5029
5030         if (num_active_slaves < 0) {
5031                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5032                 return;
5033         }
5034         if (num_active_slaves > 0) {
5035                 printf("\tActive Slaves (%d): [", num_active_slaves);
5036                 for (i = 0; i < num_active_slaves - 1; i++)
5037                         printf("%d ", slaves[i]);
5038
5039                 printf("%d]\n", slaves[num_active_slaves - 1]);
5040
5041         } else {
5042                 printf("\tActive Slaves: []\n");
5043
5044         }
5045
5046         primary_id = rte_eth_bond_primary_get(port_id);
5047         if (primary_id < 0) {
5048                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5049                 return;
5050         } else
5051                 printf("\tPrimary: [%d]\n", primary_id);
5052
5053 }
5054
5055 cmdline_parse_token_string_t cmd_showbonding_config_show =
5056 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5057                 show, "show");
5058 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5059 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5060                 bonding, "bonding");
5061 cmdline_parse_token_string_t cmd_showbonding_config_config =
5062 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5063                 config, "config");
5064 cmdline_parse_token_num_t cmd_showbonding_config_port =
5065 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5066                 port_id, UINT16);
5067
5068 cmdline_parse_inst_t cmd_show_bonding_config = {
5069                 .f = cmd_show_bonding_config_parsed,
5070                 .help_str = "show bonding config <port_id>: "
5071                         "Show the bonding config for port_id",
5072                 .data = NULL,
5073                 .tokens = {
5074                                 (void *)&cmd_showbonding_config_show,
5075                                 (void *)&cmd_showbonding_config_bonding,
5076                                 (void *)&cmd_showbonding_config_config,
5077                                 (void *)&cmd_showbonding_config_port,
5078                                 NULL
5079                 }
5080 };
5081
5082 /* *** SET BONDING PRIMARY *** */
5083 struct cmd_set_bonding_primary_result {
5084         cmdline_fixed_string_t set;
5085         cmdline_fixed_string_t bonding;
5086         cmdline_fixed_string_t primary;
5087         portid_t slave_id;
5088         portid_t port_id;
5089 };
5090
5091 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5092                 __attribute__((unused))  struct cmdline *cl,
5093                 __attribute__((unused)) void *data)
5094 {
5095         struct cmd_set_bonding_primary_result *res = parsed_result;
5096         portid_t master_port_id = res->port_id;
5097         portid_t slave_port_id = res->slave_id;
5098
5099         /* Set the primary slave for a bonded device. */
5100         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5101                 printf("\t Failed to set primary slave for port = %d.\n",
5102                                 master_port_id);
5103                 return;
5104         }
5105         init_port_config();
5106 }
5107
5108 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5109 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5110                 set, "set");
5111 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5112 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5113                 bonding, "bonding");
5114 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5115 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5116                 primary, "primary");
5117 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5118 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5119                 slave_id, UINT16);
5120 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5121 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5122                 port_id, UINT16);
5123
5124 cmdline_parse_inst_t cmd_set_bonding_primary = {
5125                 .f = cmd_set_bonding_primary_parsed,
5126                 .help_str = "set bonding primary <slave_id> <port_id>: "
5127                         "Set the primary slave for port_id",
5128                 .data = NULL,
5129                 .tokens = {
5130                                 (void *)&cmd_setbonding_primary_set,
5131                                 (void *)&cmd_setbonding_primary_bonding,
5132                                 (void *)&cmd_setbonding_primary_primary,
5133                                 (void *)&cmd_setbonding_primary_slave,
5134                                 (void *)&cmd_setbonding_primary_port,
5135                                 NULL
5136                 }
5137 };
5138
5139 /* *** ADD SLAVE *** */
5140 struct cmd_add_bonding_slave_result {
5141         cmdline_fixed_string_t add;
5142         cmdline_fixed_string_t bonding;
5143         cmdline_fixed_string_t slave;
5144         portid_t slave_id;
5145         portid_t port_id;
5146 };
5147
5148 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5149                 __attribute__((unused))  struct cmdline *cl,
5150                 __attribute__((unused)) void *data)
5151 {
5152         struct cmd_add_bonding_slave_result *res = parsed_result;
5153         portid_t master_port_id = res->port_id;
5154         portid_t slave_port_id = res->slave_id;
5155
5156         /* add the slave for a bonded device. */
5157         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5158                 printf("\t Failed to add slave %d to master port = %d.\n",
5159                                 slave_port_id, master_port_id);
5160                 return;
5161         }
5162         init_port_config();
5163         set_port_slave_flag(slave_port_id);
5164 }
5165
5166 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5167 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5168                 add, "add");
5169 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5170 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5171                 bonding, "bonding");
5172 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5173 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5174                 slave, "slave");
5175 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5176 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5177                 slave_id, UINT16);
5178 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5179 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5180                 port_id, UINT16);
5181
5182 cmdline_parse_inst_t cmd_add_bonding_slave = {
5183                 .f = cmd_add_bonding_slave_parsed,
5184                 .help_str = "add bonding slave <slave_id> <port_id>: "
5185                         "Add a slave device to a bonded device",
5186                 .data = NULL,
5187                 .tokens = {
5188                                 (void *)&cmd_addbonding_slave_add,
5189                                 (void *)&cmd_addbonding_slave_bonding,
5190                                 (void *)&cmd_addbonding_slave_slave,
5191                                 (void *)&cmd_addbonding_slave_slaveid,
5192                                 (void *)&cmd_addbonding_slave_port,
5193                                 NULL
5194                 }
5195 };
5196
5197 /* *** REMOVE SLAVE *** */
5198 struct cmd_remove_bonding_slave_result {
5199         cmdline_fixed_string_t remove;
5200         cmdline_fixed_string_t bonding;
5201         cmdline_fixed_string_t slave;
5202         portid_t slave_id;
5203         portid_t port_id;
5204 };
5205
5206 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5207                 __attribute__((unused))  struct cmdline *cl,
5208                 __attribute__((unused)) void *data)
5209 {
5210         struct cmd_remove_bonding_slave_result *res = parsed_result;
5211         portid_t master_port_id = res->port_id;
5212         portid_t slave_port_id = res->slave_id;
5213
5214         /* remove the slave from a bonded device. */
5215         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5216                 printf("\t Failed to remove slave %d from master port = %d.\n",
5217                                 slave_port_id, master_port_id);
5218                 return;
5219         }
5220         init_port_config();
5221         clear_port_slave_flag(slave_port_id);
5222 }
5223
5224 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5225                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5226                                 remove, "remove");
5227 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5228                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5229                                 bonding, "bonding");
5230 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5231                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5232                                 slave, "slave");
5233 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5234                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5235                                 slave_id, UINT16);
5236 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5237                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5238                                 port_id, UINT16);
5239
5240 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5241                 .f = cmd_remove_bonding_slave_parsed,
5242                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5243                         "Remove a slave device from a bonded device",
5244                 .data = NULL,
5245                 .tokens = {
5246                                 (void *)&cmd_removebonding_slave_remove,
5247                                 (void *)&cmd_removebonding_slave_bonding,
5248                                 (void *)&cmd_removebonding_slave_slave,
5249                                 (void *)&cmd_removebonding_slave_slaveid,
5250                                 (void *)&cmd_removebonding_slave_port,
5251                                 NULL
5252                 }
5253 };
5254
5255 /* *** CREATE BONDED DEVICE *** */
5256 struct cmd_create_bonded_device_result {
5257         cmdline_fixed_string_t create;
5258         cmdline_fixed_string_t bonded;
5259         cmdline_fixed_string_t device;
5260         uint8_t mode;
5261         uint8_t socket;
5262 };
5263
5264 static int bond_dev_num = 0;
5265
5266 static void cmd_create_bonded_device_parsed(void *parsed_result,
5267                 __attribute__((unused))  struct cmdline *cl,
5268                 __attribute__((unused)) void *data)
5269 {
5270         struct cmd_create_bonded_device_result *res = parsed_result;
5271         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5272         int port_id;
5273
5274         if (test_done == 0) {
5275                 printf("Please stop forwarding first\n");
5276                 return;
5277         }
5278
5279         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5280                         bond_dev_num++);
5281
5282         /* Create a new bonded device. */
5283         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5284         if (port_id < 0) {
5285                 printf("\t Failed to create bonded device.\n");
5286                 return;
5287         } else {
5288                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5289                                 port_id);
5290
5291                 /* Update number of ports */
5292                 nb_ports = rte_eth_dev_count();
5293                 reconfig(port_id, res->socket);
5294                 rte_eth_promiscuous_enable(port_id);
5295         }
5296
5297 }
5298
5299 cmdline_parse_token_string_t cmd_createbonded_device_create =
5300                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5301                                 create, "create");
5302 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5303                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5304                                 bonded, "bonded");
5305 cmdline_parse_token_string_t cmd_createbonded_device_device =
5306                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5307                                 device, "device");
5308 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5309                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5310                                 mode, UINT8);
5311 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5312                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5313                                 socket, UINT8);
5314
5315 cmdline_parse_inst_t cmd_create_bonded_device = {
5316                 .f = cmd_create_bonded_device_parsed,
5317                 .help_str = "create bonded device <mode> <socket>: "
5318                         "Create a new bonded device with specific bonding mode and socket",
5319                 .data = NULL,
5320                 .tokens = {
5321                                 (void *)&cmd_createbonded_device_create,
5322                                 (void *)&cmd_createbonded_device_bonded,
5323                                 (void *)&cmd_createbonded_device_device,
5324                                 (void *)&cmd_createbonded_device_mode,
5325                                 (void *)&cmd_createbonded_device_socket,
5326                                 NULL
5327                 }
5328 };
5329
5330 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5331 struct cmd_set_bond_mac_addr_result {
5332         cmdline_fixed_string_t set;
5333         cmdline_fixed_string_t bonding;
5334         cmdline_fixed_string_t mac_addr;
5335         uint16_t port_num;
5336         struct ether_addr address;
5337 };
5338
5339 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5340                 __attribute__((unused))  struct cmdline *cl,
5341                 __attribute__((unused)) void *data)
5342 {
5343         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5344         int ret;
5345
5346         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5347                 return;
5348
5349         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5350
5351         /* check the return value and print it if is < 0 */
5352         if (ret < 0)
5353                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5354 }
5355
5356 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5357                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5358 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5359                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5360                                 "bonding");
5361 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5362                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5363                                 "mac_addr");
5364 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5365                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5366                                 port_num, UINT16);
5367 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5368                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5369
5370 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5371                 .f = cmd_set_bond_mac_addr_parsed,
5372                 .data = (void *) 0,
5373                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5374                 .tokens = {
5375                                 (void *)&cmd_set_bond_mac_addr_set,
5376                                 (void *)&cmd_set_bond_mac_addr_bonding,
5377                                 (void *)&cmd_set_bond_mac_addr_mac,
5378                                 (void *)&cmd_set_bond_mac_addr_portnum,
5379                                 (void *)&cmd_set_bond_mac_addr_addr,
5380                                 NULL
5381                 }
5382 };
5383
5384
5385 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5386 struct cmd_set_bond_mon_period_result {
5387         cmdline_fixed_string_t set;
5388         cmdline_fixed_string_t bonding;
5389         cmdline_fixed_string_t mon_period;
5390         uint16_t port_num;
5391         uint32_t period_ms;
5392 };
5393
5394 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5395                 __attribute__((unused))  struct cmdline *cl,
5396                 __attribute__((unused)) void *data)
5397 {
5398         struct cmd_set_bond_mon_period_result *res = parsed_result;
5399         int ret;
5400
5401         if (res->port_num >= nb_ports) {
5402                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5403                 return;
5404         }
5405
5406         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5407
5408         /* check the return value and print it if is < 0 */
5409         if (ret < 0)
5410                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5411 }
5412
5413 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5414                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5415                                 set, "set");
5416 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5417                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5418                                 bonding, "bonding");
5419 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5420                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5421                                 mon_period,     "mon_period");
5422 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5423                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5424                                 port_num, UINT16);
5425 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5426                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5427                                 period_ms, UINT32);
5428
5429 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5430                 .f = cmd_set_bond_mon_period_parsed,
5431                 .data = (void *) 0,
5432                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5433                 .tokens = {
5434                                 (void *)&cmd_set_bond_mon_period_set,
5435                                 (void *)&cmd_set_bond_mon_period_bonding,
5436                                 (void *)&cmd_set_bond_mon_period_mon_period,
5437                                 (void *)&cmd_set_bond_mon_period_portnum,
5438                                 (void *)&cmd_set_bond_mon_period_period_ms,
5439                                 NULL
5440                 }
5441 };
5442
5443
5444
5445 struct cmd_set_bonding_agg_mode_policy_result {
5446         cmdline_fixed_string_t set;
5447         cmdline_fixed_string_t bonding;
5448         cmdline_fixed_string_t agg_mode;
5449         uint16_t port_num;
5450         cmdline_fixed_string_t policy;
5451 };
5452
5453
5454 static void
5455 cmd_set_bonding_agg_mode(void *parsed_result,
5456                 __attribute__((unused)) struct cmdline *cl,
5457                 __attribute__((unused)) void *data)
5458 {
5459         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5460         uint8_t policy = AGG_BANDWIDTH;
5461
5462         if (res->port_num >= nb_ports) {
5463                 printf("Port id %d must be less than %d\n",
5464                                 res->port_num, nb_ports);
5465                 return;
5466         }
5467
5468         if (!strcmp(res->policy, "bandwidth"))
5469                 policy = AGG_BANDWIDTH;
5470         else if (!strcmp(res->policy, "stable"))
5471                 policy = AGG_STABLE;
5472         else if (!strcmp(res->policy, "count"))
5473                 policy = AGG_COUNT;
5474
5475         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5476 }
5477
5478
5479 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5480         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5481                                 set, "set");
5482 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5483         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5484                                 bonding, "bonding");
5485
5486 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5488                                 agg_mode, "agg_mode");
5489
5490 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5491         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5492                                 port_num, UINT16);
5493
5494 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5495         TOKEN_STRING_INITIALIZER(
5496                         struct cmd_set_bonding_balance_xmit_policy_result,
5497                 policy, "stable#bandwidth#count");
5498
5499 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5500         .f = cmd_set_bonding_agg_mode,
5501         .data = (void *) 0,
5502         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5503         .tokens = {
5504                         (void *)&cmd_set_bonding_agg_mode_set,
5505                         (void *)&cmd_set_bonding_agg_mode_bonding,
5506                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5507                         (void *)&cmd_set_bonding_agg_mode_portnum,
5508                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5509                         NULL
5510                 }
5511 };
5512
5513
5514 #endif /* RTE_LIBRTE_PMD_BOND */
5515
5516 /* *** SET FORWARDING MODE *** */
5517 struct cmd_set_fwd_mode_result {
5518         cmdline_fixed_string_t set;
5519         cmdline_fixed_string_t fwd;
5520         cmdline_fixed_string_t mode;
5521 };
5522
5523 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5524                                     __attribute__((unused)) struct cmdline *cl,
5525                                     __attribute__((unused)) void *data)
5526 {
5527         struct cmd_set_fwd_mode_result *res = parsed_result;
5528
5529         retry_enabled = 0;
5530         set_pkt_forwarding_mode(res->mode);
5531 }
5532
5533 cmdline_parse_token_string_t cmd_setfwd_set =
5534         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5535 cmdline_parse_token_string_t cmd_setfwd_fwd =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5537 cmdline_parse_token_string_t cmd_setfwd_mode =
5538         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5539                 "" /* defined at init */);
5540
5541 cmdline_parse_inst_t cmd_set_fwd_mode = {
5542         .f = cmd_set_fwd_mode_parsed,
5543         .data = NULL,
5544         .help_str = NULL, /* defined at init */
5545         .tokens = {
5546                 (void *)&cmd_setfwd_set,
5547                 (void *)&cmd_setfwd_fwd,
5548                 (void *)&cmd_setfwd_mode,
5549                 NULL,
5550         },
5551 };
5552
5553 static void cmd_set_fwd_mode_init(void)
5554 {
5555         char *modes, *c;
5556         static char token[128];
5557         static char help[256];
5558         cmdline_parse_token_string_t *token_struct;
5559
5560         modes = list_pkt_forwarding_modes();
5561         snprintf(help, sizeof(help), "set fwd %s: "
5562                 "Set packet forwarding mode", modes);
5563         cmd_set_fwd_mode.help_str = help;
5564
5565         /* string token separator is # */
5566         for (c = token; *modes != '\0'; modes++)
5567                 if (*modes == '|')
5568                         *c++ = '#';
5569                 else
5570                         *c++ = *modes;
5571         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5572         token_struct->string_data.str = token;
5573 }
5574
5575 /* *** SET RETRY FORWARDING MODE *** */
5576 struct cmd_set_fwd_retry_mode_result {
5577         cmdline_fixed_string_t set;
5578         cmdline_fixed_string_t fwd;
5579         cmdline_fixed_string_t mode;
5580         cmdline_fixed_string_t retry;
5581 };
5582
5583 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5584                             __attribute__((unused)) struct cmdline *cl,
5585                             __attribute__((unused)) void *data)
5586 {
5587         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5588
5589         retry_enabled = 1;
5590         set_pkt_forwarding_mode(res->mode);
5591 }
5592
5593 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5594         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5595                         set, "set");
5596 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5597         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5598                         fwd, "fwd");
5599 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5600         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5601                         mode,
5602                 "" /* defined at init */);
5603 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5604         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5605                         retry, "retry");
5606
5607 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5608         .f = cmd_set_fwd_retry_mode_parsed,
5609         .data = NULL,
5610         .help_str = NULL, /* defined at init */
5611         .tokens = {
5612                 (void *)&cmd_setfwd_retry_set,
5613                 (void *)&cmd_setfwd_retry_fwd,
5614                 (void *)&cmd_setfwd_retry_mode,
5615                 (void *)&cmd_setfwd_retry_retry,
5616                 NULL,
5617         },
5618 };
5619
5620 static void cmd_set_fwd_retry_mode_init(void)
5621 {
5622         char *modes, *c;
5623         static char token[128];
5624         static char help[256];
5625         cmdline_parse_token_string_t *token_struct;
5626
5627         modes = list_pkt_forwarding_retry_modes();
5628         snprintf(help, sizeof(help), "set fwd %s retry: "
5629                 "Set packet forwarding mode with retry", modes);
5630         cmd_set_fwd_retry_mode.help_str = help;
5631
5632         /* string token separator is # */
5633         for (c = token; *modes != '\0'; modes++)
5634                 if (*modes == '|')
5635                         *c++ = '#';
5636                 else
5637                         *c++ = *modes;
5638         token_struct = (cmdline_parse_token_string_t *)
5639                 cmd_set_fwd_retry_mode.tokens[2];
5640         token_struct->string_data.str = token;
5641 }
5642
5643 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5644 struct cmd_set_burst_tx_retry_result {
5645         cmdline_fixed_string_t set;
5646         cmdline_fixed_string_t burst;
5647         cmdline_fixed_string_t tx;
5648         cmdline_fixed_string_t delay;
5649         uint32_t time;
5650         cmdline_fixed_string_t retry;
5651         uint32_t retry_num;
5652 };
5653
5654 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5655                                         __attribute__((unused)) struct cmdline *cl,
5656                                         __attribute__((unused)) void *data)
5657 {
5658         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5659
5660         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5661                 && !strcmp(res->tx, "tx")) {
5662                 if (!strcmp(res->delay, "delay"))
5663                         burst_tx_delay_time = res->time;
5664                 if (!strcmp(res->retry, "retry"))
5665                         burst_tx_retry_num = res->retry_num;
5666         }
5667
5668 }
5669
5670 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5671         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5672 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5673         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5674                                  "burst");
5675 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5676         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5677 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5678         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5679 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5680         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5681 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5682         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5683 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5684         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5685
5686 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5687         .f = cmd_set_burst_tx_retry_parsed,
5688         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5689         .tokens = {
5690                 (void *)&cmd_set_burst_tx_retry_set,
5691                 (void *)&cmd_set_burst_tx_retry_burst,
5692                 (void *)&cmd_set_burst_tx_retry_tx,
5693                 (void *)&cmd_set_burst_tx_retry_delay,
5694                 (void *)&cmd_set_burst_tx_retry_time,
5695                 (void *)&cmd_set_burst_tx_retry_retry,
5696                 (void *)&cmd_set_burst_tx_retry_retry_num,
5697                 NULL,
5698         },
5699 };
5700
5701 /* *** SET PROMISC MODE *** */
5702 struct cmd_set_promisc_mode_result {
5703         cmdline_fixed_string_t set;
5704         cmdline_fixed_string_t promisc;
5705         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5706         uint16_t port_num;               /* valid if "allports" argument == 0 */
5707         cmdline_fixed_string_t mode;
5708 };
5709
5710 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5711                                         __attribute__((unused)) struct cmdline *cl,
5712                                         void *allports)
5713 {
5714         struct cmd_set_promisc_mode_result *res = parsed_result;
5715         int enable;
5716         portid_t i;
5717
5718         if (!strcmp(res->mode, "on"))
5719                 enable = 1;
5720         else
5721                 enable = 0;
5722
5723         /* all ports */
5724         if (allports) {
5725                 RTE_ETH_FOREACH_DEV(i) {
5726                         if (enable)
5727                                 rte_eth_promiscuous_enable(i);
5728                         else
5729                                 rte_eth_promiscuous_disable(i);
5730                 }
5731         }
5732         else {
5733                 if (enable)
5734                         rte_eth_promiscuous_enable(res->port_num);
5735                 else
5736                         rte_eth_promiscuous_disable(res->port_num);
5737         }
5738 }
5739
5740 cmdline_parse_token_string_t cmd_setpromisc_set =
5741         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5742 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5743         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5744                                  "promisc");
5745 cmdline_parse_token_string_t cmd_setpromisc_portall =
5746         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5747                                  "all");
5748 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5749         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5750                               UINT8);
5751 cmdline_parse_token_string_t cmd_setpromisc_mode =
5752         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5753                                  "on#off");
5754
5755 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5756         .f = cmd_set_promisc_mode_parsed,
5757         .data = (void *)1,
5758         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5759         .tokens = {
5760                 (void *)&cmd_setpromisc_set,
5761                 (void *)&cmd_setpromisc_promisc,
5762                 (void *)&cmd_setpromisc_portall,
5763                 (void *)&cmd_setpromisc_mode,
5764                 NULL,
5765         },
5766 };
5767
5768 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5769         .f = cmd_set_promisc_mode_parsed,
5770         .data = (void *)0,
5771         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5772         .tokens = {
5773                 (void *)&cmd_setpromisc_set,
5774                 (void *)&cmd_setpromisc_promisc,
5775                 (void *)&cmd_setpromisc_portnum,
5776                 (void *)&cmd_setpromisc_mode,
5777                 NULL,
5778         },
5779 };
5780
5781 /* *** SET ALLMULTI MODE *** */
5782 struct cmd_set_allmulti_mode_result {
5783         cmdline_fixed_string_t set;
5784         cmdline_fixed_string_t allmulti;
5785         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5786         uint16_t port_num;               /* valid if "allports" argument == 0 */
5787         cmdline_fixed_string_t mode;
5788 };
5789
5790 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5791                                         __attribute__((unused)) struct cmdline *cl,
5792                                         void *allports)
5793 {
5794         struct cmd_set_allmulti_mode_result *res = parsed_result;
5795         int enable;
5796         portid_t i;
5797
5798         if (!strcmp(res->mode, "on"))
5799                 enable = 1;
5800         else
5801                 enable = 0;
5802
5803         /* all ports */
5804         if (allports) {
5805                 RTE_ETH_FOREACH_DEV(i) {
5806                         if (enable)
5807                                 rte_eth_allmulticast_enable(i);
5808                         else
5809                                 rte_eth_allmulticast_disable(i);
5810                 }
5811         }
5812         else {
5813                 if (enable)
5814                         rte_eth_allmulticast_enable(res->port_num);
5815                 else
5816                         rte_eth_allmulticast_disable(res->port_num);
5817         }
5818 }
5819
5820 cmdline_parse_token_string_t cmd_setallmulti_set =
5821         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5822 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5823         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5824                                  "allmulti");
5825 cmdline_parse_token_string_t cmd_setallmulti_portall =
5826         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5827                                  "all");
5828 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5829         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5830                               UINT16);
5831 cmdline_parse_token_string_t cmd_setallmulti_mode =
5832         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5833                                  "on#off");
5834
5835 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5836         .f = cmd_set_allmulti_mode_parsed,
5837         .data = (void *)1,
5838         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5839         .tokens = {
5840                 (void *)&cmd_setallmulti_set,
5841                 (void *)&cmd_setallmulti_allmulti,
5842                 (void *)&cmd_setallmulti_portall,
5843                 (void *)&cmd_setallmulti_mode,
5844                 NULL,
5845         },
5846 };
5847
5848 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5849         .f = cmd_set_allmulti_mode_parsed,
5850         .data = (void *)0,
5851         .help_str = "set allmulti <port_id> on|off: "
5852                 "Set allmulti mode on port_id",
5853         .tokens = {
5854                 (void *)&cmd_setallmulti_set,
5855                 (void *)&cmd_setallmulti_allmulti,
5856                 (void *)&cmd_setallmulti_portnum,
5857                 (void *)&cmd_setallmulti_mode,
5858                 NULL,
5859         },
5860 };
5861
5862 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5863 struct cmd_link_flow_ctrl_set_result {
5864         cmdline_fixed_string_t set;
5865         cmdline_fixed_string_t flow_ctrl;
5866         cmdline_fixed_string_t rx;
5867         cmdline_fixed_string_t rx_lfc_mode;
5868         cmdline_fixed_string_t tx;
5869         cmdline_fixed_string_t tx_lfc_mode;
5870         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5871         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5872         cmdline_fixed_string_t autoneg_str;
5873         cmdline_fixed_string_t autoneg;
5874         cmdline_fixed_string_t hw_str;
5875         uint32_t high_water;
5876         cmdline_fixed_string_t lw_str;
5877         uint32_t low_water;
5878         cmdline_fixed_string_t pt_str;
5879         uint16_t pause_time;
5880         cmdline_fixed_string_t xon_str;
5881         uint16_t send_xon;
5882         portid_t port_id;
5883 };
5884
5885 cmdline_parse_token_string_t cmd_lfc_set_set =
5886         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5887                                 set, "set");
5888 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5889         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5890                                 flow_ctrl, "flow_ctrl");
5891 cmdline_parse_token_string_t cmd_lfc_set_rx =
5892         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5893                                 rx, "rx");
5894 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5895         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5896                                 rx_lfc_mode, "on#off");
5897 cmdline_parse_token_string_t cmd_lfc_set_tx =
5898         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5899                                 tx, "tx");
5900 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5901         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5902                                 tx_lfc_mode, "on#off");
5903 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5904         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5905                                 hw_str, "high_water");
5906 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5907         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5908                                 high_water, UINT32);
5909 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5910         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5911                                 lw_str, "low_water");
5912 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5913         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5914                                 low_water, UINT32);
5915 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5916         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5917                                 pt_str, "pause_time");
5918 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5919         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5920                                 pause_time, UINT16);
5921 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5922         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5923                                 xon_str, "send_xon");
5924 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5925         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5926                                 send_xon, UINT16);
5927 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5928         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5929                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5930 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5931         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5932                                 mac_ctrl_frame_fwd_mode, "on#off");
5933 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5934         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5935                                 autoneg_str, "autoneg");
5936 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5937         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5938                                 autoneg, "on#off");
5939 cmdline_parse_token_num_t cmd_lfc_set_portid =
5940         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5941                                 port_id, UINT16);
5942
5943 /* forward declaration */
5944 static void
5945 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5946                               void *data);
5947
5948 cmdline_parse_inst_t cmd_link_flow_control_set = {
5949         .f = cmd_link_flow_ctrl_set_parsed,
5950         .data = NULL,
5951         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5952                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5953                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5954         .tokens = {
5955                 (void *)&cmd_lfc_set_set,
5956                 (void *)&cmd_lfc_set_flow_ctrl,
5957                 (void *)&cmd_lfc_set_rx,
5958                 (void *)&cmd_lfc_set_rx_mode,
5959                 (void *)&cmd_lfc_set_tx,
5960                 (void *)&cmd_lfc_set_tx_mode,
5961                 (void *)&cmd_lfc_set_high_water,
5962                 (void *)&cmd_lfc_set_low_water,
5963                 (void *)&cmd_lfc_set_pause_time,
5964                 (void *)&cmd_lfc_set_send_xon,
5965                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5966                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5967                 (void *)&cmd_lfc_set_autoneg_str,
5968                 (void *)&cmd_lfc_set_autoneg,
5969                 (void *)&cmd_lfc_set_portid,
5970                 NULL,
5971         },
5972 };
5973
5974 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5975         .f = cmd_link_flow_ctrl_set_parsed,
5976         .data = (void *)&cmd_link_flow_control_set_rx,
5977         .help_str = "set flow_ctrl rx on|off <port_id>: "
5978                 "Change rx flow control parameter",
5979         .tokens = {
5980                 (void *)&cmd_lfc_set_set,
5981                 (void *)&cmd_lfc_set_flow_ctrl,
5982                 (void *)&cmd_lfc_set_rx,
5983                 (void *)&cmd_lfc_set_rx_mode,
5984                 (void *)&cmd_lfc_set_portid,
5985                 NULL,
5986         },
5987 };
5988
5989 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5990         .f = cmd_link_flow_ctrl_set_parsed,
5991         .data = (void *)&cmd_link_flow_control_set_tx,
5992         .help_str = "set flow_ctrl tx on|off <port_id>: "
5993                 "Change tx flow control parameter",
5994         .tokens = {
5995                 (void *)&cmd_lfc_set_set,
5996                 (void *)&cmd_lfc_set_flow_ctrl,
5997                 (void *)&cmd_lfc_set_tx,
5998                 (void *)&cmd_lfc_set_tx_mode,
5999                 (void *)&cmd_lfc_set_portid,
6000                 NULL,
6001         },
6002 };
6003
6004 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6005         .f = cmd_link_flow_ctrl_set_parsed,
6006         .data = (void *)&cmd_link_flow_control_set_hw,
6007         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6008                 "Change high water flow control parameter",
6009         .tokens = {
6010                 (void *)&cmd_lfc_set_set,
6011                 (void *)&cmd_lfc_set_flow_ctrl,
6012                 (void *)&cmd_lfc_set_high_water_str,
6013                 (void *)&cmd_lfc_set_high_water,
6014                 (void *)&cmd_lfc_set_portid,
6015                 NULL,
6016         },
6017 };
6018
6019 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6020         .f = cmd_link_flow_ctrl_set_parsed,
6021         .data = (void *)&cmd_link_flow_control_set_lw,
6022         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6023                 "Change low water flow control parameter",
6024         .tokens = {
6025                 (void *)&cmd_lfc_set_set,
6026                 (void *)&cmd_lfc_set_flow_ctrl,
6027                 (void *)&cmd_lfc_set_low_water_str,
6028                 (void *)&cmd_lfc_set_low_water,
6029                 (void *)&cmd_lfc_set_portid,
6030                 NULL,
6031         },
6032 };
6033
6034 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6035         .f = cmd_link_flow_ctrl_set_parsed,
6036         .data = (void *)&cmd_link_flow_control_set_pt,
6037         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6038                 "Change pause time flow control parameter",
6039         .tokens = {
6040                 (void *)&cmd_lfc_set_set,
6041                 (void *)&cmd_lfc_set_flow_ctrl,
6042                 (void *)&cmd_lfc_set_pause_time_str,
6043                 (void *)&cmd_lfc_set_pause_time,
6044                 (void *)&cmd_lfc_set_portid,
6045                 NULL,
6046         },
6047 };
6048
6049 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6050         .f = cmd_link_flow_ctrl_set_parsed,
6051         .data = (void *)&cmd_link_flow_control_set_xon,
6052         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6053                 "Change send_xon flow control parameter",
6054         .tokens = {
6055                 (void *)&cmd_lfc_set_set,
6056                 (void *)&cmd_lfc_set_flow_ctrl,
6057                 (void *)&cmd_lfc_set_send_xon_str,
6058                 (void *)&cmd_lfc_set_send_xon,
6059                 (void *)&cmd_lfc_set_portid,
6060                 NULL,
6061         },
6062 };
6063
6064 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6065         .f = cmd_link_flow_ctrl_set_parsed,
6066         .data = (void *)&cmd_link_flow_control_set_macfwd,
6067         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6068                 "Change mac ctrl fwd flow control parameter",
6069         .tokens = {
6070                 (void *)&cmd_lfc_set_set,
6071                 (void *)&cmd_lfc_set_flow_ctrl,
6072                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6073                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6074                 (void *)&cmd_lfc_set_portid,
6075                 NULL,
6076         },
6077 };
6078
6079 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6080         .f = cmd_link_flow_ctrl_set_parsed,
6081         .data = (void *)&cmd_link_flow_control_set_autoneg,
6082         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6083                 "Change autoneg flow control parameter",
6084         .tokens = {
6085                 (void *)&cmd_lfc_set_set,
6086                 (void *)&cmd_lfc_set_flow_ctrl,
6087                 (void *)&cmd_lfc_set_autoneg_str,
6088                 (void *)&cmd_lfc_set_autoneg,
6089                 (void *)&cmd_lfc_set_portid,
6090                 NULL,
6091         },
6092 };
6093
6094 static void
6095 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6096                               __attribute__((unused)) struct cmdline *cl,
6097                               void *data)
6098 {
6099         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6100         cmdline_parse_inst_t *cmd = data;
6101         struct rte_eth_fc_conf fc_conf;
6102         int rx_fc_en = 0;
6103         int tx_fc_en = 0;
6104         int ret;
6105
6106         /*
6107          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6108          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6109          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6110          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6111          */
6112         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6113                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6114         };
6115
6116         /* Partial command line, retrieve current configuration */
6117         if (cmd) {
6118                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6119                 if (ret != 0) {
6120                         printf("cannot get current flow ctrl parameters, return"
6121                                "code = %d\n", ret);
6122                         return;
6123                 }
6124
6125                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6126                     (fc_conf.mode == RTE_FC_FULL))
6127                         rx_fc_en = 1;
6128                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6129                     (fc_conf.mode == RTE_FC_FULL))
6130                         tx_fc_en = 1;
6131         }
6132
6133         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6134                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6135
6136         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6137                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6138
6139         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6140
6141         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6142                 fc_conf.high_water = res->high_water;
6143
6144         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6145                 fc_conf.low_water = res->low_water;
6146
6147         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6148                 fc_conf.pause_time = res->pause_time;
6149
6150         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6151                 fc_conf.send_xon = res->send_xon;
6152
6153         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6154                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6155                         fc_conf.mac_ctrl_frame_fwd = 1;
6156                 else
6157                         fc_conf.mac_ctrl_frame_fwd = 0;
6158         }
6159
6160         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6161                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6162
6163         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6164         if (ret != 0)
6165                 printf("bad flow contrl parameter, return code = %d \n", ret);
6166 }
6167
6168 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6169 struct cmd_priority_flow_ctrl_set_result {
6170         cmdline_fixed_string_t set;
6171         cmdline_fixed_string_t pfc_ctrl;
6172         cmdline_fixed_string_t rx;
6173         cmdline_fixed_string_t rx_pfc_mode;
6174         cmdline_fixed_string_t tx;
6175         cmdline_fixed_string_t tx_pfc_mode;
6176         uint32_t high_water;
6177         uint32_t low_water;
6178         uint16_t pause_time;
6179         uint8_t  priority;
6180         portid_t port_id;
6181 };
6182
6183 static void
6184 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6185                        __attribute__((unused)) struct cmdline *cl,
6186                        __attribute__((unused)) void *data)
6187 {
6188         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6189         struct rte_eth_pfc_conf pfc_conf;
6190         int rx_fc_enable, tx_fc_enable;
6191         int ret;
6192
6193         /*
6194          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6195          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6196          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6197          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6198          */
6199         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6200                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6201         };
6202
6203         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6204         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6205         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6206         pfc_conf.fc.high_water = res->high_water;
6207         pfc_conf.fc.low_water  = res->low_water;
6208         pfc_conf.fc.pause_time = res->pause_time;
6209         pfc_conf.priority      = res->priority;
6210
6211         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6212         if (ret != 0)
6213                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6214 }
6215
6216 cmdline_parse_token_string_t cmd_pfc_set_set =
6217         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6218                                 set, "set");
6219 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6220         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6221                                 pfc_ctrl, "pfc_ctrl");
6222 cmdline_parse_token_string_t cmd_pfc_set_rx =
6223         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6224                                 rx, "rx");
6225 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6226         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6227                                 rx_pfc_mode, "on#off");
6228 cmdline_parse_token_string_t cmd_pfc_set_tx =
6229         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6230                                 tx, "tx");
6231 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6232         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6233                                 tx_pfc_mode, "on#off");
6234 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6235         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6236                                 high_water, UINT32);
6237 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6238         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6239                                 low_water, UINT32);
6240 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6241         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6242                                 pause_time, UINT16);
6243 cmdline_parse_token_num_t cmd_pfc_set_priority =
6244         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6245                                 priority, UINT8);
6246 cmdline_parse_token_num_t cmd_pfc_set_portid =
6247         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6248                                 port_id, UINT16);
6249
6250 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6251         .f = cmd_priority_flow_ctrl_set_parsed,
6252         .data = NULL,
6253         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6254                 "<pause_time> <priority> <port_id>: "
6255                 "Configure the Ethernet priority flow control",
6256         .tokens = {
6257                 (void *)&cmd_pfc_set_set,
6258                 (void *)&cmd_pfc_set_flow_ctrl,
6259                 (void *)&cmd_pfc_set_rx,
6260                 (void *)&cmd_pfc_set_rx_mode,
6261                 (void *)&cmd_pfc_set_tx,
6262                 (void *)&cmd_pfc_set_tx_mode,
6263                 (void *)&cmd_pfc_set_high_water,
6264                 (void *)&cmd_pfc_set_low_water,
6265                 (void *)&cmd_pfc_set_pause_time,
6266                 (void *)&cmd_pfc_set_priority,
6267                 (void *)&cmd_pfc_set_portid,
6268                 NULL,
6269         },
6270 };
6271
6272 /* *** RESET CONFIGURATION *** */
6273 struct cmd_reset_result {
6274         cmdline_fixed_string_t reset;
6275         cmdline_fixed_string_t def;
6276 };
6277
6278 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6279                              struct cmdline *cl,
6280                              __attribute__((unused)) void *data)
6281 {
6282         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6283         set_def_fwd_config();
6284 }
6285
6286 cmdline_parse_token_string_t cmd_reset_set =
6287         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6288 cmdline_parse_token_string_t cmd_reset_def =
6289         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6290                                  "default");
6291
6292 cmdline_parse_inst_t cmd_reset = {
6293         .f = cmd_reset_parsed,
6294         .data = NULL,
6295         .help_str = "set default: Reset default forwarding configuration",
6296         .tokens = {
6297                 (void *)&cmd_reset_set,
6298                 (void *)&cmd_reset_def,
6299                 NULL,
6300         },
6301 };
6302
6303 /* *** START FORWARDING *** */
6304 struct cmd_start_result {
6305         cmdline_fixed_string_t start;
6306 };
6307
6308 cmdline_parse_token_string_t cmd_start_start =
6309         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6310
6311 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6312                              __attribute__((unused)) struct cmdline *cl,
6313                              __attribute__((unused)) void *data)
6314 {
6315         start_packet_forwarding(0);
6316 }
6317
6318 cmdline_parse_inst_t cmd_start = {
6319         .f = cmd_start_parsed,
6320         .data = NULL,
6321         .help_str = "start: Start packet forwarding",
6322         .tokens = {
6323                 (void *)&cmd_start_start,
6324                 NULL,
6325         },
6326 };
6327
6328 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6329 struct cmd_start_tx_first_result {
6330         cmdline_fixed_string_t start;
6331         cmdline_fixed_string_t tx_first;
6332 };
6333
6334 static void
6335 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6336                           __attribute__((unused)) struct cmdline *cl,
6337                           __attribute__((unused)) void *data)
6338 {
6339         start_packet_forwarding(1);
6340 }
6341
6342 cmdline_parse_token_string_t cmd_start_tx_first_start =
6343         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6344                                  "start");
6345 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6346         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6347                                  tx_first, "tx_first");
6348
6349 cmdline_parse_inst_t cmd_start_tx_first = {
6350         .f = cmd_start_tx_first_parsed,
6351         .data = NULL,
6352         .help_str = "start tx_first: Start packet forwarding, "
6353                 "after sending 1 burst of packets",
6354         .tokens = {
6355                 (void *)&cmd_start_tx_first_start,
6356                 (void *)&cmd_start_tx_first_tx_first,
6357                 NULL,
6358         },
6359 };
6360
6361 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6362 struct cmd_start_tx_first_n_result {
6363         cmdline_fixed_string_t start;
6364         cmdline_fixed_string_t tx_first;
6365         uint32_t tx_num;
6366 };
6367
6368 static void
6369 cmd_start_tx_first_n_parsed(void *parsed_result,
6370                           __attribute__((unused)) struct cmdline *cl,
6371                           __attribute__((unused)) void *data)
6372 {
6373         struct cmd_start_tx_first_n_result *res = parsed_result;
6374
6375         start_packet_forwarding(res->tx_num);
6376 }
6377
6378 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6379         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6380                         start, "start");
6381 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6382         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6383                         tx_first, "tx_first");
6384 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6385         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6386                         tx_num, UINT32);
6387
6388 cmdline_parse_inst_t cmd_start_tx_first_n = {
6389         .f = cmd_start_tx_first_n_parsed,
6390         .data = NULL,
6391         .help_str = "start tx_first <num>: "
6392                 "packet forwarding, after sending <num> bursts of packets",
6393         .tokens = {
6394                 (void *)&cmd_start_tx_first_n_start,
6395                 (void *)&cmd_start_tx_first_n_tx_first,
6396                 (void *)&cmd_start_tx_first_n_tx_num,
6397                 NULL,
6398         },
6399 };
6400
6401 /* *** SET LINK UP *** */
6402 struct cmd_set_link_up_result {
6403         cmdline_fixed_string_t set;
6404         cmdline_fixed_string_t link_up;
6405         cmdline_fixed_string_t port;
6406         portid_t port_id;
6407 };
6408
6409 cmdline_parse_token_string_t cmd_set_link_up_set =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6411 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6412         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6413                                 "link-up");
6414 cmdline_parse_token_string_t cmd_set_link_up_port =
6415         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6416 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6417         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6418
6419 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6420                              __attribute__((unused)) struct cmdline *cl,
6421                              __attribute__((unused)) void *data)
6422 {
6423         struct cmd_set_link_up_result *res = parsed_result;
6424         dev_set_link_up(res->port_id);
6425 }
6426
6427 cmdline_parse_inst_t cmd_set_link_up = {
6428         .f = cmd_set_link_up_parsed,
6429         .data = NULL,
6430         .help_str = "set link-up port <port id>",
6431         .tokens = {
6432                 (void *)&cmd_set_link_up_set,
6433                 (void *)&cmd_set_link_up_link_up,
6434                 (void *)&cmd_set_link_up_port,
6435                 (void *)&cmd_set_link_up_port_id,
6436                 NULL,
6437         },
6438 };
6439
6440 /* *** SET LINK DOWN *** */
6441 struct cmd_set_link_down_result {
6442         cmdline_fixed_string_t set;
6443         cmdline_fixed_string_t link_down;
6444         cmdline_fixed_string_t port;
6445         portid_t port_id;
6446 };
6447
6448 cmdline_parse_token_string_t cmd_set_link_down_set =
6449         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6450 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6451         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6452                                 "link-down");
6453 cmdline_parse_token_string_t cmd_set_link_down_port =
6454         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6455 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6456         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6457
6458 static void cmd_set_link_down_parsed(
6459                                 __attribute__((unused)) void *parsed_result,
6460                                 __attribute__((unused)) struct cmdline *cl,
6461                                 __attribute__((unused)) void *data)
6462 {
6463         struct cmd_set_link_down_result *res = parsed_result;
6464         dev_set_link_down(res->port_id);
6465 }
6466
6467 cmdline_parse_inst_t cmd_set_link_down = {
6468         .f = cmd_set_link_down_parsed,
6469         .data = NULL,
6470         .help_str = "set link-down port <port id>",
6471         .tokens = {
6472                 (void *)&cmd_set_link_down_set,
6473                 (void *)&cmd_set_link_down_link_down,
6474                 (void *)&cmd_set_link_down_port,
6475                 (void *)&cmd_set_link_down_port_id,
6476                 NULL,
6477         },
6478 };
6479
6480 /* *** SHOW CFG *** */
6481 struct cmd_showcfg_result {
6482         cmdline_fixed_string_t show;
6483         cmdline_fixed_string_t cfg;
6484         cmdline_fixed_string_t what;
6485 };
6486
6487 static void cmd_showcfg_parsed(void *parsed_result,
6488                                __attribute__((unused)) struct cmdline *cl,
6489                                __attribute__((unused)) void *data)
6490 {
6491         struct cmd_showcfg_result *res = parsed_result;
6492         if (!strcmp(res->what, "rxtx"))
6493                 rxtx_config_display();
6494         else if (!strcmp(res->what, "cores"))
6495                 fwd_lcores_config_display();
6496         else if (!strcmp(res->what, "fwd"))
6497                 pkt_fwd_config_display(&cur_fwd_config);
6498         else if (!strcmp(res->what, "txpkts"))
6499                 show_tx_pkt_segments();
6500 }
6501
6502 cmdline_parse_token_string_t cmd_showcfg_show =
6503         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6504 cmdline_parse_token_string_t cmd_showcfg_port =
6505         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6506 cmdline_parse_token_string_t cmd_showcfg_what =
6507         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6508                                  "rxtx#cores#fwd#txpkts");
6509
6510 cmdline_parse_inst_t cmd_showcfg = {
6511         .f = cmd_showcfg_parsed,
6512         .data = NULL,
6513         .help_str = "show config rxtx|cores|fwd|txpkts",
6514         .tokens = {
6515                 (void *)&cmd_showcfg_show,
6516                 (void *)&cmd_showcfg_port,
6517                 (void *)&cmd_showcfg_what,
6518                 NULL,
6519         },
6520 };
6521
6522 /* *** SHOW ALL PORT INFO *** */
6523 struct cmd_showportall_result {
6524         cmdline_fixed_string_t show;
6525         cmdline_fixed_string_t port;
6526         cmdline_fixed_string_t what;
6527         cmdline_fixed_string_t all;
6528 };
6529
6530 static void cmd_showportall_parsed(void *parsed_result,
6531                                 __attribute__((unused)) struct cmdline *cl,
6532                                 __attribute__((unused)) void *data)
6533 {
6534         portid_t i;
6535
6536         struct cmd_showportall_result *res = parsed_result;
6537         if (!strcmp(res->show, "clear")) {
6538                 if (!strcmp(res->what, "stats"))
6539                         RTE_ETH_FOREACH_DEV(i)
6540                                 nic_stats_clear(i);
6541                 else if (!strcmp(res->what, "xstats"))
6542                         RTE_ETH_FOREACH_DEV(i)
6543                                 nic_xstats_clear(i);
6544         } else if (!strcmp(res->what, "info"))
6545                 RTE_ETH_FOREACH_DEV(i)
6546                         port_infos_display(i);
6547         else if (!strcmp(res->what, "stats"))
6548                 RTE_ETH_FOREACH_DEV(i)
6549                         nic_stats_display(i);
6550         else if (!strcmp(res->what, "xstats"))
6551                 RTE_ETH_FOREACH_DEV(i)
6552                         nic_xstats_display(i);
6553         else if (!strcmp(res->what, "fdir"))
6554                 RTE_ETH_FOREACH_DEV(i)
6555                         fdir_get_infos(i);
6556         else if (!strcmp(res->what, "stat_qmap"))
6557                 RTE_ETH_FOREACH_DEV(i)
6558                         nic_stats_mapping_display(i);
6559         else if (!strcmp(res->what, "dcb_tc"))
6560                 RTE_ETH_FOREACH_DEV(i)
6561                         port_dcb_info_display(i);
6562         else if (!strcmp(res->what, "cap"))
6563                 RTE_ETH_FOREACH_DEV(i)
6564                         port_offload_cap_display(i);
6565 }
6566
6567 cmdline_parse_token_string_t cmd_showportall_show =
6568         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6569                                  "show#clear");
6570 cmdline_parse_token_string_t cmd_showportall_port =
6571         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6572 cmdline_parse_token_string_t cmd_showportall_what =
6573         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6574                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6575 cmdline_parse_token_string_t cmd_showportall_all =
6576         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6577 cmdline_parse_inst_t cmd_showportall = {
6578         .f = cmd_showportall_parsed,
6579         .data = NULL,
6580         .help_str = "show|clear port "
6581                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6582         .tokens = {
6583                 (void *)&cmd_showportall_show,
6584                 (void *)&cmd_showportall_port,
6585                 (void *)&cmd_showportall_what,
6586                 (void *)&cmd_showportall_all,
6587                 NULL,
6588         },
6589 };
6590
6591 /* *** SHOW PORT INFO *** */
6592 struct cmd_showport_result {
6593         cmdline_fixed_string_t show;
6594         cmdline_fixed_string_t port;
6595         cmdline_fixed_string_t what;
6596         uint16_t portnum;
6597 };
6598
6599 static void cmd_showport_parsed(void *parsed_result,
6600                                 __attribute__((unused)) struct cmdline *cl,
6601                                 __attribute__((unused)) void *data)
6602 {
6603         struct cmd_showport_result *res = parsed_result;
6604         if (!strcmp(res->show, "clear")) {
6605                 if (!strcmp(res->what, "stats"))
6606                         nic_stats_clear(res->portnum);
6607                 else if (!strcmp(res->what, "xstats"))
6608                         nic_xstats_clear(res->portnum);
6609         } else if (!strcmp(res->what, "info"))
6610                 port_infos_display(res->portnum);
6611         else if (!strcmp(res->what, "stats"))
6612                 nic_stats_display(res->portnum);
6613         else if (!strcmp(res->what, "xstats"))
6614                 nic_xstats_display(res->portnum);
6615         else if (!strcmp(res->what, "fdir"))
6616                  fdir_get_infos(res->portnum);
6617         else if (!strcmp(res->what, "stat_qmap"))
6618                 nic_stats_mapping_display(res->portnum);
6619         else if (!strcmp(res->what, "dcb_tc"))
6620                 port_dcb_info_display(res->portnum);
6621         else if (!strcmp(res->what, "cap"))
6622                 port_offload_cap_display(res->portnum);
6623 }
6624
6625 cmdline_parse_token_string_t cmd_showport_show =
6626         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6627                                  "show#clear");
6628 cmdline_parse_token_string_t cmd_showport_port =
6629         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6630 cmdline_parse_token_string_t cmd_showport_what =
6631         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6632                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6633 cmdline_parse_token_num_t cmd_showport_portnum =
6634         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6635
6636 cmdline_parse_inst_t cmd_showport = {
6637         .f = cmd_showport_parsed,
6638         .data = NULL,
6639         .help_str = "show|clear port "
6640                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6641                 "<port_id>",
6642         .tokens = {
6643                 (void *)&cmd_showport_show,
6644                 (void *)&cmd_showport_port,
6645                 (void *)&cmd_showport_what,
6646                 (void *)&cmd_showport_portnum,
6647                 NULL,
6648         },
6649 };
6650
6651 /* *** SHOW QUEUE INFO *** */
6652 struct cmd_showqueue_result {
6653         cmdline_fixed_string_t show;
6654         cmdline_fixed_string_t type;
6655         cmdline_fixed_string_t what;
6656         uint16_t portnum;
6657         uint16_t queuenum;
6658 };
6659
6660 static void
6661 cmd_showqueue_parsed(void *parsed_result,
6662         __attribute__((unused)) struct cmdline *cl,
6663         __attribute__((unused)) void *data)
6664 {
6665         struct cmd_showqueue_result *res = parsed_result;
6666
6667         if (!strcmp(res->type, "rxq"))
6668                 rx_queue_infos_display(res->portnum, res->queuenum);
6669         else if (!strcmp(res->type, "txq"))
6670                 tx_queue_infos_display(res->portnum, res->queuenum);
6671 }
6672
6673 cmdline_parse_token_string_t cmd_showqueue_show =
6674         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6675 cmdline_parse_token_string_t cmd_showqueue_type =
6676         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6677 cmdline_parse_token_string_t cmd_showqueue_what =
6678         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6679 cmdline_parse_token_num_t cmd_showqueue_portnum =
6680         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6681 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6682         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6683
6684 cmdline_parse_inst_t cmd_showqueue = {
6685         .f = cmd_showqueue_parsed,
6686         .data = NULL,
6687         .help_str = "show rxq|txq info <port_id> <queue_id>",
6688         .tokens = {
6689                 (void *)&cmd_showqueue_show,
6690                 (void *)&cmd_showqueue_type,
6691                 (void *)&cmd_showqueue_what,
6692                 (void *)&cmd_showqueue_portnum,
6693                 (void *)&cmd_showqueue_queuenum,
6694                 NULL,
6695         },
6696 };
6697
6698 /* *** READ PORT REGISTER *** */
6699 struct cmd_read_reg_result {
6700         cmdline_fixed_string_t read;
6701         cmdline_fixed_string_t reg;
6702         portid_t port_id;
6703         uint32_t reg_off;
6704 };
6705
6706 static void
6707 cmd_read_reg_parsed(void *parsed_result,
6708                     __attribute__((unused)) struct cmdline *cl,
6709                     __attribute__((unused)) void *data)
6710 {
6711         struct cmd_read_reg_result *res = parsed_result;
6712         port_reg_display(res->port_id, res->reg_off);
6713 }
6714
6715 cmdline_parse_token_string_t cmd_read_reg_read =
6716         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6717 cmdline_parse_token_string_t cmd_read_reg_reg =
6718         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6719 cmdline_parse_token_num_t cmd_read_reg_port_id =
6720         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6721 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6722         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6723
6724 cmdline_parse_inst_t cmd_read_reg = {
6725         .f = cmd_read_reg_parsed,
6726         .data = NULL,
6727         .help_str = "read reg <port_id> <reg_off>",
6728         .tokens = {
6729                 (void *)&cmd_read_reg_read,
6730                 (void *)&cmd_read_reg_reg,
6731                 (void *)&cmd_read_reg_port_id,
6732                 (void *)&cmd_read_reg_reg_off,
6733                 NULL,
6734         },
6735 };
6736
6737 /* *** READ PORT REGISTER BIT FIELD *** */
6738 struct cmd_read_reg_bit_field_result {
6739         cmdline_fixed_string_t read;
6740         cmdline_fixed_string_t regfield;
6741         portid_t port_id;
6742         uint32_t reg_off;
6743         uint8_t bit1_pos;
6744         uint8_t bit2_pos;
6745 };
6746
6747 static void
6748 cmd_read_reg_bit_field_parsed(void *parsed_result,
6749                               __attribute__((unused)) struct cmdline *cl,
6750                               __attribute__((unused)) void *data)
6751 {
6752         struct cmd_read_reg_bit_field_result *res = parsed_result;
6753         port_reg_bit_field_display(res->port_id, res->reg_off,
6754                                    res->bit1_pos, res->bit2_pos);
6755 }
6756
6757 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6758         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6759                                  "read");
6760 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6761         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6762                                  regfield, "regfield");
6763 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6764         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6765                               UINT16);
6766 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6767         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6768                               UINT32);
6769 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6770         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6771                               UINT8);
6772 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6773         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6774                               UINT8);
6775
6776 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6777         .f = cmd_read_reg_bit_field_parsed,
6778         .data = NULL,
6779         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6780         "Read register bit field between bit_x and bit_y included",
6781         .tokens = {
6782                 (void *)&cmd_read_reg_bit_field_read,
6783                 (void *)&cmd_read_reg_bit_field_regfield,
6784                 (void *)&cmd_read_reg_bit_field_port_id,
6785                 (void *)&cmd_read_reg_bit_field_reg_off,
6786                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6787                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6788                 NULL,
6789         },
6790 };
6791
6792 /* *** READ PORT REGISTER BIT *** */
6793 struct cmd_read_reg_bit_result {
6794         cmdline_fixed_string_t read;
6795         cmdline_fixed_string_t regbit;
6796         portid_t port_id;
6797         uint32_t reg_off;
6798         uint8_t bit_pos;
6799 };
6800
6801 static void
6802 cmd_read_reg_bit_parsed(void *parsed_result,
6803                         __attribute__((unused)) struct cmdline *cl,
6804                         __attribute__((unused)) void *data)
6805 {
6806         struct cmd_read_reg_bit_result *res = parsed_result;
6807         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6808 }
6809
6810 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6811         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6812 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6813         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6814                                  regbit, "regbit");
6815 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6816         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6817 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6818         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6819 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6820         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6821
6822 cmdline_parse_inst_t cmd_read_reg_bit = {
6823         .f = cmd_read_reg_bit_parsed,
6824         .data = NULL,
6825         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6826         .tokens = {
6827                 (void *)&cmd_read_reg_bit_read,
6828                 (void *)&cmd_read_reg_bit_regbit,
6829                 (void *)&cmd_read_reg_bit_port_id,
6830                 (void *)&cmd_read_reg_bit_reg_off,
6831                 (void *)&cmd_read_reg_bit_bit_pos,
6832                 NULL,
6833         },
6834 };
6835
6836 /* *** WRITE PORT REGISTER *** */
6837 struct cmd_write_reg_result {
6838         cmdline_fixed_string_t write;
6839         cmdline_fixed_string_t reg;
6840         portid_t port_id;
6841         uint32_t reg_off;
6842         uint32_t value;
6843 };
6844
6845 static void
6846 cmd_write_reg_parsed(void *parsed_result,
6847                      __attribute__((unused)) struct cmdline *cl,
6848                      __attribute__((unused)) void *data)
6849 {
6850         struct cmd_write_reg_result *res = parsed_result;
6851         port_reg_set(res->port_id, res->reg_off, res->value);
6852 }
6853
6854 cmdline_parse_token_string_t cmd_write_reg_write =
6855         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6856 cmdline_parse_token_string_t cmd_write_reg_reg =
6857         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6858 cmdline_parse_token_num_t cmd_write_reg_port_id =
6859         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6860 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6861         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6862 cmdline_parse_token_num_t cmd_write_reg_value =
6863         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6864
6865 cmdline_parse_inst_t cmd_write_reg = {
6866         .f = cmd_write_reg_parsed,
6867         .data = NULL,
6868         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6869         .tokens = {
6870                 (void *)&cmd_write_reg_write,
6871                 (void *)&cmd_write_reg_reg,
6872                 (void *)&cmd_write_reg_port_id,
6873                 (void *)&cmd_write_reg_reg_off,
6874                 (void *)&cmd_write_reg_value,
6875                 NULL,
6876         },
6877 };
6878
6879 /* *** WRITE PORT REGISTER BIT FIELD *** */
6880 struct cmd_write_reg_bit_field_result {
6881         cmdline_fixed_string_t write;
6882         cmdline_fixed_string_t regfield;
6883         portid_t port_id;
6884         uint32_t reg_off;
6885         uint8_t bit1_pos;
6886         uint8_t bit2_pos;
6887         uint32_t value;
6888 };
6889
6890 static void
6891 cmd_write_reg_bit_field_parsed(void *parsed_result,
6892                                __attribute__((unused)) struct cmdline *cl,
6893                                __attribute__((unused)) void *data)
6894 {
6895         struct cmd_write_reg_bit_field_result *res = parsed_result;
6896         port_reg_bit_field_set(res->port_id, res->reg_off,
6897                           res->bit1_pos, res->bit2_pos, res->value);
6898 }
6899
6900 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6901         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6902                                  "write");
6903 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6904         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6905                                  regfield, "regfield");
6906 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6907         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6908                               UINT16);
6909 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6910         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6911                               UINT32);
6912 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6913         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6914                               UINT8);
6915 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6916         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6917                               UINT8);
6918 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6919         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6920                               UINT32);
6921
6922 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6923         .f = cmd_write_reg_bit_field_parsed,
6924         .data = NULL,
6925         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6926                 "<reg_value>: "
6927                 "Set register bit field between bit_x and bit_y included",
6928         .tokens = {
6929                 (void *)&cmd_write_reg_bit_field_write,
6930                 (void *)&cmd_write_reg_bit_field_regfield,
6931                 (void *)&cmd_write_reg_bit_field_port_id,
6932                 (void *)&cmd_write_reg_bit_field_reg_off,
6933                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6934                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6935                 (void *)&cmd_write_reg_bit_field_value,
6936                 NULL,
6937         },
6938 };
6939
6940 /* *** WRITE PORT REGISTER BIT *** */
6941 struct cmd_write_reg_bit_result {
6942         cmdline_fixed_string_t write;
6943         cmdline_fixed_string_t regbit;
6944         portid_t port_id;
6945         uint32_t reg_off;
6946         uint8_t bit_pos;
6947         uint8_t value;
6948 };
6949
6950 static void
6951 cmd_write_reg_bit_parsed(void *parsed_result,
6952                          __attribute__((unused)) struct cmdline *cl,
6953                          __attribute__((unused)) void *data)
6954 {
6955         struct cmd_write_reg_bit_result *res = parsed_result;
6956         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6957 }
6958
6959 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6960         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6961                                  "write");
6962 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6963         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6964                                  regbit, "regbit");
6965 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6966         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6967 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6968         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6969 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6970         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6971 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6972         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6973
6974 cmdline_parse_inst_t cmd_write_reg_bit = {
6975         .f = cmd_write_reg_bit_parsed,
6976         .data = NULL,
6977         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6978                 "0 <= bit_x <= 31",
6979         .tokens = {
6980                 (void *)&cmd_write_reg_bit_write,
6981                 (void *)&cmd_write_reg_bit_regbit,
6982                 (void *)&cmd_write_reg_bit_port_id,
6983                 (void *)&cmd_write_reg_bit_reg_off,
6984                 (void *)&cmd_write_reg_bit_bit_pos,
6985                 (void *)&cmd_write_reg_bit_value,
6986                 NULL,
6987         },
6988 };
6989
6990 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6991 struct cmd_read_rxd_txd_result {
6992         cmdline_fixed_string_t read;
6993         cmdline_fixed_string_t rxd_txd;
6994         portid_t port_id;
6995         uint16_t queue_id;
6996         uint16_t desc_id;
6997 };
6998
6999 static void
7000 cmd_read_rxd_txd_parsed(void *parsed_result,
7001                         __attribute__((unused)) struct cmdline *cl,
7002                         __attribute__((unused)) void *data)
7003 {
7004         struct cmd_read_rxd_txd_result *res = parsed_result;
7005
7006         if (!strcmp(res->rxd_txd, "rxd"))
7007                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7008         else if (!strcmp(res->rxd_txd, "txd"))
7009                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7010 }
7011
7012 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7013         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7014 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7015         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7016                                  "rxd#txd");
7017 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7018         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7019 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7020         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7021 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7022         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7023
7024 cmdline_parse_inst_t cmd_read_rxd_txd = {
7025         .f = cmd_read_rxd_txd_parsed,
7026         .data = NULL,
7027         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7028         .tokens = {
7029                 (void *)&cmd_read_rxd_txd_read,
7030                 (void *)&cmd_read_rxd_txd_rxd_txd,
7031                 (void *)&cmd_read_rxd_txd_port_id,
7032                 (void *)&cmd_read_rxd_txd_queue_id,
7033                 (void *)&cmd_read_rxd_txd_desc_id,
7034                 NULL,
7035         },
7036 };
7037
7038 /* *** QUIT *** */
7039 struct cmd_quit_result {
7040         cmdline_fixed_string_t quit;
7041 };
7042
7043 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7044                             struct cmdline *cl,
7045                             __attribute__((unused)) void *data)
7046 {
7047         pmd_test_exit();
7048         cmdline_quit(cl);
7049 }
7050
7051 cmdline_parse_token_string_t cmd_quit_quit =
7052         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7053
7054 cmdline_parse_inst_t cmd_quit = {
7055         .f = cmd_quit_parsed,
7056         .data = NULL,
7057         .help_str = "quit: Exit application",
7058         .tokens = {
7059                 (void *)&cmd_quit_quit,
7060                 NULL,
7061         },
7062 };
7063
7064 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7065 struct cmd_mac_addr_result {
7066         cmdline_fixed_string_t mac_addr_cmd;
7067         cmdline_fixed_string_t what;
7068         uint16_t port_num;
7069         struct ether_addr address;
7070 };
7071
7072 static void cmd_mac_addr_parsed(void *parsed_result,
7073                 __attribute__((unused)) struct cmdline *cl,
7074                 __attribute__((unused)) void *data)
7075 {
7076         struct cmd_mac_addr_result *res = parsed_result;
7077         int ret;
7078
7079         if (strcmp(res->what, "add") == 0)
7080                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7081         else if (strcmp(res->what, "set") == 0)
7082                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7083                                                        &res->address);
7084         else
7085                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7086
7087         /* check the return value and print it if is < 0 */
7088         if(ret < 0)
7089                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7090
7091 }
7092
7093 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7094         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7095                                 "mac_addr");
7096 cmdline_parse_token_string_t cmd_mac_addr_what =
7097         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7098                                 "add#remove#set");
7099 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7100                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7101                                         UINT16);
7102 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7103                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7104
7105 cmdline_parse_inst_t cmd_mac_addr = {
7106         .f = cmd_mac_addr_parsed,
7107         .data = (void *)0,
7108         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7109                         "Add/Remove/Set MAC address on port_id",
7110         .tokens = {
7111                 (void *)&cmd_mac_addr_cmd,
7112                 (void *)&cmd_mac_addr_what,
7113                 (void *)&cmd_mac_addr_portnum,
7114                 (void *)&cmd_mac_addr_addr,
7115                 NULL,
7116         },
7117 };
7118
7119
7120 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7121 struct cmd_set_qmap_result {
7122         cmdline_fixed_string_t set;
7123         cmdline_fixed_string_t qmap;
7124         cmdline_fixed_string_t what;
7125         portid_t port_id;
7126         uint16_t queue_id;
7127         uint8_t map_value;
7128 };
7129
7130 static void
7131 cmd_set_qmap_parsed(void *parsed_result,
7132                        __attribute__((unused)) struct cmdline *cl,
7133                        __attribute__((unused)) void *data)
7134 {
7135         struct cmd_set_qmap_result *res = parsed_result;
7136         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7137
7138         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7139 }
7140
7141 cmdline_parse_token_string_t cmd_setqmap_set =
7142         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7143                                  set, "set");
7144 cmdline_parse_token_string_t cmd_setqmap_qmap =
7145         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7146                                  qmap, "stat_qmap");
7147 cmdline_parse_token_string_t cmd_setqmap_what =
7148         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7149                                  what, "tx#rx");
7150 cmdline_parse_token_num_t cmd_setqmap_portid =
7151         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7152                               port_id, UINT16);
7153 cmdline_parse_token_num_t cmd_setqmap_queueid =
7154         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7155                               queue_id, UINT16);
7156 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7157         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7158                               map_value, UINT8);
7159
7160 cmdline_parse_inst_t cmd_set_qmap = {
7161         .f = cmd_set_qmap_parsed,
7162         .data = NULL,
7163         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7164                 "Set statistics mapping value on tx|rx queue_id of port_id",
7165         .tokens = {
7166                 (void *)&cmd_setqmap_set,
7167                 (void *)&cmd_setqmap_qmap,
7168                 (void *)&cmd_setqmap_what,
7169                 (void *)&cmd_setqmap_portid,
7170                 (void *)&cmd_setqmap_queueid,
7171                 (void *)&cmd_setqmap_mapvalue,
7172                 NULL,
7173         },
7174 };
7175
7176 /* *** CONFIGURE UNICAST HASH TABLE *** */
7177 struct cmd_set_uc_hash_table {
7178         cmdline_fixed_string_t set;
7179         cmdline_fixed_string_t port;
7180         portid_t port_id;
7181         cmdline_fixed_string_t what;
7182         struct ether_addr address;
7183         cmdline_fixed_string_t mode;
7184 };
7185
7186 static void
7187 cmd_set_uc_hash_parsed(void *parsed_result,
7188                        __attribute__((unused)) struct cmdline *cl,
7189                        __attribute__((unused)) void *data)
7190 {
7191         int ret=0;
7192         struct cmd_set_uc_hash_table *res = parsed_result;
7193
7194         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7195
7196         if (strcmp(res->what, "uta") == 0)
7197                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7198                                                 &res->address,(uint8_t)is_on);
7199         if (ret < 0)
7200                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7201
7202 }
7203
7204 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7205         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7206                                  set, "set");
7207 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7208         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7209                                  port, "port");
7210 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7211         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7212                               port_id, UINT16);
7213 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7215                                  what, "uta");
7216 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7217         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7218                                 address);
7219 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7221                                  mode, "on#off");
7222
7223 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7224         .f = cmd_set_uc_hash_parsed,
7225         .data = NULL,
7226         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7227         .tokens = {
7228                 (void *)&cmd_set_uc_hash_set,
7229                 (void *)&cmd_set_uc_hash_port,
7230                 (void *)&cmd_set_uc_hash_portid,
7231                 (void *)&cmd_set_uc_hash_what,
7232                 (void *)&cmd_set_uc_hash_mac,
7233                 (void *)&cmd_set_uc_hash_mode,
7234                 NULL,
7235         },
7236 };
7237
7238 struct cmd_set_uc_all_hash_table {
7239         cmdline_fixed_string_t set;
7240         cmdline_fixed_string_t port;
7241         portid_t port_id;
7242         cmdline_fixed_string_t what;
7243         cmdline_fixed_string_t value;
7244         cmdline_fixed_string_t mode;
7245 };
7246
7247 static void
7248 cmd_set_uc_all_hash_parsed(void *parsed_result,
7249                        __attribute__((unused)) struct cmdline *cl,
7250                        __attribute__((unused)) void *data)
7251 {
7252         int ret=0;
7253         struct cmd_set_uc_all_hash_table *res = parsed_result;
7254
7255         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7256
7257         if ((strcmp(res->what, "uta") == 0) &&
7258                 (strcmp(res->value, "all") == 0))
7259                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7260         if (ret < 0)
7261                 printf("bad unicast hash table parameter,"
7262                         "return code = %d \n", ret);
7263 }
7264
7265 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7266         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7267                                  set, "set");
7268 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7269         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7270                                  port, "port");
7271 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7272         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7273                               port_id, UINT16);
7274 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7275         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7276                                  what, "uta");
7277 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7278         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7279                                 value,"all");
7280 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7281         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7282                                  mode, "on#off");
7283
7284 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7285         .f = cmd_set_uc_all_hash_parsed,
7286         .data = NULL,
7287         .help_str = "set port <port_id> uta all on|off",
7288         .tokens = {
7289                 (void *)&cmd_set_uc_all_hash_set,
7290                 (void *)&cmd_set_uc_all_hash_port,
7291                 (void *)&cmd_set_uc_all_hash_portid,
7292                 (void *)&cmd_set_uc_all_hash_what,
7293                 (void *)&cmd_set_uc_all_hash_value,
7294                 (void *)&cmd_set_uc_all_hash_mode,
7295                 NULL,
7296         },
7297 };
7298
7299 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7300 struct cmd_set_vf_macvlan_filter {
7301         cmdline_fixed_string_t set;
7302         cmdline_fixed_string_t port;
7303         portid_t port_id;
7304         cmdline_fixed_string_t vf;
7305         uint8_t vf_id;
7306         struct ether_addr address;
7307         cmdline_fixed_string_t filter_type;
7308         cmdline_fixed_string_t mode;
7309 };
7310
7311 static void
7312 cmd_set_vf_macvlan_parsed(void *parsed_result,
7313                        __attribute__((unused)) struct cmdline *cl,
7314                        __attribute__((unused)) void *data)
7315 {
7316         int is_on, ret = 0;
7317         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7318         struct rte_eth_mac_filter filter;
7319
7320         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7321
7322         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7323
7324         /* set VF MAC filter */
7325         filter.is_vf = 1;
7326
7327         /* set VF ID */
7328         filter.dst_id = res->vf_id;
7329
7330         if (!strcmp(res->filter_type, "exact-mac"))
7331                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7332         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7333                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7334         else if (!strcmp(res->filter_type, "hashmac"))
7335                 filter.filter_type = RTE_MAC_HASH_MATCH;
7336         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7337                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7338
7339         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7340
7341         if (is_on)
7342                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7343                                         RTE_ETH_FILTER_MACVLAN,
7344                                         RTE_ETH_FILTER_ADD,
7345                                          &filter);
7346         else
7347                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7348                                         RTE_ETH_FILTER_MACVLAN,
7349                                         RTE_ETH_FILTER_DELETE,
7350                                         &filter);
7351
7352         if (ret < 0)
7353                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7354
7355 }
7356
7357 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7358         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7359                                  set, "set");
7360 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7361         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7362                                  port, "port");
7363 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7364         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7365                               port_id, UINT16);
7366 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7367         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7368                                  vf, "vf");
7369 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7370         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7371                                 vf_id, UINT8);
7372 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7373         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7374                                 address);
7375 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7376         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7377                                 filter_type, "exact-mac#exact-mac-vlan"
7378                                 "#hashmac#hashmac-vlan");
7379 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7380         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7381                                  mode, "on#off");
7382
7383 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7384         .f = cmd_set_vf_macvlan_parsed,
7385         .data = NULL,
7386         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7387                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7388                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7389                 "hash match rule: hash match of MAC and exact match of VLAN",
7390         .tokens = {
7391                 (void *)&cmd_set_vf_macvlan_set,
7392                 (void *)&cmd_set_vf_macvlan_port,
7393                 (void *)&cmd_set_vf_macvlan_portid,
7394                 (void *)&cmd_set_vf_macvlan_vf,
7395                 (void *)&cmd_set_vf_macvlan_vf_id,
7396                 (void *)&cmd_set_vf_macvlan_mac,
7397                 (void *)&cmd_set_vf_macvlan_filter_type,
7398                 (void *)&cmd_set_vf_macvlan_mode,
7399                 NULL,
7400         },
7401 };
7402
7403 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7404 struct cmd_set_vf_traffic {
7405         cmdline_fixed_string_t set;
7406         cmdline_fixed_string_t port;
7407         portid_t port_id;
7408         cmdline_fixed_string_t vf;
7409         uint8_t vf_id;
7410         cmdline_fixed_string_t what;
7411         cmdline_fixed_string_t mode;
7412 };
7413
7414 static void
7415 cmd_set_vf_traffic_parsed(void *parsed_result,
7416                        __attribute__((unused)) struct cmdline *cl,
7417                        __attribute__((unused)) void *data)
7418 {
7419         struct cmd_set_vf_traffic *res = parsed_result;
7420         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7421         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7422
7423         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7424 }
7425
7426 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7427         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7428                                  set, "set");
7429 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7431                                  port, "port");
7432 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7433         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7434                               port_id, UINT16);
7435 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7437                                  vf, "vf");
7438 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7439         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7440                               vf_id, UINT8);
7441 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7443                                  what, "tx#rx");
7444 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7445         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7446                                  mode, "on#off");
7447
7448 cmdline_parse_inst_t cmd_set_vf_traffic = {
7449         .f = cmd_set_vf_traffic_parsed,
7450         .data = NULL,
7451         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7452         .tokens = {
7453                 (void *)&cmd_setvf_traffic_set,
7454                 (void *)&cmd_setvf_traffic_port,
7455                 (void *)&cmd_setvf_traffic_portid,
7456                 (void *)&cmd_setvf_traffic_vf,
7457                 (void *)&cmd_setvf_traffic_vfid,
7458                 (void *)&cmd_setvf_traffic_what,
7459                 (void *)&cmd_setvf_traffic_mode,
7460                 NULL,
7461         },
7462 };
7463
7464 /* *** CONFIGURE VF RECEIVE MODE *** */
7465 struct cmd_set_vf_rxmode {
7466         cmdline_fixed_string_t set;
7467         cmdline_fixed_string_t port;
7468         portid_t port_id;
7469         cmdline_fixed_string_t vf;
7470         uint8_t vf_id;
7471         cmdline_fixed_string_t what;
7472         cmdline_fixed_string_t mode;
7473         cmdline_fixed_string_t on;
7474 };
7475
7476 static void
7477 cmd_set_vf_rxmode_parsed(void *parsed_result,
7478                        __attribute__((unused)) struct cmdline *cl,
7479                        __attribute__((unused)) void *data)
7480 {
7481         int ret = -ENOTSUP;
7482         uint16_t rx_mode = 0;
7483         struct cmd_set_vf_rxmode *res = parsed_result;
7484
7485         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7486         if (!strcmp(res->what,"rxmode")) {
7487                 if (!strcmp(res->mode, "AUPE"))
7488                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7489                 else if (!strcmp(res->mode, "ROPE"))
7490                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7491                 else if (!strcmp(res->mode, "BAM"))
7492                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7493                 else if (!strncmp(res->mode, "MPE",3))
7494                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7495         }
7496
7497         RTE_SET_USED(is_on);
7498
7499 #ifdef RTE_LIBRTE_IXGBE_PMD
7500         if (ret == -ENOTSUP)
7501                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7502                                                   rx_mode, (uint8_t)is_on);
7503 #endif
7504 #ifdef RTE_LIBRTE_BNXT_PMD
7505         if (ret == -ENOTSUP)
7506                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7507                                                  rx_mode, (uint8_t)is_on);
7508 #endif
7509         if (ret < 0)
7510                 printf("bad VF receive mode parameter, return code = %d \n",
7511                 ret);
7512 }
7513
7514 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7515         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7516                                  set, "set");
7517 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7518         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7519                                  port, "port");
7520 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7521         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7522                               port_id, UINT16);
7523 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7524         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7525                                  vf, "vf");
7526 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7527         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7528                               vf_id, UINT8);
7529 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7530         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7531                                  what, "rxmode");
7532 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7533         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7534                                  mode, "AUPE#ROPE#BAM#MPE");
7535 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7536         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7537                                  on, "on#off");
7538
7539 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7540         .f = cmd_set_vf_rxmode_parsed,
7541         .data = NULL,
7542         .help_str = "set port <port_id> vf <vf_id> rxmode "
7543                 "AUPE|ROPE|BAM|MPE on|off",
7544         .tokens = {
7545                 (void *)&cmd_set_vf_rxmode_set,
7546                 (void *)&cmd_set_vf_rxmode_port,
7547                 (void *)&cmd_set_vf_rxmode_portid,
7548                 (void *)&cmd_set_vf_rxmode_vf,
7549                 (void *)&cmd_set_vf_rxmode_vfid,
7550                 (void *)&cmd_set_vf_rxmode_what,
7551                 (void *)&cmd_set_vf_rxmode_mode,
7552                 (void *)&cmd_set_vf_rxmode_on,
7553                 NULL,
7554         },
7555 };
7556
7557 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7558 struct cmd_vf_mac_addr_result {
7559         cmdline_fixed_string_t mac_addr_cmd;
7560         cmdline_fixed_string_t what;
7561         cmdline_fixed_string_t port;
7562         uint16_t port_num;
7563         cmdline_fixed_string_t vf;
7564         uint8_t vf_num;
7565         struct ether_addr address;
7566 };
7567
7568 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7569                 __attribute__((unused)) struct cmdline *cl,
7570                 __attribute__((unused)) void *data)
7571 {
7572         struct cmd_vf_mac_addr_result *res = parsed_result;
7573         int ret = -ENOTSUP;
7574
7575         if (strcmp(res->what, "add") != 0)
7576                 return;
7577
7578 #ifdef RTE_LIBRTE_I40E_PMD
7579         if (ret == -ENOTSUP)
7580                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7581                                                    &res->address);
7582 #endif
7583 #ifdef RTE_LIBRTE_BNXT_PMD
7584         if (ret == -ENOTSUP)
7585                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7586                                                 res->vf_num);
7587 #endif
7588
7589         if(ret < 0)
7590                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7591
7592 }
7593
7594 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7595         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7596                                 mac_addr_cmd,"mac_addr");
7597 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7598         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7599                                 what,"add");
7600 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7601         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7602                                 port,"port");
7603 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7604         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7605                                 port_num, UINT16);
7606 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7607         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7608                                 vf,"vf");
7609 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7610         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7611                                 vf_num, UINT8);
7612 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7613         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7614                                 address);
7615
7616 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7617         .f = cmd_vf_mac_addr_parsed,
7618         .data = (void *)0,
7619         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7620                 "Add MAC address filtering for a VF on port_id",
7621         .tokens = {
7622                 (void *)&cmd_vf_mac_addr_cmd,
7623                 (void *)&cmd_vf_mac_addr_what,
7624                 (void *)&cmd_vf_mac_addr_port,
7625                 (void *)&cmd_vf_mac_addr_portnum,
7626                 (void *)&cmd_vf_mac_addr_vf,
7627                 (void *)&cmd_vf_mac_addr_vfnum,
7628                 (void *)&cmd_vf_mac_addr_addr,
7629                 NULL,
7630         },
7631 };
7632
7633 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7634 struct cmd_vf_rx_vlan_filter {
7635         cmdline_fixed_string_t rx_vlan;
7636         cmdline_fixed_string_t what;
7637         uint16_t vlan_id;
7638         cmdline_fixed_string_t port;
7639         portid_t port_id;
7640         cmdline_fixed_string_t vf;
7641         uint64_t vf_mask;
7642 };
7643
7644 static void
7645 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7646                           __attribute__((unused)) struct cmdline *cl,
7647                           __attribute__((unused)) void *data)
7648 {
7649         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7650         int ret = -ENOTSUP;
7651
7652         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7653
7654 #ifdef RTE_LIBRTE_IXGBE_PMD
7655         if (ret == -ENOTSUP)
7656                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7657                                 res->vlan_id, res->vf_mask, is_add);
7658 #endif
7659 #ifdef RTE_LIBRTE_I40E_PMD
7660         if (ret == -ENOTSUP)
7661                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7662                                 res->vlan_id, res->vf_mask, is_add);
7663 #endif
7664 #ifdef RTE_LIBRTE_BNXT_PMD
7665         if (ret == -ENOTSUP)
7666                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7667                                 res->vlan_id, res->vf_mask, is_add);
7668 #endif
7669
7670         switch (ret) {
7671         case 0:
7672                 break;
7673         case -EINVAL:
7674                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7675                                 res->vlan_id, res->vf_mask);
7676                 break;
7677         case -ENODEV:
7678                 printf("invalid port_id %d\n", res->port_id);
7679                 break;
7680         case -ENOTSUP:
7681                 printf("function not implemented or supported\n");
7682                 break;
7683         default:
7684                 printf("programming error: (%s)\n", strerror(-ret));
7685         }
7686 }
7687
7688 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7689         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7690                                  rx_vlan, "rx_vlan");
7691 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7692         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7693                                  what, "add#rm");
7694 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7695         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7696                               vlan_id, UINT16);
7697 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7698         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7699                                  port, "port");
7700 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7701         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7702                               port_id, UINT16);
7703 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7704         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7705                                  vf, "vf");
7706 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7707         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7708                               vf_mask, UINT64);
7709
7710 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7711         .f = cmd_vf_rx_vlan_filter_parsed,
7712         .data = NULL,
7713         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7714                 "(vf_mask = hexadecimal VF mask)",
7715         .tokens = {
7716                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7717                 (void *)&cmd_vf_rx_vlan_filter_what,
7718                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7719                 (void *)&cmd_vf_rx_vlan_filter_port,
7720                 (void *)&cmd_vf_rx_vlan_filter_portid,
7721                 (void *)&cmd_vf_rx_vlan_filter_vf,
7722                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7723                 NULL,
7724         },
7725 };
7726
7727 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7728 struct cmd_queue_rate_limit_result {
7729         cmdline_fixed_string_t set;
7730         cmdline_fixed_string_t port;
7731         uint16_t port_num;
7732         cmdline_fixed_string_t queue;
7733         uint8_t queue_num;
7734         cmdline_fixed_string_t rate;
7735         uint16_t rate_num;
7736 };
7737
7738 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7739                 __attribute__((unused)) struct cmdline *cl,
7740                 __attribute__((unused)) void *data)
7741 {
7742         struct cmd_queue_rate_limit_result *res = parsed_result;
7743         int ret = 0;
7744
7745         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7746                 && (strcmp(res->queue, "queue") == 0)
7747                 && (strcmp(res->rate, "rate") == 0))
7748                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7749                                         res->rate_num);
7750         if (ret < 0)
7751                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7752
7753 }
7754
7755 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7756         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7757                                 set, "set");
7758 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7759         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7760                                 port, "port");
7761 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7762         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7763                                 port_num, UINT16);
7764 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7765         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7766                                 queue, "queue");
7767 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7768         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7769                                 queue_num, UINT8);
7770 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7771         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7772                                 rate, "rate");
7773 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7774         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7775                                 rate_num, UINT16);
7776
7777 cmdline_parse_inst_t cmd_queue_rate_limit = {
7778         .f = cmd_queue_rate_limit_parsed,
7779         .data = (void *)0,
7780         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7781                 "Set rate limit for a queue on port_id",
7782         .tokens = {
7783                 (void *)&cmd_queue_rate_limit_set,
7784                 (void *)&cmd_queue_rate_limit_port,
7785                 (void *)&cmd_queue_rate_limit_portnum,
7786                 (void *)&cmd_queue_rate_limit_queue,
7787                 (void *)&cmd_queue_rate_limit_queuenum,
7788                 (void *)&cmd_queue_rate_limit_rate,
7789                 (void *)&cmd_queue_rate_limit_ratenum,
7790                 NULL,
7791         },
7792 };
7793
7794 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7795 struct cmd_vf_rate_limit_result {
7796         cmdline_fixed_string_t set;
7797         cmdline_fixed_string_t port;
7798         uint16_t port_num;
7799         cmdline_fixed_string_t vf;
7800         uint8_t vf_num;
7801         cmdline_fixed_string_t rate;
7802         uint16_t rate_num;
7803         cmdline_fixed_string_t q_msk;
7804         uint64_t q_msk_val;
7805 };
7806
7807 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7808                 __attribute__((unused)) struct cmdline *cl,
7809                 __attribute__((unused)) void *data)
7810 {
7811         struct cmd_vf_rate_limit_result *res = parsed_result;
7812         int ret = 0;
7813
7814         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7815                 && (strcmp(res->vf, "vf") == 0)
7816                 && (strcmp(res->rate, "rate") == 0)
7817                 && (strcmp(res->q_msk, "queue_mask") == 0))
7818                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7819                                         res->rate_num, res->q_msk_val);
7820         if (ret < 0)
7821                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7822
7823 }
7824
7825 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7826         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7827                                 set, "set");
7828 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7829         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7830                                 port, "port");
7831 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7832         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7833                                 port_num, UINT16);
7834 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7835         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7836                                 vf, "vf");
7837 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7838         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7839                                 vf_num, UINT8);
7840 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7841         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7842                                 rate, "rate");
7843 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7844         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7845                                 rate_num, UINT16);
7846 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7847         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7848                                 q_msk, "queue_mask");
7849 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7850         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7851                                 q_msk_val, UINT64);
7852
7853 cmdline_parse_inst_t cmd_vf_rate_limit = {
7854         .f = cmd_vf_rate_limit_parsed,
7855         .data = (void *)0,
7856         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7857                 "queue_mask <queue_mask_value>: "
7858                 "Set rate limit for queues of VF on port_id",
7859         .tokens = {
7860                 (void *)&cmd_vf_rate_limit_set,
7861                 (void *)&cmd_vf_rate_limit_port,
7862                 (void *)&cmd_vf_rate_limit_portnum,
7863                 (void *)&cmd_vf_rate_limit_vf,
7864                 (void *)&cmd_vf_rate_limit_vfnum,
7865                 (void *)&cmd_vf_rate_limit_rate,
7866                 (void *)&cmd_vf_rate_limit_ratenum,
7867                 (void *)&cmd_vf_rate_limit_q_msk,
7868                 (void *)&cmd_vf_rate_limit_q_msk_val,
7869                 NULL,
7870         },
7871 };
7872
7873 /* *** ADD TUNNEL FILTER OF A PORT *** */
7874 struct cmd_tunnel_filter_result {
7875         cmdline_fixed_string_t cmd;
7876         cmdline_fixed_string_t what;
7877         portid_t port_id;
7878         struct ether_addr outer_mac;
7879         struct ether_addr inner_mac;
7880         cmdline_ipaddr_t ip_value;
7881         uint16_t inner_vlan;
7882         cmdline_fixed_string_t tunnel_type;
7883         cmdline_fixed_string_t filter_type;
7884         uint32_t tenant_id;
7885         uint16_t queue_num;
7886 };
7887
7888 static void
7889 cmd_tunnel_filter_parsed(void *parsed_result,
7890                           __attribute__((unused)) struct cmdline *cl,
7891                           __attribute__((unused)) void *data)
7892 {
7893         struct cmd_tunnel_filter_result *res = parsed_result;
7894         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7895         int ret = 0;
7896
7897         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7898
7899         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7900         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7901         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7902
7903         if (res->ip_value.family == AF_INET) {
7904                 tunnel_filter_conf.ip_addr.ipv4_addr =
7905                         res->ip_value.addr.ipv4.s_addr;
7906                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7907         } else {
7908                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7909                         &(res->ip_value.addr.ipv6),
7910                         sizeof(struct in6_addr));
7911                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7912         }
7913
7914         if (!strcmp(res->filter_type, "imac-ivlan"))
7915                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7916         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7917                 tunnel_filter_conf.filter_type =
7918                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7919         else if (!strcmp(res->filter_type, "imac-tenid"))
7920                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7921         else if (!strcmp(res->filter_type, "imac"))
7922                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7923         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7924                 tunnel_filter_conf.filter_type =
7925                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7926         else if (!strcmp(res->filter_type, "oip"))
7927                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7928         else if (!strcmp(res->filter_type, "iip"))
7929                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7930         else {
7931                 printf("The filter type is not supported");
7932                 return;
7933         }
7934
7935         if (!strcmp(res->tunnel_type, "vxlan"))
7936                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7937         else if (!strcmp(res->tunnel_type, "nvgre"))
7938                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7939         else if (!strcmp(res->tunnel_type, "ipingre"))
7940                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7941         else {
7942                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7943                 return;
7944         }
7945
7946         tunnel_filter_conf.tenant_id = res->tenant_id;
7947         tunnel_filter_conf.queue_id = res->queue_num;
7948         if (!strcmp(res->what, "add"))
7949                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7950                                         RTE_ETH_FILTER_TUNNEL,
7951                                         RTE_ETH_FILTER_ADD,
7952                                         &tunnel_filter_conf);
7953         else
7954                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7955                                         RTE_ETH_FILTER_TUNNEL,
7956                                         RTE_ETH_FILTER_DELETE,
7957                                         &tunnel_filter_conf);
7958         if (ret < 0)
7959                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7960                                 strerror(-ret));
7961
7962 }
7963 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7964         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7965         cmd, "tunnel_filter");
7966 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7967         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7968         what, "add#rm");
7969 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7970         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7971         port_id, UINT16);
7972 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7973         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7974         outer_mac);
7975 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7976         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7977         inner_mac);
7978 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7979         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7980         inner_vlan, UINT16);
7981 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7982         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7983         ip_value);
7984 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7985         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7986         tunnel_type, "vxlan#nvgre#ipingre");
7987
7988 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7989         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7990         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7991                 "imac#omac-imac-tenid");
7992 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7993         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7994         tenant_id, UINT32);
7995 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7996         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7997         queue_num, UINT16);
7998
7999 cmdline_parse_inst_t cmd_tunnel_filter = {
8000         .f = cmd_tunnel_filter_parsed,
8001         .data = (void *)0,
8002         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8003                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8004                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8005                 "<queue_id>: Add/Rm tunnel filter of a port",
8006         .tokens = {
8007                 (void *)&cmd_tunnel_filter_cmd,
8008                 (void *)&cmd_tunnel_filter_what,
8009                 (void *)&cmd_tunnel_filter_port_id,
8010                 (void *)&cmd_tunnel_filter_outer_mac,
8011                 (void *)&cmd_tunnel_filter_inner_mac,
8012                 (void *)&cmd_tunnel_filter_ip_value,
8013                 (void *)&cmd_tunnel_filter_innner_vlan,
8014                 (void *)&cmd_tunnel_filter_tunnel_type,
8015                 (void *)&cmd_tunnel_filter_filter_type,
8016                 (void *)&cmd_tunnel_filter_tenant_id,
8017                 (void *)&cmd_tunnel_filter_queue_num,
8018                 NULL,
8019         },
8020 };
8021
8022 /* *** CONFIGURE TUNNEL UDP PORT *** */
8023 struct cmd_tunnel_udp_config {
8024         cmdline_fixed_string_t cmd;
8025         cmdline_fixed_string_t what;
8026         uint16_t udp_port;
8027         portid_t port_id;
8028 };
8029
8030 static void
8031 cmd_tunnel_udp_config_parsed(void *parsed_result,
8032                           __attribute__((unused)) struct cmdline *cl,
8033                           __attribute__((unused)) void *data)
8034 {
8035         struct cmd_tunnel_udp_config *res = parsed_result;
8036         struct rte_eth_udp_tunnel tunnel_udp;
8037         int ret;
8038
8039         tunnel_udp.udp_port = res->udp_port;
8040
8041         if (!strcmp(res->cmd, "rx_vxlan_port"))
8042                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8043
8044         if (!strcmp(res->what, "add"))
8045                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8046                                                       &tunnel_udp);
8047         else
8048                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8049                                                          &tunnel_udp);
8050
8051         if (ret < 0)
8052                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8053 }
8054
8055 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8056         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8057                                 cmd, "rx_vxlan_port");
8058 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8059         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8060                                 what, "add#rm");
8061 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8062         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8063                                 udp_port, UINT16);
8064 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8065         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8066                                 port_id, UINT16);
8067
8068 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8069         .f = cmd_tunnel_udp_config_parsed,
8070         .data = (void *)0,
8071         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8072                 "Add/Remove a tunneling UDP port filter",
8073         .tokens = {
8074                 (void *)&cmd_tunnel_udp_config_cmd,
8075                 (void *)&cmd_tunnel_udp_config_what,
8076                 (void *)&cmd_tunnel_udp_config_udp_port,
8077                 (void *)&cmd_tunnel_udp_config_port_id,
8078                 NULL,
8079         },
8080 };
8081
8082 /* *** GLOBAL CONFIG *** */
8083 struct cmd_global_config_result {
8084         cmdline_fixed_string_t cmd;
8085         portid_t port_id;
8086         cmdline_fixed_string_t cfg_type;
8087         uint8_t len;
8088 };
8089
8090 static void
8091 cmd_global_config_parsed(void *parsed_result,
8092                          __attribute__((unused)) struct cmdline *cl,
8093                          __attribute__((unused)) void *data)
8094 {
8095         struct cmd_global_config_result *res = parsed_result;
8096         struct rte_eth_global_cfg conf;
8097         int ret;
8098
8099         memset(&conf, 0, sizeof(conf));
8100         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8101         conf.cfg.gre_key_len = res->len;
8102         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8103                                       RTE_ETH_FILTER_SET, &conf);
8104         if (ret != 0)
8105                 printf("Global config error\n");
8106 }
8107
8108 cmdline_parse_token_string_t cmd_global_config_cmd =
8109         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8110                 "global_config");
8111 cmdline_parse_token_num_t cmd_global_config_port_id =
8112         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8113                                UINT16);
8114 cmdline_parse_token_string_t cmd_global_config_type =
8115         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8116                 cfg_type, "gre-key-len");
8117 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8118         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8119                 len, UINT8);
8120
8121 cmdline_parse_inst_t cmd_global_config = {
8122         .f = cmd_global_config_parsed,
8123         .data = (void *)NULL,
8124         .help_str = "global_config <port_id> gre-key-len <key_len>",
8125         .tokens = {
8126                 (void *)&cmd_global_config_cmd,
8127                 (void *)&cmd_global_config_port_id,
8128                 (void *)&cmd_global_config_type,
8129                 (void *)&cmd_global_config_gre_key_len,
8130                 NULL,
8131         },
8132 };
8133
8134 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8135 struct cmd_set_mirror_mask_result {
8136         cmdline_fixed_string_t set;
8137         cmdline_fixed_string_t port;
8138         portid_t port_id;
8139         cmdline_fixed_string_t mirror;
8140         uint8_t rule_id;
8141         cmdline_fixed_string_t what;
8142         cmdline_fixed_string_t value;
8143         cmdline_fixed_string_t dstpool;
8144         uint8_t dstpool_id;
8145         cmdline_fixed_string_t on;
8146 };
8147
8148 cmdline_parse_token_string_t cmd_mirror_mask_set =
8149         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8150                                 set, "set");
8151 cmdline_parse_token_string_t cmd_mirror_mask_port =
8152         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8153                                 port, "port");
8154 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8155         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8156                                 port_id, UINT16);
8157 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8158         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8159                                 mirror, "mirror-rule");
8160 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8161         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8162                                 rule_id, UINT8);
8163 cmdline_parse_token_string_t cmd_mirror_mask_what =
8164         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8165                                 what, "pool-mirror-up#pool-mirror-down"
8166                                       "#vlan-mirror");
8167 cmdline_parse_token_string_t cmd_mirror_mask_value =
8168         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8169                                 value, NULL);
8170 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8171         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8172                                 dstpool, "dst-pool");
8173 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8174         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8175                                 dstpool_id, UINT8);
8176 cmdline_parse_token_string_t cmd_mirror_mask_on =
8177         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8178                                 on, "on#off");
8179
8180 static void
8181 cmd_set_mirror_mask_parsed(void *parsed_result,
8182                        __attribute__((unused)) struct cmdline *cl,
8183                        __attribute__((unused)) void *data)
8184 {
8185         int ret,nb_item,i;
8186         struct cmd_set_mirror_mask_result *res = parsed_result;
8187         struct rte_eth_mirror_conf mr_conf;
8188
8189         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8190
8191         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8192
8193         mr_conf.dst_pool = res->dstpool_id;
8194
8195         if (!strcmp(res->what, "pool-mirror-up")) {
8196                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8197                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8198         } else if (!strcmp(res->what, "pool-mirror-down")) {
8199                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8200                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8201         } else if (!strcmp(res->what, "vlan-mirror")) {
8202                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8203                 nb_item = parse_item_list(res->value, "vlan",
8204                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8205                 if (nb_item <= 0)
8206                         return;
8207
8208                 for (i = 0; i < nb_item; i++) {
8209                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8210                                 printf("Invalid vlan_id: must be < 4096\n");
8211                                 return;
8212                         }
8213
8214                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8215                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8216                 }
8217         }
8218
8219         if (!strcmp(res->on, "on"))
8220                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8221                                                 res->rule_id, 1);
8222         else
8223                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8224                                                 res->rule_id, 0);
8225         if (ret < 0)
8226                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8227 }
8228
8229 cmdline_parse_inst_t cmd_set_mirror_mask = {
8230                 .f = cmd_set_mirror_mask_parsed,
8231                 .data = NULL,
8232                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8233                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8234                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8235                 .tokens = {
8236                         (void *)&cmd_mirror_mask_set,
8237                         (void *)&cmd_mirror_mask_port,
8238                         (void *)&cmd_mirror_mask_portid,
8239                         (void *)&cmd_mirror_mask_mirror,
8240                         (void *)&cmd_mirror_mask_ruleid,
8241                         (void *)&cmd_mirror_mask_what,
8242                         (void *)&cmd_mirror_mask_value,
8243                         (void *)&cmd_mirror_mask_dstpool,
8244                         (void *)&cmd_mirror_mask_poolid,
8245                         (void *)&cmd_mirror_mask_on,
8246                         NULL,
8247                 },
8248 };
8249
8250 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8251 struct cmd_set_mirror_link_result {
8252         cmdline_fixed_string_t set;
8253         cmdline_fixed_string_t port;
8254         portid_t port_id;
8255         cmdline_fixed_string_t mirror;
8256         uint8_t rule_id;
8257         cmdline_fixed_string_t what;
8258         cmdline_fixed_string_t dstpool;
8259         uint8_t dstpool_id;
8260         cmdline_fixed_string_t on;
8261 };
8262
8263 cmdline_parse_token_string_t cmd_mirror_link_set =
8264         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8265                                  set, "set");
8266 cmdline_parse_token_string_t cmd_mirror_link_port =
8267         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8268                                 port, "port");
8269 cmdline_parse_token_num_t cmd_mirror_link_portid =
8270         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8271                                 port_id, UINT16);
8272 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8273         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8274                                 mirror, "mirror-rule");
8275 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8276         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8277                             rule_id, UINT8);
8278 cmdline_parse_token_string_t cmd_mirror_link_what =
8279         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8280                                 what, "uplink-mirror#downlink-mirror");
8281 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8282         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8283                                 dstpool, "dst-pool");
8284 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8285         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8286                                 dstpool_id, UINT8);
8287 cmdline_parse_token_string_t cmd_mirror_link_on =
8288         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8289                                 on, "on#off");
8290
8291 static void
8292 cmd_set_mirror_link_parsed(void *parsed_result,
8293                        __attribute__((unused)) struct cmdline *cl,
8294                        __attribute__((unused)) void *data)
8295 {
8296         int ret;
8297         struct cmd_set_mirror_link_result *res = parsed_result;
8298         struct rte_eth_mirror_conf mr_conf;
8299
8300         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8301         if (!strcmp(res->what, "uplink-mirror"))
8302                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8303         else
8304                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8305
8306         mr_conf.dst_pool = res->dstpool_id;
8307
8308         if (!strcmp(res->on, "on"))
8309                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8310                                                 res->rule_id, 1);
8311         else
8312                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8313                                                 res->rule_id, 0);
8314
8315         /* check the return value and print it if is < 0 */
8316         if (ret < 0)
8317                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8318
8319 }
8320
8321 cmdline_parse_inst_t cmd_set_mirror_link = {
8322                 .f = cmd_set_mirror_link_parsed,
8323                 .data = NULL,
8324                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8325                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8326                 .tokens = {
8327                         (void *)&cmd_mirror_link_set,
8328                         (void *)&cmd_mirror_link_port,
8329                         (void *)&cmd_mirror_link_portid,
8330                         (void *)&cmd_mirror_link_mirror,
8331                         (void *)&cmd_mirror_link_ruleid,
8332                         (void *)&cmd_mirror_link_what,
8333                         (void *)&cmd_mirror_link_dstpool,
8334                         (void *)&cmd_mirror_link_poolid,
8335                         (void *)&cmd_mirror_link_on,
8336                         NULL,
8337                 },
8338 };
8339
8340 /* *** RESET VM MIRROR RULE *** */
8341 struct cmd_rm_mirror_rule_result {
8342         cmdline_fixed_string_t reset;
8343         cmdline_fixed_string_t port;
8344         portid_t port_id;
8345         cmdline_fixed_string_t mirror;
8346         uint8_t rule_id;
8347 };
8348
8349 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8350         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8351                                  reset, "reset");
8352 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8353         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8354                                 port, "port");
8355 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8356         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8357                                 port_id, UINT16);
8358 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8359         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8360                                 mirror, "mirror-rule");
8361 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8362         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8363                                 rule_id, UINT8);
8364
8365 static void
8366 cmd_reset_mirror_rule_parsed(void *parsed_result,
8367                        __attribute__((unused)) struct cmdline *cl,
8368                        __attribute__((unused)) void *data)
8369 {
8370         int ret;
8371         struct cmd_set_mirror_link_result *res = parsed_result;
8372         /* check rule_id */
8373         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8374         if(ret < 0)
8375                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8376 }
8377
8378 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8379                 .f = cmd_reset_mirror_rule_parsed,
8380                 .data = NULL,
8381                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8382                 .tokens = {
8383                         (void *)&cmd_rm_mirror_rule_reset,
8384                         (void *)&cmd_rm_mirror_rule_port,
8385                         (void *)&cmd_rm_mirror_rule_portid,
8386                         (void *)&cmd_rm_mirror_rule_mirror,
8387                         (void *)&cmd_rm_mirror_rule_ruleid,
8388                         NULL,
8389                 },
8390 };
8391
8392 /* ******************************************************************************** */
8393
8394 struct cmd_dump_result {
8395         cmdline_fixed_string_t dump;
8396 };
8397
8398 static void
8399 dump_struct_sizes(void)
8400 {
8401 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8402         DUMP_SIZE(struct rte_mbuf);
8403         DUMP_SIZE(struct rte_mempool);
8404         DUMP_SIZE(struct rte_ring);
8405 #undef DUMP_SIZE
8406 }
8407
8408 static void cmd_dump_parsed(void *parsed_result,
8409                             __attribute__((unused)) struct cmdline *cl,
8410                             __attribute__((unused)) void *data)
8411 {
8412         struct cmd_dump_result *res = parsed_result;
8413
8414         if (!strcmp(res->dump, "dump_physmem"))
8415                 rte_dump_physmem_layout(stdout);
8416         else if (!strcmp(res->dump, "dump_memzone"))
8417                 rte_memzone_dump(stdout);
8418         else if (!strcmp(res->dump, "dump_struct_sizes"))
8419                 dump_struct_sizes();
8420         else if (!strcmp(res->dump, "dump_ring"))
8421                 rte_ring_list_dump(stdout);
8422         else if (!strcmp(res->dump, "dump_mempool"))
8423                 rte_mempool_list_dump(stdout);
8424         else if (!strcmp(res->dump, "dump_devargs"))
8425                 rte_eal_devargs_dump(stdout);
8426         else if (!strcmp(res->dump, "dump_log_types"))
8427                 rte_log_dump(stdout);
8428 }
8429
8430 cmdline_parse_token_string_t cmd_dump_dump =
8431         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8432                 "dump_physmem#"
8433                 "dump_memzone#"
8434                 "dump_struct_sizes#"
8435                 "dump_ring#"
8436                 "dump_mempool#"
8437                 "dump_devargs#"
8438                 "dump_log_types");
8439
8440 cmdline_parse_inst_t cmd_dump = {
8441         .f = cmd_dump_parsed,  /* function to call */
8442         .data = NULL,      /* 2nd arg of func */
8443         .help_str = "Dump status",
8444         .tokens = {        /* token list, NULL terminated */
8445                 (void *)&cmd_dump_dump,
8446                 NULL,
8447         },
8448 };
8449
8450 /* ******************************************************************************** */
8451
8452 struct cmd_dump_one_result {
8453         cmdline_fixed_string_t dump;
8454         cmdline_fixed_string_t name;
8455 };
8456
8457 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8458                                 __attribute__((unused)) void *data)
8459 {
8460         struct cmd_dump_one_result *res = parsed_result;
8461
8462         if (!strcmp(res->dump, "dump_ring")) {
8463                 struct rte_ring *r;
8464                 r = rte_ring_lookup(res->name);
8465                 if (r == NULL) {
8466                         cmdline_printf(cl, "Cannot find ring\n");
8467                         return;
8468                 }
8469                 rte_ring_dump(stdout, r);
8470         } else if (!strcmp(res->dump, "dump_mempool")) {
8471                 struct rte_mempool *mp;
8472                 mp = rte_mempool_lookup(res->name);
8473                 if (mp == NULL) {
8474                         cmdline_printf(cl, "Cannot find mempool\n");
8475                         return;
8476                 }
8477                 rte_mempool_dump(stdout, mp);
8478         }
8479 }
8480
8481 cmdline_parse_token_string_t cmd_dump_one_dump =
8482         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8483                                  "dump_ring#dump_mempool");
8484
8485 cmdline_parse_token_string_t cmd_dump_one_name =
8486         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8487
8488 cmdline_parse_inst_t cmd_dump_one = {
8489         .f = cmd_dump_one_parsed,  /* function to call */
8490         .data = NULL,      /* 2nd arg of func */
8491         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8492         .tokens = {        /* token list, NULL terminated */
8493                 (void *)&cmd_dump_one_dump,
8494                 (void *)&cmd_dump_one_name,
8495                 NULL,
8496         },
8497 };
8498
8499 /* *** Add/Del syn filter *** */
8500 struct cmd_syn_filter_result {
8501         cmdline_fixed_string_t filter;
8502         portid_t port_id;
8503         cmdline_fixed_string_t ops;
8504         cmdline_fixed_string_t priority;
8505         cmdline_fixed_string_t high;
8506         cmdline_fixed_string_t queue;
8507         uint16_t queue_id;
8508 };
8509
8510 static void
8511 cmd_syn_filter_parsed(void *parsed_result,
8512                         __attribute__((unused)) struct cmdline *cl,
8513                         __attribute__((unused)) void *data)
8514 {
8515         struct cmd_syn_filter_result *res = parsed_result;
8516         struct rte_eth_syn_filter syn_filter;
8517         int ret = 0;
8518
8519         ret = rte_eth_dev_filter_supported(res->port_id,
8520                                         RTE_ETH_FILTER_SYN);
8521         if (ret < 0) {
8522                 printf("syn filter is not supported on port %u.\n",
8523                                 res->port_id);
8524                 return;
8525         }
8526
8527         memset(&syn_filter, 0, sizeof(syn_filter));
8528
8529         if (!strcmp(res->ops, "add")) {
8530                 if (!strcmp(res->high, "high"))
8531                         syn_filter.hig_pri = 1;
8532                 else
8533                         syn_filter.hig_pri = 0;
8534
8535                 syn_filter.queue = res->queue_id;
8536                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8537                                                 RTE_ETH_FILTER_SYN,
8538                                                 RTE_ETH_FILTER_ADD,
8539                                                 &syn_filter);
8540         } else
8541                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8542                                                 RTE_ETH_FILTER_SYN,
8543                                                 RTE_ETH_FILTER_DELETE,
8544                                                 &syn_filter);
8545
8546         if (ret < 0)
8547                 printf("syn filter programming error: (%s)\n",
8548                                 strerror(-ret));
8549 }
8550
8551 cmdline_parse_token_string_t cmd_syn_filter_filter =
8552         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8553         filter, "syn_filter");
8554 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8555         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8556         port_id, UINT16);
8557 cmdline_parse_token_string_t cmd_syn_filter_ops =
8558         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8559         ops, "add#del");
8560 cmdline_parse_token_string_t cmd_syn_filter_priority =
8561         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8562                                 priority, "priority");
8563 cmdline_parse_token_string_t cmd_syn_filter_high =
8564         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8565                                 high, "high#low");
8566 cmdline_parse_token_string_t cmd_syn_filter_queue =
8567         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8568                                 queue, "queue");
8569 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8570         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8571                                 queue_id, UINT16);
8572
8573 cmdline_parse_inst_t cmd_syn_filter = {
8574         .f = cmd_syn_filter_parsed,
8575         .data = NULL,
8576         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8577                 "<queue_id>: Add/Delete syn filter",
8578         .tokens = {
8579                 (void *)&cmd_syn_filter_filter,
8580                 (void *)&cmd_syn_filter_port_id,
8581                 (void *)&cmd_syn_filter_ops,
8582                 (void *)&cmd_syn_filter_priority,
8583                 (void *)&cmd_syn_filter_high,
8584                 (void *)&cmd_syn_filter_queue,
8585                 (void *)&cmd_syn_filter_queue_id,
8586                 NULL,
8587         },
8588 };
8589
8590 /* *** queue region set *** */
8591 struct cmd_queue_region_result {
8592         cmdline_fixed_string_t set;
8593         cmdline_fixed_string_t port;
8594         portid_t port_id;
8595         cmdline_fixed_string_t cmd;
8596         cmdline_fixed_string_t region;
8597         uint8_t  region_id;
8598         cmdline_fixed_string_t queue_start_index;
8599         uint8_t  queue_id;
8600         cmdline_fixed_string_t queue_num;
8601         uint8_t  queue_num_value;
8602 };
8603
8604 static void
8605 cmd_queue_region_parsed(void *parsed_result,
8606                         __attribute__((unused)) struct cmdline *cl,
8607                         __attribute__((unused)) void *data)
8608 {
8609         struct cmd_queue_region_result *res = parsed_result;
8610         int ret = -ENOTSUP;
8611 #ifdef RTE_LIBRTE_I40E_PMD
8612         struct rte_pmd_i40e_queue_region_conf region_conf;
8613         enum rte_pmd_i40e_queue_region_op op_type;
8614 #endif
8615
8616         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8617                 return;
8618
8619 #ifdef RTE_LIBRTE_I40E_PMD
8620         memset(&region_conf, 0, sizeof(region_conf));
8621         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8622         region_conf.region_id = res->region_id;
8623         region_conf.queue_num = res->queue_num_value;
8624         region_conf.queue_start_index = res->queue_id;
8625
8626         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8627                                 op_type, &region_conf);
8628 #endif
8629
8630         switch (ret) {
8631         case 0:
8632                 break;
8633         case -ENOTSUP:
8634                 printf("function not implemented or supported\n");
8635                 break;
8636         default:
8637                 printf("queue region config error: (%s)\n", strerror(-ret));
8638         }
8639 }
8640
8641 cmdline_parse_token_string_t cmd_queue_region_set =
8642 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8643                 set, "set");
8644 cmdline_parse_token_string_t cmd_queue_region_port =
8645         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8646 cmdline_parse_token_num_t cmd_queue_region_port_id =
8647         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8648                                 port_id, UINT16);
8649 cmdline_parse_token_string_t cmd_queue_region_cmd =
8650         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8651                                  cmd, "queue-region");
8652 cmdline_parse_token_string_t cmd_queue_region_id =
8653         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8654                                 region, "region_id");
8655 cmdline_parse_token_num_t cmd_queue_region_index =
8656         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8657                                 region_id, UINT8);
8658 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8659         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8660                                 queue_start_index, "queue_start_index");
8661 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8662         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8663                                 queue_id, UINT8);
8664 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8665         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8666                                 queue_num, "queue_num");
8667 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8668         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8669                                 queue_num_value, UINT8);
8670
8671 cmdline_parse_inst_t cmd_queue_region = {
8672         .f = cmd_queue_region_parsed,
8673         .data = NULL,
8674         .help_str = "set port <port_id> queue-region region_id <value> "
8675                 "queue_start_index <value> queue_num <value>: Set a queue region",
8676         .tokens = {
8677                 (void *)&cmd_queue_region_set,
8678                 (void *)&cmd_queue_region_port,
8679                 (void *)&cmd_queue_region_port_id,
8680                 (void *)&cmd_queue_region_cmd,
8681                 (void *)&cmd_queue_region_id,
8682                 (void *)&cmd_queue_region_index,
8683                 (void *)&cmd_queue_region_queue_start_index,
8684                 (void *)&cmd_queue_region_queue_id,
8685                 (void *)&cmd_queue_region_queue_num,
8686                 (void *)&cmd_queue_region_queue_num_value,
8687                 NULL,
8688         },
8689 };
8690
8691 /* *** queue region and flowtype set *** */
8692 struct cmd_region_flowtype_result {
8693         cmdline_fixed_string_t set;
8694         cmdline_fixed_string_t port;
8695         portid_t port_id;
8696         cmdline_fixed_string_t cmd;
8697         cmdline_fixed_string_t region;
8698         uint8_t  region_id;
8699         cmdline_fixed_string_t flowtype;
8700         uint8_t  flowtype_id;
8701 };
8702
8703 static void
8704 cmd_region_flowtype_parsed(void *parsed_result,
8705                         __attribute__((unused)) struct cmdline *cl,
8706                         __attribute__((unused)) void *data)
8707 {
8708         struct cmd_region_flowtype_result *res = parsed_result;
8709         int ret = -ENOTSUP;
8710 #ifdef RTE_LIBRTE_I40E_PMD
8711         struct rte_pmd_i40e_queue_region_conf region_conf;
8712         enum rte_pmd_i40e_queue_region_op op_type;
8713 #endif
8714
8715         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8716                 return;
8717
8718 #ifdef RTE_LIBRTE_I40E_PMD
8719         memset(&region_conf, 0, sizeof(region_conf));
8720
8721         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8722         region_conf.region_id = res->region_id;
8723         region_conf.hw_flowtype = res->flowtype_id;
8724
8725         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8726                         op_type, &region_conf);
8727 #endif
8728
8729         switch (ret) {
8730         case 0:
8731                 break;
8732         case -ENOTSUP:
8733                 printf("function not implemented or supported\n");
8734                 break;
8735         default:
8736                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8737         }
8738 }
8739
8740 cmdline_parse_token_string_t cmd_region_flowtype_set =
8741 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8742                                 set, "set");
8743 cmdline_parse_token_string_t cmd_region_flowtype_port =
8744         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8745                                 port, "port");
8746 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8747         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8748                                 port_id, UINT16);
8749 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8750         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8751                                 cmd, "queue-region");
8752 cmdline_parse_token_string_t cmd_region_flowtype_index =
8753         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8754                                 region, "region_id");
8755 cmdline_parse_token_num_t cmd_region_flowtype_id =
8756         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8757                                 region_id, UINT8);
8758 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8759         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8760                                 flowtype, "flowtype");
8761 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8762         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8763                                 flowtype_id, UINT8);
8764 cmdline_parse_inst_t cmd_region_flowtype = {
8765         .f = cmd_region_flowtype_parsed,
8766         .data = NULL,
8767         .help_str = "set port <port_id> queue-region region_id <value> "
8768                 "flowtype <value>: Set a flowtype region index",
8769         .tokens = {
8770                 (void *)&cmd_region_flowtype_set,
8771                 (void *)&cmd_region_flowtype_port,
8772                 (void *)&cmd_region_flowtype_port_index,
8773                 (void *)&cmd_region_flowtype_cmd,
8774                 (void *)&cmd_region_flowtype_index,
8775                 (void *)&cmd_region_flowtype_id,
8776                 (void *)&cmd_region_flowtype_flow_index,
8777                 (void *)&cmd_region_flowtype_flow_id,
8778                 NULL,
8779         },
8780 };
8781
8782 /* *** User Priority (UP) to queue region (region_id) set *** */
8783 struct cmd_user_priority_region_result {
8784         cmdline_fixed_string_t set;
8785         cmdline_fixed_string_t port;
8786         portid_t port_id;
8787         cmdline_fixed_string_t cmd;
8788         cmdline_fixed_string_t user_priority;
8789         uint8_t  user_priority_id;
8790         cmdline_fixed_string_t region;
8791         uint8_t  region_id;
8792 };
8793
8794 static void
8795 cmd_user_priority_region_parsed(void *parsed_result,
8796                         __attribute__((unused)) struct cmdline *cl,
8797                         __attribute__((unused)) void *data)
8798 {
8799         struct cmd_user_priority_region_result *res = parsed_result;
8800         int ret = -ENOTSUP;
8801 #ifdef RTE_LIBRTE_I40E_PMD
8802         struct rte_pmd_i40e_queue_region_conf region_conf;
8803         enum rte_pmd_i40e_queue_region_op op_type;
8804 #endif
8805
8806         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8807                 return;
8808
8809 #ifdef RTE_LIBRTE_I40E_PMD
8810         memset(&region_conf, 0, sizeof(region_conf));
8811         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8812         region_conf.user_priority = res->user_priority_id;
8813         region_conf.region_id = res->region_id;
8814
8815         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8816                                 op_type, &region_conf);
8817 #endif
8818
8819         switch (ret) {
8820         case 0:
8821                 break;
8822         case -ENOTSUP:
8823                 printf("function not implemented or supported\n");
8824                 break;
8825         default:
8826                 printf("user_priority region config error: (%s)\n",
8827                                 strerror(-ret));
8828         }
8829 }
8830
8831 cmdline_parse_token_string_t cmd_user_priority_region_set =
8832         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8833                                 set, "set");
8834 cmdline_parse_token_string_t cmd_user_priority_region_port =
8835         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8836                                 port, "port");
8837 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8838         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8839                                 port_id, UINT16);
8840 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8841         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8842                                 cmd, "queue-region");
8843 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8844         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8845                                 user_priority, "UP");
8846 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8847         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8848                                 user_priority_id, UINT8);
8849 cmdline_parse_token_string_t cmd_user_priority_region_region =
8850         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8851                                 region, "region_id");
8852 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8853         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8854                                 region_id, UINT8);
8855
8856 cmdline_parse_inst_t cmd_user_priority_region = {
8857         .f = cmd_user_priority_region_parsed,
8858         .data = NULL,
8859         .help_str = "set port <port_id> queue-region UP <value> "
8860                 "region_id <value>: Set the mapping of User Priority (UP) "
8861                 "to queue region (region_id) ",
8862         .tokens = {
8863                 (void *)&cmd_user_priority_region_set,
8864                 (void *)&cmd_user_priority_region_port,
8865                 (void *)&cmd_user_priority_region_port_index,
8866                 (void *)&cmd_user_priority_region_cmd,
8867                 (void *)&cmd_user_priority_region_UP,
8868                 (void *)&cmd_user_priority_region_UP_id,
8869                 (void *)&cmd_user_priority_region_region,
8870                 (void *)&cmd_user_priority_region_region_id,
8871                 NULL,
8872         },
8873 };
8874
8875 /* *** flush all queue region related configuration *** */
8876 struct cmd_flush_queue_region_result {
8877         cmdline_fixed_string_t set;
8878         cmdline_fixed_string_t port;
8879         portid_t port_id;
8880         cmdline_fixed_string_t cmd;
8881         cmdline_fixed_string_t flush;
8882         cmdline_fixed_string_t what;
8883 };
8884
8885 static void
8886 cmd_flush_queue_region_parsed(void *parsed_result,
8887                         __attribute__((unused)) struct cmdline *cl,
8888                         __attribute__((unused)) void *data)
8889 {
8890         struct cmd_flush_queue_region_result *res = parsed_result;
8891         int ret = -ENOTSUP;
8892 #ifdef RTE_LIBRTE_I40E_PMD
8893         struct rte_pmd_i40e_queue_region_conf region_conf;
8894         enum rte_pmd_i40e_queue_region_op op_type;
8895 #endif
8896
8897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8898                 return;
8899
8900 #ifdef RTE_LIBRTE_I40E_PMD
8901         memset(&region_conf, 0, sizeof(region_conf));
8902
8903         if (strcmp(res->what, "on") == 0)
8904                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8905         else
8906                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8907
8908         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8909                                 op_type, &region_conf);
8910 #endif
8911
8912         switch (ret) {
8913         case 0:
8914                 break;
8915         case -ENOTSUP:
8916                 printf("function not implemented or supported\n");
8917                 break;
8918         default:
8919                 printf("queue region config flush error: (%s)\n",
8920                                 strerror(-ret));
8921         }
8922 }
8923
8924 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8925         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8926                                 set, "set");
8927 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8928         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8929                                 port, "port");
8930 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8931         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8932                                 port_id, UINT16);
8933 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8934         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8935                                 cmd, "queue-region");
8936 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8937         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8938                                 flush, "flush");
8939 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8940         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8941                                 what, "on#off");
8942
8943 cmdline_parse_inst_t cmd_flush_queue_region = {
8944         .f = cmd_flush_queue_region_parsed,
8945         .data = NULL,
8946         .help_str = "set port <port_id> queue-region flush on|off"
8947                 ": flush all queue region related configuration",
8948         .tokens = {
8949                 (void *)&cmd_flush_queue_region_set,
8950                 (void *)&cmd_flush_queue_region_port,
8951                 (void *)&cmd_flush_queue_region_port_index,
8952                 (void *)&cmd_flush_queue_region_cmd,
8953                 (void *)&cmd_flush_queue_region_flush,
8954                 (void *)&cmd_flush_queue_region_what,
8955                 NULL,
8956         },
8957 };
8958
8959 /* *** get all queue region related configuration info *** */
8960 struct cmd_show_queue_region_info {
8961         cmdline_fixed_string_t show;
8962         cmdline_fixed_string_t port;
8963         portid_t port_id;
8964         cmdline_fixed_string_t cmd;
8965 };
8966
8967 static void
8968 cmd_show_queue_region_info_parsed(void *parsed_result,
8969                         __attribute__((unused)) struct cmdline *cl,
8970                         __attribute__((unused)) void *data)
8971 {
8972         struct cmd_show_queue_region_info *res = parsed_result;
8973         int ret = -ENOTSUP;
8974 #ifdef RTE_LIBRTE_I40E_PMD
8975         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
8976         enum rte_pmd_i40e_queue_region_op op_type;
8977 #endif
8978
8979         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8980                 return;
8981
8982 #ifdef RTE_LIBRTE_I40E_PMD
8983         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
8984
8985         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
8986
8987         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8988                                         op_type, &rte_pmd_regions);
8989
8990         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
8991 #endif
8992
8993         switch (ret) {
8994         case 0:
8995                 break;
8996         case -ENOTSUP:
8997                 printf("function not implemented or supported\n");
8998                 break;
8999         default:
9000                 printf("queue region config info show error: (%s)\n",
9001                                 strerror(-ret));
9002         }
9003 }
9004
9005 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9006 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9007                                 show, "show");
9008 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9009         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9010                                 port, "port");
9011 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9012         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9013                                 port_id, UINT16);
9014 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9015         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9016                                 cmd, "queue-region");
9017
9018 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9019         .f = cmd_show_queue_region_info_parsed,
9020         .data = NULL,
9021         .help_str = "show port <port_id> queue-region"
9022                 ": show all queue region related configuration info",
9023         .tokens = {
9024                 (void *)&cmd_show_queue_region_info_get,
9025                 (void *)&cmd_show_queue_region_info_port,
9026                 (void *)&cmd_show_queue_region_info_port_index,
9027                 (void *)&cmd_show_queue_region_info_cmd,
9028                 NULL,
9029         },
9030 };
9031
9032 /* *** ADD/REMOVE A 2tuple FILTER *** */
9033 struct cmd_2tuple_filter_result {
9034         cmdline_fixed_string_t filter;
9035         portid_t port_id;
9036         cmdline_fixed_string_t ops;
9037         cmdline_fixed_string_t dst_port;
9038         uint16_t dst_port_value;
9039         cmdline_fixed_string_t protocol;
9040         uint8_t protocol_value;
9041         cmdline_fixed_string_t mask;
9042         uint8_t  mask_value;
9043         cmdline_fixed_string_t tcp_flags;
9044         uint8_t tcp_flags_value;
9045         cmdline_fixed_string_t priority;
9046         uint8_t  priority_value;
9047         cmdline_fixed_string_t queue;
9048         uint16_t  queue_id;
9049 };
9050
9051 static void
9052 cmd_2tuple_filter_parsed(void *parsed_result,
9053                         __attribute__((unused)) struct cmdline *cl,
9054                         __attribute__((unused)) void *data)
9055 {
9056         struct rte_eth_ntuple_filter filter;
9057         struct cmd_2tuple_filter_result *res = parsed_result;
9058         int ret = 0;
9059
9060         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9061         if (ret < 0) {
9062                 printf("ntuple filter is not supported on port %u.\n",
9063                         res->port_id);
9064                 return;
9065         }
9066
9067         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9068
9069         filter.flags = RTE_2TUPLE_FLAGS;
9070         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9071         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9072         filter.proto = res->protocol_value;
9073         filter.priority = res->priority_value;
9074         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9075                 printf("nonzero tcp_flags is only meaningful"
9076                         " when protocol is TCP.\n");
9077                 return;
9078         }
9079         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9080                 printf("invalid TCP flags.\n");
9081                 return;
9082         }
9083
9084         if (res->tcp_flags_value != 0) {
9085                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9086                 filter.tcp_flags = res->tcp_flags_value;
9087         }
9088
9089         /* need convert to big endian. */
9090         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9091         filter.queue = res->queue_id;
9092
9093         if (!strcmp(res->ops, "add"))
9094                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9095                                 RTE_ETH_FILTER_NTUPLE,
9096                                 RTE_ETH_FILTER_ADD,
9097                                 &filter);
9098         else
9099                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9100                                 RTE_ETH_FILTER_NTUPLE,
9101                                 RTE_ETH_FILTER_DELETE,
9102                                 &filter);
9103         if (ret < 0)
9104                 printf("2tuple filter programming error: (%s)\n",
9105                         strerror(-ret));
9106
9107 }
9108
9109 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9110         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9111                                  filter, "2tuple_filter");
9112 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9113         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9114                                 port_id, UINT16);
9115 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9116         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9117                                  ops, "add#del");
9118 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9119         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9120                                 dst_port, "dst_port");
9121 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9122         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9123                                 dst_port_value, UINT16);
9124 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9125         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9126                                 protocol, "protocol");
9127 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9128         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9129                                 protocol_value, UINT8);
9130 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9131         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9132                                 mask, "mask");
9133 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9134         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9135                                 mask_value, INT8);
9136 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9137         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9138                                 tcp_flags, "tcp_flags");
9139 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9140         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9141                                 tcp_flags_value, UINT8);
9142 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9143         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9144                                 priority, "priority");
9145 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9146         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9147                                 priority_value, UINT8);
9148 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9149         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9150                                 queue, "queue");
9151 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9152         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9153                                 queue_id, UINT16);
9154
9155 cmdline_parse_inst_t cmd_2tuple_filter = {
9156         .f = cmd_2tuple_filter_parsed,
9157         .data = NULL,
9158         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9159                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9160                 "<queue_id>: Add a 2tuple filter",
9161         .tokens = {
9162                 (void *)&cmd_2tuple_filter_filter,
9163                 (void *)&cmd_2tuple_filter_port_id,
9164                 (void *)&cmd_2tuple_filter_ops,
9165                 (void *)&cmd_2tuple_filter_dst_port,
9166                 (void *)&cmd_2tuple_filter_dst_port_value,
9167                 (void *)&cmd_2tuple_filter_protocol,
9168                 (void *)&cmd_2tuple_filter_protocol_value,
9169                 (void *)&cmd_2tuple_filter_mask,
9170                 (void *)&cmd_2tuple_filter_mask_value,
9171                 (void *)&cmd_2tuple_filter_tcp_flags,
9172                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9173                 (void *)&cmd_2tuple_filter_priority,
9174                 (void *)&cmd_2tuple_filter_priority_value,
9175                 (void *)&cmd_2tuple_filter_queue,
9176                 (void *)&cmd_2tuple_filter_queue_id,
9177                 NULL,
9178         },
9179 };
9180
9181 /* *** ADD/REMOVE A 5tuple FILTER *** */
9182 struct cmd_5tuple_filter_result {
9183         cmdline_fixed_string_t filter;
9184         portid_t port_id;
9185         cmdline_fixed_string_t ops;
9186         cmdline_fixed_string_t dst_ip;
9187         cmdline_ipaddr_t dst_ip_value;
9188         cmdline_fixed_string_t src_ip;
9189         cmdline_ipaddr_t src_ip_value;
9190         cmdline_fixed_string_t dst_port;
9191         uint16_t dst_port_value;
9192         cmdline_fixed_string_t src_port;
9193         uint16_t src_port_value;
9194         cmdline_fixed_string_t protocol;
9195         uint8_t protocol_value;
9196         cmdline_fixed_string_t mask;
9197         uint8_t  mask_value;
9198         cmdline_fixed_string_t tcp_flags;
9199         uint8_t tcp_flags_value;
9200         cmdline_fixed_string_t priority;
9201         uint8_t  priority_value;
9202         cmdline_fixed_string_t queue;
9203         uint16_t  queue_id;
9204 };
9205
9206 static void
9207 cmd_5tuple_filter_parsed(void *parsed_result,
9208                         __attribute__((unused)) struct cmdline *cl,
9209                         __attribute__((unused)) void *data)
9210 {
9211         struct rte_eth_ntuple_filter filter;
9212         struct cmd_5tuple_filter_result *res = parsed_result;
9213         int ret = 0;
9214
9215         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9216         if (ret < 0) {
9217                 printf("ntuple filter is not supported on port %u.\n",
9218                         res->port_id);
9219                 return;
9220         }
9221
9222         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9223
9224         filter.flags = RTE_5TUPLE_FLAGS;
9225         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9226         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9227         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9228         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9229         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9230         filter.proto = res->protocol_value;
9231         filter.priority = res->priority_value;
9232         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9233                 printf("nonzero tcp_flags is only meaningful"
9234                         " when protocol is TCP.\n");
9235                 return;
9236         }
9237         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9238                 printf("invalid TCP flags.\n");
9239                 return;
9240         }
9241
9242         if (res->tcp_flags_value != 0) {
9243                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9244                 filter.tcp_flags = res->tcp_flags_value;
9245         }
9246
9247         if (res->dst_ip_value.family == AF_INET)
9248                 /* no need to convert, already big endian. */
9249                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9250         else {
9251                 if (filter.dst_ip_mask == 0) {
9252                         printf("can not support ipv6 involved compare.\n");
9253                         return;
9254                 }
9255                 filter.dst_ip = 0;
9256         }
9257
9258         if (res->src_ip_value.family == AF_INET)
9259                 /* no need to convert, already big endian. */
9260                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9261         else {
9262                 if (filter.src_ip_mask == 0) {
9263                         printf("can not support ipv6 involved compare.\n");
9264                         return;
9265                 }
9266                 filter.src_ip = 0;
9267         }
9268         /* need convert to big endian. */
9269         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9270         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9271         filter.queue = res->queue_id;
9272
9273         if (!strcmp(res->ops, "add"))
9274                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9275                                 RTE_ETH_FILTER_NTUPLE,
9276                                 RTE_ETH_FILTER_ADD,
9277                                 &filter);
9278         else
9279                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9280                                 RTE_ETH_FILTER_NTUPLE,
9281                                 RTE_ETH_FILTER_DELETE,
9282                                 &filter);
9283         if (ret < 0)
9284                 printf("5tuple filter programming error: (%s)\n",
9285                         strerror(-ret));
9286 }
9287
9288 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9289         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9290                                  filter, "5tuple_filter");
9291 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9292         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9293                                 port_id, UINT16);
9294 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9295         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9296                                  ops, "add#del");
9297 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9298         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9299                                 dst_ip, "dst_ip");
9300 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9301         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9302                                 dst_ip_value);
9303 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9304         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9305                                 src_ip, "src_ip");
9306 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9307         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9308                                 src_ip_value);
9309 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9310         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9311                                 dst_port, "dst_port");
9312 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9313         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9314                                 dst_port_value, UINT16);
9315 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9316         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9317                                 src_port, "src_port");
9318 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9319         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9320                                 src_port_value, UINT16);
9321 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9322         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9323                                 protocol, "protocol");
9324 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9325         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9326                                 protocol_value, UINT8);
9327 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9328         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9329                                 mask, "mask");
9330 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9331         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9332                                 mask_value, INT8);
9333 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9334         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9335                                 tcp_flags, "tcp_flags");
9336 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9337         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9338                                 tcp_flags_value, UINT8);
9339 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9340         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9341                                 priority, "priority");
9342 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9343         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9344                                 priority_value, UINT8);
9345 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9346         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9347                                 queue, "queue");
9348 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9349         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9350                                 queue_id, UINT16);
9351
9352 cmdline_parse_inst_t cmd_5tuple_filter = {
9353         .f = cmd_5tuple_filter_parsed,
9354         .data = NULL,
9355         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9356                 "src_ip <value> dst_port <value> src_port <value> "
9357                 "protocol <value>  mask <value> tcp_flags <value> "
9358                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9359         .tokens = {
9360                 (void *)&cmd_5tuple_filter_filter,
9361                 (void *)&cmd_5tuple_filter_port_id,
9362                 (void *)&cmd_5tuple_filter_ops,
9363                 (void *)&cmd_5tuple_filter_dst_ip,
9364                 (void *)&cmd_5tuple_filter_dst_ip_value,
9365                 (void *)&cmd_5tuple_filter_src_ip,
9366                 (void *)&cmd_5tuple_filter_src_ip_value,
9367                 (void *)&cmd_5tuple_filter_dst_port,
9368                 (void *)&cmd_5tuple_filter_dst_port_value,
9369                 (void *)&cmd_5tuple_filter_src_port,
9370                 (void *)&cmd_5tuple_filter_src_port_value,
9371                 (void *)&cmd_5tuple_filter_protocol,
9372                 (void *)&cmd_5tuple_filter_protocol_value,
9373                 (void *)&cmd_5tuple_filter_mask,
9374                 (void *)&cmd_5tuple_filter_mask_value,
9375                 (void *)&cmd_5tuple_filter_tcp_flags,
9376                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9377                 (void *)&cmd_5tuple_filter_priority,
9378                 (void *)&cmd_5tuple_filter_priority_value,
9379                 (void *)&cmd_5tuple_filter_queue,
9380                 (void *)&cmd_5tuple_filter_queue_id,
9381                 NULL,
9382         },
9383 };
9384
9385 /* *** ADD/REMOVE A flex FILTER *** */
9386 struct cmd_flex_filter_result {
9387         cmdline_fixed_string_t filter;
9388         cmdline_fixed_string_t ops;
9389         portid_t port_id;
9390         cmdline_fixed_string_t len;
9391         uint8_t len_value;
9392         cmdline_fixed_string_t bytes;
9393         cmdline_fixed_string_t bytes_value;
9394         cmdline_fixed_string_t mask;
9395         cmdline_fixed_string_t mask_value;
9396         cmdline_fixed_string_t priority;
9397         uint8_t priority_value;
9398         cmdline_fixed_string_t queue;
9399         uint16_t queue_id;
9400 };
9401
9402 static int xdigit2val(unsigned char c)
9403 {
9404         int val;
9405         if (isdigit(c))
9406                 val = c - '0';
9407         else if (isupper(c))
9408                 val = c - 'A' + 10;
9409         else
9410                 val = c - 'a' + 10;
9411         return val;
9412 }
9413
9414 static void
9415 cmd_flex_filter_parsed(void *parsed_result,
9416                           __attribute__((unused)) struct cmdline *cl,
9417                           __attribute__((unused)) void *data)
9418 {
9419         int ret = 0;
9420         struct rte_eth_flex_filter filter;
9421         struct cmd_flex_filter_result *res = parsed_result;
9422         char *bytes_ptr, *mask_ptr;
9423         uint16_t len, i, j = 0;
9424         char c;
9425         int val;
9426         uint8_t byte = 0;
9427
9428         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9429                 printf("the len exceed the max length 128\n");
9430                 return;
9431         }
9432         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9433         filter.len = res->len_value;
9434         filter.priority = res->priority_value;
9435         filter.queue = res->queue_id;
9436         bytes_ptr = res->bytes_value;
9437         mask_ptr = res->mask_value;
9438
9439          /* translate bytes string to array. */
9440         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9441                 (bytes_ptr[1] == 'X')))
9442                 bytes_ptr += 2;
9443         len = strnlen(bytes_ptr, res->len_value * 2);
9444         if (len == 0 || (len % 8 != 0)) {
9445                 printf("please check len and bytes input\n");
9446                 return;
9447         }
9448         for (i = 0; i < len; i++) {
9449                 c = bytes_ptr[i];
9450                 if (isxdigit(c) == 0) {
9451                         /* invalid characters. */
9452                         printf("invalid input\n");
9453                         return;
9454                 }
9455                 val = xdigit2val(c);
9456                 if (i % 2) {
9457                         byte |= val;
9458                         filter.bytes[j] = byte;
9459                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9460                         j++;
9461                         byte = 0;
9462                 } else
9463                         byte |= val << 4;
9464         }
9465         printf("\n");
9466          /* translate mask string to uint8_t array. */
9467         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9468                 (mask_ptr[1] == 'X')))
9469                 mask_ptr += 2;
9470         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9471         if (len == 0) {
9472                 printf("invalid input\n");
9473                 return;
9474         }
9475         j = 0;
9476         byte = 0;
9477         for (i = 0; i < len; i++) {
9478                 c = mask_ptr[i];
9479                 if (isxdigit(c) == 0) {
9480                         /* invalid characters. */
9481                         printf("invalid input\n");
9482                         return;
9483                 }
9484                 val = xdigit2val(c);
9485                 if (i % 2) {
9486                         byte |= val;
9487                         filter.mask[j] = byte;
9488                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9489                         j++;
9490                         byte = 0;
9491                 } else
9492                         byte |= val << 4;
9493         }
9494         printf("\n");
9495
9496         if (!strcmp(res->ops, "add"))
9497                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9498                                 RTE_ETH_FILTER_FLEXIBLE,
9499                                 RTE_ETH_FILTER_ADD,
9500                                 &filter);
9501         else
9502                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9503                                 RTE_ETH_FILTER_FLEXIBLE,
9504                                 RTE_ETH_FILTER_DELETE,
9505                                 &filter);
9506
9507         if (ret < 0)
9508                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9509 }
9510
9511 cmdline_parse_token_string_t cmd_flex_filter_filter =
9512         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9513                                 filter, "flex_filter");
9514 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9515         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9516                                 port_id, UINT16);
9517 cmdline_parse_token_string_t cmd_flex_filter_ops =
9518         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9519                                 ops, "add#del");
9520 cmdline_parse_token_string_t cmd_flex_filter_len =
9521         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9522                                 len, "len");
9523 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9524         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9525                                 len_value, UINT8);
9526 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9527         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9528                                 bytes, "bytes");
9529 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9530         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9531                                 bytes_value, NULL);
9532 cmdline_parse_token_string_t cmd_flex_filter_mask =
9533         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9534                                 mask, "mask");
9535 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9536         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9537                                 mask_value, NULL);
9538 cmdline_parse_token_string_t cmd_flex_filter_priority =
9539         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9540                                 priority, "priority");
9541 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9542         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9543                                 priority_value, UINT8);
9544 cmdline_parse_token_string_t cmd_flex_filter_queue =
9545         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9546                                 queue, "queue");
9547 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9548         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9549                                 queue_id, UINT16);
9550 cmdline_parse_inst_t cmd_flex_filter = {
9551         .f = cmd_flex_filter_parsed,
9552         .data = NULL,
9553         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9554                 "<value> mask <value> priority <value> queue <queue_id>: "
9555                 "Add/Del a flex filter",
9556         .tokens = {
9557                 (void *)&cmd_flex_filter_filter,
9558                 (void *)&cmd_flex_filter_port_id,
9559                 (void *)&cmd_flex_filter_ops,
9560                 (void *)&cmd_flex_filter_len,
9561                 (void *)&cmd_flex_filter_len_value,
9562                 (void *)&cmd_flex_filter_bytes,
9563                 (void *)&cmd_flex_filter_bytes_value,
9564                 (void *)&cmd_flex_filter_mask,
9565                 (void *)&cmd_flex_filter_mask_value,
9566                 (void *)&cmd_flex_filter_priority,
9567                 (void *)&cmd_flex_filter_priority_value,
9568                 (void *)&cmd_flex_filter_queue,
9569                 (void *)&cmd_flex_filter_queue_id,
9570                 NULL,
9571         },
9572 };
9573
9574 /* *** Filters Control *** */
9575
9576 /* *** deal with ethertype filter *** */
9577 struct cmd_ethertype_filter_result {
9578         cmdline_fixed_string_t filter;
9579         portid_t port_id;
9580         cmdline_fixed_string_t ops;
9581         cmdline_fixed_string_t mac;
9582         struct ether_addr mac_addr;
9583         cmdline_fixed_string_t ethertype;
9584         uint16_t ethertype_value;
9585         cmdline_fixed_string_t drop;
9586         cmdline_fixed_string_t queue;
9587         uint16_t  queue_id;
9588 };
9589
9590 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9591         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9592                                  filter, "ethertype_filter");
9593 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9594         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9595                               port_id, UINT16);
9596 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9597         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9598                                  ops, "add#del");
9599 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9600         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9601                                  mac, "mac_addr#mac_ignr");
9602 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9603         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9604                                      mac_addr);
9605 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9606         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9607                                  ethertype, "ethertype");
9608 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9609         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9610                               ethertype_value, UINT16);
9611 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9612         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9613                                  drop, "drop#fwd");
9614 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9615         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9616                                  queue, "queue");
9617 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9618         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9619                               queue_id, UINT16);
9620
9621 static void
9622 cmd_ethertype_filter_parsed(void *parsed_result,
9623                           __attribute__((unused)) struct cmdline *cl,
9624                           __attribute__((unused)) void *data)
9625 {
9626         struct cmd_ethertype_filter_result *res = parsed_result;
9627         struct rte_eth_ethertype_filter filter;
9628         int ret = 0;
9629
9630         ret = rte_eth_dev_filter_supported(res->port_id,
9631                         RTE_ETH_FILTER_ETHERTYPE);
9632         if (ret < 0) {
9633                 printf("ethertype filter is not supported on port %u.\n",
9634                         res->port_id);
9635                 return;
9636         }
9637
9638         memset(&filter, 0, sizeof(filter));
9639         if (!strcmp(res->mac, "mac_addr")) {
9640                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9641                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9642                         sizeof(struct ether_addr));
9643         }
9644         if (!strcmp(res->drop, "drop"))
9645                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9646         filter.ether_type = res->ethertype_value;
9647         filter.queue = res->queue_id;
9648
9649         if (!strcmp(res->ops, "add"))
9650                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9651                                 RTE_ETH_FILTER_ETHERTYPE,
9652                                 RTE_ETH_FILTER_ADD,
9653                                 &filter);
9654         else
9655                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9656                                 RTE_ETH_FILTER_ETHERTYPE,
9657                                 RTE_ETH_FILTER_DELETE,
9658                                 &filter);
9659         if (ret < 0)
9660                 printf("ethertype filter programming error: (%s)\n",
9661                         strerror(-ret));
9662 }
9663
9664 cmdline_parse_inst_t cmd_ethertype_filter = {
9665         .f = cmd_ethertype_filter_parsed,
9666         .data = NULL,
9667         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9668                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9669                 "Add or delete an ethertype filter entry",
9670         .tokens = {
9671                 (void *)&cmd_ethertype_filter_filter,
9672                 (void *)&cmd_ethertype_filter_port_id,
9673                 (void *)&cmd_ethertype_filter_ops,
9674                 (void *)&cmd_ethertype_filter_mac,
9675                 (void *)&cmd_ethertype_filter_mac_addr,
9676                 (void *)&cmd_ethertype_filter_ethertype,
9677                 (void *)&cmd_ethertype_filter_ethertype_value,
9678                 (void *)&cmd_ethertype_filter_drop,
9679                 (void *)&cmd_ethertype_filter_queue,
9680                 (void *)&cmd_ethertype_filter_queue_id,
9681                 NULL,
9682         },
9683 };
9684
9685 /* *** deal with flow director filter *** */
9686 struct cmd_flow_director_result {
9687         cmdline_fixed_string_t flow_director_filter;
9688         portid_t port_id;
9689         cmdline_fixed_string_t mode;
9690         cmdline_fixed_string_t mode_value;
9691         cmdline_fixed_string_t ops;
9692         cmdline_fixed_string_t flow;
9693         cmdline_fixed_string_t flow_type;
9694         cmdline_fixed_string_t ether;
9695         uint16_t ether_type;
9696         cmdline_fixed_string_t src;
9697         cmdline_ipaddr_t ip_src;
9698         uint16_t port_src;
9699         cmdline_fixed_string_t dst;
9700         cmdline_ipaddr_t ip_dst;
9701         uint16_t port_dst;
9702         cmdline_fixed_string_t verify_tag;
9703         uint32_t verify_tag_value;
9704         cmdline_ipaddr_t tos;
9705         uint8_t tos_value;
9706         cmdline_ipaddr_t proto;
9707         uint8_t proto_value;
9708         cmdline_ipaddr_t ttl;
9709         uint8_t ttl_value;
9710         cmdline_fixed_string_t vlan;
9711         uint16_t vlan_value;
9712         cmdline_fixed_string_t flexbytes;
9713         cmdline_fixed_string_t flexbytes_value;
9714         cmdline_fixed_string_t pf_vf;
9715         cmdline_fixed_string_t drop;
9716         cmdline_fixed_string_t queue;
9717         uint16_t  queue_id;
9718         cmdline_fixed_string_t fd_id;
9719         uint32_t  fd_id_value;
9720         cmdline_fixed_string_t mac;
9721         struct ether_addr mac_addr;
9722         cmdline_fixed_string_t tunnel;
9723         cmdline_fixed_string_t tunnel_type;
9724         cmdline_fixed_string_t tunnel_id;
9725         uint32_t tunnel_id_value;
9726 };
9727
9728 static inline int
9729 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9730 {
9731         char s[256];
9732         const char *p, *p0 = q_arg;
9733         char *end;
9734         unsigned long int_fld;
9735         char *str_fld[max_num];
9736         int i;
9737         unsigned size;
9738         int ret = -1;
9739
9740         p = strchr(p0, '(');
9741         if (p == NULL)
9742                 return -1;
9743         ++p;
9744         p0 = strchr(p, ')');
9745         if (p0 == NULL)
9746                 return -1;
9747
9748         size = p0 - p;
9749         if (size >= sizeof(s))
9750                 return -1;
9751
9752         snprintf(s, sizeof(s), "%.*s", size, p);
9753         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9754         if (ret < 0 || ret > max_num)
9755                 return -1;
9756         for (i = 0; i < ret; i++) {
9757                 errno = 0;
9758                 int_fld = strtoul(str_fld[i], &end, 0);
9759                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9760                         return -1;
9761                 flexbytes[i] = (uint8_t)int_fld;
9762         }
9763         return ret;
9764 }
9765
9766 static uint16_t
9767 str2flowtype(char *string)
9768 {
9769         uint8_t i = 0;
9770         static const struct {
9771                 char str[32];
9772                 uint16_t type;
9773         } flowtype_str[] = {
9774                 {"raw", RTE_ETH_FLOW_RAW},
9775                 {"ipv4", RTE_ETH_FLOW_IPV4},
9776                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9777                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9778                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9779                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9780                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9781                 {"ipv6", RTE_ETH_FLOW_IPV6},
9782                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9783                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9784                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9785                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9786                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9787                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9788         };
9789
9790         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9791                 if (!strcmp(flowtype_str[i].str, string))
9792                         return flowtype_str[i].type;
9793         }
9794
9795         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9796                 return (uint16_t)atoi(string);
9797
9798         return RTE_ETH_FLOW_UNKNOWN;
9799 }
9800
9801 static enum rte_eth_fdir_tunnel_type
9802 str2fdir_tunneltype(char *string)
9803 {
9804         uint8_t i = 0;
9805
9806         static const struct {
9807                 char str[32];
9808                 enum rte_eth_fdir_tunnel_type type;
9809         } tunneltype_str[] = {
9810                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9811                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9812         };
9813
9814         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9815                 if (!strcmp(tunneltype_str[i].str, string))
9816                         return tunneltype_str[i].type;
9817         }
9818         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9819 }
9820
9821 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9822 do { \
9823         if ((ip_addr).family == AF_INET) \
9824                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9825         else { \
9826                 printf("invalid parameter.\n"); \
9827                 return; \
9828         } \
9829 } while (0)
9830
9831 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9832 do { \
9833         if ((ip_addr).family == AF_INET6) \
9834                 rte_memcpy(&(ip), \
9835                                  &((ip_addr).addr.ipv6), \
9836                                  sizeof(struct in6_addr)); \
9837         else { \
9838                 printf("invalid parameter.\n"); \
9839                 return; \
9840         } \
9841 } while (0)
9842
9843 static void
9844 cmd_flow_director_filter_parsed(void *parsed_result,
9845                           __attribute__((unused)) struct cmdline *cl,
9846                           __attribute__((unused)) void *data)
9847 {
9848         struct cmd_flow_director_result *res = parsed_result;
9849         struct rte_eth_fdir_filter entry;
9850         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9851         char *end;
9852         unsigned long vf_id;
9853         int ret = 0;
9854
9855         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9856         if (ret < 0) {
9857                 printf("flow director is not supported on port %u.\n",
9858                         res->port_id);
9859                 return;
9860         }
9861         memset(flexbytes, 0, sizeof(flexbytes));
9862         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9863
9864         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9865                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9866                         printf("Please set mode to MAC-VLAN.\n");
9867                         return;
9868                 }
9869         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9870                 if (strcmp(res->mode_value, "Tunnel")) {
9871                         printf("Please set mode to Tunnel.\n");
9872                         return;
9873                 }
9874         } else {
9875                 if (strcmp(res->mode_value, "IP")) {
9876                         printf("Please set mode to IP.\n");
9877                         return;
9878                 }
9879                 entry.input.flow_type = str2flowtype(res->flow_type);
9880         }
9881
9882         ret = parse_flexbytes(res->flexbytes_value,
9883                                         flexbytes,
9884                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9885         if (ret < 0) {
9886                 printf("error: Cannot parse flexbytes input.\n");
9887                 return;
9888         }
9889
9890         switch (entry.input.flow_type) {
9891         case RTE_ETH_FLOW_FRAG_IPV4:
9892         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9893                 entry.input.flow.ip4_flow.proto = res->proto_value;
9894                 /* fall-through */
9895         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9896         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9897                 IPV4_ADDR_TO_UINT(res->ip_dst,
9898                         entry.input.flow.ip4_flow.dst_ip);
9899                 IPV4_ADDR_TO_UINT(res->ip_src,
9900                         entry.input.flow.ip4_flow.src_ip);
9901                 entry.input.flow.ip4_flow.tos = res->tos_value;
9902                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9903                 /* need convert to big endian. */
9904                 entry.input.flow.udp4_flow.dst_port =
9905                                 rte_cpu_to_be_16(res->port_dst);
9906                 entry.input.flow.udp4_flow.src_port =
9907                                 rte_cpu_to_be_16(res->port_src);
9908                 break;
9909         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9910                 IPV4_ADDR_TO_UINT(res->ip_dst,
9911                         entry.input.flow.sctp4_flow.ip.dst_ip);
9912                 IPV4_ADDR_TO_UINT(res->ip_src,
9913                         entry.input.flow.sctp4_flow.ip.src_ip);
9914                 entry.input.flow.ip4_flow.tos = res->tos_value;
9915                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9916                 /* need convert to big endian. */
9917                 entry.input.flow.sctp4_flow.dst_port =
9918                                 rte_cpu_to_be_16(res->port_dst);
9919                 entry.input.flow.sctp4_flow.src_port =
9920                                 rte_cpu_to_be_16(res->port_src);
9921                 entry.input.flow.sctp4_flow.verify_tag =
9922                                 rte_cpu_to_be_32(res->verify_tag_value);
9923                 break;
9924         case RTE_ETH_FLOW_FRAG_IPV6:
9925         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9926                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9927                 /* fall-through */
9928         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9929         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9930                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9931                         entry.input.flow.ipv6_flow.dst_ip);
9932                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9933                         entry.input.flow.ipv6_flow.src_ip);
9934                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9935                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9936                 /* need convert to big endian. */
9937                 entry.input.flow.udp6_flow.dst_port =
9938                                 rte_cpu_to_be_16(res->port_dst);
9939                 entry.input.flow.udp6_flow.src_port =
9940                                 rte_cpu_to_be_16(res->port_src);
9941                 break;
9942         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9943                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9944                         entry.input.flow.sctp6_flow.ip.dst_ip);
9945                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9946                         entry.input.flow.sctp6_flow.ip.src_ip);
9947                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9948                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9949                 /* need convert to big endian. */
9950                 entry.input.flow.sctp6_flow.dst_port =
9951                                 rte_cpu_to_be_16(res->port_dst);
9952                 entry.input.flow.sctp6_flow.src_port =
9953                                 rte_cpu_to_be_16(res->port_src);
9954                 entry.input.flow.sctp6_flow.verify_tag =
9955                                 rte_cpu_to_be_32(res->verify_tag_value);
9956                 break;
9957         case RTE_ETH_FLOW_L2_PAYLOAD:
9958                 entry.input.flow.l2_flow.ether_type =
9959                         rte_cpu_to_be_16(res->ether_type);
9960                 break;
9961         default:
9962                 break;
9963         }
9964
9965         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9966                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9967                                  &res->mac_addr,
9968                                  sizeof(struct ether_addr));
9969
9970         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9971                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9972                                  &res->mac_addr,
9973                                  sizeof(struct ether_addr));
9974                 entry.input.flow.tunnel_flow.tunnel_type =
9975                         str2fdir_tunneltype(res->tunnel_type);
9976                 entry.input.flow.tunnel_flow.tunnel_id =
9977                         rte_cpu_to_be_32(res->tunnel_id_value);
9978         }
9979
9980         rte_memcpy(entry.input.flow_ext.flexbytes,
9981                    flexbytes,
9982                    RTE_ETH_FDIR_MAX_FLEXLEN);
9983
9984         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9985
9986         entry.action.flex_off = 0;  /*use 0 by default */
9987         if (!strcmp(res->drop, "drop"))
9988                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9989         else
9990                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9991
9992         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9993             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9994                 if (!strcmp(res->pf_vf, "pf"))
9995                         entry.input.flow_ext.is_vf = 0;
9996                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9997                         struct rte_eth_dev_info dev_info;
9998
9999                         memset(&dev_info, 0, sizeof(dev_info));
10000                         rte_eth_dev_info_get(res->port_id, &dev_info);
10001                         errno = 0;
10002                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10003                         if (errno != 0 || *end != '\0' ||
10004                             vf_id >= dev_info.max_vfs) {
10005                                 printf("invalid parameter %s.\n", res->pf_vf);
10006                                 return;
10007                         }
10008                         entry.input.flow_ext.is_vf = 1;
10009                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10010                 } else {
10011                         printf("invalid parameter %s.\n", res->pf_vf);
10012                         return;
10013                 }
10014         }
10015
10016         /* set to report FD ID by default */
10017         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10018         entry.action.rx_queue = res->queue_id;
10019         entry.soft_id = res->fd_id_value;
10020         if (!strcmp(res->ops, "add"))
10021                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10022                                              RTE_ETH_FILTER_ADD, &entry);
10023         else if (!strcmp(res->ops, "del"))
10024                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10025                                              RTE_ETH_FILTER_DELETE, &entry);
10026         else
10027                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10028                                              RTE_ETH_FILTER_UPDATE, &entry);
10029         if (ret < 0)
10030                 printf("flow director programming error: (%s)\n",
10031                         strerror(-ret));
10032 }
10033
10034 cmdline_parse_token_string_t cmd_flow_director_filter =
10035         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10036                                  flow_director_filter, "flow_director_filter");
10037 cmdline_parse_token_num_t cmd_flow_director_port_id =
10038         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10039                               port_id, UINT16);
10040 cmdline_parse_token_string_t cmd_flow_director_ops =
10041         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10042                                  ops, "add#del#update");
10043 cmdline_parse_token_string_t cmd_flow_director_flow =
10044         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10045                                  flow, "flow");
10046 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10047         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10048                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10049                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10050 cmdline_parse_token_string_t cmd_flow_director_ether =
10051         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10052                                  ether, "ether");
10053 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10054         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10055                               ether_type, UINT16);
10056 cmdline_parse_token_string_t cmd_flow_director_src =
10057         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10058                                  src, "src");
10059 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10060         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10061                                  ip_src);
10062 cmdline_parse_token_num_t cmd_flow_director_port_src =
10063         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10064                               port_src, UINT16);
10065 cmdline_parse_token_string_t cmd_flow_director_dst =
10066         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10067                                  dst, "dst");
10068 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10069         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10070                                  ip_dst);
10071 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10072         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10073                               port_dst, UINT16);
10074 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10075         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10076                                   verify_tag, "verify_tag");
10077 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10078         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10079                               verify_tag_value, UINT32);
10080 cmdline_parse_token_string_t cmd_flow_director_tos =
10081         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10082                                  tos, "tos");
10083 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10084         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10085                               tos_value, UINT8);
10086 cmdline_parse_token_string_t cmd_flow_director_proto =
10087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10088                                  proto, "proto");
10089 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10090         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10091                               proto_value, UINT8);
10092 cmdline_parse_token_string_t cmd_flow_director_ttl =
10093         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10094                                  ttl, "ttl");
10095 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10096         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10097                               ttl_value, UINT8);
10098 cmdline_parse_token_string_t cmd_flow_director_vlan =
10099         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10100                                  vlan, "vlan");
10101 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10102         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10103                               vlan_value, UINT16);
10104 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10105         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10106                                  flexbytes, "flexbytes");
10107 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10108         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10109                               flexbytes_value, NULL);
10110 cmdline_parse_token_string_t cmd_flow_director_drop =
10111         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10112                                  drop, "drop#fwd");
10113 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10114         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10115                               pf_vf, NULL);
10116 cmdline_parse_token_string_t cmd_flow_director_queue =
10117         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10118                                  queue, "queue");
10119 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10120         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10121                               queue_id, UINT16);
10122 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10123         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10124                                  fd_id, "fd_id");
10125 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10126         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10127                               fd_id_value, UINT32);
10128
10129 cmdline_parse_token_string_t cmd_flow_director_mode =
10130         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10131                                  mode, "mode");
10132 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10133         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10134                                  mode_value, "IP");
10135 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10136         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10137                                  mode_value, "MAC-VLAN");
10138 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10139         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10140                                  mode_value, "Tunnel");
10141 cmdline_parse_token_string_t cmd_flow_director_mac =
10142         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10143                                  mac, "mac");
10144 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10145         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10146                                     mac_addr);
10147 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10148         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10149                                  tunnel, "tunnel");
10150 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10151         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10152                                  tunnel_type, "NVGRE#VxLAN");
10153 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10154         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10155                                  tunnel_id, "tunnel-id");
10156 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10157         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10158                               tunnel_id_value, UINT32);
10159
10160 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10161         .f = cmd_flow_director_filter_parsed,
10162         .data = NULL,
10163         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10164                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10165                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10166                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10167                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10168                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
10169                 "fd_id <fd_id_value>: "
10170                 "Add or delete an ip flow director entry on NIC",
10171         .tokens = {
10172                 (void *)&cmd_flow_director_filter,
10173                 (void *)&cmd_flow_director_port_id,
10174                 (void *)&cmd_flow_director_mode,
10175                 (void *)&cmd_flow_director_mode_ip,
10176                 (void *)&cmd_flow_director_ops,
10177                 (void *)&cmd_flow_director_flow,
10178                 (void *)&cmd_flow_director_flow_type,
10179                 (void *)&cmd_flow_director_src,
10180                 (void *)&cmd_flow_director_ip_src,
10181                 (void *)&cmd_flow_director_dst,
10182                 (void *)&cmd_flow_director_ip_dst,
10183                 (void *)&cmd_flow_director_tos,
10184                 (void *)&cmd_flow_director_tos_value,
10185                 (void *)&cmd_flow_director_proto,
10186                 (void *)&cmd_flow_director_proto_value,
10187                 (void *)&cmd_flow_director_ttl,
10188                 (void *)&cmd_flow_director_ttl_value,
10189                 (void *)&cmd_flow_director_vlan,
10190                 (void *)&cmd_flow_director_vlan_value,
10191                 (void *)&cmd_flow_director_flexbytes,
10192                 (void *)&cmd_flow_director_flexbytes_value,
10193                 (void *)&cmd_flow_director_drop,
10194                 (void *)&cmd_flow_director_pf_vf,
10195                 (void *)&cmd_flow_director_queue,
10196                 (void *)&cmd_flow_director_queue_id,
10197                 (void *)&cmd_flow_director_fd_id,
10198                 (void *)&cmd_flow_director_fd_id_value,
10199                 NULL,
10200         },
10201 };
10202
10203 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10204         .f = cmd_flow_director_filter_parsed,
10205         .data = NULL,
10206         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10207                 "director entry on NIC",
10208         .tokens = {
10209                 (void *)&cmd_flow_director_filter,
10210                 (void *)&cmd_flow_director_port_id,
10211                 (void *)&cmd_flow_director_mode,
10212                 (void *)&cmd_flow_director_mode_ip,
10213                 (void *)&cmd_flow_director_ops,
10214                 (void *)&cmd_flow_director_flow,
10215                 (void *)&cmd_flow_director_flow_type,
10216                 (void *)&cmd_flow_director_src,
10217                 (void *)&cmd_flow_director_ip_src,
10218                 (void *)&cmd_flow_director_port_src,
10219                 (void *)&cmd_flow_director_dst,
10220                 (void *)&cmd_flow_director_ip_dst,
10221                 (void *)&cmd_flow_director_port_dst,
10222                 (void *)&cmd_flow_director_tos,
10223                 (void *)&cmd_flow_director_tos_value,
10224                 (void *)&cmd_flow_director_ttl,
10225                 (void *)&cmd_flow_director_ttl_value,
10226                 (void *)&cmd_flow_director_vlan,
10227                 (void *)&cmd_flow_director_vlan_value,
10228                 (void *)&cmd_flow_director_flexbytes,
10229                 (void *)&cmd_flow_director_flexbytes_value,
10230                 (void *)&cmd_flow_director_drop,
10231                 (void *)&cmd_flow_director_pf_vf,
10232                 (void *)&cmd_flow_director_queue,
10233                 (void *)&cmd_flow_director_queue_id,
10234                 (void *)&cmd_flow_director_fd_id,
10235                 (void *)&cmd_flow_director_fd_id_value,
10236                 NULL,
10237         },
10238 };
10239
10240 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10241         .f = cmd_flow_director_filter_parsed,
10242         .data = NULL,
10243         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10244                 "director entry on NIC",
10245         .tokens = {
10246                 (void *)&cmd_flow_director_filter,
10247                 (void *)&cmd_flow_director_port_id,
10248                 (void *)&cmd_flow_director_mode,
10249                 (void *)&cmd_flow_director_mode_ip,
10250                 (void *)&cmd_flow_director_ops,
10251                 (void *)&cmd_flow_director_flow,
10252                 (void *)&cmd_flow_director_flow_type,
10253                 (void *)&cmd_flow_director_src,
10254                 (void *)&cmd_flow_director_ip_src,
10255                 (void *)&cmd_flow_director_port_dst,
10256                 (void *)&cmd_flow_director_dst,
10257                 (void *)&cmd_flow_director_ip_dst,
10258                 (void *)&cmd_flow_director_port_dst,
10259                 (void *)&cmd_flow_director_verify_tag,
10260                 (void *)&cmd_flow_director_verify_tag_value,
10261                 (void *)&cmd_flow_director_tos,
10262                 (void *)&cmd_flow_director_tos_value,
10263                 (void *)&cmd_flow_director_ttl,
10264                 (void *)&cmd_flow_director_ttl_value,
10265                 (void *)&cmd_flow_director_vlan,
10266                 (void *)&cmd_flow_director_vlan_value,
10267                 (void *)&cmd_flow_director_flexbytes,
10268                 (void *)&cmd_flow_director_flexbytes_value,
10269                 (void *)&cmd_flow_director_drop,
10270                 (void *)&cmd_flow_director_pf_vf,
10271                 (void *)&cmd_flow_director_queue,
10272                 (void *)&cmd_flow_director_queue_id,
10273                 (void *)&cmd_flow_director_fd_id,
10274                 (void *)&cmd_flow_director_fd_id_value,
10275                 NULL,
10276         },
10277 };
10278
10279 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10280         .f = cmd_flow_director_filter_parsed,
10281         .data = NULL,
10282         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10283                 "director entry on NIC",
10284         .tokens = {
10285                 (void *)&cmd_flow_director_filter,
10286                 (void *)&cmd_flow_director_port_id,
10287                 (void *)&cmd_flow_director_mode,
10288                 (void *)&cmd_flow_director_mode_ip,
10289                 (void *)&cmd_flow_director_ops,
10290                 (void *)&cmd_flow_director_flow,
10291                 (void *)&cmd_flow_director_flow_type,
10292                 (void *)&cmd_flow_director_ether,
10293                 (void *)&cmd_flow_director_ether_type,
10294                 (void *)&cmd_flow_director_flexbytes,
10295                 (void *)&cmd_flow_director_flexbytes_value,
10296                 (void *)&cmd_flow_director_drop,
10297                 (void *)&cmd_flow_director_pf_vf,
10298                 (void *)&cmd_flow_director_queue,
10299                 (void *)&cmd_flow_director_queue_id,
10300                 (void *)&cmd_flow_director_fd_id,
10301                 (void *)&cmd_flow_director_fd_id_value,
10302                 NULL,
10303         },
10304 };
10305
10306 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10307         .f = cmd_flow_director_filter_parsed,
10308         .data = NULL,
10309         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10310                 "director entry on NIC",
10311         .tokens = {
10312                 (void *)&cmd_flow_director_filter,
10313                 (void *)&cmd_flow_director_port_id,
10314                 (void *)&cmd_flow_director_mode,
10315                 (void *)&cmd_flow_director_mode_mac_vlan,
10316                 (void *)&cmd_flow_director_ops,
10317                 (void *)&cmd_flow_director_mac,
10318                 (void *)&cmd_flow_director_mac_addr,
10319                 (void *)&cmd_flow_director_vlan,
10320                 (void *)&cmd_flow_director_vlan_value,
10321                 (void *)&cmd_flow_director_flexbytes,
10322                 (void *)&cmd_flow_director_flexbytes_value,
10323                 (void *)&cmd_flow_director_drop,
10324                 (void *)&cmd_flow_director_queue,
10325                 (void *)&cmd_flow_director_queue_id,
10326                 (void *)&cmd_flow_director_fd_id,
10327                 (void *)&cmd_flow_director_fd_id_value,
10328                 NULL,
10329         },
10330 };
10331
10332 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10333         .f = cmd_flow_director_filter_parsed,
10334         .data = NULL,
10335         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10336                 "director entry on NIC",
10337         .tokens = {
10338                 (void *)&cmd_flow_director_filter,
10339                 (void *)&cmd_flow_director_port_id,
10340                 (void *)&cmd_flow_director_mode,
10341                 (void *)&cmd_flow_director_mode_tunnel,
10342                 (void *)&cmd_flow_director_ops,
10343                 (void *)&cmd_flow_director_mac,
10344                 (void *)&cmd_flow_director_mac_addr,
10345                 (void *)&cmd_flow_director_vlan,
10346                 (void *)&cmd_flow_director_vlan_value,
10347                 (void *)&cmd_flow_director_tunnel,
10348                 (void *)&cmd_flow_director_tunnel_type,
10349                 (void *)&cmd_flow_director_tunnel_id,
10350                 (void *)&cmd_flow_director_tunnel_id_value,
10351                 (void *)&cmd_flow_director_flexbytes,
10352                 (void *)&cmd_flow_director_flexbytes_value,
10353                 (void *)&cmd_flow_director_drop,
10354                 (void *)&cmd_flow_director_queue,
10355                 (void *)&cmd_flow_director_queue_id,
10356                 (void *)&cmd_flow_director_fd_id,
10357                 (void *)&cmd_flow_director_fd_id_value,
10358                 NULL,
10359         },
10360 };
10361
10362 struct cmd_flush_flow_director_result {
10363         cmdline_fixed_string_t flush_flow_director;
10364         portid_t port_id;
10365 };
10366
10367 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10368         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10369                                  flush_flow_director, "flush_flow_director");
10370 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10371         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10372                               port_id, UINT16);
10373
10374 static void
10375 cmd_flush_flow_director_parsed(void *parsed_result,
10376                           __attribute__((unused)) struct cmdline *cl,
10377                           __attribute__((unused)) void *data)
10378 {
10379         struct cmd_flow_director_result *res = parsed_result;
10380         int ret = 0;
10381
10382         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10383         if (ret < 0) {
10384                 printf("flow director is not supported on port %u.\n",
10385                         res->port_id);
10386                 return;
10387         }
10388
10389         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10390                         RTE_ETH_FILTER_FLUSH, NULL);
10391         if (ret < 0)
10392                 printf("flow director table flushing error: (%s)\n",
10393                         strerror(-ret));
10394 }
10395
10396 cmdline_parse_inst_t cmd_flush_flow_director = {
10397         .f = cmd_flush_flow_director_parsed,
10398         .data = NULL,
10399         .help_str = "flush_flow_director <port_id>: "
10400                 "Flush all flow director entries of a device on NIC",
10401         .tokens = {
10402                 (void *)&cmd_flush_flow_director_flush,
10403                 (void *)&cmd_flush_flow_director_port_id,
10404                 NULL,
10405         },
10406 };
10407
10408 /* *** deal with flow director mask *** */
10409 struct cmd_flow_director_mask_result {
10410         cmdline_fixed_string_t flow_director_mask;
10411         portid_t port_id;
10412         cmdline_fixed_string_t mode;
10413         cmdline_fixed_string_t mode_value;
10414         cmdline_fixed_string_t vlan;
10415         uint16_t vlan_mask;
10416         cmdline_fixed_string_t src_mask;
10417         cmdline_ipaddr_t ipv4_src;
10418         cmdline_ipaddr_t ipv6_src;
10419         uint16_t port_src;
10420         cmdline_fixed_string_t dst_mask;
10421         cmdline_ipaddr_t ipv4_dst;
10422         cmdline_ipaddr_t ipv6_dst;
10423         uint16_t port_dst;
10424         cmdline_fixed_string_t mac;
10425         uint8_t mac_addr_byte_mask;
10426         cmdline_fixed_string_t tunnel_id;
10427         uint32_t tunnel_id_mask;
10428         cmdline_fixed_string_t tunnel_type;
10429         uint8_t tunnel_type_mask;
10430 };
10431
10432 static void
10433 cmd_flow_director_mask_parsed(void *parsed_result,
10434                           __attribute__((unused)) struct cmdline *cl,
10435                           __attribute__((unused)) void *data)
10436 {
10437         struct cmd_flow_director_mask_result *res = parsed_result;
10438         struct rte_eth_fdir_masks *mask;
10439         struct rte_port *port;
10440
10441         if (res->port_id > nb_ports) {
10442                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10443                 return;
10444         }
10445
10446         port = &ports[res->port_id];
10447         /** Check if the port is not started **/
10448         if (port->port_status != RTE_PORT_STOPPED) {
10449                 printf("Please stop port %d first\n", res->port_id);
10450                 return;
10451         }
10452
10453         mask = &port->dev_conf.fdir_conf.mask;
10454
10455         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10456                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10457                         printf("Please set mode to MAC-VLAN.\n");
10458                         return;
10459                 }
10460
10461                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10462         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10463                 if (strcmp(res->mode_value, "Tunnel")) {
10464                         printf("Please set mode to Tunnel.\n");
10465                         return;
10466                 }
10467
10468                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10469                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10470                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10471                 mask->tunnel_type_mask = res->tunnel_type_mask;
10472         } else {
10473                 if (strcmp(res->mode_value, "IP")) {
10474                         printf("Please set mode to IP.\n");
10475                         return;
10476                 }
10477
10478                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10479                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10480                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10481                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10482                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10483                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10484                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10485         }
10486
10487         cmd_reconfig_device_queue(res->port_id, 1, 1);
10488 }
10489
10490 cmdline_parse_token_string_t cmd_flow_director_mask =
10491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10492                                  flow_director_mask, "flow_director_mask");
10493 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10494         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10495                               port_id, UINT16);
10496 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10498                                  vlan, "vlan");
10499 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10500         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10501                               vlan_mask, UINT16);
10502 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10503         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10504                                  src_mask, "src_mask");
10505 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10506         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10507                                  ipv4_src);
10508 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10509         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10510                                  ipv6_src);
10511 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10512         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10513                               port_src, UINT16);
10514 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10515         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10516                                  dst_mask, "dst_mask");
10517 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10518         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10519                                  ipv4_dst);
10520 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10521         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10522                                  ipv6_dst);
10523 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10524         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10525                               port_dst, UINT16);
10526
10527 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10528         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10529                                  mode, "mode");
10530 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10531         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10532                                  mode_value, "IP");
10533 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10534         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10535                                  mode_value, "MAC-VLAN");
10536 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10537         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10538                                  mode_value, "Tunnel");
10539 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10540         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10541                                  mac, "mac");
10542 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10543         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10544                               mac_addr_byte_mask, UINT8);
10545 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10546         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10547                                  tunnel_type, "tunnel-type");
10548 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10549         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10550                               tunnel_type_mask, UINT8);
10551 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10552         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10553                                  tunnel_id, "tunnel-id");
10554 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10555         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10556                               tunnel_id_mask, UINT32);
10557
10558 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10559         .f = cmd_flow_director_mask_parsed,
10560         .data = NULL,
10561         .help_str = "flow_director_mask ... : "
10562                 "Set IP mode flow director's mask on NIC",
10563         .tokens = {
10564                 (void *)&cmd_flow_director_mask,
10565                 (void *)&cmd_flow_director_mask_port_id,
10566                 (void *)&cmd_flow_director_mask_mode,
10567                 (void *)&cmd_flow_director_mask_mode_ip,
10568                 (void *)&cmd_flow_director_mask_vlan,
10569                 (void *)&cmd_flow_director_mask_vlan_value,
10570                 (void *)&cmd_flow_director_mask_src,
10571                 (void *)&cmd_flow_director_mask_ipv4_src,
10572                 (void *)&cmd_flow_director_mask_ipv6_src,
10573                 (void *)&cmd_flow_director_mask_port_src,
10574                 (void *)&cmd_flow_director_mask_dst,
10575                 (void *)&cmd_flow_director_mask_ipv4_dst,
10576                 (void *)&cmd_flow_director_mask_ipv6_dst,
10577                 (void *)&cmd_flow_director_mask_port_dst,
10578                 NULL,
10579         },
10580 };
10581
10582 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10583         .f = cmd_flow_director_mask_parsed,
10584         .data = NULL,
10585         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10586                 "flow director's mask on NIC",
10587         .tokens = {
10588                 (void *)&cmd_flow_director_mask,
10589                 (void *)&cmd_flow_director_mask_port_id,
10590                 (void *)&cmd_flow_director_mask_mode,
10591                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10592                 (void *)&cmd_flow_director_mask_vlan,
10593                 (void *)&cmd_flow_director_mask_vlan_value,
10594                 NULL,
10595         },
10596 };
10597
10598 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10599         .f = cmd_flow_director_mask_parsed,
10600         .data = NULL,
10601         .help_str = "flow_director_mask ... : Set tunnel mode "
10602                 "flow director's mask on NIC",
10603         .tokens = {
10604                 (void *)&cmd_flow_director_mask,
10605                 (void *)&cmd_flow_director_mask_port_id,
10606                 (void *)&cmd_flow_director_mask_mode,
10607                 (void *)&cmd_flow_director_mask_mode_tunnel,
10608                 (void *)&cmd_flow_director_mask_vlan,
10609                 (void *)&cmd_flow_director_mask_vlan_value,
10610                 (void *)&cmd_flow_director_mask_mac,
10611                 (void *)&cmd_flow_director_mask_mac_value,
10612                 (void *)&cmd_flow_director_mask_tunnel_type,
10613                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10614                 (void *)&cmd_flow_director_mask_tunnel_id,
10615                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10616                 NULL,
10617         },
10618 };
10619
10620 /* *** deal with flow director mask on flexible payload *** */
10621 struct cmd_flow_director_flex_mask_result {
10622         cmdline_fixed_string_t flow_director_flexmask;
10623         portid_t port_id;
10624         cmdline_fixed_string_t flow;
10625         cmdline_fixed_string_t flow_type;
10626         cmdline_fixed_string_t mask;
10627 };
10628
10629 static void
10630 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10631                           __attribute__((unused)) struct cmdline *cl,
10632                           __attribute__((unused)) void *data)
10633 {
10634         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10635         struct rte_eth_fdir_info fdir_info;
10636         struct rte_eth_fdir_flex_mask flex_mask;
10637         struct rte_port *port;
10638         uint32_t flow_type_mask;
10639         uint16_t i;
10640         int ret;
10641
10642         if (res->port_id > nb_ports) {
10643                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10644                 return;
10645         }
10646
10647         port = &ports[res->port_id];
10648         /** Check if the port is not started **/
10649         if (port->port_status != RTE_PORT_STOPPED) {
10650                 printf("Please stop port %d first\n", res->port_id);
10651                 return;
10652         }
10653
10654         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10655         ret = parse_flexbytes(res->mask,
10656                         flex_mask.mask,
10657                         RTE_ETH_FDIR_MAX_FLEXLEN);
10658         if (ret < 0) {
10659                 printf("error: Cannot parse mask input.\n");
10660                 return;
10661         }
10662
10663         memset(&fdir_info, 0, sizeof(fdir_info));
10664         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10665                                 RTE_ETH_FILTER_INFO, &fdir_info);
10666         if (ret < 0) {
10667                 printf("Cannot get FDir filter info\n");
10668                 return;
10669         }
10670
10671         if (!strcmp(res->flow_type, "none")) {
10672                 /* means don't specify the flow type */
10673                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10674                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10675                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10676                                0, sizeof(struct rte_eth_fdir_flex_mask));
10677                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10678                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10679                                  &flex_mask,
10680                                  sizeof(struct rte_eth_fdir_flex_mask));
10681                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10682                 return;
10683         }
10684         flow_type_mask = fdir_info.flow_types_mask[0];
10685         if (!strcmp(res->flow_type, "all")) {
10686                 if (!flow_type_mask) {
10687                         printf("No flow type supported\n");
10688                         return;
10689                 }
10690                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10691                         if (flow_type_mask & (1 << i)) {
10692                                 flex_mask.flow_type = i;
10693                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10694                         }
10695                 }
10696                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10697                 return;
10698         }
10699         flex_mask.flow_type = str2flowtype(res->flow_type);
10700         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10701                 printf("Flow type %s not supported on port %d\n",
10702                                 res->flow_type, res->port_id);
10703                 return;
10704         }
10705         fdir_set_flex_mask(res->port_id, &flex_mask);
10706         cmd_reconfig_device_queue(res->port_id, 1, 1);
10707 }
10708
10709 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10710         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10711                                  flow_director_flexmask,
10712                                  "flow_director_flex_mask");
10713 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10714         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10715                               port_id, UINT16);
10716 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10718                                  flow, "flow");
10719 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10721                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10722                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10723 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10724         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10725                                  mask, NULL);
10726
10727 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10728         .f = cmd_flow_director_flex_mask_parsed,
10729         .data = NULL,
10730         .help_str = "flow_director_flex_mask ... : "
10731                 "Set flow director's flex mask on NIC",
10732         .tokens = {
10733                 (void *)&cmd_flow_director_flexmask,
10734                 (void *)&cmd_flow_director_flexmask_port_id,
10735                 (void *)&cmd_flow_director_flexmask_flow,
10736                 (void *)&cmd_flow_director_flexmask_flow_type,
10737                 (void *)&cmd_flow_director_flexmask_mask,
10738                 NULL,
10739         },
10740 };
10741
10742 /* *** deal with flow director flexible payload configuration *** */
10743 struct cmd_flow_director_flexpayload_result {
10744         cmdline_fixed_string_t flow_director_flexpayload;
10745         portid_t port_id;
10746         cmdline_fixed_string_t payload_layer;
10747         cmdline_fixed_string_t payload_cfg;
10748 };
10749
10750 static inline int
10751 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10752 {
10753         char s[256];
10754         const char *p, *p0 = q_arg;
10755         char *end;
10756         unsigned long int_fld;
10757         char *str_fld[max_num];
10758         int i;
10759         unsigned size;
10760         int ret = -1;
10761
10762         p = strchr(p0, '(');
10763         if (p == NULL)
10764                 return -1;
10765         ++p;
10766         p0 = strchr(p, ')');
10767         if (p0 == NULL)
10768                 return -1;
10769
10770         size = p0 - p;
10771         if (size >= sizeof(s))
10772                 return -1;
10773
10774         snprintf(s, sizeof(s), "%.*s", size, p);
10775         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10776         if (ret < 0 || ret > max_num)
10777                 return -1;
10778         for (i = 0; i < ret; i++) {
10779                 errno = 0;
10780                 int_fld = strtoul(str_fld[i], &end, 0);
10781                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10782                         return -1;
10783                 offsets[i] = (uint16_t)int_fld;
10784         }
10785         return ret;
10786 }
10787
10788 static void
10789 cmd_flow_director_flxpld_parsed(void *parsed_result,
10790                           __attribute__((unused)) struct cmdline *cl,
10791                           __attribute__((unused)) void *data)
10792 {
10793         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10794         struct rte_eth_flex_payload_cfg flex_cfg;
10795         struct rte_port *port;
10796         int ret = 0;
10797
10798         if (res->port_id > nb_ports) {
10799                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10800                 return;
10801         }
10802
10803         port = &ports[res->port_id];
10804         /** Check if the port is not started **/
10805         if (port->port_status != RTE_PORT_STOPPED) {
10806                 printf("Please stop port %d first\n", res->port_id);
10807                 return;
10808         }
10809
10810         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10811
10812         if (!strcmp(res->payload_layer, "raw"))
10813                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10814         else if (!strcmp(res->payload_layer, "l2"))
10815                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10816         else if (!strcmp(res->payload_layer, "l3"))
10817                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10818         else if (!strcmp(res->payload_layer, "l4"))
10819                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10820
10821         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10822                             RTE_ETH_FDIR_MAX_FLEXLEN);
10823         if (ret < 0) {
10824                 printf("error: Cannot parse flex payload input.\n");
10825                 return;
10826         }
10827
10828         fdir_set_flex_payload(res->port_id, &flex_cfg);
10829         cmd_reconfig_device_queue(res->port_id, 1, 1);
10830 }
10831
10832 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10833         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10834                                  flow_director_flexpayload,
10835                                  "flow_director_flex_payload");
10836 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10837         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10838                               port_id, UINT16);
10839 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10840         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10841                                  payload_layer, "raw#l2#l3#l4");
10842 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10843         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10844                                  payload_cfg, NULL);
10845
10846 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10847         .f = cmd_flow_director_flxpld_parsed,
10848         .data = NULL,
10849         .help_str = "flow_director_flexpayload ... : "
10850                 "Set flow director's flex payload on NIC",
10851         .tokens = {
10852                 (void *)&cmd_flow_director_flexpayload,
10853                 (void *)&cmd_flow_director_flexpayload_port_id,
10854                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10855                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10856                 NULL,
10857         },
10858 };
10859
10860 /* Generic flow interface command. */
10861 extern cmdline_parse_inst_t cmd_flow;
10862
10863 /* *** Classification Filters Control *** */
10864 /* *** Get symmetric hash enable per port *** */
10865 struct cmd_get_sym_hash_ena_per_port_result {
10866         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10867         portid_t port_id;
10868 };
10869
10870 static void
10871 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10872                                  __rte_unused struct cmdline *cl,
10873                                  __rte_unused void *data)
10874 {
10875         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10876         struct rte_eth_hash_filter_info info;
10877         int ret;
10878
10879         if (rte_eth_dev_filter_supported(res->port_id,
10880                                 RTE_ETH_FILTER_HASH) < 0) {
10881                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10882                                                         res->port_id);
10883                 return;
10884         }
10885
10886         memset(&info, 0, sizeof(info));
10887         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10888         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10889                                                 RTE_ETH_FILTER_GET, &info);
10890
10891         if (ret < 0) {
10892                 printf("Cannot get symmetric hash enable per port "
10893                                         "on port %u\n", res->port_id);
10894                 return;
10895         }
10896
10897         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10898                                 "enabled" : "disabled", res->port_id);
10899 }
10900
10901 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10902         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10903                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10904 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10905         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10906                 port_id, UINT16);
10907
10908 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10909         .f = cmd_get_sym_hash_per_port_parsed,
10910         .data = NULL,
10911         .help_str = "get_sym_hash_ena_per_port <port_id>",
10912         .tokens = {
10913                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10914                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10915                 NULL,
10916         },
10917 };
10918
10919 /* *** Set symmetric hash enable per port *** */
10920 struct cmd_set_sym_hash_ena_per_port_result {
10921         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10922         cmdline_fixed_string_t enable;
10923         portid_t port_id;
10924 };
10925
10926 static void
10927 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10928                                  __rte_unused struct cmdline *cl,
10929                                  __rte_unused void *data)
10930 {
10931         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10932         struct rte_eth_hash_filter_info info;
10933         int ret;
10934
10935         if (rte_eth_dev_filter_supported(res->port_id,
10936                                 RTE_ETH_FILTER_HASH) < 0) {
10937                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10938                                                         res->port_id);
10939                 return;
10940         }
10941
10942         memset(&info, 0, sizeof(info));
10943         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10944         if (!strcmp(res->enable, "enable"))
10945                 info.info.enable = 1;
10946         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10947                                         RTE_ETH_FILTER_SET, &info);
10948         if (ret < 0) {
10949                 printf("Cannot set symmetric hash enable per port on "
10950                                         "port %u\n", res->port_id);
10951                 return;
10952         }
10953         printf("Symmetric hash has been set to %s on port %u\n",
10954                                         res->enable, res->port_id);
10955 }
10956
10957 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10958         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10959                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10960 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10961         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10962                 port_id, UINT16);
10963 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10964         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10965                 enable, "enable#disable");
10966
10967 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10968         .f = cmd_set_sym_hash_per_port_parsed,
10969         .data = NULL,
10970         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10971         .tokens = {
10972                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10973                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10974                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10975                 NULL,
10976         },
10977 };
10978
10979 /* Get global config of hash function */
10980 struct cmd_get_hash_global_config_result {
10981         cmdline_fixed_string_t get_hash_global_config;
10982         portid_t port_id;
10983 };
10984
10985 static char *
10986 flowtype_to_str(uint16_t ftype)
10987 {
10988         uint16_t i;
10989         static struct {
10990                 char str[16];
10991                 uint16_t ftype;
10992         } ftype_table[] = {
10993                 {"ipv4", RTE_ETH_FLOW_IPV4},
10994                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10995                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10996                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10997                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10998                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10999                 {"ipv6", RTE_ETH_FLOW_IPV6},
11000                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11001                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11002                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11003                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11004                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11005                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11006                 {"port", RTE_ETH_FLOW_PORT},
11007                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11008                 {"geneve", RTE_ETH_FLOW_GENEVE},
11009                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11010         };
11011
11012         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11013                 if (ftype_table[i].ftype == ftype)
11014                         return ftype_table[i].str;
11015         }
11016
11017         return NULL;
11018 }
11019
11020 static void
11021 cmd_get_hash_global_config_parsed(void *parsed_result,
11022                                   __rte_unused struct cmdline *cl,
11023                                   __rte_unused void *data)
11024 {
11025         struct cmd_get_hash_global_config_result *res = parsed_result;
11026         struct rte_eth_hash_filter_info info;
11027         uint32_t idx, offset;
11028         uint16_t i;
11029         char *str;
11030         int ret;
11031
11032         if (rte_eth_dev_filter_supported(res->port_id,
11033                         RTE_ETH_FILTER_HASH) < 0) {
11034                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11035                                                         res->port_id);
11036                 return;
11037         }
11038
11039         memset(&info, 0, sizeof(info));
11040         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11041         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11042                                         RTE_ETH_FILTER_GET, &info);
11043         if (ret < 0) {
11044                 printf("Cannot get hash global configurations by port %d\n",
11045                                                         res->port_id);
11046                 return;
11047         }
11048
11049         switch (info.info.global_conf.hash_func) {
11050         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11051                 printf("Hash function is Toeplitz\n");
11052                 break;
11053         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11054                 printf("Hash function is Simple XOR\n");
11055                 break;
11056         default:
11057                 printf("Unknown hash function\n");
11058                 break;
11059         }
11060
11061         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11062                 idx = i / UINT32_BIT;
11063                 offset = i % UINT32_BIT;
11064                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11065                                                 (1UL << offset)))
11066                         continue;
11067                 str = flowtype_to_str(i);
11068                 if (!str)
11069                         continue;
11070                 printf("Symmetric hash is %s globally for flow type %s "
11071                                                         "by port %d\n",
11072                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11073                         (1UL << offset)) ? "enabled" : "disabled"), str,
11074                                                         res->port_id);
11075         }
11076 }
11077
11078 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11079         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11080                 get_hash_global_config, "get_hash_global_config");
11081 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11082         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11083                 port_id, UINT16);
11084
11085 cmdline_parse_inst_t cmd_get_hash_global_config = {
11086         .f = cmd_get_hash_global_config_parsed,
11087         .data = NULL,
11088         .help_str = "get_hash_global_config <port_id>",
11089         .tokens = {
11090                 (void *)&cmd_get_hash_global_config_all,
11091                 (void *)&cmd_get_hash_global_config_port_id,
11092                 NULL,
11093         },
11094 };
11095
11096 /* Set global config of hash function */
11097 struct cmd_set_hash_global_config_result {
11098         cmdline_fixed_string_t set_hash_global_config;
11099         portid_t port_id;
11100         cmdline_fixed_string_t hash_func;
11101         cmdline_fixed_string_t flow_type;
11102         cmdline_fixed_string_t enable;
11103 };
11104
11105 static void
11106 cmd_set_hash_global_config_parsed(void *parsed_result,
11107                                   __rte_unused struct cmdline *cl,
11108                                   __rte_unused void *data)
11109 {
11110         struct cmd_set_hash_global_config_result *res = parsed_result;
11111         struct rte_eth_hash_filter_info info;
11112         uint32_t ftype, idx, offset;
11113         int ret;
11114
11115         if (rte_eth_dev_filter_supported(res->port_id,
11116                                 RTE_ETH_FILTER_HASH) < 0) {
11117                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11118                                                         res->port_id);
11119                 return;
11120         }
11121         memset(&info, 0, sizeof(info));
11122         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11123         if (!strcmp(res->hash_func, "toeplitz"))
11124                 info.info.global_conf.hash_func =
11125                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11126         else if (!strcmp(res->hash_func, "simple_xor"))
11127                 info.info.global_conf.hash_func =
11128                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11129         else if (!strcmp(res->hash_func, "default"))
11130                 info.info.global_conf.hash_func =
11131                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11132
11133         ftype = str2flowtype(res->flow_type);
11134         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11135         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11136         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11137         if (!strcmp(res->enable, "enable"))
11138                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11139                                                 (1UL << offset);
11140         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11141                                         RTE_ETH_FILTER_SET, &info);
11142         if (ret < 0)
11143                 printf("Cannot set global hash configurations by port %d\n",
11144                                                         res->port_id);
11145         else
11146                 printf("Global hash configurations have been set "
11147                         "succcessfully by port %d\n", res->port_id);
11148 }
11149
11150 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11151         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11152                 set_hash_global_config, "set_hash_global_config");
11153 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11154         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11155                 port_id, UINT16);
11156 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11157         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11158                 hash_func, "toeplitz#simple_xor#default");
11159 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11160         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11161                 flow_type,
11162                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11163                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11164 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11165         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11166                 enable, "enable#disable");
11167
11168 cmdline_parse_inst_t cmd_set_hash_global_config = {
11169         .f = cmd_set_hash_global_config_parsed,
11170         .data = NULL,
11171         .help_str = "set_hash_global_config <port_id> "
11172                 "toeplitz|simple_xor|default "
11173                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11174                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11175                 "l2_payload enable|disable",
11176         .tokens = {
11177                 (void *)&cmd_set_hash_global_config_all,
11178                 (void *)&cmd_set_hash_global_config_port_id,
11179                 (void *)&cmd_set_hash_global_config_hash_func,
11180                 (void *)&cmd_set_hash_global_config_flow_type,
11181                 (void *)&cmd_set_hash_global_config_enable,
11182                 NULL,
11183         },
11184 };
11185
11186 /* Set hash input set */
11187 struct cmd_set_hash_input_set_result {
11188         cmdline_fixed_string_t set_hash_input_set;
11189         portid_t port_id;
11190         cmdline_fixed_string_t flow_type;
11191         cmdline_fixed_string_t inset_field;
11192         cmdline_fixed_string_t select;
11193 };
11194
11195 static enum rte_eth_input_set_field
11196 str2inset(char *string)
11197 {
11198         uint16_t i;
11199
11200         static const struct {
11201                 char str[32];
11202                 enum rte_eth_input_set_field inset;
11203         } inset_table[] = {
11204                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11205                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11206                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11207                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11208                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11209                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11210                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11211                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11212                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11213                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11214                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11215                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11216                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11217                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11218                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11219                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11220                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11221                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11222                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11223                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11224                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11225                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11226                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11227                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11228                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11229                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11230                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11231                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11232                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11233                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11234                 {"none", RTE_ETH_INPUT_SET_NONE},
11235         };
11236
11237         for (i = 0; i < RTE_DIM(inset_table); i++) {
11238                 if (!strcmp(string, inset_table[i].str))
11239                         return inset_table[i].inset;
11240         }
11241
11242         return RTE_ETH_INPUT_SET_UNKNOWN;
11243 }
11244
11245 static void
11246 cmd_set_hash_input_set_parsed(void *parsed_result,
11247                               __rte_unused struct cmdline *cl,
11248                               __rte_unused void *data)
11249 {
11250         struct cmd_set_hash_input_set_result *res = parsed_result;
11251         struct rte_eth_hash_filter_info info;
11252
11253         memset(&info, 0, sizeof(info));
11254         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11255         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11256         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11257         info.info.input_set_conf.inset_size = 1;
11258         if (!strcmp(res->select, "select"))
11259                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11260         else if (!strcmp(res->select, "add"))
11261                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11262         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11263                                 RTE_ETH_FILTER_SET, &info);
11264 }
11265
11266 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11267         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11268                 set_hash_input_set, "set_hash_input_set");
11269 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11270         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11271                 port_id, UINT16);
11272 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11273         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11274                 flow_type, NULL);
11275 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11276         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11277                 inset_field,
11278                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11279                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11280                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11281                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11282                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11283                 "fld-8th#none");
11284 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11285         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11286                 select, "select#add");
11287
11288 cmdline_parse_inst_t cmd_set_hash_input_set = {
11289         .f = cmd_set_hash_input_set_parsed,
11290         .data = NULL,
11291         .help_str = "set_hash_input_set <port_id> "
11292         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11293         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11294         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11295         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11296         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11297         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11298         "fld-7th|fld-8th|none select|add",
11299         .tokens = {
11300                 (void *)&cmd_set_hash_input_set_cmd,
11301                 (void *)&cmd_set_hash_input_set_port_id,
11302                 (void *)&cmd_set_hash_input_set_flow_type,
11303                 (void *)&cmd_set_hash_input_set_field,
11304                 (void *)&cmd_set_hash_input_set_select,
11305                 NULL,
11306         },
11307 };
11308
11309 /* Set flow director input set */
11310 struct cmd_set_fdir_input_set_result {
11311         cmdline_fixed_string_t set_fdir_input_set;
11312         portid_t port_id;
11313         cmdline_fixed_string_t flow_type;
11314         cmdline_fixed_string_t inset_field;
11315         cmdline_fixed_string_t select;
11316 };
11317
11318 static void
11319 cmd_set_fdir_input_set_parsed(void *parsed_result,
11320         __rte_unused struct cmdline *cl,
11321         __rte_unused void *data)
11322 {
11323         struct cmd_set_fdir_input_set_result *res = parsed_result;
11324         struct rte_eth_fdir_filter_info info;
11325
11326         memset(&info, 0, sizeof(info));
11327         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11328         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11329         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11330         info.info.input_set_conf.inset_size = 1;
11331         if (!strcmp(res->select, "select"))
11332                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11333         else if (!strcmp(res->select, "add"))
11334                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11335         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11336                 RTE_ETH_FILTER_SET, &info);
11337 }
11338
11339 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11340         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11341         set_fdir_input_set, "set_fdir_input_set");
11342 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11343         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11344         port_id, UINT16);
11345 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11346         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11347         flow_type,
11348         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11349         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11350 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11351         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11352         inset_field,
11353         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11354         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11355         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11356         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11357         "sctp-veri-tag#none");
11358 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11359         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11360         select, "select#add");
11361
11362 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11363         .f = cmd_set_fdir_input_set_parsed,
11364         .data = NULL,
11365         .help_str = "set_fdir_input_set <port_id> "
11366         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11367         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11368         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11369         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11370         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11371         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11372         "sctp-veri-tag|none select|add",
11373         .tokens = {
11374                 (void *)&cmd_set_fdir_input_set_cmd,
11375                 (void *)&cmd_set_fdir_input_set_port_id,
11376                 (void *)&cmd_set_fdir_input_set_flow_type,
11377                 (void *)&cmd_set_fdir_input_set_field,
11378                 (void *)&cmd_set_fdir_input_set_select,
11379                 NULL,
11380         },
11381 };
11382
11383 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11384 struct cmd_mcast_addr_result {
11385         cmdline_fixed_string_t mcast_addr_cmd;
11386         cmdline_fixed_string_t what;
11387         uint16_t port_num;
11388         struct ether_addr mc_addr;
11389 };
11390
11391 static void cmd_mcast_addr_parsed(void *parsed_result,
11392                 __attribute__((unused)) struct cmdline *cl,
11393                 __attribute__((unused)) void *data)
11394 {
11395         struct cmd_mcast_addr_result *res = parsed_result;
11396
11397         if (!is_multicast_ether_addr(&res->mc_addr)) {
11398                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11399                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11400                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11401                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11402                 return;
11403         }
11404         if (strcmp(res->what, "add") == 0)
11405                 mcast_addr_add(res->port_num, &res->mc_addr);
11406         else
11407                 mcast_addr_remove(res->port_num, &res->mc_addr);
11408 }
11409
11410 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11411         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11412                                  mcast_addr_cmd, "mcast_addr");
11413 cmdline_parse_token_string_t cmd_mcast_addr_what =
11414         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11415                                  "add#remove");
11416 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11417         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11418 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11419         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11420
11421 cmdline_parse_inst_t cmd_mcast_addr = {
11422         .f = cmd_mcast_addr_parsed,
11423         .data = (void *)0,
11424         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11425                 "Add/Remove multicast MAC address on port_id",
11426         .tokens = {
11427                 (void *)&cmd_mcast_addr_cmd,
11428                 (void *)&cmd_mcast_addr_what,
11429                 (void *)&cmd_mcast_addr_portnum,
11430                 (void *)&cmd_mcast_addr_addr,
11431                 NULL,
11432         },
11433 };
11434
11435 /* l2 tunnel config
11436  * only support E-tag now.
11437  */
11438
11439 /* Ether type config */
11440 struct cmd_config_l2_tunnel_eth_type_result {
11441         cmdline_fixed_string_t port;
11442         cmdline_fixed_string_t config;
11443         cmdline_fixed_string_t all;
11444         uint8_t id;
11445         cmdline_fixed_string_t l2_tunnel;
11446         cmdline_fixed_string_t l2_tunnel_type;
11447         cmdline_fixed_string_t eth_type;
11448         uint16_t eth_type_val;
11449 };
11450
11451 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11452         TOKEN_STRING_INITIALIZER
11453                 (struct cmd_config_l2_tunnel_eth_type_result,
11454                  port, "port");
11455 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11456         TOKEN_STRING_INITIALIZER
11457                 (struct cmd_config_l2_tunnel_eth_type_result,
11458                  config, "config");
11459 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11460         TOKEN_STRING_INITIALIZER
11461                 (struct cmd_config_l2_tunnel_eth_type_result,
11462                  all, "all");
11463 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11464         TOKEN_NUM_INITIALIZER
11465                 (struct cmd_config_l2_tunnel_eth_type_result,
11466                  id, UINT8);
11467 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11468         TOKEN_STRING_INITIALIZER
11469                 (struct cmd_config_l2_tunnel_eth_type_result,
11470                  l2_tunnel, "l2-tunnel");
11471 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11472         TOKEN_STRING_INITIALIZER
11473                 (struct cmd_config_l2_tunnel_eth_type_result,
11474                  l2_tunnel_type, "E-tag");
11475 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11476         TOKEN_STRING_INITIALIZER
11477                 (struct cmd_config_l2_tunnel_eth_type_result,
11478                  eth_type, "ether-type");
11479 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11480         TOKEN_NUM_INITIALIZER
11481                 (struct cmd_config_l2_tunnel_eth_type_result,
11482                  eth_type_val, UINT16);
11483
11484 static enum rte_eth_tunnel_type
11485 str2fdir_l2_tunnel_type(char *string)
11486 {
11487         uint32_t i = 0;
11488
11489         static const struct {
11490                 char str[32];
11491                 enum rte_eth_tunnel_type type;
11492         } l2_tunnel_type_str[] = {
11493                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11494         };
11495
11496         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11497                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11498                         return l2_tunnel_type_str[i].type;
11499         }
11500         return RTE_TUNNEL_TYPE_NONE;
11501 }
11502
11503 /* ether type config for all ports */
11504 static void
11505 cmd_config_l2_tunnel_eth_type_all_parsed
11506         (void *parsed_result,
11507          __attribute__((unused)) struct cmdline *cl,
11508          __attribute__((unused)) void *data)
11509 {
11510         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11511         struct rte_eth_l2_tunnel_conf entry;
11512         portid_t pid;
11513
11514         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11515         entry.ether_type = res->eth_type_val;
11516
11517         RTE_ETH_FOREACH_DEV(pid) {
11518                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11519         }
11520 }
11521
11522 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11523         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11524         .data = NULL,
11525         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11526         .tokens = {
11527                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11528                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11529                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11530                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11531                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11532                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11533                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11534                 NULL,
11535         },
11536 };
11537
11538 /* ether type config for a specific port */
11539 static void
11540 cmd_config_l2_tunnel_eth_type_specific_parsed(
11541         void *parsed_result,
11542         __attribute__((unused)) struct cmdline *cl,
11543         __attribute__((unused)) void *data)
11544 {
11545         struct cmd_config_l2_tunnel_eth_type_result *res =
11546                  parsed_result;
11547         struct rte_eth_l2_tunnel_conf entry;
11548
11549         if (port_id_is_invalid(res->id, ENABLED_WARN))
11550                 return;
11551
11552         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11553         entry.ether_type = res->eth_type_val;
11554
11555         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11556 }
11557
11558 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11559         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11560         .data = NULL,
11561         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11562         .tokens = {
11563                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11564                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11565                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11566                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11567                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11568                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11569                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11570                 NULL,
11571         },
11572 };
11573
11574 /* Enable/disable l2 tunnel */
11575 struct cmd_config_l2_tunnel_en_dis_result {
11576         cmdline_fixed_string_t port;
11577         cmdline_fixed_string_t config;
11578         cmdline_fixed_string_t all;
11579         uint8_t id;
11580         cmdline_fixed_string_t l2_tunnel;
11581         cmdline_fixed_string_t l2_tunnel_type;
11582         cmdline_fixed_string_t en_dis;
11583 };
11584
11585 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11586         TOKEN_STRING_INITIALIZER
11587                 (struct cmd_config_l2_tunnel_en_dis_result,
11588                  port, "port");
11589 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11590         TOKEN_STRING_INITIALIZER
11591                 (struct cmd_config_l2_tunnel_en_dis_result,
11592                  config, "config");
11593 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11594         TOKEN_STRING_INITIALIZER
11595                 (struct cmd_config_l2_tunnel_en_dis_result,
11596                  all, "all");
11597 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11598         TOKEN_NUM_INITIALIZER
11599                 (struct cmd_config_l2_tunnel_en_dis_result,
11600                  id, UINT8);
11601 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11602         TOKEN_STRING_INITIALIZER
11603                 (struct cmd_config_l2_tunnel_en_dis_result,
11604                  l2_tunnel, "l2-tunnel");
11605 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11606         TOKEN_STRING_INITIALIZER
11607                 (struct cmd_config_l2_tunnel_en_dis_result,
11608                  l2_tunnel_type, "E-tag");
11609 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11610         TOKEN_STRING_INITIALIZER
11611                 (struct cmd_config_l2_tunnel_en_dis_result,
11612                  en_dis, "enable#disable");
11613
11614 /* enable/disable l2 tunnel for all ports */
11615 static void
11616 cmd_config_l2_tunnel_en_dis_all_parsed(
11617         void *parsed_result,
11618         __attribute__((unused)) struct cmdline *cl,
11619         __attribute__((unused)) void *data)
11620 {
11621         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11622         struct rte_eth_l2_tunnel_conf entry;
11623         portid_t pid;
11624         uint8_t en;
11625
11626         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11627
11628         if (!strcmp("enable", res->en_dis))
11629                 en = 1;
11630         else
11631                 en = 0;
11632
11633         RTE_ETH_FOREACH_DEV(pid) {
11634                 rte_eth_dev_l2_tunnel_offload_set(pid,
11635                                                   &entry,
11636                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11637                                                   en);
11638         }
11639 }
11640
11641 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11642         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11643         .data = NULL,
11644         .help_str = "port config all l2-tunnel E-tag enable|disable",
11645         .tokens = {
11646                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11647                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11648                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11649                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11650                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11651                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11652                 NULL,
11653         },
11654 };
11655
11656 /* enable/disable l2 tunnel for a port */
11657 static void
11658 cmd_config_l2_tunnel_en_dis_specific_parsed(
11659         void *parsed_result,
11660         __attribute__((unused)) struct cmdline *cl,
11661         __attribute__((unused)) void *data)
11662 {
11663         struct cmd_config_l2_tunnel_en_dis_result *res =
11664                 parsed_result;
11665         struct rte_eth_l2_tunnel_conf entry;
11666
11667         if (port_id_is_invalid(res->id, ENABLED_WARN))
11668                 return;
11669
11670         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11671
11672         if (!strcmp("enable", res->en_dis))
11673                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11674                                                   &entry,
11675                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11676                                                   1);
11677         else
11678                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11679                                                   &entry,
11680                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11681                                                   0);
11682 }
11683
11684 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11685         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11686         .data = NULL,
11687         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11688         .tokens = {
11689                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11690                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11691                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11692                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11693                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11694                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11695                 NULL,
11696         },
11697 };
11698
11699 /* E-tag configuration */
11700
11701 /* Common result structure for all E-tag configuration */
11702 struct cmd_config_e_tag_result {
11703         cmdline_fixed_string_t e_tag;
11704         cmdline_fixed_string_t set;
11705         cmdline_fixed_string_t insertion;
11706         cmdline_fixed_string_t stripping;
11707         cmdline_fixed_string_t forwarding;
11708         cmdline_fixed_string_t filter;
11709         cmdline_fixed_string_t add;
11710         cmdline_fixed_string_t del;
11711         cmdline_fixed_string_t on;
11712         cmdline_fixed_string_t off;
11713         cmdline_fixed_string_t on_off;
11714         cmdline_fixed_string_t port_tag_id;
11715         uint32_t port_tag_id_val;
11716         cmdline_fixed_string_t e_tag_id;
11717         uint16_t e_tag_id_val;
11718         cmdline_fixed_string_t dst_pool;
11719         uint8_t dst_pool_val;
11720         cmdline_fixed_string_t port;
11721         portid_t port_id;
11722         cmdline_fixed_string_t vf;
11723         uint8_t vf_id;
11724 };
11725
11726 /* Common CLI fields for all E-tag configuration */
11727 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11728         TOKEN_STRING_INITIALIZER
11729                 (struct cmd_config_e_tag_result,
11730                  e_tag, "E-tag");
11731 cmdline_parse_token_string_t cmd_config_e_tag_set =
11732         TOKEN_STRING_INITIALIZER
11733                 (struct cmd_config_e_tag_result,
11734                  set, "set");
11735 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11736         TOKEN_STRING_INITIALIZER
11737                 (struct cmd_config_e_tag_result,
11738                  insertion, "insertion");
11739 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11740         TOKEN_STRING_INITIALIZER
11741                 (struct cmd_config_e_tag_result,
11742                  stripping, "stripping");
11743 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11744         TOKEN_STRING_INITIALIZER
11745                 (struct cmd_config_e_tag_result,
11746                  forwarding, "forwarding");
11747 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11748         TOKEN_STRING_INITIALIZER
11749                 (struct cmd_config_e_tag_result,
11750                  filter, "filter");
11751 cmdline_parse_token_string_t cmd_config_e_tag_add =
11752         TOKEN_STRING_INITIALIZER
11753                 (struct cmd_config_e_tag_result,
11754                  add, "add");
11755 cmdline_parse_token_string_t cmd_config_e_tag_del =
11756         TOKEN_STRING_INITIALIZER
11757                 (struct cmd_config_e_tag_result,
11758                  del, "del");
11759 cmdline_parse_token_string_t cmd_config_e_tag_on =
11760         TOKEN_STRING_INITIALIZER
11761                 (struct cmd_config_e_tag_result,
11762                  on, "on");
11763 cmdline_parse_token_string_t cmd_config_e_tag_off =
11764         TOKEN_STRING_INITIALIZER
11765                 (struct cmd_config_e_tag_result,
11766                  off, "off");
11767 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11768         TOKEN_STRING_INITIALIZER
11769                 (struct cmd_config_e_tag_result,
11770                  on_off, "on#off");
11771 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11772         TOKEN_STRING_INITIALIZER
11773                 (struct cmd_config_e_tag_result,
11774                  port_tag_id, "port-tag-id");
11775 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11776         TOKEN_NUM_INITIALIZER
11777                 (struct cmd_config_e_tag_result,
11778                  port_tag_id_val, UINT32);
11779 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11780         TOKEN_STRING_INITIALIZER
11781                 (struct cmd_config_e_tag_result,
11782                  e_tag_id, "e-tag-id");
11783 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11784         TOKEN_NUM_INITIALIZER
11785                 (struct cmd_config_e_tag_result,
11786                  e_tag_id_val, UINT16);
11787 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11788         TOKEN_STRING_INITIALIZER
11789                 (struct cmd_config_e_tag_result,
11790                  dst_pool, "dst-pool");
11791 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11792         TOKEN_NUM_INITIALIZER
11793                 (struct cmd_config_e_tag_result,
11794                  dst_pool_val, UINT8);
11795 cmdline_parse_token_string_t cmd_config_e_tag_port =
11796         TOKEN_STRING_INITIALIZER
11797                 (struct cmd_config_e_tag_result,
11798                  port, "port");
11799 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11800         TOKEN_NUM_INITIALIZER
11801                 (struct cmd_config_e_tag_result,
11802                  port_id, UINT16);
11803 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11804         TOKEN_STRING_INITIALIZER
11805                 (struct cmd_config_e_tag_result,
11806                  vf, "vf");
11807 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11808         TOKEN_NUM_INITIALIZER
11809                 (struct cmd_config_e_tag_result,
11810                  vf_id, UINT8);
11811
11812 /* E-tag insertion configuration */
11813 static void
11814 cmd_config_e_tag_insertion_en_parsed(
11815         void *parsed_result,
11816         __attribute__((unused)) struct cmdline *cl,
11817         __attribute__((unused)) void *data)
11818 {
11819         struct cmd_config_e_tag_result *res =
11820                 parsed_result;
11821         struct rte_eth_l2_tunnel_conf entry;
11822
11823         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11824                 return;
11825
11826         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11827         entry.tunnel_id = res->port_tag_id_val;
11828         entry.vf_id = res->vf_id;
11829         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11830                                           &entry,
11831                                           ETH_L2_TUNNEL_INSERTION_MASK,
11832                                           1);
11833 }
11834
11835 static void
11836 cmd_config_e_tag_insertion_dis_parsed(
11837         void *parsed_result,
11838         __attribute__((unused)) struct cmdline *cl,
11839         __attribute__((unused)) void *data)
11840 {
11841         struct cmd_config_e_tag_result *res =
11842                 parsed_result;
11843         struct rte_eth_l2_tunnel_conf entry;
11844
11845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11846                 return;
11847
11848         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11849         entry.vf_id = res->vf_id;
11850
11851         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11852                                           &entry,
11853                                           ETH_L2_TUNNEL_INSERTION_MASK,
11854                                           0);
11855 }
11856
11857 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11858         .f = cmd_config_e_tag_insertion_en_parsed,
11859         .data = NULL,
11860         .help_str = "E-tag ... : E-tag insertion enable",
11861         .tokens = {
11862                 (void *)&cmd_config_e_tag_e_tag,
11863                 (void *)&cmd_config_e_tag_set,
11864                 (void *)&cmd_config_e_tag_insertion,
11865                 (void *)&cmd_config_e_tag_on,
11866                 (void *)&cmd_config_e_tag_port_tag_id,
11867                 (void *)&cmd_config_e_tag_port_tag_id_val,
11868                 (void *)&cmd_config_e_tag_port,
11869                 (void *)&cmd_config_e_tag_port_id,
11870                 (void *)&cmd_config_e_tag_vf,
11871                 (void *)&cmd_config_e_tag_vf_id,
11872                 NULL,
11873         },
11874 };
11875
11876 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11877         .f = cmd_config_e_tag_insertion_dis_parsed,
11878         .data = NULL,
11879         .help_str = "E-tag ... : E-tag insertion disable",
11880         .tokens = {
11881                 (void *)&cmd_config_e_tag_e_tag,
11882                 (void *)&cmd_config_e_tag_set,
11883                 (void *)&cmd_config_e_tag_insertion,
11884                 (void *)&cmd_config_e_tag_off,
11885                 (void *)&cmd_config_e_tag_port,
11886                 (void *)&cmd_config_e_tag_port_id,
11887                 (void *)&cmd_config_e_tag_vf,
11888                 (void *)&cmd_config_e_tag_vf_id,
11889                 NULL,
11890         },
11891 };
11892
11893 /* E-tag stripping configuration */
11894 static void
11895 cmd_config_e_tag_stripping_parsed(
11896         void *parsed_result,
11897         __attribute__((unused)) struct cmdline *cl,
11898         __attribute__((unused)) void *data)
11899 {
11900         struct cmd_config_e_tag_result *res =
11901                 parsed_result;
11902         struct rte_eth_l2_tunnel_conf entry;
11903
11904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11905                 return;
11906
11907         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11908
11909         if (!strcmp(res->on_off, "on"))
11910                 rte_eth_dev_l2_tunnel_offload_set
11911                         (res->port_id,
11912                          &entry,
11913                          ETH_L2_TUNNEL_STRIPPING_MASK,
11914                          1);
11915         else
11916                 rte_eth_dev_l2_tunnel_offload_set
11917                         (res->port_id,
11918                          &entry,
11919                          ETH_L2_TUNNEL_STRIPPING_MASK,
11920                          0);
11921 }
11922
11923 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11924         .f = cmd_config_e_tag_stripping_parsed,
11925         .data = NULL,
11926         .help_str = "E-tag ... : E-tag stripping enable/disable",
11927         .tokens = {
11928                 (void *)&cmd_config_e_tag_e_tag,
11929                 (void *)&cmd_config_e_tag_set,
11930                 (void *)&cmd_config_e_tag_stripping,
11931                 (void *)&cmd_config_e_tag_on_off,
11932                 (void *)&cmd_config_e_tag_port,
11933                 (void *)&cmd_config_e_tag_port_id,
11934                 NULL,
11935         },
11936 };
11937
11938 /* E-tag forwarding configuration */
11939 static void
11940 cmd_config_e_tag_forwarding_parsed(
11941         void *parsed_result,
11942         __attribute__((unused)) struct cmdline *cl,
11943         __attribute__((unused)) void *data)
11944 {
11945         struct cmd_config_e_tag_result *res = parsed_result;
11946         struct rte_eth_l2_tunnel_conf entry;
11947
11948         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11949                 return;
11950
11951         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11952
11953         if (!strcmp(res->on_off, "on"))
11954                 rte_eth_dev_l2_tunnel_offload_set
11955                         (res->port_id,
11956                          &entry,
11957                          ETH_L2_TUNNEL_FORWARDING_MASK,
11958                          1);
11959         else
11960                 rte_eth_dev_l2_tunnel_offload_set
11961                         (res->port_id,
11962                          &entry,
11963                          ETH_L2_TUNNEL_FORWARDING_MASK,
11964                          0);
11965 }
11966
11967 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11968         .f = cmd_config_e_tag_forwarding_parsed,
11969         .data = NULL,
11970         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11971         .tokens = {
11972                 (void *)&cmd_config_e_tag_e_tag,
11973                 (void *)&cmd_config_e_tag_set,
11974                 (void *)&cmd_config_e_tag_forwarding,
11975                 (void *)&cmd_config_e_tag_on_off,
11976                 (void *)&cmd_config_e_tag_port,
11977                 (void *)&cmd_config_e_tag_port_id,
11978                 NULL,
11979         },
11980 };
11981
11982 /* E-tag filter configuration */
11983 static void
11984 cmd_config_e_tag_filter_add_parsed(
11985         void *parsed_result,
11986         __attribute__((unused)) struct cmdline *cl,
11987         __attribute__((unused)) void *data)
11988 {
11989         struct cmd_config_e_tag_result *res = parsed_result;
11990         struct rte_eth_l2_tunnel_conf entry;
11991         int ret = 0;
11992
11993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11994                 return;
11995
11996         if (res->e_tag_id_val > 0x3fff) {
11997                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11998                 return;
11999         }
12000
12001         ret = rte_eth_dev_filter_supported(res->port_id,
12002                                            RTE_ETH_FILTER_L2_TUNNEL);
12003         if (ret < 0) {
12004                 printf("E-tag filter is not supported on port %u.\n",
12005                        res->port_id);
12006                 return;
12007         }
12008
12009         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12010         entry.tunnel_id = res->e_tag_id_val;
12011         entry.pool = res->dst_pool_val;
12012
12013         ret = rte_eth_dev_filter_ctrl(res->port_id,
12014                                       RTE_ETH_FILTER_L2_TUNNEL,
12015                                       RTE_ETH_FILTER_ADD,
12016                                       &entry);
12017         if (ret < 0)
12018                 printf("E-tag filter programming error: (%s)\n",
12019                        strerror(-ret));
12020 }
12021
12022 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12023         .f = cmd_config_e_tag_filter_add_parsed,
12024         .data = NULL,
12025         .help_str = "E-tag ... : E-tag filter add",
12026         .tokens = {
12027                 (void *)&cmd_config_e_tag_e_tag,
12028                 (void *)&cmd_config_e_tag_set,
12029                 (void *)&cmd_config_e_tag_filter,
12030                 (void *)&cmd_config_e_tag_add,
12031                 (void *)&cmd_config_e_tag_e_tag_id,
12032                 (void *)&cmd_config_e_tag_e_tag_id_val,
12033                 (void *)&cmd_config_e_tag_dst_pool,
12034                 (void *)&cmd_config_e_tag_dst_pool_val,
12035                 (void *)&cmd_config_e_tag_port,
12036                 (void *)&cmd_config_e_tag_port_id,
12037                 NULL,
12038         },
12039 };
12040
12041 static void
12042 cmd_config_e_tag_filter_del_parsed(
12043         void *parsed_result,
12044         __attribute__((unused)) struct cmdline *cl,
12045         __attribute__((unused)) void *data)
12046 {
12047         struct cmd_config_e_tag_result *res = parsed_result;
12048         struct rte_eth_l2_tunnel_conf entry;
12049         int ret = 0;
12050
12051         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12052                 return;
12053
12054         if (res->e_tag_id_val > 0x3fff) {
12055                 printf("e-tag-id must be less than 0x3fff.\n");
12056                 return;
12057         }
12058
12059         ret = rte_eth_dev_filter_supported(res->port_id,
12060                                            RTE_ETH_FILTER_L2_TUNNEL);
12061         if (ret < 0) {
12062                 printf("E-tag filter is not supported on port %u.\n",
12063                        res->port_id);
12064                 return;
12065         }
12066
12067         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12068         entry.tunnel_id = res->e_tag_id_val;
12069
12070         ret = rte_eth_dev_filter_ctrl(res->port_id,
12071                                       RTE_ETH_FILTER_L2_TUNNEL,
12072                                       RTE_ETH_FILTER_DELETE,
12073                                       &entry);
12074         if (ret < 0)
12075                 printf("E-tag filter programming error: (%s)\n",
12076                        strerror(-ret));
12077 }
12078
12079 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12080         .f = cmd_config_e_tag_filter_del_parsed,
12081         .data = NULL,
12082         .help_str = "E-tag ... : E-tag filter delete",
12083         .tokens = {
12084                 (void *)&cmd_config_e_tag_e_tag,
12085                 (void *)&cmd_config_e_tag_set,
12086                 (void *)&cmd_config_e_tag_filter,
12087                 (void *)&cmd_config_e_tag_del,
12088                 (void *)&cmd_config_e_tag_e_tag_id,
12089                 (void *)&cmd_config_e_tag_e_tag_id_val,
12090                 (void *)&cmd_config_e_tag_port,
12091                 (void *)&cmd_config_e_tag_port_id,
12092                 NULL,
12093         },
12094 };
12095
12096 /* vf vlan anti spoof configuration */
12097
12098 /* Common result structure for vf vlan anti spoof */
12099 struct cmd_vf_vlan_anti_spoof_result {
12100         cmdline_fixed_string_t set;
12101         cmdline_fixed_string_t vf;
12102         cmdline_fixed_string_t vlan;
12103         cmdline_fixed_string_t antispoof;
12104         portid_t port_id;
12105         uint32_t vf_id;
12106         cmdline_fixed_string_t on_off;
12107 };
12108
12109 /* Common CLI fields for vf vlan anti spoof enable disable */
12110 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12111         TOKEN_STRING_INITIALIZER
12112                 (struct cmd_vf_vlan_anti_spoof_result,
12113                  set, "set");
12114 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12115         TOKEN_STRING_INITIALIZER
12116                 (struct cmd_vf_vlan_anti_spoof_result,
12117                  vf, "vf");
12118 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12119         TOKEN_STRING_INITIALIZER
12120                 (struct cmd_vf_vlan_anti_spoof_result,
12121                  vlan, "vlan");
12122 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12123         TOKEN_STRING_INITIALIZER
12124                 (struct cmd_vf_vlan_anti_spoof_result,
12125                  antispoof, "antispoof");
12126 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12127         TOKEN_NUM_INITIALIZER
12128                 (struct cmd_vf_vlan_anti_spoof_result,
12129                  port_id, UINT16);
12130 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12131         TOKEN_NUM_INITIALIZER
12132                 (struct cmd_vf_vlan_anti_spoof_result,
12133                  vf_id, UINT32);
12134 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12135         TOKEN_STRING_INITIALIZER
12136                 (struct cmd_vf_vlan_anti_spoof_result,
12137                  on_off, "on#off");
12138
12139 static void
12140 cmd_set_vf_vlan_anti_spoof_parsed(
12141         void *parsed_result,
12142         __attribute__((unused)) struct cmdline *cl,
12143         __attribute__((unused)) void *data)
12144 {
12145         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12146         int ret = -ENOTSUP;
12147
12148         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12149
12150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12151                 return;
12152
12153 #ifdef RTE_LIBRTE_IXGBE_PMD
12154         if (ret == -ENOTSUP)
12155                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12156                                 res->vf_id, is_on);
12157 #endif
12158 #ifdef RTE_LIBRTE_I40E_PMD
12159         if (ret == -ENOTSUP)
12160                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12161                                 res->vf_id, is_on);
12162 #endif
12163 #ifdef RTE_LIBRTE_BNXT_PMD
12164         if (ret == -ENOTSUP)
12165                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12166                                 res->vf_id, is_on);
12167 #endif
12168
12169         switch (ret) {
12170         case 0:
12171                 break;
12172         case -EINVAL:
12173                 printf("invalid vf_id %d\n", res->vf_id);
12174                 break;
12175         case -ENODEV:
12176                 printf("invalid port_id %d\n", res->port_id);
12177                 break;
12178         case -ENOTSUP:
12179                 printf("function not implemented\n");
12180                 break;
12181         default:
12182                 printf("programming error: (%s)\n", strerror(-ret));
12183         }
12184 }
12185
12186 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12187         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12188         .data = NULL,
12189         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12190         .tokens = {
12191                 (void *)&cmd_vf_vlan_anti_spoof_set,
12192                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12193                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12194                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12195                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12196                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12197                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12198                 NULL,
12199         },
12200 };
12201
12202 /* vf mac anti spoof configuration */
12203
12204 /* Common result structure for vf mac anti spoof */
12205 struct cmd_vf_mac_anti_spoof_result {
12206         cmdline_fixed_string_t set;
12207         cmdline_fixed_string_t vf;
12208         cmdline_fixed_string_t mac;
12209         cmdline_fixed_string_t antispoof;
12210         portid_t port_id;
12211         uint32_t vf_id;
12212         cmdline_fixed_string_t on_off;
12213 };
12214
12215 /* Common CLI fields for vf mac anti spoof enable disable */
12216 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12217         TOKEN_STRING_INITIALIZER
12218                 (struct cmd_vf_mac_anti_spoof_result,
12219                  set, "set");
12220 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12221         TOKEN_STRING_INITIALIZER
12222                 (struct cmd_vf_mac_anti_spoof_result,
12223                  vf, "vf");
12224 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12225         TOKEN_STRING_INITIALIZER
12226                 (struct cmd_vf_mac_anti_spoof_result,
12227                  mac, "mac");
12228 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12229         TOKEN_STRING_INITIALIZER
12230                 (struct cmd_vf_mac_anti_spoof_result,
12231                  antispoof, "antispoof");
12232 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12233         TOKEN_NUM_INITIALIZER
12234                 (struct cmd_vf_mac_anti_spoof_result,
12235                  port_id, UINT16);
12236 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12237         TOKEN_NUM_INITIALIZER
12238                 (struct cmd_vf_mac_anti_spoof_result,
12239                  vf_id, UINT32);
12240 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12241         TOKEN_STRING_INITIALIZER
12242                 (struct cmd_vf_mac_anti_spoof_result,
12243                  on_off, "on#off");
12244
12245 static void
12246 cmd_set_vf_mac_anti_spoof_parsed(
12247         void *parsed_result,
12248         __attribute__((unused)) struct cmdline *cl,
12249         __attribute__((unused)) void *data)
12250 {
12251         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12252         int ret = -ENOTSUP;
12253
12254         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12255
12256         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12257                 return;
12258
12259 #ifdef RTE_LIBRTE_IXGBE_PMD
12260         if (ret == -ENOTSUP)
12261                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12262                         res->vf_id, is_on);
12263 #endif
12264 #ifdef RTE_LIBRTE_I40E_PMD
12265         if (ret == -ENOTSUP)
12266                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12267                         res->vf_id, is_on);
12268 #endif
12269 #ifdef RTE_LIBRTE_BNXT_PMD
12270         if (ret == -ENOTSUP)
12271                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12272                         res->vf_id, is_on);
12273 #endif
12274
12275         switch (ret) {
12276         case 0:
12277                 break;
12278         case -EINVAL:
12279                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12280                 break;
12281         case -ENODEV:
12282                 printf("invalid port_id %d\n", res->port_id);
12283                 break;
12284         case -ENOTSUP:
12285                 printf("function not implemented\n");
12286                 break;
12287         default:
12288                 printf("programming error: (%s)\n", strerror(-ret));
12289         }
12290 }
12291
12292 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12293         .f = cmd_set_vf_mac_anti_spoof_parsed,
12294         .data = NULL,
12295         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12296         .tokens = {
12297                 (void *)&cmd_vf_mac_anti_spoof_set,
12298                 (void *)&cmd_vf_mac_anti_spoof_vf,
12299                 (void *)&cmd_vf_mac_anti_spoof_mac,
12300                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12301                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12302                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12303                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12304                 NULL,
12305         },
12306 };
12307
12308 /* vf vlan strip queue configuration */
12309
12310 /* Common result structure for vf mac anti spoof */
12311 struct cmd_vf_vlan_stripq_result {
12312         cmdline_fixed_string_t set;
12313         cmdline_fixed_string_t vf;
12314         cmdline_fixed_string_t vlan;
12315         cmdline_fixed_string_t stripq;
12316         portid_t port_id;
12317         uint16_t vf_id;
12318         cmdline_fixed_string_t on_off;
12319 };
12320
12321 /* Common CLI fields for vf vlan strip enable disable */
12322 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12323         TOKEN_STRING_INITIALIZER
12324                 (struct cmd_vf_vlan_stripq_result,
12325                  set, "set");
12326 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12327         TOKEN_STRING_INITIALIZER
12328                 (struct cmd_vf_vlan_stripq_result,
12329                  vf, "vf");
12330 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12331         TOKEN_STRING_INITIALIZER
12332                 (struct cmd_vf_vlan_stripq_result,
12333                  vlan, "vlan");
12334 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12335         TOKEN_STRING_INITIALIZER
12336                 (struct cmd_vf_vlan_stripq_result,
12337                  stripq, "stripq");
12338 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12339         TOKEN_NUM_INITIALIZER
12340                 (struct cmd_vf_vlan_stripq_result,
12341                  port_id, UINT16);
12342 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12343         TOKEN_NUM_INITIALIZER
12344                 (struct cmd_vf_vlan_stripq_result,
12345                  vf_id, UINT16);
12346 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12347         TOKEN_STRING_INITIALIZER
12348                 (struct cmd_vf_vlan_stripq_result,
12349                  on_off, "on#off");
12350
12351 static void
12352 cmd_set_vf_vlan_stripq_parsed(
12353         void *parsed_result,
12354         __attribute__((unused)) struct cmdline *cl,
12355         __attribute__((unused)) void *data)
12356 {
12357         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12358         int ret = -ENOTSUP;
12359
12360         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12361
12362         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12363                 return;
12364
12365 #ifdef RTE_LIBRTE_IXGBE_PMD
12366         if (ret == -ENOTSUP)
12367                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12368                         res->vf_id, is_on);
12369 #endif
12370 #ifdef RTE_LIBRTE_I40E_PMD
12371         if (ret == -ENOTSUP)
12372                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12373                         res->vf_id, is_on);
12374 #endif
12375 #ifdef RTE_LIBRTE_BNXT_PMD
12376         if (ret == -ENOTSUP)
12377                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12378                         res->vf_id, is_on);
12379 #endif
12380
12381         switch (ret) {
12382         case 0:
12383                 break;
12384         case -EINVAL:
12385                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12386                 break;
12387         case -ENODEV:
12388                 printf("invalid port_id %d\n", res->port_id);
12389                 break;
12390         case -ENOTSUP:
12391                 printf("function not implemented\n");
12392                 break;
12393         default:
12394                 printf("programming error: (%s)\n", strerror(-ret));
12395         }
12396 }
12397
12398 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12399         .f = cmd_set_vf_vlan_stripq_parsed,
12400         .data = NULL,
12401         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12402         .tokens = {
12403                 (void *)&cmd_vf_vlan_stripq_set,
12404                 (void *)&cmd_vf_vlan_stripq_vf,
12405                 (void *)&cmd_vf_vlan_stripq_vlan,
12406                 (void *)&cmd_vf_vlan_stripq_stripq,
12407                 (void *)&cmd_vf_vlan_stripq_port_id,
12408                 (void *)&cmd_vf_vlan_stripq_vf_id,
12409                 (void *)&cmd_vf_vlan_stripq_on_off,
12410                 NULL,
12411         },
12412 };
12413
12414 /* vf vlan insert configuration */
12415
12416 /* Common result structure for vf vlan insert */
12417 struct cmd_vf_vlan_insert_result {
12418         cmdline_fixed_string_t set;
12419         cmdline_fixed_string_t vf;
12420         cmdline_fixed_string_t vlan;
12421         cmdline_fixed_string_t insert;
12422         portid_t port_id;
12423         uint16_t vf_id;
12424         uint16_t vlan_id;
12425 };
12426
12427 /* Common CLI fields for vf vlan insert enable disable */
12428 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12429         TOKEN_STRING_INITIALIZER
12430                 (struct cmd_vf_vlan_insert_result,
12431                  set, "set");
12432 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12433         TOKEN_STRING_INITIALIZER
12434                 (struct cmd_vf_vlan_insert_result,
12435                  vf, "vf");
12436 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12437         TOKEN_STRING_INITIALIZER
12438                 (struct cmd_vf_vlan_insert_result,
12439                  vlan, "vlan");
12440 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12441         TOKEN_STRING_INITIALIZER
12442                 (struct cmd_vf_vlan_insert_result,
12443                  insert, "insert");
12444 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12445         TOKEN_NUM_INITIALIZER
12446                 (struct cmd_vf_vlan_insert_result,
12447                  port_id, UINT16);
12448 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12449         TOKEN_NUM_INITIALIZER
12450                 (struct cmd_vf_vlan_insert_result,
12451                  vf_id, UINT16);
12452 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12453         TOKEN_NUM_INITIALIZER
12454                 (struct cmd_vf_vlan_insert_result,
12455                  vlan_id, UINT16);
12456
12457 static void
12458 cmd_set_vf_vlan_insert_parsed(
12459         void *parsed_result,
12460         __attribute__((unused)) struct cmdline *cl,
12461         __attribute__((unused)) void *data)
12462 {
12463         struct cmd_vf_vlan_insert_result *res = parsed_result;
12464         int ret = -ENOTSUP;
12465
12466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12467                 return;
12468
12469 #ifdef RTE_LIBRTE_IXGBE_PMD
12470         if (ret == -ENOTSUP)
12471                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12472                         res->vlan_id);
12473 #endif
12474 #ifdef RTE_LIBRTE_I40E_PMD
12475         if (ret == -ENOTSUP)
12476                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12477                         res->vlan_id);
12478 #endif
12479 #ifdef RTE_LIBRTE_BNXT_PMD
12480         if (ret == -ENOTSUP)
12481                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12482                         res->vlan_id);
12483 #endif
12484
12485         switch (ret) {
12486         case 0:
12487                 break;
12488         case -EINVAL:
12489                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12490                 break;
12491         case -ENODEV:
12492                 printf("invalid port_id %d\n", res->port_id);
12493                 break;
12494         case -ENOTSUP:
12495                 printf("function not implemented\n");
12496                 break;
12497         default:
12498                 printf("programming error: (%s)\n", strerror(-ret));
12499         }
12500 }
12501
12502 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12503         .f = cmd_set_vf_vlan_insert_parsed,
12504         .data = NULL,
12505         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12506         .tokens = {
12507                 (void *)&cmd_vf_vlan_insert_set,
12508                 (void *)&cmd_vf_vlan_insert_vf,
12509                 (void *)&cmd_vf_vlan_insert_vlan,
12510                 (void *)&cmd_vf_vlan_insert_insert,
12511                 (void *)&cmd_vf_vlan_insert_port_id,
12512                 (void *)&cmd_vf_vlan_insert_vf_id,
12513                 (void *)&cmd_vf_vlan_insert_vlan_id,
12514                 NULL,
12515         },
12516 };
12517
12518 /* tx loopback configuration */
12519
12520 /* Common result structure for tx loopback */
12521 struct cmd_tx_loopback_result {
12522         cmdline_fixed_string_t set;
12523         cmdline_fixed_string_t tx;
12524         cmdline_fixed_string_t loopback;
12525         portid_t port_id;
12526         cmdline_fixed_string_t on_off;
12527 };
12528
12529 /* Common CLI fields for tx loopback enable disable */
12530 cmdline_parse_token_string_t cmd_tx_loopback_set =
12531         TOKEN_STRING_INITIALIZER
12532                 (struct cmd_tx_loopback_result,
12533                  set, "set");
12534 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12535         TOKEN_STRING_INITIALIZER
12536                 (struct cmd_tx_loopback_result,
12537                  tx, "tx");
12538 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12539         TOKEN_STRING_INITIALIZER
12540                 (struct cmd_tx_loopback_result,
12541                  loopback, "loopback");
12542 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12543         TOKEN_NUM_INITIALIZER
12544                 (struct cmd_tx_loopback_result,
12545                  port_id, UINT16);
12546 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12547         TOKEN_STRING_INITIALIZER
12548                 (struct cmd_tx_loopback_result,
12549                  on_off, "on#off");
12550
12551 static void
12552 cmd_set_tx_loopback_parsed(
12553         void *parsed_result,
12554         __attribute__((unused)) struct cmdline *cl,
12555         __attribute__((unused)) void *data)
12556 {
12557         struct cmd_tx_loopback_result *res = parsed_result;
12558         int ret = -ENOTSUP;
12559
12560         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12561
12562         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12563                 return;
12564
12565 #ifdef RTE_LIBRTE_IXGBE_PMD
12566         if (ret == -ENOTSUP)
12567                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12568 #endif
12569 #ifdef RTE_LIBRTE_I40E_PMD
12570         if (ret == -ENOTSUP)
12571                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12572 #endif
12573 #ifdef RTE_LIBRTE_BNXT_PMD
12574         if (ret == -ENOTSUP)
12575                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12576 #endif
12577
12578         switch (ret) {
12579         case 0:
12580                 break;
12581         case -EINVAL:
12582                 printf("invalid is_on %d\n", is_on);
12583                 break;
12584         case -ENODEV:
12585                 printf("invalid port_id %d\n", res->port_id);
12586                 break;
12587         case -ENOTSUP:
12588                 printf("function not implemented\n");
12589                 break;
12590         default:
12591                 printf("programming error: (%s)\n", strerror(-ret));
12592         }
12593 }
12594
12595 cmdline_parse_inst_t cmd_set_tx_loopback = {
12596         .f = cmd_set_tx_loopback_parsed,
12597         .data = NULL,
12598         .help_str = "set tx loopback <port_id> on|off",
12599         .tokens = {
12600                 (void *)&cmd_tx_loopback_set,
12601                 (void *)&cmd_tx_loopback_tx,
12602                 (void *)&cmd_tx_loopback_loopback,
12603                 (void *)&cmd_tx_loopback_port_id,
12604                 (void *)&cmd_tx_loopback_on_off,
12605                 NULL,
12606         },
12607 };
12608
12609 /* all queues drop enable configuration */
12610
12611 /* Common result structure for all queues drop enable */
12612 struct cmd_all_queues_drop_en_result {
12613         cmdline_fixed_string_t set;
12614         cmdline_fixed_string_t all;
12615         cmdline_fixed_string_t queues;
12616         cmdline_fixed_string_t drop;
12617         portid_t port_id;
12618         cmdline_fixed_string_t on_off;
12619 };
12620
12621 /* Common CLI fields for tx loopback enable disable */
12622 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12623         TOKEN_STRING_INITIALIZER
12624                 (struct cmd_all_queues_drop_en_result,
12625                  set, "set");
12626 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12627         TOKEN_STRING_INITIALIZER
12628                 (struct cmd_all_queues_drop_en_result,
12629                  all, "all");
12630 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12631         TOKEN_STRING_INITIALIZER
12632                 (struct cmd_all_queues_drop_en_result,
12633                  queues, "queues");
12634 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12635         TOKEN_STRING_INITIALIZER
12636                 (struct cmd_all_queues_drop_en_result,
12637                  drop, "drop");
12638 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12639         TOKEN_NUM_INITIALIZER
12640                 (struct cmd_all_queues_drop_en_result,
12641                  port_id, UINT16);
12642 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12643         TOKEN_STRING_INITIALIZER
12644                 (struct cmd_all_queues_drop_en_result,
12645                  on_off, "on#off");
12646
12647 static void
12648 cmd_set_all_queues_drop_en_parsed(
12649         void *parsed_result,
12650         __attribute__((unused)) struct cmdline *cl,
12651         __attribute__((unused)) void *data)
12652 {
12653         struct cmd_all_queues_drop_en_result *res = parsed_result;
12654         int ret = -ENOTSUP;
12655         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12656
12657         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12658                 return;
12659
12660 #ifdef RTE_LIBRTE_IXGBE_PMD
12661         if (ret == -ENOTSUP)
12662                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12663 #endif
12664 #ifdef RTE_LIBRTE_BNXT_PMD
12665         if (ret == -ENOTSUP)
12666                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12667 #endif
12668         switch (ret) {
12669         case 0:
12670                 break;
12671         case -EINVAL:
12672                 printf("invalid is_on %d\n", is_on);
12673                 break;
12674         case -ENODEV:
12675                 printf("invalid port_id %d\n", res->port_id);
12676                 break;
12677         case -ENOTSUP:
12678                 printf("function not implemented\n");
12679                 break;
12680         default:
12681                 printf("programming error: (%s)\n", strerror(-ret));
12682         }
12683 }
12684
12685 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12686         .f = cmd_set_all_queues_drop_en_parsed,
12687         .data = NULL,
12688         .help_str = "set all queues drop <port_id> on|off",
12689         .tokens = {
12690                 (void *)&cmd_all_queues_drop_en_set,
12691                 (void *)&cmd_all_queues_drop_en_all,
12692                 (void *)&cmd_all_queues_drop_en_queues,
12693                 (void *)&cmd_all_queues_drop_en_drop,
12694                 (void *)&cmd_all_queues_drop_en_port_id,
12695                 (void *)&cmd_all_queues_drop_en_on_off,
12696                 NULL,
12697         },
12698 };
12699
12700 /* vf split drop enable configuration */
12701
12702 /* Common result structure for vf split drop enable */
12703 struct cmd_vf_split_drop_en_result {
12704         cmdline_fixed_string_t set;
12705         cmdline_fixed_string_t vf;
12706         cmdline_fixed_string_t split;
12707         cmdline_fixed_string_t drop;
12708         portid_t port_id;
12709         uint16_t vf_id;
12710         cmdline_fixed_string_t on_off;
12711 };
12712
12713 /* Common CLI fields for vf split drop enable disable */
12714 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12715         TOKEN_STRING_INITIALIZER
12716                 (struct cmd_vf_split_drop_en_result,
12717                  set, "set");
12718 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12719         TOKEN_STRING_INITIALIZER
12720                 (struct cmd_vf_split_drop_en_result,
12721                  vf, "vf");
12722 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12723         TOKEN_STRING_INITIALIZER
12724                 (struct cmd_vf_split_drop_en_result,
12725                  split, "split");
12726 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12727         TOKEN_STRING_INITIALIZER
12728                 (struct cmd_vf_split_drop_en_result,
12729                  drop, "drop");
12730 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12731         TOKEN_NUM_INITIALIZER
12732                 (struct cmd_vf_split_drop_en_result,
12733                  port_id, UINT16);
12734 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12735         TOKEN_NUM_INITIALIZER
12736                 (struct cmd_vf_split_drop_en_result,
12737                  vf_id, UINT16);
12738 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12739         TOKEN_STRING_INITIALIZER
12740                 (struct cmd_vf_split_drop_en_result,
12741                  on_off, "on#off");
12742
12743 static void
12744 cmd_set_vf_split_drop_en_parsed(
12745         void *parsed_result,
12746         __attribute__((unused)) struct cmdline *cl,
12747         __attribute__((unused)) void *data)
12748 {
12749         struct cmd_vf_split_drop_en_result *res = parsed_result;
12750         int ret = -ENOTSUP;
12751         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12752
12753         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12754                 return;
12755
12756 #ifdef RTE_LIBRTE_IXGBE_PMD
12757         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12758                         is_on);
12759 #endif
12760         switch (ret) {
12761         case 0:
12762                 break;
12763         case -EINVAL:
12764                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12765                 break;
12766         case -ENODEV:
12767                 printf("invalid port_id %d\n", res->port_id);
12768                 break;
12769         case -ENOTSUP:
12770                 printf("not supported on port %d\n", res->port_id);
12771                 break;
12772         default:
12773                 printf("programming error: (%s)\n", strerror(-ret));
12774         }
12775 }
12776
12777 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12778         .f = cmd_set_vf_split_drop_en_parsed,
12779         .data = NULL,
12780         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12781         .tokens = {
12782                 (void *)&cmd_vf_split_drop_en_set,
12783                 (void *)&cmd_vf_split_drop_en_vf,
12784                 (void *)&cmd_vf_split_drop_en_split,
12785                 (void *)&cmd_vf_split_drop_en_drop,
12786                 (void *)&cmd_vf_split_drop_en_port_id,
12787                 (void *)&cmd_vf_split_drop_en_vf_id,
12788                 (void *)&cmd_vf_split_drop_en_on_off,
12789                 NULL,
12790         },
12791 };
12792
12793 /* vf mac address configuration */
12794
12795 /* Common result structure for vf mac address */
12796 struct cmd_set_vf_mac_addr_result {
12797         cmdline_fixed_string_t set;
12798         cmdline_fixed_string_t vf;
12799         cmdline_fixed_string_t mac;
12800         cmdline_fixed_string_t addr;
12801         portid_t port_id;
12802         uint16_t vf_id;
12803         struct ether_addr mac_addr;
12804
12805 };
12806
12807 /* Common CLI fields for vf split drop enable disable */
12808 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12809         TOKEN_STRING_INITIALIZER
12810                 (struct cmd_set_vf_mac_addr_result,
12811                  set, "set");
12812 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12813         TOKEN_STRING_INITIALIZER
12814                 (struct cmd_set_vf_mac_addr_result,
12815                  vf, "vf");
12816 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12817         TOKEN_STRING_INITIALIZER
12818                 (struct cmd_set_vf_mac_addr_result,
12819                  mac, "mac");
12820 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12821         TOKEN_STRING_INITIALIZER
12822                 (struct cmd_set_vf_mac_addr_result,
12823                  addr, "addr");
12824 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12825         TOKEN_NUM_INITIALIZER
12826                 (struct cmd_set_vf_mac_addr_result,
12827                  port_id, UINT16);
12828 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12829         TOKEN_NUM_INITIALIZER
12830                 (struct cmd_set_vf_mac_addr_result,
12831                  vf_id, UINT16);
12832 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12833         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12834                  mac_addr);
12835
12836 static void
12837 cmd_set_vf_mac_addr_parsed(
12838         void *parsed_result,
12839         __attribute__((unused)) struct cmdline *cl,
12840         __attribute__((unused)) void *data)
12841 {
12842         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12843         int ret = -ENOTSUP;
12844
12845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12846                 return;
12847
12848 #ifdef RTE_LIBRTE_IXGBE_PMD
12849         if (ret == -ENOTSUP)
12850                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12851                                 &res->mac_addr);
12852 #endif
12853 #ifdef RTE_LIBRTE_I40E_PMD
12854         if (ret == -ENOTSUP)
12855                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12856                                 &res->mac_addr);
12857 #endif
12858 #ifdef RTE_LIBRTE_BNXT_PMD
12859         if (ret == -ENOTSUP)
12860                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12861                                 &res->mac_addr);
12862 #endif
12863
12864         switch (ret) {
12865         case 0:
12866                 break;
12867         case -EINVAL:
12868                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12869                 break;
12870         case -ENODEV:
12871                 printf("invalid port_id %d\n", res->port_id);
12872                 break;
12873         case -ENOTSUP:
12874                 printf("function not implemented\n");
12875                 break;
12876         default:
12877                 printf("programming error: (%s)\n", strerror(-ret));
12878         }
12879 }
12880
12881 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12882         .f = cmd_set_vf_mac_addr_parsed,
12883         .data = NULL,
12884         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12885         .tokens = {
12886                 (void *)&cmd_set_vf_mac_addr_set,
12887                 (void *)&cmd_set_vf_mac_addr_vf,
12888                 (void *)&cmd_set_vf_mac_addr_mac,
12889                 (void *)&cmd_set_vf_mac_addr_addr,
12890                 (void *)&cmd_set_vf_mac_addr_port_id,
12891                 (void *)&cmd_set_vf_mac_addr_vf_id,
12892                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12893                 NULL,
12894         },
12895 };
12896
12897 /* MACsec configuration */
12898
12899 /* Common result structure for MACsec offload enable */
12900 struct cmd_macsec_offload_on_result {
12901         cmdline_fixed_string_t set;
12902         cmdline_fixed_string_t macsec;
12903         cmdline_fixed_string_t offload;
12904         portid_t port_id;
12905         cmdline_fixed_string_t on;
12906         cmdline_fixed_string_t encrypt;
12907         cmdline_fixed_string_t en_on_off;
12908         cmdline_fixed_string_t replay_protect;
12909         cmdline_fixed_string_t rp_on_off;
12910 };
12911
12912 /* Common CLI fields for MACsec offload disable */
12913 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12914         TOKEN_STRING_INITIALIZER
12915                 (struct cmd_macsec_offload_on_result,
12916                  set, "set");
12917 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12918         TOKEN_STRING_INITIALIZER
12919                 (struct cmd_macsec_offload_on_result,
12920                  macsec, "macsec");
12921 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12922         TOKEN_STRING_INITIALIZER
12923                 (struct cmd_macsec_offload_on_result,
12924                  offload, "offload");
12925 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12926         TOKEN_NUM_INITIALIZER
12927                 (struct cmd_macsec_offload_on_result,
12928                  port_id, UINT16);
12929 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12930         TOKEN_STRING_INITIALIZER
12931                 (struct cmd_macsec_offload_on_result,
12932                  on, "on");
12933 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12934         TOKEN_STRING_INITIALIZER
12935                 (struct cmd_macsec_offload_on_result,
12936                  encrypt, "encrypt");
12937 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12938         TOKEN_STRING_INITIALIZER
12939                 (struct cmd_macsec_offload_on_result,
12940                  en_on_off, "on#off");
12941 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_macsec_offload_on_result,
12944                  replay_protect, "replay-protect");
12945 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12946         TOKEN_STRING_INITIALIZER
12947                 (struct cmd_macsec_offload_on_result,
12948                  rp_on_off, "on#off");
12949
12950 static void
12951 cmd_set_macsec_offload_on_parsed(
12952         void *parsed_result,
12953         __attribute__((unused)) struct cmdline *cl,
12954         __attribute__((unused)) void *data)
12955 {
12956         struct cmd_macsec_offload_on_result *res = parsed_result;
12957         int ret = -ENOTSUP;
12958         portid_t port_id = res->port_id;
12959         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12960         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12961
12962         if (port_id_is_invalid(port_id, ENABLED_WARN))
12963                 return;
12964
12965         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12966 #ifdef RTE_LIBRTE_IXGBE_PMD
12967         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12968 #endif
12969         RTE_SET_USED(en);
12970         RTE_SET_USED(rp);
12971
12972         switch (ret) {
12973         case 0:
12974                 break;
12975         case -ENODEV:
12976                 printf("invalid port_id %d\n", port_id);
12977                 break;
12978         case -ENOTSUP:
12979                 printf("not supported on port %d\n", port_id);
12980                 break;
12981         default:
12982                 printf("programming error: (%s)\n", strerror(-ret));
12983         }
12984 }
12985
12986 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12987         .f = cmd_set_macsec_offload_on_parsed,
12988         .data = NULL,
12989         .help_str = "set macsec offload <port_id> on "
12990                 "encrypt on|off replay-protect on|off",
12991         .tokens = {
12992                 (void *)&cmd_macsec_offload_on_set,
12993                 (void *)&cmd_macsec_offload_on_macsec,
12994                 (void *)&cmd_macsec_offload_on_offload,
12995                 (void *)&cmd_macsec_offload_on_port_id,
12996                 (void *)&cmd_macsec_offload_on_on,
12997                 (void *)&cmd_macsec_offload_on_encrypt,
12998                 (void *)&cmd_macsec_offload_on_en_on_off,
12999                 (void *)&cmd_macsec_offload_on_replay_protect,
13000                 (void *)&cmd_macsec_offload_on_rp_on_off,
13001                 NULL,
13002         },
13003 };
13004
13005 /* Common result structure for MACsec offload disable */
13006 struct cmd_macsec_offload_off_result {
13007         cmdline_fixed_string_t set;
13008         cmdline_fixed_string_t macsec;
13009         cmdline_fixed_string_t offload;
13010         portid_t port_id;
13011         cmdline_fixed_string_t off;
13012 };
13013
13014 /* Common CLI fields for MACsec offload disable */
13015 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13016         TOKEN_STRING_INITIALIZER
13017                 (struct cmd_macsec_offload_off_result,
13018                  set, "set");
13019 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13020         TOKEN_STRING_INITIALIZER
13021                 (struct cmd_macsec_offload_off_result,
13022                  macsec, "macsec");
13023 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13024         TOKEN_STRING_INITIALIZER
13025                 (struct cmd_macsec_offload_off_result,
13026                  offload, "offload");
13027 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13028         TOKEN_NUM_INITIALIZER
13029                 (struct cmd_macsec_offload_off_result,
13030                  port_id, UINT16);
13031 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13032         TOKEN_STRING_INITIALIZER
13033                 (struct cmd_macsec_offload_off_result,
13034                  off, "off");
13035
13036 static void
13037 cmd_set_macsec_offload_off_parsed(
13038         void *parsed_result,
13039         __attribute__((unused)) struct cmdline *cl,
13040         __attribute__((unused)) void *data)
13041 {
13042         struct cmd_macsec_offload_off_result *res = parsed_result;
13043         int ret = -ENOTSUP;
13044         portid_t port_id = res->port_id;
13045
13046         if (port_id_is_invalid(port_id, ENABLED_WARN))
13047                 return;
13048
13049         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13050 #ifdef RTE_LIBRTE_IXGBE_PMD
13051         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13052 #endif
13053
13054         switch (ret) {
13055         case 0:
13056                 break;
13057         case -ENODEV:
13058                 printf("invalid port_id %d\n", port_id);
13059                 break;
13060         case -ENOTSUP:
13061                 printf("not supported on port %d\n", port_id);
13062                 break;
13063         default:
13064                 printf("programming error: (%s)\n", strerror(-ret));
13065         }
13066 }
13067
13068 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13069         .f = cmd_set_macsec_offload_off_parsed,
13070         .data = NULL,
13071         .help_str = "set macsec offload <port_id> off",
13072         .tokens = {
13073                 (void *)&cmd_macsec_offload_off_set,
13074                 (void *)&cmd_macsec_offload_off_macsec,
13075                 (void *)&cmd_macsec_offload_off_offload,
13076                 (void *)&cmd_macsec_offload_off_port_id,
13077                 (void *)&cmd_macsec_offload_off_off,
13078                 NULL,
13079         },
13080 };
13081
13082 /* Common result structure for MACsec secure connection configure */
13083 struct cmd_macsec_sc_result {
13084         cmdline_fixed_string_t set;
13085         cmdline_fixed_string_t macsec;
13086         cmdline_fixed_string_t sc;
13087         cmdline_fixed_string_t tx_rx;
13088         portid_t port_id;
13089         struct ether_addr mac;
13090         uint16_t pi;
13091 };
13092
13093 /* Common CLI fields for MACsec secure connection configure */
13094 cmdline_parse_token_string_t cmd_macsec_sc_set =
13095         TOKEN_STRING_INITIALIZER
13096                 (struct cmd_macsec_sc_result,
13097                  set, "set");
13098 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13099         TOKEN_STRING_INITIALIZER
13100                 (struct cmd_macsec_sc_result,
13101                  macsec, "macsec");
13102 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13103         TOKEN_STRING_INITIALIZER
13104                 (struct cmd_macsec_sc_result,
13105                  sc, "sc");
13106 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13107         TOKEN_STRING_INITIALIZER
13108                 (struct cmd_macsec_sc_result,
13109                  tx_rx, "tx#rx");
13110 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13111         TOKEN_NUM_INITIALIZER
13112                 (struct cmd_macsec_sc_result,
13113                  port_id, UINT16);
13114 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13115         TOKEN_ETHERADDR_INITIALIZER
13116                 (struct cmd_macsec_sc_result,
13117                  mac);
13118 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13119         TOKEN_NUM_INITIALIZER
13120                 (struct cmd_macsec_sc_result,
13121                  pi, UINT16);
13122
13123 static void
13124 cmd_set_macsec_sc_parsed(
13125         void *parsed_result,
13126         __attribute__((unused)) struct cmdline *cl,
13127         __attribute__((unused)) void *data)
13128 {
13129         struct cmd_macsec_sc_result *res = parsed_result;
13130         int ret = -ENOTSUP;
13131         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13132
13133 #ifdef RTE_LIBRTE_IXGBE_PMD
13134         ret = is_tx ?
13135                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13136                                 res->mac.addr_bytes) :
13137                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13138                                 res->mac.addr_bytes, res->pi);
13139 #endif
13140         RTE_SET_USED(is_tx);
13141
13142         switch (ret) {
13143         case 0:
13144                 break;
13145         case -ENODEV:
13146                 printf("invalid port_id %d\n", res->port_id);
13147                 break;
13148         case -ENOTSUP:
13149                 printf("not supported on port %d\n", res->port_id);
13150                 break;
13151         default:
13152                 printf("programming error: (%s)\n", strerror(-ret));
13153         }
13154 }
13155
13156 cmdline_parse_inst_t cmd_set_macsec_sc = {
13157         .f = cmd_set_macsec_sc_parsed,
13158         .data = NULL,
13159         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13160         .tokens = {
13161                 (void *)&cmd_macsec_sc_set,
13162                 (void *)&cmd_macsec_sc_macsec,
13163                 (void *)&cmd_macsec_sc_sc,
13164                 (void *)&cmd_macsec_sc_tx_rx,
13165                 (void *)&cmd_macsec_sc_port_id,
13166                 (void *)&cmd_macsec_sc_mac,
13167                 (void *)&cmd_macsec_sc_pi,
13168                 NULL,
13169         },
13170 };
13171
13172 /* Common result structure for MACsec secure connection configure */
13173 struct cmd_macsec_sa_result {
13174         cmdline_fixed_string_t set;
13175         cmdline_fixed_string_t macsec;
13176         cmdline_fixed_string_t sa;
13177         cmdline_fixed_string_t tx_rx;
13178         portid_t port_id;
13179         uint8_t idx;
13180         uint8_t an;
13181         uint32_t pn;
13182         cmdline_fixed_string_t key;
13183 };
13184
13185 /* Common CLI fields for MACsec secure connection configure */
13186 cmdline_parse_token_string_t cmd_macsec_sa_set =
13187         TOKEN_STRING_INITIALIZER
13188                 (struct cmd_macsec_sa_result,
13189                  set, "set");
13190 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13191         TOKEN_STRING_INITIALIZER
13192                 (struct cmd_macsec_sa_result,
13193                  macsec, "macsec");
13194 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13195         TOKEN_STRING_INITIALIZER
13196                 (struct cmd_macsec_sa_result,
13197                  sa, "sa");
13198 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13199         TOKEN_STRING_INITIALIZER
13200                 (struct cmd_macsec_sa_result,
13201                  tx_rx, "tx#rx");
13202 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13203         TOKEN_NUM_INITIALIZER
13204                 (struct cmd_macsec_sa_result,
13205                  port_id, UINT16);
13206 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13207         TOKEN_NUM_INITIALIZER
13208                 (struct cmd_macsec_sa_result,
13209                  idx, UINT8);
13210 cmdline_parse_token_num_t cmd_macsec_sa_an =
13211         TOKEN_NUM_INITIALIZER
13212                 (struct cmd_macsec_sa_result,
13213                  an, UINT8);
13214 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13215         TOKEN_NUM_INITIALIZER
13216                 (struct cmd_macsec_sa_result,
13217                  pn, UINT32);
13218 cmdline_parse_token_string_t cmd_macsec_sa_key =
13219         TOKEN_STRING_INITIALIZER
13220                 (struct cmd_macsec_sa_result,
13221                  key, NULL);
13222
13223 static void
13224 cmd_set_macsec_sa_parsed(
13225         void *parsed_result,
13226         __attribute__((unused)) struct cmdline *cl,
13227         __attribute__((unused)) void *data)
13228 {
13229         struct cmd_macsec_sa_result *res = parsed_result;
13230         int ret = -ENOTSUP;
13231         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13232         uint8_t key[16] = { 0 };
13233         uint8_t xdgt0;
13234         uint8_t xdgt1;
13235         int key_len;
13236         int i;
13237
13238         key_len = strlen(res->key) / 2;
13239         if (key_len > 16)
13240                 key_len = 16;
13241
13242         for (i = 0; i < key_len; i++) {
13243                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13244                 if (xdgt0 == 0xFF)
13245                         return;
13246                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13247                 if (xdgt1 == 0xFF)
13248                         return;
13249                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13250         }
13251
13252 #ifdef RTE_LIBRTE_IXGBE_PMD
13253         ret = is_tx ?
13254                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13255                         res->idx, res->an, res->pn, key) :
13256                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13257                         res->idx, res->an, res->pn, key);
13258 #endif
13259         RTE_SET_USED(is_tx);
13260         RTE_SET_USED(key);
13261
13262         switch (ret) {
13263         case 0:
13264                 break;
13265         case -EINVAL:
13266                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13267                 break;
13268         case -ENODEV:
13269                 printf("invalid port_id %d\n", res->port_id);
13270                 break;
13271         case -ENOTSUP:
13272                 printf("not supported on port %d\n", res->port_id);
13273                 break;
13274         default:
13275                 printf("programming error: (%s)\n", strerror(-ret));
13276         }
13277 }
13278
13279 cmdline_parse_inst_t cmd_set_macsec_sa = {
13280         .f = cmd_set_macsec_sa_parsed,
13281         .data = NULL,
13282         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13283         .tokens = {
13284                 (void *)&cmd_macsec_sa_set,
13285                 (void *)&cmd_macsec_sa_macsec,
13286                 (void *)&cmd_macsec_sa_sa,
13287                 (void *)&cmd_macsec_sa_tx_rx,
13288                 (void *)&cmd_macsec_sa_port_id,
13289                 (void *)&cmd_macsec_sa_idx,
13290                 (void *)&cmd_macsec_sa_an,
13291                 (void *)&cmd_macsec_sa_pn,
13292                 (void *)&cmd_macsec_sa_key,
13293                 NULL,
13294         },
13295 };
13296
13297 /* VF unicast promiscuous mode configuration */
13298
13299 /* Common result structure for VF unicast promiscuous mode */
13300 struct cmd_vf_promisc_result {
13301         cmdline_fixed_string_t set;
13302         cmdline_fixed_string_t vf;
13303         cmdline_fixed_string_t promisc;
13304         portid_t port_id;
13305         uint32_t vf_id;
13306         cmdline_fixed_string_t on_off;
13307 };
13308
13309 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13310 cmdline_parse_token_string_t cmd_vf_promisc_set =
13311         TOKEN_STRING_INITIALIZER
13312                 (struct cmd_vf_promisc_result,
13313                  set, "set");
13314 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13315         TOKEN_STRING_INITIALIZER
13316                 (struct cmd_vf_promisc_result,
13317                  vf, "vf");
13318 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13319         TOKEN_STRING_INITIALIZER
13320                 (struct cmd_vf_promisc_result,
13321                  promisc, "promisc");
13322 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13323         TOKEN_NUM_INITIALIZER
13324                 (struct cmd_vf_promisc_result,
13325                  port_id, UINT16);
13326 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13327         TOKEN_NUM_INITIALIZER
13328                 (struct cmd_vf_promisc_result,
13329                  vf_id, UINT32);
13330 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13331         TOKEN_STRING_INITIALIZER
13332                 (struct cmd_vf_promisc_result,
13333                  on_off, "on#off");
13334
13335 static void
13336 cmd_set_vf_promisc_parsed(
13337         void *parsed_result,
13338         __attribute__((unused)) struct cmdline *cl,
13339         __attribute__((unused)) void *data)
13340 {
13341         struct cmd_vf_promisc_result *res = parsed_result;
13342         int ret = -ENOTSUP;
13343
13344         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13345
13346         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13347                 return;
13348
13349 #ifdef RTE_LIBRTE_I40E_PMD
13350         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13351                                                   res->vf_id, is_on);
13352 #endif
13353
13354         switch (ret) {
13355         case 0:
13356                 break;
13357         case -EINVAL:
13358                 printf("invalid vf_id %d\n", res->vf_id);
13359                 break;
13360         case -ENODEV:
13361                 printf("invalid port_id %d\n", res->port_id);
13362                 break;
13363         case -ENOTSUP:
13364                 printf("function not implemented\n");
13365                 break;
13366         default:
13367                 printf("programming error: (%s)\n", strerror(-ret));
13368         }
13369 }
13370
13371 cmdline_parse_inst_t cmd_set_vf_promisc = {
13372         .f = cmd_set_vf_promisc_parsed,
13373         .data = NULL,
13374         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13375                 "Set unicast promiscuous mode for a VF from the PF",
13376         .tokens = {
13377                 (void *)&cmd_vf_promisc_set,
13378                 (void *)&cmd_vf_promisc_vf,
13379                 (void *)&cmd_vf_promisc_promisc,
13380                 (void *)&cmd_vf_promisc_port_id,
13381                 (void *)&cmd_vf_promisc_vf_id,
13382                 (void *)&cmd_vf_promisc_on_off,
13383                 NULL,
13384         },
13385 };
13386
13387 /* VF multicast promiscuous mode configuration */
13388
13389 /* Common result structure for VF multicast promiscuous mode */
13390 struct cmd_vf_allmulti_result {
13391         cmdline_fixed_string_t set;
13392         cmdline_fixed_string_t vf;
13393         cmdline_fixed_string_t allmulti;
13394         portid_t port_id;
13395         uint32_t vf_id;
13396         cmdline_fixed_string_t on_off;
13397 };
13398
13399 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13400 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13401         TOKEN_STRING_INITIALIZER
13402                 (struct cmd_vf_allmulti_result,
13403                  set, "set");
13404 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13405         TOKEN_STRING_INITIALIZER
13406                 (struct cmd_vf_allmulti_result,
13407                  vf, "vf");
13408 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13409         TOKEN_STRING_INITIALIZER
13410                 (struct cmd_vf_allmulti_result,
13411                  allmulti, "allmulti");
13412 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13413         TOKEN_NUM_INITIALIZER
13414                 (struct cmd_vf_allmulti_result,
13415                  port_id, UINT16);
13416 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13417         TOKEN_NUM_INITIALIZER
13418                 (struct cmd_vf_allmulti_result,
13419                  vf_id, UINT32);
13420 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13421         TOKEN_STRING_INITIALIZER
13422                 (struct cmd_vf_allmulti_result,
13423                  on_off, "on#off");
13424
13425 static void
13426 cmd_set_vf_allmulti_parsed(
13427         void *parsed_result,
13428         __attribute__((unused)) struct cmdline *cl,
13429         __attribute__((unused)) void *data)
13430 {
13431         struct cmd_vf_allmulti_result *res = parsed_result;
13432         int ret = -ENOTSUP;
13433
13434         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13435
13436         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13437                 return;
13438
13439 #ifdef RTE_LIBRTE_I40E_PMD
13440         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13441                                                     res->vf_id, is_on);
13442 #endif
13443
13444         switch (ret) {
13445         case 0:
13446                 break;
13447         case -EINVAL:
13448                 printf("invalid vf_id %d\n", res->vf_id);
13449                 break;
13450         case -ENODEV:
13451                 printf("invalid port_id %d\n", res->port_id);
13452                 break;
13453         case -ENOTSUP:
13454                 printf("function not implemented\n");
13455                 break;
13456         default:
13457                 printf("programming error: (%s)\n", strerror(-ret));
13458         }
13459 }
13460
13461 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13462         .f = cmd_set_vf_allmulti_parsed,
13463         .data = NULL,
13464         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13465                 "Set multicast promiscuous mode for a VF from the PF",
13466         .tokens = {
13467                 (void *)&cmd_vf_allmulti_set,
13468                 (void *)&cmd_vf_allmulti_vf,
13469                 (void *)&cmd_vf_allmulti_allmulti,
13470                 (void *)&cmd_vf_allmulti_port_id,
13471                 (void *)&cmd_vf_allmulti_vf_id,
13472                 (void *)&cmd_vf_allmulti_on_off,
13473                 NULL,
13474         },
13475 };
13476
13477 /* vf broadcast mode configuration */
13478
13479 /* Common result structure for vf broadcast */
13480 struct cmd_set_vf_broadcast_result {
13481         cmdline_fixed_string_t set;
13482         cmdline_fixed_string_t vf;
13483         cmdline_fixed_string_t broadcast;
13484         portid_t port_id;
13485         uint16_t vf_id;
13486         cmdline_fixed_string_t on_off;
13487 };
13488
13489 /* Common CLI fields for vf broadcast enable disable */
13490 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13491         TOKEN_STRING_INITIALIZER
13492                 (struct cmd_set_vf_broadcast_result,
13493                  set, "set");
13494 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13495         TOKEN_STRING_INITIALIZER
13496                 (struct cmd_set_vf_broadcast_result,
13497                  vf, "vf");
13498 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13499         TOKEN_STRING_INITIALIZER
13500                 (struct cmd_set_vf_broadcast_result,
13501                  broadcast, "broadcast");
13502 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13503         TOKEN_NUM_INITIALIZER
13504                 (struct cmd_set_vf_broadcast_result,
13505                  port_id, UINT16);
13506 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13507         TOKEN_NUM_INITIALIZER
13508                 (struct cmd_set_vf_broadcast_result,
13509                  vf_id, UINT16);
13510 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13511         TOKEN_STRING_INITIALIZER
13512                 (struct cmd_set_vf_broadcast_result,
13513                  on_off, "on#off");
13514
13515 static void
13516 cmd_set_vf_broadcast_parsed(
13517         void *parsed_result,
13518         __attribute__((unused)) struct cmdline *cl,
13519         __attribute__((unused)) void *data)
13520 {
13521         struct cmd_set_vf_broadcast_result *res = parsed_result;
13522         int ret = -ENOTSUP;
13523
13524         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13525
13526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13527                 return;
13528
13529 #ifdef RTE_LIBRTE_I40E_PMD
13530         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13531                                             res->vf_id, is_on);
13532 #endif
13533
13534         switch (ret) {
13535         case 0:
13536                 break;
13537         case -EINVAL:
13538                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13539                 break;
13540         case -ENODEV:
13541                 printf("invalid port_id %d\n", res->port_id);
13542                 break;
13543         case -ENOTSUP:
13544                 printf("function not implemented\n");
13545                 break;
13546         default:
13547                 printf("programming error: (%s)\n", strerror(-ret));
13548         }
13549 }
13550
13551 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13552         .f = cmd_set_vf_broadcast_parsed,
13553         .data = NULL,
13554         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13555         .tokens = {
13556                 (void *)&cmd_set_vf_broadcast_set,
13557                 (void *)&cmd_set_vf_broadcast_vf,
13558                 (void *)&cmd_set_vf_broadcast_broadcast,
13559                 (void *)&cmd_set_vf_broadcast_port_id,
13560                 (void *)&cmd_set_vf_broadcast_vf_id,
13561                 (void *)&cmd_set_vf_broadcast_on_off,
13562                 NULL,
13563         },
13564 };
13565
13566 /* vf vlan tag configuration */
13567
13568 /* Common result structure for vf vlan tag */
13569 struct cmd_set_vf_vlan_tag_result {
13570         cmdline_fixed_string_t set;
13571         cmdline_fixed_string_t vf;
13572         cmdline_fixed_string_t vlan;
13573         cmdline_fixed_string_t tag;
13574         portid_t port_id;
13575         uint16_t vf_id;
13576         cmdline_fixed_string_t on_off;
13577 };
13578
13579 /* Common CLI fields for vf vlan tag enable disable */
13580 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13581         TOKEN_STRING_INITIALIZER
13582                 (struct cmd_set_vf_vlan_tag_result,
13583                  set, "set");
13584 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13585         TOKEN_STRING_INITIALIZER
13586                 (struct cmd_set_vf_vlan_tag_result,
13587                  vf, "vf");
13588 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13589         TOKEN_STRING_INITIALIZER
13590                 (struct cmd_set_vf_vlan_tag_result,
13591                  vlan, "vlan");
13592 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13593         TOKEN_STRING_INITIALIZER
13594                 (struct cmd_set_vf_vlan_tag_result,
13595                  tag, "tag");
13596 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13597         TOKEN_NUM_INITIALIZER
13598                 (struct cmd_set_vf_vlan_tag_result,
13599                  port_id, UINT16);
13600 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13601         TOKEN_NUM_INITIALIZER
13602                 (struct cmd_set_vf_vlan_tag_result,
13603                  vf_id, UINT16);
13604 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13605         TOKEN_STRING_INITIALIZER
13606                 (struct cmd_set_vf_vlan_tag_result,
13607                  on_off, "on#off");
13608
13609 static void
13610 cmd_set_vf_vlan_tag_parsed(
13611         void *parsed_result,
13612         __attribute__((unused)) struct cmdline *cl,
13613         __attribute__((unused)) void *data)
13614 {
13615         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13616         int ret = -ENOTSUP;
13617
13618         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13619
13620         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13621                 return;
13622
13623 #ifdef RTE_LIBRTE_I40E_PMD
13624         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13625                                            res->vf_id, is_on);
13626 #endif
13627
13628         switch (ret) {
13629         case 0:
13630                 break;
13631         case -EINVAL:
13632                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13633                 break;
13634         case -ENODEV:
13635                 printf("invalid port_id %d\n", res->port_id);
13636                 break;
13637         case -ENOTSUP:
13638                 printf("function not implemented\n");
13639                 break;
13640         default:
13641                 printf("programming error: (%s)\n", strerror(-ret));
13642         }
13643 }
13644
13645 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13646         .f = cmd_set_vf_vlan_tag_parsed,
13647         .data = NULL,
13648         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13649         .tokens = {
13650                 (void *)&cmd_set_vf_vlan_tag_set,
13651                 (void *)&cmd_set_vf_vlan_tag_vf,
13652                 (void *)&cmd_set_vf_vlan_tag_vlan,
13653                 (void *)&cmd_set_vf_vlan_tag_tag,
13654                 (void *)&cmd_set_vf_vlan_tag_port_id,
13655                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13656                 (void *)&cmd_set_vf_vlan_tag_on_off,
13657                 NULL,
13658         },
13659 };
13660
13661 /* Common definition of VF and TC TX bandwidth configuration */
13662 struct cmd_vf_tc_bw_result {
13663         cmdline_fixed_string_t set;
13664         cmdline_fixed_string_t vf;
13665         cmdline_fixed_string_t tc;
13666         cmdline_fixed_string_t tx;
13667         cmdline_fixed_string_t min_bw;
13668         cmdline_fixed_string_t max_bw;
13669         cmdline_fixed_string_t strict_link_prio;
13670         portid_t port_id;
13671         uint16_t vf_id;
13672         uint8_t tc_no;
13673         uint32_t bw;
13674         cmdline_fixed_string_t bw_list;
13675         uint8_t tc_map;
13676 };
13677
13678 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_vf_tc_bw_result,
13681                  set, "set");
13682 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13683         TOKEN_STRING_INITIALIZER
13684                 (struct cmd_vf_tc_bw_result,
13685                  vf, "vf");
13686 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13687         TOKEN_STRING_INITIALIZER
13688                 (struct cmd_vf_tc_bw_result,
13689                  tc, "tc");
13690 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13691         TOKEN_STRING_INITIALIZER
13692                 (struct cmd_vf_tc_bw_result,
13693                  tx, "tx");
13694 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13695         TOKEN_STRING_INITIALIZER
13696                 (struct cmd_vf_tc_bw_result,
13697                  strict_link_prio, "strict-link-priority");
13698 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13699         TOKEN_STRING_INITIALIZER
13700                 (struct cmd_vf_tc_bw_result,
13701                  min_bw, "min-bandwidth");
13702 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13703         TOKEN_STRING_INITIALIZER
13704                 (struct cmd_vf_tc_bw_result,
13705                  max_bw, "max-bandwidth");
13706 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13707         TOKEN_NUM_INITIALIZER
13708                 (struct cmd_vf_tc_bw_result,
13709                  port_id, UINT16);
13710 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13711         TOKEN_NUM_INITIALIZER
13712                 (struct cmd_vf_tc_bw_result,
13713                  vf_id, UINT16);
13714 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13715         TOKEN_NUM_INITIALIZER
13716                 (struct cmd_vf_tc_bw_result,
13717                  tc_no, UINT8);
13718 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13719         TOKEN_NUM_INITIALIZER
13720                 (struct cmd_vf_tc_bw_result,
13721                  bw, UINT32);
13722 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13723         TOKEN_STRING_INITIALIZER
13724                 (struct cmd_vf_tc_bw_result,
13725                  bw_list, NULL);
13726 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13727         TOKEN_NUM_INITIALIZER
13728                 (struct cmd_vf_tc_bw_result,
13729                  tc_map, UINT8);
13730
13731 /* VF max bandwidth setting */
13732 static void
13733 cmd_vf_max_bw_parsed(
13734         void *parsed_result,
13735         __attribute__((unused)) struct cmdline *cl,
13736         __attribute__((unused)) void *data)
13737 {
13738         struct cmd_vf_tc_bw_result *res = parsed_result;
13739         int ret = -ENOTSUP;
13740
13741         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13742                 return;
13743
13744 #ifdef RTE_LIBRTE_I40E_PMD
13745         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13746                                          res->vf_id, res->bw);
13747 #endif
13748
13749         switch (ret) {
13750         case 0:
13751                 break;
13752         case -EINVAL:
13753                 printf("invalid vf_id %d or bandwidth %d\n",
13754                        res->vf_id, res->bw);
13755                 break;
13756         case -ENODEV:
13757                 printf("invalid port_id %d\n", res->port_id);
13758                 break;
13759         case -ENOTSUP:
13760                 printf("function not implemented\n");
13761                 break;
13762         default:
13763                 printf("programming error: (%s)\n", strerror(-ret));
13764         }
13765 }
13766
13767 cmdline_parse_inst_t cmd_vf_max_bw = {
13768         .f = cmd_vf_max_bw_parsed,
13769         .data = NULL,
13770         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13771         .tokens = {
13772                 (void *)&cmd_vf_tc_bw_set,
13773                 (void *)&cmd_vf_tc_bw_vf,
13774                 (void *)&cmd_vf_tc_bw_tx,
13775                 (void *)&cmd_vf_tc_bw_max_bw,
13776                 (void *)&cmd_vf_tc_bw_port_id,
13777                 (void *)&cmd_vf_tc_bw_vf_id,
13778                 (void *)&cmd_vf_tc_bw_bw,
13779                 NULL,
13780         },
13781 };
13782
13783 static int
13784 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13785                            uint8_t *tc_num,
13786                            char *str)
13787 {
13788         uint32_t size;
13789         const char *p, *p0 = str;
13790         char s[256];
13791         char *end;
13792         char *str_fld[16];
13793         uint16_t i;
13794         int ret;
13795
13796         p = strchr(p0, '(');
13797         if (p == NULL) {
13798                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13799                 return -1;
13800         }
13801         p++;
13802         p0 = strchr(p, ')');
13803         if (p0 == NULL) {
13804                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13805                 return -1;
13806         }
13807         size = p0 - p;
13808         if (size >= sizeof(s)) {
13809                 printf("The string size exceeds the internal buffer size\n");
13810                 return -1;
13811         }
13812         snprintf(s, sizeof(s), "%.*s", size, p);
13813         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13814         if (ret <= 0) {
13815                 printf("Failed to get the bandwidth list. ");
13816                 return -1;
13817         }
13818         *tc_num = ret;
13819         for (i = 0; i < ret; i++)
13820                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13821
13822         return 0;
13823 }
13824
13825 /* TC min bandwidth setting */
13826 static void
13827 cmd_vf_tc_min_bw_parsed(
13828         void *parsed_result,
13829         __attribute__((unused)) struct cmdline *cl,
13830         __attribute__((unused)) void *data)
13831 {
13832         struct cmd_vf_tc_bw_result *res = parsed_result;
13833         uint8_t tc_num;
13834         uint8_t bw[16];
13835         int ret = -ENOTSUP;
13836
13837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13838                 return;
13839
13840         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13841         if (ret)
13842                 return;
13843
13844 #ifdef RTE_LIBRTE_I40E_PMD
13845         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13846                                               tc_num, bw);
13847 #endif
13848
13849         switch (ret) {
13850         case 0:
13851                 break;
13852         case -EINVAL:
13853                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13854                 break;
13855         case -ENODEV:
13856                 printf("invalid port_id %d\n", res->port_id);
13857                 break;
13858         case -ENOTSUP:
13859                 printf("function not implemented\n");
13860                 break;
13861         default:
13862                 printf("programming error: (%s)\n", strerror(-ret));
13863         }
13864 }
13865
13866 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13867         .f = cmd_vf_tc_min_bw_parsed,
13868         .data = NULL,
13869         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13870                     " <bw1, bw2, ...>",
13871         .tokens = {
13872                 (void *)&cmd_vf_tc_bw_set,
13873                 (void *)&cmd_vf_tc_bw_vf,
13874                 (void *)&cmd_vf_tc_bw_tc,
13875                 (void *)&cmd_vf_tc_bw_tx,
13876                 (void *)&cmd_vf_tc_bw_min_bw,
13877                 (void *)&cmd_vf_tc_bw_port_id,
13878                 (void *)&cmd_vf_tc_bw_vf_id,
13879                 (void *)&cmd_vf_tc_bw_bw_list,
13880                 NULL,
13881         },
13882 };
13883
13884 static void
13885 cmd_tc_min_bw_parsed(
13886         void *parsed_result,
13887         __attribute__((unused)) struct cmdline *cl,
13888         __attribute__((unused)) void *data)
13889 {
13890         struct cmd_vf_tc_bw_result *res = parsed_result;
13891         struct rte_port *port;
13892         uint8_t tc_num;
13893         uint8_t bw[16];
13894         int ret = -ENOTSUP;
13895
13896         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13897                 return;
13898
13899         port = &ports[res->port_id];
13900         /** Check if the port is not started **/
13901         if (port->port_status != RTE_PORT_STOPPED) {
13902                 printf("Please stop port %d first\n", res->port_id);
13903                 return;
13904         }
13905
13906         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13907         if (ret)
13908                 return;
13909
13910 #ifdef RTE_LIBRTE_IXGBE_PMD
13911         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13912 #endif
13913
13914         switch (ret) {
13915         case 0:
13916                 break;
13917         case -EINVAL:
13918                 printf("invalid bandwidth\n");
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_tc_min_bw = {
13932         .f = cmd_tc_min_bw_parsed,
13933         .data = NULL,
13934         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13935         .tokens = {
13936                 (void *)&cmd_vf_tc_bw_set,
13937                 (void *)&cmd_vf_tc_bw_tc,
13938                 (void *)&cmd_vf_tc_bw_tx,
13939                 (void *)&cmd_vf_tc_bw_min_bw,
13940                 (void *)&cmd_vf_tc_bw_port_id,
13941                 (void *)&cmd_vf_tc_bw_bw_list,
13942                 NULL,
13943         },
13944 };
13945
13946 /* TC max bandwidth setting */
13947 static void
13948 cmd_vf_tc_max_bw_parsed(
13949         void *parsed_result,
13950         __attribute__((unused)) struct cmdline *cl,
13951         __attribute__((unused)) void *data)
13952 {
13953         struct cmd_vf_tc_bw_result *res = parsed_result;
13954         int ret = -ENOTSUP;
13955
13956         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13957                 return;
13958
13959 #ifdef RTE_LIBRTE_I40E_PMD
13960         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13961                                             res->tc_no, res->bw);
13962 #endif
13963
13964         switch (ret) {
13965         case 0:
13966                 break;
13967         case -EINVAL:
13968                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13969                        res->vf_id, res->tc_no, res->bw);
13970                 break;
13971         case -ENODEV:
13972                 printf("invalid port_id %d\n", res->port_id);
13973                 break;
13974         case -ENOTSUP:
13975                 printf("function not implemented\n");
13976                 break;
13977         default:
13978                 printf("programming error: (%s)\n", strerror(-ret));
13979         }
13980 }
13981
13982 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13983         .f = cmd_vf_tc_max_bw_parsed,
13984         .data = NULL,
13985         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13986                     " <bandwidth>",
13987         .tokens = {
13988                 (void *)&cmd_vf_tc_bw_set,
13989                 (void *)&cmd_vf_tc_bw_vf,
13990                 (void *)&cmd_vf_tc_bw_tc,
13991                 (void *)&cmd_vf_tc_bw_tx,
13992                 (void *)&cmd_vf_tc_bw_max_bw,
13993                 (void *)&cmd_vf_tc_bw_port_id,
13994                 (void *)&cmd_vf_tc_bw_vf_id,
13995                 (void *)&cmd_vf_tc_bw_tc_no,
13996                 (void *)&cmd_vf_tc_bw_bw,
13997                 NULL,
13998         },
13999 };
14000
14001
14002 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14003
14004 /* *** Set Port default Traffic Management Hierarchy *** */
14005 struct cmd_set_port_tm_hierarchy_default_result {
14006         cmdline_fixed_string_t set;
14007         cmdline_fixed_string_t port;
14008         cmdline_fixed_string_t tm;
14009         cmdline_fixed_string_t hierarchy;
14010         cmdline_fixed_string_t def;
14011         portid_t port_id;
14012 };
14013
14014 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14015         TOKEN_STRING_INITIALIZER(
14016                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14017 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14018         TOKEN_STRING_INITIALIZER(
14019                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14020 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14021         TOKEN_STRING_INITIALIZER(
14022                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14023 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14024         TOKEN_STRING_INITIALIZER(
14025                 struct cmd_set_port_tm_hierarchy_default_result,
14026                         hierarchy, "hierarchy");
14027 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14028         TOKEN_STRING_INITIALIZER(
14029                 struct cmd_set_port_tm_hierarchy_default_result,
14030                         def, "default");
14031 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14032         TOKEN_NUM_INITIALIZER(
14033                 struct cmd_set_port_tm_hierarchy_default_result,
14034                         port_id, UINT16);
14035
14036 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14037         __attribute__((unused)) struct cmdline *cl,
14038         __attribute__((unused)) void *data)
14039 {
14040         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14041         struct rte_port *p;
14042         portid_t port_id = res->port_id;
14043
14044         if (port_id_is_invalid(port_id, ENABLED_WARN))
14045                 return;
14046
14047         p = &ports[port_id];
14048
14049         /* Port tm flag */
14050         if (p->softport.tm_flag == 0) {
14051                 printf("  tm not enabled on port %u (error)\n", port_id);
14052                 return;
14053         }
14054
14055         /* Forward mode: tm */
14056         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14057                 printf("  tm mode not enabled(error)\n");
14058                 return;
14059         }
14060
14061         /* Set the default tm hierarchy */
14062         p->softport.tm.default_hierarchy_enable = 1;
14063 }
14064
14065 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14066         .f = cmd_set_port_tm_hierarchy_default_parsed,
14067         .data = NULL,
14068         .help_str = "set port tm hierarchy default <port_id>",
14069         .tokens = {
14070                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14071                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14072                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14073                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14074                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14075                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14076                 NULL,
14077         },
14078 };
14079 #endif
14080
14081 /* Strict link priority scheduling mode setting */
14082 static void
14083 cmd_strict_link_prio_parsed(
14084         void *parsed_result,
14085         __attribute__((unused)) struct cmdline *cl,
14086         __attribute__((unused)) void *data)
14087 {
14088         struct cmd_vf_tc_bw_result *res = parsed_result;
14089         int ret = -ENOTSUP;
14090
14091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14092                 return;
14093
14094 #ifdef RTE_LIBRTE_I40E_PMD
14095         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14096 #endif
14097
14098         switch (ret) {
14099         case 0:
14100                 break;
14101         case -EINVAL:
14102                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14103                 break;
14104         case -ENODEV:
14105                 printf("invalid port_id %d\n", res->port_id);
14106                 break;
14107         case -ENOTSUP:
14108                 printf("function not implemented\n");
14109                 break;
14110         default:
14111                 printf("programming error: (%s)\n", strerror(-ret));
14112         }
14113 }
14114
14115 cmdline_parse_inst_t cmd_strict_link_prio = {
14116         .f = cmd_strict_link_prio_parsed,
14117         .data = NULL,
14118         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14119         .tokens = {
14120                 (void *)&cmd_vf_tc_bw_set,
14121                 (void *)&cmd_vf_tc_bw_tx,
14122                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14123                 (void *)&cmd_vf_tc_bw_port_id,
14124                 (void *)&cmd_vf_tc_bw_tc_map,
14125                 NULL,
14126         },
14127 };
14128
14129 /* Load dynamic device personalization*/
14130 struct cmd_ddp_add_result {
14131         cmdline_fixed_string_t ddp;
14132         cmdline_fixed_string_t add;
14133         portid_t port_id;
14134         char filepath[];
14135 };
14136
14137 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14138         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14139 cmdline_parse_token_string_t cmd_ddp_add_add =
14140         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14141 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14142         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14143 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14144         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14145
14146 static void
14147 cmd_ddp_add_parsed(
14148         void *parsed_result,
14149         __attribute__((unused)) struct cmdline *cl,
14150         __attribute__((unused)) void *data)
14151 {
14152         struct cmd_ddp_add_result *res = parsed_result;
14153         uint8_t *buff;
14154         uint32_t size;
14155         char *filepath;
14156         char *file_fld[2];
14157         int file_num;
14158         int ret = -ENOTSUP;
14159
14160         if (res->port_id > nb_ports) {
14161                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14162                 return;
14163         }
14164
14165         if (!all_ports_stopped()) {
14166                 printf("Please stop all ports first\n");
14167                 return;
14168         }
14169
14170         filepath = strdup(res->filepath);
14171         if (filepath == NULL) {
14172                 printf("Failed to allocate memory\n");
14173                 return;
14174         }
14175         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14176
14177         buff = open_ddp_package_file(file_fld[0], &size);
14178         if (!buff) {
14179                 free((void *)filepath);
14180                 return;
14181         }
14182
14183 #ifdef RTE_LIBRTE_I40E_PMD
14184         if (ret == -ENOTSUP)
14185                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14186                                                buff, size,
14187                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14188 #endif
14189
14190         if (ret == -EEXIST)
14191                 printf("Profile has already existed.\n");
14192         else if (ret < 0)
14193                 printf("Failed to load profile.\n");
14194         else if (file_num == 2)
14195                 save_ddp_package_file(file_fld[1], buff, size);
14196
14197         close_ddp_package_file(buff);
14198         free((void *)filepath);
14199 }
14200
14201 cmdline_parse_inst_t cmd_ddp_add = {
14202         .f = cmd_ddp_add_parsed,
14203         .data = NULL,
14204         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14205         .tokens = {
14206                 (void *)&cmd_ddp_add_ddp,
14207                 (void *)&cmd_ddp_add_add,
14208                 (void *)&cmd_ddp_add_port_id,
14209                 (void *)&cmd_ddp_add_filepath,
14210                 NULL,
14211         },
14212 };
14213
14214 /* Delete dynamic device personalization*/
14215 struct cmd_ddp_del_result {
14216         cmdline_fixed_string_t ddp;
14217         cmdline_fixed_string_t del;
14218         portid_t port_id;
14219         char filepath[];
14220 };
14221
14222 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14223         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14224 cmdline_parse_token_string_t cmd_ddp_del_del =
14225         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14226 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14227         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14228 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14229         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14230
14231 static void
14232 cmd_ddp_del_parsed(
14233         void *parsed_result,
14234         __attribute__((unused)) struct cmdline *cl,
14235         __attribute__((unused)) void *data)
14236 {
14237         struct cmd_ddp_del_result *res = parsed_result;
14238         uint8_t *buff;
14239         uint32_t size;
14240         int ret = -ENOTSUP;
14241
14242         if (res->port_id > nb_ports) {
14243                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14244                 return;
14245         }
14246
14247         if (!all_ports_stopped()) {
14248                 printf("Please stop all ports first\n");
14249                 return;
14250         }
14251
14252         buff = open_ddp_package_file(res->filepath, &size);
14253         if (!buff)
14254                 return;
14255
14256 #ifdef RTE_LIBRTE_I40E_PMD
14257         if (ret == -ENOTSUP)
14258                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14259                                                buff, size,
14260                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14261 #endif
14262
14263         if (ret == -EACCES)
14264                 printf("Profile does not exist.\n");
14265         else if (ret < 0)
14266                 printf("Failed to delete profile.\n");
14267
14268         close_ddp_package_file(buff);
14269 }
14270
14271 cmdline_parse_inst_t cmd_ddp_del = {
14272         .f = cmd_ddp_del_parsed,
14273         .data = NULL,
14274         .help_str = "ddp del <port_id> <profile_path>",
14275         .tokens = {
14276                 (void *)&cmd_ddp_del_ddp,
14277                 (void *)&cmd_ddp_del_del,
14278                 (void *)&cmd_ddp_del_port_id,
14279                 (void *)&cmd_ddp_del_filepath,
14280                 NULL,
14281         },
14282 };
14283
14284 /* Get dynamic device personalization profile info */
14285 struct cmd_ddp_info_result {
14286         cmdline_fixed_string_t ddp;
14287         cmdline_fixed_string_t get;
14288         cmdline_fixed_string_t info;
14289         char filepath[];
14290 };
14291
14292 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14293         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14294 cmdline_parse_token_string_t cmd_ddp_info_get =
14295         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14296 cmdline_parse_token_string_t cmd_ddp_info_info =
14297         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14298 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14299         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14300
14301 static void
14302 cmd_ddp_info_parsed(
14303         void *parsed_result,
14304         __attribute__((unused)) struct cmdline *cl,
14305         __attribute__((unused)) void *data)
14306 {
14307         struct cmd_ddp_info_result *res = parsed_result;
14308         uint8_t *pkg;
14309         uint32_t pkg_size;
14310         int ret = -ENOTSUP;
14311 #ifdef RTE_LIBRTE_I40E_PMD
14312         uint32_t i, j, n;
14313         uint8_t *buff;
14314         uint32_t buff_size = 0;
14315         struct rte_pmd_i40e_profile_info info;
14316         uint32_t dev_num = 0;
14317         struct rte_pmd_i40e_ddp_device_id *devs;
14318         uint32_t proto_num = 0;
14319         struct rte_pmd_i40e_proto_info *proto;
14320         uint32_t pctype_num = 0;
14321         struct rte_pmd_i40e_ptype_info *pctype;
14322         uint32_t ptype_num = 0;
14323         struct rte_pmd_i40e_ptype_info *ptype;
14324         uint8_t proto_id;
14325
14326 #endif
14327
14328         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14329         if (!pkg)
14330                 return;
14331
14332 #ifdef RTE_LIBRTE_I40E_PMD
14333         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14334                                 (uint8_t *)&info, sizeof(info),
14335                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14336         if (!ret) {
14337                 printf("Global Track id:       0x%x\n", info.track_id);
14338                 printf("Global Version:        %d.%d.%d.%d\n",
14339                         info.version.major,
14340                         info.version.minor,
14341                         info.version.update,
14342                         info.version.draft);
14343                 printf("Global Package name:   %s\n\n", info.name);
14344         }
14345
14346         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14347                                 (uint8_t *)&info, sizeof(info),
14348                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14349         if (!ret) {
14350                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14351                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14352                         info.version.major,
14353                         info.version.minor,
14354                         info.version.update,
14355                         info.version.draft);
14356                 printf("i40e Profile name:     %s\n\n", info.name);
14357         }
14358
14359         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14360                                 (uint8_t *)&buff_size, sizeof(buff_size),
14361                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14362         if (!ret && buff_size) {
14363                 buff = (uint8_t *)malloc(buff_size);
14364                 if (buff) {
14365                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14366                                                 buff, buff_size,
14367                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14368                         if (!ret)
14369                                 printf("Package Notes:\n%s\n\n", buff);
14370                         free(buff);
14371                 }
14372         }
14373
14374         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14375                                 (uint8_t *)&dev_num, sizeof(dev_num),
14376                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14377         if (!ret && dev_num) {
14378                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14379                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14380                 if (devs) {
14381                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14382                                                 (uint8_t *)devs, buff_size,
14383                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14384                         if (!ret) {
14385                                 printf("List of supported devices:\n");
14386                                 for (i = 0; i < dev_num; i++) {
14387                                         printf("  %04X:%04X %04X:%04X\n",
14388                                                 devs[i].vendor_dev_id >> 16,
14389                                                 devs[i].vendor_dev_id & 0xFFFF,
14390                                                 devs[i].sub_vendor_dev_id >> 16,
14391                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14392                                 }
14393                                 printf("\n");
14394                         }
14395                         free(devs);
14396                 }
14397         }
14398
14399         /* get information about protocols and packet types */
14400         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14401                 (uint8_t *)&proto_num, sizeof(proto_num),
14402                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14403         if (ret || !proto_num)
14404                 goto no_print_return;
14405
14406         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14407         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14408         if (!proto)
14409                 goto no_print_return;
14410
14411         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14412                                         buff_size,
14413                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14414         if (!ret) {
14415                 printf("List of used protocols:\n");
14416                 for (i = 0; i < proto_num; i++)
14417                         printf("  %2u: %s\n", proto[i].proto_id,
14418                                proto[i].name);
14419                 printf("\n");
14420         }
14421         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14422                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14423                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14424         if (ret || !pctype_num)
14425                 goto no_print_pctypes;
14426
14427         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14428         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14429         if (!pctype)
14430                 goto no_print_pctypes;
14431
14432         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14433                                         buff_size,
14434                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14435         if (ret) {
14436                 free(pctype);
14437                 goto no_print_pctypes;
14438         }
14439
14440         printf("List of defined packet classification types:\n");
14441         for (i = 0; i < pctype_num; i++) {
14442                 printf("  %2u:", pctype[i].ptype_id);
14443                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14444                         proto_id = pctype[i].protocols[j];
14445                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14446                                 for (n = 0; n < proto_num; n++) {
14447                                         if (proto[n].proto_id == proto_id) {
14448                                                 printf(" %s", proto[n].name);
14449                                                 break;
14450                                         }
14451                                 }
14452                         }
14453                 }
14454                 printf("\n");
14455         }
14456         printf("\n");
14457         free(pctype);
14458
14459 no_print_pctypes:
14460
14461         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14462                                         sizeof(ptype_num),
14463                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14464         if (ret || !ptype_num)
14465                 goto no_print_return;
14466
14467         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14468         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14469         if (!ptype)
14470                 goto no_print_return;
14471
14472         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14473                                         buff_size,
14474                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14475         if (ret) {
14476                 free(ptype);
14477                 goto no_print_return;
14478         }
14479         printf("List of defined packet types:\n");
14480         for (i = 0; i < ptype_num; i++) {
14481                 printf("  %2u:", ptype[i].ptype_id);
14482                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14483                         proto_id = ptype[i].protocols[j];
14484                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14485                                 for (n = 0; n < proto_num; n++) {
14486                                         if (proto[n].proto_id == proto_id) {
14487                                                 printf(" %s", proto[n].name);
14488                                                 break;
14489                                         }
14490                                 }
14491                         }
14492                 }
14493                 printf("\n");
14494         }
14495         free(ptype);
14496         printf("\n");
14497
14498         free(proto);
14499         ret = 0;
14500 no_print_return:
14501 #endif
14502         if (ret == -ENOTSUP)
14503                 printf("Function not supported in PMD driver\n");
14504         close_ddp_package_file(pkg);
14505 }
14506
14507 cmdline_parse_inst_t cmd_ddp_get_info = {
14508         .f = cmd_ddp_info_parsed,
14509         .data = NULL,
14510         .help_str = "ddp get info <profile_path>",
14511         .tokens = {
14512                 (void *)&cmd_ddp_info_ddp,
14513                 (void *)&cmd_ddp_info_get,
14514                 (void *)&cmd_ddp_info_info,
14515                 (void *)&cmd_ddp_info_filepath,
14516                 NULL,
14517         },
14518 };
14519
14520 /* Get dynamic device personalization profile info list*/
14521 #define PROFILE_INFO_SIZE 48
14522 #define MAX_PROFILE_NUM 16
14523
14524 struct cmd_ddp_get_list_result {
14525         cmdline_fixed_string_t ddp;
14526         cmdline_fixed_string_t get;
14527         cmdline_fixed_string_t list;
14528         portid_t port_id;
14529 };
14530
14531 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14532         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14533 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14534         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14535 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14536         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14537 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14538         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14539
14540 static void
14541 cmd_ddp_get_list_parsed(
14542         void *parsed_result,
14543         __attribute__((unused)) struct cmdline *cl,
14544         __attribute__((unused)) void *data)
14545 {
14546         struct cmd_ddp_get_list_result *res = parsed_result;
14547 #ifdef RTE_LIBRTE_I40E_PMD
14548         struct rte_pmd_i40e_profile_list *p_list;
14549         struct rte_pmd_i40e_profile_info *p_info;
14550         uint32_t p_num;
14551         uint32_t size;
14552         uint32_t i;
14553 #endif
14554         int ret = -ENOTSUP;
14555
14556         if (res->port_id > nb_ports) {
14557                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14558                 return;
14559         }
14560
14561 #ifdef RTE_LIBRTE_I40E_PMD
14562         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14563         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14564         if (!p_list)
14565                 printf("%s: Failed to malloc buffer\n", __func__);
14566
14567         if (ret == -ENOTSUP)
14568                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14569                                                 (uint8_t *)p_list, size);
14570
14571         if (!ret) {
14572                 p_num = p_list->p_count;
14573                 printf("Profile number is: %d\n\n", p_num);
14574
14575                 for (i = 0; i < p_num; i++) {
14576                         p_info = &p_list->p_info[i];
14577                         printf("Profile %d:\n", i);
14578                         printf("Track id:     0x%x\n", p_info->track_id);
14579                         printf("Version:      %d.%d.%d.%d\n",
14580                                p_info->version.major,
14581                                p_info->version.minor,
14582                                p_info->version.update,
14583                                p_info->version.draft);
14584                         printf("Profile name: %s\n\n", p_info->name);
14585                 }
14586         }
14587
14588         free(p_list);
14589 #endif
14590
14591         if (ret < 0)
14592                 printf("Failed to get ddp list\n");
14593 }
14594
14595 cmdline_parse_inst_t cmd_ddp_get_list = {
14596         .f = cmd_ddp_get_list_parsed,
14597         .data = NULL,
14598         .help_str = "ddp get list <port_id>",
14599         .tokens = {
14600                 (void *)&cmd_ddp_get_list_ddp,
14601                 (void *)&cmd_ddp_get_list_get,
14602                 (void *)&cmd_ddp_get_list_list,
14603                 (void *)&cmd_ddp_get_list_port_id,
14604                 NULL,
14605         },
14606 };
14607
14608 /* show vf stats */
14609
14610 /* Common result structure for show vf stats */
14611 struct cmd_show_vf_stats_result {
14612         cmdline_fixed_string_t show;
14613         cmdline_fixed_string_t vf;
14614         cmdline_fixed_string_t stats;
14615         portid_t port_id;
14616         uint16_t vf_id;
14617 };
14618
14619 /* Common CLI fields show vf stats*/
14620 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14621         TOKEN_STRING_INITIALIZER
14622                 (struct cmd_show_vf_stats_result,
14623                  show, "show");
14624 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14625         TOKEN_STRING_INITIALIZER
14626                 (struct cmd_show_vf_stats_result,
14627                  vf, "vf");
14628 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14629         TOKEN_STRING_INITIALIZER
14630                 (struct cmd_show_vf_stats_result,
14631                  stats, "stats");
14632 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14633         TOKEN_NUM_INITIALIZER
14634                 (struct cmd_show_vf_stats_result,
14635                  port_id, UINT16);
14636 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14637         TOKEN_NUM_INITIALIZER
14638                 (struct cmd_show_vf_stats_result,
14639                  vf_id, UINT16);
14640
14641 static void
14642 cmd_show_vf_stats_parsed(
14643         void *parsed_result,
14644         __attribute__((unused)) struct cmdline *cl,
14645         __attribute__((unused)) void *data)
14646 {
14647         struct cmd_show_vf_stats_result *res = parsed_result;
14648         struct rte_eth_stats stats;
14649         int ret = -ENOTSUP;
14650         static const char *nic_stats_border = "########################";
14651
14652         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14653                 return;
14654
14655         memset(&stats, 0, sizeof(stats));
14656
14657 #ifdef RTE_LIBRTE_I40E_PMD
14658         if (ret == -ENOTSUP)
14659                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14660                                                 res->vf_id,
14661                                                 &stats);
14662 #endif
14663 #ifdef RTE_LIBRTE_BNXT_PMD
14664         if (ret == -ENOTSUP)
14665                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14666                                                 res->vf_id,
14667                                                 &stats);
14668 #endif
14669
14670         switch (ret) {
14671         case 0:
14672                 break;
14673         case -EINVAL:
14674                 printf("invalid vf_id %d\n", res->vf_id);
14675                 break;
14676         case -ENODEV:
14677                 printf("invalid port_id %d\n", res->port_id);
14678                 break;
14679         case -ENOTSUP:
14680                 printf("function not implemented\n");
14681                 break;
14682         default:
14683                 printf("programming error: (%s)\n", strerror(-ret));
14684         }
14685
14686         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14687                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14688
14689         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14690                "%-"PRIu64"\n",
14691                stats.ipackets, stats.imissed, stats.ibytes);
14692         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14693         printf("  RX-nombuf:  %-10"PRIu64"\n",
14694                stats.rx_nombuf);
14695         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14696                "%-"PRIu64"\n",
14697                stats.opackets, stats.oerrors, stats.obytes);
14698
14699         printf("  %s############################%s\n",
14700                                nic_stats_border, nic_stats_border);
14701 }
14702
14703 cmdline_parse_inst_t cmd_show_vf_stats = {
14704         .f = cmd_show_vf_stats_parsed,
14705         .data = NULL,
14706         .help_str = "show vf stats <port_id> <vf_id>",
14707         .tokens = {
14708                 (void *)&cmd_show_vf_stats_show,
14709                 (void *)&cmd_show_vf_stats_vf,
14710                 (void *)&cmd_show_vf_stats_stats,
14711                 (void *)&cmd_show_vf_stats_port_id,
14712                 (void *)&cmd_show_vf_stats_vf_id,
14713                 NULL,
14714         },
14715 };
14716
14717 /* clear vf stats */
14718
14719 /* Common result structure for clear vf stats */
14720 struct cmd_clear_vf_stats_result {
14721         cmdline_fixed_string_t clear;
14722         cmdline_fixed_string_t vf;
14723         cmdline_fixed_string_t stats;
14724         portid_t port_id;
14725         uint16_t vf_id;
14726 };
14727
14728 /* Common CLI fields clear vf stats*/
14729 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14730         TOKEN_STRING_INITIALIZER
14731                 (struct cmd_clear_vf_stats_result,
14732                  clear, "clear");
14733 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14734         TOKEN_STRING_INITIALIZER
14735                 (struct cmd_clear_vf_stats_result,
14736                  vf, "vf");
14737 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14738         TOKEN_STRING_INITIALIZER
14739                 (struct cmd_clear_vf_stats_result,
14740                  stats, "stats");
14741 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14742         TOKEN_NUM_INITIALIZER
14743                 (struct cmd_clear_vf_stats_result,
14744                  port_id, UINT16);
14745 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14746         TOKEN_NUM_INITIALIZER
14747                 (struct cmd_clear_vf_stats_result,
14748                  vf_id, UINT16);
14749
14750 static void
14751 cmd_clear_vf_stats_parsed(
14752         void *parsed_result,
14753         __attribute__((unused)) struct cmdline *cl,
14754         __attribute__((unused)) void *data)
14755 {
14756         struct cmd_clear_vf_stats_result *res = parsed_result;
14757         int ret = -ENOTSUP;
14758
14759         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14760                 return;
14761
14762 #ifdef RTE_LIBRTE_I40E_PMD
14763         if (ret == -ENOTSUP)
14764                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14765                                                   res->vf_id);
14766 #endif
14767 #ifdef RTE_LIBRTE_BNXT_PMD
14768         if (ret == -ENOTSUP)
14769                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14770                                                   res->vf_id);
14771 #endif
14772
14773         switch (ret) {
14774         case 0:
14775                 break;
14776         case -EINVAL:
14777                 printf("invalid vf_id %d\n", res->vf_id);
14778                 break;
14779         case -ENODEV:
14780                 printf("invalid port_id %d\n", res->port_id);
14781                 break;
14782         case -ENOTSUP:
14783                 printf("function not implemented\n");
14784                 break;
14785         default:
14786                 printf("programming error: (%s)\n", strerror(-ret));
14787         }
14788 }
14789
14790 cmdline_parse_inst_t cmd_clear_vf_stats = {
14791         .f = cmd_clear_vf_stats_parsed,
14792         .data = NULL,
14793         .help_str = "clear vf stats <port_id> <vf_id>",
14794         .tokens = {
14795                 (void *)&cmd_clear_vf_stats_clear,
14796                 (void *)&cmd_clear_vf_stats_vf,
14797                 (void *)&cmd_clear_vf_stats_stats,
14798                 (void *)&cmd_clear_vf_stats_port_id,
14799                 (void *)&cmd_clear_vf_stats_vf_id,
14800                 NULL,
14801         },
14802 };
14803
14804 /* port config pctype mapping reset */
14805
14806 /* Common result structure for port config pctype mapping reset */
14807 struct cmd_pctype_mapping_reset_result {
14808         cmdline_fixed_string_t port;
14809         cmdline_fixed_string_t config;
14810         portid_t port_id;
14811         cmdline_fixed_string_t pctype;
14812         cmdline_fixed_string_t mapping;
14813         cmdline_fixed_string_t reset;
14814 };
14815
14816 /* Common CLI fields for port config pctype mapping reset*/
14817 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14818         TOKEN_STRING_INITIALIZER
14819                 (struct cmd_pctype_mapping_reset_result,
14820                  port, "port");
14821 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14822         TOKEN_STRING_INITIALIZER
14823                 (struct cmd_pctype_mapping_reset_result,
14824                  config, "config");
14825 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14826         TOKEN_NUM_INITIALIZER
14827                 (struct cmd_pctype_mapping_reset_result,
14828                  port_id, UINT16);
14829 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14830         TOKEN_STRING_INITIALIZER
14831                 (struct cmd_pctype_mapping_reset_result,
14832                  pctype, "pctype");
14833 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14834         TOKEN_STRING_INITIALIZER
14835                 (struct cmd_pctype_mapping_reset_result,
14836                  mapping, "mapping");
14837 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14838         TOKEN_STRING_INITIALIZER
14839                 (struct cmd_pctype_mapping_reset_result,
14840                  reset, "reset");
14841
14842 static void
14843 cmd_pctype_mapping_reset_parsed(
14844         void *parsed_result,
14845         __attribute__((unused)) struct cmdline *cl,
14846         __attribute__((unused)) void *data)
14847 {
14848         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14849         int ret = -ENOTSUP;
14850
14851         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14852                 return;
14853
14854 #ifdef RTE_LIBRTE_I40E_PMD
14855         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14856 #endif
14857
14858         switch (ret) {
14859         case 0:
14860                 break;
14861         case -ENODEV:
14862                 printf("invalid port_id %d\n", res->port_id);
14863                 break;
14864         case -ENOTSUP:
14865                 printf("function not implemented\n");
14866                 break;
14867         default:
14868                 printf("programming error: (%s)\n", strerror(-ret));
14869         }
14870 }
14871
14872 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14873         .f = cmd_pctype_mapping_reset_parsed,
14874         .data = NULL,
14875         .help_str = "port config <port_id> pctype mapping reset",
14876         .tokens = {
14877                 (void *)&cmd_pctype_mapping_reset_port,
14878                 (void *)&cmd_pctype_mapping_reset_config,
14879                 (void *)&cmd_pctype_mapping_reset_port_id,
14880                 (void *)&cmd_pctype_mapping_reset_pctype,
14881                 (void *)&cmd_pctype_mapping_reset_mapping,
14882                 (void *)&cmd_pctype_mapping_reset_reset,
14883                 NULL,
14884         },
14885 };
14886
14887 /* show port pctype mapping */
14888
14889 /* Common result structure for show port pctype mapping */
14890 struct cmd_pctype_mapping_get_result {
14891         cmdline_fixed_string_t show;
14892         cmdline_fixed_string_t port;
14893         portid_t port_id;
14894         cmdline_fixed_string_t pctype;
14895         cmdline_fixed_string_t mapping;
14896 };
14897
14898 /* Common CLI fields for pctype mapping get */
14899 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14900         TOKEN_STRING_INITIALIZER
14901                 (struct cmd_pctype_mapping_get_result,
14902                  show, "show");
14903 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14904         TOKEN_STRING_INITIALIZER
14905                 (struct cmd_pctype_mapping_get_result,
14906                  port, "port");
14907 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14908         TOKEN_NUM_INITIALIZER
14909                 (struct cmd_pctype_mapping_get_result,
14910                  port_id, UINT16);
14911 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14912         TOKEN_STRING_INITIALIZER
14913                 (struct cmd_pctype_mapping_get_result,
14914                  pctype, "pctype");
14915 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14916         TOKEN_STRING_INITIALIZER
14917                 (struct cmd_pctype_mapping_get_result,
14918                  mapping, "mapping");
14919
14920 static void
14921 cmd_pctype_mapping_get_parsed(
14922         void *parsed_result,
14923         __attribute__((unused)) struct cmdline *cl,
14924         __attribute__((unused)) void *data)
14925 {
14926         struct cmd_pctype_mapping_get_result *res = parsed_result;
14927         int ret = -ENOTSUP;
14928 #ifdef RTE_LIBRTE_I40E_PMD
14929         struct rte_pmd_i40e_flow_type_mapping
14930                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14931         int i, j, first_pctype;
14932 #endif
14933
14934         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14935                 return;
14936
14937 #ifdef RTE_LIBRTE_I40E_PMD
14938         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14939 #endif
14940
14941         switch (ret) {
14942         case 0:
14943                 break;
14944         case -ENODEV:
14945                 printf("invalid port_id %d\n", res->port_id);
14946                 return;
14947         case -ENOTSUP:
14948                 printf("function not implemented\n");
14949                 return;
14950         default:
14951                 printf("programming error: (%s)\n", strerror(-ret));
14952                 return;
14953         }
14954
14955 #ifdef RTE_LIBRTE_I40E_PMD
14956         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14957                 if (mapping[i].pctype != 0ULL) {
14958                         first_pctype = 1;
14959
14960                         printf("pctype: ");
14961                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14962                                 if (mapping[i].pctype & (1ULL << j)) {
14963                                         printf(first_pctype ?
14964                                                "%02d" : ",%02d", j);
14965                                         first_pctype = 0;
14966                                 }
14967                         }
14968                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14969                 }
14970         }
14971 #endif
14972 }
14973
14974 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14975         .f = cmd_pctype_mapping_get_parsed,
14976         .data = NULL,
14977         .help_str = "show port <port_id> pctype mapping",
14978         .tokens = {
14979                 (void *)&cmd_pctype_mapping_get_show,
14980                 (void *)&cmd_pctype_mapping_get_port,
14981                 (void *)&cmd_pctype_mapping_get_port_id,
14982                 (void *)&cmd_pctype_mapping_get_pctype,
14983                 (void *)&cmd_pctype_mapping_get_mapping,
14984                 NULL,
14985         },
14986 };
14987
14988 /* port config pctype mapping update */
14989
14990 /* Common result structure for port config pctype mapping update */
14991 struct cmd_pctype_mapping_update_result {
14992         cmdline_fixed_string_t port;
14993         cmdline_fixed_string_t config;
14994         portid_t port_id;
14995         cmdline_fixed_string_t pctype;
14996         cmdline_fixed_string_t mapping;
14997         cmdline_fixed_string_t update;
14998         cmdline_fixed_string_t pctype_list;
14999         uint16_t flow_type;
15000 };
15001
15002 /* Common CLI fields for pctype mapping update*/
15003 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15004         TOKEN_STRING_INITIALIZER
15005                 (struct cmd_pctype_mapping_update_result,
15006                  port, "port");
15007 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15008         TOKEN_STRING_INITIALIZER
15009                 (struct cmd_pctype_mapping_update_result,
15010                  config, "config");
15011 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15012         TOKEN_NUM_INITIALIZER
15013                 (struct cmd_pctype_mapping_update_result,
15014                  port_id, UINT16);
15015 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15016         TOKEN_STRING_INITIALIZER
15017                 (struct cmd_pctype_mapping_update_result,
15018                  pctype, "pctype");
15019 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15020         TOKEN_STRING_INITIALIZER
15021                 (struct cmd_pctype_mapping_update_result,
15022                  mapping, "mapping");
15023 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15024         TOKEN_STRING_INITIALIZER
15025                 (struct cmd_pctype_mapping_update_result,
15026                  update, "update");
15027 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15028         TOKEN_STRING_INITIALIZER
15029                 (struct cmd_pctype_mapping_update_result,
15030                  pctype_list, NULL);
15031 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15032         TOKEN_NUM_INITIALIZER
15033                 (struct cmd_pctype_mapping_update_result,
15034                  flow_type, UINT16);
15035
15036 static void
15037 cmd_pctype_mapping_update_parsed(
15038         void *parsed_result,
15039         __attribute__((unused)) struct cmdline *cl,
15040         __attribute__((unused)) void *data)
15041 {
15042         struct cmd_pctype_mapping_update_result *res = parsed_result;
15043         int ret = -ENOTSUP;
15044 #ifdef RTE_LIBRTE_I40E_PMD
15045         struct rte_pmd_i40e_flow_type_mapping mapping;
15046         unsigned int i;
15047         unsigned int nb_item;
15048         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15049 #endif
15050
15051         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15052                 return;
15053
15054 #ifdef RTE_LIBRTE_I40E_PMD
15055         nb_item = parse_item_list(res->pctype_list, "pctypes",
15056                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15057         mapping.flow_type = res->flow_type;
15058         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15059                 mapping.pctype |= (1ULL << pctype_list[i]);
15060         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15061                                                 &mapping,
15062                                                 1,
15063                                                 0);
15064 #endif
15065
15066         switch (ret) {
15067         case 0:
15068                 break;
15069         case -EINVAL:
15070                 printf("invalid pctype or flow type\n");
15071                 break;
15072         case -ENODEV:
15073                 printf("invalid port_id %d\n", res->port_id);
15074                 break;
15075         case -ENOTSUP:
15076                 printf("function not implemented\n");
15077                 break;
15078         default:
15079                 printf("programming error: (%s)\n", strerror(-ret));
15080         }
15081 }
15082
15083 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15084         .f = cmd_pctype_mapping_update_parsed,
15085         .data = NULL,
15086         .help_str = "port config <port_id> pctype mapping update"
15087         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15088         .tokens = {
15089                 (void *)&cmd_pctype_mapping_update_port,
15090                 (void *)&cmd_pctype_mapping_update_config,
15091                 (void *)&cmd_pctype_mapping_update_port_id,
15092                 (void *)&cmd_pctype_mapping_update_pctype,
15093                 (void *)&cmd_pctype_mapping_update_mapping,
15094                 (void *)&cmd_pctype_mapping_update_update,
15095                 (void *)&cmd_pctype_mapping_update_pc_type,
15096                 (void *)&cmd_pctype_mapping_update_flow_type,
15097                 NULL,
15098         },
15099 };
15100
15101 /* ptype mapping get */
15102
15103 /* Common result structure for ptype mapping get */
15104 struct cmd_ptype_mapping_get_result {
15105         cmdline_fixed_string_t ptype;
15106         cmdline_fixed_string_t mapping;
15107         cmdline_fixed_string_t get;
15108         portid_t port_id;
15109         uint8_t valid_only;
15110 };
15111
15112 /* Common CLI fields for ptype mapping get */
15113 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15114         TOKEN_STRING_INITIALIZER
15115                 (struct cmd_ptype_mapping_get_result,
15116                  ptype, "ptype");
15117 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15118         TOKEN_STRING_INITIALIZER
15119                 (struct cmd_ptype_mapping_get_result,
15120                  mapping, "mapping");
15121 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15122         TOKEN_STRING_INITIALIZER
15123                 (struct cmd_ptype_mapping_get_result,
15124                  get, "get");
15125 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15126         TOKEN_NUM_INITIALIZER
15127                 (struct cmd_ptype_mapping_get_result,
15128                  port_id, UINT16);
15129 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15130         TOKEN_NUM_INITIALIZER
15131                 (struct cmd_ptype_mapping_get_result,
15132                  valid_only, UINT8);
15133
15134 static void
15135 cmd_ptype_mapping_get_parsed(
15136         void *parsed_result,
15137         __attribute__((unused)) struct cmdline *cl,
15138         __attribute__((unused)) void *data)
15139 {
15140         struct cmd_ptype_mapping_get_result *res = parsed_result;
15141         int ret = -ENOTSUP;
15142 #ifdef RTE_LIBRTE_I40E_PMD
15143         int max_ptype_num = 256;
15144         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15145         uint16_t count;
15146         int i;
15147 #endif
15148
15149         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15150                 return;
15151
15152 #ifdef RTE_LIBRTE_I40E_PMD
15153         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15154                                         mapping,
15155                                         max_ptype_num,
15156                                         &count,
15157                                         res->valid_only);
15158 #endif
15159
15160         switch (ret) {
15161         case 0:
15162                 break;
15163         case -ENODEV:
15164                 printf("invalid port_id %d\n", res->port_id);
15165                 break;
15166         case -ENOTSUP:
15167                 printf("function not implemented\n");
15168                 break;
15169         default:
15170                 printf("programming error: (%s)\n", strerror(-ret));
15171         }
15172
15173 #ifdef RTE_LIBRTE_I40E_PMD
15174         if (!ret) {
15175                 for (i = 0; i < count; i++)
15176                         printf("%3d\t0x%08x\n",
15177                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15178         }
15179 #endif
15180 }
15181
15182 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15183         .f = cmd_ptype_mapping_get_parsed,
15184         .data = NULL,
15185         .help_str = "ptype mapping get <port_id> <valid_only>",
15186         .tokens = {
15187                 (void *)&cmd_ptype_mapping_get_ptype,
15188                 (void *)&cmd_ptype_mapping_get_mapping,
15189                 (void *)&cmd_ptype_mapping_get_get,
15190                 (void *)&cmd_ptype_mapping_get_port_id,
15191                 (void *)&cmd_ptype_mapping_get_valid_only,
15192                 NULL,
15193         },
15194 };
15195
15196 /* ptype mapping replace */
15197
15198 /* Common result structure for ptype mapping replace */
15199 struct cmd_ptype_mapping_replace_result {
15200         cmdline_fixed_string_t ptype;
15201         cmdline_fixed_string_t mapping;
15202         cmdline_fixed_string_t replace;
15203         portid_t port_id;
15204         uint32_t target;
15205         uint8_t mask;
15206         uint32_t pkt_type;
15207 };
15208
15209 /* Common CLI fields for ptype mapping replace */
15210 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15211         TOKEN_STRING_INITIALIZER
15212                 (struct cmd_ptype_mapping_replace_result,
15213                  ptype, "ptype");
15214 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15215         TOKEN_STRING_INITIALIZER
15216                 (struct cmd_ptype_mapping_replace_result,
15217                  mapping, "mapping");
15218 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15219         TOKEN_STRING_INITIALIZER
15220                 (struct cmd_ptype_mapping_replace_result,
15221                  replace, "replace");
15222 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15223         TOKEN_NUM_INITIALIZER
15224                 (struct cmd_ptype_mapping_replace_result,
15225                  port_id, UINT16);
15226 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15227         TOKEN_NUM_INITIALIZER
15228                 (struct cmd_ptype_mapping_replace_result,
15229                  target, UINT32);
15230 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15231         TOKEN_NUM_INITIALIZER
15232                 (struct cmd_ptype_mapping_replace_result,
15233                  mask, UINT8);
15234 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15235         TOKEN_NUM_INITIALIZER
15236                 (struct cmd_ptype_mapping_replace_result,
15237                  pkt_type, UINT32);
15238
15239 static void
15240 cmd_ptype_mapping_replace_parsed(
15241         void *parsed_result,
15242         __attribute__((unused)) struct cmdline *cl,
15243         __attribute__((unused)) void *data)
15244 {
15245         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15246         int ret = -ENOTSUP;
15247
15248         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15249                 return;
15250
15251 #ifdef RTE_LIBRTE_I40E_PMD
15252         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15253                                         res->target,
15254                                         res->mask,
15255                                         res->pkt_type);
15256 #endif
15257
15258         switch (ret) {
15259         case 0:
15260                 break;
15261         case -EINVAL:
15262                 printf("invalid ptype 0x%8x or 0x%8x\n",
15263                                 res->target, res->pkt_type);
15264                 break;
15265         case -ENODEV:
15266                 printf("invalid port_id %d\n", res->port_id);
15267                 break;
15268         case -ENOTSUP:
15269                 printf("function not implemented\n");
15270                 break;
15271         default:
15272                 printf("programming error: (%s)\n", strerror(-ret));
15273         }
15274 }
15275
15276 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15277         .f = cmd_ptype_mapping_replace_parsed,
15278         .data = NULL,
15279         .help_str =
15280                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15281         .tokens = {
15282                 (void *)&cmd_ptype_mapping_replace_ptype,
15283                 (void *)&cmd_ptype_mapping_replace_mapping,
15284                 (void *)&cmd_ptype_mapping_replace_replace,
15285                 (void *)&cmd_ptype_mapping_replace_port_id,
15286                 (void *)&cmd_ptype_mapping_replace_target,
15287                 (void *)&cmd_ptype_mapping_replace_mask,
15288                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15289                 NULL,
15290         },
15291 };
15292
15293 /* ptype mapping reset */
15294
15295 /* Common result structure for ptype mapping reset */
15296 struct cmd_ptype_mapping_reset_result {
15297         cmdline_fixed_string_t ptype;
15298         cmdline_fixed_string_t mapping;
15299         cmdline_fixed_string_t reset;
15300         portid_t port_id;
15301 };
15302
15303 /* Common CLI fields for ptype mapping reset*/
15304 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15305         TOKEN_STRING_INITIALIZER
15306                 (struct cmd_ptype_mapping_reset_result,
15307                  ptype, "ptype");
15308 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15309         TOKEN_STRING_INITIALIZER
15310                 (struct cmd_ptype_mapping_reset_result,
15311                  mapping, "mapping");
15312 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15313         TOKEN_STRING_INITIALIZER
15314                 (struct cmd_ptype_mapping_reset_result,
15315                  reset, "reset");
15316 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15317         TOKEN_NUM_INITIALIZER
15318                 (struct cmd_ptype_mapping_reset_result,
15319                  port_id, UINT16);
15320
15321 static void
15322 cmd_ptype_mapping_reset_parsed(
15323         void *parsed_result,
15324         __attribute__((unused)) struct cmdline *cl,
15325         __attribute__((unused)) void *data)
15326 {
15327         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15328         int ret = -ENOTSUP;
15329
15330         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15331                 return;
15332
15333 #ifdef RTE_LIBRTE_I40E_PMD
15334         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15335 #endif
15336
15337         switch (ret) {
15338         case 0:
15339                 break;
15340         case -ENODEV:
15341                 printf("invalid port_id %d\n", res->port_id);
15342                 break;
15343         case -ENOTSUP:
15344                 printf("function not implemented\n");
15345                 break;
15346         default:
15347                 printf("programming error: (%s)\n", strerror(-ret));
15348         }
15349 }
15350
15351 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15352         .f = cmd_ptype_mapping_reset_parsed,
15353         .data = NULL,
15354         .help_str = "ptype mapping reset <port_id>",
15355         .tokens = {
15356                 (void *)&cmd_ptype_mapping_reset_ptype,
15357                 (void *)&cmd_ptype_mapping_reset_mapping,
15358                 (void *)&cmd_ptype_mapping_reset_reset,
15359                 (void *)&cmd_ptype_mapping_reset_port_id,
15360                 NULL,
15361         },
15362 };
15363
15364 /* ptype mapping update */
15365
15366 /* Common result structure for ptype mapping update */
15367 struct cmd_ptype_mapping_update_result {
15368         cmdline_fixed_string_t ptype;
15369         cmdline_fixed_string_t mapping;
15370         cmdline_fixed_string_t reset;
15371         portid_t port_id;
15372         uint8_t hw_ptype;
15373         uint32_t sw_ptype;
15374 };
15375
15376 /* Common CLI fields for ptype mapping update*/
15377 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15378         TOKEN_STRING_INITIALIZER
15379                 (struct cmd_ptype_mapping_update_result,
15380                  ptype, "ptype");
15381 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15382         TOKEN_STRING_INITIALIZER
15383                 (struct cmd_ptype_mapping_update_result,
15384                  mapping, "mapping");
15385 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15386         TOKEN_STRING_INITIALIZER
15387                 (struct cmd_ptype_mapping_update_result,
15388                  reset, "update");
15389 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15390         TOKEN_NUM_INITIALIZER
15391                 (struct cmd_ptype_mapping_update_result,
15392                  port_id, UINT16);
15393 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15394         TOKEN_NUM_INITIALIZER
15395                 (struct cmd_ptype_mapping_update_result,
15396                  hw_ptype, UINT8);
15397 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15398         TOKEN_NUM_INITIALIZER
15399                 (struct cmd_ptype_mapping_update_result,
15400                  sw_ptype, UINT32);
15401
15402 static void
15403 cmd_ptype_mapping_update_parsed(
15404         void *parsed_result,
15405         __attribute__((unused)) struct cmdline *cl,
15406         __attribute__((unused)) void *data)
15407 {
15408         struct cmd_ptype_mapping_update_result *res = parsed_result;
15409         int ret = -ENOTSUP;
15410 #ifdef RTE_LIBRTE_I40E_PMD
15411         struct rte_pmd_i40e_ptype_mapping mapping;
15412 #endif
15413         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15414                 return;
15415
15416 #ifdef RTE_LIBRTE_I40E_PMD
15417         mapping.hw_ptype = res->hw_ptype;
15418         mapping.sw_ptype = res->sw_ptype;
15419         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15420                                                 &mapping,
15421                                                 1,
15422                                                 0);
15423 #endif
15424
15425         switch (ret) {
15426         case 0:
15427                 break;
15428         case -EINVAL:
15429                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15430                 break;
15431         case -ENODEV:
15432                 printf("invalid port_id %d\n", res->port_id);
15433                 break;
15434         case -ENOTSUP:
15435                 printf("function not implemented\n");
15436                 break;
15437         default:
15438                 printf("programming error: (%s)\n", strerror(-ret));
15439         }
15440 }
15441
15442 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15443         .f = cmd_ptype_mapping_update_parsed,
15444         .data = NULL,
15445         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15446         .tokens = {
15447                 (void *)&cmd_ptype_mapping_update_ptype,
15448                 (void *)&cmd_ptype_mapping_update_mapping,
15449                 (void *)&cmd_ptype_mapping_update_update,
15450                 (void *)&cmd_ptype_mapping_update_port_id,
15451                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15452                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15453                 NULL,
15454         },
15455 };
15456
15457 /* Common result structure for file commands */
15458 struct cmd_cmdfile_result {
15459         cmdline_fixed_string_t load;
15460         cmdline_fixed_string_t filename;
15461 };
15462
15463 /* Common CLI fields for file commands */
15464 cmdline_parse_token_string_t cmd_load_cmdfile =
15465         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15466 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15467         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15468
15469 static void
15470 cmd_load_from_file_parsed(
15471         void *parsed_result,
15472         __attribute__((unused)) struct cmdline *cl,
15473         __attribute__((unused)) void *data)
15474 {
15475         struct cmd_cmdfile_result *res = parsed_result;
15476
15477         cmdline_read_from_file(res->filename);
15478 }
15479
15480 cmdline_parse_inst_t cmd_load_from_file = {
15481         .f = cmd_load_from_file_parsed,
15482         .data = NULL,
15483         .help_str = "load <filename>",
15484         .tokens = {
15485                 (void *)&cmd_load_cmdfile,
15486                 (void *)&cmd_load_cmdfile_filename,
15487                 NULL,
15488         },
15489 };
15490
15491 /* ******************************************************************************** */
15492
15493 /* list of instructions */
15494 cmdline_parse_ctx_t main_ctx[] = {
15495         (cmdline_parse_inst_t *)&cmd_help_brief,
15496         (cmdline_parse_inst_t *)&cmd_help_long,
15497         (cmdline_parse_inst_t *)&cmd_quit,
15498         (cmdline_parse_inst_t *)&cmd_load_from_file,
15499         (cmdline_parse_inst_t *)&cmd_showport,
15500         (cmdline_parse_inst_t *)&cmd_showqueue,
15501         (cmdline_parse_inst_t *)&cmd_showportall,
15502         (cmdline_parse_inst_t *)&cmd_showcfg,
15503         (cmdline_parse_inst_t *)&cmd_start,
15504         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15505         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15506         (cmdline_parse_inst_t *)&cmd_set_link_up,
15507         (cmdline_parse_inst_t *)&cmd_set_link_down,
15508         (cmdline_parse_inst_t *)&cmd_reset,
15509         (cmdline_parse_inst_t *)&cmd_set_numbers,
15510         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15511         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15512         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15513         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15514         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15515         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15516         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15517         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15518         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15519         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15520         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15521         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15522         (cmdline_parse_inst_t *)&cmd_set_link_check,
15523         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15524         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15525         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15526         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15527 #ifdef RTE_LIBRTE_PMD_BOND
15528         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15529         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15530         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15531         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15532         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15533         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15534         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15535         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15536         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15537         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15538         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15539 #endif
15540         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15541         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15542         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15543         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15544         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15545         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15546         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15547         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15548         (cmdline_parse_inst_t *)&cmd_csum_set,
15549         (cmdline_parse_inst_t *)&cmd_csum_show,
15550         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15551         (cmdline_parse_inst_t *)&cmd_tso_set,
15552         (cmdline_parse_inst_t *)&cmd_tso_show,
15553         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15554         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15555         (cmdline_parse_inst_t *)&cmd_gro_enable,
15556         (cmdline_parse_inst_t *)&cmd_gro_flush,
15557         (cmdline_parse_inst_t *)&cmd_gro_show,
15558         (cmdline_parse_inst_t *)&cmd_gso_enable,
15559         (cmdline_parse_inst_t *)&cmd_gso_size,
15560         (cmdline_parse_inst_t *)&cmd_gso_show,
15561         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15562         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15568         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15569         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15570         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15571         (cmdline_parse_inst_t *)&cmd_config_dcb,
15572         (cmdline_parse_inst_t *)&cmd_read_reg,
15573         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15574         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15575         (cmdline_parse_inst_t *)&cmd_write_reg,
15576         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15577         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15578         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15579         (cmdline_parse_inst_t *)&cmd_stop,
15580         (cmdline_parse_inst_t *)&cmd_mac_addr,
15581         (cmdline_parse_inst_t *)&cmd_set_qmap,
15582         (cmdline_parse_inst_t *)&cmd_operate_port,
15583         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15584         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15585         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15586         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15587         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15588         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15589         (cmdline_parse_inst_t *)&cmd_config_mtu,
15590         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15591         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15592         (cmdline_parse_inst_t *)&cmd_config_rss,
15593         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15594         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15595         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15596         (cmdline_parse_inst_t *)&cmd_showport_reta,
15597         (cmdline_parse_inst_t *)&cmd_config_burst,
15598         (cmdline_parse_inst_t *)&cmd_config_thresh,
15599         (cmdline_parse_inst_t *)&cmd_config_threshold,
15600         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15601         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15602         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15603         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15604         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15605         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15606         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15607         (cmdline_parse_inst_t *)&cmd_global_config,
15608         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15609         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15610         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15611         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15612         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15613         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15614         (cmdline_parse_inst_t *)&cmd_dump,
15615         (cmdline_parse_inst_t *)&cmd_dump_one,
15616         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15617         (cmdline_parse_inst_t *)&cmd_syn_filter,
15618         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15619         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15620         (cmdline_parse_inst_t *)&cmd_flex_filter,
15621         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15622         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15623         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15624         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15625         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15626         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15627         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15628         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15629         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15630         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15631         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15632         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15633         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15634         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15635         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15636         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15637         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15638         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15639         (cmdline_parse_inst_t *)&cmd_flow,
15640         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15641         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15642         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15643         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15644         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15645         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15646         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15647         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15648         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15649         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15650         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15651         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15652         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15653         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15654         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15655         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15656         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15657         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15658         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15659         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15660         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15661         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15662         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15663         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15664         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15665         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15666         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15667         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15668         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15669         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15670         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15671         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15672         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15673         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15674         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15675         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15676         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15677         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15678         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15679         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15680         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15681         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15682         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15683         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15684         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15685 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15686         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15687 #endif
15688         (cmdline_parse_inst_t *)&cmd_ddp_add,
15689         (cmdline_parse_inst_t *)&cmd_ddp_del,
15690         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15691         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15692         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15693         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15694         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15695         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15696         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15697         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15698
15699         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15700         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15701         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15702         (cmdline_parse_inst_t *)&cmd_queue_region,
15703         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15704         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15705         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15706         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15707         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15708         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15709         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15710         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15711         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15712         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15713         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15714         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15715         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15716         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15717         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15718         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15719         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15720         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15721         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15722         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15723         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15724         NULL,
15725 };
15726
15727 /* read cmdline commands from file */
15728 void
15729 cmdline_read_from_file(const char *filename)
15730 {
15731         struct cmdline *cl;
15732
15733         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15734         if (cl == NULL) {
15735                 printf("Failed to create file based cmdline context: %s\n",
15736                        filename);
15737                 return;
15738         }
15739
15740         cmdline_interact(cl);
15741         cmdline_quit(cl);
15742
15743         cmdline_free(cl);
15744
15745         printf("Read CLI commands from %s\n", filename);
15746 }
15747
15748 /* prompt function, called from main on MASTER lcore */
15749 void
15750 prompt(void)
15751 {
15752         /* initialize non-constant commands */
15753         cmd_set_fwd_mode_init();
15754         cmd_set_fwd_retry_mode_init();
15755
15756         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15757         if (testpmd_cl == NULL)
15758                 return;
15759         cmdline_interact(testpmd_cl);
15760         cmdline_stdin_exit(testpmd_cl);
15761 }
15762
15763 void
15764 prompt_exit(void)
15765 {
15766         if (testpmd_cl != NULL)
15767                 cmdline_quit(testpmd_cl);
15768 }
15769
15770 static void
15771 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15772 {
15773         if (id == (portid_t)RTE_PORT_ALL) {
15774                 portid_t pid;
15775
15776                 RTE_ETH_FOREACH_DEV(pid) {
15777                         /* check if need_reconfig has been set to 1 */
15778                         if (ports[pid].need_reconfig == 0)
15779                                 ports[pid].need_reconfig = dev;
15780                         /* check if need_reconfig_queues has been set to 1 */
15781                         if (ports[pid].need_reconfig_queues == 0)
15782                                 ports[pid].need_reconfig_queues = queue;
15783                 }
15784         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15785                 /* check if need_reconfig has been set to 1 */
15786                 if (ports[id].need_reconfig == 0)
15787                         ports[id].need_reconfig = dev;
15788                 /* check if need_reconfig_queues has been set to 1 */
15789                 if (ports[id].need_reconfig_queues == 0)
15790                         ports[id].need_reconfig_queues = queue;
15791         }
15792 }