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