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