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