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