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