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