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