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