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