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