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