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