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