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