app/testpmd: convert to new Tx offloads API
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set xstats-hide-zero on|off\n"
530                         "    Set the option to hide the zero values"
531                         " for xstats display.\n"
532
533                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
534                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
535
536                         "set port (port_id) vf (vf_id) (mac_addr)"
537                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
538                         "   Add/Remove unicast or multicast MAC addr filter"
539                         " for a VF.\n\n"
540
541                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
542                         "|MPE) (on|off)\n"
543                         "    AUPE:accepts untagged VLAN;"
544                         "ROPE:accept unicast hash\n\n"
545                         "    BAM:accepts broadcast packets;"
546                         "MPE:accepts all multicast packets\n\n"
547                         "    Enable/Disable a VF receive mode of a port\n\n"
548
549                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
550                         "    Set rate limit for a queue of a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rate (rate_num) "
553                         "queue_mask (queue_mask_value)\n"
554                         "    Set rate limit for queues in VF of a port\n\n"
555
556                         "set port (port_id) mirror-rule (rule_id)"
557                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
558                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
559                         "   Set pool or vlan type mirror rule on a port.\n"
560                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
561                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
562                         " to pool 0.\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (uplink-mirror|downlink-mirror) dst-pool"
566                         " (pool_id) (on|off)\n"
567                         "   Set uplink or downlink type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
569                         " 0 on' enable mirror income traffic to pool 0.\n\n"
570
571                         "reset port (port_id) mirror-rule (rule_id)\n"
572                         "   Reset a mirror rule.\n\n"
573
574                         "set flush_rx (on|off)\n"
575                         "   Flush (default) or don't flush RX streams before"
576                         " forwarding. Mainly used with PCAP drivers.\n\n"
577
578                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the bypass mode for the lowest port on bypass enabled"
580                         " NIC.\n\n"
581
582                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
583                         "mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the event required to initiate specified bypass mode for"
585                         " the lowest port on a bypass enabled NIC where:\n"
586                         "       timeout   = enable bypass after watchdog timeout.\n"
587                         "       os_on     = enable bypass when OS/board is powered on.\n"
588                         "       os_off    = enable bypass when OS/board is powered off.\n"
589                         "       power_on  = enable bypass when power supply is turned on.\n"
590                         "       power_off = enable bypass when power supply is turned off."
591                         "\n\n"
592
593                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
594                         "   Set the bypass watchdog timeout to 'n' seconds"
595                         " where 0 = instant.\n\n"
596
597                         "show bypass config (port_id)\n"
598                         "   Show the bypass configuration for a bypass enabled NIC"
599                         " using the lowest port on the NIC.\n\n"
600
601 #ifdef RTE_LIBRTE_PMD_BOND
602                         "create bonded device (mode) (socket)\n"
603                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
604
605                         "add bonding slave (slave_id) (port_id)\n"
606                         "       Add a slave device to a bonded device.\n\n"
607
608                         "remove bonding slave (slave_id) (port_id)\n"
609                         "       Remove a slave device from a bonded device.\n\n"
610
611                         "set bonding mode (value) (port_id)\n"
612                         "       Set the bonding mode on a bonded device.\n\n"
613
614                         "set bonding primary (slave_id) (port_id)\n"
615                         "       Set the primary slave for a bonded device.\n\n"
616
617                         "show bonding config (port_id)\n"
618                         "       Show the bonding config for port_id.\n\n"
619
620                         "set bonding mac_addr (port_id) (address)\n"
621                         "       Set the MAC address of a bonded device.\n\n"
622
623                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
624                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
625
626                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
627                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
628
629                         "set bonding mon_period (port_id) (value)\n"
630                         "       Set the bonding link status monitoring polling period in ms.\n\n"
631
632                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
633                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
634
635 #endif
636                         "set link-up port (port_id)\n"
637                         "       Set link up for a port.\n\n"
638
639                         "set link-down port (port_id)\n"
640                         "       Set link down for a port.\n\n"
641
642                         "E-tag set insertion on port-tag-id (value)"
643                         " port (port_id) vf (vf_id)\n"
644                         "    Enable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
647                         "    Disable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set stripping (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag stripping on a port\n\n"
651
652                         "E-tag set forwarding (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag based forwarding"
654                         " on a port\n\n"
655
656                         "E-tag set filter add e-tag-id (value) dst-pool"
657                         " (pool_id) port (port_id)\n"
658                         "    Add an E-tag forwarding filter on a port\n\n"
659
660                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
661                         "    Delete an E-tag forwarding filter on a port\n\n"
662
663 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
664                         "set port tm hierarchy default (port_id)\n"
665                         "       Set default traffic Management hierarchy on a port\n\n"
666
667 #endif
668                         "ddp add (port_id) (profile_path[,output_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "queue_start_index (value) queue_num (value)\n"
688                         "    Set a queue region on a port\n\n"
689
690                         "set port (port_id) queue-region region_id (value) "
691                         "flowtype (value)\n"
692                         "    Set a flowtype region index on a port\n\n"
693
694                         "set port (port_id) queue-region UP (value) region_id (value)\n"
695                         "    Set the mapping of User Priority to "
696                         "queue region on a port\n\n"
697
698                         "set port (port_id) queue-region flush (on|off)\n"
699                         "    flush all queue region related configuration\n\n"
700
701                         "show port meter cap (port_id)\n"
702                         "    Show port meter capability information\n\n"
703
704                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
705                         "    meter profile add - srtcm rfc 2697\n\n"
706
707                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
708                         "    meter profile add - trtcm rfc 2698\n\n"
709
710                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
711                         "    meter profile add - trtcm rfc 4115\n\n"
712
713                         "del port meter profile (port_id) (profile_id)\n"
714                         "    meter profile delete\n\n"
715
716                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
717                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
718                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
719                         "(dscp_tbl_entry63)]\n"
720                         "    meter create\n\n"
721
722                         "enable port meter (port_id) (mtr_id)\n"
723                         "    meter enable\n\n"
724
725                         "disable port meter (port_id) (mtr_id)\n"
726                         "    meter disable\n\n"
727
728                         "del port meter (port_id) (mtr_id)\n"
729                         "    meter delete\n\n"
730
731                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
732                         "    meter update meter profile\n\n"
733
734                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
735                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
736                         "    update meter dscp table entries\n\n"
737
738                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
739                         "(action0) [(action1) (action2)]\n"
740                         "    meter update policer action\n\n"
741
742                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
743                         "    meter update stats\n\n"
744
745                         "show port (port_id) queue-region\n"
746                         "    show all queue region related configuration info\n\n"
747
748                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
749                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
750                         "       Add port tm node private shaper profile.\n\n"
751
752                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
753                         "       Delete port tm node private shaper profile.\n\n"
754
755                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
756                         " (shaper_profile_id)\n"
757                         "       Add/update port tm node shared shaper.\n\n"
758
759                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
760                         "       Delete port tm node shared shaper.\n\n"
761
762                         "set port tm node shaper profile (port_id) (node_id)"
763                         " (shaper_profile_id)\n"
764                         "       Set port tm node shaper profile.\n\n"
765
766                         "add port tm node wred profile (port_id) (wred_profile_id)"
767                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
768                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
769                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
770                         "       Add port tm node wred profile.\n\n"
771
772                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
773                         "       Delete port tm node wred profile.\n\n"
774
775                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
776                         " (priority) (weight) (level_id) (shaper_profile_id)"
777                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
778                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
779                         "       Add port tm nonleaf node.\n\n"
780
781                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm leaf node.\n\n"
786
787                         "del port tm node (port_id) (node_id)\n"
788                         "       Delete port tm node.\n\n"
789
790                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
791                         " (priority) (weight)\n"
792                         "       Set port tm node parent.\n\n"
793
794                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
795                         "       Commit tm hierarchy.\n\n"
796
797                         , list_pkt_forwarding_modes()
798                 );
799         }
800
801         if (show_all || !strcmp(res->section, "ports")) {
802
803                 cmdline_printf(
804                         cl,
805                         "\n"
806                         "Port Operations:\n"
807                         "----------------\n\n"
808
809                         "port start (port_id|all)\n"
810                         "    Start all ports or port_id.\n\n"
811
812                         "port stop (port_id|all)\n"
813                         "    Stop all ports or port_id.\n\n"
814
815                         "port close (port_id|all)\n"
816                         "    Close all ports or port_id.\n\n"
817
818                         "port attach (ident)\n"
819                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
820
821                         "port detach (port_id)\n"
822                         "    Detach physical or virtual dev by port_id\n\n"
823
824                         "port config (port_id|all)"
825                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
826                         " duplex (half|full|auto)\n"
827                         "    Set speed and duplex for all ports or port_id\n\n"
828
829                         "port config all (rxq|txq|rxd|txd) (value)\n"
830                         "    Set number for rxq/txq/rxd/txd.\n\n"
831
832                         "port config all max-pkt-len (value)\n"
833                         "    Set the max packet length.\n\n"
834
835                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
836                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
837                         " (on|off)\n"
838                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
839                         " for ports.\n\n"
840
841                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
842                         "geneve|nvgre|none|<flowtype_id>)\n"
843                         "    Set the RSS mode.\n\n"
844
845                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
846                         "    Set the RSS redirection table.\n\n"
847
848                         "port config (port_id) dcb vt (on|off) (traffic_class)"
849                         " pfc (on|off)\n"
850                         "    Set the DCB mode.\n\n"
851
852                         "port config all burst (value)\n"
853                         "    Set the number of packets per burst.\n\n"
854
855                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
856                         " (value)\n"
857                         "    Set the ring prefetch/host/writeback threshold"
858                         " for tx/rx queue.\n\n"
859
860                         "port config all (txfreet|txrst|rxfreet) (value)\n"
861                         "    Set free threshold for rx/tx, or set"
862                         " tx rs bit threshold.\n\n"
863                         "port config mtu X value\n"
864                         "    Set the MTU of port X to a given value\n\n"
865
866                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
867                         "    Start/stop a rx/tx queue of port X. Only take effect"
868                         " when port X is started\n\n"
869
870                         "port config (port_id|all) l2-tunnel E-tag ether-type"
871                         " (value)\n"
872                         "    Set the value of E-tag ether-type.\n\n"
873
874                         "port config (port_id|all) l2-tunnel E-tag"
875                         " (enable|disable)\n"
876                         "    Enable/disable the E-tag support.\n\n"
877
878                         "port config (port_id) pctype mapping reset\n"
879                         "    Reset flow type to pctype mapping on a port\n\n"
880
881                         "port config (port_id) pctype mapping update"
882                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
883                         "    Update a flow type to pctype mapping item on a port\n\n"
884                 );
885         }
886
887         if (show_all || !strcmp(res->section, "registers")) {
888
889                 cmdline_printf(
890                         cl,
891                         "\n"
892                         "Registers:\n"
893                         "----------\n\n"
894
895                         "read reg (port_id) (address)\n"
896                         "    Display value of a port register.\n\n"
897
898                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
899                         "    Display a port register bit field.\n\n"
900
901                         "read regbit (port_id) (address) (bit_x)\n"
902                         "    Display a single port register bit.\n\n"
903
904                         "write reg (port_id) (address) (value)\n"
905                         "    Set value of a port register.\n\n"
906
907                         "write regfield (port_id) (address) (bit_x) (bit_y)"
908                         " (value)\n"
909                         "    Set bit field of a port register.\n\n"
910
911                         "write regbit (port_id) (address) (bit_x) (value)\n"
912                         "    Set single bit value of a port register.\n\n"
913                 );
914         }
915         if (show_all || !strcmp(res->section, "filters")) {
916
917                 cmdline_printf(
918                         cl,
919                         "\n"
920                         "filters:\n"
921                         "--------\n\n"
922
923                         "ethertype_filter (port_id) (add|del)"
924                         " (mac_addr|mac_ignr) (mac_address) ethertype"
925                         " (ether_type) (drop|fwd) queue (queue_id)\n"
926                         "    Add/Del an ethertype filter.\n\n"
927
928                         "2tuple_filter (port_id) (add|del)"
929                         " dst_port (dst_port_value) protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 2tuple filter.\n\n"
933
934                         "5tuple_filter (port_id) (add|del)"
935                         " dst_ip (dst_address) src_ip (src_address)"
936                         " dst_port (dst_port_value) src_port (src_port_value)"
937                         " protocol (protocol_value)"
938                         " mask (mask_value) tcp_flags (tcp_flags_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a 5tuple filter.\n\n"
941
942                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
943                         "    Add/Del syn filter.\n\n"
944
945                         "flex_filter (port_id) (add|del) len (len_value)"
946                         " bytes (bytes_value) mask (mask_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a flex filter.\n\n"
949
950                         "flow_director_filter (port_id) mode IP (add|del|update)"
951                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
952                         " src (src_ip_address) dst (dst_ip_address)"
953                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
954                         " vlan (vlan_value) flexbytes (flexbytes_value)"
955                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
956                         " fd_id (fd_id_value)\n"
957                         "    Add/Del an IP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
961                         " src (src_ip_address) (src_port)"
962                         " dst (dst_ip_address) (dst_port)"
963                         " tos (tos_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-sctp|ipv6-sctp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tag (verification_tag) "
974                         " tos (tos_value) ttl (ttl_value)"
975                         " vlan (vlan_value)"
976                         " flexbytes (flexbytes_value) (drop|fwd)"
977                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
978                         "    Add/Del a SCTP type flow director filter.\n\n"
979
980                         "flow_director_filter (port_id) mode IP (add|del|update)"
981                         " flow l2_payload ether (ethertype)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a l2 payload type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
987                         " mac (mac_address) vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a Tunnel flow director filter.\n\n"
998
999                         "flush_flow_director (port_id)\n"
1000                         "    Flush all flow director entries of a device.\n\n"
1001
1002                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1003                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1004                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1005                         "    Set flow director IP mask.\n\n"
1006
1007                         "flow_director_mask (port_id) mode MAC-VLAN"
1008                         " vlan (vlan_value)\n"
1009                         "    Set flow director MAC-VLAN mask.\n\n"
1010
1011                         "flow_director_mask (port_id) mode Tunnel"
1012                         " vlan (vlan_value) mac (mac_value)"
1013                         " tunnel-type (tunnel_type_value)"
1014                         " tunnel-id (tunnel_id_value)\n"
1015                         "    Set flow director Tunnel mask.\n\n"
1016
1017                         "flow_director_flex_mask (port_id)"
1018                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1019                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1020                         " (mask)\n"
1021                         "    Configure mask of flex payload.\n\n"
1022
1023                         "flow_director_flex_payload (port_id)"
1024                         " (raw|l2|l3|l4) (config)\n"
1025                         "    Configure flex payload selection.\n\n"
1026
1027                         "get_sym_hash_ena_per_port (port_id)\n"
1028                         "    get symmetric hash enable configuration per port.\n\n"
1029
1030                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1031                         "    set symmetric hash enable configuration per port"
1032                         " to enable or disable.\n\n"
1033
1034                         "get_hash_global_config (port_id)\n"
1035                         "    Get the global configurations of hash filters.\n\n"
1036
1037                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1038                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1039                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1040                         " (enable|disable)\n"
1041                         "    Set the global configurations of hash filters.\n\n"
1042
1043                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1044                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1045                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1046                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1047                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1048                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1049                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1050                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1051                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1052                         "fld-8th|none) (select|add)\n"
1053                         "    Set the input set for hash.\n\n"
1054
1055                         "set_fdir_input_set (port_id) "
1056                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1058                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1059                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1060                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1061                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1062                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1063                         " (select|add)\n"
1064                         "    Set the input set for FDir.\n\n"
1065
1066                         "flow validate {port_id}"
1067                         " [group {group_id}] [priority {level}]"
1068                         " [ingress] [egress]"
1069                         " pattern {item} [/ {item} [...]] / end"
1070                         " actions {action} [/ {action} [...]] / end\n"
1071                         "    Check whether a flow rule can be created.\n\n"
1072
1073                         "flow create {port_id}"
1074                         " [group {group_id}] [priority {level}]"
1075                         " [ingress] [egress]"
1076                         " pattern {item} [/ {item} [...]] / end"
1077                         " actions {action} [/ {action} [...]] / end\n"
1078                         "    Create a flow rule.\n\n"
1079
1080                         "flow destroy {port_id} rule {rule_id} [...]\n"
1081                         "    Destroy specific flow rules.\n\n"
1082
1083                         "flow flush {port_id}\n"
1084                         "    Destroy all flow rules.\n\n"
1085
1086                         "flow query {port_id} {rule_id} {action}\n"
1087                         "    Query an existing flow rule.\n\n"
1088
1089                         "flow list {port_id} [group {group_id}] [...]\n"
1090                         "    List existing flow rules sorted by priority,"
1091                         " filtered by group identifiers.\n\n"
1092
1093                         "flow isolate {port_id} {boolean}\n"
1094                         "    Restrict ingress traffic to the defined"
1095                         " flow rules\n\n"
1096                 );
1097         }
1098 }
1099
1100 cmdline_parse_token_string_t cmd_help_long_help =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1102
1103 cmdline_parse_token_string_t cmd_help_long_section =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1105                         "all#control#display#config#"
1106                         "ports#registers#filters");
1107
1108 cmdline_parse_inst_t cmd_help_long = {
1109         .f = cmd_help_long_parsed,
1110         .data = NULL,
1111         .help_str = "help all|control|display|config|ports|register|filters: "
1112                 "Show help",
1113         .tokens = {
1114                 (void *)&cmd_help_long_help,
1115                 (void *)&cmd_help_long_section,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 /* *** start/stop/close all ports *** */
1122 struct cmd_operate_port_result {
1123         cmdline_fixed_string_t keyword;
1124         cmdline_fixed_string_t name;
1125         cmdline_fixed_string_t value;
1126 };
1127
1128 static void cmd_operate_port_parsed(void *parsed_result,
1129                                 __attribute__((unused)) struct cmdline *cl,
1130                                 __attribute__((unused)) void *data)
1131 {
1132         struct cmd_operate_port_result *res = parsed_result;
1133
1134         if (!strcmp(res->name, "start"))
1135                 start_port(RTE_PORT_ALL);
1136         else if (!strcmp(res->name, "stop"))
1137                 stop_port(RTE_PORT_ALL);
1138         else if (!strcmp(res->name, "close"))
1139                 close_port(RTE_PORT_ALL);
1140         else if (!strcmp(res->name, "reset"))
1141                 reset_port(RTE_PORT_ALL);
1142         else
1143                 printf("Unknown parameter\n");
1144 }
1145
1146 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1148                                                                 "port");
1149 cmdline_parse_token_string_t cmd_operate_port_all_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1151                                                 "start#stop#close#reset");
1152 cmdline_parse_token_string_t cmd_operate_port_all_all =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1154
1155 cmdline_parse_inst_t cmd_operate_port = {
1156         .f = cmd_operate_port_parsed,
1157         .data = NULL,
1158         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1159         .tokens = {
1160                 (void *)&cmd_operate_port_all_cmd,
1161                 (void *)&cmd_operate_port_all_port,
1162                 (void *)&cmd_operate_port_all_all,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** start/stop/close specific port *** */
1168 struct cmd_operate_specific_port_result {
1169         cmdline_fixed_string_t keyword;
1170         cmdline_fixed_string_t name;
1171         uint8_t value;
1172 };
1173
1174 static void cmd_operate_specific_port_parsed(void *parsed_result,
1175                         __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_operate_specific_port_result *res = parsed_result;
1179
1180         if (!strcmp(res->name, "start"))
1181                 start_port(res->value);
1182         else if (!strcmp(res->name, "stop"))
1183                 stop_port(res->value);
1184         else if (!strcmp(res->name, "close"))
1185                 close_port(res->value);
1186         else if (!strcmp(res->name, "reset"))
1187                 reset_port(res->value);
1188         else
1189                 printf("Unknown parameter\n");
1190 }
1191
1192 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                         keyword, "port");
1195 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                 name, "start#stop#close#reset");
1198 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1199         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                         value, UINT8);
1201
1202 cmdline_parse_inst_t cmd_operate_specific_port = {
1203         .f = cmd_operate_specific_port_parsed,
1204         .data = NULL,
1205         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1206         .tokens = {
1207                 (void *)&cmd_operate_specific_port_cmd,
1208                 (void *)&cmd_operate_specific_port_port,
1209                 (void *)&cmd_operate_specific_port_id,
1210                 NULL,
1211         },
1212 };
1213
1214 /* *** attach a specified port *** */
1215 struct cmd_operate_attach_port_result {
1216         cmdline_fixed_string_t port;
1217         cmdline_fixed_string_t keyword;
1218         cmdline_fixed_string_t identifier;
1219 };
1220
1221 static void cmd_operate_attach_port_parsed(void *parsed_result,
1222                                 __attribute__((unused)) struct cmdline *cl,
1223                                 __attribute__((unused)) void *data)
1224 {
1225         struct cmd_operate_attach_port_result *res = parsed_result;
1226
1227         if (!strcmp(res->keyword, "attach"))
1228                 attach_port(res->identifier);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         port, "port");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         keyword, "attach");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         identifier, NULL);
1242
1243 cmdline_parse_inst_t cmd_operate_attach_port = {
1244         .f = cmd_operate_attach_port_parsed,
1245         .data = NULL,
1246         .help_str = "port attach <identifier>: "
1247                 "(identifier: pci address or virtual dev name)",
1248         .tokens = {
1249                 (void *)&cmd_operate_attach_port_port,
1250                 (void *)&cmd_operate_attach_port_keyword,
1251                 (void *)&cmd_operate_attach_port_identifier,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** detach a specified port *** */
1257 struct cmd_operate_detach_port_result {
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t keyword;
1260         portid_t port_id;
1261 };
1262
1263 static void cmd_operate_detach_port_parsed(void *parsed_result,
1264                                 __attribute__((unused)) struct cmdline *cl,
1265                                 __attribute__((unused)) void *data)
1266 {
1267         struct cmd_operate_detach_port_result *res = parsed_result;
1268
1269         if (!strcmp(res->keyword, "detach"))
1270                 detach_port(res->port_id);
1271         else
1272                 printf("Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         port, "port");
1278 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         keyword, "detach");
1281 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         port_id, UINT16);
1284
1285 cmdline_parse_inst_t cmd_operate_detach_port = {
1286         .f = cmd_operate_detach_port_parsed,
1287         .data = NULL,
1288         .help_str = "port detach <port_id>",
1289         .tokens = {
1290                 (void *)&cmd_operate_detach_port_port,
1291                 (void *)&cmd_operate_detach_port_keyword,
1292                 (void *)&cmd_operate_detach_port_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** configure speed for all ports *** */
1298 struct cmd_config_speed_all {
1299         cmdline_fixed_string_t port;
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t all;
1302         cmdline_fixed_string_t item1;
1303         cmdline_fixed_string_t item2;
1304         cmdline_fixed_string_t value1;
1305         cmdline_fixed_string_t value2;
1306 };
1307
1308 static int
1309 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1310 {
1311
1312         int duplex;
1313
1314         if (!strcmp(duplexstr, "half")) {
1315                 duplex = ETH_LINK_HALF_DUPLEX;
1316         } else if (!strcmp(duplexstr, "full")) {
1317                 duplex = ETH_LINK_FULL_DUPLEX;
1318         } else if (!strcmp(duplexstr, "auto")) {
1319                 duplex = ETH_LINK_FULL_DUPLEX;
1320         } else {
1321                 printf("Unknown duplex parameter\n");
1322                 return -1;
1323         }
1324
1325         if (!strcmp(speedstr, "10")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1328         } else if (!strcmp(speedstr, "100")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1331         } else {
1332                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1333                         printf("Invalid speed/duplex parameters\n");
1334                         return -1;
1335                 }
1336                 if (!strcmp(speedstr, "1000")) {
1337                         *speed = ETH_LINK_SPEED_1G;
1338                 } else if (!strcmp(speedstr, "10000")) {
1339                         *speed = ETH_LINK_SPEED_10G;
1340                 } else if (!strcmp(speedstr, "25000")) {
1341                         *speed = ETH_LINK_SPEED_25G;
1342                 } else if (!strcmp(speedstr, "40000")) {
1343                         *speed = ETH_LINK_SPEED_40G;
1344                 } else if (!strcmp(speedstr, "50000")) {
1345                         *speed = ETH_LINK_SPEED_50G;
1346                 } else if (!strcmp(speedstr, "100000")) {
1347                         *speed = ETH_LINK_SPEED_100G;
1348                 } else if (!strcmp(speedstr, "auto")) {
1349                         *speed = ETH_LINK_SPEED_AUTONEG;
1350                 } else {
1351                         printf("Unknown speed parameter\n");
1352                         return -1;
1353                 }
1354         }
1355
1356         return 0;
1357 }
1358
1359 static void
1360 cmd_config_speed_all_parsed(void *parsed_result,
1361                         __attribute__((unused)) struct cmdline *cl,
1362                         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_config_speed_all *res = parsed_result;
1365         uint32_t link_speed;
1366         portid_t pid;
1367
1368         if (!all_ports_stopped()) {
1369                 printf("Please stop all ports first\n");
1370                 return;
1371         }
1372
1373         if (parse_and_check_speed_duplex(res->value1, res->value2,
1374                         &link_speed) < 0)
1375                 return;
1376
1377         RTE_ETH_FOREACH_DEV(pid) {
1378                 ports[pid].dev_conf.link_speeds = link_speed;
1379         }
1380
1381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1382 }
1383
1384 cmdline_parse_token_string_t cmd_config_speed_all_port =
1385         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1386 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1388                                                         "config");
1389 cmdline_parse_token_string_t cmd_config_speed_all_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1391 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1393 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1395                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1400                                                 "half#full#auto");
1401
1402 cmdline_parse_inst_t cmd_config_speed_all = {
1403         .f = cmd_config_speed_all_parsed,
1404         .data = NULL,
1405         .help_str = "port config all speed "
1406                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1407                                                         "half|full|auto",
1408         .tokens = {
1409                 (void *)&cmd_config_speed_all_port,
1410                 (void *)&cmd_config_speed_all_keyword,
1411                 (void *)&cmd_config_speed_all_all,
1412                 (void *)&cmd_config_speed_all_item1,
1413                 (void *)&cmd_config_speed_all_value1,
1414                 (void *)&cmd_config_speed_all_item2,
1415                 (void *)&cmd_config_speed_all_value2,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** configure speed for specific port *** */
1421 struct cmd_config_speed_specific {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         uint8_t id;
1425         cmdline_fixed_string_t item1;
1426         cmdline_fixed_string_t item2;
1427         cmdline_fixed_string_t value1;
1428         cmdline_fixed_string_t value2;
1429 };
1430
1431 static void
1432 cmd_config_speed_specific_parsed(void *parsed_result,
1433                                 __attribute__((unused)) struct cmdline *cl,
1434                                 __attribute__((unused)) void *data)
1435 {
1436         struct cmd_config_speed_specific *res = parsed_result;
1437         uint32_t link_speed;
1438
1439         if (!all_ports_stopped()) {
1440                 printf("Please stop all ports first\n");
1441                 return;
1442         }
1443
1444         if (port_id_is_invalid(res->id, ENABLED_WARN))
1445                 return;
1446
1447         if (parse_and_check_speed_duplex(res->value1, res->value2,
1448                         &link_speed) < 0)
1449                 return;
1450
1451         ports[res->id].dev_conf.link_speeds = link_speed;
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456
1457 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1459                                                                 "port");
1460 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1462                                                                 "config");
1463 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1464         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1465 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1467                                                                 "speed");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1470                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1473                                                                 "duplex");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1476                                                         "half#full#auto");
1477
1478 cmdline_parse_inst_t cmd_config_speed_specific = {
1479         .f = cmd_config_speed_specific_parsed,
1480         .data = NULL,
1481         .help_str = "port config <port_id> speed "
1482                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1483                                                         "half|full|auto",
1484         .tokens = {
1485                 (void *)&cmd_config_speed_specific_port,
1486                 (void *)&cmd_config_speed_specific_keyword,
1487                 (void *)&cmd_config_speed_specific_id,
1488                 (void *)&cmd_config_speed_specific_item1,
1489                 (void *)&cmd_config_speed_specific_value1,
1490                 (void *)&cmd_config_speed_specific_item2,
1491                 (void *)&cmd_config_speed_specific_value2,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure txq/rxq, txd/rxd *** */
1497 struct cmd_config_rx_tx {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t name;
1502         uint16_t value;
1503 };
1504
1505 static void
1506 cmd_config_rx_tx_parsed(void *parsed_result,
1507                         __attribute__((unused)) struct cmdline *cl,
1508                         __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_rx_tx *res = parsed_result;
1511
1512         if (!all_ports_stopped()) {
1513                 printf("Please stop all ports first\n");
1514                 return;
1515         }
1516         if (!strcmp(res->name, "rxq")) {
1517                 if (!res->value && !nb_txq) {
1518                         printf("Warning: Either rx or tx queues should be non zero\n");
1519                         return;
1520                 }
1521                 nb_rxq = res->value;
1522         }
1523         else if (!strcmp(res->name, "txq")) {
1524                 if (!res->value && !nb_rxq) {
1525                         printf("Warning: Either rx or tx queues should be non zero\n");
1526                         return;
1527                 }
1528                 nb_txq = res->value;
1529         }
1530         else if (!strcmp(res->name, "rxd")) {
1531                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1532                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1533                                         res->value, RTE_TEST_RX_DESC_MAX);
1534                         return;
1535                 }
1536                 nb_rxd = res->value;
1537         } else if (!strcmp(res->name, "txd")) {
1538                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1539                         printf("txd %d invalid - must be > 0 && <= %d\n",
1540                                         res->value, RTE_TEST_TX_DESC_MAX);
1541                         return;
1542                 }
1543                 nb_txd = res->value;
1544         } else {
1545                 printf("Unknown parameter\n");
1546                 return;
1547         }
1548
1549         fwd_config_setup();
1550
1551         init_port_config();
1552
1553         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1558 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1560 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1562 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1564                                                 "rxq#txq#rxd#txd");
1565 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1566         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1567
1568 cmdline_parse_inst_t cmd_config_rx_tx = {
1569         .f = cmd_config_rx_tx_parsed,
1570         .data = NULL,
1571         .help_str = "port config all rxq|txq|rxd|txd <value>",
1572         .tokens = {
1573                 (void *)&cmd_config_rx_tx_port,
1574                 (void *)&cmd_config_rx_tx_keyword,
1575                 (void *)&cmd_config_rx_tx_all,
1576                 (void *)&cmd_config_rx_tx_name,
1577                 (void *)&cmd_config_rx_tx_value,
1578                 NULL,
1579         },
1580 };
1581
1582 /* *** config max packet length *** */
1583 struct cmd_config_max_pkt_len_result {
1584         cmdline_fixed_string_t port;
1585         cmdline_fixed_string_t keyword;
1586         cmdline_fixed_string_t all;
1587         cmdline_fixed_string_t name;
1588         uint32_t value;
1589 };
1590
1591 static void
1592 cmd_config_max_pkt_len_parsed(void *parsed_result,
1593                                 __attribute__((unused)) struct cmdline *cl,
1594                                 __attribute__((unused)) void *data)
1595 {
1596         struct cmd_config_max_pkt_len_result *res = parsed_result;
1597         uint64_t rx_offloads = rx_mode.offloads;
1598
1599         if (!all_ports_stopped()) {
1600                 printf("Please stop all ports first\n");
1601                 return;
1602         }
1603
1604         if (!strcmp(res->name, "max-pkt-len")) {
1605                 if (res->value < ETHER_MIN_LEN) {
1606                         printf("max-pkt-len can not be less than %d\n",
1607                                                         ETHER_MIN_LEN);
1608                         return;
1609                 }
1610                 if (res->value == rx_mode.max_rx_pkt_len)
1611                         return;
1612
1613                 rx_mode.max_rx_pkt_len = res->value;
1614                 if (res->value > ETHER_MAX_LEN)
1615                         rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1616                 else
1617                         rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1618         } else {
1619                 printf("Unknown parameter\n");
1620                 return;
1621         }
1622
1623         rx_mode.offloads = rx_offloads;
1624
1625         init_port_config();
1626
1627         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1628 }
1629
1630 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1632                                                                 "port");
1633 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1635                                                                 "config");
1636 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1638                                                                 "all");
1639 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1641                                                                 "max-pkt-len");
1642 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1643         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1644                                                                 UINT32);
1645
1646 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1647         .f = cmd_config_max_pkt_len_parsed,
1648         .data = NULL,
1649         .help_str = "port config all max-pkt-len <value>",
1650         .tokens = {
1651                 (void *)&cmd_config_max_pkt_len_port,
1652                 (void *)&cmd_config_max_pkt_len_keyword,
1653                 (void *)&cmd_config_max_pkt_len_all,
1654                 (void *)&cmd_config_max_pkt_len_name,
1655                 (void *)&cmd_config_max_pkt_len_value,
1656                 NULL,
1657         },
1658 };
1659
1660 /* *** configure port MTU *** */
1661 struct cmd_config_mtu_result {
1662         cmdline_fixed_string_t port;
1663         cmdline_fixed_string_t keyword;
1664         cmdline_fixed_string_t mtu;
1665         portid_t port_id;
1666         uint16_t value;
1667 };
1668
1669 static void
1670 cmd_config_mtu_parsed(void *parsed_result,
1671                       __attribute__((unused)) struct cmdline *cl,
1672                       __attribute__((unused)) void *data)
1673 {
1674         struct cmd_config_mtu_result *res = parsed_result;
1675
1676         if (res->value < ETHER_MIN_LEN) {
1677                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1678                 return;
1679         }
1680         port_mtu_set(res->port_id, res->value);
1681 }
1682
1683 cmdline_parse_token_string_t cmd_config_mtu_port =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1685                                  "port");
1686 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1688                                  "config");
1689 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1690         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1691                                  "mtu");
1692 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1693         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1694 cmdline_parse_token_num_t cmd_config_mtu_value =
1695         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1696
1697 cmdline_parse_inst_t cmd_config_mtu = {
1698         .f = cmd_config_mtu_parsed,
1699         .data = NULL,
1700         .help_str = "port config mtu <port_id> <value>",
1701         .tokens = {
1702                 (void *)&cmd_config_mtu_port,
1703                 (void *)&cmd_config_mtu_keyword,
1704                 (void *)&cmd_config_mtu_mtu,
1705                 (void *)&cmd_config_mtu_port_id,
1706                 (void *)&cmd_config_mtu_value,
1707                 NULL,
1708         },
1709 };
1710
1711 /* *** configure rx mode *** */
1712 struct cmd_config_rx_mode_flag {
1713         cmdline_fixed_string_t port;
1714         cmdline_fixed_string_t keyword;
1715         cmdline_fixed_string_t all;
1716         cmdline_fixed_string_t name;
1717         cmdline_fixed_string_t value;
1718 };
1719
1720 static void
1721 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1722                                 __attribute__((unused)) struct cmdline *cl,
1723                                 __attribute__((unused)) void *data)
1724 {
1725         struct cmd_config_rx_mode_flag *res = parsed_result;
1726         uint64_t rx_offloads = rx_mode.offloads;
1727
1728         if (!all_ports_stopped()) {
1729                 printf("Please stop all ports first\n");
1730                 return;
1731         }
1732
1733         if (!strcmp(res->name, "crc-strip")) {
1734                 if (!strcmp(res->value, "on"))
1735                         rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1736                 else if (!strcmp(res->value, "off"))
1737                         rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1738                 else {
1739                         printf("Unknown parameter\n");
1740                         return;
1741                 }
1742         } else if (!strcmp(res->name, "scatter")) {
1743                 if (!strcmp(res->value, "on")) {
1744                         rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1745                 } else if (!strcmp(res->value, "off")) {
1746                         rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1747                 } else {
1748                         printf("Unknown parameter\n");
1749                         return;
1750                 }
1751         } else if (!strcmp(res->name, "rx-cksum")) {
1752                 if (!strcmp(res->value, "on"))
1753                         rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1754                 else if (!strcmp(res->value, "off"))
1755                         rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1756                 else {
1757                         printf("Unknown parameter\n");
1758                         return;
1759                 }
1760         } else if (!strcmp(res->name, "rx-timestamp")) {
1761                 if (!strcmp(res->value, "on"))
1762                         rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1763                 else if (!strcmp(res->value, "off"))
1764                         rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1765                 else {
1766                         printf("Unknown parameter\n");
1767                         return;
1768                 }
1769         } else if (!strcmp(res->name, "hw-vlan")) {
1770                 if (!strcmp(res->value, "on")) {
1771                         rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1772                                         DEV_RX_OFFLOAD_VLAN_STRIP);
1773                 }
1774                 else if (!strcmp(res->value, "off")) {
1775                         rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1776                                         DEV_RX_OFFLOAD_VLAN_STRIP);
1777                 }
1778                 else {
1779                         printf("Unknown parameter\n");
1780                         return;
1781                 }
1782         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1783                 if (!strcmp(res->value, "on"))
1784                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1785                 else if (!strcmp(res->value, "off"))
1786                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1787                 else {
1788                         printf("Unknown parameter\n");
1789                         return;
1790                 }
1791         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1792                 if (!strcmp(res->value, "on"))
1793                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1794                 else if (!strcmp(res->value, "off"))
1795                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1796                 else {
1797                         printf("Unknown parameter\n");
1798                         return;
1799                 }
1800         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1801                 if (!strcmp(res->value, "on"))
1802                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1803                 else if (!strcmp(res->value, "off"))
1804                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1805                 else {
1806                         printf("Unknown parameter\n");
1807                         return;
1808                 }
1809         } else if (!strcmp(res->name, "drop-en")) {
1810                 if (!strcmp(res->value, "on"))
1811                         rx_drop_en = 1;
1812                 else if (!strcmp(res->value, "off"))
1813                         rx_drop_en = 0;
1814                 else {
1815                         printf("Unknown parameter\n");
1816                         return;
1817                 }
1818         } else {
1819                 printf("Unknown parameter\n");
1820                 return;
1821         }
1822         rx_mode.offloads = rx_offloads;
1823
1824         init_port_config();
1825
1826         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1827 }
1828
1829 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1830         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1831 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1832         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1833                                                                 "config");
1834 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1835         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1836 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1837         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1838                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1839                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1840 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1841         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1842                                                         "on#off");
1843
1844 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1845         .f = cmd_config_rx_mode_flag_parsed,
1846         .data = NULL,
1847         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1848                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1849         .tokens = {
1850                 (void *)&cmd_config_rx_mode_flag_port,
1851                 (void *)&cmd_config_rx_mode_flag_keyword,
1852                 (void *)&cmd_config_rx_mode_flag_all,
1853                 (void *)&cmd_config_rx_mode_flag_name,
1854                 (void *)&cmd_config_rx_mode_flag_value,
1855                 NULL,
1856         },
1857 };
1858
1859 /* *** configure rss *** */
1860 struct cmd_config_rss {
1861         cmdline_fixed_string_t port;
1862         cmdline_fixed_string_t keyword;
1863         cmdline_fixed_string_t all;
1864         cmdline_fixed_string_t name;
1865         cmdline_fixed_string_t value;
1866 };
1867
1868 static void
1869 cmd_config_rss_parsed(void *parsed_result,
1870                         __attribute__((unused)) struct cmdline *cl,
1871                         __attribute__((unused)) void *data)
1872 {
1873         struct cmd_config_rss *res = parsed_result;
1874         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1875         int diag;
1876         uint8_t i;
1877
1878         if (!strcmp(res->value, "all"))
1879                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1880                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1881                                         ETH_RSS_L2_PAYLOAD;
1882         else if (!strcmp(res->value, "ip"))
1883                 rss_conf.rss_hf = ETH_RSS_IP;
1884         else if (!strcmp(res->value, "udp"))
1885                 rss_conf.rss_hf = ETH_RSS_UDP;
1886         else if (!strcmp(res->value, "tcp"))
1887                 rss_conf.rss_hf = ETH_RSS_TCP;
1888         else if (!strcmp(res->value, "sctp"))
1889                 rss_conf.rss_hf = ETH_RSS_SCTP;
1890         else if (!strcmp(res->value, "ether"))
1891                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1892         else if (!strcmp(res->value, "port"))
1893                 rss_conf.rss_hf = ETH_RSS_PORT;
1894         else if (!strcmp(res->value, "vxlan"))
1895                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1896         else if (!strcmp(res->value, "geneve"))
1897                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1898         else if (!strcmp(res->value, "nvgre"))
1899                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1900         else if (!strcmp(res->value, "none"))
1901                 rss_conf.rss_hf = 0;
1902         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1903                                                 atoi(res->value) < 64)
1904                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1905         else {
1906                 printf("Unknown parameter\n");
1907                 return;
1908         }
1909         rss_conf.rss_key = NULL;
1910         for (i = 0; i < rte_eth_dev_count(); i++) {
1911                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1912                 if (diag < 0)
1913                         printf("Configuration of RSS hash at ethernet port %d "
1914                                 "failed with error (%d): %s.\n",
1915                                 i, -diag, strerror(-diag));
1916         }
1917 }
1918
1919 cmdline_parse_token_string_t cmd_config_rss_port =
1920         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1921 cmdline_parse_token_string_t cmd_config_rss_keyword =
1922         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1923 cmdline_parse_token_string_t cmd_config_rss_all =
1924         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1925 cmdline_parse_token_string_t cmd_config_rss_name =
1926         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1927 cmdline_parse_token_string_t cmd_config_rss_value =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1929
1930 cmdline_parse_inst_t cmd_config_rss = {
1931         .f = cmd_config_rss_parsed,
1932         .data = NULL,
1933         .help_str = "port config all rss "
1934                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1935         .tokens = {
1936                 (void *)&cmd_config_rss_port,
1937                 (void *)&cmd_config_rss_keyword,
1938                 (void *)&cmd_config_rss_all,
1939                 (void *)&cmd_config_rss_name,
1940                 (void *)&cmd_config_rss_value,
1941                 NULL,
1942         },
1943 };
1944
1945 /* *** configure rss hash key *** */
1946 struct cmd_config_rss_hash_key {
1947         cmdline_fixed_string_t port;
1948         cmdline_fixed_string_t config;
1949         portid_t port_id;
1950         cmdline_fixed_string_t rss_hash_key;
1951         cmdline_fixed_string_t rss_type;
1952         cmdline_fixed_string_t key;
1953 };
1954
1955 static uint8_t
1956 hexa_digit_to_value(char hexa_digit)
1957 {
1958         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1959                 return (uint8_t) (hexa_digit - '0');
1960         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1961                 return (uint8_t) ((hexa_digit - 'a') + 10);
1962         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1963                 return (uint8_t) ((hexa_digit - 'A') + 10);
1964         /* Invalid hexa digit */
1965         return 0xFF;
1966 }
1967
1968 static uint8_t
1969 parse_and_check_key_hexa_digit(char *key, int idx)
1970 {
1971         uint8_t hexa_v;
1972
1973         hexa_v = hexa_digit_to_value(key[idx]);
1974         if (hexa_v == 0xFF)
1975                 printf("invalid key: character %c at position %d is not a "
1976                        "valid hexa digit\n", key[idx], idx);
1977         return hexa_v;
1978 }
1979
1980 static void
1981 cmd_config_rss_hash_key_parsed(void *parsed_result,
1982                                __attribute__((unused)) struct cmdline *cl,
1983                                __attribute__((unused)) void *data)
1984 {
1985         struct cmd_config_rss_hash_key *res = parsed_result;
1986         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1987         uint8_t xdgt0;
1988         uint8_t xdgt1;
1989         int i;
1990         struct rte_eth_dev_info dev_info;
1991         uint8_t hash_key_size;
1992         uint32_t key_len;
1993
1994         memset(&dev_info, 0, sizeof(dev_info));
1995         rte_eth_dev_info_get(res->port_id, &dev_info);
1996         if (dev_info.hash_key_size > 0 &&
1997                         dev_info.hash_key_size <= sizeof(hash_key))
1998                 hash_key_size = dev_info.hash_key_size;
1999         else {
2000                 printf("dev_info did not provide a valid hash key size\n");
2001                 return;
2002         }
2003         /* Check the length of the RSS hash key */
2004         key_len = strlen(res->key);
2005         if (key_len != (hash_key_size * 2)) {
2006                 printf("key length: %d invalid - key must be a string of %d"
2007                            " hexa-decimal numbers\n",
2008                            (int) key_len, hash_key_size * 2);
2009                 return;
2010         }
2011         /* Translate RSS hash key into binary representation */
2012         for (i = 0; i < hash_key_size; i++) {
2013                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2014                 if (xdgt0 == 0xFF)
2015                         return;
2016                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2017                 if (xdgt1 == 0xFF)
2018                         return;
2019                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2020         }
2021         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2022                         hash_key_size);
2023 }
2024
2025 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2026         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2027 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2028         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2029                                  "config");
2030 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2031         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2032 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2034                                  rss_hash_key, "rss-hash-key");
2035 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2037                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2038                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2039                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2040                                  "ipv6-tcp-ex#ipv6-udp-ex");
2041 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2042         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2043
2044 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2045         .f = cmd_config_rss_hash_key_parsed,
2046         .data = NULL,
2047         .help_str = "port config <port_id> rss-hash-key "
2048                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2049                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2050                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2051                 "<string of hex digits (variable length, NIC dependent)>",
2052         .tokens = {
2053                 (void *)&cmd_config_rss_hash_key_port,
2054                 (void *)&cmd_config_rss_hash_key_config,
2055                 (void *)&cmd_config_rss_hash_key_port_id,
2056                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2057                 (void *)&cmd_config_rss_hash_key_rss_type,
2058                 (void *)&cmd_config_rss_hash_key_value,
2059                 NULL,
2060         },
2061 };
2062
2063 /* *** configure port rxq/txq start/stop *** */
2064 struct cmd_config_rxtx_queue {
2065         cmdline_fixed_string_t port;
2066         portid_t portid;
2067         cmdline_fixed_string_t rxtxq;
2068         uint16_t qid;
2069         cmdline_fixed_string_t opname;
2070 };
2071
2072 static void
2073 cmd_config_rxtx_queue_parsed(void *parsed_result,
2074                         __attribute__((unused)) struct cmdline *cl,
2075                         __attribute__((unused)) void *data)
2076 {
2077         struct cmd_config_rxtx_queue *res = parsed_result;
2078         uint8_t isrx;
2079         uint8_t isstart;
2080         int ret = 0;
2081
2082         if (test_done == 0) {
2083                 printf("Please stop forwarding first\n");
2084                 return;
2085         }
2086
2087         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2088                 return;
2089
2090         if (port_is_started(res->portid) != 1) {
2091                 printf("Please start port %u first\n", res->portid);
2092                 return;
2093         }
2094
2095         if (!strcmp(res->rxtxq, "rxq"))
2096                 isrx = 1;
2097         else if (!strcmp(res->rxtxq, "txq"))
2098                 isrx = 0;
2099         else {
2100                 printf("Unknown parameter\n");
2101                 return;
2102         }
2103
2104         if (isrx && rx_queue_id_is_invalid(res->qid))
2105                 return;
2106         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2107                 return;
2108
2109         if (!strcmp(res->opname, "start"))
2110                 isstart = 1;
2111         else if (!strcmp(res->opname, "stop"))
2112                 isstart = 0;
2113         else {
2114                 printf("Unknown parameter\n");
2115                 return;
2116         }
2117
2118         if (isstart && isrx)
2119                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2120         else if (!isstart && isrx)
2121                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2122         else if (isstart && !isrx)
2123                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2124         else
2125                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2126
2127         if (ret == -ENOTSUP)
2128                 printf("Function not supported in PMD driver\n");
2129 }
2130
2131 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2133 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2134         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2135 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2137 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2138         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2139 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2141                                                 "start#stop");
2142
2143 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2144         .f = cmd_config_rxtx_queue_parsed,
2145         .data = NULL,
2146         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2147         .tokens = {
2148                 (void *)&cmd_config_speed_all_port,
2149                 (void *)&cmd_config_rxtx_queue_portid,
2150                 (void *)&cmd_config_rxtx_queue_rxtxq,
2151                 (void *)&cmd_config_rxtx_queue_qid,
2152                 (void *)&cmd_config_rxtx_queue_opname,
2153                 NULL,
2154         },
2155 };
2156
2157 /* *** Configure RSS RETA *** */
2158 struct cmd_config_rss_reta {
2159         cmdline_fixed_string_t port;
2160         cmdline_fixed_string_t keyword;
2161         portid_t port_id;
2162         cmdline_fixed_string_t name;
2163         cmdline_fixed_string_t list_name;
2164         cmdline_fixed_string_t list_of_items;
2165 };
2166
2167 static int
2168 parse_reta_config(const char *str,
2169                   struct rte_eth_rss_reta_entry64 *reta_conf,
2170                   uint16_t nb_entries)
2171 {
2172         int i;
2173         unsigned size;
2174         uint16_t hash_index, idx, shift;
2175         uint16_t nb_queue;
2176         char s[256];
2177         const char *p, *p0 = str;
2178         char *end;
2179         enum fieldnames {
2180                 FLD_HASH_INDEX = 0,
2181                 FLD_QUEUE,
2182                 _NUM_FLD
2183         };
2184         unsigned long int_fld[_NUM_FLD];
2185         char *str_fld[_NUM_FLD];
2186
2187         while ((p = strchr(p0,'(')) != NULL) {
2188                 ++p;
2189                 if((p0 = strchr(p,')')) == NULL)
2190                         return -1;
2191
2192                 size = p0 - p;
2193                 if(size >= sizeof(s))
2194                         return -1;
2195
2196                 snprintf(s, sizeof(s), "%.*s", size, p);
2197                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2198                         return -1;
2199                 for (i = 0; i < _NUM_FLD; i++) {
2200                         errno = 0;
2201                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2202                         if (errno != 0 || end == str_fld[i] ||
2203                                         int_fld[i] > 65535)
2204                                 return -1;
2205                 }
2206
2207                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2208                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2209
2210                 if (hash_index >= nb_entries) {
2211                         printf("Invalid RETA hash index=%d\n", hash_index);
2212                         return -1;
2213                 }
2214
2215                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2216                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2217                 reta_conf[idx].mask |= (1ULL << shift);
2218                 reta_conf[idx].reta[shift] = nb_queue;
2219         }
2220
2221         return 0;
2222 }
2223
2224 static void
2225 cmd_set_rss_reta_parsed(void *parsed_result,
2226                         __attribute__((unused)) struct cmdline *cl,
2227                         __attribute__((unused)) void *data)
2228 {
2229         int ret;
2230         struct rte_eth_dev_info dev_info;
2231         struct rte_eth_rss_reta_entry64 reta_conf[8];
2232         struct cmd_config_rss_reta *res = parsed_result;
2233
2234         memset(&dev_info, 0, sizeof(dev_info));
2235         rte_eth_dev_info_get(res->port_id, &dev_info);
2236         if (dev_info.reta_size == 0) {
2237                 printf("Redirection table size is 0 which is "
2238                                         "invalid for RSS\n");
2239                 return;
2240         } else
2241                 printf("The reta size of port %d is %u\n",
2242                         res->port_id, dev_info.reta_size);
2243         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2244                 printf("Currently do not support more than %u entries of "
2245                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2246                 return;
2247         }
2248
2249         memset(reta_conf, 0, sizeof(reta_conf));
2250         if (!strcmp(res->list_name, "reta")) {
2251                 if (parse_reta_config(res->list_of_items, reta_conf,
2252                                                 dev_info.reta_size)) {
2253                         printf("Invalid RSS Redirection Table "
2254                                         "config entered\n");
2255                         return;
2256                 }
2257                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2258                                 reta_conf, dev_info.reta_size);
2259                 if (ret != 0)
2260                         printf("Bad redirection table parameter, "
2261                                         "return code = %d \n", ret);
2262         }
2263 }
2264
2265 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2267 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2268         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2269 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2270         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2271 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2273 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2275 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2277                                  NULL);
2278 cmdline_parse_inst_t cmd_config_rss_reta = {
2279         .f = cmd_set_rss_reta_parsed,
2280         .data = NULL,
2281         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2282         .tokens = {
2283                 (void *)&cmd_config_rss_reta_port,
2284                 (void *)&cmd_config_rss_reta_keyword,
2285                 (void *)&cmd_config_rss_reta_port_id,
2286                 (void *)&cmd_config_rss_reta_name,
2287                 (void *)&cmd_config_rss_reta_list_name,
2288                 (void *)&cmd_config_rss_reta_list_of_items,
2289                 NULL,
2290         },
2291 };
2292
2293 /* *** SHOW PORT RETA INFO *** */
2294 struct cmd_showport_reta {
2295         cmdline_fixed_string_t show;
2296         cmdline_fixed_string_t port;
2297         portid_t port_id;
2298         cmdline_fixed_string_t rss;
2299         cmdline_fixed_string_t reta;
2300         uint16_t size;
2301         cmdline_fixed_string_t list_of_items;
2302 };
2303
2304 static int
2305 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2306                            uint16_t nb_entries,
2307                            char *str)
2308 {
2309         uint32_t size;
2310         const char *p, *p0 = str;
2311         char s[256];
2312         char *end;
2313         char *str_fld[8];
2314         uint16_t i;
2315         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2316                         RTE_RETA_GROUP_SIZE;
2317         int ret;
2318
2319         p = strchr(p0, '(');
2320         if (p == NULL)
2321                 return -1;
2322         p++;
2323         p0 = strchr(p, ')');
2324         if (p0 == NULL)
2325                 return -1;
2326         size = p0 - p;
2327         if (size >= sizeof(s)) {
2328                 printf("The string size exceeds the internal buffer size\n");
2329                 return -1;
2330         }
2331         snprintf(s, sizeof(s), "%.*s", size, p);
2332         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2333         if (ret <= 0 || ret != num) {
2334                 printf("The bits of masks do not match the number of "
2335                                         "reta entries: %u\n", num);
2336                 return -1;
2337         }
2338         for (i = 0; i < ret; i++)
2339                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2340
2341         return 0;
2342 }
2343
2344 static void
2345 cmd_showport_reta_parsed(void *parsed_result,
2346                          __attribute__((unused)) struct cmdline *cl,
2347                          __attribute__((unused)) void *data)
2348 {
2349         struct cmd_showport_reta *res = parsed_result;
2350         struct rte_eth_rss_reta_entry64 reta_conf[8];
2351         struct rte_eth_dev_info dev_info;
2352         uint16_t max_reta_size;
2353
2354         memset(&dev_info, 0, sizeof(dev_info));
2355         rte_eth_dev_info_get(res->port_id, &dev_info);
2356         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2357         if (res->size == 0 || res->size > max_reta_size) {
2358                 printf("Invalid redirection table size: %u (1-%u)\n",
2359                         res->size, max_reta_size);
2360                 return;
2361         }
2362
2363         memset(reta_conf, 0, sizeof(reta_conf));
2364         if (showport_parse_reta_config(reta_conf, res->size,
2365                                 res->list_of_items) < 0) {
2366                 printf("Invalid string: %s for reta masks\n",
2367                                         res->list_of_items);
2368                 return;
2369         }
2370         port_rss_reta_info(res->port_id, reta_conf, res->size);
2371 }
2372
2373 cmdline_parse_token_string_t cmd_showport_reta_show =
2374         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2375 cmdline_parse_token_string_t cmd_showport_reta_port =
2376         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2377 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2378         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2379 cmdline_parse_token_string_t cmd_showport_reta_rss =
2380         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2381 cmdline_parse_token_string_t cmd_showport_reta_reta =
2382         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2383 cmdline_parse_token_num_t cmd_showport_reta_size =
2384         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2385 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2386         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2387                                         list_of_items, NULL);
2388
2389 cmdline_parse_inst_t cmd_showport_reta = {
2390         .f = cmd_showport_reta_parsed,
2391         .data = NULL,
2392         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2393         .tokens = {
2394                 (void *)&cmd_showport_reta_show,
2395                 (void *)&cmd_showport_reta_port,
2396                 (void *)&cmd_showport_reta_port_id,
2397                 (void *)&cmd_showport_reta_rss,
2398                 (void *)&cmd_showport_reta_reta,
2399                 (void *)&cmd_showport_reta_size,
2400                 (void *)&cmd_showport_reta_list_of_items,
2401                 NULL,
2402         },
2403 };
2404
2405 /* *** Show RSS hash configuration *** */
2406 struct cmd_showport_rss_hash {
2407         cmdline_fixed_string_t show;
2408         cmdline_fixed_string_t port;
2409         portid_t port_id;
2410         cmdline_fixed_string_t rss_hash;
2411         cmdline_fixed_string_t rss_type;
2412         cmdline_fixed_string_t key; /* optional argument */
2413 };
2414
2415 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2416                                 __attribute__((unused)) struct cmdline *cl,
2417                                 void *show_rss_key)
2418 {
2419         struct cmd_showport_rss_hash *res = parsed_result;
2420
2421         port_rss_hash_conf_show(res->port_id, res->rss_type,
2422                                 show_rss_key != NULL);
2423 }
2424
2425 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2426         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2427 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2428         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2429 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2430         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2431 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2432         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2433                                  "rss-hash");
2434 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2435         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2436                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2437                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2438                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2439                                  "ipv6-tcp-ex#ipv6-udp-ex");
2440 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2441         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2442
2443 cmdline_parse_inst_t cmd_showport_rss_hash = {
2444         .f = cmd_showport_rss_hash_parsed,
2445         .data = NULL,
2446         .help_str = "show port <port_id> rss-hash "
2447                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2448                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2449                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2450         .tokens = {
2451                 (void *)&cmd_showport_rss_hash_show,
2452                 (void *)&cmd_showport_rss_hash_port,
2453                 (void *)&cmd_showport_rss_hash_port_id,
2454                 (void *)&cmd_showport_rss_hash_rss_hash,
2455                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2456                 NULL,
2457         },
2458 };
2459
2460 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2461         .f = cmd_showport_rss_hash_parsed,
2462         .data = (void *)1,
2463         .help_str = "show port <port_id> rss-hash "
2464                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2465                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2466                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2467         .tokens = {
2468                 (void *)&cmd_showport_rss_hash_show,
2469                 (void *)&cmd_showport_rss_hash_port,
2470                 (void *)&cmd_showport_rss_hash_port_id,
2471                 (void *)&cmd_showport_rss_hash_rss_hash,
2472                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2473                 (void *)&cmd_showport_rss_hash_rss_key,
2474                 NULL,
2475         },
2476 };
2477
2478 /* *** Configure DCB *** */
2479 struct cmd_config_dcb {
2480         cmdline_fixed_string_t port;
2481         cmdline_fixed_string_t config;
2482         portid_t port_id;
2483         cmdline_fixed_string_t dcb;
2484         cmdline_fixed_string_t vt;
2485         cmdline_fixed_string_t vt_en;
2486         uint8_t num_tcs;
2487         cmdline_fixed_string_t pfc;
2488         cmdline_fixed_string_t pfc_en;
2489 };
2490
2491 static void
2492 cmd_config_dcb_parsed(void *parsed_result,
2493                         __attribute__((unused)) struct cmdline *cl,
2494                         __attribute__((unused)) void *data)
2495 {
2496         struct cmd_config_dcb *res = parsed_result;
2497         portid_t port_id = res->port_id;
2498         struct rte_port *port;
2499         uint8_t pfc_en;
2500         int ret;
2501
2502         port = &ports[port_id];
2503         /** Check if the port is not started **/
2504         if (port->port_status != RTE_PORT_STOPPED) {
2505                 printf("Please stop port %d first\n", port_id);
2506                 return;
2507         }
2508
2509         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2510                 printf("The invalid number of traffic class,"
2511                         " only 4 or 8 allowed.\n");
2512                 return;
2513         }
2514
2515         if (nb_fwd_lcores < res->num_tcs) {
2516                 printf("nb_cores shouldn't be less than number of TCs.\n");
2517                 return;
2518         }
2519         if (!strncmp(res->pfc_en, "on", 2))
2520                 pfc_en = 1;
2521         else
2522                 pfc_en = 0;
2523
2524         /* DCB in VT mode */
2525         if (!strncmp(res->vt_en, "on", 2))
2526                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2527                                 (enum rte_eth_nb_tcs)res->num_tcs,
2528                                 pfc_en);
2529         else
2530                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2531                                 (enum rte_eth_nb_tcs)res->num_tcs,
2532                                 pfc_en);
2533
2534
2535         if (ret != 0) {
2536                 printf("Cannot initialize network ports.\n");
2537                 return;
2538         }
2539
2540         cmd_reconfig_device_queue(port_id, 1, 1);
2541 }
2542
2543 cmdline_parse_token_string_t cmd_config_dcb_port =
2544         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2545 cmdline_parse_token_string_t cmd_config_dcb_config =
2546         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2547 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2548         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2549 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2550         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2551 cmdline_parse_token_string_t cmd_config_dcb_vt =
2552         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2553 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2555 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2556         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2557 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2559 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2561
2562 cmdline_parse_inst_t cmd_config_dcb = {
2563         .f = cmd_config_dcb_parsed,
2564         .data = NULL,
2565         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2566         .tokens = {
2567                 (void *)&cmd_config_dcb_port,
2568                 (void *)&cmd_config_dcb_config,
2569                 (void *)&cmd_config_dcb_port_id,
2570                 (void *)&cmd_config_dcb_dcb,
2571                 (void *)&cmd_config_dcb_vt,
2572                 (void *)&cmd_config_dcb_vt_en,
2573                 (void *)&cmd_config_dcb_num_tcs,
2574                 (void *)&cmd_config_dcb_pfc,
2575                 (void *)&cmd_config_dcb_pfc_en,
2576                 NULL,
2577         },
2578 };
2579
2580 /* *** configure number of packets per burst *** */
2581 struct cmd_config_burst {
2582         cmdline_fixed_string_t port;
2583         cmdline_fixed_string_t keyword;
2584         cmdline_fixed_string_t all;
2585         cmdline_fixed_string_t name;
2586         uint16_t value;
2587 };
2588
2589 static void
2590 cmd_config_burst_parsed(void *parsed_result,
2591                         __attribute__((unused)) struct cmdline *cl,
2592                         __attribute__((unused)) void *data)
2593 {
2594         struct cmd_config_burst *res = parsed_result;
2595
2596         if (!all_ports_stopped()) {
2597                 printf("Please stop all ports first\n");
2598                 return;
2599         }
2600
2601         if (!strcmp(res->name, "burst")) {
2602                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2603                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2604                         return;
2605                 }
2606                 nb_pkt_per_burst = res->value;
2607         } else {
2608                 printf("Unknown parameter\n");
2609                 return;
2610         }
2611
2612         init_port_config();
2613
2614         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2615 }
2616
2617 cmdline_parse_token_string_t cmd_config_burst_port =
2618         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2619 cmdline_parse_token_string_t cmd_config_burst_keyword =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2621 cmdline_parse_token_string_t cmd_config_burst_all =
2622         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2623 cmdline_parse_token_string_t cmd_config_burst_name =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2625 cmdline_parse_token_num_t cmd_config_burst_value =
2626         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2627
2628 cmdline_parse_inst_t cmd_config_burst = {
2629         .f = cmd_config_burst_parsed,
2630         .data = NULL,
2631         .help_str = "port config all burst <value>",
2632         .tokens = {
2633                 (void *)&cmd_config_burst_port,
2634                 (void *)&cmd_config_burst_keyword,
2635                 (void *)&cmd_config_burst_all,
2636                 (void *)&cmd_config_burst_name,
2637                 (void *)&cmd_config_burst_value,
2638                 NULL,
2639         },
2640 };
2641
2642 /* *** configure rx/tx queues *** */
2643 struct cmd_config_thresh {
2644         cmdline_fixed_string_t port;
2645         cmdline_fixed_string_t keyword;
2646         cmdline_fixed_string_t all;
2647         cmdline_fixed_string_t name;
2648         uint8_t value;
2649 };
2650
2651 static void
2652 cmd_config_thresh_parsed(void *parsed_result,
2653                         __attribute__((unused)) struct cmdline *cl,
2654                         __attribute__((unused)) void *data)
2655 {
2656         struct cmd_config_thresh *res = parsed_result;
2657
2658         if (!all_ports_stopped()) {
2659                 printf("Please stop all ports first\n");
2660                 return;
2661         }
2662
2663         if (!strcmp(res->name, "txpt"))
2664                 tx_pthresh = res->value;
2665         else if(!strcmp(res->name, "txht"))
2666                 tx_hthresh = res->value;
2667         else if(!strcmp(res->name, "txwt"))
2668                 tx_wthresh = res->value;
2669         else if(!strcmp(res->name, "rxpt"))
2670                 rx_pthresh = res->value;
2671         else if(!strcmp(res->name, "rxht"))
2672                 rx_hthresh = res->value;
2673         else if(!strcmp(res->name, "rxwt"))
2674                 rx_wthresh = res->value;
2675         else {
2676                 printf("Unknown parameter\n");
2677                 return;
2678         }
2679
2680         init_port_config();
2681
2682         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2683 }
2684
2685 cmdline_parse_token_string_t cmd_config_thresh_port =
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2687 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2689 cmdline_parse_token_string_t cmd_config_thresh_all =
2690         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2691 cmdline_parse_token_string_t cmd_config_thresh_name =
2692         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2693                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2694 cmdline_parse_token_num_t cmd_config_thresh_value =
2695         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2696
2697 cmdline_parse_inst_t cmd_config_thresh = {
2698         .f = cmd_config_thresh_parsed,
2699         .data = NULL,
2700         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2701         .tokens = {
2702                 (void *)&cmd_config_thresh_port,
2703                 (void *)&cmd_config_thresh_keyword,
2704                 (void *)&cmd_config_thresh_all,
2705                 (void *)&cmd_config_thresh_name,
2706                 (void *)&cmd_config_thresh_value,
2707                 NULL,
2708         },
2709 };
2710
2711 /* *** configure free/rs threshold *** */
2712 struct cmd_config_threshold {
2713         cmdline_fixed_string_t port;
2714         cmdline_fixed_string_t keyword;
2715         cmdline_fixed_string_t all;
2716         cmdline_fixed_string_t name;
2717         uint16_t value;
2718 };
2719
2720 static void
2721 cmd_config_threshold_parsed(void *parsed_result,
2722                         __attribute__((unused)) struct cmdline *cl,
2723                         __attribute__((unused)) void *data)
2724 {
2725         struct cmd_config_threshold *res = parsed_result;
2726
2727         if (!all_ports_stopped()) {
2728                 printf("Please stop all ports first\n");
2729                 return;
2730         }
2731
2732         if (!strcmp(res->name, "txfreet"))
2733                 tx_free_thresh = res->value;
2734         else if (!strcmp(res->name, "txrst"))
2735                 tx_rs_thresh = res->value;
2736         else if (!strcmp(res->name, "rxfreet"))
2737                 rx_free_thresh = res->value;
2738         else {
2739                 printf("Unknown parameter\n");
2740                 return;
2741         }
2742
2743         init_port_config();
2744
2745         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2746 }
2747
2748 cmdline_parse_token_string_t cmd_config_threshold_port =
2749         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2750 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2751         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2752                                                                 "config");
2753 cmdline_parse_token_string_t cmd_config_threshold_all =
2754         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2755 cmdline_parse_token_string_t cmd_config_threshold_name =
2756         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2757                                                 "txfreet#txrst#rxfreet");
2758 cmdline_parse_token_num_t cmd_config_threshold_value =
2759         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2760
2761 cmdline_parse_inst_t cmd_config_threshold = {
2762         .f = cmd_config_threshold_parsed,
2763         .data = NULL,
2764         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2765         .tokens = {
2766                 (void *)&cmd_config_threshold_port,
2767                 (void *)&cmd_config_threshold_keyword,
2768                 (void *)&cmd_config_threshold_all,
2769                 (void *)&cmd_config_threshold_name,
2770                 (void *)&cmd_config_threshold_value,
2771                 NULL,
2772         },
2773 };
2774
2775 /* *** stop *** */
2776 struct cmd_stop_result {
2777         cmdline_fixed_string_t stop;
2778 };
2779
2780 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2781                             __attribute__((unused)) struct cmdline *cl,
2782                             __attribute__((unused)) void *data)
2783 {
2784         stop_packet_forwarding();
2785 }
2786
2787 cmdline_parse_token_string_t cmd_stop_stop =
2788         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2789
2790 cmdline_parse_inst_t cmd_stop = {
2791         .f = cmd_stop_parsed,
2792         .data = NULL,
2793         .help_str = "stop: Stop packet forwarding",
2794         .tokens = {
2795                 (void *)&cmd_stop_stop,
2796                 NULL,
2797         },
2798 };
2799
2800 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2801
2802 unsigned int
2803 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2804                 unsigned int *parsed_items, int check_unique_values)
2805 {
2806         unsigned int nb_item;
2807         unsigned int value;
2808         unsigned int i;
2809         unsigned int j;
2810         int value_ok;
2811         char c;
2812
2813         /*
2814          * First parse all items in the list and store their value.
2815          */
2816         value = 0;
2817         nb_item = 0;
2818         value_ok = 0;
2819         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2820                 c = str[i];
2821                 if ((c >= '0') && (c <= '9')) {
2822                         value = (unsigned int) (value * 10 + (c - '0'));
2823                         value_ok = 1;
2824                         continue;
2825                 }
2826                 if (c != ',') {
2827                         printf("character %c is not a decimal digit\n", c);
2828                         return 0;
2829                 }
2830                 if (! value_ok) {
2831                         printf("No valid value before comma\n");
2832                         return 0;
2833                 }
2834                 if (nb_item < max_items) {
2835                         parsed_items[nb_item] = value;
2836                         value_ok = 0;
2837                         value = 0;
2838                 }
2839                 nb_item++;
2840         }
2841         if (nb_item >= max_items) {
2842                 printf("Number of %s = %u > %u (maximum items)\n",
2843                        item_name, nb_item + 1, max_items);
2844                 return 0;
2845         }
2846         parsed_items[nb_item++] = value;
2847         if (! check_unique_values)
2848                 return nb_item;
2849
2850         /*
2851          * Then, check that all values in the list are differents.
2852          * No optimization here...
2853          */
2854         for (i = 0; i < nb_item; i++) {
2855                 for (j = i + 1; j < nb_item; j++) {
2856                         if (parsed_items[j] == parsed_items[i]) {
2857                                 printf("duplicated %s %u at index %u and %u\n",
2858                                        item_name, parsed_items[i], i, j);
2859                                 return 0;
2860                         }
2861                 }
2862         }
2863         return nb_item;
2864 }
2865
2866 struct cmd_set_list_result {
2867         cmdline_fixed_string_t cmd_keyword;
2868         cmdline_fixed_string_t list_name;
2869         cmdline_fixed_string_t list_of_items;
2870 };
2871
2872 static void cmd_set_list_parsed(void *parsed_result,
2873                                 __attribute__((unused)) struct cmdline *cl,
2874                                 __attribute__((unused)) void *data)
2875 {
2876         struct cmd_set_list_result *res;
2877         union {
2878                 unsigned int lcorelist[RTE_MAX_LCORE];
2879                 unsigned int portlist[RTE_MAX_ETHPORTS];
2880         } parsed_items;
2881         unsigned int nb_item;
2882
2883         if (test_done == 0) {
2884                 printf("Please stop forwarding first\n");
2885                 return;
2886         }
2887
2888         res = parsed_result;
2889         if (!strcmp(res->list_name, "corelist")) {
2890                 nb_item = parse_item_list(res->list_of_items, "core",
2891                                           RTE_MAX_LCORE,
2892                                           parsed_items.lcorelist, 1);
2893                 if (nb_item > 0) {
2894                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2895                         fwd_config_setup();
2896                 }
2897                 return;
2898         }
2899         if (!strcmp(res->list_name, "portlist")) {
2900                 nb_item = parse_item_list(res->list_of_items, "port",
2901                                           RTE_MAX_ETHPORTS,
2902                                           parsed_items.portlist, 1);
2903                 if (nb_item > 0) {
2904                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2905                         fwd_config_setup();
2906                 }
2907         }
2908 }
2909
2910 cmdline_parse_token_string_t cmd_set_list_keyword =
2911         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2912                                  "set");
2913 cmdline_parse_token_string_t cmd_set_list_name =
2914         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2915                                  "corelist#portlist");
2916 cmdline_parse_token_string_t cmd_set_list_of_items =
2917         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2918                                  NULL);
2919
2920 cmdline_parse_inst_t cmd_set_fwd_list = {
2921         .f = cmd_set_list_parsed,
2922         .data = NULL,
2923         .help_str = "set corelist|portlist <list0[,list1]*>",
2924         .tokens = {
2925                 (void *)&cmd_set_list_keyword,
2926                 (void *)&cmd_set_list_name,
2927                 (void *)&cmd_set_list_of_items,
2928                 NULL,
2929         },
2930 };
2931
2932 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2933
2934 struct cmd_setmask_result {
2935         cmdline_fixed_string_t set;
2936         cmdline_fixed_string_t mask;
2937         uint64_t hexavalue;
2938 };
2939
2940 static void cmd_set_mask_parsed(void *parsed_result,
2941                                 __attribute__((unused)) struct cmdline *cl,
2942                                 __attribute__((unused)) void *data)
2943 {
2944         struct cmd_setmask_result *res = parsed_result;
2945
2946         if (test_done == 0) {
2947                 printf("Please stop forwarding first\n");
2948                 return;
2949         }
2950         if (!strcmp(res->mask, "coremask")) {
2951                 set_fwd_lcores_mask(res->hexavalue);
2952                 fwd_config_setup();
2953         } else if (!strcmp(res->mask, "portmask")) {
2954                 set_fwd_ports_mask(res->hexavalue);
2955                 fwd_config_setup();
2956         }
2957 }
2958
2959 cmdline_parse_token_string_t cmd_setmask_set =
2960         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2961 cmdline_parse_token_string_t cmd_setmask_mask =
2962         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2963                                  "coremask#portmask");
2964 cmdline_parse_token_num_t cmd_setmask_value =
2965         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2966
2967 cmdline_parse_inst_t cmd_set_fwd_mask = {
2968         .f = cmd_set_mask_parsed,
2969         .data = NULL,
2970         .help_str = "set coremask|portmask <hexadecimal value>",
2971         .tokens = {
2972                 (void *)&cmd_setmask_set,
2973                 (void *)&cmd_setmask_mask,
2974                 (void *)&cmd_setmask_value,
2975                 NULL,
2976         },
2977 };
2978
2979 /*
2980  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2981  */
2982 struct cmd_set_result {
2983         cmdline_fixed_string_t set;
2984         cmdline_fixed_string_t what;
2985         uint16_t value;
2986 };
2987
2988 static void cmd_set_parsed(void *parsed_result,
2989                            __attribute__((unused)) struct cmdline *cl,
2990                            __attribute__((unused)) void *data)
2991 {
2992         struct cmd_set_result *res = parsed_result;
2993         if (!strcmp(res->what, "nbport")) {
2994                 set_fwd_ports_number(res->value);
2995                 fwd_config_setup();
2996         } else if (!strcmp(res->what, "nbcore")) {
2997                 set_fwd_lcores_number(res->value);
2998                 fwd_config_setup();
2999         } else if (!strcmp(res->what, "burst"))
3000                 set_nb_pkt_per_burst(res->value);
3001         else if (!strcmp(res->what, "verbose"))
3002                 set_verbose_level(res->value);
3003 }
3004
3005 cmdline_parse_token_string_t cmd_set_set =
3006         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3007 cmdline_parse_token_string_t cmd_set_what =
3008         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3009                                  "nbport#nbcore#burst#verbose");
3010 cmdline_parse_token_num_t cmd_set_value =
3011         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3012
3013 cmdline_parse_inst_t cmd_set_numbers = {
3014         .f = cmd_set_parsed,
3015         .data = NULL,
3016         .help_str = "set nbport|nbcore|burst|verbose <value>",
3017         .tokens = {
3018                 (void *)&cmd_set_set,
3019                 (void *)&cmd_set_what,
3020                 (void *)&cmd_set_value,
3021                 NULL,
3022         },
3023 };
3024
3025 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3026
3027 struct cmd_set_txpkts_result {
3028         cmdline_fixed_string_t cmd_keyword;
3029         cmdline_fixed_string_t txpkts;
3030         cmdline_fixed_string_t seg_lengths;
3031 };
3032
3033 static void
3034 cmd_set_txpkts_parsed(void *parsed_result,
3035                       __attribute__((unused)) struct cmdline *cl,
3036                       __attribute__((unused)) void *data)
3037 {
3038         struct cmd_set_txpkts_result *res;
3039         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3040         unsigned int nb_segs;
3041
3042         res = parsed_result;
3043         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3044                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3045         if (nb_segs > 0)
3046                 set_tx_pkt_segments(seg_lengths, nb_segs);
3047 }
3048
3049 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3050         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3051                                  cmd_keyword, "set");
3052 cmdline_parse_token_string_t cmd_set_txpkts_name =
3053         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3054                                  txpkts, "txpkts");
3055 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3056         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3057                                  seg_lengths, NULL);
3058
3059 cmdline_parse_inst_t cmd_set_txpkts = {
3060         .f = cmd_set_txpkts_parsed,
3061         .data = NULL,
3062         .help_str = "set txpkts <len0[,len1]*>",
3063         .tokens = {
3064                 (void *)&cmd_set_txpkts_keyword,
3065                 (void *)&cmd_set_txpkts_name,
3066                 (void *)&cmd_set_txpkts_lengths,
3067                 NULL,
3068         },
3069 };
3070
3071 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3072
3073 struct cmd_set_txsplit_result {
3074         cmdline_fixed_string_t cmd_keyword;
3075         cmdline_fixed_string_t txsplit;
3076         cmdline_fixed_string_t mode;
3077 };
3078
3079 static void
3080 cmd_set_txsplit_parsed(void *parsed_result,
3081                       __attribute__((unused)) struct cmdline *cl,
3082                       __attribute__((unused)) void *data)
3083 {
3084         struct cmd_set_txsplit_result *res;
3085
3086         res = parsed_result;
3087         set_tx_pkt_split(res->mode);
3088 }
3089
3090 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3091         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3092                                  cmd_keyword, "set");
3093 cmdline_parse_token_string_t cmd_set_txsplit_name =
3094         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3095                                  txsplit, "txsplit");
3096 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3097         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3098                                  mode, NULL);
3099
3100 cmdline_parse_inst_t cmd_set_txsplit = {
3101         .f = cmd_set_txsplit_parsed,
3102         .data = NULL,
3103         .help_str = "set txsplit on|off|rand",
3104         .tokens = {
3105                 (void *)&cmd_set_txsplit_keyword,
3106                 (void *)&cmd_set_txsplit_name,
3107                 (void *)&cmd_set_txsplit_mode,
3108                 NULL,
3109         },
3110 };
3111
3112 /* *** CONFIG TX QUEUE FLAGS *** */
3113
3114 struct cmd_config_txqflags_result {
3115         cmdline_fixed_string_t port;
3116         cmdline_fixed_string_t config;
3117         cmdline_fixed_string_t all;
3118         cmdline_fixed_string_t what;
3119         int32_t hexvalue;
3120 };
3121
3122 static void cmd_config_txqflags_parsed(void *parsed_result,
3123                                 __attribute__((unused)) struct cmdline *cl,
3124                                 __attribute__((unused)) void *data)
3125 {
3126         struct cmd_config_txqflags_result *res = parsed_result;
3127
3128         if (!all_ports_stopped()) {
3129                 printf("Please stop all ports first\n");
3130                 return;
3131         }
3132
3133         if (strcmp(res->what, "txqflags")) {
3134                 printf("Unknown parameter\n");
3135                 return;
3136         }
3137
3138         if (res->hexvalue >= 0) {
3139                 txq_flags = res->hexvalue;
3140         } else {
3141                 printf("txqflags must be >= 0\n");
3142                 return;
3143         }
3144
3145         init_port_config();
3146
3147         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3148 }
3149
3150 cmdline_parse_token_string_t cmd_config_txqflags_port =
3151         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3152                                  "port");
3153 cmdline_parse_token_string_t cmd_config_txqflags_config =
3154         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3155                                  "config");
3156 cmdline_parse_token_string_t cmd_config_txqflags_all =
3157         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3158                                  "all");
3159 cmdline_parse_token_string_t cmd_config_txqflags_what =
3160         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3161                                  "txqflags");
3162 cmdline_parse_token_num_t cmd_config_txqflags_value =
3163         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3164                                 hexvalue, INT32);
3165
3166 cmdline_parse_inst_t cmd_config_txqflags = {
3167         .f = cmd_config_txqflags_parsed,
3168         .data = NULL,
3169         .help_str = "port config all txqflags <value>",
3170         .tokens = {
3171                 (void *)&cmd_config_txqflags_port,
3172                 (void *)&cmd_config_txqflags_config,
3173                 (void *)&cmd_config_txqflags_all,
3174                 (void *)&cmd_config_txqflags_what,
3175                 (void *)&cmd_config_txqflags_value,
3176                 NULL,
3177         },
3178 };
3179
3180 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3181 struct cmd_rx_vlan_filter_all_result {
3182         cmdline_fixed_string_t rx_vlan;
3183         cmdline_fixed_string_t what;
3184         cmdline_fixed_string_t all;
3185         portid_t port_id;
3186 };
3187
3188 static void
3189 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3190                               __attribute__((unused)) struct cmdline *cl,
3191                               __attribute__((unused)) void *data)
3192 {
3193         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3194
3195         if (!strcmp(res->what, "add"))
3196                 rx_vlan_all_filter_set(res->port_id, 1);
3197         else
3198                 rx_vlan_all_filter_set(res->port_id, 0);
3199 }
3200
3201 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3202         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3203                                  rx_vlan, "rx_vlan");
3204 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3205         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3206                                  what, "add#rm");
3207 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3208         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3209                                  all, "all");
3210 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3211         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3212                               port_id, UINT16);
3213
3214 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3215         .f = cmd_rx_vlan_filter_all_parsed,
3216         .data = NULL,
3217         .help_str = "rx_vlan add|rm all <port_id>: "
3218                 "Add/Remove all identifiers to/from the set of VLAN "
3219                 "identifiers filtered by a port",
3220         .tokens = {
3221                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3222                 (void *)&cmd_rx_vlan_filter_all_what,
3223                 (void *)&cmd_rx_vlan_filter_all_all,
3224                 (void *)&cmd_rx_vlan_filter_all_portid,
3225                 NULL,
3226         },
3227 };
3228
3229 /* *** VLAN OFFLOAD SET ON A PORT *** */
3230 struct cmd_vlan_offload_result {
3231         cmdline_fixed_string_t vlan;
3232         cmdline_fixed_string_t set;
3233         cmdline_fixed_string_t vlan_type;
3234         cmdline_fixed_string_t what;
3235         cmdline_fixed_string_t on;
3236         cmdline_fixed_string_t port_id;
3237 };
3238
3239 static void
3240 cmd_vlan_offload_parsed(void *parsed_result,
3241                           __attribute__((unused)) struct cmdline *cl,
3242                           __attribute__((unused)) void *data)
3243 {
3244         int on;
3245         struct cmd_vlan_offload_result *res = parsed_result;
3246         char *str;
3247         int i, len = 0;
3248         portid_t port_id = 0;
3249         unsigned int tmp;
3250
3251         str = res->port_id;
3252         len = strnlen(str, STR_TOKEN_SIZE);
3253         i = 0;
3254         /* Get port_id first */
3255         while(i < len){
3256                 if(str[i] == ',')
3257                         break;
3258
3259                 i++;
3260         }
3261         str[i]='\0';
3262         tmp = strtoul(str, NULL, 0);
3263         /* If port_id greater that what portid_t can represent, return */
3264         if(tmp >= RTE_MAX_ETHPORTS)
3265                 return;
3266         port_id = (portid_t)tmp;
3267
3268         if (!strcmp(res->on, "on"))
3269                 on = 1;
3270         else
3271                 on = 0;
3272
3273         if (!strcmp(res->what, "strip"))
3274                 rx_vlan_strip_set(port_id,  on);
3275         else if(!strcmp(res->what, "stripq")){
3276                 uint16_t queue_id = 0;
3277
3278                 /* No queue_id, return */
3279                 if(i + 1 >= len) {
3280                         printf("must specify (port,queue_id)\n");
3281                         return;
3282                 }
3283                 tmp = strtoul(str + i + 1, NULL, 0);
3284                 /* If queue_id greater that what 16-bits can represent, return */
3285                 if(tmp > 0xffff)
3286                         return;
3287
3288                 queue_id = (uint16_t)tmp;
3289                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3290         }
3291         else if (!strcmp(res->what, "filter"))
3292                 rx_vlan_filter_set(port_id, on);
3293         else
3294                 vlan_extend_set(port_id, on);
3295
3296         return;
3297 }
3298
3299 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3300         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3301                                  vlan, "vlan");
3302 cmdline_parse_token_string_t cmd_vlan_offload_set =
3303         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3304                                  set, "set");
3305 cmdline_parse_token_string_t cmd_vlan_offload_what =
3306         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3307                                  what, "strip#filter#qinq#stripq");
3308 cmdline_parse_token_string_t cmd_vlan_offload_on =
3309         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3310                               on, "on#off");
3311 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3312         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3313                               port_id, NULL);
3314
3315 cmdline_parse_inst_t cmd_vlan_offload = {
3316         .f = cmd_vlan_offload_parsed,
3317         .data = NULL,
3318         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3319                 "<port_id[,queue_id]>: "
3320                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3321         .tokens = {
3322                 (void *)&cmd_vlan_offload_vlan,
3323                 (void *)&cmd_vlan_offload_set,
3324                 (void *)&cmd_vlan_offload_what,
3325                 (void *)&cmd_vlan_offload_on,
3326                 (void *)&cmd_vlan_offload_portid,
3327                 NULL,
3328         },
3329 };
3330
3331 /* *** VLAN TPID SET ON A PORT *** */
3332 struct cmd_vlan_tpid_result {
3333         cmdline_fixed_string_t vlan;
3334         cmdline_fixed_string_t set;
3335         cmdline_fixed_string_t vlan_type;
3336         cmdline_fixed_string_t what;
3337         uint16_t tp_id;
3338         portid_t port_id;
3339 };
3340
3341 static void
3342 cmd_vlan_tpid_parsed(void *parsed_result,
3343                           __attribute__((unused)) struct cmdline *cl,
3344                           __attribute__((unused)) void *data)
3345 {
3346         struct cmd_vlan_tpid_result *res = parsed_result;
3347         enum rte_vlan_type vlan_type;
3348
3349         if (!strcmp(res->vlan_type, "inner"))
3350                 vlan_type = ETH_VLAN_TYPE_INNER;
3351         else if (!strcmp(res->vlan_type, "outer"))
3352                 vlan_type = ETH_VLAN_TYPE_OUTER;
3353         else {
3354                 printf("Unknown vlan type\n");
3355                 return;
3356         }
3357         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3358 }
3359
3360 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3361         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3362                                  vlan, "vlan");
3363 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3364         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3365                                  set, "set");
3366 cmdline_parse_token_string_t cmd_vlan_type =
3367         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3368                                  vlan_type, "inner#outer");
3369 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3370         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3371                                  what, "tpid");
3372 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3373         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3374                               tp_id, UINT16);
3375 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3376         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3377                               port_id, UINT16);
3378
3379 cmdline_parse_inst_t cmd_vlan_tpid = {
3380         .f = cmd_vlan_tpid_parsed,
3381         .data = NULL,
3382         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3383                 "Set the VLAN Ether type",
3384         .tokens = {
3385                 (void *)&cmd_vlan_tpid_vlan,
3386                 (void *)&cmd_vlan_tpid_set,
3387                 (void *)&cmd_vlan_type,
3388                 (void *)&cmd_vlan_tpid_what,
3389                 (void *)&cmd_vlan_tpid_tpid,
3390                 (void *)&cmd_vlan_tpid_portid,
3391                 NULL,
3392         },
3393 };
3394
3395 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3396 struct cmd_rx_vlan_filter_result {
3397         cmdline_fixed_string_t rx_vlan;
3398         cmdline_fixed_string_t what;
3399         uint16_t vlan_id;
3400         portid_t port_id;
3401 };
3402
3403 static void
3404 cmd_rx_vlan_filter_parsed(void *parsed_result,
3405                           __attribute__((unused)) struct cmdline *cl,
3406                           __attribute__((unused)) void *data)
3407 {
3408         struct cmd_rx_vlan_filter_result *res = parsed_result;
3409
3410         if (!strcmp(res->what, "add"))
3411                 rx_vft_set(res->port_id, res->vlan_id, 1);
3412         else
3413                 rx_vft_set(res->port_id, res->vlan_id, 0);
3414 }
3415
3416 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3417         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3418                                  rx_vlan, "rx_vlan");
3419 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3420         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3421                                  what, "add#rm");
3422 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3423         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3424                               vlan_id, UINT16);
3425 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3426         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3427                               port_id, UINT16);
3428
3429 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3430         .f = cmd_rx_vlan_filter_parsed,
3431         .data = NULL,
3432         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3433                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3434                 "identifiers filtered by a port",
3435         .tokens = {
3436                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3437                 (void *)&cmd_rx_vlan_filter_what,
3438                 (void *)&cmd_rx_vlan_filter_vlanid,
3439                 (void *)&cmd_rx_vlan_filter_portid,
3440                 NULL,
3441         },
3442 };
3443
3444 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3445 struct cmd_tx_vlan_set_result {
3446         cmdline_fixed_string_t tx_vlan;
3447         cmdline_fixed_string_t set;
3448         portid_t port_id;
3449         uint16_t vlan_id;
3450 };
3451
3452 static void
3453 cmd_tx_vlan_set_parsed(void *parsed_result,
3454                        __attribute__((unused)) struct cmdline *cl,
3455                        __attribute__((unused)) void *data)
3456 {
3457         struct cmd_tx_vlan_set_result *res = parsed_result;
3458
3459         if (!port_is_stopped(res->port_id)) {
3460                 printf("Please stop port %d first\n", res->port_id);
3461                 return;
3462         }
3463
3464         tx_vlan_set(res->port_id, res->vlan_id);
3465
3466         cmd_reconfig_device_queue(res->port_id, 1, 1);
3467 }
3468
3469 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3470         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3471                                  tx_vlan, "tx_vlan");
3472 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3473         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3474                                  set, "set");
3475 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3476         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3477                               port_id, UINT16);
3478 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3479         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3480                               vlan_id, UINT16);
3481
3482 cmdline_parse_inst_t cmd_tx_vlan_set = {
3483         .f = cmd_tx_vlan_set_parsed,
3484         .data = NULL,
3485         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3486                 "Enable hardware insertion of a single VLAN header "
3487                 "with a given TAG Identifier in packets sent on a port",
3488         .tokens = {
3489                 (void *)&cmd_tx_vlan_set_tx_vlan,
3490                 (void *)&cmd_tx_vlan_set_set,
3491                 (void *)&cmd_tx_vlan_set_portid,
3492                 (void *)&cmd_tx_vlan_set_vlanid,
3493                 NULL,
3494         },
3495 };
3496
3497 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3498 struct cmd_tx_vlan_set_qinq_result {
3499         cmdline_fixed_string_t tx_vlan;
3500         cmdline_fixed_string_t set;
3501         portid_t port_id;
3502         uint16_t vlan_id;
3503         uint16_t vlan_id_outer;
3504 };
3505
3506 static void
3507 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3508                             __attribute__((unused)) struct cmdline *cl,
3509                             __attribute__((unused)) void *data)
3510 {
3511         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3512
3513         if (!port_is_stopped(res->port_id)) {
3514                 printf("Please stop port %d first\n", res->port_id);
3515                 return;
3516         }
3517
3518         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3519
3520         cmd_reconfig_device_queue(res->port_id, 1, 1);
3521 }
3522
3523 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3524         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3525                 tx_vlan, "tx_vlan");
3526 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3527         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3528                 set, "set");
3529 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3530         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3531                 port_id, UINT16);
3532 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3533         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3534                 vlan_id, UINT16);
3535 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3536         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3537                 vlan_id_outer, UINT16);
3538
3539 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3540         .f = cmd_tx_vlan_set_qinq_parsed,
3541         .data = NULL,
3542         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3543                 "Enable hardware insertion of double VLAN header "
3544                 "with given TAG Identifiers in packets sent on a port",
3545         .tokens = {
3546                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3547                 (void *)&cmd_tx_vlan_set_qinq_set,
3548                 (void *)&cmd_tx_vlan_set_qinq_portid,
3549                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3550                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3551                 NULL,
3552         },
3553 };
3554
3555 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3556 struct cmd_tx_vlan_set_pvid_result {
3557         cmdline_fixed_string_t tx_vlan;
3558         cmdline_fixed_string_t set;
3559         cmdline_fixed_string_t pvid;
3560         portid_t port_id;
3561         uint16_t vlan_id;
3562         cmdline_fixed_string_t mode;
3563 };
3564
3565 static void
3566 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3567                             __attribute__((unused)) struct cmdline *cl,
3568                             __attribute__((unused)) void *data)
3569 {
3570         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3571
3572         if (strcmp(res->mode, "on") == 0)
3573                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3574         else
3575                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3576 }
3577
3578 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3579         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3580                                  tx_vlan, "tx_vlan");
3581 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3582         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3583                                  set, "set");
3584 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3585         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3586                                  pvid, "pvid");
3587 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3588         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3589                              port_id, UINT16);
3590 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3591         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3592                               vlan_id, UINT16);
3593 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3594         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3595                                  mode, "on#off");
3596
3597 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3598         .f = cmd_tx_vlan_set_pvid_parsed,
3599         .data = NULL,
3600         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3601         .tokens = {
3602                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3603                 (void *)&cmd_tx_vlan_set_pvid_set,
3604                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3605                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3606                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3607                 (void *)&cmd_tx_vlan_set_pvid_mode,
3608                 NULL,
3609         },
3610 };
3611
3612 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3613 struct cmd_tx_vlan_reset_result {
3614         cmdline_fixed_string_t tx_vlan;
3615         cmdline_fixed_string_t reset;
3616         portid_t port_id;
3617 };
3618
3619 static void
3620 cmd_tx_vlan_reset_parsed(void *parsed_result,
3621                          __attribute__((unused)) struct cmdline *cl,
3622                          __attribute__((unused)) void *data)
3623 {
3624         struct cmd_tx_vlan_reset_result *res = parsed_result;
3625
3626         if (!port_is_stopped(res->port_id)) {
3627                 printf("Please stop port %d first\n", res->port_id);
3628                 return;
3629         }
3630
3631         tx_vlan_reset(res->port_id);
3632
3633         cmd_reconfig_device_queue(res->port_id, 1, 1);
3634 }
3635
3636 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3637         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3638                                  tx_vlan, "tx_vlan");
3639 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3640         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3641                                  reset, "reset");
3642 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3643         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3644                               port_id, UINT16);
3645
3646 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3647         .f = cmd_tx_vlan_reset_parsed,
3648         .data = NULL,
3649         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3650                 "VLAN header in packets sent on a port",
3651         .tokens = {
3652                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3653                 (void *)&cmd_tx_vlan_reset_reset,
3654                 (void *)&cmd_tx_vlan_reset_portid,
3655                 NULL,
3656         },
3657 };
3658
3659
3660 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3661 struct cmd_csum_result {
3662         cmdline_fixed_string_t csum;
3663         cmdline_fixed_string_t mode;
3664         cmdline_fixed_string_t proto;
3665         cmdline_fixed_string_t hwsw;
3666         portid_t port_id;
3667 };
3668
3669 static void
3670 csum_show(int port_id)
3671 {
3672         struct rte_eth_dev_info dev_info;
3673         uint16_t ol_flags;
3674
3675         ol_flags = ports[port_id].tx_ol_flags;
3676         printf("Parse tunnel is %s\n",
3677                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3678         printf("IP checksum offload is %s\n",
3679                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3680         printf("UDP checksum offload is %s\n",
3681                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3682         printf("TCP checksum offload is %s\n",
3683                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3684         printf("SCTP checksum offload is %s\n",
3685                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3686         printf("Outer-Ip checksum offload is %s\n",
3687                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3688
3689         /* display warnings if configuration is not supported by the NIC */
3690         rte_eth_dev_info_get(port_id, &dev_info);
3691         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3692                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3693                 printf("Warning: hardware IP checksum enabled but not "
3694                         "supported by port %d\n", port_id);
3695         }
3696         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3697                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3698                 printf("Warning: hardware UDP checksum enabled but not "
3699                         "supported by port %d\n", port_id);
3700         }
3701         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3702                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3703                 printf("Warning: hardware TCP checksum enabled but not "
3704                         "supported by port %d\n", port_id);
3705         }
3706         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3707                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3708                 printf("Warning: hardware SCTP checksum enabled but not "
3709                         "supported by port %d\n", port_id);
3710         }
3711         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3712                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3713                 printf("Warning: hardware outer IP checksum enabled but not "
3714                         "supported by port %d\n", port_id);
3715         }
3716 }
3717
3718 static void
3719 cmd_csum_parsed(void *parsed_result,
3720                        __attribute__((unused)) struct cmdline *cl,
3721                        __attribute__((unused)) void *data)
3722 {
3723         struct cmd_csum_result *res = parsed_result;
3724         int hw = 0;
3725         uint16_t mask = 0;
3726         uint64_t csum_offloads = 0;
3727
3728         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3729                 printf("invalid port %d\n", res->port_id);
3730                 return;
3731         }
3732         if (!port_is_stopped(res->port_id)) {
3733                 printf("Please stop port %d first\n", res->port_id);
3734                 return;
3735         }
3736
3737         if (!strcmp(res->mode, "set")) {
3738
3739                 if (!strcmp(res->hwsw, "hw"))
3740                         hw = 1;
3741
3742                 if (!strcmp(res->proto, "ip")) {
3743                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3744                         csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3745                 } else if (!strcmp(res->proto, "udp")) {
3746                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3747                         csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3748                 } else if (!strcmp(res->proto, "tcp")) {
3749                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3750                         csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3751                 } else if (!strcmp(res->proto, "sctp")) {
3752                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3753                         csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3754                 } else if (!strcmp(res->proto, "outer-ip")) {
3755                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3756                         csum_offloads |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3757                 }
3758
3759                 if (hw) {
3760                         ports[res->port_id].tx_ol_flags |= mask;
3761                         ports[res->port_id].dev_conf.txmode.offloads |=
3762                                                         csum_offloads;
3763                 } else {
3764                         ports[res->port_id].tx_ol_flags &= (~mask);
3765                         ports[res->port_id].dev_conf.txmode.offloads &=
3766                                                         (~csum_offloads);
3767                 }
3768         }
3769         csum_show(res->port_id);
3770
3771         cmd_reconfig_device_queue(res->port_id, 1, 1);
3772 }
3773
3774 cmdline_parse_token_string_t cmd_csum_csum =
3775         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3776                                 csum, "csum");
3777 cmdline_parse_token_string_t cmd_csum_mode =
3778         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3779                                 mode, "set");
3780 cmdline_parse_token_string_t cmd_csum_proto =
3781         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3782                                 proto, "ip#tcp#udp#sctp#outer-ip");
3783 cmdline_parse_token_string_t cmd_csum_hwsw =
3784         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3785                                 hwsw, "hw#sw");
3786 cmdline_parse_token_num_t cmd_csum_portid =
3787         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3788                                 port_id, UINT16);
3789
3790 cmdline_parse_inst_t cmd_csum_set = {
3791         .f = cmd_csum_parsed,
3792         .data = NULL,
3793         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3794                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3795                 "using csum forward engine",
3796         .tokens = {
3797                 (void *)&cmd_csum_csum,
3798                 (void *)&cmd_csum_mode,
3799                 (void *)&cmd_csum_proto,
3800                 (void *)&cmd_csum_hwsw,
3801                 (void *)&cmd_csum_portid,
3802                 NULL,
3803         },
3804 };
3805
3806 cmdline_parse_token_string_t cmd_csum_mode_show =
3807         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3808                                 mode, "show");
3809
3810 cmdline_parse_inst_t cmd_csum_show = {
3811         .f = cmd_csum_parsed,
3812         .data = NULL,
3813         .help_str = "csum show <port_id>: Show checksum offload configuration",
3814         .tokens = {
3815                 (void *)&cmd_csum_csum,
3816                 (void *)&cmd_csum_mode_show,
3817                 (void *)&cmd_csum_portid,
3818                 NULL,
3819         },
3820 };
3821
3822 /* Enable/disable tunnel parsing */
3823 struct cmd_csum_tunnel_result {
3824         cmdline_fixed_string_t csum;
3825         cmdline_fixed_string_t parse;
3826         cmdline_fixed_string_t onoff;
3827         portid_t port_id;
3828 };
3829
3830 static void
3831 cmd_csum_tunnel_parsed(void *parsed_result,
3832                        __attribute__((unused)) struct cmdline *cl,
3833                        __attribute__((unused)) void *data)
3834 {
3835         struct cmd_csum_tunnel_result *res = parsed_result;
3836
3837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3838                 return;
3839
3840         if (!strcmp(res->onoff, "on"))
3841                 ports[res->port_id].tx_ol_flags |=
3842                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3843         else
3844                 ports[res->port_id].tx_ol_flags &=
3845                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3846
3847         csum_show(res->port_id);
3848 }
3849
3850 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3851         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3852                                 csum, "csum");
3853 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3854         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3855                                 parse, "parse_tunnel");
3856 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3857         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3858                                 onoff, "on#off");
3859 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3860         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3861                                 port_id, UINT16);
3862
3863 cmdline_parse_inst_t cmd_csum_tunnel = {
3864         .f = cmd_csum_tunnel_parsed,
3865         .data = NULL,
3866         .help_str = "csum parse_tunnel on|off <port_id>: "
3867                 "Enable/Disable parsing of tunnels for csum engine",
3868         .tokens = {
3869                 (void *)&cmd_csum_tunnel_csum,
3870                 (void *)&cmd_csum_tunnel_parse,
3871                 (void *)&cmd_csum_tunnel_onoff,
3872                 (void *)&cmd_csum_tunnel_portid,
3873                 NULL,
3874         },
3875 };
3876
3877 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3878 struct cmd_tso_set_result {
3879         cmdline_fixed_string_t tso;
3880         cmdline_fixed_string_t mode;
3881         uint16_t tso_segsz;
3882         portid_t port_id;
3883 };
3884
3885 static void
3886 cmd_tso_set_parsed(void *parsed_result,
3887                        __attribute__((unused)) struct cmdline *cl,
3888                        __attribute__((unused)) void *data)
3889 {
3890         struct cmd_tso_set_result *res = parsed_result;
3891         struct rte_eth_dev_info dev_info;
3892
3893         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3894                 return;
3895         if (!port_is_stopped(res->port_id)) {
3896                 printf("Please stop port %d first\n", res->port_id);
3897                 return;
3898         }
3899
3900         if (!strcmp(res->mode, "set"))
3901                 ports[res->port_id].tso_segsz = res->tso_segsz;
3902
3903         if (ports[res->port_id].tso_segsz == 0) {
3904                 ports[res->port_id].dev_conf.txmode.offloads &=
3905                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3906                 printf("TSO for non-tunneled packets is disabled\n");
3907         } else {
3908                 ports[res->port_id].dev_conf.txmode.offloads |=
3909                                                 DEV_TX_OFFLOAD_TCP_TSO;
3910                 printf("TSO segment size for non-tunneled packets is %d\n",
3911                         ports[res->port_id].tso_segsz);
3912         }
3913
3914         /* display warnings if configuration is not supported by the NIC */
3915         rte_eth_dev_info_get(res->port_id, &dev_info);
3916         if ((ports[res->port_id].tso_segsz != 0) &&
3917                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3918                 printf("Warning: TSO enabled but not "
3919                         "supported by port %d\n", res->port_id);
3920         }
3921
3922         cmd_reconfig_device_queue(res->port_id, 1, 1);
3923 }
3924
3925 cmdline_parse_token_string_t cmd_tso_set_tso =
3926         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3927                                 tso, "tso");
3928 cmdline_parse_token_string_t cmd_tso_set_mode =
3929         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3930                                 mode, "set");
3931 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3932         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3933                                 tso_segsz, UINT16);
3934 cmdline_parse_token_num_t cmd_tso_set_portid =
3935         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3936                                 port_id, UINT16);
3937
3938 cmdline_parse_inst_t cmd_tso_set = {
3939         .f = cmd_tso_set_parsed,
3940         .data = NULL,
3941         .help_str = "tso set <tso_segsz> <port_id>: "
3942                 "Set TSO segment size of non-tunneled packets for csum engine "
3943                 "(0 to disable)",
3944         .tokens = {
3945                 (void *)&cmd_tso_set_tso,
3946                 (void *)&cmd_tso_set_mode,
3947                 (void *)&cmd_tso_set_tso_segsz,
3948                 (void *)&cmd_tso_set_portid,
3949                 NULL,
3950         },
3951 };
3952
3953 cmdline_parse_token_string_t cmd_tso_show_mode =
3954         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3955                                 mode, "show");
3956
3957
3958 cmdline_parse_inst_t cmd_tso_show = {
3959         .f = cmd_tso_set_parsed,
3960         .data = NULL,
3961         .help_str = "tso show <port_id>: "
3962                 "Show TSO segment size of non-tunneled packets for csum engine",
3963         .tokens = {
3964                 (void *)&cmd_tso_set_tso,
3965                 (void *)&cmd_tso_show_mode,
3966                 (void *)&cmd_tso_set_portid,
3967                 NULL,
3968         },
3969 };
3970
3971 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3972 struct cmd_tunnel_tso_set_result {
3973         cmdline_fixed_string_t tso;
3974         cmdline_fixed_string_t mode;
3975         uint16_t tso_segsz;
3976         portid_t port_id;
3977 };
3978
3979 static void
3980 check_tunnel_tso_nic_support(portid_t port_id)
3981 {
3982         struct rte_eth_dev_info dev_info;
3983
3984         rte_eth_dev_info_get(port_id, &dev_info);
3985         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3986                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3987                        "supported by port %d\n", port_id);
3988         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3989                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3990                         "supported by port %d\n", port_id);
3991         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3992                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3993                        "supported by port %d\n", port_id);
3994         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3995                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3996                        "supported by port %d\n", port_id);
3997 }
3998
3999 static void
4000 cmd_tunnel_tso_set_parsed(void *parsed_result,
4001                           __attribute__((unused)) struct cmdline *cl,
4002                           __attribute__((unused)) void *data)
4003 {
4004         struct cmd_tunnel_tso_set_result *res = parsed_result;
4005
4006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4007                 return;
4008         if (!port_is_stopped(res->port_id)) {
4009                 printf("Please stop port %d first\n", res->port_id);
4010                 return;
4011         }
4012
4013         if (!strcmp(res->mode, "set"))
4014                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4015
4016         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4017                 ports[res->port_id].dev_conf.txmode.offloads &=
4018                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4019                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4020                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4021                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4022                 printf("TSO for tunneled packets is disabled\n");
4023         } else {
4024                 ports[res->port_id].dev_conf.txmode.offloads |=
4025                         (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4026                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4027                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4028                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4029                 printf("TSO segment size for tunneled packets is %d\n",
4030                         ports[res->port_id].tunnel_tso_segsz);
4031
4032                 /* Below conditions are needed to make it work:
4033                  * (1) tunnel TSO is supported by the NIC;
4034                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4035                  * are recognized;
4036                  * (3) for tunneled pkts with outer L3 of IPv4,
4037                  * "csum set outer-ip" must be set to hw, because after tso,
4038                  * total_len of outer IP header is changed, and the checksum
4039                  * of outer IP header calculated by sw should be wrong; that
4040                  * is not necessary for IPv6 tunneled pkts because there's no
4041                  * checksum in IP header anymore.
4042                  */
4043                 check_tunnel_tso_nic_support(res->port_id);
4044
4045                 if (!(ports[res->port_id].tx_ol_flags &
4046                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
4047                         printf("Warning: csum parse_tunnel must be set "
4048                                 "so that tunneled packets are recognized\n");
4049                 if (!(ports[res->port_id].tx_ol_flags &
4050                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
4051                         printf("Warning: csum set outer-ip must be set to hw "
4052                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4053         }
4054
4055         cmd_reconfig_device_queue(res->port_id, 1, 1);
4056 }
4057
4058 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4059         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4060                                 tso, "tunnel_tso");
4061 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4062         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4063                                 mode, "set");
4064 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4065         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4066                                 tso_segsz, UINT16);
4067 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4068         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4069                                 port_id, UINT16);
4070
4071 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4072         .f = cmd_tunnel_tso_set_parsed,
4073         .data = NULL,
4074         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4075                 "Set TSO segment size of tunneled packets for csum engine "
4076                 "(0 to disable)",
4077         .tokens = {
4078                 (void *)&cmd_tunnel_tso_set_tso,
4079                 (void *)&cmd_tunnel_tso_set_mode,
4080                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4081                 (void *)&cmd_tunnel_tso_set_portid,
4082                 NULL,
4083         },
4084 };
4085
4086 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4087         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4088                                 mode, "show");
4089
4090
4091 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4092         .f = cmd_tunnel_tso_set_parsed,
4093         .data = NULL,
4094         .help_str = "tunnel_tso show <port_id> "
4095                 "Show TSO segment size of tunneled packets for csum engine",
4096         .tokens = {
4097                 (void *)&cmd_tunnel_tso_set_tso,
4098                 (void *)&cmd_tunnel_tso_show_mode,
4099                 (void *)&cmd_tunnel_tso_set_portid,
4100                 NULL,
4101         },
4102 };
4103
4104 /* *** SET GRO FOR A PORT *** */
4105 struct cmd_gro_enable_result {
4106         cmdline_fixed_string_t cmd_set;
4107         cmdline_fixed_string_t cmd_port;
4108         cmdline_fixed_string_t cmd_keyword;
4109         cmdline_fixed_string_t cmd_onoff;
4110         portid_t cmd_pid;
4111 };
4112
4113 static void
4114 cmd_gro_enable_parsed(void *parsed_result,
4115                 __attribute__((unused)) struct cmdline *cl,
4116                 __attribute__((unused)) void *data)
4117 {
4118         struct cmd_gro_enable_result *res;
4119
4120         res = parsed_result;
4121         if (!strcmp(res->cmd_keyword, "gro"))
4122                 setup_gro(res->cmd_onoff, res->cmd_pid);
4123 }
4124
4125 cmdline_parse_token_string_t cmd_gro_enable_set =
4126         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4127                         cmd_set, "set");
4128 cmdline_parse_token_string_t cmd_gro_enable_port =
4129         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4130                         cmd_keyword, "port");
4131 cmdline_parse_token_num_t cmd_gro_enable_pid =
4132         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4133                         cmd_pid, UINT16);
4134 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4135         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4136                         cmd_keyword, "gro");
4137 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4138         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4139                         cmd_onoff, "on#off");
4140
4141 cmdline_parse_inst_t cmd_gro_enable = {
4142         .f = cmd_gro_enable_parsed,
4143         .data = NULL,
4144         .help_str = "set port <port_id> gro on|off",
4145         .tokens = {
4146                 (void *)&cmd_gro_enable_set,
4147                 (void *)&cmd_gro_enable_port,
4148                 (void *)&cmd_gro_enable_pid,
4149                 (void *)&cmd_gro_enable_keyword,
4150                 (void *)&cmd_gro_enable_onoff,
4151                 NULL,
4152         },
4153 };
4154
4155 /* *** DISPLAY GRO CONFIGURATION *** */
4156 struct cmd_gro_show_result {
4157         cmdline_fixed_string_t cmd_show;
4158         cmdline_fixed_string_t cmd_port;
4159         cmdline_fixed_string_t cmd_keyword;
4160         portid_t cmd_pid;
4161 };
4162
4163 static void
4164 cmd_gro_show_parsed(void *parsed_result,
4165                 __attribute__((unused)) struct cmdline *cl,
4166                 __attribute__((unused)) void *data)
4167 {
4168         struct cmd_gro_show_result *res;
4169
4170         res = parsed_result;
4171         if (!strcmp(res->cmd_keyword, "gro"))
4172                 show_gro(res->cmd_pid);
4173 }
4174
4175 cmdline_parse_token_string_t cmd_gro_show_show =
4176         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4177                         cmd_show, "show");
4178 cmdline_parse_token_string_t cmd_gro_show_port =
4179         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4180                         cmd_port, "port");
4181 cmdline_parse_token_num_t cmd_gro_show_pid =
4182         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4183                         cmd_pid, UINT16);
4184 cmdline_parse_token_string_t cmd_gro_show_keyword =
4185         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4186                         cmd_keyword, "gro");
4187
4188 cmdline_parse_inst_t cmd_gro_show = {
4189         .f = cmd_gro_show_parsed,
4190         .data = NULL,
4191         .help_str = "show port <port_id> gro",
4192         .tokens = {
4193                 (void *)&cmd_gro_show_show,
4194                 (void *)&cmd_gro_show_port,
4195                 (void *)&cmd_gro_show_pid,
4196                 (void *)&cmd_gro_show_keyword,
4197                 NULL,
4198         },
4199 };
4200
4201 /* *** SET FLUSH CYCLES FOR GRO *** */
4202 struct cmd_gro_flush_result {
4203         cmdline_fixed_string_t cmd_set;
4204         cmdline_fixed_string_t cmd_keyword;
4205         cmdline_fixed_string_t cmd_flush;
4206         uint8_t cmd_cycles;
4207 };
4208
4209 static void
4210 cmd_gro_flush_parsed(void *parsed_result,
4211                 __attribute__((unused)) struct cmdline *cl,
4212                 __attribute__((unused)) void *data)
4213 {
4214         struct cmd_gro_flush_result *res;
4215
4216         res = parsed_result;
4217         if ((!strcmp(res->cmd_keyword, "gro")) &&
4218                         (!strcmp(res->cmd_flush, "flush")))
4219                 setup_gro_flush_cycles(res->cmd_cycles);
4220 }
4221
4222 cmdline_parse_token_string_t cmd_gro_flush_set =
4223         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4224                         cmd_set, "set");
4225 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4226         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4227                         cmd_keyword, "gro");
4228 cmdline_parse_token_string_t cmd_gro_flush_flush =
4229         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4230                         cmd_flush, "flush");
4231 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4232         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4233                         cmd_cycles, UINT8);
4234
4235 cmdline_parse_inst_t cmd_gro_flush = {
4236         .f = cmd_gro_flush_parsed,
4237         .data = NULL,
4238         .help_str = "set gro flush <cycles>",
4239         .tokens = {
4240                 (void *)&cmd_gro_flush_set,
4241                 (void *)&cmd_gro_flush_keyword,
4242                 (void *)&cmd_gro_flush_flush,
4243                 (void *)&cmd_gro_flush_cycles,
4244                 NULL,
4245         },
4246 };
4247
4248 /* *** ENABLE/DISABLE GSO *** */
4249 struct cmd_gso_enable_result {
4250         cmdline_fixed_string_t cmd_set;
4251         cmdline_fixed_string_t cmd_port;
4252         cmdline_fixed_string_t cmd_keyword;
4253         cmdline_fixed_string_t cmd_mode;
4254         portid_t cmd_pid;
4255 };
4256
4257 static void
4258 cmd_gso_enable_parsed(void *parsed_result,
4259                 __attribute__((unused)) struct cmdline *cl,
4260                 __attribute__((unused)) void *data)
4261 {
4262         struct cmd_gso_enable_result *res;
4263
4264         res = parsed_result;
4265         if (!strcmp(res->cmd_keyword, "gso"))
4266                 setup_gso(res->cmd_mode, res->cmd_pid);
4267 }
4268
4269 cmdline_parse_token_string_t cmd_gso_enable_set =
4270         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4271                         cmd_set, "set");
4272 cmdline_parse_token_string_t cmd_gso_enable_port =
4273         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4274                         cmd_port, "port");
4275 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4276         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4277                         cmd_keyword, "gso");
4278 cmdline_parse_token_string_t cmd_gso_enable_mode =
4279         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4280                         cmd_mode, "on#off");
4281 cmdline_parse_token_num_t cmd_gso_enable_pid =
4282         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4283                         cmd_pid, UINT16);
4284
4285 cmdline_parse_inst_t cmd_gso_enable = {
4286         .f = cmd_gso_enable_parsed,
4287         .data = NULL,
4288         .help_str = "set port <port_id> gso on|off",
4289         .tokens = {
4290                 (void *)&cmd_gso_enable_set,
4291                 (void *)&cmd_gso_enable_port,
4292                 (void *)&cmd_gso_enable_pid,
4293                 (void *)&cmd_gso_enable_keyword,
4294                 (void *)&cmd_gso_enable_mode,
4295                 NULL,
4296         },
4297 };
4298
4299 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4300 struct cmd_gso_size_result {
4301         cmdline_fixed_string_t cmd_set;
4302         cmdline_fixed_string_t cmd_keyword;
4303         cmdline_fixed_string_t cmd_segsz;
4304         uint16_t cmd_size;
4305 };
4306
4307 static void
4308 cmd_gso_size_parsed(void *parsed_result,
4309                        __attribute__((unused)) struct cmdline *cl,
4310                        __attribute__((unused)) void *data)
4311 {
4312         struct cmd_gso_size_result *res = parsed_result;
4313
4314         if (test_done == 0) {
4315                 printf("Before setting GSO segsz, please first"
4316                                 " stop fowarding\n");
4317                 return;
4318         }
4319
4320         if (!strcmp(res->cmd_keyword, "gso") &&
4321                         !strcmp(res->cmd_segsz, "segsz")) {
4322                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4323                         printf("gso_size should be larger than %zu."
4324                                         " Please input a legal value\n",
4325                                         RTE_GSO_SEG_SIZE_MIN);
4326                 else
4327                         gso_max_segment_size = res->cmd_size;
4328         }
4329 }
4330
4331 cmdline_parse_token_string_t cmd_gso_size_set =
4332         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4333                                 cmd_set, "set");
4334 cmdline_parse_token_string_t cmd_gso_size_keyword =
4335         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4336                                 cmd_keyword, "gso");
4337 cmdline_parse_token_string_t cmd_gso_size_segsz =
4338         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4339                                 cmd_segsz, "segsz");
4340 cmdline_parse_token_num_t cmd_gso_size_size =
4341         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4342                                 cmd_size, UINT16);
4343
4344 cmdline_parse_inst_t cmd_gso_size = {
4345         .f = cmd_gso_size_parsed,
4346         .data = NULL,
4347         .help_str = "set gso segsz <length>",
4348         .tokens = {
4349                 (void *)&cmd_gso_size_set,
4350                 (void *)&cmd_gso_size_keyword,
4351                 (void *)&cmd_gso_size_segsz,
4352                 (void *)&cmd_gso_size_size,
4353                 NULL,
4354         },
4355 };
4356
4357 /* *** SHOW GSO CONFIGURATION *** */
4358 struct cmd_gso_show_result {
4359         cmdline_fixed_string_t cmd_show;
4360         cmdline_fixed_string_t cmd_port;
4361         cmdline_fixed_string_t cmd_keyword;
4362         portid_t cmd_pid;
4363 };
4364
4365 static void
4366 cmd_gso_show_parsed(void *parsed_result,
4367                        __attribute__((unused)) struct cmdline *cl,
4368                        __attribute__((unused)) void *data)
4369 {
4370         struct cmd_gso_show_result *res = parsed_result;
4371
4372         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4373                 printf("invalid port id %u\n", res->cmd_pid);
4374                 return;
4375         }
4376         if (!strcmp(res->cmd_keyword, "gso")) {
4377                 if (gso_ports[res->cmd_pid].enable) {
4378                         printf("Max GSO'd packet size: %uB\n"
4379                                         "Supported GSO types: TCP/IPv4, "
4380                                         "VxLAN with inner TCP/IPv4 packet, "
4381                                         "GRE with inner TCP/IPv4  packet\n",
4382                                         gso_max_segment_size);
4383                 } else
4384                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4385         }
4386 }
4387
4388 cmdline_parse_token_string_t cmd_gso_show_show =
4389 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4390                 cmd_show, "show");
4391 cmdline_parse_token_string_t cmd_gso_show_port =
4392 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4393                 cmd_port, "port");
4394 cmdline_parse_token_string_t cmd_gso_show_keyword =
4395         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4396                                 cmd_keyword, "gso");
4397 cmdline_parse_token_num_t cmd_gso_show_pid =
4398         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4399                                 cmd_pid, UINT16);
4400
4401 cmdline_parse_inst_t cmd_gso_show = {
4402         .f = cmd_gso_show_parsed,
4403         .data = NULL,
4404         .help_str = "show port <port_id> gso",
4405         .tokens = {
4406                 (void *)&cmd_gso_show_show,
4407                 (void *)&cmd_gso_show_port,
4408                 (void *)&cmd_gso_show_pid,
4409                 (void *)&cmd_gso_show_keyword,
4410                 NULL,
4411         },
4412 };
4413
4414 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4415 struct cmd_set_flush_rx {
4416         cmdline_fixed_string_t set;
4417         cmdline_fixed_string_t flush_rx;
4418         cmdline_fixed_string_t mode;
4419 };
4420
4421 static void
4422 cmd_set_flush_rx_parsed(void *parsed_result,
4423                 __attribute__((unused)) struct cmdline *cl,
4424                 __attribute__((unused)) void *data)
4425 {
4426         struct cmd_set_flush_rx *res = parsed_result;
4427         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4428 }
4429
4430 cmdline_parse_token_string_t cmd_setflushrx_set =
4431         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4432                         set, "set");
4433 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4434         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4435                         flush_rx, "flush_rx");
4436 cmdline_parse_token_string_t cmd_setflushrx_mode =
4437         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4438                         mode, "on#off");
4439
4440
4441 cmdline_parse_inst_t cmd_set_flush_rx = {
4442         .f = cmd_set_flush_rx_parsed,
4443         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4444         .data = NULL,
4445         .tokens = {
4446                 (void *)&cmd_setflushrx_set,
4447                 (void *)&cmd_setflushrx_flush_rx,
4448                 (void *)&cmd_setflushrx_mode,
4449                 NULL,
4450         },
4451 };
4452
4453 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4454 struct cmd_set_link_check {
4455         cmdline_fixed_string_t set;
4456         cmdline_fixed_string_t link_check;
4457         cmdline_fixed_string_t mode;
4458 };
4459
4460 static void
4461 cmd_set_link_check_parsed(void *parsed_result,
4462                 __attribute__((unused)) struct cmdline *cl,
4463                 __attribute__((unused)) void *data)
4464 {
4465         struct cmd_set_link_check *res = parsed_result;
4466         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4467 }
4468
4469 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4470         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4471                         set, "set");
4472 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4473         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4474                         link_check, "link_check");
4475 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4476         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4477                         mode, "on#off");
4478
4479
4480 cmdline_parse_inst_t cmd_set_link_check = {
4481         .f = cmd_set_link_check_parsed,
4482         .help_str = "set link_check on|off: Enable/Disable link status check "
4483                     "when starting/stopping a port",
4484         .data = NULL,
4485         .tokens = {
4486                 (void *)&cmd_setlinkcheck_set,
4487                 (void *)&cmd_setlinkcheck_link_check,
4488                 (void *)&cmd_setlinkcheck_mode,
4489                 NULL,
4490         },
4491 };
4492
4493 /* *** SET NIC BYPASS MODE *** */
4494 struct cmd_set_bypass_mode_result {
4495         cmdline_fixed_string_t set;
4496         cmdline_fixed_string_t bypass;
4497         cmdline_fixed_string_t mode;
4498         cmdline_fixed_string_t value;
4499         portid_t port_id;
4500 };
4501
4502 static void
4503 cmd_set_bypass_mode_parsed(void *parsed_result,
4504                 __attribute__((unused)) struct cmdline *cl,
4505                 __attribute__((unused)) void *data)
4506 {
4507         struct cmd_set_bypass_mode_result *res = parsed_result;
4508         portid_t port_id = res->port_id;
4509         int32_t rc = -EINVAL;
4510
4511 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4512         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4513
4514         if (!strcmp(res->value, "bypass"))
4515                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4516         else if (!strcmp(res->value, "isolate"))
4517                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4518         else
4519                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4520
4521         /* Set the bypass mode for the relevant port. */
4522         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4523 #endif
4524         if (rc != 0)
4525                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4526 }
4527
4528 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4529         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4530                         set, "set");
4531 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4532         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4533                         bypass, "bypass");
4534 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4535         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4536                         mode, "mode");
4537 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4538         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4539                         value, "normal#bypass#isolate");
4540 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4541         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4542                                 port_id, UINT16);
4543
4544 cmdline_parse_inst_t cmd_set_bypass_mode = {
4545         .f = cmd_set_bypass_mode_parsed,
4546         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4547                     "Set the NIC bypass mode for port_id",
4548         .data = NULL,
4549         .tokens = {
4550                 (void *)&cmd_setbypass_mode_set,
4551                 (void *)&cmd_setbypass_mode_bypass,
4552                 (void *)&cmd_setbypass_mode_mode,
4553                 (void *)&cmd_setbypass_mode_value,
4554                 (void *)&cmd_setbypass_mode_port,
4555                 NULL,
4556         },
4557 };
4558
4559 /* *** SET NIC BYPASS EVENT *** */
4560 struct cmd_set_bypass_event_result {
4561         cmdline_fixed_string_t set;
4562         cmdline_fixed_string_t bypass;
4563         cmdline_fixed_string_t event;
4564         cmdline_fixed_string_t event_value;
4565         cmdline_fixed_string_t mode;
4566         cmdline_fixed_string_t mode_value;
4567         portid_t port_id;
4568 };
4569
4570 static void
4571 cmd_set_bypass_event_parsed(void *parsed_result,
4572                 __attribute__((unused)) struct cmdline *cl,
4573                 __attribute__((unused)) void *data)
4574 {
4575         int32_t rc = -EINVAL;
4576         struct cmd_set_bypass_event_result *res = parsed_result;
4577         portid_t port_id = res->port_id;
4578
4579 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4580         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4581         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4582
4583         if (!strcmp(res->event_value, "timeout"))
4584                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4585         else if (!strcmp(res->event_value, "os_on"))
4586                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4587         else if (!strcmp(res->event_value, "os_off"))
4588                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4589         else if (!strcmp(res->event_value, "power_on"))
4590                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4591         else if (!strcmp(res->event_value, "power_off"))
4592                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4593         else
4594                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4595
4596         if (!strcmp(res->mode_value, "bypass"))
4597                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4598         else if (!strcmp(res->mode_value, "isolate"))
4599                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4600         else
4601                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4602
4603         /* Set the watchdog timeout. */
4604         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4605
4606                 rc = -EINVAL;
4607                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4608                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4609                                                            bypass_timeout);
4610                 }
4611                 if (rc != 0) {
4612                         printf("Failed to set timeout value %u "
4613                         "for port %d, errto code: %d.\n",
4614                         bypass_timeout, port_id, rc);
4615                 }
4616         }
4617
4618         /* Set the bypass event to transition to bypass mode. */
4619         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4620                                               bypass_mode);
4621 #endif
4622
4623         if (rc != 0)
4624                 printf("\t Failed to set bypass event for port = %d.\n",
4625                        port_id);
4626 }
4627
4628 cmdline_parse_token_string_t cmd_setbypass_event_set =
4629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4630                         set, "set");
4631 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4633                         bypass, "bypass");
4634 cmdline_parse_token_string_t cmd_setbypass_event_event =
4635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4636                         event, "event");
4637 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4639                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4640 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4642                         mode, "mode");
4643 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4644         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4645                         mode_value, "normal#bypass#isolate");
4646 cmdline_parse_token_num_t cmd_setbypass_event_port =
4647         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4648                                 port_id, UINT16);
4649
4650 cmdline_parse_inst_t cmd_set_bypass_event = {
4651         .f = cmd_set_bypass_event_parsed,
4652         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4653                 "power_off mode normal|bypass|isolate <port_id>: "
4654                 "Set the NIC bypass event mode for port_id",
4655         .data = NULL,
4656         .tokens = {
4657                 (void *)&cmd_setbypass_event_set,
4658                 (void *)&cmd_setbypass_event_bypass,
4659                 (void *)&cmd_setbypass_event_event,
4660                 (void *)&cmd_setbypass_event_event_value,
4661                 (void *)&cmd_setbypass_event_mode,
4662                 (void *)&cmd_setbypass_event_mode_value,
4663                 (void *)&cmd_setbypass_event_port,
4664                 NULL,
4665         },
4666 };
4667
4668
4669 /* *** SET NIC BYPASS TIMEOUT *** */
4670 struct cmd_set_bypass_timeout_result {
4671         cmdline_fixed_string_t set;
4672         cmdline_fixed_string_t bypass;
4673         cmdline_fixed_string_t timeout;
4674         cmdline_fixed_string_t value;
4675 };
4676
4677 static void
4678 cmd_set_bypass_timeout_parsed(void *parsed_result,
4679                 __attribute__((unused)) struct cmdline *cl,
4680                 __attribute__((unused)) void *data)
4681 {
4682         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4683
4684 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4685         if (!strcmp(res->value, "1.5"))
4686                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4687         else if (!strcmp(res->value, "2"))
4688                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4689         else if (!strcmp(res->value, "3"))
4690                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4691         else if (!strcmp(res->value, "4"))
4692                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4693         else if (!strcmp(res->value, "8"))
4694                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4695         else if (!strcmp(res->value, "16"))
4696                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4697         else if (!strcmp(res->value, "32"))
4698                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4699         else
4700                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4701 #endif
4702 }
4703
4704 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4705         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4706                         set, "set");
4707 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4708         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4709                         bypass, "bypass");
4710 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4711         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4712                         timeout, "timeout");
4713 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4714         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4715                         value, "0#1.5#2#3#4#8#16#32");
4716
4717 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4718         .f = cmd_set_bypass_timeout_parsed,
4719         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4720                 "Set the NIC bypass watchdog timeout in seconds",
4721         .data = NULL,
4722         .tokens = {
4723                 (void *)&cmd_setbypass_timeout_set,
4724                 (void *)&cmd_setbypass_timeout_bypass,
4725                 (void *)&cmd_setbypass_timeout_timeout,
4726                 (void *)&cmd_setbypass_timeout_value,
4727                 NULL,
4728         },
4729 };
4730
4731 /* *** SHOW NIC BYPASS MODE *** */
4732 struct cmd_show_bypass_config_result {
4733         cmdline_fixed_string_t show;
4734         cmdline_fixed_string_t bypass;
4735         cmdline_fixed_string_t config;
4736         portid_t port_id;
4737 };
4738
4739 static void
4740 cmd_show_bypass_config_parsed(void *parsed_result,
4741                 __attribute__((unused)) struct cmdline *cl,
4742                 __attribute__((unused)) void *data)
4743 {
4744         struct cmd_show_bypass_config_result *res = parsed_result;
4745         portid_t port_id = res->port_id;
4746         int rc = -EINVAL;
4747 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4748         uint32_t event_mode;
4749         uint32_t bypass_mode;
4750         uint32_t timeout = bypass_timeout;
4751         int i;
4752
4753         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4754                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4755         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4756                 {"UNKNOWN", "normal", "bypass", "isolate"};
4757         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4758                 "NONE",
4759                 "OS/board on",
4760                 "power supply on",
4761                 "OS/board off",
4762                 "power supply off",
4763                 "timeout"};
4764         int num_events = (sizeof events) / (sizeof events[0]);
4765
4766         /* Display the bypass mode.*/
4767         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4768                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4769                 return;
4770         }
4771         else {
4772                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4773                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4774
4775                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4776         }
4777
4778         /* Display the bypass timeout.*/
4779         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4780                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4781
4782         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4783
4784         /* Display the bypass events and associated modes. */
4785         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4786
4787                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4788                         printf("\tFailed to get bypass mode for event = %s\n",
4789                                 events[i]);
4790                 } else {
4791                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4792                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4793
4794                         printf("\tbypass event: %-16s = %s\n", events[i],
4795                                 modes[event_mode]);
4796                 }
4797         }
4798 #endif
4799         if (rc != 0)
4800                 printf("\tFailed to get bypass configuration for port = %d\n",
4801                        port_id);
4802 }
4803
4804 cmdline_parse_token_string_t cmd_showbypass_config_show =
4805         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4806                         show, "show");
4807 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4808         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4809                         bypass, "bypass");
4810 cmdline_parse_token_string_t cmd_showbypass_config_config =
4811         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4812                         config, "config");
4813 cmdline_parse_token_num_t cmd_showbypass_config_port =
4814         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4815                                 port_id, UINT16);
4816
4817 cmdline_parse_inst_t cmd_show_bypass_config = {
4818         .f = cmd_show_bypass_config_parsed,
4819         .help_str = "show bypass config <port_id>: "
4820                     "Show the NIC bypass config for port_id",
4821         .data = NULL,
4822         .tokens = {
4823                 (void *)&cmd_showbypass_config_show,
4824                 (void *)&cmd_showbypass_config_bypass,
4825                 (void *)&cmd_showbypass_config_config,
4826                 (void *)&cmd_showbypass_config_port,
4827                 NULL,
4828         },
4829 };
4830
4831 #ifdef RTE_LIBRTE_PMD_BOND
4832 /* *** SET BONDING MODE *** */
4833 struct cmd_set_bonding_mode_result {
4834         cmdline_fixed_string_t set;
4835         cmdline_fixed_string_t bonding;
4836         cmdline_fixed_string_t mode;
4837         uint8_t value;
4838         portid_t port_id;
4839 };
4840
4841 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4842                 __attribute__((unused))  struct cmdline *cl,
4843                 __attribute__((unused)) void *data)
4844 {
4845         struct cmd_set_bonding_mode_result *res = parsed_result;
4846         portid_t port_id = res->port_id;
4847
4848         /* Set the bonding mode for the relevant port. */
4849         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4850                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4851 }
4852
4853 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4855                 set, "set");
4856 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4858                 bonding, "bonding");
4859 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4860 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4861                 mode, "mode");
4862 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4863 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4864                 value, UINT8);
4865 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4866 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4867                 port_id, UINT16);
4868
4869 cmdline_parse_inst_t cmd_set_bonding_mode = {
4870                 .f = cmd_set_bonding_mode_parsed,
4871                 .help_str = "set bonding mode <mode_value> <port_id>: "
4872                         "Set the bonding mode for port_id",
4873                 .data = NULL,
4874                 .tokens = {
4875                                 (void *) &cmd_setbonding_mode_set,
4876                                 (void *) &cmd_setbonding_mode_bonding,
4877                                 (void *) &cmd_setbonding_mode_mode,
4878                                 (void *) &cmd_setbonding_mode_value,
4879                                 (void *) &cmd_setbonding_mode_port,
4880                                 NULL
4881                 }
4882 };
4883
4884 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4885 struct cmd_set_bonding_lacp_dedicated_queues_result {
4886         cmdline_fixed_string_t set;
4887         cmdline_fixed_string_t bonding;
4888         cmdline_fixed_string_t lacp;
4889         cmdline_fixed_string_t dedicated_queues;
4890         portid_t port_id;
4891         cmdline_fixed_string_t mode;
4892 };
4893
4894 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4895                 __attribute__((unused))  struct cmdline *cl,
4896                 __attribute__((unused)) void *data)
4897 {
4898         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4899         portid_t port_id = res->port_id;
4900         struct rte_port *port;
4901
4902         port = &ports[port_id];
4903
4904         /** Check if the port is not started **/
4905         if (port->port_status != RTE_PORT_STOPPED) {
4906                 printf("Please stop port %d first\n", port_id);
4907                 return;
4908         }
4909
4910         if (!strcmp(res->mode, "enable")) {
4911                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4912                         printf("Dedicate queues for LACP control packets"
4913                                         " enabled\n");
4914                 else
4915                         printf("Enabling dedicate queues for LACP control "
4916                                         "packets on port %d failed\n", port_id);
4917         } else if (!strcmp(res->mode, "disable")) {
4918                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4919                         printf("Dedicated queues for LACP control packets "
4920                                         "disabled\n");
4921                 else
4922                         printf("Disabling dedicated queues for LACP control "
4923                                         "traffic on port %d failed\n", port_id);
4924         }
4925 }
4926
4927 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4929                 set, "set");
4930 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4932                 bonding, "bonding");
4933 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4934 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4935                 lacp, "lacp");
4936 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4937 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4938                 dedicated_queues, "dedicated_queues");
4939 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4940 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4941                 port_id, UINT16);
4942 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4943 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4944                 mode, "enable#disable");
4945
4946 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4947                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4948                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4949                         "enable|disable: "
4950                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4951                 .data = NULL,
4952                 .tokens = {
4953                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4954                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4955                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4956                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4957                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4958                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4959                         NULL
4960                 }
4961 };
4962
4963 /* *** SET BALANCE XMIT POLICY *** */
4964 struct cmd_set_bonding_balance_xmit_policy_result {
4965         cmdline_fixed_string_t set;
4966         cmdline_fixed_string_t bonding;
4967         cmdline_fixed_string_t balance_xmit_policy;
4968         portid_t port_id;
4969         cmdline_fixed_string_t policy;
4970 };
4971
4972 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4973                 __attribute__((unused))  struct cmdline *cl,
4974                 __attribute__((unused)) void *data)
4975 {
4976         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4977         portid_t port_id = res->port_id;
4978         uint8_t policy;
4979
4980         if (!strcmp(res->policy, "l2")) {
4981                 policy = BALANCE_XMIT_POLICY_LAYER2;
4982         } else if (!strcmp(res->policy, "l23")) {
4983                 policy = BALANCE_XMIT_POLICY_LAYER23;
4984         } else if (!strcmp(res->policy, "l34")) {
4985                 policy = BALANCE_XMIT_POLICY_LAYER34;
4986         } else {
4987                 printf("\t Invalid xmit policy selection");
4988                 return;
4989         }
4990
4991         /* Set the bonding mode for the relevant port. */
4992         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4993                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4994                                 port_id);
4995         }
4996 }
4997
4998 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4999 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5000                 set, "set");
5001 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5002 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5003                 bonding, "bonding");
5004 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5005 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5006                 balance_xmit_policy, "balance_xmit_policy");
5007 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5008 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5009                 port_id, UINT16);
5010 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5011 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5012                 policy, "l2#l23#l34");
5013
5014 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5015                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5016                 .help_str = "set bonding balance_xmit_policy <port_id> "
5017                         "l2|l23|l34: "
5018                         "Set the bonding balance_xmit_policy for port_id",
5019                 .data = NULL,
5020                 .tokens = {
5021                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5022                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5023                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5024                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5025                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5026                                 NULL
5027                 }
5028 };
5029
5030 /* *** SHOW NIC BONDING CONFIGURATION *** */
5031 struct cmd_show_bonding_config_result {
5032         cmdline_fixed_string_t show;
5033         cmdline_fixed_string_t bonding;
5034         cmdline_fixed_string_t config;
5035         portid_t port_id;
5036 };
5037
5038 static void cmd_show_bonding_config_parsed(void *parsed_result,
5039                 __attribute__((unused))  struct cmdline *cl,
5040                 __attribute__((unused)) void *data)
5041 {
5042         struct cmd_show_bonding_config_result *res = parsed_result;
5043         int bonding_mode, agg_mode;
5044         portid_t slaves[RTE_MAX_ETHPORTS];
5045         int num_slaves, num_active_slaves;
5046         int primary_id;
5047         int i;
5048         portid_t port_id = res->port_id;
5049
5050         /* Display the bonding mode.*/
5051         bonding_mode = rte_eth_bond_mode_get(port_id);
5052         if (bonding_mode < 0) {
5053                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5054                 return;
5055         } else
5056                 printf("\tBonding mode: %d\n", bonding_mode);
5057
5058         if (bonding_mode == BONDING_MODE_BALANCE) {
5059                 int balance_xmit_policy;
5060
5061                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5062                 if (balance_xmit_policy < 0) {
5063                         printf("\tFailed to get balance xmit policy for port = %d\n",
5064                                         port_id);
5065                         return;
5066                 } else {
5067                         printf("\tBalance Xmit Policy: ");
5068
5069                         switch (balance_xmit_policy) {
5070                         case BALANCE_XMIT_POLICY_LAYER2:
5071                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5072                                 break;
5073                         case BALANCE_XMIT_POLICY_LAYER23:
5074                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5075                                 break;
5076                         case BALANCE_XMIT_POLICY_LAYER34:
5077                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5078                                 break;
5079                         }
5080                         printf("\n");
5081                 }
5082         }
5083
5084         if (bonding_mode == BONDING_MODE_8023AD) {
5085                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5086                 printf("\tIEEE802.3AD Aggregator Mode: ");
5087                 switch (agg_mode) {
5088                 case AGG_BANDWIDTH:
5089                         printf("bandwidth");
5090                         break;
5091                 case AGG_STABLE:
5092                         printf("stable");
5093                         break;
5094                 case AGG_COUNT:
5095                         printf("count");
5096                         break;
5097                 }
5098                 printf("\n");
5099         }
5100
5101         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5102
5103         if (num_slaves < 0) {
5104                 printf("\tFailed to get slave list for port = %d\n", port_id);
5105                 return;
5106         }
5107         if (num_slaves > 0) {
5108                 printf("\tSlaves (%d): [", num_slaves);
5109                 for (i = 0; i < num_slaves - 1; i++)
5110                         printf("%d ", slaves[i]);
5111
5112                 printf("%d]\n", slaves[num_slaves - 1]);
5113         } else {
5114                 printf("\tSlaves: []\n");
5115
5116         }
5117
5118         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5119                         RTE_MAX_ETHPORTS);
5120
5121         if (num_active_slaves < 0) {
5122                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5123                 return;
5124         }
5125         if (num_active_slaves > 0) {
5126                 printf("\tActive Slaves (%d): [", num_active_slaves);
5127                 for (i = 0; i < num_active_slaves - 1; i++)
5128                         printf("%d ", slaves[i]);
5129
5130                 printf("%d]\n", slaves[num_active_slaves - 1]);
5131
5132         } else {
5133                 printf("\tActive Slaves: []\n");
5134
5135         }
5136
5137         primary_id = rte_eth_bond_primary_get(port_id);
5138         if (primary_id < 0) {
5139                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5140                 return;
5141         } else
5142                 printf("\tPrimary: [%d]\n", primary_id);
5143
5144 }
5145
5146 cmdline_parse_token_string_t cmd_showbonding_config_show =
5147 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5148                 show, "show");
5149 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5150 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5151                 bonding, "bonding");
5152 cmdline_parse_token_string_t cmd_showbonding_config_config =
5153 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5154                 config, "config");
5155 cmdline_parse_token_num_t cmd_showbonding_config_port =
5156 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5157                 port_id, UINT16);
5158
5159 cmdline_parse_inst_t cmd_show_bonding_config = {
5160                 .f = cmd_show_bonding_config_parsed,
5161                 .help_str = "show bonding config <port_id>: "
5162                         "Show the bonding config for port_id",
5163                 .data = NULL,
5164                 .tokens = {
5165                                 (void *)&cmd_showbonding_config_show,
5166                                 (void *)&cmd_showbonding_config_bonding,
5167                                 (void *)&cmd_showbonding_config_config,
5168                                 (void *)&cmd_showbonding_config_port,
5169                                 NULL
5170                 }
5171 };
5172
5173 /* *** SET BONDING PRIMARY *** */
5174 struct cmd_set_bonding_primary_result {
5175         cmdline_fixed_string_t set;
5176         cmdline_fixed_string_t bonding;
5177         cmdline_fixed_string_t primary;
5178         portid_t slave_id;
5179         portid_t port_id;
5180 };
5181
5182 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5183                 __attribute__((unused))  struct cmdline *cl,
5184                 __attribute__((unused)) void *data)
5185 {
5186         struct cmd_set_bonding_primary_result *res = parsed_result;
5187         portid_t master_port_id = res->port_id;
5188         portid_t slave_port_id = res->slave_id;
5189
5190         /* Set the primary slave for a bonded device. */
5191         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5192                 printf("\t Failed to set primary slave for port = %d.\n",
5193                                 master_port_id);
5194                 return;
5195         }
5196         init_port_config();
5197 }
5198
5199 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5200 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5201                 set, "set");
5202 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5203 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5204                 bonding, "bonding");
5205 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5206 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5207                 primary, "primary");
5208 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5209 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5210                 slave_id, UINT16);
5211 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5212 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5213                 port_id, UINT16);
5214
5215 cmdline_parse_inst_t cmd_set_bonding_primary = {
5216                 .f = cmd_set_bonding_primary_parsed,
5217                 .help_str = "set bonding primary <slave_id> <port_id>: "
5218                         "Set the primary slave for port_id",
5219                 .data = NULL,
5220                 .tokens = {
5221                                 (void *)&cmd_setbonding_primary_set,
5222                                 (void *)&cmd_setbonding_primary_bonding,
5223                                 (void *)&cmd_setbonding_primary_primary,
5224                                 (void *)&cmd_setbonding_primary_slave,
5225                                 (void *)&cmd_setbonding_primary_port,
5226                                 NULL
5227                 }
5228 };
5229
5230 /* *** ADD SLAVE *** */
5231 struct cmd_add_bonding_slave_result {
5232         cmdline_fixed_string_t add;
5233         cmdline_fixed_string_t bonding;
5234         cmdline_fixed_string_t slave;
5235         portid_t slave_id;
5236         portid_t port_id;
5237 };
5238
5239 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5240                 __attribute__((unused))  struct cmdline *cl,
5241                 __attribute__((unused)) void *data)
5242 {
5243         struct cmd_add_bonding_slave_result *res = parsed_result;
5244         portid_t master_port_id = res->port_id;
5245         portid_t slave_port_id = res->slave_id;
5246
5247         /* add the slave for a bonded device. */
5248         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5249                 printf("\t Failed to add slave %d to master port = %d.\n",
5250                                 slave_port_id, master_port_id);
5251                 return;
5252         }
5253         init_port_config();
5254         set_port_slave_flag(slave_port_id);
5255 }
5256
5257 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5258 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5259                 add, "add");
5260 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5261 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5262                 bonding, "bonding");
5263 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5264 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5265                 slave, "slave");
5266 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5267 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5268                 slave_id, UINT16);
5269 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5270 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5271                 port_id, UINT16);
5272
5273 cmdline_parse_inst_t cmd_add_bonding_slave = {
5274                 .f = cmd_add_bonding_slave_parsed,
5275                 .help_str = "add bonding slave <slave_id> <port_id>: "
5276                         "Add a slave device to a bonded device",
5277                 .data = NULL,
5278                 .tokens = {
5279                                 (void *)&cmd_addbonding_slave_add,
5280                                 (void *)&cmd_addbonding_slave_bonding,
5281                                 (void *)&cmd_addbonding_slave_slave,
5282                                 (void *)&cmd_addbonding_slave_slaveid,
5283                                 (void *)&cmd_addbonding_slave_port,
5284                                 NULL
5285                 }
5286 };
5287
5288 /* *** REMOVE SLAVE *** */
5289 struct cmd_remove_bonding_slave_result {
5290         cmdline_fixed_string_t remove;
5291         cmdline_fixed_string_t bonding;
5292         cmdline_fixed_string_t slave;
5293         portid_t slave_id;
5294         portid_t port_id;
5295 };
5296
5297 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5298                 __attribute__((unused))  struct cmdline *cl,
5299                 __attribute__((unused)) void *data)
5300 {
5301         struct cmd_remove_bonding_slave_result *res = parsed_result;
5302         portid_t master_port_id = res->port_id;
5303         portid_t slave_port_id = res->slave_id;
5304
5305         /* remove the slave from a bonded device. */
5306         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5307                 printf("\t Failed to remove slave %d from master port = %d.\n",
5308                                 slave_port_id, master_port_id);
5309                 return;
5310         }
5311         init_port_config();
5312         clear_port_slave_flag(slave_port_id);
5313 }
5314
5315 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5316                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5317                                 remove, "remove");
5318 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5319                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5320                                 bonding, "bonding");
5321 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5322                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5323                                 slave, "slave");
5324 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5325                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5326                                 slave_id, UINT16);
5327 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5328                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5329                                 port_id, UINT16);
5330
5331 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5332                 .f = cmd_remove_bonding_slave_parsed,
5333                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5334                         "Remove a slave device from a bonded device",
5335                 .data = NULL,
5336                 .tokens = {
5337                                 (void *)&cmd_removebonding_slave_remove,
5338                                 (void *)&cmd_removebonding_slave_bonding,
5339                                 (void *)&cmd_removebonding_slave_slave,
5340                                 (void *)&cmd_removebonding_slave_slaveid,
5341                                 (void *)&cmd_removebonding_slave_port,
5342                                 NULL
5343                 }
5344 };
5345
5346 /* *** CREATE BONDED DEVICE *** */
5347 struct cmd_create_bonded_device_result {
5348         cmdline_fixed_string_t create;
5349         cmdline_fixed_string_t bonded;
5350         cmdline_fixed_string_t device;
5351         uint8_t mode;
5352         uint8_t socket;
5353 };
5354
5355 static int bond_dev_num = 0;
5356
5357 static void cmd_create_bonded_device_parsed(void *parsed_result,
5358                 __attribute__((unused))  struct cmdline *cl,
5359                 __attribute__((unused)) void *data)
5360 {
5361         struct cmd_create_bonded_device_result *res = parsed_result;
5362         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5363         int port_id;
5364
5365         if (test_done == 0) {
5366                 printf("Please stop forwarding first\n");
5367                 return;
5368         }
5369
5370         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5371                         bond_dev_num++);
5372
5373         /* Create a new bonded device. */
5374         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5375         if (port_id < 0) {
5376                 printf("\t Failed to create bonded device.\n");
5377                 return;
5378         } else {
5379                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5380                                 port_id);
5381
5382                 /* Update number of ports */
5383                 nb_ports = rte_eth_dev_count();
5384                 reconfig(port_id, res->socket);
5385                 rte_eth_promiscuous_enable(port_id);
5386         }
5387
5388 }
5389
5390 cmdline_parse_token_string_t cmd_createbonded_device_create =
5391                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5392                                 create, "create");
5393 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5394                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5395                                 bonded, "bonded");
5396 cmdline_parse_token_string_t cmd_createbonded_device_device =
5397                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5398                                 device, "device");
5399 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5400                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5401                                 mode, UINT8);
5402 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5403                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5404                                 socket, UINT8);
5405
5406 cmdline_parse_inst_t cmd_create_bonded_device = {
5407                 .f = cmd_create_bonded_device_parsed,
5408                 .help_str = "create bonded device <mode> <socket>: "
5409                         "Create a new bonded device with specific bonding mode and socket",
5410                 .data = NULL,
5411                 .tokens = {
5412                                 (void *)&cmd_createbonded_device_create,
5413                                 (void *)&cmd_createbonded_device_bonded,
5414                                 (void *)&cmd_createbonded_device_device,
5415                                 (void *)&cmd_createbonded_device_mode,
5416                                 (void *)&cmd_createbonded_device_socket,
5417                                 NULL
5418                 }
5419 };
5420
5421 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5422 struct cmd_set_bond_mac_addr_result {
5423         cmdline_fixed_string_t set;
5424         cmdline_fixed_string_t bonding;
5425         cmdline_fixed_string_t mac_addr;
5426         uint16_t port_num;
5427         struct ether_addr address;
5428 };
5429
5430 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5431                 __attribute__((unused))  struct cmdline *cl,
5432                 __attribute__((unused)) void *data)
5433 {
5434         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5435         int ret;
5436
5437         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5438                 return;
5439
5440         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5441
5442         /* check the return value and print it if is < 0 */
5443         if (ret < 0)
5444                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5445 }
5446
5447 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5448                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5449 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5450                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5451                                 "bonding");
5452 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5453                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5454                                 "mac_addr");
5455 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5456                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5457                                 port_num, UINT16);
5458 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5459                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5460
5461 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5462                 .f = cmd_set_bond_mac_addr_parsed,
5463                 .data = (void *) 0,
5464                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5465                 .tokens = {
5466                                 (void *)&cmd_set_bond_mac_addr_set,
5467                                 (void *)&cmd_set_bond_mac_addr_bonding,
5468                                 (void *)&cmd_set_bond_mac_addr_mac,
5469                                 (void *)&cmd_set_bond_mac_addr_portnum,
5470                                 (void *)&cmd_set_bond_mac_addr_addr,
5471                                 NULL
5472                 }
5473 };
5474
5475
5476 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5477 struct cmd_set_bond_mon_period_result {
5478         cmdline_fixed_string_t set;
5479         cmdline_fixed_string_t bonding;
5480         cmdline_fixed_string_t mon_period;
5481         uint16_t port_num;
5482         uint32_t period_ms;
5483 };
5484
5485 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5486                 __attribute__((unused))  struct cmdline *cl,
5487                 __attribute__((unused)) void *data)
5488 {
5489         struct cmd_set_bond_mon_period_result *res = parsed_result;
5490         int ret;
5491
5492         if (res->port_num >= nb_ports) {
5493                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5494                 return;
5495         }
5496
5497         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5498
5499         /* check the return value and print it if is < 0 */
5500         if (ret < 0)
5501                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5502 }
5503
5504 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5505                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5506                                 set, "set");
5507 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5508                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5509                                 bonding, "bonding");
5510 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5511                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5512                                 mon_period,     "mon_period");
5513 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5514                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5515                                 port_num, UINT16);
5516 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5517                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5518                                 period_ms, UINT32);
5519
5520 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5521                 .f = cmd_set_bond_mon_period_parsed,
5522                 .data = (void *) 0,
5523                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5524                 .tokens = {
5525                                 (void *)&cmd_set_bond_mon_period_set,
5526                                 (void *)&cmd_set_bond_mon_period_bonding,
5527                                 (void *)&cmd_set_bond_mon_period_mon_period,
5528                                 (void *)&cmd_set_bond_mon_period_portnum,
5529                                 (void *)&cmd_set_bond_mon_period_period_ms,
5530                                 NULL
5531                 }
5532 };
5533
5534
5535
5536 struct cmd_set_bonding_agg_mode_policy_result {
5537         cmdline_fixed_string_t set;
5538         cmdline_fixed_string_t bonding;
5539         cmdline_fixed_string_t agg_mode;
5540         uint16_t port_num;
5541         cmdline_fixed_string_t policy;
5542 };
5543
5544
5545 static void
5546 cmd_set_bonding_agg_mode(void *parsed_result,
5547                 __attribute__((unused)) struct cmdline *cl,
5548                 __attribute__((unused)) void *data)
5549 {
5550         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5551         uint8_t policy = AGG_BANDWIDTH;
5552
5553         if (res->port_num >= nb_ports) {
5554                 printf("Port id %d must be less than %d\n",
5555                                 res->port_num, nb_ports);
5556                 return;
5557         }
5558
5559         if (!strcmp(res->policy, "bandwidth"))
5560                 policy = AGG_BANDWIDTH;
5561         else if (!strcmp(res->policy, "stable"))
5562                 policy = AGG_STABLE;
5563         else if (!strcmp(res->policy, "count"))
5564                 policy = AGG_COUNT;
5565
5566         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5567 }
5568
5569
5570 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5572                                 set, "set");
5573 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5574         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5575                                 bonding, "bonding");
5576
5577 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5578         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5579                                 agg_mode, "agg_mode");
5580
5581 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5582         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5583                                 port_num, UINT16);
5584
5585 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5586         TOKEN_STRING_INITIALIZER(
5587                         struct cmd_set_bonding_balance_xmit_policy_result,
5588                 policy, "stable#bandwidth#count");
5589
5590 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5591         .f = cmd_set_bonding_agg_mode,
5592         .data = (void *) 0,
5593         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5594         .tokens = {
5595                         (void *)&cmd_set_bonding_agg_mode_set,
5596                         (void *)&cmd_set_bonding_agg_mode_bonding,
5597                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5598                         (void *)&cmd_set_bonding_agg_mode_portnum,
5599                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5600                         NULL
5601                 }
5602 };
5603
5604
5605 #endif /* RTE_LIBRTE_PMD_BOND */
5606
5607 /* *** SET FORWARDING MODE *** */
5608 struct cmd_set_fwd_mode_result {
5609         cmdline_fixed_string_t set;
5610         cmdline_fixed_string_t fwd;
5611         cmdline_fixed_string_t mode;
5612 };
5613
5614 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5615                                     __attribute__((unused)) struct cmdline *cl,
5616                                     __attribute__((unused)) void *data)
5617 {
5618         struct cmd_set_fwd_mode_result *res = parsed_result;
5619
5620         retry_enabled = 0;
5621         set_pkt_forwarding_mode(res->mode);
5622 }
5623
5624 cmdline_parse_token_string_t cmd_setfwd_set =
5625         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5626 cmdline_parse_token_string_t cmd_setfwd_fwd =
5627         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5628 cmdline_parse_token_string_t cmd_setfwd_mode =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5630                 "" /* defined at init */);
5631
5632 cmdline_parse_inst_t cmd_set_fwd_mode = {
5633         .f = cmd_set_fwd_mode_parsed,
5634         .data = NULL,
5635         .help_str = NULL, /* defined at init */
5636         .tokens = {
5637                 (void *)&cmd_setfwd_set,
5638                 (void *)&cmd_setfwd_fwd,
5639                 (void *)&cmd_setfwd_mode,
5640                 NULL,
5641         },
5642 };
5643
5644 static void cmd_set_fwd_mode_init(void)
5645 {
5646         char *modes, *c;
5647         static char token[128];
5648         static char help[256];
5649         cmdline_parse_token_string_t *token_struct;
5650
5651         modes = list_pkt_forwarding_modes();
5652         snprintf(help, sizeof(help), "set fwd %s: "
5653                 "Set packet forwarding mode", modes);
5654         cmd_set_fwd_mode.help_str = help;
5655
5656         /* string token separator is # */
5657         for (c = token; *modes != '\0'; modes++)
5658                 if (*modes == '|')
5659                         *c++ = '#';
5660                 else
5661                         *c++ = *modes;
5662         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5663         token_struct->string_data.str = token;
5664 }
5665
5666 /* *** SET RETRY FORWARDING MODE *** */
5667 struct cmd_set_fwd_retry_mode_result {
5668         cmdline_fixed_string_t set;
5669         cmdline_fixed_string_t fwd;
5670         cmdline_fixed_string_t mode;
5671         cmdline_fixed_string_t retry;
5672 };
5673
5674 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5675                             __attribute__((unused)) struct cmdline *cl,
5676                             __attribute__((unused)) void *data)
5677 {
5678         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5679
5680         retry_enabled = 1;
5681         set_pkt_forwarding_mode(res->mode);
5682 }
5683
5684 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5685         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5686                         set, "set");
5687 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5688         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5689                         fwd, "fwd");
5690 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5691         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5692                         mode,
5693                 "" /* defined at init */);
5694 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5695         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5696                         retry, "retry");
5697
5698 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5699         .f = cmd_set_fwd_retry_mode_parsed,
5700         .data = NULL,
5701         .help_str = NULL, /* defined at init */
5702         .tokens = {
5703                 (void *)&cmd_setfwd_retry_set,
5704                 (void *)&cmd_setfwd_retry_fwd,
5705                 (void *)&cmd_setfwd_retry_mode,
5706                 (void *)&cmd_setfwd_retry_retry,
5707                 NULL,
5708         },
5709 };
5710
5711 static void cmd_set_fwd_retry_mode_init(void)
5712 {
5713         char *modes, *c;
5714         static char token[128];
5715         static char help[256];
5716         cmdline_parse_token_string_t *token_struct;
5717
5718         modes = list_pkt_forwarding_retry_modes();
5719         snprintf(help, sizeof(help), "set fwd %s retry: "
5720                 "Set packet forwarding mode with retry", modes);
5721         cmd_set_fwd_retry_mode.help_str = help;
5722
5723         /* string token separator is # */
5724         for (c = token; *modes != '\0'; modes++)
5725                 if (*modes == '|')
5726                         *c++ = '#';
5727                 else
5728                         *c++ = *modes;
5729         token_struct = (cmdline_parse_token_string_t *)
5730                 cmd_set_fwd_retry_mode.tokens[2];
5731         token_struct->string_data.str = token;
5732 }
5733
5734 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5735 struct cmd_set_burst_tx_retry_result {
5736         cmdline_fixed_string_t set;
5737         cmdline_fixed_string_t burst;
5738         cmdline_fixed_string_t tx;
5739         cmdline_fixed_string_t delay;
5740         uint32_t time;
5741         cmdline_fixed_string_t retry;
5742         uint32_t retry_num;
5743 };
5744
5745 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5746                                         __attribute__((unused)) struct cmdline *cl,
5747                                         __attribute__((unused)) void *data)
5748 {
5749         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5750
5751         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5752                 && !strcmp(res->tx, "tx")) {
5753                 if (!strcmp(res->delay, "delay"))
5754                         burst_tx_delay_time = res->time;
5755                 if (!strcmp(res->retry, "retry"))
5756                         burst_tx_retry_num = res->retry_num;
5757         }
5758
5759 }
5760
5761 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5762         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5763 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5765                                  "burst");
5766 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5768 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5769         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5770 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5771         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5772 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5773         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5774 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5775         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5776
5777 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5778         .f = cmd_set_burst_tx_retry_parsed,
5779         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5780         .tokens = {
5781                 (void *)&cmd_set_burst_tx_retry_set,
5782                 (void *)&cmd_set_burst_tx_retry_burst,
5783                 (void *)&cmd_set_burst_tx_retry_tx,
5784                 (void *)&cmd_set_burst_tx_retry_delay,
5785                 (void *)&cmd_set_burst_tx_retry_time,
5786                 (void *)&cmd_set_burst_tx_retry_retry,
5787                 (void *)&cmd_set_burst_tx_retry_retry_num,
5788                 NULL,
5789         },
5790 };
5791
5792 /* *** SET PROMISC MODE *** */
5793 struct cmd_set_promisc_mode_result {
5794         cmdline_fixed_string_t set;
5795         cmdline_fixed_string_t promisc;
5796         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5797         uint16_t port_num;               /* valid if "allports" argument == 0 */
5798         cmdline_fixed_string_t mode;
5799 };
5800
5801 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5802                                         __attribute__((unused)) struct cmdline *cl,
5803                                         void *allports)
5804 {
5805         struct cmd_set_promisc_mode_result *res = parsed_result;
5806         int enable;
5807         portid_t i;
5808
5809         if (!strcmp(res->mode, "on"))
5810                 enable = 1;
5811         else
5812                 enable = 0;
5813
5814         /* all ports */
5815         if (allports) {
5816                 RTE_ETH_FOREACH_DEV(i) {
5817                         if (enable)
5818                                 rte_eth_promiscuous_enable(i);
5819                         else
5820                                 rte_eth_promiscuous_disable(i);
5821                 }
5822         }
5823         else {
5824                 if (enable)
5825                         rte_eth_promiscuous_enable(res->port_num);
5826                 else
5827                         rte_eth_promiscuous_disable(res->port_num);
5828         }
5829 }
5830
5831 cmdline_parse_token_string_t cmd_setpromisc_set =
5832         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5833 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5834         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5835                                  "promisc");
5836 cmdline_parse_token_string_t cmd_setpromisc_portall =
5837         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5838                                  "all");
5839 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5840         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5841                               UINT8);
5842 cmdline_parse_token_string_t cmd_setpromisc_mode =
5843         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5844                                  "on#off");
5845
5846 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5847         .f = cmd_set_promisc_mode_parsed,
5848         .data = (void *)1,
5849         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5850         .tokens = {
5851                 (void *)&cmd_setpromisc_set,
5852                 (void *)&cmd_setpromisc_promisc,
5853                 (void *)&cmd_setpromisc_portall,
5854                 (void *)&cmd_setpromisc_mode,
5855                 NULL,
5856         },
5857 };
5858
5859 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5860         .f = cmd_set_promisc_mode_parsed,
5861         .data = (void *)0,
5862         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5863         .tokens = {
5864                 (void *)&cmd_setpromisc_set,
5865                 (void *)&cmd_setpromisc_promisc,
5866                 (void *)&cmd_setpromisc_portnum,
5867                 (void *)&cmd_setpromisc_mode,
5868                 NULL,
5869         },
5870 };
5871
5872 /* *** SET ALLMULTI MODE *** */
5873 struct cmd_set_allmulti_mode_result {
5874         cmdline_fixed_string_t set;
5875         cmdline_fixed_string_t allmulti;
5876         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5877         uint16_t port_num;               /* valid if "allports" argument == 0 */
5878         cmdline_fixed_string_t mode;
5879 };
5880
5881 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5882                                         __attribute__((unused)) struct cmdline *cl,
5883                                         void *allports)
5884 {
5885         struct cmd_set_allmulti_mode_result *res = parsed_result;
5886         int enable;
5887         portid_t i;
5888
5889         if (!strcmp(res->mode, "on"))
5890                 enable = 1;
5891         else
5892                 enable = 0;
5893
5894         /* all ports */
5895         if (allports) {
5896                 RTE_ETH_FOREACH_DEV(i) {
5897                         if (enable)
5898                                 rte_eth_allmulticast_enable(i);
5899                         else
5900                                 rte_eth_allmulticast_disable(i);
5901                 }
5902         }
5903         else {
5904                 if (enable)
5905                         rte_eth_allmulticast_enable(res->port_num);
5906                 else
5907                         rte_eth_allmulticast_disable(res->port_num);
5908         }
5909 }
5910
5911 cmdline_parse_token_string_t cmd_setallmulti_set =
5912         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5913 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5914         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5915                                  "allmulti");
5916 cmdline_parse_token_string_t cmd_setallmulti_portall =
5917         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5918                                  "all");
5919 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5920         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5921                               UINT16);
5922 cmdline_parse_token_string_t cmd_setallmulti_mode =
5923         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5924                                  "on#off");
5925
5926 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5927         .f = cmd_set_allmulti_mode_parsed,
5928         .data = (void *)1,
5929         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5930         .tokens = {
5931                 (void *)&cmd_setallmulti_set,
5932                 (void *)&cmd_setallmulti_allmulti,
5933                 (void *)&cmd_setallmulti_portall,
5934                 (void *)&cmd_setallmulti_mode,
5935                 NULL,
5936         },
5937 };
5938
5939 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5940         .f = cmd_set_allmulti_mode_parsed,
5941         .data = (void *)0,
5942         .help_str = "set allmulti <port_id> on|off: "
5943                 "Set allmulti mode on port_id",
5944         .tokens = {
5945                 (void *)&cmd_setallmulti_set,
5946                 (void *)&cmd_setallmulti_allmulti,
5947                 (void *)&cmd_setallmulti_portnum,
5948                 (void *)&cmd_setallmulti_mode,
5949                 NULL,
5950         },
5951 };
5952
5953 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5954 struct cmd_link_flow_ctrl_set_result {
5955         cmdline_fixed_string_t set;
5956         cmdline_fixed_string_t flow_ctrl;
5957         cmdline_fixed_string_t rx;
5958         cmdline_fixed_string_t rx_lfc_mode;
5959         cmdline_fixed_string_t tx;
5960         cmdline_fixed_string_t tx_lfc_mode;
5961         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5962         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5963         cmdline_fixed_string_t autoneg_str;
5964         cmdline_fixed_string_t autoneg;
5965         cmdline_fixed_string_t hw_str;
5966         uint32_t high_water;
5967         cmdline_fixed_string_t lw_str;
5968         uint32_t low_water;
5969         cmdline_fixed_string_t pt_str;
5970         uint16_t pause_time;
5971         cmdline_fixed_string_t xon_str;
5972         uint16_t send_xon;
5973         portid_t port_id;
5974 };
5975
5976 cmdline_parse_token_string_t cmd_lfc_set_set =
5977         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5978                                 set, "set");
5979 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5980         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5981                                 flow_ctrl, "flow_ctrl");
5982 cmdline_parse_token_string_t cmd_lfc_set_rx =
5983         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5984                                 rx, "rx");
5985 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5986         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5987                                 rx_lfc_mode, "on#off");
5988 cmdline_parse_token_string_t cmd_lfc_set_tx =
5989         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5990                                 tx, "tx");
5991 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5992         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5993                                 tx_lfc_mode, "on#off");
5994 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5995         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5996                                 hw_str, "high_water");
5997 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5998         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5999                                 high_water, UINT32);
6000 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6001         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6002                                 lw_str, "low_water");
6003 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6004         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6005                                 low_water, UINT32);
6006 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6007         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6008                                 pt_str, "pause_time");
6009 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6010         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6011                                 pause_time, UINT16);
6012 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6013         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6014                                 xon_str, "send_xon");
6015 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6016         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6017                                 send_xon, UINT16);
6018 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6019         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6020                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6021 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6022         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6023                                 mac_ctrl_frame_fwd_mode, "on#off");
6024 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6025         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6026                                 autoneg_str, "autoneg");
6027 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6028         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6029                                 autoneg, "on#off");
6030 cmdline_parse_token_num_t cmd_lfc_set_portid =
6031         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6032                                 port_id, UINT16);
6033
6034 /* forward declaration */
6035 static void
6036 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6037                               void *data);
6038
6039 cmdline_parse_inst_t cmd_link_flow_control_set = {
6040         .f = cmd_link_flow_ctrl_set_parsed,
6041         .data = NULL,
6042         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6043                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6044                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6045         .tokens = {
6046                 (void *)&cmd_lfc_set_set,
6047                 (void *)&cmd_lfc_set_flow_ctrl,
6048                 (void *)&cmd_lfc_set_rx,
6049                 (void *)&cmd_lfc_set_rx_mode,
6050                 (void *)&cmd_lfc_set_tx,
6051                 (void *)&cmd_lfc_set_tx_mode,
6052                 (void *)&cmd_lfc_set_high_water,
6053                 (void *)&cmd_lfc_set_low_water,
6054                 (void *)&cmd_lfc_set_pause_time,
6055                 (void *)&cmd_lfc_set_send_xon,
6056                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6057                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6058                 (void *)&cmd_lfc_set_autoneg_str,
6059                 (void *)&cmd_lfc_set_autoneg,
6060                 (void *)&cmd_lfc_set_portid,
6061                 NULL,
6062         },
6063 };
6064
6065 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6066         .f = cmd_link_flow_ctrl_set_parsed,
6067         .data = (void *)&cmd_link_flow_control_set_rx,
6068         .help_str = "set flow_ctrl rx on|off <port_id>: "
6069                 "Change rx flow control parameter",
6070         .tokens = {
6071                 (void *)&cmd_lfc_set_set,
6072                 (void *)&cmd_lfc_set_flow_ctrl,
6073                 (void *)&cmd_lfc_set_rx,
6074                 (void *)&cmd_lfc_set_rx_mode,
6075                 (void *)&cmd_lfc_set_portid,
6076                 NULL,
6077         },
6078 };
6079
6080 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6081         .f = cmd_link_flow_ctrl_set_parsed,
6082         .data = (void *)&cmd_link_flow_control_set_tx,
6083         .help_str = "set flow_ctrl tx on|off <port_id>: "
6084                 "Change tx flow control parameter",
6085         .tokens = {
6086                 (void *)&cmd_lfc_set_set,
6087                 (void *)&cmd_lfc_set_flow_ctrl,
6088                 (void *)&cmd_lfc_set_tx,
6089                 (void *)&cmd_lfc_set_tx_mode,
6090                 (void *)&cmd_lfc_set_portid,
6091                 NULL,
6092         },
6093 };
6094
6095 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6096         .f = cmd_link_flow_ctrl_set_parsed,
6097         .data = (void *)&cmd_link_flow_control_set_hw,
6098         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6099                 "Change high water flow control parameter",
6100         .tokens = {
6101                 (void *)&cmd_lfc_set_set,
6102                 (void *)&cmd_lfc_set_flow_ctrl,
6103                 (void *)&cmd_lfc_set_high_water_str,
6104                 (void *)&cmd_lfc_set_high_water,
6105                 (void *)&cmd_lfc_set_portid,
6106                 NULL,
6107         },
6108 };
6109
6110 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6111         .f = cmd_link_flow_ctrl_set_parsed,
6112         .data = (void *)&cmd_link_flow_control_set_lw,
6113         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6114                 "Change low water flow control parameter",
6115         .tokens = {
6116                 (void *)&cmd_lfc_set_set,
6117                 (void *)&cmd_lfc_set_flow_ctrl,
6118                 (void *)&cmd_lfc_set_low_water_str,
6119                 (void *)&cmd_lfc_set_low_water,
6120                 (void *)&cmd_lfc_set_portid,
6121                 NULL,
6122         },
6123 };
6124
6125 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6126         .f = cmd_link_flow_ctrl_set_parsed,
6127         .data = (void *)&cmd_link_flow_control_set_pt,
6128         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6129                 "Change pause time flow control parameter",
6130         .tokens = {
6131                 (void *)&cmd_lfc_set_set,
6132                 (void *)&cmd_lfc_set_flow_ctrl,
6133                 (void *)&cmd_lfc_set_pause_time_str,
6134                 (void *)&cmd_lfc_set_pause_time,
6135                 (void *)&cmd_lfc_set_portid,
6136                 NULL,
6137         },
6138 };
6139
6140 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6141         .f = cmd_link_flow_ctrl_set_parsed,
6142         .data = (void *)&cmd_link_flow_control_set_xon,
6143         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6144                 "Change send_xon flow control parameter",
6145         .tokens = {
6146                 (void *)&cmd_lfc_set_set,
6147                 (void *)&cmd_lfc_set_flow_ctrl,
6148                 (void *)&cmd_lfc_set_send_xon_str,
6149                 (void *)&cmd_lfc_set_send_xon,
6150                 (void *)&cmd_lfc_set_portid,
6151                 NULL,
6152         },
6153 };
6154
6155 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6156         .f = cmd_link_flow_ctrl_set_parsed,
6157         .data = (void *)&cmd_link_flow_control_set_macfwd,
6158         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6159                 "Change mac ctrl fwd flow control parameter",
6160         .tokens = {
6161                 (void *)&cmd_lfc_set_set,
6162                 (void *)&cmd_lfc_set_flow_ctrl,
6163                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6164                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6165                 (void *)&cmd_lfc_set_portid,
6166                 NULL,
6167         },
6168 };
6169
6170 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6171         .f = cmd_link_flow_ctrl_set_parsed,
6172         .data = (void *)&cmd_link_flow_control_set_autoneg,
6173         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6174                 "Change autoneg flow control parameter",
6175         .tokens = {
6176                 (void *)&cmd_lfc_set_set,
6177                 (void *)&cmd_lfc_set_flow_ctrl,
6178                 (void *)&cmd_lfc_set_autoneg_str,
6179                 (void *)&cmd_lfc_set_autoneg,
6180                 (void *)&cmd_lfc_set_portid,
6181                 NULL,
6182         },
6183 };
6184
6185 static void
6186 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6187                               __attribute__((unused)) struct cmdline *cl,
6188                               void *data)
6189 {
6190         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6191         cmdline_parse_inst_t *cmd = data;
6192         struct rte_eth_fc_conf fc_conf;
6193         int rx_fc_en = 0;
6194         int tx_fc_en = 0;
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_lfc_mode[2][2] = {
6204                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6205         };
6206
6207         /* Partial command line, retrieve current configuration */
6208         if (cmd) {
6209                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6210                 if (ret != 0) {
6211                         printf("cannot get current flow ctrl parameters, return"
6212                                "code = %d\n", ret);
6213                         return;
6214                 }
6215
6216                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6217                     (fc_conf.mode == RTE_FC_FULL))
6218                         rx_fc_en = 1;
6219                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6220                     (fc_conf.mode == RTE_FC_FULL))
6221                         tx_fc_en = 1;
6222         }
6223
6224         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6225                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6226
6227         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6228                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6229
6230         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6231
6232         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6233                 fc_conf.high_water = res->high_water;
6234
6235         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6236                 fc_conf.low_water = res->low_water;
6237
6238         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6239                 fc_conf.pause_time = res->pause_time;
6240
6241         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6242                 fc_conf.send_xon = res->send_xon;
6243
6244         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6245                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6246                         fc_conf.mac_ctrl_frame_fwd = 1;
6247                 else
6248                         fc_conf.mac_ctrl_frame_fwd = 0;
6249         }
6250
6251         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6252                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6253
6254         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6255         if (ret != 0)
6256                 printf("bad flow contrl parameter, return code = %d \n", ret);
6257 }
6258
6259 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6260 struct cmd_priority_flow_ctrl_set_result {
6261         cmdline_fixed_string_t set;
6262         cmdline_fixed_string_t pfc_ctrl;
6263         cmdline_fixed_string_t rx;
6264         cmdline_fixed_string_t rx_pfc_mode;
6265         cmdline_fixed_string_t tx;
6266         cmdline_fixed_string_t tx_pfc_mode;
6267         uint32_t high_water;
6268         uint32_t low_water;
6269         uint16_t pause_time;
6270         uint8_t  priority;
6271         portid_t port_id;
6272 };
6273
6274 static void
6275 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6276                        __attribute__((unused)) struct cmdline *cl,
6277                        __attribute__((unused)) void *data)
6278 {
6279         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6280         struct rte_eth_pfc_conf pfc_conf;
6281         int rx_fc_enable, tx_fc_enable;
6282         int ret;
6283
6284         /*
6285          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6286          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6287          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6288          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6289          */
6290         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6291                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6292         };
6293
6294         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6295         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6296         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6297         pfc_conf.fc.high_water = res->high_water;
6298         pfc_conf.fc.low_water  = res->low_water;
6299         pfc_conf.fc.pause_time = res->pause_time;
6300         pfc_conf.priority      = res->priority;
6301
6302         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6303         if (ret != 0)
6304                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6305 }
6306
6307 cmdline_parse_token_string_t cmd_pfc_set_set =
6308         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6309                                 set, "set");
6310 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6311         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6312                                 pfc_ctrl, "pfc_ctrl");
6313 cmdline_parse_token_string_t cmd_pfc_set_rx =
6314         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6315                                 rx, "rx");
6316 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6317         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6318                                 rx_pfc_mode, "on#off");
6319 cmdline_parse_token_string_t cmd_pfc_set_tx =
6320         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6321                                 tx, "tx");
6322 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6323         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6324                                 tx_pfc_mode, "on#off");
6325 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6326         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6327                                 high_water, UINT32);
6328 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6329         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6330                                 low_water, UINT32);
6331 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6332         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6333                                 pause_time, UINT16);
6334 cmdline_parse_token_num_t cmd_pfc_set_priority =
6335         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6336                                 priority, UINT8);
6337 cmdline_parse_token_num_t cmd_pfc_set_portid =
6338         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6339                                 port_id, UINT16);
6340
6341 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6342         .f = cmd_priority_flow_ctrl_set_parsed,
6343         .data = NULL,
6344         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6345                 "<pause_time> <priority> <port_id>: "
6346                 "Configure the Ethernet priority flow control",
6347         .tokens = {
6348                 (void *)&cmd_pfc_set_set,
6349                 (void *)&cmd_pfc_set_flow_ctrl,
6350                 (void *)&cmd_pfc_set_rx,
6351                 (void *)&cmd_pfc_set_rx_mode,
6352                 (void *)&cmd_pfc_set_tx,
6353                 (void *)&cmd_pfc_set_tx_mode,
6354                 (void *)&cmd_pfc_set_high_water,
6355                 (void *)&cmd_pfc_set_low_water,
6356                 (void *)&cmd_pfc_set_pause_time,
6357                 (void *)&cmd_pfc_set_priority,
6358                 (void *)&cmd_pfc_set_portid,
6359                 NULL,
6360         },
6361 };
6362
6363 /* *** RESET CONFIGURATION *** */
6364 struct cmd_reset_result {
6365         cmdline_fixed_string_t reset;
6366         cmdline_fixed_string_t def;
6367 };
6368
6369 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6370                              struct cmdline *cl,
6371                              __attribute__((unused)) void *data)
6372 {
6373         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6374         set_def_fwd_config();
6375 }
6376
6377 cmdline_parse_token_string_t cmd_reset_set =
6378         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6379 cmdline_parse_token_string_t cmd_reset_def =
6380         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6381                                  "default");
6382
6383 cmdline_parse_inst_t cmd_reset = {
6384         .f = cmd_reset_parsed,
6385         .data = NULL,
6386         .help_str = "set default: Reset default forwarding configuration",
6387         .tokens = {
6388                 (void *)&cmd_reset_set,
6389                 (void *)&cmd_reset_def,
6390                 NULL,
6391         },
6392 };
6393
6394 /* *** START FORWARDING *** */
6395 struct cmd_start_result {
6396         cmdline_fixed_string_t start;
6397 };
6398
6399 cmdline_parse_token_string_t cmd_start_start =
6400         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6401
6402 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6403                              __attribute__((unused)) struct cmdline *cl,
6404                              __attribute__((unused)) void *data)
6405 {
6406         start_packet_forwarding(0);
6407 }
6408
6409 cmdline_parse_inst_t cmd_start = {
6410         .f = cmd_start_parsed,
6411         .data = NULL,
6412         .help_str = "start: Start packet forwarding",
6413         .tokens = {
6414                 (void *)&cmd_start_start,
6415                 NULL,
6416         },
6417 };
6418
6419 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6420 struct cmd_start_tx_first_result {
6421         cmdline_fixed_string_t start;
6422         cmdline_fixed_string_t tx_first;
6423 };
6424
6425 static void
6426 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6427                           __attribute__((unused)) struct cmdline *cl,
6428                           __attribute__((unused)) void *data)
6429 {
6430         start_packet_forwarding(1);
6431 }
6432
6433 cmdline_parse_token_string_t cmd_start_tx_first_start =
6434         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6435                                  "start");
6436 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6437         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6438                                  tx_first, "tx_first");
6439
6440 cmdline_parse_inst_t cmd_start_tx_first = {
6441         .f = cmd_start_tx_first_parsed,
6442         .data = NULL,
6443         .help_str = "start tx_first: Start packet forwarding, "
6444                 "after sending 1 burst of packets",
6445         .tokens = {
6446                 (void *)&cmd_start_tx_first_start,
6447                 (void *)&cmd_start_tx_first_tx_first,
6448                 NULL,
6449         },
6450 };
6451
6452 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6453 struct cmd_start_tx_first_n_result {
6454         cmdline_fixed_string_t start;
6455         cmdline_fixed_string_t tx_first;
6456         uint32_t tx_num;
6457 };
6458
6459 static void
6460 cmd_start_tx_first_n_parsed(void *parsed_result,
6461                           __attribute__((unused)) struct cmdline *cl,
6462                           __attribute__((unused)) void *data)
6463 {
6464         struct cmd_start_tx_first_n_result *res = parsed_result;
6465
6466         start_packet_forwarding(res->tx_num);
6467 }
6468
6469 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6470         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6471                         start, "start");
6472 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6473         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6474                         tx_first, "tx_first");
6475 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6476         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6477                         tx_num, UINT32);
6478
6479 cmdline_parse_inst_t cmd_start_tx_first_n = {
6480         .f = cmd_start_tx_first_n_parsed,
6481         .data = NULL,
6482         .help_str = "start tx_first <num>: "
6483                 "packet forwarding, after sending <num> bursts of packets",
6484         .tokens = {
6485                 (void *)&cmd_start_tx_first_n_start,
6486                 (void *)&cmd_start_tx_first_n_tx_first,
6487                 (void *)&cmd_start_tx_first_n_tx_num,
6488                 NULL,
6489         },
6490 };
6491
6492 /* *** SET LINK UP *** */
6493 struct cmd_set_link_up_result {
6494         cmdline_fixed_string_t set;
6495         cmdline_fixed_string_t link_up;
6496         cmdline_fixed_string_t port;
6497         portid_t port_id;
6498 };
6499
6500 cmdline_parse_token_string_t cmd_set_link_up_set =
6501         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6502 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6503         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6504                                 "link-up");
6505 cmdline_parse_token_string_t cmd_set_link_up_port =
6506         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6507 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6508         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6509
6510 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6511                              __attribute__((unused)) struct cmdline *cl,
6512                              __attribute__((unused)) void *data)
6513 {
6514         struct cmd_set_link_up_result *res = parsed_result;
6515         dev_set_link_up(res->port_id);
6516 }
6517
6518 cmdline_parse_inst_t cmd_set_link_up = {
6519         .f = cmd_set_link_up_parsed,
6520         .data = NULL,
6521         .help_str = "set link-up port <port id>",
6522         .tokens = {
6523                 (void *)&cmd_set_link_up_set,
6524                 (void *)&cmd_set_link_up_link_up,
6525                 (void *)&cmd_set_link_up_port,
6526                 (void *)&cmd_set_link_up_port_id,
6527                 NULL,
6528         },
6529 };
6530
6531 /* *** SET LINK DOWN *** */
6532 struct cmd_set_link_down_result {
6533         cmdline_fixed_string_t set;
6534         cmdline_fixed_string_t link_down;
6535         cmdline_fixed_string_t port;
6536         portid_t port_id;
6537 };
6538
6539 cmdline_parse_token_string_t cmd_set_link_down_set =
6540         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6541 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6542         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6543                                 "link-down");
6544 cmdline_parse_token_string_t cmd_set_link_down_port =
6545         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6546 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6547         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6548
6549 static void cmd_set_link_down_parsed(
6550                                 __attribute__((unused)) void *parsed_result,
6551                                 __attribute__((unused)) struct cmdline *cl,
6552                                 __attribute__((unused)) void *data)
6553 {
6554         struct cmd_set_link_down_result *res = parsed_result;
6555         dev_set_link_down(res->port_id);
6556 }
6557
6558 cmdline_parse_inst_t cmd_set_link_down = {
6559         .f = cmd_set_link_down_parsed,
6560         .data = NULL,
6561         .help_str = "set link-down port <port id>",
6562         .tokens = {
6563                 (void *)&cmd_set_link_down_set,
6564                 (void *)&cmd_set_link_down_link_down,
6565                 (void *)&cmd_set_link_down_port,
6566                 (void *)&cmd_set_link_down_port_id,
6567                 NULL,
6568         },
6569 };
6570
6571 /* *** SHOW CFG *** */
6572 struct cmd_showcfg_result {
6573         cmdline_fixed_string_t show;
6574         cmdline_fixed_string_t cfg;
6575         cmdline_fixed_string_t what;
6576 };
6577
6578 static void cmd_showcfg_parsed(void *parsed_result,
6579                                __attribute__((unused)) struct cmdline *cl,
6580                                __attribute__((unused)) void *data)
6581 {
6582         struct cmd_showcfg_result *res = parsed_result;
6583         if (!strcmp(res->what, "rxtx"))
6584                 rxtx_config_display();
6585         else if (!strcmp(res->what, "cores"))
6586                 fwd_lcores_config_display();
6587         else if (!strcmp(res->what, "fwd"))
6588                 pkt_fwd_config_display(&cur_fwd_config);
6589         else if (!strcmp(res->what, "txpkts"))
6590                 show_tx_pkt_segments();
6591 }
6592
6593 cmdline_parse_token_string_t cmd_showcfg_show =
6594         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6595 cmdline_parse_token_string_t cmd_showcfg_port =
6596         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6597 cmdline_parse_token_string_t cmd_showcfg_what =
6598         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6599                                  "rxtx#cores#fwd#txpkts");
6600
6601 cmdline_parse_inst_t cmd_showcfg = {
6602         .f = cmd_showcfg_parsed,
6603         .data = NULL,
6604         .help_str = "show config rxtx|cores|fwd|txpkts",
6605         .tokens = {
6606                 (void *)&cmd_showcfg_show,
6607                 (void *)&cmd_showcfg_port,
6608                 (void *)&cmd_showcfg_what,
6609                 NULL,
6610         },
6611 };
6612
6613 /* *** SHOW ALL PORT INFO *** */
6614 struct cmd_showportall_result {
6615         cmdline_fixed_string_t show;
6616         cmdline_fixed_string_t port;
6617         cmdline_fixed_string_t what;
6618         cmdline_fixed_string_t all;
6619 };
6620
6621 static void cmd_showportall_parsed(void *parsed_result,
6622                                 __attribute__((unused)) struct cmdline *cl,
6623                                 __attribute__((unused)) void *data)
6624 {
6625         portid_t i;
6626
6627         struct cmd_showportall_result *res = parsed_result;
6628         if (!strcmp(res->show, "clear")) {
6629                 if (!strcmp(res->what, "stats"))
6630                         RTE_ETH_FOREACH_DEV(i)
6631                                 nic_stats_clear(i);
6632                 else if (!strcmp(res->what, "xstats"))
6633                         RTE_ETH_FOREACH_DEV(i)
6634                                 nic_xstats_clear(i);
6635         } else if (!strcmp(res->what, "info"))
6636                 RTE_ETH_FOREACH_DEV(i)
6637                         port_infos_display(i);
6638         else if (!strcmp(res->what, "stats"))
6639                 RTE_ETH_FOREACH_DEV(i)
6640                         nic_stats_display(i);
6641         else if (!strcmp(res->what, "xstats"))
6642                 RTE_ETH_FOREACH_DEV(i)
6643                         nic_xstats_display(i);
6644         else if (!strcmp(res->what, "fdir"))
6645                 RTE_ETH_FOREACH_DEV(i)
6646                         fdir_get_infos(i);
6647         else if (!strcmp(res->what, "stat_qmap"))
6648                 RTE_ETH_FOREACH_DEV(i)
6649                         nic_stats_mapping_display(i);
6650         else if (!strcmp(res->what, "dcb_tc"))
6651                 RTE_ETH_FOREACH_DEV(i)
6652                         port_dcb_info_display(i);
6653         else if (!strcmp(res->what, "cap"))
6654                 RTE_ETH_FOREACH_DEV(i)
6655                         port_offload_cap_display(i);
6656 }
6657
6658 cmdline_parse_token_string_t cmd_showportall_show =
6659         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6660                                  "show#clear");
6661 cmdline_parse_token_string_t cmd_showportall_port =
6662         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6663 cmdline_parse_token_string_t cmd_showportall_what =
6664         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6665                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6666 cmdline_parse_token_string_t cmd_showportall_all =
6667         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6668 cmdline_parse_inst_t cmd_showportall = {
6669         .f = cmd_showportall_parsed,
6670         .data = NULL,
6671         .help_str = "show|clear port "
6672                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6673         .tokens = {
6674                 (void *)&cmd_showportall_show,
6675                 (void *)&cmd_showportall_port,
6676                 (void *)&cmd_showportall_what,
6677                 (void *)&cmd_showportall_all,
6678                 NULL,
6679         },
6680 };
6681
6682 /* *** SHOW PORT INFO *** */
6683 struct cmd_showport_result {
6684         cmdline_fixed_string_t show;
6685         cmdline_fixed_string_t port;
6686         cmdline_fixed_string_t what;
6687         uint16_t portnum;
6688 };
6689
6690 static void cmd_showport_parsed(void *parsed_result,
6691                                 __attribute__((unused)) struct cmdline *cl,
6692                                 __attribute__((unused)) void *data)
6693 {
6694         struct cmd_showport_result *res = parsed_result;
6695         if (!strcmp(res->show, "clear")) {
6696                 if (!strcmp(res->what, "stats"))
6697                         nic_stats_clear(res->portnum);
6698                 else if (!strcmp(res->what, "xstats"))
6699                         nic_xstats_clear(res->portnum);
6700         } else if (!strcmp(res->what, "info"))
6701                 port_infos_display(res->portnum);
6702         else if (!strcmp(res->what, "stats"))
6703                 nic_stats_display(res->portnum);
6704         else if (!strcmp(res->what, "xstats"))
6705                 nic_xstats_display(res->portnum);
6706         else if (!strcmp(res->what, "fdir"))
6707                  fdir_get_infos(res->portnum);
6708         else if (!strcmp(res->what, "stat_qmap"))
6709                 nic_stats_mapping_display(res->portnum);
6710         else if (!strcmp(res->what, "dcb_tc"))
6711                 port_dcb_info_display(res->portnum);
6712         else if (!strcmp(res->what, "cap"))
6713                 port_offload_cap_display(res->portnum);
6714 }
6715
6716 cmdline_parse_token_string_t cmd_showport_show =
6717         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6718                                  "show#clear");
6719 cmdline_parse_token_string_t cmd_showport_port =
6720         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6721 cmdline_parse_token_string_t cmd_showport_what =
6722         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6723                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6724 cmdline_parse_token_num_t cmd_showport_portnum =
6725         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6726
6727 cmdline_parse_inst_t cmd_showport = {
6728         .f = cmd_showport_parsed,
6729         .data = NULL,
6730         .help_str = "show|clear port "
6731                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6732                 "<port_id>",
6733         .tokens = {
6734                 (void *)&cmd_showport_show,
6735                 (void *)&cmd_showport_port,
6736                 (void *)&cmd_showport_what,
6737                 (void *)&cmd_showport_portnum,
6738                 NULL,
6739         },
6740 };
6741
6742 /* *** SHOW QUEUE INFO *** */
6743 struct cmd_showqueue_result {
6744         cmdline_fixed_string_t show;
6745         cmdline_fixed_string_t type;
6746         cmdline_fixed_string_t what;
6747         uint16_t portnum;
6748         uint16_t queuenum;
6749 };
6750
6751 static void
6752 cmd_showqueue_parsed(void *parsed_result,
6753         __attribute__((unused)) struct cmdline *cl,
6754         __attribute__((unused)) void *data)
6755 {
6756         struct cmd_showqueue_result *res = parsed_result;
6757
6758         if (!strcmp(res->type, "rxq"))
6759                 rx_queue_infos_display(res->portnum, res->queuenum);
6760         else if (!strcmp(res->type, "txq"))
6761                 tx_queue_infos_display(res->portnum, res->queuenum);
6762 }
6763
6764 cmdline_parse_token_string_t cmd_showqueue_show =
6765         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6766 cmdline_parse_token_string_t cmd_showqueue_type =
6767         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6768 cmdline_parse_token_string_t cmd_showqueue_what =
6769         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6770 cmdline_parse_token_num_t cmd_showqueue_portnum =
6771         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6772 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6773         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6774
6775 cmdline_parse_inst_t cmd_showqueue = {
6776         .f = cmd_showqueue_parsed,
6777         .data = NULL,
6778         .help_str = "show rxq|txq info <port_id> <queue_id>",
6779         .tokens = {
6780                 (void *)&cmd_showqueue_show,
6781                 (void *)&cmd_showqueue_type,
6782                 (void *)&cmd_showqueue_what,
6783                 (void *)&cmd_showqueue_portnum,
6784                 (void *)&cmd_showqueue_queuenum,
6785                 NULL,
6786         },
6787 };
6788
6789 /* *** READ PORT REGISTER *** */
6790 struct cmd_read_reg_result {
6791         cmdline_fixed_string_t read;
6792         cmdline_fixed_string_t reg;
6793         portid_t port_id;
6794         uint32_t reg_off;
6795 };
6796
6797 static void
6798 cmd_read_reg_parsed(void *parsed_result,
6799                     __attribute__((unused)) struct cmdline *cl,
6800                     __attribute__((unused)) void *data)
6801 {
6802         struct cmd_read_reg_result *res = parsed_result;
6803         port_reg_display(res->port_id, res->reg_off);
6804 }
6805
6806 cmdline_parse_token_string_t cmd_read_reg_read =
6807         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6808 cmdline_parse_token_string_t cmd_read_reg_reg =
6809         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6810 cmdline_parse_token_num_t cmd_read_reg_port_id =
6811         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6812 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6813         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6814
6815 cmdline_parse_inst_t cmd_read_reg = {
6816         .f = cmd_read_reg_parsed,
6817         .data = NULL,
6818         .help_str = "read reg <port_id> <reg_off>",
6819         .tokens = {
6820                 (void *)&cmd_read_reg_read,
6821                 (void *)&cmd_read_reg_reg,
6822                 (void *)&cmd_read_reg_port_id,
6823                 (void *)&cmd_read_reg_reg_off,
6824                 NULL,
6825         },
6826 };
6827
6828 /* *** READ PORT REGISTER BIT FIELD *** */
6829 struct cmd_read_reg_bit_field_result {
6830         cmdline_fixed_string_t read;
6831         cmdline_fixed_string_t regfield;
6832         portid_t port_id;
6833         uint32_t reg_off;
6834         uint8_t bit1_pos;
6835         uint8_t bit2_pos;
6836 };
6837
6838 static void
6839 cmd_read_reg_bit_field_parsed(void *parsed_result,
6840                               __attribute__((unused)) struct cmdline *cl,
6841                               __attribute__((unused)) void *data)
6842 {
6843         struct cmd_read_reg_bit_field_result *res = parsed_result;
6844         port_reg_bit_field_display(res->port_id, res->reg_off,
6845                                    res->bit1_pos, res->bit2_pos);
6846 }
6847
6848 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6849         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6850                                  "read");
6851 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6852         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6853                                  regfield, "regfield");
6854 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6855         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6856                               UINT16);
6857 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6858         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6859                               UINT32);
6860 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6861         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6862                               UINT8);
6863 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6864         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6865                               UINT8);
6866
6867 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6868         .f = cmd_read_reg_bit_field_parsed,
6869         .data = NULL,
6870         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6871         "Read register bit field between bit_x and bit_y included",
6872         .tokens = {
6873                 (void *)&cmd_read_reg_bit_field_read,
6874                 (void *)&cmd_read_reg_bit_field_regfield,
6875                 (void *)&cmd_read_reg_bit_field_port_id,
6876                 (void *)&cmd_read_reg_bit_field_reg_off,
6877                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6878                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6879                 NULL,
6880         },
6881 };
6882
6883 /* *** READ PORT REGISTER BIT *** */
6884 struct cmd_read_reg_bit_result {
6885         cmdline_fixed_string_t read;
6886         cmdline_fixed_string_t regbit;
6887         portid_t port_id;
6888         uint32_t reg_off;
6889         uint8_t bit_pos;
6890 };
6891
6892 static void
6893 cmd_read_reg_bit_parsed(void *parsed_result,
6894                         __attribute__((unused)) struct cmdline *cl,
6895                         __attribute__((unused)) void *data)
6896 {
6897         struct cmd_read_reg_bit_result *res = parsed_result;
6898         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6899 }
6900
6901 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6902         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6903 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6904         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6905                                  regbit, "regbit");
6906 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6907         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6908 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6909         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6910 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6911         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6912
6913 cmdline_parse_inst_t cmd_read_reg_bit = {
6914         .f = cmd_read_reg_bit_parsed,
6915         .data = NULL,
6916         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6917         .tokens = {
6918                 (void *)&cmd_read_reg_bit_read,
6919                 (void *)&cmd_read_reg_bit_regbit,
6920                 (void *)&cmd_read_reg_bit_port_id,
6921                 (void *)&cmd_read_reg_bit_reg_off,
6922                 (void *)&cmd_read_reg_bit_bit_pos,
6923                 NULL,
6924         },
6925 };
6926
6927 /* *** WRITE PORT REGISTER *** */
6928 struct cmd_write_reg_result {
6929         cmdline_fixed_string_t write;
6930         cmdline_fixed_string_t reg;
6931         portid_t port_id;
6932         uint32_t reg_off;
6933         uint32_t value;
6934 };
6935
6936 static void
6937 cmd_write_reg_parsed(void *parsed_result,
6938                      __attribute__((unused)) struct cmdline *cl,
6939                      __attribute__((unused)) void *data)
6940 {
6941         struct cmd_write_reg_result *res = parsed_result;
6942         port_reg_set(res->port_id, res->reg_off, res->value);
6943 }
6944
6945 cmdline_parse_token_string_t cmd_write_reg_write =
6946         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6947 cmdline_parse_token_string_t cmd_write_reg_reg =
6948         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6949 cmdline_parse_token_num_t cmd_write_reg_port_id =
6950         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6951 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6952         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6953 cmdline_parse_token_num_t cmd_write_reg_value =
6954         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6955
6956 cmdline_parse_inst_t cmd_write_reg = {
6957         .f = cmd_write_reg_parsed,
6958         .data = NULL,
6959         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6960         .tokens = {
6961                 (void *)&cmd_write_reg_write,
6962                 (void *)&cmd_write_reg_reg,
6963                 (void *)&cmd_write_reg_port_id,
6964                 (void *)&cmd_write_reg_reg_off,
6965                 (void *)&cmd_write_reg_value,
6966                 NULL,
6967         },
6968 };
6969
6970 /* *** WRITE PORT REGISTER BIT FIELD *** */
6971 struct cmd_write_reg_bit_field_result {
6972         cmdline_fixed_string_t write;
6973         cmdline_fixed_string_t regfield;
6974         portid_t port_id;
6975         uint32_t reg_off;
6976         uint8_t bit1_pos;
6977         uint8_t bit2_pos;
6978         uint32_t value;
6979 };
6980
6981 static void
6982 cmd_write_reg_bit_field_parsed(void *parsed_result,
6983                                __attribute__((unused)) struct cmdline *cl,
6984                                __attribute__((unused)) void *data)
6985 {
6986         struct cmd_write_reg_bit_field_result *res = parsed_result;
6987         port_reg_bit_field_set(res->port_id, res->reg_off,
6988                           res->bit1_pos, res->bit2_pos, res->value);
6989 }
6990
6991 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6992         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6993                                  "write");
6994 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6995         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6996                                  regfield, "regfield");
6997 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6998         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6999                               UINT16);
7000 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7001         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7002                               UINT32);
7003 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7004         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7005                               UINT8);
7006 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7007         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7008                               UINT8);
7009 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7010         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7011                               UINT32);
7012
7013 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7014         .f = cmd_write_reg_bit_field_parsed,
7015         .data = NULL,
7016         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7017                 "<reg_value>: "
7018                 "Set register bit field between bit_x and bit_y included",
7019         .tokens = {
7020                 (void *)&cmd_write_reg_bit_field_write,
7021                 (void *)&cmd_write_reg_bit_field_regfield,
7022                 (void *)&cmd_write_reg_bit_field_port_id,
7023                 (void *)&cmd_write_reg_bit_field_reg_off,
7024                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7025                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7026                 (void *)&cmd_write_reg_bit_field_value,
7027                 NULL,
7028         },
7029 };
7030
7031 /* *** WRITE PORT REGISTER BIT *** */
7032 struct cmd_write_reg_bit_result {
7033         cmdline_fixed_string_t write;
7034         cmdline_fixed_string_t regbit;
7035         portid_t port_id;
7036         uint32_t reg_off;
7037         uint8_t bit_pos;
7038         uint8_t value;
7039 };
7040
7041 static void
7042 cmd_write_reg_bit_parsed(void *parsed_result,
7043                          __attribute__((unused)) struct cmdline *cl,
7044                          __attribute__((unused)) void *data)
7045 {
7046         struct cmd_write_reg_bit_result *res = parsed_result;
7047         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7048 }
7049
7050 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7051         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7052                                  "write");
7053 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7054         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7055                                  regbit, "regbit");
7056 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7057         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7058 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7059         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7060 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7062 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7063         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7064
7065 cmdline_parse_inst_t cmd_write_reg_bit = {
7066         .f = cmd_write_reg_bit_parsed,
7067         .data = NULL,
7068         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7069                 "0 <= bit_x <= 31",
7070         .tokens = {
7071                 (void *)&cmd_write_reg_bit_write,
7072                 (void *)&cmd_write_reg_bit_regbit,
7073                 (void *)&cmd_write_reg_bit_port_id,
7074                 (void *)&cmd_write_reg_bit_reg_off,
7075                 (void *)&cmd_write_reg_bit_bit_pos,
7076                 (void *)&cmd_write_reg_bit_value,
7077                 NULL,
7078         },
7079 };
7080
7081 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7082 struct cmd_read_rxd_txd_result {
7083         cmdline_fixed_string_t read;
7084         cmdline_fixed_string_t rxd_txd;
7085         portid_t port_id;
7086         uint16_t queue_id;
7087         uint16_t desc_id;
7088 };
7089
7090 static void
7091 cmd_read_rxd_txd_parsed(void *parsed_result,
7092                         __attribute__((unused)) struct cmdline *cl,
7093                         __attribute__((unused)) void *data)
7094 {
7095         struct cmd_read_rxd_txd_result *res = parsed_result;
7096
7097         if (!strcmp(res->rxd_txd, "rxd"))
7098                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7099         else if (!strcmp(res->rxd_txd, "txd"))
7100                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7101 }
7102
7103 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7104         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7105 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7106         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7107                                  "rxd#txd");
7108 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7109         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7110 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7111         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7112 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7113         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7114
7115 cmdline_parse_inst_t cmd_read_rxd_txd = {
7116         .f = cmd_read_rxd_txd_parsed,
7117         .data = NULL,
7118         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7119         .tokens = {
7120                 (void *)&cmd_read_rxd_txd_read,
7121                 (void *)&cmd_read_rxd_txd_rxd_txd,
7122                 (void *)&cmd_read_rxd_txd_port_id,
7123                 (void *)&cmd_read_rxd_txd_queue_id,
7124                 (void *)&cmd_read_rxd_txd_desc_id,
7125                 NULL,
7126         },
7127 };
7128
7129 /* *** QUIT *** */
7130 struct cmd_quit_result {
7131         cmdline_fixed_string_t quit;
7132 };
7133
7134 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7135                             struct cmdline *cl,
7136                             __attribute__((unused)) void *data)
7137 {
7138         pmd_test_exit();
7139         cmdline_quit(cl);
7140 }
7141
7142 cmdline_parse_token_string_t cmd_quit_quit =
7143         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7144
7145 cmdline_parse_inst_t cmd_quit = {
7146         .f = cmd_quit_parsed,
7147         .data = NULL,
7148         .help_str = "quit: Exit application",
7149         .tokens = {
7150                 (void *)&cmd_quit_quit,
7151                 NULL,
7152         },
7153 };
7154
7155 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7156 struct cmd_mac_addr_result {
7157         cmdline_fixed_string_t mac_addr_cmd;
7158         cmdline_fixed_string_t what;
7159         uint16_t port_num;
7160         struct ether_addr address;
7161 };
7162
7163 static void cmd_mac_addr_parsed(void *parsed_result,
7164                 __attribute__((unused)) struct cmdline *cl,
7165                 __attribute__((unused)) void *data)
7166 {
7167         struct cmd_mac_addr_result *res = parsed_result;
7168         int ret;
7169
7170         if (strcmp(res->what, "add") == 0)
7171                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7172         else if (strcmp(res->what, "set") == 0)
7173                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7174                                                        &res->address);
7175         else
7176                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7177
7178         /* check the return value and print it if is < 0 */
7179         if(ret < 0)
7180                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7181
7182 }
7183
7184 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7185         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7186                                 "mac_addr");
7187 cmdline_parse_token_string_t cmd_mac_addr_what =
7188         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7189                                 "add#remove#set");
7190 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7191                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7192                                         UINT16);
7193 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7194                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7195
7196 cmdline_parse_inst_t cmd_mac_addr = {
7197         .f = cmd_mac_addr_parsed,
7198         .data = (void *)0,
7199         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7200                         "Add/Remove/Set MAC address on port_id",
7201         .tokens = {
7202                 (void *)&cmd_mac_addr_cmd,
7203                 (void *)&cmd_mac_addr_what,
7204                 (void *)&cmd_mac_addr_portnum,
7205                 (void *)&cmd_mac_addr_addr,
7206                 NULL,
7207         },
7208 };
7209
7210
7211 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7212 struct cmd_set_qmap_result {
7213         cmdline_fixed_string_t set;
7214         cmdline_fixed_string_t qmap;
7215         cmdline_fixed_string_t what;
7216         portid_t port_id;
7217         uint16_t queue_id;
7218         uint8_t map_value;
7219 };
7220
7221 static void
7222 cmd_set_qmap_parsed(void *parsed_result,
7223                        __attribute__((unused)) struct cmdline *cl,
7224                        __attribute__((unused)) void *data)
7225 {
7226         struct cmd_set_qmap_result *res = parsed_result;
7227         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7228
7229         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7230 }
7231
7232 cmdline_parse_token_string_t cmd_setqmap_set =
7233         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7234                                  set, "set");
7235 cmdline_parse_token_string_t cmd_setqmap_qmap =
7236         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7237                                  qmap, "stat_qmap");
7238 cmdline_parse_token_string_t cmd_setqmap_what =
7239         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7240                                  what, "tx#rx");
7241 cmdline_parse_token_num_t cmd_setqmap_portid =
7242         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7243                               port_id, UINT16);
7244 cmdline_parse_token_num_t cmd_setqmap_queueid =
7245         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7246                               queue_id, UINT16);
7247 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7248         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7249                               map_value, UINT8);
7250
7251 cmdline_parse_inst_t cmd_set_qmap = {
7252         .f = cmd_set_qmap_parsed,
7253         .data = NULL,
7254         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7255                 "Set statistics mapping value on tx|rx queue_id of port_id",
7256         .tokens = {
7257                 (void *)&cmd_setqmap_set,
7258                 (void *)&cmd_setqmap_qmap,
7259                 (void *)&cmd_setqmap_what,
7260                 (void *)&cmd_setqmap_portid,
7261                 (void *)&cmd_setqmap_queueid,
7262                 (void *)&cmd_setqmap_mapvalue,
7263                 NULL,
7264         },
7265 };
7266
7267 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7268 struct cmd_set_xstats_hide_zero_result {
7269         cmdline_fixed_string_t keyword;
7270         cmdline_fixed_string_t name;
7271         cmdline_fixed_string_t on_off;
7272 };
7273
7274 static void
7275 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7276                         __attribute__((unused)) struct cmdline *cl,
7277                         __attribute__((unused)) void *data)
7278 {
7279         struct cmd_set_xstats_hide_zero_result *res;
7280         uint16_t on_off = 0;
7281
7282         res = parsed_result;
7283         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7284         set_xstats_hide_zero(on_off);
7285 }
7286
7287 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7288         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7289                                  keyword, "set");
7290 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7291         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7292                                  name, "xstats-hide-zero");
7293 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7294         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7295                                  on_off, "on#off");
7296
7297 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7298         .f = cmd_set_xstats_hide_zero_parsed,
7299         .data = NULL,
7300         .help_str = "set xstats-hide-zero on|off",
7301         .tokens = {
7302                 (void *)&cmd_set_xstats_hide_zero_keyword,
7303                 (void *)&cmd_set_xstats_hide_zero_name,
7304                 (void *)&cmd_set_xstats_hide_zero_on_off,
7305                 NULL,
7306         },
7307 };
7308
7309 /* *** CONFIGURE UNICAST HASH TABLE *** */
7310 struct cmd_set_uc_hash_table {
7311         cmdline_fixed_string_t set;
7312         cmdline_fixed_string_t port;
7313         portid_t port_id;
7314         cmdline_fixed_string_t what;
7315         struct ether_addr address;
7316         cmdline_fixed_string_t mode;
7317 };
7318
7319 static void
7320 cmd_set_uc_hash_parsed(void *parsed_result,
7321                        __attribute__((unused)) struct cmdline *cl,
7322                        __attribute__((unused)) void *data)
7323 {
7324         int ret=0;
7325         struct cmd_set_uc_hash_table *res = parsed_result;
7326
7327         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7328
7329         if (strcmp(res->what, "uta") == 0)
7330                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7331                                                 &res->address,(uint8_t)is_on);
7332         if (ret < 0)
7333                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7334
7335 }
7336
7337 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7338         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7339                                  set, "set");
7340 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7341         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7342                                  port, "port");
7343 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7344         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7345                               port_id, UINT16);
7346 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7347         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7348                                  what, "uta");
7349 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7350         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7351                                 address);
7352 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7353         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7354                                  mode, "on#off");
7355
7356 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7357         .f = cmd_set_uc_hash_parsed,
7358         .data = NULL,
7359         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7360         .tokens = {
7361                 (void *)&cmd_set_uc_hash_set,
7362                 (void *)&cmd_set_uc_hash_port,
7363                 (void *)&cmd_set_uc_hash_portid,
7364                 (void *)&cmd_set_uc_hash_what,
7365                 (void *)&cmd_set_uc_hash_mac,
7366                 (void *)&cmd_set_uc_hash_mode,
7367                 NULL,
7368         },
7369 };
7370
7371 struct cmd_set_uc_all_hash_table {
7372         cmdline_fixed_string_t set;
7373         cmdline_fixed_string_t port;
7374         portid_t port_id;
7375         cmdline_fixed_string_t what;
7376         cmdline_fixed_string_t value;
7377         cmdline_fixed_string_t mode;
7378 };
7379
7380 static void
7381 cmd_set_uc_all_hash_parsed(void *parsed_result,
7382                        __attribute__((unused)) struct cmdline *cl,
7383                        __attribute__((unused)) void *data)
7384 {
7385         int ret=0;
7386         struct cmd_set_uc_all_hash_table *res = parsed_result;
7387
7388         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7389
7390         if ((strcmp(res->what, "uta") == 0) &&
7391                 (strcmp(res->value, "all") == 0))
7392                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7393         if (ret < 0)
7394                 printf("bad unicast hash table parameter,"
7395                         "return code = %d \n", ret);
7396 }
7397
7398 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7399         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7400                                  set, "set");
7401 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7402         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7403                                  port, "port");
7404 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7405         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7406                               port_id, UINT16);
7407 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7408         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7409                                  what, "uta");
7410 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7411         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7412                                 value,"all");
7413 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7414         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7415                                  mode, "on#off");
7416
7417 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7418         .f = cmd_set_uc_all_hash_parsed,
7419         .data = NULL,
7420         .help_str = "set port <port_id> uta all on|off",
7421         .tokens = {
7422                 (void *)&cmd_set_uc_all_hash_set,
7423                 (void *)&cmd_set_uc_all_hash_port,
7424                 (void *)&cmd_set_uc_all_hash_portid,
7425                 (void *)&cmd_set_uc_all_hash_what,
7426                 (void *)&cmd_set_uc_all_hash_value,
7427                 (void *)&cmd_set_uc_all_hash_mode,
7428                 NULL,
7429         },
7430 };
7431
7432 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7433 struct cmd_set_vf_macvlan_filter {
7434         cmdline_fixed_string_t set;
7435         cmdline_fixed_string_t port;
7436         portid_t port_id;
7437         cmdline_fixed_string_t vf;
7438         uint8_t vf_id;
7439         struct ether_addr address;
7440         cmdline_fixed_string_t filter_type;
7441         cmdline_fixed_string_t mode;
7442 };
7443
7444 static void
7445 cmd_set_vf_macvlan_parsed(void *parsed_result,
7446                        __attribute__((unused)) struct cmdline *cl,
7447                        __attribute__((unused)) void *data)
7448 {
7449         int is_on, ret = 0;
7450         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7451         struct rte_eth_mac_filter filter;
7452
7453         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7454
7455         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7456
7457         /* set VF MAC filter */
7458         filter.is_vf = 1;
7459
7460         /* set VF ID */
7461         filter.dst_id = res->vf_id;
7462
7463         if (!strcmp(res->filter_type, "exact-mac"))
7464                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7465         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7466                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7467         else if (!strcmp(res->filter_type, "hashmac"))
7468                 filter.filter_type = RTE_MAC_HASH_MATCH;
7469         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7470                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7471
7472         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7473
7474         if (is_on)
7475                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7476                                         RTE_ETH_FILTER_MACVLAN,
7477                                         RTE_ETH_FILTER_ADD,
7478                                          &filter);
7479         else
7480                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7481                                         RTE_ETH_FILTER_MACVLAN,
7482                                         RTE_ETH_FILTER_DELETE,
7483                                         &filter);
7484
7485         if (ret < 0)
7486                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7487
7488 }
7489
7490 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7491         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7492                                  set, "set");
7493 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7494         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7495                                  port, "port");
7496 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7497         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7498                               port_id, UINT16);
7499 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7500         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7501                                  vf, "vf");
7502 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7503         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7504                                 vf_id, UINT8);
7505 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7506         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7507                                 address);
7508 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7509         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7510                                 filter_type, "exact-mac#exact-mac-vlan"
7511                                 "#hashmac#hashmac-vlan");
7512 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7513         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7514                                  mode, "on#off");
7515
7516 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7517         .f = cmd_set_vf_macvlan_parsed,
7518         .data = NULL,
7519         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7520                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7521                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7522                 "hash match rule: hash match of MAC and exact match of VLAN",
7523         .tokens = {
7524                 (void *)&cmd_set_vf_macvlan_set,
7525                 (void *)&cmd_set_vf_macvlan_port,
7526                 (void *)&cmd_set_vf_macvlan_portid,
7527                 (void *)&cmd_set_vf_macvlan_vf,
7528                 (void *)&cmd_set_vf_macvlan_vf_id,
7529                 (void *)&cmd_set_vf_macvlan_mac,
7530                 (void *)&cmd_set_vf_macvlan_filter_type,
7531                 (void *)&cmd_set_vf_macvlan_mode,
7532                 NULL,
7533         },
7534 };
7535
7536 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7537 struct cmd_set_vf_traffic {
7538         cmdline_fixed_string_t set;
7539         cmdline_fixed_string_t port;
7540         portid_t port_id;
7541         cmdline_fixed_string_t vf;
7542         uint8_t vf_id;
7543         cmdline_fixed_string_t what;
7544         cmdline_fixed_string_t mode;
7545 };
7546
7547 static void
7548 cmd_set_vf_traffic_parsed(void *parsed_result,
7549                        __attribute__((unused)) struct cmdline *cl,
7550                        __attribute__((unused)) void *data)
7551 {
7552         struct cmd_set_vf_traffic *res = parsed_result;
7553         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7554         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7555
7556         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7557 }
7558
7559 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7560         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7561                                  set, "set");
7562 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7563         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7564                                  port, "port");
7565 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7566         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7567                               port_id, UINT16);
7568 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7569         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7570                                  vf, "vf");
7571 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7572         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7573                               vf_id, UINT8);
7574 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7575         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7576                                  what, "tx#rx");
7577 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7578         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7579                                  mode, "on#off");
7580
7581 cmdline_parse_inst_t cmd_set_vf_traffic = {
7582         .f = cmd_set_vf_traffic_parsed,
7583         .data = NULL,
7584         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7585         .tokens = {
7586                 (void *)&cmd_setvf_traffic_set,
7587                 (void *)&cmd_setvf_traffic_port,
7588                 (void *)&cmd_setvf_traffic_portid,
7589                 (void *)&cmd_setvf_traffic_vf,
7590                 (void *)&cmd_setvf_traffic_vfid,
7591                 (void *)&cmd_setvf_traffic_what,
7592                 (void *)&cmd_setvf_traffic_mode,
7593                 NULL,
7594         },
7595 };
7596
7597 /* *** CONFIGURE VF RECEIVE MODE *** */
7598 struct cmd_set_vf_rxmode {
7599         cmdline_fixed_string_t set;
7600         cmdline_fixed_string_t port;
7601         portid_t port_id;
7602         cmdline_fixed_string_t vf;
7603         uint8_t vf_id;
7604         cmdline_fixed_string_t what;
7605         cmdline_fixed_string_t mode;
7606         cmdline_fixed_string_t on;
7607 };
7608
7609 static void
7610 cmd_set_vf_rxmode_parsed(void *parsed_result,
7611                        __attribute__((unused)) struct cmdline *cl,
7612                        __attribute__((unused)) void *data)
7613 {
7614         int ret = -ENOTSUP;
7615         uint16_t rx_mode = 0;
7616         struct cmd_set_vf_rxmode *res = parsed_result;
7617
7618         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7619         if (!strcmp(res->what,"rxmode")) {
7620                 if (!strcmp(res->mode, "AUPE"))
7621                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7622                 else if (!strcmp(res->mode, "ROPE"))
7623                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7624                 else if (!strcmp(res->mode, "BAM"))
7625                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7626                 else if (!strncmp(res->mode, "MPE",3))
7627                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7628         }
7629
7630         RTE_SET_USED(is_on);
7631
7632 #ifdef RTE_LIBRTE_IXGBE_PMD
7633         if (ret == -ENOTSUP)
7634                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7635                                                   rx_mode, (uint8_t)is_on);
7636 #endif
7637 #ifdef RTE_LIBRTE_BNXT_PMD
7638         if (ret == -ENOTSUP)
7639                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7640                                                  rx_mode, (uint8_t)is_on);
7641 #endif
7642         if (ret < 0)
7643                 printf("bad VF receive mode parameter, return code = %d \n",
7644                 ret);
7645 }
7646
7647 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7648         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7649                                  set, "set");
7650 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7651         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7652                                  port, "port");
7653 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7654         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7655                               port_id, UINT16);
7656 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7657         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7658                                  vf, "vf");
7659 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7660         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7661                               vf_id, UINT8);
7662 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7663         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7664                                  what, "rxmode");
7665 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7666         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7667                                  mode, "AUPE#ROPE#BAM#MPE");
7668 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7669         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7670                                  on, "on#off");
7671
7672 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7673         .f = cmd_set_vf_rxmode_parsed,
7674         .data = NULL,
7675         .help_str = "set port <port_id> vf <vf_id> rxmode "
7676                 "AUPE|ROPE|BAM|MPE on|off",
7677         .tokens = {
7678                 (void *)&cmd_set_vf_rxmode_set,
7679                 (void *)&cmd_set_vf_rxmode_port,
7680                 (void *)&cmd_set_vf_rxmode_portid,
7681                 (void *)&cmd_set_vf_rxmode_vf,
7682                 (void *)&cmd_set_vf_rxmode_vfid,
7683                 (void *)&cmd_set_vf_rxmode_what,
7684                 (void *)&cmd_set_vf_rxmode_mode,
7685                 (void *)&cmd_set_vf_rxmode_on,
7686                 NULL,
7687         },
7688 };
7689
7690 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7691 struct cmd_vf_mac_addr_result {
7692         cmdline_fixed_string_t mac_addr_cmd;
7693         cmdline_fixed_string_t what;
7694         cmdline_fixed_string_t port;
7695         uint16_t port_num;
7696         cmdline_fixed_string_t vf;
7697         uint8_t vf_num;
7698         struct ether_addr address;
7699 };
7700
7701 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7702                 __attribute__((unused)) struct cmdline *cl,
7703                 __attribute__((unused)) void *data)
7704 {
7705         struct cmd_vf_mac_addr_result *res = parsed_result;
7706         int ret = -ENOTSUP;
7707
7708         if (strcmp(res->what, "add") != 0)
7709                 return;
7710
7711 #ifdef RTE_LIBRTE_I40E_PMD
7712         if (ret == -ENOTSUP)
7713                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7714                                                    &res->address);
7715 #endif
7716 #ifdef RTE_LIBRTE_BNXT_PMD
7717         if (ret == -ENOTSUP)
7718                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7719                                                 res->vf_num);
7720 #endif
7721
7722         if(ret < 0)
7723                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7724
7725 }
7726
7727 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7728         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7729                                 mac_addr_cmd,"mac_addr");
7730 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7731         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7732                                 what,"add");
7733 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7734         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7735                                 port,"port");
7736 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7737         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7738                                 port_num, UINT16);
7739 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7740         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7741                                 vf,"vf");
7742 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7743         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7744                                 vf_num, UINT8);
7745 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7746         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7747                                 address);
7748
7749 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7750         .f = cmd_vf_mac_addr_parsed,
7751         .data = (void *)0,
7752         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7753                 "Add MAC address filtering for a VF on port_id",
7754         .tokens = {
7755                 (void *)&cmd_vf_mac_addr_cmd,
7756                 (void *)&cmd_vf_mac_addr_what,
7757                 (void *)&cmd_vf_mac_addr_port,
7758                 (void *)&cmd_vf_mac_addr_portnum,
7759                 (void *)&cmd_vf_mac_addr_vf,
7760                 (void *)&cmd_vf_mac_addr_vfnum,
7761                 (void *)&cmd_vf_mac_addr_addr,
7762                 NULL,
7763         },
7764 };
7765
7766 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7767 struct cmd_vf_rx_vlan_filter {
7768         cmdline_fixed_string_t rx_vlan;
7769         cmdline_fixed_string_t what;
7770         uint16_t vlan_id;
7771         cmdline_fixed_string_t port;
7772         portid_t port_id;
7773         cmdline_fixed_string_t vf;
7774         uint64_t vf_mask;
7775 };
7776
7777 static void
7778 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7779                           __attribute__((unused)) struct cmdline *cl,
7780                           __attribute__((unused)) void *data)
7781 {
7782         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7783         int ret = -ENOTSUP;
7784
7785         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7786
7787 #ifdef RTE_LIBRTE_IXGBE_PMD
7788         if (ret == -ENOTSUP)
7789                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7790                                 res->vlan_id, res->vf_mask, is_add);
7791 #endif
7792 #ifdef RTE_LIBRTE_I40E_PMD
7793         if (ret == -ENOTSUP)
7794                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7795                                 res->vlan_id, res->vf_mask, is_add);
7796 #endif
7797 #ifdef RTE_LIBRTE_BNXT_PMD
7798         if (ret == -ENOTSUP)
7799                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7800                                 res->vlan_id, res->vf_mask, is_add);
7801 #endif
7802
7803         switch (ret) {
7804         case 0:
7805                 break;
7806         case -EINVAL:
7807                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7808                                 res->vlan_id, res->vf_mask);
7809                 break;
7810         case -ENODEV:
7811                 printf("invalid port_id %d\n", res->port_id);
7812                 break;
7813         case -ENOTSUP:
7814                 printf("function not implemented or supported\n");
7815                 break;
7816         default:
7817                 printf("programming error: (%s)\n", strerror(-ret));
7818         }
7819 }
7820
7821 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7822         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7823                                  rx_vlan, "rx_vlan");
7824 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7825         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7826                                  what, "add#rm");
7827 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7828         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7829                               vlan_id, UINT16);
7830 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7831         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7832                                  port, "port");
7833 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7834         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7835                               port_id, UINT16);
7836 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7837         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7838                                  vf, "vf");
7839 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7840         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7841                               vf_mask, UINT64);
7842
7843 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7844         .f = cmd_vf_rx_vlan_filter_parsed,
7845         .data = NULL,
7846         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7847                 "(vf_mask = hexadecimal VF mask)",
7848         .tokens = {
7849                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7850                 (void *)&cmd_vf_rx_vlan_filter_what,
7851                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7852                 (void *)&cmd_vf_rx_vlan_filter_port,
7853                 (void *)&cmd_vf_rx_vlan_filter_portid,
7854                 (void *)&cmd_vf_rx_vlan_filter_vf,
7855                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7856                 NULL,
7857         },
7858 };
7859
7860 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7861 struct cmd_queue_rate_limit_result {
7862         cmdline_fixed_string_t set;
7863         cmdline_fixed_string_t port;
7864         uint16_t port_num;
7865         cmdline_fixed_string_t queue;
7866         uint8_t queue_num;
7867         cmdline_fixed_string_t rate;
7868         uint16_t rate_num;
7869 };
7870
7871 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7872                 __attribute__((unused)) struct cmdline *cl,
7873                 __attribute__((unused)) void *data)
7874 {
7875         struct cmd_queue_rate_limit_result *res = parsed_result;
7876         int ret = 0;
7877
7878         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7879                 && (strcmp(res->queue, "queue") == 0)
7880                 && (strcmp(res->rate, "rate") == 0))
7881                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7882                                         res->rate_num);
7883         if (ret < 0)
7884                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7885
7886 }
7887
7888 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7889         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7890                                 set, "set");
7891 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7892         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7893                                 port, "port");
7894 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7895         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7896                                 port_num, UINT16);
7897 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7898         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7899                                 queue, "queue");
7900 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7901         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7902                                 queue_num, UINT8);
7903 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7904         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7905                                 rate, "rate");
7906 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7907         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7908                                 rate_num, UINT16);
7909
7910 cmdline_parse_inst_t cmd_queue_rate_limit = {
7911         .f = cmd_queue_rate_limit_parsed,
7912         .data = (void *)0,
7913         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7914                 "Set rate limit for a queue on port_id",
7915         .tokens = {
7916                 (void *)&cmd_queue_rate_limit_set,
7917                 (void *)&cmd_queue_rate_limit_port,
7918                 (void *)&cmd_queue_rate_limit_portnum,
7919                 (void *)&cmd_queue_rate_limit_queue,
7920                 (void *)&cmd_queue_rate_limit_queuenum,
7921                 (void *)&cmd_queue_rate_limit_rate,
7922                 (void *)&cmd_queue_rate_limit_ratenum,
7923                 NULL,
7924         },
7925 };
7926
7927 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7928 struct cmd_vf_rate_limit_result {
7929         cmdline_fixed_string_t set;
7930         cmdline_fixed_string_t port;
7931         uint16_t port_num;
7932         cmdline_fixed_string_t vf;
7933         uint8_t vf_num;
7934         cmdline_fixed_string_t rate;
7935         uint16_t rate_num;
7936         cmdline_fixed_string_t q_msk;
7937         uint64_t q_msk_val;
7938 };
7939
7940 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7941                 __attribute__((unused)) struct cmdline *cl,
7942                 __attribute__((unused)) void *data)
7943 {
7944         struct cmd_vf_rate_limit_result *res = parsed_result;
7945         int ret = 0;
7946
7947         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7948                 && (strcmp(res->vf, "vf") == 0)
7949                 && (strcmp(res->rate, "rate") == 0)
7950                 && (strcmp(res->q_msk, "queue_mask") == 0))
7951                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7952                                         res->rate_num, res->q_msk_val);
7953         if (ret < 0)
7954                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7955
7956 }
7957
7958 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7959         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7960                                 set, "set");
7961 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7962         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7963                                 port, "port");
7964 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7965         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7966                                 port_num, UINT16);
7967 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7968         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7969                                 vf, "vf");
7970 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7971         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7972                                 vf_num, UINT8);
7973 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7974         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7975                                 rate, "rate");
7976 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7977         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7978                                 rate_num, UINT16);
7979 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7980         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7981                                 q_msk, "queue_mask");
7982 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7983         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7984                                 q_msk_val, UINT64);
7985
7986 cmdline_parse_inst_t cmd_vf_rate_limit = {
7987         .f = cmd_vf_rate_limit_parsed,
7988         .data = (void *)0,
7989         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7990                 "queue_mask <queue_mask_value>: "
7991                 "Set rate limit for queues of VF on port_id",
7992         .tokens = {
7993                 (void *)&cmd_vf_rate_limit_set,
7994                 (void *)&cmd_vf_rate_limit_port,
7995                 (void *)&cmd_vf_rate_limit_portnum,
7996                 (void *)&cmd_vf_rate_limit_vf,
7997                 (void *)&cmd_vf_rate_limit_vfnum,
7998                 (void *)&cmd_vf_rate_limit_rate,
7999                 (void *)&cmd_vf_rate_limit_ratenum,
8000                 (void *)&cmd_vf_rate_limit_q_msk,
8001                 (void *)&cmd_vf_rate_limit_q_msk_val,
8002                 NULL,
8003         },
8004 };
8005
8006 /* *** ADD TUNNEL FILTER OF A PORT *** */
8007 struct cmd_tunnel_filter_result {
8008         cmdline_fixed_string_t cmd;
8009         cmdline_fixed_string_t what;
8010         portid_t port_id;
8011         struct ether_addr outer_mac;
8012         struct ether_addr inner_mac;
8013         cmdline_ipaddr_t ip_value;
8014         uint16_t inner_vlan;
8015         cmdline_fixed_string_t tunnel_type;
8016         cmdline_fixed_string_t filter_type;
8017         uint32_t tenant_id;
8018         uint16_t queue_num;
8019 };
8020
8021 static void
8022 cmd_tunnel_filter_parsed(void *parsed_result,
8023                           __attribute__((unused)) struct cmdline *cl,
8024                           __attribute__((unused)) void *data)
8025 {
8026         struct cmd_tunnel_filter_result *res = parsed_result;
8027         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8028         int ret = 0;
8029
8030         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8031
8032         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8033         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8034         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8035
8036         if (res->ip_value.family == AF_INET) {
8037                 tunnel_filter_conf.ip_addr.ipv4_addr =
8038                         res->ip_value.addr.ipv4.s_addr;
8039                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8040         } else {
8041                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8042                         &(res->ip_value.addr.ipv6),
8043                         sizeof(struct in6_addr));
8044                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8045         }
8046
8047         if (!strcmp(res->filter_type, "imac-ivlan"))
8048                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8049         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8050                 tunnel_filter_conf.filter_type =
8051                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8052         else if (!strcmp(res->filter_type, "imac-tenid"))
8053                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8054         else if (!strcmp(res->filter_type, "imac"))
8055                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8056         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8057                 tunnel_filter_conf.filter_type =
8058                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8059         else if (!strcmp(res->filter_type, "oip"))
8060                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8061         else if (!strcmp(res->filter_type, "iip"))
8062                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8063         else {
8064                 printf("The filter type is not supported");
8065                 return;
8066         }
8067
8068         if (!strcmp(res->tunnel_type, "vxlan"))
8069                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8070         else if (!strcmp(res->tunnel_type, "nvgre"))
8071                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8072         else if (!strcmp(res->tunnel_type, "ipingre"))
8073                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8074         else {
8075                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8076                 return;
8077         }
8078
8079         tunnel_filter_conf.tenant_id = res->tenant_id;
8080         tunnel_filter_conf.queue_id = res->queue_num;
8081         if (!strcmp(res->what, "add"))
8082                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8083                                         RTE_ETH_FILTER_TUNNEL,
8084                                         RTE_ETH_FILTER_ADD,
8085                                         &tunnel_filter_conf);
8086         else
8087                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8088                                         RTE_ETH_FILTER_TUNNEL,
8089                                         RTE_ETH_FILTER_DELETE,
8090                                         &tunnel_filter_conf);
8091         if (ret < 0)
8092                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8093                                 strerror(-ret));
8094
8095 }
8096 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8097         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8098         cmd, "tunnel_filter");
8099 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8100         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8101         what, "add#rm");
8102 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8103         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8104         port_id, UINT16);
8105 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8106         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8107         outer_mac);
8108 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8109         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8110         inner_mac);
8111 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8112         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8113         inner_vlan, UINT16);
8114 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8115         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8116         ip_value);
8117 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8118         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8119         tunnel_type, "vxlan#nvgre#ipingre");
8120
8121 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8122         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8123         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8124                 "imac#omac-imac-tenid");
8125 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8126         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8127         tenant_id, UINT32);
8128 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8129         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8130         queue_num, UINT16);
8131
8132 cmdline_parse_inst_t cmd_tunnel_filter = {
8133         .f = cmd_tunnel_filter_parsed,
8134         .data = (void *)0,
8135         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8136                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8137                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8138                 "<queue_id>: Add/Rm tunnel filter of a port",
8139         .tokens = {
8140                 (void *)&cmd_tunnel_filter_cmd,
8141                 (void *)&cmd_tunnel_filter_what,
8142                 (void *)&cmd_tunnel_filter_port_id,
8143                 (void *)&cmd_tunnel_filter_outer_mac,
8144                 (void *)&cmd_tunnel_filter_inner_mac,
8145                 (void *)&cmd_tunnel_filter_ip_value,
8146                 (void *)&cmd_tunnel_filter_innner_vlan,
8147                 (void *)&cmd_tunnel_filter_tunnel_type,
8148                 (void *)&cmd_tunnel_filter_filter_type,
8149                 (void *)&cmd_tunnel_filter_tenant_id,
8150                 (void *)&cmd_tunnel_filter_queue_num,
8151                 NULL,
8152         },
8153 };
8154
8155 /* *** CONFIGURE TUNNEL UDP PORT *** */
8156 struct cmd_tunnel_udp_config {
8157         cmdline_fixed_string_t cmd;
8158         cmdline_fixed_string_t what;
8159         uint16_t udp_port;
8160         portid_t port_id;
8161 };
8162
8163 static void
8164 cmd_tunnel_udp_config_parsed(void *parsed_result,
8165                           __attribute__((unused)) struct cmdline *cl,
8166                           __attribute__((unused)) void *data)
8167 {
8168         struct cmd_tunnel_udp_config *res = parsed_result;
8169         struct rte_eth_udp_tunnel tunnel_udp;
8170         int ret;
8171
8172         tunnel_udp.udp_port = res->udp_port;
8173
8174         if (!strcmp(res->cmd, "rx_vxlan_port"))
8175                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8176
8177         if (!strcmp(res->what, "add"))
8178                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8179                                                       &tunnel_udp);
8180         else
8181                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8182                                                          &tunnel_udp);
8183
8184         if (ret < 0)
8185                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8186 }
8187
8188 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8189         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8190                                 cmd, "rx_vxlan_port");
8191 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8192         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8193                                 what, "add#rm");
8194 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8195         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8196                                 udp_port, UINT16);
8197 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8198         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8199                                 port_id, UINT16);
8200
8201 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8202         .f = cmd_tunnel_udp_config_parsed,
8203         .data = (void *)0,
8204         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8205                 "Add/Remove a tunneling UDP port filter",
8206         .tokens = {
8207                 (void *)&cmd_tunnel_udp_config_cmd,
8208                 (void *)&cmd_tunnel_udp_config_what,
8209                 (void *)&cmd_tunnel_udp_config_udp_port,
8210                 (void *)&cmd_tunnel_udp_config_port_id,
8211                 NULL,
8212         },
8213 };
8214
8215 /* *** GLOBAL CONFIG *** */
8216 struct cmd_global_config_result {
8217         cmdline_fixed_string_t cmd;
8218         portid_t port_id;
8219         cmdline_fixed_string_t cfg_type;
8220         uint8_t len;
8221 };
8222
8223 static void
8224 cmd_global_config_parsed(void *parsed_result,
8225                          __attribute__((unused)) struct cmdline *cl,
8226                          __attribute__((unused)) void *data)
8227 {
8228         struct cmd_global_config_result *res = parsed_result;
8229         struct rte_eth_global_cfg conf;
8230         int ret;
8231
8232         memset(&conf, 0, sizeof(conf));
8233         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8234         conf.cfg.gre_key_len = res->len;
8235         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8236                                       RTE_ETH_FILTER_SET, &conf);
8237         if (ret != 0)
8238                 printf("Global config error\n");
8239 }
8240
8241 cmdline_parse_token_string_t cmd_global_config_cmd =
8242         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8243                 "global_config");
8244 cmdline_parse_token_num_t cmd_global_config_port_id =
8245         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8246                                UINT16);
8247 cmdline_parse_token_string_t cmd_global_config_type =
8248         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8249                 cfg_type, "gre-key-len");
8250 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8251         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8252                 len, UINT8);
8253
8254 cmdline_parse_inst_t cmd_global_config = {
8255         .f = cmd_global_config_parsed,
8256         .data = (void *)NULL,
8257         .help_str = "global_config <port_id> gre-key-len <key_len>",
8258         .tokens = {
8259                 (void *)&cmd_global_config_cmd,
8260                 (void *)&cmd_global_config_port_id,
8261                 (void *)&cmd_global_config_type,
8262                 (void *)&cmd_global_config_gre_key_len,
8263                 NULL,
8264         },
8265 };
8266
8267 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8268 struct cmd_set_mirror_mask_result {
8269         cmdline_fixed_string_t set;
8270         cmdline_fixed_string_t port;
8271         portid_t port_id;
8272         cmdline_fixed_string_t mirror;
8273         uint8_t rule_id;
8274         cmdline_fixed_string_t what;
8275         cmdline_fixed_string_t value;
8276         cmdline_fixed_string_t dstpool;
8277         uint8_t dstpool_id;
8278         cmdline_fixed_string_t on;
8279 };
8280
8281 cmdline_parse_token_string_t cmd_mirror_mask_set =
8282         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8283                                 set, "set");
8284 cmdline_parse_token_string_t cmd_mirror_mask_port =
8285         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8286                                 port, "port");
8287 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8288         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8289                                 port_id, UINT16);
8290 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8291         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8292                                 mirror, "mirror-rule");
8293 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8294         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8295                                 rule_id, UINT8);
8296 cmdline_parse_token_string_t cmd_mirror_mask_what =
8297         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8298                                 what, "pool-mirror-up#pool-mirror-down"
8299                                       "#vlan-mirror");
8300 cmdline_parse_token_string_t cmd_mirror_mask_value =
8301         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8302                                 value, NULL);
8303 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8304         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8305                                 dstpool, "dst-pool");
8306 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8307         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8308                                 dstpool_id, UINT8);
8309 cmdline_parse_token_string_t cmd_mirror_mask_on =
8310         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8311                                 on, "on#off");
8312
8313 static void
8314 cmd_set_mirror_mask_parsed(void *parsed_result,
8315                        __attribute__((unused)) struct cmdline *cl,
8316                        __attribute__((unused)) void *data)
8317 {
8318         int ret,nb_item,i;
8319         struct cmd_set_mirror_mask_result *res = parsed_result;
8320         struct rte_eth_mirror_conf mr_conf;
8321
8322         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8323
8324         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8325
8326         mr_conf.dst_pool = res->dstpool_id;
8327
8328         if (!strcmp(res->what, "pool-mirror-up")) {
8329                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8330                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8331         } else if (!strcmp(res->what, "pool-mirror-down")) {
8332                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8333                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8334         } else if (!strcmp(res->what, "vlan-mirror")) {
8335                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8336                 nb_item = parse_item_list(res->value, "vlan",
8337                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8338                 if (nb_item <= 0)
8339                         return;
8340
8341                 for (i = 0; i < nb_item; i++) {
8342                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8343                                 printf("Invalid vlan_id: must be < 4096\n");
8344                                 return;
8345                         }
8346
8347                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8348                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8349                 }
8350         }
8351
8352         if (!strcmp(res->on, "on"))
8353                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8354                                                 res->rule_id, 1);
8355         else
8356                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8357                                                 res->rule_id, 0);
8358         if (ret < 0)
8359                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8360 }
8361
8362 cmdline_parse_inst_t cmd_set_mirror_mask = {
8363                 .f = cmd_set_mirror_mask_parsed,
8364                 .data = NULL,
8365                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8366                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8367                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8368                 .tokens = {
8369                         (void *)&cmd_mirror_mask_set,
8370                         (void *)&cmd_mirror_mask_port,
8371                         (void *)&cmd_mirror_mask_portid,
8372                         (void *)&cmd_mirror_mask_mirror,
8373                         (void *)&cmd_mirror_mask_ruleid,
8374                         (void *)&cmd_mirror_mask_what,
8375                         (void *)&cmd_mirror_mask_value,
8376                         (void *)&cmd_mirror_mask_dstpool,
8377                         (void *)&cmd_mirror_mask_poolid,
8378                         (void *)&cmd_mirror_mask_on,
8379                         NULL,
8380                 },
8381 };
8382
8383 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8384 struct cmd_set_mirror_link_result {
8385         cmdline_fixed_string_t set;
8386         cmdline_fixed_string_t port;
8387         portid_t port_id;
8388         cmdline_fixed_string_t mirror;
8389         uint8_t rule_id;
8390         cmdline_fixed_string_t what;
8391         cmdline_fixed_string_t dstpool;
8392         uint8_t dstpool_id;
8393         cmdline_fixed_string_t on;
8394 };
8395
8396 cmdline_parse_token_string_t cmd_mirror_link_set =
8397         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8398                                  set, "set");
8399 cmdline_parse_token_string_t cmd_mirror_link_port =
8400         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8401                                 port, "port");
8402 cmdline_parse_token_num_t cmd_mirror_link_portid =
8403         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8404                                 port_id, UINT16);
8405 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8406         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8407                                 mirror, "mirror-rule");
8408 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8409         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8410                             rule_id, UINT8);
8411 cmdline_parse_token_string_t cmd_mirror_link_what =
8412         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8413                                 what, "uplink-mirror#downlink-mirror");
8414 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8415         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8416                                 dstpool, "dst-pool");
8417 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8418         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8419                                 dstpool_id, UINT8);
8420 cmdline_parse_token_string_t cmd_mirror_link_on =
8421         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8422                                 on, "on#off");
8423
8424 static void
8425 cmd_set_mirror_link_parsed(void *parsed_result,
8426                        __attribute__((unused)) struct cmdline *cl,
8427                        __attribute__((unused)) void *data)
8428 {
8429         int ret;
8430         struct cmd_set_mirror_link_result *res = parsed_result;
8431         struct rte_eth_mirror_conf mr_conf;
8432
8433         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8434         if (!strcmp(res->what, "uplink-mirror"))
8435                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8436         else
8437                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8438
8439         mr_conf.dst_pool = res->dstpool_id;
8440
8441         if (!strcmp(res->on, "on"))
8442                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8443                                                 res->rule_id, 1);
8444         else
8445                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8446                                                 res->rule_id, 0);
8447
8448         /* check the return value and print it if is < 0 */
8449         if (ret < 0)
8450                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8451
8452 }
8453
8454 cmdline_parse_inst_t cmd_set_mirror_link = {
8455                 .f = cmd_set_mirror_link_parsed,
8456                 .data = NULL,
8457                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8458                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8459                 .tokens = {
8460                         (void *)&cmd_mirror_link_set,
8461                         (void *)&cmd_mirror_link_port,
8462                         (void *)&cmd_mirror_link_portid,
8463                         (void *)&cmd_mirror_link_mirror,
8464                         (void *)&cmd_mirror_link_ruleid,
8465                         (void *)&cmd_mirror_link_what,
8466                         (void *)&cmd_mirror_link_dstpool,
8467                         (void *)&cmd_mirror_link_poolid,
8468                         (void *)&cmd_mirror_link_on,
8469                         NULL,
8470                 },
8471 };
8472
8473 /* *** RESET VM MIRROR RULE *** */
8474 struct cmd_rm_mirror_rule_result {
8475         cmdline_fixed_string_t reset;
8476         cmdline_fixed_string_t port;
8477         portid_t port_id;
8478         cmdline_fixed_string_t mirror;
8479         uint8_t rule_id;
8480 };
8481
8482 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8483         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8484                                  reset, "reset");
8485 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8486         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8487                                 port, "port");
8488 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8489         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8490                                 port_id, UINT16);
8491 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8492         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8493                                 mirror, "mirror-rule");
8494 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8495         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8496                                 rule_id, UINT8);
8497
8498 static void
8499 cmd_reset_mirror_rule_parsed(void *parsed_result,
8500                        __attribute__((unused)) struct cmdline *cl,
8501                        __attribute__((unused)) void *data)
8502 {
8503         int ret;
8504         struct cmd_set_mirror_link_result *res = parsed_result;
8505         /* check rule_id */
8506         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8507         if(ret < 0)
8508                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8509 }
8510
8511 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8512                 .f = cmd_reset_mirror_rule_parsed,
8513                 .data = NULL,
8514                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8515                 .tokens = {
8516                         (void *)&cmd_rm_mirror_rule_reset,
8517                         (void *)&cmd_rm_mirror_rule_port,
8518                         (void *)&cmd_rm_mirror_rule_portid,
8519                         (void *)&cmd_rm_mirror_rule_mirror,
8520                         (void *)&cmd_rm_mirror_rule_ruleid,
8521                         NULL,
8522                 },
8523 };
8524
8525 /* ******************************************************************************** */
8526
8527 struct cmd_dump_result {
8528         cmdline_fixed_string_t dump;
8529 };
8530
8531 static void
8532 dump_struct_sizes(void)
8533 {
8534 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8535         DUMP_SIZE(struct rte_mbuf);
8536         DUMP_SIZE(struct rte_mempool);
8537         DUMP_SIZE(struct rte_ring);
8538 #undef DUMP_SIZE
8539 }
8540
8541 static void cmd_dump_parsed(void *parsed_result,
8542                             __attribute__((unused)) struct cmdline *cl,
8543                             __attribute__((unused)) void *data)
8544 {
8545         struct cmd_dump_result *res = parsed_result;
8546
8547         if (!strcmp(res->dump, "dump_physmem"))
8548                 rte_dump_physmem_layout(stdout);
8549         else if (!strcmp(res->dump, "dump_memzone"))
8550                 rte_memzone_dump(stdout);
8551         else if (!strcmp(res->dump, "dump_struct_sizes"))
8552                 dump_struct_sizes();
8553         else if (!strcmp(res->dump, "dump_ring"))
8554                 rte_ring_list_dump(stdout);
8555         else if (!strcmp(res->dump, "dump_mempool"))
8556                 rte_mempool_list_dump(stdout);
8557         else if (!strcmp(res->dump, "dump_devargs"))
8558                 rte_eal_devargs_dump(stdout);
8559         else if (!strcmp(res->dump, "dump_log_types"))
8560                 rte_log_dump(stdout);
8561 }
8562
8563 cmdline_parse_token_string_t cmd_dump_dump =
8564         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8565                 "dump_physmem#"
8566                 "dump_memzone#"
8567                 "dump_struct_sizes#"
8568                 "dump_ring#"
8569                 "dump_mempool#"
8570                 "dump_devargs#"
8571                 "dump_log_types");
8572
8573 cmdline_parse_inst_t cmd_dump = {
8574         .f = cmd_dump_parsed,  /* function to call */
8575         .data = NULL,      /* 2nd arg of func */
8576         .help_str = "Dump status",
8577         .tokens = {        /* token list, NULL terminated */
8578                 (void *)&cmd_dump_dump,
8579                 NULL,
8580         },
8581 };
8582
8583 /* ******************************************************************************** */
8584
8585 struct cmd_dump_one_result {
8586         cmdline_fixed_string_t dump;
8587         cmdline_fixed_string_t name;
8588 };
8589
8590 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8591                                 __attribute__((unused)) void *data)
8592 {
8593         struct cmd_dump_one_result *res = parsed_result;
8594
8595         if (!strcmp(res->dump, "dump_ring")) {
8596                 struct rte_ring *r;
8597                 r = rte_ring_lookup(res->name);
8598                 if (r == NULL) {
8599                         cmdline_printf(cl, "Cannot find ring\n");
8600                         return;
8601                 }
8602                 rte_ring_dump(stdout, r);
8603         } else if (!strcmp(res->dump, "dump_mempool")) {
8604                 struct rte_mempool *mp;
8605                 mp = rte_mempool_lookup(res->name);
8606                 if (mp == NULL) {
8607                         cmdline_printf(cl, "Cannot find mempool\n");
8608                         return;
8609                 }
8610                 rte_mempool_dump(stdout, mp);
8611         }
8612 }
8613
8614 cmdline_parse_token_string_t cmd_dump_one_dump =
8615         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8616                                  "dump_ring#dump_mempool");
8617
8618 cmdline_parse_token_string_t cmd_dump_one_name =
8619         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8620
8621 cmdline_parse_inst_t cmd_dump_one = {
8622         .f = cmd_dump_one_parsed,  /* function to call */
8623         .data = NULL,      /* 2nd arg of func */
8624         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8625         .tokens = {        /* token list, NULL terminated */
8626                 (void *)&cmd_dump_one_dump,
8627                 (void *)&cmd_dump_one_name,
8628                 NULL,
8629         },
8630 };
8631
8632 /* *** Add/Del syn filter *** */
8633 struct cmd_syn_filter_result {
8634         cmdline_fixed_string_t filter;
8635         portid_t port_id;
8636         cmdline_fixed_string_t ops;
8637         cmdline_fixed_string_t priority;
8638         cmdline_fixed_string_t high;
8639         cmdline_fixed_string_t queue;
8640         uint16_t queue_id;
8641 };
8642
8643 static void
8644 cmd_syn_filter_parsed(void *parsed_result,
8645                         __attribute__((unused)) struct cmdline *cl,
8646                         __attribute__((unused)) void *data)
8647 {
8648         struct cmd_syn_filter_result *res = parsed_result;
8649         struct rte_eth_syn_filter syn_filter;
8650         int ret = 0;
8651
8652         ret = rte_eth_dev_filter_supported(res->port_id,
8653                                         RTE_ETH_FILTER_SYN);
8654         if (ret < 0) {
8655                 printf("syn filter is not supported on port %u.\n",
8656                                 res->port_id);
8657                 return;
8658         }
8659
8660         memset(&syn_filter, 0, sizeof(syn_filter));
8661
8662         if (!strcmp(res->ops, "add")) {
8663                 if (!strcmp(res->high, "high"))
8664                         syn_filter.hig_pri = 1;
8665                 else
8666                         syn_filter.hig_pri = 0;
8667
8668                 syn_filter.queue = res->queue_id;
8669                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8670                                                 RTE_ETH_FILTER_SYN,
8671                                                 RTE_ETH_FILTER_ADD,
8672                                                 &syn_filter);
8673         } else
8674                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8675                                                 RTE_ETH_FILTER_SYN,
8676                                                 RTE_ETH_FILTER_DELETE,
8677                                                 &syn_filter);
8678
8679         if (ret < 0)
8680                 printf("syn filter programming error: (%s)\n",
8681                                 strerror(-ret));
8682 }
8683
8684 cmdline_parse_token_string_t cmd_syn_filter_filter =
8685         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8686         filter, "syn_filter");
8687 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8688         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8689         port_id, UINT16);
8690 cmdline_parse_token_string_t cmd_syn_filter_ops =
8691         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8692         ops, "add#del");
8693 cmdline_parse_token_string_t cmd_syn_filter_priority =
8694         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8695                                 priority, "priority");
8696 cmdline_parse_token_string_t cmd_syn_filter_high =
8697         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8698                                 high, "high#low");
8699 cmdline_parse_token_string_t cmd_syn_filter_queue =
8700         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8701                                 queue, "queue");
8702 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8703         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8704                                 queue_id, UINT16);
8705
8706 cmdline_parse_inst_t cmd_syn_filter = {
8707         .f = cmd_syn_filter_parsed,
8708         .data = NULL,
8709         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8710                 "<queue_id>: Add/Delete syn filter",
8711         .tokens = {
8712                 (void *)&cmd_syn_filter_filter,
8713                 (void *)&cmd_syn_filter_port_id,
8714                 (void *)&cmd_syn_filter_ops,
8715                 (void *)&cmd_syn_filter_priority,
8716                 (void *)&cmd_syn_filter_high,
8717                 (void *)&cmd_syn_filter_queue,
8718                 (void *)&cmd_syn_filter_queue_id,
8719                 NULL,
8720         },
8721 };
8722
8723 /* *** queue region set *** */
8724 struct cmd_queue_region_result {
8725         cmdline_fixed_string_t set;
8726         cmdline_fixed_string_t port;
8727         portid_t port_id;
8728         cmdline_fixed_string_t cmd;
8729         cmdline_fixed_string_t region;
8730         uint8_t  region_id;
8731         cmdline_fixed_string_t queue_start_index;
8732         uint8_t  queue_id;
8733         cmdline_fixed_string_t queue_num;
8734         uint8_t  queue_num_value;
8735 };
8736
8737 static void
8738 cmd_queue_region_parsed(void *parsed_result,
8739                         __attribute__((unused)) struct cmdline *cl,
8740                         __attribute__((unused)) void *data)
8741 {
8742         struct cmd_queue_region_result *res = parsed_result;
8743         int ret = -ENOTSUP;
8744 #ifdef RTE_LIBRTE_I40E_PMD
8745         struct rte_pmd_i40e_queue_region_conf region_conf;
8746         enum rte_pmd_i40e_queue_region_op op_type;
8747 #endif
8748
8749         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8750                 return;
8751
8752 #ifdef RTE_LIBRTE_I40E_PMD
8753         memset(&region_conf, 0, sizeof(region_conf));
8754         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8755         region_conf.region_id = res->region_id;
8756         region_conf.queue_num = res->queue_num_value;
8757         region_conf.queue_start_index = res->queue_id;
8758
8759         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8760                                 op_type, &region_conf);
8761 #endif
8762
8763         switch (ret) {
8764         case 0:
8765                 break;
8766         case -ENOTSUP:
8767                 printf("function not implemented or supported\n");
8768                 break;
8769         default:
8770                 printf("queue region config error: (%s)\n", strerror(-ret));
8771         }
8772 }
8773
8774 cmdline_parse_token_string_t cmd_queue_region_set =
8775 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8776                 set, "set");
8777 cmdline_parse_token_string_t cmd_queue_region_port =
8778         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8779 cmdline_parse_token_num_t cmd_queue_region_port_id =
8780         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8781                                 port_id, UINT16);
8782 cmdline_parse_token_string_t cmd_queue_region_cmd =
8783         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8784                                  cmd, "queue-region");
8785 cmdline_parse_token_string_t cmd_queue_region_id =
8786         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8787                                 region, "region_id");
8788 cmdline_parse_token_num_t cmd_queue_region_index =
8789         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8790                                 region_id, UINT8);
8791 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8792         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8793                                 queue_start_index, "queue_start_index");
8794 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8795         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8796                                 queue_id, UINT8);
8797 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8798         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8799                                 queue_num, "queue_num");
8800 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8801         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8802                                 queue_num_value, UINT8);
8803
8804 cmdline_parse_inst_t cmd_queue_region = {
8805         .f = cmd_queue_region_parsed,
8806         .data = NULL,
8807         .help_str = "set port <port_id> queue-region region_id <value> "
8808                 "queue_start_index <value> queue_num <value>: Set a queue region",
8809         .tokens = {
8810                 (void *)&cmd_queue_region_set,
8811                 (void *)&cmd_queue_region_port,
8812                 (void *)&cmd_queue_region_port_id,
8813                 (void *)&cmd_queue_region_cmd,
8814                 (void *)&cmd_queue_region_id,
8815                 (void *)&cmd_queue_region_index,
8816                 (void *)&cmd_queue_region_queue_start_index,
8817                 (void *)&cmd_queue_region_queue_id,
8818                 (void *)&cmd_queue_region_queue_num,
8819                 (void *)&cmd_queue_region_queue_num_value,
8820                 NULL,
8821         },
8822 };
8823
8824 /* *** queue region and flowtype set *** */
8825 struct cmd_region_flowtype_result {
8826         cmdline_fixed_string_t set;
8827         cmdline_fixed_string_t port;
8828         portid_t port_id;
8829         cmdline_fixed_string_t cmd;
8830         cmdline_fixed_string_t region;
8831         uint8_t  region_id;
8832         cmdline_fixed_string_t flowtype;
8833         uint8_t  flowtype_id;
8834 };
8835
8836 static void
8837 cmd_region_flowtype_parsed(void *parsed_result,
8838                         __attribute__((unused)) struct cmdline *cl,
8839                         __attribute__((unused)) void *data)
8840 {
8841         struct cmd_region_flowtype_result *res = parsed_result;
8842         int ret = -ENOTSUP;
8843 #ifdef RTE_LIBRTE_I40E_PMD
8844         struct rte_pmd_i40e_queue_region_conf region_conf;
8845         enum rte_pmd_i40e_queue_region_op op_type;
8846 #endif
8847
8848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8849                 return;
8850
8851 #ifdef RTE_LIBRTE_I40E_PMD
8852         memset(&region_conf, 0, sizeof(region_conf));
8853
8854         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8855         region_conf.region_id = res->region_id;
8856         region_conf.hw_flowtype = res->flowtype_id;
8857
8858         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8859                         op_type, &region_conf);
8860 #endif
8861
8862         switch (ret) {
8863         case 0:
8864                 break;
8865         case -ENOTSUP:
8866                 printf("function not implemented or supported\n");
8867                 break;
8868         default:
8869                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8870         }
8871 }
8872
8873 cmdline_parse_token_string_t cmd_region_flowtype_set =
8874 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8875                                 set, "set");
8876 cmdline_parse_token_string_t cmd_region_flowtype_port =
8877         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8878                                 port, "port");
8879 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8880         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8881                                 port_id, UINT16);
8882 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8883         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8884                                 cmd, "queue-region");
8885 cmdline_parse_token_string_t cmd_region_flowtype_index =
8886         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8887                                 region, "region_id");
8888 cmdline_parse_token_num_t cmd_region_flowtype_id =
8889         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8890                                 region_id, UINT8);
8891 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8892         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8893                                 flowtype, "flowtype");
8894 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8895         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8896                                 flowtype_id, UINT8);
8897 cmdline_parse_inst_t cmd_region_flowtype = {
8898         .f = cmd_region_flowtype_parsed,
8899         .data = NULL,
8900         .help_str = "set port <port_id> queue-region region_id <value> "
8901                 "flowtype <value>: Set a flowtype region index",
8902         .tokens = {
8903                 (void *)&cmd_region_flowtype_set,
8904                 (void *)&cmd_region_flowtype_port,
8905                 (void *)&cmd_region_flowtype_port_index,
8906                 (void *)&cmd_region_flowtype_cmd,
8907                 (void *)&cmd_region_flowtype_index,
8908                 (void *)&cmd_region_flowtype_id,
8909                 (void *)&cmd_region_flowtype_flow_index,
8910                 (void *)&cmd_region_flowtype_flow_id,
8911                 NULL,
8912         },
8913 };
8914
8915 /* *** User Priority (UP) to queue region (region_id) set *** */
8916 struct cmd_user_priority_region_result {
8917         cmdline_fixed_string_t set;
8918         cmdline_fixed_string_t port;
8919         portid_t port_id;
8920         cmdline_fixed_string_t cmd;
8921         cmdline_fixed_string_t user_priority;
8922         uint8_t  user_priority_id;
8923         cmdline_fixed_string_t region;
8924         uint8_t  region_id;
8925 };
8926
8927 static void
8928 cmd_user_priority_region_parsed(void *parsed_result,
8929                         __attribute__((unused)) struct cmdline *cl,
8930                         __attribute__((unused)) void *data)
8931 {
8932         struct cmd_user_priority_region_result *res = parsed_result;
8933         int ret = -ENOTSUP;
8934 #ifdef RTE_LIBRTE_I40E_PMD
8935         struct rte_pmd_i40e_queue_region_conf region_conf;
8936         enum rte_pmd_i40e_queue_region_op op_type;
8937 #endif
8938
8939         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8940                 return;
8941
8942 #ifdef RTE_LIBRTE_I40E_PMD
8943         memset(&region_conf, 0, sizeof(region_conf));
8944         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8945         region_conf.user_priority = res->user_priority_id;
8946         region_conf.region_id = res->region_id;
8947
8948         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8949                                 op_type, &region_conf);
8950 #endif
8951
8952         switch (ret) {
8953         case 0:
8954                 break;
8955         case -ENOTSUP:
8956                 printf("function not implemented or supported\n");
8957                 break;
8958         default:
8959                 printf("user_priority region config error: (%s)\n",
8960                                 strerror(-ret));
8961         }
8962 }
8963
8964 cmdline_parse_token_string_t cmd_user_priority_region_set =
8965         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8966                                 set, "set");
8967 cmdline_parse_token_string_t cmd_user_priority_region_port =
8968         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8969                                 port, "port");
8970 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8971         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8972                                 port_id, UINT16);
8973 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8974         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8975                                 cmd, "queue-region");
8976 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8977         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8978                                 user_priority, "UP");
8979 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8980         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8981                                 user_priority_id, UINT8);
8982 cmdline_parse_token_string_t cmd_user_priority_region_region =
8983         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8984                                 region, "region_id");
8985 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8986         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8987                                 region_id, UINT8);
8988
8989 cmdline_parse_inst_t cmd_user_priority_region = {
8990         .f = cmd_user_priority_region_parsed,
8991         .data = NULL,
8992         .help_str = "set port <port_id> queue-region UP <value> "
8993                 "region_id <value>: Set the mapping of User Priority (UP) "
8994                 "to queue region (region_id) ",
8995         .tokens = {
8996                 (void *)&cmd_user_priority_region_set,
8997                 (void *)&cmd_user_priority_region_port,
8998                 (void *)&cmd_user_priority_region_port_index,
8999                 (void *)&cmd_user_priority_region_cmd,
9000                 (void *)&cmd_user_priority_region_UP,
9001                 (void *)&cmd_user_priority_region_UP_id,
9002                 (void *)&cmd_user_priority_region_region,
9003                 (void *)&cmd_user_priority_region_region_id,
9004                 NULL,
9005         },
9006 };
9007
9008 /* *** flush all queue region related configuration *** */
9009 struct cmd_flush_queue_region_result {
9010         cmdline_fixed_string_t set;
9011         cmdline_fixed_string_t port;
9012         portid_t port_id;
9013         cmdline_fixed_string_t cmd;
9014         cmdline_fixed_string_t flush;
9015         cmdline_fixed_string_t what;
9016 };
9017
9018 static void
9019 cmd_flush_queue_region_parsed(void *parsed_result,
9020                         __attribute__((unused)) struct cmdline *cl,
9021                         __attribute__((unused)) void *data)
9022 {
9023         struct cmd_flush_queue_region_result *res = parsed_result;
9024         int ret = -ENOTSUP;
9025 #ifdef RTE_LIBRTE_I40E_PMD
9026         struct rte_pmd_i40e_queue_region_conf region_conf;
9027         enum rte_pmd_i40e_queue_region_op op_type;
9028 #endif
9029
9030         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9031                 return;
9032
9033 #ifdef RTE_LIBRTE_I40E_PMD
9034         memset(&region_conf, 0, sizeof(region_conf));
9035
9036         if (strcmp(res->what, "on") == 0)
9037                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9038         else
9039                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9040
9041         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9042                                 op_type, &region_conf);
9043 #endif
9044
9045         switch (ret) {
9046         case 0:
9047                 break;
9048         case -ENOTSUP:
9049                 printf("function not implemented or supported\n");
9050                 break;
9051         default:
9052                 printf("queue region config flush error: (%s)\n",
9053                                 strerror(-ret));
9054         }
9055 }
9056
9057 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9058         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9059                                 set, "set");
9060 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9061         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9062                                 port, "port");
9063 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9064         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9065                                 port_id, UINT16);
9066 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9067         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9068                                 cmd, "queue-region");
9069 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9070         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9071                                 flush, "flush");
9072 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9073         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9074                                 what, "on#off");
9075
9076 cmdline_parse_inst_t cmd_flush_queue_region = {
9077         .f = cmd_flush_queue_region_parsed,
9078         .data = NULL,
9079         .help_str = "set port <port_id> queue-region flush on|off"
9080                 ": flush all queue region related configuration",
9081         .tokens = {
9082                 (void *)&cmd_flush_queue_region_set,
9083                 (void *)&cmd_flush_queue_region_port,
9084                 (void *)&cmd_flush_queue_region_port_index,
9085                 (void *)&cmd_flush_queue_region_cmd,
9086                 (void *)&cmd_flush_queue_region_flush,
9087                 (void *)&cmd_flush_queue_region_what,
9088                 NULL,
9089         },
9090 };
9091
9092 /* *** get all queue region related configuration info *** */
9093 struct cmd_show_queue_region_info {
9094         cmdline_fixed_string_t show;
9095         cmdline_fixed_string_t port;
9096         portid_t port_id;
9097         cmdline_fixed_string_t cmd;
9098 };
9099
9100 static void
9101 cmd_show_queue_region_info_parsed(void *parsed_result,
9102                         __attribute__((unused)) struct cmdline *cl,
9103                         __attribute__((unused)) void *data)
9104 {
9105         struct cmd_show_queue_region_info *res = parsed_result;
9106         int ret = -ENOTSUP;
9107 #ifdef RTE_LIBRTE_I40E_PMD
9108         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9109         enum rte_pmd_i40e_queue_region_op op_type;
9110 #endif
9111
9112         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9113                 return;
9114
9115 #ifdef RTE_LIBRTE_I40E_PMD
9116         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9117
9118         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9119
9120         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9121                                         op_type, &rte_pmd_regions);
9122
9123         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9124 #endif
9125
9126         switch (ret) {
9127         case 0:
9128                 break;
9129         case -ENOTSUP:
9130                 printf("function not implemented or supported\n");
9131                 break;
9132         default:
9133                 printf("queue region config info show error: (%s)\n",
9134                                 strerror(-ret));
9135         }
9136 }
9137
9138 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9139 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9140                                 show, "show");
9141 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9142         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9143                                 port, "port");
9144 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9145         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9146                                 port_id, UINT16);
9147 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9148         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9149                                 cmd, "queue-region");
9150
9151 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9152         .f = cmd_show_queue_region_info_parsed,
9153         .data = NULL,
9154         .help_str = "show port <port_id> queue-region"
9155                 ": show all queue region related configuration info",
9156         .tokens = {
9157                 (void *)&cmd_show_queue_region_info_get,
9158                 (void *)&cmd_show_queue_region_info_port,
9159                 (void *)&cmd_show_queue_region_info_port_index,
9160                 (void *)&cmd_show_queue_region_info_cmd,
9161                 NULL,
9162         },
9163 };
9164
9165 /* *** ADD/REMOVE A 2tuple FILTER *** */
9166 struct cmd_2tuple_filter_result {
9167         cmdline_fixed_string_t filter;
9168         portid_t port_id;
9169         cmdline_fixed_string_t ops;
9170         cmdline_fixed_string_t dst_port;
9171         uint16_t dst_port_value;
9172         cmdline_fixed_string_t protocol;
9173         uint8_t protocol_value;
9174         cmdline_fixed_string_t mask;
9175         uint8_t  mask_value;
9176         cmdline_fixed_string_t tcp_flags;
9177         uint8_t tcp_flags_value;
9178         cmdline_fixed_string_t priority;
9179         uint8_t  priority_value;
9180         cmdline_fixed_string_t queue;
9181         uint16_t  queue_id;
9182 };
9183
9184 static void
9185 cmd_2tuple_filter_parsed(void *parsed_result,
9186                         __attribute__((unused)) struct cmdline *cl,
9187                         __attribute__((unused)) void *data)
9188 {
9189         struct rte_eth_ntuple_filter filter;
9190         struct cmd_2tuple_filter_result *res = parsed_result;
9191         int ret = 0;
9192
9193         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9194         if (ret < 0) {
9195                 printf("ntuple filter is not supported on port %u.\n",
9196                         res->port_id);
9197                 return;
9198         }
9199
9200         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9201
9202         filter.flags = RTE_2TUPLE_FLAGS;
9203         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9204         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9205         filter.proto = res->protocol_value;
9206         filter.priority = res->priority_value;
9207         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9208                 printf("nonzero tcp_flags is only meaningful"
9209                         " when protocol is TCP.\n");
9210                 return;
9211         }
9212         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9213                 printf("invalid TCP flags.\n");
9214                 return;
9215         }
9216
9217         if (res->tcp_flags_value != 0) {
9218                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9219                 filter.tcp_flags = res->tcp_flags_value;
9220         }
9221
9222         /* need convert to big endian. */
9223         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9224         filter.queue = res->queue_id;
9225
9226         if (!strcmp(res->ops, "add"))
9227                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9228                                 RTE_ETH_FILTER_NTUPLE,
9229                                 RTE_ETH_FILTER_ADD,
9230                                 &filter);
9231         else
9232                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9233                                 RTE_ETH_FILTER_NTUPLE,
9234                                 RTE_ETH_FILTER_DELETE,
9235                                 &filter);
9236         if (ret < 0)
9237                 printf("2tuple filter programming error: (%s)\n",
9238                         strerror(-ret));
9239
9240 }
9241
9242 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9243         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9244                                  filter, "2tuple_filter");
9245 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9246         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9247                                 port_id, UINT16);
9248 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9249         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9250                                  ops, "add#del");
9251 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9252         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9253                                 dst_port, "dst_port");
9254 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9255         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9256                                 dst_port_value, UINT16);
9257 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9258         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9259                                 protocol, "protocol");
9260 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9261         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9262                                 protocol_value, UINT8);
9263 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9264         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9265                                 mask, "mask");
9266 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9267         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9268                                 mask_value, INT8);
9269 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9270         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9271                                 tcp_flags, "tcp_flags");
9272 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9273         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9274                                 tcp_flags_value, UINT8);
9275 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9276         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9277                                 priority, "priority");
9278 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9279         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9280                                 priority_value, UINT8);
9281 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9282         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9283                                 queue, "queue");
9284 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9285         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9286                                 queue_id, UINT16);
9287
9288 cmdline_parse_inst_t cmd_2tuple_filter = {
9289         .f = cmd_2tuple_filter_parsed,
9290         .data = NULL,
9291         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9292                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9293                 "<queue_id>: Add a 2tuple filter",
9294         .tokens = {
9295                 (void *)&cmd_2tuple_filter_filter,
9296                 (void *)&cmd_2tuple_filter_port_id,
9297                 (void *)&cmd_2tuple_filter_ops,
9298                 (void *)&cmd_2tuple_filter_dst_port,
9299                 (void *)&cmd_2tuple_filter_dst_port_value,
9300                 (void *)&cmd_2tuple_filter_protocol,
9301                 (void *)&cmd_2tuple_filter_protocol_value,
9302                 (void *)&cmd_2tuple_filter_mask,
9303                 (void *)&cmd_2tuple_filter_mask_value,
9304                 (void *)&cmd_2tuple_filter_tcp_flags,
9305                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9306                 (void *)&cmd_2tuple_filter_priority,
9307                 (void *)&cmd_2tuple_filter_priority_value,
9308                 (void *)&cmd_2tuple_filter_queue,
9309                 (void *)&cmd_2tuple_filter_queue_id,
9310                 NULL,
9311         },
9312 };
9313
9314 /* *** ADD/REMOVE A 5tuple FILTER *** */
9315 struct cmd_5tuple_filter_result {
9316         cmdline_fixed_string_t filter;
9317         portid_t port_id;
9318         cmdline_fixed_string_t ops;
9319         cmdline_fixed_string_t dst_ip;
9320         cmdline_ipaddr_t dst_ip_value;
9321         cmdline_fixed_string_t src_ip;
9322         cmdline_ipaddr_t src_ip_value;
9323         cmdline_fixed_string_t dst_port;
9324         uint16_t dst_port_value;
9325         cmdline_fixed_string_t src_port;
9326         uint16_t src_port_value;
9327         cmdline_fixed_string_t protocol;
9328         uint8_t protocol_value;
9329         cmdline_fixed_string_t mask;
9330         uint8_t  mask_value;
9331         cmdline_fixed_string_t tcp_flags;
9332         uint8_t tcp_flags_value;
9333         cmdline_fixed_string_t priority;
9334         uint8_t  priority_value;
9335         cmdline_fixed_string_t queue;
9336         uint16_t  queue_id;
9337 };
9338
9339 static void
9340 cmd_5tuple_filter_parsed(void *parsed_result,
9341                         __attribute__((unused)) struct cmdline *cl,
9342                         __attribute__((unused)) void *data)
9343 {
9344         struct rte_eth_ntuple_filter filter;
9345         struct cmd_5tuple_filter_result *res = parsed_result;
9346         int ret = 0;
9347
9348         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9349         if (ret < 0) {
9350                 printf("ntuple filter is not supported on port %u.\n",
9351                         res->port_id);
9352                 return;
9353         }
9354
9355         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9356
9357         filter.flags = RTE_5TUPLE_FLAGS;
9358         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9359         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9360         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9361         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9362         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9363         filter.proto = res->protocol_value;
9364         filter.priority = res->priority_value;
9365         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9366                 printf("nonzero tcp_flags is only meaningful"
9367                         " when protocol is TCP.\n");
9368                 return;
9369         }
9370         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9371                 printf("invalid TCP flags.\n");
9372                 return;
9373         }
9374
9375         if (res->tcp_flags_value != 0) {
9376                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9377                 filter.tcp_flags = res->tcp_flags_value;
9378         }
9379
9380         if (res->dst_ip_value.family == AF_INET)
9381                 /* no need to convert, already big endian. */
9382                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9383         else {
9384                 if (filter.dst_ip_mask == 0) {
9385                         printf("can not support ipv6 involved compare.\n");
9386                         return;
9387                 }
9388                 filter.dst_ip = 0;
9389         }
9390
9391         if (res->src_ip_value.family == AF_INET)
9392                 /* no need to convert, already big endian. */
9393                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9394         else {
9395                 if (filter.src_ip_mask == 0) {
9396                         printf("can not support ipv6 involved compare.\n");
9397                         return;
9398                 }
9399                 filter.src_ip = 0;
9400         }
9401         /* need convert to big endian. */
9402         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9403         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9404         filter.queue = res->queue_id;
9405
9406         if (!strcmp(res->ops, "add"))
9407                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9408                                 RTE_ETH_FILTER_NTUPLE,
9409                                 RTE_ETH_FILTER_ADD,
9410                                 &filter);
9411         else
9412                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9413                                 RTE_ETH_FILTER_NTUPLE,
9414                                 RTE_ETH_FILTER_DELETE,
9415                                 &filter);
9416         if (ret < 0)
9417                 printf("5tuple filter programming error: (%s)\n",
9418                         strerror(-ret));
9419 }
9420
9421 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9422         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9423                                  filter, "5tuple_filter");
9424 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9425         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9426                                 port_id, UINT16);
9427 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9428         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9429                                  ops, "add#del");
9430 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9431         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9432                                 dst_ip, "dst_ip");
9433 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9434         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9435                                 dst_ip_value);
9436 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9437         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9438                                 src_ip, "src_ip");
9439 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9440         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9441                                 src_ip_value);
9442 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9443         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9444                                 dst_port, "dst_port");
9445 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9446         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9447                                 dst_port_value, UINT16);
9448 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9449         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9450                                 src_port, "src_port");
9451 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9452         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9453                                 src_port_value, UINT16);
9454 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9455         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9456                                 protocol, "protocol");
9457 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9458         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9459                                 protocol_value, UINT8);
9460 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9461         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9462                                 mask, "mask");
9463 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9464         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9465                                 mask_value, INT8);
9466 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9467         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9468                                 tcp_flags, "tcp_flags");
9469 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9470         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9471                                 tcp_flags_value, UINT8);
9472 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9473         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9474                                 priority, "priority");
9475 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9476         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9477                                 priority_value, UINT8);
9478 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9479         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9480                                 queue, "queue");
9481 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9482         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9483                                 queue_id, UINT16);
9484
9485 cmdline_parse_inst_t cmd_5tuple_filter = {
9486         .f = cmd_5tuple_filter_parsed,
9487         .data = NULL,
9488         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9489                 "src_ip <value> dst_port <value> src_port <value> "
9490                 "protocol <value>  mask <value> tcp_flags <value> "
9491                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9492         .tokens = {
9493                 (void *)&cmd_5tuple_filter_filter,
9494                 (void *)&cmd_5tuple_filter_port_id,
9495                 (void *)&cmd_5tuple_filter_ops,
9496                 (void *)&cmd_5tuple_filter_dst_ip,
9497                 (void *)&cmd_5tuple_filter_dst_ip_value,
9498                 (void *)&cmd_5tuple_filter_src_ip,
9499                 (void *)&cmd_5tuple_filter_src_ip_value,
9500                 (void *)&cmd_5tuple_filter_dst_port,
9501                 (void *)&cmd_5tuple_filter_dst_port_value,
9502                 (void *)&cmd_5tuple_filter_src_port,
9503                 (void *)&cmd_5tuple_filter_src_port_value,
9504                 (void *)&cmd_5tuple_filter_protocol,
9505                 (void *)&cmd_5tuple_filter_protocol_value,
9506                 (void *)&cmd_5tuple_filter_mask,
9507                 (void *)&cmd_5tuple_filter_mask_value,
9508                 (void *)&cmd_5tuple_filter_tcp_flags,
9509                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9510                 (void *)&cmd_5tuple_filter_priority,
9511                 (void *)&cmd_5tuple_filter_priority_value,
9512                 (void *)&cmd_5tuple_filter_queue,
9513                 (void *)&cmd_5tuple_filter_queue_id,
9514                 NULL,
9515         },
9516 };
9517
9518 /* *** ADD/REMOVE A flex FILTER *** */
9519 struct cmd_flex_filter_result {
9520         cmdline_fixed_string_t filter;
9521         cmdline_fixed_string_t ops;
9522         portid_t port_id;
9523         cmdline_fixed_string_t len;
9524         uint8_t len_value;
9525         cmdline_fixed_string_t bytes;
9526         cmdline_fixed_string_t bytes_value;
9527         cmdline_fixed_string_t mask;
9528         cmdline_fixed_string_t mask_value;
9529         cmdline_fixed_string_t priority;
9530         uint8_t priority_value;
9531         cmdline_fixed_string_t queue;
9532         uint16_t queue_id;
9533 };
9534
9535 static int xdigit2val(unsigned char c)
9536 {
9537         int val;
9538         if (isdigit(c))
9539                 val = c - '0';
9540         else if (isupper(c))
9541                 val = c - 'A' + 10;
9542         else
9543                 val = c - 'a' + 10;
9544         return val;
9545 }
9546
9547 static void
9548 cmd_flex_filter_parsed(void *parsed_result,
9549                           __attribute__((unused)) struct cmdline *cl,
9550                           __attribute__((unused)) void *data)
9551 {
9552         int ret = 0;
9553         struct rte_eth_flex_filter filter;
9554         struct cmd_flex_filter_result *res = parsed_result;
9555         char *bytes_ptr, *mask_ptr;
9556         uint16_t len, i, j = 0;
9557         char c;
9558         int val;
9559         uint8_t byte = 0;
9560
9561         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9562                 printf("the len exceed the max length 128\n");
9563                 return;
9564         }
9565         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9566         filter.len = res->len_value;
9567         filter.priority = res->priority_value;
9568         filter.queue = res->queue_id;
9569         bytes_ptr = res->bytes_value;
9570         mask_ptr = res->mask_value;
9571
9572          /* translate bytes string to array. */
9573         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9574                 (bytes_ptr[1] == 'X')))
9575                 bytes_ptr += 2;
9576         len = strnlen(bytes_ptr, res->len_value * 2);
9577         if (len == 0 || (len % 8 != 0)) {
9578                 printf("please check len and bytes input\n");
9579                 return;
9580         }
9581         for (i = 0; i < len; i++) {
9582                 c = bytes_ptr[i];
9583                 if (isxdigit(c) == 0) {
9584                         /* invalid characters. */
9585                         printf("invalid input\n");
9586                         return;
9587                 }
9588                 val = xdigit2val(c);
9589                 if (i % 2) {
9590                         byte |= val;
9591                         filter.bytes[j] = byte;
9592                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9593                         j++;
9594                         byte = 0;
9595                 } else
9596                         byte |= val << 4;
9597         }
9598         printf("\n");
9599          /* translate mask string to uint8_t array. */
9600         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9601                 (mask_ptr[1] == 'X')))
9602                 mask_ptr += 2;
9603         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9604         if (len == 0) {
9605                 printf("invalid input\n");
9606                 return;
9607         }
9608         j = 0;
9609         byte = 0;
9610         for (i = 0; i < len; i++) {
9611                 c = mask_ptr[i];
9612                 if (isxdigit(c) == 0) {
9613                         /* invalid characters. */
9614                         printf("invalid input\n");
9615                         return;
9616                 }
9617                 val = xdigit2val(c);
9618                 if (i % 2) {
9619                         byte |= val;
9620                         filter.mask[j] = byte;
9621                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9622                         j++;
9623                         byte = 0;
9624                 } else
9625                         byte |= val << 4;
9626         }
9627         printf("\n");
9628
9629         if (!strcmp(res->ops, "add"))
9630                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9631                                 RTE_ETH_FILTER_FLEXIBLE,
9632                                 RTE_ETH_FILTER_ADD,
9633                                 &filter);
9634         else
9635                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9636                                 RTE_ETH_FILTER_FLEXIBLE,
9637                                 RTE_ETH_FILTER_DELETE,
9638                                 &filter);
9639
9640         if (ret < 0)
9641                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9642 }
9643
9644 cmdline_parse_token_string_t cmd_flex_filter_filter =
9645         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9646                                 filter, "flex_filter");
9647 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9648         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9649                                 port_id, UINT16);
9650 cmdline_parse_token_string_t cmd_flex_filter_ops =
9651         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9652                                 ops, "add#del");
9653 cmdline_parse_token_string_t cmd_flex_filter_len =
9654         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9655                                 len, "len");
9656 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9657         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9658                                 len_value, UINT8);
9659 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9660         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9661                                 bytes, "bytes");
9662 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9663         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9664                                 bytes_value, NULL);
9665 cmdline_parse_token_string_t cmd_flex_filter_mask =
9666         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9667                                 mask, "mask");
9668 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9669         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9670                                 mask_value, NULL);
9671 cmdline_parse_token_string_t cmd_flex_filter_priority =
9672         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9673                                 priority, "priority");
9674 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9675         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9676                                 priority_value, UINT8);
9677 cmdline_parse_token_string_t cmd_flex_filter_queue =
9678         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9679                                 queue, "queue");
9680 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9681         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9682                                 queue_id, UINT16);
9683 cmdline_parse_inst_t cmd_flex_filter = {
9684         .f = cmd_flex_filter_parsed,
9685         .data = NULL,
9686         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9687                 "<value> mask <value> priority <value> queue <queue_id>: "
9688                 "Add/Del a flex filter",
9689         .tokens = {
9690                 (void *)&cmd_flex_filter_filter,
9691                 (void *)&cmd_flex_filter_port_id,
9692                 (void *)&cmd_flex_filter_ops,
9693                 (void *)&cmd_flex_filter_len,
9694                 (void *)&cmd_flex_filter_len_value,
9695                 (void *)&cmd_flex_filter_bytes,
9696                 (void *)&cmd_flex_filter_bytes_value,
9697                 (void *)&cmd_flex_filter_mask,
9698                 (void *)&cmd_flex_filter_mask_value,
9699                 (void *)&cmd_flex_filter_priority,
9700                 (void *)&cmd_flex_filter_priority_value,
9701                 (void *)&cmd_flex_filter_queue,
9702                 (void *)&cmd_flex_filter_queue_id,
9703                 NULL,
9704         },
9705 };
9706
9707 /* *** Filters Control *** */
9708
9709 /* *** deal with ethertype filter *** */
9710 struct cmd_ethertype_filter_result {
9711         cmdline_fixed_string_t filter;
9712         portid_t port_id;
9713         cmdline_fixed_string_t ops;
9714         cmdline_fixed_string_t mac;
9715         struct ether_addr mac_addr;
9716         cmdline_fixed_string_t ethertype;
9717         uint16_t ethertype_value;
9718         cmdline_fixed_string_t drop;
9719         cmdline_fixed_string_t queue;
9720         uint16_t  queue_id;
9721 };
9722
9723 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9724         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9725                                  filter, "ethertype_filter");
9726 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9727         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9728                               port_id, UINT16);
9729 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9730         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9731                                  ops, "add#del");
9732 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9733         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9734                                  mac, "mac_addr#mac_ignr");
9735 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9736         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9737                                      mac_addr);
9738 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9739         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9740                                  ethertype, "ethertype");
9741 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9742         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9743                               ethertype_value, UINT16);
9744 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9745         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9746                                  drop, "drop#fwd");
9747 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9748         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9749                                  queue, "queue");
9750 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9751         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9752                               queue_id, UINT16);
9753
9754 static void
9755 cmd_ethertype_filter_parsed(void *parsed_result,
9756                           __attribute__((unused)) struct cmdline *cl,
9757                           __attribute__((unused)) void *data)
9758 {
9759         struct cmd_ethertype_filter_result *res = parsed_result;
9760         struct rte_eth_ethertype_filter filter;
9761         int ret = 0;
9762
9763         ret = rte_eth_dev_filter_supported(res->port_id,
9764                         RTE_ETH_FILTER_ETHERTYPE);
9765         if (ret < 0) {
9766                 printf("ethertype filter is not supported on port %u.\n",
9767                         res->port_id);
9768                 return;
9769         }
9770
9771         memset(&filter, 0, sizeof(filter));
9772         if (!strcmp(res->mac, "mac_addr")) {
9773                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9774                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9775                         sizeof(struct ether_addr));
9776         }
9777         if (!strcmp(res->drop, "drop"))
9778                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9779         filter.ether_type = res->ethertype_value;
9780         filter.queue = res->queue_id;
9781
9782         if (!strcmp(res->ops, "add"))
9783                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9784                                 RTE_ETH_FILTER_ETHERTYPE,
9785                                 RTE_ETH_FILTER_ADD,
9786                                 &filter);
9787         else
9788                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9789                                 RTE_ETH_FILTER_ETHERTYPE,
9790                                 RTE_ETH_FILTER_DELETE,
9791                                 &filter);
9792         if (ret < 0)
9793                 printf("ethertype filter programming error: (%s)\n",
9794                         strerror(-ret));
9795 }
9796
9797 cmdline_parse_inst_t cmd_ethertype_filter = {
9798         .f = cmd_ethertype_filter_parsed,
9799         .data = NULL,
9800         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9801                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9802                 "Add or delete an ethertype filter entry",
9803         .tokens = {
9804                 (void *)&cmd_ethertype_filter_filter,
9805                 (void *)&cmd_ethertype_filter_port_id,
9806                 (void *)&cmd_ethertype_filter_ops,
9807                 (void *)&cmd_ethertype_filter_mac,
9808                 (void *)&cmd_ethertype_filter_mac_addr,
9809                 (void *)&cmd_ethertype_filter_ethertype,
9810                 (void *)&cmd_ethertype_filter_ethertype_value,
9811                 (void *)&cmd_ethertype_filter_drop,
9812                 (void *)&cmd_ethertype_filter_queue,
9813                 (void *)&cmd_ethertype_filter_queue_id,
9814                 NULL,
9815         },
9816 };
9817
9818 /* *** deal with flow director filter *** */
9819 struct cmd_flow_director_result {
9820         cmdline_fixed_string_t flow_director_filter;
9821         portid_t port_id;
9822         cmdline_fixed_string_t mode;
9823         cmdline_fixed_string_t mode_value;
9824         cmdline_fixed_string_t ops;
9825         cmdline_fixed_string_t flow;
9826         cmdline_fixed_string_t flow_type;
9827         cmdline_fixed_string_t ether;
9828         uint16_t ether_type;
9829         cmdline_fixed_string_t src;
9830         cmdline_ipaddr_t ip_src;
9831         uint16_t port_src;
9832         cmdline_fixed_string_t dst;
9833         cmdline_ipaddr_t ip_dst;
9834         uint16_t port_dst;
9835         cmdline_fixed_string_t verify_tag;
9836         uint32_t verify_tag_value;
9837         cmdline_ipaddr_t tos;
9838         uint8_t tos_value;
9839         cmdline_ipaddr_t proto;
9840         uint8_t proto_value;
9841         cmdline_ipaddr_t ttl;
9842         uint8_t ttl_value;
9843         cmdline_fixed_string_t vlan;
9844         uint16_t vlan_value;
9845         cmdline_fixed_string_t flexbytes;
9846         cmdline_fixed_string_t flexbytes_value;
9847         cmdline_fixed_string_t pf_vf;
9848         cmdline_fixed_string_t drop;
9849         cmdline_fixed_string_t queue;
9850         uint16_t  queue_id;
9851         cmdline_fixed_string_t fd_id;
9852         uint32_t  fd_id_value;
9853         cmdline_fixed_string_t mac;
9854         struct ether_addr mac_addr;
9855         cmdline_fixed_string_t tunnel;
9856         cmdline_fixed_string_t tunnel_type;
9857         cmdline_fixed_string_t tunnel_id;
9858         uint32_t tunnel_id_value;
9859 };
9860
9861 static inline int
9862 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9863 {
9864         char s[256];
9865         const char *p, *p0 = q_arg;
9866         char *end;
9867         unsigned long int_fld;
9868         char *str_fld[max_num];
9869         int i;
9870         unsigned size;
9871         int ret = -1;
9872
9873         p = strchr(p0, '(');
9874         if (p == NULL)
9875                 return -1;
9876         ++p;
9877         p0 = strchr(p, ')');
9878         if (p0 == NULL)
9879                 return -1;
9880
9881         size = p0 - p;
9882         if (size >= sizeof(s))
9883                 return -1;
9884
9885         snprintf(s, sizeof(s), "%.*s", size, p);
9886         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9887         if (ret < 0 || ret > max_num)
9888                 return -1;
9889         for (i = 0; i < ret; i++) {
9890                 errno = 0;
9891                 int_fld = strtoul(str_fld[i], &end, 0);
9892                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9893                         return -1;
9894                 flexbytes[i] = (uint8_t)int_fld;
9895         }
9896         return ret;
9897 }
9898
9899 static uint16_t
9900 str2flowtype(char *string)
9901 {
9902         uint8_t i = 0;
9903         static const struct {
9904                 char str[32];
9905                 uint16_t type;
9906         } flowtype_str[] = {
9907                 {"raw", RTE_ETH_FLOW_RAW},
9908                 {"ipv4", RTE_ETH_FLOW_IPV4},
9909                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9910                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9911                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9912                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9913                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9914                 {"ipv6", RTE_ETH_FLOW_IPV6},
9915                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9916                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9917                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9918                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9919                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9920                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9921         };
9922
9923         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9924                 if (!strcmp(flowtype_str[i].str, string))
9925                         return flowtype_str[i].type;
9926         }
9927
9928         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9929                 return (uint16_t)atoi(string);
9930
9931         return RTE_ETH_FLOW_UNKNOWN;
9932 }
9933
9934 static enum rte_eth_fdir_tunnel_type
9935 str2fdir_tunneltype(char *string)
9936 {
9937         uint8_t i = 0;
9938
9939         static const struct {
9940                 char str[32];
9941                 enum rte_eth_fdir_tunnel_type type;
9942         } tunneltype_str[] = {
9943                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9944                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9945         };
9946
9947         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9948                 if (!strcmp(tunneltype_str[i].str, string))
9949                         return tunneltype_str[i].type;
9950         }
9951         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9952 }
9953
9954 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9955 do { \
9956         if ((ip_addr).family == AF_INET) \
9957                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9958         else { \
9959                 printf("invalid parameter.\n"); \
9960                 return; \
9961         } \
9962 } while (0)
9963
9964 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9965 do { \
9966         if ((ip_addr).family == AF_INET6) \
9967                 rte_memcpy(&(ip), \
9968                                  &((ip_addr).addr.ipv6), \
9969                                  sizeof(struct in6_addr)); \
9970         else { \
9971                 printf("invalid parameter.\n"); \
9972                 return; \
9973         } \
9974 } while (0)
9975
9976 static void
9977 cmd_flow_director_filter_parsed(void *parsed_result,
9978                           __attribute__((unused)) struct cmdline *cl,
9979                           __attribute__((unused)) void *data)
9980 {
9981         struct cmd_flow_director_result *res = parsed_result;
9982         struct rte_eth_fdir_filter entry;
9983         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9984         char *end;
9985         unsigned long vf_id;
9986         int ret = 0;
9987
9988         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9989         if (ret < 0) {
9990                 printf("flow director is not supported on port %u.\n",
9991                         res->port_id);
9992                 return;
9993         }
9994         memset(flexbytes, 0, sizeof(flexbytes));
9995         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9996
9997         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9998                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9999                         printf("Please set mode to MAC-VLAN.\n");
10000                         return;
10001                 }
10002         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10003                 if (strcmp(res->mode_value, "Tunnel")) {
10004                         printf("Please set mode to Tunnel.\n");
10005                         return;
10006                 }
10007         } else {
10008                 if (strcmp(res->mode_value, "IP")) {
10009                         printf("Please set mode to IP.\n");
10010                         return;
10011                 }
10012                 entry.input.flow_type = str2flowtype(res->flow_type);
10013         }
10014
10015         ret = parse_flexbytes(res->flexbytes_value,
10016                                         flexbytes,
10017                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10018         if (ret < 0) {
10019                 printf("error: Cannot parse flexbytes input.\n");
10020                 return;
10021         }
10022
10023         switch (entry.input.flow_type) {
10024         case RTE_ETH_FLOW_FRAG_IPV4:
10025         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10026                 entry.input.flow.ip4_flow.proto = res->proto_value;
10027                 /* fall-through */
10028         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10029         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10030                 IPV4_ADDR_TO_UINT(res->ip_dst,
10031                         entry.input.flow.ip4_flow.dst_ip);
10032                 IPV4_ADDR_TO_UINT(res->ip_src,
10033                         entry.input.flow.ip4_flow.src_ip);
10034                 entry.input.flow.ip4_flow.tos = res->tos_value;
10035                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10036                 /* need convert to big endian. */
10037                 entry.input.flow.udp4_flow.dst_port =
10038                                 rte_cpu_to_be_16(res->port_dst);
10039                 entry.input.flow.udp4_flow.src_port =
10040                                 rte_cpu_to_be_16(res->port_src);
10041                 break;
10042         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10043                 IPV4_ADDR_TO_UINT(res->ip_dst,
10044                         entry.input.flow.sctp4_flow.ip.dst_ip);
10045                 IPV4_ADDR_TO_UINT(res->ip_src,
10046                         entry.input.flow.sctp4_flow.ip.src_ip);
10047                 entry.input.flow.ip4_flow.tos = res->tos_value;
10048                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10049                 /* need convert to big endian. */
10050                 entry.input.flow.sctp4_flow.dst_port =
10051                                 rte_cpu_to_be_16(res->port_dst);
10052                 entry.input.flow.sctp4_flow.src_port =
10053                                 rte_cpu_to_be_16(res->port_src);
10054                 entry.input.flow.sctp4_flow.verify_tag =
10055                                 rte_cpu_to_be_32(res->verify_tag_value);
10056                 break;
10057         case RTE_ETH_FLOW_FRAG_IPV6:
10058         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10059                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10060                 /* fall-through */
10061         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10062         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10063                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10064                         entry.input.flow.ipv6_flow.dst_ip);
10065                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10066                         entry.input.flow.ipv6_flow.src_ip);
10067                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10068                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10069                 /* need convert to big endian. */
10070                 entry.input.flow.udp6_flow.dst_port =
10071                                 rte_cpu_to_be_16(res->port_dst);
10072                 entry.input.flow.udp6_flow.src_port =
10073                                 rte_cpu_to_be_16(res->port_src);
10074                 break;
10075         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10076                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10077                         entry.input.flow.sctp6_flow.ip.dst_ip);
10078                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10079                         entry.input.flow.sctp6_flow.ip.src_ip);
10080                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10081                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10082                 /* need convert to big endian. */
10083                 entry.input.flow.sctp6_flow.dst_port =
10084                                 rte_cpu_to_be_16(res->port_dst);
10085                 entry.input.flow.sctp6_flow.src_port =
10086                                 rte_cpu_to_be_16(res->port_src);
10087                 entry.input.flow.sctp6_flow.verify_tag =
10088                                 rte_cpu_to_be_32(res->verify_tag_value);
10089                 break;
10090         case RTE_ETH_FLOW_L2_PAYLOAD:
10091                 entry.input.flow.l2_flow.ether_type =
10092                         rte_cpu_to_be_16(res->ether_type);
10093                 break;
10094         default:
10095                 break;
10096         }
10097
10098         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10099                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10100                                  &res->mac_addr,
10101                                  sizeof(struct ether_addr));
10102
10103         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10104                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10105                                  &res->mac_addr,
10106                                  sizeof(struct ether_addr));
10107                 entry.input.flow.tunnel_flow.tunnel_type =
10108                         str2fdir_tunneltype(res->tunnel_type);
10109                 entry.input.flow.tunnel_flow.tunnel_id =
10110                         rte_cpu_to_be_32(res->tunnel_id_value);
10111         }
10112
10113         rte_memcpy(entry.input.flow_ext.flexbytes,
10114                    flexbytes,
10115                    RTE_ETH_FDIR_MAX_FLEXLEN);
10116
10117         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10118
10119         entry.action.flex_off = 0;  /*use 0 by default */
10120         if (!strcmp(res->drop, "drop"))
10121                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10122         else
10123                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10124
10125         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10126             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10127                 if (!strcmp(res->pf_vf, "pf"))
10128                         entry.input.flow_ext.is_vf = 0;
10129                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10130                         struct rte_eth_dev_info dev_info;
10131
10132                         memset(&dev_info, 0, sizeof(dev_info));
10133                         rte_eth_dev_info_get(res->port_id, &dev_info);
10134                         errno = 0;
10135                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10136                         if (errno != 0 || *end != '\0' ||
10137                             vf_id >= dev_info.max_vfs) {
10138                                 printf("invalid parameter %s.\n", res->pf_vf);
10139                                 return;
10140                         }
10141                         entry.input.flow_ext.is_vf = 1;
10142                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10143                 } else {
10144                         printf("invalid parameter %s.\n", res->pf_vf);
10145                         return;
10146                 }
10147         }
10148
10149         /* set to report FD ID by default */
10150         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10151         entry.action.rx_queue = res->queue_id;
10152         entry.soft_id = res->fd_id_value;
10153         if (!strcmp(res->ops, "add"))
10154                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10155                                              RTE_ETH_FILTER_ADD, &entry);
10156         else if (!strcmp(res->ops, "del"))
10157                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10158                                              RTE_ETH_FILTER_DELETE, &entry);
10159         else
10160                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10161                                              RTE_ETH_FILTER_UPDATE, &entry);
10162         if (ret < 0)
10163                 printf("flow director programming error: (%s)\n",
10164                         strerror(-ret));
10165 }
10166
10167 cmdline_parse_token_string_t cmd_flow_director_filter =
10168         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10169                                  flow_director_filter, "flow_director_filter");
10170 cmdline_parse_token_num_t cmd_flow_director_port_id =
10171         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10172                               port_id, UINT16);
10173 cmdline_parse_token_string_t cmd_flow_director_ops =
10174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10175                                  ops, "add#del#update");
10176 cmdline_parse_token_string_t cmd_flow_director_flow =
10177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10178                                  flow, "flow");
10179 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10181                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10182                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10183 cmdline_parse_token_string_t cmd_flow_director_ether =
10184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10185                                  ether, "ether");
10186 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10187         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10188                               ether_type, UINT16);
10189 cmdline_parse_token_string_t cmd_flow_director_src =
10190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10191                                  src, "src");
10192 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10193         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10194                                  ip_src);
10195 cmdline_parse_token_num_t cmd_flow_director_port_src =
10196         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10197                               port_src, UINT16);
10198 cmdline_parse_token_string_t cmd_flow_director_dst =
10199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10200                                  dst, "dst");
10201 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10202         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10203                                  ip_dst);
10204 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10205         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10206                               port_dst, UINT16);
10207 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10209                                   verify_tag, "verify_tag");
10210 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10211         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10212                               verify_tag_value, UINT32);
10213 cmdline_parse_token_string_t cmd_flow_director_tos =
10214         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10215                                  tos, "tos");
10216 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10217         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10218                               tos_value, UINT8);
10219 cmdline_parse_token_string_t cmd_flow_director_proto =
10220         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10221                                  proto, "proto");
10222 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10223         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10224                               proto_value, UINT8);
10225 cmdline_parse_token_string_t cmd_flow_director_ttl =
10226         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10227                                  ttl, "ttl");
10228 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10229         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10230                               ttl_value, UINT8);
10231 cmdline_parse_token_string_t cmd_flow_director_vlan =
10232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10233                                  vlan, "vlan");
10234 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10235         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10236                               vlan_value, UINT16);
10237 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10239                                  flexbytes, "flexbytes");
10240 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10242                               flexbytes_value, NULL);
10243 cmdline_parse_token_string_t cmd_flow_director_drop =
10244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10245                                  drop, "drop#fwd");
10246 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10248                               pf_vf, NULL);
10249 cmdline_parse_token_string_t cmd_flow_director_queue =
10250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10251                                  queue, "queue");
10252 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10253         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10254                               queue_id, UINT16);
10255 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10256         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10257                                  fd_id, "fd_id");
10258 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10259         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10260                               fd_id_value, UINT32);
10261
10262 cmdline_parse_token_string_t cmd_flow_director_mode =
10263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10264                                  mode, "mode");
10265 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10267                                  mode_value, "IP");
10268 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10270                                  mode_value, "MAC-VLAN");
10271 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10273                                  mode_value, "Tunnel");
10274 cmdline_parse_token_string_t cmd_flow_director_mac =
10275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10276                                  mac, "mac");
10277 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10278         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10279                                     mac_addr);
10280 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10282                                  tunnel, "tunnel");
10283 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10285                                  tunnel_type, "NVGRE#VxLAN");
10286 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10288                                  tunnel_id, "tunnel-id");
10289 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10290         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10291                               tunnel_id_value, UINT32);
10292
10293 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10294         .f = cmd_flow_director_filter_parsed,
10295         .data = NULL,
10296         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10297                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10298                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10299                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10300                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10301                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10302                 "fd_id <fd_id_value>: "
10303                 "Add or delete an ip flow director entry on NIC",
10304         .tokens = {
10305                 (void *)&cmd_flow_director_filter,
10306                 (void *)&cmd_flow_director_port_id,
10307                 (void *)&cmd_flow_director_mode,
10308                 (void *)&cmd_flow_director_mode_ip,
10309                 (void *)&cmd_flow_director_ops,
10310                 (void *)&cmd_flow_director_flow,
10311                 (void *)&cmd_flow_director_flow_type,
10312                 (void *)&cmd_flow_director_src,
10313                 (void *)&cmd_flow_director_ip_src,
10314                 (void *)&cmd_flow_director_dst,
10315                 (void *)&cmd_flow_director_ip_dst,
10316                 (void *)&cmd_flow_director_tos,
10317                 (void *)&cmd_flow_director_tos_value,
10318                 (void *)&cmd_flow_director_proto,
10319                 (void *)&cmd_flow_director_proto_value,
10320                 (void *)&cmd_flow_director_ttl,
10321                 (void *)&cmd_flow_director_ttl_value,
10322                 (void *)&cmd_flow_director_vlan,
10323                 (void *)&cmd_flow_director_vlan_value,
10324                 (void *)&cmd_flow_director_flexbytes,
10325                 (void *)&cmd_flow_director_flexbytes_value,
10326                 (void *)&cmd_flow_director_drop,
10327                 (void *)&cmd_flow_director_pf_vf,
10328                 (void *)&cmd_flow_director_queue,
10329                 (void *)&cmd_flow_director_queue_id,
10330                 (void *)&cmd_flow_director_fd_id,
10331                 (void *)&cmd_flow_director_fd_id_value,
10332                 NULL,
10333         },
10334 };
10335
10336 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10337         .f = cmd_flow_director_filter_parsed,
10338         .data = NULL,
10339         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10340                 "director entry on NIC",
10341         .tokens = {
10342                 (void *)&cmd_flow_director_filter,
10343                 (void *)&cmd_flow_director_port_id,
10344                 (void *)&cmd_flow_director_mode,
10345                 (void *)&cmd_flow_director_mode_ip,
10346                 (void *)&cmd_flow_director_ops,
10347                 (void *)&cmd_flow_director_flow,
10348                 (void *)&cmd_flow_director_flow_type,
10349                 (void *)&cmd_flow_director_src,
10350                 (void *)&cmd_flow_director_ip_src,
10351                 (void *)&cmd_flow_director_port_src,
10352                 (void *)&cmd_flow_director_dst,
10353                 (void *)&cmd_flow_director_ip_dst,
10354                 (void *)&cmd_flow_director_port_dst,
10355                 (void *)&cmd_flow_director_tos,
10356                 (void *)&cmd_flow_director_tos_value,
10357                 (void *)&cmd_flow_director_ttl,
10358                 (void *)&cmd_flow_director_ttl_value,
10359                 (void *)&cmd_flow_director_vlan,
10360                 (void *)&cmd_flow_director_vlan_value,
10361                 (void *)&cmd_flow_director_flexbytes,
10362                 (void *)&cmd_flow_director_flexbytes_value,
10363                 (void *)&cmd_flow_director_drop,
10364                 (void *)&cmd_flow_director_pf_vf,
10365                 (void *)&cmd_flow_director_queue,
10366                 (void *)&cmd_flow_director_queue_id,
10367                 (void *)&cmd_flow_director_fd_id,
10368                 (void *)&cmd_flow_director_fd_id_value,
10369                 NULL,
10370         },
10371 };
10372
10373 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10374         .f = cmd_flow_director_filter_parsed,
10375         .data = NULL,
10376         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10377                 "director entry on NIC",
10378         .tokens = {
10379                 (void *)&cmd_flow_director_filter,
10380                 (void *)&cmd_flow_director_port_id,
10381                 (void *)&cmd_flow_director_mode,
10382                 (void *)&cmd_flow_director_mode_ip,
10383                 (void *)&cmd_flow_director_ops,
10384                 (void *)&cmd_flow_director_flow,
10385                 (void *)&cmd_flow_director_flow_type,
10386                 (void *)&cmd_flow_director_src,
10387                 (void *)&cmd_flow_director_ip_src,
10388                 (void *)&cmd_flow_director_port_dst,
10389                 (void *)&cmd_flow_director_dst,
10390                 (void *)&cmd_flow_director_ip_dst,
10391                 (void *)&cmd_flow_director_port_dst,
10392                 (void *)&cmd_flow_director_verify_tag,
10393                 (void *)&cmd_flow_director_verify_tag_value,
10394                 (void *)&cmd_flow_director_tos,
10395                 (void *)&cmd_flow_director_tos_value,
10396                 (void *)&cmd_flow_director_ttl,
10397                 (void *)&cmd_flow_director_ttl_value,
10398                 (void *)&cmd_flow_director_vlan,
10399                 (void *)&cmd_flow_director_vlan_value,
10400                 (void *)&cmd_flow_director_flexbytes,
10401                 (void *)&cmd_flow_director_flexbytes_value,
10402                 (void *)&cmd_flow_director_drop,
10403                 (void *)&cmd_flow_director_pf_vf,
10404                 (void *)&cmd_flow_director_queue,
10405                 (void *)&cmd_flow_director_queue_id,
10406                 (void *)&cmd_flow_director_fd_id,
10407                 (void *)&cmd_flow_director_fd_id_value,
10408                 NULL,
10409         },
10410 };
10411
10412 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10413         .f = cmd_flow_director_filter_parsed,
10414         .data = NULL,
10415         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10416                 "director entry on NIC",
10417         .tokens = {
10418                 (void *)&cmd_flow_director_filter,
10419                 (void *)&cmd_flow_director_port_id,
10420                 (void *)&cmd_flow_director_mode,
10421                 (void *)&cmd_flow_director_mode_ip,
10422                 (void *)&cmd_flow_director_ops,
10423                 (void *)&cmd_flow_director_flow,
10424                 (void *)&cmd_flow_director_flow_type,
10425                 (void *)&cmd_flow_director_ether,
10426                 (void *)&cmd_flow_director_ether_type,
10427                 (void *)&cmd_flow_director_flexbytes,
10428                 (void *)&cmd_flow_director_flexbytes_value,
10429                 (void *)&cmd_flow_director_drop,
10430                 (void *)&cmd_flow_director_pf_vf,
10431                 (void *)&cmd_flow_director_queue,
10432                 (void *)&cmd_flow_director_queue_id,
10433                 (void *)&cmd_flow_director_fd_id,
10434                 (void *)&cmd_flow_director_fd_id_value,
10435                 NULL,
10436         },
10437 };
10438
10439 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10440         .f = cmd_flow_director_filter_parsed,
10441         .data = NULL,
10442         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10443                 "director entry on NIC",
10444         .tokens = {
10445                 (void *)&cmd_flow_director_filter,
10446                 (void *)&cmd_flow_director_port_id,
10447                 (void *)&cmd_flow_director_mode,
10448                 (void *)&cmd_flow_director_mode_mac_vlan,
10449                 (void *)&cmd_flow_director_ops,
10450                 (void *)&cmd_flow_director_mac,
10451                 (void *)&cmd_flow_director_mac_addr,
10452                 (void *)&cmd_flow_director_vlan,
10453                 (void *)&cmd_flow_director_vlan_value,
10454                 (void *)&cmd_flow_director_flexbytes,
10455                 (void *)&cmd_flow_director_flexbytes_value,
10456                 (void *)&cmd_flow_director_drop,
10457                 (void *)&cmd_flow_director_queue,
10458                 (void *)&cmd_flow_director_queue_id,
10459                 (void *)&cmd_flow_director_fd_id,
10460                 (void *)&cmd_flow_director_fd_id_value,
10461                 NULL,
10462         },
10463 };
10464
10465 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10466         .f = cmd_flow_director_filter_parsed,
10467         .data = NULL,
10468         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10469                 "director entry on NIC",
10470         .tokens = {
10471                 (void *)&cmd_flow_director_filter,
10472                 (void *)&cmd_flow_director_port_id,
10473                 (void *)&cmd_flow_director_mode,
10474                 (void *)&cmd_flow_director_mode_tunnel,
10475                 (void *)&cmd_flow_director_ops,
10476                 (void *)&cmd_flow_director_mac,
10477                 (void *)&cmd_flow_director_mac_addr,
10478                 (void *)&cmd_flow_director_vlan,
10479                 (void *)&cmd_flow_director_vlan_value,
10480                 (void *)&cmd_flow_director_tunnel,
10481                 (void *)&cmd_flow_director_tunnel_type,
10482                 (void *)&cmd_flow_director_tunnel_id,
10483                 (void *)&cmd_flow_director_tunnel_id_value,
10484                 (void *)&cmd_flow_director_flexbytes,
10485                 (void *)&cmd_flow_director_flexbytes_value,
10486                 (void *)&cmd_flow_director_drop,
10487                 (void *)&cmd_flow_director_queue,
10488                 (void *)&cmd_flow_director_queue_id,
10489                 (void *)&cmd_flow_director_fd_id,
10490                 (void *)&cmd_flow_director_fd_id_value,
10491                 NULL,
10492         },
10493 };
10494
10495 struct cmd_flush_flow_director_result {
10496         cmdline_fixed_string_t flush_flow_director;
10497         portid_t port_id;
10498 };
10499
10500 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10501         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10502                                  flush_flow_director, "flush_flow_director");
10503 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10504         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10505                               port_id, UINT16);
10506
10507 static void
10508 cmd_flush_flow_director_parsed(void *parsed_result,
10509                           __attribute__((unused)) struct cmdline *cl,
10510                           __attribute__((unused)) void *data)
10511 {
10512         struct cmd_flow_director_result *res = parsed_result;
10513         int ret = 0;
10514
10515         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10516         if (ret < 0) {
10517                 printf("flow director is not supported on port %u.\n",
10518                         res->port_id);
10519                 return;
10520         }
10521
10522         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10523                         RTE_ETH_FILTER_FLUSH, NULL);
10524         if (ret < 0)
10525                 printf("flow director table flushing error: (%s)\n",
10526                         strerror(-ret));
10527 }
10528
10529 cmdline_parse_inst_t cmd_flush_flow_director = {
10530         .f = cmd_flush_flow_director_parsed,
10531         .data = NULL,
10532         .help_str = "flush_flow_director <port_id>: "
10533                 "Flush all flow director entries of a device on NIC",
10534         .tokens = {
10535                 (void *)&cmd_flush_flow_director_flush,
10536                 (void *)&cmd_flush_flow_director_port_id,
10537                 NULL,
10538         },
10539 };
10540
10541 /* *** deal with flow director mask *** */
10542 struct cmd_flow_director_mask_result {
10543         cmdline_fixed_string_t flow_director_mask;
10544         portid_t port_id;
10545         cmdline_fixed_string_t mode;
10546         cmdline_fixed_string_t mode_value;
10547         cmdline_fixed_string_t vlan;
10548         uint16_t vlan_mask;
10549         cmdline_fixed_string_t src_mask;
10550         cmdline_ipaddr_t ipv4_src;
10551         cmdline_ipaddr_t ipv6_src;
10552         uint16_t port_src;
10553         cmdline_fixed_string_t dst_mask;
10554         cmdline_ipaddr_t ipv4_dst;
10555         cmdline_ipaddr_t ipv6_dst;
10556         uint16_t port_dst;
10557         cmdline_fixed_string_t mac;
10558         uint8_t mac_addr_byte_mask;
10559         cmdline_fixed_string_t tunnel_id;
10560         uint32_t tunnel_id_mask;
10561         cmdline_fixed_string_t tunnel_type;
10562         uint8_t tunnel_type_mask;
10563 };
10564
10565 static void
10566 cmd_flow_director_mask_parsed(void *parsed_result,
10567                           __attribute__((unused)) struct cmdline *cl,
10568                           __attribute__((unused)) void *data)
10569 {
10570         struct cmd_flow_director_mask_result *res = parsed_result;
10571         struct rte_eth_fdir_masks *mask;
10572         struct rte_port *port;
10573
10574         if (res->port_id > nb_ports) {
10575                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10576                 return;
10577         }
10578
10579         port = &ports[res->port_id];
10580         /** Check if the port is not started **/
10581         if (port->port_status != RTE_PORT_STOPPED) {
10582                 printf("Please stop port %d first\n", res->port_id);
10583                 return;
10584         }
10585
10586         mask = &port->dev_conf.fdir_conf.mask;
10587
10588         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10589                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10590                         printf("Please set mode to MAC-VLAN.\n");
10591                         return;
10592                 }
10593
10594                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10595         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10596                 if (strcmp(res->mode_value, "Tunnel")) {
10597                         printf("Please set mode to Tunnel.\n");
10598                         return;
10599                 }
10600
10601                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10602                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10603                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10604                 mask->tunnel_type_mask = res->tunnel_type_mask;
10605         } else {
10606                 if (strcmp(res->mode_value, "IP")) {
10607                         printf("Please set mode to IP.\n");
10608                         return;
10609                 }
10610
10611                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10612                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10613                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10614                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10615                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10616                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10617                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10618         }
10619
10620         cmd_reconfig_device_queue(res->port_id, 1, 1);
10621 }
10622
10623 cmdline_parse_token_string_t cmd_flow_director_mask =
10624         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10625                                  flow_director_mask, "flow_director_mask");
10626 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10627         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10628                               port_id, UINT16);
10629 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10630         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10631                                  vlan, "vlan");
10632 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10633         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10634                               vlan_mask, UINT16);
10635 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10636         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10637                                  src_mask, "src_mask");
10638 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10639         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10640                                  ipv4_src);
10641 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10642         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10643                                  ipv6_src);
10644 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10645         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10646                               port_src, UINT16);
10647 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10649                                  dst_mask, "dst_mask");
10650 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10651         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10652                                  ipv4_dst);
10653 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10654         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10655                                  ipv6_dst);
10656 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10657         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10658                               port_dst, UINT16);
10659
10660 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10661         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10662                                  mode, "mode");
10663 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10664         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10665                                  mode_value, "IP");
10666 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10667         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10668                                  mode_value, "MAC-VLAN");
10669 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10671                                  mode_value, "Tunnel");
10672 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10673         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10674                                  mac, "mac");
10675 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10676         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10677                               mac_addr_byte_mask, UINT8);
10678 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10679         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10680                                  tunnel_type, "tunnel-type");
10681 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10682         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10683                               tunnel_type_mask, UINT8);
10684 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10685         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10686                                  tunnel_id, "tunnel-id");
10687 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10688         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10689                               tunnel_id_mask, UINT32);
10690
10691 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10692         .f = cmd_flow_director_mask_parsed,
10693         .data = NULL,
10694         .help_str = "flow_director_mask ... : "
10695                 "Set IP mode flow director's mask on NIC",
10696         .tokens = {
10697                 (void *)&cmd_flow_director_mask,
10698                 (void *)&cmd_flow_director_mask_port_id,
10699                 (void *)&cmd_flow_director_mask_mode,
10700                 (void *)&cmd_flow_director_mask_mode_ip,
10701                 (void *)&cmd_flow_director_mask_vlan,
10702                 (void *)&cmd_flow_director_mask_vlan_value,
10703                 (void *)&cmd_flow_director_mask_src,
10704                 (void *)&cmd_flow_director_mask_ipv4_src,
10705                 (void *)&cmd_flow_director_mask_ipv6_src,
10706                 (void *)&cmd_flow_director_mask_port_src,
10707                 (void *)&cmd_flow_director_mask_dst,
10708                 (void *)&cmd_flow_director_mask_ipv4_dst,
10709                 (void *)&cmd_flow_director_mask_ipv6_dst,
10710                 (void *)&cmd_flow_director_mask_port_dst,
10711                 NULL,
10712         },
10713 };
10714
10715 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10716         .f = cmd_flow_director_mask_parsed,
10717         .data = NULL,
10718         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10719                 "flow director's mask on NIC",
10720         .tokens = {
10721                 (void *)&cmd_flow_director_mask,
10722                 (void *)&cmd_flow_director_mask_port_id,
10723                 (void *)&cmd_flow_director_mask_mode,
10724                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10725                 (void *)&cmd_flow_director_mask_vlan,
10726                 (void *)&cmd_flow_director_mask_vlan_value,
10727                 NULL,
10728         },
10729 };
10730
10731 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10732         .f = cmd_flow_director_mask_parsed,
10733         .data = NULL,
10734         .help_str = "flow_director_mask ... : Set tunnel mode "
10735                 "flow director's mask on NIC",
10736         .tokens = {
10737                 (void *)&cmd_flow_director_mask,
10738                 (void *)&cmd_flow_director_mask_port_id,
10739                 (void *)&cmd_flow_director_mask_mode,
10740                 (void *)&cmd_flow_director_mask_mode_tunnel,
10741                 (void *)&cmd_flow_director_mask_vlan,
10742                 (void *)&cmd_flow_director_mask_vlan_value,
10743                 (void *)&cmd_flow_director_mask_mac,
10744                 (void *)&cmd_flow_director_mask_mac_value,
10745                 (void *)&cmd_flow_director_mask_tunnel_type,
10746                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10747                 (void *)&cmd_flow_director_mask_tunnel_id,
10748                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10749                 NULL,
10750         },
10751 };
10752
10753 /* *** deal with flow director mask on flexible payload *** */
10754 struct cmd_flow_director_flex_mask_result {
10755         cmdline_fixed_string_t flow_director_flexmask;
10756         portid_t port_id;
10757         cmdline_fixed_string_t flow;
10758         cmdline_fixed_string_t flow_type;
10759         cmdline_fixed_string_t mask;
10760 };
10761
10762 static void
10763 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10764                           __attribute__((unused)) struct cmdline *cl,
10765                           __attribute__((unused)) void *data)
10766 {
10767         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10768         struct rte_eth_fdir_info fdir_info;
10769         struct rte_eth_fdir_flex_mask flex_mask;
10770         struct rte_port *port;
10771         uint32_t flow_type_mask;
10772         uint16_t i;
10773         int ret;
10774
10775         if (res->port_id > nb_ports) {
10776                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10777                 return;
10778         }
10779
10780         port = &ports[res->port_id];
10781         /** Check if the port is not started **/
10782         if (port->port_status != RTE_PORT_STOPPED) {
10783                 printf("Please stop port %d first\n", res->port_id);
10784                 return;
10785         }
10786
10787         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10788         ret = parse_flexbytes(res->mask,
10789                         flex_mask.mask,
10790                         RTE_ETH_FDIR_MAX_FLEXLEN);
10791         if (ret < 0) {
10792                 printf("error: Cannot parse mask input.\n");
10793                 return;
10794         }
10795
10796         memset(&fdir_info, 0, sizeof(fdir_info));
10797         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10798                                 RTE_ETH_FILTER_INFO, &fdir_info);
10799         if (ret < 0) {
10800                 printf("Cannot get FDir filter info\n");
10801                 return;
10802         }
10803
10804         if (!strcmp(res->flow_type, "none")) {
10805                 /* means don't specify the flow type */
10806                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10807                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10808                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10809                                0, sizeof(struct rte_eth_fdir_flex_mask));
10810                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10811                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10812                                  &flex_mask,
10813                                  sizeof(struct rte_eth_fdir_flex_mask));
10814                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10815                 return;
10816         }
10817         flow_type_mask = fdir_info.flow_types_mask[0];
10818         if (!strcmp(res->flow_type, "all")) {
10819                 if (!flow_type_mask) {
10820                         printf("No flow type supported\n");
10821                         return;
10822                 }
10823                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10824                         if (flow_type_mask & (1 << i)) {
10825                                 flex_mask.flow_type = i;
10826                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10827                         }
10828                 }
10829                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10830                 return;
10831         }
10832         flex_mask.flow_type = str2flowtype(res->flow_type);
10833         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10834                 printf("Flow type %s not supported on port %d\n",
10835                                 res->flow_type, res->port_id);
10836                 return;
10837         }
10838         fdir_set_flex_mask(res->port_id, &flex_mask);
10839         cmd_reconfig_device_queue(res->port_id, 1, 1);
10840 }
10841
10842 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10843         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10844                                  flow_director_flexmask,
10845                                  "flow_director_flex_mask");
10846 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10847         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10848                               port_id, UINT16);
10849 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10851                                  flow, "flow");
10852 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10853         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10854                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10855                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10856 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10857         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10858                                  mask, NULL);
10859
10860 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10861         .f = cmd_flow_director_flex_mask_parsed,
10862         .data = NULL,
10863         .help_str = "flow_director_flex_mask ... : "
10864                 "Set flow director's flex mask on NIC",
10865         .tokens = {
10866                 (void *)&cmd_flow_director_flexmask,
10867                 (void *)&cmd_flow_director_flexmask_port_id,
10868                 (void *)&cmd_flow_director_flexmask_flow,
10869                 (void *)&cmd_flow_director_flexmask_flow_type,
10870                 (void *)&cmd_flow_director_flexmask_mask,
10871                 NULL,
10872         },
10873 };
10874
10875 /* *** deal with flow director flexible payload configuration *** */
10876 struct cmd_flow_director_flexpayload_result {
10877         cmdline_fixed_string_t flow_director_flexpayload;
10878         portid_t port_id;
10879         cmdline_fixed_string_t payload_layer;
10880         cmdline_fixed_string_t payload_cfg;
10881 };
10882
10883 static inline int
10884 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10885 {
10886         char s[256];
10887         const char *p, *p0 = q_arg;
10888         char *end;
10889         unsigned long int_fld;
10890         char *str_fld[max_num];
10891         int i;
10892         unsigned size;
10893         int ret = -1;
10894
10895         p = strchr(p0, '(');
10896         if (p == NULL)
10897                 return -1;
10898         ++p;
10899         p0 = strchr(p, ')');
10900         if (p0 == NULL)
10901                 return -1;
10902
10903         size = p0 - p;
10904         if (size >= sizeof(s))
10905                 return -1;
10906
10907         snprintf(s, sizeof(s), "%.*s", size, p);
10908         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10909         if (ret < 0 || ret > max_num)
10910                 return -1;
10911         for (i = 0; i < ret; i++) {
10912                 errno = 0;
10913                 int_fld = strtoul(str_fld[i], &end, 0);
10914                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10915                         return -1;
10916                 offsets[i] = (uint16_t)int_fld;
10917         }
10918         return ret;
10919 }
10920
10921 static void
10922 cmd_flow_director_flxpld_parsed(void *parsed_result,
10923                           __attribute__((unused)) struct cmdline *cl,
10924                           __attribute__((unused)) void *data)
10925 {
10926         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10927         struct rte_eth_flex_payload_cfg flex_cfg;
10928         struct rte_port *port;
10929         int ret = 0;
10930
10931         if (res->port_id > nb_ports) {
10932                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10933                 return;
10934         }
10935
10936         port = &ports[res->port_id];
10937         /** Check if the port is not started **/
10938         if (port->port_status != RTE_PORT_STOPPED) {
10939                 printf("Please stop port %d first\n", res->port_id);
10940                 return;
10941         }
10942
10943         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10944
10945         if (!strcmp(res->payload_layer, "raw"))
10946                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10947         else if (!strcmp(res->payload_layer, "l2"))
10948                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10949         else if (!strcmp(res->payload_layer, "l3"))
10950                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10951         else if (!strcmp(res->payload_layer, "l4"))
10952                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10953
10954         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10955                             RTE_ETH_FDIR_MAX_FLEXLEN);
10956         if (ret < 0) {
10957                 printf("error: Cannot parse flex payload input.\n");
10958                 return;
10959         }
10960
10961         fdir_set_flex_payload(res->port_id, &flex_cfg);
10962         cmd_reconfig_device_queue(res->port_id, 1, 1);
10963 }
10964
10965 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10966         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10967                                  flow_director_flexpayload,
10968                                  "flow_director_flex_payload");
10969 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10970         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10971                               port_id, UINT16);
10972 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10973         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10974                                  payload_layer, "raw#l2#l3#l4");
10975 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10976         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10977                                  payload_cfg, NULL);
10978
10979 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10980         .f = cmd_flow_director_flxpld_parsed,
10981         .data = NULL,
10982         .help_str = "flow_director_flexpayload ... : "
10983                 "Set flow director's flex payload on NIC",
10984         .tokens = {
10985                 (void *)&cmd_flow_director_flexpayload,
10986                 (void *)&cmd_flow_director_flexpayload_port_id,
10987                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10988                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10989                 NULL,
10990         },
10991 };
10992
10993 /* Generic flow interface command. */
10994 extern cmdline_parse_inst_t cmd_flow;
10995
10996 /* *** Classification Filters Control *** */
10997 /* *** Get symmetric hash enable per port *** */
10998 struct cmd_get_sym_hash_ena_per_port_result {
10999         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11000         portid_t port_id;
11001 };
11002
11003 static void
11004 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11005                                  __rte_unused struct cmdline *cl,
11006                                  __rte_unused void *data)
11007 {
11008         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11009         struct rte_eth_hash_filter_info info;
11010         int ret;
11011
11012         if (rte_eth_dev_filter_supported(res->port_id,
11013                                 RTE_ETH_FILTER_HASH) < 0) {
11014                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11015                                                         res->port_id);
11016                 return;
11017         }
11018
11019         memset(&info, 0, sizeof(info));
11020         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11021         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11022                                                 RTE_ETH_FILTER_GET, &info);
11023
11024         if (ret < 0) {
11025                 printf("Cannot get symmetric hash enable per port "
11026                                         "on port %u\n", res->port_id);
11027                 return;
11028         }
11029
11030         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11031                                 "enabled" : "disabled", res->port_id);
11032 }
11033
11034 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11035         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11036                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11037 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11038         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11039                 port_id, UINT16);
11040
11041 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11042         .f = cmd_get_sym_hash_per_port_parsed,
11043         .data = NULL,
11044         .help_str = "get_sym_hash_ena_per_port <port_id>",
11045         .tokens = {
11046                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11047                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11048                 NULL,
11049         },
11050 };
11051
11052 /* *** Set symmetric hash enable per port *** */
11053 struct cmd_set_sym_hash_ena_per_port_result {
11054         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11055         cmdline_fixed_string_t enable;
11056         portid_t port_id;
11057 };
11058
11059 static void
11060 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11061                                  __rte_unused struct cmdline *cl,
11062                                  __rte_unused void *data)
11063 {
11064         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11065         struct rte_eth_hash_filter_info info;
11066         int ret;
11067
11068         if (rte_eth_dev_filter_supported(res->port_id,
11069                                 RTE_ETH_FILTER_HASH) < 0) {
11070                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11071                                                         res->port_id);
11072                 return;
11073         }
11074
11075         memset(&info, 0, sizeof(info));
11076         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11077         if (!strcmp(res->enable, "enable"))
11078                 info.info.enable = 1;
11079         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11080                                         RTE_ETH_FILTER_SET, &info);
11081         if (ret < 0) {
11082                 printf("Cannot set symmetric hash enable per port on "
11083                                         "port %u\n", res->port_id);
11084                 return;
11085         }
11086         printf("Symmetric hash has been set to %s on port %u\n",
11087                                         res->enable, res->port_id);
11088 }
11089
11090 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11091         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11092                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11093 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11094         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11095                 port_id, UINT16);
11096 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11097         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11098                 enable, "enable#disable");
11099
11100 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11101         .f = cmd_set_sym_hash_per_port_parsed,
11102         .data = NULL,
11103         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11104         .tokens = {
11105                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11106                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11107                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11108                 NULL,
11109         },
11110 };
11111
11112 /* Get global config of hash function */
11113 struct cmd_get_hash_global_config_result {
11114         cmdline_fixed_string_t get_hash_global_config;
11115         portid_t port_id;
11116 };
11117
11118 static char *
11119 flowtype_to_str(uint16_t ftype)
11120 {
11121         uint16_t i;
11122         static struct {
11123                 char str[16];
11124                 uint16_t ftype;
11125         } ftype_table[] = {
11126                 {"ipv4", RTE_ETH_FLOW_IPV4},
11127                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11128                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11129                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11130                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11131                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11132                 {"ipv6", RTE_ETH_FLOW_IPV6},
11133                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11134                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11135                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11136                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11137                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11138                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11139                 {"port", RTE_ETH_FLOW_PORT},
11140                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11141                 {"geneve", RTE_ETH_FLOW_GENEVE},
11142                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11143         };
11144
11145         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11146                 if (ftype_table[i].ftype == ftype)
11147                         return ftype_table[i].str;
11148         }
11149
11150         return NULL;
11151 }
11152
11153 static void
11154 cmd_get_hash_global_config_parsed(void *parsed_result,
11155                                   __rte_unused struct cmdline *cl,
11156                                   __rte_unused void *data)
11157 {
11158         struct cmd_get_hash_global_config_result *res = parsed_result;
11159         struct rte_eth_hash_filter_info info;
11160         uint32_t idx, offset;
11161         uint16_t i;
11162         char *str;
11163         int ret;
11164
11165         if (rte_eth_dev_filter_supported(res->port_id,
11166                         RTE_ETH_FILTER_HASH) < 0) {
11167                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11168                                                         res->port_id);
11169                 return;
11170         }
11171
11172         memset(&info, 0, sizeof(info));
11173         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11174         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11175                                         RTE_ETH_FILTER_GET, &info);
11176         if (ret < 0) {
11177                 printf("Cannot get hash global configurations by port %d\n",
11178                                                         res->port_id);
11179                 return;
11180         }
11181
11182         switch (info.info.global_conf.hash_func) {
11183         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11184                 printf("Hash function is Toeplitz\n");
11185                 break;
11186         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11187                 printf("Hash function is Simple XOR\n");
11188                 break;
11189         default:
11190                 printf("Unknown hash function\n");
11191                 break;
11192         }
11193
11194         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11195                 idx = i / UINT32_BIT;
11196                 offset = i % UINT32_BIT;
11197                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11198                                                 (1UL << offset)))
11199                         continue;
11200                 str = flowtype_to_str(i);
11201                 if (!str)
11202                         continue;
11203                 printf("Symmetric hash is %s globally for flow type %s "
11204                                                         "by port %d\n",
11205                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11206                         (1UL << offset)) ? "enabled" : "disabled"), str,
11207                                                         res->port_id);
11208         }
11209 }
11210
11211 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11212         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11213                 get_hash_global_config, "get_hash_global_config");
11214 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11215         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11216                 port_id, UINT16);
11217
11218 cmdline_parse_inst_t cmd_get_hash_global_config = {
11219         .f = cmd_get_hash_global_config_parsed,
11220         .data = NULL,
11221         .help_str = "get_hash_global_config <port_id>",
11222         .tokens = {
11223                 (void *)&cmd_get_hash_global_config_all,
11224                 (void *)&cmd_get_hash_global_config_port_id,
11225                 NULL,
11226         },
11227 };
11228
11229 /* Set global config of hash function */
11230 struct cmd_set_hash_global_config_result {
11231         cmdline_fixed_string_t set_hash_global_config;
11232         portid_t port_id;
11233         cmdline_fixed_string_t hash_func;
11234         cmdline_fixed_string_t flow_type;
11235         cmdline_fixed_string_t enable;
11236 };
11237
11238 static void
11239 cmd_set_hash_global_config_parsed(void *parsed_result,
11240                                   __rte_unused struct cmdline *cl,
11241                                   __rte_unused void *data)
11242 {
11243         struct cmd_set_hash_global_config_result *res = parsed_result;
11244         struct rte_eth_hash_filter_info info;
11245         uint32_t ftype, idx, offset;
11246         int ret;
11247
11248         if (rte_eth_dev_filter_supported(res->port_id,
11249                                 RTE_ETH_FILTER_HASH) < 0) {
11250                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11251                                                         res->port_id);
11252                 return;
11253         }
11254         memset(&info, 0, sizeof(info));
11255         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11256         if (!strcmp(res->hash_func, "toeplitz"))
11257                 info.info.global_conf.hash_func =
11258                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11259         else if (!strcmp(res->hash_func, "simple_xor"))
11260                 info.info.global_conf.hash_func =
11261                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11262         else if (!strcmp(res->hash_func, "default"))
11263                 info.info.global_conf.hash_func =
11264                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11265
11266         ftype = str2flowtype(res->flow_type);
11267         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11268         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11269         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11270         if (!strcmp(res->enable, "enable"))
11271                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11272                                                 (1UL << offset);
11273         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11274                                         RTE_ETH_FILTER_SET, &info);
11275         if (ret < 0)
11276                 printf("Cannot set global hash configurations by port %d\n",
11277                                                         res->port_id);
11278         else
11279                 printf("Global hash configurations have been set "
11280                         "succcessfully by port %d\n", res->port_id);
11281 }
11282
11283 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11284         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11285                 set_hash_global_config, "set_hash_global_config");
11286 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11287         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11288                 port_id, UINT16);
11289 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11290         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11291                 hash_func, "toeplitz#simple_xor#default");
11292 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11293         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11294                 flow_type,
11295                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11296                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11297 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11298         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11299                 enable, "enable#disable");
11300
11301 cmdline_parse_inst_t cmd_set_hash_global_config = {
11302         .f = cmd_set_hash_global_config_parsed,
11303         .data = NULL,
11304         .help_str = "set_hash_global_config <port_id> "
11305                 "toeplitz|simple_xor|default "
11306                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11307                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11308                 "l2_payload enable|disable",
11309         .tokens = {
11310                 (void *)&cmd_set_hash_global_config_all,
11311                 (void *)&cmd_set_hash_global_config_port_id,
11312                 (void *)&cmd_set_hash_global_config_hash_func,
11313                 (void *)&cmd_set_hash_global_config_flow_type,
11314                 (void *)&cmd_set_hash_global_config_enable,
11315                 NULL,
11316         },
11317 };
11318
11319 /* Set hash input set */
11320 struct cmd_set_hash_input_set_result {
11321         cmdline_fixed_string_t set_hash_input_set;
11322         portid_t port_id;
11323         cmdline_fixed_string_t flow_type;
11324         cmdline_fixed_string_t inset_field;
11325         cmdline_fixed_string_t select;
11326 };
11327
11328 static enum rte_eth_input_set_field
11329 str2inset(char *string)
11330 {
11331         uint16_t i;
11332
11333         static const struct {
11334                 char str[32];
11335                 enum rte_eth_input_set_field inset;
11336         } inset_table[] = {
11337                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11338                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11339                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11340                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11341                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11342                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11343                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11344                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11345                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11346                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11347                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11348                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11349                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11350                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11351                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11352                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11353                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11354                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11355                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11356                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11357                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11358                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11359                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11360                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11361                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11362                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11363                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11364                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11365                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11366                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11367                 {"none", RTE_ETH_INPUT_SET_NONE},
11368         };
11369
11370         for (i = 0; i < RTE_DIM(inset_table); i++) {
11371                 if (!strcmp(string, inset_table[i].str))
11372                         return inset_table[i].inset;
11373         }
11374
11375         return RTE_ETH_INPUT_SET_UNKNOWN;
11376 }
11377
11378 static void
11379 cmd_set_hash_input_set_parsed(void *parsed_result,
11380                               __rte_unused struct cmdline *cl,
11381                               __rte_unused void *data)
11382 {
11383         struct cmd_set_hash_input_set_result *res = parsed_result;
11384         struct rte_eth_hash_filter_info info;
11385
11386         memset(&info, 0, sizeof(info));
11387         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11388         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11389         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11390         info.info.input_set_conf.inset_size = 1;
11391         if (!strcmp(res->select, "select"))
11392                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11393         else if (!strcmp(res->select, "add"))
11394                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11395         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11396                                 RTE_ETH_FILTER_SET, &info);
11397 }
11398
11399 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11400         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11401                 set_hash_input_set, "set_hash_input_set");
11402 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11403         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11404                 port_id, UINT16);
11405 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11406         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11407                 flow_type, NULL);
11408 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11409         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11410                 inset_field,
11411                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11412                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11413                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11414                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11415                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11416                 "fld-8th#none");
11417 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11418         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11419                 select, "select#add");
11420
11421 cmdline_parse_inst_t cmd_set_hash_input_set = {
11422         .f = cmd_set_hash_input_set_parsed,
11423         .data = NULL,
11424         .help_str = "set_hash_input_set <port_id> "
11425         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11426         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11427         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11428         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11429         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11430         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11431         "fld-7th|fld-8th|none select|add",
11432         .tokens = {
11433                 (void *)&cmd_set_hash_input_set_cmd,
11434                 (void *)&cmd_set_hash_input_set_port_id,
11435                 (void *)&cmd_set_hash_input_set_flow_type,
11436                 (void *)&cmd_set_hash_input_set_field,
11437                 (void *)&cmd_set_hash_input_set_select,
11438                 NULL,
11439         },
11440 };
11441
11442 /* Set flow director input set */
11443 struct cmd_set_fdir_input_set_result {
11444         cmdline_fixed_string_t set_fdir_input_set;
11445         portid_t port_id;
11446         cmdline_fixed_string_t flow_type;
11447         cmdline_fixed_string_t inset_field;
11448         cmdline_fixed_string_t select;
11449 };
11450
11451 static void
11452 cmd_set_fdir_input_set_parsed(void *parsed_result,
11453         __rte_unused struct cmdline *cl,
11454         __rte_unused void *data)
11455 {
11456         struct cmd_set_fdir_input_set_result *res = parsed_result;
11457         struct rte_eth_fdir_filter_info info;
11458
11459         memset(&info, 0, sizeof(info));
11460         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11461         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11462         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11463         info.info.input_set_conf.inset_size = 1;
11464         if (!strcmp(res->select, "select"))
11465                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11466         else if (!strcmp(res->select, "add"))
11467                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11468         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11469                 RTE_ETH_FILTER_SET, &info);
11470 }
11471
11472 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11473         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11474         set_fdir_input_set, "set_fdir_input_set");
11475 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11476         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11477         port_id, UINT16);
11478 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11479         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11480         flow_type,
11481         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11482         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11483 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11484         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11485         inset_field,
11486         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11487         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11488         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11489         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11490         "sctp-veri-tag#none");
11491 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11492         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11493         select, "select#add");
11494
11495 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11496         .f = cmd_set_fdir_input_set_parsed,
11497         .data = NULL,
11498         .help_str = "set_fdir_input_set <port_id> "
11499         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11500         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11501         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11502         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11503         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11504         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11505         "sctp-veri-tag|none select|add",
11506         .tokens = {
11507                 (void *)&cmd_set_fdir_input_set_cmd,
11508                 (void *)&cmd_set_fdir_input_set_port_id,
11509                 (void *)&cmd_set_fdir_input_set_flow_type,
11510                 (void *)&cmd_set_fdir_input_set_field,
11511                 (void *)&cmd_set_fdir_input_set_select,
11512                 NULL,
11513         },
11514 };
11515
11516 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11517 struct cmd_mcast_addr_result {
11518         cmdline_fixed_string_t mcast_addr_cmd;
11519         cmdline_fixed_string_t what;
11520         uint16_t port_num;
11521         struct ether_addr mc_addr;
11522 };
11523
11524 static void cmd_mcast_addr_parsed(void *parsed_result,
11525                 __attribute__((unused)) struct cmdline *cl,
11526                 __attribute__((unused)) void *data)
11527 {
11528         struct cmd_mcast_addr_result *res = parsed_result;
11529
11530         if (!is_multicast_ether_addr(&res->mc_addr)) {
11531                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11532                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11533                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11534                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11535                 return;
11536         }
11537         if (strcmp(res->what, "add") == 0)
11538                 mcast_addr_add(res->port_num, &res->mc_addr);
11539         else
11540                 mcast_addr_remove(res->port_num, &res->mc_addr);
11541 }
11542
11543 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11544         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11545                                  mcast_addr_cmd, "mcast_addr");
11546 cmdline_parse_token_string_t cmd_mcast_addr_what =
11547         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11548                                  "add#remove");
11549 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11550         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11551 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11552         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11553
11554 cmdline_parse_inst_t cmd_mcast_addr = {
11555         .f = cmd_mcast_addr_parsed,
11556         .data = (void *)0,
11557         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11558                 "Add/Remove multicast MAC address on port_id",
11559         .tokens = {
11560                 (void *)&cmd_mcast_addr_cmd,
11561                 (void *)&cmd_mcast_addr_what,
11562                 (void *)&cmd_mcast_addr_portnum,
11563                 (void *)&cmd_mcast_addr_addr,
11564                 NULL,
11565         },
11566 };
11567
11568 /* l2 tunnel config
11569  * only support E-tag now.
11570  */
11571
11572 /* Ether type config */
11573 struct cmd_config_l2_tunnel_eth_type_result {
11574         cmdline_fixed_string_t port;
11575         cmdline_fixed_string_t config;
11576         cmdline_fixed_string_t all;
11577         uint8_t id;
11578         cmdline_fixed_string_t l2_tunnel;
11579         cmdline_fixed_string_t l2_tunnel_type;
11580         cmdline_fixed_string_t eth_type;
11581         uint16_t eth_type_val;
11582 };
11583
11584 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11585         TOKEN_STRING_INITIALIZER
11586                 (struct cmd_config_l2_tunnel_eth_type_result,
11587                  port, "port");
11588 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11589         TOKEN_STRING_INITIALIZER
11590                 (struct cmd_config_l2_tunnel_eth_type_result,
11591                  config, "config");
11592 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11593         TOKEN_STRING_INITIALIZER
11594                 (struct cmd_config_l2_tunnel_eth_type_result,
11595                  all, "all");
11596 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11597         TOKEN_NUM_INITIALIZER
11598                 (struct cmd_config_l2_tunnel_eth_type_result,
11599                  id, UINT8);
11600 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11601         TOKEN_STRING_INITIALIZER
11602                 (struct cmd_config_l2_tunnel_eth_type_result,
11603                  l2_tunnel, "l2-tunnel");
11604 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11605         TOKEN_STRING_INITIALIZER
11606                 (struct cmd_config_l2_tunnel_eth_type_result,
11607                  l2_tunnel_type, "E-tag");
11608 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11609         TOKEN_STRING_INITIALIZER
11610                 (struct cmd_config_l2_tunnel_eth_type_result,
11611                  eth_type, "ether-type");
11612 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11613         TOKEN_NUM_INITIALIZER
11614                 (struct cmd_config_l2_tunnel_eth_type_result,
11615                  eth_type_val, UINT16);
11616
11617 static enum rte_eth_tunnel_type
11618 str2fdir_l2_tunnel_type(char *string)
11619 {
11620         uint32_t i = 0;
11621
11622         static const struct {
11623                 char str[32];
11624                 enum rte_eth_tunnel_type type;
11625         } l2_tunnel_type_str[] = {
11626                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11627         };
11628
11629         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11630                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11631                         return l2_tunnel_type_str[i].type;
11632         }
11633         return RTE_TUNNEL_TYPE_NONE;
11634 }
11635
11636 /* ether type config for all ports */
11637 static void
11638 cmd_config_l2_tunnel_eth_type_all_parsed
11639         (void *parsed_result,
11640          __attribute__((unused)) struct cmdline *cl,
11641          __attribute__((unused)) void *data)
11642 {
11643         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11644         struct rte_eth_l2_tunnel_conf entry;
11645         portid_t pid;
11646
11647         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11648         entry.ether_type = res->eth_type_val;
11649
11650         RTE_ETH_FOREACH_DEV(pid) {
11651                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11652         }
11653 }
11654
11655 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11656         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11657         .data = NULL,
11658         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11659         .tokens = {
11660                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11661                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11662                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11663                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11664                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11665                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11666                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11667                 NULL,
11668         },
11669 };
11670
11671 /* ether type config for a specific port */
11672 static void
11673 cmd_config_l2_tunnel_eth_type_specific_parsed(
11674         void *parsed_result,
11675         __attribute__((unused)) struct cmdline *cl,
11676         __attribute__((unused)) void *data)
11677 {
11678         struct cmd_config_l2_tunnel_eth_type_result *res =
11679                  parsed_result;
11680         struct rte_eth_l2_tunnel_conf entry;
11681
11682         if (port_id_is_invalid(res->id, ENABLED_WARN))
11683                 return;
11684
11685         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11686         entry.ether_type = res->eth_type_val;
11687
11688         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11689 }
11690
11691 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11692         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11693         .data = NULL,
11694         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11695         .tokens = {
11696                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11697                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11698                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11699                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11700                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11701                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11702                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11703                 NULL,
11704         },
11705 };
11706
11707 /* Enable/disable l2 tunnel */
11708 struct cmd_config_l2_tunnel_en_dis_result {
11709         cmdline_fixed_string_t port;
11710         cmdline_fixed_string_t config;
11711         cmdline_fixed_string_t all;
11712         uint8_t id;
11713         cmdline_fixed_string_t l2_tunnel;
11714         cmdline_fixed_string_t l2_tunnel_type;
11715         cmdline_fixed_string_t en_dis;
11716 };
11717
11718 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11719         TOKEN_STRING_INITIALIZER
11720                 (struct cmd_config_l2_tunnel_en_dis_result,
11721                  port, "port");
11722 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11723         TOKEN_STRING_INITIALIZER
11724                 (struct cmd_config_l2_tunnel_en_dis_result,
11725                  config, "config");
11726 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11727         TOKEN_STRING_INITIALIZER
11728                 (struct cmd_config_l2_tunnel_en_dis_result,
11729                  all, "all");
11730 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11731         TOKEN_NUM_INITIALIZER
11732                 (struct cmd_config_l2_tunnel_en_dis_result,
11733                  id, UINT8);
11734 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11735         TOKEN_STRING_INITIALIZER
11736                 (struct cmd_config_l2_tunnel_en_dis_result,
11737                  l2_tunnel, "l2-tunnel");
11738 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11739         TOKEN_STRING_INITIALIZER
11740                 (struct cmd_config_l2_tunnel_en_dis_result,
11741                  l2_tunnel_type, "E-tag");
11742 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11743         TOKEN_STRING_INITIALIZER
11744                 (struct cmd_config_l2_tunnel_en_dis_result,
11745                  en_dis, "enable#disable");
11746
11747 /* enable/disable l2 tunnel for all ports */
11748 static void
11749 cmd_config_l2_tunnel_en_dis_all_parsed(
11750         void *parsed_result,
11751         __attribute__((unused)) struct cmdline *cl,
11752         __attribute__((unused)) void *data)
11753 {
11754         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11755         struct rte_eth_l2_tunnel_conf entry;
11756         portid_t pid;
11757         uint8_t en;
11758
11759         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11760
11761         if (!strcmp("enable", res->en_dis))
11762                 en = 1;
11763         else
11764                 en = 0;
11765
11766         RTE_ETH_FOREACH_DEV(pid) {
11767                 rte_eth_dev_l2_tunnel_offload_set(pid,
11768                                                   &entry,
11769                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11770                                                   en);
11771         }
11772 }
11773
11774 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11775         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11776         .data = NULL,
11777         .help_str = "port config all l2-tunnel E-tag enable|disable",
11778         .tokens = {
11779                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11780                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11781                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11782                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11783                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11784                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11785                 NULL,
11786         },
11787 };
11788
11789 /* enable/disable l2 tunnel for a port */
11790 static void
11791 cmd_config_l2_tunnel_en_dis_specific_parsed(
11792         void *parsed_result,
11793         __attribute__((unused)) struct cmdline *cl,
11794         __attribute__((unused)) void *data)
11795 {
11796         struct cmd_config_l2_tunnel_en_dis_result *res =
11797                 parsed_result;
11798         struct rte_eth_l2_tunnel_conf entry;
11799
11800         if (port_id_is_invalid(res->id, ENABLED_WARN))
11801                 return;
11802
11803         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11804
11805         if (!strcmp("enable", res->en_dis))
11806                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11807                                                   &entry,
11808                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11809                                                   1);
11810         else
11811                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11812                                                   &entry,
11813                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11814                                                   0);
11815 }
11816
11817 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11818         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11819         .data = NULL,
11820         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11821         .tokens = {
11822                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11823                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11824                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11825                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11826                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11827                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11828                 NULL,
11829         },
11830 };
11831
11832 /* E-tag configuration */
11833
11834 /* Common result structure for all E-tag configuration */
11835 struct cmd_config_e_tag_result {
11836         cmdline_fixed_string_t e_tag;
11837         cmdline_fixed_string_t set;
11838         cmdline_fixed_string_t insertion;
11839         cmdline_fixed_string_t stripping;
11840         cmdline_fixed_string_t forwarding;
11841         cmdline_fixed_string_t filter;
11842         cmdline_fixed_string_t add;
11843         cmdline_fixed_string_t del;
11844         cmdline_fixed_string_t on;
11845         cmdline_fixed_string_t off;
11846         cmdline_fixed_string_t on_off;
11847         cmdline_fixed_string_t port_tag_id;
11848         uint32_t port_tag_id_val;
11849         cmdline_fixed_string_t e_tag_id;
11850         uint16_t e_tag_id_val;
11851         cmdline_fixed_string_t dst_pool;
11852         uint8_t dst_pool_val;
11853         cmdline_fixed_string_t port;
11854         portid_t port_id;
11855         cmdline_fixed_string_t vf;
11856         uint8_t vf_id;
11857 };
11858
11859 /* Common CLI fields for all E-tag configuration */
11860 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11861         TOKEN_STRING_INITIALIZER
11862                 (struct cmd_config_e_tag_result,
11863                  e_tag, "E-tag");
11864 cmdline_parse_token_string_t cmd_config_e_tag_set =
11865         TOKEN_STRING_INITIALIZER
11866                 (struct cmd_config_e_tag_result,
11867                  set, "set");
11868 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11869         TOKEN_STRING_INITIALIZER
11870                 (struct cmd_config_e_tag_result,
11871                  insertion, "insertion");
11872 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11873         TOKEN_STRING_INITIALIZER
11874                 (struct cmd_config_e_tag_result,
11875                  stripping, "stripping");
11876 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11877         TOKEN_STRING_INITIALIZER
11878                 (struct cmd_config_e_tag_result,
11879                  forwarding, "forwarding");
11880 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11881         TOKEN_STRING_INITIALIZER
11882                 (struct cmd_config_e_tag_result,
11883                  filter, "filter");
11884 cmdline_parse_token_string_t cmd_config_e_tag_add =
11885         TOKEN_STRING_INITIALIZER
11886                 (struct cmd_config_e_tag_result,
11887                  add, "add");
11888 cmdline_parse_token_string_t cmd_config_e_tag_del =
11889         TOKEN_STRING_INITIALIZER
11890                 (struct cmd_config_e_tag_result,
11891                  del, "del");
11892 cmdline_parse_token_string_t cmd_config_e_tag_on =
11893         TOKEN_STRING_INITIALIZER
11894                 (struct cmd_config_e_tag_result,
11895                  on, "on");
11896 cmdline_parse_token_string_t cmd_config_e_tag_off =
11897         TOKEN_STRING_INITIALIZER
11898                 (struct cmd_config_e_tag_result,
11899                  off, "off");
11900 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11901         TOKEN_STRING_INITIALIZER
11902                 (struct cmd_config_e_tag_result,
11903                  on_off, "on#off");
11904 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11905         TOKEN_STRING_INITIALIZER
11906                 (struct cmd_config_e_tag_result,
11907                  port_tag_id, "port-tag-id");
11908 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11909         TOKEN_NUM_INITIALIZER
11910                 (struct cmd_config_e_tag_result,
11911                  port_tag_id_val, UINT32);
11912 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11913         TOKEN_STRING_INITIALIZER
11914                 (struct cmd_config_e_tag_result,
11915                  e_tag_id, "e-tag-id");
11916 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11917         TOKEN_NUM_INITIALIZER
11918                 (struct cmd_config_e_tag_result,
11919                  e_tag_id_val, UINT16);
11920 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11921         TOKEN_STRING_INITIALIZER
11922                 (struct cmd_config_e_tag_result,
11923                  dst_pool, "dst-pool");
11924 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11925         TOKEN_NUM_INITIALIZER
11926                 (struct cmd_config_e_tag_result,
11927                  dst_pool_val, UINT8);
11928 cmdline_parse_token_string_t cmd_config_e_tag_port =
11929         TOKEN_STRING_INITIALIZER
11930                 (struct cmd_config_e_tag_result,
11931                  port, "port");
11932 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11933         TOKEN_NUM_INITIALIZER
11934                 (struct cmd_config_e_tag_result,
11935                  port_id, UINT16);
11936 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11937         TOKEN_STRING_INITIALIZER
11938                 (struct cmd_config_e_tag_result,
11939                  vf, "vf");
11940 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11941         TOKEN_NUM_INITIALIZER
11942                 (struct cmd_config_e_tag_result,
11943                  vf_id, UINT8);
11944
11945 /* E-tag insertion configuration */
11946 static void
11947 cmd_config_e_tag_insertion_en_parsed(
11948         void *parsed_result,
11949         __attribute__((unused)) struct cmdline *cl,
11950         __attribute__((unused)) void *data)
11951 {
11952         struct cmd_config_e_tag_result *res =
11953                 parsed_result;
11954         struct rte_eth_l2_tunnel_conf entry;
11955
11956         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11957                 return;
11958
11959         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11960         entry.tunnel_id = res->port_tag_id_val;
11961         entry.vf_id = res->vf_id;
11962         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11963                                           &entry,
11964                                           ETH_L2_TUNNEL_INSERTION_MASK,
11965                                           1);
11966 }
11967
11968 static void
11969 cmd_config_e_tag_insertion_dis_parsed(
11970         void *parsed_result,
11971         __attribute__((unused)) struct cmdline *cl,
11972         __attribute__((unused)) void *data)
11973 {
11974         struct cmd_config_e_tag_result *res =
11975                 parsed_result;
11976         struct rte_eth_l2_tunnel_conf entry;
11977
11978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11979                 return;
11980
11981         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11982         entry.vf_id = res->vf_id;
11983
11984         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11985                                           &entry,
11986                                           ETH_L2_TUNNEL_INSERTION_MASK,
11987                                           0);
11988 }
11989
11990 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11991         .f = cmd_config_e_tag_insertion_en_parsed,
11992         .data = NULL,
11993         .help_str = "E-tag ... : E-tag insertion enable",
11994         .tokens = {
11995                 (void *)&cmd_config_e_tag_e_tag,
11996                 (void *)&cmd_config_e_tag_set,
11997                 (void *)&cmd_config_e_tag_insertion,
11998                 (void *)&cmd_config_e_tag_on,
11999                 (void *)&cmd_config_e_tag_port_tag_id,
12000                 (void *)&cmd_config_e_tag_port_tag_id_val,
12001                 (void *)&cmd_config_e_tag_port,
12002                 (void *)&cmd_config_e_tag_port_id,
12003                 (void *)&cmd_config_e_tag_vf,
12004                 (void *)&cmd_config_e_tag_vf_id,
12005                 NULL,
12006         },
12007 };
12008
12009 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12010         .f = cmd_config_e_tag_insertion_dis_parsed,
12011         .data = NULL,
12012         .help_str = "E-tag ... : E-tag insertion disable",
12013         .tokens = {
12014                 (void *)&cmd_config_e_tag_e_tag,
12015                 (void *)&cmd_config_e_tag_set,
12016                 (void *)&cmd_config_e_tag_insertion,
12017                 (void *)&cmd_config_e_tag_off,
12018                 (void *)&cmd_config_e_tag_port,
12019                 (void *)&cmd_config_e_tag_port_id,
12020                 (void *)&cmd_config_e_tag_vf,
12021                 (void *)&cmd_config_e_tag_vf_id,
12022                 NULL,
12023         },
12024 };
12025
12026 /* E-tag stripping configuration */
12027 static void
12028 cmd_config_e_tag_stripping_parsed(
12029         void *parsed_result,
12030         __attribute__((unused)) struct cmdline *cl,
12031         __attribute__((unused)) void *data)
12032 {
12033         struct cmd_config_e_tag_result *res =
12034                 parsed_result;
12035         struct rte_eth_l2_tunnel_conf entry;
12036
12037         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12038                 return;
12039
12040         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12041
12042         if (!strcmp(res->on_off, "on"))
12043                 rte_eth_dev_l2_tunnel_offload_set
12044                         (res->port_id,
12045                          &entry,
12046                          ETH_L2_TUNNEL_STRIPPING_MASK,
12047                          1);
12048         else
12049                 rte_eth_dev_l2_tunnel_offload_set
12050                         (res->port_id,
12051                          &entry,
12052                          ETH_L2_TUNNEL_STRIPPING_MASK,
12053                          0);
12054 }
12055
12056 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12057         .f = cmd_config_e_tag_stripping_parsed,
12058         .data = NULL,
12059         .help_str = "E-tag ... : E-tag stripping enable/disable",
12060         .tokens = {
12061                 (void *)&cmd_config_e_tag_e_tag,
12062                 (void *)&cmd_config_e_tag_set,
12063                 (void *)&cmd_config_e_tag_stripping,
12064                 (void *)&cmd_config_e_tag_on_off,
12065                 (void *)&cmd_config_e_tag_port,
12066                 (void *)&cmd_config_e_tag_port_id,
12067                 NULL,
12068         },
12069 };
12070
12071 /* E-tag forwarding configuration */
12072 static void
12073 cmd_config_e_tag_forwarding_parsed(
12074         void *parsed_result,
12075         __attribute__((unused)) struct cmdline *cl,
12076         __attribute__((unused)) void *data)
12077 {
12078         struct cmd_config_e_tag_result *res = parsed_result;
12079         struct rte_eth_l2_tunnel_conf entry;
12080
12081         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12082                 return;
12083
12084         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12085
12086         if (!strcmp(res->on_off, "on"))
12087                 rte_eth_dev_l2_tunnel_offload_set
12088                         (res->port_id,
12089                          &entry,
12090                          ETH_L2_TUNNEL_FORWARDING_MASK,
12091                          1);
12092         else
12093                 rte_eth_dev_l2_tunnel_offload_set
12094                         (res->port_id,
12095                          &entry,
12096                          ETH_L2_TUNNEL_FORWARDING_MASK,
12097                          0);
12098 }
12099
12100 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12101         .f = cmd_config_e_tag_forwarding_parsed,
12102         .data = NULL,
12103         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12104         .tokens = {
12105                 (void *)&cmd_config_e_tag_e_tag,
12106                 (void *)&cmd_config_e_tag_set,
12107                 (void *)&cmd_config_e_tag_forwarding,
12108                 (void *)&cmd_config_e_tag_on_off,
12109                 (void *)&cmd_config_e_tag_port,
12110                 (void *)&cmd_config_e_tag_port_id,
12111                 NULL,
12112         },
12113 };
12114
12115 /* E-tag filter configuration */
12116 static void
12117 cmd_config_e_tag_filter_add_parsed(
12118         void *parsed_result,
12119         __attribute__((unused)) struct cmdline *cl,
12120         __attribute__((unused)) void *data)
12121 {
12122         struct cmd_config_e_tag_result *res = parsed_result;
12123         struct rte_eth_l2_tunnel_conf entry;
12124         int ret = 0;
12125
12126         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12127                 return;
12128
12129         if (res->e_tag_id_val > 0x3fff) {
12130                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12131                 return;
12132         }
12133
12134         ret = rte_eth_dev_filter_supported(res->port_id,
12135                                            RTE_ETH_FILTER_L2_TUNNEL);
12136         if (ret < 0) {
12137                 printf("E-tag filter is not supported on port %u.\n",
12138                        res->port_id);
12139                 return;
12140         }
12141
12142         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12143         entry.tunnel_id = res->e_tag_id_val;
12144         entry.pool = res->dst_pool_val;
12145
12146         ret = rte_eth_dev_filter_ctrl(res->port_id,
12147                                       RTE_ETH_FILTER_L2_TUNNEL,
12148                                       RTE_ETH_FILTER_ADD,
12149                                       &entry);
12150         if (ret < 0)
12151                 printf("E-tag filter programming error: (%s)\n",
12152                        strerror(-ret));
12153 }
12154
12155 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12156         .f = cmd_config_e_tag_filter_add_parsed,
12157         .data = NULL,
12158         .help_str = "E-tag ... : E-tag filter add",
12159         .tokens = {
12160                 (void *)&cmd_config_e_tag_e_tag,
12161                 (void *)&cmd_config_e_tag_set,
12162                 (void *)&cmd_config_e_tag_filter,
12163                 (void *)&cmd_config_e_tag_add,
12164                 (void *)&cmd_config_e_tag_e_tag_id,
12165                 (void *)&cmd_config_e_tag_e_tag_id_val,
12166                 (void *)&cmd_config_e_tag_dst_pool,
12167                 (void *)&cmd_config_e_tag_dst_pool_val,
12168                 (void *)&cmd_config_e_tag_port,
12169                 (void *)&cmd_config_e_tag_port_id,
12170                 NULL,
12171         },
12172 };
12173
12174 static void
12175 cmd_config_e_tag_filter_del_parsed(
12176         void *parsed_result,
12177         __attribute__((unused)) struct cmdline *cl,
12178         __attribute__((unused)) void *data)
12179 {
12180         struct cmd_config_e_tag_result *res = parsed_result;
12181         struct rte_eth_l2_tunnel_conf entry;
12182         int ret = 0;
12183
12184         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12185                 return;
12186
12187         if (res->e_tag_id_val > 0x3fff) {
12188                 printf("e-tag-id must be less than 0x3fff.\n");
12189                 return;
12190         }
12191
12192         ret = rte_eth_dev_filter_supported(res->port_id,
12193                                            RTE_ETH_FILTER_L2_TUNNEL);
12194         if (ret < 0) {
12195                 printf("E-tag filter is not supported on port %u.\n",
12196                        res->port_id);
12197                 return;
12198         }
12199
12200         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12201         entry.tunnel_id = res->e_tag_id_val;
12202
12203         ret = rte_eth_dev_filter_ctrl(res->port_id,
12204                                       RTE_ETH_FILTER_L2_TUNNEL,
12205                                       RTE_ETH_FILTER_DELETE,
12206                                       &entry);
12207         if (ret < 0)
12208                 printf("E-tag filter programming error: (%s)\n",
12209                        strerror(-ret));
12210 }
12211
12212 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12213         .f = cmd_config_e_tag_filter_del_parsed,
12214         .data = NULL,
12215         .help_str = "E-tag ... : E-tag filter delete",
12216         .tokens = {
12217                 (void *)&cmd_config_e_tag_e_tag,
12218                 (void *)&cmd_config_e_tag_set,
12219                 (void *)&cmd_config_e_tag_filter,
12220                 (void *)&cmd_config_e_tag_del,
12221                 (void *)&cmd_config_e_tag_e_tag_id,
12222                 (void *)&cmd_config_e_tag_e_tag_id_val,
12223                 (void *)&cmd_config_e_tag_port,
12224                 (void *)&cmd_config_e_tag_port_id,
12225                 NULL,
12226         },
12227 };
12228
12229 /* vf vlan anti spoof configuration */
12230
12231 /* Common result structure for vf vlan anti spoof */
12232 struct cmd_vf_vlan_anti_spoof_result {
12233         cmdline_fixed_string_t set;
12234         cmdline_fixed_string_t vf;
12235         cmdline_fixed_string_t vlan;
12236         cmdline_fixed_string_t antispoof;
12237         portid_t port_id;
12238         uint32_t vf_id;
12239         cmdline_fixed_string_t on_off;
12240 };
12241
12242 /* Common CLI fields for vf vlan anti spoof enable disable */
12243 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12244         TOKEN_STRING_INITIALIZER
12245                 (struct cmd_vf_vlan_anti_spoof_result,
12246                  set, "set");
12247 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12248         TOKEN_STRING_INITIALIZER
12249                 (struct cmd_vf_vlan_anti_spoof_result,
12250                  vf, "vf");
12251 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12252         TOKEN_STRING_INITIALIZER
12253                 (struct cmd_vf_vlan_anti_spoof_result,
12254                  vlan, "vlan");
12255 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12256         TOKEN_STRING_INITIALIZER
12257                 (struct cmd_vf_vlan_anti_spoof_result,
12258                  antispoof, "antispoof");
12259 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12260         TOKEN_NUM_INITIALIZER
12261                 (struct cmd_vf_vlan_anti_spoof_result,
12262                  port_id, UINT16);
12263 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12264         TOKEN_NUM_INITIALIZER
12265                 (struct cmd_vf_vlan_anti_spoof_result,
12266                  vf_id, UINT32);
12267 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12268         TOKEN_STRING_INITIALIZER
12269                 (struct cmd_vf_vlan_anti_spoof_result,
12270                  on_off, "on#off");
12271
12272 static void
12273 cmd_set_vf_vlan_anti_spoof_parsed(
12274         void *parsed_result,
12275         __attribute__((unused)) struct cmdline *cl,
12276         __attribute__((unused)) void *data)
12277 {
12278         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12279         int ret = -ENOTSUP;
12280
12281         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12282
12283         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12284                 return;
12285
12286 #ifdef RTE_LIBRTE_IXGBE_PMD
12287         if (ret == -ENOTSUP)
12288                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12289                                 res->vf_id, is_on);
12290 #endif
12291 #ifdef RTE_LIBRTE_I40E_PMD
12292         if (ret == -ENOTSUP)
12293                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12294                                 res->vf_id, is_on);
12295 #endif
12296 #ifdef RTE_LIBRTE_BNXT_PMD
12297         if (ret == -ENOTSUP)
12298                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12299                                 res->vf_id, is_on);
12300 #endif
12301
12302         switch (ret) {
12303         case 0:
12304                 break;
12305         case -EINVAL:
12306                 printf("invalid vf_id %d\n", res->vf_id);
12307                 break;
12308         case -ENODEV:
12309                 printf("invalid port_id %d\n", res->port_id);
12310                 break;
12311         case -ENOTSUP:
12312                 printf("function not implemented\n");
12313                 break;
12314         default:
12315                 printf("programming error: (%s)\n", strerror(-ret));
12316         }
12317 }
12318
12319 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12320         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12321         .data = NULL,
12322         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12323         .tokens = {
12324                 (void *)&cmd_vf_vlan_anti_spoof_set,
12325                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12326                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12327                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12328                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12329                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12330                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12331                 NULL,
12332         },
12333 };
12334
12335 /* vf mac anti spoof configuration */
12336
12337 /* Common result structure for vf mac anti spoof */
12338 struct cmd_vf_mac_anti_spoof_result {
12339         cmdline_fixed_string_t set;
12340         cmdline_fixed_string_t vf;
12341         cmdline_fixed_string_t mac;
12342         cmdline_fixed_string_t antispoof;
12343         portid_t port_id;
12344         uint32_t vf_id;
12345         cmdline_fixed_string_t on_off;
12346 };
12347
12348 /* Common CLI fields for vf mac anti spoof enable disable */
12349 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12350         TOKEN_STRING_INITIALIZER
12351                 (struct cmd_vf_mac_anti_spoof_result,
12352                  set, "set");
12353 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12354         TOKEN_STRING_INITIALIZER
12355                 (struct cmd_vf_mac_anti_spoof_result,
12356                  vf, "vf");
12357 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12358         TOKEN_STRING_INITIALIZER
12359                 (struct cmd_vf_mac_anti_spoof_result,
12360                  mac, "mac");
12361 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12362         TOKEN_STRING_INITIALIZER
12363                 (struct cmd_vf_mac_anti_spoof_result,
12364                  antispoof, "antispoof");
12365 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12366         TOKEN_NUM_INITIALIZER
12367                 (struct cmd_vf_mac_anti_spoof_result,
12368                  port_id, UINT16);
12369 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12370         TOKEN_NUM_INITIALIZER
12371                 (struct cmd_vf_mac_anti_spoof_result,
12372                  vf_id, UINT32);
12373 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12374         TOKEN_STRING_INITIALIZER
12375                 (struct cmd_vf_mac_anti_spoof_result,
12376                  on_off, "on#off");
12377
12378 static void
12379 cmd_set_vf_mac_anti_spoof_parsed(
12380         void *parsed_result,
12381         __attribute__((unused)) struct cmdline *cl,
12382         __attribute__((unused)) void *data)
12383 {
12384         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12385         int ret = -ENOTSUP;
12386
12387         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12388
12389         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12390                 return;
12391
12392 #ifdef RTE_LIBRTE_IXGBE_PMD
12393         if (ret == -ENOTSUP)
12394                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12395                         res->vf_id, is_on);
12396 #endif
12397 #ifdef RTE_LIBRTE_I40E_PMD
12398         if (ret == -ENOTSUP)
12399                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12400                         res->vf_id, is_on);
12401 #endif
12402 #ifdef RTE_LIBRTE_BNXT_PMD
12403         if (ret == -ENOTSUP)
12404                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12405                         res->vf_id, is_on);
12406 #endif
12407
12408         switch (ret) {
12409         case 0:
12410                 break;
12411         case -EINVAL:
12412                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12413                 break;
12414         case -ENODEV:
12415                 printf("invalid port_id %d\n", res->port_id);
12416                 break;
12417         case -ENOTSUP:
12418                 printf("function not implemented\n");
12419                 break;
12420         default:
12421                 printf("programming error: (%s)\n", strerror(-ret));
12422         }
12423 }
12424
12425 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12426         .f = cmd_set_vf_mac_anti_spoof_parsed,
12427         .data = NULL,
12428         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12429         .tokens = {
12430                 (void *)&cmd_vf_mac_anti_spoof_set,
12431                 (void *)&cmd_vf_mac_anti_spoof_vf,
12432                 (void *)&cmd_vf_mac_anti_spoof_mac,
12433                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12434                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12435                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12436                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12437                 NULL,
12438         },
12439 };
12440
12441 /* vf vlan strip queue configuration */
12442
12443 /* Common result structure for vf mac anti spoof */
12444 struct cmd_vf_vlan_stripq_result {
12445         cmdline_fixed_string_t set;
12446         cmdline_fixed_string_t vf;
12447         cmdline_fixed_string_t vlan;
12448         cmdline_fixed_string_t stripq;
12449         portid_t port_id;
12450         uint16_t vf_id;
12451         cmdline_fixed_string_t on_off;
12452 };
12453
12454 /* Common CLI fields for vf vlan strip enable disable */
12455 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12456         TOKEN_STRING_INITIALIZER
12457                 (struct cmd_vf_vlan_stripq_result,
12458                  set, "set");
12459 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12460         TOKEN_STRING_INITIALIZER
12461                 (struct cmd_vf_vlan_stripq_result,
12462                  vf, "vf");
12463 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12464         TOKEN_STRING_INITIALIZER
12465                 (struct cmd_vf_vlan_stripq_result,
12466                  vlan, "vlan");
12467 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12468         TOKEN_STRING_INITIALIZER
12469                 (struct cmd_vf_vlan_stripq_result,
12470                  stripq, "stripq");
12471 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12472         TOKEN_NUM_INITIALIZER
12473                 (struct cmd_vf_vlan_stripq_result,
12474                  port_id, UINT16);
12475 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12476         TOKEN_NUM_INITIALIZER
12477                 (struct cmd_vf_vlan_stripq_result,
12478                  vf_id, UINT16);
12479 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12480         TOKEN_STRING_INITIALIZER
12481                 (struct cmd_vf_vlan_stripq_result,
12482                  on_off, "on#off");
12483
12484 static void
12485 cmd_set_vf_vlan_stripq_parsed(
12486         void *parsed_result,
12487         __attribute__((unused)) struct cmdline *cl,
12488         __attribute__((unused)) void *data)
12489 {
12490         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12491         int ret = -ENOTSUP;
12492
12493         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12494
12495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12496                 return;
12497
12498 #ifdef RTE_LIBRTE_IXGBE_PMD
12499         if (ret == -ENOTSUP)
12500                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12501                         res->vf_id, is_on);
12502 #endif
12503 #ifdef RTE_LIBRTE_I40E_PMD
12504         if (ret == -ENOTSUP)
12505                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12506                         res->vf_id, is_on);
12507 #endif
12508 #ifdef RTE_LIBRTE_BNXT_PMD
12509         if (ret == -ENOTSUP)
12510                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12511                         res->vf_id, is_on);
12512 #endif
12513
12514         switch (ret) {
12515         case 0:
12516                 break;
12517         case -EINVAL:
12518                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12519                 break;
12520         case -ENODEV:
12521                 printf("invalid port_id %d\n", res->port_id);
12522                 break;
12523         case -ENOTSUP:
12524                 printf("function not implemented\n");
12525                 break;
12526         default:
12527                 printf("programming error: (%s)\n", strerror(-ret));
12528         }
12529 }
12530
12531 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12532         .f = cmd_set_vf_vlan_stripq_parsed,
12533         .data = NULL,
12534         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12535         .tokens = {
12536                 (void *)&cmd_vf_vlan_stripq_set,
12537                 (void *)&cmd_vf_vlan_stripq_vf,
12538                 (void *)&cmd_vf_vlan_stripq_vlan,
12539                 (void *)&cmd_vf_vlan_stripq_stripq,
12540                 (void *)&cmd_vf_vlan_stripq_port_id,
12541                 (void *)&cmd_vf_vlan_stripq_vf_id,
12542                 (void *)&cmd_vf_vlan_stripq_on_off,
12543                 NULL,
12544         },
12545 };
12546
12547 /* vf vlan insert configuration */
12548
12549 /* Common result structure for vf vlan insert */
12550 struct cmd_vf_vlan_insert_result {
12551         cmdline_fixed_string_t set;
12552         cmdline_fixed_string_t vf;
12553         cmdline_fixed_string_t vlan;
12554         cmdline_fixed_string_t insert;
12555         portid_t port_id;
12556         uint16_t vf_id;
12557         uint16_t vlan_id;
12558 };
12559
12560 /* Common CLI fields for vf vlan insert enable disable */
12561 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12562         TOKEN_STRING_INITIALIZER
12563                 (struct cmd_vf_vlan_insert_result,
12564                  set, "set");
12565 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12566         TOKEN_STRING_INITIALIZER
12567                 (struct cmd_vf_vlan_insert_result,
12568                  vf, "vf");
12569 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12570         TOKEN_STRING_INITIALIZER
12571                 (struct cmd_vf_vlan_insert_result,
12572                  vlan, "vlan");
12573 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12574         TOKEN_STRING_INITIALIZER
12575                 (struct cmd_vf_vlan_insert_result,
12576                  insert, "insert");
12577 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12578         TOKEN_NUM_INITIALIZER
12579                 (struct cmd_vf_vlan_insert_result,
12580                  port_id, UINT16);
12581 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12582         TOKEN_NUM_INITIALIZER
12583                 (struct cmd_vf_vlan_insert_result,
12584                  vf_id, UINT16);
12585 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12586         TOKEN_NUM_INITIALIZER
12587                 (struct cmd_vf_vlan_insert_result,
12588                  vlan_id, UINT16);
12589
12590 static void
12591 cmd_set_vf_vlan_insert_parsed(
12592         void *parsed_result,
12593         __attribute__((unused)) struct cmdline *cl,
12594         __attribute__((unused)) void *data)
12595 {
12596         struct cmd_vf_vlan_insert_result *res = parsed_result;
12597         int ret = -ENOTSUP;
12598
12599         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12600                 return;
12601
12602 #ifdef RTE_LIBRTE_IXGBE_PMD
12603         if (ret == -ENOTSUP)
12604                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12605                         res->vlan_id);
12606 #endif
12607 #ifdef RTE_LIBRTE_I40E_PMD
12608         if (ret == -ENOTSUP)
12609                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12610                         res->vlan_id);
12611 #endif
12612 #ifdef RTE_LIBRTE_BNXT_PMD
12613         if (ret == -ENOTSUP)
12614                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12615                         res->vlan_id);
12616 #endif
12617
12618         switch (ret) {
12619         case 0:
12620                 break;
12621         case -EINVAL:
12622                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12623                 break;
12624         case -ENODEV:
12625                 printf("invalid port_id %d\n", res->port_id);
12626                 break;
12627         case -ENOTSUP:
12628                 printf("function not implemented\n");
12629                 break;
12630         default:
12631                 printf("programming error: (%s)\n", strerror(-ret));
12632         }
12633 }
12634
12635 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12636         .f = cmd_set_vf_vlan_insert_parsed,
12637         .data = NULL,
12638         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12639         .tokens = {
12640                 (void *)&cmd_vf_vlan_insert_set,
12641                 (void *)&cmd_vf_vlan_insert_vf,
12642                 (void *)&cmd_vf_vlan_insert_vlan,
12643                 (void *)&cmd_vf_vlan_insert_insert,
12644                 (void *)&cmd_vf_vlan_insert_port_id,
12645                 (void *)&cmd_vf_vlan_insert_vf_id,
12646                 (void *)&cmd_vf_vlan_insert_vlan_id,
12647                 NULL,
12648         },
12649 };
12650
12651 /* tx loopback configuration */
12652
12653 /* Common result structure for tx loopback */
12654 struct cmd_tx_loopback_result {
12655         cmdline_fixed_string_t set;
12656         cmdline_fixed_string_t tx;
12657         cmdline_fixed_string_t loopback;
12658         portid_t port_id;
12659         cmdline_fixed_string_t on_off;
12660 };
12661
12662 /* Common CLI fields for tx loopback enable disable */
12663 cmdline_parse_token_string_t cmd_tx_loopback_set =
12664         TOKEN_STRING_INITIALIZER
12665                 (struct cmd_tx_loopback_result,
12666                  set, "set");
12667 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12668         TOKEN_STRING_INITIALIZER
12669                 (struct cmd_tx_loopback_result,
12670                  tx, "tx");
12671 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12672         TOKEN_STRING_INITIALIZER
12673                 (struct cmd_tx_loopback_result,
12674                  loopback, "loopback");
12675 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12676         TOKEN_NUM_INITIALIZER
12677                 (struct cmd_tx_loopback_result,
12678                  port_id, UINT16);
12679 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12680         TOKEN_STRING_INITIALIZER
12681                 (struct cmd_tx_loopback_result,
12682                  on_off, "on#off");
12683
12684 static void
12685 cmd_set_tx_loopback_parsed(
12686         void *parsed_result,
12687         __attribute__((unused)) struct cmdline *cl,
12688         __attribute__((unused)) void *data)
12689 {
12690         struct cmd_tx_loopback_result *res = parsed_result;
12691         int ret = -ENOTSUP;
12692
12693         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12694
12695         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12696                 return;
12697
12698 #ifdef RTE_LIBRTE_IXGBE_PMD
12699         if (ret == -ENOTSUP)
12700                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12701 #endif
12702 #ifdef RTE_LIBRTE_I40E_PMD
12703         if (ret == -ENOTSUP)
12704                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12705 #endif
12706 #ifdef RTE_LIBRTE_BNXT_PMD
12707         if (ret == -ENOTSUP)
12708                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12709 #endif
12710
12711         switch (ret) {
12712         case 0:
12713                 break;
12714         case -EINVAL:
12715                 printf("invalid is_on %d\n", is_on);
12716                 break;
12717         case -ENODEV:
12718                 printf("invalid port_id %d\n", res->port_id);
12719                 break;
12720         case -ENOTSUP:
12721                 printf("function not implemented\n");
12722                 break;
12723         default:
12724                 printf("programming error: (%s)\n", strerror(-ret));
12725         }
12726 }
12727
12728 cmdline_parse_inst_t cmd_set_tx_loopback = {
12729         .f = cmd_set_tx_loopback_parsed,
12730         .data = NULL,
12731         .help_str = "set tx loopback <port_id> on|off",
12732         .tokens = {
12733                 (void *)&cmd_tx_loopback_set,
12734                 (void *)&cmd_tx_loopback_tx,
12735                 (void *)&cmd_tx_loopback_loopback,
12736                 (void *)&cmd_tx_loopback_port_id,
12737                 (void *)&cmd_tx_loopback_on_off,
12738                 NULL,
12739         },
12740 };
12741
12742 /* all queues drop enable configuration */
12743
12744 /* Common result structure for all queues drop enable */
12745 struct cmd_all_queues_drop_en_result {
12746         cmdline_fixed_string_t set;
12747         cmdline_fixed_string_t all;
12748         cmdline_fixed_string_t queues;
12749         cmdline_fixed_string_t drop;
12750         portid_t port_id;
12751         cmdline_fixed_string_t on_off;
12752 };
12753
12754 /* Common CLI fields for tx loopback enable disable */
12755 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12756         TOKEN_STRING_INITIALIZER
12757                 (struct cmd_all_queues_drop_en_result,
12758                  set, "set");
12759 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12760         TOKEN_STRING_INITIALIZER
12761                 (struct cmd_all_queues_drop_en_result,
12762                  all, "all");
12763 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12764         TOKEN_STRING_INITIALIZER
12765                 (struct cmd_all_queues_drop_en_result,
12766                  queues, "queues");
12767 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12768         TOKEN_STRING_INITIALIZER
12769                 (struct cmd_all_queues_drop_en_result,
12770                  drop, "drop");
12771 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12772         TOKEN_NUM_INITIALIZER
12773                 (struct cmd_all_queues_drop_en_result,
12774                  port_id, UINT16);
12775 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12776         TOKEN_STRING_INITIALIZER
12777                 (struct cmd_all_queues_drop_en_result,
12778                  on_off, "on#off");
12779
12780 static void
12781 cmd_set_all_queues_drop_en_parsed(
12782         void *parsed_result,
12783         __attribute__((unused)) struct cmdline *cl,
12784         __attribute__((unused)) void *data)
12785 {
12786         struct cmd_all_queues_drop_en_result *res = parsed_result;
12787         int ret = -ENOTSUP;
12788         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12789
12790         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12791                 return;
12792
12793 #ifdef RTE_LIBRTE_IXGBE_PMD
12794         if (ret == -ENOTSUP)
12795                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12796 #endif
12797 #ifdef RTE_LIBRTE_BNXT_PMD
12798         if (ret == -ENOTSUP)
12799                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12800 #endif
12801         switch (ret) {
12802         case 0:
12803                 break;
12804         case -EINVAL:
12805                 printf("invalid is_on %d\n", is_on);
12806                 break;
12807         case -ENODEV:
12808                 printf("invalid port_id %d\n", res->port_id);
12809                 break;
12810         case -ENOTSUP:
12811                 printf("function not implemented\n");
12812                 break;
12813         default:
12814                 printf("programming error: (%s)\n", strerror(-ret));
12815         }
12816 }
12817
12818 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12819         .f = cmd_set_all_queues_drop_en_parsed,
12820         .data = NULL,
12821         .help_str = "set all queues drop <port_id> on|off",
12822         .tokens = {
12823                 (void *)&cmd_all_queues_drop_en_set,
12824                 (void *)&cmd_all_queues_drop_en_all,
12825                 (void *)&cmd_all_queues_drop_en_queues,
12826                 (void *)&cmd_all_queues_drop_en_drop,
12827                 (void *)&cmd_all_queues_drop_en_port_id,
12828                 (void *)&cmd_all_queues_drop_en_on_off,
12829                 NULL,
12830         },
12831 };
12832
12833 /* vf split drop enable configuration */
12834
12835 /* Common result structure for vf split drop enable */
12836 struct cmd_vf_split_drop_en_result {
12837         cmdline_fixed_string_t set;
12838         cmdline_fixed_string_t vf;
12839         cmdline_fixed_string_t split;
12840         cmdline_fixed_string_t drop;
12841         portid_t port_id;
12842         uint16_t vf_id;
12843         cmdline_fixed_string_t on_off;
12844 };
12845
12846 /* Common CLI fields for vf split drop enable disable */
12847 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12848         TOKEN_STRING_INITIALIZER
12849                 (struct cmd_vf_split_drop_en_result,
12850                  set, "set");
12851 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12852         TOKEN_STRING_INITIALIZER
12853                 (struct cmd_vf_split_drop_en_result,
12854                  vf, "vf");
12855 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12856         TOKEN_STRING_INITIALIZER
12857                 (struct cmd_vf_split_drop_en_result,
12858                  split, "split");
12859 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12860         TOKEN_STRING_INITIALIZER
12861                 (struct cmd_vf_split_drop_en_result,
12862                  drop, "drop");
12863 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12864         TOKEN_NUM_INITIALIZER
12865                 (struct cmd_vf_split_drop_en_result,
12866                  port_id, UINT16);
12867 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12868         TOKEN_NUM_INITIALIZER
12869                 (struct cmd_vf_split_drop_en_result,
12870                  vf_id, UINT16);
12871 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12872         TOKEN_STRING_INITIALIZER
12873                 (struct cmd_vf_split_drop_en_result,
12874                  on_off, "on#off");
12875
12876 static void
12877 cmd_set_vf_split_drop_en_parsed(
12878         void *parsed_result,
12879         __attribute__((unused)) struct cmdline *cl,
12880         __attribute__((unused)) void *data)
12881 {
12882         struct cmd_vf_split_drop_en_result *res = parsed_result;
12883         int ret = -ENOTSUP;
12884         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12885
12886         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12887                 return;
12888
12889 #ifdef RTE_LIBRTE_IXGBE_PMD
12890         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12891                         is_on);
12892 #endif
12893         switch (ret) {
12894         case 0:
12895                 break;
12896         case -EINVAL:
12897                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12898                 break;
12899         case -ENODEV:
12900                 printf("invalid port_id %d\n", res->port_id);
12901                 break;
12902         case -ENOTSUP:
12903                 printf("not supported on port %d\n", res->port_id);
12904                 break;
12905         default:
12906                 printf("programming error: (%s)\n", strerror(-ret));
12907         }
12908 }
12909
12910 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12911         .f = cmd_set_vf_split_drop_en_parsed,
12912         .data = NULL,
12913         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12914         .tokens = {
12915                 (void *)&cmd_vf_split_drop_en_set,
12916                 (void *)&cmd_vf_split_drop_en_vf,
12917                 (void *)&cmd_vf_split_drop_en_split,
12918                 (void *)&cmd_vf_split_drop_en_drop,
12919                 (void *)&cmd_vf_split_drop_en_port_id,
12920                 (void *)&cmd_vf_split_drop_en_vf_id,
12921                 (void *)&cmd_vf_split_drop_en_on_off,
12922                 NULL,
12923         },
12924 };
12925
12926 /* vf mac address configuration */
12927
12928 /* Common result structure for vf mac address */
12929 struct cmd_set_vf_mac_addr_result {
12930         cmdline_fixed_string_t set;
12931         cmdline_fixed_string_t vf;
12932         cmdline_fixed_string_t mac;
12933         cmdline_fixed_string_t addr;
12934         portid_t port_id;
12935         uint16_t vf_id;
12936         struct ether_addr mac_addr;
12937
12938 };
12939
12940 /* Common CLI fields for vf split drop enable disable */
12941 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_set_vf_mac_addr_result,
12944                  set, "set");
12945 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12946         TOKEN_STRING_INITIALIZER
12947                 (struct cmd_set_vf_mac_addr_result,
12948                  vf, "vf");
12949 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12950         TOKEN_STRING_INITIALIZER
12951                 (struct cmd_set_vf_mac_addr_result,
12952                  mac, "mac");
12953 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12954         TOKEN_STRING_INITIALIZER
12955                 (struct cmd_set_vf_mac_addr_result,
12956                  addr, "addr");
12957 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12958         TOKEN_NUM_INITIALIZER
12959                 (struct cmd_set_vf_mac_addr_result,
12960                  port_id, UINT16);
12961 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12962         TOKEN_NUM_INITIALIZER
12963                 (struct cmd_set_vf_mac_addr_result,
12964                  vf_id, UINT16);
12965 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12966         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12967                  mac_addr);
12968
12969 static void
12970 cmd_set_vf_mac_addr_parsed(
12971         void *parsed_result,
12972         __attribute__((unused)) struct cmdline *cl,
12973         __attribute__((unused)) void *data)
12974 {
12975         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12976         int ret = -ENOTSUP;
12977
12978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12979                 return;
12980
12981 #ifdef RTE_LIBRTE_IXGBE_PMD
12982         if (ret == -ENOTSUP)
12983                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12984                                 &res->mac_addr);
12985 #endif
12986 #ifdef RTE_LIBRTE_I40E_PMD
12987         if (ret == -ENOTSUP)
12988                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12989                                 &res->mac_addr);
12990 #endif
12991 #ifdef RTE_LIBRTE_BNXT_PMD
12992         if (ret == -ENOTSUP)
12993                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12994                                 &res->mac_addr);
12995 #endif
12996
12997         switch (ret) {
12998         case 0:
12999                 break;
13000         case -EINVAL:
13001                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13002                 break;
13003         case -ENODEV:
13004                 printf("invalid port_id %d\n", res->port_id);
13005                 break;
13006         case -ENOTSUP:
13007                 printf("function not implemented\n");
13008                 break;
13009         default:
13010                 printf("programming error: (%s)\n", strerror(-ret));
13011         }
13012 }
13013
13014 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13015         .f = cmd_set_vf_mac_addr_parsed,
13016         .data = NULL,
13017         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13018         .tokens = {
13019                 (void *)&cmd_set_vf_mac_addr_set,
13020                 (void *)&cmd_set_vf_mac_addr_vf,
13021                 (void *)&cmd_set_vf_mac_addr_mac,
13022                 (void *)&cmd_set_vf_mac_addr_addr,
13023                 (void *)&cmd_set_vf_mac_addr_port_id,
13024                 (void *)&cmd_set_vf_mac_addr_vf_id,
13025                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13026                 NULL,
13027         },
13028 };
13029
13030 /* MACsec configuration */
13031
13032 /* Common result structure for MACsec offload enable */
13033 struct cmd_macsec_offload_on_result {
13034         cmdline_fixed_string_t set;
13035         cmdline_fixed_string_t macsec;
13036         cmdline_fixed_string_t offload;
13037         portid_t port_id;
13038         cmdline_fixed_string_t on;
13039         cmdline_fixed_string_t encrypt;
13040         cmdline_fixed_string_t en_on_off;
13041         cmdline_fixed_string_t replay_protect;
13042         cmdline_fixed_string_t rp_on_off;
13043 };
13044
13045 /* Common CLI fields for MACsec offload disable */
13046 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13047         TOKEN_STRING_INITIALIZER
13048                 (struct cmd_macsec_offload_on_result,
13049                  set, "set");
13050 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13051         TOKEN_STRING_INITIALIZER
13052                 (struct cmd_macsec_offload_on_result,
13053                  macsec, "macsec");
13054 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13055         TOKEN_STRING_INITIALIZER
13056                 (struct cmd_macsec_offload_on_result,
13057                  offload, "offload");
13058 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13059         TOKEN_NUM_INITIALIZER
13060                 (struct cmd_macsec_offload_on_result,
13061                  port_id, UINT16);
13062 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13063         TOKEN_STRING_INITIALIZER
13064                 (struct cmd_macsec_offload_on_result,
13065                  on, "on");
13066 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13067         TOKEN_STRING_INITIALIZER
13068                 (struct cmd_macsec_offload_on_result,
13069                  encrypt, "encrypt");
13070 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_macsec_offload_on_result,
13073                  en_on_off, "on#off");
13074 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_macsec_offload_on_result,
13077                  replay_protect, "replay-protect");
13078 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_macsec_offload_on_result,
13081                  rp_on_off, "on#off");
13082
13083 static void
13084 cmd_set_macsec_offload_on_parsed(
13085         void *parsed_result,
13086         __attribute__((unused)) struct cmdline *cl,
13087         __attribute__((unused)) void *data)
13088 {
13089         struct cmd_macsec_offload_on_result *res = parsed_result;
13090         int ret = -ENOTSUP;
13091         portid_t port_id = res->port_id;
13092         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13093         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13094
13095         if (port_id_is_invalid(port_id, ENABLED_WARN))
13096                 return;
13097         if (!port_is_stopped(port_id)) {
13098                 printf("Please stop port %d first\n", port_id);
13099                 return;
13100         }
13101
13102         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
13103         ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_MACSEC_INSERT;
13104 #ifdef RTE_LIBRTE_IXGBE_PMD
13105         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13106 #endif
13107         RTE_SET_USED(en);
13108         RTE_SET_USED(rp);
13109
13110         switch (ret) {
13111         case 0:
13112                 cmd_reconfig_device_queue(port_id, 1, 1);
13113                 break;
13114         case -ENODEV:
13115                 printf("invalid port_id %d\n", port_id);
13116                 break;
13117         case -ENOTSUP:
13118                 printf("not supported on port %d\n", port_id);
13119                 break;
13120         default:
13121                 printf("programming error: (%s)\n", strerror(-ret));
13122         }
13123 }
13124
13125 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13126         .f = cmd_set_macsec_offload_on_parsed,
13127         .data = NULL,
13128         .help_str = "set macsec offload <port_id> on "
13129                 "encrypt on|off replay-protect on|off",
13130         .tokens = {
13131                 (void *)&cmd_macsec_offload_on_set,
13132                 (void *)&cmd_macsec_offload_on_macsec,
13133                 (void *)&cmd_macsec_offload_on_offload,
13134                 (void *)&cmd_macsec_offload_on_port_id,
13135                 (void *)&cmd_macsec_offload_on_on,
13136                 (void *)&cmd_macsec_offload_on_encrypt,
13137                 (void *)&cmd_macsec_offload_on_en_on_off,
13138                 (void *)&cmd_macsec_offload_on_replay_protect,
13139                 (void *)&cmd_macsec_offload_on_rp_on_off,
13140                 NULL,
13141         },
13142 };
13143
13144 /* Common result structure for MACsec offload disable */
13145 struct cmd_macsec_offload_off_result {
13146         cmdline_fixed_string_t set;
13147         cmdline_fixed_string_t macsec;
13148         cmdline_fixed_string_t offload;
13149         portid_t port_id;
13150         cmdline_fixed_string_t off;
13151 };
13152
13153 /* Common CLI fields for MACsec offload disable */
13154 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13155         TOKEN_STRING_INITIALIZER
13156                 (struct cmd_macsec_offload_off_result,
13157                  set, "set");
13158 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13159         TOKEN_STRING_INITIALIZER
13160                 (struct cmd_macsec_offload_off_result,
13161                  macsec, "macsec");
13162 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13163         TOKEN_STRING_INITIALIZER
13164                 (struct cmd_macsec_offload_off_result,
13165                  offload, "offload");
13166 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13167         TOKEN_NUM_INITIALIZER
13168                 (struct cmd_macsec_offload_off_result,
13169                  port_id, UINT16);
13170 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13171         TOKEN_STRING_INITIALIZER
13172                 (struct cmd_macsec_offload_off_result,
13173                  off, "off");
13174
13175 static void
13176 cmd_set_macsec_offload_off_parsed(
13177         void *parsed_result,
13178         __attribute__((unused)) struct cmdline *cl,
13179         __attribute__((unused)) void *data)
13180 {
13181         struct cmd_macsec_offload_off_result *res = parsed_result;
13182         int ret = -ENOTSUP;
13183         portid_t port_id = res->port_id;
13184
13185         if (port_id_is_invalid(port_id, ENABLED_WARN))
13186                 return;
13187         if (!port_is_stopped(port_id)) {
13188                 printf("Please stop port %d first\n", port_id);
13189                 return;
13190         }
13191
13192         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13193         ports[port_id].dev_conf.txmode.offloads &=
13194                                         ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13195 #ifdef RTE_LIBRTE_IXGBE_PMD
13196         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13197 #endif
13198
13199         switch (ret) {
13200         case 0:
13201                 cmd_reconfig_device_queue(port_id, 1, 1);
13202                 break;
13203         case -ENODEV:
13204                 printf("invalid port_id %d\n", port_id);
13205                 break;
13206         case -ENOTSUP:
13207                 printf("not supported on port %d\n", port_id);
13208                 break;
13209         default:
13210                 printf("programming error: (%s)\n", strerror(-ret));
13211         }
13212 }
13213
13214 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13215         .f = cmd_set_macsec_offload_off_parsed,
13216         .data = NULL,
13217         .help_str = "set macsec offload <port_id> off",
13218         .tokens = {
13219                 (void *)&cmd_macsec_offload_off_set,
13220                 (void *)&cmd_macsec_offload_off_macsec,
13221                 (void *)&cmd_macsec_offload_off_offload,
13222                 (void *)&cmd_macsec_offload_off_port_id,
13223                 (void *)&cmd_macsec_offload_off_off,
13224                 NULL,
13225         },
13226 };
13227
13228 /* Common result structure for MACsec secure connection configure */
13229 struct cmd_macsec_sc_result {
13230         cmdline_fixed_string_t set;
13231         cmdline_fixed_string_t macsec;
13232         cmdline_fixed_string_t sc;
13233         cmdline_fixed_string_t tx_rx;
13234         portid_t port_id;
13235         struct ether_addr mac;
13236         uint16_t pi;
13237 };
13238
13239 /* Common CLI fields for MACsec secure connection configure */
13240 cmdline_parse_token_string_t cmd_macsec_sc_set =
13241         TOKEN_STRING_INITIALIZER
13242                 (struct cmd_macsec_sc_result,
13243                  set, "set");
13244 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13245         TOKEN_STRING_INITIALIZER
13246                 (struct cmd_macsec_sc_result,
13247                  macsec, "macsec");
13248 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13249         TOKEN_STRING_INITIALIZER
13250                 (struct cmd_macsec_sc_result,
13251                  sc, "sc");
13252 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13253         TOKEN_STRING_INITIALIZER
13254                 (struct cmd_macsec_sc_result,
13255                  tx_rx, "tx#rx");
13256 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13257         TOKEN_NUM_INITIALIZER
13258                 (struct cmd_macsec_sc_result,
13259                  port_id, UINT16);
13260 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13261         TOKEN_ETHERADDR_INITIALIZER
13262                 (struct cmd_macsec_sc_result,
13263                  mac);
13264 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13265         TOKEN_NUM_INITIALIZER
13266                 (struct cmd_macsec_sc_result,
13267                  pi, UINT16);
13268
13269 static void
13270 cmd_set_macsec_sc_parsed(
13271         void *parsed_result,
13272         __attribute__((unused)) struct cmdline *cl,
13273         __attribute__((unused)) void *data)
13274 {
13275         struct cmd_macsec_sc_result *res = parsed_result;
13276         int ret = -ENOTSUP;
13277         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13278
13279 #ifdef RTE_LIBRTE_IXGBE_PMD
13280         ret = is_tx ?
13281                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13282                                 res->mac.addr_bytes) :
13283                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13284                                 res->mac.addr_bytes, res->pi);
13285 #endif
13286         RTE_SET_USED(is_tx);
13287
13288         switch (ret) {
13289         case 0:
13290                 break;
13291         case -ENODEV:
13292                 printf("invalid port_id %d\n", res->port_id);
13293                 break;
13294         case -ENOTSUP:
13295                 printf("not supported on port %d\n", res->port_id);
13296                 break;
13297         default:
13298                 printf("programming error: (%s)\n", strerror(-ret));
13299         }
13300 }
13301
13302 cmdline_parse_inst_t cmd_set_macsec_sc = {
13303         .f = cmd_set_macsec_sc_parsed,
13304         .data = NULL,
13305         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13306         .tokens = {
13307                 (void *)&cmd_macsec_sc_set,
13308                 (void *)&cmd_macsec_sc_macsec,
13309                 (void *)&cmd_macsec_sc_sc,
13310                 (void *)&cmd_macsec_sc_tx_rx,
13311                 (void *)&cmd_macsec_sc_port_id,
13312                 (void *)&cmd_macsec_sc_mac,
13313                 (void *)&cmd_macsec_sc_pi,
13314                 NULL,
13315         },
13316 };
13317
13318 /* Common result structure for MACsec secure connection configure */
13319 struct cmd_macsec_sa_result {
13320         cmdline_fixed_string_t set;
13321         cmdline_fixed_string_t macsec;
13322         cmdline_fixed_string_t sa;
13323         cmdline_fixed_string_t tx_rx;
13324         portid_t port_id;
13325         uint8_t idx;
13326         uint8_t an;
13327         uint32_t pn;
13328         cmdline_fixed_string_t key;
13329 };
13330
13331 /* Common CLI fields for MACsec secure connection configure */
13332 cmdline_parse_token_string_t cmd_macsec_sa_set =
13333         TOKEN_STRING_INITIALIZER
13334                 (struct cmd_macsec_sa_result,
13335                  set, "set");
13336 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13337         TOKEN_STRING_INITIALIZER
13338                 (struct cmd_macsec_sa_result,
13339                  macsec, "macsec");
13340 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13341         TOKEN_STRING_INITIALIZER
13342                 (struct cmd_macsec_sa_result,
13343                  sa, "sa");
13344 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13345         TOKEN_STRING_INITIALIZER
13346                 (struct cmd_macsec_sa_result,
13347                  tx_rx, "tx#rx");
13348 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13349         TOKEN_NUM_INITIALIZER
13350                 (struct cmd_macsec_sa_result,
13351                  port_id, UINT16);
13352 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13353         TOKEN_NUM_INITIALIZER
13354                 (struct cmd_macsec_sa_result,
13355                  idx, UINT8);
13356 cmdline_parse_token_num_t cmd_macsec_sa_an =
13357         TOKEN_NUM_INITIALIZER
13358                 (struct cmd_macsec_sa_result,
13359                  an, UINT8);
13360 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13361         TOKEN_NUM_INITIALIZER
13362                 (struct cmd_macsec_sa_result,
13363                  pn, UINT32);
13364 cmdline_parse_token_string_t cmd_macsec_sa_key =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_macsec_sa_result,
13367                  key, NULL);
13368
13369 static void
13370 cmd_set_macsec_sa_parsed(
13371         void *parsed_result,
13372         __attribute__((unused)) struct cmdline *cl,
13373         __attribute__((unused)) void *data)
13374 {
13375         struct cmd_macsec_sa_result *res = parsed_result;
13376         int ret = -ENOTSUP;
13377         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13378         uint8_t key[16] = { 0 };
13379         uint8_t xdgt0;
13380         uint8_t xdgt1;
13381         int key_len;
13382         int i;
13383
13384         key_len = strlen(res->key) / 2;
13385         if (key_len > 16)
13386                 key_len = 16;
13387
13388         for (i = 0; i < key_len; i++) {
13389                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13390                 if (xdgt0 == 0xFF)
13391                         return;
13392                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13393                 if (xdgt1 == 0xFF)
13394                         return;
13395                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13396         }
13397
13398 #ifdef RTE_LIBRTE_IXGBE_PMD
13399         ret = is_tx ?
13400                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13401                         res->idx, res->an, res->pn, key) :
13402                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13403                         res->idx, res->an, res->pn, key);
13404 #endif
13405         RTE_SET_USED(is_tx);
13406         RTE_SET_USED(key);
13407
13408         switch (ret) {
13409         case 0:
13410                 break;
13411         case -EINVAL:
13412                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13413                 break;
13414         case -ENODEV:
13415                 printf("invalid port_id %d\n", res->port_id);
13416                 break;
13417         case -ENOTSUP:
13418                 printf("not supported on port %d\n", res->port_id);
13419                 break;
13420         default:
13421                 printf("programming error: (%s)\n", strerror(-ret));
13422         }
13423 }
13424
13425 cmdline_parse_inst_t cmd_set_macsec_sa = {
13426         .f = cmd_set_macsec_sa_parsed,
13427         .data = NULL,
13428         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13429         .tokens = {
13430                 (void *)&cmd_macsec_sa_set,
13431                 (void *)&cmd_macsec_sa_macsec,
13432                 (void *)&cmd_macsec_sa_sa,
13433                 (void *)&cmd_macsec_sa_tx_rx,
13434                 (void *)&cmd_macsec_sa_port_id,
13435                 (void *)&cmd_macsec_sa_idx,
13436                 (void *)&cmd_macsec_sa_an,
13437                 (void *)&cmd_macsec_sa_pn,
13438                 (void *)&cmd_macsec_sa_key,
13439                 NULL,
13440         },
13441 };
13442
13443 /* VF unicast promiscuous mode configuration */
13444
13445 /* Common result structure for VF unicast promiscuous mode */
13446 struct cmd_vf_promisc_result {
13447         cmdline_fixed_string_t set;
13448         cmdline_fixed_string_t vf;
13449         cmdline_fixed_string_t promisc;
13450         portid_t port_id;
13451         uint32_t vf_id;
13452         cmdline_fixed_string_t on_off;
13453 };
13454
13455 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13456 cmdline_parse_token_string_t cmd_vf_promisc_set =
13457         TOKEN_STRING_INITIALIZER
13458                 (struct cmd_vf_promisc_result,
13459                  set, "set");
13460 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13461         TOKEN_STRING_INITIALIZER
13462                 (struct cmd_vf_promisc_result,
13463                  vf, "vf");
13464 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_vf_promisc_result,
13467                  promisc, "promisc");
13468 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13469         TOKEN_NUM_INITIALIZER
13470                 (struct cmd_vf_promisc_result,
13471                  port_id, UINT16);
13472 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13473         TOKEN_NUM_INITIALIZER
13474                 (struct cmd_vf_promisc_result,
13475                  vf_id, UINT32);
13476 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_promisc_result,
13479                  on_off, "on#off");
13480
13481 static void
13482 cmd_set_vf_promisc_parsed(
13483         void *parsed_result,
13484         __attribute__((unused)) struct cmdline *cl,
13485         __attribute__((unused)) void *data)
13486 {
13487         struct cmd_vf_promisc_result *res = parsed_result;
13488         int ret = -ENOTSUP;
13489
13490         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13491
13492         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13493                 return;
13494
13495 #ifdef RTE_LIBRTE_I40E_PMD
13496         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13497                                                   res->vf_id, is_on);
13498 #endif
13499
13500         switch (ret) {
13501         case 0:
13502                 break;
13503         case -EINVAL:
13504                 printf("invalid vf_id %d\n", res->vf_id);
13505                 break;
13506         case -ENODEV:
13507                 printf("invalid port_id %d\n", res->port_id);
13508                 break;
13509         case -ENOTSUP:
13510                 printf("function not implemented\n");
13511                 break;
13512         default:
13513                 printf("programming error: (%s)\n", strerror(-ret));
13514         }
13515 }
13516
13517 cmdline_parse_inst_t cmd_set_vf_promisc = {
13518         .f = cmd_set_vf_promisc_parsed,
13519         .data = NULL,
13520         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13521                 "Set unicast promiscuous mode for a VF from the PF",
13522         .tokens = {
13523                 (void *)&cmd_vf_promisc_set,
13524                 (void *)&cmd_vf_promisc_vf,
13525                 (void *)&cmd_vf_promisc_promisc,
13526                 (void *)&cmd_vf_promisc_port_id,
13527                 (void *)&cmd_vf_promisc_vf_id,
13528                 (void *)&cmd_vf_promisc_on_off,
13529                 NULL,
13530         },
13531 };
13532
13533 /* VF multicast promiscuous mode configuration */
13534
13535 /* Common result structure for VF multicast promiscuous mode */
13536 struct cmd_vf_allmulti_result {
13537         cmdline_fixed_string_t set;
13538         cmdline_fixed_string_t vf;
13539         cmdline_fixed_string_t allmulti;
13540         portid_t port_id;
13541         uint32_t vf_id;
13542         cmdline_fixed_string_t on_off;
13543 };
13544
13545 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13546 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13547         TOKEN_STRING_INITIALIZER
13548                 (struct cmd_vf_allmulti_result,
13549                  set, "set");
13550 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13551         TOKEN_STRING_INITIALIZER
13552                 (struct cmd_vf_allmulti_result,
13553                  vf, "vf");
13554 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13555         TOKEN_STRING_INITIALIZER
13556                 (struct cmd_vf_allmulti_result,
13557                  allmulti, "allmulti");
13558 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13559         TOKEN_NUM_INITIALIZER
13560                 (struct cmd_vf_allmulti_result,
13561                  port_id, UINT16);
13562 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13563         TOKEN_NUM_INITIALIZER
13564                 (struct cmd_vf_allmulti_result,
13565                  vf_id, UINT32);
13566 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13567         TOKEN_STRING_INITIALIZER
13568                 (struct cmd_vf_allmulti_result,
13569                  on_off, "on#off");
13570
13571 static void
13572 cmd_set_vf_allmulti_parsed(
13573         void *parsed_result,
13574         __attribute__((unused)) struct cmdline *cl,
13575         __attribute__((unused)) void *data)
13576 {
13577         struct cmd_vf_allmulti_result *res = parsed_result;
13578         int ret = -ENOTSUP;
13579
13580         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13581
13582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13583                 return;
13584
13585 #ifdef RTE_LIBRTE_I40E_PMD
13586         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13587                                                     res->vf_id, is_on);
13588 #endif
13589
13590         switch (ret) {
13591         case 0:
13592                 break;
13593         case -EINVAL:
13594                 printf("invalid vf_id %d\n", res->vf_id);
13595                 break;
13596         case -ENODEV:
13597                 printf("invalid port_id %d\n", res->port_id);
13598                 break;
13599         case -ENOTSUP:
13600                 printf("function not implemented\n");
13601                 break;
13602         default:
13603                 printf("programming error: (%s)\n", strerror(-ret));
13604         }
13605 }
13606
13607 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13608         .f = cmd_set_vf_allmulti_parsed,
13609         .data = NULL,
13610         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13611                 "Set multicast promiscuous mode for a VF from the PF",
13612         .tokens = {
13613                 (void *)&cmd_vf_allmulti_set,
13614                 (void *)&cmd_vf_allmulti_vf,
13615                 (void *)&cmd_vf_allmulti_allmulti,
13616                 (void *)&cmd_vf_allmulti_port_id,
13617                 (void *)&cmd_vf_allmulti_vf_id,
13618                 (void *)&cmd_vf_allmulti_on_off,
13619                 NULL,
13620         },
13621 };
13622
13623 /* vf broadcast mode configuration */
13624
13625 /* Common result structure for vf broadcast */
13626 struct cmd_set_vf_broadcast_result {
13627         cmdline_fixed_string_t set;
13628         cmdline_fixed_string_t vf;
13629         cmdline_fixed_string_t broadcast;
13630         portid_t port_id;
13631         uint16_t vf_id;
13632         cmdline_fixed_string_t on_off;
13633 };
13634
13635 /* Common CLI fields for vf broadcast enable disable */
13636 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13637         TOKEN_STRING_INITIALIZER
13638                 (struct cmd_set_vf_broadcast_result,
13639                  set, "set");
13640 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13641         TOKEN_STRING_INITIALIZER
13642                 (struct cmd_set_vf_broadcast_result,
13643                  vf, "vf");
13644 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13645         TOKEN_STRING_INITIALIZER
13646                 (struct cmd_set_vf_broadcast_result,
13647                  broadcast, "broadcast");
13648 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13649         TOKEN_NUM_INITIALIZER
13650                 (struct cmd_set_vf_broadcast_result,
13651                  port_id, UINT16);
13652 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13653         TOKEN_NUM_INITIALIZER
13654                 (struct cmd_set_vf_broadcast_result,
13655                  vf_id, UINT16);
13656 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_set_vf_broadcast_result,
13659                  on_off, "on#off");
13660
13661 static void
13662 cmd_set_vf_broadcast_parsed(
13663         void *parsed_result,
13664         __attribute__((unused)) struct cmdline *cl,
13665         __attribute__((unused)) void *data)
13666 {
13667         struct cmd_set_vf_broadcast_result *res = parsed_result;
13668         int ret = -ENOTSUP;
13669
13670         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13671
13672         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13673                 return;
13674
13675 #ifdef RTE_LIBRTE_I40E_PMD
13676         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13677                                             res->vf_id, is_on);
13678 #endif
13679
13680         switch (ret) {
13681         case 0:
13682                 break;
13683         case -EINVAL:
13684                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13685                 break;
13686         case -ENODEV:
13687                 printf("invalid port_id %d\n", res->port_id);
13688                 break;
13689         case -ENOTSUP:
13690                 printf("function not implemented\n");
13691                 break;
13692         default:
13693                 printf("programming error: (%s)\n", strerror(-ret));
13694         }
13695 }
13696
13697 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13698         .f = cmd_set_vf_broadcast_parsed,
13699         .data = NULL,
13700         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13701         .tokens = {
13702                 (void *)&cmd_set_vf_broadcast_set,
13703                 (void *)&cmd_set_vf_broadcast_vf,
13704                 (void *)&cmd_set_vf_broadcast_broadcast,
13705                 (void *)&cmd_set_vf_broadcast_port_id,
13706                 (void *)&cmd_set_vf_broadcast_vf_id,
13707                 (void *)&cmd_set_vf_broadcast_on_off,
13708                 NULL,
13709         },
13710 };
13711
13712 /* vf vlan tag configuration */
13713
13714 /* Common result structure for vf vlan tag */
13715 struct cmd_set_vf_vlan_tag_result {
13716         cmdline_fixed_string_t set;
13717         cmdline_fixed_string_t vf;
13718         cmdline_fixed_string_t vlan;
13719         cmdline_fixed_string_t tag;
13720         portid_t port_id;
13721         uint16_t vf_id;
13722         cmdline_fixed_string_t on_off;
13723 };
13724
13725 /* Common CLI fields for vf vlan tag enable disable */
13726 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13727         TOKEN_STRING_INITIALIZER
13728                 (struct cmd_set_vf_vlan_tag_result,
13729                  set, "set");
13730 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13731         TOKEN_STRING_INITIALIZER
13732                 (struct cmd_set_vf_vlan_tag_result,
13733                  vf, "vf");
13734 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13735         TOKEN_STRING_INITIALIZER
13736                 (struct cmd_set_vf_vlan_tag_result,
13737                  vlan, "vlan");
13738 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13739         TOKEN_STRING_INITIALIZER
13740                 (struct cmd_set_vf_vlan_tag_result,
13741                  tag, "tag");
13742 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13743         TOKEN_NUM_INITIALIZER
13744                 (struct cmd_set_vf_vlan_tag_result,
13745                  port_id, UINT16);
13746 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13747         TOKEN_NUM_INITIALIZER
13748                 (struct cmd_set_vf_vlan_tag_result,
13749                  vf_id, UINT16);
13750 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13751         TOKEN_STRING_INITIALIZER
13752                 (struct cmd_set_vf_vlan_tag_result,
13753                  on_off, "on#off");
13754
13755 static void
13756 cmd_set_vf_vlan_tag_parsed(
13757         void *parsed_result,
13758         __attribute__((unused)) struct cmdline *cl,
13759         __attribute__((unused)) void *data)
13760 {
13761         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13762         int ret = -ENOTSUP;
13763
13764         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13765
13766         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13767                 return;
13768
13769 #ifdef RTE_LIBRTE_I40E_PMD
13770         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13771                                            res->vf_id, is_on);
13772 #endif
13773
13774         switch (ret) {
13775         case 0:
13776                 break;
13777         case -EINVAL:
13778                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13779                 break;
13780         case -ENODEV:
13781                 printf("invalid port_id %d\n", res->port_id);
13782                 break;
13783         case -ENOTSUP:
13784                 printf("function not implemented\n");
13785                 break;
13786         default:
13787                 printf("programming error: (%s)\n", strerror(-ret));
13788         }
13789 }
13790
13791 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13792         .f = cmd_set_vf_vlan_tag_parsed,
13793         .data = NULL,
13794         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13795         .tokens = {
13796                 (void *)&cmd_set_vf_vlan_tag_set,
13797                 (void *)&cmd_set_vf_vlan_tag_vf,
13798                 (void *)&cmd_set_vf_vlan_tag_vlan,
13799                 (void *)&cmd_set_vf_vlan_tag_tag,
13800                 (void *)&cmd_set_vf_vlan_tag_port_id,
13801                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13802                 (void *)&cmd_set_vf_vlan_tag_on_off,
13803                 NULL,
13804         },
13805 };
13806
13807 /* Common definition of VF and TC TX bandwidth configuration */
13808 struct cmd_vf_tc_bw_result {
13809         cmdline_fixed_string_t set;
13810         cmdline_fixed_string_t vf;
13811         cmdline_fixed_string_t tc;
13812         cmdline_fixed_string_t tx;
13813         cmdline_fixed_string_t min_bw;
13814         cmdline_fixed_string_t max_bw;
13815         cmdline_fixed_string_t strict_link_prio;
13816         portid_t port_id;
13817         uint16_t vf_id;
13818         uint8_t tc_no;
13819         uint32_t bw;
13820         cmdline_fixed_string_t bw_list;
13821         uint8_t tc_map;
13822 };
13823
13824 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13825         TOKEN_STRING_INITIALIZER
13826                 (struct cmd_vf_tc_bw_result,
13827                  set, "set");
13828 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13829         TOKEN_STRING_INITIALIZER
13830                 (struct cmd_vf_tc_bw_result,
13831                  vf, "vf");
13832 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13833         TOKEN_STRING_INITIALIZER
13834                 (struct cmd_vf_tc_bw_result,
13835                  tc, "tc");
13836 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13837         TOKEN_STRING_INITIALIZER
13838                 (struct cmd_vf_tc_bw_result,
13839                  tx, "tx");
13840 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13841         TOKEN_STRING_INITIALIZER
13842                 (struct cmd_vf_tc_bw_result,
13843                  strict_link_prio, "strict-link-priority");
13844 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13845         TOKEN_STRING_INITIALIZER
13846                 (struct cmd_vf_tc_bw_result,
13847                  min_bw, "min-bandwidth");
13848 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13849         TOKEN_STRING_INITIALIZER
13850                 (struct cmd_vf_tc_bw_result,
13851                  max_bw, "max-bandwidth");
13852 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13853         TOKEN_NUM_INITIALIZER
13854                 (struct cmd_vf_tc_bw_result,
13855                  port_id, UINT16);
13856 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13857         TOKEN_NUM_INITIALIZER
13858                 (struct cmd_vf_tc_bw_result,
13859                  vf_id, UINT16);
13860 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13861         TOKEN_NUM_INITIALIZER
13862                 (struct cmd_vf_tc_bw_result,
13863                  tc_no, UINT8);
13864 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13865         TOKEN_NUM_INITIALIZER
13866                 (struct cmd_vf_tc_bw_result,
13867                  bw, UINT32);
13868 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_vf_tc_bw_result,
13871                  bw_list, NULL);
13872 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13873         TOKEN_NUM_INITIALIZER
13874                 (struct cmd_vf_tc_bw_result,
13875                  tc_map, UINT8);
13876
13877 /* VF max bandwidth setting */
13878 static void
13879 cmd_vf_max_bw_parsed(
13880         void *parsed_result,
13881         __attribute__((unused)) struct cmdline *cl,
13882         __attribute__((unused)) void *data)
13883 {
13884         struct cmd_vf_tc_bw_result *res = parsed_result;
13885         int ret = -ENOTSUP;
13886
13887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13888                 return;
13889
13890 #ifdef RTE_LIBRTE_I40E_PMD
13891         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13892                                          res->vf_id, res->bw);
13893 #endif
13894
13895         switch (ret) {
13896         case 0:
13897                 break;
13898         case -EINVAL:
13899                 printf("invalid vf_id %d or bandwidth %d\n",
13900                        res->vf_id, res->bw);
13901                 break;
13902         case -ENODEV:
13903                 printf("invalid port_id %d\n", res->port_id);
13904                 break;
13905         case -ENOTSUP:
13906                 printf("function not implemented\n");
13907                 break;
13908         default:
13909                 printf("programming error: (%s)\n", strerror(-ret));
13910         }
13911 }
13912
13913 cmdline_parse_inst_t cmd_vf_max_bw = {
13914         .f = cmd_vf_max_bw_parsed,
13915         .data = NULL,
13916         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13917         .tokens = {
13918                 (void *)&cmd_vf_tc_bw_set,
13919                 (void *)&cmd_vf_tc_bw_vf,
13920                 (void *)&cmd_vf_tc_bw_tx,
13921                 (void *)&cmd_vf_tc_bw_max_bw,
13922                 (void *)&cmd_vf_tc_bw_port_id,
13923                 (void *)&cmd_vf_tc_bw_vf_id,
13924                 (void *)&cmd_vf_tc_bw_bw,
13925                 NULL,
13926         },
13927 };
13928
13929 static int
13930 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13931                            uint8_t *tc_num,
13932                            char *str)
13933 {
13934         uint32_t size;
13935         const char *p, *p0 = str;
13936         char s[256];
13937         char *end;
13938         char *str_fld[16];
13939         uint16_t i;
13940         int ret;
13941
13942         p = strchr(p0, '(');
13943         if (p == NULL) {
13944                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13945                 return -1;
13946         }
13947         p++;
13948         p0 = strchr(p, ')');
13949         if (p0 == NULL) {
13950                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13951                 return -1;
13952         }
13953         size = p0 - p;
13954         if (size >= sizeof(s)) {
13955                 printf("The string size exceeds the internal buffer size\n");
13956                 return -1;
13957         }
13958         snprintf(s, sizeof(s), "%.*s", size, p);
13959         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13960         if (ret <= 0) {
13961                 printf("Failed to get the bandwidth list. ");
13962                 return -1;
13963         }
13964         *tc_num = ret;
13965         for (i = 0; i < ret; i++)
13966                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13967
13968         return 0;
13969 }
13970
13971 /* TC min bandwidth setting */
13972 static void
13973 cmd_vf_tc_min_bw_parsed(
13974         void *parsed_result,
13975         __attribute__((unused)) struct cmdline *cl,
13976         __attribute__((unused)) void *data)
13977 {
13978         struct cmd_vf_tc_bw_result *res = parsed_result;
13979         uint8_t tc_num;
13980         uint8_t bw[16];
13981         int ret = -ENOTSUP;
13982
13983         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13984                 return;
13985
13986         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13987         if (ret)
13988                 return;
13989
13990 #ifdef RTE_LIBRTE_I40E_PMD
13991         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13992                                               tc_num, bw);
13993 #endif
13994
13995         switch (ret) {
13996         case 0:
13997                 break;
13998         case -EINVAL:
13999                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14000                 break;
14001         case -ENODEV:
14002                 printf("invalid port_id %d\n", res->port_id);
14003                 break;
14004         case -ENOTSUP:
14005                 printf("function not implemented\n");
14006                 break;
14007         default:
14008                 printf("programming error: (%s)\n", strerror(-ret));
14009         }
14010 }
14011
14012 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14013         .f = cmd_vf_tc_min_bw_parsed,
14014         .data = NULL,
14015         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14016                     " <bw1, bw2, ...>",
14017         .tokens = {
14018                 (void *)&cmd_vf_tc_bw_set,
14019                 (void *)&cmd_vf_tc_bw_vf,
14020                 (void *)&cmd_vf_tc_bw_tc,
14021                 (void *)&cmd_vf_tc_bw_tx,
14022                 (void *)&cmd_vf_tc_bw_min_bw,
14023                 (void *)&cmd_vf_tc_bw_port_id,
14024                 (void *)&cmd_vf_tc_bw_vf_id,
14025                 (void *)&cmd_vf_tc_bw_bw_list,
14026                 NULL,
14027         },
14028 };
14029
14030 static void
14031 cmd_tc_min_bw_parsed(
14032         void *parsed_result,
14033         __attribute__((unused)) struct cmdline *cl,
14034         __attribute__((unused)) void *data)
14035 {
14036         struct cmd_vf_tc_bw_result *res = parsed_result;
14037         struct rte_port *port;
14038         uint8_t tc_num;
14039         uint8_t bw[16];
14040         int ret = -ENOTSUP;
14041
14042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14043                 return;
14044
14045         port = &ports[res->port_id];
14046         /** Check if the port is not started **/
14047         if (port->port_status != RTE_PORT_STOPPED) {
14048                 printf("Please stop port %d first\n", res->port_id);
14049                 return;
14050         }
14051
14052         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14053         if (ret)
14054                 return;
14055
14056 #ifdef RTE_LIBRTE_IXGBE_PMD
14057         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14058 #endif
14059
14060         switch (ret) {
14061         case 0:
14062                 break;
14063         case -EINVAL:
14064                 printf("invalid bandwidth\n");
14065                 break;
14066         case -ENODEV:
14067                 printf("invalid port_id %d\n", res->port_id);
14068                 break;
14069         case -ENOTSUP:
14070                 printf("function not implemented\n");
14071                 break;
14072         default:
14073                 printf("programming error: (%s)\n", strerror(-ret));
14074         }
14075 }
14076
14077 cmdline_parse_inst_t cmd_tc_min_bw = {
14078         .f = cmd_tc_min_bw_parsed,
14079         .data = NULL,
14080         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14081         .tokens = {
14082                 (void *)&cmd_vf_tc_bw_set,
14083                 (void *)&cmd_vf_tc_bw_tc,
14084                 (void *)&cmd_vf_tc_bw_tx,
14085                 (void *)&cmd_vf_tc_bw_min_bw,
14086                 (void *)&cmd_vf_tc_bw_port_id,
14087                 (void *)&cmd_vf_tc_bw_bw_list,
14088                 NULL,
14089         },
14090 };
14091
14092 /* TC max bandwidth setting */
14093 static void
14094 cmd_vf_tc_max_bw_parsed(
14095         void *parsed_result,
14096         __attribute__((unused)) struct cmdline *cl,
14097         __attribute__((unused)) void *data)
14098 {
14099         struct cmd_vf_tc_bw_result *res = parsed_result;
14100         int ret = -ENOTSUP;
14101
14102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14103                 return;
14104
14105 #ifdef RTE_LIBRTE_I40E_PMD
14106         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14107                                             res->tc_no, res->bw);
14108 #endif
14109
14110         switch (ret) {
14111         case 0:
14112                 break;
14113         case -EINVAL:
14114                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14115                        res->vf_id, res->tc_no, res->bw);
14116                 break;
14117         case -ENODEV:
14118                 printf("invalid port_id %d\n", res->port_id);
14119                 break;
14120         case -ENOTSUP:
14121                 printf("function not implemented\n");
14122                 break;
14123         default:
14124                 printf("programming error: (%s)\n", strerror(-ret));
14125         }
14126 }
14127
14128 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14129         .f = cmd_vf_tc_max_bw_parsed,
14130         .data = NULL,
14131         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14132                     " <bandwidth>",
14133         .tokens = {
14134                 (void *)&cmd_vf_tc_bw_set,
14135                 (void *)&cmd_vf_tc_bw_vf,
14136                 (void *)&cmd_vf_tc_bw_tc,
14137                 (void *)&cmd_vf_tc_bw_tx,
14138                 (void *)&cmd_vf_tc_bw_max_bw,
14139                 (void *)&cmd_vf_tc_bw_port_id,
14140                 (void *)&cmd_vf_tc_bw_vf_id,
14141                 (void *)&cmd_vf_tc_bw_tc_no,
14142                 (void *)&cmd_vf_tc_bw_bw,
14143                 NULL,
14144         },
14145 };
14146
14147
14148 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14149
14150 /* *** Set Port default Traffic Management Hierarchy *** */
14151 struct cmd_set_port_tm_hierarchy_default_result {
14152         cmdline_fixed_string_t set;
14153         cmdline_fixed_string_t port;
14154         cmdline_fixed_string_t tm;
14155         cmdline_fixed_string_t hierarchy;
14156         cmdline_fixed_string_t def;
14157         portid_t port_id;
14158 };
14159
14160 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14161         TOKEN_STRING_INITIALIZER(
14162                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14163 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14164         TOKEN_STRING_INITIALIZER(
14165                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14166 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14167         TOKEN_STRING_INITIALIZER(
14168                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14169 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14170         TOKEN_STRING_INITIALIZER(
14171                 struct cmd_set_port_tm_hierarchy_default_result,
14172                         hierarchy, "hierarchy");
14173 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14174         TOKEN_STRING_INITIALIZER(
14175                 struct cmd_set_port_tm_hierarchy_default_result,
14176                         def, "default");
14177 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14178         TOKEN_NUM_INITIALIZER(
14179                 struct cmd_set_port_tm_hierarchy_default_result,
14180                         port_id, UINT16);
14181
14182 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14183         __attribute__((unused)) struct cmdline *cl,
14184         __attribute__((unused)) void *data)
14185 {
14186         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14187         struct rte_port *p;
14188         portid_t port_id = res->port_id;
14189
14190         if (port_id_is_invalid(port_id, ENABLED_WARN))
14191                 return;
14192
14193         p = &ports[port_id];
14194
14195         /* Port tm flag */
14196         if (p->softport.tm_flag == 0) {
14197                 printf("  tm not enabled on port %u (error)\n", port_id);
14198                 return;
14199         }
14200
14201         /* Forward mode: tm */
14202         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14203                 printf("  tm mode not enabled(error)\n");
14204                 return;
14205         }
14206
14207         /* Set the default tm hierarchy */
14208         p->softport.tm.default_hierarchy_enable = 1;
14209 }
14210
14211 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14212         .f = cmd_set_port_tm_hierarchy_default_parsed,
14213         .data = NULL,
14214         .help_str = "set port tm hierarchy default <port_id>",
14215         .tokens = {
14216                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14217                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14218                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14219                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14220                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14221                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14222                 NULL,
14223         },
14224 };
14225 #endif
14226
14227 /* Strict link priority scheduling mode setting */
14228 static void
14229 cmd_strict_link_prio_parsed(
14230         void *parsed_result,
14231         __attribute__((unused)) struct cmdline *cl,
14232         __attribute__((unused)) void *data)
14233 {
14234         struct cmd_vf_tc_bw_result *res = parsed_result;
14235         int ret = -ENOTSUP;
14236
14237         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14238                 return;
14239
14240 #ifdef RTE_LIBRTE_I40E_PMD
14241         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14242 #endif
14243
14244         switch (ret) {
14245         case 0:
14246                 break;
14247         case -EINVAL:
14248                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14249                 break;
14250         case -ENODEV:
14251                 printf("invalid port_id %d\n", res->port_id);
14252                 break;
14253         case -ENOTSUP:
14254                 printf("function not implemented\n");
14255                 break;
14256         default:
14257                 printf("programming error: (%s)\n", strerror(-ret));
14258         }
14259 }
14260
14261 cmdline_parse_inst_t cmd_strict_link_prio = {
14262         .f = cmd_strict_link_prio_parsed,
14263         .data = NULL,
14264         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14265         .tokens = {
14266                 (void *)&cmd_vf_tc_bw_set,
14267                 (void *)&cmd_vf_tc_bw_tx,
14268                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14269                 (void *)&cmd_vf_tc_bw_port_id,
14270                 (void *)&cmd_vf_tc_bw_tc_map,
14271                 NULL,
14272         },
14273 };
14274
14275 /* Load dynamic device personalization*/
14276 struct cmd_ddp_add_result {
14277         cmdline_fixed_string_t ddp;
14278         cmdline_fixed_string_t add;
14279         portid_t port_id;
14280         char filepath[];
14281 };
14282
14283 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14284         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14285 cmdline_parse_token_string_t cmd_ddp_add_add =
14286         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14287 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14288         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14289 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14290         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14291
14292 static void
14293 cmd_ddp_add_parsed(
14294         void *parsed_result,
14295         __attribute__((unused)) struct cmdline *cl,
14296         __attribute__((unused)) void *data)
14297 {
14298         struct cmd_ddp_add_result *res = parsed_result;
14299         uint8_t *buff;
14300         uint32_t size;
14301         char *filepath;
14302         char *file_fld[2];
14303         int file_num;
14304         int ret = -ENOTSUP;
14305
14306         if (res->port_id > nb_ports) {
14307                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14308                 return;
14309         }
14310
14311         if (!all_ports_stopped()) {
14312                 printf("Please stop all ports first\n");
14313                 return;
14314         }
14315
14316         filepath = strdup(res->filepath);
14317         if (filepath == NULL) {
14318                 printf("Failed to allocate memory\n");
14319                 return;
14320         }
14321         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14322
14323         buff = open_ddp_package_file(file_fld[0], &size);
14324         if (!buff) {
14325                 free((void *)filepath);
14326                 return;
14327         }
14328
14329 #ifdef RTE_LIBRTE_I40E_PMD
14330         if (ret == -ENOTSUP)
14331                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14332                                                buff, size,
14333                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14334 #endif
14335
14336         if (ret == -EEXIST)
14337                 printf("Profile has already existed.\n");
14338         else if (ret < 0)
14339                 printf("Failed to load profile.\n");
14340         else if (file_num == 2)
14341                 save_ddp_package_file(file_fld[1], buff, size);
14342
14343         close_ddp_package_file(buff);
14344         free((void *)filepath);
14345 }
14346
14347 cmdline_parse_inst_t cmd_ddp_add = {
14348         .f = cmd_ddp_add_parsed,
14349         .data = NULL,
14350         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14351         .tokens = {
14352                 (void *)&cmd_ddp_add_ddp,
14353                 (void *)&cmd_ddp_add_add,
14354                 (void *)&cmd_ddp_add_port_id,
14355                 (void *)&cmd_ddp_add_filepath,
14356                 NULL,
14357         },
14358 };
14359
14360 /* Delete dynamic device personalization*/
14361 struct cmd_ddp_del_result {
14362         cmdline_fixed_string_t ddp;
14363         cmdline_fixed_string_t del;
14364         portid_t port_id;
14365         char filepath[];
14366 };
14367
14368 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14369         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14370 cmdline_parse_token_string_t cmd_ddp_del_del =
14371         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14372 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14373         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14374 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14375         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14376
14377 static void
14378 cmd_ddp_del_parsed(
14379         void *parsed_result,
14380         __attribute__((unused)) struct cmdline *cl,
14381         __attribute__((unused)) void *data)
14382 {
14383         struct cmd_ddp_del_result *res = parsed_result;
14384         uint8_t *buff;
14385         uint32_t size;
14386         int ret = -ENOTSUP;
14387
14388         if (res->port_id > nb_ports) {
14389                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14390                 return;
14391         }
14392
14393         if (!all_ports_stopped()) {
14394                 printf("Please stop all ports first\n");
14395                 return;
14396         }
14397
14398         buff = open_ddp_package_file(res->filepath, &size);
14399         if (!buff)
14400                 return;
14401
14402 #ifdef RTE_LIBRTE_I40E_PMD
14403         if (ret == -ENOTSUP)
14404                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14405                                                buff, size,
14406                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14407 #endif
14408
14409         if (ret == -EACCES)
14410                 printf("Profile does not exist.\n");
14411         else if (ret < 0)
14412                 printf("Failed to delete profile.\n");
14413
14414         close_ddp_package_file(buff);
14415 }
14416
14417 cmdline_parse_inst_t cmd_ddp_del = {
14418         .f = cmd_ddp_del_parsed,
14419         .data = NULL,
14420         .help_str = "ddp del <port_id> <profile_path>",
14421         .tokens = {
14422                 (void *)&cmd_ddp_del_ddp,
14423                 (void *)&cmd_ddp_del_del,
14424                 (void *)&cmd_ddp_del_port_id,
14425                 (void *)&cmd_ddp_del_filepath,
14426                 NULL,
14427         },
14428 };
14429
14430 /* Get dynamic device personalization profile info */
14431 struct cmd_ddp_info_result {
14432         cmdline_fixed_string_t ddp;
14433         cmdline_fixed_string_t get;
14434         cmdline_fixed_string_t info;
14435         char filepath[];
14436 };
14437
14438 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14439         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14440 cmdline_parse_token_string_t cmd_ddp_info_get =
14441         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14442 cmdline_parse_token_string_t cmd_ddp_info_info =
14443         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14444 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14445         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14446
14447 static void
14448 cmd_ddp_info_parsed(
14449         void *parsed_result,
14450         __attribute__((unused)) struct cmdline *cl,
14451         __attribute__((unused)) void *data)
14452 {
14453         struct cmd_ddp_info_result *res = parsed_result;
14454         uint8_t *pkg;
14455         uint32_t pkg_size;
14456         int ret = -ENOTSUP;
14457 #ifdef RTE_LIBRTE_I40E_PMD
14458         uint32_t i, j, n;
14459         uint8_t *buff;
14460         uint32_t buff_size = 0;
14461         struct rte_pmd_i40e_profile_info info;
14462         uint32_t dev_num = 0;
14463         struct rte_pmd_i40e_ddp_device_id *devs;
14464         uint32_t proto_num = 0;
14465         struct rte_pmd_i40e_proto_info *proto = NULL;
14466         uint32_t pctype_num = 0;
14467         struct rte_pmd_i40e_ptype_info *pctype;
14468         uint32_t ptype_num = 0;
14469         struct rte_pmd_i40e_ptype_info *ptype;
14470         uint8_t proto_id;
14471
14472 #endif
14473
14474         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14475         if (!pkg)
14476                 return;
14477
14478 #ifdef RTE_LIBRTE_I40E_PMD
14479         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14480                                 (uint8_t *)&info, sizeof(info),
14481                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14482         if (!ret) {
14483                 printf("Global Track id:       0x%x\n", info.track_id);
14484                 printf("Global Version:        %d.%d.%d.%d\n",
14485                         info.version.major,
14486                         info.version.minor,
14487                         info.version.update,
14488                         info.version.draft);
14489                 printf("Global Package name:   %s\n\n", info.name);
14490         }
14491
14492         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14493                                 (uint8_t *)&info, sizeof(info),
14494                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14495         if (!ret) {
14496                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14497                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14498                         info.version.major,
14499                         info.version.minor,
14500                         info.version.update,
14501                         info.version.draft);
14502                 printf("i40e Profile name:     %s\n\n", info.name);
14503         }
14504
14505         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14506                                 (uint8_t *)&buff_size, sizeof(buff_size),
14507                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14508         if (!ret && buff_size) {
14509                 buff = (uint8_t *)malloc(buff_size);
14510                 if (buff) {
14511                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14512                                                 buff, buff_size,
14513                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14514                         if (!ret)
14515                                 printf("Package Notes:\n%s\n\n", buff);
14516                         free(buff);
14517                 }
14518         }
14519
14520         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14521                                 (uint8_t *)&dev_num, sizeof(dev_num),
14522                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14523         if (!ret && dev_num) {
14524                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14525                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14526                 if (devs) {
14527                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14528                                                 (uint8_t *)devs, buff_size,
14529                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14530                         if (!ret) {
14531                                 printf("List of supported devices:\n");
14532                                 for (i = 0; i < dev_num; i++) {
14533                                         printf("  %04X:%04X %04X:%04X\n",
14534                                                 devs[i].vendor_dev_id >> 16,
14535                                                 devs[i].vendor_dev_id & 0xFFFF,
14536                                                 devs[i].sub_vendor_dev_id >> 16,
14537                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14538                                 }
14539                                 printf("\n");
14540                         }
14541                         free(devs);
14542                 }
14543         }
14544
14545         /* get information about protocols and packet types */
14546         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14547                 (uint8_t *)&proto_num, sizeof(proto_num),
14548                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14549         if (ret || !proto_num)
14550                 goto no_print_return;
14551
14552         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14553         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14554         if (!proto)
14555                 goto no_print_return;
14556
14557         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14558                                         buff_size,
14559                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14560         if (!ret) {
14561                 printf("List of used protocols:\n");
14562                 for (i = 0; i < proto_num; i++)
14563                         printf("  %2u: %s\n", proto[i].proto_id,
14564                                proto[i].name);
14565                 printf("\n");
14566         }
14567         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14568                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14569                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14570         if (ret || !pctype_num)
14571                 goto no_print_pctypes;
14572
14573         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14574         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14575         if (!pctype)
14576                 goto no_print_pctypes;
14577
14578         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14579                                         buff_size,
14580                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14581         if (ret) {
14582                 free(pctype);
14583                 goto no_print_pctypes;
14584         }
14585
14586         printf("List of defined packet classification types:\n");
14587         for (i = 0; i < pctype_num; i++) {
14588                 printf("  %2u:", pctype[i].ptype_id);
14589                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14590                         proto_id = pctype[i].protocols[j];
14591                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14592                                 for (n = 0; n < proto_num; n++) {
14593                                         if (proto[n].proto_id == proto_id) {
14594                                                 printf(" %s", proto[n].name);
14595                                                 break;
14596                                         }
14597                                 }
14598                         }
14599                 }
14600                 printf("\n");
14601         }
14602         printf("\n");
14603         free(pctype);
14604
14605 no_print_pctypes:
14606
14607         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14608                                         sizeof(ptype_num),
14609                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14610         if (ret || !ptype_num)
14611                 goto no_print_return;
14612
14613         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14614         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14615         if (!ptype)
14616                 goto no_print_return;
14617
14618         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14619                                         buff_size,
14620                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14621         if (ret) {
14622                 free(ptype);
14623                 goto no_print_return;
14624         }
14625         printf("List of defined packet types:\n");
14626         for (i = 0; i < ptype_num; i++) {
14627                 printf("  %2u:", ptype[i].ptype_id);
14628                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14629                         proto_id = ptype[i].protocols[j];
14630                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14631                                 for (n = 0; n < proto_num; n++) {
14632                                         if (proto[n].proto_id == proto_id) {
14633                                                 printf(" %s", proto[n].name);
14634                                                 break;
14635                                         }
14636                                 }
14637                         }
14638                 }
14639                 printf("\n");
14640         }
14641         free(ptype);
14642         printf("\n");
14643
14644         ret = 0;
14645 no_print_return:
14646         if (proto)
14647                 free(proto);
14648 #endif
14649         if (ret == -ENOTSUP)
14650                 printf("Function not supported in PMD driver\n");
14651         close_ddp_package_file(pkg);
14652 }
14653
14654 cmdline_parse_inst_t cmd_ddp_get_info = {
14655         .f = cmd_ddp_info_parsed,
14656         .data = NULL,
14657         .help_str = "ddp get info <profile_path>",
14658         .tokens = {
14659                 (void *)&cmd_ddp_info_ddp,
14660                 (void *)&cmd_ddp_info_get,
14661                 (void *)&cmd_ddp_info_info,
14662                 (void *)&cmd_ddp_info_filepath,
14663                 NULL,
14664         },
14665 };
14666
14667 /* Get dynamic device personalization profile info list*/
14668 #define PROFILE_INFO_SIZE 48
14669 #define MAX_PROFILE_NUM 16
14670
14671 struct cmd_ddp_get_list_result {
14672         cmdline_fixed_string_t ddp;
14673         cmdline_fixed_string_t get;
14674         cmdline_fixed_string_t list;
14675         portid_t port_id;
14676 };
14677
14678 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14679         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14680 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14681         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14682 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14683         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14684 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14685         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14686
14687 static void
14688 cmd_ddp_get_list_parsed(
14689         void *parsed_result,
14690         __attribute__((unused)) struct cmdline *cl,
14691         __attribute__((unused)) void *data)
14692 {
14693         struct cmd_ddp_get_list_result *res = parsed_result;
14694 #ifdef RTE_LIBRTE_I40E_PMD
14695         struct rte_pmd_i40e_profile_list *p_list;
14696         struct rte_pmd_i40e_profile_info *p_info;
14697         uint32_t p_num;
14698         uint32_t size;
14699         uint32_t i;
14700 #endif
14701         int ret = -ENOTSUP;
14702
14703         if (res->port_id > nb_ports) {
14704                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14705                 return;
14706         }
14707
14708 #ifdef RTE_LIBRTE_I40E_PMD
14709         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14710         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14711         if (!p_list)
14712                 printf("%s: Failed to malloc buffer\n", __func__);
14713
14714         if (ret == -ENOTSUP)
14715                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14716                                                 (uint8_t *)p_list, size);
14717
14718         if (!ret) {
14719                 p_num = p_list->p_count;
14720                 printf("Profile number is: %d\n\n", p_num);
14721
14722                 for (i = 0; i < p_num; i++) {
14723                         p_info = &p_list->p_info[i];
14724                         printf("Profile %d:\n", i);
14725                         printf("Track id:     0x%x\n", p_info->track_id);
14726                         printf("Version:      %d.%d.%d.%d\n",
14727                                p_info->version.major,
14728                                p_info->version.minor,
14729                                p_info->version.update,
14730                                p_info->version.draft);
14731                         printf("Profile name: %s\n\n", p_info->name);
14732                 }
14733         }
14734
14735         free(p_list);
14736 #endif
14737
14738         if (ret < 0)
14739                 printf("Failed to get ddp list\n");
14740 }
14741
14742 cmdline_parse_inst_t cmd_ddp_get_list = {
14743         .f = cmd_ddp_get_list_parsed,
14744         .data = NULL,
14745         .help_str = "ddp get list <port_id>",
14746         .tokens = {
14747                 (void *)&cmd_ddp_get_list_ddp,
14748                 (void *)&cmd_ddp_get_list_get,
14749                 (void *)&cmd_ddp_get_list_list,
14750                 (void *)&cmd_ddp_get_list_port_id,
14751                 NULL,
14752         },
14753 };
14754
14755 /* show vf stats */
14756
14757 /* Common result structure for show vf stats */
14758 struct cmd_show_vf_stats_result {
14759         cmdline_fixed_string_t show;
14760         cmdline_fixed_string_t vf;
14761         cmdline_fixed_string_t stats;
14762         portid_t port_id;
14763         uint16_t vf_id;
14764 };
14765
14766 /* Common CLI fields show vf stats*/
14767 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14768         TOKEN_STRING_INITIALIZER
14769                 (struct cmd_show_vf_stats_result,
14770                  show, "show");
14771 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14772         TOKEN_STRING_INITIALIZER
14773                 (struct cmd_show_vf_stats_result,
14774                  vf, "vf");
14775 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14776         TOKEN_STRING_INITIALIZER
14777                 (struct cmd_show_vf_stats_result,
14778                  stats, "stats");
14779 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14780         TOKEN_NUM_INITIALIZER
14781                 (struct cmd_show_vf_stats_result,
14782                  port_id, UINT16);
14783 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14784         TOKEN_NUM_INITIALIZER
14785                 (struct cmd_show_vf_stats_result,
14786                  vf_id, UINT16);
14787
14788 static void
14789 cmd_show_vf_stats_parsed(
14790         void *parsed_result,
14791         __attribute__((unused)) struct cmdline *cl,
14792         __attribute__((unused)) void *data)
14793 {
14794         struct cmd_show_vf_stats_result *res = parsed_result;
14795         struct rte_eth_stats stats;
14796         int ret = -ENOTSUP;
14797         static const char *nic_stats_border = "########################";
14798
14799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14800                 return;
14801
14802         memset(&stats, 0, sizeof(stats));
14803
14804 #ifdef RTE_LIBRTE_I40E_PMD
14805         if (ret == -ENOTSUP)
14806                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14807                                                 res->vf_id,
14808                                                 &stats);
14809 #endif
14810 #ifdef RTE_LIBRTE_BNXT_PMD
14811         if (ret == -ENOTSUP)
14812                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14813                                                 res->vf_id,
14814                                                 &stats);
14815 #endif
14816
14817         switch (ret) {
14818         case 0:
14819                 break;
14820         case -EINVAL:
14821                 printf("invalid vf_id %d\n", res->vf_id);
14822                 break;
14823         case -ENODEV:
14824                 printf("invalid port_id %d\n", res->port_id);
14825                 break;
14826         case -ENOTSUP:
14827                 printf("function not implemented\n");
14828                 break;
14829         default:
14830                 printf("programming error: (%s)\n", strerror(-ret));
14831         }
14832
14833         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14834                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14835
14836         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14837                "%-"PRIu64"\n",
14838                stats.ipackets, stats.imissed, stats.ibytes);
14839         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14840         printf("  RX-nombuf:  %-10"PRIu64"\n",
14841                stats.rx_nombuf);
14842         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14843                "%-"PRIu64"\n",
14844                stats.opackets, stats.oerrors, stats.obytes);
14845
14846         printf("  %s############################%s\n",
14847                                nic_stats_border, nic_stats_border);
14848 }
14849
14850 cmdline_parse_inst_t cmd_show_vf_stats = {
14851         .f = cmd_show_vf_stats_parsed,
14852         .data = NULL,
14853         .help_str = "show vf stats <port_id> <vf_id>",
14854         .tokens = {
14855                 (void *)&cmd_show_vf_stats_show,
14856                 (void *)&cmd_show_vf_stats_vf,
14857                 (void *)&cmd_show_vf_stats_stats,
14858                 (void *)&cmd_show_vf_stats_port_id,
14859                 (void *)&cmd_show_vf_stats_vf_id,
14860                 NULL,
14861         },
14862 };
14863
14864 /* clear vf stats */
14865
14866 /* Common result structure for clear vf stats */
14867 struct cmd_clear_vf_stats_result {
14868         cmdline_fixed_string_t clear;
14869         cmdline_fixed_string_t vf;
14870         cmdline_fixed_string_t stats;
14871         portid_t port_id;
14872         uint16_t vf_id;
14873 };
14874
14875 /* Common CLI fields clear vf stats*/
14876 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14877         TOKEN_STRING_INITIALIZER
14878                 (struct cmd_clear_vf_stats_result,
14879                  clear, "clear");
14880 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14881         TOKEN_STRING_INITIALIZER
14882                 (struct cmd_clear_vf_stats_result,
14883                  vf, "vf");
14884 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14885         TOKEN_STRING_INITIALIZER
14886                 (struct cmd_clear_vf_stats_result,
14887                  stats, "stats");
14888 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14889         TOKEN_NUM_INITIALIZER
14890                 (struct cmd_clear_vf_stats_result,
14891                  port_id, UINT16);
14892 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14893         TOKEN_NUM_INITIALIZER
14894                 (struct cmd_clear_vf_stats_result,
14895                  vf_id, UINT16);
14896
14897 static void
14898 cmd_clear_vf_stats_parsed(
14899         void *parsed_result,
14900         __attribute__((unused)) struct cmdline *cl,
14901         __attribute__((unused)) void *data)
14902 {
14903         struct cmd_clear_vf_stats_result *res = parsed_result;
14904         int ret = -ENOTSUP;
14905
14906         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14907                 return;
14908
14909 #ifdef RTE_LIBRTE_I40E_PMD
14910         if (ret == -ENOTSUP)
14911                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14912                                                   res->vf_id);
14913 #endif
14914 #ifdef RTE_LIBRTE_BNXT_PMD
14915         if (ret == -ENOTSUP)
14916                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14917                                                   res->vf_id);
14918 #endif
14919
14920         switch (ret) {
14921         case 0:
14922                 break;
14923         case -EINVAL:
14924                 printf("invalid vf_id %d\n", res->vf_id);
14925                 break;
14926         case -ENODEV:
14927                 printf("invalid port_id %d\n", res->port_id);
14928                 break;
14929         case -ENOTSUP:
14930                 printf("function not implemented\n");
14931                 break;
14932         default:
14933                 printf("programming error: (%s)\n", strerror(-ret));
14934         }
14935 }
14936
14937 cmdline_parse_inst_t cmd_clear_vf_stats = {
14938         .f = cmd_clear_vf_stats_parsed,
14939         .data = NULL,
14940         .help_str = "clear vf stats <port_id> <vf_id>",
14941         .tokens = {
14942                 (void *)&cmd_clear_vf_stats_clear,
14943                 (void *)&cmd_clear_vf_stats_vf,
14944                 (void *)&cmd_clear_vf_stats_stats,
14945                 (void *)&cmd_clear_vf_stats_port_id,
14946                 (void *)&cmd_clear_vf_stats_vf_id,
14947                 NULL,
14948         },
14949 };
14950
14951 /* port config pctype mapping reset */
14952
14953 /* Common result structure for port config pctype mapping reset */
14954 struct cmd_pctype_mapping_reset_result {
14955         cmdline_fixed_string_t port;
14956         cmdline_fixed_string_t config;
14957         portid_t port_id;
14958         cmdline_fixed_string_t pctype;
14959         cmdline_fixed_string_t mapping;
14960         cmdline_fixed_string_t reset;
14961 };
14962
14963 /* Common CLI fields for port config pctype mapping reset*/
14964 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14965         TOKEN_STRING_INITIALIZER
14966                 (struct cmd_pctype_mapping_reset_result,
14967                  port, "port");
14968 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14969         TOKEN_STRING_INITIALIZER
14970                 (struct cmd_pctype_mapping_reset_result,
14971                  config, "config");
14972 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14973         TOKEN_NUM_INITIALIZER
14974                 (struct cmd_pctype_mapping_reset_result,
14975                  port_id, UINT16);
14976 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14977         TOKEN_STRING_INITIALIZER
14978                 (struct cmd_pctype_mapping_reset_result,
14979                  pctype, "pctype");
14980 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14981         TOKEN_STRING_INITIALIZER
14982                 (struct cmd_pctype_mapping_reset_result,
14983                  mapping, "mapping");
14984 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14985         TOKEN_STRING_INITIALIZER
14986                 (struct cmd_pctype_mapping_reset_result,
14987                  reset, "reset");
14988
14989 static void
14990 cmd_pctype_mapping_reset_parsed(
14991         void *parsed_result,
14992         __attribute__((unused)) struct cmdline *cl,
14993         __attribute__((unused)) void *data)
14994 {
14995         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14996         int ret = -ENOTSUP;
14997
14998         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14999                 return;
15000
15001 #ifdef RTE_LIBRTE_I40E_PMD
15002         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15003 #endif
15004
15005         switch (ret) {
15006         case 0:
15007                 break;
15008         case -ENODEV:
15009                 printf("invalid port_id %d\n", res->port_id);
15010                 break;
15011         case -ENOTSUP:
15012                 printf("function not implemented\n");
15013                 break;
15014         default:
15015                 printf("programming error: (%s)\n", strerror(-ret));
15016         }
15017 }
15018
15019 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15020         .f = cmd_pctype_mapping_reset_parsed,
15021         .data = NULL,
15022         .help_str = "port config <port_id> pctype mapping reset",
15023         .tokens = {
15024                 (void *)&cmd_pctype_mapping_reset_port,
15025                 (void *)&cmd_pctype_mapping_reset_config,
15026                 (void *)&cmd_pctype_mapping_reset_port_id,
15027                 (void *)&cmd_pctype_mapping_reset_pctype,
15028                 (void *)&cmd_pctype_mapping_reset_mapping,
15029                 (void *)&cmd_pctype_mapping_reset_reset,
15030                 NULL,
15031         },
15032 };
15033
15034 /* show port pctype mapping */
15035
15036 /* Common result structure for show port pctype mapping */
15037 struct cmd_pctype_mapping_get_result {
15038         cmdline_fixed_string_t show;
15039         cmdline_fixed_string_t port;
15040         portid_t port_id;
15041         cmdline_fixed_string_t pctype;
15042         cmdline_fixed_string_t mapping;
15043 };
15044
15045 /* Common CLI fields for pctype mapping get */
15046 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15047         TOKEN_STRING_INITIALIZER
15048                 (struct cmd_pctype_mapping_get_result,
15049                  show, "show");
15050 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15051         TOKEN_STRING_INITIALIZER
15052                 (struct cmd_pctype_mapping_get_result,
15053                  port, "port");
15054 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15055         TOKEN_NUM_INITIALIZER
15056                 (struct cmd_pctype_mapping_get_result,
15057                  port_id, UINT16);
15058 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15059         TOKEN_STRING_INITIALIZER
15060                 (struct cmd_pctype_mapping_get_result,
15061                  pctype, "pctype");
15062 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15063         TOKEN_STRING_INITIALIZER
15064                 (struct cmd_pctype_mapping_get_result,
15065                  mapping, "mapping");
15066
15067 static void
15068 cmd_pctype_mapping_get_parsed(
15069         void *parsed_result,
15070         __attribute__((unused)) struct cmdline *cl,
15071         __attribute__((unused)) void *data)
15072 {
15073         struct cmd_pctype_mapping_get_result *res = parsed_result;
15074         int ret = -ENOTSUP;
15075 #ifdef RTE_LIBRTE_I40E_PMD
15076         struct rte_pmd_i40e_flow_type_mapping
15077                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15078         int i, j, first_pctype;
15079 #endif
15080
15081         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15082                 return;
15083
15084 #ifdef RTE_LIBRTE_I40E_PMD
15085         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15086 #endif
15087
15088         switch (ret) {
15089         case 0:
15090                 break;
15091         case -ENODEV:
15092                 printf("invalid port_id %d\n", res->port_id);
15093                 return;
15094         case -ENOTSUP:
15095                 printf("function not implemented\n");
15096                 return;
15097         default:
15098                 printf("programming error: (%s)\n", strerror(-ret));
15099                 return;
15100         }
15101
15102 #ifdef RTE_LIBRTE_I40E_PMD
15103         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15104                 if (mapping[i].pctype != 0ULL) {
15105                         first_pctype = 1;
15106
15107                         printf("pctype: ");
15108                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15109                                 if (mapping[i].pctype & (1ULL << j)) {
15110                                         printf(first_pctype ?
15111                                                "%02d" : ",%02d", j);
15112                                         first_pctype = 0;
15113                                 }
15114                         }
15115                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15116                 }
15117         }
15118 #endif
15119 }
15120
15121 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15122         .f = cmd_pctype_mapping_get_parsed,
15123         .data = NULL,
15124         .help_str = "show port <port_id> pctype mapping",
15125         .tokens = {
15126                 (void *)&cmd_pctype_mapping_get_show,
15127                 (void *)&cmd_pctype_mapping_get_port,
15128                 (void *)&cmd_pctype_mapping_get_port_id,
15129                 (void *)&cmd_pctype_mapping_get_pctype,
15130                 (void *)&cmd_pctype_mapping_get_mapping,
15131                 NULL,
15132         },
15133 };
15134
15135 /* port config pctype mapping update */
15136
15137 /* Common result structure for port config pctype mapping update */
15138 struct cmd_pctype_mapping_update_result {
15139         cmdline_fixed_string_t port;
15140         cmdline_fixed_string_t config;
15141         portid_t port_id;
15142         cmdline_fixed_string_t pctype;
15143         cmdline_fixed_string_t mapping;
15144         cmdline_fixed_string_t update;
15145         cmdline_fixed_string_t pctype_list;
15146         uint16_t flow_type;
15147 };
15148
15149 /* Common CLI fields for pctype mapping update*/
15150 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15151         TOKEN_STRING_INITIALIZER
15152                 (struct cmd_pctype_mapping_update_result,
15153                  port, "port");
15154 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15155         TOKEN_STRING_INITIALIZER
15156                 (struct cmd_pctype_mapping_update_result,
15157                  config, "config");
15158 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15159         TOKEN_NUM_INITIALIZER
15160                 (struct cmd_pctype_mapping_update_result,
15161                  port_id, UINT16);
15162 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15163         TOKEN_STRING_INITIALIZER
15164                 (struct cmd_pctype_mapping_update_result,
15165                  pctype, "pctype");
15166 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15167         TOKEN_STRING_INITIALIZER
15168                 (struct cmd_pctype_mapping_update_result,
15169                  mapping, "mapping");
15170 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15171         TOKEN_STRING_INITIALIZER
15172                 (struct cmd_pctype_mapping_update_result,
15173                  update, "update");
15174 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15175         TOKEN_STRING_INITIALIZER
15176                 (struct cmd_pctype_mapping_update_result,
15177                  pctype_list, NULL);
15178 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15179         TOKEN_NUM_INITIALIZER
15180                 (struct cmd_pctype_mapping_update_result,
15181                  flow_type, UINT16);
15182
15183 static void
15184 cmd_pctype_mapping_update_parsed(
15185         void *parsed_result,
15186         __attribute__((unused)) struct cmdline *cl,
15187         __attribute__((unused)) void *data)
15188 {
15189         struct cmd_pctype_mapping_update_result *res = parsed_result;
15190         int ret = -ENOTSUP;
15191 #ifdef RTE_LIBRTE_I40E_PMD
15192         struct rte_pmd_i40e_flow_type_mapping mapping;
15193         unsigned int i;
15194         unsigned int nb_item;
15195         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15196 #endif
15197
15198         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15199                 return;
15200
15201 #ifdef RTE_LIBRTE_I40E_PMD
15202         nb_item = parse_item_list(res->pctype_list, "pctypes",
15203                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15204         mapping.flow_type = res->flow_type;
15205         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15206                 mapping.pctype |= (1ULL << pctype_list[i]);
15207         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15208                                                 &mapping,
15209                                                 1,
15210                                                 0);
15211 #endif
15212
15213         switch (ret) {
15214         case 0:
15215                 break;
15216         case -EINVAL:
15217                 printf("invalid pctype or flow type\n");
15218                 break;
15219         case -ENODEV:
15220                 printf("invalid port_id %d\n", res->port_id);
15221                 break;
15222         case -ENOTSUP:
15223                 printf("function not implemented\n");
15224                 break;
15225         default:
15226                 printf("programming error: (%s)\n", strerror(-ret));
15227         }
15228 }
15229
15230 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15231         .f = cmd_pctype_mapping_update_parsed,
15232         .data = NULL,
15233         .help_str = "port config <port_id> pctype mapping update"
15234         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15235         .tokens = {
15236                 (void *)&cmd_pctype_mapping_update_port,
15237                 (void *)&cmd_pctype_mapping_update_config,
15238                 (void *)&cmd_pctype_mapping_update_port_id,
15239                 (void *)&cmd_pctype_mapping_update_pctype,
15240                 (void *)&cmd_pctype_mapping_update_mapping,
15241                 (void *)&cmd_pctype_mapping_update_update,
15242                 (void *)&cmd_pctype_mapping_update_pc_type,
15243                 (void *)&cmd_pctype_mapping_update_flow_type,
15244                 NULL,
15245         },
15246 };
15247
15248 /* ptype mapping get */
15249
15250 /* Common result structure for ptype mapping get */
15251 struct cmd_ptype_mapping_get_result {
15252         cmdline_fixed_string_t ptype;
15253         cmdline_fixed_string_t mapping;
15254         cmdline_fixed_string_t get;
15255         portid_t port_id;
15256         uint8_t valid_only;
15257 };
15258
15259 /* Common CLI fields for ptype mapping get */
15260 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15261         TOKEN_STRING_INITIALIZER
15262                 (struct cmd_ptype_mapping_get_result,
15263                  ptype, "ptype");
15264 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15265         TOKEN_STRING_INITIALIZER
15266                 (struct cmd_ptype_mapping_get_result,
15267                  mapping, "mapping");
15268 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15269         TOKEN_STRING_INITIALIZER
15270                 (struct cmd_ptype_mapping_get_result,
15271                  get, "get");
15272 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15273         TOKEN_NUM_INITIALIZER
15274                 (struct cmd_ptype_mapping_get_result,
15275                  port_id, UINT16);
15276 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15277         TOKEN_NUM_INITIALIZER
15278                 (struct cmd_ptype_mapping_get_result,
15279                  valid_only, UINT8);
15280
15281 static void
15282 cmd_ptype_mapping_get_parsed(
15283         void *parsed_result,
15284         __attribute__((unused)) struct cmdline *cl,
15285         __attribute__((unused)) void *data)
15286 {
15287         struct cmd_ptype_mapping_get_result *res = parsed_result;
15288         int ret = -ENOTSUP;
15289 #ifdef RTE_LIBRTE_I40E_PMD
15290         int max_ptype_num = 256;
15291         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15292         uint16_t count;
15293         int i;
15294 #endif
15295
15296         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15297                 return;
15298
15299 #ifdef RTE_LIBRTE_I40E_PMD
15300         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15301                                         mapping,
15302                                         max_ptype_num,
15303                                         &count,
15304                                         res->valid_only);
15305 #endif
15306
15307         switch (ret) {
15308         case 0:
15309                 break;
15310         case -ENODEV:
15311                 printf("invalid port_id %d\n", res->port_id);
15312                 break;
15313         case -ENOTSUP:
15314                 printf("function not implemented\n");
15315                 break;
15316         default:
15317                 printf("programming error: (%s)\n", strerror(-ret));
15318         }
15319
15320 #ifdef RTE_LIBRTE_I40E_PMD
15321         if (!ret) {
15322                 for (i = 0; i < count; i++)
15323                         printf("%3d\t0x%08x\n",
15324                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15325         }
15326 #endif
15327 }
15328
15329 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15330         .f = cmd_ptype_mapping_get_parsed,
15331         .data = NULL,
15332         .help_str = "ptype mapping get <port_id> <valid_only>",
15333         .tokens = {
15334                 (void *)&cmd_ptype_mapping_get_ptype,
15335                 (void *)&cmd_ptype_mapping_get_mapping,
15336                 (void *)&cmd_ptype_mapping_get_get,
15337                 (void *)&cmd_ptype_mapping_get_port_id,
15338                 (void *)&cmd_ptype_mapping_get_valid_only,
15339                 NULL,
15340         },
15341 };
15342
15343 /* ptype mapping replace */
15344
15345 /* Common result structure for ptype mapping replace */
15346 struct cmd_ptype_mapping_replace_result {
15347         cmdline_fixed_string_t ptype;
15348         cmdline_fixed_string_t mapping;
15349         cmdline_fixed_string_t replace;
15350         portid_t port_id;
15351         uint32_t target;
15352         uint8_t mask;
15353         uint32_t pkt_type;
15354 };
15355
15356 /* Common CLI fields for ptype mapping replace */
15357 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15358         TOKEN_STRING_INITIALIZER
15359                 (struct cmd_ptype_mapping_replace_result,
15360                  ptype, "ptype");
15361 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15362         TOKEN_STRING_INITIALIZER
15363                 (struct cmd_ptype_mapping_replace_result,
15364                  mapping, "mapping");
15365 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15366         TOKEN_STRING_INITIALIZER
15367                 (struct cmd_ptype_mapping_replace_result,
15368                  replace, "replace");
15369 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15370         TOKEN_NUM_INITIALIZER
15371                 (struct cmd_ptype_mapping_replace_result,
15372                  port_id, UINT16);
15373 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15374         TOKEN_NUM_INITIALIZER
15375                 (struct cmd_ptype_mapping_replace_result,
15376                  target, UINT32);
15377 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15378         TOKEN_NUM_INITIALIZER
15379                 (struct cmd_ptype_mapping_replace_result,
15380                  mask, UINT8);
15381 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15382         TOKEN_NUM_INITIALIZER
15383                 (struct cmd_ptype_mapping_replace_result,
15384                  pkt_type, UINT32);
15385
15386 static void
15387 cmd_ptype_mapping_replace_parsed(
15388         void *parsed_result,
15389         __attribute__((unused)) struct cmdline *cl,
15390         __attribute__((unused)) void *data)
15391 {
15392         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15393         int ret = -ENOTSUP;
15394
15395         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15396                 return;
15397
15398 #ifdef RTE_LIBRTE_I40E_PMD
15399         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15400                                         res->target,
15401                                         res->mask,
15402                                         res->pkt_type);
15403 #endif
15404
15405         switch (ret) {
15406         case 0:
15407                 break;
15408         case -EINVAL:
15409                 printf("invalid ptype 0x%8x or 0x%8x\n",
15410                                 res->target, res->pkt_type);
15411                 break;
15412         case -ENODEV:
15413                 printf("invalid port_id %d\n", res->port_id);
15414                 break;
15415         case -ENOTSUP:
15416                 printf("function not implemented\n");
15417                 break;
15418         default:
15419                 printf("programming error: (%s)\n", strerror(-ret));
15420         }
15421 }
15422
15423 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15424         .f = cmd_ptype_mapping_replace_parsed,
15425         .data = NULL,
15426         .help_str =
15427                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15428         .tokens = {
15429                 (void *)&cmd_ptype_mapping_replace_ptype,
15430                 (void *)&cmd_ptype_mapping_replace_mapping,
15431                 (void *)&cmd_ptype_mapping_replace_replace,
15432                 (void *)&cmd_ptype_mapping_replace_port_id,
15433                 (void *)&cmd_ptype_mapping_replace_target,
15434                 (void *)&cmd_ptype_mapping_replace_mask,
15435                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15436                 NULL,
15437         },
15438 };
15439
15440 /* ptype mapping reset */
15441
15442 /* Common result structure for ptype mapping reset */
15443 struct cmd_ptype_mapping_reset_result {
15444         cmdline_fixed_string_t ptype;
15445         cmdline_fixed_string_t mapping;
15446         cmdline_fixed_string_t reset;
15447         portid_t port_id;
15448 };
15449
15450 /* Common CLI fields for ptype mapping reset*/
15451 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15452         TOKEN_STRING_INITIALIZER
15453                 (struct cmd_ptype_mapping_reset_result,
15454                  ptype, "ptype");
15455 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15456         TOKEN_STRING_INITIALIZER
15457                 (struct cmd_ptype_mapping_reset_result,
15458                  mapping, "mapping");
15459 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15460         TOKEN_STRING_INITIALIZER
15461                 (struct cmd_ptype_mapping_reset_result,
15462                  reset, "reset");
15463 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15464         TOKEN_NUM_INITIALIZER
15465                 (struct cmd_ptype_mapping_reset_result,
15466                  port_id, UINT16);
15467
15468 static void
15469 cmd_ptype_mapping_reset_parsed(
15470         void *parsed_result,
15471         __attribute__((unused)) struct cmdline *cl,
15472         __attribute__((unused)) void *data)
15473 {
15474         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15475         int ret = -ENOTSUP;
15476
15477         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15478                 return;
15479
15480 #ifdef RTE_LIBRTE_I40E_PMD
15481         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15482 #endif
15483
15484         switch (ret) {
15485         case 0:
15486                 break;
15487         case -ENODEV:
15488                 printf("invalid port_id %d\n", res->port_id);
15489                 break;
15490         case -ENOTSUP:
15491                 printf("function not implemented\n");
15492                 break;
15493         default:
15494                 printf("programming error: (%s)\n", strerror(-ret));
15495         }
15496 }
15497
15498 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15499         .f = cmd_ptype_mapping_reset_parsed,
15500         .data = NULL,
15501         .help_str = "ptype mapping reset <port_id>",
15502         .tokens = {
15503                 (void *)&cmd_ptype_mapping_reset_ptype,
15504                 (void *)&cmd_ptype_mapping_reset_mapping,
15505                 (void *)&cmd_ptype_mapping_reset_reset,
15506                 (void *)&cmd_ptype_mapping_reset_port_id,
15507                 NULL,
15508         },
15509 };
15510
15511 /* ptype mapping update */
15512
15513 /* Common result structure for ptype mapping update */
15514 struct cmd_ptype_mapping_update_result {
15515         cmdline_fixed_string_t ptype;
15516         cmdline_fixed_string_t mapping;
15517         cmdline_fixed_string_t reset;
15518         portid_t port_id;
15519         uint8_t hw_ptype;
15520         uint32_t sw_ptype;
15521 };
15522
15523 /* Common CLI fields for ptype mapping update*/
15524 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15525         TOKEN_STRING_INITIALIZER
15526                 (struct cmd_ptype_mapping_update_result,
15527                  ptype, "ptype");
15528 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15529         TOKEN_STRING_INITIALIZER
15530                 (struct cmd_ptype_mapping_update_result,
15531                  mapping, "mapping");
15532 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15533         TOKEN_STRING_INITIALIZER
15534                 (struct cmd_ptype_mapping_update_result,
15535                  reset, "update");
15536 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15537         TOKEN_NUM_INITIALIZER
15538                 (struct cmd_ptype_mapping_update_result,
15539                  port_id, UINT16);
15540 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15541         TOKEN_NUM_INITIALIZER
15542                 (struct cmd_ptype_mapping_update_result,
15543                  hw_ptype, UINT8);
15544 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15545         TOKEN_NUM_INITIALIZER
15546                 (struct cmd_ptype_mapping_update_result,
15547                  sw_ptype, UINT32);
15548
15549 static void
15550 cmd_ptype_mapping_update_parsed(
15551         void *parsed_result,
15552         __attribute__((unused)) struct cmdline *cl,
15553         __attribute__((unused)) void *data)
15554 {
15555         struct cmd_ptype_mapping_update_result *res = parsed_result;
15556         int ret = -ENOTSUP;
15557 #ifdef RTE_LIBRTE_I40E_PMD
15558         struct rte_pmd_i40e_ptype_mapping mapping;
15559 #endif
15560         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15561                 return;
15562
15563 #ifdef RTE_LIBRTE_I40E_PMD
15564         mapping.hw_ptype = res->hw_ptype;
15565         mapping.sw_ptype = res->sw_ptype;
15566         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15567                                                 &mapping,
15568                                                 1,
15569                                                 0);
15570 #endif
15571
15572         switch (ret) {
15573         case 0:
15574                 break;
15575         case -EINVAL:
15576                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15577                 break;
15578         case -ENODEV:
15579                 printf("invalid port_id %d\n", res->port_id);
15580                 break;
15581         case -ENOTSUP:
15582                 printf("function not implemented\n");
15583                 break;
15584         default:
15585                 printf("programming error: (%s)\n", strerror(-ret));
15586         }
15587 }
15588
15589 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15590         .f = cmd_ptype_mapping_update_parsed,
15591         .data = NULL,
15592         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15593         .tokens = {
15594                 (void *)&cmd_ptype_mapping_update_ptype,
15595                 (void *)&cmd_ptype_mapping_update_mapping,
15596                 (void *)&cmd_ptype_mapping_update_update,
15597                 (void *)&cmd_ptype_mapping_update_port_id,
15598                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15599                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15600                 NULL,
15601         },
15602 };
15603
15604 /* Common result structure for file commands */
15605 struct cmd_cmdfile_result {
15606         cmdline_fixed_string_t load;
15607         cmdline_fixed_string_t filename;
15608 };
15609
15610 /* Common CLI fields for file commands */
15611 cmdline_parse_token_string_t cmd_load_cmdfile =
15612         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15613 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15614         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15615
15616 static void
15617 cmd_load_from_file_parsed(
15618         void *parsed_result,
15619         __attribute__((unused)) struct cmdline *cl,
15620         __attribute__((unused)) void *data)
15621 {
15622         struct cmd_cmdfile_result *res = parsed_result;
15623
15624         cmdline_read_from_file(res->filename);
15625 }
15626
15627 cmdline_parse_inst_t cmd_load_from_file = {
15628         .f = cmd_load_from_file_parsed,
15629         .data = NULL,
15630         .help_str = "load <filename>",
15631         .tokens = {
15632                 (void *)&cmd_load_cmdfile,
15633                 (void *)&cmd_load_cmdfile_filename,
15634                 NULL,
15635         },
15636 };
15637
15638 /* ******************************************************************************** */
15639
15640 /* list of instructions */
15641 cmdline_parse_ctx_t main_ctx[] = {
15642         (cmdline_parse_inst_t *)&cmd_help_brief,
15643         (cmdline_parse_inst_t *)&cmd_help_long,
15644         (cmdline_parse_inst_t *)&cmd_quit,
15645         (cmdline_parse_inst_t *)&cmd_load_from_file,
15646         (cmdline_parse_inst_t *)&cmd_showport,
15647         (cmdline_parse_inst_t *)&cmd_showqueue,
15648         (cmdline_parse_inst_t *)&cmd_showportall,
15649         (cmdline_parse_inst_t *)&cmd_showcfg,
15650         (cmdline_parse_inst_t *)&cmd_start,
15651         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15652         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15653         (cmdline_parse_inst_t *)&cmd_set_link_up,
15654         (cmdline_parse_inst_t *)&cmd_set_link_down,
15655         (cmdline_parse_inst_t *)&cmd_reset,
15656         (cmdline_parse_inst_t *)&cmd_set_numbers,
15657         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15658         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15659         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15660         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15661         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15662         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15663         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15664         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15665         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15666         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15667         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15668         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15669         (cmdline_parse_inst_t *)&cmd_set_link_check,
15670         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15671         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15672         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15673         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15674 #ifdef RTE_LIBRTE_PMD_BOND
15675         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15676         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15677         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15678         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15679         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15680         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15681         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15682         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15683         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15684         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15685         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15686 #endif
15687         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15688         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15689         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15690         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15691         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15692         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15693         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15694         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15695         (cmdline_parse_inst_t *)&cmd_csum_set,
15696         (cmdline_parse_inst_t *)&cmd_csum_show,
15697         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15698         (cmdline_parse_inst_t *)&cmd_tso_set,
15699         (cmdline_parse_inst_t *)&cmd_tso_show,
15700         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15701         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15702         (cmdline_parse_inst_t *)&cmd_gro_enable,
15703         (cmdline_parse_inst_t *)&cmd_gro_flush,
15704         (cmdline_parse_inst_t *)&cmd_gro_show,
15705         (cmdline_parse_inst_t *)&cmd_gso_enable,
15706         (cmdline_parse_inst_t *)&cmd_gso_size,
15707         (cmdline_parse_inst_t *)&cmd_gso_show,
15708         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15709         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15710         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15711         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15712         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15713         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15714         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15715         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15716         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15717         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15718         (cmdline_parse_inst_t *)&cmd_config_dcb,
15719         (cmdline_parse_inst_t *)&cmd_read_reg,
15720         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15721         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15722         (cmdline_parse_inst_t *)&cmd_write_reg,
15723         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15724         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15725         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15726         (cmdline_parse_inst_t *)&cmd_stop,
15727         (cmdline_parse_inst_t *)&cmd_mac_addr,
15728         (cmdline_parse_inst_t *)&cmd_set_qmap,
15729         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15730         (cmdline_parse_inst_t *)&cmd_operate_port,
15731         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15732         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15733         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15734         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15735         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15736         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15737         (cmdline_parse_inst_t *)&cmd_config_mtu,
15738         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15739         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15740         (cmdline_parse_inst_t *)&cmd_config_rss,
15741         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15742         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15743         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15744         (cmdline_parse_inst_t *)&cmd_showport_reta,
15745         (cmdline_parse_inst_t *)&cmd_config_burst,
15746         (cmdline_parse_inst_t *)&cmd_config_thresh,
15747         (cmdline_parse_inst_t *)&cmd_config_threshold,
15748         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15749         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15750         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15751         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15752         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15753         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15754         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15755         (cmdline_parse_inst_t *)&cmd_global_config,
15756         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15757         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15758         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15759         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15760         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15761         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15762         (cmdline_parse_inst_t *)&cmd_dump,
15763         (cmdline_parse_inst_t *)&cmd_dump_one,
15764         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15765         (cmdline_parse_inst_t *)&cmd_syn_filter,
15766         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15767         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15768         (cmdline_parse_inst_t *)&cmd_flex_filter,
15769         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15770         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15771         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15772         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15773         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15774         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15775         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15776         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15777         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15778         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15779         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15780         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15781         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15782         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15783         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15784         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15785         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15786         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15787         (cmdline_parse_inst_t *)&cmd_flow,
15788         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15789         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15790         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15791         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15792         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15793         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15794         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15795         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15796         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15797         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15798         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15799         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15800         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15801         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15802         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15803         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15804         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15805         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15806         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15807         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15808         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15809         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15810         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15811         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15812         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15813         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15814         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15815         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15816         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15817         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15818         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15819         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15820         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15821         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15822         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15823         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15824         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15825         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15826         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15827         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15828         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15829         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15830         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15831         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15832         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15833         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15834         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15835         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15836         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15837 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15838         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15839 #endif
15840         (cmdline_parse_inst_t *)&cmd_ddp_add,
15841         (cmdline_parse_inst_t *)&cmd_ddp_del,
15842         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15843         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15844         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15845         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15846         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15847         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15848         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15849         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15850
15851         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15852         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15853         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15854         (cmdline_parse_inst_t *)&cmd_queue_region,
15855         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15856         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15857         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15858         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15859         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15860         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15861         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15862         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15863         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15864         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15865         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15866         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15867         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15868         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15869         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15870         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15871         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15872         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15873         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15874         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15875         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15876         NULL,
15877 };
15878
15879 /* read cmdline commands from file */
15880 void
15881 cmdline_read_from_file(const char *filename)
15882 {
15883         struct cmdline *cl;
15884
15885         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15886         if (cl == NULL) {
15887                 printf("Failed to create file based cmdline context: %s\n",
15888                        filename);
15889                 return;
15890         }
15891
15892         cmdline_interact(cl);
15893         cmdline_quit(cl);
15894
15895         cmdline_free(cl);
15896
15897         printf("Read CLI commands from %s\n", filename);
15898 }
15899
15900 /* prompt function, called from main on MASTER lcore */
15901 void
15902 prompt(void)
15903 {
15904         /* initialize non-constant commands */
15905         cmd_set_fwd_mode_init();
15906         cmd_set_fwd_retry_mode_init();
15907
15908         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15909         if (testpmd_cl == NULL)
15910                 return;
15911         cmdline_interact(testpmd_cl);
15912         cmdline_stdin_exit(testpmd_cl);
15913 }
15914
15915 void
15916 prompt_exit(void)
15917 {
15918         if (testpmd_cl != NULL)
15919                 cmdline_quit(testpmd_cl);
15920 }
15921
15922 static void
15923 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15924 {
15925         if (id == (portid_t)RTE_PORT_ALL) {
15926                 portid_t pid;
15927
15928                 RTE_ETH_FOREACH_DEV(pid) {
15929                         /* check if need_reconfig has been set to 1 */
15930                         if (ports[pid].need_reconfig == 0)
15931                                 ports[pid].need_reconfig = dev;
15932                         /* check if need_reconfig_queues has been set to 1 */
15933                         if (ports[pid].need_reconfig_queues == 0)
15934                                 ports[pid].need_reconfig_queues = queue;
15935                 }
15936         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15937                 /* check if need_reconfig has been set to 1 */
15938                 if (ports[id].need_reconfig == 0)
15939                         ports[id].need_reconfig = dev;
15940                 /* check if need_reconfig_queues has been set to 1 */
15941                 if (ports[id].need_reconfig_queues == 0)
15942                         ports[id].need_reconfig_queues = queue;
15943         }
15944 }