doc: add octeontx mempool guide
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set xstats-hide-zero on|off\n"
530                         "    Set the option to hide the zero values"
531                         " for xstats display.\n"
532
533                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
534                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
535
536                         "set port (port_id) vf (vf_id) (mac_addr)"
537                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
538                         "   Add/Remove unicast or multicast MAC addr filter"
539                         " for a VF.\n\n"
540
541                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
542                         "|MPE) (on|off)\n"
543                         "    AUPE:accepts untagged VLAN;"
544                         "ROPE:accept unicast hash\n\n"
545                         "    BAM:accepts broadcast packets;"
546                         "MPE:accepts all multicast packets\n\n"
547                         "    Enable/Disable a VF receive mode of a port\n\n"
548
549                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
550                         "    Set rate limit for a queue of a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rate (rate_num) "
553                         "queue_mask (queue_mask_value)\n"
554                         "    Set rate limit for queues in VF of a port\n\n"
555
556                         "set port (port_id) mirror-rule (rule_id)"
557                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
558                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
559                         "   Set pool or vlan type mirror rule on a port.\n"
560                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
561                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
562                         " to pool 0.\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (uplink-mirror|downlink-mirror) dst-pool"
566                         " (pool_id) (on|off)\n"
567                         "   Set uplink or downlink type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
569                         " 0 on' enable mirror income traffic to pool 0.\n\n"
570
571                         "reset port (port_id) mirror-rule (rule_id)\n"
572                         "   Reset a mirror rule.\n\n"
573
574                         "set flush_rx (on|off)\n"
575                         "   Flush (default) or don't flush RX streams before"
576                         " forwarding. Mainly used with PCAP drivers.\n\n"
577
578                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the bypass mode for the lowest port on bypass enabled"
580                         " NIC.\n\n"
581
582                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
583                         "mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the event required to initiate specified bypass mode for"
585                         " the lowest port on a bypass enabled NIC where:\n"
586                         "       timeout   = enable bypass after watchdog timeout.\n"
587                         "       os_on     = enable bypass when OS/board is powered on.\n"
588                         "       os_off    = enable bypass when OS/board is powered off.\n"
589                         "       power_on  = enable bypass when power supply is turned on.\n"
590                         "       power_off = enable bypass when power supply is turned off."
591                         "\n\n"
592
593                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
594                         "   Set the bypass watchdog timeout to 'n' seconds"
595                         " where 0 = instant.\n\n"
596
597                         "show bypass config (port_id)\n"
598                         "   Show the bypass configuration for a bypass enabled NIC"
599                         " using the lowest port on the NIC.\n\n"
600
601 #ifdef RTE_LIBRTE_PMD_BOND
602                         "create bonded device (mode) (socket)\n"
603                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
604
605                         "add bonding slave (slave_id) (port_id)\n"
606                         "       Add a slave device to a bonded device.\n\n"
607
608                         "remove bonding slave (slave_id) (port_id)\n"
609                         "       Remove a slave device from a bonded device.\n\n"
610
611                         "set bonding mode (value) (port_id)\n"
612                         "       Set the bonding mode on a bonded device.\n\n"
613
614                         "set bonding primary (slave_id) (port_id)\n"
615                         "       Set the primary slave for a bonded device.\n\n"
616
617                         "show bonding config (port_id)\n"
618                         "       Show the bonding config for port_id.\n\n"
619
620                         "set bonding mac_addr (port_id) (address)\n"
621                         "       Set the MAC address of a bonded device.\n\n"
622
623                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
624                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
625
626                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
627                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
628
629                         "set bonding mon_period (port_id) (value)\n"
630                         "       Set the bonding link status monitoring polling period in ms.\n\n"
631
632                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
633                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
634
635 #endif
636                         "set link-up port (port_id)\n"
637                         "       Set link up for a port.\n\n"
638
639                         "set link-down port (port_id)\n"
640                         "       Set link down for a port.\n\n"
641
642                         "E-tag set insertion on port-tag-id (value)"
643                         " port (port_id) vf (vf_id)\n"
644                         "    Enable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
647                         "    Disable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set stripping (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag stripping on a port\n\n"
651
652                         "E-tag set forwarding (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag based forwarding"
654                         " on a port\n\n"
655
656                         "E-tag set filter add e-tag-id (value) dst-pool"
657                         " (pool_id) port (port_id)\n"
658                         "    Add an E-tag forwarding filter on a port\n\n"
659
660                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
661                         "    Delete an E-tag forwarding filter on a port\n\n"
662
663 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
664                         "set port tm hierarchy default (port_id)\n"
665                         "       Set default traffic Management hierarchy on a port\n\n"
666
667 #endif
668                         "ddp add (port_id) (profile_path[,output_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "queue_start_index (value) queue_num (value)\n"
688                         "    Set a queue region on a port\n\n"
689
690                         "set port (port_id) queue-region region_id (value) "
691                         "flowtype (value)\n"
692                         "    Set a flowtype region index on a port\n\n"
693
694                         "set port (port_id) queue-region UP (value) region_id (value)\n"
695                         "    Set the mapping of User Priority to "
696                         "queue region on a port\n\n"
697
698                         "set port (port_id) queue-region flush (on|off)\n"
699                         "    flush all queue region related configuration\n\n"
700
701                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n"
702                         "    meter profile add - srtcm rfc 2697\n\n"
703
704                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
705                         "    meter profile add - trtcm rfc 2698\n\n"
706
707                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
708                         "    meter profile add - trtcm rfc 4115\n\n"
709
710                         "del port meter profile (port_id) (profile_id)\n"
711                         "    meter profile delete\n\n"
712
713                         "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n"
714                         "    meter create\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter policer action (port_id) (mtr_id) (color) (action)\n"
723                         "    meter update policer action\n\n"
724
725                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
726                         "    meter update stats\n\n"
727
728                         "show port (port_id) queue-region\n"
729                         "    show all queue region related configuration info\n\n"
730
731                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
732                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
733                         "       Add port tm node private shaper profile.\n\n"
734
735                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
736                         "       Delete port tm node private shaper profile.\n\n"
737
738                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
739                         " (shaper_profile_id)\n"
740                         "       Add/update port tm node shared shaper.\n\n"
741
742                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
743                         "       Delete port tm node shared shaper.\n\n"
744
745                         "set port tm node shaper profile (port_id) (node_id)"
746                         " (shaper_profile_id)\n"
747                         "       Set port tm node shaper profile.\n\n"
748
749                         "add port tm node wred profile (port_id) (wred_profile_id)"
750                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
751                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
752                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
753                         "       Add port tm node wred profile.\n\n"
754
755                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
756                         "       Delete port tm node wred profile.\n\n"
757
758                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
759                         " (priority) (weight) (level_id) (shaper_profile_id)"
760                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
761                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
762                         "       Add port tm nonleaf node.\n\n"
763
764                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
765                         " (priority) (weight) (level_id) (shaper_profile_id)"
766                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
767                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
768                         "       Add port tm leaf node.\n\n"
769
770                         "del port tm node (port_id) (node_id)\n"
771                         "       Delete port tm node.\n\n"
772
773                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
774                         " (priority) (weight)\n"
775                         "       Set port tm node parent.\n\n"
776
777                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
778                         "       Commit tm hierarchy.\n\n"
779
780                         , list_pkt_forwarding_modes()
781                 );
782         }
783
784         if (show_all || !strcmp(res->section, "ports")) {
785
786                 cmdline_printf(
787                         cl,
788                         "\n"
789                         "Port Operations:\n"
790                         "----------------\n\n"
791
792                         "port start (port_id|all)\n"
793                         "    Start all ports or port_id.\n\n"
794
795                         "port stop (port_id|all)\n"
796                         "    Stop all ports or port_id.\n\n"
797
798                         "port close (port_id|all)\n"
799                         "    Close all ports or port_id.\n\n"
800
801                         "port attach (ident)\n"
802                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
803
804                         "port detach (port_id)\n"
805                         "    Detach physical or virtual dev by port_id\n\n"
806
807                         "port config (port_id|all)"
808                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
809                         " duplex (half|full|auto)\n"
810                         "    Set speed and duplex for all ports or port_id\n\n"
811
812                         "port config all (rxq|txq|rxd|txd) (value)\n"
813                         "    Set number for rxq/txq/rxd/txd.\n\n"
814
815                         "port config all max-pkt-len (value)\n"
816                         "    Set the max packet length.\n\n"
817
818                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
819                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
820                         " (on|off)\n"
821                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
822                         " for ports.\n\n"
823
824                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
825                         "geneve|nvgre|none|<flowtype_id>)\n"
826                         "    Set the RSS mode.\n\n"
827
828                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
829                         "    Set the RSS redirection table.\n\n"
830
831                         "port config (port_id) dcb vt (on|off) (traffic_class)"
832                         " pfc (on|off)\n"
833                         "    Set the DCB mode.\n\n"
834
835                         "port config all burst (value)\n"
836                         "    Set the number of packets per burst.\n\n"
837
838                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
839                         " (value)\n"
840                         "    Set the ring prefetch/host/writeback threshold"
841                         " for tx/rx queue.\n\n"
842
843                         "port config all (txfreet|txrst|rxfreet) (value)\n"
844                         "    Set free threshold for rx/tx, or set"
845                         " tx rs bit threshold.\n\n"
846                         "port config mtu X value\n"
847                         "    Set the MTU of port X to a given value\n\n"
848
849                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
850                         "    Start/stop a rx/tx queue of port X. Only take effect"
851                         " when port X is started\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag ether-type"
854                         " (value)\n"
855                         "    Set the value of E-tag ether-type.\n\n"
856
857                         "port config (port_id|all) l2-tunnel E-tag"
858                         " (enable|disable)\n"
859                         "    Enable/disable the E-tag support.\n\n"
860
861                         "port config (port_id) pctype mapping reset\n"
862                         "    Reset flow type to pctype mapping on a port\n\n"
863
864                         "port config (port_id) pctype mapping update"
865                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
866                         "    Update a flow type to pctype mapping item on a port\n\n"
867                 );
868         }
869
870         if (show_all || !strcmp(res->section, "registers")) {
871
872                 cmdline_printf(
873                         cl,
874                         "\n"
875                         "Registers:\n"
876                         "----------\n\n"
877
878                         "read reg (port_id) (address)\n"
879                         "    Display value of a port register.\n\n"
880
881                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
882                         "    Display a port register bit field.\n\n"
883
884                         "read regbit (port_id) (address) (bit_x)\n"
885                         "    Display a single port register bit.\n\n"
886
887                         "write reg (port_id) (address) (value)\n"
888                         "    Set value of a port register.\n\n"
889
890                         "write regfield (port_id) (address) (bit_x) (bit_y)"
891                         " (value)\n"
892                         "    Set bit field of a port register.\n\n"
893
894                         "write regbit (port_id) (address) (bit_x) (value)\n"
895                         "    Set single bit value of a port register.\n\n"
896                 );
897         }
898         if (show_all || !strcmp(res->section, "filters")) {
899
900                 cmdline_printf(
901                         cl,
902                         "\n"
903                         "filters:\n"
904                         "--------\n\n"
905
906                         "ethertype_filter (port_id) (add|del)"
907                         " (mac_addr|mac_ignr) (mac_address) ethertype"
908                         " (ether_type) (drop|fwd) queue (queue_id)\n"
909                         "    Add/Del an ethertype filter.\n\n"
910
911                         "2tuple_filter (port_id) (add|del)"
912                         " dst_port (dst_port_value) protocol (protocol_value)"
913                         " mask (mask_value) tcp_flags (tcp_flags_value)"
914                         " priority (prio_value) queue (queue_id)\n"
915                         "    Add/Del a 2tuple filter.\n\n"
916
917                         "5tuple_filter (port_id) (add|del)"
918                         " dst_ip (dst_address) src_ip (src_address)"
919                         " dst_port (dst_port_value) src_port (src_port_value)"
920                         " protocol (protocol_value)"
921                         " mask (mask_value) tcp_flags (tcp_flags_value)"
922                         " priority (prio_value) queue (queue_id)\n"
923                         "    Add/Del a 5tuple filter.\n\n"
924
925                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
926                         "    Add/Del syn filter.\n\n"
927
928                         "flex_filter (port_id) (add|del) len (len_value)"
929                         " bytes (bytes_value) mask (mask_value)"
930                         " priority (prio_value) queue (queue_id)\n"
931                         "    Add/Del a flex filter.\n\n"
932
933                         "flow_director_filter (port_id) mode IP (add|del|update)"
934                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
935                         " src (src_ip_address) dst (dst_ip_address)"
936                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
937                         " vlan (vlan_value) flexbytes (flexbytes_value)"
938                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
939                         " fd_id (fd_id_value)\n"
940                         "    Add/Del an IP type flow director filter.\n\n"
941
942                         "flow_director_filter (port_id) mode IP (add|del|update)"
943                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
944                         " src (src_ip_address) (src_port)"
945                         " dst (dst_ip_address) (dst_port)"
946                         " tos (tos_value) ttl (ttl_value)"
947                         " vlan (vlan_value) flexbytes (flexbytes_value)"
948                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
949                         " fd_id (fd_id_value)\n"
950                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
951
952                         "flow_director_filter (port_id) mode IP (add|del|update)"
953                         " flow (ipv4-sctp|ipv6-sctp)"
954                         " src (src_ip_address) (src_port)"
955                         " dst (dst_ip_address) (dst_port)"
956                         " tag (verification_tag) "
957                         " tos (tos_value) ttl (ttl_value)"
958                         " vlan (vlan_value)"
959                         " flexbytes (flexbytes_value) (drop|fwd)"
960                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
961                         "    Add/Del a SCTP type flow director filter.\n\n"
962
963                         "flow_director_filter (port_id) mode IP (add|del|update)"
964                         " flow l2_payload ether (ethertype)"
965                         " flexbytes (flexbytes_value) (drop|fwd)"
966                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
967                         "    Add/Del a l2 payload type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
970                         " mac (mac_address) vlan (vlan_value)"
971                         " flexbytes (flexbytes_value) (drop|fwd)"
972                         " queue (queue_id) fd_id (fd_id_value)\n"
973                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
974
975                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
976                         " mac (mac_address) vlan (vlan_value)"
977                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
978                         " flexbytes (flexbytes_value) (drop|fwd)"
979                         " queue (queue_id) fd_id (fd_id_value)\n"
980                         "    Add/Del a Tunnel flow director filter.\n\n"
981
982                         "flush_flow_director (port_id)\n"
983                         "    Flush all flow director entries of a device.\n\n"
984
985                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
986                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
987                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
988                         "    Set flow director IP mask.\n\n"
989
990                         "flow_director_mask (port_id) mode MAC-VLAN"
991                         " vlan (vlan_value)\n"
992                         "    Set flow director MAC-VLAN mask.\n\n"
993
994                         "flow_director_mask (port_id) mode Tunnel"
995                         " vlan (vlan_value) mac (mac_value)"
996                         " tunnel-type (tunnel_type_value)"
997                         " tunnel-id (tunnel_id_value)\n"
998                         "    Set flow director Tunnel mask.\n\n"
999
1000                         "flow_director_flex_mask (port_id)"
1001                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1002                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1003                         " (mask)\n"
1004                         "    Configure mask of flex payload.\n\n"
1005
1006                         "flow_director_flex_payload (port_id)"
1007                         " (raw|l2|l3|l4) (config)\n"
1008                         "    Configure flex payload selection.\n\n"
1009
1010                         "get_sym_hash_ena_per_port (port_id)\n"
1011                         "    get symmetric hash enable configuration per port.\n\n"
1012
1013                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1014                         "    set symmetric hash enable configuration per port"
1015                         " to enable or disable.\n\n"
1016
1017                         "get_hash_global_config (port_id)\n"
1018                         "    Get the global configurations of hash filters.\n\n"
1019
1020                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1021                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1022                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1023                         " (enable|disable)\n"
1024                         "    Set the global configurations of hash filters.\n\n"
1025
1026                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1027                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1028                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1029                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1030                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1031                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1032                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1033                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1034                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1035                         "fld-8th|none) (select|add)\n"
1036                         "    Set the input set for hash.\n\n"
1037
1038                         "set_fdir_input_set (port_id) "
1039                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1040                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1041                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1042                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1043                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1044                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1045                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1046                         " (select|add)\n"
1047                         "    Set the input set for FDir.\n\n"
1048
1049                         "flow validate {port_id}"
1050                         " [group {group_id}] [priority {level}]"
1051                         " [ingress] [egress]"
1052                         " pattern {item} [/ {item} [...]] / end"
1053                         " actions {action} [/ {action} [...]] / end\n"
1054                         "    Check whether a flow rule can be created.\n\n"
1055
1056                         "flow create {port_id}"
1057                         " [group {group_id}] [priority {level}]"
1058                         " [ingress] [egress]"
1059                         " pattern {item} [/ {item} [...]] / end"
1060                         " actions {action} [/ {action} [...]] / end\n"
1061                         "    Create a flow rule.\n\n"
1062
1063                         "flow destroy {port_id} rule {rule_id} [...]\n"
1064                         "    Destroy specific flow rules.\n\n"
1065
1066                         "flow flush {port_id}\n"
1067                         "    Destroy all flow rules.\n\n"
1068
1069                         "flow query {port_id} {rule_id} {action}\n"
1070                         "    Query an existing flow rule.\n\n"
1071
1072                         "flow list {port_id} [group {group_id}] [...]\n"
1073                         "    List existing flow rules sorted by priority,"
1074                         " filtered by group identifiers.\n\n"
1075
1076                         "flow isolate {port_id} {boolean}\n"
1077                         "    Restrict ingress traffic to the defined"
1078                         " flow rules\n\n"
1079                 );
1080         }
1081 }
1082
1083 cmdline_parse_token_string_t cmd_help_long_help =
1084         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1085
1086 cmdline_parse_token_string_t cmd_help_long_section =
1087         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1088                         "all#control#display#config#"
1089                         "ports#registers#filters");
1090
1091 cmdline_parse_inst_t cmd_help_long = {
1092         .f = cmd_help_long_parsed,
1093         .data = NULL,
1094         .help_str = "help all|control|display|config|ports|register|filters: "
1095                 "Show help",
1096         .tokens = {
1097                 (void *)&cmd_help_long_help,
1098                 (void *)&cmd_help_long_section,
1099                 NULL,
1100         },
1101 };
1102
1103
1104 /* *** start/stop/close all ports *** */
1105 struct cmd_operate_port_result {
1106         cmdline_fixed_string_t keyword;
1107         cmdline_fixed_string_t name;
1108         cmdline_fixed_string_t value;
1109 };
1110
1111 static void cmd_operate_port_parsed(void *parsed_result,
1112                                 __attribute__((unused)) struct cmdline *cl,
1113                                 __attribute__((unused)) void *data)
1114 {
1115         struct cmd_operate_port_result *res = parsed_result;
1116
1117         if (!strcmp(res->name, "start"))
1118                 start_port(RTE_PORT_ALL);
1119         else if (!strcmp(res->name, "stop"))
1120                 stop_port(RTE_PORT_ALL);
1121         else if (!strcmp(res->name, "close"))
1122                 close_port(RTE_PORT_ALL);
1123         else if (!strcmp(res->name, "reset"))
1124                 reset_port(RTE_PORT_ALL);
1125         else
1126                 printf("Unknown parameter\n");
1127 }
1128
1129 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1130         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1131                                                                 "port");
1132 cmdline_parse_token_string_t cmd_operate_port_all_port =
1133         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1134                                                 "start#stop#close#reset");
1135 cmdline_parse_token_string_t cmd_operate_port_all_all =
1136         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1137
1138 cmdline_parse_inst_t cmd_operate_port = {
1139         .f = cmd_operate_port_parsed,
1140         .data = NULL,
1141         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1142         .tokens = {
1143                 (void *)&cmd_operate_port_all_cmd,
1144                 (void *)&cmd_operate_port_all_port,
1145                 (void *)&cmd_operate_port_all_all,
1146                 NULL,
1147         },
1148 };
1149
1150 /* *** start/stop/close specific port *** */
1151 struct cmd_operate_specific_port_result {
1152         cmdline_fixed_string_t keyword;
1153         cmdline_fixed_string_t name;
1154         uint8_t value;
1155 };
1156
1157 static void cmd_operate_specific_port_parsed(void *parsed_result,
1158                         __attribute__((unused)) struct cmdline *cl,
1159                                 __attribute__((unused)) void *data)
1160 {
1161         struct cmd_operate_specific_port_result *res = parsed_result;
1162
1163         if (!strcmp(res->name, "start"))
1164                 start_port(res->value);
1165         else if (!strcmp(res->name, "stop"))
1166                 stop_port(res->value);
1167         else if (!strcmp(res->name, "close"))
1168                 close_port(res->value);
1169         else if (!strcmp(res->name, "reset"))
1170                 reset_port(res->value);
1171         else
1172                 printf("Unknown parameter\n");
1173 }
1174
1175 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1176         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1177                                                         keyword, "port");
1178 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1179         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1180                                                 name, "start#stop#close#reset");
1181 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1182         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1183                                                         value, UINT8);
1184
1185 cmdline_parse_inst_t cmd_operate_specific_port = {
1186         .f = cmd_operate_specific_port_parsed,
1187         .data = NULL,
1188         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1189         .tokens = {
1190                 (void *)&cmd_operate_specific_port_cmd,
1191                 (void *)&cmd_operate_specific_port_port,
1192                 (void *)&cmd_operate_specific_port_id,
1193                 NULL,
1194         },
1195 };
1196
1197 /* *** attach a specified port *** */
1198 struct cmd_operate_attach_port_result {
1199         cmdline_fixed_string_t port;
1200         cmdline_fixed_string_t keyword;
1201         cmdline_fixed_string_t identifier;
1202 };
1203
1204 static void cmd_operate_attach_port_parsed(void *parsed_result,
1205                                 __attribute__((unused)) struct cmdline *cl,
1206                                 __attribute__((unused)) void *data)
1207 {
1208         struct cmd_operate_attach_port_result *res = parsed_result;
1209
1210         if (!strcmp(res->keyword, "attach"))
1211                 attach_port(res->identifier);
1212         else
1213                 printf("Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1218                         port, "port");
1219 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1221                         keyword, "attach");
1222 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1224                         identifier, NULL);
1225
1226 cmdline_parse_inst_t cmd_operate_attach_port = {
1227         .f = cmd_operate_attach_port_parsed,
1228         .data = NULL,
1229         .help_str = "port attach <identifier>: "
1230                 "(identifier: pci address or virtual dev name)",
1231         .tokens = {
1232                 (void *)&cmd_operate_attach_port_port,
1233                 (void *)&cmd_operate_attach_port_keyword,
1234                 (void *)&cmd_operate_attach_port_identifier,
1235                 NULL,
1236         },
1237 };
1238
1239 /* *** detach a specified port *** */
1240 struct cmd_operate_detach_port_result {
1241         cmdline_fixed_string_t port;
1242         cmdline_fixed_string_t keyword;
1243         portid_t port_id;
1244 };
1245
1246 static void cmd_operate_detach_port_parsed(void *parsed_result,
1247                                 __attribute__((unused)) struct cmdline *cl,
1248                                 __attribute__((unused)) void *data)
1249 {
1250         struct cmd_operate_detach_port_result *res = parsed_result;
1251
1252         if (!strcmp(res->keyword, "detach"))
1253                 detach_port(res->port_id);
1254         else
1255                 printf("Unknown parameter\n");
1256 }
1257
1258 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1259         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1260                         port, "port");
1261 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1262         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1263                         keyword, "detach");
1264 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1265         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1266                         port_id, UINT16);
1267
1268 cmdline_parse_inst_t cmd_operate_detach_port = {
1269         .f = cmd_operate_detach_port_parsed,
1270         .data = NULL,
1271         .help_str = "port detach <port_id>",
1272         .tokens = {
1273                 (void *)&cmd_operate_detach_port_port,
1274                 (void *)&cmd_operate_detach_port_keyword,
1275                 (void *)&cmd_operate_detach_port_port_id,
1276                 NULL,
1277         },
1278 };
1279
1280 /* *** configure speed for all ports *** */
1281 struct cmd_config_speed_all {
1282         cmdline_fixed_string_t port;
1283         cmdline_fixed_string_t keyword;
1284         cmdline_fixed_string_t all;
1285         cmdline_fixed_string_t item1;
1286         cmdline_fixed_string_t item2;
1287         cmdline_fixed_string_t value1;
1288         cmdline_fixed_string_t value2;
1289 };
1290
1291 static int
1292 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1293 {
1294
1295         int duplex;
1296
1297         if (!strcmp(duplexstr, "half")) {
1298                 duplex = ETH_LINK_HALF_DUPLEX;
1299         } else if (!strcmp(duplexstr, "full")) {
1300                 duplex = ETH_LINK_FULL_DUPLEX;
1301         } else if (!strcmp(duplexstr, "auto")) {
1302                 duplex = ETH_LINK_FULL_DUPLEX;
1303         } else {
1304                 printf("Unknown duplex parameter\n");
1305                 return -1;
1306         }
1307
1308         if (!strcmp(speedstr, "10")) {
1309                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1310                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1311         } else if (!strcmp(speedstr, "100")) {
1312                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1313                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1314         } else {
1315                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1316                         printf("Invalid speed/duplex parameters\n");
1317                         return -1;
1318                 }
1319                 if (!strcmp(speedstr, "1000")) {
1320                         *speed = ETH_LINK_SPEED_1G;
1321                 } else if (!strcmp(speedstr, "10000")) {
1322                         *speed = ETH_LINK_SPEED_10G;
1323                 } else if (!strcmp(speedstr, "25000")) {
1324                         *speed = ETH_LINK_SPEED_25G;
1325                 } else if (!strcmp(speedstr, "40000")) {
1326                         *speed = ETH_LINK_SPEED_40G;
1327                 } else if (!strcmp(speedstr, "50000")) {
1328                         *speed = ETH_LINK_SPEED_50G;
1329                 } else if (!strcmp(speedstr, "100000")) {
1330                         *speed = ETH_LINK_SPEED_100G;
1331                 } else if (!strcmp(speedstr, "auto")) {
1332                         *speed = ETH_LINK_SPEED_AUTONEG;
1333                 } else {
1334                         printf("Unknown speed parameter\n");
1335                         return -1;
1336                 }
1337         }
1338
1339         return 0;
1340 }
1341
1342 static void
1343 cmd_config_speed_all_parsed(void *parsed_result,
1344                         __attribute__((unused)) struct cmdline *cl,
1345                         __attribute__((unused)) void *data)
1346 {
1347         struct cmd_config_speed_all *res = parsed_result;
1348         uint32_t link_speed;
1349         portid_t pid;
1350
1351         if (!all_ports_stopped()) {
1352                 printf("Please stop all ports first\n");
1353                 return;
1354         }
1355
1356         if (parse_and_check_speed_duplex(res->value1, res->value2,
1357                         &link_speed) < 0)
1358                 return;
1359
1360         RTE_ETH_FOREACH_DEV(pid) {
1361                 ports[pid].dev_conf.link_speeds = link_speed;
1362         }
1363
1364         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1365 }
1366
1367 cmdline_parse_token_string_t cmd_config_speed_all_port =
1368         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1369 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1370         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1371                                                         "config");
1372 cmdline_parse_token_string_t cmd_config_speed_all_all =
1373         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1374 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1375         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1376 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1377         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1378                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1379 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1380         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1381 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1382         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1383                                                 "half#full#auto");
1384
1385 cmdline_parse_inst_t cmd_config_speed_all = {
1386         .f = cmd_config_speed_all_parsed,
1387         .data = NULL,
1388         .help_str = "port config all speed "
1389                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1390                                                         "half|full|auto",
1391         .tokens = {
1392                 (void *)&cmd_config_speed_all_port,
1393                 (void *)&cmd_config_speed_all_keyword,
1394                 (void *)&cmd_config_speed_all_all,
1395                 (void *)&cmd_config_speed_all_item1,
1396                 (void *)&cmd_config_speed_all_value1,
1397                 (void *)&cmd_config_speed_all_item2,
1398                 (void *)&cmd_config_speed_all_value2,
1399                 NULL,
1400         },
1401 };
1402
1403 /* *** configure speed for specific port *** */
1404 struct cmd_config_speed_specific {
1405         cmdline_fixed_string_t port;
1406         cmdline_fixed_string_t keyword;
1407         uint8_t id;
1408         cmdline_fixed_string_t item1;
1409         cmdline_fixed_string_t item2;
1410         cmdline_fixed_string_t value1;
1411         cmdline_fixed_string_t value2;
1412 };
1413
1414 static void
1415 cmd_config_speed_specific_parsed(void *parsed_result,
1416                                 __attribute__((unused)) struct cmdline *cl,
1417                                 __attribute__((unused)) void *data)
1418 {
1419         struct cmd_config_speed_specific *res = parsed_result;
1420         uint32_t link_speed;
1421
1422         if (!all_ports_stopped()) {
1423                 printf("Please stop all ports first\n");
1424                 return;
1425         }
1426
1427         if (port_id_is_invalid(res->id, ENABLED_WARN))
1428                 return;
1429
1430         if (parse_and_check_speed_duplex(res->value1, res->value2,
1431                         &link_speed) < 0)
1432                 return;
1433
1434         ports[res->id].dev_conf.link_speeds = link_speed;
1435
1436         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1437 }
1438
1439
1440 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1441         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1442                                                                 "port");
1443 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1444         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1445                                                                 "config");
1446 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1447         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1448 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1449         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1450                                                                 "speed");
1451 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1452         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1453                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1454 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1455         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1456                                                                 "duplex");
1457 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1459                                                         "half#full#auto");
1460
1461 cmdline_parse_inst_t cmd_config_speed_specific = {
1462         .f = cmd_config_speed_specific_parsed,
1463         .data = NULL,
1464         .help_str = "port config <port_id> speed "
1465                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1466                                                         "half|full|auto",
1467         .tokens = {
1468                 (void *)&cmd_config_speed_specific_port,
1469                 (void *)&cmd_config_speed_specific_keyword,
1470                 (void *)&cmd_config_speed_specific_id,
1471                 (void *)&cmd_config_speed_specific_item1,
1472                 (void *)&cmd_config_speed_specific_value1,
1473                 (void *)&cmd_config_speed_specific_item2,
1474                 (void *)&cmd_config_speed_specific_value2,
1475                 NULL,
1476         },
1477 };
1478
1479 /* *** configure txq/rxq, txd/rxd *** */
1480 struct cmd_config_rx_tx {
1481         cmdline_fixed_string_t port;
1482         cmdline_fixed_string_t keyword;
1483         cmdline_fixed_string_t all;
1484         cmdline_fixed_string_t name;
1485         uint16_t value;
1486 };
1487
1488 static void
1489 cmd_config_rx_tx_parsed(void *parsed_result,
1490                         __attribute__((unused)) struct cmdline *cl,
1491                         __attribute__((unused)) void *data)
1492 {
1493         struct cmd_config_rx_tx *res = parsed_result;
1494
1495         if (!all_ports_stopped()) {
1496                 printf("Please stop all ports first\n");
1497                 return;
1498         }
1499         if (!strcmp(res->name, "rxq")) {
1500                 if (!res->value && !nb_txq) {
1501                         printf("Warning: Either rx or tx queues should be non zero\n");
1502                         return;
1503                 }
1504                 nb_rxq = res->value;
1505         }
1506         else if (!strcmp(res->name, "txq")) {
1507                 if (!res->value && !nb_rxq) {
1508                         printf("Warning: Either rx or tx queues should be non zero\n");
1509                         return;
1510                 }
1511                 nb_txq = res->value;
1512         }
1513         else if (!strcmp(res->name, "rxd")) {
1514                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1515                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1516                                         res->value, RTE_TEST_RX_DESC_MAX);
1517                         return;
1518                 }
1519                 nb_rxd = res->value;
1520         } else if (!strcmp(res->name, "txd")) {
1521                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1522                         printf("txd %d invalid - must be > 0 && <= %d\n",
1523                                         res->value, RTE_TEST_TX_DESC_MAX);
1524                         return;
1525                 }
1526                 nb_txd = res->value;
1527         } else {
1528                 printf("Unknown parameter\n");
1529                 return;
1530         }
1531
1532         fwd_config_setup();
1533
1534         init_port_config();
1535
1536         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1537 }
1538
1539 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1540         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1541 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1542         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1543 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1544         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1545 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1546         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1547                                                 "rxq#txq#rxd#txd");
1548 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1549         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1550
1551 cmdline_parse_inst_t cmd_config_rx_tx = {
1552         .f = cmd_config_rx_tx_parsed,
1553         .data = NULL,
1554         .help_str = "port config all rxq|txq|rxd|txd <value>",
1555         .tokens = {
1556                 (void *)&cmd_config_rx_tx_port,
1557                 (void *)&cmd_config_rx_tx_keyword,
1558                 (void *)&cmd_config_rx_tx_all,
1559                 (void *)&cmd_config_rx_tx_name,
1560                 (void *)&cmd_config_rx_tx_value,
1561                 NULL,
1562         },
1563 };
1564
1565 /* *** config max packet length *** */
1566 struct cmd_config_max_pkt_len_result {
1567         cmdline_fixed_string_t port;
1568         cmdline_fixed_string_t keyword;
1569         cmdline_fixed_string_t all;
1570         cmdline_fixed_string_t name;
1571         uint32_t value;
1572 };
1573
1574 static void
1575 cmd_config_max_pkt_len_parsed(void *parsed_result,
1576                                 __attribute__((unused)) struct cmdline *cl,
1577                                 __attribute__((unused)) void *data)
1578 {
1579         struct cmd_config_max_pkt_len_result *res = parsed_result;
1580
1581         if (!all_ports_stopped()) {
1582                 printf("Please stop all ports first\n");
1583                 return;
1584         }
1585
1586         if (!strcmp(res->name, "max-pkt-len")) {
1587                 if (res->value < ETHER_MIN_LEN) {
1588                         printf("max-pkt-len can not be less than %d\n",
1589                                                         ETHER_MIN_LEN);
1590                         return;
1591                 }
1592                 if (res->value == rx_mode.max_rx_pkt_len)
1593                         return;
1594
1595                 rx_mode.max_rx_pkt_len = res->value;
1596                 if (res->value > ETHER_MAX_LEN)
1597                         rx_mode.jumbo_frame = 1;
1598                 else
1599                         rx_mode.jumbo_frame = 0;
1600         } else {
1601                 printf("Unknown parameter\n");
1602                 return;
1603         }
1604
1605         init_port_config();
1606
1607         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1608 }
1609
1610 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1611         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1612                                                                 "port");
1613 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1614         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1615                                                                 "config");
1616 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1617         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1618                                                                 "all");
1619 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1620         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1621                                                                 "max-pkt-len");
1622 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1623         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1624                                                                 UINT32);
1625
1626 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1627         .f = cmd_config_max_pkt_len_parsed,
1628         .data = NULL,
1629         .help_str = "port config all max-pkt-len <value>",
1630         .tokens = {
1631                 (void *)&cmd_config_max_pkt_len_port,
1632                 (void *)&cmd_config_max_pkt_len_keyword,
1633                 (void *)&cmd_config_max_pkt_len_all,
1634                 (void *)&cmd_config_max_pkt_len_name,
1635                 (void *)&cmd_config_max_pkt_len_value,
1636                 NULL,
1637         },
1638 };
1639
1640 /* *** configure port MTU *** */
1641 struct cmd_config_mtu_result {
1642         cmdline_fixed_string_t port;
1643         cmdline_fixed_string_t keyword;
1644         cmdline_fixed_string_t mtu;
1645         portid_t port_id;
1646         uint16_t value;
1647 };
1648
1649 static void
1650 cmd_config_mtu_parsed(void *parsed_result,
1651                       __attribute__((unused)) struct cmdline *cl,
1652                       __attribute__((unused)) void *data)
1653 {
1654         struct cmd_config_mtu_result *res = parsed_result;
1655
1656         if (res->value < ETHER_MIN_LEN) {
1657                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1658                 return;
1659         }
1660         port_mtu_set(res->port_id, res->value);
1661 }
1662
1663 cmdline_parse_token_string_t cmd_config_mtu_port =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1665                                  "port");
1666 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1668                                  "config");
1669 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1670         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1671                                  "mtu");
1672 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1673         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1674 cmdline_parse_token_num_t cmd_config_mtu_value =
1675         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1676
1677 cmdline_parse_inst_t cmd_config_mtu = {
1678         .f = cmd_config_mtu_parsed,
1679         .data = NULL,
1680         .help_str = "port config mtu <port_id> <value>",
1681         .tokens = {
1682                 (void *)&cmd_config_mtu_port,
1683                 (void *)&cmd_config_mtu_keyword,
1684                 (void *)&cmd_config_mtu_mtu,
1685                 (void *)&cmd_config_mtu_port_id,
1686                 (void *)&cmd_config_mtu_value,
1687                 NULL,
1688         },
1689 };
1690
1691 /* *** configure rx mode *** */
1692 struct cmd_config_rx_mode_flag {
1693         cmdline_fixed_string_t port;
1694         cmdline_fixed_string_t keyword;
1695         cmdline_fixed_string_t all;
1696         cmdline_fixed_string_t name;
1697         cmdline_fixed_string_t value;
1698 };
1699
1700 static void
1701 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1702                                 __attribute__((unused)) struct cmdline *cl,
1703                                 __attribute__((unused)) void *data)
1704 {
1705         struct cmd_config_rx_mode_flag *res = parsed_result;
1706
1707         if (!all_ports_stopped()) {
1708                 printf("Please stop all ports first\n");
1709                 return;
1710         }
1711
1712         if (!strcmp(res->name, "crc-strip")) {
1713                 if (!strcmp(res->value, "on"))
1714                         rx_mode.hw_strip_crc = 1;
1715                 else if (!strcmp(res->value, "off"))
1716                         rx_mode.hw_strip_crc = 0;
1717                 else {
1718                         printf("Unknown parameter\n");
1719                         return;
1720                 }
1721         } else if (!strcmp(res->name, "scatter")) {
1722                 if (!strcmp(res->value, "on"))
1723                         rx_mode.enable_scatter = 1;
1724                 else if (!strcmp(res->value, "off"))
1725                         rx_mode.enable_scatter = 0;
1726                 else {
1727                         printf("Unknown parameter\n");
1728                         return;
1729                 }
1730         } else if (!strcmp(res->name, "rx-cksum")) {
1731                 if (!strcmp(res->value, "on"))
1732                         rx_mode.hw_ip_checksum = 1;
1733                 else if (!strcmp(res->value, "off"))
1734                         rx_mode.hw_ip_checksum = 0;
1735                 else {
1736                         printf("Unknown parameter\n");
1737                         return;
1738                 }
1739         } else if (!strcmp(res->name, "rx-timestamp")) {
1740                 if (!strcmp(res->value, "on"))
1741                         rx_mode.hw_timestamp = 1;
1742                 else if (!strcmp(res->value, "off"))
1743                         rx_mode.hw_timestamp = 0;
1744                 else {
1745                         printf("Unknown parameter\n");
1746                         return;
1747                 }
1748         } else if (!strcmp(res->name, "hw-vlan")) {
1749                 if (!strcmp(res->value, "on")) {
1750                         rx_mode.hw_vlan_filter = 1;
1751                         rx_mode.hw_vlan_strip  = 1;
1752                 }
1753                 else if (!strcmp(res->value, "off")) {
1754                         rx_mode.hw_vlan_filter = 0;
1755                         rx_mode.hw_vlan_strip  = 0;
1756                 }
1757                 else {
1758                         printf("Unknown parameter\n");
1759                         return;
1760                 }
1761         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1762                 if (!strcmp(res->value, "on"))
1763                         rx_mode.hw_vlan_filter = 1;
1764                 else if (!strcmp(res->value, "off"))
1765                         rx_mode.hw_vlan_filter = 0;
1766                 else {
1767                         printf("Unknown parameter\n");
1768                         return;
1769                 }
1770         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1771                 if (!strcmp(res->value, "on"))
1772                         rx_mode.hw_vlan_strip  = 1;
1773                 else if (!strcmp(res->value, "off"))
1774                         rx_mode.hw_vlan_strip  = 0;
1775                 else {
1776                         printf("Unknown parameter\n");
1777                         return;
1778                 }
1779         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1780                 if (!strcmp(res->value, "on"))
1781                         rx_mode.hw_vlan_extend = 1;
1782                 else if (!strcmp(res->value, "off"))
1783                         rx_mode.hw_vlan_extend = 0;
1784                 else {
1785                         printf("Unknown parameter\n");
1786                         return;
1787                 }
1788         } else if (!strcmp(res->name, "drop-en")) {
1789                 if (!strcmp(res->value, "on"))
1790                         rx_drop_en = 1;
1791                 else if (!strcmp(res->value, "off"))
1792                         rx_drop_en = 0;
1793                 else {
1794                         printf("Unknown parameter\n");
1795                         return;
1796                 }
1797         } else {
1798                 printf("Unknown parameter\n");
1799                 return;
1800         }
1801
1802         init_port_config();
1803
1804         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1805 }
1806
1807 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1809 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1810         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1811                                                                 "config");
1812 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1813         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1814 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1815         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1816                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1817                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1818 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1819         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1820                                                         "on#off");
1821
1822 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1823         .f = cmd_config_rx_mode_flag_parsed,
1824         .data = NULL,
1825         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1826                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1827         .tokens = {
1828                 (void *)&cmd_config_rx_mode_flag_port,
1829                 (void *)&cmd_config_rx_mode_flag_keyword,
1830                 (void *)&cmd_config_rx_mode_flag_all,
1831                 (void *)&cmd_config_rx_mode_flag_name,
1832                 (void *)&cmd_config_rx_mode_flag_value,
1833                 NULL,
1834         },
1835 };
1836
1837 /* *** configure rss *** */
1838 struct cmd_config_rss {
1839         cmdline_fixed_string_t port;
1840         cmdline_fixed_string_t keyword;
1841         cmdline_fixed_string_t all;
1842         cmdline_fixed_string_t name;
1843         cmdline_fixed_string_t value;
1844 };
1845
1846 static void
1847 cmd_config_rss_parsed(void *parsed_result,
1848                         __attribute__((unused)) struct cmdline *cl,
1849                         __attribute__((unused)) void *data)
1850 {
1851         struct cmd_config_rss *res = parsed_result;
1852         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1853         int diag;
1854         uint8_t i;
1855
1856         if (!strcmp(res->value, "all"))
1857                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1858                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1859                                         ETH_RSS_L2_PAYLOAD;
1860         else if (!strcmp(res->value, "ip"))
1861                 rss_conf.rss_hf = ETH_RSS_IP;
1862         else if (!strcmp(res->value, "udp"))
1863                 rss_conf.rss_hf = ETH_RSS_UDP;
1864         else if (!strcmp(res->value, "tcp"))
1865                 rss_conf.rss_hf = ETH_RSS_TCP;
1866         else if (!strcmp(res->value, "sctp"))
1867                 rss_conf.rss_hf = ETH_RSS_SCTP;
1868         else if (!strcmp(res->value, "ether"))
1869                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1870         else if (!strcmp(res->value, "port"))
1871                 rss_conf.rss_hf = ETH_RSS_PORT;
1872         else if (!strcmp(res->value, "vxlan"))
1873                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1874         else if (!strcmp(res->value, "geneve"))
1875                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1876         else if (!strcmp(res->value, "nvgre"))
1877                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1878         else if (!strcmp(res->value, "none"))
1879                 rss_conf.rss_hf = 0;
1880         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1881                                                 atoi(res->value) < 64)
1882                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1883         else {
1884                 printf("Unknown parameter\n");
1885                 return;
1886         }
1887         rss_conf.rss_key = NULL;
1888         for (i = 0; i < rte_eth_dev_count(); i++) {
1889                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1890                 if (diag < 0)
1891                         printf("Configuration of RSS hash at ethernet port %d "
1892                                 "failed with error (%d): %s.\n",
1893                                 i, -diag, strerror(-diag));
1894         }
1895 }
1896
1897 cmdline_parse_token_string_t cmd_config_rss_port =
1898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1899 cmdline_parse_token_string_t cmd_config_rss_keyword =
1900         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1901 cmdline_parse_token_string_t cmd_config_rss_all =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1903 cmdline_parse_token_string_t cmd_config_rss_name =
1904         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1905 cmdline_parse_token_string_t cmd_config_rss_value =
1906         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1907
1908 cmdline_parse_inst_t cmd_config_rss = {
1909         .f = cmd_config_rss_parsed,
1910         .data = NULL,
1911         .help_str = "port config all rss "
1912                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1913         .tokens = {
1914                 (void *)&cmd_config_rss_port,
1915                 (void *)&cmd_config_rss_keyword,
1916                 (void *)&cmd_config_rss_all,
1917                 (void *)&cmd_config_rss_name,
1918                 (void *)&cmd_config_rss_value,
1919                 NULL,
1920         },
1921 };
1922
1923 /* *** configure rss hash key *** */
1924 struct cmd_config_rss_hash_key {
1925         cmdline_fixed_string_t port;
1926         cmdline_fixed_string_t config;
1927         portid_t port_id;
1928         cmdline_fixed_string_t rss_hash_key;
1929         cmdline_fixed_string_t rss_type;
1930         cmdline_fixed_string_t key;
1931 };
1932
1933 static uint8_t
1934 hexa_digit_to_value(char hexa_digit)
1935 {
1936         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1937                 return (uint8_t) (hexa_digit - '0');
1938         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1939                 return (uint8_t) ((hexa_digit - 'a') + 10);
1940         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1941                 return (uint8_t) ((hexa_digit - 'A') + 10);
1942         /* Invalid hexa digit */
1943         return 0xFF;
1944 }
1945
1946 static uint8_t
1947 parse_and_check_key_hexa_digit(char *key, int idx)
1948 {
1949         uint8_t hexa_v;
1950
1951         hexa_v = hexa_digit_to_value(key[idx]);
1952         if (hexa_v == 0xFF)
1953                 printf("invalid key: character %c at position %d is not a "
1954                        "valid hexa digit\n", key[idx], idx);
1955         return hexa_v;
1956 }
1957
1958 static void
1959 cmd_config_rss_hash_key_parsed(void *parsed_result,
1960                                __attribute__((unused)) struct cmdline *cl,
1961                                __attribute__((unused)) void *data)
1962 {
1963         struct cmd_config_rss_hash_key *res = parsed_result;
1964         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1965         uint8_t xdgt0;
1966         uint8_t xdgt1;
1967         int i;
1968         struct rte_eth_dev_info dev_info;
1969         uint8_t hash_key_size;
1970         uint32_t key_len;
1971
1972         memset(&dev_info, 0, sizeof(dev_info));
1973         rte_eth_dev_info_get(res->port_id, &dev_info);
1974         if (dev_info.hash_key_size > 0 &&
1975                         dev_info.hash_key_size <= sizeof(hash_key))
1976                 hash_key_size = dev_info.hash_key_size;
1977         else {
1978                 printf("dev_info did not provide a valid hash key size\n");
1979                 return;
1980         }
1981         /* Check the length of the RSS hash key */
1982         key_len = strlen(res->key);
1983         if (key_len != (hash_key_size * 2)) {
1984                 printf("key length: %d invalid - key must be a string of %d"
1985                            " hexa-decimal numbers\n",
1986                            (int) key_len, hash_key_size * 2);
1987                 return;
1988         }
1989         /* Translate RSS hash key into binary representation */
1990         for (i = 0; i < hash_key_size; i++) {
1991                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1992                 if (xdgt0 == 0xFF)
1993                         return;
1994                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1995                 if (xdgt1 == 0xFF)
1996                         return;
1997                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1998         }
1999         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2000                         hash_key_size);
2001 }
2002
2003 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2004         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2005 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2006         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2007                                  "config");
2008 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2009         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2010 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2012                                  rss_hash_key, "rss-hash-key");
2013 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2015                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2016                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2017                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2018                                  "ipv6-tcp-ex#ipv6-udp-ex");
2019 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2021
2022 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2023         .f = cmd_config_rss_hash_key_parsed,
2024         .data = NULL,
2025         .help_str = "port config <port_id> rss-hash-key "
2026                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2027                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2028                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2029                 "<string of hex digits (variable length, NIC dependent)>",
2030         .tokens = {
2031                 (void *)&cmd_config_rss_hash_key_port,
2032                 (void *)&cmd_config_rss_hash_key_config,
2033                 (void *)&cmd_config_rss_hash_key_port_id,
2034                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2035                 (void *)&cmd_config_rss_hash_key_rss_type,
2036                 (void *)&cmd_config_rss_hash_key_value,
2037                 NULL,
2038         },
2039 };
2040
2041 /* *** configure port rxq/txq start/stop *** */
2042 struct cmd_config_rxtx_queue {
2043         cmdline_fixed_string_t port;
2044         portid_t portid;
2045         cmdline_fixed_string_t rxtxq;
2046         uint16_t qid;
2047         cmdline_fixed_string_t opname;
2048 };
2049
2050 static void
2051 cmd_config_rxtx_queue_parsed(void *parsed_result,
2052                         __attribute__((unused)) struct cmdline *cl,
2053                         __attribute__((unused)) void *data)
2054 {
2055         struct cmd_config_rxtx_queue *res = parsed_result;
2056         uint8_t isrx;
2057         uint8_t isstart;
2058         int ret = 0;
2059
2060         if (test_done == 0) {
2061                 printf("Please stop forwarding first\n");
2062                 return;
2063         }
2064
2065         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2066                 return;
2067
2068         if (port_is_started(res->portid) != 1) {
2069                 printf("Please start port %u first\n", res->portid);
2070                 return;
2071         }
2072
2073         if (!strcmp(res->rxtxq, "rxq"))
2074                 isrx = 1;
2075         else if (!strcmp(res->rxtxq, "txq"))
2076                 isrx = 0;
2077         else {
2078                 printf("Unknown parameter\n");
2079                 return;
2080         }
2081
2082         if (isrx && rx_queue_id_is_invalid(res->qid))
2083                 return;
2084         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2085                 return;
2086
2087         if (!strcmp(res->opname, "start"))
2088                 isstart = 1;
2089         else if (!strcmp(res->opname, "stop"))
2090                 isstart = 0;
2091         else {
2092                 printf("Unknown parameter\n");
2093                 return;
2094         }
2095
2096         if (isstart && isrx)
2097                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2098         else if (!isstart && isrx)
2099                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2100         else if (isstart && !isrx)
2101                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2102         else
2103                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2104
2105         if (ret == -ENOTSUP)
2106                 printf("Function not supported in PMD driver\n");
2107 }
2108
2109 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2111 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2112         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2113 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2114         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2115 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2116         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2117 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2119                                                 "start#stop");
2120
2121 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2122         .f = cmd_config_rxtx_queue_parsed,
2123         .data = NULL,
2124         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2125         .tokens = {
2126                 (void *)&cmd_config_speed_all_port,
2127                 (void *)&cmd_config_rxtx_queue_portid,
2128                 (void *)&cmd_config_rxtx_queue_rxtxq,
2129                 (void *)&cmd_config_rxtx_queue_qid,
2130                 (void *)&cmd_config_rxtx_queue_opname,
2131                 NULL,
2132         },
2133 };
2134
2135 /* *** Configure RSS RETA *** */
2136 struct cmd_config_rss_reta {
2137         cmdline_fixed_string_t port;
2138         cmdline_fixed_string_t keyword;
2139         portid_t port_id;
2140         cmdline_fixed_string_t name;
2141         cmdline_fixed_string_t list_name;
2142         cmdline_fixed_string_t list_of_items;
2143 };
2144
2145 static int
2146 parse_reta_config(const char *str,
2147                   struct rte_eth_rss_reta_entry64 *reta_conf,
2148                   uint16_t nb_entries)
2149 {
2150         int i;
2151         unsigned size;
2152         uint16_t hash_index, idx, shift;
2153         uint16_t nb_queue;
2154         char s[256];
2155         const char *p, *p0 = str;
2156         char *end;
2157         enum fieldnames {
2158                 FLD_HASH_INDEX = 0,
2159                 FLD_QUEUE,
2160                 _NUM_FLD
2161         };
2162         unsigned long int_fld[_NUM_FLD];
2163         char *str_fld[_NUM_FLD];
2164
2165         while ((p = strchr(p0,'(')) != NULL) {
2166                 ++p;
2167                 if((p0 = strchr(p,')')) == NULL)
2168                         return -1;
2169
2170                 size = p0 - p;
2171                 if(size >= sizeof(s))
2172                         return -1;
2173
2174                 snprintf(s, sizeof(s), "%.*s", size, p);
2175                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2176                         return -1;
2177                 for (i = 0; i < _NUM_FLD; i++) {
2178                         errno = 0;
2179                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2180                         if (errno != 0 || end == str_fld[i] ||
2181                                         int_fld[i] > 65535)
2182                                 return -1;
2183                 }
2184
2185                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2186                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2187
2188                 if (hash_index >= nb_entries) {
2189                         printf("Invalid RETA hash index=%d\n", hash_index);
2190                         return -1;
2191                 }
2192
2193                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2194                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2195                 reta_conf[idx].mask |= (1ULL << shift);
2196                 reta_conf[idx].reta[shift] = nb_queue;
2197         }
2198
2199         return 0;
2200 }
2201
2202 static void
2203 cmd_set_rss_reta_parsed(void *parsed_result,
2204                         __attribute__((unused)) struct cmdline *cl,
2205                         __attribute__((unused)) void *data)
2206 {
2207         int ret;
2208         struct rte_eth_dev_info dev_info;
2209         struct rte_eth_rss_reta_entry64 reta_conf[8];
2210         struct cmd_config_rss_reta *res = parsed_result;
2211
2212         memset(&dev_info, 0, sizeof(dev_info));
2213         rte_eth_dev_info_get(res->port_id, &dev_info);
2214         if (dev_info.reta_size == 0) {
2215                 printf("Redirection table size is 0 which is "
2216                                         "invalid for RSS\n");
2217                 return;
2218         } else
2219                 printf("The reta size of port %d is %u\n",
2220                         res->port_id, dev_info.reta_size);
2221         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2222                 printf("Currently do not support more than %u entries of "
2223                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2224                 return;
2225         }
2226
2227         memset(reta_conf, 0, sizeof(reta_conf));
2228         if (!strcmp(res->list_name, "reta")) {
2229                 if (parse_reta_config(res->list_of_items, reta_conf,
2230                                                 dev_info.reta_size)) {
2231                         printf("Invalid RSS Redirection Table "
2232                                         "config entered\n");
2233                         return;
2234                 }
2235                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2236                                 reta_conf, dev_info.reta_size);
2237                 if (ret != 0)
2238                         printf("Bad redirection table parameter, "
2239                                         "return code = %d \n", ret);
2240         }
2241 }
2242
2243 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2244         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2245 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2246         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2247 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2248         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2249 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2251 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2252         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2253 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2255                                  NULL);
2256 cmdline_parse_inst_t cmd_config_rss_reta = {
2257         .f = cmd_set_rss_reta_parsed,
2258         .data = NULL,
2259         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2260         .tokens = {
2261                 (void *)&cmd_config_rss_reta_port,
2262                 (void *)&cmd_config_rss_reta_keyword,
2263                 (void *)&cmd_config_rss_reta_port_id,
2264                 (void *)&cmd_config_rss_reta_name,
2265                 (void *)&cmd_config_rss_reta_list_name,
2266                 (void *)&cmd_config_rss_reta_list_of_items,
2267                 NULL,
2268         },
2269 };
2270
2271 /* *** SHOW PORT RETA INFO *** */
2272 struct cmd_showport_reta {
2273         cmdline_fixed_string_t show;
2274         cmdline_fixed_string_t port;
2275         portid_t port_id;
2276         cmdline_fixed_string_t rss;
2277         cmdline_fixed_string_t reta;
2278         uint16_t size;
2279         cmdline_fixed_string_t list_of_items;
2280 };
2281
2282 static int
2283 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2284                            uint16_t nb_entries,
2285                            char *str)
2286 {
2287         uint32_t size;
2288         const char *p, *p0 = str;
2289         char s[256];
2290         char *end;
2291         char *str_fld[8];
2292         uint16_t i;
2293         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2294                         RTE_RETA_GROUP_SIZE;
2295         int ret;
2296
2297         p = strchr(p0, '(');
2298         if (p == NULL)
2299                 return -1;
2300         p++;
2301         p0 = strchr(p, ')');
2302         if (p0 == NULL)
2303                 return -1;
2304         size = p0 - p;
2305         if (size >= sizeof(s)) {
2306                 printf("The string size exceeds the internal buffer size\n");
2307                 return -1;
2308         }
2309         snprintf(s, sizeof(s), "%.*s", size, p);
2310         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2311         if (ret <= 0 || ret != num) {
2312                 printf("The bits of masks do not match the number of "
2313                                         "reta entries: %u\n", num);
2314                 return -1;
2315         }
2316         for (i = 0; i < ret; i++)
2317                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2318
2319         return 0;
2320 }
2321
2322 static void
2323 cmd_showport_reta_parsed(void *parsed_result,
2324                          __attribute__((unused)) struct cmdline *cl,
2325                          __attribute__((unused)) void *data)
2326 {
2327         struct cmd_showport_reta *res = parsed_result;
2328         struct rte_eth_rss_reta_entry64 reta_conf[8];
2329         struct rte_eth_dev_info dev_info;
2330         uint16_t max_reta_size;
2331
2332         memset(&dev_info, 0, sizeof(dev_info));
2333         rte_eth_dev_info_get(res->port_id, &dev_info);
2334         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2335         if (res->size == 0 || res->size > max_reta_size) {
2336                 printf("Invalid redirection table size: %u (1-%u)\n",
2337                         res->size, max_reta_size);
2338                 return;
2339         }
2340
2341         memset(reta_conf, 0, sizeof(reta_conf));
2342         if (showport_parse_reta_config(reta_conf, res->size,
2343                                 res->list_of_items) < 0) {
2344                 printf("Invalid string: %s for reta masks\n",
2345                                         res->list_of_items);
2346                 return;
2347         }
2348         port_rss_reta_info(res->port_id, reta_conf, res->size);
2349 }
2350
2351 cmdline_parse_token_string_t cmd_showport_reta_show =
2352         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2353 cmdline_parse_token_string_t cmd_showport_reta_port =
2354         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2355 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2356         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2357 cmdline_parse_token_string_t cmd_showport_reta_rss =
2358         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2359 cmdline_parse_token_string_t cmd_showport_reta_reta =
2360         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2361 cmdline_parse_token_num_t cmd_showport_reta_size =
2362         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2363 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2364         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2365                                         list_of_items, NULL);
2366
2367 cmdline_parse_inst_t cmd_showport_reta = {
2368         .f = cmd_showport_reta_parsed,
2369         .data = NULL,
2370         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2371         .tokens = {
2372                 (void *)&cmd_showport_reta_show,
2373                 (void *)&cmd_showport_reta_port,
2374                 (void *)&cmd_showport_reta_port_id,
2375                 (void *)&cmd_showport_reta_rss,
2376                 (void *)&cmd_showport_reta_reta,
2377                 (void *)&cmd_showport_reta_size,
2378                 (void *)&cmd_showport_reta_list_of_items,
2379                 NULL,
2380         },
2381 };
2382
2383 /* *** Show RSS hash configuration *** */
2384 struct cmd_showport_rss_hash {
2385         cmdline_fixed_string_t show;
2386         cmdline_fixed_string_t port;
2387         portid_t port_id;
2388         cmdline_fixed_string_t rss_hash;
2389         cmdline_fixed_string_t rss_type;
2390         cmdline_fixed_string_t key; /* optional argument */
2391 };
2392
2393 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2394                                 __attribute__((unused)) struct cmdline *cl,
2395                                 void *show_rss_key)
2396 {
2397         struct cmd_showport_rss_hash *res = parsed_result;
2398
2399         port_rss_hash_conf_show(res->port_id, res->rss_type,
2400                                 show_rss_key != NULL);
2401 }
2402
2403 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2404         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2405 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2406         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2407 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2408         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2409 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2410         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2411                                  "rss-hash");
2412 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2413         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2414                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2415                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2416                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2417                                  "ipv6-tcp-ex#ipv6-udp-ex");
2418 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2419         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2420
2421 cmdline_parse_inst_t cmd_showport_rss_hash = {
2422         .f = cmd_showport_rss_hash_parsed,
2423         .data = NULL,
2424         .help_str = "show port <port_id> rss-hash "
2425                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2426                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2427                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2428         .tokens = {
2429                 (void *)&cmd_showport_rss_hash_show,
2430                 (void *)&cmd_showport_rss_hash_port,
2431                 (void *)&cmd_showport_rss_hash_port_id,
2432                 (void *)&cmd_showport_rss_hash_rss_hash,
2433                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2434                 NULL,
2435         },
2436 };
2437
2438 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2439         .f = cmd_showport_rss_hash_parsed,
2440         .data = (void *)1,
2441         .help_str = "show port <port_id> rss-hash "
2442                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2443                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2444                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2445         .tokens = {
2446                 (void *)&cmd_showport_rss_hash_show,
2447                 (void *)&cmd_showport_rss_hash_port,
2448                 (void *)&cmd_showport_rss_hash_port_id,
2449                 (void *)&cmd_showport_rss_hash_rss_hash,
2450                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2451                 (void *)&cmd_showport_rss_hash_rss_key,
2452                 NULL,
2453         },
2454 };
2455
2456 /* *** Configure DCB *** */
2457 struct cmd_config_dcb {
2458         cmdline_fixed_string_t port;
2459         cmdline_fixed_string_t config;
2460         portid_t port_id;
2461         cmdline_fixed_string_t dcb;
2462         cmdline_fixed_string_t vt;
2463         cmdline_fixed_string_t vt_en;
2464         uint8_t num_tcs;
2465         cmdline_fixed_string_t pfc;
2466         cmdline_fixed_string_t pfc_en;
2467 };
2468
2469 static void
2470 cmd_config_dcb_parsed(void *parsed_result,
2471                         __attribute__((unused)) struct cmdline *cl,
2472                         __attribute__((unused)) void *data)
2473 {
2474         struct cmd_config_dcb *res = parsed_result;
2475         portid_t port_id = res->port_id;
2476         struct rte_port *port;
2477         uint8_t pfc_en;
2478         int ret;
2479
2480         port = &ports[port_id];
2481         /** Check if the port is not started **/
2482         if (port->port_status != RTE_PORT_STOPPED) {
2483                 printf("Please stop port %d first\n", port_id);
2484                 return;
2485         }
2486
2487         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2488                 printf("The invalid number of traffic class,"
2489                         " only 4 or 8 allowed.\n");
2490                 return;
2491         }
2492
2493         if (nb_fwd_lcores < res->num_tcs) {
2494                 printf("nb_cores shouldn't be less than number of TCs.\n");
2495                 return;
2496         }
2497         if (!strncmp(res->pfc_en, "on", 2))
2498                 pfc_en = 1;
2499         else
2500                 pfc_en = 0;
2501
2502         /* DCB in VT mode */
2503         if (!strncmp(res->vt_en, "on", 2))
2504                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2505                                 (enum rte_eth_nb_tcs)res->num_tcs,
2506                                 pfc_en);
2507         else
2508                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2509                                 (enum rte_eth_nb_tcs)res->num_tcs,
2510                                 pfc_en);
2511
2512
2513         if (ret != 0) {
2514                 printf("Cannot initialize network ports.\n");
2515                 return;
2516         }
2517
2518         cmd_reconfig_device_queue(port_id, 1, 1);
2519 }
2520
2521 cmdline_parse_token_string_t cmd_config_dcb_port =
2522         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2523 cmdline_parse_token_string_t cmd_config_dcb_config =
2524         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2525 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2526         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2527 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2528         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2529 cmdline_parse_token_string_t cmd_config_dcb_vt =
2530         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2531 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2532         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2533 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2534         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2535 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2536         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2537 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2538         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2539
2540 cmdline_parse_inst_t cmd_config_dcb = {
2541         .f = cmd_config_dcb_parsed,
2542         .data = NULL,
2543         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2544         .tokens = {
2545                 (void *)&cmd_config_dcb_port,
2546                 (void *)&cmd_config_dcb_config,
2547                 (void *)&cmd_config_dcb_port_id,
2548                 (void *)&cmd_config_dcb_dcb,
2549                 (void *)&cmd_config_dcb_vt,
2550                 (void *)&cmd_config_dcb_vt_en,
2551                 (void *)&cmd_config_dcb_num_tcs,
2552                 (void *)&cmd_config_dcb_pfc,
2553                 (void *)&cmd_config_dcb_pfc_en,
2554                 NULL,
2555         },
2556 };
2557
2558 /* *** configure number of packets per burst *** */
2559 struct cmd_config_burst {
2560         cmdline_fixed_string_t port;
2561         cmdline_fixed_string_t keyword;
2562         cmdline_fixed_string_t all;
2563         cmdline_fixed_string_t name;
2564         uint16_t value;
2565 };
2566
2567 static void
2568 cmd_config_burst_parsed(void *parsed_result,
2569                         __attribute__((unused)) struct cmdline *cl,
2570                         __attribute__((unused)) void *data)
2571 {
2572         struct cmd_config_burst *res = parsed_result;
2573
2574         if (!all_ports_stopped()) {
2575                 printf("Please stop all ports first\n");
2576                 return;
2577         }
2578
2579         if (!strcmp(res->name, "burst")) {
2580                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2581                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2582                         return;
2583                 }
2584                 nb_pkt_per_burst = res->value;
2585         } else {
2586                 printf("Unknown parameter\n");
2587                 return;
2588         }
2589
2590         init_port_config();
2591
2592         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2593 }
2594
2595 cmdline_parse_token_string_t cmd_config_burst_port =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2597 cmdline_parse_token_string_t cmd_config_burst_keyword =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2599 cmdline_parse_token_string_t cmd_config_burst_all =
2600         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2601 cmdline_parse_token_string_t cmd_config_burst_name =
2602         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2603 cmdline_parse_token_num_t cmd_config_burst_value =
2604         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2605
2606 cmdline_parse_inst_t cmd_config_burst = {
2607         .f = cmd_config_burst_parsed,
2608         .data = NULL,
2609         .help_str = "port config all burst <value>",
2610         .tokens = {
2611                 (void *)&cmd_config_burst_port,
2612                 (void *)&cmd_config_burst_keyword,
2613                 (void *)&cmd_config_burst_all,
2614                 (void *)&cmd_config_burst_name,
2615                 (void *)&cmd_config_burst_value,
2616                 NULL,
2617         },
2618 };
2619
2620 /* *** configure rx/tx queues *** */
2621 struct cmd_config_thresh {
2622         cmdline_fixed_string_t port;
2623         cmdline_fixed_string_t keyword;
2624         cmdline_fixed_string_t all;
2625         cmdline_fixed_string_t name;
2626         uint8_t value;
2627 };
2628
2629 static void
2630 cmd_config_thresh_parsed(void *parsed_result,
2631                         __attribute__((unused)) struct cmdline *cl,
2632                         __attribute__((unused)) void *data)
2633 {
2634         struct cmd_config_thresh *res = parsed_result;
2635
2636         if (!all_ports_stopped()) {
2637                 printf("Please stop all ports first\n");
2638                 return;
2639         }
2640
2641         if (!strcmp(res->name, "txpt"))
2642                 tx_pthresh = res->value;
2643         else if(!strcmp(res->name, "txht"))
2644                 tx_hthresh = res->value;
2645         else if(!strcmp(res->name, "txwt"))
2646                 tx_wthresh = res->value;
2647         else if(!strcmp(res->name, "rxpt"))
2648                 rx_pthresh = res->value;
2649         else if(!strcmp(res->name, "rxht"))
2650                 rx_hthresh = res->value;
2651         else if(!strcmp(res->name, "rxwt"))
2652                 rx_wthresh = res->value;
2653         else {
2654                 printf("Unknown parameter\n");
2655                 return;
2656         }
2657
2658         init_port_config();
2659
2660         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2661 }
2662
2663 cmdline_parse_token_string_t cmd_config_thresh_port =
2664         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2665 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2666         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2667 cmdline_parse_token_string_t cmd_config_thresh_all =
2668         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2669 cmdline_parse_token_string_t cmd_config_thresh_name =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2671                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2672 cmdline_parse_token_num_t cmd_config_thresh_value =
2673         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2674
2675 cmdline_parse_inst_t cmd_config_thresh = {
2676         .f = cmd_config_thresh_parsed,
2677         .data = NULL,
2678         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2679         .tokens = {
2680                 (void *)&cmd_config_thresh_port,
2681                 (void *)&cmd_config_thresh_keyword,
2682                 (void *)&cmd_config_thresh_all,
2683                 (void *)&cmd_config_thresh_name,
2684                 (void *)&cmd_config_thresh_value,
2685                 NULL,
2686         },
2687 };
2688
2689 /* *** configure free/rs threshold *** */
2690 struct cmd_config_threshold {
2691         cmdline_fixed_string_t port;
2692         cmdline_fixed_string_t keyword;
2693         cmdline_fixed_string_t all;
2694         cmdline_fixed_string_t name;
2695         uint16_t value;
2696 };
2697
2698 static void
2699 cmd_config_threshold_parsed(void *parsed_result,
2700                         __attribute__((unused)) struct cmdline *cl,
2701                         __attribute__((unused)) void *data)
2702 {
2703         struct cmd_config_threshold *res = parsed_result;
2704
2705         if (!all_ports_stopped()) {
2706                 printf("Please stop all ports first\n");
2707                 return;
2708         }
2709
2710         if (!strcmp(res->name, "txfreet"))
2711                 tx_free_thresh = res->value;
2712         else if (!strcmp(res->name, "txrst"))
2713                 tx_rs_thresh = res->value;
2714         else if (!strcmp(res->name, "rxfreet"))
2715                 rx_free_thresh = res->value;
2716         else {
2717                 printf("Unknown parameter\n");
2718                 return;
2719         }
2720
2721         init_port_config();
2722
2723         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2724 }
2725
2726 cmdline_parse_token_string_t cmd_config_threshold_port =
2727         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2728 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2729         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2730                                                                 "config");
2731 cmdline_parse_token_string_t cmd_config_threshold_all =
2732         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2733 cmdline_parse_token_string_t cmd_config_threshold_name =
2734         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2735                                                 "txfreet#txrst#rxfreet");
2736 cmdline_parse_token_num_t cmd_config_threshold_value =
2737         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2738
2739 cmdline_parse_inst_t cmd_config_threshold = {
2740         .f = cmd_config_threshold_parsed,
2741         .data = NULL,
2742         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2743         .tokens = {
2744                 (void *)&cmd_config_threshold_port,
2745                 (void *)&cmd_config_threshold_keyword,
2746                 (void *)&cmd_config_threshold_all,
2747                 (void *)&cmd_config_threshold_name,
2748                 (void *)&cmd_config_threshold_value,
2749                 NULL,
2750         },
2751 };
2752
2753 /* *** stop *** */
2754 struct cmd_stop_result {
2755         cmdline_fixed_string_t stop;
2756 };
2757
2758 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2759                             __attribute__((unused)) struct cmdline *cl,
2760                             __attribute__((unused)) void *data)
2761 {
2762         stop_packet_forwarding();
2763 }
2764
2765 cmdline_parse_token_string_t cmd_stop_stop =
2766         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2767
2768 cmdline_parse_inst_t cmd_stop = {
2769         .f = cmd_stop_parsed,
2770         .data = NULL,
2771         .help_str = "stop: Stop packet forwarding",
2772         .tokens = {
2773                 (void *)&cmd_stop_stop,
2774                 NULL,
2775         },
2776 };
2777
2778 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2779
2780 unsigned int
2781 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2782                 unsigned int *parsed_items, int check_unique_values)
2783 {
2784         unsigned int nb_item;
2785         unsigned int value;
2786         unsigned int i;
2787         unsigned int j;
2788         int value_ok;
2789         char c;
2790
2791         /*
2792          * First parse all items in the list and store their value.
2793          */
2794         value = 0;
2795         nb_item = 0;
2796         value_ok = 0;
2797         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2798                 c = str[i];
2799                 if ((c >= '0') && (c <= '9')) {
2800                         value = (unsigned int) (value * 10 + (c - '0'));
2801                         value_ok = 1;
2802                         continue;
2803                 }
2804                 if (c != ',') {
2805                         printf("character %c is not a decimal digit\n", c);
2806                         return 0;
2807                 }
2808                 if (! value_ok) {
2809                         printf("No valid value before comma\n");
2810                         return 0;
2811                 }
2812                 if (nb_item < max_items) {
2813                         parsed_items[nb_item] = value;
2814                         value_ok = 0;
2815                         value = 0;
2816                 }
2817                 nb_item++;
2818         }
2819         if (nb_item >= max_items) {
2820                 printf("Number of %s = %u > %u (maximum items)\n",
2821                        item_name, nb_item + 1, max_items);
2822                 return 0;
2823         }
2824         parsed_items[nb_item++] = value;
2825         if (! check_unique_values)
2826                 return nb_item;
2827
2828         /*
2829          * Then, check that all values in the list are differents.
2830          * No optimization here...
2831          */
2832         for (i = 0; i < nb_item; i++) {
2833                 for (j = i + 1; j < nb_item; j++) {
2834                         if (parsed_items[j] == parsed_items[i]) {
2835                                 printf("duplicated %s %u at index %u and %u\n",
2836                                        item_name, parsed_items[i], i, j);
2837                                 return 0;
2838                         }
2839                 }
2840         }
2841         return nb_item;
2842 }
2843
2844 struct cmd_set_list_result {
2845         cmdline_fixed_string_t cmd_keyword;
2846         cmdline_fixed_string_t list_name;
2847         cmdline_fixed_string_t list_of_items;
2848 };
2849
2850 static void cmd_set_list_parsed(void *parsed_result,
2851                                 __attribute__((unused)) struct cmdline *cl,
2852                                 __attribute__((unused)) void *data)
2853 {
2854         struct cmd_set_list_result *res;
2855         union {
2856                 unsigned int lcorelist[RTE_MAX_LCORE];
2857                 unsigned int portlist[RTE_MAX_ETHPORTS];
2858         } parsed_items;
2859         unsigned int nb_item;
2860
2861         if (test_done == 0) {
2862                 printf("Please stop forwarding first\n");
2863                 return;
2864         }
2865
2866         res = parsed_result;
2867         if (!strcmp(res->list_name, "corelist")) {
2868                 nb_item = parse_item_list(res->list_of_items, "core",
2869                                           RTE_MAX_LCORE,
2870                                           parsed_items.lcorelist, 1);
2871                 if (nb_item > 0) {
2872                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2873                         fwd_config_setup();
2874                 }
2875                 return;
2876         }
2877         if (!strcmp(res->list_name, "portlist")) {
2878                 nb_item = parse_item_list(res->list_of_items, "port",
2879                                           RTE_MAX_ETHPORTS,
2880                                           parsed_items.portlist, 1);
2881                 if (nb_item > 0) {
2882                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2883                         fwd_config_setup();
2884                 }
2885         }
2886 }
2887
2888 cmdline_parse_token_string_t cmd_set_list_keyword =
2889         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2890                                  "set");
2891 cmdline_parse_token_string_t cmd_set_list_name =
2892         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2893                                  "corelist#portlist");
2894 cmdline_parse_token_string_t cmd_set_list_of_items =
2895         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2896                                  NULL);
2897
2898 cmdline_parse_inst_t cmd_set_fwd_list = {
2899         .f = cmd_set_list_parsed,
2900         .data = NULL,
2901         .help_str = "set corelist|portlist <list0[,list1]*>",
2902         .tokens = {
2903                 (void *)&cmd_set_list_keyword,
2904                 (void *)&cmd_set_list_name,
2905                 (void *)&cmd_set_list_of_items,
2906                 NULL,
2907         },
2908 };
2909
2910 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2911
2912 struct cmd_setmask_result {
2913         cmdline_fixed_string_t set;
2914         cmdline_fixed_string_t mask;
2915         uint64_t hexavalue;
2916 };
2917
2918 static void cmd_set_mask_parsed(void *parsed_result,
2919                                 __attribute__((unused)) struct cmdline *cl,
2920                                 __attribute__((unused)) void *data)
2921 {
2922         struct cmd_setmask_result *res = parsed_result;
2923
2924         if (test_done == 0) {
2925                 printf("Please stop forwarding first\n");
2926                 return;
2927         }
2928         if (!strcmp(res->mask, "coremask")) {
2929                 set_fwd_lcores_mask(res->hexavalue);
2930                 fwd_config_setup();
2931         } else if (!strcmp(res->mask, "portmask")) {
2932                 set_fwd_ports_mask(res->hexavalue);
2933                 fwd_config_setup();
2934         }
2935 }
2936
2937 cmdline_parse_token_string_t cmd_setmask_set =
2938         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2939 cmdline_parse_token_string_t cmd_setmask_mask =
2940         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2941                                  "coremask#portmask");
2942 cmdline_parse_token_num_t cmd_setmask_value =
2943         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2944
2945 cmdline_parse_inst_t cmd_set_fwd_mask = {
2946         .f = cmd_set_mask_parsed,
2947         .data = NULL,
2948         .help_str = "set coremask|portmask <hexadecimal value>",
2949         .tokens = {
2950                 (void *)&cmd_setmask_set,
2951                 (void *)&cmd_setmask_mask,
2952                 (void *)&cmd_setmask_value,
2953                 NULL,
2954         },
2955 };
2956
2957 /*
2958  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2959  */
2960 struct cmd_set_result {
2961         cmdline_fixed_string_t set;
2962         cmdline_fixed_string_t what;
2963         uint16_t value;
2964 };
2965
2966 static void cmd_set_parsed(void *parsed_result,
2967                            __attribute__((unused)) struct cmdline *cl,
2968                            __attribute__((unused)) void *data)
2969 {
2970         struct cmd_set_result *res = parsed_result;
2971         if (!strcmp(res->what, "nbport")) {
2972                 set_fwd_ports_number(res->value);
2973                 fwd_config_setup();
2974         } else if (!strcmp(res->what, "nbcore")) {
2975                 set_fwd_lcores_number(res->value);
2976                 fwd_config_setup();
2977         } else if (!strcmp(res->what, "burst"))
2978                 set_nb_pkt_per_burst(res->value);
2979         else if (!strcmp(res->what, "verbose"))
2980                 set_verbose_level(res->value);
2981 }
2982
2983 cmdline_parse_token_string_t cmd_set_set =
2984         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2985 cmdline_parse_token_string_t cmd_set_what =
2986         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2987                                  "nbport#nbcore#burst#verbose");
2988 cmdline_parse_token_num_t cmd_set_value =
2989         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2990
2991 cmdline_parse_inst_t cmd_set_numbers = {
2992         .f = cmd_set_parsed,
2993         .data = NULL,
2994         .help_str = "set nbport|nbcore|burst|verbose <value>",
2995         .tokens = {
2996                 (void *)&cmd_set_set,
2997                 (void *)&cmd_set_what,
2998                 (void *)&cmd_set_value,
2999                 NULL,
3000         },
3001 };
3002
3003 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3004
3005 struct cmd_set_txpkts_result {
3006         cmdline_fixed_string_t cmd_keyword;
3007         cmdline_fixed_string_t txpkts;
3008         cmdline_fixed_string_t seg_lengths;
3009 };
3010
3011 static void
3012 cmd_set_txpkts_parsed(void *parsed_result,
3013                       __attribute__((unused)) struct cmdline *cl,
3014                       __attribute__((unused)) void *data)
3015 {
3016         struct cmd_set_txpkts_result *res;
3017         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3018         unsigned int nb_segs;
3019
3020         res = parsed_result;
3021         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3022                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3023         if (nb_segs > 0)
3024                 set_tx_pkt_segments(seg_lengths, nb_segs);
3025 }
3026
3027 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3028         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3029                                  cmd_keyword, "set");
3030 cmdline_parse_token_string_t cmd_set_txpkts_name =
3031         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3032                                  txpkts, "txpkts");
3033 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3034         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3035                                  seg_lengths, NULL);
3036
3037 cmdline_parse_inst_t cmd_set_txpkts = {
3038         .f = cmd_set_txpkts_parsed,
3039         .data = NULL,
3040         .help_str = "set txpkts <len0[,len1]*>",
3041         .tokens = {
3042                 (void *)&cmd_set_txpkts_keyword,
3043                 (void *)&cmd_set_txpkts_name,
3044                 (void *)&cmd_set_txpkts_lengths,
3045                 NULL,
3046         },
3047 };
3048
3049 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3050
3051 struct cmd_set_txsplit_result {
3052         cmdline_fixed_string_t cmd_keyword;
3053         cmdline_fixed_string_t txsplit;
3054         cmdline_fixed_string_t mode;
3055 };
3056
3057 static void
3058 cmd_set_txsplit_parsed(void *parsed_result,
3059                       __attribute__((unused)) struct cmdline *cl,
3060                       __attribute__((unused)) void *data)
3061 {
3062         struct cmd_set_txsplit_result *res;
3063
3064         res = parsed_result;
3065         set_tx_pkt_split(res->mode);
3066 }
3067
3068 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3069         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3070                                  cmd_keyword, "set");
3071 cmdline_parse_token_string_t cmd_set_txsplit_name =
3072         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3073                                  txsplit, "txsplit");
3074 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3075         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3076                                  mode, NULL);
3077
3078 cmdline_parse_inst_t cmd_set_txsplit = {
3079         .f = cmd_set_txsplit_parsed,
3080         .data = NULL,
3081         .help_str = "set txsplit on|off|rand",
3082         .tokens = {
3083                 (void *)&cmd_set_txsplit_keyword,
3084                 (void *)&cmd_set_txsplit_name,
3085                 (void *)&cmd_set_txsplit_mode,
3086                 NULL,
3087         },
3088 };
3089
3090 /* *** CONFIG TX QUEUE FLAGS *** */
3091
3092 struct cmd_config_txqflags_result {
3093         cmdline_fixed_string_t port;
3094         cmdline_fixed_string_t config;
3095         cmdline_fixed_string_t all;
3096         cmdline_fixed_string_t what;
3097         int32_t hexvalue;
3098 };
3099
3100 static void cmd_config_txqflags_parsed(void *parsed_result,
3101                                 __attribute__((unused)) struct cmdline *cl,
3102                                 __attribute__((unused)) void *data)
3103 {
3104         struct cmd_config_txqflags_result *res = parsed_result;
3105
3106         if (!all_ports_stopped()) {
3107                 printf("Please stop all ports first\n");
3108                 return;
3109         }
3110
3111         if (strcmp(res->what, "txqflags")) {
3112                 printf("Unknown parameter\n");
3113                 return;
3114         }
3115
3116         if (res->hexvalue >= 0) {
3117                 txq_flags = res->hexvalue;
3118         } else {
3119                 printf("txqflags must be >= 0\n");
3120                 return;
3121         }
3122
3123         init_port_config();
3124
3125         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3126 }
3127
3128 cmdline_parse_token_string_t cmd_config_txqflags_port =
3129         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3130                                  "port");
3131 cmdline_parse_token_string_t cmd_config_txqflags_config =
3132         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3133                                  "config");
3134 cmdline_parse_token_string_t cmd_config_txqflags_all =
3135         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3136                                  "all");
3137 cmdline_parse_token_string_t cmd_config_txqflags_what =
3138         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3139                                  "txqflags");
3140 cmdline_parse_token_num_t cmd_config_txqflags_value =
3141         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3142                                 hexvalue, INT32);
3143
3144 cmdline_parse_inst_t cmd_config_txqflags = {
3145         .f = cmd_config_txqflags_parsed,
3146         .data = NULL,
3147         .help_str = "port config all txqflags <value>",
3148         .tokens = {
3149                 (void *)&cmd_config_txqflags_port,
3150                 (void *)&cmd_config_txqflags_config,
3151                 (void *)&cmd_config_txqflags_all,
3152                 (void *)&cmd_config_txqflags_what,
3153                 (void *)&cmd_config_txqflags_value,
3154                 NULL,
3155         },
3156 };
3157
3158 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3159 struct cmd_rx_vlan_filter_all_result {
3160         cmdline_fixed_string_t rx_vlan;
3161         cmdline_fixed_string_t what;
3162         cmdline_fixed_string_t all;
3163         portid_t port_id;
3164 };
3165
3166 static void
3167 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3168                               __attribute__((unused)) struct cmdline *cl,
3169                               __attribute__((unused)) void *data)
3170 {
3171         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3172
3173         if (!strcmp(res->what, "add"))
3174                 rx_vlan_all_filter_set(res->port_id, 1);
3175         else
3176                 rx_vlan_all_filter_set(res->port_id, 0);
3177 }
3178
3179 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3180         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3181                                  rx_vlan, "rx_vlan");
3182 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3183         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3184                                  what, "add#rm");
3185 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3186         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3187                                  all, "all");
3188 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3189         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3190                               port_id, UINT16);
3191
3192 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3193         .f = cmd_rx_vlan_filter_all_parsed,
3194         .data = NULL,
3195         .help_str = "rx_vlan add|rm all <port_id>: "
3196                 "Add/Remove all identifiers to/from the set of VLAN "
3197                 "identifiers filtered by a port",
3198         .tokens = {
3199                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3200                 (void *)&cmd_rx_vlan_filter_all_what,
3201                 (void *)&cmd_rx_vlan_filter_all_all,
3202                 (void *)&cmd_rx_vlan_filter_all_portid,
3203                 NULL,
3204         },
3205 };
3206
3207 /* *** VLAN OFFLOAD SET ON A PORT *** */
3208 struct cmd_vlan_offload_result {
3209         cmdline_fixed_string_t vlan;
3210         cmdline_fixed_string_t set;
3211         cmdline_fixed_string_t vlan_type;
3212         cmdline_fixed_string_t what;
3213         cmdline_fixed_string_t on;
3214         cmdline_fixed_string_t port_id;
3215 };
3216
3217 static void
3218 cmd_vlan_offload_parsed(void *parsed_result,
3219                           __attribute__((unused)) struct cmdline *cl,
3220                           __attribute__((unused)) void *data)
3221 {
3222         int on;
3223         struct cmd_vlan_offload_result *res = parsed_result;
3224         char *str;
3225         int i, len = 0;
3226         portid_t port_id = 0;
3227         unsigned int tmp;
3228
3229         str = res->port_id;
3230         len = strnlen(str, STR_TOKEN_SIZE);
3231         i = 0;
3232         /* Get port_id first */
3233         while(i < len){
3234                 if(str[i] == ',')
3235                         break;
3236
3237                 i++;
3238         }
3239         str[i]='\0';
3240         tmp = strtoul(str, NULL, 0);
3241         /* If port_id greater that what portid_t can represent, return */
3242         if(tmp >= RTE_MAX_ETHPORTS)
3243                 return;
3244         port_id = (portid_t)tmp;
3245
3246         if (!strcmp(res->on, "on"))
3247                 on = 1;
3248         else
3249                 on = 0;
3250
3251         if (!strcmp(res->what, "strip"))
3252                 rx_vlan_strip_set(port_id,  on);
3253         else if(!strcmp(res->what, "stripq")){
3254                 uint16_t queue_id = 0;
3255
3256                 /* No queue_id, return */
3257                 if(i + 1 >= len) {
3258                         printf("must specify (port,queue_id)\n");
3259                         return;
3260                 }
3261                 tmp = strtoul(str + i + 1, NULL, 0);
3262                 /* If queue_id greater that what 16-bits can represent, return */
3263                 if(tmp > 0xffff)
3264                         return;
3265
3266                 queue_id = (uint16_t)tmp;
3267                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3268         }
3269         else if (!strcmp(res->what, "filter"))
3270                 rx_vlan_filter_set(port_id, on);
3271         else
3272                 vlan_extend_set(port_id, on);
3273
3274         return;
3275 }
3276
3277 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3278         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3279                                  vlan, "vlan");
3280 cmdline_parse_token_string_t cmd_vlan_offload_set =
3281         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3282                                  set, "set");
3283 cmdline_parse_token_string_t cmd_vlan_offload_what =
3284         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3285                                  what, "strip#filter#qinq#stripq");
3286 cmdline_parse_token_string_t cmd_vlan_offload_on =
3287         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3288                               on, "on#off");
3289 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3290         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3291                               port_id, NULL);
3292
3293 cmdline_parse_inst_t cmd_vlan_offload = {
3294         .f = cmd_vlan_offload_parsed,
3295         .data = NULL,
3296         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3297                 "<port_id[,queue_id]>: "
3298                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3299         .tokens = {
3300                 (void *)&cmd_vlan_offload_vlan,
3301                 (void *)&cmd_vlan_offload_set,
3302                 (void *)&cmd_vlan_offload_what,
3303                 (void *)&cmd_vlan_offload_on,
3304                 (void *)&cmd_vlan_offload_portid,
3305                 NULL,
3306         },
3307 };
3308
3309 /* *** VLAN TPID SET ON A PORT *** */
3310 struct cmd_vlan_tpid_result {
3311         cmdline_fixed_string_t vlan;
3312         cmdline_fixed_string_t set;
3313         cmdline_fixed_string_t vlan_type;
3314         cmdline_fixed_string_t what;
3315         uint16_t tp_id;
3316         portid_t port_id;
3317 };
3318
3319 static void
3320 cmd_vlan_tpid_parsed(void *parsed_result,
3321                           __attribute__((unused)) struct cmdline *cl,
3322                           __attribute__((unused)) void *data)
3323 {
3324         struct cmd_vlan_tpid_result *res = parsed_result;
3325         enum rte_vlan_type vlan_type;
3326
3327         if (!strcmp(res->vlan_type, "inner"))
3328                 vlan_type = ETH_VLAN_TYPE_INNER;
3329         else if (!strcmp(res->vlan_type, "outer"))
3330                 vlan_type = ETH_VLAN_TYPE_OUTER;
3331         else {
3332                 printf("Unknown vlan type\n");
3333                 return;
3334         }
3335         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3336 }
3337
3338 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3339         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3340                                  vlan, "vlan");
3341 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3342         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3343                                  set, "set");
3344 cmdline_parse_token_string_t cmd_vlan_type =
3345         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3346                                  vlan_type, "inner#outer");
3347 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3348         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3349                                  what, "tpid");
3350 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3351         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3352                               tp_id, UINT16);
3353 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3354         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3355                               port_id, UINT8);
3356
3357 cmdline_parse_inst_t cmd_vlan_tpid = {
3358         .f = cmd_vlan_tpid_parsed,
3359         .data = NULL,
3360         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3361                 "Set the VLAN Ether type",
3362         .tokens = {
3363                 (void *)&cmd_vlan_tpid_vlan,
3364                 (void *)&cmd_vlan_tpid_set,
3365                 (void *)&cmd_vlan_type,
3366                 (void *)&cmd_vlan_tpid_what,
3367                 (void *)&cmd_vlan_tpid_tpid,
3368                 (void *)&cmd_vlan_tpid_portid,
3369                 NULL,
3370         },
3371 };
3372
3373 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3374 struct cmd_rx_vlan_filter_result {
3375         cmdline_fixed_string_t rx_vlan;
3376         cmdline_fixed_string_t what;
3377         uint16_t vlan_id;
3378         portid_t port_id;
3379 };
3380
3381 static void
3382 cmd_rx_vlan_filter_parsed(void *parsed_result,
3383                           __attribute__((unused)) struct cmdline *cl,
3384                           __attribute__((unused)) void *data)
3385 {
3386         struct cmd_rx_vlan_filter_result *res = parsed_result;
3387
3388         if (!strcmp(res->what, "add"))
3389                 rx_vft_set(res->port_id, res->vlan_id, 1);
3390         else
3391                 rx_vft_set(res->port_id, res->vlan_id, 0);
3392 }
3393
3394 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3395         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3396                                  rx_vlan, "rx_vlan");
3397 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3398         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3399                                  what, "add#rm");
3400 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3401         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3402                               vlan_id, UINT16);
3403 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3404         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3405                               port_id, UINT16);
3406
3407 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3408         .f = cmd_rx_vlan_filter_parsed,
3409         .data = NULL,
3410         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3411                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3412                 "identifiers filtered by a port",
3413         .tokens = {
3414                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3415                 (void *)&cmd_rx_vlan_filter_what,
3416                 (void *)&cmd_rx_vlan_filter_vlanid,
3417                 (void *)&cmd_rx_vlan_filter_portid,
3418                 NULL,
3419         },
3420 };
3421
3422 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3423 struct cmd_tx_vlan_set_result {
3424         cmdline_fixed_string_t tx_vlan;
3425         cmdline_fixed_string_t set;
3426         portid_t port_id;
3427         uint16_t vlan_id;
3428 };
3429
3430 static void
3431 cmd_tx_vlan_set_parsed(void *parsed_result,
3432                        __attribute__((unused)) struct cmdline *cl,
3433                        __attribute__((unused)) void *data)
3434 {
3435         struct cmd_tx_vlan_set_result *res = parsed_result;
3436
3437         tx_vlan_set(res->port_id, res->vlan_id);
3438 }
3439
3440 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3441         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3442                                  tx_vlan, "tx_vlan");
3443 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3444         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3445                                  set, "set");
3446 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3447         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3448                               port_id, UINT16);
3449 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3450         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3451                               vlan_id, UINT16);
3452
3453 cmdline_parse_inst_t cmd_tx_vlan_set = {
3454         .f = cmd_tx_vlan_set_parsed,
3455         .data = NULL,
3456         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3457                 "Enable hardware insertion of a single VLAN header "
3458                 "with a given TAG Identifier in packets sent on a port",
3459         .tokens = {
3460                 (void *)&cmd_tx_vlan_set_tx_vlan,
3461                 (void *)&cmd_tx_vlan_set_set,
3462                 (void *)&cmd_tx_vlan_set_portid,
3463                 (void *)&cmd_tx_vlan_set_vlanid,
3464                 NULL,
3465         },
3466 };
3467
3468 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3469 struct cmd_tx_vlan_set_qinq_result {
3470         cmdline_fixed_string_t tx_vlan;
3471         cmdline_fixed_string_t set;
3472         portid_t port_id;
3473         uint16_t vlan_id;
3474         uint16_t vlan_id_outer;
3475 };
3476
3477 static void
3478 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3479                             __attribute__((unused)) struct cmdline *cl,
3480                             __attribute__((unused)) void *data)
3481 {
3482         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3483
3484         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3485 }
3486
3487 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3488         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3489                 tx_vlan, "tx_vlan");
3490 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3491         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3492                 set, "set");
3493 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3494         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3495                 port_id, UINT16);
3496 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3497         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3498                 vlan_id, UINT16);
3499 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3500         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3501                 vlan_id_outer, UINT16);
3502
3503 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3504         .f = cmd_tx_vlan_set_qinq_parsed,
3505         .data = NULL,
3506         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3507                 "Enable hardware insertion of double VLAN header "
3508                 "with given TAG Identifiers in packets sent on a port",
3509         .tokens = {
3510                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3511                 (void *)&cmd_tx_vlan_set_qinq_set,
3512                 (void *)&cmd_tx_vlan_set_qinq_portid,
3513                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3514                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3515                 NULL,
3516         },
3517 };
3518
3519 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3520 struct cmd_tx_vlan_set_pvid_result {
3521         cmdline_fixed_string_t tx_vlan;
3522         cmdline_fixed_string_t set;
3523         cmdline_fixed_string_t pvid;
3524         portid_t port_id;
3525         uint16_t vlan_id;
3526         cmdline_fixed_string_t mode;
3527 };
3528
3529 static void
3530 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3531                             __attribute__((unused)) struct cmdline *cl,
3532                             __attribute__((unused)) void *data)
3533 {
3534         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3535
3536         if (strcmp(res->mode, "on") == 0)
3537                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3538         else
3539                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3540 }
3541
3542 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3543         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3544                                  tx_vlan, "tx_vlan");
3545 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3546         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3547                                  set, "set");
3548 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3549         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3550                                  pvid, "pvid");
3551 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3552         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3553                              port_id, UINT16);
3554 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3555         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3556                               vlan_id, UINT16);
3557 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3558         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3559                                  mode, "on#off");
3560
3561 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3562         .f = cmd_tx_vlan_set_pvid_parsed,
3563         .data = NULL,
3564         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3565         .tokens = {
3566                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3567                 (void *)&cmd_tx_vlan_set_pvid_set,
3568                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3569                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3570                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3571                 (void *)&cmd_tx_vlan_set_pvid_mode,
3572                 NULL,
3573         },
3574 };
3575
3576 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3577 struct cmd_tx_vlan_reset_result {
3578         cmdline_fixed_string_t tx_vlan;
3579         cmdline_fixed_string_t reset;
3580         portid_t port_id;
3581 };
3582
3583 static void
3584 cmd_tx_vlan_reset_parsed(void *parsed_result,
3585                          __attribute__((unused)) struct cmdline *cl,
3586                          __attribute__((unused)) void *data)
3587 {
3588         struct cmd_tx_vlan_reset_result *res = parsed_result;
3589
3590         tx_vlan_reset(res->port_id);
3591 }
3592
3593 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3594         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3595                                  tx_vlan, "tx_vlan");
3596 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3597         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3598                                  reset, "reset");
3599 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3600         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3601                               port_id, UINT16);
3602
3603 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3604         .f = cmd_tx_vlan_reset_parsed,
3605         .data = NULL,
3606         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3607                 "VLAN header in packets sent on a port",
3608         .tokens = {
3609                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3610                 (void *)&cmd_tx_vlan_reset_reset,
3611                 (void *)&cmd_tx_vlan_reset_portid,
3612                 NULL,
3613         },
3614 };
3615
3616
3617 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3618 struct cmd_csum_result {
3619         cmdline_fixed_string_t csum;
3620         cmdline_fixed_string_t mode;
3621         cmdline_fixed_string_t proto;
3622         cmdline_fixed_string_t hwsw;
3623         portid_t port_id;
3624 };
3625
3626 static void
3627 csum_show(int port_id)
3628 {
3629         struct rte_eth_dev_info dev_info;
3630         uint16_t ol_flags;
3631
3632         ol_flags = ports[port_id].tx_ol_flags;
3633         printf("Parse tunnel is %s\n",
3634                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3635         printf("IP checksum offload is %s\n",
3636                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3637         printf("UDP checksum offload is %s\n",
3638                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3639         printf("TCP checksum offload is %s\n",
3640                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3641         printf("SCTP checksum offload is %s\n",
3642                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3643         printf("Outer-Ip checksum offload is %s\n",
3644                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3645
3646         /* display warnings if configuration is not supported by the NIC */
3647         rte_eth_dev_info_get(port_id, &dev_info);
3648         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3649                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3650                 printf("Warning: hardware IP checksum enabled but not "
3651                         "supported by port %d\n", port_id);
3652         }
3653         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3654                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3655                 printf("Warning: hardware UDP checksum enabled but not "
3656                         "supported by port %d\n", port_id);
3657         }
3658         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3659                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3660                 printf("Warning: hardware TCP checksum enabled but not "
3661                         "supported by port %d\n", port_id);
3662         }
3663         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3664                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3665                 printf("Warning: hardware SCTP checksum enabled but not "
3666                         "supported by port %d\n", port_id);
3667         }
3668         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3669                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3670                 printf("Warning: hardware outer IP checksum enabled but not "
3671                         "supported by port %d\n", port_id);
3672         }
3673 }
3674
3675 static void
3676 cmd_csum_parsed(void *parsed_result,
3677                        __attribute__((unused)) struct cmdline *cl,
3678                        __attribute__((unused)) void *data)
3679 {
3680         struct cmd_csum_result *res = parsed_result;
3681         int hw = 0;
3682         uint16_t mask = 0;
3683
3684         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3685                 printf("invalid port %d\n", res->port_id);
3686                 return;
3687         }
3688
3689         if (!strcmp(res->mode, "set")) {
3690
3691                 if (!strcmp(res->hwsw, "hw"))
3692                         hw = 1;
3693
3694                 if (!strcmp(res->proto, "ip")) {
3695                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3696                 } else if (!strcmp(res->proto, "udp")) {
3697                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3698                 } else if (!strcmp(res->proto, "tcp")) {
3699                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3700                 } else if (!strcmp(res->proto, "sctp")) {
3701                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3702                 } else if (!strcmp(res->proto, "outer-ip")) {
3703                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3704                 }
3705
3706                 if (hw)
3707                         ports[res->port_id].tx_ol_flags |= mask;
3708                 else
3709                         ports[res->port_id].tx_ol_flags &= (~mask);
3710         }
3711         csum_show(res->port_id);
3712 }
3713
3714 cmdline_parse_token_string_t cmd_csum_csum =
3715         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3716                                 csum, "csum");
3717 cmdline_parse_token_string_t cmd_csum_mode =
3718         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3719                                 mode, "set");
3720 cmdline_parse_token_string_t cmd_csum_proto =
3721         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3722                                 proto, "ip#tcp#udp#sctp#outer-ip");
3723 cmdline_parse_token_string_t cmd_csum_hwsw =
3724         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3725                                 hwsw, "hw#sw");
3726 cmdline_parse_token_num_t cmd_csum_portid =
3727         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3728                                 port_id, UINT16);
3729
3730 cmdline_parse_inst_t cmd_csum_set = {
3731         .f = cmd_csum_parsed,
3732         .data = NULL,
3733         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3734                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3735                 "using csum forward engine",
3736         .tokens = {
3737                 (void *)&cmd_csum_csum,
3738                 (void *)&cmd_csum_mode,
3739                 (void *)&cmd_csum_proto,
3740                 (void *)&cmd_csum_hwsw,
3741                 (void *)&cmd_csum_portid,
3742                 NULL,
3743         },
3744 };
3745
3746 cmdline_parse_token_string_t cmd_csum_mode_show =
3747         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3748                                 mode, "show");
3749
3750 cmdline_parse_inst_t cmd_csum_show = {
3751         .f = cmd_csum_parsed,
3752         .data = NULL,
3753         .help_str = "csum show <port_id>: Show checksum offload configuration",
3754         .tokens = {
3755                 (void *)&cmd_csum_csum,
3756                 (void *)&cmd_csum_mode_show,
3757                 (void *)&cmd_csum_portid,
3758                 NULL,
3759         },
3760 };
3761
3762 /* Enable/disable tunnel parsing */
3763 struct cmd_csum_tunnel_result {
3764         cmdline_fixed_string_t csum;
3765         cmdline_fixed_string_t parse;
3766         cmdline_fixed_string_t onoff;
3767         portid_t port_id;
3768 };
3769
3770 static void
3771 cmd_csum_tunnel_parsed(void *parsed_result,
3772                        __attribute__((unused)) struct cmdline *cl,
3773                        __attribute__((unused)) void *data)
3774 {
3775         struct cmd_csum_tunnel_result *res = parsed_result;
3776
3777         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3778                 return;
3779
3780         if (!strcmp(res->onoff, "on"))
3781                 ports[res->port_id].tx_ol_flags |=
3782                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3783         else
3784                 ports[res->port_id].tx_ol_flags &=
3785                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3786
3787         csum_show(res->port_id);
3788 }
3789
3790 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3791         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3792                                 csum, "csum");
3793 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3794         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3795                                 parse, "parse_tunnel");
3796 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3797         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3798                                 onoff, "on#off");
3799 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3800         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3801                                 port_id, UINT16);
3802
3803 cmdline_parse_inst_t cmd_csum_tunnel = {
3804         .f = cmd_csum_tunnel_parsed,
3805         .data = NULL,
3806         .help_str = "csum parse_tunnel on|off <port_id>: "
3807                 "Enable/Disable parsing of tunnels for csum engine",
3808         .tokens = {
3809                 (void *)&cmd_csum_tunnel_csum,
3810                 (void *)&cmd_csum_tunnel_parse,
3811                 (void *)&cmd_csum_tunnel_onoff,
3812                 (void *)&cmd_csum_tunnel_portid,
3813                 NULL,
3814         },
3815 };
3816
3817 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3818 struct cmd_tso_set_result {
3819         cmdline_fixed_string_t tso;
3820         cmdline_fixed_string_t mode;
3821         uint16_t tso_segsz;
3822         portid_t port_id;
3823 };
3824
3825 static void
3826 cmd_tso_set_parsed(void *parsed_result,
3827                        __attribute__((unused)) struct cmdline *cl,
3828                        __attribute__((unused)) void *data)
3829 {
3830         struct cmd_tso_set_result *res = parsed_result;
3831         struct rte_eth_dev_info dev_info;
3832
3833         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3834                 return;
3835
3836         if (!strcmp(res->mode, "set"))
3837                 ports[res->port_id].tso_segsz = res->tso_segsz;
3838
3839         if (ports[res->port_id].tso_segsz == 0)
3840                 printf("TSO for non-tunneled packets is disabled\n");
3841         else
3842                 printf("TSO segment size for non-tunneled packets is %d\n",
3843                         ports[res->port_id].tso_segsz);
3844
3845         /* display warnings if configuration is not supported by the NIC */
3846         rte_eth_dev_info_get(res->port_id, &dev_info);
3847         if ((ports[res->port_id].tso_segsz != 0) &&
3848                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3849                 printf("Warning: TSO enabled but not "
3850                         "supported by port %d\n", res->port_id);
3851         }
3852 }
3853
3854 cmdline_parse_token_string_t cmd_tso_set_tso =
3855         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3856                                 tso, "tso");
3857 cmdline_parse_token_string_t cmd_tso_set_mode =
3858         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3859                                 mode, "set");
3860 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3861         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3862                                 tso_segsz, UINT16);
3863 cmdline_parse_token_num_t cmd_tso_set_portid =
3864         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3865                                 port_id, UINT16);
3866
3867 cmdline_parse_inst_t cmd_tso_set = {
3868         .f = cmd_tso_set_parsed,
3869         .data = NULL,
3870         .help_str = "tso set <tso_segsz> <port_id>: "
3871                 "Set TSO segment size of non-tunneled packets for csum engine "
3872                 "(0 to disable)",
3873         .tokens = {
3874                 (void *)&cmd_tso_set_tso,
3875                 (void *)&cmd_tso_set_mode,
3876                 (void *)&cmd_tso_set_tso_segsz,
3877                 (void *)&cmd_tso_set_portid,
3878                 NULL,
3879         },
3880 };
3881
3882 cmdline_parse_token_string_t cmd_tso_show_mode =
3883         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3884                                 mode, "show");
3885
3886
3887 cmdline_parse_inst_t cmd_tso_show = {
3888         .f = cmd_tso_set_parsed,
3889         .data = NULL,
3890         .help_str = "tso show <port_id>: "
3891                 "Show TSO segment size of non-tunneled packets for csum engine",
3892         .tokens = {
3893                 (void *)&cmd_tso_set_tso,
3894                 (void *)&cmd_tso_show_mode,
3895                 (void *)&cmd_tso_set_portid,
3896                 NULL,
3897         },
3898 };
3899
3900 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3901 struct cmd_tunnel_tso_set_result {
3902         cmdline_fixed_string_t tso;
3903         cmdline_fixed_string_t mode;
3904         uint16_t tso_segsz;
3905         portid_t port_id;
3906 };
3907
3908 static void
3909 check_tunnel_tso_nic_support(portid_t port_id)
3910 {
3911         struct rte_eth_dev_info dev_info;
3912
3913         rte_eth_dev_info_get(port_id, &dev_info);
3914         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3915                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3916                        "supported by port %d\n", port_id);
3917         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3918                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3919                         "supported by port %d\n", port_id);
3920         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3921                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3922                        "supported by port %d\n", port_id);
3923         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3924                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3925                        "supported by port %d\n", port_id);
3926 }
3927
3928 static void
3929 cmd_tunnel_tso_set_parsed(void *parsed_result,
3930                           __attribute__((unused)) struct cmdline *cl,
3931                           __attribute__((unused)) void *data)
3932 {
3933         struct cmd_tunnel_tso_set_result *res = parsed_result;
3934
3935         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3936                 return;
3937
3938         if (!strcmp(res->mode, "set"))
3939                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3940
3941         if (ports[res->port_id].tunnel_tso_segsz == 0)
3942                 printf("TSO for tunneled packets is disabled\n");
3943         else {
3944                 printf("TSO segment size for tunneled packets is %d\n",
3945                         ports[res->port_id].tunnel_tso_segsz);
3946
3947                 /* Below conditions are needed to make it work:
3948                  * (1) tunnel TSO is supported by the NIC;
3949                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3950                  * are recognized;
3951                  * (3) for tunneled pkts with outer L3 of IPv4,
3952                  * "csum set outer-ip" must be set to hw, because after tso,
3953                  * total_len of outer IP header is changed, and the checksum
3954                  * of outer IP header calculated by sw should be wrong; that
3955                  * is not necessary for IPv6 tunneled pkts because there's no
3956                  * checksum in IP header anymore.
3957                  */
3958                 check_tunnel_tso_nic_support(res->port_id);
3959
3960                 if (!(ports[res->port_id].tx_ol_flags &
3961                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3962                         printf("Warning: csum parse_tunnel must be set "
3963                                 "so that tunneled packets are recognized\n");
3964                 if (!(ports[res->port_id].tx_ol_flags &
3965                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3966                         printf("Warning: csum set outer-ip must be set to hw "
3967                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3968         }
3969 }
3970
3971 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3972         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3973                                 tso, "tunnel_tso");
3974 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3975         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3976                                 mode, "set");
3977 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3978         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3979                                 tso_segsz, UINT16);
3980 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3981         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3982                                 port_id, UINT16);
3983
3984 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3985         .f = cmd_tunnel_tso_set_parsed,
3986         .data = NULL,
3987         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3988                 "Set TSO segment size of tunneled packets for csum engine "
3989                 "(0 to disable)",
3990         .tokens = {
3991                 (void *)&cmd_tunnel_tso_set_tso,
3992                 (void *)&cmd_tunnel_tso_set_mode,
3993                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3994                 (void *)&cmd_tunnel_tso_set_portid,
3995                 NULL,
3996         },
3997 };
3998
3999 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4000         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4001                                 mode, "show");
4002
4003
4004 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4005         .f = cmd_tunnel_tso_set_parsed,
4006         .data = NULL,
4007         .help_str = "tunnel_tso show <port_id> "
4008                 "Show TSO segment size of tunneled packets for csum engine",
4009         .tokens = {
4010                 (void *)&cmd_tunnel_tso_set_tso,
4011                 (void *)&cmd_tunnel_tso_show_mode,
4012                 (void *)&cmd_tunnel_tso_set_portid,
4013                 NULL,
4014         },
4015 };
4016
4017 /* *** SET GRO FOR A PORT *** */
4018 struct cmd_gro_enable_result {
4019         cmdline_fixed_string_t cmd_set;
4020         cmdline_fixed_string_t cmd_port;
4021         cmdline_fixed_string_t cmd_keyword;
4022         cmdline_fixed_string_t cmd_onoff;
4023         portid_t cmd_pid;
4024 };
4025
4026 static void
4027 cmd_gro_enable_parsed(void *parsed_result,
4028                 __attribute__((unused)) struct cmdline *cl,
4029                 __attribute__((unused)) void *data)
4030 {
4031         struct cmd_gro_enable_result *res;
4032
4033         res = parsed_result;
4034         if (!strcmp(res->cmd_keyword, "gro"))
4035                 setup_gro(res->cmd_onoff, res->cmd_pid);
4036 }
4037
4038 cmdline_parse_token_string_t cmd_gro_enable_set =
4039         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4040                         cmd_set, "set");
4041 cmdline_parse_token_string_t cmd_gro_enable_port =
4042         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4043                         cmd_keyword, "port");
4044 cmdline_parse_token_num_t cmd_gro_enable_pid =
4045         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4046                         cmd_pid, UINT16);
4047 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4048         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4049                         cmd_keyword, "gro");
4050 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4051         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4052                         cmd_onoff, "on#off");
4053
4054 cmdline_parse_inst_t cmd_gro_enable = {
4055         .f = cmd_gro_enable_parsed,
4056         .data = NULL,
4057         .help_str = "set port <port_id> gro on|off",
4058         .tokens = {
4059                 (void *)&cmd_gro_enable_set,
4060                 (void *)&cmd_gro_enable_port,
4061                 (void *)&cmd_gro_enable_pid,
4062                 (void *)&cmd_gro_enable_keyword,
4063                 (void *)&cmd_gro_enable_onoff,
4064                 NULL,
4065         },
4066 };
4067
4068 /* *** DISPLAY GRO CONFIGURATION *** */
4069 struct cmd_gro_show_result {
4070         cmdline_fixed_string_t cmd_show;
4071         cmdline_fixed_string_t cmd_port;
4072         cmdline_fixed_string_t cmd_keyword;
4073         portid_t cmd_pid;
4074 };
4075
4076 static void
4077 cmd_gro_show_parsed(void *parsed_result,
4078                 __attribute__((unused)) struct cmdline *cl,
4079                 __attribute__((unused)) void *data)
4080 {
4081         struct cmd_gro_show_result *res;
4082
4083         res = parsed_result;
4084         if (!strcmp(res->cmd_keyword, "gro"))
4085                 show_gro(res->cmd_pid);
4086 }
4087
4088 cmdline_parse_token_string_t cmd_gro_show_show =
4089         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4090                         cmd_show, "show");
4091 cmdline_parse_token_string_t cmd_gro_show_port =
4092         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4093                         cmd_port, "port");
4094 cmdline_parse_token_num_t cmd_gro_show_pid =
4095         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4096                         cmd_pid, UINT16);
4097 cmdline_parse_token_string_t cmd_gro_show_keyword =
4098         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4099                         cmd_keyword, "gro");
4100
4101 cmdline_parse_inst_t cmd_gro_show = {
4102         .f = cmd_gro_show_parsed,
4103         .data = NULL,
4104         .help_str = "show port <port_id> gro",
4105         .tokens = {
4106                 (void *)&cmd_gro_show_show,
4107                 (void *)&cmd_gro_show_port,
4108                 (void *)&cmd_gro_show_pid,
4109                 (void *)&cmd_gro_show_keyword,
4110                 NULL,
4111         },
4112 };
4113
4114 /* *** SET FLUSH CYCLES FOR GRO *** */
4115 struct cmd_gro_flush_result {
4116         cmdline_fixed_string_t cmd_set;
4117         cmdline_fixed_string_t cmd_keyword;
4118         cmdline_fixed_string_t cmd_flush;
4119         uint8_t cmd_cycles;
4120 };
4121
4122 static void
4123 cmd_gro_flush_parsed(void *parsed_result,
4124                 __attribute__((unused)) struct cmdline *cl,
4125                 __attribute__((unused)) void *data)
4126 {
4127         struct cmd_gro_flush_result *res;
4128
4129         res = parsed_result;
4130         if ((!strcmp(res->cmd_keyword, "gro")) &&
4131                         (!strcmp(res->cmd_flush, "flush")))
4132                 setup_gro_flush_cycles(res->cmd_cycles);
4133 }
4134
4135 cmdline_parse_token_string_t cmd_gro_flush_set =
4136         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4137                         cmd_set, "set");
4138 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4139         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4140                         cmd_keyword, "gro");
4141 cmdline_parse_token_string_t cmd_gro_flush_flush =
4142         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4143                         cmd_flush, "flush");
4144 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4145         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4146                         cmd_cycles, UINT8);
4147
4148 cmdline_parse_inst_t cmd_gro_flush = {
4149         .f = cmd_gro_flush_parsed,
4150         .data = NULL,
4151         .help_str = "set gro flush <cycles>",
4152         .tokens = {
4153                 (void *)&cmd_gro_flush_set,
4154                 (void *)&cmd_gro_flush_keyword,
4155                 (void *)&cmd_gro_flush_flush,
4156                 (void *)&cmd_gro_flush_cycles,
4157                 NULL,
4158         },
4159 };
4160
4161 /* *** ENABLE/DISABLE GSO *** */
4162 struct cmd_gso_enable_result {
4163         cmdline_fixed_string_t cmd_set;
4164         cmdline_fixed_string_t cmd_port;
4165         cmdline_fixed_string_t cmd_keyword;
4166         cmdline_fixed_string_t cmd_mode;
4167         portid_t cmd_pid;
4168 };
4169
4170 static void
4171 cmd_gso_enable_parsed(void *parsed_result,
4172                 __attribute__((unused)) struct cmdline *cl,
4173                 __attribute__((unused)) void *data)
4174 {
4175         struct cmd_gso_enable_result *res;
4176
4177         res = parsed_result;
4178         if (!strcmp(res->cmd_keyword, "gso"))
4179                 setup_gso(res->cmd_mode, res->cmd_pid);
4180 }
4181
4182 cmdline_parse_token_string_t cmd_gso_enable_set =
4183         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4184                         cmd_set, "set");
4185 cmdline_parse_token_string_t cmd_gso_enable_port =
4186         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4187                         cmd_port, "port");
4188 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4189         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4190                         cmd_keyword, "gso");
4191 cmdline_parse_token_string_t cmd_gso_enable_mode =
4192         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4193                         cmd_mode, "on#off");
4194 cmdline_parse_token_num_t cmd_gso_enable_pid =
4195         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4196                         cmd_pid, UINT16);
4197
4198 cmdline_parse_inst_t cmd_gso_enable = {
4199         .f = cmd_gso_enable_parsed,
4200         .data = NULL,
4201         .help_str = "set port <port_id> gso on|off",
4202         .tokens = {
4203                 (void *)&cmd_gso_enable_set,
4204                 (void *)&cmd_gso_enable_port,
4205                 (void *)&cmd_gso_enable_pid,
4206                 (void *)&cmd_gso_enable_keyword,
4207                 (void *)&cmd_gso_enable_mode,
4208                 NULL,
4209         },
4210 };
4211
4212 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4213 struct cmd_gso_size_result {
4214         cmdline_fixed_string_t cmd_set;
4215         cmdline_fixed_string_t cmd_keyword;
4216         cmdline_fixed_string_t cmd_segsz;
4217         uint16_t cmd_size;
4218 };
4219
4220 static void
4221 cmd_gso_size_parsed(void *parsed_result,
4222                        __attribute__((unused)) struct cmdline *cl,
4223                        __attribute__((unused)) void *data)
4224 {
4225         struct cmd_gso_size_result *res = parsed_result;
4226
4227         if (test_done == 0) {
4228                 printf("Before setting GSO segsz, please first"
4229                                 " stop fowarding\n");
4230                 return;
4231         }
4232
4233         if (!strcmp(res->cmd_keyword, "gso") &&
4234                         !strcmp(res->cmd_segsz, "segsz")) {
4235                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4236                         printf("gso_size should be larger than %zu."
4237                                         " Please input a legal value\n",
4238                                         RTE_GSO_SEG_SIZE_MIN);
4239                 else
4240                         gso_max_segment_size = res->cmd_size;
4241         }
4242 }
4243
4244 cmdline_parse_token_string_t cmd_gso_size_set =
4245         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4246                                 cmd_set, "set");
4247 cmdline_parse_token_string_t cmd_gso_size_keyword =
4248         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4249                                 cmd_keyword, "gso");
4250 cmdline_parse_token_string_t cmd_gso_size_segsz =
4251         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4252                                 cmd_segsz, "segsz");
4253 cmdline_parse_token_num_t cmd_gso_size_size =
4254         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4255                                 cmd_size, UINT16);
4256
4257 cmdline_parse_inst_t cmd_gso_size = {
4258         .f = cmd_gso_size_parsed,
4259         .data = NULL,
4260         .help_str = "set gso segsz <length>",
4261         .tokens = {
4262                 (void *)&cmd_gso_size_set,
4263                 (void *)&cmd_gso_size_keyword,
4264                 (void *)&cmd_gso_size_segsz,
4265                 (void *)&cmd_gso_size_size,
4266                 NULL,
4267         },
4268 };
4269
4270 /* *** SHOW GSO CONFIGURATION *** */
4271 struct cmd_gso_show_result {
4272         cmdline_fixed_string_t cmd_show;
4273         cmdline_fixed_string_t cmd_port;
4274         cmdline_fixed_string_t cmd_keyword;
4275         portid_t cmd_pid;
4276 };
4277
4278 static void
4279 cmd_gso_show_parsed(void *parsed_result,
4280                        __attribute__((unused)) struct cmdline *cl,
4281                        __attribute__((unused)) void *data)
4282 {
4283         struct cmd_gso_show_result *res = parsed_result;
4284
4285         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4286                 printf("invalid port id %u\n", res->cmd_pid);
4287                 return;
4288         }
4289         if (!strcmp(res->cmd_keyword, "gso")) {
4290                 if (gso_ports[res->cmd_pid].enable) {
4291                         printf("Max GSO'd packet size: %uB\n"
4292                                         "Supported GSO types: TCP/IPv4, "
4293                                         "VxLAN with inner TCP/IPv4 packet, "
4294                                         "GRE with inner TCP/IPv4  packet\n",
4295                                         gso_max_segment_size);
4296                 } else
4297                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4298         }
4299 }
4300
4301 cmdline_parse_token_string_t cmd_gso_show_show =
4302 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4303                 cmd_show, "show");
4304 cmdline_parse_token_string_t cmd_gso_show_port =
4305 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4306                 cmd_port, "port");
4307 cmdline_parse_token_string_t cmd_gso_show_keyword =
4308         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4309                                 cmd_keyword, "gso");
4310 cmdline_parse_token_num_t cmd_gso_show_pid =
4311         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4312                                 cmd_pid, UINT16);
4313
4314 cmdline_parse_inst_t cmd_gso_show = {
4315         .f = cmd_gso_show_parsed,
4316         .data = NULL,
4317         .help_str = "show port <port_id> gso",
4318         .tokens = {
4319                 (void *)&cmd_gso_show_show,
4320                 (void *)&cmd_gso_show_port,
4321                 (void *)&cmd_gso_show_pid,
4322                 (void *)&cmd_gso_show_keyword,
4323                 NULL,
4324         },
4325 };
4326
4327 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4328 struct cmd_set_flush_rx {
4329         cmdline_fixed_string_t set;
4330         cmdline_fixed_string_t flush_rx;
4331         cmdline_fixed_string_t mode;
4332 };
4333
4334 static void
4335 cmd_set_flush_rx_parsed(void *parsed_result,
4336                 __attribute__((unused)) struct cmdline *cl,
4337                 __attribute__((unused)) void *data)
4338 {
4339         struct cmd_set_flush_rx *res = parsed_result;
4340         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4341 }
4342
4343 cmdline_parse_token_string_t cmd_setflushrx_set =
4344         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4345                         set, "set");
4346 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4347         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4348                         flush_rx, "flush_rx");
4349 cmdline_parse_token_string_t cmd_setflushrx_mode =
4350         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4351                         mode, "on#off");
4352
4353
4354 cmdline_parse_inst_t cmd_set_flush_rx = {
4355         .f = cmd_set_flush_rx_parsed,
4356         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4357         .data = NULL,
4358         .tokens = {
4359                 (void *)&cmd_setflushrx_set,
4360                 (void *)&cmd_setflushrx_flush_rx,
4361                 (void *)&cmd_setflushrx_mode,
4362                 NULL,
4363         },
4364 };
4365
4366 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4367 struct cmd_set_link_check {
4368         cmdline_fixed_string_t set;
4369         cmdline_fixed_string_t link_check;
4370         cmdline_fixed_string_t mode;
4371 };
4372
4373 static void
4374 cmd_set_link_check_parsed(void *parsed_result,
4375                 __attribute__((unused)) struct cmdline *cl,
4376                 __attribute__((unused)) void *data)
4377 {
4378         struct cmd_set_link_check *res = parsed_result;
4379         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4380 }
4381
4382 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4383         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4384                         set, "set");
4385 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4386         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4387                         link_check, "link_check");
4388 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4389         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4390                         mode, "on#off");
4391
4392
4393 cmdline_parse_inst_t cmd_set_link_check = {
4394         .f = cmd_set_link_check_parsed,
4395         .help_str = "set link_check on|off: Enable/Disable link status check "
4396                     "when starting/stopping a port",
4397         .data = NULL,
4398         .tokens = {
4399                 (void *)&cmd_setlinkcheck_set,
4400                 (void *)&cmd_setlinkcheck_link_check,
4401                 (void *)&cmd_setlinkcheck_mode,
4402                 NULL,
4403         },
4404 };
4405
4406 /* *** SET NIC BYPASS MODE *** */
4407 struct cmd_set_bypass_mode_result {
4408         cmdline_fixed_string_t set;
4409         cmdline_fixed_string_t bypass;
4410         cmdline_fixed_string_t mode;
4411         cmdline_fixed_string_t value;
4412         portid_t port_id;
4413 };
4414
4415 static void
4416 cmd_set_bypass_mode_parsed(void *parsed_result,
4417                 __attribute__((unused)) struct cmdline *cl,
4418                 __attribute__((unused)) void *data)
4419 {
4420         struct cmd_set_bypass_mode_result *res = parsed_result;
4421         portid_t port_id = res->port_id;
4422         int32_t rc = -EINVAL;
4423
4424 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4425         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4426
4427         if (!strcmp(res->value, "bypass"))
4428                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4429         else if (!strcmp(res->value, "isolate"))
4430                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4431         else
4432                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4433
4434         /* Set the bypass mode for the relevant port. */
4435         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4436 #endif
4437         if (rc != 0)
4438                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4439 }
4440
4441 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4442         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4443                         set, "set");
4444 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4445         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4446                         bypass, "bypass");
4447 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4448         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4449                         mode, "mode");
4450 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4451         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4452                         value, "normal#bypass#isolate");
4453 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4454         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4455                                 port_id, UINT16);
4456
4457 cmdline_parse_inst_t cmd_set_bypass_mode = {
4458         .f = cmd_set_bypass_mode_parsed,
4459         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4460                     "Set the NIC bypass mode for port_id",
4461         .data = NULL,
4462         .tokens = {
4463                 (void *)&cmd_setbypass_mode_set,
4464                 (void *)&cmd_setbypass_mode_bypass,
4465                 (void *)&cmd_setbypass_mode_mode,
4466                 (void *)&cmd_setbypass_mode_value,
4467                 (void *)&cmd_setbypass_mode_port,
4468                 NULL,
4469         },
4470 };
4471
4472 /* *** SET NIC BYPASS EVENT *** */
4473 struct cmd_set_bypass_event_result {
4474         cmdline_fixed_string_t set;
4475         cmdline_fixed_string_t bypass;
4476         cmdline_fixed_string_t event;
4477         cmdline_fixed_string_t event_value;
4478         cmdline_fixed_string_t mode;
4479         cmdline_fixed_string_t mode_value;
4480         portid_t port_id;
4481 };
4482
4483 static void
4484 cmd_set_bypass_event_parsed(void *parsed_result,
4485                 __attribute__((unused)) struct cmdline *cl,
4486                 __attribute__((unused)) void *data)
4487 {
4488         int32_t rc = -EINVAL;
4489         struct cmd_set_bypass_event_result *res = parsed_result;
4490         portid_t port_id = res->port_id;
4491
4492 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4493         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4494         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4495
4496         if (!strcmp(res->event_value, "timeout"))
4497                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4498         else if (!strcmp(res->event_value, "os_on"))
4499                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4500         else if (!strcmp(res->event_value, "os_off"))
4501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4502         else if (!strcmp(res->event_value, "power_on"))
4503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4504         else if (!strcmp(res->event_value, "power_off"))
4505                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4506         else
4507                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4508
4509         if (!strcmp(res->mode_value, "bypass"))
4510                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4511         else if (!strcmp(res->mode_value, "isolate"))
4512                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4513         else
4514                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4515
4516         /* Set the watchdog timeout. */
4517         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4518
4519                 rc = -EINVAL;
4520                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4521                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4522                                                            bypass_timeout);
4523                 }
4524                 if (rc != 0) {
4525                         printf("Failed to set timeout value %u "
4526                         "for port %d, errto code: %d.\n",
4527                         bypass_timeout, port_id, rc);
4528                 }
4529         }
4530
4531         /* Set the bypass event to transition to bypass mode. */
4532         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4533                                               bypass_mode);
4534 #endif
4535
4536         if (rc != 0)
4537                 printf("\t Failed to set bypass event for port = %d.\n",
4538                        port_id);
4539 }
4540
4541 cmdline_parse_token_string_t cmd_setbypass_event_set =
4542         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4543                         set, "set");
4544 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4545         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4546                         bypass, "bypass");
4547 cmdline_parse_token_string_t cmd_setbypass_event_event =
4548         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4549                         event, "event");
4550 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4551         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4552                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4553 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4554         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4555                         mode, "mode");
4556 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4557         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4558                         mode_value, "normal#bypass#isolate");
4559 cmdline_parse_token_num_t cmd_setbypass_event_port =
4560         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4561                                 port_id, UINT16);
4562
4563 cmdline_parse_inst_t cmd_set_bypass_event = {
4564         .f = cmd_set_bypass_event_parsed,
4565         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4566                 "power_off mode normal|bypass|isolate <port_id>: "
4567                 "Set the NIC bypass event mode for port_id",
4568         .data = NULL,
4569         .tokens = {
4570                 (void *)&cmd_setbypass_event_set,
4571                 (void *)&cmd_setbypass_event_bypass,
4572                 (void *)&cmd_setbypass_event_event,
4573                 (void *)&cmd_setbypass_event_event_value,
4574                 (void *)&cmd_setbypass_event_mode,
4575                 (void *)&cmd_setbypass_event_mode_value,
4576                 (void *)&cmd_setbypass_event_port,
4577                 NULL,
4578         },
4579 };
4580
4581
4582 /* *** SET NIC BYPASS TIMEOUT *** */
4583 struct cmd_set_bypass_timeout_result {
4584         cmdline_fixed_string_t set;
4585         cmdline_fixed_string_t bypass;
4586         cmdline_fixed_string_t timeout;
4587         cmdline_fixed_string_t value;
4588 };
4589
4590 static void
4591 cmd_set_bypass_timeout_parsed(void *parsed_result,
4592                 __attribute__((unused)) struct cmdline *cl,
4593                 __attribute__((unused)) void *data)
4594 {
4595         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4596
4597 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4598         if (!strcmp(res->value, "1.5"))
4599                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4600         else if (!strcmp(res->value, "2"))
4601                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4602         else if (!strcmp(res->value, "3"))
4603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4604         else if (!strcmp(res->value, "4"))
4605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4606         else if (!strcmp(res->value, "8"))
4607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4608         else if (!strcmp(res->value, "16"))
4609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4610         else if (!strcmp(res->value, "32"))
4611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4612         else
4613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4614 #endif
4615 }
4616
4617 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4618         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4619                         set, "set");
4620 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4621         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4622                         bypass, "bypass");
4623 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4624         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4625                         timeout, "timeout");
4626 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4627         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4628                         value, "0#1.5#2#3#4#8#16#32");
4629
4630 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4631         .f = cmd_set_bypass_timeout_parsed,
4632         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4633                 "Set the NIC bypass watchdog timeout in seconds",
4634         .data = NULL,
4635         .tokens = {
4636                 (void *)&cmd_setbypass_timeout_set,
4637                 (void *)&cmd_setbypass_timeout_bypass,
4638                 (void *)&cmd_setbypass_timeout_timeout,
4639                 (void *)&cmd_setbypass_timeout_value,
4640                 NULL,
4641         },
4642 };
4643
4644 /* *** SHOW NIC BYPASS MODE *** */
4645 struct cmd_show_bypass_config_result {
4646         cmdline_fixed_string_t show;
4647         cmdline_fixed_string_t bypass;
4648         cmdline_fixed_string_t config;
4649         portid_t port_id;
4650 };
4651
4652 static void
4653 cmd_show_bypass_config_parsed(void *parsed_result,
4654                 __attribute__((unused)) struct cmdline *cl,
4655                 __attribute__((unused)) void *data)
4656 {
4657         struct cmd_show_bypass_config_result *res = parsed_result;
4658         portid_t port_id = res->port_id;
4659         int rc = -EINVAL;
4660 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4661         uint32_t event_mode;
4662         uint32_t bypass_mode;
4663         uint32_t timeout = bypass_timeout;
4664         int i;
4665
4666         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4667                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4668         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4669                 {"UNKNOWN", "normal", "bypass", "isolate"};
4670         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4671                 "NONE",
4672                 "OS/board on",
4673                 "power supply on",
4674                 "OS/board off",
4675                 "power supply off",
4676                 "timeout"};
4677         int num_events = (sizeof events) / (sizeof events[0]);
4678
4679         /* Display the bypass mode.*/
4680         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4681                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4682                 return;
4683         }
4684         else {
4685                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4686                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4687
4688                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4689         }
4690
4691         /* Display the bypass timeout.*/
4692         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4693                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4694
4695         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4696
4697         /* Display the bypass events and associated modes. */
4698         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4699
4700                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4701                         printf("\tFailed to get bypass mode for event = %s\n",
4702                                 events[i]);
4703                 } else {
4704                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4705                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4706
4707                         printf("\tbypass event: %-16s = %s\n", events[i],
4708                                 modes[event_mode]);
4709                 }
4710         }
4711 #endif
4712         if (rc != 0)
4713                 printf("\tFailed to get bypass configuration for port = %d\n",
4714                        port_id);
4715 }
4716
4717 cmdline_parse_token_string_t cmd_showbypass_config_show =
4718         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4719                         show, "show");
4720 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4721         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4722                         bypass, "bypass");
4723 cmdline_parse_token_string_t cmd_showbypass_config_config =
4724         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4725                         config, "config");
4726 cmdline_parse_token_num_t cmd_showbypass_config_port =
4727         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4728                                 port_id, UINT16);
4729
4730 cmdline_parse_inst_t cmd_show_bypass_config = {
4731         .f = cmd_show_bypass_config_parsed,
4732         .help_str = "show bypass config <port_id>: "
4733                     "Show the NIC bypass config for port_id",
4734         .data = NULL,
4735         .tokens = {
4736                 (void *)&cmd_showbypass_config_show,
4737                 (void *)&cmd_showbypass_config_bypass,
4738                 (void *)&cmd_showbypass_config_config,
4739                 (void *)&cmd_showbypass_config_port,
4740                 NULL,
4741         },
4742 };
4743
4744 #ifdef RTE_LIBRTE_PMD_BOND
4745 /* *** SET BONDING MODE *** */
4746 struct cmd_set_bonding_mode_result {
4747         cmdline_fixed_string_t set;
4748         cmdline_fixed_string_t bonding;
4749         cmdline_fixed_string_t mode;
4750         uint8_t value;
4751         portid_t port_id;
4752 };
4753
4754 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4755                 __attribute__((unused))  struct cmdline *cl,
4756                 __attribute__((unused)) void *data)
4757 {
4758         struct cmd_set_bonding_mode_result *res = parsed_result;
4759         portid_t port_id = res->port_id;
4760
4761         /* Set the bonding mode for the relevant port. */
4762         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4763                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4764 }
4765
4766 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4767 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4768                 set, "set");
4769 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4770 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4771                 bonding, "bonding");
4772 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4773 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4774                 mode, "mode");
4775 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4776 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4777                 value, UINT8);
4778 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4779 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4780                 port_id, UINT16);
4781
4782 cmdline_parse_inst_t cmd_set_bonding_mode = {
4783                 .f = cmd_set_bonding_mode_parsed,
4784                 .help_str = "set bonding mode <mode_value> <port_id>: "
4785                         "Set the bonding mode for port_id",
4786                 .data = NULL,
4787                 .tokens = {
4788                                 (void *) &cmd_setbonding_mode_set,
4789                                 (void *) &cmd_setbonding_mode_bonding,
4790                                 (void *) &cmd_setbonding_mode_mode,
4791                                 (void *) &cmd_setbonding_mode_value,
4792                                 (void *) &cmd_setbonding_mode_port,
4793                                 NULL
4794                 }
4795 };
4796
4797 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4798 struct cmd_set_bonding_lacp_dedicated_queues_result {
4799         cmdline_fixed_string_t set;
4800         cmdline_fixed_string_t bonding;
4801         cmdline_fixed_string_t lacp;
4802         cmdline_fixed_string_t dedicated_queues;
4803         portid_t port_id;
4804         cmdline_fixed_string_t mode;
4805 };
4806
4807 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4808                 __attribute__((unused))  struct cmdline *cl,
4809                 __attribute__((unused)) void *data)
4810 {
4811         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4812         portid_t port_id = res->port_id;
4813         struct rte_port *port;
4814
4815         port = &ports[port_id];
4816
4817         /** Check if the port is not started **/
4818         if (port->port_status != RTE_PORT_STOPPED) {
4819                 printf("Please stop port %d first\n", port_id);
4820                 return;
4821         }
4822
4823         if (!strcmp(res->mode, "enable")) {
4824                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4825                         printf("Dedicate queues for LACP control packets"
4826                                         " enabled\n");
4827                 else
4828                         printf("Enabling dedicate queues for LACP control "
4829                                         "packets on port %d failed\n", port_id);
4830         } else if (!strcmp(res->mode, "disable")) {
4831                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4832                         printf("Dedicated queues for LACP control packets "
4833                                         "disabled\n");
4834                 else
4835                         printf("Disabling dedicated queues for LACP control "
4836                                         "traffic on port %d failed\n", port_id);
4837         }
4838 }
4839
4840 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4841 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4842                 set, "set");
4843 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4844 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4845                 bonding, "bonding");
4846 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4848                 lacp, "lacp");
4849 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4850 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4851                 dedicated_queues, "dedicated_queues");
4852 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4853 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4854                 port_id, UINT16);
4855 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4856 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4857                 mode, "enable#disable");
4858
4859 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4860                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4861                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4862                         "enable|disable: "
4863                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4864                 .data = NULL,
4865                 .tokens = {
4866                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4867                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4868                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4869                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4870                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4871                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4872                         NULL
4873                 }
4874 };
4875
4876 /* *** SET BALANCE XMIT POLICY *** */
4877 struct cmd_set_bonding_balance_xmit_policy_result {
4878         cmdline_fixed_string_t set;
4879         cmdline_fixed_string_t bonding;
4880         cmdline_fixed_string_t balance_xmit_policy;
4881         portid_t port_id;
4882         cmdline_fixed_string_t policy;
4883 };
4884
4885 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4886                 __attribute__((unused))  struct cmdline *cl,
4887                 __attribute__((unused)) void *data)
4888 {
4889         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4890         portid_t port_id = res->port_id;
4891         uint8_t policy;
4892
4893         if (!strcmp(res->policy, "l2")) {
4894                 policy = BALANCE_XMIT_POLICY_LAYER2;
4895         } else if (!strcmp(res->policy, "l23")) {
4896                 policy = BALANCE_XMIT_POLICY_LAYER23;
4897         } else if (!strcmp(res->policy, "l34")) {
4898                 policy = BALANCE_XMIT_POLICY_LAYER34;
4899         } else {
4900                 printf("\t Invalid xmit policy selection");
4901                 return;
4902         }
4903
4904         /* Set the bonding mode for the relevant port. */
4905         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4906                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4907                                 port_id);
4908         }
4909 }
4910
4911 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4912 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4913                 set, "set");
4914 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4916                 bonding, "bonding");
4917 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4918 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4919                 balance_xmit_policy, "balance_xmit_policy");
4920 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4921 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4922                 port_id, UINT16);
4923 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4925                 policy, "l2#l23#l34");
4926
4927 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4928                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4929                 .help_str = "set bonding balance_xmit_policy <port_id> "
4930                         "l2|l23|l34: "
4931                         "Set the bonding balance_xmit_policy for port_id",
4932                 .data = NULL,
4933                 .tokens = {
4934                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4935                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4936                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4937                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4938                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4939                                 NULL
4940                 }
4941 };
4942
4943 /* *** SHOW NIC BONDING CONFIGURATION *** */
4944 struct cmd_show_bonding_config_result {
4945         cmdline_fixed_string_t show;
4946         cmdline_fixed_string_t bonding;
4947         cmdline_fixed_string_t config;
4948         portid_t port_id;
4949 };
4950
4951 static void cmd_show_bonding_config_parsed(void *parsed_result,
4952                 __attribute__((unused))  struct cmdline *cl,
4953                 __attribute__((unused)) void *data)
4954 {
4955         struct cmd_show_bonding_config_result *res = parsed_result;
4956         int bonding_mode, agg_mode;
4957         portid_t slaves[RTE_MAX_ETHPORTS];
4958         int num_slaves, num_active_slaves;
4959         int primary_id;
4960         int i;
4961         portid_t port_id = res->port_id;
4962
4963         /* Display the bonding mode.*/
4964         bonding_mode = rte_eth_bond_mode_get(port_id);
4965         if (bonding_mode < 0) {
4966                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4967                 return;
4968         } else
4969                 printf("\tBonding mode: %d\n", bonding_mode);
4970
4971         if (bonding_mode == BONDING_MODE_BALANCE) {
4972                 int balance_xmit_policy;
4973
4974                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4975                 if (balance_xmit_policy < 0) {
4976                         printf("\tFailed to get balance xmit policy for port = %d\n",
4977                                         port_id);
4978                         return;
4979                 } else {
4980                         printf("\tBalance Xmit Policy: ");
4981
4982                         switch (balance_xmit_policy) {
4983                         case BALANCE_XMIT_POLICY_LAYER2:
4984                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4985                                 break;
4986                         case BALANCE_XMIT_POLICY_LAYER23:
4987                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4988                                 break;
4989                         case BALANCE_XMIT_POLICY_LAYER34:
4990                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4991                                 break;
4992                         }
4993                         printf("\n");
4994                 }
4995         }
4996
4997         if (bonding_mode == BONDING_MODE_8023AD) {
4998                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4999                 printf("\tIEEE802.3AD Aggregator Mode: ");
5000                 switch (agg_mode) {
5001                 case AGG_BANDWIDTH:
5002                         printf("bandwidth");
5003                         break;
5004                 case AGG_STABLE:
5005                         printf("stable");
5006                         break;
5007                 case AGG_COUNT:
5008                         printf("count");
5009                         break;
5010                 }
5011                 printf("\n");
5012         }
5013
5014         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5015
5016         if (num_slaves < 0) {
5017                 printf("\tFailed to get slave list for port = %d\n", port_id);
5018                 return;
5019         }
5020         if (num_slaves > 0) {
5021                 printf("\tSlaves (%d): [", num_slaves);
5022                 for (i = 0; i < num_slaves - 1; i++)
5023                         printf("%d ", slaves[i]);
5024
5025                 printf("%d]\n", slaves[num_slaves - 1]);
5026         } else {
5027                 printf("\tSlaves: []\n");
5028
5029         }
5030
5031         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5032                         RTE_MAX_ETHPORTS);
5033
5034         if (num_active_slaves < 0) {
5035                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5036                 return;
5037         }
5038         if (num_active_slaves > 0) {
5039                 printf("\tActive Slaves (%d): [", num_active_slaves);
5040                 for (i = 0; i < num_active_slaves - 1; i++)
5041                         printf("%d ", slaves[i]);
5042
5043                 printf("%d]\n", slaves[num_active_slaves - 1]);
5044
5045         } else {
5046                 printf("\tActive Slaves: []\n");
5047
5048         }
5049
5050         primary_id = rte_eth_bond_primary_get(port_id);
5051         if (primary_id < 0) {
5052                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5053                 return;
5054         } else
5055                 printf("\tPrimary: [%d]\n", primary_id);
5056
5057 }
5058
5059 cmdline_parse_token_string_t cmd_showbonding_config_show =
5060 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5061                 show, "show");
5062 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5063 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5064                 bonding, "bonding");
5065 cmdline_parse_token_string_t cmd_showbonding_config_config =
5066 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5067                 config, "config");
5068 cmdline_parse_token_num_t cmd_showbonding_config_port =
5069 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5070                 port_id, UINT16);
5071
5072 cmdline_parse_inst_t cmd_show_bonding_config = {
5073                 .f = cmd_show_bonding_config_parsed,
5074                 .help_str = "show bonding config <port_id>: "
5075                         "Show the bonding config for port_id",
5076                 .data = NULL,
5077                 .tokens = {
5078                                 (void *)&cmd_showbonding_config_show,
5079                                 (void *)&cmd_showbonding_config_bonding,
5080                                 (void *)&cmd_showbonding_config_config,
5081                                 (void *)&cmd_showbonding_config_port,
5082                                 NULL
5083                 }
5084 };
5085
5086 /* *** SET BONDING PRIMARY *** */
5087 struct cmd_set_bonding_primary_result {
5088         cmdline_fixed_string_t set;
5089         cmdline_fixed_string_t bonding;
5090         cmdline_fixed_string_t primary;
5091         portid_t slave_id;
5092         portid_t port_id;
5093 };
5094
5095 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5096                 __attribute__((unused))  struct cmdline *cl,
5097                 __attribute__((unused)) void *data)
5098 {
5099         struct cmd_set_bonding_primary_result *res = parsed_result;
5100         portid_t master_port_id = res->port_id;
5101         portid_t slave_port_id = res->slave_id;
5102
5103         /* Set the primary slave for a bonded device. */
5104         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5105                 printf("\t Failed to set primary slave for port = %d.\n",
5106                                 master_port_id);
5107                 return;
5108         }
5109         init_port_config();
5110 }
5111
5112 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5113 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5114                 set, "set");
5115 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5116 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5117                 bonding, "bonding");
5118 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5119 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5120                 primary, "primary");
5121 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5122 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5123                 slave_id, UINT16);
5124 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5125 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5126                 port_id, UINT16);
5127
5128 cmdline_parse_inst_t cmd_set_bonding_primary = {
5129                 .f = cmd_set_bonding_primary_parsed,
5130                 .help_str = "set bonding primary <slave_id> <port_id>: "
5131                         "Set the primary slave for port_id",
5132                 .data = NULL,
5133                 .tokens = {
5134                                 (void *)&cmd_setbonding_primary_set,
5135                                 (void *)&cmd_setbonding_primary_bonding,
5136                                 (void *)&cmd_setbonding_primary_primary,
5137                                 (void *)&cmd_setbonding_primary_slave,
5138                                 (void *)&cmd_setbonding_primary_port,
5139                                 NULL
5140                 }
5141 };
5142
5143 /* *** ADD SLAVE *** */
5144 struct cmd_add_bonding_slave_result {
5145         cmdline_fixed_string_t add;
5146         cmdline_fixed_string_t bonding;
5147         cmdline_fixed_string_t slave;
5148         portid_t slave_id;
5149         portid_t port_id;
5150 };
5151
5152 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5153                 __attribute__((unused))  struct cmdline *cl,
5154                 __attribute__((unused)) void *data)
5155 {
5156         struct cmd_add_bonding_slave_result *res = parsed_result;
5157         portid_t master_port_id = res->port_id;
5158         portid_t slave_port_id = res->slave_id;
5159
5160         /* add the slave for a bonded device. */
5161         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5162                 printf("\t Failed to add slave %d to master port = %d.\n",
5163                                 slave_port_id, master_port_id);
5164                 return;
5165         }
5166         init_port_config();
5167         set_port_slave_flag(slave_port_id);
5168 }
5169
5170 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5171 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5172                 add, "add");
5173 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5174 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5175                 bonding, "bonding");
5176 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5177 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5178                 slave, "slave");
5179 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5180 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5181                 slave_id, UINT16);
5182 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5183 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5184                 port_id, UINT16);
5185
5186 cmdline_parse_inst_t cmd_add_bonding_slave = {
5187                 .f = cmd_add_bonding_slave_parsed,
5188                 .help_str = "add bonding slave <slave_id> <port_id>: "
5189                         "Add a slave device to a bonded device",
5190                 .data = NULL,
5191                 .tokens = {
5192                                 (void *)&cmd_addbonding_slave_add,
5193                                 (void *)&cmd_addbonding_slave_bonding,
5194                                 (void *)&cmd_addbonding_slave_slave,
5195                                 (void *)&cmd_addbonding_slave_slaveid,
5196                                 (void *)&cmd_addbonding_slave_port,
5197                                 NULL
5198                 }
5199 };
5200
5201 /* *** REMOVE SLAVE *** */
5202 struct cmd_remove_bonding_slave_result {
5203         cmdline_fixed_string_t remove;
5204         cmdline_fixed_string_t bonding;
5205         cmdline_fixed_string_t slave;
5206         portid_t slave_id;
5207         portid_t port_id;
5208 };
5209
5210 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5211                 __attribute__((unused))  struct cmdline *cl,
5212                 __attribute__((unused)) void *data)
5213 {
5214         struct cmd_remove_bonding_slave_result *res = parsed_result;
5215         portid_t master_port_id = res->port_id;
5216         portid_t slave_port_id = res->slave_id;
5217
5218         /* remove the slave from a bonded device. */
5219         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5220                 printf("\t Failed to remove slave %d from master port = %d.\n",
5221                                 slave_port_id, master_port_id);
5222                 return;
5223         }
5224         init_port_config();
5225         clear_port_slave_flag(slave_port_id);
5226 }
5227
5228 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5229                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5230                                 remove, "remove");
5231 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5232                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5233                                 bonding, "bonding");
5234 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5235                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5236                                 slave, "slave");
5237 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5238                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5239                                 slave_id, UINT16);
5240 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5241                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5242                                 port_id, UINT16);
5243
5244 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5245                 .f = cmd_remove_bonding_slave_parsed,
5246                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5247                         "Remove a slave device from a bonded device",
5248                 .data = NULL,
5249                 .tokens = {
5250                                 (void *)&cmd_removebonding_slave_remove,
5251                                 (void *)&cmd_removebonding_slave_bonding,
5252                                 (void *)&cmd_removebonding_slave_slave,
5253                                 (void *)&cmd_removebonding_slave_slaveid,
5254                                 (void *)&cmd_removebonding_slave_port,
5255                                 NULL
5256                 }
5257 };
5258
5259 /* *** CREATE BONDED DEVICE *** */
5260 struct cmd_create_bonded_device_result {
5261         cmdline_fixed_string_t create;
5262         cmdline_fixed_string_t bonded;
5263         cmdline_fixed_string_t device;
5264         uint8_t mode;
5265         uint8_t socket;
5266 };
5267
5268 static int bond_dev_num = 0;
5269
5270 static void cmd_create_bonded_device_parsed(void *parsed_result,
5271                 __attribute__((unused))  struct cmdline *cl,
5272                 __attribute__((unused)) void *data)
5273 {
5274         struct cmd_create_bonded_device_result *res = parsed_result;
5275         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5276         int port_id;
5277
5278         if (test_done == 0) {
5279                 printf("Please stop forwarding first\n");
5280                 return;
5281         }
5282
5283         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5284                         bond_dev_num++);
5285
5286         /* Create a new bonded device. */
5287         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5288         if (port_id < 0) {
5289                 printf("\t Failed to create bonded device.\n");
5290                 return;
5291         } else {
5292                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5293                                 port_id);
5294
5295                 /* Update number of ports */
5296                 nb_ports = rte_eth_dev_count();
5297                 reconfig(port_id, res->socket);
5298                 rte_eth_promiscuous_enable(port_id);
5299         }
5300
5301 }
5302
5303 cmdline_parse_token_string_t cmd_createbonded_device_create =
5304                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5305                                 create, "create");
5306 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5307                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5308                                 bonded, "bonded");
5309 cmdline_parse_token_string_t cmd_createbonded_device_device =
5310                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5311                                 device, "device");
5312 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5313                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5314                                 mode, UINT8);
5315 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5316                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5317                                 socket, UINT8);
5318
5319 cmdline_parse_inst_t cmd_create_bonded_device = {
5320                 .f = cmd_create_bonded_device_parsed,
5321                 .help_str = "create bonded device <mode> <socket>: "
5322                         "Create a new bonded device with specific bonding mode and socket",
5323                 .data = NULL,
5324                 .tokens = {
5325                                 (void *)&cmd_createbonded_device_create,
5326                                 (void *)&cmd_createbonded_device_bonded,
5327                                 (void *)&cmd_createbonded_device_device,
5328                                 (void *)&cmd_createbonded_device_mode,
5329                                 (void *)&cmd_createbonded_device_socket,
5330                                 NULL
5331                 }
5332 };
5333
5334 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5335 struct cmd_set_bond_mac_addr_result {
5336         cmdline_fixed_string_t set;
5337         cmdline_fixed_string_t bonding;
5338         cmdline_fixed_string_t mac_addr;
5339         uint16_t port_num;
5340         struct ether_addr address;
5341 };
5342
5343 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5344                 __attribute__((unused))  struct cmdline *cl,
5345                 __attribute__((unused)) void *data)
5346 {
5347         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5348         int ret;
5349
5350         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5351                 return;
5352
5353         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5354
5355         /* check the return value and print it if is < 0 */
5356         if (ret < 0)
5357                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5358 }
5359
5360 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5361                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5362 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5363                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5364                                 "bonding");
5365 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5366                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5367                                 "mac_addr");
5368 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5369                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5370                                 port_num, UINT16);
5371 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5372                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5373
5374 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5375                 .f = cmd_set_bond_mac_addr_parsed,
5376                 .data = (void *) 0,
5377                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5378                 .tokens = {
5379                                 (void *)&cmd_set_bond_mac_addr_set,
5380                                 (void *)&cmd_set_bond_mac_addr_bonding,
5381                                 (void *)&cmd_set_bond_mac_addr_mac,
5382                                 (void *)&cmd_set_bond_mac_addr_portnum,
5383                                 (void *)&cmd_set_bond_mac_addr_addr,
5384                                 NULL
5385                 }
5386 };
5387
5388
5389 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5390 struct cmd_set_bond_mon_period_result {
5391         cmdline_fixed_string_t set;
5392         cmdline_fixed_string_t bonding;
5393         cmdline_fixed_string_t mon_period;
5394         uint16_t port_num;
5395         uint32_t period_ms;
5396 };
5397
5398 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5399                 __attribute__((unused))  struct cmdline *cl,
5400                 __attribute__((unused)) void *data)
5401 {
5402         struct cmd_set_bond_mon_period_result *res = parsed_result;
5403         int ret;
5404
5405         if (res->port_num >= nb_ports) {
5406                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5407                 return;
5408         }
5409
5410         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5411
5412         /* check the return value and print it if is < 0 */
5413         if (ret < 0)
5414                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5415 }
5416
5417 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5418                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5419                                 set, "set");
5420 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5421                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5422                                 bonding, "bonding");
5423 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5424                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5425                                 mon_period,     "mon_period");
5426 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5427                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5428                                 port_num, UINT16);
5429 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5430                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5431                                 period_ms, UINT32);
5432
5433 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5434                 .f = cmd_set_bond_mon_period_parsed,
5435                 .data = (void *) 0,
5436                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5437                 .tokens = {
5438                                 (void *)&cmd_set_bond_mon_period_set,
5439                                 (void *)&cmd_set_bond_mon_period_bonding,
5440                                 (void *)&cmd_set_bond_mon_period_mon_period,
5441                                 (void *)&cmd_set_bond_mon_period_portnum,
5442                                 (void *)&cmd_set_bond_mon_period_period_ms,
5443                                 NULL
5444                 }
5445 };
5446
5447
5448
5449 struct cmd_set_bonding_agg_mode_policy_result {
5450         cmdline_fixed_string_t set;
5451         cmdline_fixed_string_t bonding;
5452         cmdline_fixed_string_t agg_mode;
5453         uint16_t port_num;
5454         cmdline_fixed_string_t policy;
5455 };
5456
5457
5458 static void
5459 cmd_set_bonding_agg_mode(void *parsed_result,
5460                 __attribute__((unused)) struct cmdline *cl,
5461                 __attribute__((unused)) void *data)
5462 {
5463         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5464         uint8_t policy = AGG_BANDWIDTH;
5465
5466         if (res->port_num >= nb_ports) {
5467                 printf("Port id %d must be less than %d\n",
5468                                 res->port_num, nb_ports);
5469                 return;
5470         }
5471
5472         if (!strcmp(res->policy, "bandwidth"))
5473                 policy = AGG_BANDWIDTH;
5474         else if (!strcmp(res->policy, "stable"))
5475                 policy = AGG_STABLE;
5476         else if (!strcmp(res->policy, "count"))
5477                 policy = AGG_COUNT;
5478
5479         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5480 }
5481
5482
5483 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5484         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5485                                 set, "set");
5486 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5488                                 bonding, "bonding");
5489
5490 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5491         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5492                                 agg_mode, "agg_mode");
5493
5494 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5495         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5496                                 port_num, UINT16);
5497
5498 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5499         TOKEN_STRING_INITIALIZER(
5500                         struct cmd_set_bonding_balance_xmit_policy_result,
5501                 policy, "stable#bandwidth#count");
5502
5503 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5504         .f = cmd_set_bonding_agg_mode,
5505         .data = (void *) 0,
5506         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5507         .tokens = {
5508                         (void *)&cmd_set_bonding_agg_mode_set,
5509                         (void *)&cmd_set_bonding_agg_mode_bonding,
5510                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5511                         (void *)&cmd_set_bonding_agg_mode_portnum,
5512                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5513                         NULL
5514                 }
5515 };
5516
5517
5518 #endif /* RTE_LIBRTE_PMD_BOND */
5519
5520 /* *** SET FORWARDING MODE *** */
5521 struct cmd_set_fwd_mode_result {
5522         cmdline_fixed_string_t set;
5523         cmdline_fixed_string_t fwd;
5524         cmdline_fixed_string_t mode;
5525 };
5526
5527 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5528                                     __attribute__((unused)) struct cmdline *cl,
5529                                     __attribute__((unused)) void *data)
5530 {
5531         struct cmd_set_fwd_mode_result *res = parsed_result;
5532
5533         retry_enabled = 0;
5534         set_pkt_forwarding_mode(res->mode);
5535 }
5536
5537 cmdline_parse_token_string_t cmd_setfwd_set =
5538         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5539 cmdline_parse_token_string_t cmd_setfwd_fwd =
5540         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5541 cmdline_parse_token_string_t cmd_setfwd_mode =
5542         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5543                 "" /* defined at init */);
5544
5545 cmdline_parse_inst_t cmd_set_fwd_mode = {
5546         .f = cmd_set_fwd_mode_parsed,
5547         .data = NULL,
5548         .help_str = NULL, /* defined at init */
5549         .tokens = {
5550                 (void *)&cmd_setfwd_set,
5551                 (void *)&cmd_setfwd_fwd,
5552                 (void *)&cmd_setfwd_mode,
5553                 NULL,
5554         },
5555 };
5556
5557 static void cmd_set_fwd_mode_init(void)
5558 {
5559         char *modes, *c;
5560         static char token[128];
5561         static char help[256];
5562         cmdline_parse_token_string_t *token_struct;
5563
5564         modes = list_pkt_forwarding_modes();
5565         snprintf(help, sizeof(help), "set fwd %s: "
5566                 "Set packet forwarding mode", modes);
5567         cmd_set_fwd_mode.help_str = help;
5568
5569         /* string token separator is # */
5570         for (c = token; *modes != '\0'; modes++)
5571                 if (*modes == '|')
5572                         *c++ = '#';
5573                 else
5574                         *c++ = *modes;
5575         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5576         token_struct->string_data.str = token;
5577 }
5578
5579 /* *** SET RETRY FORWARDING MODE *** */
5580 struct cmd_set_fwd_retry_mode_result {
5581         cmdline_fixed_string_t set;
5582         cmdline_fixed_string_t fwd;
5583         cmdline_fixed_string_t mode;
5584         cmdline_fixed_string_t retry;
5585 };
5586
5587 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5588                             __attribute__((unused)) struct cmdline *cl,
5589                             __attribute__((unused)) void *data)
5590 {
5591         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5592
5593         retry_enabled = 1;
5594         set_pkt_forwarding_mode(res->mode);
5595 }
5596
5597 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5598         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5599                         set, "set");
5600 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5601         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5602                         fwd, "fwd");
5603 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5604         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5605                         mode,
5606                 "" /* defined at init */);
5607 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5608         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5609                         retry, "retry");
5610
5611 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5612         .f = cmd_set_fwd_retry_mode_parsed,
5613         .data = NULL,
5614         .help_str = NULL, /* defined at init */
5615         .tokens = {
5616                 (void *)&cmd_setfwd_retry_set,
5617                 (void *)&cmd_setfwd_retry_fwd,
5618                 (void *)&cmd_setfwd_retry_mode,
5619                 (void *)&cmd_setfwd_retry_retry,
5620                 NULL,
5621         },
5622 };
5623
5624 static void cmd_set_fwd_retry_mode_init(void)
5625 {
5626         char *modes, *c;
5627         static char token[128];
5628         static char help[256];
5629         cmdline_parse_token_string_t *token_struct;
5630
5631         modes = list_pkt_forwarding_retry_modes();
5632         snprintf(help, sizeof(help), "set fwd %s retry: "
5633                 "Set packet forwarding mode with retry", modes);
5634         cmd_set_fwd_retry_mode.help_str = help;
5635
5636         /* string token separator is # */
5637         for (c = token; *modes != '\0'; modes++)
5638                 if (*modes == '|')
5639                         *c++ = '#';
5640                 else
5641                         *c++ = *modes;
5642         token_struct = (cmdline_parse_token_string_t *)
5643                 cmd_set_fwd_retry_mode.tokens[2];
5644         token_struct->string_data.str = token;
5645 }
5646
5647 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5648 struct cmd_set_burst_tx_retry_result {
5649         cmdline_fixed_string_t set;
5650         cmdline_fixed_string_t burst;
5651         cmdline_fixed_string_t tx;
5652         cmdline_fixed_string_t delay;
5653         uint32_t time;
5654         cmdline_fixed_string_t retry;
5655         uint32_t retry_num;
5656 };
5657
5658 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5659                                         __attribute__((unused)) struct cmdline *cl,
5660                                         __attribute__((unused)) void *data)
5661 {
5662         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5663
5664         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5665                 && !strcmp(res->tx, "tx")) {
5666                 if (!strcmp(res->delay, "delay"))
5667                         burst_tx_delay_time = res->time;
5668                 if (!strcmp(res->retry, "retry"))
5669                         burst_tx_retry_num = res->retry_num;
5670         }
5671
5672 }
5673
5674 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5675         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5676 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5677         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5678                                  "burst");
5679 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5680         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5681 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5682         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5683 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5684         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5685 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5686         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5687 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5688         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5689
5690 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5691         .f = cmd_set_burst_tx_retry_parsed,
5692         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5693         .tokens = {
5694                 (void *)&cmd_set_burst_tx_retry_set,
5695                 (void *)&cmd_set_burst_tx_retry_burst,
5696                 (void *)&cmd_set_burst_tx_retry_tx,
5697                 (void *)&cmd_set_burst_tx_retry_delay,
5698                 (void *)&cmd_set_burst_tx_retry_time,
5699                 (void *)&cmd_set_burst_tx_retry_retry,
5700                 (void *)&cmd_set_burst_tx_retry_retry_num,
5701                 NULL,
5702         },
5703 };
5704
5705 /* *** SET PROMISC MODE *** */
5706 struct cmd_set_promisc_mode_result {
5707         cmdline_fixed_string_t set;
5708         cmdline_fixed_string_t promisc;
5709         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5710         uint16_t port_num;               /* valid if "allports" argument == 0 */
5711         cmdline_fixed_string_t mode;
5712 };
5713
5714 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5715                                         __attribute__((unused)) struct cmdline *cl,
5716                                         void *allports)
5717 {
5718         struct cmd_set_promisc_mode_result *res = parsed_result;
5719         int enable;
5720         portid_t i;
5721
5722         if (!strcmp(res->mode, "on"))
5723                 enable = 1;
5724         else
5725                 enable = 0;
5726
5727         /* all ports */
5728         if (allports) {
5729                 RTE_ETH_FOREACH_DEV(i) {
5730                         if (enable)
5731                                 rte_eth_promiscuous_enable(i);
5732                         else
5733                                 rte_eth_promiscuous_disable(i);
5734                 }
5735         }
5736         else {
5737                 if (enable)
5738                         rte_eth_promiscuous_enable(res->port_num);
5739                 else
5740                         rte_eth_promiscuous_disable(res->port_num);
5741         }
5742 }
5743
5744 cmdline_parse_token_string_t cmd_setpromisc_set =
5745         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5746 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5747         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5748                                  "promisc");
5749 cmdline_parse_token_string_t cmd_setpromisc_portall =
5750         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5751                                  "all");
5752 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5753         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5754                               UINT8);
5755 cmdline_parse_token_string_t cmd_setpromisc_mode =
5756         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5757                                  "on#off");
5758
5759 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5760         .f = cmd_set_promisc_mode_parsed,
5761         .data = (void *)1,
5762         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5763         .tokens = {
5764                 (void *)&cmd_setpromisc_set,
5765                 (void *)&cmd_setpromisc_promisc,
5766                 (void *)&cmd_setpromisc_portall,
5767                 (void *)&cmd_setpromisc_mode,
5768                 NULL,
5769         },
5770 };
5771
5772 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5773         .f = cmd_set_promisc_mode_parsed,
5774         .data = (void *)0,
5775         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5776         .tokens = {
5777                 (void *)&cmd_setpromisc_set,
5778                 (void *)&cmd_setpromisc_promisc,
5779                 (void *)&cmd_setpromisc_portnum,
5780                 (void *)&cmd_setpromisc_mode,
5781                 NULL,
5782         },
5783 };
5784
5785 /* *** SET ALLMULTI MODE *** */
5786 struct cmd_set_allmulti_mode_result {
5787         cmdline_fixed_string_t set;
5788         cmdline_fixed_string_t allmulti;
5789         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5790         uint16_t port_num;               /* valid if "allports" argument == 0 */
5791         cmdline_fixed_string_t mode;
5792 };
5793
5794 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5795                                         __attribute__((unused)) struct cmdline *cl,
5796                                         void *allports)
5797 {
5798         struct cmd_set_allmulti_mode_result *res = parsed_result;
5799         int enable;
5800         portid_t i;
5801
5802         if (!strcmp(res->mode, "on"))
5803                 enable = 1;
5804         else
5805                 enable = 0;
5806
5807         /* all ports */
5808         if (allports) {
5809                 RTE_ETH_FOREACH_DEV(i) {
5810                         if (enable)
5811                                 rte_eth_allmulticast_enable(i);
5812                         else
5813                                 rte_eth_allmulticast_disable(i);
5814                 }
5815         }
5816         else {
5817                 if (enable)
5818                         rte_eth_allmulticast_enable(res->port_num);
5819                 else
5820                         rte_eth_allmulticast_disable(res->port_num);
5821         }
5822 }
5823
5824 cmdline_parse_token_string_t cmd_setallmulti_set =
5825         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5826 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5827         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5828                                  "allmulti");
5829 cmdline_parse_token_string_t cmd_setallmulti_portall =
5830         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5831                                  "all");
5832 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5833         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5834                               UINT16);
5835 cmdline_parse_token_string_t cmd_setallmulti_mode =
5836         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5837                                  "on#off");
5838
5839 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5840         .f = cmd_set_allmulti_mode_parsed,
5841         .data = (void *)1,
5842         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5843         .tokens = {
5844                 (void *)&cmd_setallmulti_set,
5845                 (void *)&cmd_setallmulti_allmulti,
5846                 (void *)&cmd_setallmulti_portall,
5847                 (void *)&cmd_setallmulti_mode,
5848                 NULL,
5849         },
5850 };
5851
5852 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5853         .f = cmd_set_allmulti_mode_parsed,
5854         .data = (void *)0,
5855         .help_str = "set allmulti <port_id> on|off: "
5856                 "Set allmulti mode on port_id",
5857         .tokens = {
5858                 (void *)&cmd_setallmulti_set,
5859                 (void *)&cmd_setallmulti_allmulti,
5860                 (void *)&cmd_setallmulti_portnum,
5861                 (void *)&cmd_setallmulti_mode,
5862                 NULL,
5863         },
5864 };
5865
5866 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5867 struct cmd_link_flow_ctrl_set_result {
5868         cmdline_fixed_string_t set;
5869         cmdline_fixed_string_t flow_ctrl;
5870         cmdline_fixed_string_t rx;
5871         cmdline_fixed_string_t rx_lfc_mode;
5872         cmdline_fixed_string_t tx;
5873         cmdline_fixed_string_t tx_lfc_mode;
5874         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5875         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5876         cmdline_fixed_string_t autoneg_str;
5877         cmdline_fixed_string_t autoneg;
5878         cmdline_fixed_string_t hw_str;
5879         uint32_t high_water;
5880         cmdline_fixed_string_t lw_str;
5881         uint32_t low_water;
5882         cmdline_fixed_string_t pt_str;
5883         uint16_t pause_time;
5884         cmdline_fixed_string_t xon_str;
5885         uint16_t send_xon;
5886         portid_t port_id;
5887 };
5888
5889 cmdline_parse_token_string_t cmd_lfc_set_set =
5890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5891                                 set, "set");
5892 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5894                                 flow_ctrl, "flow_ctrl");
5895 cmdline_parse_token_string_t cmd_lfc_set_rx =
5896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5897                                 rx, "rx");
5898 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5900                                 rx_lfc_mode, "on#off");
5901 cmdline_parse_token_string_t cmd_lfc_set_tx =
5902         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5903                                 tx, "tx");
5904 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5906                                 tx_lfc_mode, "on#off");
5907 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5908         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5909                                 hw_str, "high_water");
5910 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5911         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5912                                 high_water, UINT32);
5913 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5915                                 lw_str, "low_water");
5916 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5917         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5918                                 low_water, UINT32);
5919 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5921                                 pt_str, "pause_time");
5922 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5923         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5924                                 pause_time, UINT16);
5925 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5926         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5927                                 xon_str, "send_xon");
5928 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5929         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5930                                 send_xon, UINT16);
5931 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5932         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5933                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5934 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5935         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5936                                 mac_ctrl_frame_fwd_mode, "on#off");
5937 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5938         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5939                                 autoneg_str, "autoneg");
5940 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5941         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5942                                 autoneg, "on#off");
5943 cmdline_parse_token_num_t cmd_lfc_set_portid =
5944         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5945                                 port_id, UINT16);
5946
5947 /* forward declaration */
5948 static void
5949 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5950                               void *data);
5951
5952 cmdline_parse_inst_t cmd_link_flow_control_set = {
5953         .f = cmd_link_flow_ctrl_set_parsed,
5954         .data = NULL,
5955         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5956                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5957                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5958         .tokens = {
5959                 (void *)&cmd_lfc_set_set,
5960                 (void *)&cmd_lfc_set_flow_ctrl,
5961                 (void *)&cmd_lfc_set_rx,
5962                 (void *)&cmd_lfc_set_rx_mode,
5963                 (void *)&cmd_lfc_set_tx,
5964                 (void *)&cmd_lfc_set_tx_mode,
5965                 (void *)&cmd_lfc_set_high_water,
5966                 (void *)&cmd_lfc_set_low_water,
5967                 (void *)&cmd_lfc_set_pause_time,
5968                 (void *)&cmd_lfc_set_send_xon,
5969                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5970                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5971                 (void *)&cmd_lfc_set_autoneg_str,
5972                 (void *)&cmd_lfc_set_autoneg,
5973                 (void *)&cmd_lfc_set_portid,
5974                 NULL,
5975         },
5976 };
5977
5978 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5979         .f = cmd_link_flow_ctrl_set_parsed,
5980         .data = (void *)&cmd_link_flow_control_set_rx,
5981         .help_str = "set flow_ctrl rx on|off <port_id>: "
5982                 "Change rx flow control parameter",
5983         .tokens = {
5984                 (void *)&cmd_lfc_set_set,
5985                 (void *)&cmd_lfc_set_flow_ctrl,
5986                 (void *)&cmd_lfc_set_rx,
5987                 (void *)&cmd_lfc_set_rx_mode,
5988                 (void *)&cmd_lfc_set_portid,
5989                 NULL,
5990         },
5991 };
5992
5993 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5994         .f = cmd_link_flow_ctrl_set_parsed,
5995         .data = (void *)&cmd_link_flow_control_set_tx,
5996         .help_str = "set flow_ctrl tx on|off <port_id>: "
5997                 "Change tx flow control parameter",
5998         .tokens = {
5999                 (void *)&cmd_lfc_set_set,
6000                 (void *)&cmd_lfc_set_flow_ctrl,
6001                 (void *)&cmd_lfc_set_tx,
6002                 (void *)&cmd_lfc_set_tx_mode,
6003                 (void *)&cmd_lfc_set_portid,
6004                 NULL,
6005         },
6006 };
6007
6008 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6009         .f = cmd_link_flow_ctrl_set_parsed,
6010         .data = (void *)&cmd_link_flow_control_set_hw,
6011         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6012                 "Change high water flow control parameter",
6013         .tokens = {
6014                 (void *)&cmd_lfc_set_set,
6015                 (void *)&cmd_lfc_set_flow_ctrl,
6016                 (void *)&cmd_lfc_set_high_water_str,
6017                 (void *)&cmd_lfc_set_high_water,
6018                 (void *)&cmd_lfc_set_portid,
6019                 NULL,
6020         },
6021 };
6022
6023 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6024         .f = cmd_link_flow_ctrl_set_parsed,
6025         .data = (void *)&cmd_link_flow_control_set_lw,
6026         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6027                 "Change low water flow control parameter",
6028         .tokens = {
6029                 (void *)&cmd_lfc_set_set,
6030                 (void *)&cmd_lfc_set_flow_ctrl,
6031                 (void *)&cmd_lfc_set_low_water_str,
6032                 (void *)&cmd_lfc_set_low_water,
6033                 (void *)&cmd_lfc_set_portid,
6034                 NULL,
6035         },
6036 };
6037
6038 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6039         .f = cmd_link_flow_ctrl_set_parsed,
6040         .data = (void *)&cmd_link_flow_control_set_pt,
6041         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6042                 "Change pause time flow control parameter",
6043         .tokens = {
6044                 (void *)&cmd_lfc_set_set,
6045                 (void *)&cmd_lfc_set_flow_ctrl,
6046                 (void *)&cmd_lfc_set_pause_time_str,
6047                 (void *)&cmd_lfc_set_pause_time,
6048                 (void *)&cmd_lfc_set_portid,
6049                 NULL,
6050         },
6051 };
6052
6053 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6054         .f = cmd_link_flow_ctrl_set_parsed,
6055         .data = (void *)&cmd_link_flow_control_set_xon,
6056         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6057                 "Change send_xon flow control parameter",
6058         .tokens = {
6059                 (void *)&cmd_lfc_set_set,
6060                 (void *)&cmd_lfc_set_flow_ctrl,
6061                 (void *)&cmd_lfc_set_send_xon_str,
6062                 (void *)&cmd_lfc_set_send_xon,
6063                 (void *)&cmd_lfc_set_portid,
6064                 NULL,
6065         },
6066 };
6067
6068 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6069         .f = cmd_link_flow_ctrl_set_parsed,
6070         .data = (void *)&cmd_link_flow_control_set_macfwd,
6071         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6072                 "Change mac ctrl fwd flow control parameter",
6073         .tokens = {
6074                 (void *)&cmd_lfc_set_set,
6075                 (void *)&cmd_lfc_set_flow_ctrl,
6076                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6077                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6078                 (void *)&cmd_lfc_set_portid,
6079                 NULL,
6080         },
6081 };
6082
6083 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6084         .f = cmd_link_flow_ctrl_set_parsed,
6085         .data = (void *)&cmd_link_flow_control_set_autoneg,
6086         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6087                 "Change autoneg flow control parameter",
6088         .tokens = {
6089                 (void *)&cmd_lfc_set_set,
6090                 (void *)&cmd_lfc_set_flow_ctrl,
6091                 (void *)&cmd_lfc_set_autoneg_str,
6092                 (void *)&cmd_lfc_set_autoneg,
6093                 (void *)&cmd_lfc_set_portid,
6094                 NULL,
6095         },
6096 };
6097
6098 static void
6099 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6100                               __attribute__((unused)) struct cmdline *cl,
6101                               void *data)
6102 {
6103         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6104         cmdline_parse_inst_t *cmd = data;
6105         struct rte_eth_fc_conf fc_conf;
6106         int rx_fc_en = 0;
6107         int tx_fc_en = 0;
6108         int ret;
6109
6110         /*
6111          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6112          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6113          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6114          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6115          */
6116         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6117                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6118         };
6119
6120         /* Partial command line, retrieve current configuration */
6121         if (cmd) {
6122                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6123                 if (ret != 0) {
6124                         printf("cannot get current flow ctrl parameters, return"
6125                                "code = %d\n", ret);
6126                         return;
6127                 }
6128
6129                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6130                     (fc_conf.mode == RTE_FC_FULL))
6131                         rx_fc_en = 1;
6132                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6133                     (fc_conf.mode == RTE_FC_FULL))
6134                         tx_fc_en = 1;
6135         }
6136
6137         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6138                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6139
6140         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6141                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6142
6143         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6144
6145         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6146                 fc_conf.high_water = res->high_water;
6147
6148         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6149                 fc_conf.low_water = res->low_water;
6150
6151         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6152                 fc_conf.pause_time = res->pause_time;
6153
6154         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6155                 fc_conf.send_xon = res->send_xon;
6156
6157         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6158                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6159                         fc_conf.mac_ctrl_frame_fwd = 1;
6160                 else
6161                         fc_conf.mac_ctrl_frame_fwd = 0;
6162         }
6163
6164         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6165                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6166
6167         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6168         if (ret != 0)
6169                 printf("bad flow contrl parameter, return code = %d \n", ret);
6170 }
6171
6172 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6173 struct cmd_priority_flow_ctrl_set_result {
6174         cmdline_fixed_string_t set;
6175         cmdline_fixed_string_t pfc_ctrl;
6176         cmdline_fixed_string_t rx;
6177         cmdline_fixed_string_t rx_pfc_mode;
6178         cmdline_fixed_string_t tx;
6179         cmdline_fixed_string_t tx_pfc_mode;
6180         uint32_t high_water;
6181         uint32_t low_water;
6182         uint16_t pause_time;
6183         uint8_t  priority;
6184         portid_t port_id;
6185 };
6186
6187 static void
6188 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6189                        __attribute__((unused)) struct cmdline *cl,
6190                        __attribute__((unused)) void *data)
6191 {
6192         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6193         struct rte_eth_pfc_conf pfc_conf;
6194         int rx_fc_enable, tx_fc_enable;
6195         int ret;
6196
6197         /*
6198          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6199          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6200          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6201          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6202          */
6203         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6204                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6205         };
6206
6207         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6208         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6209         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6210         pfc_conf.fc.high_water = res->high_water;
6211         pfc_conf.fc.low_water  = res->low_water;
6212         pfc_conf.fc.pause_time = res->pause_time;
6213         pfc_conf.priority      = res->priority;
6214
6215         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6216         if (ret != 0)
6217                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6218 }
6219
6220 cmdline_parse_token_string_t cmd_pfc_set_set =
6221         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6222                                 set, "set");
6223 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6224         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6225                                 pfc_ctrl, "pfc_ctrl");
6226 cmdline_parse_token_string_t cmd_pfc_set_rx =
6227         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6228                                 rx, "rx");
6229 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6230         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6231                                 rx_pfc_mode, "on#off");
6232 cmdline_parse_token_string_t cmd_pfc_set_tx =
6233         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6234                                 tx, "tx");
6235 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6236         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6237                                 tx_pfc_mode, "on#off");
6238 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6239         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6240                                 high_water, UINT32);
6241 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6242         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6243                                 low_water, UINT32);
6244 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6245         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6246                                 pause_time, UINT16);
6247 cmdline_parse_token_num_t cmd_pfc_set_priority =
6248         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6249                                 priority, UINT8);
6250 cmdline_parse_token_num_t cmd_pfc_set_portid =
6251         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6252                                 port_id, UINT16);
6253
6254 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6255         .f = cmd_priority_flow_ctrl_set_parsed,
6256         .data = NULL,
6257         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6258                 "<pause_time> <priority> <port_id>: "
6259                 "Configure the Ethernet priority flow control",
6260         .tokens = {
6261                 (void *)&cmd_pfc_set_set,
6262                 (void *)&cmd_pfc_set_flow_ctrl,
6263                 (void *)&cmd_pfc_set_rx,
6264                 (void *)&cmd_pfc_set_rx_mode,
6265                 (void *)&cmd_pfc_set_tx,
6266                 (void *)&cmd_pfc_set_tx_mode,
6267                 (void *)&cmd_pfc_set_high_water,
6268                 (void *)&cmd_pfc_set_low_water,
6269                 (void *)&cmd_pfc_set_pause_time,
6270                 (void *)&cmd_pfc_set_priority,
6271                 (void *)&cmd_pfc_set_portid,
6272                 NULL,
6273         },
6274 };
6275
6276 /* *** RESET CONFIGURATION *** */
6277 struct cmd_reset_result {
6278         cmdline_fixed_string_t reset;
6279         cmdline_fixed_string_t def;
6280 };
6281
6282 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6283                              struct cmdline *cl,
6284                              __attribute__((unused)) void *data)
6285 {
6286         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6287         set_def_fwd_config();
6288 }
6289
6290 cmdline_parse_token_string_t cmd_reset_set =
6291         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6292 cmdline_parse_token_string_t cmd_reset_def =
6293         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6294                                  "default");
6295
6296 cmdline_parse_inst_t cmd_reset = {
6297         .f = cmd_reset_parsed,
6298         .data = NULL,
6299         .help_str = "set default: Reset default forwarding configuration",
6300         .tokens = {
6301                 (void *)&cmd_reset_set,
6302                 (void *)&cmd_reset_def,
6303                 NULL,
6304         },
6305 };
6306
6307 /* *** START FORWARDING *** */
6308 struct cmd_start_result {
6309         cmdline_fixed_string_t start;
6310 };
6311
6312 cmdline_parse_token_string_t cmd_start_start =
6313         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6314
6315 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6316                              __attribute__((unused)) struct cmdline *cl,
6317                              __attribute__((unused)) void *data)
6318 {
6319         start_packet_forwarding(0);
6320 }
6321
6322 cmdline_parse_inst_t cmd_start = {
6323         .f = cmd_start_parsed,
6324         .data = NULL,
6325         .help_str = "start: Start packet forwarding",
6326         .tokens = {
6327                 (void *)&cmd_start_start,
6328                 NULL,
6329         },
6330 };
6331
6332 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6333 struct cmd_start_tx_first_result {
6334         cmdline_fixed_string_t start;
6335         cmdline_fixed_string_t tx_first;
6336 };
6337
6338 static void
6339 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6340                           __attribute__((unused)) struct cmdline *cl,
6341                           __attribute__((unused)) void *data)
6342 {
6343         start_packet_forwarding(1);
6344 }
6345
6346 cmdline_parse_token_string_t cmd_start_tx_first_start =
6347         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6348                                  "start");
6349 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6350         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6351                                  tx_first, "tx_first");
6352
6353 cmdline_parse_inst_t cmd_start_tx_first = {
6354         .f = cmd_start_tx_first_parsed,
6355         .data = NULL,
6356         .help_str = "start tx_first: Start packet forwarding, "
6357                 "after sending 1 burst of packets",
6358         .tokens = {
6359                 (void *)&cmd_start_tx_first_start,
6360                 (void *)&cmd_start_tx_first_tx_first,
6361                 NULL,
6362         },
6363 };
6364
6365 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6366 struct cmd_start_tx_first_n_result {
6367         cmdline_fixed_string_t start;
6368         cmdline_fixed_string_t tx_first;
6369         uint32_t tx_num;
6370 };
6371
6372 static void
6373 cmd_start_tx_first_n_parsed(void *parsed_result,
6374                           __attribute__((unused)) struct cmdline *cl,
6375                           __attribute__((unused)) void *data)
6376 {
6377         struct cmd_start_tx_first_n_result *res = parsed_result;
6378
6379         start_packet_forwarding(res->tx_num);
6380 }
6381
6382 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6383         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6384                         start, "start");
6385 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6386         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6387                         tx_first, "tx_first");
6388 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6389         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6390                         tx_num, UINT32);
6391
6392 cmdline_parse_inst_t cmd_start_tx_first_n = {
6393         .f = cmd_start_tx_first_n_parsed,
6394         .data = NULL,
6395         .help_str = "start tx_first <num>: "
6396                 "packet forwarding, after sending <num> bursts of packets",
6397         .tokens = {
6398                 (void *)&cmd_start_tx_first_n_start,
6399                 (void *)&cmd_start_tx_first_n_tx_first,
6400                 (void *)&cmd_start_tx_first_n_tx_num,
6401                 NULL,
6402         },
6403 };
6404
6405 /* *** SET LINK UP *** */
6406 struct cmd_set_link_up_result {
6407         cmdline_fixed_string_t set;
6408         cmdline_fixed_string_t link_up;
6409         cmdline_fixed_string_t port;
6410         portid_t port_id;
6411 };
6412
6413 cmdline_parse_token_string_t cmd_set_link_up_set =
6414         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6415 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6417                                 "link-up");
6418 cmdline_parse_token_string_t cmd_set_link_up_port =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6420 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6421         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6422
6423 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6424                              __attribute__((unused)) struct cmdline *cl,
6425                              __attribute__((unused)) void *data)
6426 {
6427         struct cmd_set_link_up_result *res = parsed_result;
6428         dev_set_link_up(res->port_id);
6429 }
6430
6431 cmdline_parse_inst_t cmd_set_link_up = {
6432         .f = cmd_set_link_up_parsed,
6433         .data = NULL,
6434         .help_str = "set link-up port <port id>",
6435         .tokens = {
6436                 (void *)&cmd_set_link_up_set,
6437                 (void *)&cmd_set_link_up_link_up,
6438                 (void *)&cmd_set_link_up_port,
6439                 (void *)&cmd_set_link_up_port_id,
6440                 NULL,
6441         },
6442 };
6443
6444 /* *** SET LINK DOWN *** */
6445 struct cmd_set_link_down_result {
6446         cmdline_fixed_string_t set;
6447         cmdline_fixed_string_t link_down;
6448         cmdline_fixed_string_t port;
6449         portid_t port_id;
6450 };
6451
6452 cmdline_parse_token_string_t cmd_set_link_down_set =
6453         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6454 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6455         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6456                                 "link-down");
6457 cmdline_parse_token_string_t cmd_set_link_down_port =
6458         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6459 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6460         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6461
6462 static void cmd_set_link_down_parsed(
6463                                 __attribute__((unused)) void *parsed_result,
6464                                 __attribute__((unused)) struct cmdline *cl,
6465                                 __attribute__((unused)) void *data)
6466 {
6467         struct cmd_set_link_down_result *res = parsed_result;
6468         dev_set_link_down(res->port_id);
6469 }
6470
6471 cmdline_parse_inst_t cmd_set_link_down = {
6472         .f = cmd_set_link_down_parsed,
6473         .data = NULL,
6474         .help_str = "set link-down port <port id>",
6475         .tokens = {
6476                 (void *)&cmd_set_link_down_set,
6477                 (void *)&cmd_set_link_down_link_down,
6478                 (void *)&cmd_set_link_down_port,
6479                 (void *)&cmd_set_link_down_port_id,
6480                 NULL,
6481         },
6482 };
6483
6484 /* *** SHOW CFG *** */
6485 struct cmd_showcfg_result {
6486         cmdline_fixed_string_t show;
6487         cmdline_fixed_string_t cfg;
6488         cmdline_fixed_string_t what;
6489 };
6490
6491 static void cmd_showcfg_parsed(void *parsed_result,
6492                                __attribute__((unused)) struct cmdline *cl,
6493                                __attribute__((unused)) void *data)
6494 {
6495         struct cmd_showcfg_result *res = parsed_result;
6496         if (!strcmp(res->what, "rxtx"))
6497                 rxtx_config_display();
6498         else if (!strcmp(res->what, "cores"))
6499                 fwd_lcores_config_display();
6500         else if (!strcmp(res->what, "fwd"))
6501                 pkt_fwd_config_display(&cur_fwd_config);
6502         else if (!strcmp(res->what, "txpkts"))
6503                 show_tx_pkt_segments();
6504 }
6505
6506 cmdline_parse_token_string_t cmd_showcfg_show =
6507         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6508 cmdline_parse_token_string_t cmd_showcfg_port =
6509         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6510 cmdline_parse_token_string_t cmd_showcfg_what =
6511         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6512                                  "rxtx#cores#fwd#txpkts");
6513
6514 cmdline_parse_inst_t cmd_showcfg = {
6515         .f = cmd_showcfg_parsed,
6516         .data = NULL,
6517         .help_str = "show config rxtx|cores|fwd|txpkts",
6518         .tokens = {
6519                 (void *)&cmd_showcfg_show,
6520                 (void *)&cmd_showcfg_port,
6521                 (void *)&cmd_showcfg_what,
6522                 NULL,
6523         },
6524 };
6525
6526 /* *** SHOW ALL PORT INFO *** */
6527 struct cmd_showportall_result {
6528         cmdline_fixed_string_t show;
6529         cmdline_fixed_string_t port;
6530         cmdline_fixed_string_t what;
6531         cmdline_fixed_string_t all;
6532 };
6533
6534 static void cmd_showportall_parsed(void *parsed_result,
6535                                 __attribute__((unused)) struct cmdline *cl,
6536                                 __attribute__((unused)) void *data)
6537 {
6538         portid_t i;
6539
6540         struct cmd_showportall_result *res = parsed_result;
6541         if (!strcmp(res->show, "clear")) {
6542                 if (!strcmp(res->what, "stats"))
6543                         RTE_ETH_FOREACH_DEV(i)
6544                                 nic_stats_clear(i);
6545                 else if (!strcmp(res->what, "xstats"))
6546                         RTE_ETH_FOREACH_DEV(i)
6547                                 nic_xstats_clear(i);
6548         } else if (!strcmp(res->what, "info"))
6549                 RTE_ETH_FOREACH_DEV(i)
6550                         port_infos_display(i);
6551         else if (!strcmp(res->what, "stats"))
6552                 RTE_ETH_FOREACH_DEV(i)
6553                         nic_stats_display(i);
6554         else if (!strcmp(res->what, "xstats"))
6555                 RTE_ETH_FOREACH_DEV(i)
6556                         nic_xstats_display(i);
6557         else if (!strcmp(res->what, "fdir"))
6558                 RTE_ETH_FOREACH_DEV(i)
6559                         fdir_get_infos(i);
6560         else if (!strcmp(res->what, "stat_qmap"))
6561                 RTE_ETH_FOREACH_DEV(i)
6562                         nic_stats_mapping_display(i);
6563         else if (!strcmp(res->what, "dcb_tc"))
6564                 RTE_ETH_FOREACH_DEV(i)
6565                         port_dcb_info_display(i);
6566         else if (!strcmp(res->what, "cap"))
6567                 RTE_ETH_FOREACH_DEV(i)
6568                         port_offload_cap_display(i);
6569 }
6570
6571 cmdline_parse_token_string_t cmd_showportall_show =
6572         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6573                                  "show#clear");
6574 cmdline_parse_token_string_t cmd_showportall_port =
6575         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6576 cmdline_parse_token_string_t cmd_showportall_what =
6577         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6578                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6579 cmdline_parse_token_string_t cmd_showportall_all =
6580         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6581 cmdline_parse_inst_t cmd_showportall = {
6582         .f = cmd_showportall_parsed,
6583         .data = NULL,
6584         .help_str = "show|clear port "
6585                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6586         .tokens = {
6587                 (void *)&cmd_showportall_show,
6588                 (void *)&cmd_showportall_port,
6589                 (void *)&cmd_showportall_what,
6590                 (void *)&cmd_showportall_all,
6591                 NULL,
6592         },
6593 };
6594
6595 /* *** SHOW PORT INFO *** */
6596 struct cmd_showport_result {
6597         cmdline_fixed_string_t show;
6598         cmdline_fixed_string_t port;
6599         cmdline_fixed_string_t what;
6600         uint16_t portnum;
6601 };
6602
6603 static void cmd_showport_parsed(void *parsed_result,
6604                                 __attribute__((unused)) struct cmdline *cl,
6605                                 __attribute__((unused)) void *data)
6606 {
6607         struct cmd_showport_result *res = parsed_result;
6608         if (!strcmp(res->show, "clear")) {
6609                 if (!strcmp(res->what, "stats"))
6610                         nic_stats_clear(res->portnum);
6611                 else if (!strcmp(res->what, "xstats"))
6612                         nic_xstats_clear(res->portnum);
6613         } else if (!strcmp(res->what, "info"))
6614                 port_infos_display(res->portnum);
6615         else if (!strcmp(res->what, "stats"))
6616                 nic_stats_display(res->portnum);
6617         else if (!strcmp(res->what, "xstats"))
6618                 nic_xstats_display(res->portnum);
6619         else if (!strcmp(res->what, "fdir"))
6620                  fdir_get_infos(res->portnum);
6621         else if (!strcmp(res->what, "stat_qmap"))
6622                 nic_stats_mapping_display(res->portnum);
6623         else if (!strcmp(res->what, "dcb_tc"))
6624                 port_dcb_info_display(res->portnum);
6625         else if (!strcmp(res->what, "cap"))
6626                 port_offload_cap_display(res->portnum);
6627 }
6628
6629 cmdline_parse_token_string_t cmd_showport_show =
6630         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6631                                  "show#clear");
6632 cmdline_parse_token_string_t cmd_showport_port =
6633         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6634 cmdline_parse_token_string_t cmd_showport_what =
6635         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6636                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6637 cmdline_parse_token_num_t cmd_showport_portnum =
6638         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6639
6640 cmdline_parse_inst_t cmd_showport = {
6641         .f = cmd_showport_parsed,
6642         .data = NULL,
6643         .help_str = "show|clear port "
6644                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6645                 "<port_id>",
6646         .tokens = {
6647                 (void *)&cmd_showport_show,
6648                 (void *)&cmd_showport_port,
6649                 (void *)&cmd_showport_what,
6650                 (void *)&cmd_showport_portnum,
6651                 NULL,
6652         },
6653 };
6654
6655 /* *** SHOW QUEUE INFO *** */
6656 struct cmd_showqueue_result {
6657         cmdline_fixed_string_t show;
6658         cmdline_fixed_string_t type;
6659         cmdline_fixed_string_t what;
6660         uint16_t portnum;
6661         uint16_t queuenum;
6662 };
6663
6664 static void
6665 cmd_showqueue_parsed(void *parsed_result,
6666         __attribute__((unused)) struct cmdline *cl,
6667         __attribute__((unused)) void *data)
6668 {
6669         struct cmd_showqueue_result *res = parsed_result;
6670
6671         if (!strcmp(res->type, "rxq"))
6672                 rx_queue_infos_display(res->portnum, res->queuenum);
6673         else if (!strcmp(res->type, "txq"))
6674                 tx_queue_infos_display(res->portnum, res->queuenum);
6675 }
6676
6677 cmdline_parse_token_string_t cmd_showqueue_show =
6678         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6679 cmdline_parse_token_string_t cmd_showqueue_type =
6680         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6681 cmdline_parse_token_string_t cmd_showqueue_what =
6682         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6683 cmdline_parse_token_num_t cmd_showqueue_portnum =
6684         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6685 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6686         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6687
6688 cmdline_parse_inst_t cmd_showqueue = {
6689         .f = cmd_showqueue_parsed,
6690         .data = NULL,
6691         .help_str = "show rxq|txq info <port_id> <queue_id>",
6692         .tokens = {
6693                 (void *)&cmd_showqueue_show,
6694                 (void *)&cmd_showqueue_type,
6695                 (void *)&cmd_showqueue_what,
6696                 (void *)&cmd_showqueue_portnum,
6697                 (void *)&cmd_showqueue_queuenum,
6698                 NULL,
6699         },
6700 };
6701
6702 /* *** READ PORT REGISTER *** */
6703 struct cmd_read_reg_result {
6704         cmdline_fixed_string_t read;
6705         cmdline_fixed_string_t reg;
6706         portid_t port_id;
6707         uint32_t reg_off;
6708 };
6709
6710 static void
6711 cmd_read_reg_parsed(void *parsed_result,
6712                     __attribute__((unused)) struct cmdline *cl,
6713                     __attribute__((unused)) void *data)
6714 {
6715         struct cmd_read_reg_result *res = parsed_result;
6716         port_reg_display(res->port_id, res->reg_off);
6717 }
6718
6719 cmdline_parse_token_string_t cmd_read_reg_read =
6720         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6721 cmdline_parse_token_string_t cmd_read_reg_reg =
6722         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6723 cmdline_parse_token_num_t cmd_read_reg_port_id =
6724         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6725 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6726         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6727
6728 cmdline_parse_inst_t cmd_read_reg = {
6729         .f = cmd_read_reg_parsed,
6730         .data = NULL,
6731         .help_str = "read reg <port_id> <reg_off>",
6732         .tokens = {
6733                 (void *)&cmd_read_reg_read,
6734                 (void *)&cmd_read_reg_reg,
6735                 (void *)&cmd_read_reg_port_id,
6736                 (void *)&cmd_read_reg_reg_off,
6737                 NULL,
6738         },
6739 };
6740
6741 /* *** READ PORT REGISTER BIT FIELD *** */
6742 struct cmd_read_reg_bit_field_result {
6743         cmdline_fixed_string_t read;
6744         cmdline_fixed_string_t regfield;
6745         portid_t port_id;
6746         uint32_t reg_off;
6747         uint8_t bit1_pos;
6748         uint8_t bit2_pos;
6749 };
6750
6751 static void
6752 cmd_read_reg_bit_field_parsed(void *parsed_result,
6753                               __attribute__((unused)) struct cmdline *cl,
6754                               __attribute__((unused)) void *data)
6755 {
6756         struct cmd_read_reg_bit_field_result *res = parsed_result;
6757         port_reg_bit_field_display(res->port_id, res->reg_off,
6758                                    res->bit1_pos, res->bit2_pos);
6759 }
6760
6761 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6762         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6763                                  "read");
6764 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6765         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6766                                  regfield, "regfield");
6767 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6768         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6769                               UINT16);
6770 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6771         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6772                               UINT32);
6773 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6774         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6775                               UINT8);
6776 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6777         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6778                               UINT8);
6779
6780 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6781         .f = cmd_read_reg_bit_field_parsed,
6782         .data = NULL,
6783         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6784         "Read register bit field between bit_x and bit_y included",
6785         .tokens = {
6786                 (void *)&cmd_read_reg_bit_field_read,
6787                 (void *)&cmd_read_reg_bit_field_regfield,
6788                 (void *)&cmd_read_reg_bit_field_port_id,
6789                 (void *)&cmd_read_reg_bit_field_reg_off,
6790                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6791                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6792                 NULL,
6793         },
6794 };
6795
6796 /* *** READ PORT REGISTER BIT *** */
6797 struct cmd_read_reg_bit_result {
6798         cmdline_fixed_string_t read;
6799         cmdline_fixed_string_t regbit;
6800         portid_t port_id;
6801         uint32_t reg_off;
6802         uint8_t bit_pos;
6803 };
6804
6805 static void
6806 cmd_read_reg_bit_parsed(void *parsed_result,
6807                         __attribute__((unused)) struct cmdline *cl,
6808                         __attribute__((unused)) void *data)
6809 {
6810         struct cmd_read_reg_bit_result *res = parsed_result;
6811         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6812 }
6813
6814 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6815         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6816 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6817         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6818                                  regbit, "regbit");
6819 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6820         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6821 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6822         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6823 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6824         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6825
6826 cmdline_parse_inst_t cmd_read_reg_bit = {
6827         .f = cmd_read_reg_bit_parsed,
6828         .data = NULL,
6829         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6830         .tokens = {
6831                 (void *)&cmd_read_reg_bit_read,
6832                 (void *)&cmd_read_reg_bit_regbit,
6833                 (void *)&cmd_read_reg_bit_port_id,
6834                 (void *)&cmd_read_reg_bit_reg_off,
6835                 (void *)&cmd_read_reg_bit_bit_pos,
6836                 NULL,
6837         },
6838 };
6839
6840 /* *** WRITE PORT REGISTER *** */
6841 struct cmd_write_reg_result {
6842         cmdline_fixed_string_t write;
6843         cmdline_fixed_string_t reg;
6844         portid_t port_id;
6845         uint32_t reg_off;
6846         uint32_t value;
6847 };
6848
6849 static void
6850 cmd_write_reg_parsed(void *parsed_result,
6851                      __attribute__((unused)) struct cmdline *cl,
6852                      __attribute__((unused)) void *data)
6853 {
6854         struct cmd_write_reg_result *res = parsed_result;
6855         port_reg_set(res->port_id, res->reg_off, res->value);
6856 }
6857
6858 cmdline_parse_token_string_t cmd_write_reg_write =
6859         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6860 cmdline_parse_token_string_t cmd_write_reg_reg =
6861         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6862 cmdline_parse_token_num_t cmd_write_reg_port_id =
6863         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6864 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6865         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6866 cmdline_parse_token_num_t cmd_write_reg_value =
6867         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6868
6869 cmdline_parse_inst_t cmd_write_reg = {
6870         .f = cmd_write_reg_parsed,
6871         .data = NULL,
6872         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6873         .tokens = {
6874                 (void *)&cmd_write_reg_write,
6875                 (void *)&cmd_write_reg_reg,
6876                 (void *)&cmd_write_reg_port_id,
6877                 (void *)&cmd_write_reg_reg_off,
6878                 (void *)&cmd_write_reg_value,
6879                 NULL,
6880         },
6881 };
6882
6883 /* *** WRITE PORT REGISTER BIT FIELD *** */
6884 struct cmd_write_reg_bit_field_result {
6885         cmdline_fixed_string_t write;
6886         cmdline_fixed_string_t regfield;
6887         portid_t port_id;
6888         uint32_t reg_off;
6889         uint8_t bit1_pos;
6890         uint8_t bit2_pos;
6891         uint32_t value;
6892 };
6893
6894 static void
6895 cmd_write_reg_bit_field_parsed(void *parsed_result,
6896                                __attribute__((unused)) struct cmdline *cl,
6897                                __attribute__((unused)) void *data)
6898 {
6899         struct cmd_write_reg_bit_field_result *res = parsed_result;
6900         port_reg_bit_field_set(res->port_id, res->reg_off,
6901                           res->bit1_pos, res->bit2_pos, res->value);
6902 }
6903
6904 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6905         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6906                                  "write");
6907 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6908         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6909                                  regfield, "regfield");
6910 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6911         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6912                               UINT16);
6913 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6914         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6915                               UINT32);
6916 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6917         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6918                               UINT8);
6919 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6920         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6921                               UINT8);
6922 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6923         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6924                               UINT32);
6925
6926 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6927         .f = cmd_write_reg_bit_field_parsed,
6928         .data = NULL,
6929         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6930                 "<reg_value>: "
6931                 "Set register bit field between bit_x and bit_y included",
6932         .tokens = {
6933                 (void *)&cmd_write_reg_bit_field_write,
6934                 (void *)&cmd_write_reg_bit_field_regfield,
6935                 (void *)&cmd_write_reg_bit_field_port_id,
6936                 (void *)&cmd_write_reg_bit_field_reg_off,
6937                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6938                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6939                 (void *)&cmd_write_reg_bit_field_value,
6940                 NULL,
6941         },
6942 };
6943
6944 /* *** WRITE PORT REGISTER BIT *** */
6945 struct cmd_write_reg_bit_result {
6946         cmdline_fixed_string_t write;
6947         cmdline_fixed_string_t regbit;
6948         portid_t port_id;
6949         uint32_t reg_off;
6950         uint8_t bit_pos;
6951         uint8_t value;
6952 };
6953
6954 static void
6955 cmd_write_reg_bit_parsed(void *parsed_result,
6956                          __attribute__((unused)) struct cmdline *cl,
6957                          __attribute__((unused)) void *data)
6958 {
6959         struct cmd_write_reg_bit_result *res = parsed_result;
6960         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6961 }
6962
6963 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6964         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6965                                  "write");
6966 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6967         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6968                                  regbit, "regbit");
6969 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6970         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6971 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6972         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6973 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6974         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6975 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6977
6978 cmdline_parse_inst_t cmd_write_reg_bit = {
6979         .f = cmd_write_reg_bit_parsed,
6980         .data = NULL,
6981         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6982                 "0 <= bit_x <= 31",
6983         .tokens = {
6984                 (void *)&cmd_write_reg_bit_write,
6985                 (void *)&cmd_write_reg_bit_regbit,
6986                 (void *)&cmd_write_reg_bit_port_id,
6987                 (void *)&cmd_write_reg_bit_reg_off,
6988                 (void *)&cmd_write_reg_bit_bit_pos,
6989                 (void *)&cmd_write_reg_bit_value,
6990                 NULL,
6991         },
6992 };
6993
6994 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6995 struct cmd_read_rxd_txd_result {
6996         cmdline_fixed_string_t read;
6997         cmdline_fixed_string_t rxd_txd;
6998         portid_t port_id;
6999         uint16_t queue_id;
7000         uint16_t desc_id;
7001 };
7002
7003 static void
7004 cmd_read_rxd_txd_parsed(void *parsed_result,
7005                         __attribute__((unused)) struct cmdline *cl,
7006                         __attribute__((unused)) void *data)
7007 {
7008         struct cmd_read_rxd_txd_result *res = parsed_result;
7009
7010         if (!strcmp(res->rxd_txd, "rxd"))
7011                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7012         else if (!strcmp(res->rxd_txd, "txd"))
7013                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7014 }
7015
7016 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7017         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7018 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7019         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7020                                  "rxd#txd");
7021 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7022         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7023 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7024         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7025 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7026         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7027
7028 cmdline_parse_inst_t cmd_read_rxd_txd = {
7029         .f = cmd_read_rxd_txd_parsed,
7030         .data = NULL,
7031         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7032         .tokens = {
7033                 (void *)&cmd_read_rxd_txd_read,
7034                 (void *)&cmd_read_rxd_txd_rxd_txd,
7035                 (void *)&cmd_read_rxd_txd_port_id,
7036                 (void *)&cmd_read_rxd_txd_queue_id,
7037                 (void *)&cmd_read_rxd_txd_desc_id,
7038                 NULL,
7039         },
7040 };
7041
7042 /* *** QUIT *** */
7043 struct cmd_quit_result {
7044         cmdline_fixed_string_t quit;
7045 };
7046
7047 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7048                             struct cmdline *cl,
7049                             __attribute__((unused)) void *data)
7050 {
7051         pmd_test_exit();
7052         cmdline_quit(cl);
7053 }
7054
7055 cmdline_parse_token_string_t cmd_quit_quit =
7056         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7057
7058 cmdline_parse_inst_t cmd_quit = {
7059         .f = cmd_quit_parsed,
7060         .data = NULL,
7061         .help_str = "quit: Exit application",
7062         .tokens = {
7063                 (void *)&cmd_quit_quit,
7064                 NULL,
7065         },
7066 };
7067
7068 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7069 struct cmd_mac_addr_result {
7070         cmdline_fixed_string_t mac_addr_cmd;
7071         cmdline_fixed_string_t what;
7072         uint16_t port_num;
7073         struct ether_addr address;
7074 };
7075
7076 static void cmd_mac_addr_parsed(void *parsed_result,
7077                 __attribute__((unused)) struct cmdline *cl,
7078                 __attribute__((unused)) void *data)
7079 {
7080         struct cmd_mac_addr_result *res = parsed_result;
7081         int ret;
7082
7083         if (strcmp(res->what, "add") == 0)
7084                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7085         else if (strcmp(res->what, "set") == 0)
7086                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7087                                                        &res->address);
7088         else
7089                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7090
7091         /* check the return value and print it if is < 0 */
7092         if(ret < 0)
7093                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7094
7095 }
7096
7097 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7098         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7099                                 "mac_addr");
7100 cmdline_parse_token_string_t cmd_mac_addr_what =
7101         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7102                                 "add#remove#set");
7103 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7104                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7105                                         UINT16);
7106 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7107                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7108
7109 cmdline_parse_inst_t cmd_mac_addr = {
7110         .f = cmd_mac_addr_parsed,
7111         .data = (void *)0,
7112         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7113                         "Add/Remove/Set MAC address on port_id",
7114         .tokens = {
7115                 (void *)&cmd_mac_addr_cmd,
7116                 (void *)&cmd_mac_addr_what,
7117                 (void *)&cmd_mac_addr_portnum,
7118                 (void *)&cmd_mac_addr_addr,
7119                 NULL,
7120         },
7121 };
7122
7123
7124 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7125 struct cmd_set_qmap_result {
7126         cmdline_fixed_string_t set;
7127         cmdline_fixed_string_t qmap;
7128         cmdline_fixed_string_t what;
7129         portid_t port_id;
7130         uint16_t queue_id;
7131         uint8_t map_value;
7132 };
7133
7134 static void
7135 cmd_set_qmap_parsed(void *parsed_result,
7136                        __attribute__((unused)) struct cmdline *cl,
7137                        __attribute__((unused)) void *data)
7138 {
7139         struct cmd_set_qmap_result *res = parsed_result;
7140         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7141
7142         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7143 }
7144
7145 cmdline_parse_token_string_t cmd_setqmap_set =
7146         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7147                                  set, "set");
7148 cmdline_parse_token_string_t cmd_setqmap_qmap =
7149         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7150                                  qmap, "stat_qmap");
7151 cmdline_parse_token_string_t cmd_setqmap_what =
7152         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7153                                  what, "tx#rx");
7154 cmdline_parse_token_num_t cmd_setqmap_portid =
7155         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7156                               port_id, UINT16);
7157 cmdline_parse_token_num_t cmd_setqmap_queueid =
7158         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7159                               queue_id, UINT16);
7160 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7161         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7162                               map_value, UINT8);
7163
7164 cmdline_parse_inst_t cmd_set_qmap = {
7165         .f = cmd_set_qmap_parsed,
7166         .data = NULL,
7167         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7168                 "Set statistics mapping value on tx|rx queue_id of port_id",
7169         .tokens = {
7170                 (void *)&cmd_setqmap_set,
7171                 (void *)&cmd_setqmap_qmap,
7172                 (void *)&cmd_setqmap_what,
7173                 (void *)&cmd_setqmap_portid,
7174                 (void *)&cmd_setqmap_queueid,
7175                 (void *)&cmd_setqmap_mapvalue,
7176                 NULL,
7177         },
7178 };
7179
7180 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7181 struct cmd_set_xstats_hide_zero_result {
7182         cmdline_fixed_string_t keyword;
7183         cmdline_fixed_string_t name;
7184         cmdline_fixed_string_t on_off;
7185 };
7186
7187 static void
7188 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7189                         __attribute__((unused)) struct cmdline *cl,
7190                         __attribute__((unused)) void *data)
7191 {
7192         struct cmd_set_xstats_hide_zero_result *res;
7193         uint16_t on_off = 0;
7194
7195         res = parsed_result;
7196         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7197         set_xstats_hide_zero(on_off);
7198 }
7199
7200 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7201         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7202                                  keyword, "set");
7203 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7204         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7205                                  name, "xstats-hide-zero");
7206 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7207         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7208                                  on_off, "on#off");
7209
7210 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7211         .f = cmd_set_xstats_hide_zero_parsed,
7212         .data = NULL,
7213         .help_str = "set xstats-hide-zero on|off",
7214         .tokens = {
7215                 (void *)&cmd_set_xstats_hide_zero_keyword,
7216                 (void *)&cmd_set_xstats_hide_zero_name,
7217                 (void *)&cmd_set_xstats_hide_zero_on_off,
7218                 NULL,
7219         },
7220 };
7221
7222 /* *** CONFIGURE UNICAST HASH TABLE *** */
7223 struct cmd_set_uc_hash_table {
7224         cmdline_fixed_string_t set;
7225         cmdline_fixed_string_t port;
7226         portid_t port_id;
7227         cmdline_fixed_string_t what;
7228         struct ether_addr address;
7229         cmdline_fixed_string_t mode;
7230 };
7231
7232 static void
7233 cmd_set_uc_hash_parsed(void *parsed_result,
7234                        __attribute__((unused)) struct cmdline *cl,
7235                        __attribute__((unused)) void *data)
7236 {
7237         int ret=0;
7238         struct cmd_set_uc_hash_table *res = parsed_result;
7239
7240         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7241
7242         if (strcmp(res->what, "uta") == 0)
7243                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7244                                                 &res->address,(uint8_t)is_on);
7245         if (ret < 0)
7246                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7247
7248 }
7249
7250 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7251         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7252                                  set, "set");
7253 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7254         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7255                                  port, "port");
7256 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7257         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7258                               port_id, UINT16);
7259 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7260         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7261                                  what, "uta");
7262 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7263         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7264                                 address);
7265 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7266         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7267                                  mode, "on#off");
7268
7269 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7270         .f = cmd_set_uc_hash_parsed,
7271         .data = NULL,
7272         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7273         .tokens = {
7274                 (void *)&cmd_set_uc_hash_set,
7275                 (void *)&cmd_set_uc_hash_port,
7276                 (void *)&cmd_set_uc_hash_portid,
7277                 (void *)&cmd_set_uc_hash_what,
7278                 (void *)&cmd_set_uc_hash_mac,
7279                 (void *)&cmd_set_uc_hash_mode,
7280                 NULL,
7281         },
7282 };
7283
7284 struct cmd_set_uc_all_hash_table {
7285         cmdline_fixed_string_t set;
7286         cmdline_fixed_string_t port;
7287         portid_t port_id;
7288         cmdline_fixed_string_t what;
7289         cmdline_fixed_string_t value;
7290         cmdline_fixed_string_t mode;
7291 };
7292
7293 static void
7294 cmd_set_uc_all_hash_parsed(void *parsed_result,
7295                        __attribute__((unused)) struct cmdline *cl,
7296                        __attribute__((unused)) void *data)
7297 {
7298         int ret=0;
7299         struct cmd_set_uc_all_hash_table *res = parsed_result;
7300
7301         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7302
7303         if ((strcmp(res->what, "uta") == 0) &&
7304                 (strcmp(res->value, "all") == 0))
7305                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7306         if (ret < 0)
7307                 printf("bad unicast hash table parameter,"
7308                         "return code = %d \n", ret);
7309 }
7310
7311 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7312         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7313                                  set, "set");
7314 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7315         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7316                                  port, "port");
7317 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7318         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7319                               port_id, UINT16);
7320 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7321         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7322                                  what, "uta");
7323 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7324         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7325                                 value,"all");
7326 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7327         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7328                                  mode, "on#off");
7329
7330 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7331         .f = cmd_set_uc_all_hash_parsed,
7332         .data = NULL,
7333         .help_str = "set port <port_id> uta all on|off",
7334         .tokens = {
7335                 (void *)&cmd_set_uc_all_hash_set,
7336                 (void *)&cmd_set_uc_all_hash_port,
7337                 (void *)&cmd_set_uc_all_hash_portid,
7338                 (void *)&cmd_set_uc_all_hash_what,
7339                 (void *)&cmd_set_uc_all_hash_value,
7340                 (void *)&cmd_set_uc_all_hash_mode,
7341                 NULL,
7342         },
7343 };
7344
7345 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7346 struct cmd_set_vf_macvlan_filter {
7347         cmdline_fixed_string_t set;
7348         cmdline_fixed_string_t port;
7349         portid_t port_id;
7350         cmdline_fixed_string_t vf;
7351         uint8_t vf_id;
7352         struct ether_addr address;
7353         cmdline_fixed_string_t filter_type;
7354         cmdline_fixed_string_t mode;
7355 };
7356
7357 static void
7358 cmd_set_vf_macvlan_parsed(void *parsed_result,
7359                        __attribute__((unused)) struct cmdline *cl,
7360                        __attribute__((unused)) void *data)
7361 {
7362         int is_on, ret = 0;
7363         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7364         struct rte_eth_mac_filter filter;
7365
7366         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7367
7368         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7369
7370         /* set VF MAC filter */
7371         filter.is_vf = 1;
7372
7373         /* set VF ID */
7374         filter.dst_id = res->vf_id;
7375
7376         if (!strcmp(res->filter_type, "exact-mac"))
7377                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7378         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7379                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7380         else if (!strcmp(res->filter_type, "hashmac"))
7381                 filter.filter_type = RTE_MAC_HASH_MATCH;
7382         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7383                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7384
7385         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7386
7387         if (is_on)
7388                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7389                                         RTE_ETH_FILTER_MACVLAN,
7390                                         RTE_ETH_FILTER_ADD,
7391                                          &filter);
7392         else
7393                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7394                                         RTE_ETH_FILTER_MACVLAN,
7395                                         RTE_ETH_FILTER_DELETE,
7396                                         &filter);
7397
7398         if (ret < 0)
7399                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7400
7401 }
7402
7403 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7404         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7405                                  set, "set");
7406 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7407         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7408                                  port, "port");
7409 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7410         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7411                               port_id, UINT16);
7412 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7413         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7414                                  vf, "vf");
7415 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7416         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7417                                 vf_id, UINT8);
7418 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7419         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7420                                 address);
7421 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7422         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7423                                 filter_type, "exact-mac#exact-mac-vlan"
7424                                 "#hashmac#hashmac-vlan");
7425 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7426         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7427                                  mode, "on#off");
7428
7429 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7430         .f = cmd_set_vf_macvlan_parsed,
7431         .data = NULL,
7432         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7433                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7434                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7435                 "hash match rule: hash match of MAC and exact match of VLAN",
7436         .tokens = {
7437                 (void *)&cmd_set_vf_macvlan_set,
7438                 (void *)&cmd_set_vf_macvlan_port,
7439                 (void *)&cmd_set_vf_macvlan_portid,
7440                 (void *)&cmd_set_vf_macvlan_vf,
7441                 (void *)&cmd_set_vf_macvlan_vf_id,
7442                 (void *)&cmd_set_vf_macvlan_mac,
7443                 (void *)&cmd_set_vf_macvlan_filter_type,
7444                 (void *)&cmd_set_vf_macvlan_mode,
7445                 NULL,
7446         },
7447 };
7448
7449 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7450 struct cmd_set_vf_traffic {
7451         cmdline_fixed_string_t set;
7452         cmdline_fixed_string_t port;
7453         portid_t port_id;
7454         cmdline_fixed_string_t vf;
7455         uint8_t vf_id;
7456         cmdline_fixed_string_t what;
7457         cmdline_fixed_string_t mode;
7458 };
7459
7460 static void
7461 cmd_set_vf_traffic_parsed(void *parsed_result,
7462                        __attribute__((unused)) struct cmdline *cl,
7463                        __attribute__((unused)) void *data)
7464 {
7465         struct cmd_set_vf_traffic *res = parsed_result;
7466         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7467         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7468
7469         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7470 }
7471
7472 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7474                                  set, "set");
7475 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7476         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7477                                  port, "port");
7478 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7479         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7480                               port_id, UINT16);
7481 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7482         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7483                                  vf, "vf");
7484 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7485         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7486                               vf_id, UINT8);
7487 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7488         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7489                                  what, "tx#rx");
7490 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7491         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7492                                  mode, "on#off");
7493
7494 cmdline_parse_inst_t cmd_set_vf_traffic = {
7495         .f = cmd_set_vf_traffic_parsed,
7496         .data = NULL,
7497         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7498         .tokens = {
7499                 (void *)&cmd_setvf_traffic_set,
7500                 (void *)&cmd_setvf_traffic_port,
7501                 (void *)&cmd_setvf_traffic_portid,
7502                 (void *)&cmd_setvf_traffic_vf,
7503                 (void *)&cmd_setvf_traffic_vfid,
7504                 (void *)&cmd_setvf_traffic_what,
7505                 (void *)&cmd_setvf_traffic_mode,
7506                 NULL,
7507         },
7508 };
7509
7510 /* *** CONFIGURE VF RECEIVE MODE *** */
7511 struct cmd_set_vf_rxmode {
7512         cmdline_fixed_string_t set;
7513         cmdline_fixed_string_t port;
7514         portid_t port_id;
7515         cmdline_fixed_string_t vf;
7516         uint8_t vf_id;
7517         cmdline_fixed_string_t what;
7518         cmdline_fixed_string_t mode;
7519         cmdline_fixed_string_t on;
7520 };
7521
7522 static void
7523 cmd_set_vf_rxmode_parsed(void *parsed_result,
7524                        __attribute__((unused)) struct cmdline *cl,
7525                        __attribute__((unused)) void *data)
7526 {
7527         int ret = -ENOTSUP;
7528         uint16_t rx_mode = 0;
7529         struct cmd_set_vf_rxmode *res = parsed_result;
7530
7531         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7532         if (!strcmp(res->what,"rxmode")) {
7533                 if (!strcmp(res->mode, "AUPE"))
7534                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7535                 else if (!strcmp(res->mode, "ROPE"))
7536                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7537                 else if (!strcmp(res->mode, "BAM"))
7538                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7539                 else if (!strncmp(res->mode, "MPE",3))
7540                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7541         }
7542
7543         RTE_SET_USED(is_on);
7544
7545 #ifdef RTE_LIBRTE_IXGBE_PMD
7546         if (ret == -ENOTSUP)
7547                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7548                                                   rx_mode, (uint8_t)is_on);
7549 #endif
7550 #ifdef RTE_LIBRTE_BNXT_PMD
7551         if (ret == -ENOTSUP)
7552                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7553                                                  rx_mode, (uint8_t)is_on);
7554 #endif
7555         if (ret < 0)
7556                 printf("bad VF receive mode parameter, return code = %d \n",
7557                 ret);
7558 }
7559
7560 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7561         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7562                                  set, "set");
7563 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7564         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7565                                  port, "port");
7566 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7567         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7568                               port_id, UINT16);
7569 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7570         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7571                                  vf, "vf");
7572 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7573         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7574                               vf_id, UINT8);
7575 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7576         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7577                                  what, "rxmode");
7578 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7579         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7580                                  mode, "AUPE#ROPE#BAM#MPE");
7581 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7582         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7583                                  on, "on#off");
7584
7585 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7586         .f = cmd_set_vf_rxmode_parsed,
7587         .data = NULL,
7588         .help_str = "set port <port_id> vf <vf_id> rxmode "
7589                 "AUPE|ROPE|BAM|MPE on|off",
7590         .tokens = {
7591                 (void *)&cmd_set_vf_rxmode_set,
7592                 (void *)&cmd_set_vf_rxmode_port,
7593                 (void *)&cmd_set_vf_rxmode_portid,
7594                 (void *)&cmd_set_vf_rxmode_vf,
7595                 (void *)&cmd_set_vf_rxmode_vfid,
7596                 (void *)&cmd_set_vf_rxmode_what,
7597                 (void *)&cmd_set_vf_rxmode_mode,
7598                 (void *)&cmd_set_vf_rxmode_on,
7599                 NULL,
7600         },
7601 };
7602
7603 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7604 struct cmd_vf_mac_addr_result {
7605         cmdline_fixed_string_t mac_addr_cmd;
7606         cmdline_fixed_string_t what;
7607         cmdline_fixed_string_t port;
7608         uint16_t port_num;
7609         cmdline_fixed_string_t vf;
7610         uint8_t vf_num;
7611         struct ether_addr address;
7612 };
7613
7614 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7615                 __attribute__((unused)) struct cmdline *cl,
7616                 __attribute__((unused)) void *data)
7617 {
7618         struct cmd_vf_mac_addr_result *res = parsed_result;
7619         int ret = -ENOTSUP;
7620
7621         if (strcmp(res->what, "add") != 0)
7622                 return;
7623
7624 #ifdef RTE_LIBRTE_I40E_PMD
7625         if (ret == -ENOTSUP)
7626                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7627                                                    &res->address);
7628 #endif
7629 #ifdef RTE_LIBRTE_BNXT_PMD
7630         if (ret == -ENOTSUP)
7631                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7632                                                 res->vf_num);
7633 #endif
7634
7635         if(ret < 0)
7636                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7637
7638 }
7639
7640 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7641         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7642                                 mac_addr_cmd,"mac_addr");
7643 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7644         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7645                                 what,"add");
7646 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7647         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7648                                 port,"port");
7649 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7650         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7651                                 port_num, UINT16);
7652 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7653         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7654                                 vf,"vf");
7655 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7656         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7657                                 vf_num, UINT8);
7658 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7659         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7660                                 address);
7661
7662 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7663         .f = cmd_vf_mac_addr_parsed,
7664         .data = (void *)0,
7665         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7666                 "Add MAC address filtering for a VF on port_id",
7667         .tokens = {
7668                 (void *)&cmd_vf_mac_addr_cmd,
7669                 (void *)&cmd_vf_mac_addr_what,
7670                 (void *)&cmd_vf_mac_addr_port,
7671                 (void *)&cmd_vf_mac_addr_portnum,
7672                 (void *)&cmd_vf_mac_addr_vf,
7673                 (void *)&cmd_vf_mac_addr_vfnum,
7674                 (void *)&cmd_vf_mac_addr_addr,
7675                 NULL,
7676         },
7677 };
7678
7679 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7680 struct cmd_vf_rx_vlan_filter {
7681         cmdline_fixed_string_t rx_vlan;
7682         cmdline_fixed_string_t what;
7683         uint16_t vlan_id;
7684         cmdline_fixed_string_t port;
7685         portid_t port_id;
7686         cmdline_fixed_string_t vf;
7687         uint64_t vf_mask;
7688 };
7689
7690 static void
7691 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7692                           __attribute__((unused)) struct cmdline *cl,
7693                           __attribute__((unused)) void *data)
7694 {
7695         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7696         int ret = -ENOTSUP;
7697
7698         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7699
7700 #ifdef RTE_LIBRTE_IXGBE_PMD
7701         if (ret == -ENOTSUP)
7702                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7703                                 res->vlan_id, res->vf_mask, is_add);
7704 #endif
7705 #ifdef RTE_LIBRTE_I40E_PMD
7706         if (ret == -ENOTSUP)
7707                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7708                                 res->vlan_id, res->vf_mask, is_add);
7709 #endif
7710 #ifdef RTE_LIBRTE_BNXT_PMD
7711         if (ret == -ENOTSUP)
7712                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7713                                 res->vlan_id, res->vf_mask, is_add);
7714 #endif
7715
7716         switch (ret) {
7717         case 0:
7718                 break;
7719         case -EINVAL:
7720                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7721                                 res->vlan_id, res->vf_mask);
7722                 break;
7723         case -ENODEV:
7724                 printf("invalid port_id %d\n", res->port_id);
7725                 break;
7726         case -ENOTSUP:
7727                 printf("function not implemented or supported\n");
7728                 break;
7729         default:
7730                 printf("programming error: (%s)\n", strerror(-ret));
7731         }
7732 }
7733
7734 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7735         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7736                                  rx_vlan, "rx_vlan");
7737 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7738         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7739                                  what, "add#rm");
7740 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7741         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7742                               vlan_id, UINT16);
7743 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7744         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7745                                  port, "port");
7746 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7747         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7748                               port_id, UINT16);
7749 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7750         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7751                                  vf, "vf");
7752 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7753         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7754                               vf_mask, UINT64);
7755
7756 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7757         .f = cmd_vf_rx_vlan_filter_parsed,
7758         .data = NULL,
7759         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7760                 "(vf_mask = hexadecimal VF mask)",
7761         .tokens = {
7762                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7763                 (void *)&cmd_vf_rx_vlan_filter_what,
7764                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7765                 (void *)&cmd_vf_rx_vlan_filter_port,
7766                 (void *)&cmd_vf_rx_vlan_filter_portid,
7767                 (void *)&cmd_vf_rx_vlan_filter_vf,
7768                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7769                 NULL,
7770         },
7771 };
7772
7773 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7774 struct cmd_queue_rate_limit_result {
7775         cmdline_fixed_string_t set;
7776         cmdline_fixed_string_t port;
7777         uint16_t port_num;
7778         cmdline_fixed_string_t queue;
7779         uint8_t queue_num;
7780         cmdline_fixed_string_t rate;
7781         uint16_t rate_num;
7782 };
7783
7784 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7785                 __attribute__((unused)) struct cmdline *cl,
7786                 __attribute__((unused)) void *data)
7787 {
7788         struct cmd_queue_rate_limit_result *res = parsed_result;
7789         int ret = 0;
7790
7791         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7792                 && (strcmp(res->queue, "queue") == 0)
7793                 && (strcmp(res->rate, "rate") == 0))
7794                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7795                                         res->rate_num);
7796         if (ret < 0)
7797                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7798
7799 }
7800
7801 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7802         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7803                                 set, "set");
7804 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7805         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7806                                 port, "port");
7807 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7808         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7809                                 port_num, UINT16);
7810 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7811         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7812                                 queue, "queue");
7813 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7814         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7815                                 queue_num, UINT8);
7816 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7817         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7818                                 rate, "rate");
7819 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7820         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7821                                 rate_num, UINT16);
7822
7823 cmdline_parse_inst_t cmd_queue_rate_limit = {
7824         .f = cmd_queue_rate_limit_parsed,
7825         .data = (void *)0,
7826         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7827                 "Set rate limit for a queue on port_id",
7828         .tokens = {
7829                 (void *)&cmd_queue_rate_limit_set,
7830                 (void *)&cmd_queue_rate_limit_port,
7831                 (void *)&cmd_queue_rate_limit_portnum,
7832                 (void *)&cmd_queue_rate_limit_queue,
7833                 (void *)&cmd_queue_rate_limit_queuenum,
7834                 (void *)&cmd_queue_rate_limit_rate,
7835                 (void *)&cmd_queue_rate_limit_ratenum,
7836                 NULL,
7837         },
7838 };
7839
7840 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7841 struct cmd_vf_rate_limit_result {
7842         cmdline_fixed_string_t set;
7843         cmdline_fixed_string_t port;
7844         uint16_t port_num;
7845         cmdline_fixed_string_t vf;
7846         uint8_t vf_num;
7847         cmdline_fixed_string_t rate;
7848         uint16_t rate_num;
7849         cmdline_fixed_string_t q_msk;
7850         uint64_t q_msk_val;
7851 };
7852
7853 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7854                 __attribute__((unused)) struct cmdline *cl,
7855                 __attribute__((unused)) void *data)
7856 {
7857         struct cmd_vf_rate_limit_result *res = parsed_result;
7858         int ret = 0;
7859
7860         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7861                 && (strcmp(res->vf, "vf") == 0)
7862                 && (strcmp(res->rate, "rate") == 0)
7863                 && (strcmp(res->q_msk, "queue_mask") == 0))
7864                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7865                                         res->rate_num, res->q_msk_val);
7866         if (ret < 0)
7867                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7868
7869 }
7870
7871 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7872         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7873                                 set, "set");
7874 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7875         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7876                                 port, "port");
7877 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7878         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7879                                 port_num, UINT16);
7880 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7881         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7882                                 vf, "vf");
7883 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7884         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7885                                 vf_num, UINT8);
7886 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7887         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7888                                 rate, "rate");
7889 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7890         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7891                                 rate_num, UINT16);
7892 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7893         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7894                                 q_msk, "queue_mask");
7895 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7896         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7897                                 q_msk_val, UINT64);
7898
7899 cmdline_parse_inst_t cmd_vf_rate_limit = {
7900         .f = cmd_vf_rate_limit_parsed,
7901         .data = (void *)0,
7902         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7903                 "queue_mask <queue_mask_value>: "
7904                 "Set rate limit for queues of VF on port_id",
7905         .tokens = {
7906                 (void *)&cmd_vf_rate_limit_set,
7907                 (void *)&cmd_vf_rate_limit_port,
7908                 (void *)&cmd_vf_rate_limit_portnum,
7909                 (void *)&cmd_vf_rate_limit_vf,
7910                 (void *)&cmd_vf_rate_limit_vfnum,
7911                 (void *)&cmd_vf_rate_limit_rate,
7912                 (void *)&cmd_vf_rate_limit_ratenum,
7913                 (void *)&cmd_vf_rate_limit_q_msk,
7914                 (void *)&cmd_vf_rate_limit_q_msk_val,
7915                 NULL,
7916         },
7917 };
7918
7919 /* *** ADD TUNNEL FILTER OF A PORT *** */
7920 struct cmd_tunnel_filter_result {
7921         cmdline_fixed_string_t cmd;
7922         cmdline_fixed_string_t what;
7923         portid_t port_id;
7924         struct ether_addr outer_mac;
7925         struct ether_addr inner_mac;
7926         cmdline_ipaddr_t ip_value;
7927         uint16_t inner_vlan;
7928         cmdline_fixed_string_t tunnel_type;
7929         cmdline_fixed_string_t filter_type;
7930         uint32_t tenant_id;
7931         uint16_t queue_num;
7932 };
7933
7934 static void
7935 cmd_tunnel_filter_parsed(void *parsed_result,
7936                           __attribute__((unused)) struct cmdline *cl,
7937                           __attribute__((unused)) void *data)
7938 {
7939         struct cmd_tunnel_filter_result *res = parsed_result;
7940         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7941         int ret = 0;
7942
7943         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7944
7945         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7946         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7947         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7948
7949         if (res->ip_value.family == AF_INET) {
7950                 tunnel_filter_conf.ip_addr.ipv4_addr =
7951                         res->ip_value.addr.ipv4.s_addr;
7952                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7953         } else {
7954                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7955                         &(res->ip_value.addr.ipv6),
7956                         sizeof(struct in6_addr));
7957                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7958         }
7959
7960         if (!strcmp(res->filter_type, "imac-ivlan"))
7961                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7962         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7963                 tunnel_filter_conf.filter_type =
7964                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7965         else if (!strcmp(res->filter_type, "imac-tenid"))
7966                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7967         else if (!strcmp(res->filter_type, "imac"))
7968                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7969         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7970                 tunnel_filter_conf.filter_type =
7971                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7972         else if (!strcmp(res->filter_type, "oip"))
7973                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7974         else if (!strcmp(res->filter_type, "iip"))
7975                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7976         else {
7977                 printf("The filter type is not supported");
7978                 return;
7979         }
7980
7981         if (!strcmp(res->tunnel_type, "vxlan"))
7982                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7983         else if (!strcmp(res->tunnel_type, "nvgre"))
7984                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7985         else if (!strcmp(res->tunnel_type, "ipingre"))
7986                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7987         else {
7988                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7989                 return;
7990         }
7991
7992         tunnel_filter_conf.tenant_id = res->tenant_id;
7993         tunnel_filter_conf.queue_id = res->queue_num;
7994         if (!strcmp(res->what, "add"))
7995                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7996                                         RTE_ETH_FILTER_TUNNEL,
7997                                         RTE_ETH_FILTER_ADD,
7998                                         &tunnel_filter_conf);
7999         else
8000                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8001                                         RTE_ETH_FILTER_TUNNEL,
8002                                         RTE_ETH_FILTER_DELETE,
8003                                         &tunnel_filter_conf);
8004         if (ret < 0)
8005                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8006                                 strerror(-ret));
8007
8008 }
8009 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8010         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8011         cmd, "tunnel_filter");
8012 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8013         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8014         what, "add#rm");
8015 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8016         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8017         port_id, UINT16);
8018 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8019         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8020         outer_mac);
8021 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8022         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8023         inner_mac);
8024 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8025         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8026         inner_vlan, UINT16);
8027 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8028         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8029         ip_value);
8030 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8031         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8032         tunnel_type, "vxlan#nvgre#ipingre");
8033
8034 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8035         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8036         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8037                 "imac#omac-imac-tenid");
8038 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8039         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8040         tenant_id, UINT32);
8041 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8042         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8043         queue_num, UINT16);
8044
8045 cmdline_parse_inst_t cmd_tunnel_filter = {
8046         .f = cmd_tunnel_filter_parsed,
8047         .data = (void *)0,
8048         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8049                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8050                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8051                 "<queue_id>: Add/Rm tunnel filter of a port",
8052         .tokens = {
8053                 (void *)&cmd_tunnel_filter_cmd,
8054                 (void *)&cmd_tunnel_filter_what,
8055                 (void *)&cmd_tunnel_filter_port_id,
8056                 (void *)&cmd_tunnel_filter_outer_mac,
8057                 (void *)&cmd_tunnel_filter_inner_mac,
8058                 (void *)&cmd_tunnel_filter_ip_value,
8059                 (void *)&cmd_tunnel_filter_innner_vlan,
8060                 (void *)&cmd_tunnel_filter_tunnel_type,
8061                 (void *)&cmd_tunnel_filter_filter_type,
8062                 (void *)&cmd_tunnel_filter_tenant_id,
8063                 (void *)&cmd_tunnel_filter_queue_num,
8064                 NULL,
8065         },
8066 };
8067
8068 /* *** CONFIGURE TUNNEL UDP PORT *** */
8069 struct cmd_tunnel_udp_config {
8070         cmdline_fixed_string_t cmd;
8071         cmdline_fixed_string_t what;
8072         uint16_t udp_port;
8073         portid_t port_id;
8074 };
8075
8076 static void
8077 cmd_tunnel_udp_config_parsed(void *parsed_result,
8078                           __attribute__((unused)) struct cmdline *cl,
8079                           __attribute__((unused)) void *data)
8080 {
8081         struct cmd_tunnel_udp_config *res = parsed_result;
8082         struct rte_eth_udp_tunnel tunnel_udp;
8083         int ret;
8084
8085         tunnel_udp.udp_port = res->udp_port;
8086
8087         if (!strcmp(res->cmd, "rx_vxlan_port"))
8088                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8089
8090         if (!strcmp(res->what, "add"))
8091                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8092                                                       &tunnel_udp);
8093         else
8094                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8095                                                          &tunnel_udp);
8096
8097         if (ret < 0)
8098                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8099 }
8100
8101 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8102         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8103                                 cmd, "rx_vxlan_port");
8104 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8105         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8106                                 what, "add#rm");
8107 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8108         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8109                                 udp_port, UINT16);
8110 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8111         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8112                                 port_id, UINT16);
8113
8114 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8115         .f = cmd_tunnel_udp_config_parsed,
8116         .data = (void *)0,
8117         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8118                 "Add/Remove a tunneling UDP port filter",
8119         .tokens = {
8120                 (void *)&cmd_tunnel_udp_config_cmd,
8121                 (void *)&cmd_tunnel_udp_config_what,
8122                 (void *)&cmd_tunnel_udp_config_udp_port,
8123                 (void *)&cmd_tunnel_udp_config_port_id,
8124                 NULL,
8125         },
8126 };
8127
8128 /* *** GLOBAL CONFIG *** */
8129 struct cmd_global_config_result {
8130         cmdline_fixed_string_t cmd;
8131         portid_t port_id;
8132         cmdline_fixed_string_t cfg_type;
8133         uint8_t len;
8134 };
8135
8136 static void
8137 cmd_global_config_parsed(void *parsed_result,
8138                          __attribute__((unused)) struct cmdline *cl,
8139                          __attribute__((unused)) void *data)
8140 {
8141         struct cmd_global_config_result *res = parsed_result;
8142         struct rte_eth_global_cfg conf;
8143         int ret;
8144
8145         memset(&conf, 0, sizeof(conf));
8146         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8147         conf.cfg.gre_key_len = res->len;
8148         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8149                                       RTE_ETH_FILTER_SET, &conf);
8150         if (ret != 0)
8151                 printf("Global config error\n");
8152 }
8153
8154 cmdline_parse_token_string_t cmd_global_config_cmd =
8155         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8156                 "global_config");
8157 cmdline_parse_token_num_t cmd_global_config_port_id =
8158         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8159                                UINT16);
8160 cmdline_parse_token_string_t cmd_global_config_type =
8161         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8162                 cfg_type, "gre-key-len");
8163 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8164         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8165                 len, UINT8);
8166
8167 cmdline_parse_inst_t cmd_global_config = {
8168         .f = cmd_global_config_parsed,
8169         .data = (void *)NULL,
8170         .help_str = "global_config <port_id> gre-key-len <key_len>",
8171         .tokens = {
8172                 (void *)&cmd_global_config_cmd,
8173                 (void *)&cmd_global_config_port_id,
8174                 (void *)&cmd_global_config_type,
8175                 (void *)&cmd_global_config_gre_key_len,
8176                 NULL,
8177         },
8178 };
8179
8180 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8181 struct cmd_set_mirror_mask_result {
8182         cmdline_fixed_string_t set;
8183         cmdline_fixed_string_t port;
8184         portid_t port_id;
8185         cmdline_fixed_string_t mirror;
8186         uint8_t rule_id;
8187         cmdline_fixed_string_t what;
8188         cmdline_fixed_string_t value;
8189         cmdline_fixed_string_t dstpool;
8190         uint8_t dstpool_id;
8191         cmdline_fixed_string_t on;
8192 };
8193
8194 cmdline_parse_token_string_t cmd_mirror_mask_set =
8195         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8196                                 set, "set");
8197 cmdline_parse_token_string_t cmd_mirror_mask_port =
8198         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8199                                 port, "port");
8200 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8201         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8202                                 port_id, UINT16);
8203 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8205                                 mirror, "mirror-rule");
8206 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8207         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8208                                 rule_id, UINT8);
8209 cmdline_parse_token_string_t cmd_mirror_mask_what =
8210         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8211                                 what, "pool-mirror-up#pool-mirror-down"
8212                                       "#vlan-mirror");
8213 cmdline_parse_token_string_t cmd_mirror_mask_value =
8214         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8215                                 value, NULL);
8216 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8217         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8218                                 dstpool, "dst-pool");
8219 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8220         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8221                                 dstpool_id, UINT8);
8222 cmdline_parse_token_string_t cmd_mirror_mask_on =
8223         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8224                                 on, "on#off");
8225
8226 static void
8227 cmd_set_mirror_mask_parsed(void *parsed_result,
8228                        __attribute__((unused)) struct cmdline *cl,
8229                        __attribute__((unused)) void *data)
8230 {
8231         int ret,nb_item,i;
8232         struct cmd_set_mirror_mask_result *res = parsed_result;
8233         struct rte_eth_mirror_conf mr_conf;
8234
8235         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8236
8237         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8238
8239         mr_conf.dst_pool = res->dstpool_id;
8240
8241         if (!strcmp(res->what, "pool-mirror-up")) {
8242                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8243                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8244         } else if (!strcmp(res->what, "pool-mirror-down")) {
8245                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8246                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8247         } else if (!strcmp(res->what, "vlan-mirror")) {
8248                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8249                 nb_item = parse_item_list(res->value, "vlan",
8250                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8251                 if (nb_item <= 0)
8252                         return;
8253
8254                 for (i = 0; i < nb_item; i++) {
8255                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8256                                 printf("Invalid vlan_id: must be < 4096\n");
8257                                 return;
8258                         }
8259
8260                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8261                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8262                 }
8263         }
8264
8265         if (!strcmp(res->on, "on"))
8266                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8267                                                 res->rule_id, 1);
8268         else
8269                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8270                                                 res->rule_id, 0);
8271         if (ret < 0)
8272                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8273 }
8274
8275 cmdline_parse_inst_t cmd_set_mirror_mask = {
8276                 .f = cmd_set_mirror_mask_parsed,
8277                 .data = NULL,
8278                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8279                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8280                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8281                 .tokens = {
8282                         (void *)&cmd_mirror_mask_set,
8283                         (void *)&cmd_mirror_mask_port,
8284                         (void *)&cmd_mirror_mask_portid,
8285                         (void *)&cmd_mirror_mask_mirror,
8286                         (void *)&cmd_mirror_mask_ruleid,
8287                         (void *)&cmd_mirror_mask_what,
8288                         (void *)&cmd_mirror_mask_value,
8289                         (void *)&cmd_mirror_mask_dstpool,
8290                         (void *)&cmd_mirror_mask_poolid,
8291                         (void *)&cmd_mirror_mask_on,
8292                         NULL,
8293                 },
8294 };
8295
8296 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8297 struct cmd_set_mirror_link_result {
8298         cmdline_fixed_string_t set;
8299         cmdline_fixed_string_t port;
8300         portid_t port_id;
8301         cmdline_fixed_string_t mirror;
8302         uint8_t rule_id;
8303         cmdline_fixed_string_t what;
8304         cmdline_fixed_string_t dstpool;
8305         uint8_t dstpool_id;
8306         cmdline_fixed_string_t on;
8307 };
8308
8309 cmdline_parse_token_string_t cmd_mirror_link_set =
8310         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8311                                  set, "set");
8312 cmdline_parse_token_string_t cmd_mirror_link_port =
8313         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8314                                 port, "port");
8315 cmdline_parse_token_num_t cmd_mirror_link_portid =
8316         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8317                                 port_id, UINT16);
8318 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8319         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8320                                 mirror, "mirror-rule");
8321 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8322         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8323                             rule_id, UINT8);
8324 cmdline_parse_token_string_t cmd_mirror_link_what =
8325         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8326                                 what, "uplink-mirror#downlink-mirror");
8327 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8328         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8329                                 dstpool, "dst-pool");
8330 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8331         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8332                                 dstpool_id, UINT8);
8333 cmdline_parse_token_string_t cmd_mirror_link_on =
8334         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8335                                 on, "on#off");
8336
8337 static void
8338 cmd_set_mirror_link_parsed(void *parsed_result,
8339                        __attribute__((unused)) struct cmdline *cl,
8340                        __attribute__((unused)) void *data)
8341 {
8342         int ret;
8343         struct cmd_set_mirror_link_result *res = parsed_result;
8344         struct rte_eth_mirror_conf mr_conf;
8345
8346         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8347         if (!strcmp(res->what, "uplink-mirror"))
8348                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8349         else
8350                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8351
8352         mr_conf.dst_pool = res->dstpool_id;
8353
8354         if (!strcmp(res->on, "on"))
8355                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8356                                                 res->rule_id, 1);
8357         else
8358                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8359                                                 res->rule_id, 0);
8360
8361         /* check the return value and print it if is < 0 */
8362         if (ret < 0)
8363                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8364
8365 }
8366
8367 cmdline_parse_inst_t cmd_set_mirror_link = {
8368                 .f = cmd_set_mirror_link_parsed,
8369                 .data = NULL,
8370                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8371                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8372                 .tokens = {
8373                         (void *)&cmd_mirror_link_set,
8374                         (void *)&cmd_mirror_link_port,
8375                         (void *)&cmd_mirror_link_portid,
8376                         (void *)&cmd_mirror_link_mirror,
8377                         (void *)&cmd_mirror_link_ruleid,
8378                         (void *)&cmd_mirror_link_what,
8379                         (void *)&cmd_mirror_link_dstpool,
8380                         (void *)&cmd_mirror_link_poolid,
8381                         (void *)&cmd_mirror_link_on,
8382                         NULL,
8383                 },
8384 };
8385
8386 /* *** RESET VM MIRROR RULE *** */
8387 struct cmd_rm_mirror_rule_result {
8388         cmdline_fixed_string_t reset;
8389         cmdline_fixed_string_t port;
8390         portid_t port_id;
8391         cmdline_fixed_string_t mirror;
8392         uint8_t rule_id;
8393 };
8394
8395 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8396         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8397                                  reset, "reset");
8398 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8399         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8400                                 port, "port");
8401 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8402         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8403                                 port_id, UINT16);
8404 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8405         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8406                                 mirror, "mirror-rule");
8407 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8408         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8409                                 rule_id, UINT8);
8410
8411 static void
8412 cmd_reset_mirror_rule_parsed(void *parsed_result,
8413                        __attribute__((unused)) struct cmdline *cl,
8414                        __attribute__((unused)) void *data)
8415 {
8416         int ret;
8417         struct cmd_set_mirror_link_result *res = parsed_result;
8418         /* check rule_id */
8419         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8420         if(ret < 0)
8421                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8422 }
8423
8424 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8425                 .f = cmd_reset_mirror_rule_parsed,
8426                 .data = NULL,
8427                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8428                 .tokens = {
8429                         (void *)&cmd_rm_mirror_rule_reset,
8430                         (void *)&cmd_rm_mirror_rule_port,
8431                         (void *)&cmd_rm_mirror_rule_portid,
8432                         (void *)&cmd_rm_mirror_rule_mirror,
8433                         (void *)&cmd_rm_mirror_rule_ruleid,
8434                         NULL,
8435                 },
8436 };
8437
8438 /* ******************************************************************************** */
8439
8440 struct cmd_dump_result {
8441         cmdline_fixed_string_t dump;
8442 };
8443
8444 static void
8445 dump_struct_sizes(void)
8446 {
8447 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8448         DUMP_SIZE(struct rte_mbuf);
8449         DUMP_SIZE(struct rte_mempool);
8450         DUMP_SIZE(struct rte_ring);
8451 #undef DUMP_SIZE
8452 }
8453
8454 static void cmd_dump_parsed(void *parsed_result,
8455                             __attribute__((unused)) struct cmdline *cl,
8456                             __attribute__((unused)) void *data)
8457 {
8458         struct cmd_dump_result *res = parsed_result;
8459
8460         if (!strcmp(res->dump, "dump_physmem"))
8461                 rte_dump_physmem_layout(stdout);
8462         else if (!strcmp(res->dump, "dump_memzone"))
8463                 rte_memzone_dump(stdout);
8464         else if (!strcmp(res->dump, "dump_struct_sizes"))
8465                 dump_struct_sizes();
8466         else if (!strcmp(res->dump, "dump_ring"))
8467                 rte_ring_list_dump(stdout);
8468         else if (!strcmp(res->dump, "dump_mempool"))
8469                 rte_mempool_list_dump(stdout);
8470         else if (!strcmp(res->dump, "dump_devargs"))
8471                 rte_eal_devargs_dump(stdout);
8472         else if (!strcmp(res->dump, "dump_log_types"))
8473                 rte_log_dump(stdout);
8474 }
8475
8476 cmdline_parse_token_string_t cmd_dump_dump =
8477         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8478                 "dump_physmem#"
8479                 "dump_memzone#"
8480                 "dump_struct_sizes#"
8481                 "dump_ring#"
8482                 "dump_mempool#"
8483                 "dump_devargs#"
8484                 "dump_log_types");
8485
8486 cmdline_parse_inst_t cmd_dump = {
8487         .f = cmd_dump_parsed,  /* function to call */
8488         .data = NULL,      /* 2nd arg of func */
8489         .help_str = "Dump status",
8490         .tokens = {        /* token list, NULL terminated */
8491                 (void *)&cmd_dump_dump,
8492                 NULL,
8493         },
8494 };
8495
8496 /* ******************************************************************************** */
8497
8498 struct cmd_dump_one_result {
8499         cmdline_fixed_string_t dump;
8500         cmdline_fixed_string_t name;
8501 };
8502
8503 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8504                                 __attribute__((unused)) void *data)
8505 {
8506         struct cmd_dump_one_result *res = parsed_result;
8507
8508         if (!strcmp(res->dump, "dump_ring")) {
8509                 struct rte_ring *r;
8510                 r = rte_ring_lookup(res->name);
8511                 if (r == NULL) {
8512                         cmdline_printf(cl, "Cannot find ring\n");
8513                         return;
8514                 }
8515                 rte_ring_dump(stdout, r);
8516         } else if (!strcmp(res->dump, "dump_mempool")) {
8517                 struct rte_mempool *mp;
8518                 mp = rte_mempool_lookup(res->name);
8519                 if (mp == NULL) {
8520                         cmdline_printf(cl, "Cannot find mempool\n");
8521                         return;
8522                 }
8523                 rte_mempool_dump(stdout, mp);
8524         }
8525 }
8526
8527 cmdline_parse_token_string_t cmd_dump_one_dump =
8528         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8529                                  "dump_ring#dump_mempool");
8530
8531 cmdline_parse_token_string_t cmd_dump_one_name =
8532         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8533
8534 cmdline_parse_inst_t cmd_dump_one = {
8535         .f = cmd_dump_one_parsed,  /* function to call */
8536         .data = NULL,      /* 2nd arg of func */
8537         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8538         .tokens = {        /* token list, NULL terminated */
8539                 (void *)&cmd_dump_one_dump,
8540                 (void *)&cmd_dump_one_name,
8541                 NULL,
8542         },
8543 };
8544
8545 /* *** Add/Del syn filter *** */
8546 struct cmd_syn_filter_result {
8547         cmdline_fixed_string_t filter;
8548         portid_t port_id;
8549         cmdline_fixed_string_t ops;
8550         cmdline_fixed_string_t priority;
8551         cmdline_fixed_string_t high;
8552         cmdline_fixed_string_t queue;
8553         uint16_t queue_id;
8554 };
8555
8556 static void
8557 cmd_syn_filter_parsed(void *parsed_result,
8558                         __attribute__((unused)) struct cmdline *cl,
8559                         __attribute__((unused)) void *data)
8560 {
8561         struct cmd_syn_filter_result *res = parsed_result;
8562         struct rte_eth_syn_filter syn_filter;
8563         int ret = 0;
8564
8565         ret = rte_eth_dev_filter_supported(res->port_id,
8566                                         RTE_ETH_FILTER_SYN);
8567         if (ret < 0) {
8568                 printf("syn filter is not supported on port %u.\n",
8569                                 res->port_id);
8570                 return;
8571         }
8572
8573         memset(&syn_filter, 0, sizeof(syn_filter));
8574
8575         if (!strcmp(res->ops, "add")) {
8576                 if (!strcmp(res->high, "high"))
8577                         syn_filter.hig_pri = 1;
8578                 else
8579                         syn_filter.hig_pri = 0;
8580
8581                 syn_filter.queue = res->queue_id;
8582                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8583                                                 RTE_ETH_FILTER_SYN,
8584                                                 RTE_ETH_FILTER_ADD,
8585                                                 &syn_filter);
8586         } else
8587                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8588                                                 RTE_ETH_FILTER_SYN,
8589                                                 RTE_ETH_FILTER_DELETE,
8590                                                 &syn_filter);
8591
8592         if (ret < 0)
8593                 printf("syn filter programming error: (%s)\n",
8594                                 strerror(-ret));
8595 }
8596
8597 cmdline_parse_token_string_t cmd_syn_filter_filter =
8598         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8599         filter, "syn_filter");
8600 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8601         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8602         port_id, UINT16);
8603 cmdline_parse_token_string_t cmd_syn_filter_ops =
8604         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8605         ops, "add#del");
8606 cmdline_parse_token_string_t cmd_syn_filter_priority =
8607         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8608                                 priority, "priority");
8609 cmdline_parse_token_string_t cmd_syn_filter_high =
8610         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8611                                 high, "high#low");
8612 cmdline_parse_token_string_t cmd_syn_filter_queue =
8613         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8614                                 queue, "queue");
8615 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8616         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8617                                 queue_id, UINT16);
8618
8619 cmdline_parse_inst_t cmd_syn_filter = {
8620         .f = cmd_syn_filter_parsed,
8621         .data = NULL,
8622         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8623                 "<queue_id>: Add/Delete syn filter",
8624         .tokens = {
8625                 (void *)&cmd_syn_filter_filter,
8626                 (void *)&cmd_syn_filter_port_id,
8627                 (void *)&cmd_syn_filter_ops,
8628                 (void *)&cmd_syn_filter_priority,
8629                 (void *)&cmd_syn_filter_high,
8630                 (void *)&cmd_syn_filter_queue,
8631                 (void *)&cmd_syn_filter_queue_id,
8632                 NULL,
8633         },
8634 };
8635
8636 /* *** queue region set *** */
8637 struct cmd_queue_region_result {
8638         cmdline_fixed_string_t set;
8639         cmdline_fixed_string_t port;
8640         portid_t port_id;
8641         cmdline_fixed_string_t cmd;
8642         cmdline_fixed_string_t region;
8643         uint8_t  region_id;
8644         cmdline_fixed_string_t queue_start_index;
8645         uint8_t  queue_id;
8646         cmdline_fixed_string_t queue_num;
8647         uint8_t  queue_num_value;
8648 };
8649
8650 static void
8651 cmd_queue_region_parsed(void *parsed_result,
8652                         __attribute__((unused)) struct cmdline *cl,
8653                         __attribute__((unused)) void *data)
8654 {
8655         struct cmd_queue_region_result *res = parsed_result;
8656         int ret = -ENOTSUP;
8657 #ifdef RTE_LIBRTE_I40E_PMD
8658         struct rte_pmd_i40e_queue_region_conf region_conf;
8659         enum rte_pmd_i40e_queue_region_op op_type;
8660 #endif
8661
8662         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8663                 return;
8664
8665 #ifdef RTE_LIBRTE_I40E_PMD
8666         memset(&region_conf, 0, sizeof(region_conf));
8667         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8668         region_conf.region_id = res->region_id;
8669         region_conf.queue_num = res->queue_num_value;
8670         region_conf.queue_start_index = res->queue_id;
8671
8672         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8673                                 op_type, &region_conf);
8674 #endif
8675
8676         switch (ret) {
8677         case 0:
8678                 break;
8679         case -ENOTSUP:
8680                 printf("function not implemented or supported\n");
8681                 break;
8682         default:
8683                 printf("queue region config error: (%s)\n", strerror(-ret));
8684         }
8685 }
8686
8687 cmdline_parse_token_string_t cmd_queue_region_set =
8688 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8689                 set, "set");
8690 cmdline_parse_token_string_t cmd_queue_region_port =
8691         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8692 cmdline_parse_token_num_t cmd_queue_region_port_id =
8693         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8694                                 port_id, UINT16);
8695 cmdline_parse_token_string_t cmd_queue_region_cmd =
8696         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8697                                  cmd, "queue-region");
8698 cmdline_parse_token_string_t cmd_queue_region_id =
8699         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8700                                 region, "region_id");
8701 cmdline_parse_token_num_t cmd_queue_region_index =
8702         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8703                                 region_id, UINT8);
8704 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8705         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8706                                 queue_start_index, "queue_start_index");
8707 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8708         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8709                                 queue_id, UINT8);
8710 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8711         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8712                                 queue_num, "queue_num");
8713 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8714         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8715                                 queue_num_value, UINT8);
8716
8717 cmdline_parse_inst_t cmd_queue_region = {
8718         .f = cmd_queue_region_parsed,
8719         .data = NULL,
8720         .help_str = "set port <port_id> queue-region region_id <value> "
8721                 "queue_start_index <value> queue_num <value>: Set a queue region",
8722         .tokens = {
8723                 (void *)&cmd_queue_region_set,
8724                 (void *)&cmd_queue_region_port,
8725                 (void *)&cmd_queue_region_port_id,
8726                 (void *)&cmd_queue_region_cmd,
8727                 (void *)&cmd_queue_region_id,
8728                 (void *)&cmd_queue_region_index,
8729                 (void *)&cmd_queue_region_queue_start_index,
8730                 (void *)&cmd_queue_region_queue_id,
8731                 (void *)&cmd_queue_region_queue_num,
8732                 (void *)&cmd_queue_region_queue_num_value,
8733                 NULL,
8734         },
8735 };
8736
8737 /* *** queue region and flowtype set *** */
8738 struct cmd_region_flowtype_result {
8739         cmdline_fixed_string_t set;
8740         cmdline_fixed_string_t port;
8741         portid_t port_id;
8742         cmdline_fixed_string_t cmd;
8743         cmdline_fixed_string_t region;
8744         uint8_t  region_id;
8745         cmdline_fixed_string_t flowtype;
8746         uint8_t  flowtype_id;
8747 };
8748
8749 static void
8750 cmd_region_flowtype_parsed(void *parsed_result,
8751                         __attribute__((unused)) struct cmdline *cl,
8752                         __attribute__((unused)) void *data)
8753 {
8754         struct cmd_region_flowtype_result *res = parsed_result;
8755         int ret = -ENOTSUP;
8756 #ifdef RTE_LIBRTE_I40E_PMD
8757         struct rte_pmd_i40e_queue_region_conf region_conf;
8758         enum rte_pmd_i40e_queue_region_op op_type;
8759 #endif
8760
8761         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8762                 return;
8763
8764 #ifdef RTE_LIBRTE_I40E_PMD
8765         memset(&region_conf, 0, sizeof(region_conf));
8766
8767         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8768         region_conf.region_id = res->region_id;
8769         region_conf.hw_flowtype = res->flowtype_id;
8770
8771         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8772                         op_type, &region_conf);
8773 #endif
8774
8775         switch (ret) {
8776         case 0:
8777                 break;
8778         case -ENOTSUP:
8779                 printf("function not implemented or supported\n");
8780                 break;
8781         default:
8782                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8783         }
8784 }
8785
8786 cmdline_parse_token_string_t cmd_region_flowtype_set =
8787 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8788                                 set, "set");
8789 cmdline_parse_token_string_t cmd_region_flowtype_port =
8790         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8791                                 port, "port");
8792 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8793         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8794                                 port_id, UINT16);
8795 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8796         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8797                                 cmd, "queue-region");
8798 cmdline_parse_token_string_t cmd_region_flowtype_index =
8799         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8800                                 region, "region_id");
8801 cmdline_parse_token_num_t cmd_region_flowtype_id =
8802         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8803                                 region_id, UINT8);
8804 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8805         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8806                                 flowtype, "flowtype");
8807 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8808         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8809                                 flowtype_id, UINT8);
8810 cmdline_parse_inst_t cmd_region_flowtype = {
8811         .f = cmd_region_flowtype_parsed,
8812         .data = NULL,
8813         .help_str = "set port <port_id> queue-region region_id <value> "
8814                 "flowtype <value>: Set a flowtype region index",
8815         .tokens = {
8816                 (void *)&cmd_region_flowtype_set,
8817                 (void *)&cmd_region_flowtype_port,
8818                 (void *)&cmd_region_flowtype_port_index,
8819                 (void *)&cmd_region_flowtype_cmd,
8820                 (void *)&cmd_region_flowtype_index,
8821                 (void *)&cmd_region_flowtype_id,
8822                 (void *)&cmd_region_flowtype_flow_index,
8823                 (void *)&cmd_region_flowtype_flow_id,
8824                 NULL,
8825         },
8826 };
8827
8828 /* *** User Priority (UP) to queue region (region_id) set *** */
8829 struct cmd_user_priority_region_result {
8830         cmdline_fixed_string_t set;
8831         cmdline_fixed_string_t port;
8832         portid_t port_id;
8833         cmdline_fixed_string_t cmd;
8834         cmdline_fixed_string_t user_priority;
8835         uint8_t  user_priority_id;
8836         cmdline_fixed_string_t region;
8837         uint8_t  region_id;
8838 };
8839
8840 static void
8841 cmd_user_priority_region_parsed(void *parsed_result,
8842                         __attribute__((unused)) struct cmdline *cl,
8843                         __attribute__((unused)) void *data)
8844 {
8845         struct cmd_user_priority_region_result *res = parsed_result;
8846         int ret = -ENOTSUP;
8847 #ifdef RTE_LIBRTE_I40E_PMD
8848         struct rte_pmd_i40e_queue_region_conf region_conf;
8849         enum rte_pmd_i40e_queue_region_op op_type;
8850 #endif
8851
8852         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8853                 return;
8854
8855 #ifdef RTE_LIBRTE_I40E_PMD
8856         memset(&region_conf, 0, sizeof(region_conf));
8857         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8858         region_conf.user_priority = res->user_priority_id;
8859         region_conf.region_id = res->region_id;
8860
8861         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8862                                 op_type, &region_conf);
8863 #endif
8864
8865         switch (ret) {
8866         case 0:
8867                 break;
8868         case -ENOTSUP:
8869                 printf("function not implemented or supported\n");
8870                 break;
8871         default:
8872                 printf("user_priority region config error: (%s)\n",
8873                                 strerror(-ret));
8874         }
8875 }
8876
8877 cmdline_parse_token_string_t cmd_user_priority_region_set =
8878         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8879                                 set, "set");
8880 cmdline_parse_token_string_t cmd_user_priority_region_port =
8881         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8882                                 port, "port");
8883 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8884         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8885                                 port_id, UINT16);
8886 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8887         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8888                                 cmd, "queue-region");
8889 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8890         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8891                                 user_priority, "UP");
8892 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8893         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8894                                 user_priority_id, UINT8);
8895 cmdline_parse_token_string_t cmd_user_priority_region_region =
8896         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8897                                 region, "region_id");
8898 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8899         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8900                                 region_id, UINT8);
8901
8902 cmdline_parse_inst_t cmd_user_priority_region = {
8903         .f = cmd_user_priority_region_parsed,
8904         .data = NULL,
8905         .help_str = "set port <port_id> queue-region UP <value> "
8906                 "region_id <value>: Set the mapping of User Priority (UP) "
8907                 "to queue region (region_id) ",
8908         .tokens = {
8909                 (void *)&cmd_user_priority_region_set,
8910                 (void *)&cmd_user_priority_region_port,
8911                 (void *)&cmd_user_priority_region_port_index,
8912                 (void *)&cmd_user_priority_region_cmd,
8913                 (void *)&cmd_user_priority_region_UP,
8914                 (void *)&cmd_user_priority_region_UP_id,
8915                 (void *)&cmd_user_priority_region_region,
8916                 (void *)&cmd_user_priority_region_region_id,
8917                 NULL,
8918         },
8919 };
8920
8921 /* *** flush all queue region related configuration *** */
8922 struct cmd_flush_queue_region_result {
8923         cmdline_fixed_string_t set;
8924         cmdline_fixed_string_t port;
8925         portid_t port_id;
8926         cmdline_fixed_string_t cmd;
8927         cmdline_fixed_string_t flush;
8928         cmdline_fixed_string_t what;
8929 };
8930
8931 static void
8932 cmd_flush_queue_region_parsed(void *parsed_result,
8933                         __attribute__((unused)) struct cmdline *cl,
8934                         __attribute__((unused)) void *data)
8935 {
8936         struct cmd_flush_queue_region_result *res = parsed_result;
8937         int ret = -ENOTSUP;
8938 #ifdef RTE_LIBRTE_I40E_PMD
8939         struct rte_pmd_i40e_queue_region_conf region_conf;
8940         enum rte_pmd_i40e_queue_region_op op_type;
8941 #endif
8942
8943         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8944                 return;
8945
8946 #ifdef RTE_LIBRTE_I40E_PMD
8947         memset(&region_conf, 0, sizeof(region_conf));
8948
8949         if (strcmp(res->what, "on") == 0)
8950                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8951         else
8952                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8953
8954         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8955                                 op_type, &region_conf);
8956 #endif
8957
8958         switch (ret) {
8959         case 0:
8960                 break;
8961         case -ENOTSUP:
8962                 printf("function not implemented or supported\n");
8963                 break;
8964         default:
8965                 printf("queue region config flush error: (%s)\n",
8966                                 strerror(-ret));
8967         }
8968 }
8969
8970 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8971         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8972                                 set, "set");
8973 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8974         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8975                                 port, "port");
8976 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8977         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8978                                 port_id, UINT16);
8979 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8980         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8981                                 cmd, "queue-region");
8982 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8983         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8984                                 flush, "flush");
8985 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8986         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8987                                 what, "on#off");
8988
8989 cmdline_parse_inst_t cmd_flush_queue_region = {
8990         .f = cmd_flush_queue_region_parsed,
8991         .data = NULL,
8992         .help_str = "set port <port_id> queue-region flush on|off"
8993                 ": flush all queue region related configuration",
8994         .tokens = {
8995                 (void *)&cmd_flush_queue_region_set,
8996                 (void *)&cmd_flush_queue_region_port,
8997                 (void *)&cmd_flush_queue_region_port_index,
8998                 (void *)&cmd_flush_queue_region_cmd,
8999                 (void *)&cmd_flush_queue_region_flush,
9000                 (void *)&cmd_flush_queue_region_what,
9001                 NULL,
9002         },
9003 };
9004
9005 /* *** get all queue region related configuration info *** */
9006 struct cmd_show_queue_region_info {
9007         cmdline_fixed_string_t show;
9008         cmdline_fixed_string_t port;
9009         portid_t port_id;
9010         cmdline_fixed_string_t cmd;
9011 };
9012
9013 static void
9014 cmd_show_queue_region_info_parsed(void *parsed_result,
9015                         __attribute__((unused)) struct cmdline *cl,
9016                         __attribute__((unused)) void *data)
9017 {
9018         struct cmd_show_queue_region_info *res = parsed_result;
9019         int ret = -ENOTSUP;
9020 #ifdef RTE_LIBRTE_I40E_PMD
9021         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9022         enum rte_pmd_i40e_queue_region_op op_type;
9023 #endif
9024
9025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9026                 return;
9027
9028 #ifdef RTE_LIBRTE_I40E_PMD
9029         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9030
9031         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9032
9033         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9034                                         op_type, &rte_pmd_regions);
9035
9036         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9037 #endif
9038
9039         switch (ret) {
9040         case 0:
9041                 break;
9042         case -ENOTSUP:
9043                 printf("function not implemented or supported\n");
9044                 break;
9045         default:
9046                 printf("queue region config info show error: (%s)\n",
9047                                 strerror(-ret));
9048         }
9049 }
9050
9051 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9052 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9053                                 show, "show");
9054 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9055         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9056                                 port, "port");
9057 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9058         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9059                                 port_id, UINT16);
9060 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9061         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9062                                 cmd, "queue-region");
9063
9064 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9065         .f = cmd_show_queue_region_info_parsed,
9066         .data = NULL,
9067         .help_str = "show port <port_id> queue-region"
9068                 ": show all queue region related configuration info",
9069         .tokens = {
9070                 (void *)&cmd_show_queue_region_info_get,
9071                 (void *)&cmd_show_queue_region_info_port,
9072                 (void *)&cmd_show_queue_region_info_port_index,
9073                 (void *)&cmd_show_queue_region_info_cmd,
9074                 NULL,
9075         },
9076 };
9077
9078 /* *** ADD/REMOVE A 2tuple FILTER *** */
9079 struct cmd_2tuple_filter_result {
9080         cmdline_fixed_string_t filter;
9081         portid_t port_id;
9082         cmdline_fixed_string_t ops;
9083         cmdline_fixed_string_t dst_port;
9084         uint16_t dst_port_value;
9085         cmdline_fixed_string_t protocol;
9086         uint8_t protocol_value;
9087         cmdline_fixed_string_t mask;
9088         uint8_t  mask_value;
9089         cmdline_fixed_string_t tcp_flags;
9090         uint8_t tcp_flags_value;
9091         cmdline_fixed_string_t priority;
9092         uint8_t  priority_value;
9093         cmdline_fixed_string_t queue;
9094         uint16_t  queue_id;
9095 };
9096
9097 static void
9098 cmd_2tuple_filter_parsed(void *parsed_result,
9099                         __attribute__((unused)) struct cmdline *cl,
9100                         __attribute__((unused)) void *data)
9101 {
9102         struct rte_eth_ntuple_filter filter;
9103         struct cmd_2tuple_filter_result *res = parsed_result;
9104         int ret = 0;
9105
9106         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9107         if (ret < 0) {
9108                 printf("ntuple filter is not supported on port %u.\n",
9109                         res->port_id);
9110                 return;
9111         }
9112
9113         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9114
9115         filter.flags = RTE_2TUPLE_FLAGS;
9116         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9117         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9118         filter.proto = res->protocol_value;
9119         filter.priority = res->priority_value;
9120         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9121                 printf("nonzero tcp_flags is only meaningful"
9122                         " when protocol is TCP.\n");
9123                 return;
9124         }
9125         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9126                 printf("invalid TCP flags.\n");
9127                 return;
9128         }
9129
9130         if (res->tcp_flags_value != 0) {
9131                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9132                 filter.tcp_flags = res->tcp_flags_value;
9133         }
9134
9135         /* need convert to big endian. */
9136         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9137         filter.queue = res->queue_id;
9138
9139         if (!strcmp(res->ops, "add"))
9140                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9141                                 RTE_ETH_FILTER_NTUPLE,
9142                                 RTE_ETH_FILTER_ADD,
9143                                 &filter);
9144         else
9145                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9146                                 RTE_ETH_FILTER_NTUPLE,
9147                                 RTE_ETH_FILTER_DELETE,
9148                                 &filter);
9149         if (ret < 0)
9150                 printf("2tuple filter programming error: (%s)\n",
9151                         strerror(-ret));
9152
9153 }
9154
9155 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9156         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9157                                  filter, "2tuple_filter");
9158 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9159         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9160                                 port_id, UINT16);
9161 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9162         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9163                                  ops, "add#del");
9164 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9165         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9166                                 dst_port, "dst_port");
9167 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9168         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9169                                 dst_port_value, UINT16);
9170 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9171         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9172                                 protocol, "protocol");
9173 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9174         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9175                                 protocol_value, UINT8);
9176 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9177         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9178                                 mask, "mask");
9179 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9180         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9181                                 mask_value, INT8);
9182 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9183         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9184                                 tcp_flags, "tcp_flags");
9185 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9186         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9187                                 tcp_flags_value, UINT8);
9188 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9189         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9190                                 priority, "priority");
9191 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9192         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9193                                 priority_value, UINT8);
9194 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9195         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9196                                 queue, "queue");
9197 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9198         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9199                                 queue_id, UINT16);
9200
9201 cmdline_parse_inst_t cmd_2tuple_filter = {
9202         .f = cmd_2tuple_filter_parsed,
9203         .data = NULL,
9204         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9205                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9206                 "<queue_id>: Add a 2tuple filter",
9207         .tokens = {
9208                 (void *)&cmd_2tuple_filter_filter,
9209                 (void *)&cmd_2tuple_filter_port_id,
9210                 (void *)&cmd_2tuple_filter_ops,
9211                 (void *)&cmd_2tuple_filter_dst_port,
9212                 (void *)&cmd_2tuple_filter_dst_port_value,
9213                 (void *)&cmd_2tuple_filter_protocol,
9214                 (void *)&cmd_2tuple_filter_protocol_value,
9215                 (void *)&cmd_2tuple_filter_mask,
9216                 (void *)&cmd_2tuple_filter_mask_value,
9217                 (void *)&cmd_2tuple_filter_tcp_flags,
9218                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9219                 (void *)&cmd_2tuple_filter_priority,
9220                 (void *)&cmd_2tuple_filter_priority_value,
9221                 (void *)&cmd_2tuple_filter_queue,
9222                 (void *)&cmd_2tuple_filter_queue_id,
9223                 NULL,
9224         },
9225 };
9226
9227 /* *** ADD/REMOVE A 5tuple FILTER *** */
9228 struct cmd_5tuple_filter_result {
9229         cmdline_fixed_string_t filter;
9230         portid_t port_id;
9231         cmdline_fixed_string_t ops;
9232         cmdline_fixed_string_t dst_ip;
9233         cmdline_ipaddr_t dst_ip_value;
9234         cmdline_fixed_string_t src_ip;
9235         cmdline_ipaddr_t src_ip_value;
9236         cmdline_fixed_string_t dst_port;
9237         uint16_t dst_port_value;
9238         cmdline_fixed_string_t src_port;
9239         uint16_t src_port_value;
9240         cmdline_fixed_string_t protocol;
9241         uint8_t protocol_value;
9242         cmdline_fixed_string_t mask;
9243         uint8_t  mask_value;
9244         cmdline_fixed_string_t tcp_flags;
9245         uint8_t tcp_flags_value;
9246         cmdline_fixed_string_t priority;
9247         uint8_t  priority_value;
9248         cmdline_fixed_string_t queue;
9249         uint16_t  queue_id;
9250 };
9251
9252 static void
9253 cmd_5tuple_filter_parsed(void *parsed_result,
9254                         __attribute__((unused)) struct cmdline *cl,
9255                         __attribute__((unused)) void *data)
9256 {
9257         struct rte_eth_ntuple_filter filter;
9258         struct cmd_5tuple_filter_result *res = parsed_result;
9259         int ret = 0;
9260
9261         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9262         if (ret < 0) {
9263                 printf("ntuple filter is not supported on port %u.\n",
9264                         res->port_id);
9265                 return;
9266         }
9267
9268         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9269
9270         filter.flags = RTE_5TUPLE_FLAGS;
9271         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9272         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9273         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9274         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9275         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9276         filter.proto = res->protocol_value;
9277         filter.priority = res->priority_value;
9278         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9279                 printf("nonzero tcp_flags is only meaningful"
9280                         " when protocol is TCP.\n");
9281                 return;
9282         }
9283         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9284                 printf("invalid TCP flags.\n");
9285                 return;
9286         }
9287
9288         if (res->tcp_flags_value != 0) {
9289                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9290                 filter.tcp_flags = res->tcp_flags_value;
9291         }
9292
9293         if (res->dst_ip_value.family == AF_INET)
9294                 /* no need to convert, already big endian. */
9295                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9296         else {
9297                 if (filter.dst_ip_mask == 0) {
9298                         printf("can not support ipv6 involved compare.\n");
9299                         return;
9300                 }
9301                 filter.dst_ip = 0;
9302         }
9303
9304         if (res->src_ip_value.family == AF_INET)
9305                 /* no need to convert, already big endian. */
9306                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9307         else {
9308                 if (filter.src_ip_mask == 0) {
9309                         printf("can not support ipv6 involved compare.\n");
9310                         return;
9311                 }
9312                 filter.src_ip = 0;
9313         }
9314         /* need convert to big endian. */
9315         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9316         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9317         filter.queue = res->queue_id;
9318
9319         if (!strcmp(res->ops, "add"))
9320                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9321                                 RTE_ETH_FILTER_NTUPLE,
9322                                 RTE_ETH_FILTER_ADD,
9323                                 &filter);
9324         else
9325                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9326                                 RTE_ETH_FILTER_NTUPLE,
9327                                 RTE_ETH_FILTER_DELETE,
9328                                 &filter);
9329         if (ret < 0)
9330                 printf("5tuple filter programming error: (%s)\n",
9331                         strerror(-ret));
9332 }
9333
9334 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9335         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9336                                  filter, "5tuple_filter");
9337 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9338         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9339                                 port_id, UINT16);
9340 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9341         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9342                                  ops, "add#del");
9343 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9344         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9345                                 dst_ip, "dst_ip");
9346 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9347         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9348                                 dst_ip_value);
9349 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9350         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9351                                 src_ip, "src_ip");
9352 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9353         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9354                                 src_ip_value);
9355 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9356         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9357                                 dst_port, "dst_port");
9358 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9359         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9360                                 dst_port_value, UINT16);
9361 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9362         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9363                                 src_port, "src_port");
9364 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9365         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9366                                 src_port_value, UINT16);
9367 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9368         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9369                                 protocol, "protocol");
9370 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9371         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9372                                 protocol_value, UINT8);
9373 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9374         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9375                                 mask, "mask");
9376 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9377         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9378                                 mask_value, INT8);
9379 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9380         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9381                                 tcp_flags, "tcp_flags");
9382 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9383         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9384                                 tcp_flags_value, UINT8);
9385 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9386         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9387                                 priority, "priority");
9388 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9389         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9390                                 priority_value, UINT8);
9391 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9392         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9393                                 queue, "queue");
9394 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9395         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9396                                 queue_id, UINT16);
9397
9398 cmdline_parse_inst_t cmd_5tuple_filter = {
9399         .f = cmd_5tuple_filter_parsed,
9400         .data = NULL,
9401         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9402                 "src_ip <value> dst_port <value> src_port <value> "
9403                 "protocol <value>  mask <value> tcp_flags <value> "
9404                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9405         .tokens = {
9406                 (void *)&cmd_5tuple_filter_filter,
9407                 (void *)&cmd_5tuple_filter_port_id,
9408                 (void *)&cmd_5tuple_filter_ops,
9409                 (void *)&cmd_5tuple_filter_dst_ip,
9410                 (void *)&cmd_5tuple_filter_dst_ip_value,
9411                 (void *)&cmd_5tuple_filter_src_ip,
9412                 (void *)&cmd_5tuple_filter_src_ip_value,
9413                 (void *)&cmd_5tuple_filter_dst_port,
9414                 (void *)&cmd_5tuple_filter_dst_port_value,
9415                 (void *)&cmd_5tuple_filter_src_port,
9416                 (void *)&cmd_5tuple_filter_src_port_value,
9417                 (void *)&cmd_5tuple_filter_protocol,
9418                 (void *)&cmd_5tuple_filter_protocol_value,
9419                 (void *)&cmd_5tuple_filter_mask,
9420                 (void *)&cmd_5tuple_filter_mask_value,
9421                 (void *)&cmd_5tuple_filter_tcp_flags,
9422                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9423                 (void *)&cmd_5tuple_filter_priority,
9424                 (void *)&cmd_5tuple_filter_priority_value,
9425                 (void *)&cmd_5tuple_filter_queue,
9426                 (void *)&cmd_5tuple_filter_queue_id,
9427                 NULL,
9428         },
9429 };
9430
9431 /* *** ADD/REMOVE A flex FILTER *** */
9432 struct cmd_flex_filter_result {
9433         cmdline_fixed_string_t filter;
9434         cmdline_fixed_string_t ops;
9435         portid_t port_id;
9436         cmdline_fixed_string_t len;
9437         uint8_t len_value;
9438         cmdline_fixed_string_t bytes;
9439         cmdline_fixed_string_t bytes_value;
9440         cmdline_fixed_string_t mask;
9441         cmdline_fixed_string_t mask_value;
9442         cmdline_fixed_string_t priority;
9443         uint8_t priority_value;
9444         cmdline_fixed_string_t queue;
9445         uint16_t queue_id;
9446 };
9447
9448 static int xdigit2val(unsigned char c)
9449 {
9450         int val;
9451         if (isdigit(c))
9452                 val = c - '0';
9453         else if (isupper(c))
9454                 val = c - 'A' + 10;
9455         else
9456                 val = c - 'a' + 10;
9457         return val;
9458 }
9459
9460 static void
9461 cmd_flex_filter_parsed(void *parsed_result,
9462                           __attribute__((unused)) struct cmdline *cl,
9463                           __attribute__((unused)) void *data)
9464 {
9465         int ret = 0;
9466         struct rte_eth_flex_filter filter;
9467         struct cmd_flex_filter_result *res = parsed_result;
9468         char *bytes_ptr, *mask_ptr;
9469         uint16_t len, i, j = 0;
9470         char c;
9471         int val;
9472         uint8_t byte = 0;
9473
9474         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9475                 printf("the len exceed the max length 128\n");
9476                 return;
9477         }
9478         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9479         filter.len = res->len_value;
9480         filter.priority = res->priority_value;
9481         filter.queue = res->queue_id;
9482         bytes_ptr = res->bytes_value;
9483         mask_ptr = res->mask_value;
9484
9485          /* translate bytes string to array. */
9486         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9487                 (bytes_ptr[1] == 'X')))
9488                 bytes_ptr += 2;
9489         len = strnlen(bytes_ptr, res->len_value * 2);
9490         if (len == 0 || (len % 8 != 0)) {
9491                 printf("please check len and bytes input\n");
9492                 return;
9493         }
9494         for (i = 0; i < len; i++) {
9495                 c = bytes_ptr[i];
9496                 if (isxdigit(c) == 0) {
9497                         /* invalid characters. */
9498                         printf("invalid input\n");
9499                         return;
9500                 }
9501                 val = xdigit2val(c);
9502                 if (i % 2) {
9503                         byte |= val;
9504                         filter.bytes[j] = byte;
9505                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9506                         j++;
9507                         byte = 0;
9508                 } else
9509                         byte |= val << 4;
9510         }
9511         printf("\n");
9512          /* translate mask string to uint8_t array. */
9513         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9514                 (mask_ptr[1] == 'X')))
9515                 mask_ptr += 2;
9516         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9517         if (len == 0) {
9518                 printf("invalid input\n");
9519                 return;
9520         }
9521         j = 0;
9522         byte = 0;
9523         for (i = 0; i < len; i++) {
9524                 c = mask_ptr[i];
9525                 if (isxdigit(c) == 0) {
9526                         /* invalid characters. */
9527                         printf("invalid input\n");
9528                         return;
9529                 }
9530                 val = xdigit2val(c);
9531                 if (i % 2) {
9532                         byte |= val;
9533                         filter.mask[j] = byte;
9534                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9535                         j++;
9536                         byte = 0;
9537                 } else
9538                         byte |= val << 4;
9539         }
9540         printf("\n");
9541
9542         if (!strcmp(res->ops, "add"))
9543                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9544                                 RTE_ETH_FILTER_FLEXIBLE,
9545                                 RTE_ETH_FILTER_ADD,
9546                                 &filter);
9547         else
9548                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9549                                 RTE_ETH_FILTER_FLEXIBLE,
9550                                 RTE_ETH_FILTER_DELETE,
9551                                 &filter);
9552
9553         if (ret < 0)
9554                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9555 }
9556
9557 cmdline_parse_token_string_t cmd_flex_filter_filter =
9558         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9559                                 filter, "flex_filter");
9560 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9561         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9562                                 port_id, UINT16);
9563 cmdline_parse_token_string_t cmd_flex_filter_ops =
9564         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9565                                 ops, "add#del");
9566 cmdline_parse_token_string_t cmd_flex_filter_len =
9567         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9568                                 len, "len");
9569 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9570         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9571                                 len_value, UINT8);
9572 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9573         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9574                                 bytes, "bytes");
9575 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9576         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9577                                 bytes_value, NULL);
9578 cmdline_parse_token_string_t cmd_flex_filter_mask =
9579         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9580                                 mask, "mask");
9581 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9582         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9583                                 mask_value, NULL);
9584 cmdline_parse_token_string_t cmd_flex_filter_priority =
9585         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9586                                 priority, "priority");
9587 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9588         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9589                                 priority_value, UINT8);
9590 cmdline_parse_token_string_t cmd_flex_filter_queue =
9591         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9592                                 queue, "queue");
9593 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9594         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9595                                 queue_id, UINT16);
9596 cmdline_parse_inst_t cmd_flex_filter = {
9597         .f = cmd_flex_filter_parsed,
9598         .data = NULL,
9599         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9600                 "<value> mask <value> priority <value> queue <queue_id>: "
9601                 "Add/Del a flex filter",
9602         .tokens = {
9603                 (void *)&cmd_flex_filter_filter,
9604                 (void *)&cmd_flex_filter_port_id,
9605                 (void *)&cmd_flex_filter_ops,
9606                 (void *)&cmd_flex_filter_len,
9607                 (void *)&cmd_flex_filter_len_value,
9608                 (void *)&cmd_flex_filter_bytes,
9609                 (void *)&cmd_flex_filter_bytes_value,
9610                 (void *)&cmd_flex_filter_mask,
9611                 (void *)&cmd_flex_filter_mask_value,
9612                 (void *)&cmd_flex_filter_priority,
9613                 (void *)&cmd_flex_filter_priority_value,
9614                 (void *)&cmd_flex_filter_queue,
9615                 (void *)&cmd_flex_filter_queue_id,
9616                 NULL,
9617         },
9618 };
9619
9620 /* *** Filters Control *** */
9621
9622 /* *** deal with ethertype filter *** */
9623 struct cmd_ethertype_filter_result {
9624         cmdline_fixed_string_t filter;
9625         portid_t port_id;
9626         cmdline_fixed_string_t ops;
9627         cmdline_fixed_string_t mac;
9628         struct ether_addr mac_addr;
9629         cmdline_fixed_string_t ethertype;
9630         uint16_t ethertype_value;
9631         cmdline_fixed_string_t drop;
9632         cmdline_fixed_string_t queue;
9633         uint16_t  queue_id;
9634 };
9635
9636 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9637         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9638                                  filter, "ethertype_filter");
9639 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9640         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9641                               port_id, UINT16);
9642 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9643         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9644                                  ops, "add#del");
9645 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9646         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9647                                  mac, "mac_addr#mac_ignr");
9648 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9649         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9650                                      mac_addr);
9651 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9652         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9653                                  ethertype, "ethertype");
9654 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9655         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9656                               ethertype_value, UINT16);
9657 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9658         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9659                                  drop, "drop#fwd");
9660 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9661         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9662                                  queue, "queue");
9663 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9664         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9665                               queue_id, UINT16);
9666
9667 static void
9668 cmd_ethertype_filter_parsed(void *parsed_result,
9669                           __attribute__((unused)) struct cmdline *cl,
9670                           __attribute__((unused)) void *data)
9671 {
9672         struct cmd_ethertype_filter_result *res = parsed_result;
9673         struct rte_eth_ethertype_filter filter;
9674         int ret = 0;
9675
9676         ret = rte_eth_dev_filter_supported(res->port_id,
9677                         RTE_ETH_FILTER_ETHERTYPE);
9678         if (ret < 0) {
9679                 printf("ethertype filter is not supported on port %u.\n",
9680                         res->port_id);
9681                 return;
9682         }
9683
9684         memset(&filter, 0, sizeof(filter));
9685         if (!strcmp(res->mac, "mac_addr")) {
9686                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9687                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9688                         sizeof(struct ether_addr));
9689         }
9690         if (!strcmp(res->drop, "drop"))
9691                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9692         filter.ether_type = res->ethertype_value;
9693         filter.queue = res->queue_id;
9694
9695         if (!strcmp(res->ops, "add"))
9696                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9697                                 RTE_ETH_FILTER_ETHERTYPE,
9698                                 RTE_ETH_FILTER_ADD,
9699                                 &filter);
9700         else
9701                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9702                                 RTE_ETH_FILTER_ETHERTYPE,
9703                                 RTE_ETH_FILTER_DELETE,
9704                                 &filter);
9705         if (ret < 0)
9706                 printf("ethertype filter programming error: (%s)\n",
9707                         strerror(-ret));
9708 }
9709
9710 cmdline_parse_inst_t cmd_ethertype_filter = {
9711         .f = cmd_ethertype_filter_parsed,
9712         .data = NULL,
9713         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9714                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9715                 "Add or delete an ethertype filter entry",
9716         .tokens = {
9717                 (void *)&cmd_ethertype_filter_filter,
9718                 (void *)&cmd_ethertype_filter_port_id,
9719                 (void *)&cmd_ethertype_filter_ops,
9720                 (void *)&cmd_ethertype_filter_mac,
9721                 (void *)&cmd_ethertype_filter_mac_addr,
9722                 (void *)&cmd_ethertype_filter_ethertype,
9723                 (void *)&cmd_ethertype_filter_ethertype_value,
9724                 (void *)&cmd_ethertype_filter_drop,
9725                 (void *)&cmd_ethertype_filter_queue,
9726                 (void *)&cmd_ethertype_filter_queue_id,
9727                 NULL,
9728         },
9729 };
9730
9731 /* *** deal with flow director filter *** */
9732 struct cmd_flow_director_result {
9733         cmdline_fixed_string_t flow_director_filter;
9734         portid_t port_id;
9735         cmdline_fixed_string_t mode;
9736         cmdline_fixed_string_t mode_value;
9737         cmdline_fixed_string_t ops;
9738         cmdline_fixed_string_t flow;
9739         cmdline_fixed_string_t flow_type;
9740         cmdline_fixed_string_t ether;
9741         uint16_t ether_type;
9742         cmdline_fixed_string_t src;
9743         cmdline_ipaddr_t ip_src;
9744         uint16_t port_src;
9745         cmdline_fixed_string_t dst;
9746         cmdline_ipaddr_t ip_dst;
9747         uint16_t port_dst;
9748         cmdline_fixed_string_t verify_tag;
9749         uint32_t verify_tag_value;
9750         cmdline_ipaddr_t tos;
9751         uint8_t tos_value;
9752         cmdline_ipaddr_t proto;
9753         uint8_t proto_value;
9754         cmdline_ipaddr_t ttl;
9755         uint8_t ttl_value;
9756         cmdline_fixed_string_t vlan;
9757         uint16_t vlan_value;
9758         cmdline_fixed_string_t flexbytes;
9759         cmdline_fixed_string_t flexbytes_value;
9760         cmdline_fixed_string_t pf_vf;
9761         cmdline_fixed_string_t drop;
9762         cmdline_fixed_string_t queue;
9763         uint16_t  queue_id;
9764         cmdline_fixed_string_t fd_id;
9765         uint32_t  fd_id_value;
9766         cmdline_fixed_string_t mac;
9767         struct ether_addr mac_addr;
9768         cmdline_fixed_string_t tunnel;
9769         cmdline_fixed_string_t tunnel_type;
9770         cmdline_fixed_string_t tunnel_id;
9771         uint32_t tunnel_id_value;
9772 };
9773
9774 static inline int
9775 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9776 {
9777         char s[256];
9778         const char *p, *p0 = q_arg;
9779         char *end;
9780         unsigned long int_fld;
9781         char *str_fld[max_num];
9782         int i;
9783         unsigned size;
9784         int ret = -1;
9785
9786         p = strchr(p0, '(');
9787         if (p == NULL)
9788                 return -1;
9789         ++p;
9790         p0 = strchr(p, ')');
9791         if (p0 == NULL)
9792                 return -1;
9793
9794         size = p0 - p;
9795         if (size >= sizeof(s))
9796                 return -1;
9797
9798         snprintf(s, sizeof(s), "%.*s", size, p);
9799         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9800         if (ret < 0 || ret > max_num)
9801                 return -1;
9802         for (i = 0; i < ret; i++) {
9803                 errno = 0;
9804                 int_fld = strtoul(str_fld[i], &end, 0);
9805                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9806                         return -1;
9807                 flexbytes[i] = (uint8_t)int_fld;
9808         }
9809         return ret;
9810 }
9811
9812 static uint16_t
9813 str2flowtype(char *string)
9814 {
9815         uint8_t i = 0;
9816         static const struct {
9817                 char str[32];
9818                 uint16_t type;
9819         } flowtype_str[] = {
9820                 {"raw", RTE_ETH_FLOW_RAW},
9821                 {"ipv4", RTE_ETH_FLOW_IPV4},
9822                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9823                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9824                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9825                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9826                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9827                 {"ipv6", RTE_ETH_FLOW_IPV6},
9828                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9829                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9830                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9831                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9832                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9833                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9834         };
9835
9836         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9837                 if (!strcmp(flowtype_str[i].str, string))
9838                         return flowtype_str[i].type;
9839         }
9840
9841         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9842                 return (uint16_t)atoi(string);
9843
9844         return RTE_ETH_FLOW_UNKNOWN;
9845 }
9846
9847 static enum rte_eth_fdir_tunnel_type
9848 str2fdir_tunneltype(char *string)
9849 {
9850         uint8_t i = 0;
9851
9852         static const struct {
9853                 char str[32];
9854                 enum rte_eth_fdir_tunnel_type type;
9855         } tunneltype_str[] = {
9856                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9857                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9858         };
9859
9860         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9861                 if (!strcmp(tunneltype_str[i].str, string))
9862                         return tunneltype_str[i].type;
9863         }
9864         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9865 }
9866
9867 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9868 do { \
9869         if ((ip_addr).family == AF_INET) \
9870                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9871         else { \
9872                 printf("invalid parameter.\n"); \
9873                 return; \
9874         } \
9875 } while (0)
9876
9877 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9878 do { \
9879         if ((ip_addr).family == AF_INET6) \
9880                 rte_memcpy(&(ip), \
9881                                  &((ip_addr).addr.ipv6), \
9882                                  sizeof(struct in6_addr)); \
9883         else { \
9884                 printf("invalid parameter.\n"); \
9885                 return; \
9886         } \
9887 } while (0)
9888
9889 static void
9890 cmd_flow_director_filter_parsed(void *parsed_result,
9891                           __attribute__((unused)) struct cmdline *cl,
9892                           __attribute__((unused)) void *data)
9893 {
9894         struct cmd_flow_director_result *res = parsed_result;
9895         struct rte_eth_fdir_filter entry;
9896         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9897         char *end;
9898         unsigned long vf_id;
9899         int ret = 0;
9900
9901         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9902         if (ret < 0) {
9903                 printf("flow director is not supported on port %u.\n",
9904                         res->port_id);
9905                 return;
9906         }
9907         memset(flexbytes, 0, sizeof(flexbytes));
9908         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9909
9910         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9911                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9912                         printf("Please set mode to MAC-VLAN.\n");
9913                         return;
9914                 }
9915         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9916                 if (strcmp(res->mode_value, "Tunnel")) {
9917                         printf("Please set mode to Tunnel.\n");
9918                         return;
9919                 }
9920         } else {
9921                 if (strcmp(res->mode_value, "IP")) {
9922                         printf("Please set mode to IP.\n");
9923                         return;
9924                 }
9925                 entry.input.flow_type = str2flowtype(res->flow_type);
9926         }
9927
9928         ret = parse_flexbytes(res->flexbytes_value,
9929                                         flexbytes,
9930                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9931         if (ret < 0) {
9932                 printf("error: Cannot parse flexbytes input.\n");
9933                 return;
9934         }
9935
9936         switch (entry.input.flow_type) {
9937         case RTE_ETH_FLOW_FRAG_IPV4:
9938         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9939                 entry.input.flow.ip4_flow.proto = res->proto_value;
9940                 /* fall-through */
9941         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9942         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9943                 IPV4_ADDR_TO_UINT(res->ip_dst,
9944                         entry.input.flow.ip4_flow.dst_ip);
9945                 IPV4_ADDR_TO_UINT(res->ip_src,
9946                         entry.input.flow.ip4_flow.src_ip);
9947                 entry.input.flow.ip4_flow.tos = res->tos_value;
9948                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9949                 /* need convert to big endian. */
9950                 entry.input.flow.udp4_flow.dst_port =
9951                                 rte_cpu_to_be_16(res->port_dst);
9952                 entry.input.flow.udp4_flow.src_port =
9953                                 rte_cpu_to_be_16(res->port_src);
9954                 break;
9955         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9956                 IPV4_ADDR_TO_UINT(res->ip_dst,
9957                         entry.input.flow.sctp4_flow.ip.dst_ip);
9958                 IPV4_ADDR_TO_UINT(res->ip_src,
9959                         entry.input.flow.sctp4_flow.ip.src_ip);
9960                 entry.input.flow.ip4_flow.tos = res->tos_value;
9961                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9962                 /* need convert to big endian. */
9963                 entry.input.flow.sctp4_flow.dst_port =
9964                                 rte_cpu_to_be_16(res->port_dst);
9965                 entry.input.flow.sctp4_flow.src_port =
9966                                 rte_cpu_to_be_16(res->port_src);
9967                 entry.input.flow.sctp4_flow.verify_tag =
9968                                 rte_cpu_to_be_32(res->verify_tag_value);
9969                 break;
9970         case RTE_ETH_FLOW_FRAG_IPV6:
9971         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9972                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9973                 /* fall-through */
9974         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9975         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9976                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9977                         entry.input.flow.ipv6_flow.dst_ip);
9978                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9979                         entry.input.flow.ipv6_flow.src_ip);
9980                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9981                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9982                 /* need convert to big endian. */
9983                 entry.input.flow.udp6_flow.dst_port =
9984                                 rte_cpu_to_be_16(res->port_dst);
9985                 entry.input.flow.udp6_flow.src_port =
9986                                 rte_cpu_to_be_16(res->port_src);
9987                 break;
9988         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9989                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9990                         entry.input.flow.sctp6_flow.ip.dst_ip);
9991                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9992                         entry.input.flow.sctp6_flow.ip.src_ip);
9993                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9994                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9995                 /* need convert to big endian. */
9996                 entry.input.flow.sctp6_flow.dst_port =
9997                                 rte_cpu_to_be_16(res->port_dst);
9998                 entry.input.flow.sctp6_flow.src_port =
9999                                 rte_cpu_to_be_16(res->port_src);
10000                 entry.input.flow.sctp6_flow.verify_tag =
10001                                 rte_cpu_to_be_32(res->verify_tag_value);
10002                 break;
10003         case RTE_ETH_FLOW_L2_PAYLOAD:
10004                 entry.input.flow.l2_flow.ether_type =
10005                         rte_cpu_to_be_16(res->ether_type);
10006                 break;
10007         default:
10008                 break;
10009         }
10010
10011         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10012                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10013                                  &res->mac_addr,
10014                                  sizeof(struct ether_addr));
10015
10016         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10017                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10018                                  &res->mac_addr,
10019                                  sizeof(struct ether_addr));
10020                 entry.input.flow.tunnel_flow.tunnel_type =
10021                         str2fdir_tunneltype(res->tunnel_type);
10022                 entry.input.flow.tunnel_flow.tunnel_id =
10023                         rte_cpu_to_be_32(res->tunnel_id_value);
10024         }
10025
10026         rte_memcpy(entry.input.flow_ext.flexbytes,
10027                    flexbytes,
10028                    RTE_ETH_FDIR_MAX_FLEXLEN);
10029
10030         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10031
10032         entry.action.flex_off = 0;  /*use 0 by default */
10033         if (!strcmp(res->drop, "drop"))
10034                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10035         else
10036                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10037
10038         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10039             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10040                 if (!strcmp(res->pf_vf, "pf"))
10041                         entry.input.flow_ext.is_vf = 0;
10042                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10043                         struct rte_eth_dev_info dev_info;
10044
10045                         memset(&dev_info, 0, sizeof(dev_info));
10046                         rte_eth_dev_info_get(res->port_id, &dev_info);
10047                         errno = 0;
10048                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10049                         if (errno != 0 || *end != '\0' ||
10050                             vf_id >= dev_info.max_vfs) {
10051                                 printf("invalid parameter %s.\n", res->pf_vf);
10052                                 return;
10053                         }
10054                         entry.input.flow_ext.is_vf = 1;
10055                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10056                 } else {
10057                         printf("invalid parameter %s.\n", res->pf_vf);
10058                         return;
10059                 }
10060         }
10061
10062         /* set to report FD ID by default */
10063         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10064         entry.action.rx_queue = res->queue_id;
10065         entry.soft_id = res->fd_id_value;
10066         if (!strcmp(res->ops, "add"))
10067                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10068                                              RTE_ETH_FILTER_ADD, &entry);
10069         else if (!strcmp(res->ops, "del"))
10070                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10071                                              RTE_ETH_FILTER_DELETE, &entry);
10072         else
10073                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10074                                              RTE_ETH_FILTER_UPDATE, &entry);
10075         if (ret < 0)
10076                 printf("flow director programming error: (%s)\n",
10077                         strerror(-ret));
10078 }
10079
10080 cmdline_parse_token_string_t cmd_flow_director_filter =
10081         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10082                                  flow_director_filter, "flow_director_filter");
10083 cmdline_parse_token_num_t cmd_flow_director_port_id =
10084         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10085                               port_id, UINT16);
10086 cmdline_parse_token_string_t cmd_flow_director_ops =
10087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10088                                  ops, "add#del#update");
10089 cmdline_parse_token_string_t cmd_flow_director_flow =
10090         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10091                                  flow, "flow");
10092 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10093         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10094                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10095                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10096 cmdline_parse_token_string_t cmd_flow_director_ether =
10097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10098                                  ether, "ether");
10099 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10100         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10101                               ether_type, UINT16);
10102 cmdline_parse_token_string_t cmd_flow_director_src =
10103         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10104                                  src, "src");
10105 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10106         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10107                                  ip_src);
10108 cmdline_parse_token_num_t cmd_flow_director_port_src =
10109         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10110                               port_src, UINT16);
10111 cmdline_parse_token_string_t cmd_flow_director_dst =
10112         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10113                                  dst, "dst");
10114 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10115         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10116                                  ip_dst);
10117 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10118         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10119                               port_dst, UINT16);
10120 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10121         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10122                                   verify_tag, "verify_tag");
10123 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10124         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10125                               verify_tag_value, UINT32);
10126 cmdline_parse_token_string_t cmd_flow_director_tos =
10127         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10128                                  tos, "tos");
10129 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10130         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10131                               tos_value, UINT8);
10132 cmdline_parse_token_string_t cmd_flow_director_proto =
10133         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10134                                  proto, "proto");
10135 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10136         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10137                               proto_value, UINT8);
10138 cmdline_parse_token_string_t cmd_flow_director_ttl =
10139         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10140                                  ttl, "ttl");
10141 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10142         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10143                               ttl_value, UINT8);
10144 cmdline_parse_token_string_t cmd_flow_director_vlan =
10145         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10146                                  vlan, "vlan");
10147 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10148         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10149                               vlan_value, UINT16);
10150 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10151         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10152                                  flexbytes, "flexbytes");
10153 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10154         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10155                               flexbytes_value, NULL);
10156 cmdline_parse_token_string_t cmd_flow_director_drop =
10157         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10158                                  drop, "drop#fwd");
10159 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10160         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10161                               pf_vf, NULL);
10162 cmdline_parse_token_string_t cmd_flow_director_queue =
10163         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10164                                  queue, "queue");
10165 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10166         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10167                               queue_id, UINT16);
10168 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10169         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10170                                  fd_id, "fd_id");
10171 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10172         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10173                               fd_id_value, UINT32);
10174
10175 cmdline_parse_token_string_t cmd_flow_director_mode =
10176         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10177                                  mode, "mode");
10178 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10179         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10180                                  mode_value, "IP");
10181 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10182         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10183                                  mode_value, "MAC-VLAN");
10184 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10185         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10186                                  mode_value, "Tunnel");
10187 cmdline_parse_token_string_t cmd_flow_director_mac =
10188         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10189                                  mac, "mac");
10190 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10191         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10192                                     mac_addr);
10193 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10194         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10195                                  tunnel, "tunnel");
10196 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10197         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10198                                  tunnel_type, "NVGRE#VxLAN");
10199 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10200         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10201                                  tunnel_id, "tunnel-id");
10202 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10203         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10204                               tunnel_id_value, UINT32);
10205
10206 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10207         .f = cmd_flow_director_filter_parsed,
10208         .data = NULL,
10209         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10210                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10211                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10212                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10213                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10214                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10215                 "fd_id <fd_id_value>: "
10216                 "Add or delete an ip flow director entry on NIC",
10217         .tokens = {
10218                 (void *)&cmd_flow_director_filter,
10219                 (void *)&cmd_flow_director_port_id,
10220                 (void *)&cmd_flow_director_mode,
10221                 (void *)&cmd_flow_director_mode_ip,
10222                 (void *)&cmd_flow_director_ops,
10223                 (void *)&cmd_flow_director_flow,
10224                 (void *)&cmd_flow_director_flow_type,
10225                 (void *)&cmd_flow_director_src,
10226                 (void *)&cmd_flow_director_ip_src,
10227                 (void *)&cmd_flow_director_dst,
10228                 (void *)&cmd_flow_director_ip_dst,
10229                 (void *)&cmd_flow_director_tos,
10230                 (void *)&cmd_flow_director_tos_value,
10231                 (void *)&cmd_flow_director_proto,
10232                 (void *)&cmd_flow_director_proto_value,
10233                 (void *)&cmd_flow_director_ttl,
10234                 (void *)&cmd_flow_director_ttl_value,
10235                 (void *)&cmd_flow_director_vlan,
10236                 (void *)&cmd_flow_director_vlan_value,
10237                 (void *)&cmd_flow_director_flexbytes,
10238                 (void *)&cmd_flow_director_flexbytes_value,
10239                 (void *)&cmd_flow_director_drop,
10240                 (void *)&cmd_flow_director_pf_vf,
10241                 (void *)&cmd_flow_director_queue,
10242                 (void *)&cmd_flow_director_queue_id,
10243                 (void *)&cmd_flow_director_fd_id,
10244                 (void *)&cmd_flow_director_fd_id_value,
10245                 NULL,
10246         },
10247 };
10248
10249 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10250         .f = cmd_flow_director_filter_parsed,
10251         .data = NULL,
10252         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10253                 "director entry on NIC",
10254         .tokens = {
10255                 (void *)&cmd_flow_director_filter,
10256                 (void *)&cmd_flow_director_port_id,
10257                 (void *)&cmd_flow_director_mode,
10258                 (void *)&cmd_flow_director_mode_ip,
10259                 (void *)&cmd_flow_director_ops,
10260                 (void *)&cmd_flow_director_flow,
10261                 (void *)&cmd_flow_director_flow_type,
10262                 (void *)&cmd_flow_director_src,
10263                 (void *)&cmd_flow_director_ip_src,
10264                 (void *)&cmd_flow_director_port_src,
10265                 (void *)&cmd_flow_director_dst,
10266                 (void *)&cmd_flow_director_ip_dst,
10267                 (void *)&cmd_flow_director_port_dst,
10268                 (void *)&cmd_flow_director_tos,
10269                 (void *)&cmd_flow_director_tos_value,
10270                 (void *)&cmd_flow_director_ttl,
10271                 (void *)&cmd_flow_director_ttl_value,
10272                 (void *)&cmd_flow_director_vlan,
10273                 (void *)&cmd_flow_director_vlan_value,
10274                 (void *)&cmd_flow_director_flexbytes,
10275                 (void *)&cmd_flow_director_flexbytes_value,
10276                 (void *)&cmd_flow_director_drop,
10277                 (void *)&cmd_flow_director_pf_vf,
10278                 (void *)&cmd_flow_director_queue,
10279                 (void *)&cmd_flow_director_queue_id,
10280                 (void *)&cmd_flow_director_fd_id,
10281                 (void *)&cmd_flow_director_fd_id_value,
10282                 NULL,
10283         },
10284 };
10285
10286 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10287         .f = cmd_flow_director_filter_parsed,
10288         .data = NULL,
10289         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10290                 "director entry on NIC",
10291         .tokens = {
10292                 (void *)&cmd_flow_director_filter,
10293                 (void *)&cmd_flow_director_port_id,
10294                 (void *)&cmd_flow_director_mode,
10295                 (void *)&cmd_flow_director_mode_ip,
10296                 (void *)&cmd_flow_director_ops,
10297                 (void *)&cmd_flow_director_flow,
10298                 (void *)&cmd_flow_director_flow_type,
10299                 (void *)&cmd_flow_director_src,
10300                 (void *)&cmd_flow_director_ip_src,
10301                 (void *)&cmd_flow_director_port_dst,
10302                 (void *)&cmd_flow_director_dst,
10303                 (void *)&cmd_flow_director_ip_dst,
10304                 (void *)&cmd_flow_director_port_dst,
10305                 (void *)&cmd_flow_director_verify_tag,
10306                 (void *)&cmd_flow_director_verify_tag_value,
10307                 (void *)&cmd_flow_director_tos,
10308                 (void *)&cmd_flow_director_tos_value,
10309                 (void *)&cmd_flow_director_ttl,
10310                 (void *)&cmd_flow_director_ttl_value,
10311                 (void *)&cmd_flow_director_vlan,
10312                 (void *)&cmd_flow_director_vlan_value,
10313                 (void *)&cmd_flow_director_flexbytes,
10314                 (void *)&cmd_flow_director_flexbytes_value,
10315                 (void *)&cmd_flow_director_drop,
10316                 (void *)&cmd_flow_director_pf_vf,
10317                 (void *)&cmd_flow_director_queue,
10318                 (void *)&cmd_flow_director_queue_id,
10319                 (void *)&cmd_flow_director_fd_id,
10320                 (void *)&cmd_flow_director_fd_id_value,
10321                 NULL,
10322         },
10323 };
10324
10325 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10326         .f = cmd_flow_director_filter_parsed,
10327         .data = NULL,
10328         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10329                 "director entry on NIC",
10330         .tokens = {
10331                 (void *)&cmd_flow_director_filter,
10332                 (void *)&cmd_flow_director_port_id,
10333                 (void *)&cmd_flow_director_mode,
10334                 (void *)&cmd_flow_director_mode_ip,
10335                 (void *)&cmd_flow_director_ops,
10336                 (void *)&cmd_flow_director_flow,
10337                 (void *)&cmd_flow_director_flow_type,
10338                 (void *)&cmd_flow_director_ether,
10339                 (void *)&cmd_flow_director_ether_type,
10340                 (void *)&cmd_flow_director_flexbytes,
10341                 (void *)&cmd_flow_director_flexbytes_value,
10342                 (void *)&cmd_flow_director_drop,
10343                 (void *)&cmd_flow_director_pf_vf,
10344                 (void *)&cmd_flow_director_queue,
10345                 (void *)&cmd_flow_director_queue_id,
10346                 (void *)&cmd_flow_director_fd_id,
10347                 (void *)&cmd_flow_director_fd_id_value,
10348                 NULL,
10349         },
10350 };
10351
10352 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10353         .f = cmd_flow_director_filter_parsed,
10354         .data = NULL,
10355         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10356                 "director entry on NIC",
10357         .tokens = {
10358                 (void *)&cmd_flow_director_filter,
10359                 (void *)&cmd_flow_director_port_id,
10360                 (void *)&cmd_flow_director_mode,
10361                 (void *)&cmd_flow_director_mode_mac_vlan,
10362                 (void *)&cmd_flow_director_ops,
10363                 (void *)&cmd_flow_director_mac,
10364                 (void *)&cmd_flow_director_mac_addr,
10365                 (void *)&cmd_flow_director_vlan,
10366                 (void *)&cmd_flow_director_vlan_value,
10367                 (void *)&cmd_flow_director_flexbytes,
10368                 (void *)&cmd_flow_director_flexbytes_value,
10369                 (void *)&cmd_flow_director_drop,
10370                 (void *)&cmd_flow_director_queue,
10371                 (void *)&cmd_flow_director_queue_id,
10372                 (void *)&cmd_flow_director_fd_id,
10373                 (void *)&cmd_flow_director_fd_id_value,
10374                 NULL,
10375         },
10376 };
10377
10378 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10379         .f = cmd_flow_director_filter_parsed,
10380         .data = NULL,
10381         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10382                 "director entry on NIC",
10383         .tokens = {
10384                 (void *)&cmd_flow_director_filter,
10385                 (void *)&cmd_flow_director_port_id,
10386                 (void *)&cmd_flow_director_mode,
10387                 (void *)&cmd_flow_director_mode_tunnel,
10388                 (void *)&cmd_flow_director_ops,
10389                 (void *)&cmd_flow_director_mac,
10390                 (void *)&cmd_flow_director_mac_addr,
10391                 (void *)&cmd_flow_director_vlan,
10392                 (void *)&cmd_flow_director_vlan_value,
10393                 (void *)&cmd_flow_director_tunnel,
10394                 (void *)&cmd_flow_director_tunnel_type,
10395                 (void *)&cmd_flow_director_tunnel_id,
10396                 (void *)&cmd_flow_director_tunnel_id_value,
10397                 (void *)&cmd_flow_director_flexbytes,
10398                 (void *)&cmd_flow_director_flexbytes_value,
10399                 (void *)&cmd_flow_director_drop,
10400                 (void *)&cmd_flow_director_queue,
10401                 (void *)&cmd_flow_director_queue_id,
10402                 (void *)&cmd_flow_director_fd_id,
10403                 (void *)&cmd_flow_director_fd_id_value,
10404                 NULL,
10405         },
10406 };
10407
10408 struct cmd_flush_flow_director_result {
10409         cmdline_fixed_string_t flush_flow_director;
10410         portid_t port_id;
10411 };
10412
10413 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10414         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10415                                  flush_flow_director, "flush_flow_director");
10416 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10417         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10418                               port_id, UINT16);
10419
10420 static void
10421 cmd_flush_flow_director_parsed(void *parsed_result,
10422                           __attribute__((unused)) struct cmdline *cl,
10423                           __attribute__((unused)) void *data)
10424 {
10425         struct cmd_flow_director_result *res = parsed_result;
10426         int ret = 0;
10427
10428         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10429         if (ret < 0) {
10430                 printf("flow director is not supported on port %u.\n",
10431                         res->port_id);
10432                 return;
10433         }
10434
10435         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10436                         RTE_ETH_FILTER_FLUSH, NULL);
10437         if (ret < 0)
10438                 printf("flow director table flushing error: (%s)\n",
10439                         strerror(-ret));
10440 }
10441
10442 cmdline_parse_inst_t cmd_flush_flow_director = {
10443         .f = cmd_flush_flow_director_parsed,
10444         .data = NULL,
10445         .help_str = "flush_flow_director <port_id>: "
10446                 "Flush all flow director entries of a device on NIC",
10447         .tokens = {
10448                 (void *)&cmd_flush_flow_director_flush,
10449                 (void *)&cmd_flush_flow_director_port_id,
10450                 NULL,
10451         },
10452 };
10453
10454 /* *** deal with flow director mask *** */
10455 struct cmd_flow_director_mask_result {
10456         cmdline_fixed_string_t flow_director_mask;
10457         portid_t port_id;
10458         cmdline_fixed_string_t mode;
10459         cmdline_fixed_string_t mode_value;
10460         cmdline_fixed_string_t vlan;
10461         uint16_t vlan_mask;
10462         cmdline_fixed_string_t src_mask;
10463         cmdline_ipaddr_t ipv4_src;
10464         cmdline_ipaddr_t ipv6_src;
10465         uint16_t port_src;
10466         cmdline_fixed_string_t dst_mask;
10467         cmdline_ipaddr_t ipv4_dst;
10468         cmdline_ipaddr_t ipv6_dst;
10469         uint16_t port_dst;
10470         cmdline_fixed_string_t mac;
10471         uint8_t mac_addr_byte_mask;
10472         cmdline_fixed_string_t tunnel_id;
10473         uint32_t tunnel_id_mask;
10474         cmdline_fixed_string_t tunnel_type;
10475         uint8_t tunnel_type_mask;
10476 };
10477
10478 static void
10479 cmd_flow_director_mask_parsed(void *parsed_result,
10480                           __attribute__((unused)) struct cmdline *cl,
10481                           __attribute__((unused)) void *data)
10482 {
10483         struct cmd_flow_director_mask_result *res = parsed_result;
10484         struct rte_eth_fdir_masks *mask;
10485         struct rte_port *port;
10486
10487         if (res->port_id > nb_ports) {
10488                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10489                 return;
10490         }
10491
10492         port = &ports[res->port_id];
10493         /** Check if the port is not started **/
10494         if (port->port_status != RTE_PORT_STOPPED) {
10495                 printf("Please stop port %d first\n", res->port_id);
10496                 return;
10497         }
10498
10499         mask = &port->dev_conf.fdir_conf.mask;
10500
10501         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10502                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10503                         printf("Please set mode to MAC-VLAN.\n");
10504                         return;
10505                 }
10506
10507                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10508         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10509                 if (strcmp(res->mode_value, "Tunnel")) {
10510                         printf("Please set mode to Tunnel.\n");
10511                         return;
10512                 }
10513
10514                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10515                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10516                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10517                 mask->tunnel_type_mask = res->tunnel_type_mask;
10518         } else {
10519                 if (strcmp(res->mode_value, "IP")) {
10520                         printf("Please set mode to IP.\n");
10521                         return;
10522                 }
10523
10524                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10525                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10526                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10527                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10528                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10529                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10530                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10531         }
10532
10533         cmd_reconfig_device_queue(res->port_id, 1, 1);
10534 }
10535
10536 cmdline_parse_token_string_t cmd_flow_director_mask =
10537         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10538                                  flow_director_mask, "flow_director_mask");
10539 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10540         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10541                               port_id, UINT16);
10542 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10543         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10544                                  vlan, "vlan");
10545 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10546         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10547                               vlan_mask, UINT16);
10548 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10549         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10550                                  src_mask, "src_mask");
10551 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10552         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10553                                  ipv4_src);
10554 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10555         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10556                                  ipv6_src);
10557 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10558         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10559                               port_src, UINT16);
10560 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10561         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10562                                  dst_mask, "dst_mask");
10563 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10564         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10565                                  ipv4_dst);
10566 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10567         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10568                                  ipv6_dst);
10569 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10570         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10571                               port_dst, UINT16);
10572
10573 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10574         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10575                                  mode, "mode");
10576 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10577         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10578                                  mode_value, "IP");
10579 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10580         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10581                                  mode_value, "MAC-VLAN");
10582 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10583         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10584                                  mode_value, "Tunnel");
10585 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10586         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10587                                  mac, "mac");
10588 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10589         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10590                               mac_addr_byte_mask, UINT8);
10591 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10592         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10593                                  tunnel_type, "tunnel-type");
10594 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10595         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10596                               tunnel_type_mask, UINT8);
10597 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10598         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10599                                  tunnel_id, "tunnel-id");
10600 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10601         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10602                               tunnel_id_mask, UINT32);
10603
10604 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10605         .f = cmd_flow_director_mask_parsed,
10606         .data = NULL,
10607         .help_str = "flow_director_mask ... : "
10608                 "Set IP mode flow director's mask on NIC",
10609         .tokens = {
10610                 (void *)&cmd_flow_director_mask,
10611                 (void *)&cmd_flow_director_mask_port_id,
10612                 (void *)&cmd_flow_director_mask_mode,
10613                 (void *)&cmd_flow_director_mask_mode_ip,
10614                 (void *)&cmd_flow_director_mask_vlan,
10615                 (void *)&cmd_flow_director_mask_vlan_value,
10616                 (void *)&cmd_flow_director_mask_src,
10617                 (void *)&cmd_flow_director_mask_ipv4_src,
10618                 (void *)&cmd_flow_director_mask_ipv6_src,
10619                 (void *)&cmd_flow_director_mask_port_src,
10620                 (void *)&cmd_flow_director_mask_dst,
10621                 (void *)&cmd_flow_director_mask_ipv4_dst,
10622                 (void *)&cmd_flow_director_mask_ipv6_dst,
10623                 (void *)&cmd_flow_director_mask_port_dst,
10624                 NULL,
10625         },
10626 };
10627
10628 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10629         .f = cmd_flow_director_mask_parsed,
10630         .data = NULL,
10631         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10632                 "flow director's mask on NIC",
10633         .tokens = {
10634                 (void *)&cmd_flow_director_mask,
10635                 (void *)&cmd_flow_director_mask_port_id,
10636                 (void *)&cmd_flow_director_mask_mode,
10637                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10638                 (void *)&cmd_flow_director_mask_vlan,
10639                 (void *)&cmd_flow_director_mask_vlan_value,
10640                 NULL,
10641         },
10642 };
10643
10644 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10645         .f = cmd_flow_director_mask_parsed,
10646         .data = NULL,
10647         .help_str = "flow_director_mask ... : Set tunnel mode "
10648                 "flow director's mask on NIC",
10649         .tokens = {
10650                 (void *)&cmd_flow_director_mask,
10651                 (void *)&cmd_flow_director_mask_port_id,
10652                 (void *)&cmd_flow_director_mask_mode,
10653                 (void *)&cmd_flow_director_mask_mode_tunnel,
10654                 (void *)&cmd_flow_director_mask_vlan,
10655                 (void *)&cmd_flow_director_mask_vlan_value,
10656                 (void *)&cmd_flow_director_mask_mac,
10657                 (void *)&cmd_flow_director_mask_mac_value,
10658                 (void *)&cmd_flow_director_mask_tunnel_type,
10659                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10660                 (void *)&cmd_flow_director_mask_tunnel_id,
10661                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10662                 NULL,
10663         },
10664 };
10665
10666 /* *** deal with flow director mask on flexible payload *** */
10667 struct cmd_flow_director_flex_mask_result {
10668         cmdline_fixed_string_t flow_director_flexmask;
10669         portid_t port_id;
10670         cmdline_fixed_string_t flow;
10671         cmdline_fixed_string_t flow_type;
10672         cmdline_fixed_string_t mask;
10673 };
10674
10675 static void
10676 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10677                           __attribute__((unused)) struct cmdline *cl,
10678                           __attribute__((unused)) void *data)
10679 {
10680         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10681         struct rte_eth_fdir_info fdir_info;
10682         struct rte_eth_fdir_flex_mask flex_mask;
10683         struct rte_port *port;
10684         uint32_t flow_type_mask;
10685         uint16_t i;
10686         int ret;
10687
10688         if (res->port_id > nb_ports) {
10689                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10690                 return;
10691         }
10692
10693         port = &ports[res->port_id];
10694         /** Check if the port is not started **/
10695         if (port->port_status != RTE_PORT_STOPPED) {
10696                 printf("Please stop port %d first\n", res->port_id);
10697                 return;
10698         }
10699
10700         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10701         ret = parse_flexbytes(res->mask,
10702                         flex_mask.mask,
10703                         RTE_ETH_FDIR_MAX_FLEXLEN);
10704         if (ret < 0) {
10705                 printf("error: Cannot parse mask input.\n");
10706                 return;
10707         }
10708
10709         memset(&fdir_info, 0, sizeof(fdir_info));
10710         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10711                                 RTE_ETH_FILTER_INFO, &fdir_info);
10712         if (ret < 0) {
10713                 printf("Cannot get FDir filter info\n");
10714                 return;
10715         }
10716
10717         if (!strcmp(res->flow_type, "none")) {
10718                 /* means don't specify the flow type */
10719                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10720                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10721                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10722                                0, sizeof(struct rte_eth_fdir_flex_mask));
10723                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10724                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10725                                  &flex_mask,
10726                                  sizeof(struct rte_eth_fdir_flex_mask));
10727                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10728                 return;
10729         }
10730         flow_type_mask = fdir_info.flow_types_mask[0];
10731         if (!strcmp(res->flow_type, "all")) {
10732                 if (!flow_type_mask) {
10733                         printf("No flow type supported\n");
10734                         return;
10735                 }
10736                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10737                         if (flow_type_mask & (1 << i)) {
10738                                 flex_mask.flow_type = i;
10739                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10740                         }
10741                 }
10742                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10743                 return;
10744         }
10745         flex_mask.flow_type = str2flowtype(res->flow_type);
10746         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10747                 printf("Flow type %s not supported on port %d\n",
10748                                 res->flow_type, res->port_id);
10749                 return;
10750         }
10751         fdir_set_flex_mask(res->port_id, &flex_mask);
10752         cmd_reconfig_device_queue(res->port_id, 1, 1);
10753 }
10754
10755 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10756         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10757                                  flow_director_flexmask,
10758                                  "flow_director_flex_mask");
10759 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10760         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10761                               port_id, UINT16);
10762 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10763         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10764                                  flow, "flow");
10765 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10767                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10768                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10769 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10770         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10771                                  mask, NULL);
10772
10773 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10774         .f = cmd_flow_director_flex_mask_parsed,
10775         .data = NULL,
10776         .help_str = "flow_director_flex_mask ... : "
10777                 "Set flow director's flex mask on NIC",
10778         .tokens = {
10779                 (void *)&cmd_flow_director_flexmask,
10780                 (void *)&cmd_flow_director_flexmask_port_id,
10781                 (void *)&cmd_flow_director_flexmask_flow,
10782                 (void *)&cmd_flow_director_flexmask_flow_type,
10783                 (void *)&cmd_flow_director_flexmask_mask,
10784                 NULL,
10785         },
10786 };
10787
10788 /* *** deal with flow director flexible payload configuration *** */
10789 struct cmd_flow_director_flexpayload_result {
10790         cmdline_fixed_string_t flow_director_flexpayload;
10791         portid_t port_id;
10792         cmdline_fixed_string_t payload_layer;
10793         cmdline_fixed_string_t payload_cfg;
10794 };
10795
10796 static inline int
10797 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10798 {
10799         char s[256];
10800         const char *p, *p0 = q_arg;
10801         char *end;
10802         unsigned long int_fld;
10803         char *str_fld[max_num];
10804         int i;
10805         unsigned size;
10806         int ret = -1;
10807
10808         p = strchr(p0, '(');
10809         if (p == NULL)
10810                 return -1;
10811         ++p;
10812         p0 = strchr(p, ')');
10813         if (p0 == NULL)
10814                 return -1;
10815
10816         size = p0 - p;
10817         if (size >= sizeof(s))
10818                 return -1;
10819
10820         snprintf(s, sizeof(s), "%.*s", size, p);
10821         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10822         if (ret < 0 || ret > max_num)
10823                 return -1;
10824         for (i = 0; i < ret; i++) {
10825                 errno = 0;
10826                 int_fld = strtoul(str_fld[i], &end, 0);
10827                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10828                         return -1;
10829                 offsets[i] = (uint16_t)int_fld;
10830         }
10831         return ret;
10832 }
10833
10834 static void
10835 cmd_flow_director_flxpld_parsed(void *parsed_result,
10836                           __attribute__((unused)) struct cmdline *cl,
10837                           __attribute__((unused)) void *data)
10838 {
10839         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10840         struct rte_eth_flex_payload_cfg flex_cfg;
10841         struct rte_port *port;
10842         int ret = 0;
10843
10844         if (res->port_id > nb_ports) {
10845                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10846                 return;
10847         }
10848
10849         port = &ports[res->port_id];
10850         /** Check if the port is not started **/
10851         if (port->port_status != RTE_PORT_STOPPED) {
10852                 printf("Please stop port %d first\n", res->port_id);
10853                 return;
10854         }
10855
10856         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10857
10858         if (!strcmp(res->payload_layer, "raw"))
10859                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10860         else if (!strcmp(res->payload_layer, "l2"))
10861                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10862         else if (!strcmp(res->payload_layer, "l3"))
10863                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10864         else if (!strcmp(res->payload_layer, "l4"))
10865                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10866
10867         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10868                             RTE_ETH_FDIR_MAX_FLEXLEN);
10869         if (ret < 0) {
10870                 printf("error: Cannot parse flex payload input.\n");
10871                 return;
10872         }
10873
10874         fdir_set_flex_payload(res->port_id, &flex_cfg);
10875         cmd_reconfig_device_queue(res->port_id, 1, 1);
10876 }
10877
10878 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10880                                  flow_director_flexpayload,
10881                                  "flow_director_flex_payload");
10882 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10883         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10884                               port_id, UINT16);
10885 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10886         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10887                                  payload_layer, "raw#l2#l3#l4");
10888 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10889         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10890                                  payload_cfg, NULL);
10891
10892 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10893         .f = cmd_flow_director_flxpld_parsed,
10894         .data = NULL,
10895         .help_str = "flow_director_flexpayload ... : "
10896                 "Set flow director's flex payload on NIC",
10897         .tokens = {
10898                 (void *)&cmd_flow_director_flexpayload,
10899                 (void *)&cmd_flow_director_flexpayload_port_id,
10900                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10901                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10902                 NULL,
10903         },
10904 };
10905
10906 /* Generic flow interface command. */
10907 extern cmdline_parse_inst_t cmd_flow;
10908
10909 /* *** Classification Filters Control *** */
10910 /* *** Get symmetric hash enable per port *** */
10911 struct cmd_get_sym_hash_ena_per_port_result {
10912         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10913         portid_t port_id;
10914 };
10915
10916 static void
10917 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10918                                  __rte_unused struct cmdline *cl,
10919                                  __rte_unused void *data)
10920 {
10921         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10922         struct rte_eth_hash_filter_info info;
10923         int ret;
10924
10925         if (rte_eth_dev_filter_supported(res->port_id,
10926                                 RTE_ETH_FILTER_HASH) < 0) {
10927                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10928                                                         res->port_id);
10929                 return;
10930         }
10931
10932         memset(&info, 0, sizeof(info));
10933         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10934         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10935                                                 RTE_ETH_FILTER_GET, &info);
10936
10937         if (ret < 0) {
10938                 printf("Cannot get symmetric hash enable per port "
10939                                         "on port %u\n", res->port_id);
10940                 return;
10941         }
10942
10943         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10944                                 "enabled" : "disabled", res->port_id);
10945 }
10946
10947 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10948         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10949                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10950 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10951         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10952                 port_id, UINT16);
10953
10954 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10955         .f = cmd_get_sym_hash_per_port_parsed,
10956         .data = NULL,
10957         .help_str = "get_sym_hash_ena_per_port <port_id>",
10958         .tokens = {
10959                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10960                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10961                 NULL,
10962         },
10963 };
10964
10965 /* *** Set symmetric hash enable per port *** */
10966 struct cmd_set_sym_hash_ena_per_port_result {
10967         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10968         cmdline_fixed_string_t enable;
10969         portid_t port_id;
10970 };
10971
10972 static void
10973 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10974                                  __rte_unused struct cmdline *cl,
10975                                  __rte_unused void *data)
10976 {
10977         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10978         struct rte_eth_hash_filter_info info;
10979         int ret;
10980
10981         if (rte_eth_dev_filter_supported(res->port_id,
10982                                 RTE_ETH_FILTER_HASH) < 0) {
10983                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10984                                                         res->port_id);
10985                 return;
10986         }
10987
10988         memset(&info, 0, sizeof(info));
10989         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10990         if (!strcmp(res->enable, "enable"))
10991                 info.info.enable = 1;
10992         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10993                                         RTE_ETH_FILTER_SET, &info);
10994         if (ret < 0) {
10995                 printf("Cannot set symmetric hash enable per port on "
10996                                         "port %u\n", res->port_id);
10997                 return;
10998         }
10999         printf("Symmetric hash has been set to %s on port %u\n",
11000                                         res->enable, res->port_id);
11001 }
11002
11003 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11004         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11005                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11006 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11007         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11008                 port_id, UINT16);
11009 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11010         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11011                 enable, "enable#disable");
11012
11013 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11014         .f = cmd_set_sym_hash_per_port_parsed,
11015         .data = NULL,
11016         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11017         .tokens = {
11018                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11019                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11020                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11021                 NULL,
11022         },
11023 };
11024
11025 /* Get global config of hash function */
11026 struct cmd_get_hash_global_config_result {
11027         cmdline_fixed_string_t get_hash_global_config;
11028         portid_t port_id;
11029 };
11030
11031 static char *
11032 flowtype_to_str(uint16_t ftype)
11033 {
11034         uint16_t i;
11035         static struct {
11036                 char str[16];
11037                 uint16_t ftype;
11038         } ftype_table[] = {
11039                 {"ipv4", RTE_ETH_FLOW_IPV4},
11040                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11041                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11042                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11043                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11044                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11045                 {"ipv6", RTE_ETH_FLOW_IPV6},
11046                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11047                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11048                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11049                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11050                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11051                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11052                 {"port", RTE_ETH_FLOW_PORT},
11053                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11054                 {"geneve", RTE_ETH_FLOW_GENEVE},
11055                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11056         };
11057
11058         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11059                 if (ftype_table[i].ftype == ftype)
11060                         return ftype_table[i].str;
11061         }
11062
11063         return NULL;
11064 }
11065
11066 static void
11067 cmd_get_hash_global_config_parsed(void *parsed_result,
11068                                   __rte_unused struct cmdline *cl,
11069                                   __rte_unused void *data)
11070 {
11071         struct cmd_get_hash_global_config_result *res = parsed_result;
11072         struct rte_eth_hash_filter_info info;
11073         uint32_t idx, offset;
11074         uint16_t i;
11075         char *str;
11076         int ret;
11077
11078         if (rte_eth_dev_filter_supported(res->port_id,
11079                         RTE_ETH_FILTER_HASH) < 0) {
11080                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11081                                                         res->port_id);
11082                 return;
11083         }
11084
11085         memset(&info, 0, sizeof(info));
11086         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11087         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11088                                         RTE_ETH_FILTER_GET, &info);
11089         if (ret < 0) {
11090                 printf("Cannot get hash global configurations by port %d\n",
11091                                                         res->port_id);
11092                 return;
11093         }
11094
11095         switch (info.info.global_conf.hash_func) {
11096         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11097                 printf("Hash function is Toeplitz\n");
11098                 break;
11099         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11100                 printf("Hash function is Simple XOR\n");
11101                 break;
11102         default:
11103                 printf("Unknown hash function\n");
11104                 break;
11105         }
11106
11107         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11108                 idx = i / UINT32_BIT;
11109                 offset = i % UINT32_BIT;
11110                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11111                                                 (1UL << offset)))
11112                         continue;
11113                 str = flowtype_to_str(i);
11114                 if (!str)
11115                         continue;
11116                 printf("Symmetric hash is %s globally for flow type %s "
11117                                                         "by port %d\n",
11118                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11119                         (1UL << offset)) ? "enabled" : "disabled"), str,
11120                                                         res->port_id);
11121         }
11122 }
11123
11124 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11125         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11126                 get_hash_global_config, "get_hash_global_config");
11127 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11128         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11129                 port_id, UINT16);
11130
11131 cmdline_parse_inst_t cmd_get_hash_global_config = {
11132         .f = cmd_get_hash_global_config_parsed,
11133         .data = NULL,
11134         .help_str = "get_hash_global_config <port_id>",
11135         .tokens = {
11136                 (void *)&cmd_get_hash_global_config_all,
11137                 (void *)&cmd_get_hash_global_config_port_id,
11138                 NULL,
11139         },
11140 };
11141
11142 /* Set global config of hash function */
11143 struct cmd_set_hash_global_config_result {
11144         cmdline_fixed_string_t set_hash_global_config;
11145         portid_t port_id;
11146         cmdline_fixed_string_t hash_func;
11147         cmdline_fixed_string_t flow_type;
11148         cmdline_fixed_string_t enable;
11149 };
11150
11151 static void
11152 cmd_set_hash_global_config_parsed(void *parsed_result,
11153                                   __rte_unused struct cmdline *cl,
11154                                   __rte_unused void *data)
11155 {
11156         struct cmd_set_hash_global_config_result *res = parsed_result;
11157         struct rte_eth_hash_filter_info info;
11158         uint32_t ftype, idx, offset;
11159         int ret;
11160
11161         if (rte_eth_dev_filter_supported(res->port_id,
11162                                 RTE_ETH_FILTER_HASH) < 0) {
11163                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11164                                                         res->port_id);
11165                 return;
11166         }
11167         memset(&info, 0, sizeof(info));
11168         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11169         if (!strcmp(res->hash_func, "toeplitz"))
11170                 info.info.global_conf.hash_func =
11171                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11172         else if (!strcmp(res->hash_func, "simple_xor"))
11173                 info.info.global_conf.hash_func =
11174                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11175         else if (!strcmp(res->hash_func, "default"))
11176                 info.info.global_conf.hash_func =
11177                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11178
11179         ftype = str2flowtype(res->flow_type);
11180         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11181         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11182         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11183         if (!strcmp(res->enable, "enable"))
11184                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11185                                                 (1UL << offset);
11186         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11187                                         RTE_ETH_FILTER_SET, &info);
11188         if (ret < 0)
11189                 printf("Cannot set global hash configurations by port %d\n",
11190                                                         res->port_id);
11191         else
11192                 printf("Global hash configurations have been set "
11193                         "succcessfully by port %d\n", res->port_id);
11194 }
11195
11196 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11197         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11198                 set_hash_global_config, "set_hash_global_config");
11199 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11200         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11201                 port_id, UINT16);
11202 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11203         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11204                 hash_func, "toeplitz#simple_xor#default");
11205 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11206         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11207                 flow_type,
11208                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11209                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11210 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11211         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11212                 enable, "enable#disable");
11213
11214 cmdline_parse_inst_t cmd_set_hash_global_config = {
11215         .f = cmd_set_hash_global_config_parsed,
11216         .data = NULL,
11217         .help_str = "set_hash_global_config <port_id> "
11218                 "toeplitz|simple_xor|default "
11219                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11220                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11221                 "l2_payload enable|disable",
11222         .tokens = {
11223                 (void *)&cmd_set_hash_global_config_all,
11224                 (void *)&cmd_set_hash_global_config_port_id,
11225                 (void *)&cmd_set_hash_global_config_hash_func,
11226                 (void *)&cmd_set_hash_global_config_flow_type,
11227                 (void *)&cmd_set_hash_global_config_enable,
11228                 NULL,
11229         },
11230 };
11231
11232 /* Set hash input set */
11233 struct cmd_set_hash_input_set_result {
11234         cmdline_fixed_string_t set_hash_input_set;
11235         portid_t port_id;
11236         cmdline_fixed_string_t flow_type;
11237         cmdline_fixed_string_t inset_field;
11238         cmdline_fixed_string_t select;
11239 };
11240
11241 static enum rte_eth_input_set_field
11242 str2inset(char *string)
11243 {
11244         uint16_t i;
11245
11246         static const struct {
11247                 char str[32];
11248                 enum rte_eth_input_set_field inset;
11249         } inset_table[] = {
11250                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11251                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11252                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11253                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11254                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11255                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11256                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11257                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11258                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11259                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11260                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11261                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11262                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11263                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11264                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11265                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11266                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11267                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11268                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11269                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11270                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11271                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11272                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11273                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11274                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11275                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11276                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11277                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11278                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11279                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11280                 {"none", RTE_ETH_INPUT_SET_NONE},
11281         };
11282
11283         for (i = 0; i < RTE_DIM(inset_table); i++) {
11284                 if (!strcmp(string, inset_table[i].str))
11285                         return inset_table[i].inset;
11286         }
11287
11288         return RTE_ETH_INPUT_SET_UNKNOWN;
11289 }
11290
11291 static void
11292 cmd_set_hash_input_set_parsed(void *parsed_result,
11293                               __rte_unused struct cmdline *cl,
11294                               __rte_unused void *data)
11295 {
11296         struct cmd_set_hash_input_set_result *res = parsed_result;
11297         struct rte_eth_hash_filter_info info;
11298
11299         memset(&info, 0, sizeof(info));
11300         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11301         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11302         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11303         info.info.input_set_conf.inset_size = 1;
11304         if (!strcmp(res->select, "select"))
11305                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11306         else if (!strcmp(res->select, "add"))
11307                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11308         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11309                                 RTE_ETH_FILTER_SET, &info);
11310 }
11311
11312 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11313         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11314                 set_hash_input_set, "set_hash_input_set");
11315 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11316         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11317                 port_id, UINT16);
11318 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11319         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11320                 flow_type, NULL);
11321 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11322         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11323                 inset_field,
11324                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11325                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11326                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11327                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11328                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11329                 "fld-8th#none");
11330 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11331         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11332                 select, "select#add");
11333
11334 cmdline_parse_inst_t cmd_set_hash_input_set = {
11335         .f = cmd_set_hash_input_set_parsed,
11336         .data = NULL,
11337         .help_str = "set_hash_input_set <port_id> "
11338         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11339         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11340         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11341         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11342         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11343         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11344         "fld-7th|fld-8th|none select|add",
11345         .tokens = {
11346                 (void *)&cmd_set_hash_input_set_cmd,
11347                 (void *)&cmd_set_hash_input_set_port_id,
11348                 (void *)&cmd_set_hash_input_set_flow_type,
11349                 (void *)&cmd_set_hash_input_set_field,
11350                 (void *)&cmd_set_hash_input_set_select,
11351                 NULL,
11352         },
11353 };
11354
11355 /* Set flow director input set */
11356 struct cmd_set_fdir_input_set_result {
11357         cmdline_fixed_string_t set_fdir_input_set;
11358         portid_t port_id;
11359         cmdline_fixed_string_t flow_type;
11360         cmdline_fixed_string_t inset_field;
11361         cmdline_fixed_string_t select;
11362 };
11363
11364 static void
11365 cmd_set_fdir_input_set_parsed(void *parsed_result,
11366         __rte_unused struct cmdline *cl,
11367         __rte_unused void *data)
11368 {
11369         struct cmd_set_fdir_input_set_result *res = parsed_result;
11370         struct rte_eth_fdir_filter_info info;
11371
11372         memset(&info, 0, sizeof(info));
11373         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11374         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11375         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11376         info.info.input_set_conf.inset_size = 1;
11377         if (!strcmp(res->select, "select"))
11378                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11379         else if (!strcmp(res->select, "add"))
11380                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11381         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11382                 RTE_ETH_FILTER_SET, &info);
11383 }
11384
11385 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11386         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11387         set_fdir_input_set, "set_fdir_input_set");
11388 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11389         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11390         port_id, UINT16);
11391 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11392         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11393         flow_type,
11394         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11395         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11396 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11397         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11398         inset_field,
11399         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11400         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11401         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11402         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11403         "sctp-veri-tag#none");
11404 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11405         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11406         select, "select#add");
11407
11408 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11409         .f = cmd_set_fdir_input_set_parsed,
11410         .data = NULL,
11411         .help_str = "set_fdir_input_set <port_id> "
11412         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11413         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11414         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11415         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11416         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11417         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11418         "sctp-veri-tag|none select|add",
11419         .tokens = {
11420                 (void *)&cmd_set_fdir_input_set_cmd,
11421                 (void *)&cmd_set_fdir_input_set_port_id,
11422                 (void *)&cmd_set_fdir_input_set_flow_type,
11423                 (void *)&cmd_set_fdir_input_set_field,
11424                 (void *)&cmd_set_fdir_input_set_select,
11425                 NULL,
11426         },
11427 };
11428
11429 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11430 struct cmd_mcast_addr_result {
11431         cmdline_fixed_string_t mcast_addr_cmd;
11432         cmdline_fixed_string_t what;
11433         uint16_t port_num;
11434         struct ether_addr mc_addr;
11435 };
11436
11437 static void cmd_mcast_addr_parsed(void *parsed_result,
11438                 __attribute__((unused)) struct cmdline *cl,
11439                 __attribute__((unused)) void *data)
11440 {
11441         struct cmd_mcast_addr_result *res = parsed_result;
11442
11443         if (!is_multicast_ether_addr(&res->mc_addr)) {
11444                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11445                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11446                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11447                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11448                 return;
11449         }
11450         if (strcmp(res->what, "add") == 0)
11451                 mcast_addr_add(res->port_num, &res->mc_addr);
11452         else
11453                 mcast_addr_remove(res->port_num, &res->mc_addr);
11454 }
11455
11456 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11457         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11458                                  mcast_addr_cmd, "mcast_addr");
11459 cmdline_parse_token_string_t cmd_mcast_addr_what =
11460         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11461                                  "add#remove");
11462 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11463         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11464 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11465         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11466
11467 cmdline_parse_inst_t cmd_mcast_addr = {
11468         .f = cmd_mcast_addr_parsed,
11469         .data = (void *)0,
11470         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11471                 "Add/Remove multicast MAC address on port_id",
11472         .tokens = {
11473                 (void *)&cmd_mcast_addr_cmd,
11474                 (void *)&cmd_mcast_addr_what,
11475                 (void *)&cmd_mcast_addr_portnum,
11476                 (void *)&cmd_mcast_addr_addr,
11477                 NULL,
11478         },
11479 };
11480
11481 /* l2 tunnel config
11482  * only support E-tag now.
11483  */
11484
11485 /* Ether type config */
11486 struct cmd_config_l2_tunnel_eth_type_result {
11487         cmdline_fixed_string_t port;
11488         cmdline_fixed_string_t config;
11489         cmdline_fixed_string_t all;
11490         uint8_t id;
11491         cmdline_fixed_string_t l2_tunnel;
11492         cmdline_fixed_string_t l2_tunnel_type;
11493         cmdline_fixed_string_t eth_type;
11494         uint16_t eth_type_val;
11495 };
11496
11497 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11498         TOKEN_STRING_INITIALIZER
11499                 (struct cmd_config_l2_tunnel_eth_type_result,
11500                  port, "port");
11501 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11502         TOKEN_STRING_INITIALIZER
11503                 (struct cmd_config_l2_tunnel_eth_type_result,
11504                  config, "config");
11505 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11506         TOKEN_STRING_INITIALIZER
11507                 (struct cmd_config_l2_tunnel_eth_type_result,
11508                  all, "all");
11509 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11510         TOKEN_NUM_INITIALIZER
11511                 (struct cmd_config_l2_tunnel_eth_type_result,
11512                  id, UINT8);
11513 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11514         TOKEN_STRING_INITIALIZER
11515                 (struct cmd_config_l2_tunnel_eth_type_result,
11516                  l2_tunnel, "l2-tunnel");
11517 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11518         TOKEN_STRING_INITIALIZER
11519                 (struct cmd_config_l2_tunnel_eth_type_result,
11520                  l2_tunnel_type, "E-tag");
11521 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_config_l2_tunnel_eth_type_result,
11524                  eth_type, "ether-type");
11525 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11526         TOKEN_NUM_INITIALIZER
11527                 (struct cmd_config_l2_tunnel_eth_type_result,
11528                  eth_type_val, UINT16);
11529
11530 static enum rte_eth_tunnel_type
11531 str2fdir_l2_tunnel_type(char *string)
11532 {
11533         uint32_t i = 0;
11534
11535         static const struct {
11536                 char str[32];
11537                 enum rte_eth_tunnel_type type;
11538         } l2_tunnel_type_str[] = {
11539                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11540         };
11541
11542         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11543                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11544                         return l2_tunnel_type_str[i].type;
11545         }
11546         return RTE_TUNNEL_TYPE_NONE;
11547 }
11548
11549 /* ether type config for all ports */
11550 static void
11551 cmd_config_l2_tunnel_eth_type_all_parsed
11552         (void *parsed_result,
11553          __attribute__((unused)) struct cmdline *cl,
11554          __attribute__((unused)) void *data)
11555 {
11556         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11557         struct rte_eth_l2_tunnel_conf entry;
11558         portid_t pid;
11559
11560         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11561         entry.ether_type = res->eth_type_val;
11562
11563         RTE_ETH_FOREACH_DEV(pid) {
11564                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11565         }
11566 }
11567
11568 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11569         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11570         .data = NULL,
11571         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11572         .tokens = {
11573                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11574                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11575                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11576                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11577                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11578                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11579                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11580                 NULL,
11581         },
11582 };
11583
11584 /* ether type config for a specific port */
11585 static void
11586 cmd_config_l2_tunnel_eth_type_specific_parsed(
11587         void *parsed_result,
11588         __attribute__((unused)) struct cmdline *cl,
11589         __attribute__((unused)) void *data)
11590 {
11591         struct cmd_config_l2_tunnel_eth_type_result *res =
11592                  parsed_result;
11593         struct rte_eth_l2_tunnel_conf entry;
11594
11595         if (port_id_is_invalid(res->id, ENABLED_WARN))
11596                 return;
11597
11598         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11599         entry.ether_type = res->eth_type_val;
11600
11601         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11602 }
11603
11604 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11605         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11606         .data = NULL,
11607         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11608         .tokens = {
11609                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11610                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11611                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11612                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11613                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11614                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11615                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11616                 NULL,
11617         },
11618 };
11619
11620 /* Enable/disable l2 tunnel */
11621 struct cmd_config_l2_tunnel_en_dis_result {
11622         cmdline_fixed_string_t port;
11623         cmdline_fixed_string_t config;
11624         cmdline_fixed_string_t all;
11625         uint8_t id;
11626         cmdline_fixed_string_t l2_tunnel;
11627         cmdline_fixed_string_t l2_tunnel_type;
11628         cmdline_fixed_string_t en_dis;
11629 };
11630
11631 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11632         TOKEN_STRING_INITIALIZER
11633                 (struct cmd_config_l2_tunnel_en_dis_result,
11634                  port, "port");
11635 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11636         TOKEN_STRING_INITIALIZER
11637                 (struct cmd_config_l2_tunnel_en_dis_result,
11638                  config, "config");
11639 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_config_l2_tunnel_en_dis_result,
11642                  all, "all");
11643 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11644         TOKEN_NUM_INITIALIZER
11645                 (struct cmd_config_l2_tunnel_en_dis_result,
11646                  id, UINT8);
11647 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11648         TOKEN_STRING_INITIALIZER
11649                 (struct cmd_config_l2_tunnel_en_dis_result,
11650                  l2_tunnel, "l2-tunnel");
11651 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11652         TOKEN_STRING_INITIALIZER
11653                 (struct cmd_config_l2_tunnel_en_dis_result,
11654                  l2_tunnel_type, "E-tag");
11655 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11656         TOKEN_STRING_INITIALIZER
11657                 (struct cmd_config_l2_tunnel_en_dis_result,
11658                  en_dis, "enable#disable");
11659
11660 /* enable/disable l2 tunnel for all ports */
11661 static void
11662 cmd_config_l2_tunnel_en_dis_all_parsed(
11663         void *parsed_result,
11664         __attribute__((unused)) struct cmdline *cl,
11665         __attribute__((unused)) void *data)
11666 {
11667         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11668         struct rte_eth_l2_tunnel_conf entry;
11669         portid_t pid;
11670         uint8_t en;
11671
11672         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11673
11674         if (!strcmp("enable", res->en_dis))
11675                 en = 1;
11676         else
11677                 en = 0;
11678
11679         RTE_ETH_FOREACH_DEV(pid) {
11680                 rte_eth_dev_l2_tunnel_offload_set(pid,
11681                                                   &entry,
11682                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11683                                                   en);
11684         }
11685 }
11686
11687 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11688         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11689         .data = NULL,
11690         .help_str = "port config all l2-tunnel E-tag enable|disable",
11691         .tokens = {
11692                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11693                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11694                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11695                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11696                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11697                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11698                 NULL,
11699         },
11700 };
11701
11702 /* enable/disable l2 tunnel for a port */
11703 static void
11704 cmd_config_l2_tunnel_en_dis_specific_parsed(
11705         void *parsed_result,
11706         __attribute__((unused)) struct cmdline *cl,
11707         __attribute__((unused)) void *data)
11708 {
11709         struct cmd_config_l2_tunnel_en_dis_result *res =
11710                 parsed_result;
11711         struct rte_eth_l2_tunnel_conf entry;
11712
11713         if (port_id_is_invalid(res->id, ENABLED_WARN))
11714                 return;
11715
11716         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11717
11718         if (!strcmp("enable", res->en_dis))
11719                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11720                                                   &entry,
11721                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11722                                                   1);
11723         else
11724                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11725                                                   &entry,
11726                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11727                                                   0);
11728 }
11729
11730 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11731         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11732         .data = NULL,
11733         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11734         .tokens = {
11735                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11736                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11737                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11738                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11739                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11740                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11741                 NULL,
11742         },
11743 };
11744
11745 /* E-tag configuration */
11746
11747 /* Common result structure for all E-tag configuration */
11748 struct cmd_config_e_tag_result {
11749         cmdline_fixed_string_t e_tag;
11750         cmdline_fixed_string_t set;
11751         cmdline_fixed_string_t insertion;
11752         cmdline_fixed_string_t stripping;
11753         cmdline_fixed_string_t forwarding;
11754         cmdline_fixed_string_t filter;
11755         cmdline_fixed_string_t add;
11756         cmdline_fixed_string_t del;
11757         cmdline_fixed_string_t on;
11758         cmdline_fixed_string_t off;
11759         cmdline_fixed_string_t on_off;
11760         cmdline_fixed_string_t port_tag_id;
11761         uint32_t port_tag_id_val;
11762         cmdline_fixed_string_t e_tag_id;
11763         uint16_t e_tag_id_val;
11764         cmdline_fixed_string_t dst_pool;
11765         uint8_t dst_pool_val;
11766         cmdline_fixed_string_t port;
11767         portid_t port_id;
11768         cmdline_fixed_string_t vf;
11769         uint8_t vf_id;
11770 };
11771
11772 /* Common CLI fields for all E-tag configuration */
11773 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11774         TOKEN_STRING_INITIALIZER
11775                 (struct cmd_config_e_tag_result,
11776                  e_tag, "E-tag");
11777 cmdline_parse_token_string_t cmd_config_e_tag_set =
11778         TOKEN_STRING_INITIALIZER
11779                 (struct cmd_config_e_tag_result,
11780                  set, "set");
11781 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11782         TOKEN_STRING_INITIALIZER
11783                 (struct cmd_config_e_tag_result,
11784                  insertion, "insertion");
11785 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11786         TOKEN_STRING_INITIALIZER
11787                 (struct cmd_config_e_tag_result,
11788                  stripping, "stripping");
11789 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11790         TOKEN_STRING_INITIALIZER
11791                 (struct cmd_config_e_tag_result,
11792                  forwarding, "forwarding");
11793 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11794         TOKEN_STRING_INITIALIZER
11795                 (struct cmd_config_e_tag_result,
11796                  filter, "filter");
11797 cmdline_parse_token_string_t cmd_config_e_tag_add =
11798         TOKEN_STRING_INITIALIZER
11799                 (struct cmd_config_e_tag_result,
11800                  add, "add");
11801 cmdline_parse_token_string_t cmd_config_e_tag_del =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_config_e_tag_result,
11804                  del, "del");
11805 cmdline_parse_token_string_t cmd_config_e_tag_on =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_config_e_tag_result,
11808                  on, "on");
11809 cmdline_parse_token_string_t cmd_config_e_tag_off =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_config_e_tag_result,
11812                  off, "off");
11813 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_config_e_tag_result,
11816                  on_off, "on#off");
11817 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11818         TOKEN_STRING_INITIALIZER
11819                 (struct cmd_config_e_tag_result,
11820                  port_tag_id, "port-tag-id");
11821 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11822         TOKEN_NUM_INITIALIZER
11823                 (struct cmd_config_e_tag_result,
11824                  port_tag_id_val, UINT32);
11825 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11826         TOKEN_STRING_INITIALIZER
11827                 (struct cmd_config_e_tag_result,
11828                  e_tag_id, "e-tag-id");
11829 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11830         TOKEN_NUM_INITIALIZER
11831                 (struct cmd_config_e_tag_result,
11832                  e_tag_id_val, UINT16);
11833 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11834         TOKEN_STRING_INITIALIZER
11835                 (struct cmd_config_e_tag_result,
11836                  dst_pool, "dst-pool");
11837 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11838         TOKEN_NUM_INITIALIZER
11839                 (struct cmd_config_e_tag_result,
11840                  dst_pool_val, UINT8);
11841 cmdline_parse_token_string_t cmd_config_e_tag_port =
11842         TOKEN_STRING_INITIALIZER
11843                 (struct cmd_config_e_tag_result,
11844                  port, "port");
11845 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11846         TOKEN_NUM_INITIALIZER
11847                 (struct cmd_config_e_tag_result,
11848                  port_id, UINT16);
11849 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11850         TOKEN_STRING_INITIALIZER
11851                 (struct cmd_config_e_tag_result,
11852                  vf, "vf");
11853 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11854         TOKEN_NUM_INITIALIZER
11855                 (struct cmd_config_e_tag_result,
11856                  vf_id, UINT8);
11857
11858 /* E-tag insertion configuration */
11859 static void
11860 cmd_config_e_tag_insertion_en_parsed(
11861         void *parsed_result,
11862         __attribute__((unused)) struct cmdline *cl,
11863         __attribute__((unused)) void *data)
11864 {
11865         struct cmd_config_e_tag_result *res =
11866                 parsed_result;
11867         struct rte_eth_l2_tunnel_conf entry;
11868
11869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11870                 return;
11871
11872         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11873         entry.tunnel_id = res->port_tag_id_val;
11874         entry.vf_id = res->vf_id;
11875         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11876                                           &entry,
11877                                           ETH_L2_TUNNEL_INSERTION_MASK,
11878                                           1);
11879 }
11880
11881 static void
11882 cmd_config_e_tag_insertion_dis_parsed(
11883         void *parsed_result,
11884         __attribute__((unused)) struct cmdline *cl,
11885         __attribute__((unused)) void *data)
11886 {
11887         struct cmd_config_e_tag_result *res =
11888                 parsed_result;
11889         struct rte_eth_l2_tunnel_conf entry;
11890
11891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11892                 return;
11893
11894         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11895         entry.vf_id = res->vf_id;
11896
11897         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11898                                           &entry,
11899                                           ETH_L2_TUNNEL_INSERTION_MASK,
11900                                           0);
11901 }
11902
11903 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11904         .f = cmd_config_e_tag_insertion_en_parsed,
11905         .data = NULL,
11906         .help_str = "E-tag ... : E-tag insertion enable",
11907         .tokens = {
11908                 (void *)&cmd_config_e_tag_e_tag,
11909                 (void *)&cmd_config_e_tag_set,
11910                 (void *)&cmd_config_e_tag_insertion,
11911                 (void *)&cmd_config_e_tag_on,
11912                 (void *)&cmd_config_e_tag_port_tag_id,
11913                 (void *)&cmd_config_e_tag_port_tag_id_val,
11914                 (void *)&cmd_config_e_tag_port,
11915                 (void *)&cmd_config_e_tag_port_id,
11916                 (void *)&cmd_config_e_tag_vf,
11917                 (void *)&cmd_config_e_tag_vf_id,
11918                 NULL,
11919         },
11920 };
11921
11922 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11923         .f = cmd_config_e_tag_insertion_dis_parsed,
11924         .data = NULL,
11925         .help_str = "E-tag ... : E-tag insertion disable",
11926         .tokens = {
11927                 (void *)&cmd_config_e_tag_e_tag,
11928                 (void *)&cmd_config_e_tag_set,
11929                 (void *)&cmd_config_e_tag_insertion,
11930                 (void *)&cmd_config_e_tag_off,
11931                 (void *)&cmd_config_e_tag_port,
11932                 (void *)&cmd_config_e_tag_port_id,
11933                 (void *)&cmd_config_e_tag_vf,
11934                 (void *)&cmd_config_e_tag_vf_id,
11935                 NULL,
11936         },
11937 };
11938
11939 /* E-tag stripping configuration */
11940 static void
11941 cmd_config_e_tag_stripping_parsed(
11942         void *parsed_result,
11943         __attribute__((unused)) struct cmdline *cl,
11944         __attribute__((unused)) void *data)
11945 {
11946         struct cmd_config_e_tag_result *res =
11947                 parsed_result;
11948         struct rte_eth_l2_tunnel_conf entry;
11949
11950         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11951                 return;
11952
11953         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11954
11955         if (!strcmp(res->on_off, "on"))
11956                 rte_eth_dev_l2_tunnel_offload_set
11957                         (res->port_id,
11958                          &entry,
11959                          ETH_L2_TUNNEL_STRIPPING_MASK,
11960                          1);
11961         else
11962                 rte_eth_dev_l2_tunnel_offload_set
11963                         (res->port_id,
11964                          &entry,
11965                          ETH_L2_TUNNEL_STRIPPING_MASK,
11966                          0);
11967 }
11968
11969 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11970         .f = cmd_config_e_tag_stripping_parsed,
11971         .data = NULL,
11972         .help_str = "E-tag ... : E-tag stripping enable/disable",
11973         .tokens = {
11974                 (void *)&cmd_config_e_tag_e_tag,
11975                 (void *)&cmd_config_e_tag_set,
11976                 (void *)&cmd_config_e_tag_stripping,
11977                 (void *)&cmd_config_e_tag_on_off,
11978                 (void *)&cmd_config_e_tag_port,
11979                 (void *)&cmd_config_e_tag_port_id,
11980                 NULL,
11981         },
11982 };
11983
11984 /* E-tag forwarding configuration */
11985 static void
11986 cmd_config_e_tag_forwarding_parsed(
11987         void *parsed_result,
11988         __attribute__((unused)) struct cmdline *cl,
11989         __attribute__((unused)) void *data)
11990 {
11991         struct cmd_config_e_tag_result *res = parsed_result;
11992         struct rte_eth_l2_tunnel_conf entry;
11993
11994         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11995                 return;
11996
11997         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11998
11999         if (!strcmp(res->on_off, "on"))
12000                 rte_eth_dev_l2_tunnel_offload_set
12001                         (res->port_id,
12002                          &entry,
12003                          ETH_L2_TUNNEL_FORWARDING_MASK,
12004                          1);
12005         else
12006                 rte_eth_dev_l2_tunnel_offload_set
12007                         (res->port_id,
12008                          &entry,
12009                          ETH_L2_TUNNEL_FORWARDING_MASK,
12010                          0);
12011 }
12012
12013 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12014         .f = cmd_config_e_tag_forwarding_parsed,
12015         .data = NULL,
12016         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12017         .tokens = {
12018                 (void *)&cmd_config_e_tag_e_tag,
12019                 (void *)&cmd_config_e_tag_set,
12020                 (void *)&cmd_config_e_tag_forwarding,
12021                 (void *)&cmd_config_e_tag_on_off,
12022                 (void *)&cmd_config_e_tag_port,
12023                 (void *)&cmd_config_e_tag_port_id,
12024                 NULL,
12025         },
12026 };
12027
12028 /* E-tag filter configuration */
12029 static void
12030 cmd_config_e_tag_filter_add_parsed(
12031         void *parsed_result,
12032         __attribute__((unused)) struct cmdline *cl,
12033         __attribute__((unused)) void *data)
12034 {
12035         struct cmd_config_e_tag_result *res = parsed_result;
12036         struct rte_eth_l2_tunnel_conf entry;
12037         int ret = 0;
12038
12039         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12040                 return;
12041
12042         if (res->e_tag_id_val > 0x3fff) {
12043                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12044                 return;
12045         }
12046
12047         ret = rte_eth_dev_filter_supported(res->port_id,
12048                                            RTE_ETH_FILTER_L2_TUNNEL);
12049         if (ret < 0) {
12050                 printf("E-tag filter is not supported on port %u.\n",
12051                        res->port_id);
12052                 return;
12053         }
12054
12055         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12056         entry.tunnel_id = res->e_tag_id_val;
12057         entry.pool = res->dst_pool_val;
12058
12059         ret = rte_eth_dev_filter_ctrl(res->port_id,
12060                                       RTE_ETH_FILTER_L2_TUNNEL,
12061                                       RTE_ETH_FILTER_ADD,
12062                                       &entry);
12063         if (ret < 0)
12064                 printf("E-tag filter programming error: (%s)\n",
12065                        strerror(-ret));
12066 }
12067
12068 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12069         .f = cmd_config_e_tag_filter_add_parsed,
12070         .data = NULL,
12071         .help_str = "E-tag ... : E-tag filter add",
12072         .tokens = {
12073                 (void *)&cmd_config_e_tag_e_tag,
12074                 (void *)&cmd_config_e_tag_set,
12075                 (void *)&cmd_config_e_tag_filter,
12076                 (void *)&cmd_config_e_tag_add,
12077                 (void *)&cmd_config_e_tag_e_tag_id,
12078                 (void *)&cmd_config_e_tag_e_tag_id_val,
12079                 (void *)&cmd_config_e_tag_dst_pool,
12080                 (void *)&cmd_config_e_tag_dst_pool_val,
12081                 (void *)&cmd_config_e_tag_port,
12082                 (void *)&cmd_config_e_tag_port_id,
12083                 NULL,
12084         },
12085 };
12086
12087 static void
12088 cmd_config_e_tag_filter_del_parsed(
12089         void *parsed_result,
12090         __attribute__((unused)) struct cmdline *cl,
12091         __attribute__((unused)) void *data)
12092 {
12093         struct cmd_config_e_tag_result *res = parsed_result;
12094         struct rte_eth_l2_tunnel_conf entry;
12095         int ret = 0;
12096
12097         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12098                 return;
12099
12100         if (res->e_tag_id_val > 0x3fff) {
12101                 printf("e-tag-id must be less than 0x3fff.\n");
12102                 return;
12103         }
12104
12105         ret = rte_eth_dev_filter_supported(res->port_id,
12106                                            RTE_ETH_FILTER_L2_TUNNEL);
12107         if (ret < 0) {
12108                 printf("E-tag filter is not supported on port %u.\n",
12109                        res->port_id);
12110                 return;
12111         }
12112
12113         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12114         entry.tunnel_id = res->e_tag_id_val;
12115
12116         ret = rte_eth_dev_filter_ctrl(res->port_id,
12117                                       RTE_ETH_FILTER_L2_TUNNEL,
12118                                       RTE_ETH_FILTER_DELETE,
12119                                       &entry);
12120         if (ret < 0)
12121                 printf("E-tag filter programming error: (%s)\n",
12122                        strerror(-ret));
12123 }
12124
12125 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12126         .f = cmd_config_e_tag_filter_del_parsed,
12127         .data = NULL,
12128         .help_str = "E-tag ... : E-tag filter delete",
12129         .tokens = {
12130                 (void *)&cmd_config_e_tag_e_tag,
12131                 (void *)&cmd_config_e_tag_set,
12132                 (void *)&cmd_config_e_tag_filter,
12133                 (void *)&cmd_config_e_tag_del,
12134                 (void *)&cmd_config_e_tag_e_tag_id,
12135                 (void *)&cmd_config_e_tag_e_tag_id_val,
12136                 (void *)&cmd_config_e_tag_port,
12137                 (void *)&cmd_config_e_tag_port_id,
12138                 NULL,
12139         },
12140 };
12141
12142 /* vf vlan anti spoof configuration */
12143
12144 /* Common result structure for vf vlan anti spoof */
12145 struct cmd_vf_vlan_anti_spoof_result {
12146         cmdline_fixed_string_t set;
12147         cmdline_fixed_string_t vf;
12148         cmdline_fixed_string_t vlan;
12149         cmdline_fixed_string_t antispoof;
12150         portid_t port_id;
12151         uint32_t vf_id;
12152         cmdline_fixed_string_t on_off;
12153 };
12154
12155 /* Common CLI fields for vf vlan anti spoof enable disable */
12156 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12157         TOKEN_STRING_INITIALIZER
12158                 (struct cmd_vf_vlan_anti_spoof_result,
12159                  set, "set");
12160 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12161         TOKEN_STRING_INITIALIZER
12162                 (struct cmd_vf_vlan_anti_spoof_result,
12163                  vf, "vf");
12164 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12165         TOKEN_STRING_INITIALIZER
12166                 (struct cmd_vf_vlan_anti_spoof_result,
12167                  vlan, "vlan");
12168 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12169         TOKEN_STRING_INITIALIZER
12170                 (struct cmd_vf_vlan_anti_spoof_result,
12171                  antispoof, "antispoof");
12172 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12173         TOKEN_NUM_INITIALIZER
12174                 (struct cmd_vf_vlan_anti_spoof_result,
12175                  port_id, UINT16);
12176 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12177         TOKEN_NUM_INITIALIZER
12178                 (struct cmd_vf_vlan_anti_spoof_result,
12179                  vf_id, UINT32);
12180 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12181         TOKEN_STRING_INITIALIZER
12182                 (struct cmd_vf_vlan_anti_spoof_result,
12183                  on_off, "on#off");
12184
12185 static void
12186 cmd_set_vf_vlan_anti_spoof_parsed(
12187         void *parsed_result,
12188         __attribute__((unused)) struct cmdline *cl,
12189         __attribute__((unused)) void *data)
12190 {
12191         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12192         int ret = -ENOTSUP;
12193
12194         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12195
12196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12197                 return;
12198
12199 #ifdef RTE_LIBRTE_IXGBE_PMD
12200         if (ret == -ENOTSUP)
12201                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12202                                 res->vf_id, is_on);
12203 #endif
12204 #ifdef RTE_LIBRTE_I40E_PMD
12205         if (ret == -ENOTSUP)
12206                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12207                                 res->vf_id, is_on);
12208 #endif
12209 #ifdef RTE_LIBRTE_BNXT_PMD
12210         if (ret == -ENOTSUP)
12211                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12212                                 res->vf_id, is_on);
12213 #endif
12214
12215         switch (ret) {
12216         case 0:
12217                 break;
12218         case -EINVAL:
12219                 printf("invalid vf_id %d\n", res->vf_id);
12220                 break;
12221         case -ENODEV:
12222                 printf("invalid port_id %d\n", res->port_id);
12223                 break;
12224         case -ENOTSUP:
12225                 printf("function not implemented\n");
12226                 break;
12227         default:
12228                 printf("programming error: (%s)\n", strerror(-ret));
12229         }
12230 }
12231
12232 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12233         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12234         .data = NULL,
12235         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12236         .tokens = {
12237                 (void *)&cmd_vf_vlan_anti_spoof_set,
12238                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12239                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12240                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12241                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12242                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12243                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12244                 NULL,
12245         },
12246 };
12247
12248 /* vf mac anti spoof configuration */
12249
12250 /* Common result structure for vf mac anti spoof */
12251 struct cmd_vf_mac_anti_spoof_result {
12252         cmdline_fixed_string_t set;
12253         cmdline_fixed_string_t vf;
12254         cmdline_fixed_string_t mac;
12255         cmdline_fixed_string_t antispoof;
12256         portid_t port_id;
12257         uint32_t vf_id;
12258         cmdline_fixed_string_t on_off;
12259 };
12260
12261 /* Common CLI fields for vf mac anti spoof enable disable */
12262 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12263         TOKEN_STRING_INITIALIZER
12264                 (struct cmd_vf_mac_anti_spoof_result,
12265                  set, "set");
12266 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12267         TOKEN_STRING_INITIALIZER
12268                 (struct cmd_vf_mac_anti_spoof_result,
12269                  vf, "vf");
12270 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12271         TOKEN_STRING_INITIALIZER
12272                 (struct cmd_vf_mac_anti_spoof_result,
12273                  mac, "mac");
12274 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12275         TOKEN_STRING_INITIALIZER
12276                 (struct cmd_vf_mac_anti_spoof_result,
12277                  antispoof, "antispoof");
12278 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12279         TOKEN_NUM_INITIALIZER
12280                 (struct cmd_vf_mac_anti_spoof_result,
12281                  port_id, UINT16);
12282 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12283         TOKEN_NUM_INITIALIZER
12284                 (struct cmd_vf_mac_anti_spoof_result,
12285                  vf_id, UINT32);
12286 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12287         TOKEN_STRING_INITIALIZER
12288                 (struct cmd_vf_mac_anti_spoof_result,
12289                  on_off, "on#off");
12290
12291 static void
12292 cmd_set_vf_mac_anti_spoof_parsed(
12293         void *parsed_result,
12294         __attribute__((unused)) struct cmdline *cl,
12295         __attribute__((unused)) void *data)
12296 {
12297         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12298         int ret = -ENOTSUP;
12299
12300         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12301
12302         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12303                 return;
12304
12305 #ifdef RTE_LIBRTE_IXGBE_PMD
12306         if (ret == -ENOTSUP)
12307                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12308                         res->vf_id, is_on);
12309 #endif
12310 #ifdef RTE_LIBRTE_I40E_PMD
12311         if (ret == -ENOTSUP)
12312                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12313                         res->vf_id, is_on);
12314 #endif
12315 #ifdef RTE_LIBRTE_BNXT_PMD
12316         if (ret == -ENOTSUP)
12317                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12318                         res->vf_id, is_on);
12319 #endif
12320
12321         switch (ret) {
12322         case 0:
12323                 break;
12324         case -EINVAL:
12325                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12326                 break;
12327         case -ENODEV:
12328                 printf("invalid port_id %d\n", res->port_id);
12329                 break;
12330         case -ENOTSUP:
12331                 printf("function not implemented\n");
12332                 break;
12333         default:
12334                 printf("programming error: (%s)\n", strerror(-ret));
12335         }
12336 }
12337
12338 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12339         .f = cmd_set_vf_mac_anti_spoof_parsed,
12340         .data = NULL,
12341         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12342         .tokens = {
12343                 (void *)&cmd_vf_mac_anti_spoof_set,
12344                 (void *)&cmd_vf_mac_anti_spoof_vf,
12345                 (void *)&cmd_vf_mac_anti_spoof_mac,
12346                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12347                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12348                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12349                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12350                 NULL,
12351         },
12352 };
12353
12354 /* vf vlan strip queue configuration */
12355
12356 /* Common result structure for vf mac anti spoof */
12357 struct cmd_vf_vlan_stripq_result {
12358         cmdline_fixed_string_t set;
12359         cmdline_fixed_string_t vf;
12360         cmdline_fixed_string_t vlan;
12361         cmdline_fixed_string_t stripq;
12362         portid_t port_id;
12363         uint16_t vf_id;
12364         cmdline_fixed_string_t on_off;
12365 };
12366
12367 /* Common CLI fields for vf vlan strip enable disable */
12368 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12369         TOKEN_STRING_INITIALIZER
12370                 (struct cmd_vf_vlan_stripq_result,
12371                  set, "set");
12372 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12373         TOKEN_STRING_INITIALIZER
12374                 (struct cmd_vf_vlan_stripq_result,
12375                  vf, "vf");
12376 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_vf_vlan_stripq_result,
12379                  vlan, "vlan");
12380 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12381         TOKEN_STRING_INITIALIZER
12382                 (struct cmd_vf_vlan_stripq_result,
12383                  stripq, "stripq");
12384 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12385         TOKEN_NUM_INITIALIZER
12386                 (struct cmd_vf_vlan_stripq_result,
12387                  port_id, UINT16);
12388 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12389         TOKEN_NUM_INITIALIZER
12390                 (struct cmd_vf_vlan_stripq_result,
12391                  vf_id, UINT16);
12392 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12393         TOKEN_STRING_INITIALIZER
12394                 (struct cmd_vf_vlan_stripq_result,
12395                  on_off, "on#off");
12396
12397 static void
12398 cmd_set_vf_vlan_stripq_parsed(
12399         void *parsed_result,
12400         __attribute__((unused)) struct cmdline *cl,
12401         __attribute__((unused)) void *data)
12402 {
12403         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12404         int ret = -ENOTSUP;
12405
12406         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12407
12408         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12409                 return;
12410
12411 #ifdef RTE_LIBRTE_IXGBE_PMD
12412         if (ret == -ENOTSUP)
12413                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12414                         res->vf_id, is_on);
12415 #endif
12416 #ifdef RTE_LIBRTE_I40E_PMD
12417         if (ret == -ENOTSUP)
12418                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12419                         res->vf_id, is_on);
12420 #endif
12421 #ifdef RTE_LIBRTE_BNXT_PMD
12422         if (ret == -ENOTSUP)
12423                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12424                         res->vf_id, is_on);
12425 #endif
12426
12427         switch (ret) {
12428         case 0:
12429                 break;
12430         case -EINVAL:
12431                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12432                 break;
12433         case -ENODEV:
12434                 printf("invalid port_id %d\n", res->port_id);
12435                 break;
12436         case -ENOTSUP:
12437                 printf("function not implemented\n");
12438                 break;
12439         default:
12440                 printf("programming error: (%s)\n", strerror(-ret));
12441         }
12442 }
12443
12444 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12445         .f = cmd_set_vf_vlan_stripq_parsed,
12446         .data = NULL,
12447         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12448         .tokens = {
12449                 (void *)&cmd_vf_vlan_stripq_set,
12450                 (void *)&cmd_vf_vlan_stripq_vf,
12451                 (void *)&cmd_vf_vlan_stripq_vlan,
12452                 (void *)&cmd_vf_vlan_stripq_stripq,
12453                 (void *)&cmd_vf_vlan_stripq_port_id,
12454                 (void *)&cmd_vf_vlan_stripq_vf_id,
12455                 (void *)&cmd_vf_vlan_stripq_on_off,
12456                 NULL,
12457         },
12458 };
12459
12460 /* vf vlan insert configuration */
12461
12462 /* Common result structure for vf vlan insert */
12463 struct cmd_vf_vlan_insert_result {
12464         cmdline_fixed_string_t set;
12465         cmdline_fixed_string_t vf;
12466         cmdline_fixed_string_t vlan;
12467         cmdline_fixed_string_t insert;
12468         portid_t port_id;
12469         uint16_t vf_id;
12470         uint16_t vlan_id;
12471 };
12472
12473 /* Common CLI fields for vf vlan insert enable disable */
12474 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12475         TOKEN_STRING_INITIALIZER
12476                 (struct cmd_vf_vlan_insert_result,
12477                  set, "set");
12478 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_vf_vlan_insert_result,
12481                  vf, "vf");
12482 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_vf_vlan_insert_result,
12485                  vlan, "vlan");
12486 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_vf_vlan_insert_result,
12489                  insert, "insert");
12490 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12491         TOKEN_NUM_INITIALIZER
12492                 (struct cmd_vf_vlan_insert_result,
12493                  port_id, UINT16);
12494 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12495         TOKEN_NUM_INITIALIZER
12496                 (struct cmd_vf_vlan_insert_result,
12497                  vf_id, UINT16);
12498 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12499         TOKEN_NUM_INITIALIZER
12500                 (struct cmd_vf_vlan_insert_result,
12501                  vlan_id, UINT16);
12502
12503 static void
12504 cmd_set_vf_vlan_insert_parsed(
12505         void *parsed_result,
12506         __attribute__((unused)) struct cmdline *cl,
12507         __attribute__((unused)) void *data)
12508 {
12509         struct cmd_vf_vlan_insert_result *res = parsed_result;
12510         int ret = -ENOTSUP;
12511
12512         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12513                 return;
12514
12515 #ifdef RTE_LIBRTE_IXGBE_PMD
12516         if (ret == -ENOTSUP)
12517                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12518                         res->vlan_id);
12519 #endif
12520 #ifdef RTE_LIBRTE_I40E_PMD
12521         if (ret == -ENOTSUP)
12522                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12523                         res->vlan_id);
12524 #endif
12525 #ifdef RTE_LIBRTE_BNXT_PMD
12526         if (ret == -ENOTSUP)
12527                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12528                         res->vlan_id);
12529 #endif
12530
12531         switch (ret) {
12532         case 0:
12533                 break;
12534         case -EINVAL:
12535                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12536                 break;
12537         case -ENODEV:
12538                 printf("invalid port_id %d\n", res->port_id);
12539                 break;
12540         case -ENOTSUP:
12541                 printf("function not implemented\n");
12542                 break;
12543         default:
12544                 printf("programming error: (%s)\n", strerror(-ret));
12545         }
12546 }
12547
12548 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12549         .f = cmd_set_vf_vlan_insert_parsed,
12550         .data = NULL,
12551         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12552         .tokens = {
12553                 (void *)&cmd_vf_vlan_insert_set,
12554                 (void *)&cmd_vf_vlan_insert_vf,
12555                 (void *)&cmd_vf_vlan_insert_vlan,
12556                 (void *)&cmd_vf_vlan_insert_insert,
12557                 (void *)&cmd_vf_vlan_insert_port_id,
12558                 (void *)&cmd_vf_vlan_insert_vf_id,
12559                 (void *)&cmd_vf_vlan_insert_vlan_id,
12560                 NULL,
12561         },
12562 };
12563
12564 /* tx loopback configuration */
12565
12566 /* Common result structure for tx loopback */
12567 struct cmd_tx_loopback_result {
12568         cmdline_fixed_string_t set;
12569         cmdline_fixed_string_t tx;
12570         cmdline_fixed_string_t loopback;
12571         portid_t port_id;
12572         cmdline_fixed_string_t on_off;
12573 };
12574
12575 /* Common CLI fields for tx loopback enable disable */
12576 cmdline_parse_token_string_t cmd_tx_loopback_set =
12577         TOKEN_STRING_INITIALIZER
12578                 (struct cmd_tx_loopback_result,
12579                  set, "set");
12580 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12581         TOKEN_STRING_INITIALIZER
12582                 (struct cmd_tx_loopback_result,
12583                  tx, "tx");
12584 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12585         TOKEN_STRING_INITIALIZER
12586                 (struct cmd_tx_loopback_result,
12587                  loopback, "loopback");
12588 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12589         TOKEN_NUM_INITIALIZER
12590                 (struct cmd_tx_loopback_result,
12591                  port_id, UINT16);
12592 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12593         TOKEN_STRING_INITIALIZER
12594                 (struct cmd_tx_loopback_result,
12595                  on_off, "on#off");
12596
12597 static void
12598 cmd_set_tx_loopback_parsed(
12599         void *parsed_result,
12600         __attribute__((unused)) struct cmdline *cl,
12601         __attribute__((unused)) void *data)
12602 {
12603         struct cmd_tx_loopback_result *res = parsed_result;
12604         int ret = -ENOTSUP;
12605
12606         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12607
12608         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12609                 return;
12610
12611 #ifdef RTE_LIBRTE_IXGBE_PMD
12612         if (ret == -ENOTSUP)
12613                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12614 #endif
12615 #ifdef RTE_LIBRTE_I40E_PMD
12616         if (ret == -ENOTSUP)
12617                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12618 #endif
12619 #ifdef RTE_LIBRTE_BNXT_PMD
12620         if (ret == -ENOTSUP)
12621                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12622 #endif
12623
12624         switch (ret) {
12625         case 0:
12626                 break;
12627         case -EINVAL:
12628                 printf("invalid is_on %d\n", is_on);
12629                 break;
12630         case -ENODEV:
12631                 printf("invalid port_id %d\n", res->port_id);
12632                 break;
12633         case -ENOTSUP:
12634                 printf("function not implemented\n");
12635                 break;
12636         default:
12637                 printf("programming error: (%s)\n", strerror(-ret));
12638         }
12639 }
12640
12641 cmdline_parse_inst_t cmd_set_tx_loopback = {
12642         .f = cmd_set_tx_loopback_parsed,
12643         .data = NULL,
12644         .help_str = "set tx loopback <port_id> on|off",
12645         .tokens = {
12646                 (void *)&cmd_tx_loopback_set,
12647                 (void *)&cmd_tx_loopback_tx,
12648                 (void *)&cmd_tx_loopback_loopback,
12649                 (void *)&cmd_tx_loopback_port_id,
12650                 (void *)&cmd_tx_loopback_on_off,
12651                 NULL,
12652         },
12653 };
12654
12655 /* all queues drop enable configuration */
12656
12657 /* Common result structure for all queues drop enable */
12658 struct cmd_all_queues_drop_en_result {
12659         cmdline_fixed_string_t set;
12660         cmdline_fixed_string_t all;
12661         cmdline_fixed_string_t queues;
12662         cmdline_fixed_string_t drop;
12663         portid_t port_id;
12664         cmdline_fixed_string_t on_off;
12665 };
12666
12667 /* Common CLI fields for tx loopback enable disable */
12668 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12669         TOKEN_STRING_INITIALIZER
12670                 (struct cmd_all_queues_drop_en_result,
12671                  set, "set");
12672 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12673         TOKEN_STRING_INITIALIZER
12674                 (struct cmd_all_queues_drop_en_result,
12675                  all, "all");
12676 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12677         TOKEN_STRING_INITIALIZER
12678                 (struct cmd_all_queues_drop_en_result,
12679                  queues, "queues");
12680 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12681         TOKEN_STRING_INITIALIZER
12682                 (struct cmd_all_queues_drop_en_result,
12683                  drop, "drop");
12684 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12685         TOKEN_NUM_INITIALIZER
12686                 (struct cmd_all_queues_drop_en_result,
12687                  port_id, UINT16);
12688 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12689         TOKEN_STRING_INITIALIZER
12690                 (struct cmd_all_queues_drop_en_result,
12691                  on_off, "on#off");
12692
12693 static void
12694 cmd_set_all_queues_drop_en_parsed(
12695         void *parsed_result,
12696         __attribute__((unused)) struct cmdline *cl,
12697         __attribute__((unused)) void *data)
12698 {
12699         struct cmd_all_queues_drop_en_result *res = parsed_result;
12700         int ret = -ENOTSUP;
12701         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12702
12703         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12704                 return;
12705
12706 #ifdef RTE_LIBRTE_IXGBE_PMD
12707         if (ret == -ENOTSUP)
12708                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12709 #endif
12710 #ifdef RTE_LIBRTE_BNXT_PMD
12711         if (ret == -ENOTSUP)
12712                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12713 #endif
12714         switch (ret) {
12715         case 0:
12716                 break;
12717         case -EINVAL:
12718                 printf("invalid is_on %d\n", is_on);
12719                 break;
12720         case -ENODEV:
12721                 printf("invalid port_id %d\n", res->port_id);
12722                 break;
12723         case -ENOTSUP:
12724                 printf("function not implemented\n");
12725                 break;
12726         default:
12727                 printf("programming error: (%s)\n", strerror(-ret));
12728         }
12729 }
12730
12731 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12732         .f = cmd_set_all_queues_drop_en_parsed,
12733         .data = NULL,
12734         .help_str = "set all queues drop <port_id> on|off",
12735         .tokens = {
12736                 (void *)&cmd_all_queues_drop_en_set,
12737                 (void *)&cmd_all_queues_drop_en_all,
12738                 (void *)&cmd_all_queues_drop_en_queues,
12739                 (void *)&cmd_all_queues_drop_en_drop,
12740                 (void *)&cmd_all_queues_drop_en_port_id,
12741                 (void *)&cmd_all_queues_drop_en_on_off,
12742                 NULL,
12743         },
12744 };
12745
12746 /* vf split drop enable configuration */
12747
12748 /* Common result structure for vf split drop enable */
12749 struct cmd_vf_split_drop_en_result {
12750         cmdline_fixed_string_t set;
12751         cmdline_fixed_string_t vf;
12752         cmdline_fixed_string_t split;
12753         cmdline_fixed_string_t drop;
12754         portid_t port_id;
12755         uint16_t vf_id;
12756         cmdline_fixed_string_t on_off;
12757 };
12758
12759 /* Common CLI fields for vf split drop enable disable */
12760 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12761         TOKEN_STRING_INITIALIZER
12762                 (struct cmd_vf_split_drop_en_result,
12763                  set, "set");
12764 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12765         TOKEN_STRING_INITIALIZER
12766                 (struct cmd_vf_split_drop_en_result,
12767                  vf, "vf");
12768 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12769         TOKEN_STRING_INITIALIZER
12770                 (struct cmd_vf_split_drop_en_result,
12771                  split, "split");
12772 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_vf_split_drop_en_result,
12775                  drop, "drop");
12776 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12777         TOKEN_NUM_INITIALIZER
12778                 (struct cmd_vf_split_drop_en_result,
12779                  port_id, UINT16);
12780 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12781         TOKEN_NUM_INITIALIZER
12782                 (struct cmd_vf_split_drop_en_result,
12783                  vf_id, UINT16);
12784 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12785         TOKEN_STRING_INITIALIZER
12786                 (struct cmd_vf_split_drop_en_result,
12787                  on_off, "on#off");
12788
12789 static void
12790 cmd_set_vf_split_drop_en_parsed(
12791         void *parsed_result,
12792         __attribute__((unused)) struct cmdline *cl,
12793         __attribute__((unused)) void *data)
12794 {
12795         struct cmd_vf_split_drop_en_result *res = parsed_result;
12796         int ret = -ENOTSUP;
12797         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12798
12799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12800                 return;
12801
12802 #ifdef RTE_LIBRTE_IXGBE_PMD
12803         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12804                         is_on);
12805 #endif
12806         switch (ret) {
12807         case 0:
12808                 break;
12809         case -EINVAL:
12810                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12811                 break;
12812         case -ENODEV:
12813                 printf("invalid port_id %d\n", res->port_id);
12814                 break;
12815         case -ENOTSUP:
12816                 printf("not supported on port %d\n", res->port_id);
12817                 break;
12818         default:
12819                 printf("programming error: (%s)\n", strerror(-ret));
12820         }
12821 }
12822
12823 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12824         .f = cmd_set_vf_split_drop_en_parsed,
12825         .data = NULL,
12826         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12827         .tokens = {
12828                 (void *)&cmd_vf_split_drop_en_set,
12829                 (void *)&cmd_vf_split_drop_en_vf,
12830                 (void *)&cmd_vf_split_drop_en_split,
12831                 (void *)&cmd_vf_split_drop_en_drop,
12832                 (void *)&cmd_vf_split_drop_en_port_id,
12833                 (void *)&cmd_vf_split_drop_en_vf_id,
12834                 (void *)&cmd_vf_split_drop_en_on_off,
12835                 NULL,
12836         },
12837 };
12838
12839 /* vf mac address configuration */
12840
12841 /* Common result structure for vf mac address */
12842 struct cmd_set_vf_mac_addr_result {
12843         cmdline_fixed_string_t set;
12844         cmdline_fixed_string_t vf;
12845         cmdline_fixed_string_t mac;
12846         cmdline_fixed_string_t addr;
12847         portid_t port_id;
12848         uint16_t vf_id;
12849         struct ether_addr mac_addr;
12850
12851 };
12852
12853 /* Common CLI fields for vf split drop enable disable */
12854 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12855         TOKEN_STRING_INITIALIZER
12856                 (struct cmd_set_vf_mac_addr_result,
12857                  set, "set");
12858 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12859         TOKEN_STRING_INITIALIZER
12860                 (struct cmd_set_vf_mac_addr_result,
12861                  vf, "vf");
12862 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_set_vf_mac_addr_result,
12865                  mac, "mac");
12866 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_set_vf_mac_addr_result,
12869                  addr, "addr");
12870 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12871         TOKEN_NUM_INITIALIZER
12872                 (struct cmd_set_vf_mac_addr_result,
12873                  port_id, UINT16);
12874 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12875         TOKEN_NUM_INITIALIZER
12876                 (struct cmd_set_vf_mac_addr_result,
12877                  vf_id, UINT16);
12878 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12879         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12880                  mac_addr);
12881
12882 static void
12883 cmd_set_vf_mac_addr_parsed(
12884         void *parsed_result,
12885         __attribute__((unused)) struct cmdline *cl,
12886         __attribute__((unused)) void *data)
12887 {
12888         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12889         int ret = -ENOTSUP;
12890
12891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12892                 return;
12893
12894 #ifdef RTE_LIBRTE_IXGBE_PMD
12895         if (ret == -ENOTSUP)
12896                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12897                                 &res->mac_addr);
12898 #endif
12899 #ifdef RTE_LIBRTE_I40E_PMD
12900         if (ret == -ENOTSUP)
12901                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12902                                 &res->mac_addr);
12903 #endif
12904 #ifdef RTE_LIBRTE_BNXT_PMD
12905         if (ret == -ENOTSUP)
12906                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12907                                 &res->mac_addr);
12908 #endif
12909
12910         switch (ret) {
12911         case 0:
12912                 break;
12913         case -EINVAL:
12914                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12915                 break;
12916         case -ENODEV:
12917                 printf("invalid port_id %d\n", res->port_id);
12918                 break;
12919         case -ENOTSUP:
12920                 printf("function not implemented\n");
12921                 break;
12922         default:
12923                 printf("programming error: (%s)\n", strerror(-ret));
12924         }
12925 }
12926
12927 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12928         .f = cmd_set_vf_mac_addr_parsed,
12929         .data = NULL,
12930         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12931         .tokens = {
12932                 (void *)&cmd_set_vf_mac_addr_set,
12933                 (void *)&cmd_set_vf_mac_addr_vf,
12934                 (void *)&cmd_set_vf_mac_addr_mac,
12935                 (void *)&cmd_set_vf_mac_addr_addr,
12936                 (void *)&cmd_set_vf_mac_addr_port_id,
12937                 (void *)&cmd_set_vf_mac_addr_vf_id,
12938                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12939                 NULL,
12940         },
12941 };
12942
12943 /* MACsec configuration */
12944
12945 /* Common result structure for MACsec offload enable */
12946 struct cmd_macsec_offload_on_result {
12947         cmdline_fixed_string_t set;
12948         cmdline_fixed_string_t macsec;
12949         cmdline_fixed_string_t offload;
12950         portid_t port_id;
12951         cmdline_fixed_string_t on;
12952         cmdline_fixed_string_t encrypt;
12953         cmdline_fixed_string_t en_on_off;
12954         cmdline_fixed_string_t replay_protect;
12955         cmdline_fixed_string_t rp_on_off;
12956 };
12957
12958 /* Common CLI fields for MACsec offload disable */
12959 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12960         TOKEN_STRING_INITIALIZER
12961                 (struct cmd_macsec_offload_on_result,
12962                  set, "set");
12963 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_macsec_offload_on_result,
12966                  macsec, "macsec");
12967 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_macsec_offload_on_result,
12970                  offload, "offload");
12971 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12972         TOKEN_NUM_INITIALIZER
12973                 (struct cmd_macsec_offload_on_result,
12974                  port_id, UINT16);
12975 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_macsec_offload_on_result,
12978                  on, "on");
12979 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12980         TOKEN_STRING_INITIALIZER
12981                 (struct cmd_macsec_offload_on_result,
12982                  encrypt, "encrypt");
12983 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12984         TOKEN_STRING_INITIALIZER
12985                 (struct cmd_macsec_offload_on_result,
12986                  en_on_off, "on#off");
12987 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12988         TOKEN_STRING_INITIALIZER
12989                 (struct cmd_macsec_offload_on_result,
12990                  replay_protect, "replay-protect");
12991 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_macsec_offload_on_result,
12994                  rp_on_off, "on#off");
12995
12996 static void
12997 cmd_set_macsec_offload_on_parsed(
12998         void *parsed_result,
12999         __attribute__((unused)) struct cmdline *cl,
13000         __attribute__((unused)) void *data)
13001 {
13002         struct cmd_macsec_offload_on_result *res = parsed_result;
13003         int ret = -ENOTSUP;
13004         portid_t port_id = res->port_id;
13005         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13006         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13007
13008         if (port_id_is_invalid(port_id, ENABLED_WARN))
13009                 return;
13010
13011         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
13012 #ifdef RTE_LIBRTE_IXGBE_PMD
13013         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13014 #endif
13015         RTE_SET_USED(en);
13016         RTE_SET_USED(rp);
13017
13018         switch (ret) {
13019         case 0:
13020                 break;
13021         case -ENODEV:
13022                 printf("invalid port_id %d\n", port_id);
13023                 break;
13024         case -ENOTSUP:
13025                 printf("not supported on port %d\n", port_id);
13026                 break;
13027         default:
13028                 printf("programming error: (%s)\n", strerror(-ret));
13029         }
13030 }
13031
13032 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13033         .f = cmd_set_macsec_offload_on_parsed,
13034         .data = NULL,
13035         .help_str = "set macsec offload <port_id> on "
13036                 "encrypt on|off replay-protect on|off",
13037         .tokens = {
13038                 (void *)&cmd_macsec_offload_on_set,
13039                 (void *)&cmd_macsec_offload_on_macsec,
13040                 (void *)&cmd_macsec_offload_on_offload,
13041                 (void *)&cmd_macsec_offload_on_port_id,
13042                 (void *)&cmd_macsec_offload_on_on,
13043                 (void *)&cmd_macsec_offload_on_encrypt,
13044                 (void *)&cmd_macsec_offload_on_en_on_off,
13045                 (void *)&cmd_macsec_offload_on_replay_protect,
13046                 (void *)&cmd_macsec_offload_on_rp_on_off,
13047                 NULL,
13048         },
13049 };
13050
13051 /* Common result structure for MACsec offload disable */
13052 struct cmd_macsec_offload_off_result {
13053         cmdline_fixed_string_t set;
13054         cmdline_fixed_string_t macsec;
13055         cmdline_fixed_string_t offload;
13056         portid_t port_id;
13057         cmdline_fixed_string_t off;
13058 };
13059
13060 /* Common CLI fields for MACsec offload disable */
13061 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13062         TOKEN_STRING_INITIALIZER
13063                 (struct cmd_macsec_offload_off_result,
13064                  set, "set");
13065 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13066         TOKEN_STRING_INITIALIZER
13067                 (struct cmd_macsec_offload_off_result,
13068                  macsec, "macsec");
13069 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_macsec_offload_off_result,
13072                  offload, "offload");
13073 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13074         TOKEN_NUM_INITIALIZER
13075                 (struct cmd_macsec_offload_off_result,
13076                  port_id, UINT16);
13077 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_macsec_offload_off_result,
13080                  off, "off");
13081
13082 static void
13083 cmd_set_macsec_offload_off_parsed(
13084         void *parsed_result,
13085         __attribute__((unused)) struct cmdline *cl,
13086         __attribute__((unused)) void *data)
13087 {
13088         struct cmd_macsec_offload_off_result *res = parsed_result;
13089         int ret = -ENOTSUP;
13090         portid_t port_id = res->port_id;
13091
13092         if (port_id_is_invalid(port_id, ENABLED_WARN))
13093                 return;
13094
13095         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13096 #ifdef RTE_LIBRTE_IXGBE_PMD
13097         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13098 #endif
13099
13100         switch (ret) {
13101         case 0:
13102                 break;
13103         case -ENODEV:
13104                 printf("invalid port_id %d\n", port_id);
13105                 break;
13106         case -ENOTSUP:
13107                 printf("not supported on port %d\n", port_id);
13108                 break;
13109         default:
13110                 printf("programming error: (%s)\n", strerror(-ret));
13111         }
13112 }
13113
13114 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13115         .f = cmd_set_macsec_offload_off_parsed,
13116         .data = NULL,
13117         .help_str = "set macsec offload <port_id> off",
13118         .tokens = {
13119                 (void *)&cmd_macsec_offload_off_set,
13120                 (void *)&cmd_macsec_offload_off_macsec,
13121                 (void *)&cmd_macsec_offload_off_offload,
13122                 (void *)&cmd_macsec_offload_off_port_id,
13123                 (void *)&cmd_macsec_offload_off_off,
13124                 NULL,
13125         },
13126 };
13127
13128 /* Common result structure for MACsec secure connection configure */
13129 struct cmd_macsec_sc_result {
13130         cmdline_fixed_string_t set;
13131         cmdline_fixed_string_t macsec;
13132         cmdline_fixed_string_t sc;
13133         cmdline_fixed_string_t tx_rx;
13134         portid_t port_id;
13135         struct ether_addr mac;
13136         uint16_t pi;
13137 };
13138
13139 /* Common CLI fields for MACsec secure connection configure */
13140 cmdline_parse_token_string_t cmd_macsec_sc_set =
13141         TOKEN_STRING_INITIALIZER
13142                 (struct cmd_macsec_sc_result,
13143                  set, "set");
13144 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13145         TOKEN_STRING_INITIALIZER
13146                 (struct cmd_macsec_sc_result,
13147                  macsec, "macsec");
13148 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13149         TOKEN_STRING_INITIALIZER
13150                 (struct cmd_macsec_sc_result,
13151                  sc, "sc");
13152 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13153         TOKEN_STRING_INITIALIZER
13154                 (struct cmd_macsec_sc_result,
13155                  tx_rx, "tx#rx");
13156 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13157         TOKEN_NUM_INITIALIZER
13158                 (struct cmd_macsec_sc_result,
13159                  port_id, UINT16);
13160 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13161         TOKEN_ETHERADDR_INITIALIZER
13162                 (struct cmd_macsec_sc_result,
13163                  mac);
13164 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13165         TOKEN_NUM_INITIALIZER
13166                 (struct cmd_macsec_sc_result,
13167                  pi, UINT16);
13168
13169 static void
13170 cmd_set_macsec_sc_parsed(
13171         void *parsed_result,
13172         __attribute__((unused)) struct cmdline *cl,
13173         __attribute__((unused)) void *data)
13174 {
13175         struct cmd_macsec_sc_result *res = parsed_result;
13176         int ret = -ENOTSUP;
13177         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13178
13179 #ifdef RTE_LIBRTE_IXGBE_PMD
13180         ret = is_tx ?
13181                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13182                                 res->mac.addr_bytes) :
13183                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13184                                 res->mac.addr_bytes, res->pi);
13185 #endif
13186         RTE_SET_USED(is_tx);
13187
13188         switch (ret) {
13189         case 0:
13190                 break;
13191         case -ENODEV:
13192                 printf("invalid port_id %d\n", res->port_id);
13193                 break;
13194         case -ENOTSUP:
13195                 printf("not supported on port %d\n", res->port_id);
13196                 break;
13197         default:
13198                 printf("programming error: (%s)\n", strerror(-ret));
13199         }
13200 }
13201
13202 cmdline_parse_inst_t cmd_set_macsec_sc = {
13203         .f = cmd_set_macsec_sc_parsed,
13204         .data = NULL,
13205         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13206         .tokens = {
13207                 (void *)&cmd_macsec_sc_set,
13208                 (void *)&cmd_macsec_sc_macsec,
13209                 (void *)&cmd_macsec_sc_sc,
13210                 (void *)&cmd_macsec_sc_tx_rx,
13211                 (void *)&cmd_macsec_sc_port_id,
13212                 (void *)&cmd_macsec_sc_mac,
13213                 (void *)&cmd_macsec_sc_pi,
13214                 NULL,
13215         },
13216 };
13217
13218 /* Common result structure for MACsec secure connection configure */
13219 struct cmd_macsec_sa_result {
13220         cmdline_fixed_string_t set;
13221         cmdline_fixed_string_t macsec;
13222         cmdline_fixed_string_t sa;
13223         cmdline_fixed_string_t tx_rx;
13224         portid_t port_id;
13225         uint8_t idx;
13226         uint8_t an;
13227         uint32_t pn;
13228         cmdline_fixed_string_t key;
13229 };
13230
13231 /* Common CLI fields for MACsec secure connection configure */
13232 cmdline_parse_token_string_t cmd_macsec_sa_set =
13233         TOKEN_STRING_INITIALIZER
13234                 (struct cmd_macsec_sa_result,
13235                  set, "set");
13236 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13237         TOKEN_STRING_INITIALIZER
13238                 (struct cmd_macsec_sa_result,
13239                  macsec, "macsec");
13240 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13241         TOKEN_STRING_INITIALIZER
13242                 (struct cmd_macsec_sa_result,
13243                  sa, "sa");
13244 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13245         TOKEN_STRING_INITIALIZER
13246                 (struct cmd_macsec_sa_result,
13247                  tx_rx, "tx#rx");
13248 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13249         TOKEN_NUM_INITIALIZER
13250                 (struct cmd_macsec_sa_result,
13251                  port_id, UINT16);
13252 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13253         TOKEN_NUM_INITIALIZER
13254                 (struct cmd_macsec_sa_result,
13255                  idx, UINT8);
13256 cmdline_parse_token_num_t cmd_macsec_sa_an =
13257         TOKEN_NUM_INITIALIZER
13258                 (struct cmd_macsec_sa_result,
13259                  an, UINT8);
13260 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13261         TOKEN_NUM_INITIALIZER
13262                 (struct cmd_macsec_sa_result,
13263                  pn, UINT32);
13264 cmdline_parse_token_string_t cmd_macsec_sa_key =
13265         TOKEN_STRING_INITIALIZER
13266                 (struct cmd_macsec_sa_result,
13267                  key, NULL);
13268
13269 static void
13270 cmd_set_macsec_sa_parsed(
13271         void *parsed_result,
13272         __attribute__((unused)) struct cmdline *cl,
13273         __attribute__((unused)) void *data)
13274 {
13275         struct cmd_macsec_sa_result *res = parsed_result;
13276         int ret = -ENOTSUP;
13277         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13278         uint8_t key[16] = { 0 };
13279         uint8_t xdgt0;
13280         uint8_t xdgt1;
13281         int key_len;
13282         int i;
13283
13284         key_len = strlen(res->key) / 2;
13285         if (key_len > 16)
13286                 key_len = 16;
13287
13288         for (i = 0; i < key_len; i++) {
13289                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13290                 if (xdgt0 == 0xFF)
13291                         return;
13292                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13293                 if (xdgt1 == 0xFF)
13294                         return;
13295                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13296         }
13297
13298 #ifdef RTE_LIBRTE_IXGBE_PMD
13299         ret = is_tx ?
13300                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13301                         res->idx, res->an, res->pn, key) :
13302                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13303                         res->idx, res->an, res->pn, key);
13304 #endif
13305         RTE_SET_USED(is_tx);
13306         RTE_SET_USED(key);
13307
13308         switch (ret) {
13309         case 0:
13310                 break;
13311         case -EINVAL:
13312                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13313                 break;
13314         case -ENODEV:
13315                 printf("invalid port_id %d\n", res->port_id);
13316                 break;
13317         case -ENOTSUP:
13318                 printf("not supported on port %d\n", res->port_id);
13319                 break;
13320         default:
13321                 printf("programming error: (%s)\n", strerror(-ret));
13322         }
13323 }
13324
13325 cmdline_parse_inst_t cmd_set_macsec_sa = {
13326         .f = cmd_set_macsec_sa_parsed,
13327         .data = NULL,
13328         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13329         .tokens = {
13330                 (void *)&cmd_macsec_sa_set,
13331                 (void *)&cmd_macsec_sa_macsec,
13332                 (void *)&cmd_macsec_sa_sa,
13333                 (void *)&cmd_macsec_sa_tx_rx,
13334                 (void *)&cmd_macsec_sa_port_id,
13335                 (void *)&cmd_macsec_sa_idx,
13336                 (void *)&cmd_macsec_sa_an,
13337                 (void *)&cmd_macsec_sa_pn,
13338                 (void *)&cmd_macsec_sa_key,
13339                 NULL,
13340         },
13341 };
13342
13343 /* VF unicast promiscuous mode configuration */
13344
13345 /* Common result structure for VF unicast promiscuous mode */
13346 struct cmd_vf_promisc_result {
13347         cmdline_fixed_string_t set;
13348         cmdline_fixed_string_t vf;
13349         cmdline_fixed_string_t promisc;
13350         portid_t port_id;
13351         uint32_t vf_id;
13352         cmdline_fixed_string_t on_off;
13353 };
13354
13355 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13356 cmdline_parse_token_string_t cmd_vf_promisc_set =
13357         TOKEN_STRING_INITIALIZER
13358                 (struct cmd_vf_promisc_result,
13359                  set, "set");
13360 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_vf_promisc_result,
13363                  vf, "vf");
13364 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_vf_promisc_result,
13367                  promisc, "promisc");
13368 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13369         TOKEN_NUM_INITIALIZER
13370                 (struct cmd_vf_promisc_result,
13371                  port_id, UINT16);
13372 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13373         TOKEN_NUM_INITIALIZER
13374                 (struct cmd_vf_promisc_result,
13375                  vf_id, UINT32);
13376 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13377         TOKEN_STRING_INITIALIZER
13378                 (struct cmd_vf_promisc_result,
13379                  on_off, "on#off");
13380
13381 static void
13382 cmd_set_vf_promisc_parsed(
13383         void *parsed_result,
13384         __attribute__((unused)) struct cmdline *cl,
13385         __attribute__((unused)) void *data)
13386 {
13387         struct cmd_vf_promisc_result *res = parsed_result;
13388         int ret = -ENOTSUP;
13389
13390         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13391
13392         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13393                 return;
13394
13395 #ifdef RTE_LIBRTE_I40E_PMD
13396         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13397                                                   res->vf_id, is_on);
13398 #endif
13399
13400         switch (ret) {
13401         case 0:
13402                 break;
13403         case -EINVAL:
13404                 printf("invalid vf_id %d\n", res->vf_id);
13405                 break;
13406         case -ENODEV:
13407                 printf("invalid port_id %d\n", res->port_id);
13408                 break;
13409         case -ENOTSUP:
13410                 printf("function not implemented\n");
13411                 break;
13412         default:
13413                 printf("programming error: (%s)\n", strerror(-ret));
13414         }
13415 }
13416
13417 cmdline_parse_inst_t cmd_set_vf_promisc = {
13418         .f = cmd_set_vf_promisc_parsed,
13419         .data = NULL,
13420         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13421                 "Set unicast promiscuous mode for a VF from the PF",
13422         .tokens = {
13423                 (void *)&cmd_vf_promisc_set,
13424                 (void *)&cmd_vf_promisc_vf,
13425                 (void *)&cmd_vf_promisc_promisc,
13426                 (void *)&cmd_vf_promisc_port_id,
13427                 (void *)&cmd_vf_promisc_vf_id,
13428                 (void *)&cmd_vf_promisc_on_off,
13429                 NULL,
13430         },
13431 };
13432
13433 /* VF multicast promiscuous mode configuration */
13434
13435 /* Common result structure for VF multicast promiscuous mode */
13436 struct cmd_vf_allmulti_result {
13437         cmdline_fixed_string_t set;
13438         cmdline_fixed_string_t vf;
13439         cmdline_fixed_string_t allmulti;
13440         portid_t port_id;
13441         uint32_t vf_id;
13442         cmdline_fixed_string_t on_off;
13443 };
13444
13445 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13446 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13447         TOKEN_STRING_INITIALIZER
13448                 (struct cmd_vf_allmulti_result,
13449                  set, "set");
13450 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13451         TOKEN_STRING_INITIALIZER
13452                 (struct cmd_vf_allmulti_result,
13453                  vf, "vf");
13454 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13455         TOKEN_STRING_INITIALIZER
13456                 (struct cmd_vf_allmulti_result,
13457                  allmulti, "allmulti");
13458 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13459         TOKEN_NUM_INITIALIZER
13460                 (struct cmd_vf_allmulti_result,
13461                  port_id, UINT16);
13462 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13463         TOKEN_NUM_INITIALIZER
13464                 (struct cmd_vf_allmulti_result,
13465                  vf_id, UINT32);
13466 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13467         TOKEN_STRING_INITIALIZER
13468                 (struct cmd_vf_allmulti_result,
13469                  on_off, "on#off");
13470
13471 static void
13472 cmd_set_vf_allmulti_parsed(
13473         void *parsed_result,
13474         __attribute__((unused)) struct cmdline *cl,
13475         __attribute__((unused)) void *data)
13476 {
13477         struct cmd_vf_allmulti_result *res = parsed_result;
13478         int ret = -ENOTSUP;
13479
13480         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13481
13482         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13483                 return;
13484
13485 #ifdef RTE_LIBRTE_I40E_PMD
13486         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13487                                                     res->vf_id, is_on);
13488 #endif
13489
13490         switch (ret) {
13491         case 0:
13492                 break;
13493         case -EINVAL:
13494                 printf("invalid vf_id %d\n", res->vf_id);
13495                 break;
13496         case -ENODEV:
13497                 printf("invalid port_id %d\n", res->port_id);
13498                 break;
13499         case -ENOTSUP:
13500                 printf("function not implemented\n");
13501                 break;
13502         default:
13503                 printf("programming error: (%s)\n", strerror(-ret));
13504         }
13505 }
13506
13507 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13508         .f = cmd_set_vf_allmulti_parsed,
13509         .data = NULL,
13510         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13511                 "Set multicast promiscuous mode for a VF from the PF",
13512         .tokens = {
13513                 (void *)&cmd_vf_allmulti_set,
13514                 (void *)&cmd_vf_allmulti_vf,
13515                 (void *)&cmd_vf_allmulti_allmulti,
13516                 (void *)&cmd_vf_allmulti_port_id,
13517                 (void *)&cmd_vf_allmulti_vf_id,
13518                 (void *)&cmd_vf_allmulti_on_off,
13519                 NULL,
13520         },
13521 };
13522
13523 /* vf broadcast mode configuration */
13524
13525 /* Common result structure for vf broadcast */
13526 struct cmd_set_vf_broadcast_result {
13527         cmdline_fixed_string_t set;
13528         cmdline_fixed_string_t vf;
13529         cmdline_fixed_string_t broadcast;
13530         portid_t port_id;
13531         uint16_t vf_id;
13532         cmdline_fixed_string_t on_off;
13533 };
13534
13535 /* Common CLI fields for vf broadcast enable disable */
13536 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13537         TOKEN_STRING_INITIALIZER
13538                 (struct cmd_set_vf_broadcast_result,
13539                  set, "set");
13540 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13541         TOKEN_STRING_INITIALIZER
13542                 (struct cmd_set_vf_broadcast_result,
13543                  vf, "vf");
13544 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13545         TOKEN_STRING_INITIALIZER
13546                 (struct cmd_set_vf_broadcast_result,
13547                  broadcast, "broadcast");
13548 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13549         TOKEN_NUM_INITIALIZER
13550                 (struct cmd_set_vf_broadcast_result,
13551                  port_id, UINT16);
13552 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13553         TOKEN_NUM_INITIALIZER
13554                 (struct cmd_set_vf_broadcast_result,
13555                  vf_id, UINT16);
13556 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13557         TOKEN_STRING_INITIALIZER
13558                 (struct cmd_set_vf_broadcast_result,
13559                  on_off, "on#off");
13560
13561 static void
13562 cmd_set_vf_broadcast_parsed(
13563         void *parsed_result,
13564         __attribute__((unused)) struct cmdline *cl,
13565         __attribute__((unused)) void *data)
13566 {
13567         struct cmd_set_vf_broadcast_result *res = parsed_result;
13568         int ret = -ENOTSUP;
13569
13570         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13571
13572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13573                 return;
13574
13575 #ifdef RTE_LIBRTE_I40E_PMD
13576         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13577                                             res->vf_id, is_on);
13578 #endif
13579
13580         switch (ret) {
13581         case 0:
13582                 break;
13583         case -EINVAL:
13584                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13585                 break;
13586         case -ENODEV:
13587                 printf("invalid port_id %d\n", res->port_id);
13588                 break;
13589         case -ENOTSUP:
13590                 printf("function not implemented\n");
13591                 break;
13592         default:
13593                 printf("programming error: (%s)\n", strerror(-ret));
13594         }
13595 }
13596
13597 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13598         .f = cmd_set_vf_broadcast_parsed,
13599         .data = NULL,
13600         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13601         .tokens = {
13602                 (void *)&cmd_set_vf_broadcast_set,
13603                 (void *)&cmd_set_vf_broadcast_vf,
13604                 (void *)&cmd_set_vf_broadcast_broadcast,
13605                 (void *)&cmd_set_vf_broadcast_port_id,
13606                 (void *)&cmd_set_vf_broadcast_vf_id,
13607                 (void *)&cmd_set_vf_broadcast_on_off,
13608                 NULL,
13609         },
13610 };
13611
13612 /* vf vlan tag configuration */
13613
13614 /* Common result structure for vf vlan tag */
13615 struct cmd_set_vf_vlan_tag_result {
13616         cmdline_fixed_string_t set;
13617         cmdline_fixed_string_t vf;
13618         cmdline_fixed_string_t vlan;
13619         cmdline_fixed_string_t tag;
13620         portid_t port_id;
13621         uint16_t vf_id;
13622         cmdline_fixed_string_t on_off;
13623 };
13624
13625 /* Common CLI fields for vf vlan tag enable disable */
13626 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13627         TOKEN_STRING_INITIALIZER
13628                 (struct cmd_set_vf_vlan_tag_result,
13629                  set, "set");
13630 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13631         TOKEN_STRING_INITIALIZER
13632                 (struct cmd_set_vf_vlan_tag_result,
13633                  vf, "vf");
13634 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13635         TOKEN_STRING_INITIALIZER
13636                 (struct cmd_set_vf_vlan_tag_result,
13637                  vlan, "vlan");
13638 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13639         TOKEN_STRING_INITIALIZER
13640                 (struct cmd_set_vf_vlan_tag_result,
13641                  tag, "tag");
13642 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13643         TOKEN_NUM_INITIALIZER
13644                 (struct cmd_set_vf_vlan_tag_result,
13645                  port_id, UINT16);
13646 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13647         TOKEN_NUM_INITIALIZER
13648                 (struct cmd_set_vf_vlan_tag_result,
13649                  vf_id, UINT16);
13650 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13651         TOKEN_STRING_INITIALIZER
13652                 (struct cmd_set_vf_vlan_tag_result,
13653                  on_off, "on#off");
13654
13655 static void
13656 cmd_set_vf_vlan_tag_parsed(
13657         void *parsed_result,
13658         __attribute__((unused)) struct cmdline *cl,
13659         __attribute__((unused)) void *data)
13660 {
13661         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13662         int ret = -ENOTSUP;
13663
13664         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13665
13666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13667                 return;
13668
13669 #ifdef RTE_LIBRTE_I40E_PMD
13670         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13671                                            res->vf_id, is_on);
13672 #endif
13673
13674         switch (ret) {
13675         case 0:
13676                 break;
13677         case -EINVAL:
13678                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13679                 break;
13680         case -ENODEV:
13681                 printf("invalid port_id %d\n", res->port_id);
13682                 break;
13683         case -ENOTSUP:
13684                 printf("function not implemented\n");
13685                 break;
13686         default:
13687                 printf("programming error: (%s)\n", strerror(-ret));
13688         }
13689 }
13690
13691 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13692         .f = cmd_set_vf_vlan_tag_parsed,
13693         .data = NULL,
13694         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13695         .tokens = {
13696                 (void *)&cmd_set_vf_vlan_tag_set,
13697                 (void *)&cmd_set_vf_vlan_tag_vf,
13698                 (void *)&cmd_set_vf_vlan_tag_vlan,
13699                 (void *)&cmd_set_vf_vlan_tag_tag,
13700                 (void *)&cmd_set_vf_vlan_tag_port_id,
13701                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13702                 (void *)&cmd_set_vf_vlan_tag_on_off,
13703                 NULL,
13704         },
13705 };
13706
13707 /* Common definition of VF and TC TX bandwidth configuration */
13708 struct cmd_vf_tc_bw_result {
13709         cmdline_fixed_string_t set;
13710         cmdline_fixed_string_t vf;
13711         cmdline_fixed_string_t tc;
13712         cmdline_fixed_string_t tx;
13713         cmdline_fixed_string_t min_bw;
13714         cmdline_fixed_string_t max_bw;
13715         cmdline_fixed_string_t strict_link_prio;
13716         portid_t port_id;
13717         uint16_t vf_id;
13718         uint8_t tc_no;
13719         uint32_t bw;
13720         cmdline_fixed_string_t bw_list;
13721         uint8_t tc_map;
13722 };
13723
13724 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13725         TOKEN_STRING_INITIALIZER
13726                 (struct cmd_vf_tc_bw_result,
13727                  set, "set");
13728 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13729         TOKEN_STRING_INITIALIZER
13730                 (struct cmd_vf_tc_bw_result,
13731                  vf, "vf");
13732 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13733         TOKEN_STRING_INITIALIZER
13734                 (struct cmd_vf_tc_bw_result,
13735                  tc, "tc");
13736 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13737         TOKEN_STRING_INITIALIZER
13738                 (struct cmd_vf_tc_bw_result,
13739                  tx, "tx");
13740 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13741         TOKEN_STRING_INITIALIZER
13742                 (struct cmd_vf_tc_bw_result,
13743                  strict_link_prio, "strict-link-priority");
13744 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_vf_tc_bw_result,
13747                  min_bw, "min-bandwidth");
13748 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13749         TOKEN_STRING_INITIALIZER
13750                 (struct cmd_vf_tc_bw_result,
13751                  max_bw, "max-bandwidth");
13752 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13753         TOKEN_NUM_INITIALIZER
13754                 (struct cmd_vf_tc_bw_result,
13755                  port_id, UINT16);
13756 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13757         TOKEN_NUM_INITIALIZER
13758                 (struct cmd_vf_tc_bw_result,
13759                  vf_id, UINT16);
13760 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13761         TOKEN_NUM_INITIALIZER
13762                 (struct cmd_vf_tc_bw_result,
13763                  tc_no, UINT8);
13764 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13765         TOKEN_NUM_INITIALIZER
13766                 (struct cmd_vf_tc_bw_result,
13767                  bw, UINT32);
13768 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13769         TOKEN_STRING_INITIALIZER
13770                 (struct cmd_vf_tc_bw_result,
13771                  bw_list, NULL);
13772 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13773         TOKEN_NUM_INITIALIZER
13774                 (struct cmd_vf_tc_bw_result,
13775                  tc_map, UINT8);
13776
13777 /* VF max bandwidth setting */
13778 static void
13779 cmd_vf_max_bw_parsed(
13780         void *parsed_result,
13781         __attribute__((unused)) struct cmdline *cl,
13782         __attribute__((unused)) void *data)
13783 {
13784         struct cmd_vf_tc_bw_result *res = parsed_result;
13785         int ret = -ENOTSUP;
13786
13787         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13788                 return;
13789
13790 #ifdef RTE_LIBRTE_I40E_PMD
13791         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13792                                          res->vf_id, res->bw);
13793 #endif
13794
13795         switch (ret) {
13796         case 0:
13797                 break;
13798         case -EINVAL:
13799                 printf("invalid vf_id %d or bandwidth %d\n",
13800                        res->vf_id, res->bw);
13801                 break;
13802         case -ENODEV:
13803                 printf("invalid port_id %d\n", res->port_id);
13804                 break;
13805         case -ENOTSUP:
13806                 printf("function not implemented\n");
13807                 break;
13808         default:
13809                 printf("programming error: (%s)\n", strerror(-ret));
13810         }
13811 }
13812
13813 cmdline_parse_inst_t cmd_vf_max_bw = {
13814         .f = cmd_vf_max_bw_parsed,
13815         .data = NULL,
13816         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13817         .tokens = {
13818                 (void *)&cmd_vf_tc_bw_set,
13819                 (void *)&cmd_vf_tc_bw_vf,
13820                 (void *)&cmd_vf_tc_bw_tx,
13821                 (void *)&cmd_vf_tc_bw_max_bw,
13822                 (void *)&cmd_vf_tc_bw_port_id,
13823                 (void *)&cmd_vf_tc_bw_vf_id,
13824                 (void *)&cmd_vf_tc_bw_bw,
13825                 NULL,
13826         },
13827 };
13828
13829 static int
13830 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13831                            uint8_t *tc_num,
13832                            char *str)
13833 {
13834         uint32_t size;
13835         const char *p, *p0 = str;
13836         char s[256];
13837         char *end;
13838         char *str_fld[16];
13839         uint16_t i;
13840         int ret;
13841
13842         p = strchr(p0, '(');
13843         if (p == NULL) {
13844                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13845                 return -1;
13846         }
13847         p++;
13848         p0 = strchr(p, ')');
13849         if (p0 == NULL) {
13850                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13851                 return -1;
13852         }
13853         size = p0 - p;
13854         if (size >= sizeof(s)) {
13855                 printf("The string size exceeds the internal buffer size\n");
13856                 return -1;
13857         }
13858         snprintf(s, sizeof(s), "%.*s", size, p);
13859         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13860         if (ret <= 0) {
13861                 printf("Failed to get the bandwidth list. ");
13862                 return -1;
13863         }
13864         *tc_num = ret;
13865         for (i = 0; i < ret; i++)
13866                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13867
13868         return 0;
13869 }
13870
13871 /* TC min bandwidth setting */
13872 static void
13873 cmd_vf_tc_min_bw_parsed(
13874         void *parsed_result,
13875         __attribute__((unused)) struct cmdline *cl,
13876         __attribute__((unused)) void *data)
13877 {
13878         struct cmd_vf_tc_bw_result *res = parsed_result;
13879         uint8_t tc_num;
13880         uint8_t bw[16];
13881         int ret = -ENOTSUP;
13882
13883         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13884                 return;
13885
13886         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13887         if (ret)
13888                 return;
13889
13890 #ifdef RTE_LIBRTE_I40E_PMD
13891         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13892                                               tc_num, bw);
13893 #endif
13894
13895         switch (ret) {
13896         case 0:
13897                 break;
13898         case -EINVAL:
13899                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13900                 break;
13901         case -ENODEV:
13902                 printf("invalid port_id %d\n", res->port_id);
13903                 break;
13904         case -ENOTSUP:
13905                 printf("function not implemented\n");
13906                 break;
13907         default:
13908                 printf("programming error: (%s)\n", strerror(-ret));
13909         }
13910 }
13911
13912 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13913         .f = cmd_vf_tc_min_bw_parsed,
13914         .data = NULL,
13915         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13916                     " <bw1, bw2, ...>",
13917         .tokens = {
13918                 (void *)&cmd_vf_tc_bw_set,
13919                 (void *)&cmd_vf_tc_bw_vf,
13920                 (void *)&cmd_vf_tc_bw_tc,
13921                 (void *)&cmd_vf_tc_bw_tx,
13922                 (void *)&cmd_vf_tc_bw_min_bw,
13923                 (void *)&cmd_vf_tc_bw_port_id,
13924                 (void *)&cmd_vf_tc_bw_vf_id,
13925                 (void *)&cmd_vf_tc_bw_bw_list,
13926                 NULL,
13927         },
13928 };
13929
13930 static void
13931 cmd_tc_min_bw_parsed(
13932         void *parsed_result,
13933         __attribute__((unused)) struct cmdline *cl,
13934         __attribute__((unused)) void *data)
13935 {
13936         struct cmd_vf_tc_bw_result *res = parsed_result;
13937         struct rte_port *port;
13938         uint8_t tc_num;
13939         uint8_t bw[16];
13940         int ret = -ENOTSUP;
13941
13942         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13943                 return;
13944
13945         port = &ports[res->port_id];
13946         /** Check if the port is not started **/
13947         if (port->port_status != RTE_PORT_STOPPED) {
13948                 printf("Please stop port %d first\n", res->port_id);
13949                 return;
13950         }
13951
13952         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13953         if (ret)
13954                 return;
13955
13956 #ifdef RTE_LIBRTE_IXGBE_PMD
13957         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13958 #endif
13959
13960         switch (ret) {
13961         case 0:
13962                 break;
13963         case -EINVAL:
13964                 printf("invalid bandwidth\n");
13965                 break;
13966         case -ENODEV:
13967                 printf("invalid port_id %d\n", res->port_id);
13968                 break;
13969         case -ENOTSUP:
13970                 printf("function not implemented\n");
13971                 break;
13972         default:
13973                 printf("programming error: (%s)\n", strerror(-ret));
13974         }
13975 }
13976
13977 cmdline_parse_inst_t cmd_tc_min_bw = {
13978         .f = cmd_tc_min_bw_parsed,
13979         .data = NULL,
13980         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13981         .tokens = {
13982                 (void *)&cmd_vf_tc_bw_set,
13983                 (void *)&cmd_vf_tc_bw_tc,
13984                 (void *)&cmd_vf_tc_bw_tx,
13985                 (void *)&cmd_vf_tc_bw_min_bw,
13986                 (void *)&cmd_vf_tc_bw_port_id,
13987                 (void *)&cmd_vf_tc_bw_bw_list,
13988                 NULL,
13989         },
13990 };
13991
13992 /* TC max bandwidth setting */
13993 static void
13994 cmd_vf_tc_max_bw_parsed(
13995         void *parsed_result,
13996         __attribute__((unused)) struct cmdline *cl,
13997         __attribute__((unused)) void *data)
13998 {
13999         struct cmd_vf_tc_bw_result *res = parsed_result;
14000         int ret = -ENOTSUP;
14001
14002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14003                 return;
14004
14005 #ifdef RTE_LIBRTE_I40E_PMD
14006         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14007                                             res->tc_no, res->bw);
14008 #endif
14009
14010         switch (ret) {
14011         case 0:
14012                 break;
14013         case -EINVAL:
14014                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14015                        res->vf_id, res->tc_no, res->bw);
14016                 break;
14017         case -ENODEV:
14018                 printf("invalid port_id %d\n", res->port_id);
14019                 break;
14020         case -ENOTSUP:
14021                 printf("function not implemented\n");
14022                 break;
14023         default:
14024                 printf("programming error: (%s)\n", strerror(-ret));
14025         }
14026 }
14027
14028 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14029         .f = cmd_vf_tc_max_bw_parsed,
14030         .data = NULL,
14031         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14032                     " <bandwidth>",
14033         .tokens = {
14034                 (void *)&cmd_vf_tc_bw_set,
14035                 (void *)&cmd_vf_tc_bw_vf,
14036                 (void *)&cmd_vf_tc_bw_tc,
14037                 (void *)&cmd_vf_tc_bw_tx,
14038                 (void *)&cmd_vf_tc_bw_max_bw,
14039                 (void *)&cmd_vf_tc_bw_port_id,
14040                 (void *)&cmd_vf_tc_bw_vf_id,
14041                 (void *)&cmd_vf_tc_bw_tc_no,
14042                 (void *)&cmd_vf_tc_bw_bw,
14043                 NULL,
14044         },
14045 };
14046
14047
14048 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14049
14050 /* *** Set Port default Traffic Management Hierarchy *** */
14051 struct cmd_set_port_tm_hierarchy_default_result {
14052         cmdline_fixed_string_t set;
14053         cmdline_fixed_string_t port;
14054         cmdline_fixed_string_t tm;
14055         cmdline_fixed_string_t hierarchy;
14056         cmdline_fixed_string_t def;
14057         portid_t port_id;
14058 };
14059
14060 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14061         TOKEN_STRING_INITIALIZER(
14062                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14063 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14064         TOKEN_STRING_INITIALIZER(
14065                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14066 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14067         TOKEN_STRING_INITIALIZER(
14068                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14069 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14070         TOKEN_STRING_INITIALIZER(
14071                 struct cmd_set_port_tm_hierarchy_default_result,
14072                         hierarchy, "hierarchy");
14073 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14074         TOKEN_STRING_INITIALIZER(
14075                 struct cmd_set_port_tm_hierarchy_default_result,
14076                         def, "default");
14077 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14078         TOKEN_NUM_INITIALIZER(
14079                 struct cmd_set_port_tm_hierarchy_default_result,
14080                         port_id, UINT16);
14081
14082 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14083         __attribute__((unused)) struct cmdline *cl,
14084         __attribute__((unused)) void *data)
14085 {
14086         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14087         struct rte_port *p;
14088         portid_t port_id = res->port_id;
14089
14090         if (port_id_is_invalid(port_id, ENABLED_WARN))
14091                 return;
14092
14093         p = &ports[port_id];
14094
14095         /* Port tm flag */
14096         if (p->softport.tm_flag == 0) {
14097                 printf("  tm not enabled on port %u (error)\n", port_id);
14098                 return;
14099         }
14100
14101         /* Forward mode: tm */
14102         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14103                 printf("  tm mode not enabled(error)\n");
14104                 return;
14105         }
14106
14107         /* Set the default tm hierarchy */
14108         p->softport.tm.default_hierarchy_enable = 1;
14109 }
14110
14111 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14112         .f = cmd_set_port_tm_hierarchy_default_parsed,
14113         .data = NULL,
14114         .help_str = "set port tm hierarchy default <port_id>",
14115         .tokens = {
14116                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14117                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14118                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14119                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14120                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14121                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14122                 NULL,
14123         },
14124 };
14125 #endif
14126
14127 /* Strict link priority scheduling mode setting */
14128 static void
14129 cmd_strict_link_prio_parsed(
14130         void *parsed_result,
14131         __attribute__((unused)) struct cmdline *cl,
14132         __attribute__((unused)) void *data)
14133 {
14134         struct cmd_vf_tc_bw_result *res = parsed_result;
14135         int ret = -ENOTSUP;
14136
14137         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14138                 return;
14139
14140 #ifdef RTE_LIBRTE_I40E_PMD
14141         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14142 #endif
14143
14144         switch (ret) {
14145         case 0:
14146                 break;
14147         case -EINVAL:
14148                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14149                 break;
14150         case -ENODEV:
14151                 printf("invalid port_id %d\n", res->port_id);
14152                 break;
14153         case -ENOTSUP:
14154                 printf("function not implemented\n");
14155                 break;
14156         default:
14157                 printf("programming error: (%s)\n", strerror(-ret));
14158         }
14159 }
14160
14161 cmdline_parse_inst_t cmd_strict_link_prio = {
14162         .f = cmd_strict_link_prio_parsed,
14163         .data = NULL,
14164         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14165         .tokens = {
14166                 (void *)&cmd_vf_tc_bw_set,
14167                 (void *)&cmd_vf_tc_bw_tx,
14168                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14169                 (void *)&cmd_vf_tc_bw_port_id,
14170                 (void *)&cmd_vf_tc_bw_tc_map,
14171                 NULL,
14172         },
14173 };
14174
14175 /* Load dynamic device personalization*/
14176 struct cmd_ddp_add_result {
14177         cmdline_fixed_string_t ddp;
14178         cmdline_fixed_string_t add;
14179         portid_t port_id;
14180         char filepath[];
14181 };
14182
14183 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14184         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14185 cmdline_parse_token_string_t cmd_ddp_add_add =
14186         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14187 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14188         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14189 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14190         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14191
14192 static void
14193 cmd_ddp_add_parsed(
14194         void *parsed_result,
14195         __attribute__((unused)) struct cmdline *cl,
14196         __attribute__((unused)) void *data)
14197 {
14198         struct cmd_ddp_add_result *res = parsed_result;
14199         uint8_t *buff;
14200         uint32_t size;
14201         char *filepath;
14202         char *file_fld[2];
14203         int file_num;
14204         int ret = -ENOTSUP;
14205
14206         if (res->port_id > nb_ports) {
14207                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14208                 return;
14209         }
14210
14211         if (!all_ports_stopped()) {
14212                 printf("Please stop all ports first\n");
14213                 return;
14214         }
14215
14216         filepath = strdup(res->filepath);
14217         if (filepath == NULL) {
14218                 printf("Failed to allocate memory\n");
14219                 return;
14220         }
14221         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14222
14223         buff = open_ddp_package_file(file_fld[0], &size);
14224         if (!buff) {
14225                 free((void *)filepath);
14226                 return;
14227         }
14228
14229 #ifdef RTE_LIBRTE_I40E_PMD
14230         if (ret == -ENOTSUP)
14231                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14232                                                buff, size,
14233                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14234 #endif
14235
14236         if (ret == -EEXIST)
14237                 printf("Profile has already existed.\n");
14238         else if (ret < 0)
14239                 printf("Failed to load profile.\n");
14240         else if (file_num == 2)
14241                 save_ddp_package_file(file_fld[1], buff, size);
14242
14243         close_ddp_package_file(buff);
14244         free((void *)filepath);
14245 }
14246
14247 cmdline_parse_inst_t cmd_ddp_add = {
14248         .f = cmd_ddp_add_parsed,
14249         .data = NULL,
14250         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14251         .tokens = {
14252                 (void *)&cmd_ddp_add_ddp,
14253                 (void *)&cmd_ddp_add_add,
14254                 (void *)&cmd_ddp_add_port_id,
14255                 (void *)&cmd_ddp_add_filepath,
14256                 NULL,
14257         },
14258 };
14259
14260 /* Delete dynamic device personalization*/
14261 struct cmd_ddp_del_result {
14262         cmdline_fixed_string_t ddp;
14263         cmdline_fixed_string_t del;
14264         portid_t port_id;
14265         char filepath[];
14266 };
14267
14268 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14269         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14270 cmdline_parse_token_string_t cmd_ddp_del_del =
14271         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14272 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14273         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14274 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14275         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14276
14277 static void
14278 cmd_ddp_del_parsed(
14279         void *parsed_result,
14280         __attribute__((unused)) struct cmdline *cl,
14281         __attribute__((unused)) void *data)
14282 {
14283         struct cmd_ddp_del_result *res = parsed_result;
14284         uint8_t *buff;
14285         uint32_t size;
14286         int ret = -ENOTSUP;
14287
14288         if (res->port_id > nb_ports) {
14289                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14290                 return;
14291         }
14292
14293         if (!all_ports_stopped()) {
14294                 printf("Please stop all ports first\n");
14295                 return;
14296         }
14297
14298         buff = open_ddp_package_file(res->filepath, &size);
14299         if (!buff)
14300                 return;
14301
14302 #ifdef RTE_LIBRTE_I40E_PMD
14303         if (ret == -ENOTSUP)
14304                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14305                                                buff, size,
14306                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14307 #endif
14308
14309         if (ret == -EACCES)
14310                 printf("Profile does not exist.\n");
14311         else if (ret < 0)
14312                 printf("Failed to delete profile.\n");
14313
14314         close_ddp_package_file(buff);
14315 }
14316
14317 cmdline_parse_inst_t cmd_ddp_del = {
14318         .f = cmd_ddp_del_parsed,
14319         .data = NULL,
14320         .help_str = "ddp del <port_id> <profile_path>",
14321         .tokens = {
14322                 (void *)&cmd_ddp_del_ddp,
14323                 (void *)&cmd_ddp_del_del,
14324                 (void *)&cmd_ddp_del_port_id,
14325                 (void *)&cmd_ddp_del_filepath,
14326                 NULL,
14327         },
14328 };
14329
14330 /* Get dynamic device personalization profile info */
14331 struct cmd_ddp_info_result {
14332         cmdline_fixed_string_t ddp;
14333         cmdline_fixed_string_t get;
14334         cmdline_fixed_string_t info;
14335         char filepath[];
14336 };
14337
14338 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14339         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14340 cmdline_parse_token_string_t cmd_ddp_info_get =
14341         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14342 cmdline_parse_token_string_t cmd_ddp_info_info =
14343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14344 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14345         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14346
14347 static void
14348 cmd_ddp_info_parsed(
14349         void *parsed_result,
14350         __attribute__((unused)) struct cmdline *cl,
14351         __attribute__((unused)) void *data)
14352 {
14353         struct cmd_ddp_info_result *res = parsed_result;
14354         uint8_t *pkg;
14355         uint32_t pkg_size;
14356         int ret = -ENOTSUP;
14357 #ifdef RTE_LIBRTE_I40E_PMD
14358         uint32_t i, j, n;
14359         uint8_t *buff;
14360         uint32_t buff_size = 0;
14361         struct rte_pmd_i40e_profile_info info;
14362         uint32_t dev_num = 0;
14363         struct rte_pmd_i40e_ddp_device_id *devs;
14364         uint32_t proto_num = 0;
14365         struct rte_pmd_i40e_proto_info *proto = NULL;
14366         uint32_t pctype_num = 0;
14367         struct rte_pmd_i40e_ptype_info *pctype;
14368         uint32_t ptype_num = 0;
14369         struct rte_pmd_i40e_ptype_info *ptype;
14370         uint8_t proto_id;
14371
14372 #endif
14373
14374         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14375         if (!pkg)
14376                 return;
14377
14378 #ifdef RTE_LIBRTE_I40E_PMD
14379         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14380                                 (uint8_t *)&info, sizeof(info),
14381                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14382         if (!ret) {
14383                 printf("Global Track id:       0x%x\n", info.track_id);
14384                 printf("Global Version:        %d.%d.%d.%d\n",
14385                         info.version.major,
14386                         info.version.minor,
14387                         info.version.update,
14388                         info.version.draft);
14389                 printf("Global Package name:   %s\n\n", info.name);
14390         }
14391
14392         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14393                                 (uint8_t *)&info, sizeof(info),
14394                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14395         if (!ret) {
14396                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14397                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14398                         info.version.major,
14399                         info.version.minor,
14400                         info.version.update,
14401                         info.version.draft);
14402                 printf("i40e Profile name:     %s\n\n", info.name);
14403         }
14404
14405         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14406                                 (uint8_t *)&buff_size, sizeof(buff_size),
14407                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14408         if (!ret && buff_size) {
14409                 buff = (uint8_t *)malloc(buff_size);
14410                 if (buff) {
14411                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14412                                                 buff, buff_size,
14413                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14414                         if (!ret)
14415                                 printf("Package Notes:\n%s\n\n", buff);
14416                         free(buff);
14417                 }
14418         }
14419
14420         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14421                                 (uint8_t *)&dev_num, sizeof(dev_num),
14422                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14423         if (!ret && dev_num) {
14424                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14425                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14426                 if (devs) {
14427                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14428                                                 (uint8_t *)devs, buff_size,
14429                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14430                         if (!ret) {
14431                                 printf("List of supported devices:\n");
14432                                 for (i = 0; i < dev_num; i++) {
14433                                         printf("  %04X:%04X %04X:%04X\n",
14434                                                 devs[i].vendor_dev_id >> 16,
14435                                                 devs[i].vendor_dev_id & 0xFFFF,
14436                                                 devs[i].sub_vendor_dev_id >> 16,
14437                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14438                                 }
14439                                 printf("\n");
14440                         }
14441                         free(devs);
14442                 }
14443         }
14444
14445         /* get information about protocols and packet types */
14446         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14447                 (uint8_t *)&proto_num, sizeof(proto_num),
14448                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14449         if (ret || !proto_num)
14450                 goto no_print_return;
14451
14452         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14453         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14454         if (!proto)
14455                 goto no_print_return;
14456
14457         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14458                                         buff_size,
14459                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14460         if (!ret) {
14461                 printf("List of used protocols:\n");
14462                 for (i = 0; i < proto_num; i++)
14463                         printf("  %2u: %s\n", proto[i].proto_id,
14464                                proto[i].name);
14465                 printf("\n");
14466         }
14467         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14468                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14469                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14470         if (ret || !pctype_num)
14471                 goto no_print_pctypes;
14472
14473         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14474         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14475         if (!pctype)
14476                 goto no_print_pctypes;
14477
14478         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14479                                         buff_size,
14480                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14481         if (ret) {
14482                 free(pctype);
14483                 goto no_print_pctypes;
14484         }
14485
14486         printf("List of defined packet classification types:\n");
14487         for (i = 0; i < pctype_num; i++) {
14488                 printf("  %2u:", pctype[i].ptype_id);
14489                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14490                         proto_id = pctype[i].protocols[j];
14491                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14492                                 for (n = 0; n < proto_num; n++) {
14493                                         if (proto[n].proto_id == proto_id) {
14494                                                 printf(" %s", proto[n].name);
14495                                                 break;
14496                                         }
14497                                 }
14498                         }
14499                 }
14500                 printf("\n");
14501         }
14502         printf("\n");
14503         free(pctype);
14504
14505 no_print_pctypes:
14506
14507         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14508                                         sizeof(ptype_num),
14509                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14510         if (ret || !ptype_num)
14511                 goto no_print_return;
14512
14513         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14514         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14515         if (!ptype)
14516                 goto no_print_return;
14517
14518         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14519                                         buff_size,
14520                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14521         if (ret) {
14522                 free(ptype);
14523                 goto no_print_return;
14524         }
14525         printf("List of defined packet types:\n");
14526         for (i = 0; i < ptype_num; i++) {
14527                 printf("  %2u:", ptype[i].ptype_id);
14528                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14529                         proto_id = ptype[i].protocols[j];
14530                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14531                                 for (n = 0; n < proto_num; n++) {
14532                                         if (proto[n].proto_id == proto_id) {
14533                                                 printf(" %s", proto[n].name);
14534                                                 break;
14535                                         }
14536                                 }
14537                         }
14538                 }
14539                 printf("\n");
14540         }
14541         free(ptype);
14542         printf("\n");
14543
14544         ret = 0;
14545 no_print_return:
14546         if (proto)
14547                 free(proto);
14548 #endif
14549         if (ret == -ENOTSUP)
14550                 printf("Function not supported in PMD driver\n");
14551         close_ddp_package_file(pkg);
14552 }
14553
14554 cmdline_parse_inst_t cmd_ddp_get_info = {
14555         .f = cmd_ddp_info_parsed,
14556         .data = NULL,
14557         .help_str = "ddp get info <profile_path>",
14558         .tokens = {
14559                 (void *)&cmd_ddp_info_ddp,
14560                 (void *)&cmd_ddp_info_get,
14561                 (void *)&cmd_ddp_info_info,
14562                 (void *)&cmd_ddp_info_filepath,
14563                 NULL,
14564         },
14565 };
14566
14567 /* Get dynamic device personalization profile info list*/
14568 #define PROFILE_INFO_SIZE 48
14569 #define MAX_PROFILE_NUM 16
14570
14571 struct cmd_ddp_get_list_result {
14572         cmdline_fixed_string_t ddp;
14573         cmdline_fixed_string_t get;
14574         cmdline_fixed_string_t list;
14575         portid_t port_id;
14576 };
14577
14578 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14579         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14580 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14581         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14582 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14583         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14584 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14585         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14586
14587 static void
14588 cmd_ddp_get_list_parsed(
14589         void *parsed_result,
14590         __attribute__((unused)) struct cmdline *cl,
14591         __attribute__((unused)) void *data)
14592 {
14593         struct cmd_ddp_get_list_result *res = parsed_result;
14594 #ifdef RTE_LIBRTE_I40E_PMD
14595         struct rte_pmd_i40e_profile_list *p_list;
14596         struct rte_pmd_i40e_profile_info *p_info;
14597         uint32_t p_num;
14598         uint32_t size;
14599         uint32_t i;
14600 #endif
14601         int ret = -ENOTSUP;
14602
14603         if (res->port_id > nb_ports) {
14604                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14605                 return;
14606         }
14607
14608 #ifdef RTE_LIBRTE_I40E_PMD
14609         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14610         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14611         if (!p_list)
14612                 printf("%s: Failed to malloc buffer\n", __func__);
14613
14614         if (ret == -ENOTSUP)
14615                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14616                                                 (uint8_t *)p_list, size);
14617
14618         if (!ret) {
14619                 p_num = p_list->p_count;
14620                 printf("Profile number is: %d\n\n", p_num);
14621
14622                 for (i = 0; i < p_num; i++) {
14623                         p_info = &p_list->p_info[i];
14624                         printf("Profile %d:\n", i);
14625                         printf("Track id:     0x%x\n", p_info->track_id);
14626                         printf("Version:      %d.%d.%d.%d\n",
14627                                p_info->version.major,
14628                                p_info->version.minor,
14629                                p_info->version.update,
14630                                p_info->version.draft);
14631                         printf("Profile name: %s\n\n", p_info->name);
14632                 }
14633         }
14634
14635         free(p_list);
14636 #endif
14637
14638         if (ret < 0)
14639                 printf("Failed to get ddp list\n");
14640 }
14641
14642 cmdline_parse_inst_t cmd_ddp_get_list = {
14643         .f = cmd_ddp_get_list_parsed,
14644         .data = NULL,
14645         .help_str = "ddp get list <port_id>",
14646         .tokens = {
14647                 (void *)&cmd_ddp_get_list_ddp,
14648                 (void *)&cmd_ddp_get_list_get,
14649                 (void *)&cmd_ddp_get_list_list,
14650                 (void *)&cmd_ddp_get_list_port_id,
14651                 NULL,
14652         },
14653 };
14654
14655 /* show vf stats */
14656
14657 /* Common result structure for show vf stats */
14658 struct cmd_show_vf_stats_result {
14659         cmdline_fixed_string_t show;
14660         cmdline_fixed_string_t vf;
14661         cmdline_fixed_string_t stats;
14662         portid_t port_id;
14663         uint16_t vf_id;
14664 };
14665
14666 /* Common CLI fields show vf stats*/
14667 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14668         TOKEN_STRING_INITIALIZER
14669                 (struct cmd_show_vf_stats_result,
14670                  show, "show");
14671 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14672         TOKEN_STRING_INITIALIZER
14673                 (struct cmd_show_vf_stats_result,
14674                  vf, "vf");
14675 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14676         TOKEN_STRING_INITIALIZER
14677                 (struct cmd_show_vf_stats_result,
14678                  stats, "stats");
14679 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14680         TOKEN_NUM_INITIALIZER
14681                 (struct cmd_show_vf_stats_result,
14682                  port_id, UINT16);
14683 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14684         TOKEN_NUM_INITIALIZER
14685                 (struct cmd_show_vf_stats_result,
14686                  vf_id, UINT16);
14687
14688 static void
14689 cmd_show_vf_stats_parsed(
14690         void *parsed_result,
14691         __attribute__((unused)) struct cmdline *cl,
14692         __attribute__((unused)) void *data)
14693 {
14694         struct cmd_show_vf_stats_result *res = parsed_result;
14695         struct rte_eth_stats stats;
14696         int ret = -ENOTSUP;
14697         static const char *nic_stats_border = "########################";
14698
14699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14700                 return;
14701
14702         memset(&stats, 0, sizeof(stats));
14703
14704 #ifdef RTE_LIBRTE_I40E_PMD
14705         if (ret == -ENOTSUP)
14706                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14707                                                 res->vf_id,
14708                                                 &stats);
14709 #endif
14710 #ifdef RTE_LIBRTE_BNXT_PMD
14711         if (ret == -ENOTSUP)
14712                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14713                                                 res->vf_id,
14714                                                 &stats);
14715 #endif
14716
14717         switch (ret) {
14718         case 0:
14719                 break;
14720         case -EINVAL:
14721                 printf("invalid vf_id %d\n", res->vf_id);
14722                 break;
14723         case -ENODEV:
14724                 printf("invalid port_id %d\n", res->port_id);
14725                 break;
14726         case -ENOTSUP:
14727                 printf("function not implemented\n");
14728                 break;
14729         default:
14730                 printf("programming error: (%s)\n", strerror(-ret));
14731         }
14732
14733         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14734                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14735
14736         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14737                "%-"PRIu64"\n",
14738                stats.ipackets, stats.imissed, stats.ibytes);
14739         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14740         printf("  RX-nombuf:  %-10"PRIu64"\n",
14741                stats.rx_nombuf);
14742         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14743                "%-"PRIu64"\n",
14744                stats.opackets, stats.oerrors, stats.obytes);
14745
14746         printf("  %s############################%s\n",
14747                                nic_stats_border, nic_stats_border);
14748 }
14749
14750 cmdline_parse_inst_t cmd_show_vf_stats = {
14751         .f = cmd_show_vf_stats_parsed,
14752         .data = NULL,
14753         .help_str = "show vf stats <port_id> <vf_id>",
14754         .tokens = {
14755                 (void *)&cmd_show_vf_stats_show,
14756                 (void *)&cmd_show_vf_stats_vf,
14757                 (void *)&cmd_show_vf_stats_stats,
14758                 (void *)&cmd_show_vf_stats_port_id,
14759                 (void *)&cmd_show_vf_stats_vf_id,
14760                 NULL,
14761         },
14762 };
14763
14764 /* clear vf stats */
14765
14766 /* Common result structure for clear vf stats */
14767 struct cmd_clear_vf_stats_result {
14768         cmdline_fixed_string_t clear;
14769         cmdline_fixed_string_t vf;
14770         cmdline_fixed_string_t stats;
14771         portid_t port_id;
14772         uint16_t vf_id;
14773 };
14774
14775 /* Common CLI fields clear vf stats*/
14776 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14777         TOKEN_STRING_INITIALIZER
14778                 (struct cmd_clear_vf_stats_result,
14779                  clear, "clear");
14780 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14781         TOKEN_STRING_INITIALIZER
14782                 (struct cmd_clear_vf_stats_result,
14783                  vf, "vf");
14784 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14785         TOKEN_STRING_INITIALIZER
14786                 (struct cmd_clear_vf_stats_result,
14787                  stats, "stats");
14788 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14789         TOKEN_NUM_INITIALIZER
14790                 (struct cmd_clear_vf_stats_result,
14791                  port_id, UINT16);
14792 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14793         TOKEN_NUM_INITIALIZER
14794                 (struct cmd_clear_vf_stats_result,
14795                  vf_id, UINT16);
14796
14797 static void
14798 cmd_clear_vf_stats_parsed(
14799         void *parsed_result,
14800         __attribute__((unused)) struct cmdline *cl,
14801         __attribute__((unused)) void *data)
14802 {
14803         struct cmd_clear_vf_stats_result *res = parsed_result;
14804         int ret = -ENOTSUP;
14805
14806         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14807                 return;
14808
14809 #ifdef RTE_LIBRTE_I40E_PMD
14810         if (ret == -ENOTSUP)
14811                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14812                                                   res->vf_id);
14813 #endif
14814 #ifdef RTE_LIBRTE_BNXT_PMD
14815         if (ret == -ENOTSUP)
14816                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14817                                                   res->vf_id);
14818 #endif
14819
14820         switch (ret) {
14821         case 0:
14822                 break;
14823         case -EINVAL:
14824                 printf("invalid vf_id %d\n", res->vf_id);
14825                 break;
14826         case -ENODEV:
14827                 printf("invalid port_id %d\n", res->port_id);
14828                 break;
14829         case -ENOTSUP:
14830                 printf("function not implemented\n");
14831                 break;
14832         default:
14833                 printf("programming error: (%s)\n", strerror(-ret));
14834         }
14835 }
14836
14837 cmdline_parse_inst_t cmd_clear_vf_stats = {
14838         .f = cmd_clear_vf_stats_parsed,
14839         .data = NULL,
14840         .help_str = "clear vf stats <port_id> <vf_id>",
14841         .tokens = {
14842                 (void *)&cmd_clear_vf_stats_clear,
14843                 (void *)&cmd_clear_vf_stats_vf,
14844                 (void *)&cmd_clear_vf_stats_stats,
14845                 (void *)&cmd_clear_vf_stats_port_id,
14846                 (void *)&cmd_clear_vf_stats_vf_id,
14847                 NULL,
14848         },
14849 };
14850
14851 /* port config pctype mapping reset */
14852
14853 /* Common result structure for port config pctype mapping reset */
14854 struct cmd_pctype_mapping_reset_result {
14855         cmdline_fixed_string_t port;
14856         cmdline_fixed_string_t config;
14857         portid_t port_id;
14858         cmdline_fixed_string_t pctype;
14859         cmdline_fixed_string_t mapping;
14860         cmdline_fixed_string_t reset;
14861 };
14862
14863 /* Common CLI fields for port config pctype mapping reset*/
14864 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14865         TOKEN_STRING_INITIALIZER
14866                 (struct cmd_pctype_mapping_reset_result,
14867                  port, "port");
14868 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14869         TOKEN_STRING_INITIALIZER
14870                 (struct cmd_pctype_mapping_reset_result,
14871                  config, "config");
14872 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14873         TOKEN_NUM_INITIALIZER
14874                 (struct cmd_pctype_mapping_reset_result,
14875                  port_id, UINT16);
14876 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14877         TOKEN_STRING_INITIALIZER
14878                 (struct cmd_pctype_mapping_reset_result,
14879                  pctype, "pctype");
14880 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14881         TOKEN_STRING_INITIALIZER
14882                 (struct cmd_pctype_mapping_reset_result,
14883                  mapping, "mapping");
14884 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14885         TOKEN_STRING_INITIALIZER
14886                 (struct cmd_pctype_mapping_reset_result,
14887                  reset, "reset");
14888
14889 static void
14890 cmd_pctype_mapping_reset_parsed(
14891         void *parsed_result,
14892         __attribute__((unused)) struct cmdline *cl,
14893         __attribute__((unused)) void *data)
14894 {
14895         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14896         int ret = -ENOTSUP;
14897
14898         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14899                 return;
14900
14901 #ifdef RTE_LIBRTE_I40E_PMD
14902         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14903 #endif
14904
14905         switch (ret) {
14906         case 0:
14907                 break;
14908         case -ENODEV:
14909                 printf("invalid port_id %d\n", res->port_id);
14910                 break;
14911         case -ENOTSUP:
14912                 printf("function not implemented\n");
14913                 break;
14914         default:
14915                 printf("programming error: (%s)\n", strerror(-ret));
14916         }
14917 }
14918
14919 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14920         .f = cmd_pctype_mapping_reset_parsed,
14921         .data = NULL,
14922         .help_str = "port config <port_id> pctype mapping reset",
14923         .tokens = {
14924                 (void *)&cmd_pctype_mapping_reset_port,
14925                 (void *)&cmd_pctype_mapping_reset_config,
14926                 (void *)&cmd_pctype_mapping_reset_port_id,
14927                 (void *)&cmd_pctype_mapping_reset_pctype,
14928                 (void *)&cmd_pctype_mapping_reset_mapping,
14929                 (void *)&cmd_pctype_mapping_reset_reset,
14930                 NULL,
14931         },
14932 };
14933
14934 /* show port pctype mapping */
14935
14936 /* Common result structure for show port pctype mapping */
14937 struct cmd_pctype_mapping_get_result {
14938         cmdline_fixed_string_t show;
14939         cmdline_fixed_string_t port;
14940         portid_t port_id;
14941         cmdline_fixed_string_t pctype;
14942         cmdline_fixed_string_t mapping;
14943 };
14944
14945 /* Common CLI fields for pctype mapping get */
14946 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14947         TOKEN_STRING_INITIALIZER
14948                 (struct cmd_pctype_mapping_get_result,
14949                  show, "show");
14950 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14951         TOKEN_STRING_INITIALIZER
14952                 (struct cmd_pctype_mapping_get_result,
14953                  port, "port");
14954 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14955         TOKEN_NUM_INITIALIZER
14956                 (struct cmd_pctype_mapping_get_result,
14957                  port_id, UINT16);
14958 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14959         TOKEN_STRING_INITIALIZER
14960                 (struct cmd_pctype_mapping_get_result,
14961                  pctype, "pctype");
14962 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14963         TOKEN_STRING_INITIALIZER
14964                 (struct cmd_pctype_mapping_get_result,
14965                  mapping, "mapping");
14966
14967 static void
14968 cmd_pctype_mapping_get_parsed(
14969         void *parsed_result,
14970         __attribute__((unused)) struct cmdline *cl,
14971         __attribute__((unused)) void *data)
14972 {
14973         struct cmd_pctype_mapping_get_result *res = parsed_result;
14974         int ret = -ENOTSUP;
14975 #ifdef RTE_LIBRTE_I40E_PMD
14976         struct rte_pmd_i40e_flow_type_mapping
14977                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14978         int i, j, first_pctype;
14979 #endif
14980
14981         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14982                 return;
14983
14984 #ifdef RTE_LIBRTE_I40E_PMD
14985         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14986 #endif
14987
14988         switch (ret) {
14989         case 0:
14990                 break;
14991         case -ENODEV:
14992                 printf("invalid port_id %d\n", res->port_id);
14993                 return;
14994         case -ENOTSUP:
14995                 printf("function not implemented\n");
14996                 return;
14997         default:
14998                 printf("programming error: (%s)\n", strerror(-ret));
14999                 return;
15000         }
15001
15002 #ifdef RTE_LIBRTE_I40E_PMD
15003         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15004                 if (mapping[i].pctype != 0ULL) {
15005                         first_pctype = 1;
15006
15007                         printf("pctype: ");
15008                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15009                                 if (mapping[i].pctype & (1ULL << j)) {
15010                                         printf(first_pctype ?
15011                                                "%02d" : ",%02d", j);
15012                                         first_pctype = 0;
15013                                 }
15014                         }
15015                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15016                 }
15017         }
15018 #endif
15019 }
15020
15021 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15022         .f = cmd_pctype_mapping_get_parsed,
15023         .data = NULL,
15024         .help_str = "show port <port_id> pctype mapping",
15025         .tokens = {
15026                 (void *)&cmd_pctype_mapping_get_show,
15027                 (void *)&cmd_pctype_mapping_get_port,
15028                 (void *)&cmd_pctype_mapping_get_port_id,
15029                 (void *)&cmd_pctype_mapping_get_pctype,
15030                 (void *)&cmd_pctype_mapping_get_mapping,
15031                 NULL,
15032         },
15033 };
15034
15035 /* port config pctype mapping update */
15036
15037 /* Common result structure for port config pctype mapping update */
15038 struct cmd_pctype_mapping_update_result {
15039         cmdline_fixed_string_t port;
15040         cmdline_fixed_string_t config;
15041         portid_t port_id;
15042         cmdline_fixed_string_t pctype;
15043         cmdline_fixed_string_t mapping;
15044         cmdline_fixed_string_t update;
15045         cmdline_fixed_string_t pctype_list;
15046         uint16_t flow_type;
15047 };
15048
15049 /* Common CLI fields for pctype mapping update*/
15050 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15051         TOKEN_STRING_INITIALIZER
15052                 (struct cmd_pctype_mapping_update_result,
15053                  port, "port");
15054 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15055         TOKEN_STRING_INITIALIZER
15056                 (struct cmd_pctype_mapping_update_result,
15057                  config, "config");
15058 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15059         TOKEN_NUM_INITIALIZER
15060                 (struct cmd_pctype_mapping_update_result,
15061                  port_id, UINT16);
15062 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15063         TOKEN_STRING_INITIALIZER
15064                 (struct cmd_pctype_mapping_update_result,
15065                  pctype, "pctype");
15066 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15067         TOKEN_STRING_INITIALIZER
15068                 (struct cmd_pctype_mapping_update_result,
15069                  mapping, "mapping");
15070 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15071         TOKEN_STRING_INITIALIZER
15072                 (struct cmd_pctype_mapping_update_result,
15073                  update, "update");
15074 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15075         TOKEN_STRING_INITIALIZER
15076                 (struct cmd_pctype_mapping_update_result,
15077                  pctype_list, NULL);
15078 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15079         TOKEN_NUM_INITIALIZER
15080                 (struct cmd_pctype_mapping_update_result,
15081                  flow_type, UINT16);
15082
15083 static void
15084 cmd_pctype_mapping_update_parsed(
15085         void *parsed_result,
15086         __attribute__((unused)) struct cmdline *cl,
15087         __attribute__((unused)) void *data)
15088 {
15089         struct cmd_pctype_mapping_update_result *res = parsed_result;
15090         int ret = -ENOTSUP;
15091 #ifdef RTE_LIBRTE_I40E_PMD
15092         struct rte_pmd_i40e_flow_type_mapping mapping;
15093         unsigned int i;
15094         unsigned int nb_item;
15095         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15096 #endif
15097
15098         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15099                 return;
15100
15101 #ifdef RTE_LIBRTE_I40E_PMD
15102         nb_item = parse_item_list(res->pctype_list, "pctypes",
15103                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15104         mapping.flow_type = res->flow_type;
15105         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15106                 mapping.pctype |= (1ULL << pctype_list[i]);
15107         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15108                                                 &mapping,
15109                                                 1,
15110                                                 0);
15111 #endif
15112
15113         switch (ret) {
15114         case 0:
15115                 break;
15116         case -EINVAL:
15117                 printf("invalid pctype or flow type\n");
15118                 break;
15119         case -ENODEV:
15120                 printf("invalid port_id %d\n", res->port_id);
15121                 break;
15122         case -ENOTSUP:
15123                 printf("function not implemented\n");
15124                 break;
15125         default:
15126                 printf("programming error: (%s)\n", strerror(-ret));
15127         }
15128 }
15129
15130 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15131         .f = cmd_pctype_mapping_update_parsed,
15132         .data = NULL,
15133         .help_str = "port config <port_id> pctype mapping update"
15134         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15135         .tokens = {
15136                 (void *)&cmd_pctype_mapping_update_port,
15137                 (void *)&cmd_pctype_mapping_update_config,
15138                 (void *)&cmd_pctype_mapping_update_port_id,
15139                 (void *)&cmd_pctype_mapping_update_pctype,
15140                 (void *)&cmd_pctype_mapping_update_mapping,
15141                 (void *)&cmd_pctype_mapping_update_update,
15142                 (void *)&cmd_pctype_mapping_update_pc_type,
15143                 (void *)&cmd_pctype_mapping_update_flow_type,
15144                 NULL,
15145         },
15146 };
15147
15148 /* ptype mapping get */
15149
15150 /* Common result structure for ptype mapping get */
15151 struct cmd_ptype_mapping_get_result {
15152         cmdline_fixed_string_t ptype;
15153         cmdline_fixed_string_t mapping;
15154         cmdline_fixed_string_t get;
15155         portid_t port_id;
15156         uint8_t valid_only;
15157 };
15158
15159 /* Common CLI fields for ptype mapping get */
15160 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15161         TOKEN_STRING_INITIALIZER
15162                 (struct cmd_ptype_mapping_get_result,
15163                  ptype, "ptype");
15164 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15165         TOKEN_STRING_INITIALIZER
15166                 (struct cmd_ptype_mapping_get_result,
15167                  mapping, "mapping");
15168 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15169         TOKEN_STRING_INITIALIZER
15170                 (struct cmd_ptype_mapping_get_result,
15171                  get, "get");
15172 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15173         TOKEN_NUM_INITIALIZER
15174                 (struct cmd_ptype_mapping_get_result,
15175                  port_id, UINT16);
15176 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15177         TOKEN_NUM_INITIALIZER
15178                 (struct cmd_ptype_mapping_get_result,
15179                  valid_only, UINT8);
15180
15181 static void
15182 cmd_ptype_mapping_get_parsed(
15183         void *parsed_result,
15184         __attribute__((unused)) struct cmdline *cl,
15185         __attribute__((unused)) void *data)
15186 {
15187         struct cmd_ptype_mapping_get_result *res = parsed_result;
15188         int ret = -ENOTSUP;
15189 #ifdef RTE_LIBRTE_I40E_PMD
15190         int max_ptype_num = 256;
15191         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15192         uint16_t count;
15193         int i;
15194 #endif
15195
15196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15197                 return;
15198
15199 #ifdef RTE_LIBRTE_I40E_PMD
15200         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15201                                         mapping,
15202                                         max_ptype_num,
15203                                         &count,
15204                                         res->valid_only);
15205 #endif
15206
15207         switch (ret) {
15208         case 0:
15209                 break;
15210         case -ENODEV:
15211                 printf("invalid port_id %d\n", res->port_id);
15212                 break;
15213         case -ENOTSUP:
15214                 printf("function not implemented\n");
15215                 break;
15216         default:
15217                 printf("programming error: (%s)\n", strerror(-ret));
15218         }
15219
15220 #ifdef RTE_LIBRTE_I40E_PMD
15221         if (!ret) {
15222                 for (i = 0; i < count; i++)
15223                         printf("%3d\t0x%08x\n",
15224                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15225         }
15226 #endif
15227 }
15228
15229 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15230         .f = cmd_ptype_mapping_get_parsed,
15231         .data = NULL,
15232         .help_str = "ptype mapping get <port_id> <valid_only>",
15233         .tokens = {
15234                 (void *)&cmd_ptype_mapping_get_ptype,
15235                 (void *)&cmd_ptype_mapping_get_mapping,
15236                 (void *)&cmd_ptype_mapping_get_get,
15237                 (void *)&cmd_ptype_mapping_get_port_id,
15238                 (void *)&cmd_ptype_mapping_get_valid_only,
15239                 NULL,
15240         },
15241 };
15242
15243 /* ptype mapping replace */
15244
15245 /* Common result structure for ptype mapping replace */
15246 struct cmd_ptype_mapping_replace_result {
15247         cmdline_fixed_string_t ptype;
15248         cmdline_fixed_string_t mapping;
15249         cmdline_fixed_string_t replace;
15250         portid_t port_id;
15251         uint32_t target;
15252         uint8_t mask;
15253         uint32_t pkt_type;
15254 };
15255
15256 /* Common CLI fields for ptype mapping replace */
15257 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15258         TOKEN_STRING_INITIALIZER
15259                 (struct cmd_ptype_mapping_replace_result,
15260                  ptype, "ptype");
15261 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15262         TOKEN_STRING_INITIALIZER
15263                 (struct cmd_ptype_mapping_replace_result,
15264                  mapping, "mapping");
15265 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15266         TOKEN_STRING_INITIALIZER
15267                 (struct cmd_ptype_mapping_replace_result,
15268                  replace, "replace");
15269 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15270         TOKEN_NUM_INITIALIZER
15271                 (struct cmd_ptype_mapping_replace_result,
15272                  port_id, UINT16);
15273 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15274         TOKEN_NUM_INITIALIZER
15275                 (struct cmd_ptype_mapping_replace_result,
15276                  target, UINT32);
15277 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15278         TOKEN_NUM_INITIALIZER
15279                 (struct cmd_ptype_mapping_replace_result,
15280                  mask, UINT8);
15281 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15282         TOKEN_NUM_INITIALIZER
15283                 (struct cmd_ptype_mapping_replace_result,
15284                  pkt_type, UINT32);
15285
15286 static void
15287 cmd_ptype_mapping_replace_parsed(
15288         void *parsed_result,
15289         __attribute__((unused)) struct cmdline *cl,
15290         __attribute__((unused)) void *data)
15291 {
15292         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15293         int ret = -ENOTSUP;
15294
15295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15296                 return;
15297
15298 #ifdef RTE_LIBRTE_I40E_PMD
15299         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15300                                         res->target,
15301                                         res->mask,
15302                                         res->pkt_type);
15303 #endif
15304
15305         switch (ret) {
15306         case 0:
15307                 break;
15308         case -EINVAL:
15309                 printf("invalid ptype 0x%8x or 0x%8x\n",
15310                                 res->target, res->pkt_type);
15311                 break;
15312         case -ENODEV:
15313                 printf("invalid port_id %d\n", res->port_id);
15314                 break;
15315         case -ENOTSUP:
15316                 printf("function not implemented\n");
15317                 break;
15318         default:
15319                 printf("programming error: (%s)\n", strerror(-ret));
15320         }
15321 }
15322
15323 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15324         .f = cmd_ptype_mapping_replace_parsed,
15325         .data = NULL,
15326         .help_str =
15327                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15328         .tokens = {
15329                 (void *)&cmd_ptype_mapping_replace_ptype,
15330                 (void *)&cmd_ptype_mapping_replace_mapping,
15331                 (void *)&cmd_ptype_mapping_replace_replace,
15332                 (void *)&cmd_ptype_mapping_replace_port_id,
15333                 (void *)&cmd_ptype_mapping_replace_target,
15334                 (void *)&cmd_ptype_mapping_replace_mask,
15335                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15336                 NULL,
15337         },
15338 };
15339
15340 /* ptype mapping reset */
15341
15342 /* Common result structure for ptype mapping reset */
15343 struct cmd_ptype_mapping_reset_result {
15344         cmdline_fixed_string_t ptype;
15345         cmdline_fixed_string_t mapping;
15346         cmdline_fixed_string_t reset;
15347         portid_t port_id;
15348 };
15349
15350 /* Common CLI fields for ptype mapping reset*/
15351 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15352         TOKEN_STRING_INITIALIZER
15353                 (struct cmd_ptype_mapping_reset_result,
15354                  ptype, "ptype");
15355 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15356         TOKEN_STRING_INITIALIZER
15357                 (struct cmd_ptype_mapping_reset_result,
15358                  mapping, "mapping");
15359 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15360         TOKEN_STRING_INITIALIZER
15361                 (struct cmd_ptype_mapping_reset_result,
15362                  reset, "reset");
15363 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15364         TOKEN_NUM_INITIALIZER
15365                 (struct cmd_ptype_mapping_reset_result,
15366                  port_id, UINT16);
15367
15368 static void
15369 cmd_ptype_mapping_reset_parsed(
15370         void *parsed_result,
15371         __attribute__((unused)) struct cmdline *cl,
15372         __attribute__((unused)) void *data)
15373 {
15374         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15375         int ret = -ENOTSUP;
15376
15377         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15378                 return;
15379
15380 #ifdef RTE_LIBRTE_I40E_PMD
15381         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15382 #endif
15383
15384         switch (ret) {
15385         case 0:
15386                 break;
15387         case -ENODEV:
15388                 printf("invalid port_id %d\n", res->port_id);
15389                 break;
15390         case -ENOTSUP:
15391                 printf("function not implemented\n");
15392                 break;
15393         default:
15394                 printf("programming error: (%s)\n", strerror(-ret));
15395         }
15396 }
15397
15398 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15399         .f = cmd_ptype_mapping_reset_parsed,
15400         .data = NULL,
15401         .help_str = "ptype mapping reset <port_id>",
15402         .tokens = {
15403                 (void *)&cmd_ptype_mapping_reset_ptype,
15404                 (void *)&cmd_ptype_mapping_reset_mapping,
15405                 (void *)&cmd_ptype_mapping_reset_reset,
15406                 (void *)&cmd_ptype_mapping_reset_port_id,
15407                 NULL,
15408         },
15409 };
15410
15411 /* ptype mapping update */
15412
15413 /* Common result structure for ptype mapping update */
15414 struct cmd_ptype_mapping_update_result {
15415         cmdline_fixed_string_t ptype;
15416         cmdline_fixed_string_t mapping;
15417         cmdline_fixed_string_t reset;
15418         portid_t port_id;
15419         uint8_t hw_ptype;
15420         uint32_t sw_ptype;
15421 };
15422
15423 /* Common CLI fields for ptype mapping update*/
15424 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15425         TOKEN_STRING_INITIALIZER
15426                 (struct cmd_ptype_mapping_update_result,
15427                  ptype, "ptype");
15428 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15429         TOKEN_STRING_INITIALIZER
15430                 (struct cmd_ptype_mapping_update_result,
15431                  mapping, "mapping");
15432 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15433         TOKEN_STRING_INITIALIZER
15434                 (struct cmd_ptype_mapping_update_result,
15435                  reset, "update");
15436 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15437         TOKEN_NUM_INITIALIZER
15438                 (struct cmd_ptype_mapping_update_result,
15439                  port_id, UINT16);
15440 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15441         TOKEN_NUM_INITIALIZER
15442                 (struct cmd_ptype_mapping_update_result,
15443                  hw_ptype, UINT8);
15444 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15445         TOKEN_NUM_INITIALIZER
15446                 (struct cmd_ptype_mapping_update_result,
15447                  sw_ptype, UINT32);
15448
15449 static void
15450 cmd_ptype_mapping_update_parsed(
15451         void *parsed_result,
15452         __attribute__((unused)) struct cmdline *cl,
15453         __attribute__((unused)) void *data)
15454 {
15455         struct cmd_ptype_mapping_update_result *res = parsed_result;
15456         int ret = -ENOTSUP;
15457 #ifdef RTE_LIBRTE_I40E_PMD
15458         struct rte_pmd_i40e_ptype_mapping mapping;
15459 #endif
15460         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15461                 return;
15462
15463 #ifdef RTE_LIBRTE_I40E_PMD
15464         mapping.hw_ptype = res->hw_ptype;
15465         mapping.sw_ptype = res->sw_ptype;
15466         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15467                                                 &mapping,
15468                                                 1,
15469                                                 0);
15470 #endif
15471
15472         switch (ret) {
15473         case 0:
15474                 break;
15475         case -EINVAL:
15476                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15477                 break;
15478         case -ENODEV:
15479                 printf("invalid port_id %d\n", res->port_id);
15480                 break;
15481         case -ENOTSUP:
15482                 printf("function not implemented\n");
15483                 break;
15484         default:
15485                 printf("programming error: (%s)\n", strerror(-ret));
15486         }
15487 }
15488
15489 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15490         .f = cmd_ptype_mapping_update_parsed,
15491         .data = NULL,
15492         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15493         .tokens = {
15494                 (void *)&cmd_ptype_mapping_update_ptype,
15495                 (void *)&cmd_ptype_mapping_update_mapping,
15496                 (void *)&cmd_ptype_mapping_update_update,
15497                 (void *)&cmd_ptype_mapping_update_port_id,
15498                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15499                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15500                 NULL,
15501         },
15502 };
15503
15504 /* Common result structure for file commands */
15505 struct cmd_cmdfile_result {
15506         cmdline_fixed_string_t load;
15507         cmdline_fixed_string_t filename;
15508 };
15509
15510 /* Common CLI fields for file commands */
15511 cmdline_parse_token_string_t cmd_load_cmdfile =
15512         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15513 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15514         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15515
15516 static void
15517 cmd_load_from_file_parsed(
15518         void *parsed_result,
15519         __attribute__((unused)) struct cmdline *cl,
15520         __attribute__((unused)) void *data)
15521 {
15522         struct cmd_cmdfile_result *res = parsed_result;
15523
15524         cmdline_read_from_file(res->filename);
15525 }
15526
15527 cmdline_parse_inst_t cmd_load_from_file = {
15528         .f = cmd_load_from_file_parsed,
15529         .data = NULL,
15530         .help_str = "load <filename>",
15531         .tokens = {
15532                 (void *)&cmd_load_cmdfile,
15533                 (void *)&cmd_load_cmdfile_filename,
15534                 NULL,
15535         },
15536 };
15537
15538 /* ******************************************************************************** */
15539
15540 /* list of instructions */
15541 cmdline_parse_ctx_t main_ctx[] = {
15542         (cmdline_parse_inst_t *)&cmd_help_brief,
15543         (cmdline_parse_inst_t *)&cmd_help_long,
15544         (cmdline_parse_inst_t *)&cmd_quit,
15545         (cmdline_parse_inst_t *)&cmd_load_from_file,
15546         (cmdline_parse_inst_t *)&cmd_showport,
15547         (cmdline_parse_inst_t *)&cmd_showqueue,
15548         (cmdline_parse_inst_t *)&cmd_showportall,
15549         (cmdline_parse_inst_t *)&cmd_showcfg,
15550         (cmdline_parse_inst_t *)&cmd_start,
15551         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15552         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15553         (cmdline_parse_inst_t *)&cmd_set_link_up,
15554         (cmdline_parse_inst_t *)&cmd_set_link_down,
15555         (cmdline_parse_inst_t *)&cmd_reset,
15556         (cmdline_parse_inst_t *)&cmd_set_numbers,
15557         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15558         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15559         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15560         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15561         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15562         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15563         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15564         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15565         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15566         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15567         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15568         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15569         (cmdline_parse_inst_t *)&cmd_set_link_check,
15570         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15571         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15572         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15573         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15574 #ifdef RTE_LIBRTE_PMD_BOND
15575         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15576         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15577         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15578         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15579         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15580         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15581         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15582         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15583         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15584         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15585         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15586 #endif
15587         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15588         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15589         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15590         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15591         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15592         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15593         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15594         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15595         (cmdline_parse_inst_t *)&cmd_csum_set,
15596         (cmdline_parse_inst_t *)&cmd_csum_show,
15597         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15598         (cmdline_parse_inst_t *)&cmd_tso_set,
15599         (cmdline_parse_inst_t *)&cmd_tso_show,
15600         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15601         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15602         (cmdline_parse_inst_t *)&cmd_gro_enable,
15603         (cmdline_parse_inst_t *)&cmd_gro_flush,
15604         (cmdline_parse_inst_t *)&cmd_gro_show,
15605         (cmdline_parse_inst_t *)&cmd_gso_enable,
15606         (cmdline_parse_inst_t *)&cmd_gso_size,
15607         (cmdline_parse_inst_t *)&cmd_gso_show,
15608         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15609         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15610         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15611         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15612         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15613         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15614         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15615         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15616         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15617         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15618         (cmdline_parse_inst_t *)&cmd_config_dcb,
15619         (cmdline_parse_inst_t *)&cmd_read_reg,
15620         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15621         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15622         (cmdline_parse_inst_t *)&cmd_write_reg,
15623         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15624         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15625         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15626         (cmdline_parse_inst_t *)&cmd_stop,
15627         (cmdline_parse_inst_t *)&cmd_mac_addr,
15628         (cmdline_parse_inst_t *)&cmd_set_qmap,
15629         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15630         (cmdline_parse_inst_t *)&cmd_operate_port,
15631         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15632         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15633         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15634         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15635         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15636         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15637         (cmdline_parse_inst_t *)&cmd_config_mtu,
15638         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15639         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15640         (cmdline_parse_inst_t *)&cmd_config_rss,
15641         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15642         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15643         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15644         (cmdline_parse_inst_t *)&cmd_showport_reta,
15645         (cmdline_parse_inst_t *)&cmd_config_burst,
15646         (cmdline_parse_inst_t *)&cmd_config_thresh,
15647         (cmdline_parse_inst_t *)&cmd_config_threshold,
15648         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15649         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15650         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15651         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15652         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15653         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15654         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15655         (cmdline_parse_inst_t *)&cmd_global_config,
15656         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15657         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15658         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15659         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15660         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15661         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15662         (cmdline_parse_inst_t *)&cmd_dump,
15663         (cmdline_parse_inst_t *)&cmd_dump_one,
15664         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15665         (cmdline_parse_inst_t *)&cmd_syn_filter,
15666         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15667         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15668         (cmdline_parse_inst_t *)&cmd_flex_filter,
15669         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15670         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15671         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15672         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15673         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15674         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15675         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15676         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15677         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15678         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15679         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15680         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15681         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15682         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15683         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15684         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15685         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15686         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15687         (cmdline_parse_inst_t *)&cmd_flow,
15688         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15689         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15690         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15691         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15692         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15693         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15694         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15695         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15696         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15697         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15698         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15699         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15700         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15701         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15702         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15703         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15704         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15705         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15706         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15707         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15708         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15709         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15710         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15711         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15712         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15713         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15714         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15715         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15716         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15717         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15718         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15719         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15720         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15721         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15722         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15723         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15724         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15725         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15726         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15727         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15728         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15729         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15730         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15731         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15732         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15733 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15734         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15735 #endif
15736         (cmdline_parse_inst_t *)&cmd_ddp_add,
15737         (cmdline_parse_inst_t *)&cmd_ddp_del,
15738         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15739         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15740         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15741         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15742         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15743         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15744         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15745         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15746
15747         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15748         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15749         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15750         (cmdline_parse_inst_t *)&cmd_queue_region,
15751         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15752         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15753         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15754         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15755         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15756         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15757         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15758         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15759         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15760         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15761         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15762         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15763         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15764         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15765         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15766         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15767         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15768         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15769         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15770         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15771         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15772         NULL,
15773 };
15774
15775 /* read cmdline commands from file */
15776 void
15777 cmdline_read_from_file(const char *filename)
15778 {
15779         struct cmdline *cl;
15780
15781         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15782         if (cl == NULL) {
15783                 printf("Failed to create file based cmdline context: %s\n",
15784                        filename);
15785                 return;
15786         }
15787
15788         cmdline_interact(cl);
15789         cmdline_quit(cl);
15790
15791         cmdline_free(cl);
15792
15793         printf("Read CLI commands from %s\n", filename);
15794 }
15795
15796 /* prompt function, called from main on MASTER lcore */
15797 void
15798 prompt(void)
15799 {
15800         /* initialize non-constant commands */
15801         cmd_set_fwd_mode_init();
15802         cmd_set_fwd_retry_mode_init();
15803
15804         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15805         if (testpmd_cl == NULL)
15806                 return;
15807         cmdline_interact(testpmd_cl);
15808         cmdline_stdin_exit(testpmd_cl);
15809 }
15810
15811 void
15812 prompt_exit(void)
15813 {
15814         if (testpmd_cl != NULL)
15815                 cmdline_quit(testpmd_cl);
15816 }
15817
15818 static void
15819 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15820 {
15821         if (id == (portid_t)RTE_PORT_ALL) {
15822                 portid_t pid;
15823
15824                 RTE_ETH_FOREACH_DEV(pid) {
15825                         /* check if need_reconfig has been set to 1 */
15826                         if (ports[pid].need_reconfig == 0)
15827                                 ports[pid].need_reconfig = dev;
15828                         /* check if need_reconfig_queues has been set to 1 */
15829                         if (ports[pid].need_reconfig_queues == 0)
15830                                 ports[pid].need_reconfig_queues = queue;
15831                 }
15832         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15833                 /* check if need_reconfig has been set to 1 */
15834                 if (ports[id].need_reconfig == 0)
15835                         ports[id].need_reconfig = dev;
15836                 /* check if need_reconfig_queues has been set to 1 */
15837                 if (ports[id].need_reconfig_queues == 0)
15838                         ports[id].need_reconfig_queues = queue;
15839         }
15840 }