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