app/testpmd: set VF Tx max bandwidth
[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 <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #ifndef __FreeBSD__
46 #include <net/socket.h>
47 #else
48 #include <sys/socket.h>
49 #endif
50 #endif
51 #include <netinet/in.h>
52
53 #include <sys/queue.h>
54
55 #include <rte_common.h>
56 #include <rte_byteorder.h>
57 #include <rte_log.h>
58 #include <rte_debug.h>
59 #include <rte_cycles.h>
60 #include <rte_memory.h>
61 #include <rte_memzone.h>
62 #include <rte_malloc.h>
63 #include <rte_launch.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77 #include <rte_eth_ctrl.h>
78 #include <rte_flow.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 #endif
91 #ifdef RTE_LIBRTE_IXGBE_PMD
92 #include <rte_pmd_ixgbe.h>
93 #endif
94 #ifdef RTE_LIBRTE_I40E_PMD
95 #include <rte_pmd_i40e.h>
96 #endif
97 #include "testpmd.h"
98
99 static struct cmdline *testpmd_cl;
100
101 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
102
103 /* *** Help command with introduction. *** */
104 struct cmd_help_brief_result {
105         cmdline_fixed_string_t help;
106 };
107
108 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
109                                   struct cmdline *cl,
110                                   __attribute__((unused)) void *data)
111 {
112         cmdline_printf(
113                 cl,
114                 "\n"
115                 "Help is available for the following sections:\n\n"
116                 "    help control    : Start and stop forwarding.\n"
117                 "    help display    : Displaying port, stats and config "
118                 "information.\n"
119                 "    help config     : Configuration information.\n"
120                 "    help ports      : Configuring ports.\n"
121                 "    help registers  : Reading and setting port registers.\n"
122                 "    help filters    : Filters configuration help.\n"
123                 "    help all        : All of the above sections.\n\n"
124         );
125
126 }
127
128 cmdline_parse_token_string_t cmd_help_brief_help =
129         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
130
131 cmdline_parse_inst_t cmd_help_brief = {
132         .f = cmd_help_brief_parsed,
133         .data = NULL,
134         .help_str = "help: Show help",
135         .tokens = {
136                 (void *)&cmd_help_brief_help,
137                 NULL,
138         },
139 };
140
141 /* *** Help command with help sections. *** */
142 struct cmd_help_long_result {
143         cmdline_fixed_string_t help;
144         cmdline_fixed_string_t section;
145 };
146
147 static void cmd_help_long_parsed(void *parsed_result,
148                                  struct cmdline *cl,
149                                  __attribute__((unused)) void *data)
150 {
151         int show_all = 0;
152         struct cmd_help_long_result *res = parsed_result;
153
154         if (!strcmp(res->section, "all"))
155                 show_all = 1;
156
157         if (show_all || !strcmp(res->section, "control")) {
158
159                 cmdline_printf(
160                         cl,
161                         "\n"
162                         "Control forwarding:\n"
163                         "-------------------\n\n"
164
165                         "start\n"
166                         "    Start packet forwarding with current configuration.\n\n"
167
168                         "start tx_first\n"
169                         "    Start packet forwarding with current config"
170                         " after sending one burst of packets.\n\n"
171
172                         "stop\n"
173                         "    Stop packet forwarding, and display accumulated"
174                         " statistics.\n\n"
175
176                         "quit\n"
177                         "    Quit to prompt.\n\n"
178                 );
179         }
180
181         if (show_all || !strcmp(res->section, "display")) {
182
183                 cmdline_printf(
184                         cl,
185                         "\n"
186                         "Display:\n"
187                         "--------\n\n"
188
189                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
190                         "    Display information for port_id, or all.\n\n"
191
192                         "show port X rss reta (size) (mask0,mask1,...)\n"
193                         "    Display the rss redirection table entry indicated"
194                         " by masks on port X. size is used to indicate the"
195                         " hardware supported reta size\n\n"
196
197                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
198                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
199                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
200                         "    Display the RSS hash functions and RSS hash key"
201                         " of port X\n\n"
202
203                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
204                         "    Clear information for port_id, or all.\n\n"
205
206                         "show (rxq|txq) info (port_id) (queue_id)\n"
207                         "    Display information for configured RX/TX queue.\n\n"
208
209                         "show config (rxtx|cores|fwd|txpkts)\n"
210                         "    Display the given configuration.\n\n"
211
212                         "read rxd (port_id) (queue_id) (rxd_id)\n"
213                         "    Display an RX descriptor of a port RX queue.\n\n"
214
215                         "read txd (port_id) (queue_id) (txd_id)\n"
216                         "    Display a TX descriptor of a port TX queue.\n\n"
217                 );
218         }
219
220         if (show_all || !strcmp(res->section, "config")) {
221                 cmdline_printf(
222                         cl,
223                         "\n"
224                         "Configuration:\n"
225                         "--------------\n"
226                         "Configuration changes only become active when"
227                         " forwarding is started/restarted.\n\n"
228
229                         "set default\n"
230                         "    Reset forwarding to the default configuration.\n\n"
231
232                         "set verbose (level)\n"
233                         "    Set the debug verbosity level X.\n\n"
234
235                         "set nbport (num)\n"
236                         "    Set number of ports.\n\n"
237
238                         "set nbcore (num)\n"
239                         "    Set number of cores.\n\n"
240
241                         "set coremask (mask)\n"
242                         "    Set the forwarding cores hexadecimal mask.\n\n"
243
244                         "set portmask (mask)\n"
245                         "    Set the forwarding ports hexadecimal mask.\n\n"
246
247                         "set burst (num)\n"
248                         "    Set number of packets per burst.\n\n"
249
250                         "set burst tx delay (microseconds) retry (num)\n"
251                         "    Set the transmit delay time and number of retries,"
252                         " effective when retry is enabled.\n\n"
253
254                         "set txpkts (x[,y]*)\n"
255                         "    Set the length of each segment of TXONLY"
256                         " and optionally CSUM packets.\n\n"
257
258                         "set txsplit (off|on|rand)\n"
259                         "    Set the split policy for the TX packets."
260                         " Right now only applicable for CSUM and TXONLY"
261                         " modes\n\n"
262
263                         "set corelist (x[,y]*)\n"
264                         "    Set the list of forwarding cores.\n\n"
265
266                         "set portlist (x[,y]*)\n"
267                         "    Set the list of forwarding ports.\n\n"
268
269                         "set tx loopback (port_id) (on|off)\n"
270                         "    Enable or disable tx loopback.\n\n"
271
272 #ifdef RTE_LIBRTE_IXGBE_PMD
273                         "set all queues drop (port_id) (on|off)\n"
274                         "    Set drop enable bit for all queues.\n\n"
275
276                         "set vf split drop (port_id) (vf_id) (on|off)\n"
277                         "    Set split drop enable bit for a VF from the PF.\n\n"
278 #endif
279
280                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
281                         "    Set MAC antispoof for a VF from the PF.\n\n"
282
283 #ifdef RTE_LIBRTE_IXGBE_PMD
284                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
285                         "    Enable MACsec offload.\n\n"
286
287                         "set macsec offload (port_id) off\n"
288                         "    Disable MACsec offload.\n\n"
289
290                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
291                         "    Configure MACsec secure connection (SC).\n\n"
292
293                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
294                         "    Configure MACsec secure association (SA).\n\n"
295 #endif
296
297                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
298                         "    Set VF broadcast for a VF from the PF.\n\n"
299
300                         "vlan set strip (on|off) (port_id)\n"
301                         "    Set the VLAN strip on a port.\n\n"
302
303                         "vlan set stripq (on|off) (port_id,queue_id)\n"
304                         "    Set the VLAN strip for a queue on a port.\n\n"
305
306                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
307                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
308
309                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
310                         "    Set VLAN insert for a VF from the PF.\n\n"
311
312                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
313                         "    Set VLAN antispoof for a VF from the PF.\n\n"
314
315                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
316                         "    Set VLAN tag for a VF from the PF.\n\n"
317
318                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
319                         "    Set a VF's max bandwidth(Mbps).\n\n"
320
321                         "vlan set filter (on|off) (port_id)\n"
322                         "    Set the VLAN filter on a port.\n\n"
323
324                         "vlan set qinq (on|off) (port_id)\n"
325                         "    Set the VLAN QinQ (extended queue in queue)"
326                         " on a port.\n\n"
327
328                         "vlan set (inner|outer) tpid (value) (port_id)\n"
329                         "    Set the VLAN TPID for Packet Filtering on"
330                         " a port\n\n"
331
332                         "rx_vlan add (vlan_id|all) (port_id)\n"
333                         "    Add a vlan_id, or all identifiers, to the set"
334                         " of VLAN identifiers filtered by port_id.\n\n"
335
336                         "rx_vlan rm (vlan_id|all) (port_id)\n"
337                         "    Remove a vlan_id, or all identifiers, from the set"
338                         " of VLAN identifiers filtered by port_id.\n\n"
339
340                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
341                         "    Add a vlan_id, to the set of VLAN identifiers"
342                         "filtered for VF(s) from port_id.\n\n"
343
344                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
345                         "    Remove a vlan_id, to the set of VLAN identifiers"
346                         "filtered for VF(s) from port_id.\n\n"
347
348                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
349                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
350                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
351                         "   add a tunnel filter of a port.\n\n"
352
353                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
354                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
355                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
356                         "   remove a tunnel filter of a port.\n\n"
357
358                         "rx_vxlan_port add (udp_port) (port_id)\n"
359                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
360
361                         "rx_vxlan_port rm (udp_port) (port_id)\n"
362                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
363
364                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
365                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
366                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
367
368                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
369                         "    Set port based TX VLAN insertion.\n\n"
370
371                         "tx_vlan reset (port_id)\n"
372                         "    Disable hardware insertion of a VLAN header in"
373                         " packets sent on a port.\n\n"
374
375                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
376                         "    Select hardware or software calculation of the"
377                         " checksum when transmitting a packet using the"
378                         " csum forward engine.\n"
379                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
380                         "    outer-ip concerns the outer IP layer in"
381                         " case the packet is recognized as a tunnel packet by"
382                         " the forward engine (vxlan, gre and ipip are supported)\n"
383                         "    Please check the NIC datasheet for HW limits.\n\n"
384
385                         "csum parse-tunnel (on|off) (tx_port_id)\n"
386                         "    If disabled, treat tunnel packets as non-tunneled"
387                         " packets (treat inner headers as payload). The port\n"
388                         "    argument is the port used for TX in csum forward"
389                         " engine.\n\n"
390
391                         "csum show (port_id)\n"
392                         "    Display tx checksum offload configuration\n\n"
393
394                         "tso set (segsize) (portid)\n"
395                         "    Enable TCP Segmentation Offload in csum forward"
396                         " engine.\n"
397                         "    Please check the NIC datasheet for HW limits.\n\n"
398
399                         "tso show (portid)"
400                         "    Display the status of TCP Segmentation Offload.\n\n"
401
402                         "set fwd (%s)\n"
403                         "    Set packet forwarding mode.\n\n"
404
405                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
406                         "    Add a MAC address on port_id.\n\n"
407
408                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
409                         "    Remove a MAC address from port_id.\n\n"
410
411                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
412                         "    Set the default MAC address for port_id.\n\n"
413
414                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
415                         "    Add a MAC address for a VF on the port.\n\n"
416
417                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
418                         "    Set the MAC address for a VF from the PF.\n\n"
419
420                         "set port (port_id) uta (mac_address|all) (on|off)\n"
421                         "    Add/Remove a or all unicast hash filter(s)"
422                         "from port X.\n\n"
423
424                         "set promisc (port_id|all) (on|off)\n"
425                         "    Set the promiscuous mode on port_id, or all.\n\n"
426
427                         "set allmulti (port_id|all) (on|off)\n"
428                         "    Set the allmulti mode on port_id, or all.\n\n"
429
430                         "set vf promisc (port_id) (vf_id) (on|off)\n"
431                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
432
433                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
434                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
435
436                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
437                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
438                         " (on|off) autoneg (on|off) (port_id)\n"
439                         "set flow_ctrl rx (on|off) (portid)\n"
440                         "set flow_ctrl tx (on|off) (portid)\n"
441                         "set flow_ctrl high_water (high_water) (portid)\n"
442                         "set flow_ctrl low_water (low_water) (portid)\n"
443                         "set flow_ctrl pause_time (pause_time) (portid)\n"
444                         "set flow_ctrl send_xon (send_xon) (portid)\n"
445                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
446                         "set flow_ctrl autoneg (on|off) (port_id)\n"
447                         "    Set the link flow control parameter on a port.\n\n"
448
449                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
450                         " (low_water) (pause_time) (priority) (port_id)\n"
451                         "    Set the priority flow control parameter on a"
452                         " port.\n\n"
453
454                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
455                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
456                         " queue on port.\n"
457                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
458                         " on port 0 to mapping 5.\n\n"
459
460                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
461                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
462
463                         "set port (port_id) vf (vf_id) (mac_addr)"
464                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
465                         "   Add/Remove unicast or multicast MAC addr filter"
466                         " for a VF.\n\n"
467
468                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
469                         "|MPE) (on|off)\n"
470                         "    AUPE:accepts untagged VLAN;"
471                         "ROPE:accept unicast hash\n\n"
472                         "    BAM:accepts broadcast packets;"
473                         "MPE:accepts all multicast packets\n\n"
474                         "    Enable/Disable a VF receive mode of a port\n\n"
475
476                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
477                         "    Set rate limit for a queue of a port\n\n"
478
479                         "set port (port_id) vf (vf_id) rate (rate_num) "
480                         "queue_mask (queue_mask_value)\n"
481                         "    Set rate limit for queues in VF of a port\n\n"
482
483                         "set port (port_id) mirror-rule (rule_id)"
484                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
485                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
486                         "   Set pool or vlan type mirror rule on a port.\n"
487                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
488                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
489                         " to pool 0.\n\n"
490
491                         "set port (port_id) mirror-rule (rule_id)"
492                         " (uplink-mirror|downlink-mirror) dst-pool"
493                         " (pool_id) (on|off)\n"
494                         "   Set uplink or downlink type mirror rule on a port.\n"
495                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
496                         " 0 on' enable mirror income traffic to pool 0.\n\n"
497
498                         "reset port (port_id) mirror-rule (rule_id)\n"
499                         "   Reset a mirror rule.\n\n"
500
501                         "set flush_rx (on|off)\n"
502                         "   Flush (default) or don't flush RX streams before"
503                         " forwarding. Mainly used with PCAP drivers.\n\n"
504
505                         #ifdef RTE_NIC_BYPASS
506                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
507                         "   Set the bypass mode for the lowest port on bypass enabled"
508                         " NIC.\n\n"
509
510                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
511                         "mode (normal|bypass|isolate) (port_id)\n"
512                         "   Set the event required to initiate specified bypass mode for"
513                         " the lowest port on a bypass enabled NIC where:\n"
514                         "       timeout   = enable bypass after watchdog timeout.\n"
515                         "       os_on     = enable bypass when OS/board is powered on.\n"
516                         "       os_off    = enable bypass when OS/board is powered off.\n"
517                         "       power_on  = enable bypass when power supply is turned on.\n"
518                         "       power_off = enable bypass when power supply is turned off."
519                         "\n\n"
520
521                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
522                         "   Set the bypass watchdog timeout to 'n' seconds"
523                         " where 0 = instant.\n\n"
524
525                         "show bypass config (port_id)\n"
526                         "   Show the bypass configuration for a bypass enabled NIC"
527                         " using the lowest port on the NIC.\n\n"
528 #endif
529 #ifdef RTE_LIBRTE_PMD_BOND
530                         "create bonded device (mode) (socket)\n"
531                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
532
533                         "add bonding slave (slave_id) (port_id)\n"
534                         "       Add a slave device to a bonded device.\n\n"
535
536                         "remove bonding slave (slave_id) (port_id)\n"
537                         "       Remove a slave device from a bonded device.\n\n"
538
539                         "set bonding mode (value) (port_id)\n"
540                         "       Set the bonding mode on a bonded device.\n\n"
541
542                         "set bonding primary (slave_id) (port_id)\n"
543                         "       Set the primary slave for a bonded device.\n\n"
544
545                         "show bonding config (port_id)\n"
546                         "       Show the bonding config for port_id.\n\n"
547
548                         "set bonding mac_addr (port_id) (address)\n"
549                         "       Set the MAC address of a bonded device.\n\n"
550
551                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
552                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
553
554                         "set bonding mon_period (port_id) (value)\n"
555                         "       Set the bonding link status monitoring polling period in ms.\n\n"
556 #endif
557                         "set link-up port (port_id)\n"
558                         "       Set link up for a port.\n\n"
559
560                         "set link-down port (port_id)\n"
561                         "       Set link down for a port.\n\n"
562
563                         "E-tag set insertion on port-tag-id (value)"
564                         " port (port_id) vf (vf_id)\n"
565                         "    Enable E-tag insertion for a VF on a port\n\n"
566
567                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
568                         "    Disable E-tag insertion for a VF on a port\n\n"
569
570                         "E-tag set stripping (on|off) port (port_id)\n"
571                         "    Enable/disable E-tag stripping on a port\n\n"
572
573                         "E-tag set forwarding (on|off) port (port_id)\n"
574                         "    Enable/disable E-tag based forwarding"
575                         " on a port\n\n"
576
577                         "E-tag set filter add e-tag-id (value) dst-pool"
578                         " (pool_id) port (port_id)\n"
579                         "    Add an E-tag forwarding filter on a port\n\n"
580
581                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
582                         "    Delete an E-tag forwarding filter on a port\n\n"
583
584                         , list_pkt_forwarding_modes()
585                 );
586         }
587
588         if (show_all || !strcmp(res->section, "ports")) {
589
590                 cmdline_printf(
591                         cl,
592                         "\n"
593                         "Port Operations:\n"
594                         "----------------\n\n"
595
596                         "port start (port_id|all)\n"
597                         "    Start all ports or port_id.\n\n"
598
599                         "port stop (port_id|all)\n"
600                         "    Stop all ports or port_id.\n\n"
601
602                         "port close (port_id|all)\n"
603                         "    Close all ports or port_id.\n\n"
604
605                         "port attach (ident)\n"
606                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
607
608                         "port detach (port_id)\n"
609                         "    Detach physical or virtual dev by port_id\n\n"
610
611                         "port config (port_id|all)"
612                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
613                         " duplex (half|full|auto)\n"
614                         "    Set speed and duplex for all ports or port_id\n\n"
615
616                         "port config all (rxq|txq|rxd|txd) (value)\n"
617                         "    Set number for rxq/txq/rxd/txd.\n\n"
618
619                         "port config all max-pkt-len (value)\n"
620                         "    Set the max packet length.\n\n"
621
622                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
623                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
624                         " (on|off)\n"
625                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
626                         " for ports.\n\n"
627
628                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n"
629                         "    Set the RSS mode.\n\n"
630
631                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
632                         "    Set the RSS redirection table.\n\n"
633
634                         "port config (port_id) dcb vt (on|off) (traffic_class)"
635                         " pfc (on|off)\n"
636                         "    Set the DCB mode.\n\n"
637
638                         "port config all burst (value)\n"
639                         "    Set the number of packets per burst.\n\n"
640
641                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
642                         " (value)\n"
643                         "    Set the ring prefetch/host/writeback threshold"
644                         " for tx/rx queue.\n\n"
645
646                         "port config all (txfreet|txrst|rxfreet) (value)\n"
647                         "    Set free threshold for rx/tx, or set"
648                         " tx rs bit threshold.\n\n"
649                         "port config mtu X value\n"
650                         "    Set the MTU of port X to a given value\n\n"
651
652                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
653                         "    Start/stop a rx/tx queue of port X. Only take effect"
654                         " when port X is started\n\n"
655
656                         "port config (port_id|all) l2-tunnel E-tag ether-type"
657                         " (value)\n"
658                         "    Set the value of E-tag ether-type.\n\n"
659
660                         "port config (port_id|all) l2-tunnel E-tag"
661                         " (enable|disable)\n"
662                         "    Enable/disable the E-tag support.\n\n"
663                 );
664         }
665
666         if (show_all || !strcmp(res->section, "registers")) {
667
668                 cmdline_printf(
669                         cl,
670                         "\n"
671                         "Registers:\n"
672                         "----------\n\n"
673
674                         "read reg (port_id) (address)\n"
675                         "    Display value of a port register.\n\n"
676
677                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
678                         "    Display a port register bit field.\n\n"
679
680                         "read regbit (port_id) (address) (bit_x)\n"
681                         "    Display a single port register bit.\n\n"
682
683                         "write reg (port_id) (address) (value)\n"
684                         "    Set value of a port register.\n\n"
685
686                         "write regfield (port_id) (address) (bit_x) (bit_y)"
687                         " (value)\n"
688                         "    Set bit field of a port register.\n\n"
689
690                         "write regbit (port_id) (address) (bit_x) (value)\n"
691                         "    Set single bit value of a port register.\n\n"
692                 );
693         }
694         if (show_all || !strcmp(res->section, "filters")) {
695
696                 cmdline_printf(
697                         cl,
698                         "\n"
699                         "filters:\n"
700                         "--------\n\n"
701
702                         "ethertype_filter (port_id) (add|del)"
703                         " (mac_addr|mac_ignr) (mac_address) ethertype"
704                         " (ether_type) (drop|fwd) queue (queue_id)\n"
705                         "    Add/Del an ethertype filter.\n\n"
706
707                         "2tuple_filter (port_id) (add|del)"
708                         " dst_port (dst_port_value) protocol (protocol_value)"
709                         " mask (mask_value) tcp_flags (tcp_flags_value)"
710                         " priority (prio_value) queue (queue_id)\n"
711                         "    Add/Del a 2tuple filter.\n\n"
712
713                         "5tuple_filter (port_id) (add|del)"
714                         " dst_ip (dst_address) src_ip (src_address)"
715                         " dst_port (dst_port_value) src_port (src_port_value)"
716                         " protocol (protocol_value)"
717                         " mask (mask_value) tcp_flags (tcp_flags_value)"
718                         " priority (prio_value) queue (queue_id)\n"
719                         "    Add/Del a 5tuple filter.\n\n"
720
721                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
722                         "    Add/Del syn filter.\n\n"
723
724                         "flex_filter (port_id) (add|del) len (len_value)"
725                         " bytes (bytes_value) mask (mask_value)"
726                         " priority (prio_value) queue (queue_id)\n"
727                         "    Add/Del a flex filter.\n\n"
728
729                         "flow_director_filter (port_id) mode IP (add|del|update)"
730                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
731                         " src (src_ip_address) dst (dst_ip_address)"
732                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
733                         " vlan (vlan_value) flexbytes (flexbytes_value)"
734                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
735                         " fd_id (fd_id_value)\n"
736                         "    Add/Del an IP type flow director filter.\n\n"
737
738                         "flow_director_filter (port_id) mode IP (add|del|update)"
739                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
740                         " src (src_ip_address) (src_port)"
741                         " dst (dst_ip_address) (dst_port)"
742                         " tos (tos_value) ttl (ttl_value)"
743                         " vlan (vlan_value) flexbytes (flexbytes_value)"
744                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
745                         " fd_id (fd_id_value)\n"
746                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
747
748                         "flow_director_filter (port_id) mode IP (add|del|update)"
749                         " flow (ipv4-sctp|ipv6-sctp)"
750                         " src (src_ip_address) (src_port)"
751                         " dst (dst_ip_address) (dst_port)"
752                         " tag (verification_tag) "
753                         " tos (tos_value) ttl (ttl_value)"
754                         " vlan (vlan_value)"
755                         " flexbytes (flexbytes_value) (drop|fwd)"
756                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
757                         "    Add/Del a SCTP type flow director filter.\n\n"
758
759                         "flow_director_filter (port_id) mode IP (add|del|update)"
760                         " flow l2_payload ether (ethertype)"
761                         " flexbytes (flexbytes_value) (drop|fwd)"
762                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
763                         "    Add/Del a l2 payload type flow director filter.\n\n"
764
765                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
766                         " mac (mac_address) vlan (vlan_value)"
767                         " flexbytes (flexbytes_value) (drop|fwd)"
768                         " queue (queue_id) fd_id (fd_id_value)\n"
769                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
770
771                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
772                         " mac (mac_address) vlan (vlan_value)"
773                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
774                         " flexbytes (flexbytes_value) (drop|fwd)"
775                         " queue (queue_id) fd_id (fd_id_value)\n"
776                         "    Add/Del a Tunnel flow director filter.\n\n"
777
778                         "flush_flow_director (port_id)\n"
779                         "    Flush all flow director entries of a device.\n\n"
780
781                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
782                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
783                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
784                         "    Set flow director IP mask.\n\n"
785
786                         "flow_director_mask (port_id) mode MAC-VLAN"
787                         " vlan (vlan_value)\n"
788                         "    Set flow director MAC-VLAN mask.\n\n"
789
790                         "flow_director_mask (port_id) mode Tunnel"
791                         " vlan (vlan_value) mac (mac_value)"
792                         " tunnel-type (tunnel_type_value)"
793                         " tunnel-id (tunnel_id_value)\n"
794                         "    Set flow director Tunnel mask.\n\n"
795
796                         "flow_director_flex_mask (port_id)"
797                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
798                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
799                         " (mask)\n"
800                         "    Configure mask of flex payload.\n\n"
801
802                         "flow_director_flex_payload (port_id)"
803                         " (raw|l2|l3|l4) (config)\n"
804                         "    Configure flex payload selection.\n\n"
805
806                         "get_sym_hash_ena_per_port (port_id)\n"
807                         "    get symmetric hash enable configuration per port.\n\n"
808
809                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
810                         "    set symmetric hash enable configuration per port"
811                         " to enable or disable.\n\n"
812
813                         "get_hash_global_config (port_id)\n"
814                         "    Get the global configurations of hash filters.\n\n"
815
816                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
817                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
818                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
819                         " (enable|disable)\n"
820                         "    Set the global configurations of hash filters.\n\n"
821
822                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
823                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
824                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
825                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
826                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
827                         "ipv6-next-header|udp-src-port|udp-dst-port|"
828                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
829                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
830                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
831                         "fld-8th|none) (select|add)\n"
832                         "    Set the input set for hash.\n\n"
833
834                         "set_fdir_input_set (port_id) "
835                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
836                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
837                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
838                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
839                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
840                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
841                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
842                         " (select|add)\n"
843                         "    Set the input set for FDir.\n\n"
844
845                         "flow validate {port_id}"
846                         " [group {group_id}] [priority {level}]"
847                         " [ingress] [egress]"
848                         " pattern {item} [/ {item} [...]] / end"
849                         " actions {action} [/ {action} [...]] / end\n"
850                         "    Check whether a flow rule can be created.\n\n"
851
852                         "flow create {port_id}"
853                         " [group {group_id}] [priority {level}]"
854                         " [ingress] [egress]"
855                         " pattern {item} [/ {item} [...]] / end"
856                         " actions {action} [/ {action} [...]] / end\n"
857                         "    Create a flow rule.\n\n"
858
859                         "flow destroy {port_id} rule {rule_id} [...]\n"
860                         "    Destroy specific flow rules.\n\n"
861
862                         "flow flush {port_id}\n"
863                         "    Destroy all flow rules.\n\n"
864
865                         "flow query {port_id} {rule_id} {action}\n"
866                         "    Query an existing flow rule.\n\n"
867
868                         "flow list {port_id} [group {group_id}] [...]\n"
869                         "    List existing flow rules sorted by priority,"
870                         " filtered by group identifiers.\n\n"
871                 );
872         }
873 }
874
875 cmdline_parse_token_string_t cmd_help_long_help =
876         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
877
878 cmdline_parse_token_string_t cmd_help_long_section =
879         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
880                         "all#control#display#config#"
881                         "ports#registers#filters");
882
883 cmdline_parse_inst_t cmd_help_long = {
884         .f = cmd_help_long_parsed,
885         .data = NULL,
886         .help_str = "help all|control|display|config|ports|register|filters: "
887                 "Show help",
888         .tokens = {
889                 (void *)&cmd_help_long_help,
890                 (void *)&cmd_help_long_section,
891                 NULL,
892         },
893 };
894
895
896 /* *** start/stop/close all ports *** */
897 struct cmd_operate_port_result {
898         cmdline_fixed_string_t keyword;
899         cmdline_fixed_string_t name;
900         cmdline_fixed_string_t value;
901 };
902
903 static void cmd_operate_port_parsed(void *parsed_result,
904                                 __attribute__((unused)) struct cmdline *cl,
905                                 __attribute__((unused)) void *data)
906 {
907         struct cmd_operate_port_result *res = parsed_result;
908
909         if (!strcmp(res->name, "start"))
910                 start_port(RTE_PORT_ALL);
911         else if (!strcmp(res->name, "stop"))
912                 stop_port(RTE_PORT_ALL);
913         else if (!strcmp(res->name, "close"))
914                 close_port(RTE_PORT_ALL);
915         else
916                 printf("Unknown parameter\n");
917 }
918
919 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
920         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
921                                                                 "port");
922 cmdline_parse_token_string_t cmd_operate_port_all_port =
923         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
924                                                 "start#stop#close");
925 cmdline_parse_token_string_t cmd_operate_port_all_all =
926         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
927
928 cmdline_parse_inst_t cmd_operate_port = {
929         .f = cmd_operate_port_parsed,
930         .data = NULL,
931         .help_str = "port start|stop|close all: Start/Stop/Close all ports",
932         .tokens = {
933                 (void *)&cmd_operate_port_all_cmd,
934                 (void *)&cmd_operate_port_all_port,
935                 (void *)&cmd_operate_port_all_all,
936                 NULL,
937         },
938 };
939
940 /* *** start/stop/close specific port *** */
941 struct cmd_operate_specific_port_result {
942         cmdline_fixed_string_t keyword;
943         cmdline_fixed_string_t name;
944         uint8_t value;
945 };
946
947 static void cmd_operate_specific_port_parsed(void *parsed_result,
948                         __attribute__((unused)) struct cmdline *cl,
949                                 __attribute__((unused)) void *data)
950 {
951         struct cmd_operate_specific_port_result *res = parsed_result;
952
953         if (!strcmp(res->name, "start"))
954                 start_port(res->value);
955         else if (!strcmp(res->name, "stop"))
956                 stop_port(res->value);
957         else if (!strcmp(res->name, "close"))
958                 close_port(res->value);
959         else
960                 printf("Unknown parameter\n");
961 }
962
963 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
964         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
965                                                         keyword, "port");
966 cmdline_parse_token_string_t cmd_operate_specific_port_port =
967         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
968                                                 name, "start#stop#close");
969 cmdline_parse_token_num_t cmd_operate_specific_port_id =
970         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
971                                                         value, UINT8);
972
973 cmdline_parse_inst_t cmd_operate_specific_port = {
974         .f = cmd_operate_specific_port_parsed,
975         .data = NULL,
976         .help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id",
977         .tokens = {
978                 (void *)&cmd_operate_specific_port_cmd,
979                 (void *)&cmd_operate_specific_port_port,
980                 (void *)&cmd_operate_specific_port_id,
981                 NULL,
982         },
983 };
984
985 /* *** attach a specified port *** */
986 struct cmd_operate_attach_port_result {
987         cmdline_fixed_string_t port;
988         cmdline_fixed_string_t keyword;
989         cmdline_fixed_string_t identifier;
990 };
991
992 static void cmd_operate_attach_port_parsed(void *parsed_result,
993                                 __attribute__((unused)) struct cmdline *cl,
994                                 __attribute__((unused)) void *data)
995 {
996         struct cmd_operate_attach_port_result *res = parsed_result;
997
998         if (!strcmp(res->keyword, "attach"))
999                 attach_port(res->identifier);
1000         else
1001                 printf("Unknown parameter\n");
1002 }
1003
1004 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1005         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1006                         port, "port");
1007 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1008         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1009                         keyword, "attach");
1010 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1011         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1012                         identifier, NULL);
1013
1014 cmdline_parse_inst_t cmd_operate_attach_port = {
1015         .f = cmd_operate_attach_port_parsed,
1016         .data = NULL,
1017         .help_str = "port attach <identifier>: "
1018                 "(identifier: pci address or virtual dev name)",
1019         .tokens = {
1020                 (void *)&cmd_operate_attach_port_port,
1021                 (void *)&cmd_operate_attach_port_keyword,
1022                 (void *)&cmd_operate_attach_port_identifier,
1023                 NULL,
1024         },
1025 };
1026
1027 /* *** detach a specified port *** */
1028 struct cmd_operate_detach_port_result {
1029         cmdline_fixed_string_t port;
1030         cmdline_fixed_string_t keyword;
1031         uint8_t port_id;
1032 };
1033
1034 static void cmd_operate_detach_port_parsed(void *parsed_result,
1035                                 __attribute__((unused)) struct cmdline *cl,
1036                                 __attribute__((unused)) void *data)
1037 {
1038         struct cmd_operate_detach_port_result *res = parsed_result;
1039
1040         if (!strcmp(res->keyword, "detach"))
1041                 detach_port(res->port_id);
1042         else
1043                 printf("Unknown parameter\n");
1044 }
1045
1046 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1047         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1048                         port, "port");
1049 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1050         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1051                         keyword, "detach");
1052 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1053         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1054                         port_id, UINT8);
1055
1056 cmdline_parse_inst_t cmd_operate_detach_port = {
1057         .f = cmd_operate_detach_port_parsed,
1058         .data = NULL,
1059         .help_str = "port detach <port_id>",
1060         .tokens = {
1061                 (void *)&cmd_operate_detach_port_port,
1062                 (void *)&cmd_operate_detach_port_keyword,
1063                 (void *)&cmd_operate_detach_port_port_id,
1064                 NULL,
1065         },
1066 };
1067
1068 /* *** configure speed for all ports *** */
1069 struct cmd_config_speed_all {
1070         cmdline_fixed_string_t port;
1071         cmdline_fixed_string_t keyword;
1072         cmdline_fixed_string_t all;
1073         cmdline_fixed_string_t item1;
1074         cmdline_fixed_string_t item2;
1075         cmdline_fixed_string_t value1;
1076         cmdline_fixed_string_t value2;
1077 };
1078
1079 static int
1080 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1081 {
1082
1083         int duplex;
1084
1085         if (!strcmp(duplexstr, "half")) {
1086                 duplex = ETH_LINK_HALF_DUPLEX;
1087         } else if (!strcmp(duplexstr, "full")) {
1088                 duplex = ETH_LINK_FULL_DUPLEX;
1089         } else if (!strcmp(duplexstr, "auto")) {
1090                 duplex = ETH_LINK_FULL_DUPLEX;
1091         } else {
1092                 printf("Unknown duplex parameter\n");
1093                 return -1;
1094         }
1095
1096         if (!strcmp(speedstr, "10")) {
1097                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1098                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1099         } else if (!strcmp(speedstr, "100")) {
1100                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1101                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1102         } else {
1103                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1104                         printf("Invalid speed/duplex parameters\n");
1105                         return -1;
1106                 }
1107                 if (!strcmp(speedstr, "1000")) {
1108                         *speed = ETH_LINK_SPEED_1G;
1109                 } else if (!strcmp(speedstr, "10000")) {
1110                         *speed = ETH_LINK_SPEED_10G;
1111                 } else if (!strcmp(speedstr, "25000")) {
1112                         *speed = ETH_LINK_SPEED_25G;
1113                 } else if (!strcmp(speedstr, "40000")) {
1114                         *speed = ETH_LINK_SPEED_40G;
1115                 } else if (!strcmp(speedstr, "50000")) {
1116                         *speed = ETH_LINK_SPEED_50G;
1117                 } else if (!strcmp(speedstr, "100000")) {
1118                         *speed = ETH_LINK_SPEED_100G;
1119                 } else if (!strcmp(speedstr, "auto")) {
1120                         *speed = ETH_LINK_SPEED_AUTONEG;
1121                 } else {
1122                         printf("Unknown speed parameter\n");
1123                         return -1;
1124                 }
1125         }
1126
1127         return 0;
1128 }
1129
1130 static void
1131 cmd_config_speed_all_parsed(void *parsed_result,
1132                         __attribute__((unused)) struct cmdline *cl,
1133                         __attribute__((unused)) void *data)
1134 {
1135         struct cmd_config_speed_all *res = parsed_result;
1136         uint32_t link_speed;
1137         portid_t pid;
1138
1139         if (!all_ports_stopped()) {
1140                 printf("Please stop all ports first\n");
1141                 return;
1142         }
1143
1144         if (parse_and_check_speed_duplex(res->value1, res->value2,
1145                         &link_speed) < 0)
1146                 return;
1147
1148         FOREACH_PORT(pid, ports) {
1149                 ports[pid].dev_conf.link_speeds = link_speed;
1150         }
1151
1152         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1153 }
1154
1155 cmdline_parse_token_string_t cmd_config_speed_all_port =
1156         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1157 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1158         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1159                                                         "config");
1160 cmdline_parse_token_string_t cmd_config_speed_all_all =
1161         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1162 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1163         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1164 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1165         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1166                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1167 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1168         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1169 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1170         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1171                                                 "half#full#auto");
1172
1173 cmdline_parse_inst_t cmd_config_speed_all = {
1174         .f = cmd_config_speed_all_parsed,
1175         .data = NULL,
1176         .help_str = "port config all speed "
1177                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1178                                                         "half|full|auto",
1179         .tokens = {
1180                 (void *)&cmd_config_speed_all_port,
1181                 (void *)&cmd_config_speed_all_keyword,
1182                 (void *)&cmd_config_speed_all_all,
1183                 (void *)&cmd_config_speed_all_item1,
1184                 (void *)&cmd_config_speed_all_value1,
1185                 (void *)&cmd_config_speed_all_item2,
1186                 (void *)&cmd_config_speed_all_value2,
1187                 NULL,
1188         },
1189 };
1190
1191 /* *** configure speed for specific port *** */
1192 struct cmd_config_speed_specific {
1193         cmdline_fixed_string_t port;
1194         cmdline_fixed_string_t keyword;
1195         uint8_t id;
1196         cmdline_fixed_string_t item1;
1197         cmdline_fixed_string_t item2;
1198         cmdline_fixed_string_t value1;
1199         cmdline_fixed_string_t value2;
1200 };
1201
1202 static void
1203 cmd_config_speed_specific_parsed(void *parsed_result,
1204                                 __attribute__((unused)) struct cmdline *cl,
1205                                 __attribute__((unused)) void *data)
1206 {
1207         struct cmd_config_speed_specific *res = parsed_result;
1208         uint32_t link_speed;
1209
1210         if (!all_ports_stopped()) {
1211                 printf("Please stop all ports first\n");
1212                 return;
1213         }
1214
1215         if (port_id_is_invalid(res->id, ENABLED_WARN))
1216                 return;
1217
1218         if (parse_and_check_speed_duplex(res->value1, res->value2,
1219                         &link_speed) < 0)
1220                 return;
1221
1222         ports[res->id].dev_conf.link_speeds = link_speed;
1223
1224         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1225 }
1226
1227
1228 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1229         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1230                                                                 "port");
1231 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1232         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1233                                                                 "config");
1234 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1235         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1236 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1237         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1238                                                                 "speed");
1239 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1240         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1241                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1242 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1243         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1244                                                                 "duplex");
1245 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1246         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1247                                                         "half#full#auto");
1248
1249 cmdline_parse_inst_t cmd_config_speed_specific = {
1250         .f = cmd_config_speed_specific_parsed,
1251         .data = NULL,
1252         .help_str = "port config <port_id> speed "
1253                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1254                                                         "half|full|auto",
1255         .tokens = {
1256                 (void *)&cmd_config_speed_specific_port,
1257                 (void *)&cmd_config_speed_specific_keyword,
1258                 (void *)&cmd_config_speed_specific_id,
1259                 (void *)&cmd_config_speed_specific_item1,
1260                 (void *)&cmd_config_speed_specific_value1,
1261                 (void *)&cmd_config_speed_specific_item2,
1262                 (void *)&cmd_config_speed_specific_value2,
1263                 NULL,
1264         },
1265 };
1266
1267 /* *** configure txq/rxq, txd/rxd *** */
1268 struct cmd_config_rx_tx {
1269         cmdline_fixed_string_t port;
1270         cmdline_fixed_string_t keyword;
1271         cmdline_fixed_string_t all;
1272         cmdline_fixed_string_t name;
1273         uint16_t value;
1274 };
1275
1276 static void
1277 cmd_config_rx_tx_parsed(void *parsed_result,
1278                         __attribute__((unused)) struct cmdline *cl,
1279                         __attribute__((unused)) void *data)
1280 {
1281         struct cmd_config_rx_tx *res = parsed_result;
1282
1283         if (!all_ports_stopped()) {
1284                 printf("Please stop all ports first\n");
1285                 return;
1286         }
1287         if (!strcmp(res->name, "rxq")) {
1288                 if (!res->value && !nb_txq) {
1289                         printf("Warning: Either rx or tx queues should be non zero\n");
1290                         return;
1291                 }
1292                 nb_rxq = res->value;
1293         }
1294         else if (!strcmp(res->name, "txq")) {
1295                 if (!res->value && !nb_rxq) {
1296                         printf("Warning: Either rx or tx queues should be non zero\n");
1297                         return;
1298                 }
1299                 nb_txq = res->value;
1300         }
1301         else if (!strcmp(res->name, "rxd")) {
1302                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1303                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1304                                         res->value, RTE_TEST_RX_DESC_MAX);
1305                         return;
1306                 }
1307                 nb_rxd = res->value;
1308         } else if (!strcmp(res->name, "txd")) {
1309                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1310                         printf("txd %d invalid - must be > 0 && <= %d\n",
1311                                         res->value, RTE_TEST_TX_DESC_MAX);
1312                         return;
1313                 }
1314                 nb_txd = res->value;
1315         } else {
1316                 printf("Unknown parameter\n");
1317                 return;
1318         }
1319
1320         fwd_config_setup();
1321
1322         init_port_config();
1323
1324         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1325 }
1326
1327 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1328         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1329 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1330         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1331 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1332         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1333 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1334         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1335                                                 "rxq#txq#rxd#txd");
1336 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1337         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1338
1339 cmdline_parse_inst_t cmd_config_rx_tx = {
1340         .f = cmd_config_rx_tx_parsed,
1341         .data = NULL,
1342         .help_str = "port config all rxq|txq|rxd|txd <value>",
1343         .tokens = {
1344                 (void *)&cmd_config_rx_tx_port,
1345                 (void *)&cmd_config_rx_tx_keyword,
1346                 (void *)&cmd_config_rx_tx_all,
1347                 (void *)&cmd_config_rx_tx_name,
1348                 (void *)&cmd_config_rx_tx_value,
1349                 NULL,
1350         },
1351 };
1352
1353 /* *** config max packet length *** */
1354 struct cmd_config_max_pkt_len_result {
1355         cmdline_fixed_string_t port;
1356         cmdline_fixed_string_t keyword;
1357         cmdline_fixed_string_t all;
1358         cmdline_fixed_string_t name;
1359         uint32_t value;
1360 };
1361
1362 static void
1363 cmd_config_max_pkt_len_parsed(void *parsed_result,
1364                                 __attribute__((unused)) struct cmdline *cl,
1365                                 __attribute__((unused)) void *data)
1366 {
1367         struct cmd_config_max_pkt_len_result *res = parsed_result;
1368
1369         if (!all_ports_stopped()) {
1370                 printf("Please stop all ports first\n");
1371                 return;
1372         }
1373
1374         if (!strcmp(res->name, "max-pkt-len")) {
1375                 if (res->value < ETHER_MIN_LEN) {
1376                         printf("max-pkt-len can not be less than %d\n",
1377                                                         ETHER_MIN_LEN);
1378                         return;
1379                 }
1380                 if (res->value == rx_mode.max_rx_pkt_len)
1381                         return;
1382
1383                 rx_mode.max_rx_pkt_len = res->value;
1384                 if (res->value > ETHER_MAX_LEN)
1385                         rx_mode.jumbo_frame = 1;
1386                 else
1387                         rx_mode.jumbo_frame = 0;
1388         } else {
1389                 printf("Unknown parameter\n");
1390                 return;
1391         }
1392
1393         init_port_config();
1394
1395         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1396 }
1397
1398 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1400                                                                 "port");
1401 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1403                                                                 "config");
1404 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1406                                                                 "all");
1407 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1408         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1409                                                                 "max-pkt-len");
1410 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1411         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1412                                                                 UINT32);
1413
1414 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1415         .f = cmd_config_max_pkt_len_parsed,
1416         .data = NULL,
1417         .help_str = "port config all max-pkt-len <value>",
1418         .tokens = {
1419                 (void *)&cmd_config_max_pkt_len_port,
1420                 (void *)&cmd_config_max_pkt_len_keyword,
1421                 (void *)&cmd_config_max_pkt_len_all,
1422                 (void *)&cmd_config_max_pkt_len_name,
1423                 (void *)&cmd_config_max_pkt_len_value,
1424                 NULL,
1425         },
1426 };
1427
1428 /* *** configure port MTU *** */
1429 struct cmd_config_mtu_result {
1430         cmdline_fixed_string_t port;
1431         cmdline_fixed_string_t keyword;
1432         cmdline_fixed_string_t mtu;
1433         uint8_t port_id;
1434         uint16_t value;
1435 };
1436
1437 static void
1438 cmd_config_mtu_parsed(void *parsed_result,
1439                       __attribute__((unused)) struct cmdline *cl,
1440                       __attribute__((unused)) void *data)
1441 {
1442         struct cmd_config_mtu_result *res = parsed_result;
1443
1444         if (res->value < ETHER_MIN_LEN) {
1445                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1446                 return;
1447         }
1448         port_mtu_set(res->port_id, res->value);
1449 }
1450
1451 cmdline_parse_token_string_t cmd_config_mtu_port =
1452         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1453                                  "port");
1454 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1455         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1456                                  "config");
1457 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1459                                  "mtu");
1460 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1461         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1462 cmdline_parse_token_num_t cmd_config_mtu_value =
1463         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1464
1465 cmdline_parse_inst_t cmd_config_mtu = {
1466         .f = cmd_config_mtu_parsed,
1467         .data = NULL,
1468         .help_str = "port config mtu <port_id> <value>",
1469         .tokens = {
1470                 (void *)&cmd_config_mtu_port,
1471                 (void *)&cmd_config_mtu_keyword,
1472                 (void *)&cmd_config_mtu_mtu,
1473                 (void *)&cmd_config_mtu_port_id,
1474                 (void *)&cmd_config_mtu_value,
1475                 NULL,
1476         },
1477 };
1478
1479 /* *** configure rx mode *** */
1480 struct cmd_config_rx_mode_flag {
1481         cmdline_fixed_string_t port;
1482         cmdline_fixed_string_t keyword;
1483         cmdline_fixed_string_t all;
1484         cmdline_fixed_string_t name;
1485         cmdline_fixed_string_t value;
1486 };
1487
1488 static void
1489 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1490                                 __attribute__((unused)) struct cmdline *cl,
1491                                 __attribute__((unused)) void *data)
1492 {
1493         struct cmd_config_rx_mode_flag *res = parsed_result;
1494
1495         if (!all_ports_stopped()) {
1496                 printf("Please stop all ports first\n");
1497                 return;
1498         }
1499
1500         if (!strcmp(res->name, "crc-strip")) {
1501                 if (!strcmp(res->value, "on"))
1502                         rx_mode.hw_strip_crc = 1;
1503                 else if (!strcmp(res->value, "off"))
1504                         rx_mode.hw_strip_crc = 0;
1505                 else {
1506                         printf("Unknown parameter\n");
1507                         return;
1508                 }
1509         } else if (!strcmp(res->name, "scatter")) {
1510                 if (!strcmp(res->value, "on"))
1511                         rx_mode.enable_scatter = 1;
1512                 else if (!strcmp(res->value, "off"))
1513                         rx_mode.enable_scatter = 0;
1514                 else {
1515                         printf("Unknown parameter\n");
1516                         return;
1517                 }
1518         } else if (!strcmp(res->name, "rx-cksum")) {
1519                 if (!strcmp(res->value, "on"))
1520                         rx_mode.hw_ip_checksum = 1;
1521                 else if (!strcmp(res->value, "off"))
1522                         rx_mode.hw_ip_checksum = 0;
1523                 else {
1524                         printf("Unknown parameter\n");
1525                         return;
1526                 }
1527         } else if (!strcmp(res->name, "hw-vlan")) {
1528                 if (!strcmp(res->value, "on")) {
1529                         rx_mode.hw_vlan_filter = 1;
1530                         rx_mode.hw_vlan_strip  = 1;
1531                 }
1532                 else if (!strcmp(res->value, "off")) {
1533                         rx_mode.hw_vlan_filter = 0;
1534                         rx_mode.hw_vlan_strip  = 0;
1535                 }
1536                 else {
1537                         printf("Unknown parameter\n");
1538                         return;
1539                 }
1540         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1541                 if (!strcmp(res->value, "on"))
1542                         rx_mode.hw_vlan_filter = 1;
1543                 else if (!strcmp(res->value, "off"))
1544                         rx_mode.hw_vlan_filter = 0;
1545                 else {
1546                         printf("Unknown parameter\n");
1547                         return;
1548                 }
1549         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1550                 if (!strcmp(res->value, "on"))
1551                         rx_mode.hw_vlan_strip  = 1;
1552                 else if (!strcmp(res->value, "off"))
1553                         rx_mode.hw_vlan_strip  = 0;
1554                 else {
1555                         printf("Unknown parameter\n");
1556                         return;
1557                 }
1558         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1559                 if (!strcmp(res->value, "on"))
1560                         rx_mode.hw_vlan_extend = 1;
1561                 else if (!strcmp(res->value, "off"))
1562                         rx_mode.hw_vlan_extend = 0;
1563                 else {
1564                         printf("Unknown parameter\n");
1565                         return;
1566                 }
1567         } else if (!strcmp(res->name, "drop-en")) {
1568                 if (!strcmp(res->value, "on"))
1569                         rx_drop_en = 1;
1570                 else if (!strcmp(res->value, "off"))
1571                         rx_drop_en = 0;
1572                 else {
1573                         printf("Unknown parameter\n");
1574                         return;
1575                 }
1576         } else {
1577                 printf("Unknown parameter\n");
1578                 return;
1579         }
1580
1581         init_port_config();
1582
1583         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1584 }
1585
1586 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1587         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1588 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1590                                                                 "config");
1591 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1592         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1593 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1594         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1595                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1596                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1597 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1599                                                         "on#off");
1600
1601 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1602         .f = cmd_config_rx_mode_flag_parsed,
1603         .data = NULL,
1604         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1605                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1606         .tokens = {
1607                 (void *)&cmd_config_rx_mode_flag_port,
1608                 (void *)&cmd_config_rx_mode_flag_keyword,
1609                 (void *)&cmd_config_rx_mode_flag_all,
1610                 (void *)&cmd_config_rx_mode_flag_name,
1611                 (void *)&cmd_config_rx_mode_flag_value,
1612                 NULL,
1613         },
1614 };
1615
1616 /* *** configure rss *** */
1617 struct cmd_config_rss {
1618         cmdline_fixed_string_t port;
1619         cmdline_fixed_string_t keyword;
1620         cmdline_fixed_string_t all;
1621         cmdline_fixed_string_t name;
1622         cmdline_fixed_string_t value;
1623 };
1624
1625 static void
1626 cmd_config_rss_parsed(void *parsed_result,
1627                         __attribute__((unused)) struct cmdline *cl,
1628                         __attribute__((unused)) void *data)
1629 {
1630         struct cmd_config_rss *res = parsed_result;
1631         struct rte_eth_rss_conf rss_conf;
1632         int diag;
1633         uint8_t i;
1634
1635         if (!strcmp(res->value, "all"))
1636                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1637                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1638                                         ETH_RSS_L2_PAYLOAD;
1639         else if (!strcmp(res->value, "ip"))
1640                 rss_conf.rss_hf = ETH_RSS_IP;
1641         else if (!strcmp(res->value, "udp"))
1642                 rss_conf.rss_hf = ETH_RSS_UDP;
1643         else if (!strcmp(res->value, "tcp"))
1644                 rss_conf.rss_hf = ETH_RSS_TCP;
1645         else if (!strcmp(res->value, "sctp"))
1646                 rss_conf.rss_hf = ETH_RSS_SCTP;
1647         else if (!strcmp(res->value, "ether"))
1648                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1649         else if (!strcmp(res->value, "port"))
1650                 rss_conf.rss_hf = ETH_RSS_PORT;
1651         else if (!strcmp(res->value, "vxlan"))
1652                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1653         else if (!strcmp(res->value, "geneve"))
1654                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1655         else if (!strcmp(res->value, "nvgre"))
1656                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1657         else if (!strcmp(res->value, "none"))
1658                 rss_conf.rss_hf = 0;
1659         else {
1660                 printf("Unknown parameter\n");
1661                 return;
1662         }
1663         rss_conf.rss_key = NULL;
1664         for (i = 0; i < rte_eth_dev_count(); i++) {
1665                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1666                 if (diag < 0)
1667                         printf("Configuration of RSS hash at ethernet port %d "
1668                                 "failed with error (%d): %s.\n",
1669                                 i, -diag, strerror(-diag));
1670         }
1671 }
1672
1673 cmdline_parse_token_string_t cmd_config_rss_port =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1675 cmdline_parse_token_string_t cmd_config_rss_keyword =
1676         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1677 cmdline_parse_token_string_t cmd_config_rss_all =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1679 cmdline_parse_token_string_t cmd_config_rss_name =
1680         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1681 cmdline_parse_token_string_t cmd_config_rss_value =
1682         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1683                 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none");
1684
1685 cmdline_parse_inst_t cmd_config_rss = {
1686         .f = cmd_config_rss_parsed,
1687         .data = NULL,
1688         .help_str = "port config all rss "
1689                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none",
1690         .tokens = {
1691                 (void *)&cmd_config_rss_port,
1692                 (void *)&cmd_config_rss_keyword,
1693                 (void *)&cmd_config_rss_all,
1694                 (void *)&cmd_config_rss_name,
1695                 (void *)&cmd_config_rss_value,
1696                 NULL,
1697         },
1698 };
1699
1700 /* *** configure rss hash key *** */
1701 struct cmd_config_rss_hash_key {
1702         cmdline_fixed_string_t port;
1703         cmdline_fixed_string_t config;
1704         uint8_t port_id;
1705         cmdline_fixed_string_t rss_hash_key;
1706         cmdline_fixed_string_t rss_type;
1707         cmdline_fixed_string_t key;
1708 };
1709
1710 static uint8_t
1711 hexa_digit_to_value(char hexa_digit)
1712 {
1713         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1714                 return (uint8_t) (hexa_digit - '0');
1715         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1716                 return (uint8_t) ((hexa_digit - 'a') + 10);
1717         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1718                 return (uint8_t) ((hexa_digit - 'A') + 10);
1719         /* Invalid hexa digit */
1720         return 0xFF;
1721 }
1722
1723 static uint8_t
1724 parse_and_check_key_hexa_digit(char *key, int idx)
1725 {
1726         uint8_t hexa_v;
1727
1728         hexa_v = hexa_digit_to_value(key[idx]);
1729         if (hexa_v == 0xFF)
1730                 printf("invalid key: character %c at position %d is not a "
1731                        "valid hexa digit\n", key[idx], idx);
1732         return hexa_v;
1733 }
1734
1735 static void
1736 cmd_config_rss_hash_key_parsed(void *parsed_result,
1737                                __attribute__((unused)) struct cmdline *cl,
1738                                __attribute__((unused)) void *data)
1739 {
1740         struct cmd_config_rss_hash_key *res = parsed_result;
1741         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1742         uint8_t xdgt0;
1743         uint8_t xdgt1;
1744         int i;
1745         struct rte_eth_dev_info dev_info;
1746         uint8_t hash_key_size;
1747         uint32_t key_len;
1748
1749         memset(&dev_info, 0, sizeof(dev_info));
1750         rte_eth_dev_info_get(res->port_id, &dev_info);
1751         if (dev_info.hash_key_size > 0 &&
1752                         dev_info.hash_key_size <= sizeof(hash_key))
1753                 hash_key_size = dev_info.hash_key_size;
1754         else {
1755                 printf("dev_info did not provide a valid hash key size\n");
1756                 return;
1757         }
1758         /* Check the length of the RSS hash key */
1759         key_len = strlen(res->key);
1760         if (key_len != (hash_key_size * 2)) {
1761                 printf("key length: %d invalid - key must be a string of %d"
1762                            " hexa-decimal numbers\n",
1763                            (int) key_len, hash_key_size * 2);
1764                 return;
1765         }
1766         /* Translate RSS hash key into binary representation */
1767         for (i = 0; i < hash_key_size; i++) {
1768                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1769                 if (xdgt0 == 0xFF)
1770                         return;
1771                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1772                 if (xdgt1 == 0xFF)
1773                         return;
1774                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1775         }
1776         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1777                         hash_key_size);
1778 }
1779
1780 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1781         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1782 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1783         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1784                                  "config");
1785 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1786         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1787 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1789                                  rss_hash_key, "rss-hash-key");
1790 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1792                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1793                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1794                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1795                                  "ipv6-tcp-ex#ipv6-udp-ex");
1796 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1798
1799 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1800         .f = cmd_config_rss_hash_key_parsed,
1801         .data = NULL,
1802         .help_str = "port config <port_id> rss-hash-key "
1803                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1804                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1805                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1806                 "<string of hex digits (variable length, NIC dependent)>",
1807         .tokens = {
1808                 (void *)&cmd_config_rss_hash_key_port,
1809                 (void *)&cmd_config_rss_hash_key_config,
1810                 (void *)&cmd_config_rss_hash_key_port_id,
1811                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1812                 (void *)&cmd_config_rss_hash_key_rss_type,
1813                 (void *)&cmd_config_rss_hash_key_value,
1814                 NULL,
1815         },
1816 };
1817
1818 /* *** configure port rxq/txq start/stop *** */
1819 struct cmd_config_rxtx_queue {
1820         cmdline_fixed_string_t port;
1821         uint8_t portid;
1822         cmdline_fixed_string_t rxtxq;
1823         uint16_t qid;
1824         cmdline_fixed_string_t opname;
1825 };
1826
1827 static void
1828 cmd_config_rxtx_queue_parsed(void *parsed_result,
1829                         __attribute__((unused)) struct cmdline *cl,
1830                         __attribute__((unused)) void *data)
1831 {
1832         struct cmd_config_rxtx_queue *res = parsed_result;
1833         uint8_t isrx;
1834         uint8_t isstart;
1835         int ret = 0;
1836
1837         if (test_done == 0) {
1838                 printf("Please stop forwarding first\n");
1839                 return;
1840         }
1841
1842         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1843                 return;
1844
1845         if (port_is_started(res->portid) != 1) {
1846                 printf("Please start port %u first\n", res->portid);
1847                 return;
1848         }
1849
1850         if (!strcmp(res->rxtxq, "rxq"))
1851                 isrx = 1;
1852         else if (!strcmp(res->rxtxq, "txq"))
1853                 isrx = 0;
1854         else {
1855                 printf("Unknown parameter\n");
1856                 return;
1857         }
1858
1859         if (isrx && rx_queue_id_is_invalid(res->qid))
1860                 return;
1861         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1862                 return;
1863
1864         if (!strcmp(res->opname, "start"))
1865                 isstart = 1;
1866         else if (!strcmp(res->opname, "stop"))
1867                 isstart = 0;
1868         else {
1869                 printf("Unknown parameter\n");
1870                 return;
1871         }
1872
1873         if (isstart && isrx)
1874                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1875         else if (!isstart && isrx)
1876                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1877         else if (isstart && !isrx)
1878                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1879         else
1880                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1881
1882         if (ret == -ENOTSUP)
1883                 printf("Function not supported in PMD driver\n");
1884 }
1885
1886 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1887         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1888 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1889         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1890 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1891         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1892 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1893         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1894 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1895         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1896                                                 "start#stop");
1897
1898 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1899         .f = cmd_config_rxtx_queue_parsed,
1900         .data = NULL,
1901         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1902         .tokens = {
1903                 (void *)&cmd_config_speed_all_port,
1904                 (void *)&cmd_config_rxtx_queue_portid,
1905                 (void *)&cmd_config_rxtx_queue_rxtxq,
1906                 (void *)&cmd_config_rxtx_queue_qid,
1907                 (void *)&cmd_config_rxtx_queue_opname,
1908                 NULL,
1909         },
1910 };
1911
1912 /* *** Configure RSS RETA *** */
1913 struct cmd_config_rss_reta {
1914         cmdline_fixed_string_t port;
1915         cmdline_fixed_string_t keyword;
1916         uint8_t port_id;
1917         cmdline_fixed_string_t name;
1918         cmdline_fixed_string_t list_name;
1919         cmdline_fixed_string_t list_of_items;
1920 };
1921
1922 static int
1923 parse_reta_config(const char *str,
1924                   struct rte_eth_rss_reta_entry64 *reta_conf,
1925                   uint16_t nb_entries)
1926 {
1927         int i;
1928         unsigned size;
1929         uint16_t hash_index, idx, shift;
1930         uint16_t nb_queue;
1931         char s[256];
1932         const char *p, *p0 = str;
1933         char *end;
1934         enum fieldnames {
1935                 FLD_HASH_INDEX = 0,
1936                 FLD_QUEUE,
1937                 _NUM_FLD
1938         };
1939         unsigned long int_fld[_NUM_FLD];
1940         char *str_fld[_NUM_FLD];
1941
1942         while ((p = strchr(p0,'(')) != NULL) {
1943                 ++p;
1944                 if((p0 = strchr(p,')')) == NULL)
1945                         return -1;
1946
1947                 size = p0 - p;
1948                 if(size >= sizeof(s))
1949                         return -1;
1950
1951                 snprintf(s, sizeof(s), "%.*s", size, p);
1952                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1953                         return -1;
1954                 for (i = 0; i < _NUM_FLD; i++) {
1955                         errno = 0;
1956                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1957                         if (errno != 0 || end == str_fld[i] ||
1958                                         int_fld[i] > 65535)
1959                                 return -1;
1960                 }
1961
1962                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
1963                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
1964
1965                 if (hash_index >= nb_entries) {
1966                         printf("Invalid RETA hash index=%d\n", hash_index);
1967                         return -1;
1968                 }
1969
1970                 idx = hash_index / RTE_RETA_GROUP_SIZE;
1971                 shift = hash_index % RTE_RETA_GROUP_SIZE;
1972                 reta_conf[idx].mask |= (1ULL << shift);
1973                 reta_conf[idx].reta[shift] = nb_queue;
1974         }
1975
1976         return 0;
1977 }
1978
1979 static void
1980 cmd_set_rss_reta_parsed(void *parsed_result,
1981                         __attribute__((unused)) struct cmdline *cl,
1982                         __attribute__((unused)) void *data)
1983 {
1984         int ret;
1985         struct rte_eth_dev_info dev_info;
1986         struct rte_eth_rss_reta_entry64 reta_conf[8];
1987         struct cmd_config_rss_reta *res = parsed_result;
1988
1989         memset(&dev_info, 0, sizeof(dev_info));
1990         rte_eth_dev_info_get(res->port_id, &dev_info);
1991         if (dev_info.reta_size == 0) {
1992                 printf("Redirection table size is 0 which is "
1993                                         "invalid for RSS\n");
1994                 return;
1995         } else
1996                 printf("The reta size of port %d is %u\n",
1997                         res->port_id, dev_info.reta_size);
1998         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
1999                 printf("Currently do not support more than %u entries of "
2000                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2001                 return;
2002         }
2003
2004         memset(reta_conf, 0, sizeof(reta_conf));
2005         if (!strcmp(res->list_name, "reta")) {
2006                 if (parse_reta_config(res->list_of_items, reta_conf,
2007                                                 dev_info.reta_size)) {
2008                         printf("Invalid RSS Redirection Table "
2009                                         "config entered\n");
2010                         return;
2011                 }
2012                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2013                                 reta_conf, dev_info.reta_size);
2014                 if (ret != 0)
2015                         printf("Bad redirection table parameter, "
2016                                         "return code = %d \n", ret);
2017         }
2018 }
2019
2020 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2022 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2023         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2024 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2025         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2026 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2027         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2028 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2029         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2030 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2031         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2032                                  NULL);
2033 cmdline_parse_inst_t cmd_config_rss_reta = {
2034         .f = cmd_set_rss_reta_parsed,
2035         .data = NULL,
2036         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2037         .tokens = {
2038                 (void *)&cmd_config_rss_reta_port,
2039                 (void *)&cmd_config_rss_reta_keyword,
2040                 (void *)&cmd_config_rss_reta_port_id,
2041                 (void *)&cmd_config_rss_reta_name,
2042                 (void *)&cmd_config_rss_reta_list_name,
2043                 (void *)&cmd_config_rss_reta_list_of_items,
2044                 NULL,
2045         },
2046 };
2047
2048 /* *** SHOW PORT RETA INFO *** */
2049 struct cmd_showport_reta {
2050         cmdline_fixed_string_t show;
2051         cmdline_fixed_string_t port;
2052         uint8_t port_id;
2053         cmdline_fixed_string_t rss;
2054         cmdline_fixed_string_t reta;
2055         uint16_t size;
2056         cmdline_fixed_string_t list_of_items;
2057 };
2058
2059 static int
2060 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2061                            uint16_t nb_entries,
2062                            char *str)
2063 {
2064         uint32_t size;
2065         const char *p, *p0 = str;
2066         char s[256];
2067         char *end;
2068         char *str_fld[8];
2069         uint16_t i, num = nb_entries / RTE_RETA_GROUP_SIZE;
2070         int ret;
2071
2072         p = strchr(p0, '(');
2073         if (p == NULL)
2074                 return -1;
2075         p++;
2076         p0 = strchr(p, ')');
2077         if (p0 == NULL)
2078                 return -1;
2079         size = p0 - p;
2080         if (size >= sizeof(s)) {
2081                 printf("The string size exceeds the internal buffer size\n");
2082                 return -1;
2083         }
2084         snprintf(s, sizeof(s), "%.*s", size, p);
2085         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2086         if (ret <= 0 || ret != num) {
2087                 printf("The bits of masks do not match the number of "
2088                                         "reta entries: %u\n", num);
2089                 return -1;
2090         }
2091         for (i = 0; i < ret; i++)
2092                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2093
2094         return 0;
2095 }
2096
2097 static void
2098 cmd_showport_reta_parsed(void *parsed_result,
2099                          __attribute__((unused)) struct cmdline *cl,
2100                          __attribute__((unused)) void *data)
2101 {
2102         struct cmd_showport_reta *res = parsed_result;
2103         struct rte_eth_rss_reta_entry64 reta_conf[8];
2104         struct rte_eth_dev_info dev_info;
2105
2106         memset(&dev_info, 0, sizeof(dev_info));
2107         rte_eth_dev_info_get(res->port_id, &dev_info);
2108         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2109                                 res->size > ETH_RSS_RETA_SIZE_512) {
2110                 printf("Invalid redirection table size: %u\n", res->size);
2111                 return;
2112         }
2113
2114         memset(reta_conf, 0, sizeof(reta_conf));
2115         if (showport_parse_reta_config(reta_conf, res->size,
2116                                 res->list_of_items) < 0) {
2117                 printf("Invalid string: %s for reta masks\n",
2118                                         res->list_of_items);
2119                 return;
2120         }
2121         port_rss_reta_info(res->port_id, reta_conf, res->size);
2122 }
2123
2124 cmdline_parse_token_string_t cmd_showport_reta_show =
2125         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2126 cmdline_parse_token_string_t cmd_showport_reta_port =
2127         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2128 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2129         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2130 cmdline_parse_token_string_t cmd_showport_reta_rss =
2131         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2132 cmdline_parse_token_string_t cmd_showport_reta_reta =
2133         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2134 cmdline_parse_token_num_t cmd_showport_reta_size =
2135         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2136 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2137         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2138                                         list_of_items, NULL);
2139
2140 cmdline_parse_inst_t cmd_showport_reta = {
2141         .f = cmd_showport_reta_parsed,
2142         .data = NULL,
2143         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2144         .tokens = {
2145                 (void *)&cmd_showport_reta_show,
2146                 (void *)&cmd_showport_reta_port,
2147                 (void *)&cmd_showport_reta_port_id,
2148                 (void *)&cmd_showport_reta_rss,
2149                 (void *)&cmd_showport_reta_reta,
2150                 (void *)&cmd_showport_reta_size,
2151                 (void *)&cmd_showport_reta_list_of_items,
2152                 NULL,
2153         },
2154 };
2155
2156 /* *** Show RSS hash configuration *** */
2157 struct cmd_showport_rss_hash {
2158         cmdline_fixed_string_t show;
2159         cmdline_fixed_string_t port;
2160         uint8_t port_id;
2161         cmdline_fixed_string_t rss_hash;
2162         cmdline_fixed_string_t rss_type;
2163         cmdline_fixed_string_t key; /* optional argument */
2164 };
2165
2166 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2167                                 __attribute__((unused)) struct cmdline *cl,
2168                                 void *show_rss_key)
2169 {
2170         struct cmd_showport_rss_hash *res = parsed_result;
2171
2172         port_rss_hash_conf_show(res->port_id, res->rss_type,
2173                                 show_rss_key != NULL);
2174 }
2175
2176 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2177         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2178 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2179         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2180 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2181         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2182 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2183         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2184                                  "rss-hash");
2185 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2186         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2187                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2188                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2189                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2190                                  "ipv6-tcp-ex#ipv6-udp-ex");
2191 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2192         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2193
2194 cmdline_parse_inst_t cmd_showport_rss_hash = {
2195         .f = cmd_showport_rss_hash_parsed,
2196         .data = NULL,
2197         .help_str = "show port <port_id> rss-hash "
2198                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2199                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2200                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2201         .tokens = {
2202                 (void *)&cmd_showport_rss_hash_show,
2203                 (void *)&cmd_showport_rss_hash_port,
2204                 (void *)&cmd_showport_rss_hash_port_id,
2205                 (void *)&cmd_showport_rss_hash_rss_hash,
2206                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2207                 NULL,
2208         },
2209 };
2210
2211 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2212         .f = cmd_showport_rss_hash_parsed,
2213         .data = (void *)1,
2214         .help_str = "show port <port_id> rss-hash "
2215                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2216                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2217                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2218         .tokens = {
2219                 (void *)&cmd_showport_rss_hash_show,
2220                 (void *)&cmd_showport_rss_hash_port,
2221                 (void *)&cmd_showport_rss_hash_port_id,
2222                 (void *)&cmd_showport_rss_hash_rss_hash,
2223                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2224                 (void *)&cmd_showport_rss_hash_rss_key,
2225                 NULL,
2226         },
2227 };
2228
2229 /* *** Configure DCB *** */
2230 struct cmd_config_dcb {
2231         cmdline_fixed_string_t port;
2232         cmdline_fixed_string_t config;
2233         uint8_t port_id;
2234         cmdline_fixed_string_t dcb;
2235         cmdline_fixed_string_t vt;
2236         cmdline_fixed_string_t vt_en;
2237         uint8_t num_tcs;
2238         cmdline_fixed_string_t pfc;
2239         cmdline_fixed_string_t pfc_en;
2240 };
2241
2242 static void
2243 cmd_config_dcb_parsed(void *parsed_result,
2244                         __attribute__((unused)) struct cmdline *cl,
2245                         __attribute__((unused)) void *data)
2246 {
2247         struct cmd_config_dcb *res = parsed_result;
2248         portid_t port_id = res->port_id;
2249         struct rte_port *port;
2250         uint8_t pfc_en;
2251         int ret;
2252
2253         port = &ports[port_id];
2254         /** Check if the port is not started **/
2255         if (port->port_status != RTE_PORT_STOPPED) {
2256                 printf("Please stop port %d first\n", port_id);
2257                 return;
2258         }
2259
2260         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2261                 printf("The invalid number of traffic class,"
2262                         " only 4 or 8 allowed.\n");
2263                 return;
2264         }
2265
2266         if (nb_fwd_lcores < res->num_tcs) {
2267                 printf("nb_cores shouldn't be less than number of TCs.\n");
2268                 return;
2269         }
2270         if (!strncmp(res->pfc_en, "on", 2))
2271                 pfc_en = 1;
2272         else
2273                 pfc_en = 0;
2274
2275         /* DCB in VT mode */
2276         if (!strncmp(res->vt_en, "on", 2))
2277                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2278                                 (enum rte_eth_nb_tcs)res->num_tcs,
2279                                 pfc_en);
2280         else
2281                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2282                                 (enum rte_eth_nb_tcs)res->num_tcs,
2283                                 pfc_en);
2284
2285
2286         if (ret != 0) {
2287                 printf("Cannot initialize network ports.\n");
2288                 return;
2289         }
2290
2291         cmd_reconfig_device_queue(port_id, 1, 1);
2292 }
2293
2294 cmdline_parse_token_string_t cmd_config_dcb_port =
2295         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2296 cmdline_parse_token_string_t cmd_config_dcb_config =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2298 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2299         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2300 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2302 cmdline_parse_token_string_t cmd_config_dcb_vt =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2304 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2306 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2307         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2308 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2309         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2310 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2311         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2312
2313 cmdline_parse_inst_t cmd_config_dcb = {
2314         .f = cmd_config_dcb_parsed,
2315         .data = NULL,
2316         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2317         .tokens = {
2318                 (void *)&cmd_config_dcb_port,
2319                 (void *)&cmd_config_dcb_config,
2320                 (void *)&cmd_config_dcb_port_id,
2321                 (void *)&cmd_config_dcb_dcb,
2322                 (void *)&cmd_config_dcb_vt,
2323                 (void *)&cmd_config_dcb_vt_en,
2324                 (void *)&cmd_config_dcb_num_tcs,
2325                 (void *)&cmd_config_dcb_pfc,
2326                 (void *)&cmd_config_dcb_pfc_en,
2327                 NULL,
2328         },
2329 };
2330
2331 /* *** configure number of packets per burst *** */
2332 struct cmd_config_burst {
2333         cmdline_fixed_string_t port;
2334         cmdline_fixed_string_t keyword;
2335         cmdline_fixed_string_t all;
2336         cmdline_fixed_string_t name;
2337         uint16_t value;
2338 };
2339
2340 static void
2341 cmd_config_burst_parsed(void *parsed_result,
2342                         __attribute__((unused)) struct cmdline *cl,
2343                         __attribute__((unused)) void *data)
2344 {
2345         struct cmd_config_burst *res = parsed_result;
2346
2347         if (!all_ports_stopped()) {
2348                 printf("Please stop all ports first\n");
2349                 return;
2350         }
2351
2352         if (!strcmp(res->name, "burst")) {
2353                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2354                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2355                         return;
2356                 }
2357                 nb_pkt_per_burst = res->value;
2358         } else {
2359                 printf("Unknown parameter\n");
2360                 return;
2361         }
2362
2363         init_port_config();
2364
2365         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2366 }
2367
2368 cmdline_parse_token_string_t cmd_config_burst_port =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2370 cmdline_parse_token_string_t cmd_config_burst_keyword =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2372 cmdline_parse_token_string_t cmd_config_burst_all =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2374 cmdline_parse_token_string_t cmd_config_burst_name =
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2376 cmdline_parse_token_num_t cmd_config_burst_value =
2377         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2378
2379 cmdline_parse_inst_t cmd_config_burst = {
2380         .f = cmd_config_burst_parsed,
2381         .data = NULL,
2382         .help_str = "port config all burst <value>",
2383         .tokens = {
2384                 (void *)&cmd_config_burst_port,
2385                 (void *)&cmd_config_burst_keyword,
2386                 (void *)&cmd_config_burst_all,
2387                 (void *)&cmd_config_burst_name,
2388                 (void *)&cmd_config_burst_value,
2389                 NULL,
2390         },
2391 };
2392
2393 /* *** configure rx/tx queues *** */
2394 struct cmd_config_thresh {
2395         cmdline_fixed_string_t port;
2396         cmdline_fixed_string_t keyword;
2397         cmdline_fixed_string_t all;
2398         cmdline_fixed_string_t name;
2399         uint8_t value;
2400 };
2401
2402 static void
2403 cmd_config_thresh_parsed(void *parsed_result,
2404                         __attribute__((unused)) struct cmdline *cl,
2405                         __attribute__((unused)) void *data)
2406 {
2407         struct cmd_config_thresh *res = parsed_result;
2408
2409         if (!all_ports_stopped()) {
2410                 printf("Please stop all ports first\n");
2411                 return;
2412         }
2413
2414         if (!strcmp(res->name, "txpt"))
2415                 tx_pthresh = res->value;
2416         else if(!strcmp(res->name, "txht"))
2417                 tx_hthresh = res->value;
2418         else if(!strcmp(res->name, "txwt"))
2419                 tx_wthresh = res->value;
2420         else if(!strcmp(res->name, "rxpt"))
2421                 rx_pthresh = res->value;
2422         else if(!strcmp(res->name, "rxht"))
2423                 rx_hthresh = res->value;
2424         else if(!strcmp(res->name, "rxwt"))
2425                 rx_wthresh = res->value;
2426         else {
2427                 printf("Unknown parameter\n");
2428                 return;
2429         }
2430
2431         init_port_config();
2432
2433         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2434 }
2435
2436 cmdline_parse_token_string_t cmd_config_thresh_port =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2438 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2440 cmdline_parse_token_string_t cmd_config_thresh_all =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2442 cmdline_parse_token_string_t cmd_config_thresh_name =
2443         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2444                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2445 cmdline_parse_token_num_t cmd_config_thresh_value =
2446         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2447
2448 cmdline_parse_inst_t cmd_config_thresh = {
2449         .f = cmd_config_thresh_parsed,
2450         .data = NULL,
2451         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2452         .tokens = {
2453                 (void *)&cmd_config_thresh_port,
2454                 (void *)&cmd_config_thresh_keyword,
2455                 (void *)&cmd_config_thresh_all,
2456                 (void *)&cmd_config_thresh_name,
2457                 (void *)&cmd_config_thresh_value,
2458                 NULL,
2459         },
2460 };
2461
2462 /* *** configure free/rs threshold *** */
2463 struct cmd_config_threshold {
2464         cmdline_fixed_string_t port;
2465         cmdline_fixed_string_t keyword;
2466         cmdline_fixed_string_t all;
2467         cmdline_fixed_string_t name;
2468         uint16_t value;
2469 };
2470
2471 static void
2472 cmd_config_threshold_parsed(void *parsed_result,
2473                         __attribute__((unused)) struct cmdline *cl,
2474                         __attribute__((unused)) void *data)
2475 {
2476         struct cmd_config_threshold *res = parsed_result;
2477
2478         if (!all_ports_stopped()) {
2479                 printf("Please stop all ports first\n");
2480                 return;
2481         }
2482
2483         if (!strcmp(res->name, "txfreet"))
2484                 tx_free_thresh = res->value;
2485         else if (!strcmp(res->name, "txrst"))
2486                 tx_rs_thresh = res->value;
2487         else if (!strcmp(res->name, "rxfreet"))
2488                 rx_free_thresh = res->value;
2489         else {
2490                 printf("Unknown parameter\n");
2491                 return;
2492         }
2493
2494         init_port_config();
2495
2496         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2497 }
2498
2499 cmdline_parse_token_string_t cmd_config_threshold_port =
2500         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2501 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2502         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2503                                                                 "config");
2504 cmdline_parse_token_string_t cmd_config_threshold_all =
2505         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2506 cmdline_parse_token_string_t cmd_config_threshold_name =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2508                                                 "txfreet#txrst#rxfreet");
2509 cmdline_parse_token_num_t cmd_config_threshold_value =
2510         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2511
2512 cmdline_parse_inst_t cmd_config_threshold = {
2513         .f = cmd_config_threshold_parsed,
2514         .data = NULL,
2515         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2516         .tokens = {
2517                 (void *)&cmd_config_threshold_port,
2518                 (void *)&cmd_config_threshold_keyword,
2519                 (void *)&cmd_config_threshold_all,
2520                 (void *)&cmd_config_threshold_name,
2521                 (void *)&cmd_config_threshold_value,
2522                 NULL,
2523         },
2524 };
2525
2526 /* *** stop *** */
2527 struct cmd_stop_result {
2528         cmdline_fixed_string_t stop;
2529 };
2530
2531 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2532                             __attribute__((unused)) struct cmdline *cl,
2533                             __attribute__((unused)) void *data)
2534 {
2535         stop_packet_forwarding();
2536 }
2537
2538 cmdline_parse_token_string_t cmd_stop_stop =
2539         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2540
2541 cmdline_parse_inst_t cmd_stop = {
2542         .f = cmd_stop_parsed,
2543         .data = NULL,
2544         .help_str = "stop: Stop packet forwarding",
2545         .tokens = {
2546                 (void *)&cmd_stop_stop,
2547                 NULL,
2548         },
2549 };
2550
2551 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2552
2553 unsigned int
2554 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2555                 unsigned int *parsed_items, int check_unique_values)
2556 {
2557         unsigned int nb_item;
2558         unsigned int value;
2559         unsigned int i;
2560         unsigned int j;
2561         int value_ok;
2562         char c;
2563
2564         /*
2565          * First parse all items in the list and store their value.
2566          */
2567         value = 0;
2568         nb_item = 0;
2569         value_ok = 0;
2570         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2571                 c = str[i];
2572                 if ((c >= '0') && (c <= '9')) {
2573                         value = (unsigned int) (value * 10 + (c - '0'));
2574                         value_ok = 1;
2575                         continue;
2576                 }
2577                 if (c != ',') {
2578                         printf("character %c is not a decimal digit\n", c);
2579                         return 0;
2580                 }
2581                 if (! value_ok) {
2582                         printf("No valid value before comma\n");
2583                         return 0;
2584                 }
2585                 if (nb_item < max_items) {
2586                         parsed_items[nb_item] = value;
2587                         value_ok = 0;
2588                         value = 0;
2589                 }
2590                 nb_item++;
2591         }
2592         if (nb_item >= max_items) {
2593                 printf("Number of %s = %u > %u (maximum items)\n",
2594                        item_name, nb_item + 1, max_items);
2595                 return 0;
2596         }
2597         parsed_items[nb_item++] = value;
2598         if (! check_unique_values)
2599                 return nb_item;
2600
2601         /*
2602          * Then, check that all values in the list are differents.
2603          * No optimization here...
2604          */
2605         for (i = 0; i < nb_item; i++) {
2606                 for (j = i + 1; j < nb_item; j++) {
2607                         if (parsed_items[j] == parsed_items[i]) {
2608                                 printf("duplicated %s %u at index %u and %u\n",
2609                                        item_name, parsed_items[i], i, j);
2610                                 return 0;
2611                         }
2612                 }
2613         }
2614         return nb_item;
2615 }
2616
2617 struct cmd_set_list_result {
2618         cmdline_fixed_string_t cmd_keyword;
2619         cmdline_fixed_string_t list_name;
2620         cmdline_fixed_string_t list_of_items;
2621 };
2622
2623 static void cmd_set_list_parsed(void *parsed_result,
2624                                 __attribute__((unused)) struct cmdline *cl,
2625                                 __attribute__((unused)) void *data)
2626 {
2627         struct cmd_set_list_result *res;
2628         union {
2629                 unsigned int lcorelist[RTE_MAX_LCORE];
2630                 unsigned int portlist[RTE_MAX_ETHPORTS];
2631         } parsed_items;
2632         unsigned int nb_item;
2633
2634         if (test_done == 0) {
2635                 printf("Please stop forwarding first\n");
2636                 return;
2637         }
2638
2639         res = parsed_result;
2640         if (!strcmp(res->list_name, "corelist")) {
2641                 nb_item = parse_item_list(res->list_of_items, "core",
2642                                           RTE_MAX_LCORE,
2643                                           parsed_items.lcorelist, 1);
2644                 if (nb_item > 0) {
2645                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2646                         fwd_config_setup();
2647                 }
2648                 return;
2649         }
2650         if (!strcmp(res->list_name, "portlist")) {
2651                 nb_item = parse_item_list(res->list_of_items, "port",
2652                                           RTE_MAX_ETHPORTS,
2653                                           parsed_items.portlist, 1);
2654                 if (nb_item > 0) {
2655                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2656                         fwd_config_setup();
2657                 }
2658         }
2659 }
2660
2661 cmdline_parse_token_string_t cmd_set_list_keyword =
2662         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2663                                  "set");
2664 cmdline_parse_token_string_t cmd_set_list_name =
2665         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2666                                  "corelist#portlist");
2667 cmdline_parse_token_string_t cmd_set_list_of_items =
2668         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2669                                  NULL);
2670
2671 cmdline_parse_inst_t cmd_set_fwd_list = {
2672         .f = cmd_set_list_parsed,
2673         .data = NULL,
2674         .help_str = "set corelist|portlist <list0[,list1]*>",
2675         .tokens = {
2676                 (void *)&cmd_set_list_keyword,
2677                 (void *)&cmd_set_list_name,
2678                 (void *)&cmd_set_list_of_items,
2679                 NULL,
2680         },
2681 };
2682
2683 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2684
2685 struct cmd_setmask_result {
2686         cmdline_fixed_string_t set;
2687         cmdline_fixed_string_t mask;
2688         uint64_t hexavalue;
2689 };
2690
2691 static void cmd_set_mask_parsed(void *parsed_result,
2692                                 __attribute__((unused)) struct cmdline *cl,
2693                                 __attribute__((unused)) void *data)
2694 {
2695         struct cmd_setmask_result *res = parsed_result;
2696
2697         if (test_done == 0) {
2698                 printf("Please stop forwarding first\n");
2699                 return;
2700         }
2701         if (!strcmp(res->mask, "coremask")) {
2702                 set_fwd_lcores_mask(res->hexavalue);
2703                 fwd_config_setup();
2704         } else if (!strcmp(res->mask, "portmask")) {
2705                 set_fwd_ports_mask(res->hexavalue);
2706                 fwd_config_setup();
2707         }
2708 }
2709
2710 cmdline_parse_token_string_t cmd_setmask_set =
2711         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2712 cmdline_parse_token_string_t cmd_setmask_mask =
2713         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2714                                  "coremask#portmask");
2715 cmdline_parse_token_num_t cmd_setmask_value =
2716         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2717
2718 cmdline_parse_inst_t cmd_set_fwd_mask = {
2719         .f = cmd_set_mask_parsed,
2720         .data = NULL,
2721         .help_str = "set coremask|portmask <hexadecimal value>",
2722         .tokens = {
2723                 (void *)&cmd_setmask_set,
2724                 (void *)&cmd_setmask_mask,
2725                 (void *)&cmd_setmask_value,
2726                 NULL,
2727         },
2728 };
2729
2730 /*
2731  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2732  */
2733 struct cmd_set_result {
2734         cmdline_fixed_string_t set;
2735         cmdline_fixed_string_t what;
2736         uint16_t value;
2737 };
2738
2739 static void cmd_set_parsed(void *parsed_result,
2740                            __attribute__((unused)) struct cmdline *cl,
2741                            __attribute__((unused)) void *data)
2742 {
2743         struct cmd_set_result *res = parsed_result;
2744         if (!strcmp(res->what, "nbport")) {
2745                 set_fwd_ports_number(res->value);
2746                 fwd_config_setup();
2747         } else if (!strcmp(res->what, "nbcore")) {
2748                 set_fwd_lcores_number(res->value);
2749                 fwd_config_setup();
2750         } else if (!strcmp(res->what, "burst"))
2751                 set_nb_pkt_per_burst(res->value);
2752         else if (!strcmp(res->what, "verbose"))
2753                 set_verbose_level(res->value);
2754 }
2755
2756 cmdline_parse_token_string_t cmd_set_set =
2757         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2758 cmdline_parse_token_string_t cmd_set_what =
2759         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2760                                  "nbport#nbcore#burst#verbose");
2761 cmdline_parse_token_num_t cmd_set_value =
2762         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2763
2764 cmdline_parse_inst_t cmd_set_numbers = {
2765         .f = cmd_set_parsed,
2766         .data = NULL,
2767         .help_str = "set nbport|nbcore|burst|verbose <value>",
2768         .tokens = {
2769                 (void *)&cmd_set_set,
2770                 (void *)&cmd_set_what,
2771                 (void *)&cmd_set_value,
2772                 NULL,
2773         },
2774 };
2775
2776 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2777
2778 struct cmd_set_txpkts_result {
2779         cmdline_fixed_string_t cmd_keyword;
2780         cmdline_fixed_string_t txpkts;
2781         cmdline_fixed_string_t seg_lengths;
2782 };
2783
2784 static void
2785 cmd_set_txpkts_parsed(void *parsed_result,
2786                       __attribute__((unused)) struct cmdline *cl,
2787                       __attribute__((unused)) void *data)
2788 {
2789         struct cmd_set_txpkts_result *res;
2790         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2791         unsigned int nb_segs;
2792
2793         res = parsed_result;
2794         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2795                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2796         if (nb_segs > 0)
2797                 set_tx_pkt_segments(seg_lengths, nb_segs);
2798 }
2799
2800 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2801         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2802                                  cmd_keyword, "set");
2803 cmdline_parse_token_string_t cmd_set_txpkts_name =
2804         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2805                                  txpkts, "txpkts");
2806 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2807         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2808                                  seg_lengths, NULL);
2809
2810 cmdline_parse_inst_t cmd_set_txpkts = {
2811         .f = cmd_set_txpkts_parsed,
2812         .data = NULL,
2813         .help_str = "set txpkts <len0[,len1]*>",
2814         .tokens = {
2815                 (void *)&cmd_set_txpkts_keyword,
2816                 (void *)&cmd_set_txpkts_name,
2817                 (void *)&cmd_set_txpkts_lengths,
2818                 NULL,
2819         },
2820 };
2821
2822 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2823
2824 struct cmd_set_txsplit_result {
2825         cmdline_fixed_string_t cmd_keyword;
2826         cmdline_fixed_string_t txsplit;
2827         cmdline_fixed_string_t mode;
2828 };
2829
2830 static void
2831 cmd_set_txsplit_parsed(void *parsed_result,
2832                       __attribute__((unused)) struct cmdline *cl,
2833                       __attribute__((unused)) void *data)
2834 {
2835         struct cmd_set_txsplit_result *res;
2836
2837         res = parsed_result;
2838         set_tx_pkt_split(res->mode);
2839 }
2840
2841 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2842         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2843                                  cmd_keyword, "set");
2844 cmdline_parse_token_string_t cmd_set_txsplit_name =
2845         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2846                                  txsplit, "txsplit");
2847 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2848         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2849                                  mode, NULL);
2850
2851 cmdline_parse_inst_t cmd_set_txsplit = {
2852         .f = cmd_set_txsplit_parsed,
2853         .data = NULL,
2854         .help_str = "set txsplit on|off|rand",
2855         .tokens = {
2856                 (void *)&cmd_set_txsplit_keyword,
2857                 (void *)&cmd_set_txsplit_name,
2858                 (void *)&cmd_set_txsplit_mode,
2859                 NULL,
2860         },
2861 };
2862
2863 /* *** CONFIG TX QUEUE FLAGS *** */
2864
2865 struct cmd_config_txqflags_result {
2866         cmdline_fixed_string_t port;
2867         cmdline_fixed_string_t config;
2868         cmdline_fixed_string_t all;
2869         cmdline_fixed_string_t what;
2870         int32_t hexvalue;
2871 };
2872
2873 static void cmd_config_txqflags_parsed(void *parsed_result,
2874                                 __attribute__((unused)) struct cmdline *cl,
2875                                 __attribute__((unused)) void *data)
2876 {
2877         struct cmd_config_txqflags_result *res = parsed_result;
2878
2879         if (!all_ports_stopped()) {
2880                 printf("Please stop all ports first\n");
2881                 return;
2882         }
2883
2884         if (strcmp(res->what, "txqflags")) {
2885                 printf("Unknown parameter\n");
2886                 return;
2887         }
2888
2889         if (res->hexvalue >= 0) {
2890                 txq_flags = res->hexvalue;
2891         } else {
2892                 printf("txqflags must be >= 0\n");
2893                 return;
2894         }
2895
2896         init_port_config();
2897
2898         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2899 }
2900
2901 cmdline_parse_token_string_t cmd_config_txqflags_port =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2903                                  "port");
2904 cmdline_parse_token_string_t cmd_config_txqflags_config =
2905         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2906                                  "config");
2907 cmdline_parse_token_string_t cmd_config_txqflags_all =
2908         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2909                                  "all");
2910 cmdline_parse_token_string_t cmd_config_txqflags_what =
2911         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2912                                  "txqflags");
2913 cmdline_parse_token_num_t cmd_config_txqflags_value =
2914         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2915                                 hexvalue, INT32);
2916
2917 cmdline_parse_inst_t cmd_config_txqflags = {
2918         .f = cmd_config_txqflags_parsed,
2919         .data = NULL,
2920         .help_str = "port config all txqflags <value>",
2921         .tokens = {
2922                 (void *)&cmd_config_txqflags_port,
2923                 (void *)&cmd_config_txqflags_config,
2924                 (void *)&cmd_config_txqflags_all,
2925                 (void *)&cmd_config_txqflags_what,
2926                 (void *)&cmd_config_txqflags_value,
2927                 NULL,
2928         },
2929 };
2930
2931 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2932 struct cmd_rx_vlan_filter_all_result {
2933         cmdline_fixed_string_t rx_vlan;
2934         cmdline_fixed_string_t what;
2935         cmdline_fixed_string_t all;
2936         uint8_t port_id;
2937 };
2938
2939 static void
2940 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2941                               __attribute__((unused)) struct cmdline *cl,
2942                               __attribute__((unused)) void *data)
2943 {
2944         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2945
2946         if (!strcmp(res->what, "add"))
2947                 rx_vlan_all_filter_set(res->port_id, 1);
2948         else
2949                 rx_vlan_all_filter_set(res->port_id, 0);
2950 }
2951
2952 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2953         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2954                                  rx_vlan, "rx_vlan");
2955 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2956         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2957                                  what, "add#rm");
2958 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2959         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2960                                  all, "all");
2961 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2962         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2963                               port_id, UINT8);
2964
2965 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2966         .f = cmd_rx_vlan_filter_all_parsed,
2967         .data = NULL,
2968         .help_str = "rx_vlan add|rm all <port_id>: "
2969                 "Add/Remove all identifiers to/from the set of VLAN "
2970                 "identifiers filtered by a port",
2971         .tokens = {
2972                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2973                 (void *)&cmd_rx_vlan_filter_all_what,
2974                 (void *)&cmd_rx_vlan_filter_all_all,
2975                 (void *)&cmd_rx_vlan_filter_all_portid,
2976                 NULL,
2977         },
2978 };
2979
2980 /* *** VLAN OFFLOAD SET ON A PORT *** */
2981 struct cmd_vlan_offload_result {
2982         cmdline_fixed_string_t vlan;
2983         cmdline_fixed_string_t set;
2984         cmdline_fixed_string_t vlan_type;
2985         cmdline_fixed_string_t what;
2986         cmdline_fixed_string_t on;
2987         cmdline_fixed_string_t port_id;
2988 };
2989
2990 static void
2991 cmd_vlan_offload_parsed(void *parsed_result,
2992                           __attribute__((unused)) struct cmdline *cl,
2993                           __attribute__((unused)) void *data)
2994 {
2995         int on;
2996         struct cmd_vlan_offload_result *res = parsed_result;
2997         char *str;
2998         int i, len = 0;
2999         portid_t port_id = 0;
3000         unsigned int tmp;
3001
3002         str = res->port_id;
3003         len = strnlen(str, STR_TOKEN_SIZE);
3004         i = 0;
3005         /* Get port_id first */
3006         while(i < len){
3007                 if(str[i] == ',')
3008                         break;
3009
3010                 i++;
3011         }
3012         str[i]='\0';
3013         tmp = strtoul(str, NULL, 0);
3014         /* If port_id greater that what portid_t can represent, return */
3015         if(tmp >= RTE_MAX_ETHPORTS)
3016                 return;
3017         port_id = (portid_t)tmp;
3018
3019         if (!strcmp(res->on, "on"))
3020                 on = 1;
3021         else
3022                 on = 0;
3023
3024         if (!strcmp(res->what, "strip"))
3025                 rx_vlan_strip_set(port_id,  on);
3026         else if(!strcmp(res->what, "stripq")){
3027                 uint16_t queue_id = 0;
3028
3029                 /* No queue_id, return */
3030                 if(i + 1 >= len) {
3031                         printf("must specify (port,queue_id)\n");
3032                         return;
3033                 }
3034                 tmp = strtoul(str + i + 1, NULL, 0);
3035                 /* If queue_id greater that what 16-bits can represent, return */
3036                 if(tmp > 0xffff)
3037                         return;
3038
3039                 queue_id = (uint16_t)tmp;
3040                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3041         }
3042         else if (!strcmp(res->what, "filter"))
3043                 rx_vlan_filter_set(port_id, on);
3044         else
3045                 vlan_extend_set(port_id, on);
3046
3047         return;
3048 }
3049
3050 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3051         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3052                                  vlan, "vlan");
3053 cmdline_parse_token_string_t cmd_vlan_offload_set =
3054         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3055                                  set, "set");
3056 cmdline_parse_token_string_t cmd_vlan_offload_what =
3057         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3058                                  what, "strip#filter#qinq#stripq");
3059 cmdline_parse_token_string_t cmd_vlan_offload_on =
3060         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3061                               on, "on#off");
3062 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3063         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3064                               port_id, NULL);
3065
3066 cmdline_parse_inst_t cmd_vlan_offload = {
3067         .f = cmd_vlan_offload_parsed,
3068         .data = NULL,
3069         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3070                 "<port_id[,queue_id]>: "
3071                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3072         .tokens = {
3073                 (void *)&cmd_vlan_offload_vlan,
3074                 (void *)&cmd_vlan_offload_set,
3075                 (void *)&cmd_vlan_offload_what,
3076                 (void *)&cmd_vlan_offload_on,
3077                 (void *)&cmd_vlan_offload_portid,
3078                 NULL,
3079         },
3080 };
3081
3082 /* *** VLAN TPID SET ON A PORT *** */
3083 struct cmd_vlan_tpid_result {
3084         cmdline_fixed_string_t vlan;
3085         cmdline_fixed_string_t set;
3086         cmdline_fixed_string_t vlan_type;
3087         cmdline_fixed_string_t what;
3088         uint16_t tp_id;
3089         uint8_t port_id;
3090 };
3091
3092 static void
3093 cmd_vlan_tpid_parsed(void *parsed_result,
3094                           __attribute__((unused)) struct cmdline *cl,
3095                           __attribute__((unused)) void *data)
3096 {
3097         struct cmd_vlan_tpid_result *res = parsed_result;
3098         enum rte_vlan_type vlan_type;
3099
3100         if (!strcmp(res->vlan_type, "inner"))
3101                 vlan_type = ETH_VLAN_TYPE_INNER;
3102         else if (!strcmp(res->vlan_type, "outer"))
3103                 vlan_type = ETH_VLAN_TYPE_OUTER;
3104         else {
3105                 printf("Unknown vlan type\n");
3106                 return;
3107         }
3108         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3109 }
3110
3111 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3112         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3113                                  vlan, "vlan");
3114 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3115         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3116                                  set, "set");
3117 cmdline_parse_token_string_t cmd_vlan_type =
3118         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3119                                  vlan_type, "inner#outer");
3120 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3121         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3122                                  what, "tpid");
3123 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3124         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3125                               tp_id, UINT16);
3126 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3127         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3128                               port_id, UINT8);
3129
3130 cmdline_parse_inst_t cmd_vlan_tpid = {
3131         .f = cmd_vlan_tpid_parsed,
3132         .data = NULL,
3133         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3134                 "Set the VLAN Ether type",
3135         .tokens = {
3136                 (void *)&cmd_vlan_tpid_vlan,
3137                 (void *)&cmd_vlan_tpid_set,
3138                 (void *)&cmd_vlan_type,
3139                 (void *)&cmd_vlan_tpid_what,
3140                 (void *)&cmd_vlan_tpid_tpid,
3141                 (void *)&cmd_vlan_tpid_portid,
3142                 NULL,
3143         },
3144 };
3145
3146 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3147 struct cmd_rx_vlan_filter_result {
3148         cmdline_fixed_string_t rx_vlan;
3149         cmdline_fixed_string_t what;
3150         uint16_t vlan_id;
3151         uint8_t port_id;
3152 };
3153
3154 static void
3155 cmd_rx_vlan_filter_parsed(void *parsed_result,
3156                           __attribute__((unused)) struct cmdline *cl,
3157                           __attribute__((unused)) void *data)
3158 {
3159         struct cmd_rx_vlan_filter_result *res = parsed_result;
3160
3161         if (!strcmp(res->what, "add"))
3162                 rx_vft_set(res->port_id, res->vlan_id, 1);
3163         else
3164                 rx_vft_set(res->port_id, res->vlan_id, 0);
3165 }
3166
3167 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3168         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3169                                  rx_vlan, "rx_vlan");
3170 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3171         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3172                                  what, "add#rm");
3173 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3174         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3175                               vlan_id, UINT16);
3176 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3177         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3178                               port_id, UINT8);
3179
3180 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3181         .f = cmd_rx_vlan_filter_parsed,
3182         .data = NULL,
3183         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3184                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3185                 "identifiers filtered by a port",
3186         .tokens = {
3187                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3188                 (void *)&cmd_rx_vlan_filter_what,
3189                 (void *)&cmd_rx_vlan_filter_vlanid,
3190                 (void *)&cmd_rx_vlan_filter_portid,
3191                 NULL,
3192         },
3193 };
3194
3195 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3196 struct cmd_tx_vlan_set_result {
3197         cmdline_fixed_string_t tx_vlan;
3198         cmdline_fixed_string_t set;
3199         uint8_t port_id;
3200         uint16_t vlan_id;
3201 };
3202
3203 static void
3204 cmd_tx_vlan_set_parsed(void *parsed_result,
3205                        __attribute__((unused)) struct cmdline *cl,
3206                        __attribute__((unused)) void *data)
3207 {
3208         struct cmd_tx_vlan_set_result *res = parsed_result;
3209
3210         tx_vlan_set(res->port_id, res->vlan_id);
3211 }
3212
3213 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3214         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3215                                  tx_vlan, "tx_vlan");
3216 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3217         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3218                                  set, "set");
3219 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3220         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3221                               port_id, UINT8);
3222 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3223         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3224                               vlan_id, UINT16);
3225
3226 cmdline_parse_inst_t cmd_tx_vlan_set = {
3227         .f = cmd_tx_vlan_set_parsed,
3228         .data = NULL,
3229         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3230                 "Enable hardware insertion of a single VLAN header "
3231                 "with a given TAG Identifier in packets sent on a port",
3232         .tokens = {
3233                 (void *)&cmd_tx_vlan_set_tx_vlan,
3234                 (void *)&cmd_tx_vlan_set_set,
3235                 (void *)&cmd_tx_vlan_set_portid,
3236                 (void *)&cmd_tx_vlan_set_vlanid,
3237                 NULL,
3238         },
3239 };
3240
3241 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3242 struct cmd_tx_vlan_set_qinq_result {
3243         cmdline_fixed_string_t tx_vlan;
3244         cmdline_fixed_string_t set;
3245         uint8_t port_id;
3246         uint16_t vlan_id;
3247         uint16_t vlan_id_outer;
3248 };
3249
3250 static void
3251 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3252                             __attribute__((unused)) struct cmdline *cl,
3253                             __attribute__((unused)) void *data)
3254 {
3255         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3256
3257         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3258 }
3259
3260 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3261         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3262                 tx_vlan, "tx_vlan");
3263 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3264         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3265                 set, "set");
3266 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3267         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3268                 port_id, UINT8);
3269 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3270         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3271                 vlan_id, UINT16);
3272 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3273         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3274                 vlan_id_outer, UINT16);
3275
3276 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3277         .f = cmd_tx_vlan_set_qinq_parsed,
3278         .data = NULL,
3279         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3280                 "Enable hardware insertion of double VLAN header "
3281                 "with given TAG Identifiers in packets sent on a port",
3282         .tokens = {
3283                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3284                 (void *)&cmd_tx_vlan_set_qinq_set,
3285                 (void *)&cmd_tx_vlan_set_qinq_portid,
3286                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3287                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3288                 NULL,
3289         },
3290 };
3291
3292 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3293 struct cmd_tx_vlan_set_pvid_result {
3294         cmdline_fixed_string_t tx_vlan;
3295         cmdline_fixed_string_t set;
3296         cmdline_fixed_string_t pvid;
3297         uint8_t port_id;
3298         uint16_t vlan_id;
3299         cmdline_fixed_string_t mode;
3300 };
3301
3302 static void
3303 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3304                             __attribute__((unused)) struct cmdline *cl,
3305                             __attribute__((unused)) void *data)
3306 {
3307         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3308
3309         if (strcmp(res->mode, "on") == 0)
3310                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3311         else
3312                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3313 }
3314
3315 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3316         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3317                                  tx_vlan, "tx_vlan");
3318 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3319         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3320                                  set, "set");
3321 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3322         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3323                                  pvid, "pvid");
3324 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3325         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3326                              port_id, UINT8);
3327 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3328         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3329                               vlan_id, UINT16);
3330 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3331         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3332                                  mode, "on#off");
3333
3334 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3335         .f = cmd_tx_vlan_set_pvid_parsed,
3336         .data = NULL,
3337         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3338         .tokens = {
3339                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3340                 (void *)&cmd_tx_vlan_set_pvid_set,
3341                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3342                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3343                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3344                 (void *)&cmd_tx_vlan_set_pvid_mode,
3345                 NULL,
3346         },
3347 };
3348
3349 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3350 struct cmd_tx_vlan_reset_result {
3351         cmdline_fixed_string_t tx_vlan;
3352         cmdline_fixed_string_t reset;
3353         uint8_t port_id;
3354 };
3355
3356 static void
3357 cmd_tx_vlan_reset_parsed(void *parsed_result,
3358                          __attribute__((unused)) struct cmdline *cl,
3359                          __attribute__((unused)) void *data)
3360 {
3361         struct cmd_tx_vlan_reset_result *res = parsed_result;
3362
3363         tx_vlan_reset(res->port_id);
3364 }
3365
3366 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3367         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3368                                  tx_vlan, "tx_vlan");
3369 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3370         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3371                                  reset, "reset");
3372 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3373         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3374                               port_id, UINT8);
3375
3376 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3377         .f = cmd_tx_vlan_reset_parsed,
3378         .data = NULL,
3379         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3380                 "VLAN header in packets sent on a port",
3381         .tokens = {
3382                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3383                 (void *)&cmd_tx_vlan_reset_reset,
3384                 (void *)&cmd_tx_vlan_reset_portid,
3385                 NULL,
3386         },
3387 };
3388
3389
3390 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3391 struct cmd_csum_result {
3392         cmdline_fixed_string_t csum;
3393         cmdline_fixed_string_t mode;
3394         cmdline_fixed_string_t proto;
3395         cmdline_fixed_string_t hwsw;
3396         uint8_t port_id;
3397 };
3398
3399 static void
3400 csum_show(int port_id)
3401 {
3402         struct rte_eth_dev_info dev_info;
3403         uint16_t ol_flags;
3404
3405         ol_flags = ports[port_id].tx_ol_flags;
3406         printf("Parse tunnel is %s\n",
3407                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3408         printf("IP checksum offload is %s\n",
3409                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3410         printf("UDP checksum offload is %s\n",
3411                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3412         printf("TCP checksum offload is %s\n",
3413                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3414         printf("SCTP checksum offload is %s\n",
3415                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3416         printf("Outer-Ip checksum offload is %s\n",
3417                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3418
3419         /* display warnings if configuration is not supported by the NIC */
3420         rte_eth_dev_info_get(port_id, &dev_info);
3421         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3422                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3423                 printf("Warning: hardware IP checksum enabled but not "
3424                         "supported by port %d\n", port_id);
3425         }
3426         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3427                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3428                 printf("Warning: hardware UDP checksum enabled but not "
3429                         "supported by port %d\n", port_id);
3430         }
3431         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3432                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3433                 printf("Warning: hardware TCP checksum enabled but not "
3434                         "supported by port %d\n", port_id);
3435         }
3436         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3437                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3438                 printf("Warning: hardware SCTP checksum enabled but not "
3439                         "supported by port %d\n", port_id);
3440         }
3441         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3442                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3443                 printf("Warning: hardware outer IP checksum enabled but not "
3444                         "supported by port %d\n", port_id);
3445         }
3446 }
3447
3448 static void
3449 cmd_csum_parsed(void *parsed_result,
3450                        __attribute__((unused)) struct cmdline *cl,
3451                        __attribute__((unused)) void *data)
3452 {
3453         struct cmd_csum_result *res = parsed_result;
3454         int hw = 0;
3455         uint16_t mask = 0;
3456
3457         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3458                 printf("invalid port %d\n", res->port_id);
3459                 return;
3460         }
3461
3462         if (!strcmp(res->mode, "set")) {
3463
3464                 if (!strcmp(res->hwsw, "hw"))
3465                         hw = 1;
3466
3467                 if (!strcmp(res->proto, "ip")) {
3468                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3469                 } else if (!strcmp(res->proto, "udp")) {
3470                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3471                 } else if (!strcmp(res->proto, "tcp")) {
3472                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3473                 } else if (!strcmp(res->proto, "sctp")) {
3474                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3475                 } else if (!strcmp(res->proto, "outer-ip")) {
3476                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3477                 }
3478
3479                 if (hw)
3480                         ports[res->port_id].tx_ol_flags |= mask;
3481                 else
3482                         ports[res->port_id].tx_ol_flags &= (~mask);
3483         }
3484         csum_show(res->port_id);
3485 }
3486
3487 cmdline_parse_token_string_t cmd_csum_csum =
3488         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3489                                 csum, "csum");
3490 cmdline_parse_token_string_t cmd_csum_mode =
3491         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3492                                 mode, "set");
3493 cmdline_parse_token_string_t cmd_csum_proto =
3494         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3495                                 proto, "ip#tcp#udp#sctp#outer-ip");
3496 cmdline_parse_token_string_t cmd_csum_hwsw =
3497         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3498                                 hwsw, "hw#sw");
3499 cmdline_parse_token_num_t cmd_csum_portid =
3500         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3501                                 port_id, UINT8);
3502
3503 cmdline_parse_inst_t cmd_csum_set = {
3504         .f = cmd_csum_parsed,
3505         .data = NULL,
3506         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3507                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3508                 "using csum forward engine",
3509         .tokens = {
3510                 (void *)&cmd_csum_csum,
3511                 (void *)&cmd_csum_mode,
3512                 (void *)&cmd_csum_proto,
3513                 (void *)&cmd_csum_hwsw,
3514                 (void *)&cmd_csum_portid,
3515                 NULL,
3516         },
3517 };
3518
3519 cmdline_parse_token_string_t cmd_csum_mode_show =
3520         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3521                                 mode, "show");
3522
3523 cmdline_parse_inst_t cmd_csum_show = {
3524         .f = cmd_csum_parsed,
3525         .data = NULL,
3526         .help_str = "csum show <port_id>: Show checksum offload configuration",
3527         .tokens = {
3528                 (void *)&cmd_csum_csum,
3529                 (void *)&cmd_csum_mode_show,
3530                 (void *)&cmd_csum_portid,
3531                 NULL,
3532         },
3533 };
3534
3535 /* Enable/disable tunnel parsing */
3536 struct cmd_csum_tunnel_result {
3537         cmdline_fixed_string_t csum;
3538         cmdline_fixed_string_t parse;
3539         cmdline_fixed_string_t onoff;
3540         uint8_t port_id;
3541 };
3542
3543 static void
3544 cmd_csum_tunnel_parsed(void *parsed_result,
3545                        __attribute__((unused)) struct cmdline *cl,
3546                        __attribute__((unused)) void *data)
3547 {
3548         struct cmd_csum_tunnel_result *res = parsed_result;
3549
3550         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3551                 return;
3552
3553         if (!strcmp(res->onoff, "on"))
3554                 ports[res->port_id].tx_ol_flags |=
3555                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3556         else
3557                 ports[res->port_id].tx_ol_flags &=
3558                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3559
3560         csum_show(res->port_id);
3561 }
3562
3563 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3564         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3565                                 csum, "csum");
3566 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3567         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3568                                 parse, "parse_tunnel");
3569 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3570         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3571                                 onoff, "on#off");
3572 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3573         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3574                                 port_id, UINT8);
3575
3576 cmdline_parse_inst_t cmd_csum_tunnel = {
3577         .f = cmd_csum_tunnel_parsed,
3578         .data = NULL,
3579         .help_str = "csum parse_tunnel on|off <port_id>: "
3580                 "Enable/Disable parsing of tunnels for csum engine",
3581         .tokens = {
3582                 (void *)&cmd_csum_tunnel_csum,
3583                 (void *)&cmd_csum_tunnel_parse,
3584                 (void *)&cmd_csum_tunnel_onoff,
3585                 (void *)&cmd_csum_tunnel_portid,
3586                 NULL,
3587         },
3588 };
3589
3590 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3591 struct cmd_tso_set_result {
3592         cmdline_fixed_string_t tso;
3593         cmdline_fixed_string_t mode;
3594         uint16_t tso_segsz;
3595         uint8_t port_id;
3596 };
3597
3598 static void
3599 cmd_tso_set_parsed(void *parsed_result,
3600                        __attribute__((unused)) struct cmdline *cl,
3601                        __attribute__((unused)) void *data)
3602 {
3603         struct cmd_tso_set_result *res = parsed_result;
3604         struct rte_eth_dev_info dev_info;
3605
3606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3607                 return;
3608
3609         if (!strcmp(res->mode, "set"))
3610                 ports[res->port_id].tso_segsz = res->tso_segsz;
3611
3612         if (ports[res->port_id].tso_segsz == 0)
3613                 printf("TSO for non-tunneled packets is disabled\n");
3614         else
3615                 printf("TSO segment size for non-tunneled packets is %d\n",
3616                         ports[res->port_id].tso_segsz);
3617
3618         /* display warnings if configuration is not supported by the NIC */
3619         rte_eth_dev_info_get(res->port_id, &dev_info);
3620         if ((ports[res->port_id].tso_segsz != 0) &&
3621                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3622                 printf("Warning: TSO enabled but not "
3623                         "supported by port %d\n", res->port_id);
3624         }
3625 }
3626
3627 cmdline_parse_token_string_t cmd_tso_set_tso =
3628         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3629                                 tso, "tso");
3630 cmdline_parse_token_string_t cmd_tso_set_mode =
3631         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3632                                 mode, "set");
3633 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3634         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3635                                 tso_segsz, UINT16);
3636 cmdline_parse_token_num_t cmd_tso_set_portid =
3637         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3638                                 port_id, UINT8);
3639
3640 cmdline_parse_inst_t cmd_tso_set = {
3641         .f = cmd_tso_set_parsed,
3642         .data = NULL,
3643         .help_str = "tso set <tso_segsz> <port_id>: "
3644                 "Set TSO segment size of non-tunneled packets for csum engine "
3645                 "(0 to disable)",
3646         .tokens = {
3647                 (void *)&cmd_tso_set_tso,
3648                 (void *)&cmd_tso_set_mode,
3649                 (void *)&cmd_tso_set_tso_segsz,
3650                 (void *)&cmd_tso_set_portid,
3651                 NULL,
3652         },
3653 };
3654
3655 cmdline_parse_token_string_t cmd_tso_show_mode =
3656         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3657                                 mode, "show");
3658
3659
3660 cmdline_parse_inst_t cmd_tso_show = {
3661         .f = cmd_tso_set_parsed,
3662         .data = NULL,
3663         .help_str = "tso show <port_id>: "
3664                 "Show TSO segment size of non-tunneled packets for csum engine",
3665         .tokens = {
3666                 (void *)&cmd_tso_set_tso,
3667                 (void *)&cmd_tso_show_mode,
3668                 (void *)&cmd_tso_set_portid,
3669                 NULL,
3670         },
3671 };
3672
3673 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3674 struct cmd_tunnel_tso_set_result {
3675         cmdline_fixed_string_t tso;
3676         cmdline_fixed_string_t mode;
3677         uint16_t tso_segsz;
3678         uint8_t port_id;
3679 };
3680
3681 static void
3682 check_tunnel_tso_nic_support(uint8_t port_id)
3683 {
3684         struct rte_eth_dev_info dev_info;
3685
3686         rte_eth_dev_info_get(port_id, &dev_info);
3687         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3688                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3689                        "supported by port %d\n", port_id);
3690         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3691                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3692                         "supported by port %d\n", port_id);
3693         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3694                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3695                        "supported by port %d\n", port_id);
3696         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3697                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3698                        "supported by port %d\n", port_id);
3699 }
3700
3701 static void
3702 cmd_tunnel_tso_set_parsed(void *parsed_result,
3703                           __attribute__((unused)) struct cmdline *cl,
3704                           __attribute__((unused)) void *data)
3705 {
3706         struct cmd_tunnel_tso_set_result *res = parsed_result;
3707
3708         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3709                 return;
3710
3711         if (!strcmp(res->mode, "set"))
3712                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3713
3714         if (ports[res->port_id].tunnel_tso_segsz == 0)
3715                 printf("TSO for tunneled packets is disabled\n");
3716         else {
3717                 printf("TSO segment size for tunneled packets is %d\n",
3718                         ports[res->port_id].tunnel_tso_segsz);
3719
3720                 /* Below conditions are needed to make it work:
3721                  * (1) tunnel TSO is supported by the NIC;
3722                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3723                  * are recognized;
3724                  * (3) for tunneled pkts with outer L3 of IPv4,
3725                  * "csum set outer-ip" must be set to hw, because after tso,
3726                  * total_len of outer IP header is changed, and the checksum
3727                  * of outer IP header calculated by sw should be wrong; that
3728                  * is not necessary for IPv6 tunneled pkts because there's no
3729                  * checksum in IP header anymore.
3730                  */
3731                 check_tunnel_tso_nic_support(res->port_id);
3732
3733                 if (!(ports[res->port_id].tx_ol_flags &
3734                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3735                         printf("Warning: csum parse_tunnel must be set "
3736                                 "so that tunneled packets are recognized\n");
3737                 if (!(ports[res->port_id].tx_ol_flags &
3738                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3739                         printf("Warning: csum set outer-ip must be set to hw "
3740                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3741         }
3742 }
3743
3744 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3745         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3746                                 tso, "tunnel_tso");
3747 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3748         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3749                                 mode, "set");
3750 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3751         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3752                                 tso_segsz, UINT16);
3753 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3754         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3755                                 port_id, UINT8);
3756
3757 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3758         .f = cmd_tunnel_tso_set_parsed,
3759         .data = NULL,
3760         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3761                 "Set TSO segment size of tunneled packets for csum engine "
3762                 "(0 to disable)",
3763         .tokens = {
3764                 (void *)&cmd_tunnel_tso_set_tso,
3765                 (void *)&cmd_tunnel_tso_set_mode,
3766                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3767                 (void *)&cmd_tunnel_tso_set_portid,
3768                 NULL,
3769         },
3770 };
3771
3772 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3773         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3774                                 mode, "show");
3775
3776
3777 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3778         .f = cmd_tunnel_tso_set_parsed,
3779         .data = NULL,
3780         .help_str = "tunnel_tso show <port_id> "
3781                 "Show TSO segment size of tunneled packets for csum engine",
3782         .tokens = {
3783                 (void *)&cmd_tunnel_tso_set_tso,
3784                 (void *)&cmd_tunnel_tso_show_mode,
3785                 (void *)&cmd_tunnel_tso_set_portid,
3786                 NULL,
3787         },
3788 };
3789
3790 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3791 struct cmd_set_flush_rx {
3792         cmdline_fixed_string_t set;
3793         cmdline_fixed_string_t flush_rx;
3794         cmdline_fixed_string_t mode;
3795 };
3796
3797 static void
3798 cmd_set_flush_rx_parsed(void *parsed_result,
3799                 __attribute__((unused)) struct cmdline *cl,
3800                 __attribute__((unused)) void *data)
3801 {
3802         struct cmd_set_flush_rx *res = parsed_result;
3803         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3804 }
3805
3806 cmdline_parse_token_string_t cmd_setflushrx_set =
3807         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3808                         set, "set");
3809 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3810         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3811                         flush_rx, "flush_rx");
3812 cmdline_parse_token_string_t cmd_setflushrx_mode =
3813         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3814                         mode, "on#off");
3815
3816
3817 cmdline_parse_inst_t cmd_set_flush_rx = {
3818         .f = cmd_set_flush_rx_parsed,
3819         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
3820         .data = NULL,
3821         .tokens = {
3822                 (void *)&cmd_setflushrx_set,
3823                 (void *)&cmd_setflushrx_flush_rx,
3824                 (void *)&cmd_setflushrx_mode,
3825                 NULL,
3826         },
3827 };
3828
3829 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3830 struct cmd_set_link_check {
3831         cmdline_fixed_string_t set;
3832         cmdline_fixed_string_t link_check;
3833         cmdline_fixed_string_t mode;
3834 };
3835
3836 static void
3837 cmd_set_link_check_parsed(void *parsed_result,
3838                 __attribute__((unused)) struct cmdline *cl,
3839                 __attribute__((unused)) void *data)
3840 {
3841         struct cmd_set_link_check *res = parsed_result;
3842         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3843 }
3844
3845 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3846         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3847                         set, "set");
3848 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3849         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3850                         link_check, "link_check");
3851 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3852         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3853                         mode, "on#off");
3854
3855
3856 cmdline_parse_inst_t cmd_set_link_check = {
3857         .f = cmd_set_link_check_parsed,
3858         .help_str = "set link_check on|off: Enable/Disable link status check "
3859                     "when starting/stopping a port",
3860         .data = NULL,
3861         .tokens = {
3862                 (void *)&cmd_setlinkcheck_set,
3863                 (void *)&cmd_setlinkcheck_link_check,
3864                 (void *)&cmd_setlinkcheck_mode,
3865                 NULL,
3866         },
3867 };
3868
3869 #ifdef RTE_NIC_BYPASS
3870 /* *** SET NIC BYPASS MODE *** */
3871 struct cmd_set_bypass_mode_result {
3872         cmdline_fixed_string_t set;
3873         cmdline_fixed_string_t bypass;
3874         cmdline_fixed_string_t mode;
3875         cmdline_fixed_string_t value;
3876         uint8_t port_id;
3877 };
3878
3879 static void
3880 cmd_set_bypass_mode_parsed(void *parsed_result,
3881                 __attribute__((unused)) struct cmdline *cl,
3882                 __attribute__((unused)) void *data)
3883 {
3884         struct cmd_set_bypass_mode_result *res = parsed_result;
3885         portid_t port_id = res->port_id;
3886         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3887
3888         if (!strcmp(res->value, "bypass"))
3889                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3890         else if (!strcmp(res->value, "isolate"))
3891                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3892         else
3893                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3894
3895         /* Set the bypass mode for the relevant port. */
3896         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3897                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3898         }
3899 }
3900
3901 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3902         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3903                         set, "set");
3904 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3905         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3906                         bypass, "bypass");
3907 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3908         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3909                         mode, "mode");
3910 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3911         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3912                         value, "normal#bypass#isolate");
3913 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3914         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3915                                 port_id, UINT8);
3916
3917 cmdline_parse_inst_t cmd_set_bypass_mode = {
3918         .f = cmd_set_bypass_mode_parsed,
3919         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
3920                     "Set the NIC bypass mode for port_id",
3921         .data = NULL,
3922         .tokens = {
3923                 (void *)&cmd_setbypass_mode_set,
3924                 (void *)&cmd_setbypass_mode_bypass,
3925                 (void *)&cmd_setbypass_mode_mode,
3926                 (void *)&cmd_setbypass_mode_value,
3927                 (void *)&cmd_setbypass_mode_port,
3928                 NULL,
3929         },
3930 };
3931
3932 /* *** SET NIC BYPASS EVENT *** */
3933 struct cmd_set_bypass_event_result {
3934         cmdline_fixed_string_t set;
3935         cmdline_fixed_string_t bypass;
3936         cmdline_fixed_string_t event;
3937         cmdline_fixed_string_t event_value;
3938         cmdline_fixed_string_t mode;
3939         cmdline_fixed_string_t mode_value;
3940         uint8_t port_id;
3941 };
3942
3943 static void
3944 cmd_set_bypass_event_parsed(void *parsed_result,
3945                 __attribute__((unused)) struct cmdline *cl,
3946                 __attribute__((unused)) void *data)
3947 {
3948         int32_t rc;
3949         struct cmd_set_bypass_event_result *res = parsed_result;
3950         portid_t port_id = res->port_id;
3951         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3952         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3953
3954         if (!strcmp(res->event_value, "timeout"))
3955                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3956         else if (!strcmp(res->event_value, "os_on"))
3957                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3958         else if (!strcmp(res->event_value, "os_off"))
3959                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3960         else if (!strcmp(res->event_value, "power_on"))
3961                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3962         else if (!strcmp(res->event_value, "power_off"))
3963                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3964         else
3965                 bypass_event = RTE_BYPASS_EVENT_NONE;
3966
3967         if (!strcmp(res->mode_value, "bypass"))
3968                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3969         else if (!strcmp(res->mode_value, "isolate"))
3970                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3971         else
3972                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3973
3974         /* Set the watchdog timeout. */
3975         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3976
3977                 rc = -EINVAL;
3978                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3979                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3980                                 bypass_timeout)) != 0) {
3981                         printf("Failed to set timeout value %u "
3982                                 "for port %d, errto code: %d.\n",
3983                                 bypass_timeout, port_id, rc);
3984                 }
3985         }
3986
3987         /* Set the bypass event to transition to bypass mode. */
3988         if (0 != rte_eth_dev_bypass_event_store(port_id,
3989                         bypass_event, bypass_mode)) {
3990                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3991         }
3992
3993 }
3994
3995 cmdline_parse_token_string_t cmd_setbypass_event_set =
3996         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3997                         set, "set");
3998 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3999         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4000                         bypass, "bypass");
4001 cmdline_parse_token_string_t cmd_setbypass_event_event =
4002         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4003                         event, "event");
4004 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4005         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4006                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4007 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4008         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4009                         mode, "mode");
4010 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4011         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4012                         mode_value, "normal#bypass#isolate");
4013 cmdline_parse_token_num_t cmd_setbypass_event_port =
4014         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4015                                 port_id, UINT8);
4016
4017 cmdline_parse_inst_t cmd_set_bypass_event = {
4018         .f = cmd_set_bypass_event_parsed,
4019         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4020                 "power_off mode normal|bypass|isolate <port_id>: "
4021                 "Set the NIC bypass event mode for port_id",
4022         .data = NULL,
4023         .tokens = {
4024                 (void *)&cmd_setbypass_event_set,
4025                 (void *)&cmd_setbypass_event_bypass,
4026                 (void *)&cmd_setbypass_event_event,
4027                 (void *)&cmd_setbypass_event_event_value,
4028                 (void *)&cmd_setbypass_event_mode,
4029                 (void *)&cmd_setbypass_event_mode_value,
4030                 (void *)&cmd_setbypass_event_port,
4031                 NULL,
4032         },
4033 };
4034
4035
4036 /* *** SET NIC BYPASS TIMEOUT *** */
4037 struct cmd_set_bypass_timeout_result {
4038         cmdline_fixed_string_t set;
4039         cmdline_fixed_string_t bypass;
4040         cmdline_fixed_string_t timeout;
4041         cmdline_fixed_string_t value;
4042 };
4043
4044 static void
4045 cmd_set_bypass_timeout_parsed(void *parsed_result,
4046                 __attribute__((unused)) struct cmdline *cl,
4047                 __attribute__((unused)) void *data)
4048 {
4049         struct cmd_set_bypass_timeout_result *res = parsed_result;
4050
4051         if (!strcmp(res->value, "1.5"))
4052                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
4053         else if (!strcmp(res->value, "2"))
4054                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
4055         else if (!strcmp(res->value, "3"))
4056                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
4057         else if (!strcmp(res->value, "4"))
4058                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
4059         else if (!strcmp(res->value, "8"))
4060                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
4061         else if (!strcmp(res->value, "16"))
4062                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
4063         else if (!strcmp(res->value, "32"))
4064                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
4065         else
4066                 bypass_timeout = RTE_BYPASS_TMT_OFF;
4067 }
4068
4069 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4070         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4071                         set, "set");
4072 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4073         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4074                         bypass, "bypass");
4075 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4076         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4077                         timeout, "timeout");
4078 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4079         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4080                         value, "0#1.5#2#3#4#8#16#32");
4081
4082 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4083         .f = cmd_set_bypass_timeout_parsed,
4084         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4085                 "Set the NIC bypass watchdog timeout in seconds",
4086         .data = NULL,
4087         .tokens = {
4088                 (void *)&cmd_setbypass_timeout_set,
4089                 (void *)&cmd_setbypass_timeout_bypass,
4090                 (void *)&cmd_setbypass_timeout_timeout,
4091                 (void *)&cmd_setbypass_timeout_value,
4092                 NULL,
4093         },
4094 };
4095
4096 /* *** SHOW NIC BYPASS MODE *** */
4097 struct cmd_show_bypass_config_result {
4098         cmdline_fixed_string_t show;
4099         cmdline_fixed_string_t bypass;
4100         cmdline_fixed_string_t config;
4101         uint8_t port_id;
4102 };
4103
4104 static void
4105 cmd_show_bypass_config_parsed(void *parsed_result,
4106                 __attribute__((unused)) struct cmdline *cl,
4107                 __attribute__((unused)) void *data)
4108 {
4109         struct cmd_show_bypass_config_result *res = parsed_result;
4110         uint32_t event_mode;
4111         uint32_t bypass_mode;
4112         portid_t port_id = res->port_id;
4113         uint32_t timeout = bypass_timeout;
4114         int i;
4115
4116         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
4117                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4118         static const char * const modes[RTE_BYPASS_MODE_NUM] =
4119                 {"UNKNOWN", "normal", "bypass", "isolate"};
4120         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
4121                 "NONE",
4122                 "OS/board on",
4123                 "power supply on",
4124                 "OS/board off",
4125                 "power supply off",
4126                 "timeout"};
4127         int num_events = (sizeof events) / (sizeof events[0]);
4128
4129         /* Display the bypass mode.*/
4130         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
4131                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4132                 return;
4133         }
4134         else {
4135                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
4136                         bypass_mode = RTE_BYPASS_MODE_NONE;
4137
4138                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4139         }
4140
4141         /* Display the bypass timeout.*/
4142         if (!RTE_BYPASS_TMT_VALID(timeout))
4143                 timeout = RTE_BYPASS_TMT_OFF;
4144
4145         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4146
4147         /* Display the bypass events and associated modes. */
4148         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
4149
4150                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
4151                         printf("\tFailed to get bypass mode for event = %s\n",
4152                                 events[i]);
4153                 } else {
4154                         if (!RTE_BYPASS_MODE_VALID(event_mode))
4155                                 event_mode = RTE_BYPASS_MODE_NONE;
4156
4157                         printf("\tbypass event: %-16s = %s\n", events[i],
4158                                 modes[event_mode]);
4159                 }
4160         }
4161 }
4162
4163 cmdline_parse_token_string_t cmd_showbypass_config_show =
4164         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4165                         show, "show");
4166 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4167         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4168                         bypass, "bypass");
4169 cmdline_parse_token_string_t cmd_showbypass_config_config =
4170         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4171                         config, "config");
4172 cmdline_parse_token_num_t cmd_showbypass_config_port =
4173         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4174                                 port_id, UINT8);
4175
4176 cmdline_parse_inst_t cmd_show_bypass_config = {
4177         .f = cmd_show_bypass_config_parsed,
4178         .help_str = "show bypass config <port_id>: "
4179                     "Show the NIC bypass config for port_id",
4180         .data = NULL,
4181         .tokens = {
4182                 (void *)&cmd_showbypass_config_show,
4183                 (void *)&cmd_showbypass_config_bypass,
4184                 (void *)&cmd_showbypass_config_config,
4185                 (void *)&cmd_showbypass_config_port,
4186                 NULL,
4187         },
4188 };
4189 #endif
4190
4191 #ifdef RTE_LIBRTE_PMD_BOND
4192 /* *** SET BONDING MODE *** */
4193 struct cmd_set_bonding_mode_result {
4194         cmdline_fixed_string_t set;
4195         cmdline_fixed_string_t bonding;
4196         cmdline_fixed_string_t mode;
4197         uint8_t value;
4198         uint8_t port_id;
4199 };
4200
4201 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4202                 __attribute__((unused))  struct cmdline *cl,
4203                 __attribute__((unused)) void *data)
4204 {
4205         struct cmd_set_bonding_mode_result *res = parsed_result;
4206         portid_t port_id = res->port_id;
4207
4208         /* Set the bonding mode for the relevant port. */
4209         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4210                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4211 }
4212
4213 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4214 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4215                 set, "set");
4216 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4217 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4218                 bonding, "bonding");
4219 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4220 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4221                 mode, "mode");
4222 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4223 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4224                 value, UINT8);
4225 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4226 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4227                 port_id, UINT8);
4228
4229 cmdline_parse_inst_t cmd_set_bonding_mode = {
4230                 .f = cmd_set_bonding_mode_parsed,
4231                 .help_str = "set bonding mode <mode_value> <port_id>: "
4232                         "Set the bonding mode for port_id",
4233                 .data = NULL,
4234                 .tokens = {
4235                                 (void *) &cmd_setbonding_mode_set,
4236                                 (void *) &cmd_setbonding_mode_bonding,
4237                                 (void *) &cmd_setbonding_mode_mode,
4238                                 (void *) &cmd_setbonding_mode_value,
4239                                 (void *) &cmd_setbonding_mode_port,
4240                                 NULL
4241                 }
4242 };
4243
4244 /* *** SET BALANCE XMIT POLICY *** */
4245 struct cmd_set_bonding_balance_xmit_policy_result {
4246         cmdline_fixed_string_t set;
4247         cmdline_fixed_string_t bonding;
4248         cmdline_fixed_string_t balance_xmit_policy;
4249         uint8_t port_id;
4250         cmdline_fixed_string_t policy;
4251 };
4252
4253 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4254                 __attribute__((unused))  struct cmdline *cl,
4255                 __attribute__((unused)) void *data)
4256 {
4257         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4258         portid_t port_id = res->port_id;
4259         uint8_t policy;
4260
4261         if (!strcmp(res->policy, "l2")) {
4262                 policy = BALANCE_XMIT_POLICY_LAYER2;
4263         } else if (!strcmp(res->policy, "l23")) {
4264                 policy = BALANCE_XMIT_POLICY_LAYER23;
4265         } else if (!strcmp(res->policy, "l34")) {
4266                 policy = BALANCE_XMIT_POLICY_LAYER34;
4267         } else {
4268                 printf("\t Invalid xmit policy selection");
4269                 return;
4270         }
4271
4272         /* Set the bonding mode for the relevant port. */
4273         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4274                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4275                                 port_id);
4276         }
4277 }
4278
4279 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4280 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4281                 set, "set");
4282 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4283 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4284                 bonding, "bonding");
4285 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4286 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4287                 balance_xmit_policy, "balance_xmit_policy");
4288 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4289 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4290                 port_id, UINT8);
4291 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4292 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4293                 policy, "l2#l23#l34");
4294
4295 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4296                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4297                 .help_str = "set bonding balance_xmit_policy <port_id> "
4298                         "l2|l23|l34: "
4299                         "Set the bonding balance_xmit_policy for port_id",
4300                 .data = NULL,
4301                 .tokens = {
4302                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4303                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4304                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4305                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4306                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4307                                 NULL
4308                 }
4309 };
4310
4311 /* *** SHOW NIC BONDING CONFIGURATION *** */
4312 struct cmd_show_bonding_config_result {
4313         cmdline_fixed_string_t show;
4314         cmdline_fixed_string_t bonding;
4315         cmdline_fixed_string_t config;
4316         uint8_t port_id;
4317 };
4318
4319 static void cmd_show_bonding_config_parsed(void *parsed_result,
4320                 __attribute__((unused))  struct cmdline *cl,
4321                 __attribute__((unused)) void *data)
4322 {
4323         struct cmd_show_bonding_config_result *res = parsed_result;
4324         int bonding_mode;
4325         uint8_t slaves[RTE_MAX_ETHPORTS];
4326         int num_slaves, num_active_slaves;
4327         int primary_id;
4328         int i;
4329         portid_t port_id = res->port_id;
4330
4331         /* Display the bonding mode.*/
4332         bonding_mode = rte_eth_bond_mode_get(port_id);
4333         if (bonding_mode < 0) {
4334                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4335                 return;
4336         } else
4337                 printf("\tBonding mode: %d\n", bonding_mode);
4338
4339         if (bonding_mode == BONDING_MODE_BALANCE) {
4340                 int balance_xmit_policy;
4341
4342                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4343                 if (balance_xmit_policy < 0) {
4344                         printf("\tFailed to get balance xmit policy for port = %d\n",
4345                                         port_id);
4346                         return;
4347                 } else {
4348                         printf("\tBalance Xmit Policy: ");
4349
4350                         switch (balance_xmit_policy) {
4351                         case BALANCE_XMIT_POLICY_LAYER2:
4352                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4353                                 break;
4354                         case BALANCE_XMIT_POLICY_LAYER23:
4355                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4356                                 break;
4357                         case BALANCE_XMIT_POLICY_LAYER34:
4358                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4359                                 break;
4360                         }
4361                         printf("\n");
4362                 }
4363         }
4364
4365         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4366
4367         if (num_slaves < 0) {
4368                 printf("\tFailed to get slave list for port = %d\n", port_id);
4369                 return;
4370         }
4371         if (num_slaves > 0) {
4372                 printf("\tSlaves (%d): [", num_slaves);
4373                 for (i = 0; i < num_slaves - 1; i++)
4374                         printf("%d ", slaves[i]);
4375
4376                 printf("%d]\n", slaves[num_slaves - 1]);
4377         } else {
4378                 printf("\tSlaves: []\n");
4379
4380         }
4381
4382         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4383                         RTE_MAX_ETHPORTS);
4384
4385         if (num_active_slaves < 0) {
4386                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4387                 return;
4388         }
4389         if (num_active_slaves > 0) {
4390                 printf("\tActive Slaves (%d): [", num_active_slaves);
4391                 for (i = 0; i < num_active_slaves - 1; i++)
4392                         printf("%d ", slaves[i]);
4393
4394                 printf("%d]\n", slaves[num_active_slaves - 1]);
4395
4396         } else {
4397                 printf("\tActive Slaves: []\n");
4398
4399         }
4400
4401         primary_id = rte_eth_bond_primary_get(port_id);
4402         if (primary_id < 0) {
4403                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4404                 return;
4405         } else
4406                 printf("\tPrimary: [%d]\n", primary_id);
4407
4408 }
4409
4410 cmdline_parse_token_string_t cmd_showbonding_config_show =
4411 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4412                 show, "show");
4413 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4414 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4415                 bonding, "bonding");
4416 cmdline_parse_token_string_t cmd_showbonding_config_config =
4417 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4418                 config, "config");
4419 cmdline_parse_token_num_t cmd_showbonding_config_port =
4420 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4421                 port_id, UINT8);
4422
4423 cmdline_parse_inst_t cmd_show_bonding_config = {
4424                 .f = cmd_show_bonding_config_parsed,
4425                 .help_str = "show bonding config <port_id>: "
4426                         "Show the bonding config for port_id",
4427                 .data = NULL,
4428                 .tokens = {
4429                                 (void *)&cmd_showbonding_config_show,
4430                                 (void *)&cmd_showbonding_config_bonding,
4431                                 (void *)&cmd_showbonding_config_config,
4432                                 (void *)&cmd_showbonding_config_port,
4433                                 NULL
4434                 }
4435 };
4436
4437 /* *** SET BONDING PRIMARY *** */
4438 struct cmd_set_bonding_primary_result {
4439         cmdline_fixed_string_t set;
4440         cmdline_fixed_string_t bonding;
4441         cmdline_fixed_string_t primary;
4442         uint8_t slave_id;
4443         uint8_t port_id;
4444 };
4445
4446 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4447                 __attribute__((unused))  struct cmdline *cl,
4448                 __attribute__((unused)) void *data)
4449 {
4450         struct cmd_set_bonding_primary_result *res = parsed_result;
4451         portid_t master_port_id = res->port_id;
4452         portid_t slave_port_id = res->slave_id;
4453
4454         /* Set the primary slave for a bonded device. */
4455         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4456                 printf("\t Failed to set primary slave for port = %d.\n",
4457                                 master_port_id);
4458                 return;
4459         }
4460         init_port_config();
4461 }
4462
4463 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4464 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4465                 set, "set");
4466 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4467 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4468                 bonding, "bonding");
4469 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4470 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4471                 primary, "primary");
4472 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4473 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4474                 slave_id, UINT8);
4475 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4476 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4477                 port_id, UINT8);
4478
4479 cmdline_parse_inst_t cmd_set_bonding_primary = {
4480                 .f = cmd_set_bonding_primary_parsed,
4481                 .help_str = "set bonding primary <slave_id> <port_id>: "
4482                         "Set the primary slave for port_id",
4483                 .data = NULL,
4484                 .tokens = {
4485                                 (void *)&cmd_setbonding_primary_set,
4486                                 (void *)&cmd_setbonding_primary_bonding,
4487                                 (void *)&cmd_setbonding_primary_primary,
4488                                 (void *)&cmd_setbonding_primary_slave,
4489                                 (void *)&cmd_setbonding_primary_port,
4490                                 NULL
4491                 }
4492 };
4493
4494 /* *** ADD SLAVE *** */
4495 struct cmd_add_bonding_slave_result {
4496         cmdline_fixed_string_t add;
4497         cmdline_fixed_string_t bonding;
4498         cmdline_fixed_string_t slave;
4499         uint8_t slave_id;
4500         uint8_t port_id;
4501 };
4502
4503 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4504                 __attribute__((unused))  struct cmdline *cl,
4505                 __attribute__((unused)) void *data)
4506 {
4507         struct cmd_add_bonding_slave_result *res = parsed_result;
4508         portid_t master_port_id = res->port_id;
4509         portid_t slave_port_id = res->slave_id;
4510
4511         /* Set the primary slave for a bonded device. */
4512         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4513                 printf("\t Failed to add slave %d to master port = %d.\n",
4514                                 slave_port_id, master_port_id);
4515                 return;
4516         }
4517         init_port_config();
4518         set_port_slave_flag(slave_port_id);
4519 }
4520
4521 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4522 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4523                 add, "add");
4524 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4525 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4526                 bonding, "bonding");
4527 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4528 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4529                 slave, "slave");
4530 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4531 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4532                 slave_id, UINT8);
4533 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4534 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4535                 port_id, UINT8);
4536
4537 cmdline_parse_inst_t cmd_add_bonding_slave = {
4538                 .f = cmd_add_bonding_slave_parsed,
4539                 .help_str = "add bonding slave <slave_id> <port_id>: "
4540                         "Add a slave device to a bonded device",
4541                 .data = NULL,
4542                 .tokens = {
4543                                 (void *)&cmd_addbonding_slave_add,
4544                                 (void *)&cmd_addbonding_slave_bonding,
4545                                 (void *)&cmd_addbonding_slave_slave,
4546                                 (void *)&cmd_addbonding_slave_slaveid,
4547                                 (void *)&cmd_addbonding_slave_port,
4548                                 NULL
4549                 }
4550 };
4551
4552 /* *** REMOVE SLAVE *** */
4553 struct cmd_remove_bonding_slave_result {
4554         cmdline_fixed_string_t remove;
4555         cmdline_fixed_string_t bonding;
4556         cmdline_fixed_string_t slave;
4557         uint8_t slave_id;
4558         uint8_t port_id;
4559 };
4560
4561 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4562                 __attribute__((unused))  struct cmdline *cl,
4563                 __attribute__((unused)) void *data)
4564 {
4565         struct cmd_remove_bonding_slave_result *res = parsed_result;
4566         portid_t master_port_id = res->port_id;
4567         portid_t slave_port_id = res->slave_id;
4568
4569         /* Set the primary slave for a bonded device. */
4570         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4571                 printf("\t Failed to remove slave %d from master port = %d.\n",
4572                                 slave_port_id, master_port_id);
4573                 return;
4574         }
4575         init_port_config();
4576         clear_port_slave_flag(slave_port_id);
4577 }
4578
4579 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4580                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4581                                 remove, "remove");
4582 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4583                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4584                                 bonding, "bonding");
4585 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4586                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4587                                 slave, "slave");
4588 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4589                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4590                                 slave_id, UINT8);
4591 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4592                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4593                                 port_id, UINT8);
4594
4595 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4596                 .f = cmd_remove_bonding_slave_parsed,
4597                 .help_str = "remove bonding slave <slave_id> <port_id>: "
4598                         "Remove a slave device from a bonded device",
4599                 .data = NULL,
4600                 .tokens = {
4601                                 (void *)&cmd_removebonding_slave_remove,
4602                                 (void *)&cmd_removebonding_slave_bonding,
4603                                 (void *)&cmd_removebonding_slave_slave,
4604                                 (void *)&cmd_removebonding_slave_slaveid,
4605                                 (void *)&cmd_removebonding_slave_port,
4606                                 NULL
4607                 }
4608 };
4609
4610 /* *** CREATE BONDED DEVICE *** */
4611 struct cmd_create_bonded_device_result {
4612         cmdline_fixed_string_t create;
4613         cmdline_fixed_string_t bonded;
4614         cmdline_fixed_string_t device;
4615         uint8_t mode;
4616         uint8_t socket;
4617 };
4618
4619 static int bond_dev_num = 0;
4620
4621 static void cmd_create_bonded_device_parsed(void *parsed_result,
4622                 __attribute__((unused))  struct cmdline *cl,
4623                 __attribute__((unused)) void *data)
4624 {
4625         struct cmd_create_bonded_device_result *res = parsed_result;
4626         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4627         int port_id;
4628
4629         if (test_done == 0) {
4630                 printf("Please stop forwarding first\n");
4631                 return;
4632         }
4633
4634         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bond_testpmd_%d",
4635                         bond_dev_num++);
4636
4637         /* Create a new bonded device. */
4638         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4639         if (port_id < 0) {
4640                 printf("\t Failed to create bonded device.\n");
4641                 return;
4642         } else {
4643                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4644                                 port_id);
4645
4646                 /* Update number of ports */
4647                 nb_ports = rte_eth_dev_count();
4648                 reconfig(port_id, res->socket);
4649                 rte_eth_promiscuous_enable(port_id);
4650                 ports[port_id].enabled = 1;
4651         }
4652
4653 }
4654
4655 cmdline_parse_token_string_t cmd_createbonded_device_create =
4656                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4657                                 create, "create");
4658 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4659                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4660                                 bonded, "bonded");
4661 cmdline_parse_token_string_t cmd_createbonded_device_device =
4662                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4663                                 device, "device");
4664 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4665                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4666                                 mode, UINT8);
4667 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4668                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4669                                 socket, UINT8);
4670
4671 cmdline_parse_inst_t cmd_create_bonded_device = {
4672                 .f = cmd_create_bonded_device_parsed,
4673                 .help_str = "create bonded device <mode> <socket>: "
4674                         "Create a new bonded device with specific bonding mode and socket",
4675                 .data = NULL,
4676                 .tokens = {
4677                                 (void *)&cmd_createbonded_device_create,
4678                                 (void *)&cmd_createbonded_device_bonded,
4679                                 (void *)&cmd_createbonded_device_device,
4680                                 (void *)&cmd_createbonded_device_mode,
4681                                 (void *)&cmd_createbonded_device_socket,
4682                                 NULL
4683                 }
4684 };
4685
4686 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4687 struct cmd_set_bond_mac_addr_result {
4688         cmdline_fixed_string_t set;
4689         cmdline_fixed_string_t bonding;
4690         cmdline_fixed_string_t mac_addr;
4691         uint8_t port_num;
4692         struct ether_addr address;
4693 };
4694
4695 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4696                 __attribute__((unused))  struct cmdline *cl,
4697                 __attribute__((unused)) void *data)
4698 {
4699         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4700         int ret;
4701
4702         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4703                 return;
4704
4705         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4706
4707         /* check the return value and print it if is < 0 */
4708         if (ret < 0)
4709                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4710 }
4711
4712 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4713                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4714 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4715                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4716                                 "bonding");
4717 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4718                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4719                                 "mac_addr");
4720 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4721                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4722 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4723                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4724
4725 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4726                 .f = cmd_set_bond_mac_addr_parsed,
4727                 .data = (void *) 0,
4728                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
4729                 .tokens = {
4730                                 (void *)&cmd_set_bond_mac_addr_set,
4731                                 (void *)&cmd_set_bond_mac_addr_bonding,
4732                                 (void *)&cmd_set_bond_mac_addr_mac,
4733                                 (void *)&cmd_set_bond_mac_addr_portnum,
4734                                 (void *)&cmd_set_bond_mac_addr_addr,
4735                                 NULL
4736                 }
4737 };
4738
4739
4740 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4741 struct cmd_set_bond_mon_period_result {
4742         cmdline_fixed_string_t set;
4743         cmdline_fixed_string_t bonding;
4744         cmdline_fixed_string_t mon_period;
4745         uint8_t port_num;
4746         uint32_t period_ms;
4747 };
4748
4749 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4750                 __attribute__((unused))  struct cmdline *cl,
4751                 __attribute__((unused)) void *data)
4752 {
4753         struct cmd_set_bond_mon_period_result *res = parsed_result;
4754         int ret;
4755
4756         if (res->port_num >= nb_ports) {
4757                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4758                 return;
4759         }
4760
4761         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4762
4763         /* check the return value and print it if is < 0 */
4764         if (ret < 0)
4765                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4766 }
4767
4768 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4769                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4770                                 set, "set");
4771 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4772                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4773                                 bonding, "bonding");
4774 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4775                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4776                                 mon_period,     "mon_period");
4777 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4778                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4779                                 port_num, UINT8);
4780 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4781                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4782                                 period_ms, UINT32);
4783
4784 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4785                 .f = cmd_set_bond_mon_period_parsed,
4786                 .data = (void *) 0,
4787                 .help_str = "set bonding mon_period <port_id> <period_ms>",
4788                 .tokens = {
4789                                 (void *)&cmd_set_bond_mon_period_set,
4790                                 (void *)&cmd_set_bond_mon_period_bonding,
4791                                 (void *)&cmd_set_bond_mon_period_mon_period,
4792                                 (void *)&cmd_set_bond_mon_period_portnum,
4793                                 (void *)&cmd_set_bond_mon_period_period_ms,
4794                                 NULL
4795                 }
4796 };
4797
4798 #endif /* RTE_LIBRTE_PMD_BOND */
4799
4800 /* *** SET FORWARDING MODE *** */
4801 struct cmd_set_fwd_mode_result {
4802         cmdline_fixed_string_t set;
4803         cmdline_fixed_string_t fwd;
4804         cmdline_fixed_string_t mode;
4805 };
4806
4807 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4808                                     __attribute__((unused)) struct cmdline *cl,
4809                                     __attribute__((unused)) void *data)
4810 {
4811         struct cmd_set_fwd_mode_result *res = parsed_result;
4812
4813         retry_enabled = 0;
4814         set_pkt_forwarding_mode(res->mode);
4815 }
4816
4817 cmdline_parse_token_string_t cmd_setfwd_set =
4818         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4819 cmdline_parse_token_string_t cmd_setfwd_fwd =
4820         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4821 cmdline_parse_token_string_t cmd_setfwd_mode =
4822         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4823                 "" /* defined at init */);
4824
4825 cmdline_parse_inst_t cmd_set_fwd_mode = {
4826         .f = cmd_set_fwd_mode_parsed,
4827         .data = NULL,
4828         .help_str = NULL, /* defined at init */
4829         .tokens = {
4830                 (void *)&cmd_setfwd_set,
4831                 (void *)&cmd_setfwd_fwd,
4832                 (void *)&cmd_setfwd_mode,
4833                 NULL,
4834         },
4835 };
4836
4837 static void cmd_set_fwd_mode_init(void)
4838 {
4839         char *modes, *c;
4840         static char token[128];
4841         static char help[256];
4842         cmdline_parse_token_string_t *token_struct;
4843
4844         modes = list_pkt_forwarding_modes();
4845         snprintf(help, sizeof(help), "set fwd %s: "
4846                 "Set packet forwarding mode", modes);
4847         cmd_set_fwd_mode.help_str = help;
4848
4849         /* string token separator is # */
4850         for (c = token; *modes != '\0'; modes++)
4851                 if (*modes == '|')
4852                         *c++ = '#';
4853                 else
4854                         *c++ = *modes;
4855         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4856         token_struct->string_data.str = token;
4857 }
4858
4859 /* *** SET RETRY FORWARDING MODE *** */
4860 struct cmd_set_fwd_retry_mode_result {
4861         cmdline_fixed_string_t set;
4862         cmdline_fixed_string_t fwd;
4863         cmdline_fixed_string_t mode;
4864         cmdline_fixed_string_t retry;
4865 };
4866
4867 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
4868                             __attribute__((unused)) struct cmdline *cl,
4869                             __attribute__((unused)) void *data)
4870 {
4871         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
4872
4873         retry_enabled = 1;
4874         set_pkt_forwarding_mode(res->mode);
4875 }
4876
4877 cmdline_parse_token_string_t cmd_setfwd_retry_set =
4878         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4879                         set, "set");
4880 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
4881         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4882                         fwd, "fwd");
4883 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
4884         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4885                         mode,
4886                 "" /* defined at init */);
4887 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
4888         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4889                         retry, "retry");
4890
4891 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
4892         .f = cmd_set_fwd_retry_mode_parsed,
4893         .data = NULL,
4894         .help_str = NULL, /* defined at init */
4895         .tokens = {
4896                 (void *)&cmd_setfwd_retry_set,
4897                 (void *)&cmd_setfwd_retry_fwd,
4898                 (void *)&cmd_setfwd_retry_mode,
4899                 (void *)&cmd_setfwd_retry_retry,
4900                 NULL,
4901         },
4902 };
4903
4904 static void cmd_set_fwd_retry_mode_init(void)
4905 {
4906         char *modes, *c;
4907         static char token[128];
4908         static char help[256];
4909         cmdline_parse_token_string_t *token_struct;
4910
4911         modes = list_pkt_forwarding_retry_modes();
4912         snprintf(help, sizeof(help), "set fwd %s retry: "
4913                 "Set packet forwarding mode with retry", modes);
4914         cmd_set_fwd_retry_mode.help_str = help;
4915
4916         /* string token separator is # */
4917         for (c = token; *modes != '\0'; modes++)
4918                 if (*modes == '|')
4919                         *c++ = '#';
4920                 else
4921                         *c++ = *modes;
4922         token_struct = (cmdline_parse_token_string_t *)
4923                 cmd_set_fwd_retry_mode.tokens[2];
4924         token_struct->string_data.str = token;
4925 }
4926
4927 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4928 struct cmd_set_burst_tx_retry_result {
4929         cmdline_fixed_string_t set;
4930         cmdline_fixed_string_t burst;
4931         cmdline_fixed_string_t tx;
4932         cmdline_fixed_string_t delay;
4933         uint32_t time;
4934         cmdline_fixed_string_t retry;
4935         uint32_t retry_num;
4936 };
4937
4938 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4939                                         __attribute__((unused)) struct cmdline *cl,
4940                                         __attribute__((unused)) void *data)
4941 {
4942         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4943
4944         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4945                 && !strcmp(res->tx, "tx")) {
4946                 if (!strcmp(res->delay, "delay"))
4947                         burst_tx_delay_time = res->time;
4948                 if (!strcmp(res->retry, "retry"))
4949                         burst_tx_retry_num = res->retry_num;
4950         }
4951
4952 }
4953
4954 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4955         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4956 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4957         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4958                                  "burst");
4959 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4960         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4961 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4962         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4963 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4964         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4965 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4966         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4967 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4968         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4969
4970 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4971         .f = cmd_set_burst_tx_retry_parsed,
4972         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
4973         .tokens = {
4974                 (void *)&cmd_set_burst_tx_retry_set,
4975                 (void *)&cmd_set_burst_tx_retry_burst,
4976                 (void *)&cmd_set_burst_tx_retry_tx,
4977                 (void *)&cmd_set_burst_tx_retry_delay,
4978                 (void *)&cmd_set_burst_tx_retry_time,
4979                 (void *)&cmd_set_burst_tx_retry_retry,
4980                 (void *)&cmd_set_burst_tx_retry_retry_num,
4981                 NULL,
4982         },
4983 };
4984
4985 /* *** SET PROMISC MODE *** */
4986 struct cmd_set_promisc_mode_result {
4987         cmdline_fixed_string_t set;
4988         cmdline_fixed_string_t promisc;
4989         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4990         uint8_t port_num;                /* valid if "allports" argument == 0 */
4991         cmdline_fixed_string_t mode;
4992 };
4993
4994 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4995                                         __attribute__((unused)) struct cmdline *cl,
4996                                         void *allports)
4997 {
4998         struct cmd_set_promisc_mode_result *res = parsed_result;
4999         int enable;
5000         portid_t i;
5001
5002         if (!strcmp(res->mode, "on"))
5003                 enable = 1;
5004         else
5005                 enable = 0;
5006
5007         /* all ports */
5008         if (allports) {
5009                 FOREACH_PORT(i, ports) {
5010                         if (enable)
5011                                 rte_eth_promiscuous_enable(i);
5012                         else
5013                                 rte_eth_promiscuous_disable(i);
5014                 }
5015         }
5016         else {
5017                 if (enable)
5018                         rte_eth_promiscuous_enable(res->port_num);
5019                 else
5020                         rte_eth_promiscuous_disable(res->port_num);
5021         }
5022 }
5023
5024 cmdline_parse_token_string_t cmd_setpromisc_set =
5025         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5026 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5027         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5028                                  "promisc");
5029 cmdline_parse_token_string_t cmd_setpromisc_portall =
5030         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5031                                  "all");
5032 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5033         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5034                               UINT8);
5035 cmdline_parse_token_string_t cmd_setpromisc_mode =
5036         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5037                                  "on#off");
5038
5039 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5040         .f = cmd_set_promisc_mode_parsed,
5041         .data = (void *)1,
5042         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5043         .tokens = {
5044                 (void *)&cmd_setpromisc_set,
5045                 (void *)&cmd_setpromisc_promisc,
5046                 (void *)&cmd_setpromisc_portall,
5047                 (void *)&cmd_setpromisc_mode,
5048                 NULL,
5049         },
5050 };
5051
5052 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5053         .f = cmd_set_promisc_mode_parsed,
5054         .data = (void *)0,
5055         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5056         .tokens = {
5057                 (void *)&cmd_setpromisc_set,
5058                 (void *)&cmd_setpromisc_promisc,
5059                 (void *)&cmd_setpromisc_portnum,
5060                 (void *)&cmd_setpromisc_mode,
5061                 NULL,
5062         },
5063 };
5064
5065 /* *** SET ALLMULTI MODE *** */
5066 struct cmd_set_allmulti_mode_result {
5067         cmdline_fixed_string_t set;
5068         cmdline_fixed_string_t allmulti;
5069         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5070         uint8_t port_num;                /* valid if "allports" argument == 0 */
5071         cmdline_fixed_string_t mode;
5072 };
5073
5074 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5075                                         __attribute__((unused)) struct cmdline *cl,
5076                                         void *allports)
5077 {
5078         struct cmd_set_allmulti_mode_result *res = parsed_result;
5079         int enable;
5080         portid_t i;
5081
5082         if (!strcmp(res->mode, "on"))
5083                 enable = 1;
5084         else
5085                 enable = 0;
5086
5087         /* all ports */
5088         if (allports) {
5089                 FOREACH_PORT(i, ports) {
5090                         if (enable)
5091                                 rte_eth_allmulticast_enable(i);
5092                         else
5093                                 rte_eth_allmulticast_disable(i);
5094                 }
5095         }
5096         else {
5097                 if (enable)
5098                         rte_eth_allmulticast_enable(res->port_num);
5099                 else
5100                         rte_eth_allmulticast_disable(res->port_num);
5101         }
5102 }
5103
5104 cmdline_parse_token_string_t cmd_setallmulti_set =
5105         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5106 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5107         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5108                                  "allmulti");
5109 cmdline_parse_token_string_t cmd_setallmulti_portall =
5110         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5111                                  "all");
5112 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5113         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5114                               UINT8);
5115 cmdline_parse_token_string_t cmd_setallmulti_mode =
5116         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5117                                  "on#off");
5118
5119 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5120         .f = cmd_set_allmulti_mode_parsed,
5121         .data = (void *)1,
5122         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5123         .tokens = {
5124                 (void *)&cmd_setallmulti_set,
5125                 (void *)&cmd_setallmulti_allmulti,
5126                 (void *)&cmd_setallmulti_portall,
5127                 (void *)&cmd_setallmulti_mode,
5128                 NULL,
5129         },
5130 };
5131
5132 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5133         .f = cmd_set_allmulti_mode_parsed,
5134         .data = (void *)0,
5135         .help_str = "set allmulti <port_id> on|off: "
5136                 "Set allmulti mode on port_id",
5137         .tokens = {
5138                 (void *)&cmd_setallmulti_set,
5139                 (void *)&cmd_setallmulti_allmulti,
5140                 (void *)&cmd_setallmulti_portnum,
5141                 (void *)&cmd_setallmulti_mode,
5142                 NULL,
5143         },
5144 };
5145
5146 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5147 struct cmd_link_flow_ctrl_set_result {
5148         cmdline_fixed_string_t set;
5149         cmdline_fixed_string_t flow_ctrl;
5150         cmdline_fixed_string_t rx;
5151         cmdline_fixed_string_t rx_lfc_mode;
5152         cmdline_fixed_string_t tx;
5153         cmdline_fixed_string_t tx_lfc_mode;
5154         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5155         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5156         cmdline_fixed_string_t autoneg_str;
5157         cmdline_fixed_string_t autoneg;
5158         cmdline_fixed_string_t hw_str;
5159         uint32_t high_water;
5160         cmdline_fixed_string_t lw_str;
5161         uint32_t low_water;
5162         cmdline_fixed_string_t pt_str;
5163         uint16_t pause_time;
5164         cmdline_fixed_string_t xon_str;
5165         uint16_t send_xon;
5166         uint8_t  port_id;
5167 };
5168
5169 cmdline_parse_token_string_t cmd_lfc_set_set =
5170         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5171                                 set, "set");
5172 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5173         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5174                                 flow_ctrl, "flow_ctrl");
5175 cmdline_parse_token_string_t cmd_lfc_set_rx =
5176         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5177                                 rx, "rx");
5178 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5179         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5180                                 rx_lfc_mode, "on#off");
5181 cmdline_parse_token_string_t cmd_lfc_set_tx =
5182         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5183                                 tx, "tx");
5184 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5185         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5186                                 tx_lfc_mode, "on#off");
5187 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5188         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5189                                 hw_str, "high_water");
5190 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5191         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5192                                 high_water, UINT32);
5193 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5194         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5195                                 lw_str, "low_water");
5196 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5197         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5198                                 low_water, UINT32);
5199 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5200         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5201                                 pt_str, "pause_time");
5202 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5203         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5204                                 pause_time, UINT16);
5205 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5206         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5207                                 xon_str, "send_xon");
5208 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5209         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5210                                 send_xon, UINT16);
5211 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5212         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5213                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5214 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5215         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5216                                 mac_ctrl_frame_fwd_mode, "on#off");
5217 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5218         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5219                                 autoneg_str, "autoneg");
5220 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5221         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5222                                 autoneg, "on#off");
5223 cmdline_parse_token_num_t cmd_lfc_set_portid =
5224         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5225                                 port_id, UINT8);
5226
5227 /* forward declaration */
5228 static void
5229 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5230                               void *data);
5231
5232 cmdline_parse_inst_t cmd_link_flow_control_set = {
5233         .f = cmd_link_flow_ctrl_set_parsed,
5234         .data = NULL,
5235         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5236                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5237                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5238         .tokens = {
5239                 (void *)&cmd_lfc_set_set,
5240                 (void *)&cmd_lfc_set_flow_ctrl,
5241                 (void *)&cmd_lfc_set_rx,
5242                 (void *)&cmd_lfc_set_rx_mode,
5243                 (void *)&cmd_lfc_set_tx,
5244                 (void *)&cmd_lfc_set_tx_mode,
5245                 (void *)&cmd_lfc_set_high_water,
5246                 (void *)&cmd_lfc_set_low_water,
5247                 (void *)&cmd_lfc_set_pause_time,
5248                 (void *)&cmd_lfc_set_send_xon,
5249                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5250                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5251                 (void *)&cmd_lfc_set_autoneg_str,
5252                 (void *)&cmd_lfc_set_autoneg,
5253                 (void *)&cmd_lfc_set_portid,
5254                 NULL,
5255         },
5256 };
5257
5258 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5259         .f = cmd_link_flow_ctrl_set_parsed,
5260         .data = (void *)&cmd_link_flow_control_set_rx,
5261         .help_str = "set flow_ctrl rx on|off <port_id>: "
5262                 "Change rx flow control parameter",
5263         .tokens = {
5264                 (void *)&cmd_lfc_set_set,
5265                 (void *)&cmd_lfc_set_flow_ctrl,
5266                 (void *)&cmd_lfc_set_rx,
5267                 (void *)&cmd_lfc_set_rx_mode,
5268                 (void *)&cmd_lfc_set_portid,
5269                 NULL,
5270         },
5271 };
5272
5273 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5274         .f = cmd_link_flow_ctrl_set_parsed,
5275         .data = (void *)&cmd_link_flow_control_set_tx,
5276         .help_str = "set flow_ctrl tx on|off <port_id>: "
5277                 "Change tx flow control parameter",
5278         .tokens = {
5279                 (void *)&cmd_lfc_set_set,
5280                 (void *)&cmd_lfc_set_flow_ctrl,
5281                 (void *)&cmd_lfc_set_tx,
5282                 (void *)&cmd_lfc_set_tx_mode,
5283                 (void *)&cmd_lfc_set_portid,
5284                 NULL,
5285         },
5286 };
5287
5288 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5289         .f = cmd_link_flow_ctrl_set_parsed,
5290         .data = (void *)&cmd_link_flow_control_set_hw,
5291         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5292                 "Change high water flow control parameter",
5293         .tokens = {
5294                 (void *)&cmd_lfc_set_set,
5295                 (void *)&cmd_lfc_set_flow_ctrl,
5296                 (void *)&cmd_lfc_set_high_water_str,
5297                 (void *)&cmd_lfc_set_high_water,
5298                 (void *)&cmd_lfc_set_portid,
5299                 NULL,
5300         },
5301 };
5302
5303 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5304         .f = cmd_link_flow_ctrl_set_parsed,
5305         .data = (void *)&cmd_link_flow_control_set_lw,
5306         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5307                 "Change low water flow control parameter",
5308         .tokens = {
5309                 (void *)&cmd_lfc_set_set,
5310                 (void *)&cmd_lfc_set_flow_ctrl,
5311                 (void *)&cmd_lfc_set_low_water_str,
5312                 (void *)&cmd_lfc_set_low_water,
5313                 (void *)&cmd_lfc_set_portid,
5314                 NULL,
5315         },
5316 };
5317
5318 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5319         .f = cmd_link_flow_ctrl_set_parsed,
5320         .data = (void *)&cmd_link_flow_control_set_pt,
5321         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5322                 "Change pause time flow control parameter",
5323         .tokens = {
5324                 (void *)&cmd_lfc_set_set,
5325                 (void *)&cmd_lfc_set_flow_ctrl,
5326                 (void *)&cmd_lfc_set_pause_time_str,
5327                 (void *)&cmd_lfc_set_pause_time,
5328                 (void *)&cmd_lfc_set_portid,
5329                 NULL,
5330         },
5331 };
5332
5333 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5334         .f = cmd_link_flow_ctrl_set_parsed,
5335         .data = (void *)&cmd_link_flow_control_set_xon,
5336         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5337                 "Change send_xon flow control parameter",
5338         .tokens = {
5339                 (void *)&cmd_lfc_set_set,
5340                 (void *)&cmd_lfc_set_flow_ctrl,
5341                 (void *)&cmd_lfc_set_send_xon_str,
5342                 (void *)&cmd_lfc_set_send_xon,
5343                 (void *)&cmd_lfc_set_portid,
5344                 NULL,
5345         },
5346 };
5347
5348 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5349         .f = cmd_link_flow_ctrl_set_parsed,
5350         .data = (void *)&cmd_link_flow_control_set_macfwd,
5351         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5352                 "Change mac ctrl fwd flow control parameter",
5353         .tokens = {
5354                 (void *)&cmd_lfc_set_set,
5355                 (void *)&cmd_lfc_set_flow_ctrl,
5356                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5357                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5358                 (void *)&cmd_lfc_set_portid,
5359                 NULL,
5360         },
5361 };
5362
5363 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5364         .f = cmd_link_flow_ctrl_set_parsed,
5365         .data = (void *)&cmd_link_flow_control_set_autoneg,
5366         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5367                 "Change autoneg flow control parameter",
5368         .tokens = {
5369                 (void *)&cmd_lfc_set_set,
5370                 (void *)&cmd_lfc_set_flow_ctrl,
5371                 (void *)&cmd_lfc_set_autoneg_str,
5372                 (void *)&cmd_lfc_set_autoneg,
5373                 (void *)&cmd_lfc_set_portid,
5374                 NULL,
5375         },
5376 };
5377
5378 static void
5379 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5380                               __attribute__((unused)) struct cmdline *cl,
5381                               void *data)
5382 {
5383         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5384         cmdline_parse_inst_t *cmd = data;
5385         struct rte_eth_fc_conf fc_conf;
5386         int rx_fc_en = 0;
5387         int tx_fc_en = 0;
5388         int ret;
5389
5390         /*
5391          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5392          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5393          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5394          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5395          */
5396         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5397                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5398         };
5399
5400         /* Partial command line, retrieve current configuration */
5401         if (cmd) {
5402                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5403                 if (ret != 0) {
5404                         printf("cannot get current flow ctrl parameters, return"
5405                                "code = %d\n", ret);
5406                         return;
5407                 }
5408
5409                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5410                     (fc_conf.mode == RTE_FC_FULL))
5411                         rx_fc_en = 1;
5412                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5413                     (fc_conf.mode == RTE_FC_FULL))
5414                         tx_fc_en = 1;
5415         }
5416
5417         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5418                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5419
5420         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5421                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5422
5423         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5424
5425         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5426                 fc_conf.high_water = res->high_water;
5427
5428         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5429                 fc_conf.low_water = res->low_water;
5430
5431         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5432                 fc_conf.pause_time = res->pause_time;
5433
5434         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5435                 fc_conf.send_xon = res->send_xon;
5436
5437         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5438                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5439                         fc_conf.mac_ctrl_frame_fwd = 1;
5440                 else
5441                         fc_conf.mac_ctrl_frame_fwd = 0;
5442         }
5443
5444         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5445                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5446
5447         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5448         if (ret != 0)
5449                 printf("bad flow contrl parameter, return code = %d \n", ret);
5450 }
5451
5452 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5453 struct cmd_priority_flow_ctrl_set_result {
5454         cmdline_fixed_string_t set;
5455         cmdline_fixed_string_t pfc_ctrl;
5456         cmdline_fixed_string_t rx;
5457         cmdline_fixed_string_t rx_pfc_mode;
5458         cmdline_fixed_string_t tx;
5459         cmdline_fixed_string_t tx_pfc_mode;
5460         uint32_t high_water;
5461         uint32_t low_water;
5462         uint16_t pause_time;
5463         uint8_t  priority;
5464         uint8_t  port_id;
5465 };
5466
5467 static void
5468 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5469                        __attribute__((unused)) struct cmdline *cl,
5470                        __attribute__((unused)) void *data)
5471 {
5472         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5473         struct rte_eth_pfc_conf pfc_conf;
5474         int rx_fc_enable, tx_fc_enable;
5475         int ret;
5476
5477         /*
5478          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5479          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5480          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5481          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5482          */
5483         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5484                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5485         };
5486
5487         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5488         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5489         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5490         pfc_conf.fc.high_water = res->high_water;
5491         pfc_conf.fc.low_water  = res->low_water;
5492         pfc_conf.fc.pause_time = res->pause_time;
5493         pfc_conf.priority      = res->priority;
5494
5495         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5496         if (ret != 0)
5497                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5498 }
5499
5500 cmdline_parse_token_string_t cmd_pfc_set_set =
5501         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5502                                 set, "set");
5503 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5504         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5505                                 pfc_ctrl, "pfc_ctrl");
5506 cmdline_parse_token_string_t cmd_pfc_set_rx =
5507         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5508                                 rx, "rx");
5509 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5510         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5511                                 rx_pfc_mode, "on#off");
5512 cmdline_parse_token_string_t cmd_pfc_set_tx =
5513         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5514                                 tx, "tx");
5515 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5516         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5517                                 tx_pfc_mode, "on#off");
5518 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5519         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5520                                 high_water, UINT32);
5521 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5522         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5523                                 low_water, UINT32);
5524 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5525         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5526                                 pause_time, UINT16);
5527 cmdline_parse_token_num_t cmd_pfc_set_priority =
5528         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5529                                 priority, UINT8);
5530 cmdline_parse_token_num_t cmd_pfc_set_portid =
5531         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5532                                 port_id, UINT8);
5533
5534 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5535         .f = cmd_priority_flow_ctrl_set_parsed,
5536         .data = NULL,
5537         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5538                 "<pause_time> <priority> <port_id>: "
5539                 "Configure the Ethernet priority flow control",
5540         .tokens = {
5541                 (void *)&cmd_pfc_set_set,
5542                 (void *)&cmd_pfc_set_flow_ctrl,
5543                 (void *)&cmd_pfc_set_rx,
5544                 (void *)&cmd_pfc_set_rx_mode,
5545                 (void *)&cmd_pfc_set_tx,
5546                 (void *)&cmd_pfc_set_tx_mode,
5547                 (void *)&cmd_pfc_set_high_water,
5548                 (void *)&cmd_pfc_set_low_water,
5549                 (void *)&cmd_pfc_set_pause_time,
5550                 (void *)&cmd_pfc_set_priority,
5551                 (void *)&cmd_pfc_set_portid,
5552                 NULL,
5553         },
5554 };
5555
5556 /* *** RESET CONFIGURATION *** */
5557 struct cmd_reset_result {
5558         cmdline_fixed_string_t reset;
5559         cmdline_fixed_string_t def;
5560 };
5561
5562 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5563                              struct cmdline *cl,
5564                              __attribute__((unused)) void *data)
5565 {
5566         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5567         set_def_fwd_config();
5568 }
5569
5570 cmdline_parse_token_string_t cmd_reset_set =
5571         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5572 cmdline_parse_token_string_t cmd_reset_def =
5573         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5574                                  "default");
5575
5576 cmdline_parse_inst_t cmd_reset = {
5577         .f = cmd_reset_parsed,
5578         .data = NULL,
5579         .help_str = "set default: Reset default forwarding configuration",
5580         .tokens = {
5581                 (void *)&cmd_reset_set,
5582                 (void *)&cmd_reset_def,
5583                 NULL,
5584         },
5585 };
5586
5587 /* *** START FORWARDING *** */
5588 struct cmd_start_result {
5589         cmdline_fixed_string_t start;
5590 };
5591
5592 cmdline_parse_token_string_t cmd_start_start =
5593         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5594
5595 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5596                              __attribute__((unused)) struct cmdline *cl,
5597                              __attribute__((unused)) void *data)
5598 {
5599         start_packet_forwarding(0);
5600 }
5601
5602 cmdline_parse_inst_t cmd_start = {
5603         .f = cmd_start_parsed,
5604         .data = NULL,
5605         .help_str = "start: Start packet forwarding",
5606         .tokens = {
5607                 (void *)&cmd_start_start,
5608                 NULL,
5609         },
5610 };
5611
5612 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5613 struct cmd_start_tx_first_result {
5614         cmdline_fixed_string_t start;
5615         cmdline_fixed_string_t tx_first;
5616 };
5617
5618 static void
5619 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5620                           __attribute__((unused)) struct cmdline *cl,
5621                           __attribute__((unused)) void *data)
5622 {
5623         start_packet_forwarding(1);
5624 }
5625
5626 cmdline_parse_token_string_t cmd_start_tx_first_start =
5627         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5628                                  "start");
5629 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5630         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5631                                  tx_first, "tx_first");
5632
5633 cmdline_parse_inst_t cmd_start_tx_first = {
5634         .f = cmd_start_tx_first_parsed,
5635         .data = NULL,
5636         .help_str = "start tx_first: Start packet forwarding, "
5637                 "after sending 1 burst of packets",
5638         .tokens = {
5639                 (void *)&cmd_start_tx_first_start,
5640                 (void *)&cmd_start_tx_first_tx_first,
5641                 NULL,
5642         },
5643 };
5644
5645 /* *** START FORWARDING WITH N TX BURST FIRST *** */
5646 struct cmd_start_tx_first_n_result {
5647         cmdline_fixed_string_t start;
5648         cmdline_fixed_string_t tx_first;
5649         uint32_t tx_num;
5650 };
5651
5652 static void
5653 cmd_start_tx_first_n_parsed(void *parsed_result,
5654                           __attribute__((unused)) struct cmdline *cl,
5655                           __attribute__((unused)) void *data)
5656 {
5657         struct cmd_start_tx_first_n_result *res = parsed_result;
5658
5659         start_packet_forwarding(res->tx_num);
5660 }
5661
5662 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
5663         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5664                         start, "start");
5665 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
5666         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5667                         tx_first, "tx_first");
5668 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
5669         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
5670                         tx_num, UINT32);
5671
5672 cmdline_parse_inst_t cmd_start_tx_first_n = {
5673         .f = cmd_start_tx_first_n_parsed,
5674         .data = NULL,
5675         .help_str = "start tx_first <num>: "
5676                 "packet forwarding, after sending <num> bursts of packets",
5677         .tokens = {
5678                 (void *)&cmd_start_tx_first_n_start,
5679                 (void *)&cmd_start_tx_first_n_tx_first,
5680                 (void *)&cmd_start_tx_first_n_tx_num,
5681                 NULL,
5682         },
5683 };
5684
5685 /* *** SET LINK UP *** */
5686 struct cmd_set_link_up_result {
5687         cmdline_fixed_string_t set;
5688         cmdline_fixed_string_t link_up;
5689         cmdline_fixed_string_t port;
5690         uint8_t port_id;
5691 };
5692
5693 cmdline_parse_token_string_t cmd_set_link_up_set =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5695 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5696         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5697                                 "link-up");
5698 cmdline_parse_token_string_t cmd_set_link_up_port =
5699         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5700 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5701         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5702
5703 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5704                              __attribute__((unused)) struct cmdline *cl,
5705                              __attribute__((unused)) void *data)
5706 {
5707         struct cmd_set_link_up_result *res = parsed_result;
5708         dev_set_link_up(res->port_id);
5709 }
5710
5711 cmdline_parse_inst_t cmd_set_link_up = {
5712         .f = cmd_set_link_up_parsed,
5713         .data = NULL,
5714         .help_str = "set link-up port <port id>",
5715         .tokens = {
5716                 (void *)&cmd_set_link_up_set,
5717                 (void *)&cmd_set_link_up_link_up,
5718                 (void *)&cmd_set_link_up_port,
5719                 (void *)&cmd_set_link_up_port_id,
5720                 NULL,
5721         },
5722 };
5723
5724 /* *** SET LINK DOWN *** */
5725 struct cmd_set_link_down_result {
5726         cmdline_fixed_string_t set;
5727         cmdline_fixed_string_t link_down;
5728         cmdline_fixed_string_t port;
5729         uint8_t port_id;
5730 };
5731
5732 cmdline_parse_token_string_t cmd_set_link_down_set =
5733         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5734 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5735         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5736                                 "link-down");
5737 cmdline_parse_token_string_t cmd_set_link_down_port =
5738         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5739 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5740         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5741
5742 static void cmd_set_link_down_parsed(
5743                                 __attribute__((unused)) void *parsed_result,
5744                                 __attribute__((unused)) struct cmdline *cl,
5745                                 __attribute__((unused)) void *data)
5746 {
5747         struct cmd_set_link_down_result *res = parsed_result;
5748         dev_set_link_down(res->port_id);
5749 }
5750
5751 cmdline_parse_inst_t cmd_set_link_down = {
5752         .f = cmd_set_link_down_parsed,
5753         .data = NULL,
5754         .help_str = "set link-down port <port id>",
5755         .tokens = {
5756                 (void *)&cmd_set_link_down_set,
5757                 (void *)&cmd_set_link_down_link_down,
5758                 (void *)&cmd_set_link_down_port,
5759                 (void *)&cmd_set_link_down_port_id,
5760                 NULL,
5761         },
5762 };
5763
5764 /* *** SHOW CFG *** */
5765 struct cmd_showcfg_result {
5766         cmdline_fixed_string_t show;
5767         cmdline_fixed_string_t cfg;
5768         cmdline_fixed_string_t what;
5769 };
5770
5771 static void cmd_showcfg_parsed(void *parsed_result,
5772                                __attribute__((unused)) struct cmdline *cl,
5773                                __attribute__((unused)) void *data)
5774 {
5775         struct cmd_showcfg_result *res = parsed_result;
5776         if (!strcmp(res->what, "rxtx"))
5777                 rxtx_config_display();
5778         else if (!strcmp(res->what, "cores"))
5779                 fwd_lcores_config_display();
5780         else if (!strcmp(res->what, "fwd"))
5781                 pkt_fwd_config_display(&cur_fwd_config);
5782         else if (!strcmp(res->what, "txpkts"))
5783                 show_tx_pkt_segments();
5784 }
5785
5786 cmdline_parse_token_string_t cmd_showcfg_show =
5787         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5788 cmdline_parse_token_string_t cmd_showcfg_port =
5789         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5790 cmdline_parse_token_string_t cmd_showcfg_what =
5791         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5792                                  "rxtx#cores#fwd#txpkts");
5793
5794 cmdline_parse_inst_t cmd_showcfg = {
5795         .f = cmd_showcfg_parsed,
5796         .data = NULL,
5797         .help_str = "show config rxtx|cores|fwd|txpkts",
5798         .tokens = {
5799                 (void *)&cmd_showcfg_show,
5800                 (void *)&cmd_showcfg_port,
5801                 (void *)&cmd_showcfg_what,
5802                 NULL,
5803         },
5804 };
5805
5806 /* *** SHOW ALL PORT INFO *** */
5807 struct cmd_showportall_result {
5808         cmdline_fixed_string_t show;
5809         cmdline_fixed_string_t port;
5810         cmdline_fixed_string_t what;
5811         cmdline_fixed_string_t all;
5812 };
5813
5814 static void cmd_showportall_parsed(void *parsed_result,
5815                                 __attribute__((unused)) struct cmdline *cl,
5816                                 __attribute__((unused)) void *data)
5817 {
5818         portid_t i;
5819
5820         struct cmd_showportall_result *res = parsed_result;
5821         if (!strcmp(res->show, "clear")) {
5822                 if (!strcmp(res->what, "stats"))
5823                         FOREACH_PORT(i, ports)
5824                                 nic_stats_clear(i);
5825                 else if (!strcmp(res->what, "xstats"))
5826                         FOREACH_PORT(i, ports)
5827                                 nic_xstats_clear(i);
5828         } else if (!strcmp(res->what, "info"))
5829                 FOREACH_PORT(i, ports)
5830                         port_infos_display(i);
5831         else if (!strcmp(res->what, "stats"))
5832                 FOREACH_PORT(i, ports)
5833                         nic_stats_display(i);
5834         else if (!strcmp(res->what, "xstats"))
5835                 FOREACH_PORT(i, ports)
5836                         nic_xstats_display(i);
5837         else if (!strcmp(res->what, "fdir"))
5838                 FOREACH_PORT(i, ports)
5839                         fdir_get_infos(i);
5840         else if (!strcmp(res->what, "stat_qmap"))
5841                 FOREACH_PORT(i, ports)
5842                         nic_stats_mapping_display(i);
5843         else if (!strcmp(res->what, "dcb_tc"))
5844                 FOREACH_PORT(i, ports)
5845                         port_dcb_info_display(i);
5846         else if (!strcmp(res->what, "cap"))
5847                 FOREACH_PORT(i, ports)
5848                         port_offload_cap_display(i);
5849 }
5850
5851 cmdline_parse_token_string_t cmd_showportall_show =
5852         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5853                                  "show#clear");
5854 cmdline_parse_token_string_t cmd_showportall_port =
5855         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5856 cmdline_parse_token_string_t cmd_showportall_what =
5857         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5858                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
5859 cmdline_parse_token_string_t cmd_showportall_all =
5860         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5861 cmdline_parse_inst_t cmd_showportall = {
5862         .f = cmd_showportall_parsed,
5863         .data = NULL,
5864         .help_str = "show|clear port "
5865                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
5866         .tokens = {
5867                 (void *)&cmd_showportall_show,
5868                 (void *)&cmd_showportall_port,
5869                 (void *)&cmd_showportall_what,
5870                 (void *)&cmd_showportall_all,
5871                 NULL,
5872         },
5873 };
5874
5875 /* *** SHOW PORT INFO *** */
5876 struct cmd_showport_result {
5877         cmdline_fixed_string_t show;
5878         cmdline_fixed_string_t port;
5879         cmdline_fixed_string_t what;
5880         uint8_t portnum;
5881 };
5882
5883 static void cmd_showport_parsed(void *parsed_result,
5884                                 __attribute__((unused)) struct cmdline *cl,
5885                                 __attribute__((unused)) void *data)
5886 {
5887         struct cmd_showport_result *res = parsed_result;
5888         if (!strcmp(res->show, "clear")) {
5889                 if (!strcmp(res->what, "stats"))
5890                         nic_stats_clear(res->portnum);
5891                 else if (!strcmp(res->what, "xstats"))
5892                         nic_xstats_clear(res->portnum);
5893         } else if (!strcmp(res->what, "info"))
5894                 port_infos_display(res->portnum);
5895         else if (!strcmp(res->what, "stats"))
5896                 nic_stats_display(res->portnum);
5897         else if (!strcmp(res->what, "xstats"))
5898                 nic_xstats_display(res->portnum);
5899         else if (!strcmp(res->what, "fdir"))
5900                  fdir_get_infos(res->portnum);
5901         else if (!strcmp(res->what, "stat_qmap"))
5902                 nic_stats_mapping_display(res->portnum);
5903         else if (!strcmp(res->what, "dcb_tc"))
5904                 port_dcb_info_display(res->portnum);
5905         else if (!strcmp(res->what, "cap"))
5906                 port_offload_cap_display(res->portnum);
5907 }
5908
5909 cmdline_parse_token_string_t cmd_showport_show =
5910         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5911                                  "show#clear");
5912 cmdline_parse_token_string_t cmd_showport_port =
5913         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5914 cmdline_parse_token_string_t cmd_showport_what =
5915         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5916                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
5917 cmdline_parse_token_num_t cmd_showport_portnum =
5918         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5919
5920 cmdline_parse_inst_t cmd_showport = {
5921         .f = cmd_showport_parsed,
5922         .data = NULL,
5923         .help_str = "show|clear port "
5924                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
5925                 "<port_id>",
5926         .tokens = {
5927                 (void *)&cmd_showport_show,
5928                 (void *)&cmd_showport_port,
5929                 (void *)&cmd_showport_what,
5930                 (void *)&cmd_showport_portnum,
5931                 NULL,
5932         },
5933 };
5934
5935 /* *** SHOW QUEUE INFO *** */
5936 struct cmd_showqueue_result {
5937         cmdline_fixed_string_t show;
5938         cmdline_fixed_string_t type;
5939         cmdline_fixed_string_t what;
5940         uint8_t portnum;
5941         uint16_t queuenum;
5942 };
5943
5944 static void
5945 cmd_showqueue_parsed(void *parsed_result,
5946         __attribute__((unused)) struct cmdline *cl,
5947         __attribute__((unused)) void *data)
5948 {
5949         struct cmd_showqueue_result *res = parsed_result;
5950
5951         if (!strcmp(res->type, "rxq"))
5952                 rx_queue_infos_display(res->portnum, res->queuenum);
5953         else if (!strcmp(res->type, "txq"))
5954                 tx_queue_infos_display(res->portnum, res->queuenum);
5955 }
5956
5957 cmdline_parse_token_string_t cmd_showqueue_show =
5958         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5959 cmdline_parse_token_string_t cmd_showqueue_type =
5960         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5961 cmdline_parse_token_string_t cmd_showqueue_what =
5962         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5963 cmdline_parse_token_num_t cmd_showqueue_portnum =
5964         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5965 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5966         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5967
5968 cmdline_parse_inst_t cmd_showqueue = {
5969         .f = cmd_showqueue_parsed,
5970         .data = NULL,
5971         .help_str = "show rxq|txq info <port_id> <queue_id>",
5972         .tokens = {
5973                 (void *)&cmd_showqueue_show,
5974                 (void *)&cmd_showqueue_type,
5975                 (void *)&cmd_showqueue_what,
5976                 (void *)&cmd_showqueue_portnum,
5977                 (void *)&cmd_showqueue_queuenum,
5978                 NULL,
5979         },
5980 };
5981
5982 /* *** READ PORT REGISTER *** */
5983 struct cmd_read_reg_result {
5984         cmdline_fixed_string_t read;
5985         cmdline_fixed_string_t reg;
5986         uint8_t port_id;
5987         uint32_t reg_off;
5988 };
5989
5990 static void
5991 cmd_read_reg_parsed(void *parsed_result,
5992                     __attribute__((unused)) struct cmdline *cl,
5993                     __attribute__((unused)) void *data)
5994 {
5995         struct cmd_read_reg_result *res = parsed_result;
5996         port_reg_display(res->port_id, res->reg_off);
5997 }
5998
5999 cmdline_parse_token_string_t cmd_read_reg_read =
6000         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6001 cmdline_parse_token_string_t cmd_read_reg_reg =
6002         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6003 cmdline_parse_token_num_t cmd_read_reg_port_id =
6004         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6005 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6006         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6007
6008 cmdline_parse_inst_t cmd_read_reg = {
6009         .f = cmd_read_reg_parsed,
6010         .data = NULL,
6011         .help_str = "read reg <port_id> <reg_off>",
6012         .tokens = {
6013                 (void *)&cmd_read_reg_read,
6014                 (void *)&cmd_read_reg_reg,
6015                 (void *)&cmd_read_reg_port_id,
6016                 (void *)&cmd_read_reg_reg_off,
6017                 NULL,
6018         },
6019 };
6020
6021 /* *** READ PORT REGISTER BIT FIELD *** */
6022 struct cmd_read_reg_bit_field_result {
6023         cmdline_fixed_string_t read;
6024         cmdline_fixed_string_t regfield;
6025         uint8_t port_id;
6026         uint32_t reg_off;
6027         uint8_t bit1_pos;
6028         uint8_t bit2_pos;
6029 };
6030
6031 static void
6032 cmd_read_reg_bit_field_parsed(void *parsed_result,
6033                               __attribute__((unused)) struct cmdline *cl,
6034                               __attribute__((unused)) void *data)
6035 {
6036         struct cmd_read_reg_bit_field_result *res = parsed_result;
6037         port_reg_bit_field_display(res->port_id, res->reg_off,
6038                                    res->bit1_pos, res->bit2_pos);
6039 }
6040
6041 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6042         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6043                                  "read");
6044 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6045         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6046                                  regfield, "regfield");
6047 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6048         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6049                               UINT8);
6050 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6051         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6052                               UINT32);
6053 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6054         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6055                               UINT8);
6056 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6057         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6058                               UINT8);
6059
6060 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6061         .f = cmd_read_reg_bit_field_parsed,
6062         .data = NULL,
6063         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6064         "Read register bit field between bit_x and bit_y included",
6065         .tokens = {
6066                 (void *)&cmd_read_reg_bit_field_read,
6067                 (void *)&cmd_read_reg_bit_field_regfield,
6068                 (void *)&cmd_read_reg_bit_field_port_id,
6069                 (void *)&cmd_read_reg_bit_field_reg_off,
6070                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6071                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6072                 NULL,
6073         },
6074 };
6075
6076 /* *** READ PORT REGISTER BIT *** */
6077 struct cmd_read_reg_bit_result {
6078         cmdline_fixed_string_t read;
6079         cmdline_fixed_string_t regbit;
6080         uint8_t port_id;
6081         uint32_t reg_off;
6082         uint8_t bit_pos;
6083 };
6084
6085 static void
6086 cmd_read_reg_bit_parsed(void *parsed_result,
6087                         __attribute__((unused)) struct cmdline *cl,
6088                         __attribute__((unused)) void *data)
6089 {
6090         struct cmd_read_reg_bit_result *res = parsed_result;
6091         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6092 }
6093
6094 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6095         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6096 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6097         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6098                                  regbit, "regbit");
6099 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6100         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6101 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6102         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6103 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6104         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6105
6106 cmdline_parse_inst_t cmd_read_reg_bit = {
6107         .f = cmd_read_reg_bit_parsed,
6108         .data = NULL,
6109         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6110         .tokens = {
6111                 (void *)&cmd_read_reg_bit_read,
6112                 (void *)&cmd_read_reg_bit_regbit,
6113                 (void *)&cmd_read_reg_bit_port_id,
6114                 (void *)&cmd_read_reg_bit_reg_off,
6115                 (void *)&cmd_read_reg_bit_bit_pos,
6116                 NULL,
6117         },
6118 };
6119
6120 /* *** WRITE PORT REGISTER *** */
6121 struct cmd_write_reg_result {
6122         cmdline_fixed_string_t write;
6123         cmdline_fixed_string_t reg;
6124         uint8_t port_id;
6125         uint32_t reg_off;
6126         uint32_t value;
6127 };
6128
6129 static void
6130 cmd_write_reg_parsed(void *parsed_result,
6131                      __attribute__((unused)) struct cmdline *cl,
6132                      __attribute__((unused)) void *data)
6133 {
6134         struct cmd_write_reg_result *res = parsed_result;
6135         port_reg_set(res->port_id, res->reg_off, res->value);
6136 }
6137
6138 cmdline_parse_token_string_t cmd_write_reg_write =
6139         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6140 cmdline_parse_token_string_t cmd_write_reg_reg =
6141         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6142 cmdline_parse_token_num_t cmd_write_reg_port_id =
6143         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6144 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6145         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6146 cmdline_parse_token_num_t cmd_write_reg_value =
6147         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6148
6149 cmdline_parse_inst_t cmd_write_reg = {
6150         .f = cmd_write_reg_parsed,
6151         .data = NULL,
6152         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6153         .tokens = {
6154                 (void *)&cmd_write_reg_write,
6155                 (void *)&cmd_write_reg_reg,
6156                 (void *)&cmd_write_reg_port_id,
6157                 (void *)&cmd_write_reg_reg_off,
6158                 (void *)&cmd_write_reg_value,
6159                 NULL,
6160         },
6161 };
6162
6163 /* *** WRITE PORT REGISTER BIT FIELD *** */
6164 struct cmd_write_reg_bit_field_result {
6165         cmdline_fixed_string_t write;
6166         cmdline_fixed_string_t regfield;
6167         uint8_t port_id;
6168         uint32_t reg_off;
6169         uint8_t bit1_pos;
6170         uint8_t bit2_pos;
6171         uint32_t value;
6172 };
6173
6174 static void
6175 cmd_write_reg_bit_field_parsed(void *parsed_result,
6176                                __attribute__((unused)) struct cmdline *cl,
6177                                __attribute__((unused)) void *data)
6178 {
6179         struct cmd_write_reg_bit_field_result *res = parsed_result;
6180         port_reg_bit_field_set(res->port_id, res->reg_off,
6181                           res->bit1_pos, res->bit2_pos, res->value);
6182 }
6183
6184 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6185         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6186                                  "write");
6187 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6188         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6189                                  regfield, "regfield");
6190 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6191         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6192                               UINT8);
6193 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6194         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6195                               UINT32);
6196 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6197         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6198                               UINT8);
6199 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6200         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6201                               UINT8);
6202 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6203         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6204                               UINT32);
6205
6206 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6207         .f = cmd_write_reg_bit_field_parsed,
6208         .data = NULL,
6209         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6210                 "<reg_value>: "
6211                 "Set register bit field between bit_x and bit_y included",
6212         .tokens = {
6213                 (void *)&cmd_write_reg_bit_field_write,
6214                 (void *)&cmd_write_reg_bit_field_regfield,
6215                 (void *)&cmd_write_reg_bit_field_port_id,
6216                 (void *)&cmd_write_reg_bit_field_reg_off,
6217                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6218                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6219                 (void *)&cmd_write_reg_bit_field_value,
6220                 NULL,
6221         },
6222 };
6223
6224 /* *** WRITE PORT REGISTER BIT *** */
6225 struct cmd_write_reg_bit_result {
6226         cmdline_fixed_string_t write;
6227         cmdline_fixed_string_t regbit;
6228         uint8_t port_id;
6229         uint32_t reg_off;
6230         uint8_t bit_pos;
6231         uint8_t value;
6232 };
6233
6234 static void
6235 cmd_write_reg_bit_parsed(void *parsed_result,
6236                          __attribute__((unused)) struct cmdline *cl,
6237                          __attribute__((unused)) void *data)
6238 {
6239         struct cmd_write_reg_bit_result *res = parsed_result;
6240         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6241 }
6242
6243 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6244         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6245                                  "write");
6246 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6247         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6248                                  regbit, "regbit");
6249 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6250         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6251 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6252         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6253 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6254         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6255 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6256         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6257
6258 cmdline_parse_inst_t cmd_write_reg_bit = {
6259         .f = cmd_write_reg_bit_parsed,
6260         .data = NULL,
6261         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6262                 "0 <= bit_x <= 31",
6263         .tokens = {
6264                 (void *)&cmd_write_reg_bit_write,
6265                 (void *)&cmd_write_reg_bit_regbit,
6266                 (void *)&cmd_write_reg_bit_port_id,
6267                 (void *)&cmd_write_reg_bit_reg_off,
6268                 (void *)&cmd_write_reg_bit_bit_pos,
6269                 (void *)&cmd_write_reg_bit_value,
6270                 NULL,
6271         },
6272 };
6273
6274 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6275 struct cmd_read_rxd_txd_result {
6276         cmdline_fixed_string_t read;
6277         cmdline_fixed_string_t rxd_txd;
6278         uint8_t port_id;
6279         uint16_t queue_id;
6280         uint16_t desc_id;
6281 };
6282
6283 static void
6284 cmd_read_rxd_txd_parsed(void *parsed_result,
6285                         __attribute__((unused)) struct cmdline *cl,
6286                         __attribute__((unused)) void *data)
6287 {
6288         struct cmd_read_rxd_txd_result *res = parsed_result;
6289
6290         if (!strcmp(res->rxd_txd, "rxd"))
6291                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6292         else if (!strcmp(res->rxd_txd, "txd"))
6293                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6294 }
6295
6296 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6297         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6298 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6299         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6300                                  "rxd#txd");
6301 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6302         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6303 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6304         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6305 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6306         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6307
6308 cmdline_parse_inst_t cmd_read_rxd_txd = {
6309         .f = cmd_read_rxd_txd_parsed,
6310         .data = NULL,
6311         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6312         .tokens = {
6313                 (void *)&cmd_read_rxd_txd_read,
6314                 (void *)&cmd_read_rxd_txd_rxd_txd,
6315                 (void *)&cmd_read_rxd_txd_port_id,
6316                 (void *)&cmd_read_rxd_txd_queue_id,
6317                 (void *)&cmd_read_rxd_txd_desc_id,
6318                 NULL,
6319         },
6320 };
6321
6322 /* *** QUIT *** */
6323 struct cmd_quit_result {
6324         cmdline_fixed_string_t quit;
6325 };
6326
6327 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6328                             struct cmdline *cl,
6329                             __attribute__((unused)) void *data)
6330 {
6331         pmd_test_exit();
6332         cmdline_quit(cl);
6333 }
6334
6335 cmdline_parse_token_string_t cmd_quit_quit =
6336         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6337
6338 cmdline_parse_inst_t cmd_quit = {
6339         .f = cmd_quit_parsed,
6340         .data = NULL,
6341         .help_str = "quit: Exit application",
6342         .tokens = {
6343                 (void *)&cmd_quit_quit,
6344                 NULL,
6345         },
6346 };
6347
6348 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6349 struct cmd_mac_addr_result {
6350         cmdline_fixed_string_t mac_addr_cmd;
6351         cmdline_fixed_string_t what;
6352         uint8_t port_num;
6353         struct ether_addr address;
6354 };
6355
6356 static void cmd_mac_addr_parsed(void *parsed_result,
6357                 __attribute__((unused)) struct cmdline *cl,
6358                 __attribute__((unused)) void *data)
6359 {
6360         struct cmd_mac_addr_result *res = parsed_result;
6361         int ret;
6362
6363         if (strcmp(res->what, "add") == 0)
6364                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6365         else if (strcmp(res->what, "set") == 0)
6366                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6367                                                        &res->address);
6368         else
6369                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6370
6371         /* check the return value and print it if is < 0 */
6372         if(ret < 0)
6373                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6374
6375 }
6376
6377 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6378         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6379                                 "mac_addr");
6380 cmdline_parse_token_string_t cmd_mac_addr_what =
6381         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6382                                 "add#remove#set");
6383 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6384                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6385 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6386                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6387
6388 cmdline_parse_inst_t cmd_mac_addr = {
6389         .f = cmd_mac_addr_parsed,
6390         .data = (void *)0,
6391         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6392                         "Add/Remove/Set MAC address on port_id",
6393         .tokens = {
6394                 (void *)&cmd_mac_addr_cmd,
6395                 (void *)&cmd_mac_addr_what,
6396                 (void *)&cmd_mac_addr_portnum,
6397                 (void *)&cmd_mac_addr_addr,
6398                 NULL,
6399         },
6400 };
6401
6402
6403 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6404 struct cmd_set_qmap_result {
6405         cmdline_fixed_string_t set;
6406         cmdline_fixed_string_t qmap;
6407         cmdline_fixed_string_t what;
6408         uint8_t port_id;
6409         uint16_t queue_id;
6410         uint8_t map_value;
6411 };
6412
6413 static void
6414 cmd_set_qmap_parsed(void *parsed_result,
6415                        __attribute__((unused)) struct cmdline *cl,
6416                        __attribute__((unused)) void *data)
6417 {
6418         struct cmd_set_qmap_result *res = parsed_result;
6419         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6420
6421         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6422 }
6423
6424 cmdline_parse_token_string_t cmd_setqmap_set =
6425         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6426                                  set, "set");
6427 cmdline_parse_token_string_t cmd_setqmap_qmap =
6428         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6429                                  qmap, "stat_qmap");
6430 cmdline_parse_token_string_t cmd_setqmap_what =
6431         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6432                                  what, "tx#rx");
6433 cmdline_parse_token_num_t cmd_setqmap_portid =
6434         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6435                               port_id, UINT8);
6436 cmdline_parse_token_num_t cmd_setqmap_queueid =
6437         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6438                               queue_id, UINT16);
6439 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6440         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6441                               map_value, UINT8);
6442
6443 cmdline_parse_inst_t cmd_set_qmap = {
6444         .f = cmd_set_qmap_parsed,
6445         .data = NULL,
6446         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6447                 "Set statistics mapping value on tx|rx queue_id of port_id",
6448         .tokens = {
6449                 (void *)&cmd_setqmap_set,
6450                 (void *)&cmd_setqmap_qmap,
6451                 (void *)&cmd_setqmap_what,
6452                 (void *)&cmd_setqmap_portid,
6453                 (void *)&cmd_setqmap_queueid,
6454                 (void *)&cmd_setqmap_mapvalue,
6455                 NULL,
6456         },
6457 };
6458
6459 /* *** CONFIGURE UNICAST HASH TABLE *** */
6460 struct cmd_set_uc_hash_table {
6461         cmdline_fixed_string_t set;
6462         cmdline_fixed_string_t port;
6463         uint8_t port_id;
6464         cmdline_fixed_string_t what;
6465         struct ether_addr address;
6466         cmdline_fixed_string_t mode;
6467 };
6468
6469 static void
6470 cmd_set_uc_hash_parsed(void *parsed_result,
6471                        __attribute__((unused)) struct cmdline *cl,
6472                        __attribute__((unused)) void *data)
6473 {
6474         int ret=0;
6475         struct cmd_set_uc_hash_table *res = parsed_result;
6476
6477         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6478
6479         if (strcmp(res->what, "uta") == 0)
6480                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6481                                                 &res->address,(uint8_t)is_on);
6482         if (ret < 0)
6483                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6484
6485 }
6486
6487 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6488         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6489                                  set, "set");
6490 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6491         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6492                                  port, "port");
6493 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6494         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6495                               port_id, UINT8);
6496 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6497         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6498                                  what, "uta");
6499 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6500         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6501                                 address);
6502 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6503         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6504                                  mode, "on#off");
6505
6506 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6507         .f = cmd_set_uc_hash_parsed,
6508         .data = NULL,
6509         .help_str = "set port <port_id> uta <mac_addr> on|off)",
6510         .tokens = {
6511                 (void *)&cmd_set_uc_hash_set,
6512                 (void *)&cmd_set_uc_hash_port,
6513                 (void *)&cmd_set_uc_hash_portid,
6514                 (void *)&cmd_set_uc_hash_what,
6515                 (void *)&cmd_set_uc_hash_mac,
6516                 (void *)&cmd_set_uc_hash_mode,
6517                 NULL,
6518         },
6519 };
6520
6521 struct cmd_set_uc_all_hash_table {
6522         cmdline_fixed_string_t set;
6523         cmdline_fixed_string_t port;
6524         uint8_t port_id;
6525         cmdline_fixed_string_t what;
6526         cmdline_fixed_string_t value;
6527         cmdline_fixed_string_t mode;
6528 };
6529
6530 static void
6531 cmd_set_uc_all_hash_parsed(void *parsed_result,
6532                        __attribute__((unused)) struct cmdline *cl,
6533                        __attribute__((unused)) void *data)
6534 {
6535         int ret=0;
6536         struct cmd_set_uc_all_hash_table *res = parsed_result;
6537
6538         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6539
6540         if ((strcmp(res->what, "uta") == 0) &&
6541                 (strcmp(res->value, "all") == 0))
6542                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6543         if (ret < 0)
6544                 printf("bad unicast hash table parameter,"
6545                         "return code = %d \n", ret);
6546 }
6547
6548 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6549         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6550                                  set, "set");
6551 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6553                                  port, "port");
6554 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6555         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6556                               port_id, UINT8);
6557 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6558         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6559                                  what, "uta");
6560 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6561         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6562                                 value,"all");
6563 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6564         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6565                                  mode, "on#off");
6566
6567 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6568         .f = cmd_set_uc_all_hash_parsed,
6569         .data = NULL,
6570         .help_str = "set port <port_id> uta all on|off",
6571         .tokens = {
6572                 (void *)&cmd_set_uc_all_hash_set,
6573                 (void *)&cmd_set_uc_all_hash_port,
6574                 (void *)&cmd_set_uc_all_hash_portid,
6575                 (void *)&cmd_set_uc_all_hash_what,
6576                 (void *)&cmd_set_uc_all_hash_value,
6577                 (void *)&cmd_set_uc_all_hash_mode,
6578                 NULL,
6579         },
6580 };
6581
6582 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6583 struct cmd_set_vf_macvlan_filter {
6584         cmdline_fixed_string_t set;
6585         cmdline_fixed_string_t port;
6586         uint8_t port_id;
6587         cmdline_fixed_string_t vf;
6588         uint8_t vf_id;
6589         struct ether_addr address;
6590         cmdline_fixed_string_t filter_type;
6591         cmdline_fixed_string_t mode;
6592 };
6593
6594 static void
6595 cmd_set_vf_macvlan_parsed(void *parsed_result,
6596                        __attribute__((unused)) struct cmdline *cl,
6597                        __attribute__((unused)) void *data)
6598 {
6599         int is_on, ret = 0;
6600         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6601         struct rte_eth_mac_filter filter;
6602
6603         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6604
6605         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6606
6607         /* set VF MAC filter */
6608         filter.is_vf = 1;
6609
6610         /* set VF ID */
6611         filter.dst_id = res->vf_id;
6612
6613         if (!strcmp(res->filter_type, "exact-mac"))
6614                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6615         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6616                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6617         else if (!strcmp(res->filter_type, "hashmac"))
6618                 filter.filter_type = RTE_MAC_HASH_MATCH;
6619         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6620                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6621
6622         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6623
6624         if (is_on)
6625                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6626                                         RTE_ETH_FILTER_MACVLAN,
6627                                         RTE_ETH_FILTER_ADD,
6628                                          &filter);
6629         else
6630                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6631                                         RTE_ETH_FILTER_MACVLAN,
6632                                         RTE_ETH_FILTER_DELETE,
6633                                         &filter);
6634
6635         if (ret < 0)
6636                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6637
6638 }
6639
6640 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6641         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6642                                  set, "set");
6643 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6644         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6645                                  port, "port");
6646 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6647         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6648                               port_id, UINT8);
6649 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6650         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6651                                  vf, "vf");
6652 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6653         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6654                                 vf_id, UINT8);
6655 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6656         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6657                                 address);
6658 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6659         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6660                                 filter_type, "exact-mac#exact-mac-vlan"
6661                                 "#hashmac#hashmac-vlan");
6662 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6663         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6664                                  mode, "on#off");
6665
6666 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6667         .f = cmd_set_vf_macvlan_parsed,
6668         .data = NULL,
6669         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
6670                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
6671                 "Exact match rule: exact match of MAC or MAC and VLAN; "
6672                 "hash match rule: hash match of MAC and exact match of VLAN",
6673         .tokens = {
6674                 (void *)&cmd_set_vf_macvlan_set,
6675                 (void *)&cmd_set_vf_macvlan_port,
6676                 (void *)&cmd_set_vf_macvlan_portid,
6677                 (void *)&cmd_set_vf_macvlan_vf,
6678                 (void *)&cmd_set_vf_macvlan_vf_id,
6679                 (void *)&cmd_set_vf_macvlan_mac,
6680                 (void *)&cmd_set_vf_macvlan_filter_type,
6681                 (void *)&cmd_set_vf_macvlan_mode,
6682                 NULL,
6683         },
6684 };
6685
6686 #ifdef RTE_LIBRTE_IXGBE_PMD
6687 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6688 struct cmd_set_vf_traffic {
6689         cmdline_fixed_string_t set;
6690         cmdline_fixed_string_t port;
6691         uint8_t port_id;
6692         cmdline_fixed_string_t vf;
6693         uint8_t vf_id;
6694         cmdline_fixed_string_t what;
6695         cmdline_fixed_string_t mode;
6696 };
6697
6698 static void
6699 cmd_set_vf_traffic_parsed(void *parsed_result,
6700                        __attribute__((unused)) struct cmdline *cl,
6701                        __attribute__((unused)) void *data)
6702 {
6703         struct cmd_set_vf_traffic *res = parsed_result;
6704         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6705         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6706
6707         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6708 }
6709
6710 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6711         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6712                                  set, "set");
6713 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6714         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6715                                  port, "port");
6716 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6717         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6718                               port_id, UINT8);
6719 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6720         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6721                                  vf, "vf");
6722 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6723         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6724                               vf_id, UINT8);
6725 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6726         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6727                                  what, "tx#rx");
6728 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6729         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6730                                  mode, "on#off");
6731
6732 cmdline_parse_inst_t cmd_set_vf_traffic = {
6733         .f = cmd_set_vf_traffic_parsed,
6734         .data = NULL,
6735         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
6736         .tokens = {
6737                 (void *)&cmd_setvf_traffic_set,
6738                 (void *)&cmd_setvf_traffic_port,
6739                 (void *)&cmd_setvf_traffic_portid,
6740                 (void *)&cmd_setvf_traffic_vf,
6741                 (void *)&cmd_setvf_traffic_vfid,
6742                 (void *)&cmd_setvf_traffic_what,
6743                 (void *)&cmd_setvf_traffic_mode,
6744                 NULL,
6745         },
6746 };
6747
6748 /* *** CONFIGURE VF RECEIVE MODE *** */
6749 struct cmd_set_vf_rxmode {
6750         cmdline_fixed_string_t set;
6751         cmdline_fixed_string_t port;
6752         uint8_t port_id;
6753         cmdline_fixed_string_t vf;
6754         uint8_t vf_id;
6755         cmdline_fixed_string_t what;
6756         cmdline_fixed_string_t mode;
6757         cmdline_fixed_string_t on;
6758 };
6759
6760 static void
6761 cmd_set_vf_rxmode_parsed(void *parsed_result,
6762                        __attribute__((unused)) struct cmdline *cl,
6763                        __attribute__((unused)) void *data)
6764 {
6765         int ret;
6766         uint16_t rx_mode = 0;
6767         struct cmd_set_vf_rxmode *res = parsed_result;
6768
6769         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6770         if (!strcmp(res->what,"rxmode")) {
6771                 if (!strcmp(res->mode, "AUPE"))
6772                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6773                 else if (!strcmp(res->mode, "ROPE"))
6774                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6775                 else if (!strcmp(res->mode, "BAM"))
6776                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6777                 else if (!strncmp(res->mode, "MPE",3))
6778                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6779         }
6780
6781         ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, rx_mode, (uint8_t)is_on);
6782         if (ret < 0)
6783                 printf("bad VF receive mode parameter, return code = %d \n",
6784                 ret);
6785 }
6786
6787 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6788         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6789                                  set, "set");
6790 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6791         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6792                                  port, "port");
6793 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6794         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6795                               port_id, UINT8);
6796 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6797         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6798                                  vf, "vf");
6799 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6800         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6801                               vf_id, UINT8);
6802 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6803         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6804                                  what, "rxmode");
6805 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6806         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6807                                  mode, "AUPE#ROPE#BAM#MPE");
6808 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6809         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6810                                  on, "on#off");
6811
6812 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6813         .f = cmd_set_vf_rxmode_parsed,
6814         .data = NULL,
6815         .help_str = "set port <port_id> vf <vf_id> rxmode "
6816                 "AUPE|ROPE|BAM|MPE on|off",
6817         .tokens = {
6818                 (void *)&cmd_set_vf_rxmode_set,
6819                 (void *)&cmd_set_vf_rxmode_port,
6820                 (void *)&cmd_set_vf_rxmode_portid,
6821                 (void *)&cmd_set_vf_rxmode_vf,
6822                 (void *)&cmd_set_vf_rxmode_vfid,
6823                 (void *)&cmd_set_vf_rxmode_what,
6824                 (void *)&cmd_set_vf_rxmode_mode,
6825                 (void *)&cmd_set_vf_rxmode_on,
6826                 NULL,
6827         },
6828 };
6829 #endif
6830
6831 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6832 struct cmd_vf_mac_addr_result {
6833         cmdline_fixed_string_t mac_addr_cmd;
6834         cmdline_fixed_string_t what;
6835         cmdline_fixed_string_t port;
6836         uint8_t port_num;
6837         cmdline_fixed_string_t vf;
6838         uint8_t vf_num;
6839         struct ether_addr address;
6840 };
6841
6842 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6843                 __attribute__((unused)) struct cmdline *cl,
6844                 __attribute__((unused)) void *data)
6845 {
6846         struct cmd_vf_mac_addr_result *res = parsed_result;
6847         int ret = 0;
6848
6849         if (strcmp(res->what, "add") == 0)
6850                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6851                                         &res->address, res->vf_num);
6852         if(ret < 0)
6853                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6854
6855 }
6856
6857 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6858         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6859                                 mac_addr_cmd,"mac_addr");
6860 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6861         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6862                                 what,"add");
6863 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6864         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6865                                 port,"port");
6866 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6867         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6868                                 port_num, UINT8);
6869 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6870         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6871                                 vf,"vf");
6872 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6873         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6874                                 vf_num, UINT8);
6875 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6876         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6877                                 address);
6878
6879 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6880         .f = cmd_vf_mac_addr_parsed,
6881         .data = (void *)0,
6882         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
6883                 "Add MAC address filtering for a VF on port_id",
6884         .tokens = {
6885                 (void *)&cmd_vf_mac_addr_cmd,
6886                 (void *)&cmd_vf_mac_addr_what,
6887                 (void *)&cmd_vf_mac_addr_port,
6888                 (void *)&cmd_vf_mac_addr_portnum,
6889                 (void *)&cmd_vf_mac_addr_vf,
6890                 (void *)&cmd_vf_mac_addr_vfnum,
6891                 (void *)&cmd_vf_mac_addr_addr,
6892                 NULL,
6893         },
6894 };
6895
6896 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6897 struct cmd_vf_rx_vlan_filter {
6898         cmdline_fixed_string_t rx_vlan;
6899         cmdline_fixed_string_t what;
6900         uint16_t vlan_id;
6901         cmdline_fixed_string_t port;
6902         uint8_t port_id;
6903         cmdline_fixed_string_t vf;
6904         uint64_t vf_mask;
6905 };
6906
6907 static void
6908 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6909                           __attribute__((unused)) struct cmdline *cl,
6910                           __attribute__((unused)) void *data)
6911 {
6912         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6913         int ret = -ENOTSUP;
6914
6915         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
6916
6917 #ifdef RTE_LIBRTE_IXGBE_PMD
6918         if (ret == -ENOTSUP)
6919                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
6920                                 res->vlan_id, res->vf_mask, is_add);
6921 #endif
6922 #ifdef RTE_LIBRTE_I40E_PMD
6923         if (ret == -ENOTSUP)
6924                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
6925                                 res->vlan_id, res->vf_mask, is_add);
6926 #endif
6927
6928         switch (ret) {
6929         case 0:
6930                 break;
6931         case -EINVAL:
6932                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
6933                                 res->vlan_id, res->vf_mask);
6934                 break;
6935         case -ENODEV:
6936                 printf("invalid port_id %d\n", res->port_id);
6937                 break;
6938         case -ENOTSUP:
6939                 printf("function not implemented or supported\n");
6940                 break;
6941         default:
6942                 printf("programming error: (%s)\n", strerror(-ret));
6943         }
6944 }
6945
6946 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6947         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6948                                  rx_vlan, "rx_vlan");
6949 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6950         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6951                                  what, "add#rm");
6952 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6953         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6954                               vlan_id, UINT16);
6955 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6956         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6957                                  port, "port");
6958 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6959         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6960                               port_id, UINT8);
6961 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6962         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6963                                  vf, "vf");
6964 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6965         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6966                               vf_mask, UINT64);
6967
6968 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6969         .f = cmd_vf_rx_vlan_filter_parsed,
6970         .data = NULL,
6971         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
6972                 "(vf_mask = hexadecimal VF mask)",
6973         .tokens = {
6974                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6975                 (void *)&cmd_vf_rx_vlan_filter_what,
6976                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6977                 (void *)&cmd_vf_rx_vlan_filter_port,
6978                 (void *)&cmd_vf_rx_vlan_filter_portid,
6979                 (void *)&cmd_vf_rx_vlan_filter_vf,
6980                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6981                 NULL,
6982         },
6983 };
6984
6985 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6986 struct cmd_queue_rate_limit_result {
6987         cmdline_fixed_string_t set;
6988         cmdline_fixed_string_t port;
6989         uint8_t port_num;
6990         cmdline_fixed_string_t queue;
6991         uint8_t queue_num;
6992         cmdline_fixed_string_t rate;
6993         uint16_t rate_num;
6994 };
6995
6996 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6997                 __attribute__((unused)) struct cmdline *cl,
6998                 __attribute__((unused)) void *data)
6999 {
7000         struct cmd_queue_rate_limit_result *res = parsed_result;
7001         int ret = 0;
7002
7003         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7004                 && (strcmp(res->queue, "queue") == 0)
7005                 && (strcmp(res->rate, "rate") == 0))
7006                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7007                                         res->rate_num);
7008         if (ret < 0)
7009                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7010
7011 }
7012
7013 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7014         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7015                                 set, "set");
7016 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7017         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7018                                 port, "port");
7019 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7020         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7021                                 port_num, UINT8);
7022 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7023         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7024                                 queue, "queue");
7025 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7026         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7027                                 queue_num, UINT8);
7028 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7029         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7030                                 rate, "rate");
7031 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7032         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7033                                 rate_num, UINT16);
7034
7035 cmdline_parse_inst_t cmd_queue_rate_limit = {
7036         .f = cmd_queue_rate_limit_parsed,
7037         .data = (void *)0,
7038         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7039                 "Set rate limit for a queue on port_id",
7040         .tokens = {
7041                 (void *)&cmd_queue_rate_limit_set,
7042                 (void *)&cmd_queue_rate_limit_port,
7043                 (void *)&cmd_queue_rate_limit_portnum,
7044                 (void *)&cmd_queue_rate_limit_queue,
7045                 (void *)&cmd_queue_rate_limit_queuenum,
7046                 (void *)&cmd_queue_rate_limit_rate,
7047                 (void *)&cmd_queue_rate_limit_ratenum,
7048                 NULL,
7049         },
7050 };
7051
7052 #ifdef RTE_LIBRTE_IXGBE_PMD
7053 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7054 struct cmd_vf_rate_limit_result {
7055         cmdline_fixed_string_t set;
7056         cmdline_fixed_string_t port;
7057         uint8_t port_num;
7058         cmdline_fixed_string_t vf;
7059         uint8_t vf_num;
7060         cmdline_fixed_string_t rate;
7061         uint16_t rate_num;
7062         cmdline_fixed_string_t q_msk;
7063         uint64_t q_msk_val;
7064 };
7065
7066 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7067                 __attribute__((unused)) struct cmdline *cl,
7068                 __attribute__((unused)) void *data)
7069 {
7070         struct cmd_vf_rate_limit_result *res = parsed_result;
7071         int ret = 0;
7072
7073         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7074                 && (strcmp(res->vf, "vf") == 0)
7075                 && (strcmp(res->rate, "rate") == 0)
7076                 && (strcmp(res->q_msk, "queue_mask") == 0))
7077                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7078                                         res->rate_num, res->q_msk_val);
7079         if (ret < 0)
7080                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7081
7082 }
7083
7084 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7085         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7086                                 set, "set");
7087 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7088         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7089                                 port, "port");
7090 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7091         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7092                                 port_num, UINT8);
7093 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7094         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7095                                 vf, "vf");
7096 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7097         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7098                                 vf_num, UINT8);
7099 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7100         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7101                                 rate, "rate");
7102 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7103         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7104                                 rate_num, UINT16);
7105 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7106         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7107                                 q_msk, "queue_mask");
7108 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7109         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7110                                 q_msk_val, UINT64);
7111
7112 cmdline_parse_inst_t cmd_vf_rate_limit = {
7113         .f = cmd_vf_rate_limit_parsed,
7114         .data = (void *)0,
7115         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7116                 "queue_mask <queue_mask_value>: "
7117                 "Set rate limit for queues of VF on port_id",
7118         .tokens = {
7119                 (void *)&cmd_vf_rate_limit_set,
7120                 (void *)&cmd_vf_rate_limit_port,
7121                 (void *)&cmd_vf_rate_limit_portnum,
7122                 (void *)&cmd_vf_rate_limit_vf,
7123                 (void *)&cmd_vf_rate_limit_vfnum,
7124                 (void *)&cmd_vf_rate_limit_rate,
7125                 (void *)&cmd_vf_rate_limit_ratenum,
7126                 (void *)&cmd_vf_rate_limit_q_msk,
7127                 (void *)&cmd_vf_rate_limit_q_msk_val,
7128                 NULL,
7129         },
7130 };
7131 #endif
7132
7133 /* *** ADD TUNNEL FILTER OF A PORT *** */
7134 struct cmd_tunnel_filter_result {
7135         cmdline_fixed_string_t cmd;
7136         cmdline_fixed_string_t what;
7137         uint8_t port_id;
7138         struct ether_addr outer_mac;
7139         struct ether_addr inner_mac;
7140         cmdline_ipaddr_t ip_value;
7141         uint16_t inner_vlan;
7142         cmdline_fixed_string_t tunnel_type;
7143         cmdline_fixed_string_t filter_type;
7144         uint32_t tenant_id;
7145         uint16_t queue_num;
7146 };
7147
7148 static void
7149 cmd_tunnel_filter_parsed(void *parsed_result,
7150                           __attribute__((unused)) struct cmdline *cl,
7151                           __attribute__((unused)) void *data)
7152 {
7153         struct cmd_tunnel_filter_result *res = parsed_result;
7154         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7155         int ret = 0;
7156
7157         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7158
7159         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7160         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7161         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7162
7163         if (res->ip_value.family == AF_INET) {
7164                 tunnel_filter_conf.ip_addr.ipv4_addr =
7165                         res->ip_value.addr.ipv4.s_addr;
7166                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7167         } else {
7168                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7169                         &(res->ip_value.addr.ipv6),
7170                         sizeof(struct in6_addr));
7171                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7172         }
7173
7174         if (!strcmp(res->filter_type, "imac-ivlan"))
7175                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7176         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7177                 tunnel_filter_conf.filter_type =
7178                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7179         else if (!strcmp(res->filter_type, "imac-tenid"))
7180                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7181         else if (!strcmp(res->filter_type, "imac"))
7182                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7183         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7184                 tunnel_filter_conf.filter_type =
7185                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7186         else if (!strcmp(res->filter_type, "oip"))
7187                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7188         else if (!strcmp(res->filter_type, "iip"))
7189                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7190         else {
7191                 printf("The filter type is not supported");
7192                 return;
7193         }
7194
7195         if (!strcmp(res->tunnel_type, "vxlan"))
7196                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7197         else if (!strcmp(res->tunnel_type, "nvgre"))
7198                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7199         else if (!strcmp(res->tunnel_type, "ipingre"))
7200                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7201         else {
7202                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7203                 return;
7204         }
7205
7206         tunnel_filter_conf.tenant_id = res->tenant_id;
7207         tunnel_filter_conf.queue_id = res->queue_num;
7208         if (!strcmp(res->what, "add"))
7209                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7210                                         RTE_ETH_FILTER_TUNNEL,
7211                                         RTE_ETH_FILTER_ADD,
7212                                         &tunnel_filter_conf);
7213         else
7214                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7215                                         RTE_ETH_FILTER_TUNNEL,
7216                                         RTE_ETH_FILTER_DELETE,
7217                                         &tunnel_filter_conf);
7218         if (ret < 0)
7219                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7220                                 strerror(-ret));
7221
7222 }
7223 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7224         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7225         cmd, "tunnel_filter");
7226 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7227         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7228         what, "add#rm");
7229 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7230         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7231         port_id, UINT8);
7232 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7233         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7234         outer_mac);
7235 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7236         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7237         inner_mac);
7238 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7239         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7240         inner_vlan, UINT16);
7241 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7242         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7243         ip_value);
7244 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7245         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7246         tunnel_type, "vxlan#nvgre#ipingre");
7247
7248 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7249         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7250         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7251                 "imac#omac-imac-tenid");
7252 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7253         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7254         tenant_id, UINT32);
7255 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7256         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7257         queue_num, UINT16);
7258
7259 cmdline_parse_inst_t cmd_tunnel_filter = {
7260         .f = cmd_tunnel_filter_parsed,
7261         .data = (void *)0,
7262         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7263                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7264                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7265                 "<queue_id>: Add/Rm tunnel filter of a port",
7266         .tokens = {
7267                 (void *)&cmd_tunnel_filter_cmd,
7268                 (void *)&cmd_tunnel_filter_what,
7269                 (void *)&cmd_tunnel_filter_port_id,
7270                 (void *)&cmd_tunnel_filter_outer_mac,
7271                 (void *)&cmd_tunnel_filter_inner_mac,
7272                 (void *)&cmd_tunnel_filter_ip_value,
7273                 (void *)&cmd_tunnel_filter_innner_vlan,
7274                 (void *)&cmd_tunnel_filter_tunnel_type,
7275                 (void *)&cmd_tunnel_filter_filter_type,
7276                 (void *)&cmd_tunnel_filter_tenant_id,
7277                 (void *)&cmd_tunnel_filter_queue_num,
7278                 NULL,
7279         },
7280 };
7281
7282 /* *** CONFIGURE TUNNEL UDP PORT *** */
7283 struct cmd_tunnel_udp_config {
7284         cmdline_fixed_string_t cmd;
7285         cmdline_fixed_string_t what;
7286         uint16_t udp_port;
7287         uint8_t port_id;
7288 };
7289
7290 static void
7291 cmd_tunnel_udp_config_parsed(void *parsed_result,
7292                           __attribute__((unused)) struct cmdline *cl,
7293                           __attribute__((unused)) void *data)
7294 {
7295         struct cmd_tunnel_udp_config *res = parsed_result;
7296         struct rte_eth_udp_tunnel tunnel_udp;
7297         int ret;
7298
7299         tunnel_udp.udp_port = res->udp_port;
7300
7301         if (!strcmp(res->cmd, "rx_vxlan_port"))
7302                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7303
7304         if (!strcmp(res->what, "add"))
7305                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7306                                                       &tunnel_udp);
7307         else
7308                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7309                                                          &tunnel_udp);
7310
7311         if (ret < 0)
7312                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7313 }
7314
7315 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7316         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7317                                 cmd, "rx_vxlan_port");
7318 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7319         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7320                                 what, "add#rm");
7321 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7322         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7323                                 udp_port, UINT16);
7324 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7325         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7326                                 port_id, UINT8);
7327
7328 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7329         .f = cmd_tunnel_udp_config_parsed,
7330         .data = (void *)0,
7331         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7332                 "Add/Remove a tunneling UDP port filter",
7333         .tokens = {
7334                 (void *)&cmd_tunnel_udp_config_cmd,
7335                 (void *)&cmd_tunnel_udp_config_what,
7336                 (void *)&cmd_tunnel_udp_config_udp_port,
7337                 (void *)&cmd_tunnel_udp_config_port_id,
7338                 NULL,
7339         },
7340 };
7341
7342 /* *** GLOBAL CONFIG *** */
7343 struct cmd_global_config_result {
7344         cmdline_fixed_string_t cmd;
7345         uint8_t port_id;
7346         cmdline_fixed_string_t cfg_type;
7347         uint8_t len;
7348 };
7349
7350 static void
7351 cmd_global_config_parsed(void *parsed_result,
7352                          __attribute__((unused)) struct cmdline *cl,
7353                          __attribute__((unused)) void *data)
7354 {
7355         struct cmd_global_config_result *res = parsed_result;
7356         struct rte_eth_global_cfg conf;
7357         int ret;
7358
7359         memset(&conf, 0, sizeof(conf));
7360         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7361         conf.cfg.gre_key_len = res->len;
7362         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7363                                       RTE_ETH_FILTER_SET, &conf);
7364         if (ret != 0)
7365                 printf("Global config error\n");
7366 }
7367
7368 cmdline_parse_token_string_t cmd_global_config_cmd =
7369         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7370                 "global_config");
7371 cmdline_parse_token_num_t cmd_global_config_port_id =
7372         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7373 cmdline_parse_token_string_t cmd_global_config_type =
7374         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7375                 cfg_type, "gre-key-len");
7376 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7377         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7378                 len, UINT8);
7379
7380 cmdline_parse_inst_t cmd_global_config = {
7381         .f = cmd_global_config_parsed,
7382         .data = (void *)NULL,
7383         .help_str = "global_config <port_id> gre-key-len <key_len>",
7384         .tokens = {
7385                 (void *)&cmd_global_config_cmd,
7386                 (void *)&cmd_global_config_port_id,
7387                 (void *)&cmd_global_config_type,
7388                 (void *)&cmd_global_config_gre_key_len,
7389                 NULL,
7390         },
7391 };
7392
7393 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7394 struct cmd_set_mirror_mask_result {
7395         cmdline_fixed_string_t set;
7396         cmdline_fixed_string_t port;
7397         uint8_t port_id;
7398         cmdline_fixed_string_t mirror;
7399         uint8_t rule_id;
7400         cmdline_fixed_string_t what;
7401         cmdline_fixed_string_t value;
7402         cmdline_fixed_string_t dstpool;
7403         uint8_t dstpool_id;
7404         cmdline_fixed_string_t on;
7405 };
7406
7407 cmdline_parse_token_string_t cmd_mirror_mask_set =
7408         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7409                                 set, "set");
7410 cmdline_parse_token_string_t cmd_mirror_mask_port =
7411         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7412                                 port, "port");
7413 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7414         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7415                                 port_id, UINT8);
7416 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7417         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7418                                 mirror, "mirror-rule");
7419 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7420         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7421                                 rule_id, UINT8);
7422 cmdline_parse_token_string_t cmd_mirror_mask_what =
7423         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7424                                 what, "pool-mirror-up#pool-mirror-down"
7425                                       "#vlan-mirror");
7426 cmdline_parse_token_string_t cmd_mirror_mask_value =
7427         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7428                                 value, NULL);
7429 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7431                                 dstpool, "dst-pool");
7432 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7433         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7434                                 dstpool_id, UINT8);
7435 cmdline_parse_token_string_t cmd_mirror_mask_on =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7437                                 on, "on#off");
7438
7439 static void
7440 cmd_set_mirror_mask_parsed(void *parsed_result,
7441                        __attribute__((unused)) struct cmdline *cl,
7442                        __attribute__((unused)) void *data)
7443 {
7444         int ret,nb_item,i;
7445         struct cmd_set_mirror_mask_result *res = parsed_result;
7446         struct rte_eth_mirror_conf mr_conf;
7447
7448         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7449
7450         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7451
7452         mr_conf.dst_pool = res->dstpool_id;
7453
7454         if (!strcmp(res->what, "pool-mirror-up")) {
7455                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7456                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7457         } else if (!strcmp(res->what, "pool-mirror-down")) {
7458                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7459                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7460         } else if (!strcmp(res->what, "vlan-mirror")) {
7461                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7462                 nb_item = parse_item_list(res->value, "vlan",
7463                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7464                 if (nb_item <= 0)
7465                         return;
7466
7467                 for (i = 0; i < nb_item; i++) {
7468                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7469                                 printf("Invalid vlan_id: must be < 4096\n");
7470                                 return;
7471                         }
7472
7473                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7474                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7475                 }
7476         }
7477
7478         if (!strcmp(res->on, "on"))
7479                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7480                                                 res->rule_id, 1);
7481         else
7482                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7483                                                 res->rule_id, 0);
7484         if (ret < 0)
7485                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7486 }
7487
7488 cmdline_parse_inst_t cmd_set_mirror_mask = {
7489                 .f = cmd_set_mirror_mask_parsed,
7490                 .data = NULL,
7491                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7492                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7493                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7494                 .tokens = {
7495                         (void *)&cmd_mirror_mask_set,
7496                         (void *)&cmd_mirror_mask_port,
7497                         (void *)&cmd_mirror_mask_portid,
7498                         (void *)&cmd_mirror_mask_mirror,
7499                         (void *)&cmd_mirror_mask_ruleid,
7500                         (void *)&cmd_mirror_mask_what,
7501                         (void *)&cmd_mirror_mask_value,
7502                         (void *)&cmd_mirror_mask_dstpool,
7503                         (void *)&cmd_mirror_mask_poolid,
7504                         (void *)&cmd_mirror_mask_on,
7505                         NULL,
7506                 },
7507 };
7508
7509 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7510 struct cmd_set_mirror_link_result {
7511         cmdline_fixed_string_t set;
7512         cmdline_fixed_string_t port;
7513         uint8_t port_id;
7514         cmdline_fixed_string_t mirror;
7515         uint8_t rule_id;
7516         cmdline_fixed_string_t what;
7517         cmdline_fixed_string_t dstpool;
7518         uint8_t dstpool_id;
7519         cmdline_fixed_string_t on;
7520 };
7521
7522 cmdline_parse_token_string_t cmd_mirror_link_set =
7523         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7524                                  set, "set");
7525 cmdline_parse_token_string_t cmd_mirror_link_port =
7526         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7527                                 port, "port");
7528 cmdline_parse_token_num_t cmd_mirror_link_portid =
7529         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7530                                 port_id, UINT8);
7531 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7532         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7533                                 mirror, "mirror-rule");
7534 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7535         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7536                             rule_id, UINT8);
7537 cmdline_parse_token_string_t cmd_mirror_link_what =
7538         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7539                                 what, "uplink-mirror#downlink-mirror");
7540 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7541         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7542                                 dstpool, "dst-pool");
7543 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7544         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7545                                 dstpool_id, UINT8);
7546 cmdline_parse_token_string_t cmd_mirror_link_on =
7547         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7548                                 on, "on#off");
7549
7550 static void
7551 cmd_set_mirror_link_parsed(void *parsed_result,
7552                        __attribute__((unused)) struct cmdline *cl,
7553                        __attribute__((unused)) void *data)
7554 {
7555         int ret;
7556         struct cmd_set_mirror_link_result *res = parsed_result;
7557         struct rte_eth_mirror_conf mr_conf;
7558
7559         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7560         if (!strcmp(res->what, "uplink-mirror"))
7561                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7562         else
7563                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7564
7565         mr_conf.dst_pool = res->dstpool_id;
7566
7567         if (!strcmp(res->on, "on"))
7568                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7569                                                 res->rule_id, 1);
7570         else
7571                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7572                                                 res->rule_id, 0);
7573
7574         /* check the return value and print it if is < 0 */
7575         if (ret < 0)
7576                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7577
7578 }
7579
7580 cmdline_parse_inst_t cmd_set_mirror_link = {
7581                 .f = cmd_set_mirror_link_parsed,
7582                 .data = NULL,
7583                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7584                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7585                 .tokens = {
7586                         (void *)&cmd_mirror_link_set,
7587                         (void *)&cmd_mirror_link_port,
7588                         (void *)&cmd_mirror_link_portid,
7589                         (void *)&cmd_mirror_link_mirror,
7590                         (void *)&cmd_mirror_link_ruleid,
7591                         (void *)&cmd_mirror_link_what,
7592                         (void *)&cmd_mirror_link_dstpool,
7593                         (void *)&cmd_mirror_link_poolid,
7594                         (void *)&cmd_mirror_link_on,
7595                         NULL,
7596                 },
7597 };
7598
7599 /* *** RESET VM MIRROR RULE *** */
7600 struct cmd_rm_mirror_rule_result {
7601         cmdline_fixed_string_t reset;
7602         cmdline_fixed_string_t port;
7603         uint8_t port_id;
7604         cmdline_fixed_string_t mirror;
7605         uint8_t rule_id;
7606 };
7607
7608 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7609         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7610                                  reset, "reset");
7611 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7612         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7613                                 port, "port");
7614 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7615         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7616                                 port_id, UINT8);
7617 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7618         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7619                                 mirror, "mirror-rule");
7620 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7621         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7622                                 rule_id, UINT8);
7623
7624 static void
7625 cmd_reset_mirror_rule_parsed(void *parsed_result,
7626                        __attribute__((unused)) struct cmdline *cl,
7627                        __attribute__((unused)) void *data)
7628 {
7629         int ret;
7630         struct cmd_set_mirror_link_result *res = parsed_result;
7631         /* check rule_id */
7632         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7633         if(ret < 0)
7634                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7635 }
7636
7637 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7638                 .f = cmd_reset_mirror_rule_parsed,
7639                 .data = NULL,
7640                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
7641                 .tokens = {
7642                         (void *)&cmd_rm_mirror_rule_reset,
7643                         (void *)&cmd_rm_mirror_rule_port,
7644                         (void *)&cmd_rm_mirror_rule_portid,
7645                         (void *)&cmd_rm_mirror_rule_mirror,
7646                         (void *)&cmd_rm_mirror_rule_ruleid,
7647                         NULL,
7648                 },
7649 };
7650
7651 /* ******************************************************************************** */
7652
7653 struct cmd_dump_result {
7654         cmdline_fixed_string_t dump;
7655 };
7656
7657 static void
7658 dump_struct_sizes(void)
7659 {
7660 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7661         DUMP_SIZE(struct rte_mbuf);
7662         DUMP_SIZE(struct rte_mempool);
7663         DUMP_SIZE(struct rte_ring);
7664 #undef DUMP_SIZE
7665 }
7666
7667 static void cmd_dump_parsed(void *parsed_result,
7668                             __attribute__((unused)) struct cmdline *cl,
7669                             __attribute__((unused)) void *data)
7670 {
7671         struct cmd_dump_result *res = parsed_result;
7672
7673         if (!strcmp(res->dump, "dump_physmem"))
7674                 rte_dump_physmem_layout(stdout);
7675         else if (!strcmp(res->dump, "dump_memzone"))
7676                 rte_memzone_dump(stdout);
7677         else if (!strcmp(res->dump, "dump_struct_sizes"))
7678                 dump_struct_sizes();
7679         else if (!strcmp(res->dump, "dump_ring"))
7680                 rte_ring_list_dump(stdout);
7681         else if (!strcmp(res->dump, "dump_mempool"))
7682                 rte_mempool_list_dump(stdout);
7683         else if (!strcmp(res->dump, "dump_devargs"))
7684                 rte_eal_devargs_dump(stdout);
7685 }
7686
7687 cmdline_parse_token_string_t cmd_dump_dump =
7688         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7689                 "dump_physmem#"
7690                 "dump_memzone#"
7691                 "dump_struct_sizes#"
7692                 "dump_ring#"
7693                 "dump_mempool#"
7694                 "dump_devargs");
7695
7696 cmdline_parse_inst_t cmd_dump = {
7697         .f = cmd_dump_parsed,  /* function to call */
7698         .data = NULL,      /* 2nd arg of func */
7699         .help_str = "Dump status",
7700         .tokens = {        /* token list, NULL terminated */
7701                 (void *)&cmd_dump_dump,
7702                 NULL,
7703         },
7704 };
7705
7706 /* ******************************************************************************** */
7707
7708 struct cmd_dump_one_result {
7709         cmdline_fixed_string_t dump;
7710         cmdline_fixed_string_t name;
7711 };
7712
7713 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7714                                 __attribute__((unused)) void *data)
7715 {
7716         struct cmd_dump_one_result *res = parsed_result;
7717
7718         if (!strcmp(res->dump, "dump_ring")) {
7719                 struct rte_ring *r;
7720                 r = rte_ring_lookup(res->name);
7721                 if (r == NULL) {
7722                         cmdline_printf(cl, "Cannot find ring\n");
7723                         return;
7724                 }
7725                 rte_ring_dump(stdout, r);
7726         } else if (!strcmp(res->dump, "dump_mempool")) {
7727                 struct rte_mempool *mp;
7728                 mp = rte_mempool_lookup(res->name);
7729                 if (mp == NULL) {
7730                         cmdline_printf(cl, "Cannot find mempool\n");
7731                         return;
7732                 }
7733                 rte_mempool_dump(stdout, mp);
7734         }
7735 }
7736
7737 cmdline_parse_token_string_t cmd_dump_one_dump =
7738         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7739                                  "dump_ring#dump_mempool");
7740
7741 cmdline_parse_token_string_t cmd_dump_one_name =
7742         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7743
7744 cmdline_parse_inst_t cmd_dump_one = {
7745         .f = cmd_dump_one_parsed,  /* function to call */
7746         .data = NULL,      /* 2nd arg of func */
7747         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
7748         .tokens = {        /* token list, NULL terminated */
7749                 (void *)&cmd_dump_one_dump,
7750                 (void *)&cmd_dump_one_name,
7751                 NULL,
7752         },
7753 };
7754
7755 /* *** Add/Del syn filter *** */
7756 struct cmd_syn_filter_result {
7757         cmdline_fixed_string_t filter;
7758         uint8_t port_id;
7759         cmdline_fixed_string_t ops;
7760         cmdline_fixed_string_t priority;
7761         cmdline_fixed_string_t high;
7762         cmdline_fixed_string_t queue;
7763         uint16_t queue_id;
7764 };
7765
7766 static void
7767 cmd_syn_filter_parsed(void *parsed_result,
7768                         __attribute__((unused)) struct cmdline *cl,
7769                         __attribute__((unused)) void *data)
7770 {
7771         struct cmd_syn_filter_result *res = parsed_result;
7772         struct rte_eth_syn_filter syn_filter;
7773         int ret = 0;
7774
7775         ret = rte_eth_dev_filter_supported(res->port_id,
7776                                         RTE_ETH_FILTER_SYN);
7777         if (ret < 0) {
7778                 printf("syn filter is not supported on port %u.\n",
7779                                 res->port_id);
7780                 return;
7781         }
7782
7783         memset(&syn_filter, 0, sizeof(syn_filter));
7784
7785         if (!strcmp(res->ops, "add")) {
7786                 if (!strcmp(res->high, "high"))
7787                         syn_filter.hig_pri = 1;
7788                 else
7789                         syn_filter.hig_pri = 0;
7790
7791                 syn_filter.queue = res->queue_id;
7792                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7793                                                 RTE_ETH_FILTER_SYN,
7794                                                 RTE_ETH_FILTER_ADD,
7795                                                 &syn_filter);
7796         } else
7797                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7798                                                 RTE_ETH_FILTER_SYN,
7799                                                 RTE_ETH_FILTER_DELETE,
7800                                                 &syn_filter);
7801
7802         if (ret < 0)
7803                 printf("syn filter programming error: (%s)\n",
7804                                 strerror(-ret));
7805 }
7806
7807 cmdline_parse_token_string_t cmd_syn_filter_filter =
7808         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7809         filter, "syn_filter");
7810 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7811         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7812         port_id, UINT8);
7813 cmdline_parse_token_string_t cmd_syn_filter_ops =
7814         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7815         ops, "add#del");
7816 cmdline_parse_token_string_t cmd_syn_filter_priority =
7817         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7818                                 priority, "priority");
7819 cmdline_parse_token_string_t cmd_syn_filter_high =
7820         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7821                                 high, "high#low");
7822 cmdline_parse_token_string_t cmd_syn_filter_queue =
7823         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7824                                 queue, "queue");
7825 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7826         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7827                                 queue_id, UINT16);
7828
7829 cmdline_parse_inst_t cmd_syn_filter = {
7830         .f = cmd_syn_filter_parsed,
7831         .data = NULL,
7832         .help_str = "syn_filter <port_id> add|del priority high|low queue "
7833                 "<queue_id>: Add/Delete syn filter",
7834         .tokens = {
7835                 (void *)&cmd_syn_filter_filter,
7836                 (void *)&cmd_syn_filter_port_id,
7837                 (void *)&cmd_syn_filter_ops,
7838                 (void *)&cmd_syn_filter_priority,
7839                 (void *)&cmd_syn_filter_high,
7840                 (void *)&cmd_syn_filter_queue,
7841                 (void *)&cmd_syn_filter_queue_id,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** ADD/REMOVE A 2tuple FILTER *** */
7847 struct cmd_2tuple_filter_result {
7848         cmdline_fixed_string_t filter;
7849         uint8_t  port_id;
7850         cmdline_fixed_string_t ops;
7851         cmdline_fixed_string_t dst_port;
7852         uint16_t dst_port_value;
7853         cmdline_fixed_string_t protocol;
7854         uint8_t protocol_value;
7855         cmdline_fixed_string_t mask;
7856         uint8_t  mask_value;
7857         cmdline_fixed_string_t tcp_flags;
7858         uint8_t tcp_flags_value;
7859         cmdline_fixed_string_t priority;
7860         uint8_t  priority_value;
7861         cmdline_fixed_string_t queue;
7862         uint16_t  queue_id;
7863 };
7864
7865 static void
7866 cmd_2tuple_filter_parsed(void *parsed_result,
7867                         __attribute__((unused)) struct cmdline *cl,
7868                         __attribute__((unused)) void *data)
7869 {
7870         struct rte_eth_ntuple_filter filter;
7871         struct cmd_2tuple_filter_result *res = parsed_result;
7872         int ret = 0;
7873
7874         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7875         if (ret < 0) {
7876                 printf("ntuple filter is not supported on port %u.\n",
7877                         res->port_id);
7878                 return;
7879         }
7880
7881         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7882
7883         filter.flags = RTE_2TUPLE_FLAGS;
7884         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7885         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7886         filter.proto = res->protocol_value;
7887         filter.priority = res->priority_value;
7888         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7889                 printf("nonzero tcp_flags is only meaningful"
7890                         " when protocol is TCP.\n");
7891                 return;
7892         }
7893         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7894                 printf("invalid TCP flags.\n");
7895                 return;
7896         }
7897
7898         if (res->tcp_flags_value != 0) {
7899                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7900                 filter.tcp_flags = res->tcp_flags_value;
7901         }
7902
7903         /* need convert to big endian. */
7904         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7905         filter.queue = res->queue_id;
7906
7907         if (!strcmp(res->ops, "add"))
7908                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7909                                 RTE_ETH_FILTER_NTUPLE,
7910                                 RTE_ETH_FILTER_ADD,
7911                                 &filter);
7912         else
7913                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7914                                 RTE_ETH_FILTER_NTUPLE,
7915                                 RTE_ETH_FILTER_DELETE,
7916                                 &filter);
7917         if (ret < 0)
7918                 printf("2tuple filter programming error: (%s)\n",
7919                         strerror(-ret));
7920
7921 }
7922
7923 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7924         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7925                                  filter, "2tuple_filter");
7926 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7927         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7928                                 port_id, UINT8);
7929 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7930         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7931                                  ops, "add#del");
7932 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7933         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7934                                 dst_port, "dst_port");
7935 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7936         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7937                                 dst_port_value, UINT16);
7938 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7939         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7940                                 protocol, "protocol");
7941 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7942         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7943                                 protocol_value, UINT8);
7944 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7945         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7946                                 mask, "mask");
7947 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7948         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7949                                 mask_value, INT8);
7950 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7951         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7952                                 tcp_flags, "tcp_flags");
7953 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7954         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7955                                 tcp_flags_value, UINT8);
7956 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7957         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7958                                 priority, "priority");
7959 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7960         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7961                                 priority_value, UINT8);
7962 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7963         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7964                                 queue, "queue");
7965 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7966         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7967                                 queue_id, UINT16);
7968
7969 cmdline_parse_inst_t cmd_2tuple_filter = {
7970         .f = cmd_2tuple_filter_parsed,
7971         .data = NULL,
7972         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
7973                 "<value> mask <value> tcp_flags <value> priority <value> queue "
7974                 "<queue_id>: Add a 2tuple filter",
7975         .tokens = {
7976                 (void *)&cmd_2tuple_filter_filter,
7977                 (void *)&cmd_2tuple_filter_port_id,
7978                 (void *)&cmd_2tuple_filter_ops,
7979                 (void *)&cmd_2tuple_filter_dst_port,
7980                 (void *)&cmd_2tuple_filter_dst_port_value,
7981                 (void *)&cmd_2tuple_filter_protocol,
7982                 (void *)&cmd_2tuple_filter_protocol_value,
7983                 (void *)&cmd_2tuple_filter_mask,
7984                 (void *)&cmd_2tuple_filter_mask_value,
7985                 (void *)&cmd_2tuple_filter_tcp_flags,
7986                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7987                 (void *)&cmd_2tuple_filter_priority,
7988                 (void *)&cmd_2tuple_filter_priority_value,
7989                 (void *)&cmd_2tuple_filter_queue,
7990                 (void *)&cmd_2tuple_filter_queue_id,
7991                 NULL,
7992         },
7993 };
7994
7995 /* *** ADD/REMOVE A 5tuple FILTER *** */
7996 struct cmd_5tuple_filter_result {
7997         cmdline_fixed_string_t filter;
7998         uint8_t  port_id;
7999         cmdline_fixed_string_t ops;
8000         cmdline_fixed_string_t dst_ip;
8001         cmdline_ipaddr_t dst_ip_value;
8002         cmdline_fixed_string_t src_ip;
8003         cmdline_ipaddr_t src_ip_value;
8004         cmdline_fixed_string_t dst_port;
8005         uint16_t dst_port_value;
8006         cmdline_fixed_string_t src_port;
8007         uint16_t src_port_value;
8008         cmdline_fixed_string_t protocol;
8009         uint8_t protocol_value;
8010         cmdline_fixed_string_t mask;
8011         uint8_t  mask_value;
8012         cmdline_fixed_string_t tcp_flags;
8013         uint8_t tcp_flags_value;
8014         cmdline_fixed_string_t priority;
8015         uint8_t  priority_value;
8016         cmdline_fixed_string_t queue;
8017         uint16_t  queue_id;
8018 };
8019
8020 static void
8021 cmd_5tuple_filter_parsed(void *parsed_result,
8022                         __attribute__((unused)) struct cmdline *cl,
8023                         __attribute__((unused)) void *data)
8024 {
8025         struct rte_eth_ntuple_filter filter;
8026         struct cmd_5tuple_filter_result *res = parsed_result;
8027         int ret = 0;
8028
8029         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8030         if (ret < 0) {
8031                 printf("ntuple filter is not supported on port %u.\n",
8032                         res->port_id);
8033                 return;
8034         }
8035
8036         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8037
8038         filter.flags = RTE_5TUPLE_FLAGS;
8039         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8040         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8041         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8042         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8043         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8044         filter.proto = res->protocol_value;
8045         filter.priority = res->priority_value;
8046         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8047                 printf("nonzero tcp_flags is only meaningful"
8048                         " when protocol is TCP.\n");
8049                 return;
8050         }
8051         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8052                 printf("invalid TCP flags.\n");
8053                 return;
8054         }
8055
8056         if (res->tcp_flags_value != 0) {
8057                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8058                 filter.tcp_flags = res->tcp_flags_value;
8059         }
8060
8061         if (res->dst_ip_value.family == AF_INET)
8062                 /* no need to convert, already big endian. */
8063                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8064         else {
8065                 if (filter.dst_ip_mask == 0) {
8066                         printf("can not support ipv6 involved compare.\n");
8067                         return;
8068                 }
8069                 filter.dst_ip = 0;
8070         }
8071
8072         if (res->src_ip_value.family == AF_INET)
8073                 /* no need to convert, already big endian. */
8074                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8075         else {
8076                 if (filter.src_ip_mask == 0) {
8077                         printf("can not support ipv6 involved compare.\n");
8078                         return;
8079                 }
8080                 filter.src_ip = 0;
8081         }
8082         /* need convert to big endian. */
8083         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8084         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8085         filter.queue = res->queue_id;
8086
8087         if (!strcmp(res->ops, "add"))
8088                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8089                                 RTE_ETH_FILTER_NTUPLE,
8090                                 RTE_ETH_FILTER_ADD,
8091                                 &filter);
8092         else
8093                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8094                                 RTE_ETH_FILTER_NTUPLE,
8095                                 RTE_ETH_FILTER_DELETE,
8096                                 &filter);
8097         if (ret < 0)
8098                 printf("5tuple filter programming error: (%s)\n",
8099                         strerror(-ret));
8100 }
8101
8102 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8103         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8104                                  filter, "5tuple_filter");
8105 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8106         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8107                                 port_id, UINT8);
8108 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8109         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8110                                  ops, "add#del");
8111 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8112         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8113                                 dst_ip, "dst_ip");
8114 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8115         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8116                                 dst_ip_value);
8117 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8118         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8119                                 src_ip, "src_ip");
8120 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8121         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8122                                 src_ip_value);
8123 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8124         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8125                                 dst_port, "dst_port");
8126 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8127         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8128                                 dst_port_value, UINT16);
8129 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8130         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8131                                 src_port, "src_port");
8132 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8133         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8134                                 src_port_value, UINT16);
8135 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8136         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8137                                 protocol, "protocol");
8138 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8139         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8140                                 protocol_value, UINT8);
8141 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8142         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8143                                 mask, "mask");
8144 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8145         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8146                                 mask_value, INT8);
8147 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8148         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8149                                 tcp_flags, "tcp_flags");
8150 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8151         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8152                                 tcp_flags_value, UINT8);
8153 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8154         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8155                                 priority, "priority");
8156 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8157         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8158                                 priority_value, UINT8);
8159 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8160         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8161                                 queue, "queue");
8162 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8163         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8164                                 queue_id, UINT16);
8165
8166 cmdline_parse_inst_t cmd_5tuple_filter = {
8167         .f = cmd_5tuple_filter_parsed,
8168         .data = NULL,
8169         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8170                 "src_ip <value> dst_port <value> src_port <value> "
8171                 "protocol <value>  mask <value> tcp_flags <value> "
8172                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8173         .tokens = {
8174                 (void *)&cmd_5tuple_filter_filter,
8175                 (void *)&cmd_5tuple_filter_port_id,
8176                 (void *)&cmd_5tuple_filter_ops,
8177                 (void *)&cmd_5tuple_filter_dst_ip,
8178                 (void *)&cmd_5tuple_filter_dst_ip_value,
8179                 (void *)&cmd_5tuple_filter_src_ip,
8180                 (void *)&cmd_5tuple_filter_src_ip_value,
8181                 (void *)&cmd_5tuple_filter_dst_port,
8182                 (void *)&cmd_5tuple_filter_dst_port_value,
8183                 (void *)&cmd_5tuple_filter_src_port,
8184                 (void *)&cmd_5tuple_filter_src_port_value,
8185                 (void *)&cmd_5tuple_filter_protocol,
8186                 (void *)&cmd_5tuple_filter_protocol_value,
8187                 (void *)&cmd_5tuple_filter_mask,
8188                 (void *)&cmd_5tuple_filter_mask_value,
8189                 (void *)&cmd_5tuple_filter_tcp_flags,
8190                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8191                 (void *)&cmd_5tuple_filter_priority,
8192                 (void *)&cmd_5tuple_filter_priority_value,
8193                 (void *)&cmd_5tuple_filter_queue,
8194                 (void *)&cmd_5tuple_filter_queue_id,
8195                 NULL,
8196         },
8197 };
8198
8199 /* *** ADD/REMOVE A flex FILTER *** */
8200 struct cmd_flex_filter_result {
8201         cmdline_fixed_string_t filter;
8202         cmdline_fixed_string_t ops;
8203         uint8_t port_id;
8204         cmdline_fixed_string_t len;
8205         uint8_t len_value;
8206         cmdline_fixed_string_t bytes;
8207         cmdline_fixed_string_t bytes_value;
8208         cmdline_fixed_string_t mask;
8209         cmdline_fixed_string_t mask_value;
8210         cmdline_fixed_string_t priority;
8211         uint8_t priority_value;
8212         cmdline_fixed_string_t queue;
8213         uint16_t queue_id;
8214 };
8215
8216 static int xdigit2val(unsigned char c)
8217 {
8218         int val;
8219         if (isdigit(c))
8220                 val = c - '0';
8221         else if (isupper(c))
8222                 val = c - 'A' + 10;
8223         else
8224                 val = c - 'a' + 10;
8225         return val;
8226 }
8227
8228 static void
8229 cmd_flex_filter_parsed(void *parsed_result,
8230                           __attribute__((unused)) struct cmdline *cl,
8231                           __attribute__((unused)) void *data)
8232 {
8233         int ret = 0;
8234         struct rte_eth_flex_filter filter;
8235         struct cmd_flex_filter_result *res = parsed_result;
8236         char *bytes_ptr, *mask_ptr;
8237         uint16_t len, i, j = 0;
8238         char c;
8239         int val;
8240         uint8_t byte = 0;
8241
8242         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8243                 printf("the len exceed the max length 128\n");
8244                 return;
8245         }
8246         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8247         filter.len = res->len_value;
8248         filter.priority = res->priority_value;
8249         filter.queue = res->queue_id;
8250         bytes_ptr = res->bytes_value;
8251         mask_ptr = res->mask_value;
8252
8253          /* translate bytes string to array. */
8254         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8255                 (bytes_ptr[1] == 'X')))
8256                 bytes_ptr += 2;
8257         len = strnlen(bytes_ptr, res->len_value * 2);
8258         if (len == 0 || (len % 8 != 0)) {
8259                 printf("please check len and bytes input\n");
8260                 return;
8261         }
8262         for (i = 0; i < len; i++) {
8263                 c = bytes_ptr[i];
8264                 if (isxdigit(c) == 0) {
8265                         /* invalid characters. */
8266                         printf("invalid input\n");
8267                         return;
8268                 }
8269                 val = xdigit2val(c);
8270                 if (i % 2) {
8271                         byte |= val;
8272                         filter.bytes[j] = byte;
8273                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8274                         j++;
8275                         byte = 0;
8276                 } else
8277                         byte |= val << 4;
8278         }
8279         printf("\n");
8280          /* translate mask string to uint8_t array. */
8281         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8282                 (mask_ptr[1] == 'X')))
8283                 mask_ptr += 2;
8284         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8285         if (len == 0) {
8286                 printf("invalid input\n");
8287                 return;
8288         }
8289         j = 0;
8290         byte = 0;
8291         for (i = 0; i < len; i++) {
8292                 c = mask_ptr[i];
8293                 if (isxdigit(c) == 0) {
8294                         /* invalid characters. */
8295                         printf("invalid input\n");
8296                         return;
8297                 }
8298                 val = xdigit2val(c);
8299                 if (i % 2) {
8300                         byte |= val;
8301                         filter.mask[j] = byte;
8302                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8303                         j++;
8304                         byte = 0;
8305                 } else
8306                         byte |= val << 4;
8307         }
8308         printf("\n");
8309
8310         if (!strcmp(res->ops, "add"))
8311                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8312                                 RTE_ETH_FILTER_FLEXIBLE,
8313                                 RTE_ETH_FILTER_ADD,
8314                                 &filter);
8315         else
8316                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8317                                 RTE_ETH_FILTER_FLEXIBLE,
8318                                 RTE_ETH_FILTER_DELETE,
8319                                 &filter);
8320
8321         if (ret < 0)
8322                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8323 }
8324
8325 cmdline_parse_token_string_t cmd_flex_filter_filter =
8326         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8327                                 filter, "flex_filter");
8328 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8329         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8330                                 port_id, UINT8);
8331 cmdline_parse_token_string_t cmd_flex_filter_ops =
8332         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8333                                 ops, "add#del");
8334 cmdline_parse_token_string_t cmd_flex_filter_len =
8335         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8336                                 len, "len");
8337 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8338         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8339                                 len_value, UINT8);
8340 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8341         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8342                                 bytes, "bytes");
8343 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8344         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8345                                 bytes_value, NULL);
8346 cmdline_parse_token_string_t cmd_flex_filter_mask =
8347         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8348                                 mask, "mask");
8349 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8350         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8351                                 mask_value, NULL);
8352 cmdline_parse_token_string_t cmd_flex_filter_priority =
8353         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8354                                 priority, "priority");
8355 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8356         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8357                                 priority_value, UINT8);
8358 cmdline_parse_token_string_t cmd_flex_filter_queue =
8359         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8360                                 queue, "queue");
8361 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8362         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8363                                 queue_id, UINT16);
8364 cmdline_parse_inst_t cmd_flex_filter = {
8365         .f = cmd_flex_filter_parsed,
8366         .data = NULL,
8367         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8368                 "<value> mask <value> priority <value> queue <queue_id>: "
8369                 "Add/Del a flex filter",
8370         .tokens = {
8371                 (void *)&cmd_flex_filter_filter,
8372                 (void *)&cmd_flex_filter_port_id,
8373                 (void *)&cmd_flex_filter_ops,
8374                 (void *)&cmd_flex_filter_len,
8375                 (void *)&cmd_flex_filter_len_value,
8376                 (void *)&cmd_flex_filter_bytes,
8377                 (void *)&cmd_flex_filter_bytes_value,
8378                 (void *)&cmd_flex_filter_mask,
8379                 (void *)&cmd_flex_filter_mask_value,
8380                 (void *)&cmd_flex_filter_priority,
8381                 (void *)&cmd_flex_filter_priority_value,
8382                 (void *)&cmd_flex_filter_queue,
8383                 (void *)&cmd_flex_filter_queue_id,
8384                 NULL,
8385         },
8386 };
8387
8388 /* *** Filters Control *** */
8389
8390 /* *** deal with ethertype filter *** */
8391 struct cmd_ethertype_filter_result {
8392         cmdline_fixed_string_t filter;
8393         uint8_t port_id;
8394         cmdline_fixed_string_t ops;
8395         cmdline_fixed_string_t mac;
8396         struct ether_addr mac_addr;
8397         cmdline_fixed_string_t ethertype;
8398         uint16_t ethertype_value;
8399         cmdline_fixed_string_t drop;
8400         cmdline_fixed_string_t queue;
8401         uint16_t  queue_id;
8402 };
8403
8404 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8405         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8406                                  filter, "ethertype_filter");
8407 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8408         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8409                               port_id, UINT8);
8410 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8411         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8412                                  ops, "add#del");
8413 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8414         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8415                                  mac, "mac_addr#mac_ignr");
8416 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8417         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8418                                      mac_addr);
8419 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8420         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8421                                  ethertype, "ethertype");
8422 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8423         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8424                               ethertype_value, UINT16);
8425 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8426         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8427                                  drop, "drop#fwd");
8428 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8429         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8430                                  queue, "queue");
8431 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8432         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8433                               queue_id, UINT16);
8434
8435 static void
8436 cmd_ethertype_filter_parsed(void *parsed_result,
8437                           __attribute__((unused)) struct cmdline *cl,
8438                           __attribute__((unused)) void *data)
8439 {
8440         struct cmd_ethertype_filter_result *res = parsed_result;
8441         struct rte_eth_ethertype_filter filter;
8442         int ret = 0;
8443
8444         ret = rte_eth_dev_filter_supported(res->port_id,
8445                         RTE_ETH_FILTER_ETHERTYPE);
8446         if (ret < 0) {
8447                 printf("ethertype filter is not supported on port %u.\n",
8448                         res->port_id);
8449                 return;
8450         }
8451
8452         memset(&filter, 0, sizeof(filter));
8453         if (!strcmp(res->mac, "mac_addr")) {
8454                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8455                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8456                         sizeof(struct ether_addr));
8457         }
8458         if (!strcmp(res->drop, "drop"))
8459                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8460         filter.ether_type = res->ethertype_value;
8461         filter.queue = res->queue_id;
8462
8463         if (!strcmp(res->ops, "add"))
8464                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8465                                 RTE_ETH_FILTER_ETHERTYPE,
8466                                 RTE_ETH_FILTER_ADD,
8467                                 &filter);
8468         else
8469                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8470                                 RTE_ETH_FILTER_ETHERTYPE,
8471                                 RTE_ETH_FILTER_DELETE,
8472                                 &filter);
8473         if (ret < 0)
8474                 printf("ethertype filter programming error: (%s)\n",
8475                         strerror(-ret));
8476 }
8477
8478 cmdline_parse_inst_t cmd_ethertype_filter = {
8479         .f = cmd_ethertype_filter_parsed,
8480         .data = NULL,
8481         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8482                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8483                 "Add or delete an ethertype filter entry",
8484         .tokens = {
8485                 (void *)&cmd_ethertype_filter_filter,
8486                 (void *)&cmd_ethertype_filter_port_id,
8487                 (void *)&cmd_ethertype_filter_ops,
8488                 (void *)&cmd_ethertype_filter_mac,
8489                 (void *)&cmd_ethertype_filter_mac_addr,
8490                 (void *)&cmd_ethertype_filter_ethertype,
8491                 (void *)&cmd_ethertype_filter_ethertype_value,
8492                 (void *)&cmd_ethertype_filter_drop,
8493                 (void *)&cmd_ethertype_filter_queue,
8494                 (void *)&cmd_ethertype_filter_queue_id,
8495                 NULL,
8496         },
8497 };
8498
8499 /* *** deal with flow director filter *** */
8500 struct cmd_flow_director_result {
8501         cmdline_fixed_string_t flow_director_filter;
8502         uint8_t port_id;
8503         cmdline_fixed_string_t mode;
8504         cmdline_fixed_string_t mode_value;
8505         cmdline_fixed_string_t ops;
8506         cmdline_fixed_string_t flow;
8507         cmdline_fixed_string_t flow_type;
8508         cmdline_fixed_string_t ether;
8509         uint16_t ether_type;
8510         cmdline_fixed_string_t src;
8511         cmdline_ipaddr_t ip_src;
8512         uint16_t port_src;
8513         cmdline_fixed_string_t dst;
8514         cmdline_ipaddr_t ip_dst;
8515         uint16_t port_dst;
8516         cmdline_fixed_string_t verify_tag;
8517         uint32_t verify_tag_value;
8518         cmdline_ipaddr_t tos;
8519         uint8_t tos_value;
8520         cmdline_ipaddr_t proto;
8521         uint8_t proto_value;
8522         cmdline_ipaddr_t ttl;
8523         uint8_t ttl_value;
8524         cmdline_fixed_string_t vlan;
8525         uint16_t vlan_value;
8526         cmdline_fixed_string_t flexbytes;
8527         cmdline_fixed_string_t flexbytes_value;
8528         cmdline_fixed_string_t pf_vf;
8529         cmdline_fixed_string_t drop;
8530         cmdline_fixed_string_t queue;
8531         uint16_t  queue_id;
8532         cmdline_fixed_string_t fd_id;
8533         uint32_t  fd_id_value;
8534         cmdline_fixed_string_t mac;
8535         struct ether_addr mac_addr;
8536         cmdline_fixed_string_t tunnel;
8537         cmdline_fixed_string_t tunnel_type;
8538         cmdline_fixed_string_t tunnel_id;
8539         uint32_t tunnel_id_value;
8540 };
8541
8542 static inline int
8543 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8544 {
8545         char s[256];
8546         const char *p, *p0 = q_arg;
8547         char *end;
8548         unsigned long int_fld;
8549         char *str_fld[max_num];
8550         int i;
8551         unsigned size;
8552         int ret = -1;
8553
8554         p = strchr(p0, '(');
8555         if (p == NULL)
8556                 return -1;
8557         ++p;
8558         p0 = strchr(p, ')');
8559         if (p0 == NULL)
8560                 return -1;
8561
8562         size = p0 - p;
8563         if (size >= sizeof(s))
8564                 return -1;
8565
8566         snprintf(s, sizeof(s), "%.*s", size, p);
8567         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8568         if (ret < 0 || ret > max_num)
8569                 return -1;
8570         for (i = 0; i < ret; i++) {
8571                 errno = 0;
8572                 int_fld = strtoul(str_fld[i], &end, 0);
8573                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8574                         return -1;
8575                 flexbytes[i] = (uint8_t)int_fld;
8576         }
8577         return ret;
8578 }
8579
8580 static uint16_t
8581 str2flowtype(char *string)
8582 {
8583         uint8_t i = 0;
8584         static const struct {
8585                 char str[32];
8586                 uint16_t type;
8587         } flowtype_str[] = {
8588                 {"raw", RTE_ETH_FLOW_RAW},
8589                 {"ipv4", RTE_ETH_FLOW_IPV4},
8590                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8591                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8592                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8593                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8594                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8595                 {"ipv6", RTE_ETH_FLOW_IPV6},
8596                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8597                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8598                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8599                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8600                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8601                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8602         };
8603
8604         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8605                 if (!strcmp(flowtype_str[i].str, string))
8606                         return flowtype_str[i].type;
8607         }
8608         return RTE_ETH_FLOW_UNKNOWN;
8609 }
8610
8611 static enum rte_eth_fdir_tunnel_type
8612 str2fdir_tunneltype(char *string)
8613 {
8614         uint8_t i = 0;
8615
8616         static const struct {
8617                 char str[32];
8618                 enum rte_eth_fdir_tunnel_type type;
8619         } tunneltype_str[] = {
8620                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8621                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8622         };
8623
8624         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8625                 if (!strcmp(tunneltype_str[i].str, string))
8626                         return tunneltype_str[i].type;
8627         }
8628         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8629 }
8630
8631 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8632 do { \
8633         if ((ip_addr).family == AF_INET) \
8634                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8635         else { \
8636                 printf("invalid parameter.\n"); \
8637                 return; \
8638         } \
8639 } while (0)
8640
8641 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8642 do { \
8643         if ((ip_addr).family == AF_INET6) \
8644                 (void)rte_memcpy(&(ip), \
8645                                  &((ip_addr).addr.ipv6), \
8646                                  sizeof(struct in6_addr)); \
8647         else { \
8648                 printf("invalid parameter.\n"); \
8649                 return; \
8650         } \
8651 } while (0)
8652
8653 static void
8654 cmd_flow_director_filter_parsed(void *parsed_result,
8655                           __attribute__((unused)) struct cmdline *cl,
8656                           __attribute__((unused)) void *data)
8657 {
8658         struct cmd_flow_director_result *res = parsed_result;
8659         struct rte_eth_fdir_filter entry;
8660         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8661         char *end;
8662         unsigned long vf_id;
8663         int ret = 0;
8664
8665         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8666         if (ret < 0) {
8667                 printf("flow director is not supported on port %u.\n",
8668                         res->port_id);
8669                 return;
8670         }
8671         memset(flexbytes, 0, sizeof(flexbytes));
8672         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8673
8674         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8675                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8676                         printf("Please set mode to MAC-VLAN.\n");
8677                         return;
8678                 }
8679         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8680                 if (strcmp(res->mode_value, "Tunnel")) {
8681                         printf("Please set mode to Tunnel.\n");
8682                         return;
8683                 }
8684         } else {
8685                 if (strcmp(res->mode_value, "IP")) {
8686                         printf("Please set mode to IP.\n");
8687                         return;
8688                 }
8689                 entry.input.flow_type = str2flowtype(res->flow_type);
8690         }
8691
8692         ret = parse_flexbytes(res->flexbytes_value,
8693                                         flexbytes,
8694                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8695         if (ret < 0) {
8696                 printf("error: Cannot parse flexbytes input.\n");
8697                 return;
8698         }
8699
8700         switch (entry.input.flow_type) {
8701         case RTE_ETH_FLOW_FRAG_IPV4:
8702         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8703                 entry.input.flow.ip4_flow.proto = res->proto_value;
8704         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8705         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8706                 IPV4_ADDR_TO_UINT(res->ip_dst,
8707                         entry.input.flow.ip4_flow.dst_ip);
8708                 IPV4_ADDR_TO_UINT(res->ip_src,
8709                         entry.input.flow.ip4_flow.src_ip);
8710                 entry.input.flow.ip4_flow.tos = res->tos_value;
8711                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8712                 /* need convert to big endian. */
8713                 entry.input.flow.udp4_flow.dst_port =
8714                                 rte_cpu_to_be_16(res->port_dst);
8715                 entry.input.flow.udp4_flow.src_port =
8716                                 rte_cpu_to_be_16(res->port_src);
8717                 break;
8718         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8719                 IPV4_ADDR_TO_UINT(res->ip_dst,
8720                         entry.input.flow.sctp4_flow.ip.dst_ip);
8721                 IPV4_ADDR_TO_UINT(res->ip_src,
8722                         entry.input.flow.sctp4_flow.ip.src_ip);
8723                 entry.input.flow.ip4_flow.tos = res->tos_value;
8724                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8725                 /* need convert to big endian. */
8726                 entry.input.flow.sctp4_flow.dst_port =
8727                                 rte_cpu_to_be_16(res->port_dst);
8728                 entry.input.flow.sctp4_flow.src_port =
8729                                 rte_cpu_to_be_16(res->port_src);
8730                 entry.input.flow.sctp4_flow.verify_tag =
8731                                 rte_cpu_to_be_32(res->verify_tag_value);
8732                 break;
8733         case RTE_ETH_FLOW_FRAG_IPV6:
8734         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8735                 entry.input.flow.ipv6_flow.proto = res->proto_value;
8736         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8737         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8738                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8739                         entry.input.flow.ipv6_flow.dst_ip);
8740                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8741                         entry.input.flow.ipv6_flow.src_ip);
8742                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8743                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8744                 /* need convert to big endian. */
8745                 entry.input.flow.udp6_flow.dst_port =
8746                                 rte_cpu_to_be_16(res->port_dst);
8747                 entry.input.flow.udp6_flow.src_port =
8748                                 rte_cpu_to_be_16(res->port_src);
8749                 break;
8750         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8751                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8752                         entry.input.flow.sctp6_flow.ip.dst_ip);
8753                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8754                         entry.input.flow.sctp6_flow.ip.src_ip);
8755                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8756                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8757                 /* need convert to big endian. */
8758                 entry.input.flow.sctp6_flow.dst_port =
8759                                 rte_cpu_to_be_16(res->port_dst);
8760                 entry.input.flow.sctp6_flow.src_port =
8761                                 rte_cpu_to_be_16(res->port_src);
8762                 entry.input.flow.sctp6_flow.verify_tag =
8763                                 rte_cpu_to_be_32(res->verify_tag_value);
8764                 break;
8765         case RTE_ETH_FLOW_L2_PAYLOAD:
8766                 entry.input.flow.l2_flow.ether_type =
8767                         rte_cpu_to_be_16(res->ether_type);
8768                 break;
8769         default:
8770                 break;
8771         }
8772
8773         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8774                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8775                                  &res->mac_addr,
8776                                  sizeof(struct ether_addr));
8777
8778         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8779                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8780                                  &res->mac_addr,
8781                                  sizeof(struct ether_addr));
8782                 entry.input.flow.tunnel_flow.tunnel_type =
8783                         str2fdir_tunneltype(res->tunnel_type);
8784                 entry.input.flow.tunnel_flow.tunnel_id =
8785                         rte_cpu_to_be_32(res->tunnel_id_value);
8786         }
8787
8788         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8789                    flexbytes,
8790                    RTE_ETH_FDIR_MAX_FLEXLEN);
8791
8792         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8793
8794         entry.action.flex_off = 0;  /*use 0 by default */
8795         if (!strcmp(res->drop, "drop"))
8796                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8797         else
8798                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8799
8800         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
8801             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8802                 if (!strcmp(res->pf_vf, "pf"))
8803                         entry.input.flow_ext.is_vf = 0;
8804                 else if (!strncmp(res->pf_vf, "vf", 2)) {
8805                         struct rte_eth_dev_info dev_info;
8806
8807                         memset(&dev_info, 0, sizeof(dev_info));
8808                         rte_eth_dev_info_get(res->port_id, &dev_info);
8809                         errno = 0;
8810                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
8811                         if (errno != 0 || *end != '\0' ||
8812                             vf_id >= dev_info.max_vfs) {
8813                                 printf("invalid parameter %s.\n", res->pf_vf);
8814                                 return;
8815                         }
8816                         entry.input.flow_ext.is_vf = 1;
8817                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8818                 } else {
8819                         printf("invalid parameter %s.\n", res->pf_vf);
8820                         return;
8821                 }
8822         }
8823
8824         /* set to report FD ID by default */
8825         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8826         entry.action.rx_queue = res->queue_id;
8827         entry.soft_id = res->fd_id_value;
8828         if (!strcmp(res->ops, "add"))
8829                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8830                                              RTE_ETH_FILTER_ADD, &entry);
8831         else if (!strcmp(res->ops, "del"))
8832                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8833                                              RTE_ETH_FILTER_DELETE, &entry);
8834         else
8835                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8836                                              RTE_ETH_FILTER_UPDATE, &entry);
8837         if (ret < 0)
8838                 printf("flow director programming error: (%s)\n",
8839                         strerror(-ret));
8840 }
8841
8842 cmdline_parse_token_string_t cmd_flow_director_filter =
8843         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8844                                  flow_director_filter, "flow_director_filter");
8845 cmdline_parse_token_num_t cmd_flow_director_port_id =
8846         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8847                               port_id, UINT8);
8848 cmdline_parse_token_string_t cmd_flow_director_ops =
8849         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8850                                  ops, "add#del#update");
8851 cmdline_parse_token_string_t cmd_flow_director_flow =
8852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8853                                  flow, "flow");
8854 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8855         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8856                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8857                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8858 cmdline_parse_token_string_t cmd_flow_director_ether =
8859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8860                                  ether, "ether");
8861 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8862         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8863                               ether_type, UINT16);
8864 cmdline_parse_token_string_t cmd_flow_director_src =
8865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8866                                  src, "src");
8867 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8868         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8869                                  ip_src);
8870 cmdline_parse_token_num_t cmd_flow_director_port_src =
8871         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8872                               port_src, UINT16);
8873 cmdline_parse_token_string_t cmd_flow_director_dst =
8874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8875                                  dst, "dst");
8876 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8877         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8878                                  ip_dst);
8879 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8880         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8881                               port_dst, UINT16);
8882 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8883         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8884                                   verify_tag, "verify_tag");
8885 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8886         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8887                               verify_tag_value, UINT32);
8888 cmdline_parse_token_string_t cmd_flow_director_tos =
8889         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8890                                  tos, "tos");
8891 cmdline_parse_token_num_t cmd_flow_director_tos_value =
8892         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8893                               tos_value, UINT8);
8894 cmdline_parse_token_string_t cmd_flow_director_proto =
8895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8896                                  proto, "proto");
8897 cmdline_parse_token_num_t cmd_flow_director_proto_value =
8898         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8899                               proto_value, UINT8);
8900 cmdline_parse_token_string_t cmd_flow_director_ttl =
8901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8902                                  ttl, "ttl");
8903 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
8904         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8905                               ttl_value, UINT8);
8906 cmdline_parse_token_string_t cmd_flow_director_vlan =
8907         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8908                                  vlan, "vlan");
8909 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8910         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8911                               vlan_value, UINT16);
8912 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8913         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8914                                  flexbytes, "flexbytes");
8915 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8916         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8917                               flexbytes_value, NULL);
8918 cmdline_parse_token_string_t cmd_flow_director_drop =
8919         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8920                                  drop, "drop#fwd");
8921 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8922         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8923                               pf_vf, NULL);
8924 cmdline_parse_token_string_t cmd_flow_director_queue =
8925         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8926                                  queue, "queue");
8927 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8928         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8929                               queue_id, UINT16);
8930 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8931         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8932                                  fd_id, "fd_id");
8933 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8934         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8935                               fd_id_value, UINT32);
8936
8937 cmdline_parse_token_string_t cmd_flow_director_mode =
8938         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8939                                  mode, "mode");
8940 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8942                                  mode_value, "IP");
8943 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8944         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8945                                  mode_value, "MAC-VLAN");
8946 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8947         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8948                                  mode_value, "Tunnel");
8949 cmdline_parse_token_string_t cmd_flow_director_mac =
8950         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8951                                  mac, "mac");
8952 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8953         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8954                                     mac_addr);
8955 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8956         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8957                                  tunnel, "tunnel");
8958 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8960                                  tunnel_type, "NVGRE#VxLAN");
8961 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8962         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8963                                  tunnel_id, "tunnel-id");
8964 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8965         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8966                               tunnel_id_value, UINT32);
8967
8968 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8969         .f = cmd_flow_director_filter_parsed,
8970         .data = NULL,
8971         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
8972                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
8973                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
8974                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
8975                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
8976                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
8977                 "fd_id <fd_id_value>: "
8978                 "Add or delete an ip flow director entry on NIC",
8979         .tokens = {
8980                 (void *)&cmd_flow_director_filter,
8981                 (void *)&cmd_flow_director_port_id,
8982                 (void *)&cmd_flow_director_mode,
8983                 (void *)&cmd_flow_director_mode_ip,
8984                 (void *)&cmd_flow_director_ops,
8985                 (void *)&cmd_flow_director_flow,
8986                 (void *)&cmd_flow_director_flow_type,
8987                 (void *)&cmd_flow_director_src,
8988                 (void *)&cmd_flow_director_ip_src,
8989                 (void *)&cmd_flow_director_dst,
8990                 (void *)&cmd_flow_director_ip_dst,
8991                 (void *)&cmd_flow_director_tos,
8992                 (void *)&cmd_flow_director_tos_value,
8993                 (void *)&cmd_flow_director_proto,
8994                 (void *)&cmd_flow_director_proto_value,
8995                 (void *)&cmd_flow_director_ttl,
8996                 (void *)&cmd_flow_director_ttl_value,
8997                 (void *)&cmd_flow_director_vlan,
8998                 (void *)&cmd_flow_director_vlan_value,
8999                 (void *)&cmd_flow_director_flexbytes,
9000                 (void *)&cmd_flow_director_flexbytes_value,
9001                 (void *)&cmd_flow_director_drop,
9002                 (void *)&cmd_flow_director_pf_vf,
9003                 (void *)&cmd_flow_director_queue,
9004                 (void *)&cmd_flow_director_queue_id,
9005                 (void *)&cmd_flow_director_fd_id,
9006                 (void *)&cmd_flow_director_fd_id_value,
9007                 NULL,
9008         },
9009 };
9010
9011 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9012         .f = cmd_flow_director_filter_parsed,
9013         .data = NULL,
9014         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9015                 "director entry on NIC",
9016         .tokens = {
9017                 (void *)&cmd_flow_director_filter,
9018                 (void *)&cmd_flow_director_port_id,
9019                 (void *)&cmd_flow_director_mode,
9020                 (void *)&cmd_flow_director_mode_ip,
9021                 (void *)&cmd_flow_director_ops,
9022                 (void *)&cmd_flow_director_flow,
9023                 (void *)&cmd_flow_director_flow_type,
9024                 (void *)&cmd_flow_director_src,
9025                 (void *)&cmd_flow_director_ip_src,
9026                 (void *)&cmd_flow_director_port_src,
9027                 (void *)&cmd_flow_director_dst,
9028                 (void *)&cmd_flow_director_ip_dst,
9029                 (void *)&cmd_flow_director_port_dst,
9030                 (void *)&cmd_flow_director_tos,
9031                 (void *)&cmd_flow_director_tos_value,
9032                 (void *)&cmd_flow_director_ttl,
9033                 (void *)&cmd_flow_director_ttl_value,
9034                 (void *)&cmd_flow_director_vlan,
9035                 (void *)&cmd_flow_director_vlan_value,
9036                 (void *)&cmd_flow_director_flexbytes,
9037                 (void *)&cmd_flow_director_flexbytes_value,
9038                 (void *)&cmd_flow_director_drop,
9039                 (void *)&cmd_flow_director_pf_vf,
9040                 (void *)&cmd_flow_director_queue,
9041                 (void *)&cmd_flow_director_queue_id,
9042                 (void *)&cmd_flow_director_fd_id,
9043                 (void *)&cmd_flow_director_fd_id_value,
9044                 NULL,
9045         },
9046 };
9047
9048 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9049         .f = cmd_flow_director_filter_parsed,
9050         .data = NULL,
9051         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9052                 "director entry on NIC",
9053         .tokens = {
9054                 (void *)&cmd_flow_director_filter,
9055                 (void *)&cmd_flow_director_port_id,
9056                 (void *)&cmd_flow_director_mode,
9057                 (void *)&cmd_flow_director_mode_ip,
9058                 (void *)&cmd_flow_director_ops,
9059                 (void *)&cmd_flow_director_flow,
9060                 (void *)&cmd_flow_director_flow_type,
9061                 (void *)&cmd_flow_director_src,
9062                 (void *)&cmd_flow_director_ip_src,
9063                 (void *)&cmd_flow_director_port_dst,
9064                 (void *)&cmd_flow_director_dst,
9065                 (void *)&cmd_flow_director_ip_dst,
9066                 (void *)&cmd_flow_director_port_dst,
9067                 (void *)&cmd_flow_director_verify_tag,
9068                 (void *)&cmd_flow_director_verify_tag_value,
9069                 (void *)&cmd_flow_director_tos,
9070                 (void *)&cmd_flow_director_tos_value,
9071                 (void *)&cmd_flow_director_ttl,
9072                 (void *)&cmd_flow_director_ttl_value,
9073                 (void *)&cmd_flow_director_vlan,
9074                 (void *)&cmd_flow_director_vlan_value,
9075                 (void *)&cmd_flow_director_flexbytes,
9076                 (void *)&cmd_flow_director_flexbytes_value,
9077                 (void *)&cmd_flow_director_drop,
9078                 (void *)&cmd_flow_director_pf_vf,
9079                 (void *)&cmd_flow_director_queue,
9080                 (void *)&cmd_flow_director_queue_id,
9081                 (void *)&cmd_flow_director_fd_id,
9082                 (void *)&cmd_flow_director_fd_id_value,
9083                 NULL,
9084         },
9085 };
9086
9087 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9088         .f = cmd_flow_director_filter_parsed,
9089         .data = NULL,
9090         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9091                 "director entry on NIC",
9092         .tokens = {
9093                 (void *)&cmd_flow_director_filter,
9094                 (void *)&cmd_flow_director_port_id,
9095                 (void *)&cmd_flow_director_mode,
9096                 (void *)&cmd_flow_director_mode_ip,
9097                 (void *)&cmd_flow_director_ops,
9098                 (void *)&cmd_flow_director_flow,
9099                 (void *)&cmd_flow_director_flow_type,
9100                 (void *)&cmd_flow_director_ether,
9101                 (void *)&cmd_flow_director_ether_type,
9102                 (void *)&cmd_flow_director_flexbytes,
9103                 (void *)&cmd_flow_director_flexbytes_value,
9104                 (void *)&cmd_flow_director_drop,
9105                 (void *)&cmd_flow_director_pf_vf,
9106                 (void *)&cmd_flow_director_queue,
9107                 (void *)&cmd_flow_director_queue_id,
9108                 (void *)&cmd_flow_director_fd_id,
9109                 (void *)&cmd_flow_director_fd_id_value,
9110                 NULL,
9111         },
9112 };
9113
9114 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9115         .f = cmd_flow_director_filter_parsed,
9116         .data = NULL,
9117         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9118                 "director entry on NIC",
9119         .tokens = {
9120                 (void *)&cmd_flow_director_filter,
9121                 (void *)&cmd_flow_director_port_id,
9122                 (void *)&cmd_flow_director_mode,
9123                 (void *)&cmd_flow_director_mode_mac_vlan,
9124                 (void *)&cmd_flow_director_ops,
9125                 (void *)&cmd_flow_director_mac,
9126                 (void *)&cmd_flow_director_mac_addr,
9127                 (void *)&cmd_flow_director_vlan,
9128                 (void *)&cmd_flow_director_vlan_value,
9129                 (void *)&cmd_flow_director_flexbytes,
9130                 (void *)&cmd_flow_director_flexbytes_value,
9131                 (void *)&cmd_flow_director_drop,
9132                 (void *)&cmd_flow_director_queue,
9133                 (void *)&cmd_flow_director_queue_id,
9134                 (void *)&cmd_flow_director_fd_id,
9135                 (void *)&cmd_flow_director_fd_id_value,
9136                 NULL,
9137         },
9138 };
9139
9140 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9141         .f = cmd_flow_director_filter_parsed,
9142         .data = NULL,
9143         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9144                 "director entry on NIC",
9145         .tokens = {
9146                 (void *)&cmd_flow_director_filter,
9147                 (void *)&cmd_flow_director_port_id,
9148                 (void *)&cmd_flow_director_mode,
9149                 (void *)&cmd_flow_director_mode_tunnel,
9150                 (void *)&cmd_flow_director_ops,
9151                 (void *)&cmd_flow_director_mac,
9152                 (void *)&cmd_flow_director_mac_addr,
9153                 (void *)&cmd_flow_director_vlan,
9154                 (void *)&cmd_flow_director_vlan_value,
9155                 (void *)&cmd_flow_director_tunnel,
9156                 (void *)&cmd_flow_director_tunnel_type,
9157                 (void *)&cmd_flow_director_tunnel_id,
9158                 (void *)&cmd_flow_director_tunnel_id_value,
9159                 (void *)&cmd_flow_director_flexbytes,
9160                 (void *)&cmd_flow_director_flexbytes_value,
9161                 (void *)&cmd_flow_director_drop,
9162                 (void *)&cmd_flow_director_queue,
9163                 (void *)&cmd_flow_director_queue_id,
9164                 (void *)&cmd_flow_director_fd_id,
9165                 (void *)&cmd_flow_director_fd_id_value,
9166                 NULL,
9167         },
9168 };
9169
9170 struct cmd_flush_flow_director_result {
9171         cmdline_fixed_string_t flush_flow_director;
9172         uint8_t port_id;
9173 };
9174
9175 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9176         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9177                                  flush_flow_director, "flush_flow_director");
9178 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9179         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9180                               port_id, UINT8);
9181
9182 static void
9183 cmd_flush_flow_director_parsed(void *parsed_result,
9184                           __attribute__((unused)) struct cmdline *cl,
9185                           __attribute__((unused)) void *data)
9186 {
9187         struct cmd_flow_director_result *res = parsed_result;
9188         int ret = 0;
9189
9190         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9191         if (ret < 0) {
9192                 printf("flow director is not supported on port %u.\n",
9193                         res->port_id);
9194                 return;
9195         }
9196
9197         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9198                         RTE_ETH_FILTER_FLUSH, NULL);
9199         if (ret < 0)
9200                 printf("flow director table flushing error: (%s)\n",
9201                         strerror(-ret));
9202 }
9203
9204 cmdline_parse_inst_t cmd_flush_flow_director = {
9205         .f = cmd_flush_flow_director_parsed,
9206         .data = NULL,
9207         .help_str = "flush_flow_director <port_id>: "
9208                 "Flush all flow director entries of a device on NIC",
9209         .tokens = {
9210                 (void *)&cmd_flush_flow_director_flush,
9211                 (void *)&cmd_flush_flow_director_port_id,
9212                 NULL,
9213         },
9214 };
9215
9216 /* *** deal with flow director mask *** */
9217 struct cmd_flow_director_mask_result {
9218         cmdline_fixed_string_t flow_director_mask;
9219         uint8_t port_id;
9220         cmdline_fixed_string_t mode;
9221         cmdline_fixed_string_t mode_value;
9222         cmdline_fixed_string_t vlan;
9223         uint16_t vlan_mask;
9224         cmdline_fixed_string_t src_mask;
9225         cmdline_ipaddr_t ipv4_src;
9226         cmdline_ipaddr_t ipv6_src;
9227         uint16_t port_src;
9228         cmdline_fixed_string_t dst_mask;
9229         cmdline_ipaddr_t ipv4_dst;
9230         cmdline_ipaddr_t ipv6_dst;
9231         uint16_t port_dst;
9232         cmdline_fixed_string_t mac;
9233         uint8_t mac_addr_byte_mask;
9234         cmdline_fixed_string_t tunnel_id;
9235         uint32_t tunnel_id_mask;
9236         cmdline_fixed_string_t tunnel_type;
9237         uint8_t tunnel_type_mask;
9238 };
9239
9240 static void
9241 cmd_flow_director_mask_parsed(void *parsed_result,
9242                           __attribute__((unused)) struct cmdline *cl,
9243                           __attribute__((unused)) void *data)
9244 {
9245         struct cmd_flow_director_mask_result *res = parsed_result;
9246         struct rte_eth_fdir_masks *mask;
9247         struct rte_port *port;
9248
9249         if (res->port_id > nb_ports) {
9250                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9251                 return;
9252         }
9253
9254         port = &ports[res->port_id];
9255         /** Check if the port is not started **/
9256         if (port->port_status != RTE_PORT_STOPPED) {
9257                 printf("Please stop port %d first\n", res->port_id);
9258                 return;
9259         }
9260
9261         mask = &port->dev_conf.fdir_conf.mask;
9262
9263         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9264                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9265                         printf("Please set mode to MAC-VLAN.\n");
9266                         return;
9267                 }
9268
9269                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9270         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9271                 if (strcmp(res->mode_value, "Tunnel")) {
9272                         printf("Please set mode to Tunnel.\n");
9273                         return;
9274                 }
9275
9276                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9277                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9278                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9279                 mask->tunnel_type_mask = res->tunnel_type_mask;
9280         } else {
9281                 if (strcmp(res->mode_value, "IP")) {
9282                         printf("Please set mode to IP.\n");
9283                         return;
9284                 }
9285
9286                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9287                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9288                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9289                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9290                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9291                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9292                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9293         }
9294
9295         cmd_reconfig_device_queue(res->port_id, 1, 1);
9296 }
9297
9298 cmdline_parse_token_string_t cmd_flow_director_mask =
9299         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9300                                  flow_director_mask, "flow_director_mask");
9301 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9302         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9303                               port_id, UINT8);
9304 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9305         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9306                                  vlan, "vlan");
9307 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9308         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9309                               vlan_mask, UINT16);
9310 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9311         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9312                                  src_mask, "src_mask");
9313 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9314         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9315                                  ipv4_src);
9316 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9317         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9318                                  ipv6_src);
9319 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9320         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9321                               port_src, UINT16);
9322 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9323         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9324                                  dst_mask, "dst_mask");
9325 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9326         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9327                                  ipv4_dst);
9328 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9329         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9330                                  ipv6_dst);
9331 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9332         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9333                               port_dst, UINT16);
9334
9335 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9337                                  mode, "mode");
9338 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9340                                  mode_value, "IP");
9341 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9343                                  mode_value, "MAC-VLAN");
9344 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9345         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9346                                  mode_value, "Tunnel");
9347 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9349                                  mac, "mac");
9350 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9351         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9352                               mac_addr_byte_mask, UINT8);
9353 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9355                                  tunnel_type, "tunnel-type");
9356 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9357         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9358                               tunnel_type_mask, UINT8);
9359 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9360         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9361                                  tunnel_id, "tunnel-id");
9362 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9363         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9364                               tunnel_id_mask, UINT32);
9365
9366 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9367         .f = cmd_flow_director_mask_parsed,
9368         .data = NULL,
9369         .help_str = "flow_director_mask ... : "
9370                 "Set IP mode flow director's mask on NIC",
9371         .tokens = {
9372                 (void *)&cmd_flow_director_mask,
9373                 (void *)&cmd_flow_director_mask_port_id,
9374                 (void *)&cmd_flow_director_mask_mode,
9375                 (void *)&cmd_flow_director_mask_mode_ip,
9376                 (void *)&cmd_flow_director_mask_vlan,
9377                 (void *)&cmd_flow_director_mask_vlan_value,
9378                 (void *)&cmd_flow_director_mask_src,
9379                 (void *)&cmd_flow_director_mask_ipv4_src,
9380                 (void *)&cmd_flow_director_mask_ipv6_src,
9381                 (void *)&cmd_flow_director_mask_port_src,
9382                 (void *)&cmd_flow_director_mask_dst,
9383                 (void *)&cmd_flow_director_mask_ipv4_dst,
9384                 (void *)&cmd_flow_director_mask_ipv6_dst,
9385                 (void *)&cmd_flow_director_mask_port_dst,
9386                 NULL,
9387         },
9388 };
9389
9390 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9391         .f = cmd_flow_director_mask_parsed,
9392         .data = NULL,
9393         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9394                 "flow director's mask on NIC",
9395         .tokens = {
9396                 (void *)&cmd_flow_director_mask,
9397                 (void *)&cmd_flow_director_mask_port_id,
9398                 (void *)&cmd_flow_director_mask_mode,
9399                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9400                 (void *)&cmd_flow_director_mask_vlan,
9401                 (void *)&cmd_flow_director_mask_vlan_value,
9402                 NULL,
9403         },
9404 };
9405
9406 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9407         .f = cmd_flow_director_mask_parsed,
9408         .data = NULL,
9409         .help_str = "flow_director_mask ... : Set tunnel mode "
9410                 "flow director's mask on NIC",
9411         .tokens = {
9412                 (void *)&cmd_flow_director_mask,
9413                 (void *)&cmd_flow_director_mask_port_id,
9414                 (void *)&cmd_flow_director_mask_mode,
9415                 (void *)&cmd_flow_director_mask_mode_tunnel,
9416                 (void *)&cmd_flow_director_mask_vlan,
9417                 (void *)&cmd_flow_director_mask_vlan_value,
9418                 (void *)&cmd_flow_director_mask_mac,
9419                 (void *)&cmd_flow_director_mask_mac_value,
9420                 (void *)&cmd_flow_director_mask_tunnel_type,
9421                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9422                 (void *)&cmd_flow_director_mask_tunnel_id,
9423                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9424                 NULL,
9425         },
9426 };
9427
9428 /* *** deal with flow director mask on flexible payload *** */
9429 struct cmd_flow_director_flex_mask_result {
9430         cmdline_fixed_string_t flow_director_flexmask;
9431         uint8_t port_id;
9432         cmdline_fixed_string_t flow;
9433         cmdline_fixed_string_t flow_type;
9434         cmdline_fixed_string_t mask;
9435 };
9436
9437 static void
9438 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9439                           __attribute__((unused)) struct cmdline *cl,
9440                           __attribute__((unused)) void *data)
9441 {
9442         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9443         struct rte_eth_fdir_info fdir_info;
9444         struct rte_eth_fdir_flex_mask flex_mask;
9445         struct rte_port *port;
9446         uint32_t flow_type_mask;
9447         uint16_t i;
9448         int ret;
9449
9450         if (res->port_id > nb_ports) {
9451                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9452                 return;
9453         }
9454
9455         port = &ports[res->port_id];
9456         /** Check if the port is not started **/
9457         if (port->port_status != RTE_PORT_STOPPED) {
9458                 printf("Please stop port %d first\n", res->port_id);
9459                 return;
9460         }
9461
9462         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9463         ret = parse_flexbytes(res->mask,
9464                         flex_mask.mask,
9465                         RTE_ETH_FDIR_MAX_FLEXLEN);
9466         if (ret < 0) {
9467                 printf("error: Cannot parse mask input.\n");
9468                 return;
9469         }
9470
9471         memset(&fdir_info, 0, sizeof(fdir_info));
9472         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9473                                 RTE_ETH_FILTER_INFO, &fdir_info);
9474         if (ret < 0) {
9475                 printf("Cannot get FDir filter info\n");
9476                 return;
9477         }
9478
9479         if (!strcmp(res->flow_type, "none")) {
9480                 /* means don't specify the flow type */
9481                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9482                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9483                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9484                                0, sizeof(struct rte_eth_fdir_flex_mask));
9485                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9486                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9487                                  &flex_mask,
9488                                  sizeof(struct rte_eth_fdir_flex_mask));
9489                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9490                 return;
9491         }
9492         flow_type_mask = fdir_info.flow_types_mask[0];
9493         if (!strcmp(res->flow_type, "all")) {
9494                 if (!flow_type_mask) {
9495                         printf("No flow type supported\n");
9496                         return;
9497                 }
9498                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9499                         if (flow_type_mask & (1 << i)) {
9500                                 flex_mask.flow_type = i;
9501                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9502                         }
9503                 }
9504                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9505                 return;
9506         }
9507         flex_mask.flow_type = str2flowtype(res->flow_type);
9508         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9509                 printf("Flow type %s not supported on port %d\n",
9510                                 res->flow_type, res->port_id);
9511                 return;
9512         }
9513         fdir_set_flex_mask(res->port_id, &flex_mask);
9514         cmd_reconfig_device_queue(res->port_id, 1, 1);
9515 }
9516
9517 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9518         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9519                                  flow_director_flexmask,
9520                                  "flow_director_flex_mask");
9521 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9522         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9523                               port_id, UINT8);
9524 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9525         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9526                                  flow, "flow");
9527 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9528         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9529                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9530                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9531 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9532         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9533                                  mask, NULL);
9534
9535 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9536         .f = cmd_flow_director_flex_mask_parsed,
9537         .data = NULL,
9538         .help_str = "flow_director_flex_mask ... : "
9539                 "Set flow director's flex mask on NIC",
9540         .tokens = {
9541                 (void *)&cmd_flow_director_flexmask,
9542                 (void *)&cmd_flow_director_flexmask_port_id,
9543                 (void *)&cmd_flow_director_flexmask_flow,
9544                 (void *)&cmd_flow_director_flexmask_flow_type,
9545                 (void *)&cmd_flow_director_flexmask_mask,
9546                 NULL,
9547         },
9548 };
9549
9550 /* *** deal with flow director flexible payload configuration *** */
9551 struct cmd_flow_director_flexpayload_result {
9552         cmdline_fixed_string_t flow_director_flexpayload;
9553         uint8_t port_id;
9554         cmdline_fixed_string_t payload_layer;
9555         cmdline_fixed_string_t payload_cfg;
9556 };
9557
9558 static inline int
9559 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9560 {
9561         char s[256];
9562         const char *p, *p0 = q_arg;
9563         char *end;
9564         unsigned long int_fld;
9565         char *str_fld[max_num];
9566         int i;
9567         unsigned size;
9568         int ret = -1;
9569
9570         p = strchr(p0, '(');
9571         if (p == NULL)
9572                 return -1;
9573         ++p;
9574         p0 = strchr(p, ')');
9575         if (p0 == NULL)
9576                 return -1;
9577
9578         size = p0 - p;
9579         if (size >= sizeof(s))
9580                 return -1;
9581
9582         snprintf(s, sizeof(s), "%.*s", size, p);
9583         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9584         if (ret < 0 || ret > max_num)
9585                 return -1;
9586         for (i = 0; i < ret; i++) {
9587                 errno = 0;
9588                 int_fld = strtoul(str_fld[i], &end, 0);
9589                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9590                         return -1;
9591                 offsets[i] = (uint16_t)int_fld;
9592         }
9593         return ret;
9594 }
9595
9596 static void
9597 cmd_flow_director_flxpld_parsed(void *parsed_result,
9598                           __attribute__((unused)) struct cmdline *cl,
9599                           __attribute__((unused)) void *data)
9600 {
9601         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9602         struct rte_eth_flex_payload_cfg flex_cfg;
9603         struct rte_port *port;
9604         int ret = 0;
9605
9606         if (res->port_id > nb_ports) {
9607                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9608                 return;
9609         }
9610
9611         port = &ports[res->port_id];
9612         /** Check if the port is not started **/
9613         if (port->port_status != RTE_PORT_STOPPED) {
9614                 printf("Please stop port %d first\n", res->port_id);
9615                 return;
9616         }
9617
9618         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9619
9620         if (!strcmp(res->payload_layer, "raw"))
9621                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9622         else if (!strcmp(res->payload_layer, "l2"))
9623                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9624         else if (!strcmp(res->payload_layer, "l3"))
9625                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9626         else if (!strcmp(res->payload_layer, "l4"))
9627                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9628
9629         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9630                             RTE_ETH_FDIR_MAX_FLEXLEN);
9631         if (ret < 0) {
9632                 printf("error: Cannot parse flex payload input.\n");
9633                 return;
9634         }
9635
9636         fdir_set_flex_payload(res->port_id, &flex_cfg);
9637         cmd_reconfig_device_queue(res->port_id, 1, 1);
9638 }
9639
9640 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9642                                  flow_director_flexpayload,
9643                                  "flow_director_flex_payload");
9644 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9645         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9646                               port_id, UINT8);
9647 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9649                                  payload_layer, "raw#l2#l3#l4");
9650 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9652                                  payload_cfg, NULL);
9653
9654 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9655         .f = cmd_flow_director_flxpld_parsed,
9656         .data = NULL,
9657         .help_str = "flow_director_flexpayload ... : "
9658                 "Set flow director's flex payload on NIC",
9659         .tokens = {
9660                 (void *)&cmd_flow_director_flexpayload,
9661                 (void *)&cmd_flow_director_flexpayload_port_id,
9662                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9663                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9664                 NULL,
9665         },
9666 };
9667
9668 /* Generic flow interface command. */
9669 extern cmdline_parse_inst_t cmd_flow;
9670
9671 /* *** Classification Filters Control *** */
9672 /* *** Get symmetric hash enable per port *** */
9673 struct cmd_get_sym_hash_ena_per_port_result {
9674         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9675         uint8_t port_id;
9676 };
9677
9678 static void
9679 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9680                                  __rte_unused struct cmdline *cl,
9681                                  __rte_unused void *data)
9682 {
9683         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9684         struct rte_eth_hash_filter_info info;
9685         int ret;
9686
9687         if (rte_eth_dev_filter_supported(res->port_id,
9688                                 RTE_ETH_FILTER_HASH) < 0) {
9689                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9690                                                         res->port_id);
9691                 return;
9692         }
9693
9694         memset(&info, 0, sizeof(info));
9695         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9696         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9697                                                 RTE_ETH_FILTER_GET, &info);
9698
9699         if (ret < 0) {
9700                 printf("Cannot get symmetric hash enable per port "
9701                                         "on port %u\n", res->port_id);
9702                 return;
9703         }
9704
9705         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9706                                 "enabled" : "disabled", res->port_id);
9707 }
9708
9709 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9710         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9711                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9712 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9713         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9714                 port_id, UINT8);
9715
9716 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9717         .f = cmd_get_sym_hash_per_port_parsed,
9718         .data = NULL,
9719         .help_str = "get_sym_hash_ena_per_port <port_id>",
9720         .tokens = {
9721                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9722                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9723                 NULL,
9724         },
9725 };
9726
9727 /* *** Set symmetric hash enable per port *** */
9728 struct cmd_set_sym_hash_ena_per_port_result {
9729         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9730         cmdline_fixed_string_t enable;
9731         uint8_t port_id;
9732 };
9733
9734 static void
9735 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9736                                  __rte_unused struct cmdline *cl,
9737                                  __rte_unused void *data)
9738 {
9739         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9740         struct rte_eth_hash_filter_info info;
9741         int ret;
9742
9743         if (rte_eth_dev_filter_supported(res->port_id,
9744                                 RTE_ETH_FILTER_HASH) < 0) {
9745                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9746                                                         res->port_id);
9747                 return;
9748         }
9749
9750         memset(&info, 0, sizeof(info));
9751         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9752         if (!strcmp(res->enable, "enable"))
9753                 info.info.enable = 1;
9754         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9755                                         RTE_ETH_FILTER_SET, &info);
9756         if (ret < 0) {
9757                 printf("Cannot set symmetric hash enable per port on "
9758                                         "port %u\n", res->port_id);
9759                 return;
9760         }
9761         printf("Symmetric hash has been set to %s on port %u\n",
9762                                         res->enable, res->port_id);
9763 }
9764
9765 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9766         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9767                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9768 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9769         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9770                 port_id, UINT8);
9771 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9772         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9773                 enable, "enable#disable");
9774
9775 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9776         .f = cmd_set_sym_hash_per_port_parsed,
9777         .data = NULL,
9778         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
9779         .tokens = {
9780                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9781                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9782                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9783                 NULL,
9784         },
9785 };
9786
9787 /* Get global config of hash function */
9788 struct cmd_get_hash_global_config_result {
9789         cmdline_fixed_string_t get_hash_global_config;
9790         uint8_t port_id;
9791 };
9792
9793 static char *
9794 flowtype_to_str(uint16_t ftype)
9795 {
9796         uint16_t i;
9797         static struct {
9798                 char str[16];
9799                 uint16_t ftype;
9800         } ftype_table[] = {
9801                 {"ipv4", RTE_ETH_FLOW_IPV4},
9802                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9803                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9804                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9805                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9806                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9807                 {"ipv6", RTE_ETH_FLOW_IPV6},
9808                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9809                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9810                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9811                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9812                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9813                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9814                 {"port", RTE_ETH_FLOW_PORT},
9815                 {"vxlan", RTE_ETH_FLOW_VXLAN},
9816                 {"geneve", RTE_ETH_FLOW_GENEVE},
9817                 {"nvgre", RTE_ETH_FLOW_NVGRE},
9818         };
9819
9820         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9821                 if (ftype_table[i].ftype == ftype)
9822                         return ftype_table[i].str;
9823         }
9824
9825         return NULL;
9826 }
9827
9828 static void
9829 cmd_get_hash_global_config_parsed(void *parsed_result,
9830                                   __rte_unused struct cmdline *cl,
9831                                   __rte_unused void *data)
9832 {
9833         struct cmd_get_hash_global_config_result *res = parsed_result;
9834         struct rte_eth_hash_filter_info info;
9835         uint32_t idx, offset;
9836         uint16_t i;
9837         char *str;
9838         int ret;
9839
9840         if (rte_eth_dev_filter_supported(res->port_id,
9841                         RTE_ETH_FILTER_HASH) < 0) {
9842                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9843                                                         res->port_id);
9844                 return;
9845         }
9846
9847         memset(&info, 0, sizeof(info));
9848         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9849         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9850                                         RTE_ETH_FILTER_GET, &info);
9851         if (ret < 0) {
9852                 printf("Cannot get hash global configurations by port %d\n",
9853                                                         res->port_id);
9854                 return;
9855         }
9856
9857         switch (info.info.global_conf.hash_func) {
9858         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9859                 printf("Hash function is Toeplitz\n");
9860                 break;
9861         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9862                 printf("Hash function is Simple XOR\n");
9863                 break;
9864         default:
9865                 printf("Unknown hash function\n");
9866                 break;
9867         }
9868
9869         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9870                 idx = i / UINT32_BIT;
9871                 offset = i % UINT32_BIT;
9872                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9873                                                 (1UL << offset)))
9874                         continue;
9875                 str = flowtype_to_str(i);
9876                 if (!str)
9877                         continue;
9878                 printf("Symmetric hash is %s globally for flow type %s "
9879                                                         "by port %d\n",
9880                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9881                         (1UL << offset)) ? "enabled" : "disabled"), str,
9882                                                         res->port_id);
9883         }
9884 }
9885
9886 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9887         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9888                 get_hash_global_config, "get_hash_global_config");
9889 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9890         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9891                 port_id, UINT8);
9892
9893 cmdline_parse_inst_t cmd_get_hash_global_config = {
9894         .f = cmd_get_hash_global_config_parsed,
9895         .data = NULL,
9896         .help_str = "get_hash_global_config <port_id>",
9897         .tokens = {
9898                 (void *)&cmd_get_hash_global_config_all,
9899                 (void *)&cmd_get_hash_global_config_port_id,
9900                 NULL,
9901         },
9902 };
9903
9904 /* Set global config of hash function */
9905 struct cmd_set_hash_global_config_result {
9906         cmdline_fixed_string_t set_hash_global_config;
9907         uint8_t port_id;
9908         cmdline_fixed_string_t hash_func;
9909         cmdline_fixed_string_t flow_type;
9910         cmdline_fixed_string_t enable;
9911 };
9912
9913 static void
9914 cmd_set_hash_global_config_parsed(void *parsed_result,
9915                                   __rte_unused struct cmdline *cl,
9916                                   __rte_unused void *data)
9917 {
9918         struct cmd_set_hash_global_config_result *res = parsed_result;
9919         struct rte_eth_hash_filter_info info;
9920         uint32_t ftype, idx, offset;
9921         int ret;
9922
9923         if (rte_eth_dev_filter_supported(res->port_id,
9924                                 RTE_ETH_FILTER_HASH) < 0) {
9925                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9926                                                         res->port_id);
9927                 return;
9928         }
9929         memset(&info, 0, sizeof(info));
9930         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9931         if (!strcmp(res->hash_func, "toeplitz"))
9932                 info.info.global_conf.hash_func =
9933                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9934         else if (!strcmp(res->hash_func, "simple_xor"))
9935                 info.info.global_conf.hash_func =
9936                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9937         else if (!strcmp(res->hash_func, "default"))
9938                 info.info.global_conf.hash_func =
9939                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9940
9941         ftype = str2flowtype(res->flow_type);
9942         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9943         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9944         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9945         if (!strcmp(res->enable, "enable"))
9946                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9947                                                 (1UL << offset);
9948         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9949                                         RTE_ETH_FILTER_SET, &info);
9950         if (ret < 0)
9951                 printf("Cannot set global hash configurations by port %d\n",
9952                                                         res->port_id);
9953         else
9954                 printf("Global hash configurations have been set "
9955                         "succcessfully by port %d\n", res->port_id);
9956 }
9957
9958 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9959         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9960                 set_hash_global_config, "set_hash_global_config");
9961 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9962         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9963                 port_id, UINT8);
9964 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9965         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9966                 hash_func, "toeplitz#simple_xor#default");
9967 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9968         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9969                 flow_type,
9970                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9971                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9972 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9973         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9974                 enable, "enable#disable");
9975
9976 cmdline_parse_inst_t cmd_set_hash_global_config = {
9977         .f = cmd_set_hash_global_config_parsed,
9978         .data = NULL,
9979         .help_str = "set_hash_global_config <port_id> "
9980                 "toeplitz|simple_xor|default "
9981                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
9982                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
9983                 "l2_payload enable|disable",
9984         .tokens = {
9985                 (void *)&cmd_set_hash_global_config_all,
9986                 (void *)&cmd_set_hash_global_config_port_id,
9987                 (void *)&cmd_set_hash_global_config_hash_func,
9988                 (void *)&cmd_set_hash_global_config_flow_type,
9989                 (void *)&cmd_set_hash_global_config_enable,
9990                 NULL,
9991         },
9992 };
9993
9994 /* Set hash input set */
9995 struct cmd_set_hash_input_set_result {
9996         cmdline_fixed_string_t set_hash_input_set;
9997         uint8_t port_id;
9998         cmdline_fixed_string_t flow_type;
9999         cmdline_fixed_string_t inset_field;
10000         cmdline_fixed_string_t select;
10001 };
10002
10003 static enum rte_eth_input_set_field
10004 str2inset(char *string)
10005 {
10006         uint16_t i;
10007
10008         static const struct {
10009                 char str[32];
10010                 enum rte_eth_input_set_field inset;
10011         } inset_table[] = {
10012                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10013                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10014                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10015                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10016                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10017                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10018                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10019                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10020                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10021                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10022                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10023                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10024                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10025                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10026                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10027                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10028                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10029                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10030                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10031                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10032                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10033                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10034                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10035                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10036                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10037                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10038                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10039                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10040                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10041                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10042                 {"none", RTE_ETH_INPUT_SET_NONE},
10043         };
10044
10045         for (i = 0; i < RTE_DIM(inset_table); i++) {
10046                 if (!strcmp(string, inset_table[i].str))
10047                         return inset_table[i].inset;
10048         }
10049
10050         return RTE_ETH_INPUT_SET_UNKNOWN;
10051 }
10052
10053 static void
10054 cmd_set_hash_input_set_parsed(void *parsed_result,
10055                               __rte_unused struct cmdline *cl,
10056                               __rte_unused void *data)
10057 {
10058         struct cmd_set_hash_input_set_result *res = parsed_result;
10059         struct rte_eth_hash_filter_info info;
10060
10061         memset(&info, 0, sizeof(info));
10062         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10063         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10064         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10065         info.info.input_set_conf.inset_size = 1;
10066         if (!strcmp(res->select, "select"))
10067                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10068         else if (!strcmp(res->select, "add"))
10069                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10070         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10071                                 RTE_ETH_FILTER_SET, &info);
10072 }
10073
10074 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10075         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10076                 set_hash_input_set, "set_hash_input_set");
10077 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10078         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10079                 port_id, UINT8);
10080 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10081         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10082                 flow_type,
10083                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10084                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10085 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10086         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10087                 inset_field,
10088                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10089                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10090                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10091                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10092                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10093                 "fld-8th#none");
10094 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10095         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10096                 select, "select#add");
10097
10098 cmdline_parse_inst_t cmd_set_hash_input_set = {
10099         .f = cmd_set_hash_input_set_parsed,
10100         .data = NULL,
10101         .help_str = "set_hash_input_set <port_id> "
10102         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10103         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10104         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10105         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10106         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10107         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10108         "fld-7th|fld-8th|none select|add",
10109         .tokens = {
10110                 (void *)&cmd_set_hash_input_set_cmd,
10111                 (void *)&cmd_set_hash_input_set_port_id,
10112                 (void *)&cmd_set_hash_input_set_flow_type,
10113                 (void *)&cmd_set_hash_input_set_field,
10114                 (void *)&cmd_set_hash_input_set_select,
10115                 NULL,
10116         },
10117 };
10118
10119 /* Set flow director input set */
10120 struct cmd_set_fdir_input_set_result {
10121         cmdline_fixed_string_t set_fdir_input_set;
10122         uint8_t port_id;
10123         cmdline_fixed_string_t flow_type;
10124         cmdline_fixed_string_t inset_field;
10125         cmdline_fixed_string_t select;
10126 };
10127
10128 static void
10129 cmd_set_fdir_input_set_parsed(void *parsed_result,
10130         __rte_unused struct cmdline *cl,
10131         __rte_unused void *data)
10132 {
10133         struct cmd_set_fdir_input_set_result *res = parsed_result;
10134         struct rte_eth_fdir_filter_info info;
10135
10136         memset(&info, 0, sizeof(info));
10137         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10138         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10139         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10140         info.info.input_set_conf.inset_size = 1;
10141         if (!strcmp(res->select, "select"))
10142                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10143         else if (!strcmp(res->select, "add"))
10144                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10145         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10146                 RTE_ETH_FILTER_SET, &info);
10147 }
10148
10149 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10150         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10151         set_fdir_input_set, "set_fdir_input_set");
10152 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10153         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10154         port_id, UINT8);
10155 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10156         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10157         flow_type,
10158         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10159         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10160 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10161         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10162         inset_field,
10163         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10164         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10165         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10166         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10167         "sctp-veri-tag#none");
10168 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10169         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10170         select, "select#add");
10171
10172 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10173         .f = cmd_set_fdir_input_set_parsed,
10174         .data = NULL,
10175         .help_str = "set_fdir_input_set <port_id> "
10176         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10177         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10178         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10179         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10180         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10181         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10182         "sctp-veri-tag|none select|add",
10183         .tokens = {
10184                 (void *)&cmd_set_fdir_input_set_cmd,
10185                 (void *)&cmd_set_fdir_input_set_port_id,
10186                 (void *)&cmd_set_fdir_input_set_flow_type,
10187                 (void *)&cmd_set_fdir_input_set_field,
10188                 (void *)&cmd_set_fdir_input_set_select,
10189                 NULL,
10190         },
10191 };
10192
10193 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10194 struct cmd_mcast_addr_result {
10195         cmdline_fixed_string_t mcast_addr_cmd;
10196         cmdline_fixed_string_t what;
10197         uint8_t port_num;
10198         struct ether_addr mc_addr;
10199 };
10200
10201 static void cmd_mcast_addr_parsed(void *parsed_result,
10202                 __attribute__((unused)) struct cmdline *cl,
10203                 __attribute__((unused)) void *data)
10204 {
10205         struct cmd_mcast_addr_result *res = parsed_result;
10206
10207         if (!is_multicast_ether_addr(&res->mc_addr)) {
10208                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10209                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10210                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10211                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10212                 return;
10213         }
10214         if (strcmp(res->what, "add") == 0)
10215                 mcast_addr_add(res->port_num, &res->mc_addr);
10216         else
10217                 mcast_addr_remove(res->port_num, &res->mc_addr);
10218 }
10219
10220 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10221         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10222                                  mcast_addr_cmd, "mcast_addr");
10223 cmdline_parse_token_string_t cmd_mcast_addr_what =
10224         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10225                                  "add#remove");
10226 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10227         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10228 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10229         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10230
10231 cmdline_parse_inst_t cmd_mcast_addr = {
10232         .f = cmd_mcast_addr_parsed,
10233         .data = (void *)0,
10234         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10235                 "Add/Remove multicast MAC address on port_id",
10236         .tokens = {
10237                 (void *)&cmd_mcast_addr_cmd,
10238                 (void *)&cmd_mcast_addr_what,
10239                 (void *)&cmd_mcast_addr_portnum,
10240                 (void *)&cmd_mcast_addr_addr,
10241                 NULL,
10242         },
10243 };
10244
10245 /* l2 tunnel config
10246  * only support E-tag now.
10247  */
10248
10249 /* Ether type config */
10250 struct cmd_config_l2_tunnel_eth_type_result {
10251         cmdline_fixed_string_t port;
10252         cmdline_fixed_string_t config;
10253         cmdline_fixed_string_t all;
10254         uint8_t id;
10255         cmdline_fixed_string_t l2_tunnel;
10256         cmdline_fixed_string_t l2_tunnel_type;
10257         cmdline_fixed_string_t eth_type;
10258         uint16_t eth_type_val;
10259 };
10260
10261 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10262         TOKEN_STRING_INITIALIZER
10263                 (struct cmd_config_l2_tunnel_eth_type_result,
10264                  port, "port");
10265 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10266         TOKEN_STRING_INITIALIZER
10267                 (struct cmd_config_l2_tunnel_eth_type_result,
10268                  config, "config");
10269 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10270         TOKEN_STRING_INITIALIZER
10271                 (struct cmd_config_l2_tunnel_eth_type_result,
10272                  all, "all");
10273 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10274         TOKEN_NUM_INITIALIZER
10275                 (struct cmd_config_l2_tunnel_eth_type_result,
10276                  id, UINT8);
10277 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10278         TOKEN_STRING_INITIALIZER
10279                 (struct cmd_config_l2_tunnel_eth_type_result,
10280                  l2_tunnel, "l2-tunnel");
10281 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10282         TOKEN_STRING_INITIALIZER
10283                 (struct cmd_config_l2_tunnel_eth_type_result,
10284                  l2_tunnel_type, "E-tag");
10285 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10286         TOKEN_STRING_INITIALIZER
10287                 (struct cmd_config_l2_tunnel_eth_type_result,
10288                  eth_type, "ether-type");
10289 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10290         TOKEN_NUM_INITIALIZER
10291                 (struct cmd_config_l2_tunnel_eth_type_result,
10292                  eth_type_val, UINT16);
10293
10294 static enum rte_eth_tunnel_type
10295 str2fdir_l2_tunnel_type(char *string)
10296 {
10297         uint32_t i = 0;
10298
10299         static const struct {
10300                 char str[32];
10301                 enum rte_eth_tunnel_type type;
10302         } l2_tunnel_type_str[] = {
10303                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10304         };
10305
10306         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10307                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10308                         return l2_tunnel_type_str[i].type;
10309         }
10310         return RTE_TUNNEL_TYPE_NONE;
10311 }
10312
10313 /* ether type config for all ports */
10314 static void
10315 cmd_config_l2_tunnel_eth_type_all_parsed
10316         (void *parsed_result,
10317          __attribute__((unused)) struct cmdline *cl,
10318          __attribute__((unused)) void *data)
10319 {
10320         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10321         struct rte_eth_l2_tunnel_conf entry;
10322         portid_t pid;
10323
10324         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10325         entry.ether_type = res->eth_type_val;
10326
10327         FOREACH_PORT(pid, ports) {
10328                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10329         }
10330 }
10331
10332 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10333         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10334         .data = NULL,
10335         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10336         .tokens = {
10337                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10338                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10339                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10340                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10341                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10342                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10343                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10344                 NULL,
10345         },
10346 };
10347
10348 /* ether type config for a specific port */
10349 static void
10350 cmd_config_l2_tunnel_eth_type_specific_parsed(
10351         void *parsed_result,
10352         __attribute__((unused)) struct cmdline *cl,
10353         __attribute__((unused)) void *data)
10354 {
10355         struct cmd_config_l2_tunnel_eth_type_result *res =
10356                  parsed_result;
10357         struct rte_eth_l2_tunnel_conf entry;
10358
10359         if (port_id_is_invalid(res->id, ENABLED_WARN))
10360                 return;
10361
10362         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10363         entry.ether_type = res->eth_type_val;
10364
10365         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10366 }
10367
10368 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10369         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10370         .data = NULL,
10371         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10372         .tokens = {
10373                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10374                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10375                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10376                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10377                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10378                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10379                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10380                 NULL,
10381         },
10382 };
10383
10384 /* Enable/disable l2 tunnel */
10385 struct cmd_config_l2_tunnel_en_dis_result {
10386         cmdline_fixed_string_t port;
10387         cmdline_fixed_string_t config;
10388         cmdline_fixed_string_t all;
10389         uint8_t id;
10390         cmdline_fixed_string_t l2_tunnel;
10391         cmdline_fixed_string_t l2_tunnel_type;
10392         cmdline_fixed_string_t en_dis;
10393 };
10394
10395 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10396         TOKEN_STRING_INITIALIZER
10397                 (struct cmd_config_l2_tunnel_en_dis_result,
10398                  port, "port");
10399 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10400         TOKEN_STRING_INITIALIZER
10401                 (struct cmd_config_l2_tunnel_en_dis_result,
10402                  config, "config");
10403 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10404         TOKEN_STRING_INITIALIZER
10405                 (struct cmd_config_l2_tunnel_en_dis_result,
10406                  all, "all");
10407 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10408         TOKEN_NUM_INITIALIZER
10409                 (struct cmd_config_l2_tunnel_en_dis_result,
10410                  id, UINT8);
10411 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10412         TOKEN_STRING_INITIALIZER
10413                 (struct cmd_config_l2_tunnel_en_dis_result,
10414                  l2_tunnel, "l2-tunnel");
10415 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10416         TOKEN_STRING_INITIALIZER
10417                 (struct cmd_config_l2_tunnel_en_dis_result,
10418                  l2_tunnel_type, "E-tag");
10419 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10420         TOKEN_STRING_INITIALIZER
10421                 (struct cmd_config_l2_tunnel_en_dis_result,
10422                  en_dis, "enable#disable");
10423
10424 /* enable/disable l2 tunnel for all ports */
10425 static void
10426 cmd_config_l2_tunnel_en_dis_all_parsed(
10427         void *parsed_result,
10428         __attribute__((unused)) struct cmdline *cl,
10429         __attribute__((unused)) void *data)
10430 {
10431         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10432         struct rte_eth_l2_tunnel_conf entry;
10433         portid_t pid;
10434         uint8_t en;
10435
10436         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10437
10438         if (!strcmp("enable", res->en_dis))
10439                 en = 1;
10440         else
10441                 en = 0;
10442
10443         FOREACH_PORT(pid, ports) {
10444                 rte_eth_dev_l2_tunnel_offload_set(pid,
10445                                                   &entry,
10446                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10447                                                   en);
10448         }
10449 }
10450
10451 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10452         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10453         .data = NULL,
10454         .help_str = "port config all l2-tunnel E-tag enable|disable",
10455         .tokens = {
10456                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10457                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10458                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10459                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10460                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10461                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10462                 NULL,
10463         },
10464 };
10465
10466 /* enable/disable l2 tunnel for a port */
10467 static void
10468 cmd_config_l2_tunnel_en_dis_specific_parsed(
10469         void *parsed_result,
10470         __attribute__((unused)) struct cmdline *cl,
10471         __attribute__((unused)) void *data)
10472 {
10473         struct cmd_config_l2_tunnel_en_dis_result *res =
10474                 parsed_result;
10475         struct rte_eth_l2_tunnel_conf entry;
10476
10477         if (port_id_is_invalid(res->id, ENABLED_WARN))
10478                 return;
10479
10480         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10481
10482         if (!strcmp("enable", res->en_dis))
10483                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10484                                                   &entry,
10485                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10486                                                   1);
10487         else
10488                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10489                                                   &entry,
10490                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10491                                                   0);
10492 }
10493
10494 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10495         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10496         .data = NULL,
10497         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10498         .tokens = {
10499                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10500                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10501                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10502                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10503                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10504                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10505                 NULL,
10506         },
10507 };
10508
10509 /* E-tag configuration */
10510
10511 /* Common result structure for all E-tag configuration */
10512 struct cmd_config_e_tag_result {
10513         cmdline_fixed_string_t e_tag;
10514         cmdline_fixed_string_t set;
10515         cmdline_fixed_string_t insertion;
10516         cmdline_fixed_string_t stripping;
10517         cmdline_fixed_string_t forwarding;
10518         cmdline_fixed_string_t filter;
10519         cmdline_fixed_string_t add;
10520         cmdline_fixed_string_t del;
10521         cmdline_fixed_string_t on;
10522         cmdline_fixed_string_t off;
10523         cmdline_fixed_string_t on_off;
10524         cmdline_fixed_string_t port_tag_id;
10525         uint32_t port_tag_id_val;
10526         cmdline_fixed_string_t e_tag_id;
10527         uint16_t e_tag_id_val;
10528         cmdline_fixed_string_t dst_pool;
10529         uint8_t dst_pool_val;
10530         cmdline_fixed_string_t port;
10531         uint8_t port_id;
10532         cmdline_fixed_string_t vf;
10533         uint8_t vf_id;
10534 };
10535
10536 /* Common CLI fields for all E-tag configuration */
10537 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10538         TOKEN_STRING_INITIALIZER
10539                 (struct cmd_config_e_tag_result,
10540                  e_tag, "E-tag");
10541 cmdline_parse_token_string_t cmd_config_e_tag_set =
10542         TOKEN_STRING_INITIALIZER
10543                 (struct cmd_config_e_tag_result,
10544                  set, "set");
10545 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10546         TOKEN_STRING_INITIALIZER
10547                 (struct cmd_config_e_tag_result,
10548                  insertion, "insertion");
10549 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10550         TOKEN_STRING_INITIALIZER
10551                 (struct cmd_config_e_tag_result,
10552                  stripping, "stripping");
10553 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10554         TOKEN_STRING_INITIALIZER
10555                 (struct cmd_config_e_tag_result,
10556                  forwarding, "forwarding");
10557 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10558         TOKEN_STRING_INITIALIZER
10559                 (struct cmd_config_e_tag_result,
10560                  filter, "filter");
10561 cmdline_parse_token_string_t cmd_config_e_tag_add =
10562         TOKEN_STRING_INITIALIZER
10563                 (struct cmd_config_e_tag_result,
10564                  add, "add");
10565 cmdline_parse_token_string_t cmd_config_e_tag_del =
10566         TOKEN_STRING_INITIALIZER
10567                 (struct cmd_config_e_tag_result,
10568                  del, "del");
10569 cmdline_parse_token_string_t cmd_config_e_tag_on =
10570         TOKEN_STRING_INITIALIZER
10571                 (struct cmd_config_e_tag_result,
10572                  on, "on");
10573 cmdline_parse_token_string_t cmd_config_e_tag_off =
10574         TOKEN_STRING_INITIALIZER
10575                 (struct cmd_config_e_tag_result,
10576                  off, "off");
10577 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10578         TOKEN_STRING_INITIALIZER
10579                 (struct cmd_config_e_tag_result,
10580                  on_off, "on#off");
10581 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10582         TOKEN_STRING_INITIALIZER
10583                 (struct cmd_config_e_tag_result,
10584                  port_tag_id, "port-tag-id");
10585 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10586         TOKEN_NUM_INITIALIZER
10587                 (struct cmd_config_e_tag_result,
10588                  port_tag_id_val, UINT32);
10589 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10590         TOKEN_STRING_INITIALIZER
10591                 (struct cmd_config_e_tag_result,
10592                  e_tag_id, "e-tag-id");
10593 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10594         TOKEN_NUM_INITIALIZER
10595                 (struct cmd_config_e_tag_result,
10596                  e_tag_id_val, UINT16);
10597 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10598         TOKEN_STRING_INITIALIZER
10599                 (struct cmd_config_e_tag_result,
10600                  dst_pool, "dst-pool");
10601 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10602         TOKEN_NUM_INITIALIZER
10603                 (struct cmd_config_e_tag_result,
10604                  dst_pool_val, UINT8);
10605 cmdline_parse_token_string_t cmd_config_e_tag_port =
10606         TOKEN_STRING_INITIALIZER
10607                 (struct cmd_config_e_tag_result,
10608                  port, "port");
10609 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10610         TOKEN_NUM_INITIALIZER
10611                 (struct cmd_config_e_tag_result,
10612                  port_id, UINT8);
10613 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10614         TOKEN_STRING_INITIALIZER
10615                 (struct cmd_config_e_tag_result,
10616                  vf, "vf");
10617 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10618         TOKEN_NUM_INITIALIZER
10619                 (struct cmd_config_e_tag_result,
10620                  vf_id, UINT8);
10621
10622 /* E-tag insertion configuration */
10623 static void
10624 cmd_config_e_tag_insertion_en_parsed(
10625         void *parsed_result,
10626         __attribute__((unused)) struct cmdline *cl,
10627         __attribute__((unused)) void *data)
10628 {
10629         struct cmd_config_e_tag_result *res =
10630                 parsed_result;
10631         struct rte_eth_l2_tunnel_conf entry;
10632
10633         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10634                 return;
10635
10636         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10637         entry.tunnel_id = res->port_tag_id_val;
10638         entry.vf_id = res->vf_id;
10639         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10640                                           &entry,
10641                                           ETH_L2_TUNNEL_INSERTION_MASK,
10642                                           1);
10643 }
10644
10645 static void
10646 cmd_config_e_tag_insertion_dis_parsed(
10647         void *parsed_result,
10648         __attribute__((unused)) struct cmdline *cl,
10649         __attribute__((unused)) void *data)
10650 {
10651         struct cmd_config_e_tag_result *res =
10652                 parsed_result;
10653         struct rte_eth_l2_tunnel_conf entry;
10654
10655         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10656                 return;
10657
10658         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10659         entry.vf_id = res->vf_id;
10660
10661         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10662                                           &entry,
10663                                           ETH_L2_TUNNEL_INSERTION_MASK,
10664                                           0);
10665 }
10666
10667 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10668         .f = cmd_config_e_tag_insertion_en_parsed,
10669         .data = NULL,
10670         .help_str = "E-tag ... : E-tag insertion enable",
10671         .tokens = {
10672                 (void *)&cmd_config_e_tag_e_tag,
10673                 (void *)&cmd_config_e_tag_set,
10674                 (void *)&cmd_config_e_tag_insertion,
10675                 (void *)&cmd_config_e_tag_on,
10676                 (void *)&cmd_config_e_tag_port_tag_id,
10677                 (void *)&cmd_config_e_tag_port_tag_id_val,
10678                 (void *)&cmd_config_e_tag_port,
10679                 (void *)&cmd_config_e_tag_port_id,
10680                 (void *)&cmd_config_e_tag_vf,
10681                 (void *)&cmd_config_e_tag_vf_id,
10682                 NULL,
10683         },
10684 };
10685
10686 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10687         .f = cmd_config_e_tag_insertion_dis_parsed,
10688         .data = NULL,
10689         .help_str = "E-tag ... : E-tag insertion disable",
10690         .tokens = {
10691                 (void *)&cmd_config_e_tag_e_tag,
10692                 (void *)&cmd_config_e_tag_set,
10693                 (void *)&cmd_config_e_tag_insertion,
10694                 (void *)&cmd_config_e_tag_off,
10695                 (void *)&cmd_config_e_tag_port,
10696                 (void *)&cmd_config_e_tag_port_id,
10697                 (void *)&cmd_config_e_tag_vf,
10698                 (void *)&cmd_config_e_tag_vf_id,
10699                 NULL,
10700         },
10701 };
10702
10703 /* E-tag stripping configuration */
10704 static void
10705 cmd_config_e_tag_stripping_parsed(
10706         void *parsed_result,
10707         __attribute__((unused)) struct cmdline *cl,
10708         __attribute__((unused)) void *data)
10709 {
10710         struct cmd_config_e_tag_result *res =
10711                 parsed_result;
10712         struct rte_eth_l2_tunnel_conf entry;
10713
10714         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10715                 return;
10716
10717         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10718
10719         if (!strcmp(res->on_off, "on"))
10720                 rte_eth_dev_l2_tunnel_offload_set
10721                         (res->port_id,
10722                          &entry,
10723                          ETH_L2_TUNNEL_STRIPPING_MASK,
10724                          1);
10725         else
10726                 rte_eth_dev_l2_tunnel_offload_set
10727                         (res->port_id,
10728                          &entry,
10729                          ETH_L2_TUNNEL_STRIPPING_MASK,
10730                          0);
10731 }
10732
10733 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
10734         .f = cmd_config_e_tag_stripping_parsed,
10735         .data = NULL,
10736         .help_str = "E-tag ... : E-tag stripping enable/disable",
10737         .tokens = {
10738                 (void *)&cmd_config_e_tag_e_tag,
10739                 (void *)&cmd_config_e_tag_set,
10740                 (void *)&cmd_config_e_tag_stripping,
10741                 (void *)&cmd_config_e_tag_on_off,
10742                 (void *)&cmd_config_e_tag_port,
10743                 (void *)&cmd_config_e_tag_port_id,
10744                 NULL,
10745         },
10746 };
10747
10748 /* E-tag forwarding configuration */
10749 static void
10750 cmd_config_e_tag_forwarding_parsed(
10751         void *parsed_result,
10752         __attribute__((unused)) struct cmdline *cl,
10753         __attribute__((unused)) void *data)
10754 {
10755         struct cmd_config_e_tag_result *res = parsed_result;
10756         struct rte_eth_l2_tunnel_conf entry;
10757
10758         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10759                 return;
10760
10761         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10762
10763         if (!strcmp(res->on_off, "on"))
10764                 rte_eth_dev_l2_tunnel_offload_set
10765                         (res->port_id,
10766                          &entry,
10767                          ETH_L2_TUNNEL_FORWARDING_MASK,
10768                          1);
10769         else
10770                 rte_eth_dev_l2_tunnel_offload_set
10771                         (res->port_id,
10772                          &entry,
10773                          ETH_L2_TUNNEL_FORWARDING_MASK,
10774                          0);
10775 }
10776
10777 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
10778         .f = cmd_config_e_tag_forwarding_parsed,
10779         .data = NULL,
10780         .help_str = "E-tag ... : E-tag forwarding enable/disable",
10781         .tokens = {
10782                 (void *)&cmd_config_e_tag_e_tag,
10783                 (void *)&cmd_config_e_tag_set,
10784                 (void *)&cmd_config_e_tag_forwarding,
10785                 (void *)&cmd_config_e_tag_on_off,
10786                 (void *)&cmd_config_e_tag_port,
10787                 (void *)&cmd_config_e_tag_port_id,
10788                 NULL,
10789         },
10790 };
10791
10792 /* E-tag filter configuration */
10793 static void
10794 cmd_config_e_tag_filter_add_parsed(
10795         void *parsed_result,
10796         __attribute__((unused)) struct cmdline *cl,
10797         __attribute__((unused)) void *data)
10798 {
10799         struct cmd_config_e_tag_result *res = parsed_result;
10800         struct rte_eth_l2_tunnel_conf entry;
10801         int ret = 0;
10802
10803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10804                 return;
10805
10806         if (res->e_tag_id_val > 0x3fff) {
10807                 printf("e-tag-id must be equal or less than 0x3fff.\n");
10808                 return;
10809         }
10810
10811         ret = rte_eth_dev_filter_supported(res->port_id,
10812                                            RTE_ETH_FILTER_L2_TUNNEL);
10813         if (ret < 0) {
10814                 printf("E-tag filter is not supported on port %u.\n",
10815                        res->port_id);
10816                 return;
10817         }
10818
10819         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10820         entry.tunnel_id = res->e_tag_id_val;
10821         entry.pool = res->dst_pool_val;
10822
10823         ret = rte_eth_dev_filter_ctrl(res->port_id,
10824                                       RTE_ETH_FILTER_L2_TUNNEL,
10825                                       RTE_ETH_FILTER_ADD,
10826                                       &entry);
10827         if (ret < 0)
10828                 printf("E-tag filter programming error: (%s)\n",
10829                        strerror(-ret));
10830 }
10831
10832 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
10833         .f = cmd_config_e_tag_filter_add_parsed,
10834         .data = NULL,
10835         .help_str = "E-tag ... : E-tag filter add",
10836         .tokens = {
10837                 (void *)&cmd_config_e_tag_e_tag,
10838                 (void *)&cmd_config_e_tag_set,
10839                 (void *)&cmd_config_e_tag_filter,
10840                 (void *)&cmd_config_e_tag_add,
10841                 (void *)&cmd_config_e_tag_e_tag_id,
10842                 (void *)&cmd_config_e_tag_e_tag_id_val,
10843                 (void *)&cmd_config_e_tag_dst_pool,
10844                 (void *)&cmd_config_e_tag_dst_pool_val,
10845                 (void *)&cmd_config_e_tag_port,
10846                 (void *)&cmd_config_e_tag_port_id,
10847                 NULL,
10848         },
10849 };
10850
10851 static void
10852 cmd_config_e_tag_filter_del_parsed(
10853         void *parsed_result,
10854         __attribute__((unused)) struct cmdline *cl,
10855         __attribute__((unused)) void *data)
10856 {
10857         struct cmd_config_e_tag_result *res = parsed_result;
10858         struct rte_eth_l2_tunnel_conf entry;
10859         int ret = 0;
10860
10861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10862                 return;
10863
10864         if (res->e_tag_id_val > 0x3fff) {
10865                 printf("e-tag-id must be less than 0x3fff.\n");
10866                 return;
10867         }
10868
10869         ret = rte_eth_dev_filter_supported(res->port_id,
10870                                            RTE_ETH_FILTER_L2_TUNNEL);
10871         if (ret < 0) {
10872                 printf("E-tag filter is not supported on port %u.\n",
10873                        res->port_id);
10874                 return;
10875         }
10876
10877         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10878         entry.tunnel_id = res->e_tag_id_val;
10879
10880         ret = rte_eth_dev_filter_ctrl(res->port_id,
10881                                       RTE_ETH_FILTER_L2_TUNNEL,
10882                                       RTE_ETH_FILTER_DELETE,
10883                                       &entry);
10884         if (ret < 0)
10885                 printf("E-tag filter programming error: (%s)\n",
10886                        strerror(-ret));
10887 }
10888
10889 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
10890         .f = cmd_config_e_tag_filter_del_parsed,
10891         .data = NULL,
10892         .help_str = "E-tag ... : E-tag filter delete",
10893         .tokens = {
10894                 (void *)&cmd_config_e_tag_e_tag,
10895                 (void *)&cmd_config_e_tag_set,
10896                 (void *)&cmd_config_e_tag_filter,
10897                 (void *)&cmd_config_e_tag_del,
10898                 (void *)&cmd_config_e_tag_e_tag_id,
10899                 (void *)&cmd_config_e_tag_e_tag_id_val,
10900                 (void *)&cmd_config_e_tag_port,
10901                 (void *)&cmd_config_e_tag_port_id,
10902                 NULL,
10903         },
10904 };
10905
10906 /* vf vlan anti spoof configuration */
10907
10908 /* Common result structure for vf vlan anti spoof */
10909 struct cmd_vf_vlan_anti_spoof_result {
10910         cmdline_fixed_string_t set;
10911         cmdline_fixed_string_t vf;
10912         cmdline_fixed_string_t vlan;
10913         cmdline_fixed_string_t antispoof;
10914         uint8_t port_id;
10915         uint32_t vf_id;
10916         cmdline_fixed_string_t on_off;
10917 };
10918
10919 /* Common CLI fields for vf vlan anti spoof enable disable */
10920 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10921         TOKEN_STRING_INITIALIZER
10922                 (struct cmd_vf_vlan_anti_spoof_result,
10923                  set, "set");
10924 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10925         TOKEN_STRING_INITIALIZER
10926                 (struct cmd_vf_vlan_anti_spoof_result,
10927                  vf, "vf");
10928 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10929         TOKEN_STRING_INITIALIZER
10930                 (struct cmd_vf_vlan_anti_spoof_result,
10931                  vlan, "vlan");
10932 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10933         TOKEN_STRING_INITIALIZER
10934                 (struct cmd_vf_vlan_anti_spoof_result,
10935                  antispoof, "antispoof");
10936 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10937         TOKEN_NUM_INITIALIZER
10938                 (struct cmd_vf_vlan_anti_spoof_result,
10939                  port_id, UINT8);
10940 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10941         TOKEN_NUM_INITIALIZER
10942                 (struct cmd_vf_vlan_anti_spoof_result,
10943                  vf_id, UINT32);
10944 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10945         TOKEN_STRING_INITIALIZER
10946                 (struct cmd_vf_vlan_anti_spoof_result,
10947                  on_off, "on#off");
10948
10949 static void
10950 cmd_set_vf_vlan_anti_spoof_parsed(
10951         void *parsed_result,
10952         __attribute__((unused)) struct cmdline *cl,
10953         __attribute__((unused)) void *data)
10954 {
10955         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10956         int ret = -ENOTSUP;
10957
10958         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10959
10960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10961                 return;
10962
10963 #ifdef RTE_LIBRTE_IXGBE_PMD
10964         if (ret == -ENOTSUP)
10965                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10966                                 res->vf_id, is_on);
10967 #endif
10968 #ifdef RTE_LIBRTE_I40E_PMD
10969         if (ret == -ENOTSUP)
10970                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10971                                 res->vf_id, is_on);
10972 #endif
10973
10974         switch (ret) {
10975         case 0:
10976                 break;
10977         case -EINVAL:
10978                 printf("invalid vf_id %d\n", res->vf_id);
10979                 break;
10980         case -ENODEV:
10981                 printf("invalid port_id %d\n", res->port_id);
10982                 break;
10983         case -ENOTSUP:
10984                 printf("function not implemented\n");
10985                 break;
10986         default:
10987                 printf("programming error: (%s)\n", strerror(-ret));
10988         }
10989 }
10990
10991 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10992         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10993         .data = NULL,
10994         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10995         .tokens = {
10996                 (void *)&cmd_vf_vlan_anti_spoof_set,
10997                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10998                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10999                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11000                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11001                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11002                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11003                 NULL,
11004         },
11005 };
11006
11007 /* vf mac anti spoof configuration */
11008
11009 /* Common result structure for vf mac anti spoof */
11010 struct cmd_vf_mac_anti_spoof_result {
11011         cmdline_fixed_string_t set;
11012         cmdline_fixed_string_t vf;
11013         cmdline_fixed_string_t mac;
11014         cmdline_fixed_string_t antispoof;
11015         uint8_t port_id;
11016         uint32_t vf_id;
11017         cmdline_fixed_string_t on_off;
11018 };
11019
11020 /* Common CLI fields for vf mac anti spoof enable disable */
11021 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11022         TOKEN_STRING_INITIALIZER
11023                 (struct cmd_vf_mac_anti_spoof_result,
11024                  set, "set");
11025 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11026         TOKEN_STRING_INITIALIZER
11027                 (struct cmd_vf_mac_anti_spoof_result,
11028                  vf, "vf");
11029 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11030         TOKEN_STRING_INITIALIZER
11031                 (struct cmd_vf_mac_anti_spoof_result,
11032                  mac, "mac");
11033 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11034         TOKEN_STRING_INITIALIZER
11035                 (struct cmd_vf_mac_anti_spoof_result,
11036                  antispoof, "antispoof");
11037 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11038         TOKEN_NUM_INITIALIZER
11039                 (struct cmd_vf_mac_anti_spoof_result,
11040                  port_id, UINT8);
11041 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11042         TOKEN_NUM_INITIALIZER
11043                 (struct cmd_vf_mac_anti_spoof_result,
11044                  vf_id, UINT32);
11045 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11046         TOKEN_STRING_INITIALIZER
11047                 (struct cmd_vf_mac_anti_spoof_result,
11048                  on_off, "on#off");
11049
11050 static void
11051 cmd_set_vf_mac_anti_spoof_parsed(
11052         void *parsed_result,
11053         __attribute__((unused)) struct cmdline *cl,
11054         __attribute__((unused)) void *data)
11055 {
11056         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11057         int ret = -ENOTSUP;
11058
11059         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11060
11061         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11062                 return;
11063
11064 #ifdef RTE_LIBRTE_IXGBE_PMD
11065         if (ret == -ENOTSUP)
11066                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11067                         res->vf_id, is_on);
11068 #endif
11069 #ifdef RTE_LIBRTE_I40E_PMD
11070         if (ret == -ENOTSUP)
11071                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11072                         res->vf_id, is_on);
11073 #endif
11074
11075         switch (ret) {
11076         case 0:
11077                 break;
11078         case -EINVAL:
11079                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11080                 break;
11081         case -ENODEV:
11082                 printf("invalid port_id %d\n", res->port_id);
11083                 break;
11084         case -ENOTSUP:
11085                 printf("function not implemented\n");
11086                 break;
11087         default:
11088                 printf("programming error: (%s)\n", strerror(-ret));
11089         }
11090 }
11091
11092 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11093         .f = cmd_set_vf_mac_anti_spoof_parsed,
11094         .data = NULL,
11095         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11096         .tokens = {
11097                 (void *)&cmd_vf_mac_anti_spoof_set,
11098                 (void *)&cmd_vf_mac_anti_spoof_vf,
11099                 (void *)&cmd_vf_mac_anti_spoof_mac,
11100                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11101                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11102                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11103                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11104                 NULL,
11105         },
11106 };
11107
11108 /* vf vlan strip queue configuration */
11109
11110 /* Common result structure for vf mac anti spoof */
11111 struct cmd_vf_vlan_stripq_result {
11112         cmdline_fixed_string_t set;
11113         cmdline_fixed_string_t vf;
11114         cmdline_fixed_string_t vlan;
11115         cmdline_fixed_string_t stripq;
11116         uint8_t port_id;
11117         uint16_t vf_id;
11118         cmdline_fixed_string_t on_off;
11119 };
11120
11121 /* Common CLI fields for vf vlan strip enable disable */
11122 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11123         TOKEN_STRING_INITIALIZER
11124                 (struct cmd_vf_vlan_stripq_result,
11125                  set, "set");
11126 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11127         TOKEN_STRING_INITIALIZER
11128                 (struct cmd_vf_vlan_stripq_result,
11129                  vf, "vf");
11130 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11131         TOKEN_STRING_INITIALIZER
11132                 (struct cmd_vf_vlan_stripq_result,
11133                  vlan, "vlan");
11134 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11135         TOKEN_STRING_INITIALIZER
11136                 (struct cmd_vf_vlan_stripq_result,
11137                  stripq, "stripq");
11138 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11139         TOKEN_NUM_INITIALIZER
11140                 (struct cmd_vf_vlan_stripq_result,
11141                  port_id, UINT8);
11142 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11143         TOKEN_NUM_INITIALIZER
11144                 (struct cmd_vf_vlan_stripq_result,
11145                  vf_id, UINT16);
11146 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11147         TOKEN_STRING_INITIALIZER
11148                 (struct cmd_vf_vlan_stripq_result,
11149                  on_off, "on#off");
11150
11151 static void
11152 cmd_set_vf_vlan_stripq_parsed(
11153         void *parsed_result,
11154         __attribute__((unused)) struct cmdline *cl,
11155         __attribute__((unused)) void *data)
11156 {
11157         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11158         int ret = -ENOTSUP;
11159
11160         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11161
11162         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11163                 return;
11164
11165 #ifdef RTE_LIBRTE_IXGBE_PMD
11166         if (ret == -ENOTSUP)
11167                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11168                         res->vf_id, is_on);
11169 #endif
11170 #ifdef RTE_LIBRTE_I40E_PMD
11171         if (ret == -ENOTSUP)
11172                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11173                         res->vf_id, is_on);
11174 #endif
11175
11176         switch (ret) {
11177         case 0:
11178                 break;
11179         case -EINVAL:
11180                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11181                 break;
11182         case -ENODEV:
11183                 printf("invalid port_id %d\n", res->port_id);
11184                 break;
11185         case -ENOTSUP:
11186                 printf("function not implemented\n");
11187                 break;
11188         default:
11189                 printf("programming error: (%s)\n", strerror(-ret));
11190         }
11191 }
11192
11193 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11194         .f = cmd_set_vf_vlan_stripq_parsed,
11195         .data = NULL,
11196         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11197         .tokens = {
11198                 (void *)&cmd_vf_vlan_stripq_set,
11199                 (void *)&cmd_vf_vlan_stripq_vf,
11200                 (void *)&cmd_vf_vlan_stripq_vlan,
11201                 (void *)&cmd_vf_vlan_stripq_stripq,
11202                 (void *)&cmd_vf_vlan_stripq_port_id,
11203                 (void *)&cmd_vf_vlan_stripq_vf_id,
11204                 (void *)&cmd_vf_vlan_stripq_on_off,
11205                 NULL,
11206         },
11207 };
11208
11209 /* vf vlan insert configuration */
11210
11211 /* Common result structure for vf vlan insert */
11212 struct cmd_vf_vlan_insert_result {
11213         cmdline_fixed_string_t set;
11214         cmdline_fixed_string_t vf;
11215         cmdline_fixed_string_t vlan;
11216         cmdline_fixed_string_t insert;
11217         uint8_t port_id;
11218         uint16_t vf_id;
11219         uint16_t vlan_id;
11220 };
11221
11222 /* Common CLI fields for vf vlan insert enable disable */
11223 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11224         TOKEN_STRING_INITIALIZER
11225                 (struct cmd_vf_vlan_insert_result,
11226                  set, "set");
11227 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11228         TOKEN_STRING_INITIALIZER
11229                 (struct cmd_vf_vlan_insert_result,
11230                  vf, "vf");
11231 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11232         TOKEN_STRING_INITIALIZER
11233                 (struct cmd_vf_vlan_insert_result,
11234                  vlan, "vlan");
11235 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11236         TOKEN_STRING_INITIALIZER
11237                 (struct cmd_vf_vlan_insert_result,
11238                  insert, "insert");
11239 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11240         TOKEN_NUM_INITIALIZER
11241                 (struct cmd_vf_vlan_insert_result,
11242                  port_id, UINT8);
11243 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11244         TOKEN_NUM_INITIALIZER
11245                 (struct cmd_vf_vlan_insert_result,
11246                  vf_id, UINT16);
11247 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11248         TOKEN_NUM_INITIALIZER
11249                 (struct cmd_vf_vlan_insert_result,
11250                  vlan_id, UINT16);
11251
11252 static void
11253 cmd_set_vf_vlan_insert_parsed(
11254         void *parsed_result,
11255         __attribute__((unused)) struct cmdline *cl,
11256         __attribute__((unused)) void *data)
11257 {
11258         struct cmd_vf_vlan_insert_result *res = parsed_result;
11259         int ret = -ENOTSUP;
11260
11261         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11262                 return;
11263
11264 #ifdef RTE_LIBRTE_IXGBE_PMD
11265         if (ret == -ENOTSUP)
11266                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11267                         res->vlan_id);
11268 #endif
11269 #ifdef RTE_LIBRTE_I40E_PMD
11270         if (ret == -ENOTSUP)
11271                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11272                         res->vlan_id);
11273 #endif
11274
11275         switch (ret) {
11276         case 0:
11277                 break;
11278         case -EINVAL:
11279                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11280                 break;
11281         case -ENODEV:
11282                 printf("invalid port_id %d\n", res->port_id);
11283                 break;
11284         case -ENOTSUP:
11285                 printf("function not implemented\n");
11286                 break;
11287         default:
11288                 printf("programming error: (%s)\n", strerror(-ret));
11289         }
11290 }
11291
11292 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11293         .f = cmd_set_vf_vlan_insert_parsed,
11294         .data = NULL,
11295         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11296         .tokens = {
11297                 (void *)&cmd_vf_vlan_insert_set,
11298                 (void *)&cmd_vf_vlan_insert_vf,
11299                 (void *)&cmd_vf_vlan_insert_vlan,
11300                 (void *)&cmd_vf_vlan_insert_insert,
11301                 (void *)&cmd_vf_vlan_insert_port_id,
11302                 (void *)&cmd_vf_vlan_insert_vf_id,
11303                 (void *)&cmd_vf_vlan_insert_vlan_id,
11304                 NULL,
11305         },
11306 };
11307
11308 /* tx loopback configuration */
11309
11310 /* Common result structure for tx loopback */
11311 struct cmd_tx_loopback_result {
11312         cmdline_fixed_string_t set;
11313         cmdline_fixed_string_t tx;
11314         cmdline_fixed_string_t loopback;
11315         uint8_t port_id;
11316         cmdline_fixed_string_t on_off;
11317 };
11318
11319 /* Common CLI fields for tx loopback enable disable */
11320 cmdline_parse_token_string_t cmd_tx_loopback_set =
11321         TOKEN_STRING_INITIALIZER
11322                 (struct cmd_tx_loopback_result,
11323                  set, "set");
11324 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11325         TOKEN_STRING_INITIALIZER
11326                 (struct cmd_tx_loopback_result,
11327                  tx, "tx");
11328 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11329         TOKEN_STRING_INITIALIZER
11330                 (struct cmd_tx_loopback_result,
11331                  loopback, "loopback");
11332 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11333         TOKEN_NUM_INITIALIZER
11334                 (struct cmd_tx_loopback_result,
11335                  port_id, UINT8);
11336 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11337         TOKEN_STRING_INITIALIZER
11338                 (struct cmd_tx_loopback_result,
11339                  on_off, "on#off");
11340
11341 static void
11342 cmd_set_tx_loopback_parsed(
11343         void *parsed_result,
11344         __attribute__((unused)) struct cmdline *cl,
11345         __attribute__((unused)) void *data)
11346 {
11347         struct cmd_tx_loopback_result *res = parsed_result;
11348         int ret = -ENOTSUP;
11349
11350         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11351
11352         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11353                 return;
11354
11355 #ifdef RTE_LIBRTE_IXGBE_PMD
11356         if (ret == -ENOTSUP)
11357                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11358 #endif
11359 #ifdef RTE_LIBRTE_I40E_PMD
11360         if (ret == -ENOTSUP)
11361                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11362 #endif
11363
11364         switch (ret) {
11365         case 0:
11366                 break;
11367         case -EINVAL:
11368                 printf("invalid is_on %d\n", is_on);
11369                 break;
11370         case -ENODEV:
11371                 printf("invalid port_id %d\n", res->port_id);
11372                 break;
11373         case -ENOTSUP:
11374                 printf("function not implemented\n");
11375                 break;
11376         default:
11377                 printf("programming error: (%s)\n", strerror(-ret));
11378         }
11379 }
11380
11381 cmdline_parse_inst_t cmd_set_tx_loopback = {
11382         .f = cmd_set_tx_loopback_parsed,
11383         .data = NULL,
11384         .help_str = "set tx loopback <port_id> on|off",
11385         .tokens = {
11386                 (void *)&cmd_tx_loopback_set,
11387                 (void *)&cmd_tx_loopback_tx,
11388                 (void *)&cmd_tx_loopback_loopback,
11389                 (void *)&cmd_tx_loopback_port_id,
11390                 (void *)&cmd_tx_loopback_on_off,
11391                 NULL,
11392         },
11393 };
11394
11395 #ifdef RTE_LIBRTE_IXGBE_PMD
11396 /* all queues drop enable configuration */
11397
11398 /* Common result structure for all queues drop enable */
11399 struct cmd_all_queues_drop_en_result {
11400         cmdline_fixed_string_t set;
11401         cmdline_fixed_string_t all;
11402         cmdline_fixed_string_t queues;
11403         cmdline_fixed_string_t drop;
11404         uint8_t port_id;
11405         cmdline_fixed_string_t on_off;
11406 };
11407
11408 /* Common CLI fields for tx loopback enable disable */
11409 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11410         TOKEN_STRING_INITIALIZER
11411                 (struct cmd_all_queues_drop_en_result,
11412                  set, "set");
11413 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11414         TOKEN_STRING_INITIALIZER
11415                 (struct cmd_all_queues_drop_en_result,
11416                  all, "all");
11417 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11418         TOKEN_STRING_INITIALIZER
11419                 (struct cmd_all_queues_drop_en_result,
11420                  queues, "queues");
11421 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11422         TOKEN_STRING_INITIALIZER
11423                 (struct cmd_all_queues_drop_en_result,
11424                  drop, "drop");
11425 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11426         TOKEN_NUM_INITIALIZER
11427                 (struct cmd_all_queues_drop_en_result,
11428                  port_id, UINT8);
11429 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11430         TOKEN_STRING_INITIALIZER
11431                 (struct cmd_all_queues_drop_en_result,
11432                  on_off, "on#off");
11433
11434 static void
11435 cmd_set_all_queues_drop_en_parsed(
11436         void *parsed_result,
11437         __attribute__((unused)) struct cmdline *cl,
11438         __attribute__((unused)) void *data)
11439 {
11440         struct cmd_all_queues_drop_en_result *res = parsed_result;
11441         int ret = 0;
11442         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11443
11444         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11445                 return;
11446
11447         ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11448         switch (ret) {
11449         case 0:
11450                 break;
11451         case -EINVAL:
11452                 printf("invalid is_on %d\n", is_on);
11453                 break;
11454         case -ENODEV:
11455                 printf("invalid port_id %d\n", res->port_id);
11456                 break;
11457         case -ENOTSUP:
11458                 printf("function not implemented\n");
11459                 break;
11460         default:
11461                 printf("programming error: (%s)\n", strerror(-ret));
11462         }
11463 }
11464
11465 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11466         .f = cmd_set_all_queues_drop_en_parsed,
11467         .data = NULL,
11468         .help_str = "set all queues drop <port_id> on|off",
11469         .tokens = {
11470                 (void *)&cmd_all_queues_drop_en_set,
11471                 (void *)&cmd_all_queues_drop_en_all,
11472                 (void *)&cmd_all_queues_drop_en_queues,
11473                 (void *)&cmd_all_queues_drop_en_drop,
11474                 (void *)&cmd_all_queues_drop_en_port_id,
11475                 (void *)&cmd_all_queues_drop_en_on_off,
11476                 NULL,
11477         },
11478 };
11479
11480 /* vf split drop enable configuration */
11481
11482 /* Common result structure for vf split drop enable */
11483 struct cmd_vf_split_drop_en_result {
11484         cmdline_fixed_string_t set;
11485         cmdline_fixed_string_t vf;
11486         cmdline_fixed_string_t split;
11487         cmdline_fixed_string_t drop;
11488         uint8_t port_id;
11489         uint16_t vf_id;
11490         cmdline_fixed_string_t on_off;
11491 };
11492
11493 /* Common CLI fields for vf split drop enable disable */
11494 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11495         TOKEN_STRING_INITIALIZER
11496                 (struct cmd_vf_split_drop_en_result,
11497                  set, "set");
11498 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11499         TOKEN_STRING_INITIALIZER
11500                 (struct cmd_vf_split_drop_en_result,
11501                  vf, "vf");
11502 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11503         TOKEN_STRING_INITIALIZER
11504                 (struct cmd_vf_split_drop_en_result,
11505                  split, "split");
11506 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11507         TOKEN_STRING_INITIALIZER
11508                 (struct cmd_vf_split_drop_en_result,
11509                  drop, "drop");
11510 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11511         TOKEN_NUM_INITIALIZER
11512                 (struct cmd_vf_split_drop_en_result,
11513                  port_id, UINT8);
11514 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11515         TOKEN_NUM_INITIALIZER
11516                 (struct cmd_vf_split_drop_en_result,
11517                  vf_id, UINT16);
11518 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11519         TOKEN_STRING_INITIALIZER
11520                 (struct cmd_vf_split_drop_en_result,
11521                  on_off, "on#off");
11522
11523 static void
11524 cmd_set_vf_split_drop_en_parsed(
11525         void *parsed_result,
11526         __attribute__((unused)) struct cmdline *cl,
11527         __attribute__((unused)) void *data)
11528 {
11529         struct cmd_vf_split_drop_en_result *res = parsed_result;
11530         int ret;
11531         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11532
11533         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11534                 return;
11535
11536         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11537                         is_on);
11538         switch (ret) {
11539         case 0:
11540                 break;
11541         case -EINVAL:
11542                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11543                 break;
11544         case -ENODEV:
11545                 printf("invalid port_id %d\n", res->port_id);
11546                 break;
11547         default:
11548                 printf("programming error: (%s)\n", strerror(-ret));
11549         }
11550 }
11551
11552 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11553         .f = cmd_set_vf_split_drop_en_parsed,
11554         .data = NULL,
11555         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11556         .tokens = {
11557                 (void *)&cmd_vf_split_drop_en_set,
11558                 (void *)&cmd_vf_split_drop_en_vf,
11559                 (void *)&cmd_vf_split_drop_en_split,
11560                 (void *)&cmd_vf_split_drop_en_drop,
11561                 (void *)&cmd_vf_split_drop_en_port_id,
11562                 (void *)&cmd_vf_split_drop_en_vf_id,
11563                 (void *)&cmd_vf_split_drop_en_on_off,
11564                 NULL,
11565         },
11566 };
11567 #endif
11568
11569 /* vf mac address configuration */
11570
11571 /* Common result structure for vf mac address */
11572 struct cmd_set_vf_mac_addr_result {
11573         cmdline_fixed_string_t set;
11574         cmdline_fixed_string_t vf;
11575         cmdline_fixed_string_t mac;
11576         cmdline_fixed_string_t addr;
11577         uint8_t port_id;
11578         uint16_t vf_id;
11579         struct ether_addr mac_addr;
11580
11581 };
11582
11583 /* Common CLI fields for vf split drop enable disable */
11584 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11585         TOKEN_STRING_INITIALIZER
11586                 (struct cmd_set_vf_mac_addr_result,
11587                  set, "set");
11588 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11589         TOKEN_STRING_INITIALIZER
11590                 (struct cmd_set_vf_mac_addr_result,
11591                  vf, "vf");
11592 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11593         TOKEN_STRING_INITIALIZER
11594                 (struct cmd_set_vf_mac_addr_result,
11595                  mac, "mac");
11596 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11597         TOKEN_STRING_INITIALIZER
11598                 (struct cmd_set_vf_mac_addr_result,
11599                  addr, "addr");
11600 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11601         TOKEN_NUM_INITIALIZER
11602                 (struct cmd_set_vf_mac_addr_result,
11603                  port_id, UINT8);
11604 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11605         TOKEN_NUM_INITIALIZER
11606                 (struct cmd_set_vf_mac_addr_result,
11607                  vf_id, UINT16);
11608 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11609         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11610                  mac_addr);
11611
11612 static void
11613 cmd_set_vf_mac_addr_parsed(
11614         void *parsed_result,
11615         __attribute__((unused)) struct cmdline *cl,
11616         __attribute__((unused)) void *data)
11617 {
11618         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11619         int ret = -ENOTSUP;
11620
11621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11622                 return;
11623
11624 #ifdef RTE_LIBRTE_IXGBE_PMD
11625         if (ret == -ENOTSUP)
11626                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11627                                 &res->mac_addr);
11628 #endif
11629 #ifdef RTE_LIBRTE_I40E_PMD
11630         if (ret == -ENOTSUP)
11631                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11632                                 &res->mac_addr);
11633 #endif
11634
11635         switch (ret) {
11636         case 0:
11637                 break;
11638         case -EINVAL:
11639                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11640                 break;
11641         case -ENODEV:
11642                 printf("invalid port_id %d\n", res->port_id);
11643                 break;
11644         case -ENOTSUP:
11645                 printf("function not implemented\n");
11646                 break;
11647         default:
11648                 printf("programming error: (%s)\n", strerror(-ret));
11649         }
11650 }
11651
11652 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11653         .f = cmd_set_vf_mac_addr_parsed,
11654         .data = NULL,
11655         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11656         .tokens = {
11657                 (void *)&cmd_set_vf_mac_addr_set,
11658                 (void *)&cmd_set_vf_mac_addr_vf,
11659                 (void *)&cmd_set_vf_mac_addr_mac,
11660                 (void *)&cmd_set_vf_mac_addr_addr,
11661                 (void *)&cmd_set_vf_mac_addr_port_id,
11662                 (void *)&cmd_set_vf_mac_addr_vf_id,
11663                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11664                 NULL,
11665         },
11666 };
11667
11668 #ifdef RTE_LIBRTE_IXGBE_PMD
11669 /* MACsec configuration */
11670
11671 /* Common result structure for MACsec offload enable */
11672 struct cmd_macsec_offload_on_result {
11673         cmdline_fixed_string_t set;
11674         cmdline_fixed_string_t macsec;
11675         cmdline_fixed_string_t offload;
11676         uint8_t port_id;
11677         cmdline_fixed_string_t on;
11678         cmdline_fixed_string_t encrypt;
11679         cmdline_fixed_string_t en_on_off;
11680         cmdline_fixed_string_t replay_protect;
11681         cmdline_fixed_string_t rp_on_off;
11682 };
11683
11684 /* Common CLI fields for MACsec offload disable */
11685 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11686         TOKEN_STRING_INITIALIZER
11687                 (struct cmd_macsec_offload_on_result,
11688                  set, "set");
11689 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11690         TOKEN_STRING_INITIALIZER
11691                 (struct cmd_macsec_offload_on_result,
11692                  macsec, "macsec");
11693 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11694         TOKEN_STRING_INITIALIZER
11695                 (struct cmd_macsec_offload_on_result,
11696                  offload, "offload");
11697 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11698         TOKEN_NUM_INITIALIZER
11699                 (struct cmd_macsec_offload_on_result,
11700                  port_id, UINT8);
11701 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11702         TOKEN_STRING_INITIALIZER
11703                 (struct cmd_macsec_offload_on_result,
11704                  on, "on");
11705 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11706         TOKEN_STRING_INITIALIZER
11707                 (struct cmd_macsec_offload_on_result,
11708                  encrypt, "encrypt");
11709 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11710         TOKEN_STRING_INITIALIZER
11711                 (struct cmd_macsec_offload_on_result,
11712                  en_on_off, "on#off");
11713 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11714         TOKEN_STRING_INITIALIZER
11715                 (struct cmd_macsec_offload_on_result,
11716                  replay_protect, "replay-protect");
11717 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11718         TOKEN_STRING_INITIALIZER
11719                 (struct cmd_macsec_offload_on_result,
11720                  rp_on_off, "on#off");
11721
11722 static void
11723 cmd_set_macsec_offload_on_parsed(
11724         void *parsed_result,
11725         __attribute__((unused)) struct cmdline *cl,
11726         __attribute__((unused)) void *data)
11727 {
11728         struct cmd_macsec_offload_on_result *res = parsed_result;
11729         int ret;
11730         portid_t port_id = res->port_id;
11731         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11732         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11733
11734         if (port_id_is_invalid(port_id, ENABLED_WARN))
11735                 return;
11736
11737         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
11738         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11739
11740         switch (ret) {
11741         case 0:
11742                 break;
11743         case -ENODEV:
11744                 printf("invalid port_id %d\n", port_id);
11745                 break;
11746         default:
11747                 printf("programming error: (%s)\n", strerror(-ret));
11748         }
11749 }
11750
11751 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11752         .f = cmd_set_macsec_offload_on_parsed,
11753         .data = NULL,
11754         .help_str = "set macsec offload <port_id> on "
11755                 "encrypt on|off replay-protect on|off",
11756         .tokens = {
11757                 (void *)&cmd_macsec_offload_on_set,
11758                 (void *)&cmd_macsec_offload_on_macsec,
11759                 (void *)&cmd_macsec_offload_on_offload,
11760                 (void *)&cmd_macsec_offload_on_port_id,
11761                 (void *)&cmd_macsec_offload_on_on,
11762                 (void *)&cmd_macsec_offload_on_encrypt,
11763                 (void *)&cmd_macsec_offload_on_en_on_off,
11764                 (void *)&cmd_macsec_offload_on_replay_protect,
11765                 (void *)&cmd_macsec_offload_on_rp_on_off,
11766                 NULL,
11767         },
11768 };
11769
11770 /* Common result structure for MACsec offload disable */
11771 struct cmd_macsec_offload_off_result {
11772         cmdline_fixed_string_t set;
11773         cmdline_fixed_string_t macsec;
11774         cmdline_fixed_string_t offload;
11775         uint8_t port_id;
11776         cmdline_fixed_string_t off;
11777 };
11778
11779 /* Common CLI fields for MACsec offload disable */
11780 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11781         TOKEN_STRING_INITIALIZER
11782                 (struct cmd_macsec_offload_off_result,
11783                  set, "set");
11784 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11785         TOKEN_STRING_INITIALIZER
11786                 (struct cmd_macsec_offload_off_result,
11787                  macsec, "macsec");
11788 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11789         TOKEN_STRING_INITIALIZER
11790                 (struct cmd_macsec_offload_off_result,
11791                  offload, "offload");
11792 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11793         TOKEN_NUM_INITIALIZER
11794                 (struct cmd_macsec_offload_off_result,
11795                  port_id, UINT8);
11796 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11797         TOKEN_STRING_INITIALIZER
11798                 (struct cmd_macsec_offload_off_result,
11799                  off, "off");
11800
11801 static void
11802 cmd_set_macsec_offload_off_parsed(
11803         void *parsed_result,
11804         __attribute__((unused)) struct cmdline *cl,
11805         __attribute__((unused)) void *data)
11806 {
11807         struct cmd_macsec_offload_off_result *res = parsed_result;
11808         int ret;
11809         portid_t port_id = res->port_id;
11810
11811         if (port_id_is_invalid(port_id, ENABLED_WARN))
11812                 return;
11813
11814         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
11815         ret = rte_pmd_ixgbe_macsec_disable(port_id);
11816
11817         switch (ret) {
11818         case 0:
11819                 break;
11820         case -ENODEV:
11821                 printf("invalid port_id %d\n", port_id);
11822                 break;
11823         default:
11824                 printf("programming error: (%s)\n", strerror(-ret));
11825         }
11826 }
11827
11828 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11829         .f = cmd_set_macsec_offload_off_parsed,
11830         .data = NULL,
11831         .help_str = "set macsec offload <port_id> off",
11832         .tokens = {
11833                 (void *)&cmd_macsec_offload_off_set,
11834                 (void *)&cmd_macsec_offload_off_macsec,
11835                 (void *)&cmd_macsec_offload_off_offload,
11836                 (void *)&cmd_macsec_offload_off_port_id,
11837                 (void *)&cmd_macsec_offload_off_off,
11838                 NULL,
11839         },
11840 };
11841
11842 /* Common result structure for MACsec secure connection configure */
11843 struct cmd_macsec_sc_result {
11844         cmdline_fixed_string_t set;
11845         cmdline_fixed_string_t macsec;
11846         cmdline_fixed_string_t sc;
11847         cmdline_fixed_string_t tx_rx;
11848         uint8_t port_id;
11849         struct ether_addr mac;
11850         uint16_t pi;
11851 };
11852
11853 /* Common CLI fields for MACsec secure connection configure */
11854 cmdline_parse_token_string_t cmd_macsec_sc_set =
11855         TOKEN_STRING_INITIALIZER
11856                 (struct cmd_macsec_sc_result,
11857                  set, "set");
11858 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11859         TOKEN_STRING_INITIALIZER
11860                 (struct cmd_macsec_sc_result,
11861                  macsec, "macsec");
11862 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11863         TOKEN_STRING_INITIALIZER
11864                 (struct cmd_macsec_sc_result,
11865                  sc, "sc");
11866 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11867         TOKEN_STRING_INITIALIZER
11868                 (struct cmd_macsec_sc_result,
11869                  tx_rx, "tx#rx");
11870 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11871         TOKEN_NUM_INITIALIZER
11872                 (struct cmd_macsec_sc_result,
11873                  port_id, UINT8);
11874 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11875         TOKEN_ETHERADDR_INITIALIZER
11876                 (struct cmd_macsec_sc_result,
11877                  mac);
11878 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11879         TOKEN_NUM_INITIALIZER
11880                 (struct cmd_macsec_sc_result,
11881                  pi, UINT16);
11882
11883 static void
11884 cmd_set_macsec_sc_parsed(
11885         void *parsed_result,
11886         __attribute__((unused)) struct cmdline *cl,
11887         __attribute__((unused)) void *data)
11888 {
11889         struct cmd_macsec_sc_result *res = parsed_result;
11890         int ret;
11891         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11892
11893         ret = is_tx ?
11894                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11895                                 res->mac.addr_bytes) :
11896                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11897                                 res->mac.addr_bytes, res->pi);
11898         switch (ret) {
11899         case 0:
11900                 break;
11901         case -ENODEV:
11902                 printf("invalid port_id %d\n", res->port_id);
11903                 break;
11904         default:
11905                 printf("programming error: (%s)\n", strerror(-ret));
11906         }
11907 }
11908
11909 cmdline_parse_inst_t cmd_set_macsec_sc = {
11910         .f = cmd_set_macsec_sc_parsed,
11911         .data = NULL,
11912         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11913         .tokens = {
11914                 (void *)&cmd_macsec_sc_set,
11915                 (void *)&cmd_macsec_sc_macsec,
11916                 (void *)&cmd_macsec_sc_sc,
11917                 (void *)&cmd_macsec_sc_tx_rx,
11918                 (void *)&cmd_macsec_sc_port_id,
11919                 (void *)&cmd_macsec_sc_mac,
11920                 (void *)&cmd_macsec_sc_pi,
11921                 NULL,
11922         },
11923 };
11924
11925 /* Common result structure for MACsec secure connection configure */
11926 struct cmd_macsec_sa_result {
11927         cmdline_fixed_string_t set;
11928         cmdline_fixed_string_t macsec;
11929         cmdline_fixed_string_t sa;
11930         cmdline_fixed_string_t tx_rx;
11931         uint8_t port_id;
11932         uint8_t idx;
11933         uint8_t an;
11934         uint32_t pn;
11935         cmdline_fixed_string_t key;
11936 };
11937
11938 /* Common CLI fields for MACsec secure connection configure */
11939 cmdline_parse_token_string_t cmd_macsec_sa_set =
11940         TOKEN_STRING_INITIALIZER
11941                 (struct cmd_macsec_sa_result,
11942                  set, "set");
11943 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11944         TOKEN_STRING_INITIALIZER
11945                 (struct cmd_macsec_sa_result,
11946                  macsec, "macsec");
11947 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11948         TOKEN_STRING_INITIALIZER
11949                 (struct cmd_macsec_sa_result,
11950                  sa, "sa");
11951 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11952         TOKEN_STRING_INITIALIZER
11953                 (struct cmd_macsec_sa_result,
11954                  tx_rx, "tx#rx");
11955 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11956         TOKEN_NUM_INITIALIZER
11957                 (struct cmd_macsec_sa_result,
11958                  port_id, UINT8);
11959 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11960         TOKEN_NUM_INITIALIZER
11961                 (struct cmd_macsec_sa_result,
11962                  idx, UINT8);
11963 cmdline_parse_token_num_t cmd_macsec_sa_an =
11964         TOKEN_NUM_INITIALIZER
11965                 (struct cmd_macsec_sa_result,
11966                  an, UINT8);
11967 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11968         TOKEN_NUM_INITIALIZER
11969                 (struct cmd_macsec_sa_result,
11970                  pn, UINT32);
11971 cmdline_parse_token_string_t cmd_macsec_sa_key =
11972         TOKEN_STRING_INITIALIZER
11973                 (struct cmd_macsec_sa_result,
11974                  key, NULL);
11975
11976 static void
11977 cmd_set_macsec_sa_parsed(
11978         void *parsed_result,
11979         __attribute__((unused)) struct cmdline *cl,
11980         __attribute__((unused)) void *data)
11981 {
11982         struct cmd_macsec_sa_result *res = parsed_result;
11983         int ret;
11984         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11985         uint8_t key[16] = { 0 };
11986         uint8_t xdgt0;
11987         uint8_t xdgt1;
11988         int key_len;
11989         int i;
11990
11991         key_len = strlen(res->key) / 2;
11992         if (key_len > 16)
11993                 key_len = 16;
11994
11995         for (i = 0; i < key_len; i++) {
11996                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11997                 if (xdgt0 == 0xFF)
11998                         return;
11999                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12000                 if (xdgt1 == 0xFF)
12001                         return;
12002                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12003         }
12004
12005         ret = is_tx ?
12006                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12007                         res->idx, res->an, res->pn, key) :
12008                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12009                         res->idx, res->an, res->pn, key);
12010         switch (ret) {
12011         case 0:
12012                 break;
12013         case -EINVAL:
12014                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12015                 break;
12016         case -ENODEV:
12017                 printf("invalid port_id %d\n", res->port_id);
12018                 break;
12019         default:
12020                 printf("programming error: (%s)\n", strerror(-ret));
12021         }
12022 }
12023
12024 cmdline_parse_inst_t cmd_set_macsec_sa = {
12025         .f = cmd_set_macsec_sa_parsed,
12026         .data = NULL,
12027         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12028         .tokens = {
12029                 (void *)&cmd_macsec_sa_set,
12030                 (void *)&cmd_macsec_sa_macsec,
12031                 (void *)&cmd_macsec_sa_sa,
12032                 (void *)&cmd_macsec_sa_tx_rx,
12033                 (void *)&cmd_macsec_sa_port_id,
12034                 (void *)&cmd_macsec_sa_idx,
12035                 (void *)&cmd_macsec_sa_an,
12036                 (void *)&cmd_macsec_sa_pn,
12037                 (void *)&cmd_macsec_sa_key,
12038                 NULL,
12039         },
12040 };
12041 #endif
12042
12043 /* VF unicast promiscuous mode configuration */
12044
12045 /* Common result structure for VF unicast promiscuous mode */
12046 struct cmd_vf_promisc_result {
12047         cmdline_fixed_string_t set;
12048         cmdline_fixed_string_t vf;
12049         cmdline_fixed_string_t promisc;
12050         uint8_t port_id;
12051         uint32_t vf_id;
12052         cmdline_fixed_string_t on_off;
12053 };
12054
12055 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12056 cmdline_parse_token_string_t cmd_vf_promisc_set =
12057         TOKEN_STRING_INITIALIZER
12058                 (struct cmd_vf_promisc_result,
12059                  set, "set");
12060 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12061         TOKEN_STRING_INITIALIZER
12062                 (struct cmd_vf_promisc_result,
12063                  vf, "vf");
12064 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12065         TOKEN_STRING_INITIALIZER
12066                 (struct cmd_vf_promisc_result,
12067                  promisc, "promisc");
12068 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12069         TOKEN_NUM_INITIALIZER
12070                 (struct cmd_vf_promisc_result,
12071                  port_id, UINT8);
12072 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12073         TOKEN_NUM_INITIALIZER
12074                 (struct cmd_vf_promisc_result,
12075                  vf_id, UINT32);
12076 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12077         TOKEN_STRING_INITIALIZER
12078                 (struct cmd_vf_promisc_result,
12079                  on_off, "on#off");
12080
12081 static void
12082 cmd_set_vf_promisc_parsed(
12083         void *parsed_result,
12084         __attribute__((unused)) struct cmdline *cl,
12085         __attribute__((unused)) void *data)
12086 {
12087         struct cmd_vf_promisc_result *res = parsed_result;
12088         int ret = -ENOTSUP;
12089
12090         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12091
12092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12093                 return;
12094
12095 #ifdef RTE_LIBRTE_I40E_PMD
12096         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12097                                                   res->vf_id, is_on);
12098 #endif
12099
12100         switch (ret) {
12101         case 0:
12102                 break;
12103         case -EINVAL:
12104                 printf("invalid vf_id %d\n", res->vf_id);
12105                 break;
12106         case -ENODEV:
12107                 printf("invalid port_id %d\n", res->port_id);
12108                 break;
12109         case -ENOTSUP:
12110                 printf("function not implemented\n");
12111                 break;
12112         default:
12113                 printf("programming error: (%s)\n", strerror(-ret));
12114         }
12115 }
12116
12117 cmdline_parse_inst_t cmd_set_vf_promisc = {
12118         .f = cmd_set_vf_promisc_parsed,
12119         .data = NULL,
12120         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12121                 "Set unicast promiscuous mode for a VF from the PF",
12122         .tokens = {
12123                 (void *)&cmd_vf_promisc_set,
12124                 (void *)&cmd_vf_promisc_vf,
12125                 (void *)&cmd_vf_promisc_promisc,
12126                 (void *)&cmd_vf_promisc_port_id,
12127                 (void *)&cmd_vf_promisc_vf_id,
12128                 (void *)&cmd_vf_promisc_on_off,
12129                 NULL,
12130         },
12131 };
12132
12133 /* VF multicast promiscuous mode configuration */
12134
12135 /* Common result structure for VF multicast promiscuous mode */
12136 struct cmd_vf_allmulti_result {
12137         cmdline_fixed_string_t set;
12138         cmdline_fixed_string_t vf;
12139         cmdline_fixed_string_t allmulti;
12140         uint8_t port_id;
12141         uint32_t vf_id;
12142         cmdline_fixed_string_t on_off;
12143 };
12144
12145 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12146 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12147         TOKEN_STRING_INITIALIZER
12148                 (struct cmd_vf_allmulti_result,
12149                  set, "set");
12150 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12151         TOKEN_STRING_INITIALIZER
12152                 (struct cmd_vf_allmulti_result,
12153                  vf, "vf");
12154 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12155         TOKEN_STRING_INITIALIZER
12156                 (struct cmd_vf_allmulti_result,
12157                  allmulti, "allmulti");
12158 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12159         TOKEN_NUM_INITIALIZER
12160                 (struct cmd_vf_allmulti_result,
12161                  port_id, UINT8);
12162 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12163         TOKEN_NUM_INITIALIZER
12164                 (struct cmd_vf_allmulti_result,
12165                  vf_id, UINT32);
12166 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12167         TOKEN_STRING_INITIALIZER
12168                 (struct cmd_vf_allmulti_result,
12169                  on_off, "on#off");
12170
12171 static void
12172 cmd_set_vf_allmulti_parsed(
12173         void *parsed_result,
12174         __attribute__((unused)) struct cmdline *cl,
12175         __attribute__((unused)) void *data)
12176 {
12177         struct cmd_vf_allmulti_result *res = parsed_result;
12178         int ret = -ENOTSUP;
12179
12180         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12181
12182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12183                 return;
12184
12185 #ifdef RTE_LIBRTE_I40E_PMD
12186         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12187                                                     res->vf_id, is_on);
12188 #endif
12189
12190         switch (ret) {
12191         case 0:
12192                 break;
12193         case -EINVAL:
12194                 printf("invalid vf_id %d\n", res->vf_id);
12195                 break;
12196         case -ENODEV:
12197                 printf("invalid port_id %d\n", res->port_id);
12198                 break;
12199         case -ENOTSUP:
12200                 printf("function not implemented\n");
12201                 break;
12202         default:
12203                 printf("programming error: (%s)\n", strerror(-ret));
12204         }
12205 }
12206
12207 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12208         .f = cmd_set_vf_allmulti_parsed,
12209         .data = NULL,
12210         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12211                 "Set multicast promiscuous mode for a VF from the PF",
12212         .tokens = {
12213                 (void *)&cmd_vf_allmulti_set,
12214                 (void *)&cmd_vf_allmulti_vf,
12215                 (void *)&cmd_vf_allmulti_allmulti,
12216                 (void *)&cmd_vf_allmulti_port_id,
12217                 (void *)&cmd_vf_allmulti_vf_id,
12218                 (void *)&cmd_vf_allmulti_on_off,
12219                 NULL,
12220         },
12221 };
12222
12223 /* vf broadcast mode configuration */
12224
12225 /* Common result structure for vf broadcast */
12226 struct cmd_set_vf_broadcast_result {
12227         cmdline_fixed_string_t set;
12228         cmdline_fixed_string_t vf;
12229         cmdline_fixed_string_t broadcast;
12230         uint8_t port_id;
12231         uint16_t vf_id;
12232         cmdline_fixed_string_t on_off;
12233 };
12234
12235 /* Common CLI fields for vf broadcast enable disable */
12236 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12237         TOKEN_STRING_INITIALIZER
12238                 (struct cmd_set_vf_broadcast_result,
12239                  set, "set");
12240 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12241         TOKEN_STRING_INITIALIZER
12242                 (struct cmd_set_vf_broadcast_result,
12243                  vf, "vf");
12244 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12245         TOKEN_STRING_INITIALIZER
12246                 (struct cmd_set_vf_broadcast_result,
12247                  broadcast, "broadcast");
12248 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12249         TOKEN_NUM_INITIALIZER
12250                 (struct cmd_set_vf_broadcast_result,
12251                  port_id, UINT8);
12252 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12253         TOKEN_NUM_INITIALIZER
12254                 (struct cmd_set_vf_broadcast_result,
12255                  vf_id, UINT16);
12256 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12257         TOKEN_STRING_INITIALIZER
12258                 (struct cmd_set_vf_broadcast_result,
12259                  on_off, "on#off");
12260
12261 static void
12262 cmd_set_vf_broadcast_parsed(
12263         void *parsed_result,
12264         __attribute__((unused)) struct cmdline *cl,
12265         __attribute__((unused)) void *data)
12266 {
12267         struct cmd_set_vf_broadcast_result *res = parsed_result;
12268         int ret = -ENOTSUP;
12269
12270         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12271
12272         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12273                 return;
12274
12275 #ifdef RTE_LIBRTE_I40E_PMD
12276         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12277                                             res->vf_id, is_on);
12278 #endif
12279
12280         switch (ret) {
12281         case 0:
12282                 break;
12283         case -EINVAL:
12284                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12285                 break;
12286         case -ENODEV:
12287                 printf("invalid port_id %d\n", res->port_id);
12288                 break;
12289         case -ENOTSUP:
12290                 printf("function not implemented\n");
12291                 break;
12292         default:
12293                 printf("programming error: (%s)\n", strerror(-ret));
12294         }
12295 }
12296
12297 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12298         .f = cmd_set_vf_broadcast_parsed,
12299         .data = NULL,
12300         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12301         .tokens = {
12302                 (void *)&cmd_set_vf_broadcast_set,
12303                 (void *)&cmd_set_vf_broadcast_vf,
12304                 (void *)&cmd_set_vf_broadcast_broadcast,
12305                 (void *)&cmd_set_vf_broadcast_port_id,
12306                 (void *)&cmd_set_vf_broadcast_vf_id,
12307                 (void *)&cmd_set_vf_broadcast_on_off,
12308                 NULL,
12309         },
12310 };
12311
12312 /* vf vlan tag configuration */
12313
12314 /* Common result structure for vf vlan tag */
12315 struct cmd_set_vf_vlan_tag_result {
12316         cmdline_fixed_string_t set;
12317         cmdline_fixed_string_t vf;
12318         cmdline_fixed_string_t vlan;
12319         cmdline_fixed_string_t tag;
12320         uint8_t port_id;
12321         uint16_t vf_id;
12322         cmdline_fixed_string_t on_off;
12323 };
12324
12325 /* Common CLI fields for vf vlan tag enable disable */
12326 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12327         TOKEN_STRING_INITIALIZER
12328                 (struct cmd_set_vf_vlan_tag_result,
12329                  set, "set");
12330 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12331         TOKEN_STRING_INITIALIZER
12332                 (struct cmd_set_vf_vlan_tag_result,
12333                  vf, "vf");
12334 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12335         TOKEN_STRING_INITIALIZER
12336                 (struct cmd_set_vf_vlan_tag_result,
12337                  vlan, "vlan");
12338 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12339         TOKEN_STRING_INITIALIZER
12340                 (struct cmd_set_vf_vlan_tag_result,
12341                  tag, "tag");
12342 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12343         TOKEN_NUM_INITIALIZER
12344                 (struct cmd_set_vf_vlan_tag_result,
12345                  port_id, UINT8);
12346 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12347         TOKEN_NUM_INITIALIZER
12348                 (struct cmd_set_vf_vlan_tag_result,
12349                  vf_id, UINT16);
12350 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12351         TOKEN_STRING_INITIALIZER
12352                 (struct cmd_set_vf_vlan_tag_result,
12353                  on_off, "on#off");
12354
12355 static void
12356 cmd_set_vf_vlan_tag_parsed(
12357         void *parsed_result,
12358         __attribute__((unused)) struct cmdline *cl,
12359         __attribute__((unused)) void *data)
12360 {
12361         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12362         int ret = -ENOTSUP;
12363
12364         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12365
12366         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12367                 return;
12368
12369 #ifdef RTE_LIBRTE_I40E_PMD
12370         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12371                                            res->vf_id, is_on);
12372 #endif
12373
12374         switch (ret) {
12375         case 0:
12376                 break;
12377         case -EINVAL:
12378                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12379                 break;
12380         case -ENODEV:
12381                 printf("invalid port_id %d\n", res->port_id);
12382                 break;
12383         case -ENOTSUP:
12384                 printf("function not implemented\n");
12385                 break;
12386         default:
12387                 printf("programming error: (%s)\n", strerror(-ret));
12388         }
12389 }
12390
12391 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12392         .f = cmd_set_vf_vlan_tag_parsed,
12393         .data = NULL,
12394         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12395         .tokens = {
12396                 (void *)&cmd_set_vf_vlan_tag_set,
12397                 (void *)&cmd_set_vf_vlan_tag_vf,
12398                 (void *)&cmd_set_vf_vlan_tag_vlan,
12399                 (void *)&cmd_set_vf_vlan_tag_tag,
12400                 (void *)&cmd_set_vf_vlan_tag_port_id,
12401                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12402                 (void *)&cmd_set_vf_vlan_tag_on_off,
12403                 NULL,
12404         },
12405 };
12406
12407 /* Common definition of VF and TC TX bandwidth configuration */
12408 struct cmd_vf_tc_bw_result {
12409         cmdline_fixed_string_t set;
12410         cmdline_fixed_string_t vf;
12411         cmdline_fixed_string_t tx;
12412         cmdline_fixed_string_t max_bw;
12413         uint8_t port_id;
12414         uint16_t vf_id;
12415         uint32_t bw;
12416 };
12417
12418 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12419         TOKEN_STRING_INITIALIZER
12420                 (struct cmd_vf_tc_bw_result,
12421                  set, "set");
12422 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12423         TOKEN_STRING_INITIALIZER
12424                 (struct cmd_vf_tc_bw_result,
12425                  vf, "vf");
12426 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12427         TOKEN_STRING_INITIALIZER
12428                 (struct cmd_vf_tc_bw_result,
12429                  tx, "tx");
12430 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12431         TOKEN_STRING_INITIALIZER
12432                 (struct cmd_vf_tc_bw_result,
12433                  max_bw, "max-bandwidth");
12434 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12435         TOKEN_NUM_INITIALIZER
12436                 (struct cmd_vf_tc_bw_result,
12437                  port_id, UINT8);
12438 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12439         TOKEN_NUM_INITIALIZER
12440                 (struct cmd_vf_tc_bw_result,
12441                  vf_id, UINT16);
12442 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12443         TOKEN_NUM_INITIALIZER
12444                 (struct cmd_vf_tc_bw_result,
12445                  bw, UINT32);
12446
12447 /* VF max bandwidth setting */
12448 static void
12449 cmd_vf_max_bw_parsed(
12450         void *parsed_result,
12451         __attribute__((unused)) struct cmdline *cl,
12452         __attribute__((unused)) void *data)
12453 {
12454         struct cmd_vf_tc_bw_result *res = parsed_result;
12455         int ret = -ENOTSUP;
12456
12457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12458                 return;
12459
12460 #ifdef RTE_LIBRTE_I40E_PMD
12461         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12462                                          res->vf_id, res->bw);
12463 #endif
12464
12465         switch (ret) {
12466         case 0:
12467                 break;
12468         case -EINVAL:
12469                 printf("invalid vf_id %d or bandwidth %d\n",
12470                        res->vf_id, res->bw);
12471                 break;
12472         case -ENODEV:
12473                 printf("invalid port_id %d\n", res->port_id);
12474                 break;
12475         case -ENOTSUP:
12476                 printf("function not implemented\n");
12477                 break;
12478         default:
12479                 printf("programming error: (%s)\n", strerror(-ret));
12480         }
12481 }
12482
12483 cmdline_parse_inst_t cmd_vf_max_bw = {
12484         .f = cmd_vf_max_bw_parsed,
12485         .data = NULL,
12486         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12487         .tokens = {
12488                 (void *)&cmd_vf_tc_bw_set,
12489                 (void *)&cmd_vf_tc_bw_vf,
12490                 (void *)&cmd_vf_tc_bw_tx,
12491                 (void *)&cmd_vf_tc_bw_max_bw,
12492                 (void *)&cmd_vf_tc_bw_port_id,
12493                 (void *)&cmd_vf_tc_bw_vf_id,
12494                 (void *)&cmd_vf_tc_bw_bw,
12495                 NULL,
12496         },
12497 };
12498
12499 /* ******************************************************************************** */
12500
12501 /* list of instructions */
12502 cmdline_parse_ctx_t main_ctx[] = {
12503         (cmdline_parse_inst_t *)&cmd_help_brief,
12504         (cmdline_parse_inst_t *)&cmd_help_long,
12505         (cmdline_parse_inst_t *)&cmd_quit,
12506         (cmdline_parse_inst_t *)&cmd_showport,
12507         (cmdline_parse_inst_t *)&cmd_showqueue,
12508         (cmdline_parse_inst_t *)&cmd_showportall,
12509         (cmdline_parse_inst_t *)&cmd_showcfg,
12510         (cmdline_parse_inst_t *)&cmd_start,
12511         (cmdline_parse_inst_t *)&cmd_start_tx_first,
12512         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
12513         (cmdline_parse_inst_t *)&cmd_set_link_up,
12514         (cmdline_parse_inst_t *)&cmd_set_link_down,
12515         (cmdline_parse_inst_t *)&cmd_reset,
12516         (cmdline_parse_inst_t *)&cmd_set_numbers,
12517         (cmdline_parse_inst_t *)&cmd_set_txpkts,
12518         (cmdline_parse_inst_t *)&cmd_set_txsplit,
12519         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
12520         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
12521         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
12522         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
12523         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
12524         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
12525         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
12526         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
12527         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
12528         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
12529         (cmdline_parse_inst_t *)&cmd_set_link_check,
12530 #ifdef RTE_NIC_BYPASS
12531         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
12532         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
12533         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
12534         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
12535 #endif
12536 #ifdef RTE_LIBRTE_PMD_BOND
12537         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
12538         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
12539         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
12540         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
12541         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
12542         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
12543         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
12544         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
12545         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
12546 #endif
12547         (cmdline_parse_inst_t *)&cmd_vlan_offload,
12548         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
12549         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
12550         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
12551         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
12552         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
12553         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
12554         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
12555         (cmdline_parse_inst_t *)&cmd_csum_set,
12556         (cmdline_parse_inst_t *)&cmd_csum_show,
12557         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
12558         (cmdline_parse_inst_t *)&cmd_tso_set,
12559         (cmdline_parse_inst_t *)&cmd_tso_show,
12560         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
12561         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
12562         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
12563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
12564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
12565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
12566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
12567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
12568         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
12569         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
12570         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
12571         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
12572         (cmdline_parse_inst_t *)&cmd_config_dcb,
12573         (cmdline_parse_inst_t *)&cmd_read_reg,
12574         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
12575         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
12576         (cmdline_parse_inst_t *)&cmd_write_reg,
12577         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
12578         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
12579         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
12580         (cmdline_parse_inst_t *)&cmd_stop,
12581         (cmdline_parse_inst_t *)&cmd_mac_addr,
12582         (cmdline_parse_inst_t *)&cmd_set_qmap,
12583         (cmdline_parse_inst_t *)&cmd_operate_port,
12584         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
12585         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
12586         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
12587         (cmdline_parse_inst_t *)&cmd_config_speed_all,
12588         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
12589         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
12590         (cmdline_parse_inst_t *)&cmd_config_mtu,
12591         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
12592         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
12593         (cmdline_parse_inst_t *)&cmd_config_rss,
12594         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
12595         (cmdline_parse_inst_t *)&cmd_config_txqflags,
12596         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
12597         (cmdline_parse_inst_t *)&cmd_showport_reta,
12598         (cmdline_parse_inst_t *)&cmd_config_burst,
12599         (cmdline_parse_inst_t *)&cmd_config_thresh,
12600         (cmdline_parse_inst_t *)&cmd_config_threshold,
12601         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
12602         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
12603         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
12604         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
12605         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
12606         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
12607         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
12608         (cmdline_parse_inst_t *)&cmd_global_config,
12609         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
12610         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
12611         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
12612         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
12613         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
12614         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
12615         (cmdline_parse_inst_t *)&cmd_dump,
12616         (cmdline_parse_inst_t *)&cmd_dump_one,
12617         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
12618         (cmdline_parse_inst_t *)&cmd_syn_filter,
12619         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
12620         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
12621         (cmdline_parse_inst_t *)&cmd_flex_filter,
12622         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
12623         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
12624         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
12625         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
12626         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
12627         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
12628         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
12629         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
12630         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
12631         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
12632         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
12633         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
12634         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
12635         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
12636         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
12637         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
12638         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
12639         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
12640         (cmdline_parse_inst_t *)&cmd_flow,
12641         (cmdline_parse_inst_t *)&cmd_mcast_addr,
12642         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
12643         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
12644         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
12645         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
12646         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
12647         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
12648         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
12649         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
12650         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
12651         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
12652         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
12653         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
12654         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
12655         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
12656         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
12657 #ifdef RTE_LIBRTE_IXGBE_PMD
12658         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
12659         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
12660         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
12661         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
12662         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
12663         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
12664         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
12665         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
12666         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
12667 #endif
12668         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
12669         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
12670         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
12671         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
12672         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
12673         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
12674         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
12675         NULL,
12676 };
12677
12678 /* prompt function, called from main on MASTER lcore */
12679 void
12680 prompt(void)
12681 {
12682         /* initialize non-constant commands */
12683         cmd_set_fwd_mode_init();
12684         cmd_set_fwd_retry_mode_init();
12685
12686         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
12687         if (testpmd_cl == NULL)
12688                 return;
12689         cmdline_interact(testpmd_cl);
12690         cmdline_stdin_exit(testpmd_cl);
12691 }
12692
12693 void
12694 prompt_exit(void)
12695 {
12696         if (testpmd_cl != NULL)
12697                 cmdline_quit(testpmd_cl);
12698 }
12699
12700 static void
12701 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
12702 {
12703         if (id == (portid_t)RTE_PORT_ALL) {
12704                 portid_t pid;
12705
12706                 FOREACH_PORT(pid, ports) {
12707                         /* check if need_reconfig has been set to 1 */
12708                         if (ports[pid].need_reconfig == 0)
12709                                 ports[pid].need_reconfig = dev;
12710                         /* check if need_reconfig_queues has been set to 1 */
12711                         if (ports[pid].need_reconfig_queues == 0)
12712                                 ports[pid].need_reconfig_queues = queue;
12713                 }
12714         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
12715                 /* check if need_reconfig has been set to 1 */
12716                 if (ports[id].need_reconfig == 0)
12717                         ports[id].need_reconfig = dev;
12718                 /* check if need_reconfig_queues has been set to 1 */
12719                 if (ports[id].need_reconfig_queues == 0)
12720                         ports[id].need_reconfig_queues = queue;
12721         }
12722 }