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