app/testpmd: use ixgbe public functions
[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 #ifdef RTE_LIBRTE_IXGBE_PMD
6658 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6659 struct cmd_set_vf_traffic {
6660         cmdline_fixed_string_t set;
6661         cmdline_fixed_string_t port;
6662         uint8_t port_id;
6663         cmdline_fixed_string_t vf;
6664         uint8_t vf_id;
6665         cmdline_fixed_string_t what;
6666         cmdline_fixed_string_t mode;
6667 };
6668
6669 static void
6670 cmd_set_vf_traffic_parsed(void *parsed_result,
6671                        __attribute__((unused)) struct cmdline *cl,
6672                        __attribute__((unused)) void *data)
6673 {
6674         struct cmd_set_vf_traffic *res = parsed_result;
6675         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6676         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6677
6678         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6679 }
6680
6681 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6682         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6683                                  set, "set");
6684 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6685         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6686                                  port, "port");
6687 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6688         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6689                               port_id, UINT8);
6690 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6691         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6692                                  vf, "vf");
6693 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6694         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6695                               vf_id, UINT8);
6696 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6697         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6698                                  what, "tx#rx");
6699 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6700         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6701                                  mode, "on#off");
6702
6703 cmdline_parse_inst_t cmd_set_vf_traffic = {
6704         .f = cmd_set_vf_traffic_parsed,
6705         .data = NULL,
6706         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
6707         .tokens = {
6708                 (void *)&cmd_setvf_traffic_set,
6709                 (void *)&cmd_setvf_traffic_port,
6710                 (void *)&cmd_setvf_traffic_portid,
6711                 (void *)&cmd_setvf_traffic_vf,
6712                 (void *)&cmd_setvf_traffic_vfid,
6713                 (void *)&cmd_setvf_traffic_what,
6714                 (void *)&cmd_setvf_traffic_mode,
6715                 NULL,
6716         },
6717 };
6718 #endif
6719
6720 #ifdef RTE_LIBRTE_IXGBE_PMD
6721 /* *** CONFIGURE VF RECEIVE MODE *** */
6722 struct cmd_set_vf_rxmode {
6723         cmdline_fixed_string_t set;
6724         cmdline_fixed_string_t port;
6725         uint8_t port_id;
6726         cmdline_fixed_string_t vf;
6727         uint8_t vf_id;
6728         cmdline_fixed_string_t what;
6729         cmdline_fixed_string_t mode;
6730         cmdline_fixed_string_t on;
6731 };
6732
6733 static void
6734 cmd_set_vf_rxmode_parsed(void *parsed_result,
6735                        __attribute__((unused)) struct cmdline *cl,
6736                        __attribute__((unused)) void *data)
6737 {
6738         int ret;
6739         uint16_t rx_mode = 0;
6740         struct cmd_set_vf_rxmode *res = parsed_result;
6741
6742         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6743         if (!strcmp(res->what,"rxmode")) {
6744                 if (!strcmp(res->mode, "AUPE"))
6745                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6746                 else if (!strcmp(res->mode, "ROPE"))
6747                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6748                 else if (!strcmp(res->mode, "BAM"))
6749                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6750                 else if (!strncmp(res->mode, "MPE",3))
6751                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6752         }
6753
6754         ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, rx_mode, (uint8_t)is_on);
6755         if (ret < 0)
6756                 printf("bad VF receive mode parameter, return code = %d \n",
6757                 ret);
6758 }
6759
6760 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6761         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6762                                  set, "set");
6763 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6764         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6765                                  port, "port");
6766 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6767         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6768                               port_id, UINT8);
6769 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6770         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6771                                  vf, "vf");
6772 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6773         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6774                               vf_id, UINT8);
6775 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6776         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6777                                  what, "rxmode");
6778 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6779         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6780                                  mode, "AUPE#ROPE#BAM#MPE");
6781 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6782         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6783                                  on, "on#off");
6784
6785 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6786         .f = cmd_set_vf_rxmode_parsed,
6787         .data = NULL,
6788         .help_str = "set port <port_id> vf <vf_id> rxmode "
6789                 "AUPE|ROPE|BAM|MPE on|off",
6790         .tokens = {
6791                 (void *)&cmd_set_vf_rxmode_set,
6792                 (void *)&cmd_set_vf_rxmode_port,
6793                 (void *)&cmd_set_vf_rxmode_portid,
6794                 (void *)&cmd_set_vf_rxmode_vf,
6795                 (void *)&cmd_set_vf_rxmode_vfid,
6796                 (void *)&cmd_set_vf_rxmode_what,
6797                 (void *)&cmd_set_vf_rxmode_mode,
6798                 (void *)&cmd_set_vf_rxmode_on,
6799                 NULL,
6800         },
6801 };
6802 #endif
6803
6804 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6805 struct cmd_vf_mac_addr_result {
6806         cmdline_fixed_string_t mac_addr_cmd;
6807         cmdline_fixed_string_t what;
6808         cmdline_fixed_string_t port;
6809         uint8_t port_num;
6810         cmdline_fixed_string_t vf;
6811         uint8_t vf_num;
6812         struct ether_addr address;
6813 };
6814
6815 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6816                 __attribute__((unused)) struct cmdline *cl,
6817                 __attribute__((unused)) void *data)
6818 {
6819         struct cmd_vf_mac_addr_result *res = parsed_result;
6820         int ret = 0;
6821
6822         if (strcmp(res->what, "add") == 0)
6823                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6824                                         &res->address, res->vf_num);
6825         if(ret < 0)
6826                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6827
6828 }
6829
6830 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6831         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6832                                 mac_addr_cmd,"mac_addr");
6833 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6834         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6835                                 what,"add");
6836 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6837         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6838                                 port,"port");
6839 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6840         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6841                                 port_num, UINT8);
6842 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6843         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6844                                 vf,"vf");
6845 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6846         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6847                                 vf_num, UINT8);
6848 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6849         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6850                                 address);
6851
6852 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6853         .f = cmd_vf_mac_addr_parsed,
6854         .data = (void *)0,
6855         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
6856                 "Add MAC address filtering for a VF on port_id",
6857         .tokens = {
6858                 (void *)&cmd_vf_mac_addr_cmd,
6859                 (void *)&cmd_vf_mac_addr_what,
6860                 (void *)&cmd_vf_mac_addr_port,
6861                 (void *)&cmd_vf_mac_addr_portnum,
6862                 (void *)&cmd_vf_mac_addr_vf,
6863                 (void *)&cmd_vf_mac_addr_vfnum,
6864                 (void *)&cmd_vf_mac_addr_addr,
6865                 NULL,
6866         },
6867 };
6868
6869 #ifdef RTE_LIBRTE_IXGBE_PMD
6870 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6871 struct cmd_vf_rx_vlan_filter {
6872         cmdline_fixed_string_t rx_vlan;
6873         cmdline_fixed_string_t what;
6874         uint16_t vlan_id;
6875         cmdline_fixed_string_t port;
6876         uint8_t port_id;
6877         cmdline_fixed_string_t vf;
6878         uint64_t vf_mask;
6879 };
6880
6881 static void
6882 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6883                           __attribute__((unused)) struct cmdline *cl,
6884                           __attribute__((unused)) void *data)
6885 {
6886         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6887
6888         if (!strcmp(res->what, "add"))
6889                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6890         else
6891                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6892 }
6893
6894 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6895         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6896                                  rx_vlan, "rx_vlan");
6897 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6898         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6899                                  what, "add#rm");
6900 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6901         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6902                               vlan_id, UINT16);
6903 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6904         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6905                                  port, "port");
6906 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6907         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6908                               port_id, UINT8);
6909 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6910         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6911                                  vf, "vf");
6912 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6913         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6914                               vf_mask, UINT64);
6915
6916 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6917         .f = cmd_vf_rx_vlan_filter_parsed,
6918         .data = NULL,
6919         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
6920                 "(vf_mask = hexadecimal VF mask)",
6921         .tokens = {
6922                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6923                 (void *)&cmd_vf_rx_vlan_filter_what,
6924                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6925                 (void *)&cmd_vf_rx_vlan_filter_port,
6926                 (void *)&cmd_vf_rx_vlan_filter_portid,
6927                 (void *)&cmd_vf_rx_vlan_filter_vf,
6928                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6929                 NULL,
6930         },
6931 };
6932 #endif
6933
6934 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6935 struct cmd_queue_rate_limit_result {
6936         cmdline_fixed_string_t set;
6937         cmdline_fixed_string_t port;
6938         uint8_t port_num;
6939         cmdline_fixed_string_t queue;
6940         uint8_t queue_num;
6941         cmdline_fixed_string_t rate;
6942         uint16_t rate_num;
6943 };
6944
6945 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6946                 __attribute__((unused)) struct cmdline *cl,
6947                 __attribute__((unused)) void *data)
6948 {
6949         struct cmd_queue_rate_limit_result *res = parsed_result;
6950         int ret = 0;
6951
6952         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6953                 && (strcmp(res->queue, "queue") == 0)
6954                 && (strcmp(res->rate, "rate") == 0))
6955                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6956                                         res->rate_num);
6957         if (ret < 0)
6958                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6959
6960 }
6961
6962 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6963         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6964                                 set, "set");
6965 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6966         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6967                                 port, "port");
6968 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6969         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6970                                 port_num, UINT8);
6971 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6972         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6973                                 queue, "queue");
6974 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6975         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6976                                 queue_num, UINT8);
6977 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6978         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6979                                 rate, "rate");
6980 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6981         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6982                                 rate_num, UINT16);
6983
6984 cmdline_parse_inst_t cmd_queue_rate_limit = {
6985         .f = cmd_queue_rate_limit_parsed,
6986         .data = (void *)0,
6987         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
6988                 "Set rate limit for a queue on port_id",
6989         .tokens = {
6990                 (void *)&cmd_queue_rate_limit_set,
6991                 (void *)&cmd_queue_rate_limit_port,
6992                 (void *)&cmd_queue_rate_limit_portnum,
6993                 (void *)&cmd_queue_rate_limit_queue,
6994                 (void *)&cmd_queue_rate_limit_queuenum,
6995                 (void *)&cmd_queue_rate_limit_rate,
6996                 (void *)&cmd_queue_rate_limit_ratenum,
6997                 NULL,
6998         },
6999 };
7000
7001 #ifdef RTE_LIBRTE_IXGBE_PMD
7002 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7003 struct cmd_vf_rate_limit_result {
7004         cmdline_fixed_string_t set;
7005         cmdline_fixed_string_t port;
7006         uint8_t port_num;
7007         cmdline_fixed_string_t vf;
7008         uint8_t vf_num;
7009         cmdline_fixed_string_t rate;
7010         uint16_t rate_num;
7011         cmdline_fixed_string_t q_msk;
7012         uint64_t q_msk_val;
7013 };
7014
7015 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7016                 __attribute__((unused)) struct cmdline *cl,
7017                 __attribute__((unused)) void *data)
7018 {
7019         struct cmd_vf_rate_limit_result *res = parsed_result;
7020         int ret = 0;
7021
7022         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7023                 && (strcmp(res->vf, "vf") == 0)
7024                 && (strcmp(res->rate, "rate") == 0)
7025                 && (strcmp(res->q_msk, "queue_mask") == 0))
7026                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7027                                         res->rate_num, res->q_msk_val);
7028         if (ret < 0)
7029                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7030
7031 }
7032
7033 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7034         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7035                                 set, "set");
7036 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7037         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7038                                 port, "port");
7039 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7040         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7041                                 port_num, UINT8);
7042 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7043         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7044                                 vf, "vf");
7045 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7046         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7047                                 vf_num, UINT8);
7048 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7049         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7050                                 rate, "rate");
7051 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7052         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7053                                 rate_num, UINT16);
7054 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7055         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7056                                 q_msk, "queue_mask");
7057 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7058         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7059                                 q_msk_val, UINT64);
7060
7061 cmdline_parse_inst_t cmd_vf_rate_limit = {
7062         .f = cmd_vf_rate_limit_parsed,
7063         .data = (void *)0,
7064         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7065                 "queue_mask <queue_mask_value>: "
7066                 "Set rate limit for queues of VF on port_id",
7067         .tokens = {
7068                 (void *)&cmd_vf_rate_limit_set,
7069                 (void *)&cmd_vf_rate_limit_port,
7070                 (void *)&cmd_vf_rate_limit_portnum,
7071                 (void *)&cmd_vf_rate_limit_vf,
7072                 (void *)&cmd_vf_rate_limit_vfnum,
7073                 (void *)&cmd_vf_rate_limit_rate,
7074                 (void *)&cmd_vf_rate_limit_ratenum,
7075                 (void *)&cmd_vf_rate_limit_q_msk,
7076                 (void *)&cmd_vf_rate_limit_q_msk_val,
7077                 NULL,
7078         },
7079 };
7080 #endif
7081
7082 /* *** ADD TUNNEL FILTER OF A PORT *** */
7083 struct cmd_tunnel_filter_result {
7084         cmdline_fixed_string_t cmd;
7085         cmdline_fixed_string_t what;
7086         uint8_t port_id;
7087         struct ether_addr outer_mac;
7088         struct ether_addr inner_mac;
7089         cmdline_ipaddr_t ip_value;
7090         uint16_t inner_vlan;
7091         cmdline_fixed_string_t tunnel_type;
7092         cmdline_fixed_string_t filter_type;
7093         uint32_t tenant_id;
7094         uint16_t queue_num;
7095 };
7096
7097 static void
7098 cmd_tunnel_filter_parsed(void *parsed_result,
7099                           __attribute__((unused)) struct cmdline *cl,
7100                           __attribute__((unused)) void *data)
7101 {
7102         struct cmd_tunnel_filter_result *res = parsed_result;
7103         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7104         int ret = 0;
7105
7106         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7107
7108         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7109         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7110         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7111
7112         if (res->ip_value.family == AF_INET) {
7113                 tunnel_filter_conf.ip_addr.ipv4_addr =
7114                         res->ip_value.addr.ipv4.s_addr;
7115                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7116         } else {
7117                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7118                         &(res->ip_value.addr.ipv6),
7119                         sizeof(struct in6_addr));
7120                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7121         }
7122
7123         if (!strcmp(res->filter_type, "imac-ivlan"))
7124                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7125         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7126                 tunnel_filter_conf.filter_type =
7127                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7128         else if (!strcmp(res->filter_type, "imac-tenid"))
7129                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7130         else if (!strcmp(res->filter_type, "imac"))
7131                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7132         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7133                 tunnel_filter_conf.filter_type =
7134                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7135         else if (!strcmp(res->filter_type, "oip"))
7136                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7137         else if (!strcmp(res->filter_type, "iip"))
7138                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7139         else {
7140                 printf("The filter type is not supported");
7141                 return;
7142         }
7143
7144         if (!strcmp(res->tunnel_type, "vxlan"))
7145                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7146         else if (!strcmp(res->tunnel_type, "nvgre"))
7147                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7148         else if (!strcmp(res->tunnel_type, "ipingre"))
7149                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7150         else {
7151                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7152                 return;
7153         }
7154
7155         tunnel_filter_conf.tenant_id = res->tenant_id;
7156         tunnel_filter_conf.queue_id = res->queue_num;
7157         if (!strcmp(res->what, "add"))
7158                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7159                                         RTE_ETH_FILTER_TUNNEL,
7160                                         RTE_ETH_FILTER_ADD,
7161                                         &tunnel_filter_conf);
7162         else
7163                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7164                                         RTE_ETH_FILTER_TUNNEL,
7165                                         RTE_ETH_FILTER_DELETE,
7166                                         &tunnel_filter_conf);
7167         if (ret < 0)
7168                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7169                                 strerror(-ret));
7170
7171 }
7172 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7173         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7174         cmd, "tunnel_filter");
7175 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7176         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7177         what, "add#rm");
7178 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7179         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7180         port_id, UINT8);
7181 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7182         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7183         outer_mac);
7184 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7185         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7186         inner_mac);
7187 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7188         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7189         inner_vlan, UINT16);
7190 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7191         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7192         ip_value);
7193 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7194         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7195         tunnel_type, "vxlan#nvgre#ipingre");
7196
7197 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7198         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7199         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7200                 "imac#omac-imac-tenid");
7201 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7202         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7203         tenant_id, UINT32);
7204 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7205         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7206         queue_num, UINT16);
7207
7208 cmdline_parse_inst_t cmd_tunnel_filter = {
7209         .f = cmd_tunnel_filter_parsed,
7210         .data = (void *)0,
7211         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7212                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7213                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7214                 "<queue_id>: Add/Rm tunnel filter of a port",
7215         .tokens = {
7216                 (void *)&cmd_tunnel_filter_cmd,
7217                 (void *)&cmd_tunnel_filter_what,
7218                 (void *)&cmd_tunnel_filter_port_id,
7219                 (void *)&cmd_tunnel_filter_outer_mac,
7220                 (void *)&cmd_tunnel_filter_inner_mac,
7221                 (void *)&cmd_tunnel_filter_ip_value,
7222                 (void *)&cmd_tunnel_filter_innner_vlan,
7223                 (void *)&cmd_tunnel_filter_tunnel_type,
7224                 (void *)&cmd_tunnel_filter_filter_type,
7225                 (void *)&cmd_tunnel_filter_tenant_id,
7226                 (void *)&cmd_tunnel_filter_queue_num,
7227                 NULL,
7228         },
7229 };
7230
7231 /* *** CONFIGURE TUNNEL UDP PORT *** */
7232 struct cmd_tunnel_udp_config {
7233         cmdline_fixed_string_t cmd;
7234         cmdline_fixed_string_t what;
7235         uint16_t udp_port;
7236         uint8_t port_id;
7237 };
7238
7239 static void
7240 cmd_tunnel_udp_config_parsed(void *parsed_result,
7241                           __attribute__((unused)) struct cmdline *cl,
7242                           __attribute__((unused)) void *data)
7243 {
7244         struct cmd_tunnel_udp_config *res = parsed_result;
7245         struct rte_eth_udp_tunnel tunnel_udp;
7246         int ret;
7247
7248         tunnel_udp.udp_port = res->udp_port;
7249
7250         if (!strcmp(res->cmd, "rx_vxlan_port"))
7251                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7252
7253         if (!strcmp(res->what, "add"))
7254                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7255                                                       &tunnel_udp);
7256         else
7257                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7258                                                          &tunnel_udp);
7259
7260         if (ret < 0)
7261                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7262 }
7263
7264 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7265         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7266                                 cmd, "rx_vxlan_port");
7267 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7268         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7269                                 what, "add#rm");
7270 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7271         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7272                                 udp_port, UINT16);
7273 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7274         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7275                                 port_id, UINT8);
7276
7277 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7278         .f = cmd_tunnel_udp_config_parsed,
7279         .data = (void *)0,
7280         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7281                 "Add/Remove a tunneling UDP port filter",
7282         .tokens = {
7283                 (void *)&cmd_tunnel_udp_config_cmd,
7284                 (void *)&cmd_tunnel_udp_config_what,
7285                 (void *)&cmd_tunnel_udp_config_udp_port,
7286                 (void *)&cmd_tunnel_udp_config_port_id,
7287                 NULL,
7288         },
7289 };
7290
7291 /* *** GLOBAL CONFIG *** */
7292 struct cmd_global_config_result {
7293         cmdline_fixed_string_t cmd;
7294         uint8_t port_id;
7295         cmdline_fixed_string_t cfg_type;
7296         uint8_t len;
7297 };
7298
7299 static void
7300 cmd_global_config_parsed(void *parsed_result,
7301                          __attribute__((unused)) struct cmdline *cl,
7302                          __attribute__((unused)) void *data)
7303 {
7304         struct cmd_global_config_result *res = parsed_result;
7305         struct rte_eth_global_cfg conf;
7306         int ret;
7307
7308         memset(&conf, 0, sizeof(conf));
7309         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7310         conf.cfg.gre_key_len = res->len;
7311         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7312                                       RTE_ETH_FILTER_SET, &conf);
7313         if (ret != 0)
7314                 printf("Global config error\n");
7315 }
7316
7317 cmdline_parse_token_string_t cmd_global_config_cmd =
7318         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7319                 "global_config");
7320 cmdline_parse_token_num_t cmd_global_config_port_id =
7321         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7322 cmdline_parse_token_string_t cmd_global_config_type =
7323         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7324                 cfg_type, "gre-key-len");
7325 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7326         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7327                 len, UINT8);
7328
7329 cmdline_parse_inst_t cmd_global_config = {
7330         .f = cmd_global_config_parsed,
7331         .data = (void *)NULL,
7332         .help_str = "global_config <port_id> gre-key-len <key_len>",
7333         .tokens = {
7334                 (void *)&cmd_global_config_cmd,
7335                 (void *)&cmd_global_config_port_id,
7336                 (void *)&cmd_global_config_type,
7337                 (void *)&cmd_global_config_gre_key_len,
7338                 NULL,
7339         },
7340 };
7341
7342 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7343 struct cmd_set_mirror_mask_result {
7344         cmdline_fixed_string_t set;
7345         cmdline_fixed_string_t port;
7346         uint8_t port_id;
7347         cmdline_fixed_string_t mirror;
7348         uint8_t rule_id;
7349         cmdline_fixed_string_t what;
7350         cmdline_fixed_string_t value;
7351         cmdline_fixed_string_t dstpool;
7352         uint8_t dstpool_id;
7353         cmdline_fixed_string_t on;
7354 };
7355
7356 cmdline_parse_token_string_t cmd_mirror_mask_set =
7357         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7358                                 set, "set");
7359 cmdline_parse_token_string_t cmd_mirror_mask_port =
7360         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7361                                 port, "port");
7362 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7363         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7364                                 port_id, UINT8);
7365 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7366         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7367                                 mirror, "mirror-rule");
7368 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7369         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7370                                 rule_id, UINT8);
7371 cmdline_parse_token_string_t cmd_mirror_mask_what =
7372         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7373                                 what, "pool-mirror-up#pool-mirror-down"
7374                                       "#vlan-mirror");
7375 cmdline_parse_token_string_t cmd_mirror_mask_value =
7376         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7377                                 value, NULL);
7378 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7379         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7380                                 dstpool, "dst-pool");
7381 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7382         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7383                                 dstpool_id, UINT8);
7384 cmdline_parse_token_string_t cmd_mirror_mask_on =
7385         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7386                                 on, "on#off");
7387
7388 static void
7389 cmd_set_mirror_mask_parsed(void *parsed_result,
7390                        __attribute__((unused)) struct cmdline *cl,
7391                        __attribute__((unused)) void *data)
7392 {
7393         int ret,nb_item,i;
7394         struct cmd_set_mirror_mask_result *res = parsed_result;
7395         struct rte_eth_mirror_conf mr_conf;
7396
7397         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7398
7399         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7400
7401         mr_conf.dst_pool = res->dstpool_id;
7402
7403         if (!strcmp(res->what, "pool-mirror-up")) {
7404                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7405                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7406         } else if (!strcmp(res->what, "pool-mirror-down")) {
7407                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7408                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7409         } else if (!strcmp(res->what, "vlan-mirror")) {
7410                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7411                 nb_item = parse_item_list(res->value, "vlan",
7412                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7413                 if (nb_item <= 0)
7414                         return;
7415
7416                 for (i = 0; i < nb_item; i++) {
7417                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7418                                 printf("Invalid vlan_id: must be < 4096\n");
7419                                 return;
7420                         }
7421
7422                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7423                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7424                 }
7425         }
7426
7427         if (!strcmp(res->on, "on"))
7428                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7429                                                 res->rule_id, 1);
7430         else
7431                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7432                                                 res->rule_id, 0);
7433         if (ret < 0)
7434                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7435 }
7436
7437 cmdline_parse_inst_t cmd_set_mirror_mask = {
7438                 .f = cmd_set_mirror_mask_parsed,
7439                 .data = NULL,
7440                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7441                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7442                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7443                 .tokens = {
7444                         (void *)&cmd_mirror_mask_set,
7445                         (void *)&cmd_mirror_mask_port,
7446                         (void *)&cmd_mirror_mask_portid,
7447                         (void *)&cmd_mirror_mask_mirror,
7448                         (void *)&cmd_mirror_mask_ruleid,
7449                         (void *)&cmd_mirror_mask_what,
7450                         (void *)&cmd_mirror_mask_value,
7451                         (void *)&cmd_mirror_mask_dstpool,
7452                         (void *)&cmd_mirror_mask_poolid,
7453                         (void *)&cmd_mirror_mask_on,
7454                         NULL,
7455                 },
7456 };
7457
7458 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
7459 struct cmd_set_mirror_link_result {
7460         cmdline_fixed_string_t set;
7461         cmdline_fixed_string_t port;
7462         uint8_t port_id;
7463         cmdline_fixed_string_t mirror;
7464         uint8_t rule_id;
7465         cmdline_fixed_string_t what;
7466         cmdline_fixed_string_t dstpool;
7467         uint8_t dstpool_id;
7468         cmdline_fixed_string_t on;
7469 };
7470
7471 cmdline_parse_token_string_t cmd_mirror_link_set =
7472         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7473                                  set, "set");
7474 cmdline_parse_token_string_t cmd_mirror_link_port =
7475         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7476                                 port, "port");
7477 cmdline_parse_token_num_t cmd_mirror_link_portid =
7478         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7479                                 port_id, UINT8);
7480 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7481         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7482                                 mirror, "mirror-rule");
7483 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7484         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7485                             rule_id, UINT8);
7486 cmdline_parse_token_string_t cmd_mirror_link_what =
7487         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7488                                 what, "uplink-mirror#downlink-mirror");
7489 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7490         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7491                                 dstpool, "dst-pool");
7492 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7493         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7494                                 dstpool_id, UINT8);
7495 cmdline_parse_token_string_t cmd_mirror_link_on =
7496         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7497                                 on, "on#off");
7498
7499 static void
7500 cmd_set_mirror_link_parsed(void *parsed_result,
7501                        __attribute__((unused)) struct cmdline *cl,
7502                        __attribute__((unused)) void *data)
7503 {
7504         int ret;
7505         struct cmd_set_mirror_link_result *res = parsed_result;
7506         struct rte_eth_mirror_conf mr_conf;
7507
7508         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7509         if (!strcmp(res->what, "uplink-mirror"))
7510                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7511         else
7512                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7513
7514         mr_conf.dst_pool = res->dstpool_id;
7515
7516         if (!strcmp(res->on, "on"))
7517                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7518                                                 res->rule_id, 1);
7519         else
7520                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7521                                                 res->rule_id, 0);
7522
7523         /* check the return value and print it if is < 0 */
7524         if (ret < 0)
7525                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7526
7527 }
7528
7529 cmdline_parse_inst_t cmd_set_mirror_link = {
7530                 .f = cmd_set_mirror_link_parsed,
7531                 .data = NULL,
7532                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7533                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7534                 .tokens = {
7535                         (void *)&cmd_mirror_link_set,
7536                         (void *)&cmd_mirror_link_port,
7537                         (void *)&cmd_mirror_link_portid,
7538                         (void *)&cmd_mirror_link_mirror,
7539                         (void *)&cmd_mirror_link_ruleid,
7540                         (void *)&cmd_mirror_link_what,
7541                         (void *)&cmd_mirror_link_dstpool,
7542                         (void *)&cmd_mirror_link_poolid,
7543                         (void *)&cmd_mirror_link_on,
7544                         NULL,
7545                 },
7546 };
7547
7548 /* *** RESET VM MIRROR RULE *** */
7549 struct cmd_rm_mirror_rule_result {
7550         cmdline_fixed_string_t reset;
7551         cmdline_fixed_string_t port;
7552         uint8_t port_id;
7553         cmdline_fixed_string_t mirror;
7554         uint8_t rule_id;
7555 };
7556
7557 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7558         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7559                                  reset, "reset");
7560 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7561         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7562                                 port, "port");
7563 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7564         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7565                                 port_id, UINT8);
7566 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7567         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7568                                 mirror, "mirror-rule");
7569 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7570         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7571                                 rule_id, UINT8);
7572
7573 static void
7574 cmd_reset_mirror_rule_parsed(void *parsed_result,
7575                        __attribute__((unused)) struct cmdline *cl,
7576                        __attribute__((unused)) void *data)
7577 {
7578         int ret;
7579         struct cmd_set_mirror_link_result *res = parsed_result;
7580         /* check rule_id */
7581         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7582         if(ret < 0)
7583                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7584 }
7585
7586 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7587                 .f = cmd_reset_mirror_rule_parsed,
7588                 .data = NULL,
7589                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
7590                 .tokens = {
7591                         (void *)&cmd_rm_mirror_rule_reset,
7592                         (void *)&cmd_rm_mirror_rule_port,
7593                         (void *)&cmd_rm_mirror_rule_portid,
7594                         (void *)&cmd_rm_mirror_rule_mirror,
7595                         (void *)&cmd_rm_mirror_rule_ruleid,
7596                         NULL,
7597                 },
7598 };
7599
7600 /* ******************************************************************************** */
7601
7602 struct cmd_dump_result {
7603         cmdline_fixed_string_t dump;
7604 };
7605
7606 static void
7607 dump_struct_sizes(void)
7608 {
7609 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7610         DUMP_SIZE(struct rte_mbuf);
7611         DUMP_SIZE(struct rte_mempool);
7612         DUMP_SIZE(struct rte_ring);
7613 #undef DUMP_SIZE
7614 }
7615
7616 static void cmd_dump_parsed(void *parsed_result,
7617                             __attribute__((unused)) struct cmdline *cl,
7618                             __attribute__((unused)) void *data)
7619 {
7620         struct cmd_dump_result *res = parsed_result;
7621
7622         if (!strcmp(res->dump, "dump_physmem"))
7623                 rte_dump_physmem_layout(stdout);
7624         else if (!strcmp(res->dump, "dump_memzone"))
7625                 rte_memzone_dump(stdout);
7626         else if (!strcmp(res->dump, "dump_struct_sizes"))
7627                 dump_struct_sizes();
7628         else if (!strcmp(res->dump, "dump_ring"))
7629                 rte_ring_list_dump(stdout);
7630         else if (!strcmp(res->dump, "dump_mempool"))
7631                 rte_mempool_list_dump(stdout);
7632         else if (!strcmp(res->dump, "dump_devargs"))
7633                 rte_eal_devargs_dump(stdout);
7634 }
7635
7636 cmdline_parse_token_string_t cmd_dump_dump =
7637         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7638                 "dump_physmem#"
7639                 "dump_memzone#"
7640                 "dump_struct_sizes#"
7641                 "dump_ring#"
7642                 "dump_mempool#"
7643                 "dump_devargs");
7644
7645 cmdline_parse_inst_t cmd_dump = {
7646         .f = cmd_dump_parsed,  /* function to call */
7647         .data = NULL,      /* 2nd arg of func */
7648         .help_str = "Dump status",
7649         .tokens = {        /* token list, NULL terminated */
7650                 (void *)&cmd_dump_dump,
7651                 NULL,
7652         },
7653 };
7654
7655 /* ******************************************************************************** */
7656
7657 struct cmd_dump_one_result {
7658         cmdline_fixed_string_t dump;
7659         cmdline_fixed_string_t name;
7660 };
7661
7662 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7663                                 __attribute__((unused)) void *data)
7664 {
7665         struct cmd_dump_one_result *res = parsed_result;
7666
7667         if (!strcmp(res->dump, "dump_ring")) {
7668                 struct rte_ring *r;
7669                 r = rte_ring_lookup(res->name);
7670                 if (r == NULL) {
7671                         cmdline_printf(cl, "Cannot find ring\n");
7672                         return;
7673                 }
7674                 rte_ring_dump(stdout, r);
7675         } else if (!strcmp(res->dump, "dump_mempool")) {
7676                 struct rte_mempool *mp;
7677                 mp = rte_mempool_lookup(res->name);
7678                 if (mp == NULL) {
7679                         cmdline_printf(cl, "Cannot find mempool\n");
7680                         return;
7681                 }
7682                 rte_mempool_dump(stdout, mp);
7683         }
7684 }
7685
7686 cmdline_parse_token_string_t cmd_dump_one_dump =
7687         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7688                                  "dump_ring#dump_mempool");
7689
7690 cmdline_parse_token_string_t cmd_dump_one_name =
7691         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7692
7693 cmdline_parse_inst_t cmd_dump_one = {
7694         .f = cmd_dump_one_parsed,  /* function to call */
7695         .data = NULL,      /* 2nd arg of func */
7696         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
7697         .tokens = {        /* token list, NULL terminated */
7698                 (void *)&cmd_dump_one_dump,
7699                 (void *)&cmd_dump_one_name,
7700                 NULL,
7701         },
7702 };
7703
7704 /* *** Add/Del syn filter *** */
7705 struct cmd_syn_filter_result {
7706         cmdline_fixed_string_t filter;
7707         uint8_t port_id;
7708         cmdline_fixed_string_t ops;
7709         cmdline_fixed_string_t priority;
7710         cmdline_fixed_string_t high;
7711         cmdline_fixed_string_t queue;
7712         uint16_t queue_id;
7713 };
7714
7715 static void
7716 cmd_syn_filter_parsed(void *parsed_result,
7717                         __attribute__((unused)) struct cmdline *cl,
7718                         __attribute__((unused)) void *data)
7719 {
7720         struct cmd_syn_filter_result *res = parsed_result;
7721         struct rte_eth_syn_filter syn_filter;
7722         int ret = 0;
7723
7724         ret = rte_eth_dev_filter_supported(res->port_id,
7725                                         RTE_ETH_FILTER_SYN);
7726         if (ret < 0) {
7727                 printf("syn filter is not supported on port %u.\n",
7728                                 res->port_id);
7729                 return;
7730         }
7731
7732         memset(&syn_filter, 0, sizeof(syn_filter));
7733
7734         if (!strcmp(res->ops, "add")) {
7735                 if (!strcmp(res->high, "high"))
7736                         syn_filter.hig_pri = 1;
7737                 else
7738                         syn_filter.hig_pri = 0;
7739
7740                 syn_filter.queue = res->queue_id;
7741                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7742                                                 RTE_ETH_FILTER_SYN,
7743                                                 RTE_ETH_FILTER_ADD,
7744                                                 &syn_filter);
7745         } else
7746                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7747                                                 RTE_ETH_FILTER_SYN,
7748                                                 RTE_ETH_FILTER_DELETE,
7749                                                 &syn_filter);
7750
7751         if (ret < 0)
7752                 printf("syn filter programming error: (%s)\n",
7753                                 strerror(-ret));
7754 }
7755
7756 cmdline_parse_token_string_t cmd_syn_filter_filter =
7757         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7758         filter, "syn_filter");
7759 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7760         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7761         port_id, UINT8);
7762 cmdline_parse_token_string_t cmd_syn_filter_ops =
7763         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7764         ops, "add#del");
7765 cmdline_parse_token_string_t cmd_syn_filter_priority =
7766         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7767                                 priority, "priority");
7768 cmdline_parse_token_string_t cmd_syn_filter_high =
7769         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7770                                 high, "high#low");
7771 cmdline_parse_token_string_t cmd_syn_filter_queue =
7772         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7773                                 queue, "queue");
7774 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7775         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7776                                 queue_id, UINT16);
7777
7778 cmdline_parse_inst_t cmd_syn_filter = {
7779         .f = cmd_syn_filter_parsed,
7780         .data = NULL,
7781         .help_str = "syn_filter <port_id> add|del priority high|low queue "
7782                 "<queue_id>: Add/Delete syn filter",
7783         .tokens = {
7784                 (void *)&cmd_syn_filter_filter,
7785                 (void *)&cmd_syn_filter_port_id,
7786                 (void *)&cmd_syn_filter_ops,
7787                 (void *)&cmd_syn_filter_priority,
7788                 (void *)&cmd_syn_filter_high,
7789                 (void *)&cmd_syn_filter_queue,
7790                 (void *)&cmd_syn_filter_queue_id,
7791                 NULL,
7792         },
7793 };
7794
7795 /* *** ADD/REMOVE A 2tuple FILTER *** */
7796 struct cmd_2tuple_filter_result {
7797         cmdline_fixed_string_t filter;
7798         uint8_t  port_id;
7799         cmdline_fixed_string_t ops;
7800         cmdline_fixed_string_t dst_port;
7801         uint16_t dst_port_value;
7802         cmdline_fixed_string_t protocol;
7803         uint8_t protocol_value;
7804         cmdline_fixed_string_t mask;
7805         uint8_t  mask_value;
7806         cmdline_fixed_string_t tcp_flags;
7807         uint8_t tcp_flags_value;
7808         cmdline_fixed_string_t priority;
7809         uint8_t  priority_value;
7810         cmdline_fixed_string_t queue;
7811         uint16_t  queue_id;
7812 };
7813
7814 static void
7815 cmd_2tuple_filter_parsed(void *parsed_result,
7816                         __attribute__((unused)) struct cmdline *cl,
7817                         __attribute__((unused)) void *data)
7818 {
7819         struct rte_eth_ntuple_filter filter;
7820         struct cmd_2tuple_filter_result *res = parsed_result;
7821         int ret = 0;
7822
7823         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7824         if (ret < 0) {
7825                 printf("ntuple filter is not supported on port %u.\n",
7826                         res->port_id);
7827                 return;
7828         }
7829
7830         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7831
7832         filter.flags = RTE_2TUPLE_FLAGS;
7833         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7834         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7835         filter.proto = res->protocol_value;
7836         filter.priority = res->priority_value;
7837         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7838                 printf("nonzero tcp_flags is only meaningful"
7839                         " when protocol is TCP.\n");
7840                 return;
7841         }
7842         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7843                 printf("invalid TCP flags.\n");
7844                 return;
7845         }
7846
7847         if (res->tcp_flags_value != 0) {
7848                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7849                 filter.tcp_flags = res->tcp_flags_value;
7850         }
7851
7852         /* need convert to big endian. */
7853         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7854         filter.queue = res->queue_id;
7855
7856         if (!strcmp(res->ops, "add"))
7857                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7858                                 RTE_ETH_FILTER_NTUPLE,
7859                                 RTE_ETH_FILTER_ADD,
7860                                 &filter);
7861         else
7862                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7863                                 RTE_ETH_FILTER_NTUPLE,
7864                                 RTE_ETH_FILTER_DELETE,
7865                                 &filter);
7866         if (ret < 0)
7867                 printf("2tuple filter programming error: (%s)\n",
7868                         strerror(-ret));
7869
7870 }
7871
7872 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7873         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7874                                  filter, "2tuple_filter");
7875 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7876         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7877                                 port_id, UINT8);
7878 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7879         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7880                                  ops, "add#del");
7881 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7882         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7883                                 dst_port, "dst_port");
7884 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7885         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7886                                 dst_port_value, UINT16);
7887 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7888         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7889                                 protocol, "protocol");
7890 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7891         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7892                                 protocol_value, UINT8);
7893 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7894         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7895                                 mask, "mask");
7896 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7897         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7898                                 mask_value, INT8);
7899 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7900         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7901                                 tcp_flags, "tcp_flags");
7902 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7903         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7904                                 tcp_flags_value, UINT8);
7905 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7906         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7907                                 priority, "priority");
7908 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7909         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7910                                 priority_value, UINT8);
7911 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7912         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7913                                 queue, "queue");
7914 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7915         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7916                                 queue_id, UINT16);
7917
7918 cmdline_parse_inst_t cmd_2tuple_filter = {
7919         .f = cmd_2tuple_filter_parsed,
7920         .data = NULL,
7921         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
7922                 "<value> mask <value> tcp_flags <value> priority <value> queue "
7923                 "<queue_id>: Add a 2tuple filter",
7924         .tokens = {
7925                 (void *)&cmd_2tuple_filter_filter,
7926                 (void *)&cmd_2tuple_filter_port_id,
7927                 (void *)&cmd_2tuple_filter_ops,
7928                 (void *)&cmd_2tuple_filter_dst_port,
7929                 (void *)&cmd_2tuple_filter_dst_port_value,
7930                 (void *)&cmd_2tuple_filter_protocol,
7931                 (void *)&cmd_2tuple_filter_protocol_value,
7932                 (void *)&cmd_2tuple_filter_mask,
7933                 (void *)&cmd_2tuple_filter_mask_value,
7934                 (void *)&cmd_2tuple_filter_tcp_flags,
7935                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7936                 (void *)&cmd_2tuple_filter_priority,
7937                 (void *)&cmd_2tuple_filter_priority_value,
7938                 (void *)&cmd_2tuple_filter_queue,
7939                 (void *)&cmd_2tuple_filter_queue_id,
7940                 NULL,
7941         },
7942 };
7943
7944 /* *** ADD/REMOVE A 5tuple FILTER *** */
7945 struct cmd_5tuple_filter_result {
7946         cmdline_fixed_string_t filter;
7947         uint8_t  port_id;
7948         cmdline_fixed_string_t ops;
7949         cmdline_fixed_string_t dst_ip;
7950         cmdline_ipaddr_t dst_ip_value;
7951         cmdline_fixed_string_t src_ip;
7952         cmdline_ipaddr_t src_ip_value;
7953         cmdline_fixed_string_t dst_port;
7954         uint16_t dst_port_value;
7955         cmdline_fixed_string_t src_port;
7956         uint16_t src_port_value;
7957         cmdline_fixed_string_t protocol;
7958         uint8_t protocol_value;
7959         cmdline_fixed_string_t mask;
7960         uint8_t  mask_value;
7961         cmdline_fixed_string_t tcp_flags;
7962         uint8_t tcp_flags_value;
7963         cmdline_fixed_string_t priority;
7964         uint8_t  priority_value;
7965         cmdline_fixed_string_t queue;
7966         uint16_t  queue_id;
7967 };
7968
7969 static void
7970 cmd_5tuple_filter_parsed(void *parsed_result,
7971                         __attribute__((unused)) struct cmdline *cl,
7972                         __attribute__((unused)) void *data)
7973 {
7974         struct rte_eth_ntuple_filter filter;
7975         struct cmd_5tuple_filter_result *res = parsed_result;
7976         int ret = 0;
7977
7978         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7979         if (ret < 0) {
7980                 printf("ntuple filter is not supported on port %u.\n",
7981                         res->port_id);
7982                 return;
7983         }
7984
7985         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7986
7987         filter.flags = RTE_5TUPLE_FLAGS;
7988         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7989         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7990         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7991         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7992         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7993         filter.proto = res->protocol_value;
7994         filter.priority = res->priority_value;
7995         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7996                 printf("nonzero tcp_flags is only meaningful"
7997                         " when protocol is TCP.\n");
7998                 return;
7999         }
8000         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8001                 printf("invalid TCP flags.\n");
8002                 return;
8003         }
8004
8005         if (res->tcp_flags_value != 0) {
8006                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8007                 filter.tcp_flags = res->tcp_flags_value;
8008         }
8009
8010         if (res->dst_ip_value.family == AF_INET)
8011                 /* no need to convert, already big endian. */
8012                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8013         else {
8014                 if (filter.dst_ip_mask == 0) {
8015                         printf("can not support ipv6 involved compare.\n");
8016                         return;
8017                 }
8018                 filter.dst_ip = 0;
8019         }
8020
8021         if (res->src_ip_value.family == AF_INET)
8022                 /* no need to convert, already big endian. */
8023                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8024         else {
8025                 if (filter.src_ip_mask == 0) {
8026                         printf("can not support ipv6 involved compare.\n");
8027                         return;
8028                 }
8029                 filter.src_ip = 0;
8030         }
8031         /* need convert to big endian. */
8032         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8033         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8034         filter.queue = res->queue_id;
8035
8036         if (!strcmp(res->ops, "add"))
8037                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8038                                 RTE_ETH_FILTER_NTUPLE,
8039                                 RTE_ETH_FILTER_ADD,
8040                                 &filter);
8041         else
8042                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8043                                 RTE_ETH_FILTER_NTUPLE,
8044                                 RTE_ETH_FILTER_DELETE,
8045                                 &filter);
8046         if (ret < 0)
8047                 printf("5tuple filter programming error: (%s)\n",
8048                         strerror(-ret));
8049 }
8050
8051 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8052         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8053                                  filter, "5tuple_filter");
8054 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8055         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8056                                 port_id, UINT8);
8057 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8058         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8059                                  ops, "add#del");
8060 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8061         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8062                                 dst_ip, "dst_ip");
8063 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8064         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8065                                 dst_ip_value);
8066 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8067         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8068                                 src_ip, "src_ip");
8069 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8070         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8071                                 src_ip_value);
8072 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8073         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8074                                 dst_port, "dst_port");
8075 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8076         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8077                                 dst_port_value, UINT16);
8078 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8079         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8080                                 src_port, "src_port");
8081 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8082         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8083                                 src_port_value, UINT16);
8084 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8085         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8086                                 protocol, "protocol");
8087 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8088         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8089                                 protocol_value, UINT8);
8090 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8091         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8092                                 mask, "mask");
8093 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8094         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8095                                 mask_value, INT8);
8096 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8097         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8098                                 tcp_flags, "tcp_flags");
8099 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8100         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8101                                 tcp_flags_value, UINT8);
8102 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8103         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8104                                 priority, "priority");
8105 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8106         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8107                                 priority_value, UINT8);
8108 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8109         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8110                                 queue, "queue");
8111 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8112         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8113                                 queue_id, UINT16);
8114
8115 cmdline_parse_inst_t cmd_5tuple_filter = {
8116         .f = cmd_5tuple_filter_parsed,
8117         .data = NULL,
8118         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8119                 "src_ip <value> dst_port <value> src_port <value> "
8120                 "protocol <value>  mask <value> tcp_flags <value> "
8121                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8122         .tokens = {
8123                 (void *)&cmd_5tuple_filter_filter,
8124                 (void *)&cmd_5tuple_filter_port_id,
8125                 (void *)&cmd_5tuple_filter_ops,
8126                 (void *)&cmd_5tuple_filter_dst_ip,
8127                 (void *)&cmd_5tuple_filter_dst_ip_value,
8128                 (void *)&cmd_5tuple_filter_src_ip,
8129                 (void *)&cmd_5tuple_filter_src_ip_value,
8130                 (void *)&cmd_5tuple_filter_dst_port,
8131                 (void *)&cmd_5tuple_filter_dst_port_value,
8132                 (void *)&cmd_5tuple_filter_src_port,
8133                 (void *)&cmd_5tuple_filter_src_port_value,
8134                 (void *)&cmd_5tuple_filter_protocol,
8135                 (void *)&cmd_5tuple_filter_protocol_value,
8136                 (void *)&cmd_5tuple_filter_mask,
8137                 (void *)&cmd_5tuple_filter_mask_value,
8138                 (void *)&cmd_5tuple_filter_tcp_flags,
8139                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8140                 (void *)&cmd_5tuple_filter_priority,
8141                 (void *)&cmd_5tuple_filter_priority_value,
8142                 (void *)&cmd_5tuple_filter_queue,
8143                 (void *)&cmd_5tuple_filter_queue_id,
8144                 NULL,
8145         },
8146 };
8147
8148 /* *** ADD/REMOVE A flex FILTER *** */
8149 struct cmd_flex_filter_result {
8150         cmdline_fixed_string_t filter;
8151         cmdline_fixed_string_t ops;
8152         uint8_t port_id;
8153         cmdline_fixed_string_t len;
8154         uint8_t len_value;
8155         cmdline_fixed_string_t bytes;
8156         cmdline_fixed_string_t bytes_value;
8157         cmdline_fixed_string_t mask;
8158         cmdline_fixed_string_t mask_value;
8159         cmdline_fixed_string_t priority;
8160         uint8_t priority_value;
8161         cmdline_fixed_string_t queue;
8162         uint16_t queue_id;
8163 };
8164
8165 static int xdigit2val(unsigned char c)
8166 {
8167         int val;
8168         if (isdigit(c))
8169                 val = c - '0';
8170         else if (isupper(c))
8171                 val = c - 'A' + 10;
8172         else
8173                 val = c - 'a' + 10;
8174         return val;
8175 }
8176
8177 static void
8178 cmd_flex_filter_parsed(void *parsed_result,
8179                           __attribute__((unused)) struct cmdline *cl,
8180                           __attribute__((unused)) void *data)
8181 {
8182         int ret = 0;
8183         struct rte_eth_flex_filter filter;
8184         struct cmd_flex_filter_result *res = parsed_result;
8185         char *bytes_ptr, *mask_ptr;
8186         uint16_t len, i, j = 0;
8187         char c;
8188         int val;
8189         uint8_t byte = 0;
8190
8191         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8192                 printf("the len exceed the max length 128\n");
8193                 return;
8194         }
8195         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8196         filter.len = res->len_value;
8197         filter.priority = res->priority_value;
8198         filter.queue = res->queue_id;
8199         bytes_ptr = res->bytes_value;
8200         mask_ptr = res->mask_value;
8201
8202          /* translate bytes string to array. */
8203         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8204                 (bytes_ptr[1] == 'X')))
8205                 bytes_ptr += 2;
8206         len = strnlen(bytes_ptr, res->len_value * 2);
8207         if (len == 0 || (len % 8 != 0)) {
8208                 printf("please check len and bytes input\n");
8209                 return;
8210         }
8211         for (i = 0; i < len; i++) {
8212                 c = bytes_ptr[i];
8213                 if (isxdigit(c) == 0) {
8214                         /* invalid characters. */
8215                         printf("invalid input\n");
8216                         return;
8217                 }
8218                 val = xdigit2val(c);
8219                 if (i % 2) {
8220                         byte |= val;
8221                         filter.bytes[j] = byte;
8222                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8223                         j++;
8224                         byte = 0;
8225                 } else
8226                         byte |= val << 4;
8227         }
8228         printf("\n");
8229          /* translate mask string to uint8_t array. */
8230         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8231                 (mask_ptr[1] == 'X')))
8232                 mask_ptr += 2;
8233         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8234         if (len == 0) {
8235                 printf("invalid input\n");
8236                 return;
8237         }
8238         j = 0;
8239         byte = 0;
8240         for (i = 0; i < len; i++) {
8241                 c = mask_ptr[i];
8242                 if (isxdigit(c) == 0) {
8243                         /* invalid characters. */
8244                         printf("invalid input\n");
8245                         return;
8246                 }
8247                 val = xdigit2val(c);
8248                 if (i % 2) {
8249                         byte |= val;
8250                         filter.mask[j] = byte;
8251                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8252                         j++;
8253                         byte = 0;
8254                 } else
8255                         byte |= val << 4;
8256         }
8257         printf("\n");
8258
8259         if (!strcmp(res->ops, "add"))
8260                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8261                                 RTE_ETH_FILTER_FLEXIBLE,
8262                                 RTE_ETH_FILTER_ADD,
8263                                 &filter);
8264         else
8265                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8266                                 RTE_ETH_FILTER_FLEXIBLE,
8267                                 RTE_ETH_FILTER_DELETE,
8268                                 &filter);
8269
8270         if (ret < 0)
8271                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8272 }
8273
8274 cmdline_parse_token_string_t cmd_flex_filter_filter =
8275         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8276                                 filter, "flex_filter");
8277 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8278         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8279                                 port_id, UINT8);
8280 cmdline_parse_token_string_t cmd_flex_filter_ops =
8281         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8282                                 ops, "add#del");
8283 cmdline_parse_token_string_t cmd_flex_filter_len =
8284         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8285                                 len, "len");
8286 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8287         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8288                                 len_value, UINT8);
8289 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8290         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8291                                 bytes, "bytes");
8292 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8293         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8294                                 bytes_value, NULL);
8295 cmdline_parse_token_string_t cmd_flex_filter_mask =
8296         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8297                                 mask, "mask");
8298 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8299         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8300                                 mask_value, NULL);
8301 cmdline_parse_token_string_t cmd_flex_filter_priority =
8302         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8303                                 priority, "priority");
8304 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8305         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8306                                 priority_value, UINT8);
8307 cmdline_parse_token_string_t cmd_flex_filter_queue =
8308         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8309                                 queue, "queue");
8310 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8311         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8312                                 queue_id, UINT16);
8313 cmdline_parse_inst_t cmd_flex_filter = {
8314         .f = cmd_flex_filter_parsed,
8315         .data = NULL,
8316         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8317                 "<value> mask <value> priority <value> queue <queue_id>: "
8318                 "Add/Del a flex filter",
8319         .tokens = {
8320                 (void *)&cmd_flex_filter_filter,
8321                 (void *)&cmd_flex_filter_port_id,
8322                 (void *)&cmd_flex_filter_ops,
8323                 (void *)&cmd_flex_filter_len,
8324                 (void *)&cmd_flex_filter_len_value,
8325                 (void *)&cmd_flex_filter_bytes,
8326                 (void *)&cmd_flex_filter_bytes_value,
8327                 (void *)&cmd_flex_filter_mask,
8328                 (void *)&cmd_flex_filter_mask_value,
8329                 (void *)&cmd_flex_filter_priority,
8330                 (void *)&cmd_flex_filter_priority_value,
8331                 (void *)&cmd_flex_filter_queue,
8332                 (void *)&cmd_flex_filter_queue_id,
8333                 NULL,
8334         },
8335 };
8336
8337 /* *** Filters Control *** */
8338
8339 /* *** deal with ethertype filter *** */
8340 struct cmd_ethertype_filter_result {
8341         cmdline_fixed_string_t filter;
8342         uint8_t port_id;
8343         cmdline_fixed_string_t ops;
8344         cmdline_fixed_string_t mac;
8345         struct ether_addr mac_addr;
8346         cmdline_fixed_string_t ethertype;
8347         uint16_t ethertype_value;
8348         cmdline_fixed_string_t drop;
8349         cmdline_fixed_string_t queue;
8350         uint16_t  queue_id;
8351 };
8352
8353 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8354         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8355                                  filter, "ethertype_filter");
8356 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8357         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8358                               port_id, UINT8);
8359 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8360         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8361                                  ops, "add#del");
8362 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8363         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8364                                  mac, "mac_addr#mac_ignr");
8365 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8366         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8367                                      mac_addr);
8368 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8369         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8370                                  ethertype, "ethertype");
8371 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8372         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8373                               ethertype_value, UINT16);
8374 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8375         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8376                                  drop, "drop#fwd");
8377 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8378         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8379                                  queue, "queue");
8380 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8381         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8382                               queue_id, UINT16);
8383
8384 static void
8385 cmd_ethertype_filter_parsed(void *parsed_result,
8386                           __attribute__((unused)) struct cmdline *cl,
8387                           __attribute__((unused)) void *data)
8388 {
8389         struct cmd_ethertype_filter_result *res = parsed_result;
8390         struct rte_eth_ethertype_filter filter;
8391         int ret = 0;
8392
8393         ret = rte_eth_dev_filter_supported(res->port_id,
8394                         RTE_ETH_FILTER_ETHERTYPE);
8395         if (ret < 0) {
8396                 printf("ethertype filter is not supported on port %u.\n",
8397                         res->port_id);
8398                 return;
8399         }
8400
8401         memset(&filter, 0, sizeof(filter));
8402         if (!strcmp(res->mac, "mac_addr")) {
8403                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8404                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8405                         sizeof(struct ether_addr));
8406         }
8407         if (!strcmp(res->drop, "drop"))
8408                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8409         filter.ether_type = res->ethertype_value;
8410         filter.queue = res->queue_id;
8411
8412         if (!strcmp(res->ops, "add"))
8413                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8414                                 RTE_ETH_FILTER_ETHERTYPE,
8415                                 RTE_ETH_FILTER_ADD,
8416                                 &filter);
8417         else
8418                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8419                                 RTE_ETH_FILTER_ETHERTYPE,
8420                                 RTE_ETH_FILTER_DELETE,
8421                                 &filter);
8422         if (ret < 0)
8423                 printf("ethertype filter programming error: (%s)\n",
8424                         strerror(-ret));
8425 }
8426
8427 cmdline_parse_inst_t cmd_ethertype_filter = {
8428         .f = cmd_ethertype_filter_parsed,
8429         .data = NULL,
8430         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8431                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8432                 "Add or delete an ethertype filter entry",
8433         .tokens = {
8434                 (void *)&cmd_ethertype_filter_filter,
8435                 (void *)&cmd_ethertype_filter_port_id,
8436                 (void *)&cmd_ethertype_filter_ops,
8437                 (void *)&cmd_ethertype_filter_mac,
8438                 (void *)&cmd_ethertype_filter_mac_addr,
8439                 (void *)&cmd_ethertype_filter_ethertype,
8440                 (void *)&cmd_ethertype_filter_ethertype_value,
8441                 (void *)&cmd_ethertype_filter_drop,
8442                 (void *)&cmd_ethertype_filter_queue,
8443                 (void *)&cmd_ethertype_filter_queue_id,
8444                 NULL,
8445         },
8446 };
8447
8448 /* *** deal with flow director filter *** */
8449 struct cmd_flow_director_result {
8450         cmdline_fixed_string_t flow_director_filter;
8451         uint8_t port_id;
8452         cmdline_fixed_string_t mode;
8453         cmdline_fixed_string_t mode_value;
8454         cmdline_fixed_string_t ops;
8455         cmdline_fixed_string_t flow;
8456         cmdline_fixed_string_t flow_type;
8457         cmdline_fixed_string_t ether;
8458         uint16_t ether_type;
8459         cmdline_fixed_string_t src;
8460         cmdline_ipaddr_t ip_src;
8461         uint16_t port_src;
8462         cmdline_fixed_string_t dst;
8463         cmdline_ipaddr_t ip_dst;
8464         uint16_t port_dst;
8465         cmdline_fixed_string_t verify_tag;
8466         uint32_t verify_tag_value;
8467         cmdline_ipaddr_t tos;
8468         uint8_t tos_value;
8469         cmdline_ipaddr_t proto;
8470         uint8_t proto_value;
8471         cmdline_ipaddr_t ttl;
8472         uint8_t ttl_value;
8473         cmdline_fixed_string_t vlan;
8474         uint16_t vlan_value;
8475         cmdline_fixed_string_t flexbytes;
8476         cmdline_fixed_string_t flexbytes_value;
8477         cmdline_fixed_string_t pf_vf;
8478         cmdline_fixed_string_t drop;
8479         cmdline_fixed_string_t queue;
8480         uint16_t  queue_id;
8481         cmdline_fixed_string_t fd_id;
8482         uint32_t  fd_id_value;
8483         cmdline_fixed_string_t mac;
8484         struct ether_addr mac_addr;
8485         cmdline_fixed_string_t tunnel;
8486         cmdline_fixed_string_t tunnel_type;
8487         cmdline_fixed_string_t tunnel_id;
8488         uint32_t tunnel_id_value;
8489 };
8490
8491 static inline int
8492 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8493 {
8494         char s[256];
8495         const char *p, *p0 = q_arg;
8496         char *end;
8497         unsigned long int_fld;
8498         char *str_fld[max_num];
8499         int i;
8500         unsigned size;
8501         int ret = -1;
8502
8503         p = strchr(p0, '(');
8504         if (p == NULL)
8505                 return -1;
8506         ++p;
8507         p0 = strchr(p, ')');
8508         if (p0 == NULL)
8509                 return -1;
8510
8511         size = p0 - p;
8512         if (size >= sizeof(s))
8513                 return -1;
8514
8515         snprintf(s, sizeof(s), "%.*s", size, p);
8516         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8517         if (ret < 0 || ret > max_num)
8518                 return -1;
8519         for (i = 0; i < ret; i++) {
8520                 errno = 0;
8521                 int_fld = strtoul(str_fld[i], &end, 0);
8522                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8523                         return -1;
8524                 flexbytes[i] = (uint8_t)int_fld;
8525         }
8526         return ret;
8527 }
8528
8529 static uint16_t
8530 str2flowtype(char *string)
8531 {
8532         uint8_t i = 0;
8533         static const struct {
8534                 char str[32];
8535                 uint16_t type;
8536         } flowtype_str[] = {
8537                 {"raw", RTE_ETH_FLOW_RAW},
8538                 {"ipv4", RTE_ETH_FLOW_IPV4},
8539                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8540                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8541                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8542                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8543                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8544                 {"ipv6", RTE_ETH_FLOW_IPV6},
8545                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8546                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8547                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8548                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8549                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8550                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8551         };
8552
8553         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8554                 if (!strcmp(flowtype_str[i].str, string))
8555                         return flowtype_str[i].type;
8556         }
8557         return RTE_ETH_FLOW_UNKNOWN;
8558 }
8559
8560 static enum rte_eth_fdir_tunnel_type
8561 str2fdir_tunneltype(char *string)
8562 {
8563         uint8_t i = 0;
8564
8565         static const struct {
8566                 char str[32];
8567                 enum rte_eth_fdir_tunnel_type type;
8568         } tunneltype_str[] = {
8569                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8570                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8571         };
8572
8573         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8574                 if (!strcmp(tunneltype_str[i].str, string))
8575                         return tunneltype_str[i].type;
8576         }
8577         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8578 }
8579
8580 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8581 do { \
8582         if ((ip_addr).family == AF_INET) \
8583                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8584         else { \
8585                 printf("invalid parameter.\n"); \
8586                 return; \
8587         } \
8588 } while (0)
8589
8590 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8591 do { \
8592         if ((ip_addr).family == AF_INET6) \
8593                 (void)rte_memcpy(&(ip), \
8594                                  &((ip_addr).addr.ipv6), \
8595                                  sizeof(struct in6_addr)); \
8596         else { \
8597                 printf("invalid parameter.\n"); \
8598                 return; \
8599         } \
8600 } while (0)
8601
8602 static void
8603 cmd_flow_director_filter_parsed(void *parsed_result,
8604                           __attribute__((unused)) struct cmdline *cl,
8605                           __attribute__((unused)) void *data)
8606 {
8607         struct cmd_flow_director_result *res = parsed_result;
8608         struct rte_eth_fdir_filter entry;
8609         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8610         char *end;
8611         unsigned long vf_id;
8612         int ret = 0;
8613
8614         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8615         if (ret < 0) {
8616                 printf("flow director is not supported on port %u.\n",
8617                         res->port_id);
8618                 return;
8619         }
8620         memset(flexbytes, 0, sizeof(flexbytes));
8621         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8622
8623         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8624                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8625                         printf("Please set mode to MAC-VLAN.\n");
8626                         return;
8627                 }
8628         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8629                 if (strcmp(res->mode_value, "Tunnel")) {
8630                         printf("Please set mode to Tunnel.\n");
8631                         return;
8632                 }
8633         } else {
8634                 if (strcmp(res->mode_value, "IP")) {
8635                         printf("Please set mode to IP.\n");
8636                         return;
8637                 }
8638                 entry.input.flow_type = str2flowtype(res->flow_type);
8639         }
8640
8641         ret = parse_flexbytes(res->flexbytes_value,
8642                                         flexbytes,
8643                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8644         if (ret < 0) {
8645                 printf("error: Cannot parse flexbytes input.\n");
8646                 return;
8647         }
8648
8649         switch (entry.input.flow_type) {
8650         case RTE_ETH_FLOW_FRAG_IPV4:
8651         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8652                 entry.input.flow.ip4_flow.proto = res->proto_value;
8653         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8654         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8655                 IPV4_ADDR_TO_UINT(res->ip_dst,
8656                         entry.input.flow.ip4_flow.dst_ip);
8657                 IPV4_ADDR_TO_UINT(res->ip_src,
8658                         entry.input.flow.ip4_flow.src_ip);
8659                 entry.input.flow.ip4_flow.tos = res->tos_value;
8660                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8661                 /* need convert to big endian. */
8662                 entry.input.flow.udp4_flow.dst_port =
8663                                 rte_cpu_to_be_16(res->port_dst);
8664                 entry.input.flow.udp4_flow.src_port =
8665                                 rte_cpu_to_be_16(res->port_src);
8666                 break;
8667         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8668                 IPV4_ADDR_TO_UINT(res->ip_dst,
8669                         entry.input.flow.sctp4_flow.ip.dst_ip);
8670                 IPV4_ADDR_TO_UINT(res->ip_src,
8671                         entry.input.flow.sctp4_flow.ip.src_ip);
8672                 entry.input.flow.ip4_flow.tos = res->tos_value;
8673                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8674                 /* need convert to big endian. */
8675                 entry.input.flow.sctp4_flow.dst_port =
8676                                 rte_cpu_to_be_16(res->port_dst);
8677                 entry.input.flow.sctp4_flow.src_port =
8678                                 rte_cpu_to_be_16(res->port_src);
8679                 entry.input.flow.sctp4_flow.verify_tag =
8680                                 rte_cpu_to_be_32(res->verify_tag_value);
8681                 break;
8682         case RTE_ETH_FLOW_FRAG_IPV6:
8683         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8684                 entry.input.flow.ipv6_flow.proto = res->proto_value;
8685         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8686         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8687                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8688                         entry.input.flow.ipv6_flow.dst_ip);
8689                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8690                         entry.input.flow.ipv6_flow.src_ip);
8691                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8692                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8693                 /* need convert to big endian. */
8694                 entry.input.flow.udp6_flow.dst_port =
8695                                 rte_cpu_to_be_16(res->port_dst);
8696                 entry.input.flow.udp6_flow.src_port =
8697                                 rte_cpu_to_be_16(res->port_src);
8698                 break;
8699         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8700                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8701                         entry.input.flow.sctp6_flow.ip.dst_ip);
8702                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8703                         entry.input.flow.sctp6_flow.ip.src_ip);
8704                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8705                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8706                 /* need convert to big endian. */
8707                 entry.input.flow.sctp6_flow.dst_port =
8708                                 rte_cpu_to_be_16(res->port_dst);
8709                 entry.input.flow.sctp6_flow.src_port =
8710                                 rte_cpu_to_be_16(res->port_src);
8711                 entry.input.flow.sctp6_flow.verify_tag =
8712                                 rte_cpu_to_be_32(res->verify_tag_value);
8713                 break;
8714         case RTE_ETH_FLOW_L2_PAYLOAD:
8715                 entry.input.flow.l2_flow.ether_type =
8716                         rte_cpu_to_be_16(res->ether_type);
8717                 break;
8718         default:
8719                 break;
8720         }
8721
8722         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8723                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8724                                  &res->mac_addr,
8725                                  sizeof(struct ether_addr));
8726
8727         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8728                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8729                                  &res->mac_addr,
8730                                  sizeof(struct ether_addr));
8731                 entry.input.flow.tunnel_flow.tunnel_type =
8732                         str2fdir_tunneltype(res->tunnel_type);
8733                 entry.input.flow.tunnel_flow.tunnel_id =
8734                         rte_cpu_to_be_32(res->tunnel_id_value);
8735         }
8736
8737         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8738                    flexbytes,
8739                    RTE_ETH_FDIR_MAX_FLEXLEN);
8740
8741         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8742
8743         entry.action.flex_off = 0;  /*use 0 by default */
8744         if (!strcmp(res->drop, "drop"))
8745                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8746         else
8747                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8748
8749         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
8750             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8751                 if (!strcmp(res->pf_vf, "pf"))
8752                         entry.input.flow_ext.is_vf = 0;
8753                 else if (!strncmp(res->pf_vf, "vf", 2)) {
8754                         struct rte_eth_dev_info dev_info;
8755
8756                         memset(&dev_info, 0, sizeof(dev_info));
8757                         rte_eth_dev_info_get(res->port_id, &dev_info);
8758                         errno = 0;
8759                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
8760                         if (errno != 0 || *end != '\0' ||
8761                             vf_id >= dev_info.max_vfs) {
8762                                 printf("invalid parameter %s.\n", res->pf_vf);
8763                                 return;
8764                         }
8765                         entry.input.flow_ext.is_vf = 1;
8766                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8767                 } else {
8768                         printf("invalid parameter %s.\n", res->pf_vf);
8769                         return;
8770                 }
8771         }
8772
8773         /* set to report FD ID by default */
8774         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8775         entry.action.rx_queue = res->queue_id;
8776         entry.soft_id = res->fd_id_value;
8777         if (!strcmp(res->ops, "add"))
8778                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8779                                              RTE_ETH_FILTER_ADD, &entry);
8780         else if (!strcmp(res->ops, "del"))
8781                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8782                                              RTE_ETH_FILTER_DELETE, &entry);
8783         else
8784                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8785                                              RTE_ETH_FILTER_UPDATE, &entry);
8786         if (ret < 0)
8787                 printf("flow director programming error: (%s)\n",
8788                         strerror(-ret));
8789 }
8790
8791 cmdline_parse_token_string_t cmd_flow_director_filter =
8792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8793                                  flow_director_filter, "flow_director_filter");
8794 cmdline_parse_token_num_t cmd_flow_director_port_id =
8795         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8796                               port_id, UINT8);
8797 cmdline_parse_token_string_t cmd_flow_director_ops =
8798         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8799                                  ops, "add#del#update");
8800 cmdline_parse_token_string_t cmd_flow_director_flow =
8801         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8802                                  flow, "flow");
8803 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8804         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8805                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8806                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8807 cmdline_parse_token_string_t cmd_flow_director_ether =
8808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8809                                  ether, "ether");
8810 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8811         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8812                               ether_type, UINT16);
8813 cmdline_parse_token_string_t cmd_flow_director_src =
8814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8815                                  src, "src");
8816 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8817         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8818                                  ip_src);
8819 cmdline_parse_token_num_t cmd_flow_director_port_src =
8820         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8821                               port_src, UINT16);
8822 cmdline_parse_token_string_t cmd_flow_director_dst =
8823         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8824                                  dst, "dst");
8825 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8826         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8827                                  ip_dst);
8828 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8829         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8830                               port_dst, UINT16);
8831 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8832         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8833                                   verify_tag, "verify_tag");
8834 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8835         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8836                               verify_tag_value, UINT32);
8837 cmdline_parse_token_string_t cmd_flow_director_tos =
8838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8839                                  tos, "tos");
8840 cmdline_parse_token_num_t cmd_flow_director_tos_value =
8841         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8842                               tos_value, UINT8);
8843 cmdline_parse_token_string_t cmd_flow_director_proto =
8844         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8845                                  proto, "proto");
8846 cmdline_parse_token_num_t cmd_flow_director_proto_value =
8847         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8848                               proto_value, UINT8);
8849 cmdline_parse_token_string_t cmd_flow_director_ttl =
8850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8851                                  ttl, "ttl");
8852 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
8853         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8854                               ttl_value, UINT8);
8855 cmdline_parse_token_string_t cmd_flow_director_vlan =
8856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8857                                  vlan, "vlan");
8858 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8859         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8860                               vlan_value, UINT16);
8861 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8863                                  flexbytes, "flexbytes");
8864 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8866                               flexbytes_value, NULL);
8867 cmdline_parse_token_string_t cmd_flow_director_drop =
8868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8869                                  drop, "drop#fwd");
8870 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8872                               pf_vf, NULL);
8873 cmdline_parse_token_string_t cmd_flow_director_queue =
8874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8875                                  queue, "queue");
8876 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8877         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8878                               queue_id, UINT16);
8879 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8880         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8881                                  fd_id, "fd_id");
8882 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8883         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8884                               fd_id_value, UINT32);
8885
8886 cmdline_parse_token_string_t cmd_flow_director_mode =
8887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8888                                  mode, "mode");
8889 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8890         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8891                                  mode_value, "IP");
8892 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8893         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8894                                  mode_value, "MAC-VLAN");
8895 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8896         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8897                                  mode_value, "Tunnel");
8898 cmdline_parse_token_string_t cmd_flow_director_mac =
8899         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8900                                  mac, "mac");
8901 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8902         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8903                                     mac_addr);
8904 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8905         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8906                                  tunnel, "tunnel");
8907 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8909                                  tunnel_type, "NVGRE#VxLAN");
8910 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8911         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8912                                  tunnel_id, "tunnel-id");
8913 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8914         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8915                               tunnel_id_value, UINT32);
8916
8917 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8918         .f = cmd_flow_director_filter_parsed,
8919         .data = NULL,
8920         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
8921                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
8922                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
8923                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
8924                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
8925                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
8926                 "fd_id <fd_id_value>: "
8927                 "Add or delete an ip flow director entry on NIC",
8928         .tokens = {
8929                 (void *)&cmd_flow_director_filter,
8930                 (void *)&cmd_flow_director_port_id,
8931                 (void *)&cmd_flow_director_mode,
8932                 (void *)&cmd_flow_director_mode_ip,
8933                 (void *)&cmd_flow_director_ops,
8934                 (void *)&cmd_flow_director_flow,
8935                 (void *)&cmd_flow_director_flow_type,
8936                 (void *)&cmd_flow_director_src,
8937                 (void *)&cmd_flow_director_ip_src,
8938                 (void *)&cmd_flow_director_dst,
8939                 (void *)&cmd_flow_director_ip_dst,
8940                 (void *)&cmd_flow_director_tos,
8941                 (void *)&cmd_flow_director_tos_value,
8942                 (void *)&cmd_flow_director_proto,
8943                 (void *)&cmd_flow_director_proto_value,
8944                 (void *)&cmd_flow_director_ttl,
8945                 (void *)&cmd_flow_director_ttl_value,
8946                 (void *)&cmd_flow_director_vlan,
8947                 (void *)&cmd_flow_director_vlan_value,
8948                 (void *)&cmd_flow_director_flexbytes,
8949                 (void *)&cmd_flow_director_flexbytes_value,
8950                 (void *)&cmd_flow_director_drop,
8951                 (void *)&cmd_flow_director_pf_vf,
8952                 (void *)&cmd_flow_director_queue,
8953                 (void *)&cmd_flow_director_queue_id,
8954                 (void *)&cmd_flow_director_fd_id,
8955                 (void *)&cmd_flow_director_fd_id_value,
8956                 NULL,
8957         },
8958 };
8959
8960 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8961         .f = cmd_flow_director_filter_parsed,
8962         .data = NULL,
8963         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
8964                 "director entry on NIC",
8965         .tokens = {
8966                 (void *)&cmd_flow_director_filter,
8967                 (void *)&cmd_flow_director_port_id,
8968                 (void *)&cmd_flow_director_mode,
8969                 (void *)&cmd_flow_director_mode_ip,
8970                 (void *)&cmd_flow_director_ops,
8971                 (void *)&cmd_flow_director_flow,
8972                 (void *)&cmd_flow_director_flow_type,
8973                 (void *)&cmd_flow_director_src,
8974                 (void *)&cmd_flow_director_ip_src,
8975                 (void *)&cmd_flow_director_port_src,
8976                 (void *)&cmd_flow_director_dst,
8977                 (void *)&cmd_flow_director_ip_dst,
8978                 (void *)&cmd_flow_director_port_dst,
8979                 (void *)&cmd_flow_director_tos,
8980                 (void *)&cmd_flow_director_tos_value,
8981                 (void *)&cmd_flow_director_ttl,
8982                 (void *)&cmd_flow_director_ttl_value,
8983                 (void *)&cmd_flow_director_vlan,
8984                 (void *)&cmd_flow_director_vlan_value,
8985                 (void *)&cmd_flow_director_flexbytes,
8986                 (void *)&cmd_flow_director_flexbytes_value,
8987                 (void *)&cmd_flow_director_drop,
8988                 (void *)&cmd_flow_director_pf_vf,
8989                 (void *)&cmd_flow_director_queue,
8990                 (void *)&cmd_flow_director_queue_id,
8991                 (void *)&cmd_flow_director_fd_id,
8992                 (void *)&cmd_flow_director_fd_id_value,
8993                 NULL,
8994         },
8995 };
8996
8997 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8998         .f = cmd_flow_director_filter_parsed,
8999         .data = NULL,
9000         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9001                 "director entry on NIC",
9002         .tokens = {
9003                 (void *)&cmd_flow_director_filter,
9004                 (void *)&cmd_flow_director_port_id,
9005                 (void *)&cmd_flow_director_mode,
9006                 (void *)&cmd_flow_director_mode_ip,
9007                 (void *)&cmd_flow_director_ops,
9008                 (void *)&cmd_flow_director_flow,
9009                 (void *)&cmd_flow_director_flow_type,
9010                 (void *)&cmd_flow_director_src,
9011                 (void *)&cmd_flow_director_ip_src,
9012                 (void *)&cmd_flow_director_port_dst,
9013                 (void *)&cmd_flow_director_dst,
9014                 (void *)&cmd_flow_director_ip_dst,
9015                 (void *)&cmd_flow_director_port_dst,
9016                 (void *)&cmd_flow_director_verify_tag,
9017                 (void *)&cmd_flow_director_verify_tag_value,
9018                 (void *)&cmd_flow_director_tos,
9019                 (void *)&cmd_flow_director_tos_value,
9020                 (void *)&cmd_flow_director_ttl,
9021                 (void *)&cmd_flow_director_ttl_value,
9022                 (void *)&cmd_flow_director_vlan,
9023                 (void *)&cmd_flow_director_vlan_value,
9024                 (void *)&cmd_flow_director_flexbytes,
9025                 (void *)&cmd_flow_director_flexbytes_value,
9026                 (void *)&cmd_flow_director_drop,
9027                 (void *)&cmd_flow_director_pf_vf,
9028                 (void *)&cmd_flow_director_queue,
9029                 (void *)&cmd_flow_director_queue_id,
9030                 (void *)&cmd_flow_director_fd_id,
9031                 (void *)&cmd_flow_director_fd_id_value,
9032                 NULL,
9033         },
9034 };
9035
9036 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9037         .f = cmd_flow_director_filter_parsed,
9038         .data = NULL,
9039         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9040                 "director entry on NIC",
9041         .tokens = {
9042                 (void *)&cmd_flow_director_filter,
9043                 (void *)&cmd_flow_director_port_id,
9044                 (void *)&cmd_flow_director_mode,
9045                 (void *)&cmd_flow_director_mode_ip,
9046                 (void *)&cmd_flow_director_ops,
9047                 (void *)&cmd_flow_director_flow,
9048                 (void *)&cmd_flow_director_flow_type,
9049                 (void *)&cmd_flow_director_ether,
9050                 (void *)&cmd_flow_director_ether_type,
9051                 (void *)&cmd_flow_director_flexbytes,
9052                 (void *)&cmd_flow_director_flexbytes_value,
9053                 (void *)&cmd_flow_director_drop,
9054                 (void *)&cmd_flow_director_pf_vf,
9055                 (void *)&cmd_flow_director_queue,
9056                 (void *)&cmd_flow_director_queue_id,
9057                 (void *)&cmd_flow_director_fd_id,
9058                 (void *)&cmd_flow_director_fd_id_value,
9059                 NULL,
9060         },
9061 };
9062
9063 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9064         .f = cmd_flow_director_filter_parsed,
9065         .data = NULL,
9066         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9067                 "director entry on NIC",
9068         .tokens = {
9069                 (void *)&cmd_flow_director_filter,
9070                 (void *)&cmd_flow_director_port_id,
9071                 (void *)&cmd_flow_director_mode,
9072                 (void *)&cmd_flow_director_mode_mac_vlan,
9073                 (void *)&cmd_flow_director_ops,
9074                 (void *)&cmd_flow_director_mac,
9075                 (void *)&cmd_flow_director_mac_addr,
9076                 (void *)&cmd_flow_director_vlan,
9077                 (void *)&cmd_flow_director_vlan_value,
9078                 (void *)&cmd_flow_director_flexbytes,
9079                 (void *)&cmd_flow_director_flexbytes_value,
9080                 (void *)&cmd_flow_director_drop,
9081                 (void *)&cmd_flow_director_queue,
9082                 (void *)&cmd_flow_director_queue_id,
9083                 (void *)&cmd_flow_director_fd_id,
9084                 (void *)&cmd_flow_director_fd_id_value,
9085                 NULL,
9086         },
9087 };
9088
9089 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9090         .f = cmd_flow_director_filter_parsed,
9091         .data = NULL,
9092         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9093                 "director entry on NIC",
9094         .tokens = {
9095                 (void *)&cmd_flow_director_filter,
9096                 (void *)&cmd_flow_director_port_id,
9097                 (void *)&cmd_flow_director_mode,
9098                 (void *)&cmd_flow_director_mode_tunnel,
9099                 (void *)&cmd_flow_director_ops,
9100                 (void *)&cmd_flow_director_mac,
9101                 (void *)&cmd_flow_director_mac_addr,
9102                 (void *)&cmd_flow_director_vlan,
9103                 (void *)&cmd_flow_director_vlan_value,
9104                 (void *)&cmd_flow_director_tunnel,
9105                 (void *)&cmd_flow_director_tunnel_type,
9106                 (void *)&cmd_flow_director_tunnel_id,
9107                 (void *)&cmd_flow_director_tunnel_id_value,
9108                 (void *)&cmd_flow_director_flexbytes,
9109                 (void *)&cmd_flow_director_flexbytes_value,
9110                 (void *)&cmd_flow_director_drop,
9111                 (void *)&cmd_flow_director_queue,
9112                 (void *)&cmd_flow_director_queue_id,
9113                 (void *)&cmd_flow_director_fd_id,
9114                 (void *)&cmd_flow_director_fd_id_value,
9115                 NULL,
9116         },
9117 };
9118
9119 struct cmd_flush_flow_director_result {
9120         cmdline_fixed_string_t flush_flow_director;
9121         uint8_t port_id;
9122 };
9123
9124 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9125         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9126                                  flush_flow_director, "flush_flow_director");
9127 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9128         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9129                               port_id, UINT8);
9130
9131 static void
9132 cmd_flush_flow_director_parsed(void *parsed_result,
9133                           __attribute__((unused)) struct cmdline *cl,
9134                           __attribute__((unused)) void *data)
9135 {
9136         struct cmd_flow_director_result *res = parsed_result;
9137         int ret = 0;
9138
9139         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9140         if (ret < 0) {
9141                 printf("flow director is not supported on port %u.\n",
9142                         res->port_id);
9143                 return;
9144         }
9145
9146         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9147                         RTE_ETH_FILTER_FLUSH, NULL);
9148         if (ret < 0)
9149                 printf("flow director table flushing error: (%s)\n",
9150                         strerror(-ret));
9151 }
9152
9153 cmdline_parse_inst_t cmd_flush_flow_director = {
9154         .f = cmd_flush_flow_director_parsed,
9155         .data = NULL,
9156         .help_str = "flush_flow_director <port_id>: "
9157                 "Flush all flow director entries of a device on NIC",
9158         .tokens = {
9159                 (void *)&cmd_flush_flow_director_flush,
9160                 (void *)&cmd_flush_flow_director_port_id,
9161                 NULL,
9162         },
9163 };
9164
9165 /* *** deal with flow director mask *** */
9166 struct cmd_flow_director_mask_result {
9167         cmdline_fixed_string_t flow_director_mask;
9168         uint8_t port_id;
9169         cmdline_fixed_string_t mode;
9170         cmdline_fixed_string_t mode_value;
9171         cmdline_fixed_string_t vlan;
9172         uint16_t vlan_mask;
9173         cmdline_fixed_string_t src_mask;
9174         cmdline_ipaddr_t ipv4_src;
9175         cmdline_ipaddr_t ipv6_src;
9176         uint16_t port_src;
9177         cmdline_fixed_string_t dst_mask;
9178         cmdline_ipaddr_t ipv4_dst;
9179         cmdline_ipaddr_t ipv6_dst;
9180         uint16_t port_dst;
9181         cmdline_fixed_string_t mac;
9182         uint8_t mac_addr_byte_mask;
9183         cmdline_fixed_string_t tunnel_id;
9184         uint32_t tunnel_id_mask;
9185         cmdline_fixed_string_t tunnel_type;
9186         uint8_t tunnel_type_mask;
9187 };
9188
9189 static void
9190 cmd_flow_director_mask_parsed(void *parsed_result,
9191                           __attribute__((unused)) struct cmdline *cl,
9192                           __attribute__((unused)) void *data)
9193 {
9194         struct cmd_flow_director_mask_result *res = parsed_result;
9195         struct rte_eth_fdir_masks *mask;
9196         struct rte_port *port;
9197
9198         if (res->port_id > nb_ports) {
9199                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9200                 return;
9201         }
9202
9203         port = &ports[res->port_id];
9204         /** Check if the port is not started **/
9205         if (port->port_status != RTE_PORT_STOPPED) {
9206                 printf("Please stop port %d first\n", res->port_id);
9207                 return;
9208         }
9209
9210         mask = &port->dev_conf.fdir_conf.mask;
9211
9212         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9213                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9214                         printf("Please set mode to MAC-VLAN.\n");
9215                         return;
9216                 }
9217
9218                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9219         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9220                 if (strcmp(res->mode_value, "Tunnel")) {
9221                         printf("Please set mode to Tunnel.\n");
9222                         return;
9223                 }
9224
9225                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9226                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9227                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9228                 mask->tunnel_type_mask = res->tunnel_type_mask;
9229         } else {
9230                 if (strcmp(res->mode_value, "IP")) {
9231                         printf("Please set mode to IP.\n");
9232                         return;
9233                 }
9234
9235                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9236                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9237                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9238                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9239                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9240                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9241                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9242         }
9243
9244         cmd_reconfig_device_queue(res->port_id, 1, 1);
9245 }
9246
9247 cmdline_parse_token_string_t cmd_flow_director_mask =
9248         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9249                                  flow_director_mask, "flow_director_mask");
9250 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9251         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9252                               port_id, UINT8);
9253 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9255                                  vlan, "vlan");
9256 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9258                               vlan_mask, UINT16);
9259 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9261                                  src_mask, "src_mask");
9262 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9263         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9264                                  ipv4_src);
9265 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9266         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9267                                  ipv6_src);
9268 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9269         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9270                               port_src, UINT16);
9271 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9273                                  dst_mask, "dst_mask");
9274 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9275         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9276                                  ipv4_dst);
9277 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9278         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9279                                  ipv6_dst);
9280 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9282                               port_dst, UINT16);
9283
9284 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9286                                  mode, "mode");
9287 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9289                                  mode_value, "IP");
9290 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9292                                  mode_value, "MAC-VLAN");
9293 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9295                                  mode_value, "Tunnel");
9296 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9298                                  mac, "mac");
9299 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9300         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9301                               mac_addr_byte_mask, UINT8);
9302 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9304                                  tunnel_type, "tunnel-type");
9305 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9306         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9307                               tunnel_type_mask, UINT8);
9308 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9310                                  tunnel_id, "tunnel-id");
9311 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9312         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9313                               tunnel_id_mask, UINT32);
9314
9315 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9316         .f = cmd_flow_director_mask_parsed,
9317         .data = NULL,
9318         .help_str = "flow_director_mask ... : "
9319                 "Set IP mode flow director's mask on NIC",
9320         .tokens = {
9321                 (void *)&cmd_flow_director_mask,
9322                 (void *)&cmd_flow_director_mask_port_id,
9323                 (void *)&cmd_flow_director_mask_mode,
9324                 (void *)&cmd_flow_director_mask_mode_ip,
9325                 (void *)&cmd_flow_director_mask_vlan,
9326                 (void *)&cmd_flow_director_mask_vlan_value,
9327                 (void *)&cmd_flow_director_mask_src,
9328                 (void *)&cmd_flow_director_mask_ipv4_src,
9329                 (void *)&cmd_flow_director_mask_ipv6_src,
9330                 (void *)&cmd_flow_director_mask_port_src,
9331                 (void *)&cmd_flow_director_mask_dst,
9332                 (void *)&cmd_flow_director_mask_ipv4_dst,
9333                 (void *)&cmd_flow_director_mask_ipv6_dst,
9334                 (void *)&cmd_flow_director_mask_port_dst,
9335                 NULL,
9336         },
9337 };
9338
9339 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9340         .f = cmd_flow_director_mask_parsed,
9341         .data = NULL,
9342         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9343                 "flow director's mask on NIC",
9344         .tokens = {
9345                 (void *)&cmd_flow_director_mask,
9346                 (void *)&cmd_flow_director_mask_port_id,
9347                 (void *)&cmd_flow_director_mask_mode,
9348                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9349                 (void *)&cmd_flow_director_mask_vlan,
9350                 (void *)&cmd_flow_director_mask_vlan_value,
9351                 NULL,
9352         },
9353 };
9354
9355 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9356         .f = cmd_flow_director_mask_parsed,
9357         .data = NULL,
9358         .help_str = "flow_director_mask ... : Set tunnel mode "
9359                 "flow director's mask on NIC",
9360         .tokens = {
9361                 (void *)&cmd_flow_director_mask,
9362                 (void *)&cmd_flow_director_mask_port_id,
9363                 (void *)&cmd_flow_director_mask_mode,
9364                 (void *)&cmd_flow_director_mask_mode_tunnel,
9365                 (void *)&cmd_flow_director_mask_vlan,
9366                 (void *)&cmd_flow_director_mask_vlan_value,
9367                 (void *)&cmd_flow_director_mask_mac,
9368                 (void *)&cmd_flow_director_mask_mac_value,
9369                 (void *)&cmd_flow_director_mask_tunnel_type,
9370                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9371                 (void *)&cmd_flow_director_mask_tunnel_id,
9372                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9373                 NULL,
9374         },
9375 };
9376
9377 /* *** deal with flow director mask on flexible payload *** */
9378 struct cmd_flow_director_flex_mask_result {
9379         cmdline_fixed_string_t flow_director_flexmask;
9380         uint8_t port_id;
9381         cmdline_fixed_string_t flow;
9382         cmdline_fixed_string_t flow_type;
9383         cmdline_fixed_string_t mask;
9384 };
9385
9386 static void
9387 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9388                           __attribute__((unused)) struct cmdline *cl,
9389                           __attribute__((unused)) void *data)
9390 {
9391         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9392         struct rte_eth_fdir_info fdir_info;
9393         struct rte_eth_fdir_flex_mask flex_mask;
9394         struct rte_port *port;
9395         uint32_t flow_type_mask;
9396         uint16_t i;
9397         int ret;
9398
9399         if (res->port_id > nb_ports) {
9400                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9401                 return;
9402         }
9403
9404         port = &ports[res->port_id];
9405         /** Check if the port is not started **/
9406         if (port->port_status != RTE_PORT_STOPPED) {
9407                 printf("Please stop port %d first\n", res->port_id);
9408                 return;
9409         }
9410
9411         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9412         ret = parse_flexbytes(res->mask,
9413                         flex_mask.mask,
9414                         RTE_ETH_FDIR_MAX_FLEXLEN);
9415         if (ret < 0) {
9416                 printf("error: Cannot parse mask input.\n");
9417                 return;
9418         }
9419
9420         memset(&fdir_info, 0, sizeof(fdir_info));
9421         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9422                                 RTE_ETH_FILTER_INFO, &fdir_info);
9423         if (ret < 0) {
9424                 printf("Cannot get FDir filter info\n");
9425                 return;
9426         }
9427
9428         if (!strcmp(res->flow_type, "none")) {
9429                 /* means don't specify the flow type */
9430                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9431                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9432                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9433                                0, sizeof(struct rte_eth_fdir_flex_mask));
9434                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9435                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9436                                  &flex_mask,
9437                                  sizeof(struct rte_eth_fdir_flex_mask));
9438                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9439                 return;
9440         }
9441         flow_type_mask = fdir_info.flow_types_mask[0];
9442         if (!strcmp(res->flow_type, "all")) {
9443                 if (!flow_type_mask) {
9444                         printf("No flow type supported\n");
9445                         return;
9446                 }
9447                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9448                         if (flow_type_mask & (1 << i)) {
9449                                 flex_mask.flow_type = i;
9450                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9451                         }
9452                 }
9453                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9454                 return;
9455         }
9456         flex_mask.flow_type = str2flowtype(res->flow_type);
9457         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9458                 printf("Flow type %s not supported on port %d\n",
9459                                 res->flow_type, res->port_id);
9460                 return;
9461         }
9462         fdir_set_flex_mask(res->port_id, &flex_mask);
9463         cmd_reconfig_device_queue(res->port_id, 1, 1);
9464 }
9465
9466 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9468                                  flow_director_flexmask,
9469                                  "flow_director_flex_mask");
9470 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9471         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9472                               port_id, UINT8);
9473 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9474         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9475                                  flow, "flow");
9476 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9478                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9479                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9480 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9481         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9482                                  mask, NULL);
9483
9484 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9485         .f = cmd_flow_director_flex_mask_parsed,
9486         .data = NULL,
9487         .help_str = "flow_director_flex_mask ... : "
9488                 "Set flow director's flex mask on NIC",
9489         .tokens = {
9490                 (void *)&cmd_flow_director_flexmask,
9491                 (void *)&cmd_flow_director_flexmask_port_id,
9492                 (void *)&cmd_flow_director_flexmask_flow,
9493                 (void *)&cmd_flow_director_flexmask_flow_type,
9494                 (void *)&cmd_flow_director_flexmask_mask,
9495                 NULL,
9496         },
9497 };
9498
9499 /* *** deal with flow director flexible payload configuration *** */
9500 struct cmd_flow_director_flexpayload_result {
9501         cmdline_fixed_string_t flow_director_flexpayload;
9502         uint8_t port_id;
9503         cmdline_fixed_string_t payload_layer;
9504         cmdline_fixed_string_t payload_cfg;
9505 };
9506
9507 static inline int
9508 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9509 {
9510         char s[256];
9511         const char *p, *p0 = q_arg;
9512         char *end;
9513         unsigned long int_fld;
9514         char *str_fld[max_num];
9515         int i;
9516         unsigned size;
9517         int ret = -1;
9518
9519         p = strchr(p0, '(');
9520         if (p == NULL)
9521                 return -1;
9522         ++p;
9523         p0 = strchr(p, ')');
9524         if (p0 == NULL)
9525                 return -1;
9526
9527         size = p0 - p;
9528         if (size >= sizeof(s))
9529                 return -1;
9530
9531         snprintf(s, sizeof(s), "%.*s", size, p);
9532         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9533         if (ret < 0 || ret > max_num)
9534                 return -1;
9535         for (i = 0; i < ret; i++) {
9536                 errno = 0;
9537                 int_fld = strtoul(str_fld[i], &end, 0);
9538                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9539                         return -1;
9540                 offsets[i] = (uint16_t)int_fld;
9541         }
9542         return ret;
9543 }
9544
9545 static void
9546 cmd_flow_director_flxpld_parsed(void *parsed_result,
9547                           __attribute__((unused)) struct cmdline *cl,
9548                           __attribute__((unused)) void *data)
9549 {
9550         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9551         struct rte_eth_flex_payload_cfg flex_cfg;
9552         struct rte_port *port;
9553         int ret = 0;
9554
9555         if (res->port_id > nb_ports) {
9556                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9557                 return;
9558         }
9559
9560         port = &ports[res->port_id];
9561         /** Check if the port is not started **/
9562         if (port->port_status != RTE_PORT_STOPPED) {
9563                 printf("Please stop port %d first\n", res->port_id);
9564                 return;
9565         }
9566
9567         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9568
9569         if (!strcmp(res->payload_layer, "raw"))
9570                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9571         else if (!strcmp(res->payload_layer, "l2"))
9572                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9573         else if (!strcmp(res->payload_layer, "l3"))
9574                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9575         else if (!strcmp(res->payload_layer, "l4"))
9576                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9577
9578         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9579                             RTE_ETH_FDIR_MAX_FLEXLEN);
9580         if (ret < 0) {
9581                 printf("error: Cannot parse flex payload input.\n");
9582                 return;
9583         }
9584
9585         fdir_set_flex_payload(res->port_id, &flex_cfg);
9586         cmd_reconfig_device_queue(res->port_id, 1, 1);
9587 }
9588
9589 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9591                                  flow_director_flexpayload,
9592                                  "flow_director_flex_payload");
9593 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9594         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9595                               port_id, UINT8);
9596 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9598                                  payload_layer, "raw#l2#l3#l4");
9599 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9600         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9601                                  payload_cfg, NULL);
9602
9603 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9604         .f = cmd_flow_director_flxpld_parsed,
9605         .data = NULL,
9606         .help_str = "flow_director_flexpayload ... : "
9607                 "Set flow director's flex payload on NIC",
9608         .tokens = {
9609                 (void *)&cmd_flow_director_flexpayload,
9610                 (void *)&cmd_flow_director_flexpayload_port_id,
9611                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9612                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9613                 NULL,
9614         },
9615 };
9616
9617 /* Generic flow interface command. */
9618 extern cmdline_parse_inst_t cmd_flow;
9619
9620 /* *** Classification Filters Control *** */
9621 /* *** Get symmetric hash enable per port *** */
9622 struct cmd_get_sym_hash_ena_per_port_result {
9623         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9624         uint8_t port_id;
9625 };
9626
9627 static void
9628 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9629                                  __rte_unused struct cmdline *cl,
9630                                  __rte_unused void *data)
9631 {
9632         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9633         struct rte_eth_hash_filter_info info;
9634         int ret;
9635
9636         if (rte_eth_dev_filter_supported(res->port_id,
9637                                 RTE_ETH_FILTER_HASH) < 0) {
9638                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9639                                                         res->port_id);
9640                 return;
9641         }
9642
9643         memset(&info, 0, sizeof(info));
9644         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9645         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9646                                                 RTE_ETH_FILTER_GET, &info);
9647
9648         if (ret < 0) {
9649                 printf("Cannot get symmetric hash enable per port "
9650                                         "on port %u\n", res->port_id);
9651                 return;
9652         }
9653
9654         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9655                                 "enabled" : "disabled", res->port_id);
9656 }
9657
9658 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9659         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9660                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9661 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9662         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9663                 port_id, UINT8);
9664
9665 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9666         .f = cmd_get_sym_hash_per_port_parsed,
9667         .data = NULL,
9668         .help_str = "get_sym_hash_ena_per_port <port_id>",
9669         .tokens = {
9670                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9671                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9672                 NULL,
9673         },
9674 };
9675
9676 /* *** Set symmetric hash enable per port *** */
9677 struct cmd_set_sym_hash_ena_per_port_result {
9678         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9679         cmdline_fixed_string_t enable;
9680         uint8_t port_id;
9681 };
9682
9683 static void
9684 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9685                                  __rte_unused struct cmdline *cl,
9686                                  __rte_unused void *data)
9687 {
9688         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9689         struct rte_eth_hash_filter_info info;
9690         int ret;
9691
9692         if (rte_eth_dev_filter_supported(res->port_id,
9693                                 RTE_ETH_FILTER_HASH) < 0) {
9694                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9695                                                         res->port_id);
9696                 return;
9697         }
9698
9699         memset(&info, 0, sizeof(info));
9700         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9701         if (!strcmp(res->enable, "enable"))
9702                 info.info.enable = 1;
9703         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9704                                         RTE_ETH_FILTER_SET, &info);
9705         if (ret < 0) {
9706                 printf("Cannot set symmetric hash enable per port on "
9707                                         "port %u\n", res->port_id);
9708                 return;
9709         }
9710         printf("Symmetric hash has been set to %s on port %u\n",
9711                                         res->enable, res->port_id);
9712 }
9713
9714 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9715         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9716                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9717 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9718         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9719                 port_id, UINT8);
9720 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9721         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9722                 enable, "enable#disable");
9723
9724 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9725         .f = cmd_set_sym_hash_per_port_parsed,
9726         .data = NULL,
9727         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
9728         .tokens = {
9729                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9730                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9731                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9732                 NULL,
9733         },
9734 };
9735
9736 /* Get global config of hash function */
9737 struct cmd_get_hash_global_config_result {
9738         cmdline_fixed_string_t get_hash_global_config;
9739         uint8_t port_id;
9740 };
9741
9742 static char *
9743 flowtype_to_str(uint16_t ftype)
9744 {
9745         uint16_t i;
9746         static struct {
9747                 char str[16];
9748                 uint16_t ftype;
9749         } ftype_table[] = {
9750                 {"ipv4", RTE_ETH_FLOW_IPV4},
9751                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9752                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9753                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9754                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9755                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9756                 {"ipv6", RTE_ETH_FLOW_IPV6},
9757                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9758                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9759                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9760                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9761                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9762                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9763                 {"port", RTE_ETH_FLOW_PORT},
9764                 {"vxlan", RTE_ETH_FLOW_VXLAN},
9765                 {"geneve", RTE_ETH_FLOW_GENEVE},
9766                 {"nvgre", RTE_ETH_FLOW_NVGRE},
9767         };
9768
9769         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9770                 if (ftype_table[i].ftype == ftype)
9771                         return ftype_table[i].str;
9772         }
9773
9774         return NULL;
9775 }
9776
9777 static void
9778 cmd_get_hash_global_config_parsed(void *parsed_result,
9779                                   __rte_unused struct cmdline *cl,
9780                                   __rte_unused void *data)
9781 {
9782         struct cmd_get_hash_global_config_result *res = parsed_result;
9783         struct rte_eth_hash_filter_info info;
9784         uint32_t idx, offset;
9785         uint16_t i;
9786         char *str;
9787         int ret;
9788
9789         if (rte_eth_dev_filter_supported(res->port_id,
9790                         RTE_ETH_FILTER_HASH) < 0) {
9791                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9792                                                         res->port_id);
9793                 return;
9794         }
9795
9796         memset(&info, 0, sizeof(info));
9797         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9798         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9799                                         RTE_ETH_FILTER_GET, &info);
9800         if (ret < 0) {
9801                 printf("Cannot get hash global configurations by port %d\n",
9802                                                         res->port_id);
9803                 return;
9804         }
9805
9806         switch (info.info.global_conf.hash_func) {
9807         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9808                 printf("Hash function is Toeplitz\n");
9809                 break;
9810         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9811                 printf("Hash function is Simple XOR\n");
9812                 break;
9813         default:
9814                 printf("Unknown hash function\n");
9815                 break;
9816         }
9817
9818         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9819                 idx = i / UINT32_BIT;
9820                 offset = i % UINT32_BIT;
9821                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9822                                                 (1UL << offset)))
9823                         continue;
9824                 str = flowtype_to_str(i);
9825                 if (!str)
9826                         continue;
9827                 printf("Symmetric hash is %s globally for flow type %s "
9828                                                         "by port %d\n",
9829                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9830                         (1UL << offset)) ? "enabled" : "disabled"), str,
9831                                                         res->port_id);
9832         }
9833 }
9834
9835 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9836         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9837                 get_hash_global_config, "get_hash_global_config");
9838 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9839         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9840                 port_id, UINT8);
9841
9842 cmdline_parse_inst_t cmd_get_hash_global_config = {
9843         .f = cmd_get_hash_global_config_parsed,
9844         .data = NULL,
9845         .help_str = "get_hash_global_config <port_id>",
9846         .tokens = {
9847                 (void *)&cmd_get_hash_global_config_all,
9848                 (void *)&cmd_get_hash_global_config_port_id,
9849                 NULL,
9850         },
9851 };
9852
9853 /* Set global config of hash function */
9854 struct cmd_set_hash_global_config_result {
9855         cmdline_fixed_string_t set_hash_global_config;
9856         uint8_t port_id;
9857         cmdline_fixed_string_t hash_func;
9858         cmdline_fixed_string_t flow_type;
9859         cmdline_fixed_string_t enable;
9860 };
9861
9862 static void
9863 cmd_set_hash_global_config_parsed(void *parsed_result,
9864                                   __rte_unused struct cmdline *cl,
9865                                   __rte_unused void *data)
9866 {
9867         struct cmd_set_hash_global_config_result *res = parsed_result;
9868         struct rte_eth_hash_filter_info info;
9869         uint32_t ftype, idx, offset;
9870         int ret;
9871
9872         if (rte_eth_dev_filter_supported(res->port_id,
9873                                 RTE_ETH_FILTER_HASH) < 0) {
9874                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9875                                                         res->port_id);
9876                 return;
9877         }
9878         memset(&info, 0, sizeof(info));
9879         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9880         if (!strcmp(res->hash_func, "toeplitz"))
9881                 info.info.global_conf.hash_func =
9882                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9883         else if (!strcmp(res->hash_func, "simple_xor"))
9884                 info.info.global_conf.hash_func =
9885                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9886         else if (!strcmp(res->hash_func, "default"))
9887                 info.info.global_conf.hash_func =
9888                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9889
9890         ftype = str2flowtype(res->flow_type);
9891         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9892         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9893         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9894         if (!strcmp(res->enable, "enable"))
9895                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9896                                                 (1UL << offset);
9897         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9898                                         RTE_ETH_FILTER_SET, &info);
9899         if (ret < 0)
9900                 printf("Cannot set global hash configurations by port %d\n",
9901                                                         res->port_id);
9902         else
9903                 printf("Global hash configurations have been set "
9904                         "succcessfully by port %d\n", res->port_id);
9905 }
9906
9907 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9908         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9909                 set_hash_global_config, "set_hash_global_config");
9910 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9911         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9912                 port_id, UINT8);
9913 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9914         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9915                 hash_func, "toeplitz#simple_xor#default");
9916 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9917         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9918                 flow_type,
9919                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9920                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9921 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9922         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9923                 enable, "enable#disable");
9924
9925 cmdline_parse_inst_t cmd_set_hash_global_config = {
9926         .f = cmd_set_hash_global_config_parsed,
9927         .data = NULL,
9928         .help_str = "set_hash_global_config <port_id> "
9929                 "toeplitz|simple_xor|default "
9930                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
9931                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
9932                 "l2_payload enable|disable",
9933         .tokens = {
9934                 (void *)&cmd_set_hash_global_config_all,
9935                 (void *)&cmd_set_hash_global_config_port_id,
9936                 (void *)&cmd_set_hash_global_config_hash_func,
9937                 (void *)&cmd_set_hash_global_config_flow_type,
9938                 (void *)&cmd_set_hash_global_config_enable,
9939                 NULL,
9940         },
9941 };
9942
9943 /* Set hash input set */
9944 struct cmd_set_hash_input_set_result {
9945         cmdline_fixed_string_t set_hash_input_set;
9946         uint8_t port_id;
9947         cmdline_fixed_string_t flow_type;
9948         cmdline_fixed_string_t inset_field;
9949         cmdline_fixed_string_t select;
9950 };
9951
9952 static enum rte_eth_input_set_field
9953 str2inset(char *string)
9954 {
9955         uint16_t i;
9956
9957         static const struct {
9958                 char str[32];
9959                 enum rte_eth_input_set_field inset;
9960         } inset_table[] = {
9961                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
9962                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
9963                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
9964                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
9965                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
9966                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
9967                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
9968                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
9969                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
9970                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
9971                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
9972                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
9973                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
9974                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
9975                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
9976                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
9977                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
9978                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
9979                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
9980                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
9981                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
9982                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
9983                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
9984                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
9985                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
9986                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
9987                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
9988                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
9989                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
9990                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
9991                 {"none", RTE_ETH_INPUT_SET_NONE},
9992         };
9993
9994         for (i = 0; i < RTE_DIM(inset_table); i++) {
9995                 if (!strcmp(string, inset_table[i].str))
9996                         return inset_table[i].inset;
9997         }
9998
9999         return RTE_ETH_INPUT_SET_UNKNOWN;
10000 }
10001
10002 static void
10003 cmd_set_hash_input_set_parsed(void *parsed_result,
10004                               __rte_unused struct cmdline *cl,
10005                               __rte_unused void *data)
10006 {
10007         struct cmd_set_hash_input_set_result *res = parsed_result;
10008         struct rte_eth_hash_filter_info info;
10009
10010         memset(&info, 0, sizeof(info));
10011         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10012         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10013         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10014         info.info.input_set_conf.inset_size = 1;
10015         if (!strcmp(res->select, "select"))
10016                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10017         else if (!strcmp(res->select, "add"))
10018                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10019         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10020                                 RTE_ETH_FILTER_SET, &info);
10021 }
10022
10023 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10024         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10025                 set_hash_input_set, "set_hash_input_set");
10026 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10027         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10028                 port_id, UINT8);
10029 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10030         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10031                 flow_type,
10032                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10033                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10034 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10035         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10036                 inset_field,
10037                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10038                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10039                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10040                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10041                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10042                 "fld-8th#none");
10043 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10044         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10045                 select, "select#add");
10046
10047 cmdline_parse_inst_t cmd_set_hash_input_set = {
10048         .f = cmd_set_hash_input_set_parsed,
10049         .data = NULL,
10050         .help_str = "set_hash_input_set <port_id> "
10051         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10052         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10053         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10054         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10055         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10056         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10057         "fld-7th|fld-8th|none select|add",
10058         .tokens = {
10059                 (void *)&cmd_set_hash_input_set_cmd,
10060                 (void *)&cmd_set_hash_input_set_port_id,
10061                 (void *)&cmd_set_hash_input_set_flow_type,
10062                 (void *)&cmd_set_hash_input_set_field,
10063                 (void *)&cmd_set_hash_input_set_select,
10064                 NULL,
10065         },
10066 };
10067
10068 /* Set flow director input set */
10069 struct cmd_set_fdir_input_set_result {
10070         cmdline_fixed_string_t set_fdir_input_set;
10071         uint8_t port_id;
10072         cmdline_fixed_string_t flow_type;
10073         cmdline_fixed_string_t inset_field;
10074         cmdline_fixed_string_t select;
10075 };
10076
10077 static void
10078 cmd_set_fdir_input_set_parsed(void *parsed_result,
10079         __rte_unused struct cmdline *cl,
10080         __rte_unused void *data)
10081 {
10082         struct cmd_set_fdir_input_set_result *res = parsed_result;
10083         struct rte_eth_fdir_filter_info info;
10084
10085         memset(&info, 0, sizeof(info));
10086         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10087         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10088         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10089         info.info.input_set_conf.inset_size = 1;
10090         if (!strcmp(res->select, "select"))
10091                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10092         else if (!strcmp(res->select, "add"))
10093                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10094         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10095                 RTE_ETH_FILTER_SET, &info);
10096 }
10097
10098 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10099         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10100         set_fdir_input_set, "set_fdir_input_set");
10101 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10102         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10103         port_id, UINT8);
10104 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10105         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10106         flow_type,
10107         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10108         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10109 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10110         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10111         inset_field,
10112         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10113         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10114         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10115         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10116         "sctp-veri-tag#none");
10117 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10118         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10119         select, "select#add");
10120
10121 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10122         .f = cmd_set_fdir_input_set_parsed,
10123         .data = NULL,
10124         .help_str = "set_fdir_input_set <port_id> "
10125         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10126         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10127         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10128         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10129         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10130         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10131         "sctp-veri-tag|none select|add",
10132         .tokens = {
10133                 (void *)&cmd_set_fdir_input_set_cmd,
10134                 (void *)&cmd_set_fdir_input_set_port_id,
10135                 (void *)&cmd_set_fdir_input_set_flow_type,
10136                 (void *)&cmd_set_fdir_input_set_field,
10137                 (void *)&cmd_set_fdir_input_set_select,
10138                 NULL,
10139         },
10140 };
10141
10142 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10143 struct cmd_mcast_addr_result {
10144         cmdline_fixed_string_t mcast_addr_cmd;
10145         cmdline_fixed_string_t what;
10146         uint8_t port_num;
10147         struct ether_addr mc_addr;
10148 };
10149
10150 static void cmd_mcast_addr_parsed(void *parsed_result,
10151                 __attribute__((unused)) struct cmdline *cl,
10152                 __attribute__((unused)) void *data)
10153 {
10154         struct cmd_mcast_addr_result *res = parsed_result;
10155
10156         if (!is_multicast_ether_addr(&res->mc_addr)) {
10157                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10158                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10159                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10160                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10161                 return;
10162         }
10163         if (strcmp(res->what, "add") == 0)
10164                 mcast_addr_add(res->port_num, &res->mc_addr);
10165         else
10166                 mcast_addr_remove(res->port_num, &res->mc_addr);
10167 }
10168
10169 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10170         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10171                                  mcast_addr_cmd, "mcast_addr");
10172 cmdline_parse_token_string_t cmd_mcast_addr_what =
10173         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10174                                  "add#remove");
10175 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10176         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10177 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10178         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10179
10180 cmdline_parse_inst_t cmd_mcast_addr = {
10181         .f = cmd_mcast_addr_parsed,
10182         .data = (void *)0,
10183         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10184                 "Add/Remove multicast MAC address on port_id",
10185         .tokens = {
10186                 (void *)&cmd_mcast_addr_cmd,
10187                 (void *)&cmd_mcast_addr_what,
10188                 (void *)&cmd_mcast_addr_portnum,
10189                 (void *)&cmd_mcast_addr_addr,
10190                 NULL,
10191         },
10192 };
10193
10194 /* l2 tunnel config
10195  * only support E-tag now.
10196  */
10197
10198 /* Ether type config */
10199 struct cmd_config_l2_tunnel_eth_type_result {
10200         cmdline_fixed_string_t port;
10201         cmdline_fixed_string_t config;
10202         cmdline_fixed_string_t all;
10203         uint8_t id;
10204         cmdline_fixed_string_t l2_tunnel;
10205         cmdline_fixed_string_t l2_tunnel_type;
10206         cmdline_fixed_string_t eth_type;
10207         uint16_t eth_type_val;
10208 };
10209
10210 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10211         TOKEN_STRING_INITIALIZER
10212                 (struct cmd_config_l2_tunnel_eth_type_result,
10213                  port, "port");
10214 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10215         TOKEN_STRING_INITIALIZER
10216                 (struct cmd_config_l2_tunnel_eth_type_result,
10217                  config, "config");
10218 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10219         TOKEN_STRING_INITIALIZER
10220                 (struct cmd_config_l2_tunnel_eth_type_result,
10221                  all, "all");
10222 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10223         TOKEN_NUM_INITIALIZER
10224                 (struct cmd_config_l2_tunnel_eth_type_result,
10225                  id, UINT8);
10226 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10227         TOKEN_STRING_INITIALIZER
10228                 (struct cmd_config_l2_tunnel_eth_type_result,
10229                  l2_tunnel, "l2-tunnel");
10230 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10231         TOKEN_STRING_INITIALIZER
10232                 (struct cmd_config_l2_tunnel_eth_type_result,
10233                  l2_tunnel_type, "E-tag");
10234 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10235         TOKEN_STRING_INITIALIZER
10236                 (struct cmd_config_l2_tunnel_eth_type_result,
10237                  eth_type, "ether-type");
10238 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10239         TOKEN_NUM_INITIALIZER
10240                 (struct cmd_config_l2_tunnel_eth_type_result,
10241                  eth_type_val, UINT16);
10242
10243 static enum rte_eth_tunnel_type
10244 str2fdir_l2_tunnel_type(char *string)
10245 {
10246         uint32_t i = 0;
10247
10248         static const struct {
10249                 char str[32];
10250                 enum rte_eth_tunnel_type type;
10251         } l2_tunnel_type_str[] = {
10252                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10253         };
10254
10255         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10256                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10257                         return l2_tunnel_type_str[i].type;
10258         }
10259         return RTE_TUNNEL_TYPE_NONE;
10260 }
10261
10262 /* ether type config for all ports */
10263 static void
10264 cmd_config_l2_tunnel_eth_type_all_parsed
10265         (void *parsed_result,
10266          __attribute__((unused)) struct cmdline *cl,
10267          __attribute__((unused)) void *data)
10268 {
10269         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10270         struct rte_eth_l2_tunnel_conf entry;
10271         portid_t pid;
10272
10273         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10274         entry.ether_type = res->eth_type_val;
10275
10276         FOREACH_PORT(pid, ports) {
10277                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10278         }
10279 }
10280
10281 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10282         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10283         .data = NULL,
10284         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10285         .tokens = {
10286                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10287                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10288                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10289                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10290                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10291                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10292                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10293                 NULL,
10294         },
10295 };
10296
10297 /* ether type config for a specific port */
10298 static void
10299 cmd_config_l2_tunnel_eth_type_specific_parsed(
10300         void *parsed_result,
10301         __attribute__((unused)) struct cmdline *cl,
10302         __attribute__((unused)) void *data)
10303 {
10304         struct cmd_config_l2_tunnel_eth_type_result *res =
10305                  parsed_result;
10306         struct rte_eth_l2_tunnel_conf entry;
10307
10308         if (port_id_is_invalid(res->id, ENABLED_WARN))
10309                 return;
10310
10311         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10312         entry.ether_type = res->eth_type_val;
10313
10314         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10315 }
10316
10317 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10318         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10319         .data = NULL,
10320         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10321         .tokens = {
10322                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10323                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10324                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10325                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10326                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10327                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10328                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10329                 NULL,
10330         },
10331 };
10332
10333 /* Enable/disable l2 tunnel */
10334 struct cmd_config_l2_tunnel_en_dis_result {
10335         cmdline_fixed_string_t port;
10336         cmdline_fixed_string_t config;
10337         cmdline_fixed_string_t all;
10338         uint8_t id;
10339         cmdline_fixed_string_t l2_tunnel;
10340         cmdline_fixed_string_t l2_tunnel_type;
10341         cmdline_fixed_string_t en_dis;
10342 };
10343
10344 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10345         TOKEN_STRING_INITIALIZER
10346                 (struct cmd_config_l2_tunnel_en_dis_result,
10347                  port, "port");
10348 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10349         TOKEN_STRING_INITIALIZER
10350                 (struct cmd_config_l2_tunnel_en_dis_result,
10351                  config, "config");
10352 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10353         TOKEN_STRING_INITIALIZER
10354                 (struct cmd_config_l2_tunnel_en_dis_result,
10355                  all, "all");
10356 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10357         TOKEN_NUM_INITIALIZER
10358                 (struct cmd_config_l2_tunnel_en_dis_result,
10359                  id, UINT8);
10360 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10361         TOKEN_STRING_INITIALIZER
10362                 (struct cmd_config_l2_tunnel_en_dis_result,
10363                  l2_tunnel, "l2-tunnel");
10364 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10365         TOKEN_STRING_INITIALIZER
10366                 (struct cmd_config_l2_tunnel_en_dis_result,
10367                  l2_tunnel_type, "E-tag");
10368 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10369         TOKEN_STRING_INITIALIZER
10370                 (struct cmd_config_l2_tunnel_en_dis_result,
10371                  en_dis, "enable#disable");
10372
10373 /* enable/disable l2 tunnel for all ports */
10374 static void
10375 cmd_config_l2_tunnel_en_dis_all_parsed(
10376         void *parsed_result,
10377         __attribute__((unused)) struct cmdline *cl,
10378         __attribute__((unused)) void *data)
10379 {
10380         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10381         struct rte_eth_l2_tunnel_conf entry;
10382         portid_t pid;
10383         uint8_t en;
10384
10385         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10386
10387         if (!strcmp("enable", res->en_dis))
10388                 en = 1;
10389         else
10390                 en = 0;
10391
10392         FOREACH_PORT(pid, ports) {
10393                 rte_eth_dev_l2_tunnel_offload_set(pid,
10394                                                   &entry,
10395                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10396                                                   en);
10397         }
10398 }
10399
10400 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10401         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10402         .data = NULL,
10403         .help_str = "port config all l2-tunnel E-tag enable|disable",
10404         .tokens = {
10405                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10406                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10407                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10408                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10409                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10410                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10411                 NULL,
10412         },
10413 };
10414
10415 /* enable/disable l2 tunnel for a port */
10416 static void
10417 cmd_config_l2_tunnel_en_dis_specific_parsed(
10418         void *parsed_result,
10419         __attribute__((unused)) struct cmdline *cl,
10420         __attribute__((unused)) void *data)
10421 {
10422         struct cmd_config_l2_tunnel_en_dis_result *res =
10423                 parsed_result;
10424         struct rte_eth_l2_tunnel_conf entry;
10425
10426         if (port_id_is_invalid(res->id, ENABLED_WARN))
10427                 return;
10428
10429         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10430
10431         if (!strcmp("enable", res->en_dis))
10432                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10433                                                   &entry,
10434                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10435                                                   1);
10436         else
10437                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10438                                                   &entry,
10439                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10440                                                   0);
10441 }
10442
10443 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10444         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10445         .data = NULL,
10446         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10447         .tokens = {
10448                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10449                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10450                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10451                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10452                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10453                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10454                 NULL,
10455         },
10456 };
10457
10458 /* E-tag configuration */
10459
10460 /* Common result structure for all E-tag configuration */
10461 struct cmd_config_e_tag_result {
10462         cmdline_fixed_string_t e_tag;
10463         cmdline_fixed_string_t set;
10464         cmdline_fixed_string_t insertion;
10465         cmdline_fixed_string_t stripping;
10466         cmdline_fixed_string_t forwarding;
10467         cmdline_fixed_string_t filter;
10468         cmdline_fixed_string_t add;
10469         cmdline_fixed_string_t del;
10470         cmdline_fixed_string_t on;
10471         cmdline_fixed_string_t off;
10472         cmdline_fixed_string_t on_off;
10473         cmdline_fixed_string_t port_tag_id;
10474         uint32_t port_tag_id_val;
10475         cmdline_fixed_string_t e_tag_id;
10476         uint16_t e_tag_id_val;
10477         cmdline_fixed_string_t dst_pool;
10478         uint8_t dst_pool_val;
10479         cmdline_fixed_string_t port;
10480         uint8_t port_id;
10481         cmdline_fixed_string_t vf;
10482         uint8_t vf_id;
10483 };
10484
10485 /* Common CLI fields for all E-tag configuration */
10486 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10487         TOKEN_STRING_INITIALIZER
10488                 (struct cmd_config_e_tag_result,
10489                  e_tag, "E-tag");
10490 cmdline_parse_token_string_t cmd_config_e_tag_set =
10491         TOKEN_STRING_INITIALIZER
10492                 (struct cmd_config_e_tag_result,
10493                  set, "set");
10494 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10495         TOKEN_STRING_INITIALIZER
10496                 (struct cmd_config_e_tag_result,
10497                  insertion, "insertion");
10498 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10499         TOKEN_STRING_INITIALIZER
10500                 (struct cmd_config_e_tag_result,
10501                  stripping, "stripping");
10502 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10503         TOKEN_STRING_INITIALIZER
10504                 (struct cmd_config_e_tag_result,
10505                  forwarding, "forwarding");
10506 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10507         TOKEN_STRING_INITIALIZER
10508                 (struct cmd_config_e_tag_result,
10509                  filter, "filter");
10510 cmdline_parse_token_string_t cmd_config_e_tag_add =
10511         TOKEN_STRING_INITIALIZER
10512                 (struct cmd_config_e_tag_result,
10513                  add, "add");
10514 cmdline_parse_token_string_t cmd_config_e_tag_del =
10515         TOKEN_STRING_INITIALIZER
10516                 (struct cmd_config_e_tag_result,
10517                  del, "del");
10518 cmdline_parse_token_string_t cmd_config_e_tag_on =
10519         TOKEN_STRING_INITIALIZER
10520                 (struct cmd_config_e_tag_result,
10521                  on, "on");
10522 cmdline_parse_token_string_t cmd_config_e_tag_off =
10523         TOKEN_STRING_INITIALIZER
10524                 (struct cmd_config_e_tag_result,
10525                  off, "off");
10526 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10527         TOKEN_STRING_INITIALIZER
10528                 (struct cmd_config_e_tag_result,
10529                  on_off, "on#off");
10530 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10531         TOKEN_STRING_INITIALIZER
10532                 (struct cmd_config_e_tag_result,
10533                  port_tag_id, "port-tag-id");
10534 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10535         TOKEN_NUM_INITIALIZER
10536                 (struct cmd_config_e_tag_result,
10537                  port_tag_id_val, UINT32);
10538 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10539         TOKEN_STRING_INITIALIZER
10540                 (struct cmd_config_e_tag_result,
10541                  e_tag_id, "e-tag-id");
10542 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10543         TOKEN_NUM_INITIALIZER
10544                 (struct cmd_config_e_tag_result,
10545                  e_tag_id_val, UINT16);
10546 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10547         TOKEN_STRING_INITIALIZER
10548                 (struct cmd_config_e_tag_result,
10549                  dst_pool, "dst-pool");
10550 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10551         TOKEN_NUM_INITIALIZER
10552                 (struct cmd_config_e_tag_result,
10553                  dst_pool_val, UINT8);
10554 cmdline_parse_token_string_t cmd_config_e_tag_port =
10555         TOKEN_STRING_INITIALIZER
10556                 (struct cmd_config_e_tag_result,
10557                  port, "port");
10558 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10559         TOKEN_NUM_INITIALIZER
10560                 (struct cmd_config_e_tag_result,
10561                  port_id, UINT8);
10562 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10563         TOKEN_STRING_INITIALIZER
10564                 (struct cmd_config_e_tag_result,
10565                  vf, "vf");
10566 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10567         TOKEN_NUM_INITIALIZER
10568                 (struct cmd_config_e_tag_result,
10569                  vf_id, UINT8);
10570
10571 /* E-tag insertion configuration */
10572 static void
10573 cmd_config_e_tag_insertion_en_parsed(
10574         void *parsed_result,
10575         __attribute__((unused)) struct cmdline *cl,
10576         __attribute__((unused)) void *data)
10577 {
10578         struct cmd_config_e_tag_result *res =
10579                 parsed_result;
10580         struct rte_eth_l2_tunnel_conf entry;
10581
10582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10583                 return;
10584
10585         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10586         entry.tunnel_id = res->port_tag_id_val;
10587         entry.vf_id = res->vf_id;
10588         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10589                                           &entry,
10590                                           ETH_L2_TUNNEL_INSERTION_MASK,
10591                                           1);
10592 }
10593
10594 static void
10595 cmd_config_e_tag_insertion_dis_parsed(
10596         void *parsed_result,
10597         __attribute__((unused)) struct cmdline *cl,
10598         __attribute__((unused)) void *data)
10599 {
10600         struct cmd_config_e_tag_result *res =
10601                 parsed_result;
10602         struct rte_eth_l2_tunnel_conf entry;
10603
10604         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10605                 return;
10606
10607         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10608         entry.vf_id = res->vf_id;
10609
10610         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10611                                           &entry,
10612                                           ETH_L2_TUNNEL_INSERTION_MASK,
10613                                           0);
10614 }
10615
10616 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10617         .f = cmd_config_e_tag_insertion_en_parsed,
10618         .data = NULL,
10619         .help_str = "E-tag ... : E-tag insertion enable",
10620         .tokens = {
10621                 (void *)&cmd_config_e_tag_e_tag,
10622                 (void *)&cmd_config_e_tag_set,
10623                 (void *)&cmd_config_e_tag_insertion,
10624                 (void *)&cmd_config_e_tag_on,
10625                 (void *)&cmd_config_e_tag_port_tag_id,
10626                 (void *)&cmd_config_e_tag_port_tag_id_val,
10627                 (void *)&cmd_config_e_tag_port,
10628                 (void *)&cmd_config_e_tag_port_id,
10629                 (void *)&cmd_config_e_tag_vf,
10630                 (void *)&cmd_config_e_tag_vf_id,
10631                 NULL,
10632         },
10633 };
10634
10635 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10636         .f = cmd_config_e_tag_insertion_dis_parsed,
10637         .data = NULL,
10638         .help_str = "E-tag ... : E-tag insertion disable",
10639         .tokens = {
10640                 (void *)&cmd_config_e_tag_e_tag,
10641                 (void *)&cmd_config_e_tag_set,
10642                 (void *)&cmd_config_e_tag_insertion,
10643                 (void *)&cmd_config_e_tag_off,
10644                 (void *)&cmd_config_e_tag_port,
10645                 (void *)&cmd_config_e_tag_port_id,
10646                 (void *)&cmd_config_e_tag_vf,
10647                 (void *)&cmd_config_e_tag_vf_id,
10648                 NULL,
10649         },
10650 };
10651
10652 /* E-tag stripping configuration */
10653 static void
10654 cmd_config_e_tag_stripping_parsed(
10655         void *parsed_result,
10656         __attribute__((unused)) struct cmdline *cl,
10657         __attribute__((unused)) void *data)
10658 {
10659         struct cmd_config_e_tag_result *res =
10660                 parsed_result;
10661         struct rte_eth_l2_tunnel_conf entry;
10662
10663         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10664                 return;
10665
10666         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10667
10668         if (!strcmp(res->on_off, "on"))
10669                 rte_eth_dev_l2_tunnel_offload_set
10670                         (res->port_id,
10671                          &entry,
10672                          ETH_L2_TUNNEL_STRIPPING_MASK,
10673                          1);
10674         else
10675                 rte_eth_dev_l2_tunnel_offload_set
10676                         (res->port_id,
10677                          &entry,
10678                          ETH_L2_TUNNEL_STRIPPING_MASK,
10679                          0);
10680 }
10681
10682 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
10683         .f = cmd_config_e_tag_stripping_parsed,
10684         .data = NULL,
10685         .help_str = "E-tag ... : E-tag stripping enable/disable",
10686         .tokens = {
10687                 (void *)&cmd_config_e_tag_e_tag,
10688                 (void *)&cmd_config_e_tag_set,
10689                 (void *)&cmd_config_e_tag_stripping,
10690                 (void *)&cmd_config_e_tag_on_off,
10691                 (void *)&cmd_config_e_tag_port,
10692                 (void *)&cmd_config_e_tag_port_id,
10693                 NULL,
10694         },
10695 };
10696
10697 /* E-tag forwarding configuration */
10698 static void
10699 cmd_config_e_tag_forwarding_parsed(
10700         void *parsed_result,
10701         __attribute__((unused)) struct cmdline *cl,
10702         __attribute__((unused)) void *data)
10703 {
10704         struct cmd_config_e_tag_result *res = parsed_result;
10705         struct rte_eth_l2_tunnel_conf entry;
10706
10707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10708                 return;
10709
10710         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10711
10712         if (!strcmp(res->on_off, "on"))
10713                 rte_eth_dev_l2_tunnel_offload_set
10714                         (res->port_id,
10715                          &entry,
10716                          ETH_L2_TUNNEL_FORWARDING_MASK,
10717                          1);
10718         else
10719                 rte_eth_dev_l2_tunnel_offload_set
10720                         (res->port_id,
10721                          &entry,
10722                          ETH_L2_TUNNEL_FORWARDING_MASK,
10723                          0);
10724 }
10725
10726 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
10727         .f = cmd_config_e_tag_forwarding_parsed,
10728         .data = NULL,
10729         .help_str = "E-tag ... : E-tag forwarding enable/disable",
10730         .tokens = {
10731                 (void *)&cmd_config_e_tag_e_tag,
10732                 (void *)&cmd_config_e_tag_set,
10733                 (void *)&cmd_config_e_tag_forwarding,
10734                 (void *)&cmd_config_e_tag_on_off,
10735                 (void *)&cmd_config_e_tag_port,
10736                 (void *)&cmd_config_e_tag_port_id,
10737                 NULL,
10738         },
10739 };
10740
10741 /* E-tag filter configuration */
10742 static void
10743 cmd_config_e_tag_filter_add_parsed(
10744         void *parsed_result,
10745         __attribute__((unused)) struct cmdline *cl,
10746         __attribute__((unused)) void *data)
10747 {
10748         struct cmd_config_e_tag_result *res = parsed_result;
10749         struct rte_eth_l2_tunnel_conf entry;
10750         int ret = 0;
10751
10752         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10753                 return;
10754
10755         if (res->e_tag_id_val > 0x3fff) {
10756                 printf("e-tag-id must be equal or less than 0x3fff.\n");
10757                 return;
10758         }
10759
10760         ret = rte_eth_dev_filter_supported(res->port_id,
10761                                            RTE_ETH_FILTER_L2_TUNNEL);
10762         if (ret < 0) {
10763                 printf("E-tag filter is not supported on port %u.\n",
10764                        res->port_id);
10765                 return;
10766         }
10767
10768         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10769         entry.tunnel_id = res->e_tag_id_val;
10770         entry.pool = res->dst_pool_val;
10771
10772         ret = rte_eth_dev_filter_ctrl(res->port_id,
10773                                       RTE_ETH_FILTER_L2_TUNNEL,
10774                                       RTE_ETH_FILTER_ADD,
10775                                       &entry);
10776         if (ret < 0)
10777                 printf("E-tag filter programming error: (%s)\n",
10778                        strerror(-ret));
10779 }
10780
10781 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
10782         .f = cmd_config_e_tag_filter_add_parsed,
10783         .data = NULL,
10784         .help_str = "E-tag ... : E-tag filter add",
10785         .tokens = {
10786                 (void *)&cmd_config_e_tag_e_tag,
10787                 (void *)&cmd_config_e_tag_set,
10788                 (void *)&cmd_config_e_tag_filter,
10789                 (void *)&cmd_config_e_tag_add,
10790                 (void *)&cmd_config_e_tag_e_tag_id,
10791                 (void *)&cmd_config_e_tag_e_tag_id_val,
10792                 (void *)&cmd_config_e_tag_dst_pool,
10793                 (void *)&cmd_config_e_tag_dst_pool_val,
10794                 (void *)&cmd_config_e_tag_port,
10795                 (void *)&cmd_config_e_tag_port_id,
10796                 NULL,
10797         },
10798 };
10799
10800 static void
10801 cmd_config_e_tag_filter_del_parsed(
10802         void *parsed_result,
10803         __attribute__((unused)) struct cmdline *cl,
10804         __attribute__((unused)) void *data)
10805 {
10806         struct cmd_config_e_tag_result *res = parsed_result;
10807         struct rte_eth_l2_tunnel_conf entry;
10808         int ret = 0;
10809
10810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10811                 return;
10812
10813         if (res->e_tag_id_val > 0x3fff) {
10814                 printf("e-tag-id must be less than 0x3fff.\n");
10815                 return;
10816         }
10817
10818         ret = rte_eth_dev_filter_supported(res->port_id,
10819                                            RTE_ETH_FILTER_L2_TUNNEL);
10820         if (ret < 0) {
10821                 printf("E-tag filter is not supported on port %u.\n",
10822                        res->port_id);
10823                 return;
10824         }
10825
10826         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10827         entry.tunnel_id = res->e_tag_id_val;
10828
10829         ret = rte_eth_dev_filter_ctrl(res->port_id,
10830                                       RTE_ETH_FILTER_L2_TUNNEL,
10831                                       RTE_ETH_FILTER_DELETE,
10832                                       &entry);
10833         if (ret < 0)
10834                 printf("E-tag filter programming error: (%s)\n",
10835                        strerror(-ret));
10836 }
10837
10838 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
10839         .f = cmd_config_e_tag_filter_del_parsed,
10840         .data = NULL,
10841         .help_str = "E-tag ... : E-tag filter delete",
10842         .tokens = {
10843                 (void *)&cmd_config_e_tag_e_tag,
10844                 (void *)&cmd_config_e_tag_set,
10845                 (void *)&cmd_config_e_tag_filter,
10846                 (void *)&cmd_config_e_tag_del,
10847                 (void *)&cmd_config_e_tag_e_tag_id,
10848                 (void *)&cmd_config_e_tag_e_tag_id_val,
10849                 (void *)&cmd_config_e_tag_port,
10850                 (void *)&cmd_config_e_tag_port_id,
10851                 NULL,
10852         },
10853 };
10854 #ifdef RTE_LIBRTE_IXGBE_PMD
10855
10856 /* vf vlan anti spoof configuration */
10857
10858 /* Common result structure for vf vlan anti spoof */
10859 struct cmd_vf_vlan_anti_spoof_result {
10860         cmdline_fixed_string_t set;
10861         cmdline_fixed_string_t vf;
10862         cmdline_fixed_string_t vlan;
10863         cmdline_fixed_string_t antispoof;
10864         uint8_t port_id;
10865         uint32_t vf_id;
10866         cmdline_fixed_string_t on_off;
10867 };
10868
10869 /* Common CLI fields for vf vlan anti spoof enable disable */
10870 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10871         TOKEN_STRING_INITIALIZER
10872                 (struct cmd_vf_vlan_anti_spoof_result,
10873                  set, "set");
10874 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10875         TOKEN_STRING_INITIALIZER
10876                 (struct cmd_vf_vlan_anti_spoof_result,
10877                  vf, "vf");
10878 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10879         TOKEN_STRING_INITIALIZER
10880                 (struct cmd_vf_vlan_anti_spoof_result,
10881                  vlan, "vlan");
10882 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10883         TOKEN_STRING_INITIALIZER
10884                 (struct cmd_vf_vlan_anti_spoof_result,
10885                  antispoof, "antispoof");
10886 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10887         TOKEN_NUM_INITIALIZER
10888                 (struct cmd_vf_vlan_anti_spoof_result,
10889                  port_id, UINT8);
10890 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10891         TOKEN_NUM_INITIALIZER
10892                 (struct cmd_vf_vlan_anti_spoof_result,
10893                  vf_id, UINT32);
10894 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10895         TOKEN_STRING_INITIALIZER
10896                 (struct cmd_vf_vlan_anti_spoof_result,
10897                  on_off, "on#off");
10898
10899 static void
10900 cmd_set_vf_vlan_anti_spoof_parsed(
10901         void *parsed_result,
10902         __attribute__((unused)) struct cmdline *cl,
10903         __attribute__((unused)) void *data)
10904 {
10905         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10906         int ret = 0;
10907         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10908
10909         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10910                 return;
10911
10912         ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, res->vf_id,
10913                         is_on);
10914         switch (ret) {
10915         case 0:
10916                 break;
10917         case -EINVAL:
10918                 printf("invalid vf_id %d\n", res->vf_id);
10919                 break;
10920         case -ENODEV:
10921                 printf("invalid port_id %d\n", res->port_id);
10922                 break;
10923         default:
10924                 printf("programming error: (%s)\n", strerror(-ret));
10925         }
10926 }
10927
10928 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10929         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10930         .data = NULL,
10931         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10932         .tokens = {
10933                 (void *)&cmd_vf_vlan_anti_spoof_set,
10934                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10935                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10936                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10937                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10938                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10939                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10940                 NULL,
10941         },
10942 };
10943
10944 /* vf mac anti spoof configuration */
10945
10946 /* Common result structure for vf mac anti spoof */
10947 struct cmd_vf_mac_anti_spoof_result {
10948         cmdline_fixed_string_t set;
10949         cmdline_fixed_string_t vf;
10950         cmdline_fixed_string_t mac;
10951         cmdline_fixed_string_t antispoof;
10952         uint8_t port_id;
10953         uint32_t vf_id;
10954         cmdline_fixed_string_t on_off;
10955 };
10956
10957 /* Common CLI fields for vf mac anti spoof enable disable */
10958 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10959         TOKEN_STRING_INITIALIZER
10960                 (struct cmd_vf_mac_anti_spoof_result,
10961                  set, "set");
10962 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10963         TOKEN_STRING_INITIALIZER
10964                 (struct cmd_vf_mac_anti_spoof_result,
10965                  vf, "vf");
10966 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10967         TOKEN_STRING_INITIALIZER
10968                 (struct cmd_vf_mac_anti_spoof_result,
10969                  mac, "mac");
10970 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10971         TOKEN_STRING_INITIALIZER
10972                 (struct cmd_vf_mac_anti_spoof_result,
10973                  antispoof, "antispoof");
10974 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10975         TOKEN_NUM_INITIALIZER
10976                 (struct cmd_vf_mac_anti_spoof_result,
10977                  port_id, UINT8);
10978 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10979         TOKEN_NUM_INITIALIZER
10980                 (struct cmd_vf_mac_anti_spoof_result,
10981                  vf_id, UINT32);
10982 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10983         TOKEN_STRING_INITIALIZER
10984                 (struct cmd_vf_mac_anti_spoof_result,
10985                  on_off, "on#off");
10986
10987 static void
10988 cmd_set_vf_mac_anti_spoof_parsed(
10989         void *parsed_result,
10990         __attribute__((unused)) struct cmdline *cl,
10991         __attribute__((unused)) void *data)
10992 {
10993         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10994         int ret;
10995         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10996
10997         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10998                 return;
10999
11000         ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, res->vf_id,
11001                         is_on);
11002         switch (ret) {
11003         case 0:
11004                 break;
11005         case -EINVAL:
11006                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11007                 break;
11008         case -ENODEV:
11009                 printf("invalid port_id %d\n", res->port_id);
11010                 break;
11011         default:
11012                 printf("programming error: (%s)\n", strerror(-ret));
11013         }
11014 }
11015
11016 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11017         .f = cmd_set_vf_mac_anti_spoof_parsed,
11018         .data = NULL,
11019         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11020         .tokens = {
11021                 (void *)&cmd_vf_mac_anti_spoof_set,
11022                 (void *)&cmd_vf_mac_anti_spoof_vf,
11023                 (void *)&cmd_vf_mac_anti_spoof_mac,
11024                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11025                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11026                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11027                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11028                 NULL,
11029         },
11030 };
11031
11032 /* vf vlan strip queue configuration */
11033
11034 /* Common result structure for vf mac anti spoof */
11035 struct cmd_vf_vlan_stripq_result {
11036         cmdline_fixed_string_t set;
11037         cmdline_fixed_string_t vf;
11038         cmdline_fixed_string_t vlan;
11039         cmdline_fixed_string_t stripq;
11040         uint8_t port_id;
11041         uint16_t vf_id;
11042         cmdline_fixed_string_t on_off;
11043 };
11044
11045 /* Common CLI fields for vf vlan strip enable disable */
11046 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11047         TOKEN_STRING_INITIALIZER
11048                 (struct cmd_vf_vlan_stripq_result,
11049                  set, "set");
11050 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11051         TOKEN_STRING_INITIALIZER
11052                 (struct cmd_vf_vlan_stripq_result,
11053                  vf, "vf");
11054 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11055         TOKEN_STRING_INITIALIZER
11056                 (struct cmd_vf_vlan_stripq_result,
11057                  vlan, "vlan");
11058 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11059         TOKEN_STRING_INITIALIZER
11060                 (struct cmd_vf_vlan_stripq_result,
11061                  stripq, "stripq");
11062 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11063         TOKEN_NUM_INITIALIZER
11064                 (struct cmd_vf_vlan_stripq_result,
11065                  port_id, UINT8);
11066 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11067         TOKEN_NUM_INITIALIZER
11068                 (struct cmd_vf_vlan_stripq_result,
11069                  vf_id, UINT16);
11070 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11071         TOKEN_STRING_INITIALIZER
11072                 (struct cmd_vf_vlan_stripq_result,
11073                  on_off, "on#off");
11074
11075 static void
11076 cmd_set_vf_vlan_stripq_parsed(
11077         void *parsed_result,
11078         __attribute__((unused)) struct cmdline *cl,
11079         __attribute__((unused)) void *data)
11080 {
11081         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11082         int ret = 0;
11083         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11084
11085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11086                 return;
11087
11088         ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, res->vf_id, is_on);
11089         switch (ret) {
11090         case 0:
11091                 break;
11092         case -EINVAL:
11093                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11094                 break;
11095         case -ENODEV:
11096                 printf("invalid port_id %d\n", res->port_id);
11097                 break;
11098         default:
11099                 printf("programming error: (%s)\n", strerror(-ret));
11100         }
11101 }
11102
11103 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11104         .f = cmd_set_vf_vlan_stripq_parsed,
11105         .data = NULL,
11106         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11107         .tokens = {
11108                 (void *)&cmd_vf_vlan_stripq_set,
11109                 (void *)&cmd_vf_vlan_stripq_vf,
11110                 (void *)&cmd_vf_vlan_stripq_vlan,
11111                 (void *)&cmd_vf_vlan_stripq_stripq,
11112                 (void *)&cmd_vf_vlan_stripq_port_id,
11113                 (void *)&cmd_vf_vlan_stripq_vf_id,
11114                 (void *)&cmd_vf_vlan_stripq_on_off,
11115                 NULL,
11116         },
11117 };
11118
11119 /* vf vlan insert configuration */
11120
11121 /* Common result structure for vf vlan insert */
11122 struct cmd_vf_vlan_insert_result {
11123         cmdline_fixed_string_t set;
11124         cmdline_fixed_string_t vf;
11125         cmdline_fixed_string_t vlan;
11126         cmdline_fixed_string_t insert;
11127         uint8_t port_id;
11128         uint16_t vf_id;
11129         uint16_t vlan_id;
11130 };
11131
11132 /* Common CLI fields for vf vlan insert enable disable */
11133 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11134         TOKEN_STRING_INITIALIZER
11135                 (struct cmd_vf_vlan_insert_result,
11136                  set, "set");
11137 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11138         TOKEN_STRING_INITIALIZER
11139                 (struct cmd_vf_vlan_insert_result,
11140                  vf, "vf");
11141 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11142         TOKEN_STRING_INITIALIZER
11143                 (struct cmd_vf_vlan_insert_result,
11144                  vlan, "vlan");
11145 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11146         TOKEN_STRING_INITIALIZER
11147                 (struct cmd_vf_vlan_insert_result,
11148                  insert, "insert");
11149 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11150         TOKEN_NUM_INITIALIZER
11151                 (struct cmd_vf_vlan_insert_result,
11152                  port_id, UINT8);
11153 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11154         TOKEN_NUM_INITIALIZER
11155                 (struct cmd_vf_vlan_insert_result,
11156                  vf_id, UINT16);
11157 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11158         TOKEN_NUM_INITIALIZER
11159                 (struct cmd_vf_vlan_insert_result,
11160                  vlan_id, UINT16);
11161
11162 static void
11163 cmd_set_vf_vlan_insert_parsed(
11164         void *parsed_result,
11165         __attribute__((unused)) struct cmdline *cl,
11166         __attribute__((unused)) void *data)
11167 {
11168         struct cmd_vf_vlan_insert_result *res = parsed_result;
11169         int ret;
11170
11171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11172                 return;
11173
11174         ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, res->vlan_id);
11175         switch (ret) {
11176         case 0:
11177                 break;
11178         case -EINVAL:
11179                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11180                 break;
11181         case -ENODEV:
11182                 printf("invalid port_id %d\n", res->port_id);
11183                 break;
11184         default:
11185                 printf("programming error: (%s)\n", strerror(-ret));
11186         }
11187 }
11188
11189 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11190         .f = cmd_set_vf_vlan_insert_parsed,
11191         .data = NULL,
11192         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11193         .tokens = {
11194                 (void *)&cmd_vf_vlan_insert_set,
11195                 (void *)&cmd_vf_vlan_insert_vf,
11196                 (void *)&cmd_vf_vlan_insert_vlan,
11197                 (void *)&cmd_vf_vlan_insert_insert,
11198                 (void *)&cmd_vf_vlan_insert_port_id,
11199                 (void *)&cmd_vf_vlan_insert_vf_id,
11200                 (void *)&cmd_vf_vlan_insert_vlan_id,
11201                 NULL,
11202         },
11203 };
11204
11205 /* tx loopback configuration */
11206
11207 /* Common result structure for tx loopback */
11208 struct cmd_tx_loopback_result {
11209         cmdline_fixed_string_t set;
11210         cmdline_fixed_string_t tx;
11211         cmdline_fixed_string_t loopback;
11212         uint8_t port_id;
11213         cmdline_fixed_string_t on_off;
11214 };
11215
11216 /* Common CLI fields for tx loopback enable disable */
11217 cmdline_parse_token_string_t cmd_tx_loopback_set =
11218         TOKEN_STRING_INITIALIZER
11219                 (struct cmd_tx_loopback_result,
11220                  set, "set");
11221 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11222         TOKEN_STRING_INITIALIZER
11223                 (struct cmd_tx_loopback_result,
11224                  tx, "tx");
11225 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11226         TOKEN_STRING_INITIALIZER
11227                 (struct cmd_tx_loopback_result,
11228                  loopback, "loopback");
11229 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11230         TOKEN_NUM_INITIALIZER
11231                 (struct cmd_tx_loopback_result,
11232                  port_id, UINT8);
11233 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11234         TOKEN_STRING_INITIALIZER
11235                 (struct cmd_tx_loopback_result,
11236                  on_off, "on#off");
11237
11238 static void
11239 cmd_set_tx_loopback_parsed(
11240         void *parsed_result,
11241         __attribute__((unused)) struct cmdline *cl,
11242         __attribute__((unused)) void *data)
11243 {
11244         struct cmd_tx_loopback_result *res = parsed_result;
11245         int ret;
11246         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11247
11248         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11249                 return;
11250
11251         ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11252         switch (ret) {
11253         case 0:
11254                 break;
11255         case -EINVAL:
11256                 printf("invalid is_on %d\n", is_on);
11257                 break;
11258         case -ENODEV:
11259                 printf("invalid port_id %d\n", res->port_id);
11260                 break;
11261         default:
11262                 printf("programming error: (%s)\n", strerror(-ret));
11263         }
11264 }
11265
11266 cmdline_parse_inst_t cmd_set_tx_loopback = {
11267         .f = cmd_set_tx_loopback_parsed,
11268         .data = NULL,
11269         .help_str = "set tx loopback <port_id> on|off",
11270         .tokens = {
11271                 (void *)&cmd_tx_loopback_set,
11272                 (void *)&cmd_tx_loopback_tx,
11273                 (void *)&cmd_tx_loopback_loopback,
11274                 (void *)&cmd_tx_loopback_port_id,
11275                 (void *)&cmd_tx_loopback_on_off,
11276                 NULL,
11277         },
11278 };
11279
11280 /* all queues drop enable configuration */
11281
11282 /* Common result structure for all queues drop enable */
11283 struct cmd_all_queues_drop_en_result {
11284         cmdline_fixed_string_t set;
11285         cmdline_fixed_string_t all;
11286         cmdline_fixed_string_t queues;
11287         cmdline_fixed_string_t drop;
11288         uint8_t port_id;
11289         cmdline_fixed_string_t on_off;
11290 };
11291
11292 /* Common CLI fields for tx loopback enable disable */
11293 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11294         TOKEN_STRING_INITIALIZER
11295                 (struct cmd_all_queues_drop_en_result,
11296                  set, "set");
11297 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11298         TOKEN_STRING_INITIALIZER
11299                 (struct cmd_all_queues_drop_en_result,
11300                  all, "all");
11301 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11302         TOKEN_STRING_INITIALIZER
11303                 (struct cmd_all_queues_drop_en_result,
11304                  queues, "queues");
11305 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11306         TOKEN_STRING_INITIALIZER
11307                 (struct cmd_all_queues_drop_en_result,
11308                  drop, "drop");
11309 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11310         TOKEN_NUM_INITIALIZER
11311                 (struct cmd_all_queues_drop_en_result,
11312                  port_id, UINT8);
11313 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11314         TOKEN_STRING_INITIALIZER
11315                 (struct cmd_all_queues_drop_en_result,
11316                  on_off, "on#off");
11317
11318 static void
11319 cmd_set_all_queues_drop_en_parsed(
11320         void *parsed_result,
11321         __attribute__((unused)) struct cmdline *cl,
11322         __attribute__((unused)) void *data)
11323 {
11324         struct cmd_all_queues_drop_en_result *res = parsed_result;
11325         int ret = 0;
11326         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11327
11328         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11329                 return;
11330
11331         ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11332         switch (ret) {
11333         case 0:
11334                 break;
11335         case -EINVAL:
11336                 printf("invalid is_on %d\n", is_on);
11337                 break;
11338         case -ENODEV:
11339                 printf("invalid port_id %d\n", res->port_id);
11340                 break;
11341         default:
11342                 printf("programming error: (%s)\n", strerror(-ret));
11343         }
11344 }
11345
11346 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11347         .f = cmd_set_all_queues_drop_en_parsed,
11348         .data = NULL,
11349         .help_str = "set all queues drop <port_id> on|off",
11350         .tokens = {
11351                 (void *)&cmd_all_queues_drop_en_set,
11352                 (void *)&cmd_all_queues_drop_en_all,
11353                 (void *)&cmd_all_queues_drop_en_queues,
11354                 (void *)&cmd_all_queues_drop_en_drop,
11355                 (void *)&cmd_all_queues_drop_en_port_id,
11356                 (void *)&cmd_all_queues_drop_en_on_off,
11357                 NULL,
11358         },
11359 };
11360
11361 /* vf split drop enable configuration */
11362
11363 /* Common result structure for vf split drop enable */
11364 struct cmd_vf_split_drop_en_result {
11365         cmdline_fixed_string_t set;
11366         cmdline_fixed_string_t vf;
11367         cmdline_fixed_string_t split;
11368         cmdline_fixed_string_t drop;
11369         uint8_t port_id;
11370         uint16_t vf_id;
11371         cmdline_fixed_string_t on_off;
11372 };
11373
11374 /* Common CLI fields for vf split drop enable disable */
11375 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11376         TOKEN_STRING_INITIALIZER
11377                 (struct cmd_vf_split_drop_en_result,
11378                  set, "set");
11379 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11380         TOKEN_STRING_INITIALIZER
11381                 (struct cmd_vf_split_drop_en_result,
11382                  vf, "vf");
11383 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11384         TOKEN_STRING_INITIALIZER
11385                 (struct cmd_vf_split_drop_en_result,
11386                  split, "split");
11387 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11388         TOKEN_STRING_INITIALIZER
11389                 (struct cmd_vf_split_drop_en_result,
11390                  drop, "drop");
11391 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11392         TOKEN_NUM_INITIALIZER
11393                 (struct cmd_vf_split_drop_en_result,
11394                  port_id, UINT8);
11395 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11396         TOKEN_NUM_INITIALIZER
11397                 (struct cmd_vf_split_drop_en_result,
11398                  vf_id, UINT16);
11399 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11400         TOKEN_STRING_INITIALIZER
11401                 (struct cmd_vf_split_drop_en_result,
11402                  on_off, "on#off");
11403
11404 static void
11405 cmd_set_vf_split_drop_en_parsed(
11406         void *parsed_result,
11407         __attribute__((unused)) struct cmdline *cl,
11408         __attribute__((unused)) void *data)
11409 {
11410         struct cmd_vf_split_drop_en_result *res = parsed_result;
11411         int ret;
11412         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11413
11414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11415                 return;
11416
11417         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11418                         is_on);
11419         switch (ret) {
11420         case 0:
11421                 break;
11422         case -EINVAL:
11423                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11424                 break;
11425         case -ENODEV:
11426                 printf("invalid port_id %d\n", res->port_id);
11427                 break;
11428         default:
11429                 printf("programming error: (%s)\n", strerror(-ret));
11430         }
11431 }
11432
11433 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11434         .f = cmd_set_vf_split_drop_en_parsed,
11435         .data = NULL,
11436         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11437         .tokens = {
11438                 (void *)&cmd_vf_split_drop_en_set,
11439                 (void *)&cmd_vf_split_drop_en_vf,
11440                 (void *)&cmd_vf_split_drop_en_split,
11441                 (void *)&cmd_vf_split_drop_en_drop,
11442                 (void *)&cmd_vf_split_drop_en_port_id,
11443                 (void *)&cmd_vf_split_drop_en_vf_id,
11444                 (void *)&cmd_vf_split_drop_en_on_off,
11445                 NULL,
11446         },
11447 };
11448
11449 /* vf mac address configuration */
11450
11451 /* Common result structure for vf mac address */
11452 struct cmd_set_vf_mac_addr_result {
11453         cmdline_fixed_string_t set;
11454         cmdline_fixed_string_t vf;
11455         cmdline_fixed_string_t mac;
11456         cmdline_fixed_string_t addr;
11457         uint8_t port_id;
11458         uint16_t vf_id;
11459         struct ether_addr mac_addr;
11460
11461 };
11462
11463 /* Common CLI fields for vf split drop enable disable */
11464 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11465         TOKEN_STRING_INITIALIZER
11466                 (struct cmd_set_vf_mac_addr_result,
11467                  set, "set");
11468 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11469         TOKEN_STRING_INITIALIZER
11470                 (struct cmd_set_vf_mac_addr_result,
11471                  vf, "vf");
11472 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11473         TOKEN_STRING_INITIALIZER
11474                 (struct cmd_set_vf_mac_addr_result,
11475                  mac, "mac");
11476 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11477         TOKEN_STRING_INITIALIZER
11478                 (struct cmd_set_vf_mac_addr_result,
11479                  addr, "addr");
11480 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11481         TOKEN_NUM_INITIALIZER
11482                 (struct cmd_set_vf_mac_addr_result,
11483                  port_id, UINT8);
11484 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11485         TOKEN_NUM_INITIALIZER
11486                 (struct cmd_set_vf_mac_addr_result,
11487                  vf_id, UINT16);
11488 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11489         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11490                  mac_addr);
11491
11492 static void
11493 cmd_set_vf_mac_addr_parsed(
11494         void *parsed_result,
11495         __attribute__((unused)) struct cmdline *cl,
11496         __attribute__((unused)) void *data)
11497 {
11498         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11499         int ret;
11500
11501         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11502                 return;
11503
11504         ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11505                         &res->mac_addr);
11506         switch (ret) {
11507         case 0:
11508                 break;
11509         case -EINVAL:
11510                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11511                 break;
11512         case -ENODEV:
11513                 printf("invalid port_id %d\n", res->port_id);
11514                 break;
11515         default:
11516                 printf("programming error: (%s)\n", strerror(-ret));
11517         }
11518 }
11519
11520 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11521         .f = cmd_set_vf_mac_addr_parsed,
11522         .data = NULL,
11523         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11524         .tokens = {
11525                 (void *)&cmd_set_vf_mac_addr_set,
11526                 (void *)&cmd_set_vf_mac_addr_vf,
11527                 (void *)&cmd_set_vf_mac_addr_mac,
11528                 (void *)&cmd_set_vf_mac_addr_addr,
11529                 (void *)&cmd_set_vf_mac_addr_port_id,
11530                 (void *)&cmd_set_vf_mac_addr_vf_id,
11531                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11532                 NULL,
11533         },
11534 };
11535
11536 /* MACsec configuration */
11537
11538 /* Common result structure for MACsec offload enable */
11539 struct cmd_macsec_offload_on_result {
11540         cmdline_fixed_string_t set;
11541         cmdline_fixed_string_t macsec;
11542         cmdline_fixed_string_t offload;
11543         uint8_t port_id;
11544         cmdline_fixed_string_t on;
11545         cmdline_fixed_string_t encrypt;
11546         cmdline_fixed_string_t en_on_off;
11547         cmdline_fixed_string_t replay_protect;
11548         cmdline_fixed_string_t rp_on_off;
11549 };
11550
11551 /* Common CLI fields for MACsec offload disable */
11552 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11553         TOKEN_STRING_INITIALIZER
11554                 (struct cmd_macsec_offload_on_result,
11555                  set, "set");
11556 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11557         TOKEN_STRING_INITIALIZER
11558                 (struct cmd_macsec_offload_on_result,
11559                  macsec, "macsec");
11560 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11561         TOKEN_STRING_INITIALIZER
11562                 (struct cmd_macsec_offload_on_result,
11563                  offload, "offload");
11564 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11565         TOKEN_NUM_INITIALIZER
11566                 (struct cmd_macsec_offload_on_result,
11567                  port_id, UINT8);
11568 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11569         TOKEN_STRING_INITIALIZER
11570                 (struct cmd_macsec_offload_on_result,
11571                  on, "on");
11572 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11573         TOKEN_STRING_INITIALIZER
11574                 (struct cmd_macsec_offload_on_result,
11575                  encrypt, "encrypt");
11576 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11577         TOKEN_STRING_INITIALIZER
11578                 (struct cmd_macsec_offload_on_result,
11579                  en_on_off, "on#off");
11580 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11581         TOKEN_STRING_INITIALIZER
11582                 (struct cmd_macsec_offload_on_result,
11583                  replay_protect, "replay-protect");
11584 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11585         TOKEN_STRING_INITIALIZER
11586                 (struct cmd_macsec_offload_on_result,
11587                  rp_on_off, "on#off");
11588
11589 static void
11590 cmd_set_macsec_offload_on_parsed(
11591         void *parsed_result,
11592         __attribute__((unused)) struct cmdline *cl,
11593         __attribute__((unused)) void *data)
11594 {
11595         struct cmd_macsec_offload_on_result *res = parsed_result;
11596         int ret;
11597         portid_t port_id = res->port_id;
11598         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11599         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11600
11601         if (port_id_is_invalid(port_id, ENABLED_WARN))
11602                 return;
11603
11604         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
11605         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11606
11607         switch (ret) {
11608         case 0:
11609                 break;
11610         case -ENODEV:
11611                 printf("invalid port_id %d\n", port_id);
11612                 break;
11613         default:
11614                 printf("programming error: (%s)\n", strerror(-ret));
11615         }
11616 }
11617
11618 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11619         .f = cmd_set_macsec_offload_on_parsed,
11620         .data = NULL,
11621         .help_str = "set macsec offload <port_id> on "
11622                 "encrypt on|off replay-protect on|off",
11623         .tokens = {
11624                 (void *)&cmd_macsec_offload_on_set,
11625                 (void *)&cmd_macsec_offload_on_macsec,
11626                 (void *)&cmd_macsec_offload_on_offload,
11627                 (void *)&cmd_macsec_offload_on_port_id,
11628                 (void *)&cmd_macsec_offload_on_on,
11629                 (void *)&cmd_macsec_offload_on_encrypt,
11630                 (void *)&cmd_macsec_offload_on_en_on_off,
11631                 (void *)&cmd_macsec_offload_on_replay_protect,
11632                 (void *)&cmd_macsec_offload_on_rp_on_off,
11633                 NULL,
11634         },
11635 };
11636
11637 /* Common result structure for MACsec offload disable */
11638 struct cmd_macsec_offload_off_result {
11639         cmdline_fixed_string_t set;
11640         cmdline_fixed_string_t macsec;
11641         cmdline_fixed_string_t offload;
11642         uint8_t port_id;
11643         cmdline_fixed_string_t off;
11644 };
11645
11646 /* Common CLI fields for MACsec offload disable */
11647 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11648         TOKEN_STRING_INITIALIZER
11649                 (struct cmd_macsec_offload_off_result,
11650                  set, "set");
11651 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11652         TOKEN_STRING_INITIALIZER
11653                 (struct cmd_macsec_offload_off_result,
11654                  macsec, "macsec");
11655 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11656         TOKEN_STRING_INITIALIZER
11657                 (struct cmd_macsec_offload_off_result,
11658                  offload, "offload");
11659 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11660         TOKEN_NUM_INITIALIZER
11661                 (struct cmd_macsec_offload_off_result,
11662                  port_id, UINT8);
11663 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11664         TOKEN_STRING_INITIALIZER
11665                 (struct cmd_macsec_offload_off_result,
11666                  off, "off");
11667
11668 static void
11669 cmd_set_macsec_offload_off_parsed(
11670         void *parsed_result,
11671         __attribute__((unused)) struct cmdline *cl,
11672         __attribute__((unused)) void *data)
11673 {
11674         struct cmd_macsec_offload_off_result *res = parsed_result;
11675         int ret;
11676         portid_t port_id = res->port_id;
11677
11678         if (port_id_is_invalid(port_id, ENABLED_WARN))
11679                 return;
11680
11681         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
11682         ret = rte_pmd_ixgbe_macsec_disable(port_id);
11683
11684         switch (ret) {
11685         case 0:
11686                 break;
11687         case -ENODEV:
11688                 printf("invalid port_id %d\n", port_id);
11689                 break;
11690         default:
11691                 printf("programming error: (%s)\n", strerror(-ret));
11692         }
11693 }
11694
11695 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11696         .f = cmd_set_macsec_offload_off_parsed,
11697         .data = NULL,
11698         .help_str = "set macsec offload <port_id> off",
11699         .tokens = {
11700                 (void *)&cmd_macsec_offload_off_set,
11701                 (void *)&cmd_macsec_offload_off_macsec,
11702                 (void *)&cmd_macsec_offload_off_offload,
11703                 (void *)&cmd_macsec_offload_off_port_id,
11704                 (void *)&cmd_macsec_offload_off_off,
11705                 NULL,
11706         },
11707 };
11708
11709 /* Common result structure for MACsec secure connection configure */
11710 struct cmd_macsec_sc_result {
11711         cmdline_fixed_string_t set;
11712         cmdline_fixed_string_t macsec;
11713         cmdline_fixed_string_t sc;
11714         cmdline_fixed_string_t tx_rx;
11715         uint8_t port_id;
11716         struct ether_addr mac;
11717         uint16_t pi;
11718 };
11719
11720 /* Common CLI fields for MACsec secure connection configure */
11721 cmdline_parse_token_string_t cmd_macsec_sc_set =
11722         TOKEN_STRING_INITIALIZER
11723                 (struct cmd_macsec_sc_result,
11724                  set, "set");
11725 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11726         TOKEN_STRING_INITIALIZER
11727                 (struct cmd_macsec_sc_result,
11728                  macsec, "macsec");
11729 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11730         TOKEN_STRING_INITIALIZER
11731                 (struct cmd_macsec_sc_result,
11732                  sc, "sc");
11733 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11734         TOKEN_STRING_INITIALIZER
11735                 (struct cmd_macsec_sc_result,
11736                  tx_rx, "tx#rx");
11737 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11738         TOKEN_NUM_INITIALIZER
11739                 (struct cmd_macsec_sc_result,
11740                  port_id, UINT8);
11741 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11742         TOKEN_ETHERADDR_INITIALIZER
11743                 (struct cmd_macsec_sc_result,
11744                  mac);
11745 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11746         TOKEN_NUM_INITIALIZER
11747                 (struct cmd_macsec_sc_result,
11748                  pi, UINT16);
11749
11750 static void
11751 cmd_set_macsec_sc_parsed(
11752         void *parsed_result,
11753         __attribute__((unused)) struct cmdline *cl,
11754         __attribute__((unused)) void *data)
11755 {
11756         struct cmd_macsec_sc_result *res = parsed_result;
11757         int ret;
11758         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11759
11760         ret = is_tx ?
11761                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11762                                 res->mac.addr_bytes) :
11763                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11764                                 res->mac.addr_bytes, res->pi);
11765         switch (ret) {
11766         case 0:
11767                 break;
11768         case -ENODEV:
11769                 printf("invalid port_id %d\n", res->port_id);
11770                 break;
11771         default:
11772                 printf("programming error: (%s)\n", strerror(-ret));
11773         }
11774 }
11775
11776 cmdline_parse_inst_t cmd_set_macsec_sc = {
11777         .f = cmd_set_macsec_sc_parsed,
11778         .data = NULL,
11779         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11780         .tokens = {
11781                 (void *)&cmd_macsec_sc_set,
11782                 (void *)&cmd_macsec_sc_macsec,
11783                 (void *)&cmd_macsec_sc_sc,
11784                 (void *)&cmd_macsec_sc_tx_rx,
11785                 (void *)&cmd_macsec_sc_port_id,
11786                 (void *)&cmd_macsec_sc_mac,
11787                 (void *)&cmd_macsec_sc_pi,
11788                 NULL,
11789         },
11790 };
11791
11792 /* Common result structure for MACsec secure connection configure */
11793 struct cmd_macsec_sa_result {
11794         cmdline_fixed_string_t set;
11795         cmdline_fixed_string_t macsec;
11796         cmdline_fixed_string_t sa;
11797         cmdline_fixed_string_t tx_rx;
11798         uint8_t port_id;
11799         uint8_t idx;
11800         uint8_t an;
11801         uint32_t pn;
11802         cmdline_fixed_string_t key;
11803 };
11804
11805 /* Common CLI fields for MACsec secure connection configure */
11806 cmdline_parse_token_string_t cmd_macsec_sa_set =
11807         TOKEN_STRING_INITIALIZER
11808                 (struct cmd_macsec_sa_result,
11809                  set, "set");
11810 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11811         TOKEN_STRING_INITIALIZER
11812                 (struct cmd_macsec_sa_result,
11813                  macsec, "macsec");
11814 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11815         TOKEN_STRING_INITIALIZER
11816                 (struct cmd_macsec_sa_result,
11817                  sa, "sa");
11818 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11819         TOKEN_STRING_INITIALIZER
11820                 (struct cmd_macsec_sa_result,
11821                  tx_rx, "tx#rx");
11822 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11823         TOKEN_NUM_INITIALIZER
11824                 (struct cmd_macsec_sa_result,
11825                  port_id, UINT8);
11826 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11827         TOKEN_NUM_INITIALIZER
11828                 (struct cmd_macsec_sa_result,
11829                  idx, UINT8);
11830 cmdline_parse_token_num_t cmd_macsec_sa_an =
11831         TOKEN_NUM_INITIALIZER
11832                 (struct cmd_macsec_sa_result,
11833                  an, UINT8);
11834 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11835         TOKEN_NUM_INITIALIZER
11836                 (struct cmd_macsec_sa_result,
11837                  pn, UINT32);
11838 cmdline_parse_token_string_t cmd_macsec_sa_key =
11839         TOKEN_STRING_INITIALIZER
11840                 (struct cmd_macsec_sa_result,
11841                  key, NULL);
11842
11843 static void
11844 cmd_set_macsec_sa_parsed(
11845         void *parsed_result,
11846         __attribute__((unused)) struct cmdline *cl,
11847         __attribute__((unused)) void *data)
11848 {
11849         struct cmd_macsec_sa_result *res = parsed_result;
11850         int ret;
11851         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11852         uint8_t key[16] = { 0 };
11853         uint8_t xdgt0;
11854         uint8_t xdgt1;
11855         int key_len;
11856         int i;
11857
11858         key_len = strlen(res->key) / 2;
11859         if (key_len > 16)
11860                 key_len = 16;
11861
11862         for (i = 0; i < key_len; i++) {
11863                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11864                 if (xdgt0 == 0xFF)
11865                         return;
11866                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11867                 if (xdgt1 == 0xFF)
11868                         return;
11869                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11870         }
11871
11872         ret = is_tx ?
11873                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11874                         res->idx, res->an, res->pn, key) :
11875                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11876                         res->idx, res->an, res->pn, key);
11877         switch (ret) {
11878         case 0:
11879                 break;
11880         case -EINVAL:
11881                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11882                 break;
11883         case -ENODEV:
11884                 printf("invalid port_id %d\n", res->port_id);
11885                 break;
11886         default:
11887                 printf("programming error: (%s)\n", strerror(-ret));
11888         }
11889 }
11890
11891 cmdline_parse_inst_t cmd_set_macsec_sa = {
11892         .f = cmd_set_macsec_sa_parsed,
11893         .data = NULL,
11894         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11895         .tokens = {
11896                 (void *)&cmd_macsec_sa_set,
11897                 (void *)&cmd_macsec_sa_macsec,
11898                 (void *)&cmd_macsec_sa_sa,
11899                 (void *)&cmd_macsec_sa_tx_rx,
11900                 (void *)&cmd_macsec_sa_port_id,
11901                 (void *)&cmd_macsec_sa_idx,
11902                 (void *)&cmd_macsec_sa_an,
11903                 (void *)&cmd_macsec_sa_pn,
11904                 (void *)&cmd_macsec_sa_key,
11905                 NULL,
11906         },
11907 };
11908 #endif
11909
11910 /* ******************************************************************************** */
11911
11912 /* list of instructions */
11913 cmdline_parse_ctx_t main_ctx[] = {
11914         (cmdline_parse_inst_t *)&cmd_help_brief,
11915         (cmdline_parse_inst_t *)&cmd_help_long,
11916         (cmdline_parse_inst_t *)&cmd_quit,
11917         (cmdline_parse_inst_t *)&cmd_showport,
11918         (cmdline_parse_inst_t *)&cmd_showqueue,
11919         (cmdline_parse_inst_t *)&cmd_showportall,
11920         (cmdline_parse_inst_t *)&cmd_showcfg,
11921         (cmdline_parse_inst_t *)&cmd_start,
11922         (cmdline_parse_inst_t *)&cmd_start_tx_first,
11923         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
11924         (cmdline_parse_inst_t *)&cmd_set_link_up,
11925         (cmdline_parse_inst_t *)&cmd_set_link_down,
11926         (cmdline_parse_inst_t *)&cmd_reset,
11927         (cmdline_parse_inst_t *)&cmd_set_numbers,
11928         (cmdline_parse_inst_t *)&cmd_set_txpkts,
11929         (cmdline_parse_inst_t *)&cmd_set_txsplit,
11930         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
11931         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
11932         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
11933         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
11934         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
11935         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
11936         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
11937         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
11938         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
11939         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
11940         (cmdline_parse_inst_t *)&cmd_set_link_check,
11941 #ifdef RTE_NIC_BYPASS
11942         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
11943         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
11944         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
11945         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
11946 #endif
11947 #ifdef RTE_LIBRTE_PMD_BOND
11948         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
11949         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
11950         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
11951         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
11952         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
11953         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
11954         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
11955         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
11956         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
11957 #endif
11958         (cmdline_parse_inst_t *)&cmd_vlan_offload,
11959         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
11960         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
11961         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
11962         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
11963         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
11964         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
11965         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
11966         (cmdline_parse_inst_t *)&cmd_csum_set,
11967         (cmdline_parse_inst_t *)&cmd_csum_show,
11968         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
11969         (cmdline_parse_inst_t *)&cmd_tso_set,
11970         (cmdline_parse_inst_t *)&cmd_tso_show,
11971         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
11972         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
11973         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
11974         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
11975         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
11976         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
11977         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
11978         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
11979         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
11980         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
11981         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
11982         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
11983         (cmdline_parse_inst_t *)&cmd_config_dcb,
11984         (cmdline_parse_inst_t *)&cmd_read_reg,
11985         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
11986         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
11987         (cmdline_parse_inst_t *)&cmd_write_reg,
11988         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
11989         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
11990         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
11991         (cmdline_parse_inst_t *)&cmd_stop,
11992         (cmdline_parse_inst_t *)&cmd_mac_addr,
11993         (cmdline_parse_inst_t *)&cmd_set_qmap,
11994         (cmdline_parse_inst_t *)&cmd_operate_port,
11995         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
11996         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
11997         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
11998         (cmdline_parse_inst_t *)&cmd_config_speed_all,
11999         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
12000         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
12001         (cmdline_parse_inst_t *)&cmd_config_mtu,
12002         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
12003         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
12004         (cmdline_parse_inst_t *)&cmd_config_rss,
12005         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
12006         (cmdline_parse_inst_t *)&cmd_config_txqflags,
12007         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
12008         (cmdline_parse_inst_t *)&cmd_showport_reta,
12009         (cmdline_parse_inst_t *)&cmd_config_burst,
12010         (cmdline_parse_inst_t *)&cmd_config_thresh,
12011         (cmdline_parse_inst_t *)&cmd_config_threshold,
12012         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
12013         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
12014         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
12015         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
12016         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
12017         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
12018         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
12019         (cmdline_parse_inst_t *)&cmd_global_config,
12020         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
12021         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
12022         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
12023         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
12024         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
12025         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
12026         (cmdline_parse_inst_t *)&cmd_dump,
12027         (cmdline_parse_inst_t *)&cmd_dump_one,
12028         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
12029         (cmdline_parse_inst_t *)&cmd_syn_filter,
12030         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
12031         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
12032         (cmdline_parse_inst_t *)&cmd_flex_filter,
12033         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
12034         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
12035         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
12036         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
12037         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
12038         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
12039         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
12040         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
12041         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
12042         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
12043         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
12044         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
12045         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
12046         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
12047         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
12048         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
12049         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
12050         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
12051         (cmdline_parse_inst_t *)&cmd_flow,
12052         (cmdline_parse_inst_t *)&cmd_mcast_addr,
12053         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
12054         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
12055         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
12056         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
12057         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
12058         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
12059         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
12060         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
12061         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
12062         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
12063 #ifdef RTE_LIBRTE_IXGBE_PMD
12064         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
12065         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
12066         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
12067         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
12068         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
12069         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
12070         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
12071         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
12072         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
12073         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
12074         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
12075         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
12076         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
12077         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
12078         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
12079         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
12080 #endif
12081         NULL,
12082 };
12083
12084 /* prompt function, called from main on MASTER lcore */
12085 void
12086 prompt(void)
12087 {
12088         /* initialize non-constant commands */
12089         cmd_set_fwd_mode_init();
12090         cmd_set_fwd_retry_mode_init();
12091
12092         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
12093         if (testpmd_cl == NULL)
12094                 return;
12095         cmdline_interact(testpmd_cl);
12096         cmdline_stdin_exit(testpmd_cl);
12097 }
12098
12099 void
12100 prompt_exit(void)
12101 {
12102         if (testpmd_cl != NULL)
12103                 cmdline_quit(testpmd_cl);
12104 }
12105
12106 static void
12107 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
12108 {
12109         if (id == (portid_t)RTE_PORT_ALL) {
12110                 portid_t pid;
12111
12112                 FOREACH_PORT(pid, ports) {
12113                         /* check if need_reconfig has been set to 1 */
12114                         if (ports[pid].need_reconfig == 0)
12115                                 ports[pid].need_reconfig = dev;
12116                         /* check if need_reconfig_queues has been set to 1 */
12117                         if (ports[pid].need_reconfig_queues == 0)
12118                                 ports[pid].need_reconfig_queues = queue;
12119                 }
12120         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
12121                 /* check if need_reconfig has been set to 1 */
12122                 if (ports[id].need_reconfig == 0)
12123                         ports[id].need_reconfig = dev;
12124                 /* check if need_reconfig_queues has been set to 1 */
12125                 if (ports[id].need_reconfig_queues == 0)
12126                         ports[id].need_reconfig_queues = queue;
12127         }
12128 }