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